Back to index

im-sdk  12.3.91
palette_aux.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003 Sun Microsystems Inc.
00003  *
00004  * This is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  *
00019  * Authors: Karl Park <karl.park@sun.com>
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include <stdio.h>
00027 #include <glib.h>
00028 #include <gdk/gdkx.h>
00029 #include <gtk/gtk.h>
00030 #include <assert.h>
00031 #include <koinput.h>
00032 #include <signal.h>
00033 #include <wait.h>
00034 
00035 #include "pixmap.h"
00036 #include "palette_aux.h"
00037 #include "engine-property.h"
00038 #include "kolelog.h"
00039 #include "palette_messages.h"
00040 
00041 extern KOLE_property *p_engine_property;
00042 
00043 PaletteInfoRecord palettecore;
00044 
00045 GdkColor      _normal_bg;
00046 GdkColor      _normal_text;
00047 GdkColor      _active_bg;
00048 GdkColor      _active_text;
00049 #if 0
00050 GtkWidget *   _full_width_punct_button     = 0;
00051 GtkWidget *   _full_width_letter_button    = 0;
00052 #endif
00053 
00054 GtkTooltips * widget_tooltips                    = 0;
00055 
00056 gboolean      _toolbar_window_draging      = FALSE;
00057 gint          _toolbar_window_drag_x       = 0;
00058 gint          _toolbar_window_drag_y       = 0;
00059 
00060 gint          _toolbar_window_pos_x            = 0;
00061 gint          _toolbar_window_pos_y            = 0;
00062 
00063 gboolean      _toolbar_window_show_status  = FALSE;
00064 gboolean      _full_width_punct_status     = FALSE;
00065 gboolean      _full_width_letter_status    = FALSE;
00066 
00067 static const gchar *
00068 p_active_charsets[] = {
00069     _("[Wansung]"),
00070     _("[Johap]"),
00071     NULL,
00072 };
00073 
00074 static const gchar *
00075 p_keyboard_names[] = {
00076     _("2벌식"),
00077     _("3벌식 390"),
00078     _("3벌식 최종"),  
00079 
00080     _("키보드 닫기"),  
00081     NULL,
00082 };
00083 
00084 static const gchar *
00085 p_option_names[] = {
00086 /*    _("virtual keyboard"),*/
00087     _("도움말"),
00088     _("정보"),
00089     NULL,
00090 };
00091 
00092 
00093 extern GdkFilterReturn xaux_ext_event_handler(GdkXEvent *gdk_xevent,
00094                                          GdkEvent *event,
00095                                          gpointer user_data);
00096 static GtkWidget *
00097 create_gtk_image_from_xpm (const char **xpm,
00098                         int          width,
00099                         int          height,
00100                         gboolean     force_create);
00101 
00102 static void aux_palette_set_inputmode (INPUT_MODE_T i_imode);
00103 static void aux_palette_setup_tooltips ();
00104 void aux_palette_position_set (gint pos_x, gint pos_y);
00105 static GdkPixbuf *scale_pixbuf (GdkPixbuf *pixbuf,int width, int height);
00106 static void update_input_mode_button (KOLE_property *prop);
00107 static void update_all_widgets (KOLE_property *prop);
00108 static void aux_palette_redraw_self (gboolean visibility);
00109 
00110 static gboolean
00111 aux_palette_click_event_handler (GtkWidget *window,
00112                              GdkEventButton *event,
00113                              gpointer user_data);
00114 
00115 static void aux_palette_input_mode_popup_click_event_handler (gint i);
00116 static void aux_palette_keyboard_popup_click_event_handler (gint i);
00117 static void aux_palette_option_popup_click_event_handler(gint i);
00118 static gint aux_palette_input_mode_button_click_event_handler (GtkWidget *widget, GdkEvent *event );
00119 static gint aux_palette_keyboard_button_click_event_handler (GtkWidget *widget, GdkEvent *event);
00120 static gint aux_palette_option_button_click_event_handler(GtkWidget *widget, GdkEvent *event);
00121 static GtkWidget *
00122 create_popup_menu_from_list (const gchar **strs, void(*)(gint) );
00123 static void popup_positioner_keyboard (GtkMenu  *menu, gint *x, gint *y,
00124                                    gboolean *push_in, gpointer  func_data);
00125 static void palette_core_data_init (PaletteInfo pinfo);
00126 static void palette_window_start_ime_about_dialog();
00127 void palette_window_show_vkb_window_with_layout(vkb_layout_t *);
00128 static void palette_window_start_command(char *command_str);
00129 
00130 int main(int argc, char **argv)
00131 {
00132     PangoFontDescription *font_desc = 0;
00133     GtkWidget *menu;
00134     GtkWidget *hbox;
00135     GtkWidget *frame;
00136     GtkWidget *image;
00137     GtkRequisition size;
00138     GdkWindow *root_window;
00139  
00140     gint scr_width, scr_height;
00141 
00142     gtk_init (&argc, &argv);
00143   
00144     palette_core_data_init (&palettecore);
00145   
00146     // Read configurations.
00147     gdk_color_parse ("gray92",     &_normal_bg);
00148     gdk_color_parse ("black",      &_normal_text);
00149     gdk_color_parse ("light blue", &_active_bg);
00150     gdk_color_parse ("black",      &_active_text);
00151 
00152     palettecore.pdisplay = gdk_display_get_default ();
00153     palettecore.pscreen = gdk_display_get_default_screen (palettecore.pdisplay);
00154   
00155     font_desc = pango_font_description_from_string ("sans 10");
00156   
00157     /* Create toolbar window */
00158     palettecore.ppalette = gtk_window_new (GTK_WINDOW_POPUP);
00159 
00160     gtk_window_set_policy (GTK_WINDOW (palettecore.ppalette),
00161                         TRUE, TRUE, FALSE);
00162 
00163     gtk_window_set_resizable (GTK_WINDOW (palettecore.ppalette), FALSE);
00164     gtk_widget_add_events (palettecore.ppalette, GDK_BUTTON_PRESS_MASK);
00165     gtk_widget_add_events (palettecore.ppalette, GDK_BUTTON_RELEASE_MASK);
00166     gtk_widget_add_events (palettecore.ppalette, GDK_POINTER_MOTION_MASK);
00167     g_signal_connect (G_OBJECT (palettecore.ppalette),
00168                     "button-press-event",
00169                     G_CALLBACK (aux_palette_click_event_handler),
00170                     GINT_TO_POINTER (0));
00171     g_signal_connect (G_OBJECT (palettecore.ppalette),
00172                     "button-release-event",
00173                     G_CALLBACK (aux_palette_click_event_handler),
00174                     GINT_TO_POINTER (1));
00175 
00176     frame = gtk_frame_new (0);
00177     
00178     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
00179     gtk_container_add (GTK_CONTAINER (palettecore.ppalette), frame);
00180 
00181     hbox = gtk_hbox_new (FALSE, 0);
00182     gtk_container_add (GTK_CONTAINER (frame), hbox);
00183 
00184     image = create_gtk_image_from_xpm ((const char **)move_xpm, 24, 20, 1);
00185 
00186     gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
00187 
00188     palettecore.ppopup_input_mode =
00189        create_popup_menu_from_list (p_active_charsets, aux_palette_input_mode_popup_click_event_handler);
00190 
00191     palettecore.pbutton_input_mode = gtk_button_new ();
00192     gtk_widget_modify_font (GTK_BIN (palettecore.pbutton_input_mode)->child,
00193                          font_desc);
00194     gtk_button_set_relief (GTK_BUTTON (palettecore.pbutton_input_mode),
00195                         GTK_RELIEF_NONE);
00196     gtk_box_pack_start (GTK_BOX (hbox), palettecore.pbutton_input_mode,
00197                      TRUE, TRUE, 0);
00198     g_signal_connect_swapped (G_OBJECT (palettecore.pbutton_input_mode),
00199                            "button_press_event",
00200                            G_CALLBACK (aux_palette_input_mode_button_click_event_handler),
00201                            menu);
00202 
00203     /* New full_width_punctuation button */
00204     image = create_gtk_image_from_xpm ((const char **)keyboard_xpm, -1, -1, 1);
00205     gtk_widget_size_request (image, &size);
00206     /* Keyboard button */
00207     palettecore.pbutton_keyboard = gtk_button_new ();
00208     gtk_button_set_relief (GTK_BUTTON (palettecore.pbutton_keyboard),
00209                         GTK_RELIEF_NONE);
00210     gtk_container_add (GTK_CONTAINER (palettecore.pbutton_keyboard), image);
00211     
00212     gtk_widget_set_size_request (palettecore.pbutton_keyboard,
00213                              size.width + 4, size.height + 3);
00214     gtk_box_pack_start (GTK_BOX (hbox),
00215                      palettecore.pbutton_keyboard,
00216                      TRUE, TRUE, 0);
00217 
00218     g_signal_connect (G_OBJECT (palettecore.pbutton_keyboard),
00219                     "button_press_event",
00220                     G_CALLBACK (aux_palette_keyboard_button_click_event_handler),
00221                     0);
00222 
00223 
00224     /*  
00225        g_signal_connect_swapped (G_OBJECT (palettecore.pbutton_keyboard),
00226        "button_press_event",
00227        G_CALLBACK (aux_palette_keyboard_button_click_event_handler),
00228        menu);
00229     */
00230     
00231     palettecore.ppopup_keyboard =
00232        create_popup_menu_from_list (p_keyboard_names,
00233                                  aux_palette_keyboard_popup_click_event_handler);
00234    
00235     palettecore.ppopup_option = create_popup_menu_from_list(p_option_names, \
00236                             aux_palette_option_popup_click_event_handler); 
00237 
00238     /* New full_width_punctuation button */
00239     image = create_gtk_image_from_xpm ((const char **)options_xpm, -1, -1, 1);
00240     gtk_widget_size_request (image, &size);
00241     palettecore.pbutton_option = gtk_button_new ();
00242     gtk_button_set_relief (GTK_BUTTON (palettecore.pbutton_option),
00243                         GTK_RELIEF_NONE);
00244     gtk_container_add (GTK_CONTAINER (palettecore.pbutton_option), image);
00245     gtk_widget_set_size_request (palettecore.pbutton_option,
00246                              size.width + 4, size.height + 3);
00247     gtk_box_pack_start (GTK_BOX (hbox),
00248                      palettecore.pbutton_option,
00249                      TRUE, TRUE, 0);
00250 
00251 
00252      g_signal_connect (G_OBJECT (palettecore.pbutton_option),
00253                       "button_press_event",
00254                       G_CALLBACK (aux_palette_option_button_click_event_handler),
00255                       0); 
00256 
00257     gtk_widget_show_all (palettecore.ppalette);
00258 
00259 
00260     
00261     _toolbar_window_show_status = TRUE;
00262 
00263     gtk_widget_size_request (palettecore.ppalette, &size);
00264     aux_palette_position_set (gdk_screen_width () - size.width - 7*(gdk_screen_width()/8), 
00265                            gdk_screen_height () - size.height -gdk_screen_height()/8);
00266    
00267     _toolbar_window_drag_x =  gdk_screen_width () - size.width - 7*(gdk_screen_width()/8);
00268     _toolbar_window_drag_y =  gdk_screen_height () - size.height -gdk_screen_width()/8;
00269 
00270     gtk_widget_hide(palettecore.ppalette);
00271 
00272 
00273     gdk_window_add_filter(palettecore.ppalette->window,
00274                        xaux_ext_event_handler, 0);
00275     xaux_ext_register_classes(palettecore.ppalette->window);
00276 
00277     aux_palette_setup_tooltips ();
00278 
00279     root_window = gdk_screen_get_root_window (palettecore.pscreen);
00280     /*
00281     scr_width = gdk_screen_get_width (palettecore.pscreen);
00282     scr_height = gdk_screen_get_height (palettecore.pscreen);
00283     */
00284     gtk_window_get_size (GTK_WINDOW (root_window), &scr_width, &scr_height);
00285     gtk_window_get_size (GTK_WINDOW (palettecore.ppalette),
00286                       &palettecore.i_width,
00287                       &palettecore.i_height);
00288 
00289    /* aux_palette_position_set (scr_width - palettecore.i_width,
00290                            scr_height - palettecore.i_height);
00291     */
00292     palettecore.vkb_layout_list = NULL;
00293     palettecore.current_vkb_layout = NULL;
00294     palettecore.vkb_window = NULL;
00295     palettecore.vkb_show_status = 0;                          
00296     /*palette_window_init_vkb_window();*/
00297     
00298     gtk_main ();
00299     if (font_desc)
00300        pango_font_description_free (font_desc);
00301 }
00302 
00303 
00304 static GtkWidget *
00305 create_gtk_image_from_xpm (const char **xpm,
00306                         int          width,
00307                         int          height,
00308                         gboolean     force_create)
00309 {
00310     GtkWidget *icon;
00311     GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (xpm);
00312 
00313     if (!pixbuf && !force_create)
00314        return 0;
00315   
00316     if (!pixbuf) {
00317        if (width <= 0 || height <= 0)
00318            return 0;
00319     
00320        pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
00321     
00322        if (!pixbuf)
00323            return 0;
00324     
00325        gdk_pixbuf_fill (pixbuf, 0);
00326     }
00327 
00328     if (width <= 0)
00329        width = gdk_pixbuf_get_width (pixbuf);
00330     if (height <= 0)
00331        height = gdk_pixbuf_get_height (pixbuf);
00332 
00333     pixbuf = scale_pixbuf (pixbuf, width, height);
00334 
00335     icon = gtk_image_new_from_pixbuf (pixbuf);
00336     gtk_widget_show (icon);
00337 
00338     gdk_pixbuf_unref (pixbuf);
00339 
00340     return icon;
00341 }
00342 
00343 void aux_palette_position_set (gint pos_x, gint pos_y)
00344 {
00345     GtkRequisition ws;
00346     /*
00347      */
00348     gtk_widget_size_request (palettecore.ppalette, &ws);
00349     
00350      KOLE_LOG (LOGDEST_STDOUT, "testing: pos_x is %d, pos_y is %d, ws.width is %d, ws.height is %d\n",\
00351                       pos_x, pos_y, ws.width, ws.height);    
00352  
00353     if (pos_x + ws.width > gdk_screen_width ()) {
00354        pos_x = gdk_screen_width () - ws.width;
00355     } else if (pos_x < 0) {
00356        pos_x = 0;
00357     }
00358     if (pos_y + ws.height > gdk_screen_height ())
00359        pos_y = gdk_screen_height () - ws.height;
00360     else if (pos_y < 0)
00361        pos_y = 0;
00362     
00363     if (_toolbar_window_pos_x != pos_x || _toolbar_window_pos_y != pos_y) {
00364        gtk_window_move (GTK_WINDOW (palettecore.ppalette), pos_x, pos_y);
00365        _toolbar_window_pos_x = pos_x;
00366        _toolbar_window_pos_y = pos_y;
00367     }
00368     
00369       gtk_window_move (GTK_WINDOW (palettecore.ppalette), pos_x, pos_y);
00370     
00371 }
00372 
00373 static void
00374 gtk_item_factory_menu_pos (GtkMenu  *menu,
00375                            gint     *x,
00376                            gint     *y,
00377                            gboolean *push_in,
00378                            gpointer  func_data)
00379 {
00380     GdkEventButton *bevent = (GdkEventButton *)func_data;
00381     GtkRequisition size_menu, size_widget;
00382     gint menu_pos_x, menu_pos_y;
00383 
00384     gtk_widget_size_request ((GtkWidget *)menu, &size_menu);
00385 
00386     if (_toolbar_window_pos_y - size_menu.height > 0) {
00387        menu_pos_y = _toolbar_window_pos_y - size_menu.height;
00388     } else {
00389        gtk_widget_size_request ((GtkWidget *)palettecore.ppalette, &size_widget);
00390        menu_pos_y = _toolbar_window_pos_y + size_widget.height;
00391     }
00392 
00393     menu_pos_x = _toolbar_window_pos_x + palettecore.pbutton_input_mode->allocation.x;
00394 
00395     *x = menu_pos_x;
00396     *y = menu_pos_y;
00397 }
00398 
00399 static void
00400 popup_positioner_keyboard (GtkMenu  *menu,
00401                            gint     *x,
00402                            gint     *y,
00403                            gboolean *push_in,
00404                            gpointer  func_data)
00405 {
00406     GdkEventButton *bevent = (GdkEventButton *)func_data;
00407     GtkRequisition size_menu, size_widget;
00408     gint menu_pos_x, menu_pos_y;
00409 
00410     gtk_widget_size_request ((GtkWidget *)menu, &size_menu);
00411 
00412     if (_toolbar_window_pos_y - size_menu.height > 0) {
00413        menu_pos_y = _toolbar_window_pos_y - size_menu.height;
00414     } else {
00415        gtk_widget_size_request ((GtkWidget *)palettecore.ppalette, &size_widget);
00416        menu_pos_y = _toolbar_window_pos_y + size_widget.height;
00417     }
00418 
00419     menu_pos_x = _toolbar_window_pos_x + palettecore.pbutton_input_mode->allocation.x;
00420 
00421     *x = menu_pos_x;
00422     *y = menu_pos_y;
00423 }
00424 
00425 static void
00426 popup_positioner_option (GtkMenu  *menu,
00427                            gint     *x,
00428                            gint     *y,
00429                            gboolean *push_in,
00430                            gpointer  func_data)
00431 {
00432     GdkEventButton *bevent = (GdkEventButton *)func_data;
00433     GtkRequisition size_menu, size_widget;
00434     gint menu_pos_x, menu_pos_y;
00435 
00436     gtk_widget_size_request ((GtkWidget *)menu, &size_menu);
00437 
00438     if (_toolbar_window_pos_y - size_menu.height > 0) {
00439         menu_pos_y = _toolbar_window_pos_y - size_menu.height;
00440     } else {
00441         gtk_widget_size_request ((GtkWidget *)palettecore.ppalette, &size_widget);
00442         menu_pos_y = _toolbar_window_pos_y + size_widget.height;
00443     }
00444 
00445     menu_pos_x = _toolbar_window_pos_x + palettecore.pbutton_input_mode->allocation.x +\
00446                              palettecore.pbutton_keyboard->allocation.x;
00447 
00448     *x = menu_pos_x;
00449     *y = menu_pos_y;
00450 }
00451 
00452 
00453 
00454 static gint
00455 aux_palette_input_mode_button_click_event_handler (GtkWidget *widget,
00456                                              GdkEvent *event )
00457 {
00458     GtkWidget *pp;
00459     pp = palettecore.ppopup_input_mode; 
00460     if (pp == 0)
00461        return TRUE;
00462 
00463     if (event->type == GDK_BUTTON_PRESS) {
00464        GdkEventButton *bevent = (GdkEventButton *) event;
00465 
00466        KOLE_LOG (LOGDEST_STDOUT, "Input status button popup menu");
00467        gtk_menu_popup (GTK_MENU (pp), NULL, NULL, 
00468                      gtk_item_factory_menu_pos, bevent,
00469                      bevent->button, bevent->time);
00470        /* Tell calling code that we have handled this event; the buck
00471         * stops here. */
00472        return TRUE;
00473     }
00474 
00475     /* Tell calling code that we have not handled this event; pass it on. */
00476     return FALSE;
00477 }
00478 
00479 static void
00480 aux_palette_input_mode_popup_click_event_handler (gint i)
00481 {
00482     gchar **p = (gchar **) p_active_charsets;
00483     KOLE_LOG (LOGDEST_STDOUT, "%s selected", p_active_charsets[i]);
00484   
00485     if (i != leproperty_get_charset (p_engine_property)){
00486        leproperty_set_charset (p_engine_property, i);
00487        paletteaux_send_switch_charset_request (i);
00488     }
00489     update_all_widgets (p_engine_property);
00490 }
00491 
00492 static void
00493 aux_palette_keyboard_popup_click_event_handler (gint i)
00494 {
00495     KOLE_LOG (LOGDEST_STDOUT, "%s chosen", p_keyboard_names [i]);
00496 /*   palette_window_toggle_vkb_window(); */
00497    if( i == 3 )
00498    {
00499           /*if close  keyboard, swithc keyboard layout to NO1 */
00500         /*paletteaux_send_show_keyboardaux_request(0); 
00501 
00502        palette_window_init_vkb_window();  
00503         palettecore.current_vkb_layout = palettecore.vkb_layout_list[0];*/
00504        if(palettecore.vkb_window)
00505               gtk_widget_hide(palettecore.vkb_window->window);
00506 
00507    }
00508    else
00509    {
00510       paletteaux_send_show_keyboardaux_request (i); 
00511       palette_window_init_vkb_window();
00512       palettecore.current_vkb_layout = palettecore.vkb_layout_list[i];
00513       palette_window_show_vkb_window_with_layout(palettecore.current_vkb_layout); 
00514    }
00515 
00516 }
00517 
00518 
00519 
00520 static void
00521 aux_palette_option_popup_click_event_handler (gint i)
00522 {
00523 /*    paletteaux_send_show_keyboardaux_request (i); */
00524     char command_str[256];
00525 
00526     DEBUG_printf("menu item %d of option menu is pressed\n", i);
00527      if( i == 1)
00528      {
00529          if(palettecore.about_dialog == NULL)
00530                 palette_window_start_ime_about_dialog();
00531          else
00532                 gtk_widget_show(palettecore.about_dialog);
00533      }
00534     else if(i == 0)
00535     {
00536         snprintf(command_str, 256, "/usr/bin/mozilla %s/index.html", LE_DOCS_DIR);
00537         palette_window_start_command(command_str);
00538     }
00539 }
00540 
00541 
00542 
00543 
00544 static GtkWidget *
00545 create_popup_menu_from_list (const gchar **strs,
00546                           void (*popup_menu_handler) (gint) )
00547 {
00548     GtkWidget *menu;
00549     GtkWidget *menuitem;
00550     char **p;
00551     int i;
00552 
00553     menu = gtk_menu_new();
00554 
00555     for (p=strs, i = 0; *p; p++, i++) {
00556        menuitem = gtk_menu_item_new_with_label(*p);
00557        gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
00558        g_signal_connect_swapped(G_OBJECT(menuitem), "activate",
00559                              G_CALLBACK(popup_menu_handler), (gpointer )i);
00560        gtk_widget_show(menuitem);
00561     }
00562 
00563     gtk_widget_show(menu);
00564 
00565     return(menu);
00566 }
00567 
00568 #if 0
00569 static gint
00570 ui_full_width_punct_button_click_cb (GtkWidget *widget,
00571                                  GdkEvent *event )
00572 {
00573     gboolean full_width_punct_status = !_full_width_punct_status;
00574 
00575     ui_toggle_punct (full_width_punct_status);
00576 }
00577 
00578 static gint
00579 ui_full_width_letter_button_click_cb (GtkWidget *widget,
00580                                   GdkEvent *event)
00581 {
00582     gboolean full_width_letter_status = !_full_width_letter_status;
00583 
00584     ui_toggle_letter(full_width_letter_status);
00585 }
00586 #endif
00587 
00588 static gint
00589 aux_palette_keyboard_button_click_event_handler (GtkWidget *widget,
00590                                            GdkEvent *event)
00591 {
00592     GdkEventButton *bev;
00593   
00594     if (palettecore.pbutton_keyboard == 0)
00595        return ;
00596   
00597     if (event->type == GDK_BUTTON_PRESS){
00598        bev = (GdkEventButton *) event;
00599 
00600 
00601        KOLE_LOG (LOGDEST_STDOUT, "Virtual Keyboard button popup menu");
00602        gtk_menu_popup (GTK_MENU (palettecore.ppopup_keyboard),
00603                      NULL, NULL,
00604                      popup_positioner_keyboard, bev,
00605                      bev->button, bev->time);
00606        return True;
00607     }
00608   
00609 }
00610 
00611 static gint
00612 aux_palette_option_button_click_event_handler (GtkWidget *widget,
00613                                                  GdkEvent *event)
00614 {
00615     GdkEventButton *bev;
00616 
00617 
00618     DEBUG_printf("aux_palette_option_button_click_event_handler() is called\n");
00619     if (palettecore.pbutton_option == 0)
00620         return ;
00621 
00622     if (event->type == GDK_BUTTON_PRESS){
00623         bev = (GdkEventButton *) event;
00624 
00625         KOLE_LOG (LOGDEST_STDOUT, "Option button popup menu");
00626         gtk_menu_popup (GTK_MENU (palettecore.ppopup_option),
00627                         NULL, NULL,
00628                         popup_positioner_option, bev,
00629                         bev->button, bev->time);
00630         return True;
00631     }
00632 
00633 }
00634 
00635 
00636 
00637 static gboolean
00638 ui_toolbar_window_motion_cb (GtkWidget *window,
00639                              GdkEventMotion *event,
00640                              gpointer user_data)
00641 {
00642     gint pos_x, pos_y;
00643     guint state = GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK;
00644   
00645     if ((event->state & state) != 0 && _toolbar_window_draging) {
00646     
00647        gtk_window_get_position (GTK_WINDOW (window), &pos_x, &pos_y);
00648        aux_palette_position_set (
00649            pos_x + ((gint) event->x_root - _toolbar_window_drag_x),
00650            pos_y + ((gint) event->y_root - _toolbar_window_drag_y));
00651 
00652        _toolbar_window_drag_x = (gint) event->x_root;
00653        _toolbar_window_drag_y = (gint) event->y_root;
00654                                                                                                           
00655        return TRUE;
00656     }
00657     return FALSE;
00658 }
00659 
00660 static gboolean
00661 aux_palette_click_event_handler (GtkWidget *window,
00662                              GdkEventButton *event,
00663                              gpointer user_data)
00664 {
00665     int click_type = GPOINTER_TO_INT (user_data);
00666     static gulong motion_handler;
00667     GdkCursor *cursor;
00668     if (click_type == 0 && event->button <= 1) {
00669        if (_toolbar_window_draging)
00670            return FALSE;
00671        // Connection pointer motion handler to this window.
00672        motion_handler =
00673            g_signal_connect (G_OBJECT (window), "motion-notify-event",
00674                            G_CALLBACK (ui_toolbar_window_motion_cb),
00675                            NULL);
00676 
00677 
00678        _toolbar_window_draging = TRUE;
00679        _toolbar_window_drag_x = (gint) event->x_root;
00680        _toolbar_window_drag_y = (gint) event->y_root;
00681        cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW);
00682 
00683        // Grab the cursor to prevent losing events.
00684        gdk_pointer_grab (window->window, TRUE,
00685                        (GdkEventMask) (GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK),
00686                        NULL, cursor, event->time);
00687        gdk_cursor_unref (cursor);
00688        return TRUE;
00689     } else if (click_type == 1 && event->button <= 1) {
00690        if (!_toolbar_window_draging)
00691            return FALSE;
00692        g_signal_handler_disconnect (G_OBJECT (window), motion_handler);
00693        gdk_pointer_ungrab (event->time);
00694        _toolbar_window_draging = FALSE;
00695 
00696        return TRUE;
00697     } else if (click_type == 1 && event->button > 1) {
00698        return TRUE;
00699     }
00700     return FALSE;
00701 }
00702 
00703 
00704 
00705 static GdkPixbuf *
00706 scale_pixbuf (GdkPixbuf *pixbuf, int        width, int        height)
00707 {
00708     if (pixbuf) {
00709        if (gdk_pixbuf_get_width (pixbuf) != width ||
00710            gdk_pixbuf_get_height (pixbuf) != height) {
00711            GdkPixbuf *dest =
00712               gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
00713            gdk_pixbuf_unref (pixbuf);
00714            pixbuf = dest;
00715         
00716        }
00717     }
00718     return pixbuf;
00719 }
00720 
00721 static void
00722 aux_palette_setup_tooltips ()
00723 {
00724 
00725     palettecore.ptooltip = gtk_tooltips_new ();
00726     gtk_tooltips_set_delay (palettecore.ptooltip, 1000);
00727     gtk_tooltips_set_tip (palettecore.ptooltip,
00728                        palettecore.pbutton_input_mode,
00729                        _("다른 charset을 사용하도록 전환하려면 클릭하십시오"),
00730                        NULL);
00731     gtk_tooltips_set_tip (palettecore.ptooltip,
00732                        palettecore.pbutton_keyboard,
00733                        _("다른 키보드 배열을 사용하도록 전환하려면 클릭하십시오"),
00734                        NULL);
00735     gtk_tooltips_set_tip (palettecore.ptooltip,
00736                        palettecore.pbutton_option,
00737                        _("옵션 보조 창을 시작하려면 클릭하십시오"),
00738                        NULL);
00739 }
00740 
00741 static void
00742 aux_palette_set_inputmode (INPUT_MODE_T i_mode)
00743 {
00744     if (i_mode > INPUT_MODE_NONE && i_mode <= INPUT_MODE_SYMBOL){
00745        leproperty_set_input_mode (p_engine_property, i_mode);
00746     }else{
00747        leproperty_set_input_mode (p_engine_property, INPUT_MODE_NONE);
00748     }
00749   
00750     update_input_mode_button (p_engine_property);
00751 }
00752 
00753 static void
00754 aux_palette_redraw_self (gboolean visibility)
00755 {
00756     if (visibility){
00757        gtk_widget_show_all (palettecore.ppalette);
00758     } else {
00759        gtk_widget_hide (palettecore.ppalette);
00760         if(palettecore.vkb_window)
00761             gtk_widget_hide(palettecore.vkb_window->window);
00762     }
00763 }
00764 
00765 static void
00766 update_all_widgets (KOLE_property *prop)
00767 {
00768     update_input_mode_button (prop);
00769 }
00770 
00771 static void
00772 update_input_mode_button (KOLE_property *prop)
00773 {
00774     int i;
00775     /*assert (prop != NULL);*/
00776     if(prop == NULL)
00777        return;
00778     i = leproperty_get_charset (prop);
00779     gtk_button_set_label (GTK_BUTTON (palettecore.pbutton_input_mode), p_active_charsets[i]);
00780 }
00781 
00782 static void
00783 palette_core_data_init (PaletteInfo pinfo)
00784 {
00785     assert (pinfo != NULL);
00786     pinfo->ppalette = NULL;
00787     pinfo->pbutton_input_mode = NULL;
00788     pinfo->ppopup_input_mode = NULL;
00789     pinfo->pbutton_keyboard = NULL;
00790     pinfo->pbutton_option = NULL;
00791     pinfo->ptooltip = NULL;
00792     pinfo->about_dialog = NULL;
00793     pinfo->i_width = pinfo->i_height = 0;
00794 }
00795 
00796 void
00797 paletteaux_update_display (KOLE_property *pep)
00798 {
00799     update_all_widgets (pep);
00800 }
00801 
00802 void
00803 paletteaux_change_visibility (gboolean visibility)
00804 {
00805     if (visibility == FALSE){
00806        gtk_widget_hide (palettecore.ppalette);
00807        if(palettecore.vkb_window)
00808             gtk_widget_hide(palettecore.vkb_window->window);
00809     }  else {
00810        gtk_widget_show_all (palettecore.ppalette);
00811     }
00812 }
00813 
00814 static GtkWidget *
00815 ui_create_punct_icon (gboolean full_width_punct_status)
00816 {
00817     GtkWidget *image;
00818     const char **xpm;
00819 
00820     if (full_width_punct_status == TRUE)
00821        xpm = (const char **)fullwidth_xpm;
00822     else
00823        xpm = (const char **)halfwidth_xpm;
00824 
00825     image = create_gtk_image_from_xpm(xpm, -1, -1, 1);
00826     return(image);
00827 }
00828 
00829 static GtkWidget *
00830 ui_create_letter_icon(gboolean full_width_letter_status)
00831 {
00832     GtkWidget *image;
00833     const char **xpm;
00834 
00835     if (full_width_letter_status == TRUE)
00836        xpm = (const char **)ch_punct_xpm;
00837     else
00838        xpm = (const char **)en_punct_xpm;
00839 
00840     image = create_gtk_image_from_xpm(xpm, -1, -1, 1);
00841     return(image);
00842 }
00843 
00844 #if 0
00845 static void
00846 ui_toggle_punct(gboolean full_width_punct_status)
00847 {
00848     if (_full_width_punct_status == full_width_punct_status)
00849        return;
00850 
00851     _full_width_punct_status = full_width_punct_status;
00852 
00853     GtkWidget *image;
00854 
00855     image = gtk_bin_get_child (GTK_BIN (_full_width_punct_button));
00856     gtk_container_remove (GTK_CONTAINER (_full_width_punct_button), image);
00857 
00858     image = ui_create_punct_icon (_full_width_punct_status);
00859     gtk_container_add (GTK_CONTAINER (_full_width_punct_button), image);
00860 
00861     if (_toolbar_window_show_status)
00862        gtk_widget_show (_full_width_punct_button);
00863 }
00864 
00865 void
00866 ui_toggle_letter (gboolean full_width_letter_status)
00867 {
00868     GtkWidget *image;
00869     if (_full_width_letter_status == full_width_letter_status)
00870        return;
00871 
00872     _full_width_letter_status = full_width_letter_status;
00873 
00874 
00875     image = gtk_bin_get_child (GTK_BIN (_full_width_letter_button));
00876     gtk_container_remove (GTK_CONTAINER (_full_width_letter_button), image);
00877 
00878     image = ui_create_letter_icon (_full_width_letter_status);
00879     gtk_container_add (GTK_CONTAINER (_full_width_letter_button), image);
00880 
00881     if (_toolbar_window_show_status)
00882        gtk_widget_show (_full_width_letter_button);
00883 }
00884 #endif
00885 
00886 
00887 /********************************************************************/
00888 /*       vkb_layout functions                                       */
00889 /********************************************************************/
00890 gboolean palette_window_init_vkb_window()
00891 {
00892     char file_name[256];
00893 
00894     if (palettecore.vkb_window == NULL)
00895         palettecore.vkb_window = (vkb_window_t *)vkb_window_new();
00896 
00897     if (palettecore.vkb_window == NULL)
00898         return FALSE;
00899 
00900     if (palettecore.vkb_layout_list != NULL)
00901         return TRUE;
00902 
00903     sprintf(file_name, "%s%s", LE_AUX_MODULES_DIR, PALETTE_AUX_VKB_LAYOUT_FILE);
00904 
00905     palettecore.vkb_layout_list = (vkb_layout_t **)
00906         vkb_layout_list_read_from_layout_file(file_name);
00907 
00908     /*vkb_layout_list_print(palettecore.vkb_layout_list);*/
00909 
00910     if (palettecore.vkb_layout_list == NULL)
00911         return FALSE;
00912 
00913     palettecore.current_vkb_layout = palettecore.vkb_layout_list[0];
00914     return TRUE;
00915 }
00916 
00917 
00918 void palette_window_show_vkb_window_with_layout(vkb_layout_t *vkb_layout)
00919 {
00920     if (palettecore.vkb_window == NULL)
00921         return;
00922 
00923     if (vkb_layout == NULL) {
00924         palettecore.vkb_show_status = 0;
00925         vkb_window_update_layout(palettecore.vkb_window, NULL);
00926     } else {
00927         palettecore.vkb_show_status = 1;
00928         palettecore.current_vkb_layout = vkb_layout;
00929         vkb_window_update_layout(palettecore.vkb_window, vkb_layout);
00930     }
00931     return;
00932 }
00933 
00934 
00935 void palette_window_toggle_vkb_window()
00936 {
00937     vkb_layout_t *vkb_layout = NULL;
00938 
00939     palette_window_init_vkb_window();
00940 
00941     if (palettecore.vkb_show_status == 0) {
00942         /* need draw the current vkb layout */
00943         vkb_layout = palettecore.current_vkb_layout;
00944     }
00945 
00946     palette_window_show_vkb_window_with_layout(vkb_layout);
00947 }
00948 
00949 static void
00950 palette_window_destroy_ime_about_dialog(GtkDialog *dialog, int response_id, gpointer data)
00951 {
00952     gtk_widget_destroy ((GtkWidget *)dialog);
00953     
00954     palettecore.about_dialog = NULL;    
00955 }
00956 
00957 
00958 static void
00959 palette_window_start_ime_about_dialog()
00960 {
00961     GtkWidget *dialog;
00962     GtkWidget *hbox;
00963     GtkWidget *vbox;
00964     GtkWidget *stock;
00965     GtkWidget *label;
00966     char message[2048];
00967     char title[256];
00968 
00969 
00970     DEBUG_printf ("about_dialog: \n");
00971 
00972 
00973     dialog = gtk_dialog_new_with_buttons ("정보",
00974                                      NULL,
00975                                      GTK_DIALOG_DESTROY_WITH_PARENT,
00976                                      GTK_STOCK_OK,
00977                                      GTK_RESPONSE_NONE,
00978                                      NULL);
00979     gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
00980     gtk_widget_show(dialog);
00981 
00982     hbox = gtk_hbox_new (FALSE, 8);
00983     gtk_widget_show(hbox);
00984     gtk_container_set_border_width (GTK_CONTAINER (hbox), 8);
00985     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
00986   
00987     stock = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
00988     gtk_widget_show(stock);
00989     gtk_box_pack_start (GTK_BOX (hbox), stock, FALSE, FALSE, 0);
00990   
00991     vbox = gtk_vbox_new (FALSE, 0);
00992     gtk_widget_show(vbox);
00993     gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 8);
00994 
00995     sprintf(message, "\n\n%s    %s%d.%02d\n\n%s\n%s\n\n%s\n%s\n\n", 
00996                     ABOUT_IME_SUFFIX,
00997                     ABOUT_IME_VERSION,
00998                     120/100,
00999                     120%100,
01000                     ABOUT_IME_AUTHOR,
01001                     "Karl.park@sun.com, Gavin.tu@sun.com, Ervin.yan@sun.com",
01002                     ABOUT_IME_COPYRIGHT,
01003                     "Copyright (c) 2004 Sun Microsystems");
01004 
01005     label = gtk_label_new (message);
01006     gtk_widget_show(label);
01007     gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
01008 
01009     g_signal_connect(dialog,
01010                    "response",
01011                    G_CALLBACK(palette_window_destroy_ime_about_dialog),
01012                    palettecore.ppalette);
01013     
01014     gtk_widget_show (dialog);
01015    palettecore.about_dialog = dialog;     
01016 }
01017 
01018 
01019 
01020 void
01021 palette_window_signal_child_handler(int sig, siginfo_t * info, void *ucontext)
01022 {
01023     pid_t pid;
01024     int status;
01025 
01026     while ((pid = waitpid(info->si_pid, &status, WNOHANG | WUNTRACED)) > 0) {
01027         printf("pid %d: die\n", pid);
01028     }
01029 }
01030 
01031 
01032 void palette_window_register_signal_child_handler()
01033 {
01034     struct sigaction act;
01035 
01036     act.sa_handler = NULL;
01037     act.sa_sigaction = palette_window_signal_child_handler;
01038     sigfillset(&act.sa_mask);
01039     act.sa_flags = SA_SIGINFO;
01040 
01041     sigaction(SIGCHLD, &act, NULL);
01042 }
01043 
01044 
01045 static void palette_window_start_command(char *command_str)
01046 {
01047     int pid;
01048 
01049     if (command_str == NULL)
01050         return;
01051 
01052     palette_window_register_signal_child_handler();
01053 
01054     pid = fork();
01055     if (pid < 0) {
01056         return;
01057     } else if (pid == 0) {
01058         /* in child process */
01059         execl("/bin/sh", "sh", "-c", command_str, (char *) 0);
01060 
01061         /* Exec failed. */
01062         fprintf(stderr, "Error: Could not exec %s!\n", command_str);
01063         _exit(1);
01064     }
01065     return;
01066 }