| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#include "mixgtk_wm.h" |
| 25 |
|
| 26 |
#include "mixgtk_config.h" |
| 27 |
#include "mixgtk_device.h" |
| 28 |
#include "mixgtk_mixvm.h" |
| 29 |
#include "mixgtk_mixal.h" |
| 30 |
#include "mixgtk_widgets.h" |
| 31 |
#include "mixgtk_cmd_dispatcher.h" |
| 32 |
#include "mixgtk_gen_handlers.h" |
| 33 |
#include "mixgtk.h" |
| 34 |
|
| 35 |
|
| 36 |
typedef struct window_info_t_ |
| 37 |
{ |
| 38 |
mixgtk_dialog_id_t dialog; |
| 39 |
GtkWidget *widget; |
| 40 |
GtkCheckMenuItem *menu; |
| 41 |
const gchar *menu_name; |
| 42 |
const gchar *config_key; |
| 43 |
const gchar *toolbar_name; |
| 44 |
const gchar *attach_button; |
| 45 |
gboolean detached; |
| 46 |
void (*detach) (void); |
| 47 |
void (*attach) (void); |
| 48 |
} window_info_t_; |
| 49 |
|
| 50 |
static const gchar *DETACH_YES_ = "Yes"; |
| 51 |
static const gchar *DETACH_NO_ = "No"; |
| 52 |
static GtkWidget *about_ = NULL; |
| 53 |
|
| 54 |
static GtkContainer *mixvm_container_ = NULL; |
| 55 |
static GtkContainer *mixal_container_ = NULL; |
| 56 |
static GtkContainer *dev_container_ = NULL; |
| 57 |
|
| 58 |
static GtkToolItem *attach_button_ = NULL; |
| 59 |
static GtkToolItem *detach_button_ = NULL; |
| 60 |
|
| 61 |
static const gchar *TB_MENU_NAME_ = "show_toolbars"; |
| 62 |
static GtkCheckMenuItem *tb_menu_ = NULL; |
| 63 |
static GtkNotebook *notebook_ = NULL; |
| 64 |
|
| 65 |
static mix_vm_t *vm_ = NULL; |
| 66 |
|
| 67 |
static void init_info_ (void); |
| 68 |
static void init_notebook_ (void); |
| 69 |
static void init_dispatcher_ (void); |
| 70 |
static void init_mixvm_ (void); |
| 71 |
static void init_mixal_ (void); |
| 72 |
static void init_dev_ (void); |
| 73 |
static void init_signals_ (void); |
| 74 |
static void init_visibility_ (void); |
| 75 |
static void init_tb_ (void); |
| 76 |
static void init_about_ (void); |
| 77 |
static void init_autosave_ (void); |
| 78 |
static void set_tb_style_ (guint style); |
| 79 |
static void show_toolbars_ (gboolean show); |
| 80 |
static void add_page_ (GtkWidget *w, mixgtk_window_id_t id); |
| 81 |
static void mixvm_attach_ (void); |
| 82 |
static void mixvm_detach_ (void); |
| 83 |
static void mixal_attach_ (void); |
| 84 |
static void mixal_detach_ (void); |
| 85 |
static void dev_attach_ (void); |
| 86 |
static void dev_detach_ (void); |
| 87 |
static void reparent_ (GtkWidget *widget, GtkWidget *parent); |
| 88 |
static void update_attach_buttons_ (void); |
| 89 |
static void on_tb_style_ (GtkMenuItem *w, gpointer style); |
| 90 |
static void on_nb_switch_ (GtkNotebook *notebook, GtkWidget *page, |
| 91 |
guint page_num, gpointer user_data); |
| 92 |
|
| 93 |
static window_info_t_ infos_[] = { |
| 94 |
{MIXGTK_MIXVM_DIALOG, NULL, NULL, |
| 95 |
"detach_vm", "MIX.detach", "mixvm_toolbar", "attach_button_mixvm", |
| 96 |
FALSE, mixvm_detach_, mixvm_attach_}, |
| 97 |
{MIXGTK_MIXAL_DIALOG, NULL, NULL, |
| 98 |
"detach_source", "MIXAL.detach", "mixal_toolbar", "attach_button_mixal", |
| 99 |
FALSE, mixal_detach_, mixal_attach_}, |
| 100 |
{MIXGTK_DEVICES_DIALOG, NULL, NULL, |
| 101 |
"detach_dev", "Devices.detach", "dev_toolbar", "attach_button_dev", |
| 102 |
FALSE, dev_detach_, dev_attach_} |
| 103 |
}; |
| 104 |
|
| 105 |
static size_t INF_NO_ = sizeof (infos_) / sizeof (infos_[0]); |
| 106 |
|
| 107 |
|
| 108 |
gboolean |
| 109 |
mixgtk_wm_init (void) |
| 110 |
{ |
| 111 |
gint k; |
| 112 |
|
| 113 |
init_info_ (); |
| 114 |
init_notebook_ (); |
| 115 |
init_dispatcher_ (); |
| 116 |
init_mixvm_ (); |
| 117 |
init_mixal_ (); |
| 118 |
init_dev_ (); |
| 119 |
init_tb_ (); |
| 120 |
|
| 121 |
for (k = 0; k < INF_NO_; ++k) |
| 122 |
{ |
| 123 |
if (infos_[k].detached) |
| 124 |
mixgtk_wm_detach_window (k); |
| 125 |
else |
| 126 |
mixgtk_wm_attach_window (k); |
| 127 |
} |
| 128 |
|
| 129 |
init_about_ (); |
| 130 |
init_autosave_ (); |
| 131 |
init_visibility_ (); |
| 132 |
init_signals_ (); |
| 133 |
|
| 134 |
return TRUE; |
| 135 |
} |
| 136 |
|
| 137 |
void |
| 138 |
mixgtk_wm_detach_window (mixgtk_window_id_t w) |
| 139 |
{ |
| 140 |
if (w < INF_NO_) |
| 141 |
{ |
| 142 |
(*(infos_[w].detach)) (); |
| 143 |
infos_[w].detached = TRUE; |
| 144 |
gtk_check_menu_item_set_active (infos_[w].menu, TRUE); |
| 145 |
mixgtk_config_update (infos_[w].config_key, DETACH_YES_); |
| 146 |
if (infos_[w].widget != NULL) gtk_widget_show (infos_[w].widget); |
| 147 |
if (gtk_notebook_get_n_pages (notebook_) < 1) |
| 148 |
gtk_widget_hide (GTK_WIDGET (notebook_)); |
| 149 |
gtk_widget_show (mixgtk_widget_factory_get_dialog (infos_[w].dialog)); |
| 150 |
update_attach_buttons_ (); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
void |
| 155 |
mixgtk_wm_attach_window (mixgtk_window_id_t w) |
| 156 |
{ |
| 157 |
if (w < INF_NO_) |
| 158 |
{ |
| 159 |
gint page = gtk_notebook_page_num (notebook_, infos_[w].widget); |
| 160 |
|
| 161 |
gtk_widget_hide (mixgtk_widget_factory_get_dialog (infos_[w].dialog)); |
| 162 |
|
| 163 |
if (page < 0) (*(infos_[w].attach)) (); |
| 164 |
|
| 165 |
infos_[w].detached = FALSE; |
| 166 |
gtk_check_menu_item_set_active (infos_[w].menu, FALSE); |
| 167 |
mixgtk_config_update (infos_[w].config_key, DETACH_NO_); |
| 168 |
if (gtk_notebook_get_n_pages (notebook_) == 1) |
| 169 |
gtk_widget_show (GTK_WIDGET (notebook_)); |
| 170 |
update_attach_buttons_ (); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
void |
| 178 |
on_detach_clicked (GtkWidget *ignored) |
| 179 |
{ |
| 180 |
gint page = gtk_notebook_get_current_page (notebook_); |
| 181 |
if (page >= 0) |
| 182 |
{ |
| 183 |
gint k; |
| 184 |
GtkWidget *w = gtk_notebook_get_nth_page (notebook_, page); |
| 185 |
|
| 186 |
for (k = 0; k < INF_NO_; ++k) |
| 187 |
if (infos_[k].widget == w) mixgtk_wm_detach_window (k); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
void |
| 192 |
on_attach_all_clicked () |
| 193 |
{ |
| 194 |
gint k; |
| 195 |
for (k = INF_NO_; k > 0; --k) |
| 196 |
if (infos_[k - 1].detached) mixgtk_wm_attach_window (k - 1); |
| 197 |
} |
| 198 |
|
| 199 |
void |
| 200 |
on_attach_toggled (GtkCheckMenuItem *item) |
| 201 |
{ |
| 202 |
gint k; |
| 203 |
for (k = 0; k < INF_NO_; ++k) |
| 204 |
if (item == infos_[k].menu) break; |
| 205 |
g_return_if_fail (k < INF_NO_); |
| 206 |
gboolean active = gtk_check_menu_item_get_active (item); |
| 207 |
if (active) mixgtk_wm_detach_window (k); |
| 208 |
else mixgtk_wm_attach_window (k); |
| 209 |
mixgtk_config_update (infos_[k].config_key, active? DETACH_YES_ : DETACH_NO_); |
| 210 |
} |
| 211 |
|
| 212 |
void |
| 213 |
on_window_hide (GtkWidget *w) |
| 214 |
{ |
| 215 |
gint k; |
| 216 |
for (k = 0; k < INF_NO_; ++k) |
| 217 |
if (w == mixgtk_widget_factory_get_dialog (infos_[k].dialog)) break; |
| 218 |
g_return_if_fail (k < INF_NO_); |
| 219 |
mixgtk_wm_attach_window (k); |
| 220 |
} |
| 221 |
|
| 222 |
void |
| 223 |
on_show_toolbars_toggled (GtkCheckMenuItem *item) |
| 224 |
{ |
| 225 |
gboolean active = gtk_check_menu_item_get_active (item); |
| 226 |
if (active != mixgtk_config_show_toolbars ()) show_toolbars_ (active); |
| 227 |
} |
| 228 |
|
| 229 |
void |
| 230 |
on_widget_attach (GtkWidget *ign, gpointer id) |
| 231 |
{ |
| 232 |
mixgtk_wm_attach_window (GPOINTER_TO_INT (id)); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
void |
| 237 |
on_about_activate (GtkWidget *w, gpointer data) |
| 238 |
{ |
| 239 |
if (!about_) init_about_ (); |
| 240 |
gtk_widget_show (about_); |
| 241 |
} |
| 242 |
|
| 243 |
void |
| 244 |
on_about_clicked (GtkWidget *w) |
| 245 |
{ |
| 246 |
if (about_) gtk_widget_hide (about_); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
static void |
| 252 |
init_info_ (void) |
| 253 |
{ |
| 254 |
gint k; |
| 255 |
for (k = 0; k < INF_NO_; ++k) |
| 256 |
{ |
| 257 |
const gchar *txt; |
| 258 |
|
| 259 |
infos_[k].menu = |
| 260 |
GTK_CHECK_MENU_ITEM |
| 261 |
(mixgtk_widget_factory_get_by_name (infos_[k].menu_name)); |
| 262 |
g_assert (infos_[k].menu != NULL); |
| 263 |
txt = mixgtk_config_get (infos_[k].config_key); |
| 264 |
infos_[k].detached = txt && !g_ascii_strcasecmp (txt, DETACH_YES_); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
static void |
| 269 |
init_notebook_ (void) |
| 270 |
{ |
| 271 |
notebook_ = |
| 272 |
GTK_NOTEBOOK (mixgtk_widget_factory_get (MIXGTK_MAIN, |
| 273 |
MIXGTK_WIDGET_NOTEBOOK)); |
| 274 |
g_assert (notebook_ != NULL); |
| 275 |
gtk_widget_show (GTK_WIDGET (notebook_)); |
| 276 |
} |
| 277 |
|
| 278 |
static void |
| 279 |
add_page_ (GtkWidget *page, mixgtk_window_id_t id) |
| 280 |
{ |
| 281 |
static const gchar *LABELS[] = { |
| 282 |
N_("_Virtual machine"), N_("_Source"), N_("_Devices") |
| 283 |
}; |
| 284 |
|
| 285 |
gint p = 0; |
| 286 |
|
| 287 |
g_assert (page != NULL); |
| 288 |
g_assert (id < INF_NO_); |
| 289 |
g_assert (notebook_ != NULL); |
| 290 |
|
| 291 |
if (id > MIXGTK_MIXVM_WINDOW) |
| 292 |
{ |
| 293 |
if (id == MIXGTK_DEVICES_WINDOW) |
| 294 |
p = gtk_notebook_get_n_pages (notebook_); |
| 295 |
else |
| 296 |
p = infos_[MIXGTK_MIXVM_WINDOW].detached ? 0 : 1; |
| 297 |
} |
| 298 |
|
| 299 |
gtk_notebook_insert_page (notebook_, page, |
| 300 |
gtk_label_new_with_mnemonic (LABELS[id]), |
| 301 |
p); |
| 302 |
gtk_notebook_set_current_page (notebook_, p); |
| 303 |
gtk_widget_show (page); |
| 304 |
gtk_widget_show (GTK_WIDGET (notebook_)); |
| 305 |
} |
| 306 |
|
| 307 |
static void |
| 308 |
init_signals_ (void) |
| 309 |
{ |
| 310 |
gint k; |
| 311 |
for (k = 0; k < INF_NO_; ++k) |
| 312 |
{ |
| 313 |
GObject *dialog = |
| 314 |
G_OBJECT (mixgtk_widget_factory_get_dialog (infos_[k].dialog)); |
| 315 |
|
| 316 |
GObject *button = |
| 317 |
G_OBJECT (mixgtk_widget_factory_get_by_name (infos_[k].attach_button)); |
| 318 |
|
| 319 |
g_assert (dialog != NULL); |
| 320 |
g_assert (button != NULL); |
| 321 |
|
| 322 |
g_signal_connect (button, "clicked", |
| 323 |
G_CALLBACK (on_widget_attach), GINT_TO_POINTER (k)); |
| 324 |
g_signal_connect (dialog, "destroy", |
| 325 |
G_CALLBACK (on_window_hide), NULL); |
| 326 |
g_signal_connect (dialog, "destroy_event", |
| 327 |
G_CALLBACK (on_window_hide), NULL); |
| 328 |
g_signal_connect (dialog, "delete_event", |
| 329 |
G_CALLBACK (on_window_hide), NULL); |
| 330 |
g_signal_connect (G_OBJECT (infos_[k].menu), "toggled", |
| 331 |
G_CALLBACK (on_attach_toggled), NULL); |
| 332 |
} |
| 333 |
|
| 334 |
GtkWindow *mainw = |
| 335 |
GTK_WINDOW (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)); |
| 336 |
|
| 337 |
g_signal_connect (mainw, "destroy", |
| 338 |
G_CALLBACK (on_file_exit_activate), NULL); |
| 339 |
} |
| 340 |
|
| 341 |
static void |
| 342 |
init_visibility_ (void) |
| 343 |
{ |
| 344 |
gint k; |
| 345 |
for (k = 0; k < INF_NO_; ++k) |
| 346 |
if (infos_[k].detached) |
| 347 |
gtk_widget_show (mixgtk_widget_factory_get_dialog (infos_[k].dialog)); |
| 348 |
|
| 349 |
if (gtk_notebook_get_n_pages (notebook_) > 0) |
| 350 |
gtk_notebook_set_current_page (notebook_, 0); |
| 351 |
|
| 352 |
gtk_widget_show (mixgtk_widget_factory_get_dialog (MIXGTK_MAIN)); |
| 353 |
} |
| 354 |
|
| 355 |
static void |
| 356 |
init_dispatcher_ (void) |
| 357 |
{ |
| 358 |
if (!mixgtk_cmd_dispatcher_init (MIXGTK_MAIN)) |
| 359 |
g_assert (FALSE); |
| 360 |
vm_ = mixgtk_cmd_dispatcher_get_vm (); |
| 361 |
g_assert (vm_ != NULL); |
| 362 |
} |
| 363 |
|
| 364 |
static void |
| 365 |
init_mixvm_ (void) |
| 366 |
{ |
| 367 |
GtkContainer *vm = |
| 368 |
GTK_CONTAINER |
| 369 |
(mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, MIXGTK_WIDGET_MIXVM)); |
| 370 |
|
| 371 |
mixvm_container_ = |
| 372 |
GTK_CONTAINER (mixgtk_widget_factory_get (MIXGTK_MIXVM_DIALOG, |
| 373 |
MIXGTK_WIDGET_MIXVM_CONTAINER)); |
| 374 |
|
| 375 |
g_assert (mixvm_container_ != NULL); |
| 376 |
|
| 377 |
g_assert (vm != NULL); |
| 378 |
g_object_ref (G_OBJECT (vm)); |
| 379 |
infos_[MIXGTK_MIXVM_WINDOW].widget = GTK_WIDGET (vm); |
| 380 |
|
| 381 |
mixgtk_mixvm_init (vm_); |
| 382 |
mixgtk_mixvm_update_vm_widgets (); |
| 383 |
|
| 384 |
gtk_widget_show (GTK_WIDGET (vm)); |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
static void |
| 389 |
init_mixal_ (void) |
| 390 |
{ |
| 391 |
GtkWidget *page = gtk_scrolled_window_new (NULL, NULL); |
| 392 |
GtkWidget *mixal = mixgtk_mixal_init (vm_); |
| 393 |
|
| 394 |
g_assert (page != NULL); |
| 395 |
g_assert (mixal != NULL); |
| 396 |
|
| 397 |
g_object_ref (page); |
| 398 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (page), |
| 399 |
GTK_POLICY_AUTOMATIC, |
| 400 |
GTK_POLICY_AUTOMATIC); |
| 401 |
|
| 402 |
gtk_container_add (GTK_CONTAINER (page), mixal); |
| 403 |
|
| 404 |
infos_[MIXGTK_MIXAL_WINDOW].widget = page; |
| 405 |
|
| 406 |
mixal_container_ = |
| 407 |
GTK_CONTAINER (mixgtk_widget_factory_get (MIXGTK_MIXAL_DIALOG, |
| 408 |
MIXGTK_WIDGET_MIXAL_CONTAINER)); |
| 409 |
|
| 410 |
g_assert (mixal_container_ != NULL); |
| 411 |
|
| 412 |
gtk_container_add (mixal_container_, page); |
| 413 |
|
| 414 |
gtk_widget_show (mixal); |
| 415 |
gtk_widget_show (page); |
| 416 |
gtk_widget_show (GTK_WIDGET (mixal_container_)); |
| 417 |
} |
| 418 |
|
| 419 |
static void |
| 420 |
init_dev_ (void) |
| 421 |
{ |
| 422 |
GtkWidget *page = gtk_scrolled_window_new (NULL, NULL); |
| 423 |
GtkWidget *devs = mixgtk_device_init (vm_); |
| 424 |
|
| 425 |
g_assert (page != NULL); |
| 426 |
g_assert (devs != NULL); |
| 427 |
|
| 428 |
g_object_ref (page); |
| 429 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (page), |
| 430 |
GTK_POLICY_AUTOMATIC, |
| 431 |
GTK_POLICY_AUTOMATIC); |
| 432 |
|
| 433 |
gtk_container_add (GTK_CONTAINER (page), devs); |
| 434 |
|
| 435 |
infos_[MIXGTK_DEVICES_WINDOW].widget = page; |
| 436 |
|
| 437 |
dev_container_ = |
| 438 |
GTK_CONTAINER (mixgtk_widget_factory_get (MIXGTK_DEVICES_DIALOG, |
| 439 |
MIXGTK_WIDGET_DEV_CONTAINER)); |
| 440 |
|
| 441 |
g_assert (dev_container_ != NULL); |
| 442 |
|
| 443 |
gtk_container_add (dev_container_, page); |
| 444 |
|
| 445 |
gtk_widget_show (devs); |
| 446 |
gtk_widget_show (page); |
| 447 |
} |
| 448 |
|
| 449 |
static void |
| 450 |
init_tb_ (void) |
| 451 |
{ |
| 452 |
gchar *names[4]; |
| 453 |
gint k; |
| 454 |
gint style = mixgtk_config_tb_style (); |
| 455 |
|
| 456 |
tb_menu_ = GTK_CHECK_MENU_ITEM |
| 457 |
(mixgtk_widget_factory_get_by_name (TB_MENU_NAME_)); |
| 458 |
g_assert (tb_menu_ != NULL); |
| 459 |
|
| 460 |
gtk_check_menu_item_set_active (tb_menu_, mixgtk_config_show_toolbars ()); |
| 461 |
show_toolbars_ (mixgtk_config_show_toolbars ()); |
| 462 |
|
| 463 |
g_signal_connect (G_OBJECT (tb_menu_), "toggled", |
| 464 |
G_CALLBACK (on_show_toolbars_toggled), NULL); |
| 465 |
|
| 466 |
attach_button_ = GTK_TOOL_ITEM |
| 467 |
(mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_ATTACH_BUTTON)); |
| 468 |
detach_button_ = GTK_TOOL_ITEM |
| 469 |
(mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_DETACH_BUTTON)); |
| 470 |
|
| 471 |
g_assert (attach_button_); |
| 472 |
g_assert (detach_button_); |
| 473 |
|
| 474 |
names[GTK_TOOLBAR_ICONS] = "tb_style_icons"; |
| 475 |
names[GTK_TOOLBAR_TEXT] = "tb_style_labels"; |
| 476 |
names[GTK_TOOLBAR_BOTH] = "tb_style_both"; |
| 477 |
names[GTK_TOOLBAR_BOTH_HORIZ] = "tb_style_bothh"; |
| 478 |
|
| 479 |
for (k = 0; k < 4; ++k) |
| 480 |
{ |
| 481 |
GtkWidget *item = mixgtk_widget_factory_get_by_name (names[k]); |
| 482 |
g_signal_connect (G_OBJECT (item), |
| 483 |
"activate", |
| 484 |
G_CALLBACK (on_tb_style_), GUINT_TO_POINTER (k)); |
| 485 |
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), (k == style)); |
| 486 |
} |
| 487 |
set_tb_style_ (style); |
| 488 |
} |
| 489 |
|
| 490 |
static void |
| 491 |
on_tb_style_ (GtkMenuItem *w, gpointer style) |
| 492 |
{ |
| 493 |
guint ui_style = GPOINTER_TO_UINT (style); |
| 494 |
set_tb_style_ (ui_style); |
| 495 |
mixgtk_config_set_tb_style (ui_style); |
| 496 |
} |
| 497 |
|
| 498 |
static const gchar *TB_NAME = "main_toolbar"; |
| 499 |
|
| 500 |
static void |
| 501 |
set_tb_style_ (guint style) |
| 502 |
{ |
| 503 |
gint k; |
| 504 |
|
| 505 |
GtkToolbar *tb = |
| 506 |
GTK_TOOLBAR (mixgtk_widget_factory_get_by_name (TB_NAME)); |
| 507 |
gtk_toolbar_set_style (tb, style); |
| 508 |
|
| 509 |
for (k = 0; k < INF_NO_; ++k) |
| 510 |
{ |
| 511 |
GtkToolbar *tb = GTK_TOOLBAR |
| 512 |
(mixgtk_widget_factory_get_by_name (infos_[k].toolbar_name)); |
| 513 |
gtk_toolbar_set_style (tb, style); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
static void |
| 518 |
show_toolbars_ (gboolean show) |
| 519 |
{ |
| 520 |
gint k; |
| 521 |
|
| 522 |
GtkWidget *handle = mixgtk_widget_factory_get_by_name (TB_NAME); |
| 523 |
|
| 524 |
if (show) |
| 525 |
gtk_widget_show (handle); |
| 526 |
else |
| 527 |
gtk_widget_hide (handle); |
| 528 |
|
| 529 |
for (k = 0; k < INF_NO_; ++k) |
| 530 |
{ |
| 531 |
GtkWidget *hd = |
| 532 |
mixgtk_widget_factory_get_by_name (infos_[k].toolbar_name); |
| 533 |
if (show) gtk_widget_show (hd); else gtk_widget_hide (hd); |
| 534 |
} |
| 535 |
|
| 536 |
mixgtk_config_set_show_toolbars (show); |
| 537 |
} |
| 538 |
|
| 539 |
static void |
| 540 |
init_autosave_ (void) |
| 541 |
{ |
| 542 |
#define AUTOSAVE_ITEM_ "save_on_exit" |
| 543 |
|
| 544 |
GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM |
| 545 |
(mixgtk_widget_factory_get_by_name (AUTOSAVE_ITEM_)); |
| 546 |
if (item) |
| 547 |
{ |
| 548 |
gtk_check_menu_item_set_active (item, mixgtk_config_is_autosave ()); |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
static void |
| 553 |
init_about_ (void) |
| 554 |
{ |
| 555 |
#define VERSION_LABEL_ "version_label" |
| 556 |
#define GPL_TEXT_ "gpl_text" |
| 557 |
GtkWidget *label; |
| 558 |
about_ = mixgtk_widget_factory_get_dialog (MIXGTK_ABOUT_DIALOG); |
| 559 |
g_assert (about_ != NULL); |
| 560 |
label = mixgtk_widget_factory_get_by_name (VERSION_LABEL_); |
| 561 |
g_assert (label != NULL); |
| 562 |
gtk_label_set_text (GTK_LABEL (label), VERSION); |
| 563 |
gtk_widget_show (label); |
| 564 |
} |
| 565 |
|
| 566 |
static void |
| 567 |
mixvm_attach_ (void) |
| 568 |
{ |
| 569 |
gtk_container_remove (mixvm_container_, infos_[MIXGTK_MIXVM_WINDOW].widget); |
| 570 |
add_page_ (infos_[MIXGTK_MIXVM_WINDOW].widget, MIXGTK_MIXVM_WINDOW); |
| 571 |
} |
| 572 |
|
| 573 |
static void |
| 574 |
reparent_ (GtkWidget *widget, GtkWidget *parent) |
| 575 |
{ |
| 576 |
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (widget)), widget); |
| 577 |
gtk_container_add (GTK_CONTAINER (parent), widget); |
| 578 |
} |
| 579 |
|
| 580 |
static void |
| 581 |
mixvm_detach_ (void) |
| 582 |
{ |
| 583 |
reparent_ (infos_[MIXGTK_MIXVM_WINDOW].widget, GTK_WIDGET (mixvm_container_)); |
| 584 |
} |
| 585 |
|
| 586 |
static void |
| 587 |
mixal_attach_ (void) |
| 588 |
{ |
| 589 |
static GtkStatusbar *stat = NULL; |
| 590 |
|
| 591 |
if (stat == NULL) |
| 592 |
{ |
| 593 |
stat = |
| 594 |
GTK_STATUSBAR |
| 595 |
(mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_STATUSBAR)); |
| 596 |
g_assert (stat); |
| 597 |
|
| 598 |
g_signal_connect (G_OBJECT (notebook_), "switch-page", |
| 599 |
G_CALLBACK (on_nb_switch_), NULL); |
| 600 |
} |
| 601 |
|
| 602 |
mixgtk_mixal_reparent (stat); |
| 603 |
gtk_container_remove (mixal_container_, infos_[MIXGTK_MIXAL_WINDOW].widget); |
| 604 |
add_page_ (infos_[MIXGTK_MIXAL_WINDOW].widget, MIXGTK_MIXAL_WINDOW); |
| 605 |
} |
| 606 |
|
| 607 |
static void |
| 608 |
mixal_detach_ (void) |
| 609 |
{ |
| 610 |
static GtkStatusbar *stat = NULL; |
| 611 |
|
| 612 |
if (stat == NULL) |
| 613 |
{ |
| 614 |
stat = |
| 615 |
GTK_STATUSBAR |
| 616 |
(mixgtk_widget_factory_get (MIXGTK_MIXAL_DIALOG, |
| 617 |
MIXGTK_WIDGET_MIXAL_STATUSBAR)); |
| 618 |
g_assert (stat); |
| 619 |
} |
| 620 |
|
| 621 |
mixgtk_mixal_reparent (stat); |
| 622 |
reparent_ (infos_[MIXGTK_MIXAL_WINDOW].widget, GTK_WIDGET (mixal_container_)); |
| 623 |
} |
| 624 |
|
| 625 |
static void |
| 626 |
dev_attach_ (void) |
| 627 |
{ |
| 628 |
gtk_container_remove (dev_container_, infos_[MIXGTK_DEVICES_WINDOW].widget); |
| 629 |
add_page_ (infos_[MIXGTK_DEVICES_WINDOW].widget, MIXGTK_DEVICES_WINDOW); |
| 630 |
} |
| 631 |
|
| 632 |
static void |
| 633 |
dev_detach_ (void) |
| 634 |
{ |
| 635 |
reparent_ (infos_[MIXGTK_DEVICES_WINDOW].widget, GTK_WIDGET (dev_container_)); |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
static void |
| 640 |
on_nb_switch_ (GtkNotebook *notebook, GtkWidget *page, |
| 641 |
guint page_num, gpointer user_data) |
| 642 |
{ |
| 643 |
if (!(infos_[MIXGTK_MIXAL_WINDOW].detached) |
| 644 |
&& (page != infos_[MIXGTK_MIXAL_WINDOW].widget)) |
| 645 |
mixgtk_mixal_pop_status (); |
| 646 |
} |
| 647 |
|
| 648 |
static void |
| 649 |
update_attach_buttons_ (void) |
| 650 |
{ |
| 651 |
gint k; |
| 652 |
gboolean wants_attach = FALSE; |
| 653 |
gboolean wants_detach = FALSE; |
| 654 |
|
| 655 |
g_assert (attach_button_); |
| 656 |
g_assert (detach_button_); |
| 657 |
|
| 658 |
for (k = 0; k < INF_NO_; ++k) |
| 659 |
{ |
| 660 |
wants_attach = wants_attach || infos_[k].detached; |
| 661 |
wants_detach = wants_detach || !infos_[k].detached; |
| 662 |
} |
| 663 |
|
| 664 |
gtk_tool_item_set_visible_horizontal (attach_button_, wants_attach); |
| 665 |
gtk_tool_item_set_visible_vertical (attach_button_, wants_attach); |
| 666 |
gtk_tool_item_set_visible_horizontal (detach_button_, wants_detach); |
| 667 |
gtk_tool_item_set_visible_vertical (detach_button_, wants_detach); |
| 668 |
} |