Back to index

im-sdk  12.3.91
lookup_aux.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include "lookup_aux.h"
00004 
00005 #define _(s)  (s)
00006 
00007 void lookup_window_hide(lookup_window_t *lookup_window);
00008 GtkWidget *lookup_window_create_symbols_page(lookup_window_t *lookup_window);
00009 GtkWidget *lookup_window_create_charmap_page(lookup_window_t *lookup_window);
00010 void lookup_window_click_ok_button_callback (GtkButton *button, gpointer user_data);
00011 gboolean lookup_window_delete_callback (GtkWidget *widget, GdkEvent *event, gpointer user_data);
00012 
00013 /*********************************************************************/
00014 /*                lookup_window_t  utilities                         */
00015 /*********************************************************************/
00016 lookup_window_t *lookup_window_new()
00017 {
00018     GtkWidget *window;
00019     GtkWidget *vbox;
00020     GtkWidget *notebook;
00021     GtkWidget *ok_button;
00022     GtkWidget *label;
00023     GtkWidget *symbols_page;
00024     GtkWidget *charmap_page;
00025     GtkWidget *hbox;
00026     lookup_window_t *lookup_window = NULL;
00027 
00028     lookup_window = (lookup_window_t *) calloc(1, sizeof(lookup_window_t));
00029     if (lookup_window == NULL)
00030         return NULL;
00031 
00032     lookup_window->lookup_data = (lookup_data_t *)lookup_data_new();
00033     lookup_data_print(lookup_window->lookup_data);
00034 
00035     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00036     gtk_window_set_accept_focus (GTK_WINDOW(window), FALSE);
00037     gtk_window_set_title(GTK_WINDOW(window), _("window"));
00038     lookup_window->window = window;
00039 
00040     vbox = gtk_vbox_new(FALSE, 6);
00041     gtk_widget_show(vbox);
00042     gtk_container_add(GTK_CONTAINER(window), vbox);
00043 
00044     notebook = gtk_notebook_new();
00045     gtk_widget_show(notebook);
00046     gtk_notebook_set_scrollable (GTK_NOTEBOOK(notebook), TRUE);
00047     gtk_notebook_popup_enable (GTK_NOTEBOOK(notebook));
00048     gtk_box_pack_start(GTK_BOX(vbox), notebook, FALSE, FALSE, 6);
00049 
00050     label = gtk_label_new(_("symbols page"));
00051     gtk_widget_show(label);
00052 
00053     symbols_page = (GtkWidget *)lookup_window_create_symbols_page(lookup_window);
00054     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), symbols_page, label);
00055 
00056     label = gtk_label_new(_("charmap page"));
00057     gtk_widget_show(label);
00058 
00059     charmap_page = lookup_window_create_charmap_page(lookup_window);
00060     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), charmap_page, label);
00061 
00062     // Create hbox for button area.
00063     hbox = gtk_hbox_new (FALSE, 0);
00064     gtk_widget_show (hbox);
00065     gtk_box_pack_start(GTK_BOX (vbox), hbox, FALSE, FALSE, 8);
00066 
00067     ok_button = gtk_button_new_from_stock ("gtk-ok");
00068     gtk_widget_show (ok_button);
00069     gtk_box_pack_end (GTK_BOX (hbox), ok_button, FALSE, FALSE, 4);
00070     GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
00071 
00072     g_signal_connect ((gpointer) ok_button, "clicked",
00073                       G_CALLBACK (lookup_window_click_ok_button_callback),
00074                       lookup_window);
00075     g_signal_connect (G_OBJECT (window), "delete_event",
00076                       G_CALLBACK (lookup_window_delete_callback),
00077                       lookup_window);
00078 
00079     gtk_widget_grab_default (ok_button);
00080 
00081     gtk_widget_realize(window);
00082 
00083     return lookup_window;
00084 }
00085 
00086 void lookup_window_destroy(lookup_window_t *lookup_window)
00087 {
00088     if (lookup_window == NULL)
00089         return;
00090 
00091     if (lookup_window->lookup_data) {
00092         lookup_data_destroy(lookup_window->lookup_data);
00093     }
00094 
00095     if (lookup_window->window)
00096         gtk_widget_destroy(lookup_window->window);
00097 
00098     free ((char *)lookup_window);
00099 }
00100 
00101 void lookup_window_print(lookup_window_t *lookup_window)
00102 {
00103     if (lookup_window == NULL)
00104         return;
00105 
00106     if (lookup_window->lookup_data) {
00107         lookup_data_print(lookup_window->lookup_data);
00108     }
00109 }
00110 
00111 void lookup_window_show(lookup_window_t *lookup_window)
00112 {
00113     if (lookup_window == NULL)
00114         return;
00115 
00116     if (lookup_window->window) {
00117         gtk_widget_show (lookup_window->window);
00118         gdk_window_raise (lookup_window->window->window);
00119     }
00120 }
00121 
00122 void lookup_window_hide(lookup_window_t *lookup_window)
00123 {
00124     if (lookup_window == NULL)
00125         return;
00126 
00127     if (lookup_window->window) {
00128         gtk_widget_hide (lookup_window->window);
00129     }
00130 }
00131 
00132 GtkWidget *lookup_window_create_charmap_page(lookup_window_t *lookup_window)
00133 {
00134     GtkWidget *hbox;
00135     GtkWidget *scrolledwindow;
00136     GtkWidget *viewport;
00137     GtkWidget *fixed;
00138     GtkWidget *button;
00139     GtkWidget *vbox;
00140     GtkWidget *label;
00141 
00142     hbox = gtk_hbox_new(FALSE, 0);
00143     gtk_widget_show(hbox);
00144 
00145     scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
00146     gtk_widget_show(scrolledwindow);
00147     gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow, TRUE, TRUE, 0);
00148     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
00149                                GTK_POLICY_AUTOMATIC,
00150                                GTK_POLICY_AUTOMATIC);
00151 
00152     viewport = gtk_viewport_new(NULL, NULL);
00153     gtk_widget_show(viewport);
00154     gtk_container_add(GTK_CONTAINER(scrolledwindow), viewport);
00155 
00156     fixed = gtk_fixed_new();
00157     gtk_widget_show(fixed);
00158     gtk_container_add(GTK_CONTAINER(viewport), fixed);
00159 
00160     button = gtk_button_new_with_mnemonic(_("button"));
00161     gtk_widget_show(button);
00162     gtk_fixed_put(GTK_FIXED(fixed), button, 160, 40);
00163     gtk_widget_set_size_request(button, 60, 27);
00164 
00165     button = gtk_button_new_with_mnemonic(_("button"));
00166     gtk_widget_show(button);
00167     gtk_fixed_put(GTK_FIXED(fixed), button, 56, 32);
00168     gtk_widget_set_size_request(button, 60, 27);
00169 
00170     vbox = gtk_vbox_new(FALSE, 0);
00171     gtk_widget_show(vbox);
00172     gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
00173 
00174     label = gtk_label_new(_("label"));
00175     gtk_widget_show(label);
00176     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00177 
00178     label = gtk_label_new(_("label"));
00179     gtk_widget_show(label);
00180     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00181 
00182     label = gtk_label_new(_("label"));
00183     gtk_widget_show(label);
00184     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
00185 
00186     button = gtk_button_new_with_mnemonic(_("button"));
00187     gtk_widget_show(button);
00188     gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00189 
00190     button = gtk_button_new_with_mnemonic(_("button"));
00191     gtk_widget_show(button);
00192     gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
00193 
00194     return hbox;
00195 }
00196 
00197 GtkWidget *lookup_window_create_symbols_page(lookup_window_t *lookup_window)
00198 {
00199     GtkWidget *hbox;
00200     GtkWidget *scrolledwindow;
00201     GtkWidget *scrolledwindow2;
00202     GtkWidget *viewport1;
00203     GtkWidget *treeview;
00204     GtkWidget *table1;
00205     GtkWidget *button;
00206 
00207     hbox = gtk_hbox_new(FALSE, 0);
00208     gtk_widget_show(hbox);
00209 
00210     scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
00211     gtk_widget_show(scrolledwindow);
00212     gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow, TRUE, TRUE, 0);
00213     gtk_widget_set_size_request(scrolledwindow, 150, 280);
00214     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
00215                                GTK_POLICY_AUTOMATIC,
00216                                GTK_POLICY_AUTOMATIC);
00217 
00218     treeview = gtk_tree_view_new();
00219     gtk_widget_show(treeview);
00220     gtk_container_add(GTK_CONTAINER(scrolledwindow), treeview);
00221     gtk_widget_set_size_request(treeview, 9, -1);
00222     gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
00223     gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
00224     gtk_tree_view_set_reorderable(GTK_TREE_VIEW(treeview), TRUE);
00225 
00226     scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL);
00227     gtk_widget_show(scrolledwindow2);
00228     gtk_box_pack_start(GTK_BOX(hbox), scrolledwindow2, TRUE, TRUE, 0);
00229     gtk_widget_set_size_request(scrolledwindow2, 470, 420);
00230     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow2),
00231                                GTK_POLICY_AUTOMATIC,
00232                                GTK_POLICY_AUTOMATIC);
00233 
00234     viewport1 = gtk_viewport_new(NULL, NULL);
00235     gtk_widget_show(viewport1);
00236     gtk_container_add(GTK_CONTAINER(scrolledwindow2), viewport1);
00237 
00238     table1 = gtk_table_new(10, 10, FALSE);
00239     gtk_widget_show(table1);
00240     gtk_container_add(GTK_CONTAINER(viewport1), table1);
00241 
00242     button = gtk_button_new_with_mnemonic(_("button"));
00243     gtk_widget_show(button);
00244     gtk_table_attach(GTK_TABLE(table1), button, 0, 1, 0, 1,
00245                    (GtkAttachOptions) (GTK_FILL),
00246                    (GtkAttachOptions) (0), 0, 0);
00247 
00248     button = gtk_button_new_with_mnemonic(_("button"));
00249     gtk_widget_show(button);
00250     gtk_table_attach(GTK_TABLE(table1), button, 1, 2, 1, 2,
00251                    (GtkAttachOptions) (GTK_FILL),
00252                    (GtkAttachOptions) (0), 0, 0);
00253 
00254     return hbox;
00255 }
00256 
00257 void
00258 lookup_window_click_ok_button_callback (GtkButton *button, gpointer user_data)
00259 {
00260     lookup_window_t *lookup_window = (lookup_window_t *)user_data;
00261 
00262     lookup_window_hide(lookup_window);
00263     return;
00264 }
00265 
00266 gboolean
00267 lookup_window_delete_callback (GtkWidget *widget, GdkEvent *event, gpointer user_data)
00268 {
00269     lookup_window_t *lookup_window = (lookup_window_t *)user_data;
00270 
00271     lookup_window_hide(lookup_window);
00272     return TRUE;
00273 }