00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011 #include "vgui_gtk_window.h"
00012
00013 #include <vgui/vgui.h>
00014 #include <vgui/vgui_menu.h>
00015
00016 #include <gtk/gtk.h>
00017 #include <gtkgl/gtkglarea.h>
00018
00019 #include "vgui_gtk_adaptor.h"
00020 #include "vgui_gtk_utils.h"
00021 #include "vgui_gtk_statusbar.h"
00022
00023 #include <vcl_compiler.h>
00024
00025 static bool debug = false;
00026
00027 extern "C" {
00028
00029
00030
00031
00032 static gint delete_event_callback(GtkWidget* w, GdkEvent* e, gpointer data)
00033 {
00034 vgui_gtk_adaptor* adaptor = static_cast<vgui_gtk_adaptor*>(data);
00035
00036 adaptor->post_destroy();
00037
00038
00039
00040 return true;
00041 }
00042
00043 }
00044
00045
00046
00047 vgui_gtk_window::vgui_gtk_window(int w, int h, const char* title)
00048 : use_menubar(false)
00049 , use_statusbar(true)
00050 , statusbar(new vgui_gtk_statusbar)
00051 , last_menubar(new vgui_menu)
00052 {
00053 if (debug) vcl_cerr << "vgui_gtk_window::vgui_gtk_window\n";
00054
00055 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00056 gtk_window_set_title(GTK_WINDOW(window), title);
00057 gtk_window_set_default_size(GTK_WINDOW(window),w,h);
00058
00059 adaptor = new vgui_gtk_adaptor(this);
00060
00061 #ifndef VCL_SGI_CC // SGI's iostream does not allow re-initialising
00062 vgui::out.rdbuf(static_cast<vgui_gtk_statusbar*>(statusbar)->statusbuf);
00063 #endif
00064
00065 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
00066 GTK_SIGNAL_FUNC(delete_event_callback),
00067 static_cast<vgui_gtk_adaptor*>(adaptor));
00068 }
00069
00070
00071
00072
00073 vgui_gtk_window::vgui_gtk_window(int w, int h, const vgui_menu& menu, const char* title)
00074 : use_menubar(true)
00075 , use_statusbar(true)
00076 , statusbar(new vgui_gtk_statusbar)
00077 , last_menubar(new vgui_menu)
00078 {
00079 if (debug) vcl_cerr << "vgui_gtk_window::vgui_gtk_window\n";
00080
00081 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00082 gtk_window_set_title(GTK_WINDOW(window), title);
00083 gtk_window_set_default_size(GTK_WINDOW(window),w,h);
00084
00085 adaptor = new vgui_gtk_adaptor(this);
00086
00087 set_menubar(menu);
00088
00089 #ifndef VCL_SGI_CC // SGI's iostream does not allow re-initialising
00090 vgui::out.rdbuf(static_cast<vgui_gtk_statusbar*>(statusbar)->statusbuf);
00091 #endif
00092
00093 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
00094 GTK_SIGNAL_FUNC(delete_event_callback),
00095 static_cast<vgui_gtk_adaptor*>(adaptor));
00096 }
00097
00098
00099
00100
00101 vgui_gtk_window::~vgui_gtk_window()
00102 {
00103 gtk_widget_destroy(window);
00104 delete last_menubar;
00105 delete statusbar;
00106 }
00107
00108
00109
00110
00111 void vgui_gtk_window::init()
00112 {
00113 box = gtk_vbox_new(FALSE, 0);
00114 gtk_container_add(GTK_CONTAINER (window), box);
00115
00116 if (use_menubar) {
00117 gtk_box_pack_start(GTK_BOX(box), menubar, FALSE, TRUE, 0);
00118 gtk_widget_show(menubar);
00119 }
00120
00121
00122 GtkWidget *frame = gtk_frame_new(0);
00123 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
00124 gtk_container_set_border_width(GTK_CONTAINER(frame), 2);
00125
00126 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 0);
00127 gtk_widget_show(frame);
00128
00129
00130
00131
00132 GtkWidget *glarea = (static_cast<vgui_gtk_adaptor*>(adaptor))->get_glarea_widget();
00133 gtk_container_add(GTK_CONTAINER(frame), glarea);
00134 gtk_widget_show(glarea);
00135
00136 if (use_statusbar) {
00137 static_cast<vgui_gtk_statusbar*>(statusbar)->widget = gtk_statusbar_new();
00138 gtk_box_pack_start(GTK_BOX(box), static_cast<vgui_gtk_statusbar*>(statusbar)->widget, FALSE, TRUE, 0);
00139 gtk_widget_show(static_cast<vgui_gtk_statusbar*>(statusbar)->widget);
00140 }
00141
00142 gtk_widget_show(box);
00143 }
00144
00145
00146
00147 void vgui_gtk_window::set_menubar(const vgui_menu &menu)
00148 {
00149 if (debug) vcl_cerr << "vgui_gtk_window::set_menubar\n";
00150
00151 use_menubar = true;
00152
00153
00154
00155 *last_menubar = menu;
00156
00157 menubar = gtk_menu_bar_new();
00158 if (vgui_gtk_utils::accel_group == NULL)
00159 {
00160 vgui_gtk_utils::accel_group = gtk_accel_group_get_default();
00161 gtk_accel_group_attach(vgui_gtk_utils::accel_group,GTK_OBJECT(window));
00162 }
00163 vgui_gtk_utils::set_menu(menubar, *last_menubar, true);
00164 }
00165
00166
00167 void vgui_gtk_window::show()
00168 {
00169 init();
00170
00171 if (debug) vcl_cerr << "vgui_gtk_window::show\n";
00172 gtk_widget_show(window);
00173 }
00174
00175 void vgui_gtk_window::hide()
00176 {
00177 if (debug) vcl_cerr << "vgui_gtk_window::hide\n";
00178 }
00179
00180 void vgui_gtk_window::set_title(vcl_string const &title)
00181 {
00182 gtk_window_set_title(GTK_WINDOW(window), title.c_str());
00183 }