accelerator.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_GTKUTIL_ACCELERATOR_H)
00023 #define INCLUDED_GTKUTIL_ACCELERATOR_H
00024 
00025 #include <gdk/gdktypes.h>
00026 #include <gdk/gdkkeysyms.h>
00027 #include <gdk/gdkkeys.h>
00028 #include "generic/callback.h"
00029 #include <string>
00030 
00031 // ignore numlock
00032 #define ALLOWED_MODIFIERS (~(GDK_MOD2_MASK | GDK_LOCK_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK))
00033 
00034 struct Accelerator
00035 {
00036         Accelerator (guint _key) :
00037             key(gdk_keyval_to_upper(_key)), modifiers((GdkModifierType) 0)
00038         {
00039         }
00040         Accelerator (guint _key, GdkModifierType _modifiers) :
00041             key(gdk_keyval_to_upper(_key)), modifiers((GdkModifierType) (_modifiers & ALLOWED_MODIFIERS))
00042         {
00043         }
00044         Accelerator (const Accelerator &src) :
00045             key(gdk_keyval_to_upper(src.key)), modifiers((GdkModifierType) (src.modifiers & ALLOWED_MODIFIERS))
00046         {
00047         }
00048         bool operator< (const Accelerator& other) const
00049         {
00050             guint k1 = key;
00051             guint k2 = other.key;
00052             int mod1 = modifiers & ALLOWED_MODIFIERS;
00053             int mod2 = other.modifiers & ALLOWED_MODIFIERS;
00054             return k1 < k2 || (!(k2 < k1) && mod1 < mod2);
00055         }
00056         bool operator== (const Accelerator& other) const
00057         {
00058             guint k1 = key;
00059             guint k2 = other.key;
00060             int mod1 = modifiers & ALLOWED_MODIFIERS;
00061             int mod2 = other.modifiers & ALLOWED_MODIFIERS;
00062             return k1 == k2 && mod1 == mod2;
00063         }
00064         Accelerator &operator= (const Accelerator& other)
00065         {
00066             key = other.key;
00067             modifiers = (GdkModifierType) (other.modifiers & ALLOWED_MODIFIERS);
00068             return *this;
00069         }
00070         guint key;
00071         GdkModifierType modifiers;
00072 };
00073 
00074 inline Accelerator accelerator_null ()
00075 {
00076     return Accelerator(0, (GdkModifierType) 0);
00077 }
00078 
00079 const char* global_keys_find (unsigned int key);
00080 unsigned int global_keys_find (const std::string& name);
00081 
00082 class TextOutputStream;
00083 void accelerator_write (const Accelerator& accelerator, TextOutputStream& ostream);
00084 
00085 template<typename TextOutputStreamType>
00086 TextOutputStreamType& ostream_write (TextOutputStreamType& ostream, const Accelerator& accelerator)
00087 {
00088     accelerator_write(accelerator, ostream);
00089     return ostream;
00090 }
00091 
00092 void keydown_accelerators_add (Accelerator accelerator, const Callback& callback);
00093 void keydown_accelerators_remove (Accelerator accelerator);
00094 void keyup_accelerators_add (Accelerator accelerator, const Callback& callback);
00095 void keyup_accelerators_remove (Accelerator accelerator);
00096 
00097 typedef struct _GtkWidget GtkWidget;
00098 typedef struct _GtkWindow GtkWindow;
00099 void global_accel_connect_window (GtkWindow* window);
00100 void global_accel_disconnect_window (GtkWindow* window);
00101 
00102 void GlobalPressedKeys_releaseAll ();
00103 
00104 typedef struct _GtkAccelGroup GtkAccelGroup;
00105 extern GtkAccelGroup* global_accel;
00106 void global_accel_init ();
00107 void global_accel_destroy ();
00108 
00109 GClosure* global_accel_group_find (Accelerator accelerator);
00110 
00111 void global_accel_group_connect (const Accelerator& accelerator, const Callback& callback);
00112 void global_accel_group_disconnect (const Accelerator& accelerator, const Callback& callback);
00113 
00114 class Command
00115 {
00116     public:
00117         Callback m_callback;
00118         const Accelerator& m_accelerator;
00119         Command (const Callback& callback, const Accelerator& accelerator) :
00120             m_callback(callback), m_accelerator(accelerator)
00121         {
00122         }
00123 };
00124 
00125 class Toggle
00126 {
00127     public:
00128         Command m_command;
00129         BoolExportCallback m_exportCallback;
00130         Toggle (const Callback& callback, const Accelerator& accelerator, const BoolExportCallback& exportCallback) :
00131             m_command(callback, accelerator), m_exportCallback(exportCallback)
00132         {
00133         }
00134 };
00135 
00136 class KeyEvent
00137 {
00138     public:
00139         const Accelerator& m_accelerator;
00140         Callback m_keyDown;
00141         Callback m_keyUp;
00142         KeyEvent (const Accelerator& accelerator, const Callback& keyDown, const Callback& keyUp) :
00143             m_accelerator(accelerator), m_keyDown(keyDown), m_keyUp(keyUp)
00144         {
00145         }
00146 };
00147 
00148 struct PressedButtons;
00149 typedef struct _GtkWidget GtkWidget;
00150 void PressedButtons_connect (PressedButtons& pressedButtons, GtkWidget* widget);
00151 
00152 extern PressedButtons g_pressedButtons;
00153 
00154 #endif

Generated by  doxygen 1.6.2