Back to index

im-sdk  12.3.91
common_aux_methods.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <X11/Xmd.h>
00003 #include <X11/Xlib.h>
00004 #include <gdk/gdkx.h>
00005 #include <gtk/gtk.h>
00006 
00007 #include "xaux_common.h"
00008 #include "xaux_ext_common.h"
00009 #include "le_aux_protocol.h"
00010 
00011 #include "common_aux_methods.h"
00012 
00013 /* Define Aux class */
00014 xaux_class_t *xc_ = 0;
00015 int im_ = 0;
00016 int ic_ = 0;
00017 
00018 #define ATOM_NUM_COMPOSITEAUX   32
00019 
00020 /* Define Aux class */
00021 xaux_class_t xaux_class = {
00022     COMPOSITE_AUX_CLASS_NAME, 1,
00023     NULL,
00024     (Window) 0, (Window) 0, (Window) 0,
00025     (Atom) 0, (Atom) 0, (Atom) 0, (Atom) 0,
00026     {(Atom) 0}, ATOM_NUM_COMPOSITEAUX, 0,
00027     {(Atom) 0}, ATOM_NUM_COMPOSITEAUX, 0,
00028     NULL,
00029 };
00030 
00031 int gLocaleID = 0;
00032 Display *gDisplay = NULL;
00033 Window gWindow = 0;
00034 
00035 
00036 /*
00037         Event Handler
00038 */
00039 GdkFilterReturn xaux_ext_event_handler(GdkXEvent * gdk_xevent,
00040                                        GdkEvent * event,
00041                                        gpointer user_data)
00042 {
00043     XEvent *xevent = (XEvent *) gdk_xevent;
00044 
00045     switch (xevent->type) {
00046     case ClientMessage:
00047         xaux_ext_process_client_message((Display *) gDisplay,
00048                                         (XClientMessageEvent *) xevent);
00049         break;
00050     case SelectionClear:
00051         break;
00052     }
00053     return GDK_FILTER_CONTINUE;
00054 }
00055 
00056 /*
00057         xaux_ext_init_classes(): Initialize the Atom of Auxiliary Window.
00058         It is in ../xaux_common/xaux_ext_common.c
00059 */
00060 int xaux_ext_register_classes(GdkWindow * window)
00061 {
00062     char *locale;
00063 
00064     gDisplay = (Display *) GDK_WINDOW_XDISPLAY(window);
00065     gWindow = (Window) GDK_WINDOW_XWINDOW(window);
00066 
00067     /* Register aux class */
00068     if (xaux_ext_init_classes(gDisplay, (xaux_class_t *) & xaux_class, gWindow) == False)
00069         return (False);
00070 
00071     return (True);
00072 }
00073 
00074 /*
00075 Note:
00076      xaux_ext_Start(), xaux_ext_Draw(), xaux_ext_Done()
00077      These three functions are all called by xaux_ext_process_client_message()
00078 
00079      xaux_ext_SetValue() will send auxiliary window information to language engine;
00080 */
00081 
00082 /* Method - Start */
00083 Bool xaux_ext_Start(xaux_class_t * xc, aux_ext_data_t * aux_ext_data,
00084                     Atom atom)
00085 {
00086     DEBUG_printf("ext_Start: im:%d, ic:%d\n", aux_ext_data->im,
00087                  aux_ext_data->ic);
00088     im_ = aux_ext_data->im;
00089     ic_ = aux_ext_data->ic;
00090     xc_ = xc;
00091 
00092     /* inform Language Engine that PaletteAux has started. */
00093 
00094     return True;
00095 }
00096 
00097 /* Method - Draw */
00098 Bool xaux_ext_Draw(xaux_class_t * xc, aux_ext_data_t * aux_ext_data,
00099                    Atom atom)
00100 {
00101     DEBUG_printf("ext_Draw == im:0x%x, ic:0x%x\n", aux_ext_data->im,
00102                  aux_ext_data->ic);
00103     im_ = aux_ext_data->im;
00104     ic_ = aux_ext_data->ic;
00105     xc_ = xc;
00106 
00107     composite_aux_Proc_LE_Notify(aux_ext_data);
00108     return True;
00109 }
00110 
00111 /* Method - Done */
00112 Bool xaux_ext_Done(xaux_class_t * xc, aux_ext_data_t * aux_ext_data,
00113                    Atom atom)
00114 {
00115     DEBUG_printf("ext_Done im:0x%x, ic_id:0x%x\n", aux_ext_data->im,
00116                  aux_ext_data->ic);
00117     return True;
00118 }
00119 
00120 void composite_aux_Set_Selection_Owner()
00121 {
00122     Atom aux_atom =
00123         XInternAtom(gDisplay, "CH_PROPERTIES_MODULE_ATOM", False);
00124 
00125     XSetSelectionOwner(gDisplay, aux_atom, gWindow, CurrentTime);
00126 }
00127 
00128 void composite_aux_get_cursor_rect(aux_ext_data_t *aux_ext_data, int *pos_x, int *pos_y, int *caret_w, int* caret_h)
00129 {
00130     int win_x = 0, win_y = 0;
00131 
00132     Window w_none;
00133     Window clientwindow;
00134     XWindowAttributes attr;
00135 
00136     clientwindow = aux_ext_data->clientwin;
00137     if (clientwindow && gDisplay) {
00138         XGetWindowAttributes(gDisplay, clientwindow, &attr);
00139         if (attr.root)
00140             XTranslateCoordinates(gDisplay, clientwindow, attr.root, -(attr.border_width), -(attr.border_width), &win_x, &win_y, &w_none );
00141     }
00142 
00143     /*
00144     if ((win_x == 0 && win_y == 0) || (aux_ext_data->point.x == 0 && aux_ext_data->point.y == 0)) {
00145         win_x =  (gdk_screen_width () > 640)?200:100;
00146         win_y = (gdk_screen_height () - 200);
00147     } else {
00148     */
00149         win_x += aux_ext_data->point.x;
00150         win_y += aux_ext_data->point.y;
00151     //}
00152 
00153     *pos_x = win_x;
00154     *pos_y = win_y-20;
00155     *caret_w = 1;
00156     *caret_h = 25;
00157 }
00158 
00159 void composite_aux_get_cursor_position(aux_ext_data_t *aux_ext_data, int *pos_x, int *pos_y)
00160 {
00161     int win_x = 0, win_y = 0;
00162 
00163     Window w_none;
00164     Window clientwindow;
00165     XWindowAttributes attr;
00166 
00167     clientwindow = aux_ext_data->clientwin;
00168     if (clientwindow && gDisplay) {
00169         XGetWindowAttributes(gDisplay, clientwindow, &attr);
00170         if (attr.root)
00171             XTranslateCoordinates(gDisplay, clientwindow, attr.root, -(attr.border_width), -(attr.border_width), &win_x, &win_y, &w_none );
00172     }
00173 
00174     /*
00175     if ((win_x == 0 && win_y == 0) || (aux_ext_data->point.x == 0 && aux_ext_data->point.y == 0)) {
00176         win_x =  (gdk_screen_width () > 640)?200:100;
00177         win_y = (gdk_screen_height () - 200);
00178     } else {
00179     */
00180         win_x += aux_ext_data->point.x;
00181         win_y += aux_ext_data->point.y + 22;
00182     //}
00183 
00184     *pos_x = win_x;
00185     *pos_y = win_y;
00186 }
00187 
00188 /* ================================================================= */
00189 /*             Send information to Language Engine                   */
00190 /* ================================================================= */
00191 void composite_aux_Connect_To_LE_Request(int locale_id)
00192 {
00193     int nIntegerCount, pIntegerList[2];
00194 
00195     nIntegerCount = 2;
00196     pIntegerList[0] = SELECTAUX_CONNECT;
00197     pIntegerList[1] = locale_id;
00198     NotifyIntegerListDataToLanguageEngine(gDisplay, nIntegerCount,
00199                                           pIntegerList);
00200 }
00201 
00202 NotifyIntegerListDataToLanguageEngine(Display * display,
00203                                       int nIntegerCount, int *pIntegerList)
00204 {
00205     aux_ext_data_t aux_ext_data;
00206 
00207     aux_ext_data.im = im_;
00208     aux_ext_data.ic = ic_;
00209     aux_ext_data.integer_count = nIntegerCount;
00210     aux_ext_data.integer_list = pIntegerList;
00211     aux_ext_data.string_count = 0;
00212     aux_ext_data.string_list = NULL;
00213     aux_ext_data.string_ptr = NULL;
00214     aux_ext_data.point.x = 0;
00215     aux_ext_data.point.y = 0;
00216 
00217     xaux_ext_SetValue(display, xc_, &aux_ext_data);
00218     XFlush(display);
00219 }
00220 
00221 NotifyStringListDataToLanguageEngine(Display * display,
00222                                      int nIntegerCount, int *pIntegerList,
00223                                      int nStringCount, int *pStringLen,
00224                                      char **pStringList)
00225 {
00226     int i;
00227 
00228     aux_ext_data_t aux_ext_data;
00229     aux_ext_string_t *p;
00230 
00231     aux_ext_data.im = im_;
00232     aux_ext_data.ic = ic_;
00233     aux_ext_data.integer_count = nIntegerCount;
00234     aux_ext_data.integer_list = pIntegerList;
00235     aux_ext_data.point.x = 0;
00236     aux_ext_data.point.y = 0;
00237 
00238     aux_ext_data.string_count = nStringCount;
00239     aux_ext_data.string_ptr = NULL;
00240 
00241     if (nStringCount > 0) {
00242         aux_ext_data.string_list =
00243             (aux_ext_string_t *) calloc(nStringCount,
00244                                         sizeof(aux_ext_string_t));
00245         for (i = 0; i < nStringCount; i++) {
00246             aux_ext_string_t *p = &aux_ext_data.string_list[i];
00247             p->length = pStringLen[i];
00248             p->ptr = (unsigned char *) (pStringList[i]);
00249         }
00250     }
00251 
00252     xaux_ext_SetValue(display, xc_, &aux_ext_data);
00253     XFlush(display);
00254 
00255     free(aux_ext_data.string_list);
00256 }