Advertisement
palmerstone

Gtk 3

Nov 18th, 2011
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. #include <cairo.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <gtk/gtk.h>
  5. #include <gdk/gdk.h>
  6. #include <gdk/gdkkeysyms.h>
  7.  
  8. GtkContainer *box;
  9. GtkWidget *window, *vbox;
  10. GtkWidget *menubar, *filemenu, *help, *helpmenu;
  11. GtkWidget *file, *quit, *open, *save, *properties, *about;
  12. GtkWidget *img, *img2;
  13. GtkWidget *dialog;
  14.  
  15. void create_menu()
  16. {
  17. vbox = gtk_vbox_new(FALSE, 0);
  18. box = gtk_vbox_new(FALSE, 0);
  19. gtk_box_pack_start(GTK_BOX(box), vbox, TRUE, TRUE, 0);
  20. menubar = gtk_menu_bar_new();
  21. filemenu = gtk_menu_new();
  22.  
  23. file = gtk_menu_item_new_with_label("File");
  24. quit = gtk_menu_item_new_with_label("Quit Ctrl + Q");
  25. open = gtk_menu_item_new_with_label("Open Ctrl + O");
  26. save = gtk_menu_item_new_with_label("Save");
  27. properties = gtk_menu_item_new_with_label("Properties Ctrl + P");
  28.  
  29. gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
  30. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
  31. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
  32. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), properties);
  33. gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  34. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
  35.  
  36. helpmenu = gtk_menu_new();
  37. about = gtk_menu_item_new_with_label("About");
  38. help = gtk_menu_item_new_with_label("Help");
  39. gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu);
  40. gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about);
  41. gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help);
  42. gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
  43. }
  44.  
  45. void show_about()
  46. {
  47. GtkWidget *dialog;
  48. const char *author[] = {"None yet\n(However, Special thanks to Mehedi Hasan :-) )",NULL};
  49. dialog = gtk_about_dialog_new();
  50. gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"You just clicked about!");
  51. gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  52. gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"Good job and go to hell");
  53. gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
  54. gtk_dialog_run(GTK_DIALOG(dialog));
  55. }
  56.  
  57. void open_file()
  58. {
  59. dialog = gtk_file_chooser_dialog_new ("Open File",window,GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,NULL);
  60. if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  61. {
  62. char *filename;
  63. filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  64. gtk_container_remove(GTK_CONTAINER(box), img);
  65. img = gtk_image_new_from_file(filename);
  66. gtk_widget_show(img);
  67. gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  68. g_free (filename);
  69. }
  70. gtk_widget_destroy (dialog);
  71. }
  72.  
  73. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer data)
  74. {
  75. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  76. exit (0x0);
  77. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  78. open_file();
  79. if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_P || lol->keyval == GDK_KEY_p))
  80. show_properties();
  81. return TRUE;
  82. }
  83.  
  84. void show_properties()
  85. {
  86.  
  87. }
  88.  
  89. int main(int argc, char*argv[])
  90. {
  91. gtk_init(&argc, &argv);
  92. window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  93. gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  94. gtk_window_set_default_size(GTK_WINDOW(window), 800, 500);
  95. gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  96.  
  97. create_menu();
  98. char picture_name[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
  99. img = gtk_image_new_from_file(picture_name);
  100. gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  101. gtk_container_add(GTK_CONTAINER(window), box);
  102.  
  103. g_signal_connect(G_OBJECT(window), "destroy",G_CALLBACK(gtk_main_quit), NULL);
  104. g_signal_connect(G_OBJECT(open), "activate", G_CALLBACK(open_file), NULL);
  105. g_signal_connect(G_OBJECT(properties), "activate", G_CALLBACK(show_properties), NULL);
  106. g_signal_connect(G_OBJECT(about), "activate", G_CALLBACK(show_about), NULL);
  107. g_signal_connect(G_OBJECT(quit), "activate",G_CALLBACK(gtk_main_quit), NULL);
  108. g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), window);
  109. gtk_widget_show_all(window);
  110. gtk_main();
  111.  
  112. return 0x0;
  113. }
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement