Пример #1
0
static void window_docking_changed(GtkComboBox *combo)
{
        int mode;

        mode = gtk_combo_box_get_active(combo);
        window_set_docked(mode);
}
Пример #2
0
void window_create(void)
/* Create the main window and child widgets */
{
        GtkWidget *widget, *window_vbox, *image;
        GdkScreen *screen;

        /* Create the window or plug */
        window = !window_embedded ? gtk_window_new(GTK_WINDOW_TOPLEVEL) :
                                    gtk_plug_new(0);
        g_signal_connect(G_OBJECT(window), "delete-event",
                         G_CALLBACK(window_close), NULL);
        g_signal_connect(G_OBJECT(window), "destroy",
                         G_CALLBACK(gtk_main_quit), NULL);
        g_signal_connect(G_OBJECT(window), "style-set",
                         G_CALLBACK(window_style_set), NULL);
        g_signal_connect(G_OBJECT(window), "configure-event",
                         G_CALLBACK(window_configure), NULL);
        gtk_window_set_accept_focus(GTK_WINDOW(window), FALSE);
        gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

        /* Tooltips */
        tooltips = gtk_tooltips_new();
        gtk_tooltips_enable(tooltips);

        /* Root box */
        window_vbox = gtk_vbox_new(FALSE, 0);
        gtk_widget_show(window_vbox);

        /* Training info label frame */
        train_label_frame = gtk_frame_new(NULL);
        gtk_widget_set_no_show_all(train_label_frame, TRUE);
        gtk_frame_set_shadow_type(GTK_FRAME(train_label_frame), GTK_SHADOW_IN);
        gtk_container_set_border_width(GTK_CONTAINER(train_label_frame), 2);

        /* Training info label */
        train_label = gtk_label_new(NULL);
        gtk_label_set_line_wrap(GTK_LABEL(train_label), TRUE);
        gtk_label_set_justify(GTK_LABEL(train_label), GTK_JUSTIFY_FILL);
        gtk_label_set_markup(GTK_LABEL(train_label),
                             "<b>Training Mode:</b> Carefully draw each "
                             "character in its cell. Multiple "
                             "samples will be stored for each character. "
                             "If you make a mistake, reset by "
                             "pressing on the cell with the pen eraser.");
        gtk_widget_show(train_label);

        /* Training info label colored box */
        train_label_box = gtk_event_box_new();
        gtk_widget_show(train_label_box);
        gtk_container_add(GTK_CONTAINER(train_label_box), train_label);
        gtk_container_add(GTK_CONTAINER(train_label_frame), train_label_box);
        gtk_widget_show_all(train_label_frame);
        gtk_box_pack_start(GTK_BOX(window_vbox), train_label_frame,
                           FALSE, FALSE, 0);

        /* Cell widget */
        cell_widget = cell_widget_new();
        gtk_box_pack_start(GTK_BOX(window_vbox), cell_widget, TRUE, TRUE, 2);
        if (!keyboard_only)
                gtk_widget_show_all(cell_widget);

        /* Key widget */
        key_widget = key_widget_new_full();
        gtk_box_pack_start(GTK_BOX(window_vbox), key_widget->drawing_area,
                           TRUE, TRUE, 2);
        if (keyboard_only) {
                gtk_widget_show(key_widget->drawing_area);
                keys_on = TRUE;
        }

        /* Bottom box */
        bottom_box = gtk_hbox_new(FALSE, 0);

        /* Train button */
        train_button = gtk_toggle_button_new_with_label("Train");
        gtk_button_set_focus_on_click(GTK_BUTTON(train_button), FALSE);
        gtk_button_set_image(GTK_BUTTON(train_button),
                             gtk_image_new_from_stock(GTK_STOCK_MEDIA_RECORD,
                                                      GTK_ICON_SIZE_BUTTON));
        gtk_button_set_relief(GTK_BUTTON(train_button), GTK_RELIEF_NONE);
        gtk_box_pack_start(GTK_BOX(bottom_box), train_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(train_button), "toggled",
                         G_CALLBACK(train_button_toggled), 0);
        gtk_tooltips_set_tip(tooltips, train_button, "Toggle training mode",
                             NULL);

        /* Setup button */
        setup_button = gtk_button_new_with_label("Setup");
        gtk_button_set_focus_on_click(GTK_BUTTON(setup_button), FALSE);
        gtk_button_set_image(GTK_BUTTON(setup_button),
                             gtk_image_new_from_stock(GTK_STOCK_PREFERENCES,
                                                      GTK_ICON_SIZE_BUTTON));
        gtk_button_set_relief(GTK_BUTTON(setup_button), GTK_RELIEF_NONE);
        gtk_box_pack_start(GTK_BOX(bottom_box), setup_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(setup_button), "clicked",
                         G_CALLBACK(options_dialog_open), 0);
        gtk_tooltips_set_tip(tooltips, setup_button, "Edit program options",
                             NULL);

        /* Expanding box to keep things tidy */
        widget = gtk_vbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(bottom_box), widget, TRUE, FALSE, 0);

        /* Training Unicode Block selector */
        widget = create_blocks_combo();
        gtk_box_pack_start(GTK_BOX(bottom_box), widget, FALSE, FALSE, 0);
        gtk_widget_set_no_show_all(blocks_combo, TRUE);

        /* Clear button */
        clear_button = gtk_button_new_with_label("Clear");
        gtk_button_set_focus_on_click(GTK_BUTTON(clear_button), FALSE);
        image = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(clear_button), image);
        gtk_button_set_relief(GTK_BUTTON(clear_button), GTK_RELIEF_NONE);
        gtk_box_pack_start(GTK_BOX(bottom_box), clear_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(clear_button), "clicked",
                         G_CALLBACK(cell_widget_clear), 0);
        gtk_tooltips_set_tip(tooltips, clear_button, "Clear current input",
                             NULL);

        /* Keys button */
        keys_button = gtk_toggle_button_new_with_label("Keys");
        gtk_button_set_focus_on_click(GTK_BUTTON(keys_button), FALSE);
        image = gtk_image_new_from_icon_name("keyboard", GTK_ICON_SIZE_BUTTON);
        gtk_button_set_image(GTK_BUTTON(keys_button), image);
        gtk_button_set_relief(GTK_BUTTON(keys_button), GTK_RELIEF_NONE);
        gtk_box_pack_start(GTK_BOX(bottom_box), keys_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(keys_button), "toggled",
                         G_CALLBACK(keys_button_toggled), 0);
        gtk_tooltips_set_tip(tooltips, keys_button,
                             "Switch between on-screen keyboard and "
                             "handwriting input", NULL);

        /* Insert button */
        insert_button = gtk_button_new_with_label("Enter");
        gtk_button_set_focus_on_click(GTK_BUTTON(insert_button), FALSE);
        gtk_button_set_image(GTK_BUTTON(insert_button),
                             gtk_image_new_from_stock(GTK_STOCK_OK,
                                                      GTK_ICON_SIZE_BUTTON));
        gtk_button_set_relief(GTK_BUTTON(insert_button), GTK_RELIEF_NONE);
        gtk_box_pack_start(GTK_BOX(bottom_box), insert_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(insert_button), "clicked",
                         G_CALLBACK(insert_button_clicked), 0);
        gtk_tooltips_set_tip(tooltips, insert_button,
                             "Insert input or press Enter key", NULL);

        /* Back buffer button */
        buffer_button = gtk_toggle_button_new();
        gtk_button_set_focus_on_click(GTK_BUTTON(buffer_button), FALSE);
        button_set_image_xpm(buffer_button, tab_xpm);
        gtk_button_set_relief(GTK_BUTTON(buffer_button), GTK_RELIEF_NONE);
        gtk_box_pack_start(GTK_BOX(bottom_box), buffer_button, FALSE, FALSE, 0);
        g_signal_connect(G_OBJECT(buffer_button), "pressed",
                         G_CALLBACK(buffer_button_pressed), NULL);
        gtk_tooltips_set_tip(tooltips, buffer_button,
                             "Recall previously entered input", NULL);
        gtk_widget_set_sensitive(buffer_button, FALSE);

        /* Pack the regular bottom box */
        gtk_box_pack_start(GTK_BOX(window_vbox), bottom_box, FALSE, FALSE, 0);
        if (!keyboard_only)
                gtk_widget_show_all(bottom_box);

        /* Update button labels */
        toggle_button_labels(window_button_labels);

        /* Set window style */
        window_style_set(window);

        if (window_embedded) {

                /* Embedding in a screensaver won't let us popup new windows */
                gtk_widget_hide(buffer_button);
                gtk_widget_hide(train_button);
                gtk_widget_hide(setup_button);

                /* If we are embedded we need to print the plug's window XID */
                g_signal_connect_after(G_OBJECT(window), "realize",
                                       G_CALLBACK(print_window_xid), NULL);

                gtk_container_add(GTK_CONTAINER(window), window_vbox);
                gtk_widget_show(window);
                return;
        }

        /* Non-embedded window configuration */
        gtk_container_add(GTK_CONTAINER(window), window_vbox);
        gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);
        gtk_window_set_type_hint(GTK_WINDOW(window),
                                 GDK_WINDOW_TYPE_HINT_UTILITY);
        gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME);
        gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);
        gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
        gtk_window_set_decorated(GTK_WINDOW(window), TRUE);
        gtk_window_stick(GTK_WINDOW(window));

        /* Coordinates passed on the command-line */
        if (window_force_x >= 0)
                window_frame.x = window_force_x;
        if (window_force_y >= 0)
                window_frame.y = window_force_y;

        /* Center window on initial startup */
        screen = gtk_window_get_screen(GTK_WINDOW(window));
        if (window_frame.x < 0)
                window_frame.x = gdk_screen_get_width(screen) / 2;
        if (window_frame.y < 0)
                window_frame.y = gdk_screen_get_height(screen) * 3 / 4;
        gtk_window_move(GTK_WINDOW(window), window_frame.x,
                        window_frame.y);

        /* Create status icon */
        status_icon_create();

        /* Set the window size */
        if (window_force_docked >= WINDOW_UNDOCKED)
                window_docked = window_force_docked;
        if (window_docked) {
                int mode;

                mode = window_docked;
                window_docked = WINDOW_UNDOCKED;
                window_set_docked(mode);
        }

        /* Show window */
        if (window_force_hide)
                window_shown = FALSE;
        else if (window_force_show)
                window_shown = TRUE;
        if (window_shown) {
                gtk_widget_show(window);
        } else {
                /* Check if the status icon is embedded after a timeout so that
                   it has a chance to embed itself into the tray. */
                gtk_timeout_add(10, status_icon_embedded_check, NULL);
        }
}