Back to index

im-sdk  12.3.91
PaletteAux.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include <locale.h>
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <limits.h>
00046 
00047 #include <Xm/XmAll.h>
00048 #include <Xm/MwmUtil.h>
00049 
00050 #include "trace_message.h"
00051 
00052 #include "xaux_common.h"
00053 #include "xaux_ext_common.h"
00054 
00055 #include "sampleja3_xaux.h"
00056 
00057 /* Definer Aux class */
00058 xaux_class_t xaux_class = {
00059     "com.sun.sampleja3.PaletteAux", 1,
00060     (Window) 0, (Window) 0,
00061     (Atom) 0, (Atom) 0, (Atom) 0, (Atom) 0, (Atom) 0,
00062     NULL,
00063 };
00064 
00065 Widget toplevel;
00066 Widget aux;
00067 Widget button_text;
00068 
00069 static xaux_class_t *xc_ = 0;
00070 static int im_ = 0;
00071 static int ic_ = 0;
00072 
00073 void xt_ext_event_handler(Widget, XtPointer, XEvent *, Boolean * b);
00074 
00075 /* Event Handler */
00076 void
00077 xt_ext_event_handler(
00078                    Widget w,
00079                    XtPointer client_data,
00080                    XEvent * event,
00081                    Boolean * b)
00082 {
00083 
00084     switch (event->type) {
00085        case ClientMessage:
00086        xaux_ext_process_client_message(XtDisplay(w),
00087                                  (XClientMessageEvent *) event);
00088        break;
00089     default:
00090        break;
00091     }
00092 
00093     return;
00094 }
00095 
00096 /* Method - Start */
00097 Bool
00098 xaux_ext_Start(
00099               xaux_class_t * xc,
00100               aux_ext_data_t * aux_ext_data)
00101 {
00102     return True;
00103 }
00104 
00105 /* Method - Draw */
00106 Bool
00107 xaux_ext_Draw(
00108              xaux_class_t * xc,
00109              aux_ext_data_t * aux_ext_data)
00110 {
00111     size_t i;
00112     char *sp;
00113     Bool rv = True;
00114     char buf[256];
00115 
00116     strncpy(buf, (const char *) aux_ext_data->aux_name,
00117            aux_ext_data->aux_name_length);
00118 
00119     printf("ext_Draw[%s] im:0x%x, ic:0x%x\n",
00120           buf, aux_ext_data->im, aux_ext_data->ic);
00121 
00122 
00123     for (i = 0; i < aux_ext_data->integer_count; i++) {
00124        printf("\tiv[%02d]=%d\n", i, aux_ext_data->integer_list[i]);
00125     }
00126 
00127     for (i = 0; i < aux_ext_data->string_count; i++) {
00128        printf("\tsv[%02d]=%s\n", i,
00129               aux_ext_data->string_list[i].ptr);
00130     }
00131 
00132     im_ = aux_ext_data->im;
00133     ic_ = aux_ext_data->ic;
00134     xc_ = xc;
00135 
00136     if (aux_ext_data->integer_count == 1) {
00137        switch (aux_ext_data->integer_list[0]) {
00138        case SAMPLEJA3_AUXPALETTE_CONVON:
00139            XtVaSetValues(button_text,
00140                        XtVaTypedArg, XmNlabelString,
00141            XmRString, "conversion ON", strlen("conversion ON") + 1,
00142                        NULL);
00143            break;
00144        case SAMPLEJA3_AUXPALETTE_CONVOFF:
00145            XtVaSetValues(button_text,
00146                        XtVaTypedArg, XmNlabelString,
00147                        XmRString, "conversion OFF", strlen("conversion OFF") + 1,
00148                        NULL);
00149            break;
00150        }
00151     }
00152     return True;
00153 }
00154 
00155 /* Method - Done */
00156 Bool
00157 xaux_ext_Done(
00158              xaux_class_t * xc,
00159              aux_ext_data_t * aux_ext_data)
00160 {
00161     int i;
00162     char buf[256];
00163 
00164     strncpy(buf, (const char *) aux_ext_data->aux_name,
00165            aux_ext_data->aux_name_length);
00166 
00167     printf("ext_Done[%s] im:0x%x, ic_id:0x%x\n",
00168           buf, aux_ext_data->im, aux_ext_data->ic);
00169 
00170     return True;
00171 }
00172 
00173 void
00174 ButtonCallback(Widget w, XtPointer client_data, XtPointer call_data)
00175 {
00176     int integers[5];
00177     char *strings[5];
00178 
00179     integers[0] = 1;
00180     integers[1] = 2;
00181     integers[2] = 3;
00182     integers[3] = 4;
00183     strings[0] = "test_string1";
00184     strings[1] = "test_string2";
00185     strings[2] = "test_string3";
00186     strings[3] = "test_string4";
00187     ReturnToEngine(4, integers, 4, strings);
00188 
00189 HelpInvoke("a.html");
00190 
00191     return;
00192 }
00193 
00194 int
00195 main(int argc, char **argv)
00196 {
00197     XtAppContext app;
00198     Display *display;
00199     int narg;
00200     Arg args[10];
00201 Widget textfield;
00202 
00203     TRACE_MESSAGE_INIT("TRACE_AUX_EXT");
00204 
00205     setlocale(LC_ALL, NULL);
00206     XtSetLanguageProc(NULL, NULL, NULL);
00207 
00208     narg = 0;
00209     XtSetArg(args[narg], XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_RESIZE); narg++;
00210     XtSetArg(args[narg], XmNx, 10); narg++;
00211     XtSetArg(args[narg], XmNy, 10); narg++;
00212     XtSetArg(args[narg], XmNtitle, "Motif Palette"); narg++;
00213 
00214 
00215     toplevel = XtAppInitialize(&app, "aux", NULL, 0,
00216                             &argc, argv, NULL, args, narg);
00217 
00218     display = XtDisplay(toplevel);
00219 
00220     aux = XtVaCreateManagedWidget("aux", xmRowColumnWidgetClass,
00221                               toplevel, NULL, 0);
00222 
00223     button_text = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
00224                                    aux, NULL, 0);
00225     XtVaSetValues(button_text,
00226                 XtVaTypedArg, XmNlabelString,
00227                  XmRString, "Test", strlen("Test") + 1,
00228                 NULL);
00229 
00230     XtAddCallback(button_text, XmNarmCallback, ButtonCallback, NULL);
00231 
00232        narg = 0;
00233         XtSetArg(args[narg], XmNcolumns, 30);  ++narg;
00234 
00235     textfield = XmCreateTextField(aux, "textfield", args, narg);
00236        XtManageChild(textfield);
00237 
00238     XtRealizeWidget(toplevel);
00239 
00240     /* Register aux class */
00241     if (xaux_ext_init_classes(XtDisplay(toplevel),
00242                      &xaux_class, XtWindow(toplevel)) == False) {
00243        return 2;
00244     }
00245 
00246     /* Register event handler */
00247     XtAddEventHandler(toplevel, PropertyChangeMask, False,
00248                     xt_ext_event_handler, NULL);
00249 
00250     XtAddEventHandler(toplevel, NoEventMask, True,
00251                     xt_ext_event_handler, NULL);
00252 
00253     XtAppMainLoop(app);
00254 
00255     return 0;
00256 }
00257 
00258 ReturnToEngine(
00259               int integer_count,
00260               int *integers,
00261               int string_count,
00262               char **strings
00263 )
00264 {
00265     int i;
00266 
00267     aux_ext_data_t *aux_data;
00268 
00269     if (!im_ || !ic_ || !xc_)
00270        return;
00271 
00272     if (!integer_count && !string_count)
00273        return;
00274 
00275     aux_data = (aux_ext_data_t *) calloc(1, sizeof(aux_ext_data_t));
00276 
00277     aux_data->im = im_;
00278     aux_data->ic = ic_;
00279     aux_data->integer_count = integer_count;
00280     aux_data->string_count = string_count;
00281 
00282     if (aux_data->integer_count) {
00283        aux_data->integer_list = (int *) calloc(1, sizeof(int) * aux_data->integer_count);
00284        for (i = 0; i < aux_data->integer_count; i++) {
00285            aux_data->integer_list[i] = integers[i];
00286        }
00287     }
00288     if (aux_data->string_count) {
00289        aux_data->string_list = (aux_ext_string_t *) calloc(1,
00290                sizeof(aux_ext_string_t) * aux_data->string_count);
00291        for (i = 0; i < aux_data->string_count; i++) {
00292            aux_ext_string_t *p = &aux_data->string_list[i];
00293            p->length = strlen(strings[i]);
00294            p->ptr = (unsigned char *) strdup(strings[i]);
00295        }
00296     }
00297     xaux_ext_SetValue(XtDisplay(toplevel), xc_, aux_data);
00298 
00299     if (aux_data->integer_list)
00300        free(aux_data->integer_list);
00301     if (aux_data->string_list) {
00302        for (i = 0; i < aux_data->string_count; i++) {
00303            aux_ext_string_t *p = &aux_data->string_list[i];
00304            if (p && p->ptr)
00305               free(p->ptr);
00306        }
00307        free(aux_data->string_list);
00308     }
00309     free(aux_data);
00310 }