Guest User

Untitled

a guest
Oct 29th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <gtkmm.h>
  2.  
  3. class MainWindow;
  4.  
  5. class CEntry : public Gtk::Entry
  6. {
  7. public:
  8. CEntry ();
  9. void SetParent ( MainWindow* );
  10. private:
  11. virtual bool on_key_press_event ( GdkEventKey* );
  12. MainWindow* parent;
  13. };
  14.  
  15. class MainWindow
  16. :
  17. public Gtk::Window
  18. {
  19. public:
  20.  
  21. MainWindow();
  22. virtual ~MainWindow();
  23. void SetText ( const Glib::ustring& );
  24.  
  25. private:
  26.  
  27. // Gtkmm Widgets...
  28.  
  29. Gtk::Grid grid;
  30. CEntry entry;
  31. Gtk::Label label;
  32. };
  33.  
  34.  
  35. MainWindow::MainWindow()
  36. {
  37. set_title ("Window Keys");
  38.  
  39. entry.SetParent ( this );
  40.  
  41. grid.set_column_homogeneous (false);
  42. grid.set_row_homogeneous (false);
  43. grid.set_row_spacing (10);
  44.  
  45. grid.attach (entry, 0, 0, 1, 1);
  46. grid.attach (label, 0, 1, 1, 1);
  47.  
  48. add (grid);
  49.  
  50. show_all_children();
  51. }
  52.  
  53. MainWindow::~MainWindow()
  54. {
  55. }
  56.  
  57. void MainWindow::SetText ( const Glib::ustring& text )
  58. {
  59. label.set_text ( text );
  60. }
  61.  
  62. CEntry::CEntry () {}
  63.  
  64. void CEntry::SetParent ( MainWindow* p )
  65. {
  66. parent = p;
  67. }
  68.  
  69. bool
  70. CEntry::on_key_press_event (GdkEventKey * key)
  71. {
  72. Glib::ustring s =
  73. Glib::ustring::compose ("State : %1\n", key->state) +
  74. Glib::ustring::compose ("KeyVal : %1\n", key->keyval) +
  75. Glib::ustring::compose ("KeyCode : %1\n", key->hardware_keycode) +
  76. Glib::ustring::compose ("Group : %1\n", key->group) +
  77. Glib::ustring::compose ("Modifier? %1\n", key->is_modifier);
  78. parent->SetText ( s );
  79. // to get standard Entry processing as well, uncomment the next line
  80. //Gtk::Entry::on_key_press_event ( key );
  81. return true;
  82. }
  83.  
  84. int main (int argc, char *argv[])
  85. {
  86. Glib::RefPtr<Gtk::Application> app =
  87. Gtk::Application::create (argc, argv);
  88.  
  89. MainWindow main_window;
  90.  
  91. return
  92. app->run (main_window);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment