Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gtkmm.h>
- class MainWindow;
- class CEntry : public Gtk::Entry
- {
- public:
- CEntry ();
- void SetParent ( MainWindow* );
- private:
- virtual bool on_key_press_event ( GdkEventKey* );
- MainWindow* parent;
- };
- class MainWindow
- :
- public Gtk::Window
- {
- public:
- MainWindow();
- virtual ~MainWindow();
- void SetText ( const Glib::ustring& );
- private:
- // Gtkmm Widgets...
- Gtk::Grid grid;
- CEntry entry;
- Gtk::Label label;
- };
- MainWindow::MainWindow()
- {
- set_title ("Window Keys");
- entry.SetParent ( this );
- grid.set_column_homogeneous (false);
- grid.set_row_homogeneous (false);
- grid.set_row_spacing (10);
- grid.attach (entry, 0, 0, 1, 1);
- grid.attach (label, 0, 1, 1, 1);
- add (grid);
- show_all_children();
- }
- MainWindow::~MainWindow()
- {
- }
- void MainWindow::SetText ( const Glib::ustring& text )
- {
- label.set_text ( text );
- }
- CEntry::CEntry () {}
- void CEntry::SetParent ( MainWindow* p )
- {
- parent = p;
- }
- bool
- CEntry::on_key_press_event (GdkEventKey * key)
- {
- Glib::ustring s =
- Glib::ustring::compose ("State : %1\n", key->state) +
- Glib::ustring::compose ("KeyVal : %1\n", key->keyval) +
- Glib::ustring::compose ("KeyCode : %1\n", key->hardware_keycode) +
- Glib::ustring::compose ("Group : %1\n", key->group) +
- Glib::ustring::compose ("Modifier? %1\n", key->is_modifier);
- parent->SetText ( s );
- // to get standard Entry processing as well, uncomment the next line
- //Gtk::Entry::on_key_press_event ( key );
- return true;
- }
- int main (int argc, char *argv[])
- {
- Glib::RefPtr<Gtk::Application> app =
- Gtk::Application::create (argc, argv);
- MainWindow main_window;
- return
- app->run (main_window);
- }
Advertisement
Add Comment
Please, Sign In to add comment