00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <signal.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011
00012 #include "sci_mem_alloc.h"
00013 #include "GetProperty.h"
00014 #include "DestroyObjects.h"
00015 #include "SGraph.h"
00016 #include "xs2file.h"
00017 #include "Xcall1.h"
00018 #include "WindowList.h"
00019 #include "Actions.h"
00020 #include "periWin.h"
00021 extern int StoreCommand __PARAMS((char *command));
00022
00023
00025 #ifdef __STDC__
00026 #include <sys/types.h>
00027 #include <unistd.h>
00028 #else
00029 extern char * getenv();
00030 extern int getpid();
00031 #endif
00032
00033 #include "math.h"
00034 #include "men_Sutils.h"
00035 #include "men_scilab.h"
00036 #include "All-extern.h"
00037 #include "All-extern-x1.h"
00038 #include "Events.h"
00039
00040 extern XtAppContext app_con;
00041
00042
00043 extern Widget initColors __PARAMS((Widget));
00044 extern Window GetBGWindowNumber __PARAMS((int));
00045 extern void DisplayInit __PARAMS((char *string,Display **dpy,Widget *toplevel));
00046 extern void ChangeBandF __PARAMS((int win_num,Pixel fg, Pixel bg));
00047 extern integer F2C(fbutn) __PARAMS((char *,integer*,integer*));
00048 extern void DeleteObjs __PARAMS((int win_num));
00049 extern int demo_menu_activate;
00050 extern int GetEventWindow(XEvent* event);
00051
00052
00053
00054 static void ChangeBF1 __PARAMS(( Widget w, char *str, Pixel fg, Pixel bg));
00055 static void SetHints __PARAMS((Widget topW));
00056 static int AddNewWin __PARAMS((int, struct BCG *));
00057
00058 static XtEventHandler EventProc1 __PARAMS((Widget widget, XtPointer , XEvent *));
00059
00060
00061 static void Efface __PARAMS((Widget, XtPointer , XtPointer ));
00062 static void Select __PARAMS((Widget, XtPointer , XtPointer ));
00063 static void Delete __PARAMS((Widget, XtPointer , XtPointer ));
00064 static void Print __PARAMS((Widget, XtPointer , XtPointer ));
00065 static void SavePs __PARAMS((Widget, XtPointer , XtPointer ));
00066 static void Save __PARAMS((Widget, XtPointer , XtPointer ));
00067 static void Load __PARAMS((Widget, XtPointer , XtPointer ));
00068 static void Zoom __PARAMS((Widget, XtPointer , XtPointer ));
00069 static void UnZoom __PARAMS((Widget, XtPointer , XtPointer ));
00070 static void Rot3D __PARAMS((Widget, XtPointer , XtPointer ));
00071 static void ChangeBF1 __PARAMS((Widget, char *str, Pixel fg, Pixel bg));
00072 static void KillButton __PARAMS((Widget, XtPointer , caddr_t ));
00073 static void SelMenu __PARAMS((Widget, XtPointer , caddr_t));
00074 static void SetUnsetMenu __PARAMS((integer *, char *, integer *, int));
00075 static void PannerCallback __PARAMS((Widget, XtPointer , XtPointer ));
00076 static void ViewportCallback __PARAMS((Widget, XtPointer , XtPointer ));
00077 static void MoveChild __PARAMS((Widget viewp, Position x,Position y));
00078 static int GetChilds __PARAMS((int win_num, int *nc,WidgetList *wL,Widget *outer,char *name,
00079 int *name_pos) );
00080 static void ignore_events( Widget widget, XEvent *event2,long mask );
00081
00082
00083 static char popupname[sizeof("ScilabGraphic")+32];
00084 static Arg args[10] ;
00085 static int iargs=0;
00086 static int MultiClickTime=200;
00087
00088
00089
00090
00091 static Atom wmDeleteWindow;
00092 static Atom Close_SG_Window_Activated ;
00093
00094 static void SetHints(topW)
00095 Widget topW;
00096 {
00097 XSizeHints size_hints;
00098 size_hints.width = 600;
00099 size_hints.height = 400;
00100 size_hints.min_width = 400;
00101 size_hints.min_height = 300;
00102 size_hints.flags = USSize | PMinSize;
00103 XSetNormalHints(XtDisplay(topW),XtWindow(topW), &size_hints);
00104
00105
00106
00107
00108 wmDeleteWindow = XInternAtom(XtDisplay(topW), "WM_DELETE_WINDOW", False);
00109 XSetWMProtocols(XtDisplay(topW),XtWindow(topW),&wmDeleteWindow, 1);
00111 Close_SG_Window_Activated = XInternAtom(XtDisplay(topW),
00112 "SCI_DELETE_WINDOW", False);
00113 }
00114
00117 int IswmDeleteWindow(XEvent *event)
00118 {
00119 return event->type == ClientMessage &&
00120 event->xclient.data.l[0] == (int)wmDeleteWindow ;
00121 }
00122
00126 int IsCloseSGWindow(XEvent *event)
00127 {
00128 if ( event->type == ClientMessage &&
00129 ((XClientMessageEvent *)event)->message_type == Close_SG_Window_Activated )
00130 return event->xclient.data.l[0];
00131 else
00132 return -1;
00133 }
00134
00135
00136
00137
00138
00139 static Bool wait_dclick = FALSE;
00140 static Bool dclick = FALSE;
00141 static Bool lose_up = FALSE;
00142 static long timerId;
00143 static void
00144 reset_click_counter (XtPointer ptr)
00145 {
00146 dclick = FALSE;
00147 wait_dclick = FALSE;
00148 }
00149
00150
00151 void
00152 btn_pressed(Widget widget, XEvent* event, String* params, Cardinal* num_params)
00153 {
00154
00155
00156
00157
00158
00159
00160 if (wait_dclick) {
00161
00162
00163 wait_dclick = FALSE;
00164 dclick = TRUE;
00165 lose_up = FALSE;
00166 XtRemoveTimeOut (timerId);
00167 return;
00168 }
00169 timerId = XtAppAddTimeOut(app_con, MultiClickTime,
00170 (XtTimerCallbackProc) reset_click_counter, (XtPointer) NULL);
00171 wait_dclick = TRUE;
00172 lose_up = FALSE;
00173 dclick = FALSE;
00174
00175
00176
00177
00178
00179 do {
00180 if (XtAppPending (app_con))
00181 XtAppProcessEvent (app_con, XtIMAll);
00182 } while (wait_dclick);
00183
00184
00185
00186 if (dclick ) {
00187 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00188 event->xbutton.y,
00189 event->xbutton.button-1+10,0,0);
00190 }
00191 else {
00192 if (lose_up) {
00193 if (params[0][0]=='0')
00194 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00195 event->xbutton.y,
00196 event->xbutton.button-1+3,0,0);
00197 else if (params[0][0]=='1')
00198 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00199 event->xbutton.y,
00200 event->xbutton.button-1+3+2000,0,0);
00201 else if (params[0][0]=='2')
00202 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00203 event->xbutton.y,
00204 event->xbutton.button-1+3+1000,0,0);
00205
00206 lose_up = FALSE;
00207
00208 }
00209 else {
00210 if (params[0][0]=='0')
00211 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00212 event->xbutton.y,
00213 event->xbutton.button-1,0,0);
00214 else if (params[0][0]=='1')
00215 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00216 event->xbutton.y,
00217 event->xbutton.button-1+2000,0,0);
00218 else if (params[0][0]=='2')
00219 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00220 event->xbutton.y,
00221 event->xbutton.button-1+1000,0,0);
00222
00223 }
00224
00225 }
00226
00227
00228
00229 }
00230
00231 void
00232 btn_released(Widget widget, XEvent* event,String* params, Cardinal* num_params)
00233 {
00234 if (wait_dclick) {
00235 lose_up = TRUE;
00236 return;
00237 }
00238 if (dclick) return;
00239
00240 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00241 event->xbutton.y,
00242 event->xbutton.button-6,0,1);
00243 }
00244
00245 void
00246 ctrl_key(Widget widget, XEvent* event, String* params, Cardinal* num_params)
00247 {
00248 char buf[10];
00249 int ten=10;
00250 KeySym keysym;
00251 XComposeStatus compose_status = {NULL, 0};
00252 XLookupString((XKeyEvent *)&(event->xkey), buf,
00253 ten, &keysym,&compose_status);
00254
00255 PushClickQueue(GetEventWindow(event),event->xkey.x,
00256 event->xkey.y,(int)keysym+1000,0,0);
00257 }
00258
00259 void
00260 key_pressed(Widget widget, XEvent* event, String* params, Cardinal* num_params)
00261 {
00262 char buf[10];
00263 int ten=10;
00264 KeySym keysym;
00265 XComposeStatus compose_status = {NULL, 0};
00266 XLookupString((XKeyEvent *)&(event->xkey), buf,
00267 ten, &keysym,&compose_status);
00268 if ((int)keysym < XK_Shift_L ||(int)keysym ==XK_Delete ){
00269
00270 PushClickQueue(GetEventWindow(event),event->xkey.x,
00271 event->xkey.y,(int)keysym,0,0);
00272 }
00273 }
00274 void
00275 key_released(Widget widget,XEvent* event, String* params, Cardinal* num_params)
00276 {
00277 char buf[10];
00278 int ten=10;
00279 KeySym keysym;
00280 XComposeStatus compose_status = {NULL, 0};
00281 XLookupString((XKeyEvent *)&(event->xkey), buf,
00282 ten, &keysym,&compose_status);
00283 if ((int)keysym <65000) {
00284
00285 PushClickQueue(GetEventWindow(event),event->xkey.x,
00286 event->xkey.y,-(int)keysym,0,1);
00287 }
00288 }
00289 void
00290 mouse_moved(Widget widget, XEvent* event, String* params, Cardinal* num_params)
00291 {
00292
00293 if (wait_dclick) {
00294 wait_dclick=FALSE;
00295 XtRemoveTimeOut (timerId);
00296 return;
00297 }
00298 PushClickQueue(GetEventWindow(event),event->xbutton.x,
00299 event->xbutton.y,
00300 -1,1,0);
00301 }
00302
00303
00304
00305
00306
00307
00308 static XtActionsRec event_actions[] =
00309 {
00310 {"BtnPressed", (XtActionProc) btn_pressed},
00311 {"BtnReleased", (XtActionProc) btn_released},
00312 {"CtrlKey", (XtActionProc) ctrl_key},
00313 {"KeyPressed", (XtActionProc) key_pressed},
00314 {"KeyReleased", (XtActionProc) key_released},
00315 {"MouseMoved", (XtActionProc) mouse_moved},
00316 };
00317
00318 static String event_translations =
00319 "\
00320 <MouseMoved>:MouseMoved()\n\
00321 Ctrl<Key>:CtrlKey()\n\
00322 !Shift<KeyDown>:KeyPressed(1)\n\
00323 !Lock<KeyDown>:KeyPressed(1)\n\
00324 !Lock Shift <KeyDown>:KeyPressed(0)\n\
00325 None<KeyDown>:KeyPressed(0)\n\
00326 !Shift<KeyUp>:KeyReleased(1)\n\
00327 !Lock<KeyUp>:KeyReleased(1)\n\
00328 !Lock Shift<KeyUp>:KeyReleased(1)\n\
00329 None<KeyUp>:KeyReleased(0)\n\
00330 <BtnUp>:BtnReleased()\n\
00331 !Shift<BtnDown>:BtnPressed(1)\n\
00332 !Ctrl<BtnDown>:BtnPressed(2)\n\
00333 <BtnDown>:BtnPressed(0)\n\
00334 ";
00335
00336
00337
00338 #define DEFAULT_MES "graphic window"
00339
00340 static int AddNewWin( int popupc, struct BCG *ScilabXgc)
00341 {
00342 Widget bbox,color;
00343 Widget outer,zoom_,rot3d,unzoom_,sel,menuform;
00344 Widget filebutton,filemenu,clear,prnt,save,load,delete,saveps;
00345
00346 iargs=0;
00347
00348 color = initColors(ScilabXgc->popup);
00349 outer = XtCreateManagedWidget( "scigForm", panedWidgetClass,
00350 color,
00351 args, iargs);
00352
00354 iargs = 0;
00355 menuform = XtCreateManagedWidget( "scigmForm", formWidgetClass,outer,
00356 args, iargs);
00357
00358 ScilabXgc->Panner = XtCreateManagedWidget("Panner", pannerWidgetClass,
00359 menuform , NULL, ZERO);
00360
00361 iargs=0;
00362 XtSetArg(args[iargs], XtNlabel," ");iargs++;
00363 ScilabXgc->CinfoW = XtCreateManagedWidget("scigraphicinfo",labelWidgetClass,
00364 menuform, args, iargs);
00365
00367
00368 iargs=0;
00369 filebutton = XtCreateManagedWidget("File",
00370 menuButtonWidgetClass,menuform,args, iargs);
00371 iargs=0;
00372 filemenu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
00373 filebutton,args, iargs);
00374 iargs=0;
00375 clear = XtCreateManagedWidget("Clear", smeBSBObjectClass,filemenu,args, iargs);
00376 XtAddCallback(clear, XtNcallback,(XtCallbackProc) Efface,(XtPointer) popupc);
00377 sel = XtCreateManagedWidget("Select", smeBSBObjectClass,filemenu,args, iargs);
00378 XtAddCallback(sel, XtNcallback,(XtCallbackProc) Select,(XtPointer) popupc);
00379 prnt = XtCreateManagedWidget("Print", smeBSBObjectClass,filemenu,args, iargs);
00380 XtAddCallback(prnt, XtNcallback,(XtCallbackProc) Print,(XtPointer) popupc);
00381 saveps = XtCreateManagedWidget("Export", smeBSBObjectClass,filemenu,args, iargs);
00382 XtAddCallback(saveps, XtNcallback,(XtCallbackProc) SavePs,(XtPointer)popupc);
00383 save = XtCreateManagedWidget("Save", smeBSBObjectClass,filemenu,args, iargs);
00384 XtAddCallback(save, XtNcallback,(XtCallbackProc) Save,(XtPointer)popupc);
00385 load = XtCreateManagedWidget("Load", smeBSBObjectClass,filemenu,args, iargs);
00386 XtAddCallback(load, XtNcallback,(XtCallbackProc) Load,(XtPointer)popupc);
00387 delete = XtCreateManagedWidget("Close", smeBSBObjectClass,filemenu,args, iargs);
00388 XtAddCallback(delete, XtNcallback,(XtCallbackProc) Delete,(XtPointer)popupc);
00389
00390
00391 zoom_ = XtCreateManagedWidget("Zoom", commandWidgetClass,menuform,args, iargs);
00392 XtAddCallback(zoom_, XtNcallback,(XtCallbackProc) Zoom,
00393 (XtPointer) popupc);
00394 unzoom_ = XtCreateManagedWidget("UnZoom", commandWidgetClass,menuform,args, iargs);
00395 XtAddCallback(unzoom_, XtNcallback,(XtCallbackProc) UnZoom,
00396 (XtPointer) popupc);
00397 rot3d = XtCreateManagedWidget("Rot3D", commandWidgetClass,menuform,args, iargs);
00398 XtAddCallback(rot3d, XtNcallback,(XtCallbackProc) Rot3D,
00399 (XtPointer) popupc);
00400
00403 iargs =0;
00404
00405 ScilabXgc->Viewport = XtCreateManagedWidget("graphicviewport",viewportWidgetClass,outer,args,iargs);
00406
00407 bbox= XtCreateManagedWidget("bbox",boxWidgetClass,ScilabXgc->Viewport, args, iargs);
00408
00409
00410 iargs=0;
00411 XtSetArg(args[iargs], XtNlabel," ");iargs++;
00412 ScilabXgc->drawbox= XtCreateManagedWidget("scigraphic",labelWidgetClass,bbox, args, iargs);
00413
00414
00415
00416 XtAddEventHandler(ScilabXgc->drawbox, ExposureMask| StructureNotifyMask,
00417 False,
00418 (XtEventHandler) EventProc1,
00419 (XtPointer) popupc);
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 XtOverrideTranslations(ScilabXgc->drawbox,
00433 XtParseTranslationTable(event_translations));
00434 XtAppAddActions(app_con, event_actions, XtNumber(event_actions));
00435
00438 XtAddCallback( ScilabXgc->Viewport,
00439 XtNreportCallback, ViewportCallback, (XtPointer) ScilabXgc);
00440 XtAddCallback(ScilabXgc->Panner,
00441 XtNreportCallback, PannerCallback, (XtPointer) ScilabXgc);
00442
00443
00444 if ( demo_menu_activate == 1 ) AddNewMenu(outer,ScilabXgc->drawbox);
00445 return(0);
00446 }
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 void PannerCallback(w, scigc_ptr , report_ptr)
00460 Widget w;
00461 XtPointer scigc_ptr, report_ptr;
00462 {
00463 struct BCG *ScilabXgc = ((struct BCG *) scigc_ptr);
00464 Widget viewport = ScilabXgc->Viewport;
00465 XawPannerReport *report = (XawPannerReport *) report_ptr;
00466 MoveChild(viewport, report->slider_x ,report->slider_y);
00467 }
00468
00469
00470 void SciViewportMove(struct BCG *ScilabXgc, int x, int y)
00471
00472 {
00473 Widget viewport,panner;
00474 Cardinal n=0;
00475 if ( ScilabXgc != NULL)
00476 {
00477 viewport = ScilabXgc->Viewport;
00478 panner = ScilabXgc->Panner;
00479 MoveChild(viewport,x,y);
00480 XtSetArg (args[n], XtNsliderX, x); n++;
00481 XtSetArg (args[n], XtNsliderY, y); n++;
00482 XtSetValues (panner, args, n);
00483 }
00484 }
00485
00486
00487
00488 void SciViewportGet(struct BCG *ScilabXgc, int *x, int *y)
00489 {
00490 Widget panner;
00491 Cardinal n=0;
00492 if ( ScilabXgc != NULL)
00493 {
00494 Dimension dx,dy;
00495 panner = ScilabXgc->Panner;
00496 XtSetArg (args[n], XtNsliderX, &dx); n++;
00497 XtSetArg (args[n], XtNsliderY, &dy); n++;
00498 XtGetValues (panner, args, n);
00499 *x = dx; *y=dy;
00500 }
00501 else
00502 {
00503 *x=0;*y=0;
00504 }
00505 }
00506
00507
00508
00509
00510
00511
00512
00513 void SciViewportClipGetSize(struct BCG *ScilabXgc,int *w,int *h)
00514 {
00515 if ( ScilabXgc != NULL)
00516 {
00517 ViewportWidget widg = ( ViewportWidget ) ScilabXgc->Viewport;
00518 register Widget clip = widg->viewport.clip;
00519 *w = clip->core.width;
00520 *h = clip->core.height;
00521 }
00522 }
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 extern void sci_pixmap_resize(struct BCG *Xgc,int x,int y);
00534
00535
00536
00537
00538 void ViewportCallback(Widget w,XtPointer scigc_ptr, XtPointer report_ptr)
00539 {
00540 Dimension cwidth,cheight,clwidth,clheight,gwidth,gheight;
00541 ViewportWidget viewpw = ( ViewportWidget ) w;
00542 register Widget clip = viewpw->viewport.clip;
00543 register Widget child = viewpw->viewport.child;
00544
00545 Cardinal n = 0;
00546 XawPannerReport *report = (XawPannerReport *) report_ptr;
00547 struct BCG *ScilabXgc = ((struct BCG *) scigc_ptr);
00548 Widget panner = ScilabXgc->Panner;
00549
00550
00551 if ( ScilabXgc->CurResizeStatus == 0)
00552 {
00553
00554 XtSetArg (args[n], XtNsliderX, report->slider_x); n++;
00555 XtSetArg (args[n], XtNsliderY, report->slider_y); n++;
00556 if (report->changed != (XawPRSliderX | XawPRSliderY)) {
00557 XtSetArg (args[n], XtNsliderWidth, report->slider_width); n++;
00558 XtSetArg (args[n], XtNsliderHeight, report->slider_height); n++;
00559 XtSetArg (args[n], XtNcanvasWidth, report->canvas_width); n++;
00560 XtSetArg (args[n], XtNcanvasHeight, report->canvas_height); n++;
00561
00562
00563
00564
00565 }
00566 XtSetValues (panner, args, n);
00567
00571 iargs = 0 ;
00572 XtSetArg (args[iargs], XtNwidth, &cwidth ); iargs++;
00573 XtSetArg (args[iargs], XtNheight, &cheight); iargs++;
00574 XtGetValues (child, args, iargs);
00575 iargs = 0;
00576 XtSetArg (args[iargs], XtNwidth, &clwidth ); iargs++;
00577 XtSetArg (args[iargs], XtNheight, &clheight); iargs++;
00578 XtGetValues (clip, args, iargs);
00579
00580 if ( ScilabXgc->drawbox != NULL)
00581 {
00582 int nw,nh;
00583 iargs = 0;
00584 XtSetArg (args[iargs], XtNwidth, &gwidth ); iargs++;
00585 XtSetArg (args[iargs], XtNheight, &gheight); iargs++;
00586 XtGetValues (ScilabXgc->drawbox, args, iargs);
00587 nw= Max(gwidth,clwidth);
00588 nh= Max(gheight,clheight);
00589 if ( nw < cwidth || nh < cheight )
00590 {
00591 XtResizeWidget(child,nw,nh,0);
00592 n=0;
00593 XtSetArg (args[n], XtNcanvasWidth, nw); n++;
00594 XtSetArg (args[n], XtNcanvasHeight,nh); n++;
00595 XtSetValues (panner, args, n);
00596 }
00597 }
00598 }
00599 else
00600 {
00605 iargs = 0 ;
00606 XtSetArg (args[iargs], XtNwidth, &cwidth ); iargs++;
00607 XtSetArg (args[iargs], XtNheight, &cheight); iargs++;
00608 XtGetValues (child, args, iargs);
00609 iargs = 0;
00610 XtSetArg (args[iargs], XtNwidth, &clwidth ); iargs++;
00611 XtSetArg (args[iargs], XtNheight, &clheight); iargs++;
00612 XtGetValues (clip, args, iargs);
00613 if ( ScilabXgc->drawbox != NULL)
00614 {
00615
00616 XtResizeWidget(ScilabXgc->drawbox,clwidth,clheight,0);
00617 ScilabXgc->CWindowWidth = clwidth;
00618 ScilabXgc->CWindowHeight = clheight;
00619 XtResizeWidget(child,clwidth,clheight,0);
00620
00621 if (ScilabXgc->Cdrawable != (Drawable) NULL)
00622 {
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635 ScilabXgc->Cdrawable_flag=1;
00636 }
00637 n=0;
00638 XtSetArg (args[n], XtNsliderWidth, clwidth); n++;
00639 XtSetArg (args[n], XtNsliderHeight,clheight); n++;
00640 XtSetArg (args[n], XtNcanvasWidth, clwidth); n++;
00641 XtSetArg (args[n], XtNcanvasHeight,clheight); n++;
00642 XtSetValues (panner, args, n);
00643 }
00644 }
00645 }
00646
00647 void SetBar(Widget w, Position top, Dimension length, Dimension total)
00648 {
00649 XawScrollbarSetThumb(w, (float) top / (float) total,
00650 (float) length / (float) total );
00651 }
00652
00653
00654
00655 void RedrawThumbs(ViewportWidget w)
00656 {
00657 register Widget child = w->viewport.child;
00658 register Widget clip = w->viewport.clip;
00659
00660 if (w->viewport.horiz_bar)
00661 SetBar( w->viewport.horiz_bar, -(child->core.x),
00662 clip->core.width, child->core.width );
00663
00664 if (w->viewport.vert_bar)
00665 SetBar( w->viewport.vert_bar, -(child->core.y),
00666 clip->core.height, child->core.height );
00667 }
00668
00669
00670
00671 static void MoveChild(Widget viewp, Position x, Position y)
00672 {
00673 ViewportWidget w = (ViewportWidget) viewp;
00674 register Widget child = w->viewport.child;
00675 register Widget clip = w->viewport.clip;
00676
00677
00678 if ((int) (x + clip->core.width) > (int) child->core.width)
00679 x = child->core.width - clip->core.width;
00680
00681 if ((int) (y + clip->core.height) > (int ) child->core.height)
00682 y = child->core.height - clip->core.height;
00683
00684
00685 if (x < 0) x = 0;
00686 if (y < 0) y = 0;
00687
00688 XtMoveWidget(child, - x, - y);
00689 RedrawThumbs(w);
00690 }
00691
00694 #define WINMINW 100
00695 #define WINMINH 100
00696
00697 void GViewportResize(struct BCG *ScilabXgc, int *width,int *height)
00698 {
00699 int Width = Max(*width, WINMINW);
00700 int Height= Max(*height, WINMINH);
00701 Position x,y;
00702 Dimension cwidth,cheight,clwidth,clheight,wv,hv;
00703 ViewportWidget w = ( ViewportWidget ) ScilabXgc->Viewport;
00704 register Widget clip = w->viewport.clip;
00705 register Widget child = w->viewport.child;
00706
00707 if ( ScilabXgc->CurResizeStatus == 0)
00708 {
00710 XtResizeWidget(ScilabXgc->drawbox ,Width,Height,0);
00712 if (ScilabXgc->Cdrawable != (Drawable) 0 )
00713 {
00714 sci_pixmap_resize(ScilabXgc,Width,Height);
00715 }
00716
00717
00718
00719
00720
00721 wv = Max(Width,clip->core.width);
00722 hv = Max(Height,clip->core.height);
00723 XtResizeWidget(child,wv,hv,0);
00724 RedrawThumbs(w);
00725
00728 iargs = 0 ;
00729 XtSetArg (args[iargs], XtNx, &x); iargs++;
00730 XtSetArg (args[iargs], XtNy, &y); iargs++;
00731 XtSetArg (args[iargs], XtNwidth, &cwidth ); iargs++;
00732 XtSetArg (args[iargs], XtNheight, &cheight); iargs++;
00733 XtGetValues (child, args, iargs);
00735 iargs = 0 ;
00736 XtSetArg (args[iargs], XtNwidth, &clwidth ); iargs++;
00737 XtSetArg (args[iargs], XtNheight, &clheight); iargs++;
00738 XtGetValues (clip, args, iargs);
00741 iargs =0;
00742 XtSetArg (args[iargs], XtNsliderX, -x); iargs++;
00743 XtSetArg (args[iargs], XtNsliderY, -y); iargs++;
00744 XtSetArg (args[iargs], XtNsliderWidth, clwidth ); iargs++;
00745 XtSetArg (args[iargs], XtNsliderHeight, clheight); iargs++;
00746 XtSetArg (args[iargs], XtNcanvasWidth, cwidth); iargs++;
00747 XtSetArg (args[iargs], XtNcanvasHeight, cheight); iargs++;
00750 XtSetValues (ScilabXgc->Panner, args, iargs);
00751 }
00752 else
00753 {
00754
00755
00756
00757
00758 iargs =0;
00759 XtSetArg (args[iargs], XtNwidth, &clwidth ); iargs++;
00760 XtSetArg (args[iargs], XtNheight, &clheight); iargs++;
00761 XtGetValues (ScilabXgc->popup, args, iargs);
00762 iargs =0;
00763 XtSetArg (args[iargs], XtNwidth, &cwidth ); iargs++;
00764 XtSetArg (args[iargs], XtNheight, &cheight); iargs++;
00765 XtGetValues (ScilabXgc->drawbox, args, iargs);
00766
00767
00768
00769
00770 clwidth = Width + Max(0,(int)clwidth - (int)cwidth);
00771 clheight= Height + Max(0,(int)clheight - (int)cheight);
00772 iargs = 0;
00773 XtSetArg (args[iargs], XtNwidth, clwidth ); iargs++;
00774 XtSetArg (args[iargs], XtNheight,clheight); iargs++;
00775 XtSetValues (ScilabXgc->popup, args, iargs);
00777 if (ScilabXgc->Cdrawable != (Drawable) 0 )
00778 {
00780 iargs =0;
00781 XtSetArg (args[iargs], XtNwidth, &cwidth ); iargs++;
00782 XtSetArg (args[iargs], XtNheight, &cheight); iargs++;
00783 XtGetValues (ScilabXgc->drawbox, args, iargs);
00784 sci_pixmap_resize(ScilabXgc,cwidth,cheight);
00785
00786 }
00787 }
00788 }
00789
00791 void GPopupResize(struct BCG *ScilabXgc, int *width,int *height)
00792 {
00793 Dimension clwidth = Max(*width, WINMINW);
00794 Dimension clheight= Max(*height, WINMINH);
00795 if ( ScilabXgc->popup!=(Widget)0) {
00796 iargs = 0;
00797 XtSetArg (args[iargs], XtNwidth, clwidth ); iargs++;
00798 XtSetArg (args[iargs], XtNheight,clheight); iargs++;
00799 XtSetValues (ScilabXgc->popup, args, iargs);
00800 }
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 #ifdef EPDEBUG
00813 #define FDEBUG(x) fprintf x
00814 #else
00815 #define FDEBUG(x)
00816 #endif
00817
00818
00819 static void ignore_events( Widget widget, XEvent *event2,long mask )
00820 {
00821 while (XCheckWindowEvent(XtDisplay(widget),XtWindow(widget),mask ,event2)==True)
00822 {
00823 FDEBUG((stderr,"inside ignore_events count = %d\n",((XExposeEvent *) event2)->count));
00824 }
00825 }
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 #ifdef EP1DEBUG
00842 #define FDEBUG_EP1(x) fprintf x
00843 #else
00844 #define FDEBUG_EP1(x)
00845 #endif
00846
00847
00848 static XtEventHandler
00849 EventProc1( Widget widget, XtPointer number, XEvent *event)
00850 {
00851 XEvent event2;
00852 integer win_num= (integer) number;
00853 XExposeEvent *event1;
00854 #ifdef EP1DEBUG
00855 static int counter=0;
00856 counter++;
00857 #endif
00858 switch (event->type)
00859 {
00860 case Expose :
00862 event1= (XExposeEvent *) event;
00863
00864
00865
00866
00867 if ( event1->count == 0)
00868 {
00869 struct BCG *SciGc = getWindowXgcNumber(win_num );
00870 if ( SciGc->Cdrawable_flag == 1)
00871 {
00872 FDEBUG_EP1((stderr,"EventProc1: Expose: --> scig_resize %d \r\n",counter));
00873 SciGc->Cdrawable_flag = 0;
00874 scig_resize(win_num);
00875 }
00876 else
00877 {
00878 FDEBUG_EP1((stderr,"EventProc1: Expose: --> scig_expose %d \r\n",counter));
00879 scig_expose(win_num);
00880 }
00881 ignore_events(widget,&event2, ExposureMask | StructureNotifyMask) ;
00882 }
00883 break;
00884 case VisibilityNotify :
00885
00886 FDEBUG_EP1((stderr,"EventProc1: VisibilityNotify\n"));
00887 break;
00888 case ConfigureNotify :
00889 FDEBUG_EP1((stderr,"EventProc1: ConfigureNotify %d \n",counter));
00890 scig_resize(win_num);
00892 ignore_events(widget,&event2, ExposureMask | StructureNotifyMask);
00893 break;
00894 case CreateNotify :
00895 FDEBUG_EP1((stderr,"EventProc1: CreateNotify\r\n",counter));
00896 break ;
00897 case MapNotify :
00898 FDEBUG_EP1((stderr,"EventProc1: MapNotify\r\n",counter));
00900 ignore_events(widget,&event2, ExposureMask );
00901 break;
00902 case ReparentNotify :
00903 FDEBUG_EP1((stderr,"EventProc1: ReparentNotify\r\n"));
00904 break;
00905 default:
00906 FDEBUG_EP1((stderr,"EventProc1: default, event=%d window=%d\r\n",event->type,(int) win_num));
00907 return(0);
00908 }
00909 return(0);
00910 }
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 static void
00921 Efface(w, number, client_data)
00922 Widget w;
00923 XtPointer number;
00924 XtPointer client_data;
00925 {
00926 integer win_num = (integer) number ;
00927 scig_erase(win_num);
00928 }
00929
00930
00931
00932
00933
00934
00935
00936 static void
00937 Select(w, number, client_data)
00938 Widget w;
00939 XtPointer number;
00940 XtPointer client_data;
00941 {
00942 integer win_num = (integer) number ;
00943 scig_sel(win_num);
00944 }
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975 extern int get_xclick_client_message_flag(void);
00976
00977 static void
00978 Delete(Widget w, XtPointer number, XtPointer client_data)
00979 {
00980 int v_flag = 1;
00981 integer win_num = (integer) number ;
00982 if ( get_delete_win_mode() == 1 )
00983 {
00984 wininfo("Cannot destroy window while acquiring zoom rectangle ");
00985 return;
00986 }
00987 if ( get_xclick_client_message_flag() == 1 )
00988 {
00989
00990
00991
00992 PushClickQueue(win_num,0,0,-100,0,0);
00993 }
00995 Efface((Widget) 0,(XtPointer) number, (XtPointer) 0);
00996 DeleteObjs(win_num);
00997 v_flag = 0;
00998 scig_deletegwin_handler(win_num);
00999 DeleteSGWin(win_num);
01000
01001
01002
01003 delete_sgwin_entities(win_num);
01004 }
01005
01006
01007
01008 int C2F(deletewin)(integer *number) {
01009 Delete((Widget) 0,(XtPointer) *number,(XtPointer) 0);
01010 return(0);
01011 }
01012
01013
01014
01015
01016
01017
01018 static char bufname[256];
01019 static char printer[128];
01020 static char file[256];
01021
01022 static void
01023 Print(Widget w,XtPointer number, XtPointer client_data)
01024 {
01025 char *p1;
01026 integer win_num = (integer) number ;
01027 integer colored,orientation,flag=1,ok;
01028
01029 prtdlg(&flag,printer,&colored,&orientation,file,&ok);
01030 if (ok==1)
01031 {
01032 if ( ( p1 = getenv("TMPDIR")) == (char *) 0 )
01033 {
01034 sciprint("Cannot find environment variable TMPDIR\r\n");
01035 }
01036
01037 sprintf(bufname,"%s/scilab-%d",p1,(int)win_num);
01038 scig_toPs(win_num,colored,bufname,"Pos");
01039 sprintf(bufname,"$SCI/bin/scilab -%s %s/scilab-%d %s",
01040 (orientation == 1) ? "print_l" : "print_p",
01041 p1,(int)win_num,printer);
01042 system(bufname);
01043 }
01044 }
01045
01046
01047
01048 void scig_print(integer number)
01049 {
01050 Print(NULL,(XtPointer) number,NULL);
01051 }
01052
01053
01054
01055
01056
01057 static void
01058 SavePs(Widget w, XtPointer number, XtPointer client_data)
01059 {
01060 integer win_num = (integer) number ;
01061 integer colored,orientation,flag=2,ok;
01062 prtdlg(&flag,printer,&colored,&orientation,file,&ok);
01063 if (ok==1)
01064 {
01065 if (strncmp(printer,"Postscript",10)==0 )
01066 {
01068 scig_toPs(win_num,colored,file,"Pos");
01069 }
01070 else if (strcmp(printer,"Xfig")==0)
01071 {
01073 scig_toPs(win_num,colored,file,"Fig");
01074 }
01075 else if (strcmp(printer,"Gif")==0)
01076 {
01078 scig_toPs(win_num,colored,file,"GIF");
01079 }
01080 else if (strcmp(printer,"PPM")==0)
01081 {
01083 scig_toPs(win_num,colored,file,"PPM");
01084 }
01085 if ( strcmp(printer,"Postscript No Preamble") != 0)
01086 {
01087 sprintf(bufname,"$SCI/bin/scilab -%s %s %s",
01088 ( orientation == 1) ? "save_l" : "save_p",file,printer);
01089 system(bufname);
01090 }
01091 }
01092 }
01093
01094
01095
01096 void scig_export(integer number)
01097 {
01098 SavePs(NULL,(XtPointer) number,NULL);
01099 }
01100
01101
01102
01103
01104
01105 static void
01106 Save(Widget w, XtPointer number, XtPointer client_data)
01107 {
01108 char *filename;
01109
01110 int ierr=0,rep;
01111 static char *init ="*.scg";
01112 rep=GetFileWindow(init,&filename,".",0,&ierr,"Save Graphic File");
01113 if ( ierr == 0 && rep == TRUE )
01114 {
01115
01116 }
01117 }
01118
01119
01120
01121
01122
01123 static void
01124 Load(Widget w, XtPointer number, XtPointer client_data)
01125 {
01126 char *filename;
01127 integer win_num = (integer) number ;
01128 int ierr=0,rep;
01129 static char *init ="*.scg";
01130 rep=GetFileWindow(init,&filename,".",0,&ierr,"Load Graphic File");
01131 if ( ierr == 0 && rep == TRUE )
01132 {
01133 integer verb=0,cur,na;
01134 C2F(dr)("xget","window",&verb,&cur,&na,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
01135 C2F(dr)("xset","window",&win_num,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
01136
01137 C2F(dr)("xset","window",&cur,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
01138 }
01139 }
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149 static void
01150 Zoom(Widget w, XtPointer number, XtPointer client_data)
01151 {
01152
01153 integer win_num = (integer) number,ne=0;
01154 iargs = 0;
01155 XtSetArg(args[iargs], XtNsensitive, False); iargs++;
01156 XtSetValues(w, args, iargs);
01157 SetUnsetMenu(&win_num,"3D Rot.",&ne,False);
01158 SetUnsetMenu(&win_num,"UnZoom",&ne,False);
01159 SetUnsetMenu(&win_num,"File",&ne,False);
01160 if(scig_2dzoom(win_num) != 1){
01161 iargs = 0;
01162 XtSetArg(args[iargs], XtNsensitive,True); iargs++;
01163 XtSetValues(w, args, iargs);
01164 }
01165 SetUnsetMenu(&win_num,"3D Rot.",&ne,True);
01166 SetUnsetMenu(&win_num,"UnZoom",&ne,True);
01167 SetUnsetMenu(&win_num,"File",&ne,True);
01168 }
01169
01170
01171
01172
01173
01174
01175 static void
01176 UnZoom(w, number, client_data)
01177 Widget w;
01178 XtPointer number;
01179 XtPointer client_data;
01180 {
01181 integer win_num = (integer) number;
01182 iargs = 0;
01183 XtSetArg(args[iargs], XtNsensitive, False); iargs++;
01184 XtSetValues(w, args, iargs);
01185 scig_unzoom(win_num);
01186 iargs = 0;
01187 XtSetArg(args[iargs], XtNsensitive,True); iargs++;
01188 XtSetValues(w, args, iargs);
01189 }
01190
01191
01192
01193
01194
01195
01196
01197 static void
01198 Rot3D(w, number, client_data)
01199 Widget w;
01200 XtPointer number;
01201 XtPointer client_data;
01202 {
01203 integer win_num = (integer) number,ne=0;
01204 iargs=0;
01205 XtSetArg(args[iargs], XtNsensitive, False); iargs++;
01206 XtSetValues(w, args, iargs);
01207 SetUnsetMenu(&win_num,"UnZoom",&ne,False);
01208 SetUnsetMenu(&win_num,"Zoom",&ne,False);
01209 SetUnsetMenu(&win_num,"File",&ne,False);
01210 scig_3drot(win_num);
01211 iargs = 0;
01212 XtSetArg(args[iargs], XtNsensitive,True); iargs++;
01213 XtSetValues(w, args, iargs);
01214 SetUnsetMenu(&win_num,"UnZoom",&ne,True);
01215 SetUnsetMenu(&win_num,"Zoom",&ne,True);
01216 SetUnsetMenu(&win_num,"File",&ne,True);
01217 }
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01233 void SGDeleteWindow(w, event, params, num__PARAMS)
01234 Widget w;
01235 XEvent *event;
01236 String *params;
01237 Cardinal *num__PARAMS;
01238 {
01239 int i;
01240 Window Win = XtWindow(w), Win1;
01241 int wincount = getWinsMaxId()+1;
01242 for (i=0 ; i < wincount ; i++)
01243 {
01244 Win1=GetBGWindowNumber(i);
01245 if (Win1 == Win )
01246 {
01248 Delete((Widget) 0,(XtPointer) i,(XtPointer) 0);
01249 return ;
01250 }
01251 }
01252 return ;
01253 }
01254
01255
01256 static String sg_trans =
01257 "<Message>WM_PROTOCOLS: SGDeleteWindow()\n\
01258 <ClientMessage>WM_PROTOCOLS: SGDeleteWindow()\n";
01259
01260 void CreatePopupWindow(integer WinNum, Widget button, struct BCG *ScilabXgc, Pixel *fg, Pixel *bg)
01261 {
01262 Widget toplevel;
01263 Display *dpy;
01264 XColor x_fg_color,x_bg_color;
01265 static XSetWindowAttributes attributes;
01266 unsigned char winname[6];
01267 iargs=0;
01268 XtSetArg(args[iargs], XtNx, 100+20*WinNum % 200); iargs++;
01269 XtSetArg(args[iargs], XtNy, 100+20*WinNum % 200); iargs++;
01270 sprintf(popupname,"ScilabGraphic%d",(int)WinNum);
01271 XtSetArg(args[iargs],XtNtitle,popupname);iargs++;
01272
01273 DisplayInit("",&dpy,&toplevel);
01274 MultiClickTime=XtGetMultiClickTime(dpy);
01275
01276
01277
01278
01279
01280 ScilabXgc->popup = XtAppCreateShell("Xscilab",popupname,topLevelShellWidgetClass,dpy,
01281 args,iargs);
01282 AddNewWin((int) WinNum,ScilabXgc);
01283 XtPopup(ScilabXgc->popup, XtGrabNone);
01284 SetHints(ScilabXgc->popup);
01285
01286 sprintf((char *)winname,"BG%d",(int)WinNum);
01287 XChangeProperty(XtDisplay(ScilabXgc->drawbox),
01288 XtWindow(ScilabXgc->drawbox), XA_WM_NAME, XA_STRING, 8,
01289 PropModeReplace, winname, 5);
01290 attributes.backing_store = Always;
01291 attributes.bit_gravity = NorthWestGravity;
01292 XChangeWindowAttributes(XtDisplay((ScilabXgc->drawbox)),
01293 XtWindow((ScilabXgc->drawbox)),
01294 CWBackingStore | CWBitGravity,&attributes);
01295 XSync(XtDisplay(ScilabXgc->popup),0);
01296 ScilabXgc->CWindow=XtWindow(ScilabXgc->drawbox);
01297 ScilabXgc->CBGWindow=XtWindow(ScilabXgc->popup);
01298 XtOverrideTranslations(ScilabXgc->popup, XtParseTranslationTable(sg_trans));
01299
01300 XtSetArg(args[0],XtNforeground, &x_fg_color.pixel);
01301 XtSetArg(args[1],XtNbackground, &x_bg_color.pixel);
01302 XtGetValues(ScilabXgc->drawbox,args,2);
01303 *fg = x_fg_color.pixel;
01304 *bg = x_bg_color.pixel;
01305 }
01306
01307
01308
01309
01310
01311
01312
01313 void ChangeBandF(win_num,fg,bg)
01314 int win_num;
01315 Pixel fg;
01316 Pixel bg;
01317 {
01318 struct BCG *SciGc;
01319 Widget popup,toplevel;
01320 static Display *dpy = (Display *) NULL;
01321 DisplayInit("",&dpy,&toplevel);
01322 SciGc = getWindowXgcNumber(win_num);
01323 if ( SciGc != NULL )
01324 {
01325 popup = SciGc->popup;
01326 if (popup == NULL) return;
01327 ChangeBF1(popup,"*.scigForm.scigmForm.File",fg,bg);
01328 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu",fg,bg);
01329 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Clear",fg,bg);
01330 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Select",fg,bg);
01331 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Print",fg,bg);
01332 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Export",fg,bg);
01333 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Save",fg,bg);
01334 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Load",fg,bg);
01335 ChangeBF1(popup,"*.scigForm.scigmForm.File.menu.Close",fg,bg);
01336 ChangeBF1(popup,"*.scigForm.scigmForm.Zoom",fg,bg);
01337 ChangeBF1(popup,"*.scigForm.scigmForm.UnZoom",fg,bg);
01338 ChangeBF1(popup,"*.scigForm.scigmForm.Rot3D",fg,bg);
01339 }
01340 }
01341
01342 static void ChangeBF1(w,str,fg,bg)
01343 Widget w;
01344 char *str;
01345 Pixel fg;
01346 Pixel bg;
01347 {
01348 Widget loc;
01349 loc = XtNameToWidget(w,str);
01350 if ( loc != NULL)
01351 {
01352 iargs=0;
01353 XtSetArg(args[iargs], XtNforeground, fg); iargs++;
01354 XtSetArg(args[iargs], XtNbackground, bg); iargs++;
01355 XtSetValues(loc, args, iargs);
01356 }
01357 else
01358 {
01359 sciprint("widget %s not found\r\n",str);
01360 }
01361 }
01362
01363
01364
01365
01366
01367
01368 typedef struct {
01369 int win_num;
01370 int entry;
01371 int type;
01372 char *fname;
01373 } MenuData,*MenuDataPtr;
01374
01375 extern Widget commandWindow;
01376
01377 static void
01378 KillButton(w, client_data, call_data)
01379 Widget w;
01380 XtPointer client_data;
01381 caddr_t call_data;
01382 {
01383 MenuDataPtr datas =(MenuDataPtr)client_data;
01385 if ( datas->entry == 0)
01386 FREE(datas->fname);
01387 FREE(datas);
01388 }
01389
01390
01391
01392
01393 static void
01394 SelMenu(w, client_data, call_data)
01395 Widget w;
01396 XtPointer client_data;
01397 caddr_t call_data;
01398 {
01399 static char buf[256];
01400 MenuDataPtr datas = (MenuDataPtr) client_data;
01401 if (datas->type == 0)
01402 {
01403
01404 if ( datas->win_num < 0 )
01405 {
01406 sprintf(buf,"execstr(%s(%d))",datas->fname,datas->entry+1);
01407 }
01408 else
01409 {
01410 sprintf(buf,"execstr(%s_%d(%d))",datas->fname,datas->win_num,datas->entry+1);
01411 }
01412 StoreCommand(buf);
01413 }
01414 else if (datas->type == 2)
01415 {
01416
01417 if ( datas->win_num < 0 )
01418 {
01419 sprintf(buf,"%s(%d)",datas->fname,datas->entry+1);
01420 }
01421 else
01422 {
01423 sprintf(buf,"%s(%d,%d)",datas->fname,datas->entry+1,datas->win_num);
01424 }
01425 StoreCommand(buf);
01426 }
01427 else
01428 {
01429
01430 int rep ;
01431 C2F(setfbutn)(datas->fname,&rep);
01432 if ( rep == 0)
01433 F2C(fbutn)((datas->fname),&(datas->win_num),&(datas->entry));
01434 }
01435 }
01436
01437
01438
01439
01440
01441
01442
01443 int C2F(delbtn)(win_num,button_name)
01444 integer *win_num;
01445 char *button_name;
01446 {
01447 int nc=0;
01448 WidgetList childs;
01449 Widget outer,h,v,w;
01450 int i,pos=0;
01451 int name_pos ;
01452
01453 if (GetChilds(*win_num,&nc,&childs,&outer,button_name,&name_pos)== FALSE)
01454 return 0;
01455 if (name_pos == -1 ) return 0;
01456
01457 pos = name_pos +1;
01458 if ( pos==(int)nc )
01459 {
01460
01461 XtDestroyWidget(childs[name_pos]);
01462 return 0;
01463 }
01464 iargs=0;
01465 XtSetArg(args[iargs], XtNfromHoriz,&h); iargs++;
01466 XtSetArg(args[iargs], XtNfromVert,&v); iargs++;
01467 XtGetValues(childs[pos-1], args, iargs);
01468
01469 iargs=0;
01470 XtSetArg(args[iargs], XtNfromHoriz,h); iargs++;
01471 XtSetArg(args[iargs], XtNtop,XawChainTop); iargs++;
01472 XtSetArg(args[iargs], XtNbottom,XawChainTop); iargs++;
01473 XtSetValues(childs[pos], args, iargs);
01474
01475 if (v!=NULL) {
01476 iargs=0;
01477 XtSetArg(args[iargs], XtNfromVert,v); iargs++;
01478 XtSetArg(args[iargs], XtNtop,XawChainTop); iargs++;
01479 XtSetArg(args[iargs], XtNbottom,XawChainTop); iargs++;
01480 XtSetValues(childs[pos], args, iargs);
01481 for (i=pos+1;i<(int)nc;i++) {
01482 iargs=0;
01483 XtSetArg(args[iargs], XtNfromVert,&w); iargs++;
01484 XtGetValues(childs[i], args, iargs);
01485 if (w== childs[pos-1]) {
01486 iargs=0;
01487 XtSetArg(args[iargs], XtNfromVert,v); iargs++;
01488 XtSetArg(args[iargs], XtNtop,XawChainTop); iargs++;
01489 XtSetArg(args[iargs], XtNbottom,XawChainTop); iargs++;
01490 XtSetValues(childs[i], args, iargs);
01491 }
01492 }
01493 }
01494
01495 if ( childs[pos-1] != NULL)
01496 XtDestroyWidget(childs[pos-1]);
01497 return(0);
01498 }
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512 void AddMenu(win_num, button_name, entries, ne, typ, fname, ierr)
01513 integer *win_num;
01514 char *button_name;
01515 char **entries;
01516 integer *ne;
01517 integer *typ;
01518 char *fname;
01519 integer *ierr;
01520 {
01521 int newline,i;
01522 WidgetList childs;
01523 Widget outer,command,w,menu,entry;
01524 Position x;
01525 Dimension width,height,mainwidth,mainheight,bw=0;
01526 XFontStruct *temp_font;
01527 char *func;
01528 MenuDataPtr datas;
01529 int nc, name_pos;
01530 if (GetChilds(*win_num,&nc,&childs,&outer,NULL,&name_pos)== FALSE) return;
01531 if ( nc < 2 ) return ;
01532 iargs=0;
01533 XtSetArg(args[iargs], XtNx,&x); iargs++;
01534 XtSetArg(args[iargs], XtNwidth,&width); iargs++;
01535 XtSetArg(args[iargs], XtNheight,&height); iargs++;
01536 XtSetArg(args[iargs], XtNfont, &temp_font); iargs++;
01537 XtGetValues(childs[nc-1], args, iargs);
01538 iargs=0;
01539 XtSetArg(args[iargs], XtNwidth,&mainwidth); iargs++;
01540 XtSetArg(args[iargs], XtNheight,&mainheight); iargs++;
01541 XtGetValues(outer, args, iargs);
01542
01543 bw= ( temp_font != NULL )? strlen(button_name)*((temp_font)->max_bounds.width) : 0;
01544 if ( (Dimension) (width+bw+x) < mainwidth)
01545 {
01547 newline=0;
01548 iargs=0;
01549 XtSetArg(args[iargs], XtNfromVert,&w); iargs++;
01550 XtGetValues(childs[nc-1], args, iargs);
01551 iargs=0;
01552 XtSetArg(args[iargs], XtNfromHoriz,childs[nc-1]); iargs++;
01553 XtSetArg(args[iargs], XtNfromVert,w); iargs++;
01554 }
01555 else
01556 {
01558 newline=1;
01559 iargs=0;
01560 XtSetArg(args[iargs], XtNfromVert,childs[nc-1]); iargs++;
01561 XtSetArg(args[iargs], XtNfromHoriz,childs[0]); iargs++;
01562 }
01563
01564 func=(char *) MALLOC( (strlen(fname)+1)*(sizeof(char)));
01565 if ( func == ( char *) 0 )
01566 {
01567 *ierr=1 ;return;
01568 }
01569 strcpy(func,fname);
01570
01571 XtSetArg(args[iargs], XtNheight,height); iargs++;
01572 if (*ne==0) {
01573 command = XtCreateManagedWidget(button_name,
01574 commandWidgetClass,outer,args, iargs);
01575 datas= (MenuDataPtr) MALLOC(sizeof(MenuData) );
01576 if ( datas == (MenuDataPtr) 0)
01577 {
01578 *ierr=1 ;return;
01579 }
01580 datas->win_num= *win_num;
01581 datas->entry=0;
01582 datas->type=*typ;
01583 datas->fname=func;
01584 XtAddCallback(command, XtNcallback,(XtCallbackProc) SelMenu,
01585 (XtPointer)datas);
01586 XtAddCallback(command, XtNdestroyCallback,(XtCallbackProc) KillButton,
01587 (XtPointer)datas);
01588 }
01589 else {
01590 command = XtCreateManagedWidget(button_name,
01591 menuButtonWidgetClass,outer,args, iargs);
01592 iargs=0;
01593 menu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
01594 command,args, iargs);
01595 for (i=0;i<*ne;i++){
01596 iargs=0;
01597 entry= XtCreateManagedWidget(entries[i], smeBSBObjectClass, menu,
01598 args, iargs);
01599 datas= (MenuDataPtr) MALLOC(sizeof(MenuData) );
01600 if ( datas == (MenuDataPtr) 0)
01601 {
01602 *ierr=1 ;return;
01603 }
01604 datas->win_num = *win_num;
01605 datas->entry=i;
01606 datas->type=*typ;
01607 datas->fname=func;
01608 XtAddCallback(entry,XtNcallback,(XtCallbackProc)SelMenu,
01609 (XtPointer)datas);
01610 XtAddCallback(entry, XtNdestroyCallback,(XtCallbackProc) KillButton,
01611 (XtPointer)datas);
01612 }
01613 }
01614 if (newline==1) {
01615
01616 }
01617 }
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634 int C2F(addmen)(win_num,button_name,entries,ptrentries,ne,typ,fname,ierr)
01635 integer *win_num,*entries,*ptrentries,*ne,*ierr,*typ;
01636 char *button_name,*fname;
01637 {
01638 char ** menu_entries = NULL ;
01639 int i ;
01640 *ierr =0;
01641 if (*ne!=0) {
01642 ScilabMStr2CM(entries,ne,ptrentries,&menu_entries,ierr);
01643 if ( *ierr == 1) return(0);
01644 }
01645 AddMenu(win_num,button_name,menu_entries,ne,typ,fname,ierr);
01646
01647 for ( i = 0 ; i < *ne ; i++ )
01648 {
01649 FREE( menu_entries[i] ) ;
01650 }
01651 FREE( menu_entries ) ;
01652 return(0);
01653 }
01654
01655
01656
01657
01658
01659 static void SetUnsetMenu(win_num, button_name, ne,flag)
01660 integer *win_num;
01661 char *button_name;
01662 integer *ne;
01663 int flag;
01664 {
01665 Cardinal nc=0;
01666 WidgetList childs;
01667 Widget outer;
01668 int nc1,name_pos;
01669 if (GetChilds(*win_num,&nc1,&childs,&outer,button_name,&name_pos)== FALSE) return;
01670 if (name_pos == -1 ) return;
01671 if (*ne==0)
01672 {
01674 iargs=0;
01675 XtSetArg(args[iargs],XtNsensitive,flag); iargs++;
01676 XtSetValues(childs[name_pos], args, iargs );
01677 }
01678 else
01679 {
01680 Widget w1;
01681 String mname=NULL;
01682
01683
01684
01685 iargs=0;
01686 XtSetArg(args[iargs], XtNmenuName, &mname); iargs++;
01687 XtGetValues(childs[name_pos], args, iargs);
01688 w1= (mname == NULL) ? NULL : XtNameToWidget(childs[name_pos],mname);
01689 if (w1==NULL) {
01690 iargs=0;
01691 XtSetArg(args[iargs],XtNsensitive,flag); iargs++;
01692 XtSetValues(childs[name_pos], args, iargs );
01693 return;
01694 }
01695 iargs=0;
01696 XtSetArg(args[iargs], XtNnumChildren, &nc); iargs++;
01697 XtSetArg(args[iargs], XtNchildren, &childs); iargs++;
01698 XtGetValues(w1, args, iargs);
01699 if (*ne <= (int)nc) {
01700 iargs=0;
01701 XtSetArg(args[iargs],XtNsensitive,flag); iargs++;
01702 XtSetValues(childs[*ne-1], args, iargs );
01703 }
01704 }
01705 }
01706
01707
01710 int C2F(setmen)(win_num,button_name,entries,ptrentries,ne,ierr)
01711 integer *win_num,*entries,*ptrentries,*ne,*ierr;
01712 char *button_name;
01713 {
01714 SetUnsetMenu(win_num,button_name,ne,True);
01715 return(0);
01716 }
01717
01718 int C2F(unsmen)(win_num,button_name,entries,ptrentries,ne,ierr)
01719 integer *win_num,*entries,*ptrentries,*ne,*ierr;
01720 char *button_name;
01721 {
01722 SetUnsetMenu(win_num,button_name,ne,False);
01723 return(0);
01724 }
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737 static int GetChilds(win_num,nc,wL,outer,name,name_pos)
01738 int win_num;
01739 int *nc;
01740 WidgetList *wL;
01741 Widget *outer;
01742 char *name;
01743 int * name_pos;
01744 {
01745 Cardinal nc1=0;
01746 Widget popup,toplevel;
01747 char * label;
01748 static Display *dpy = (Display *) NULL;
01749 DisplayInit("",&dpy,&toplevel);
01750 if ( win_num == -1)
01751 {
01752 *outer = commandWindow;
01753 }
01754 else
01755 {
01756 struct BCG *SciGc;
01757 SciGc = getWindowXgcNumber(win_num);
01758 if ( SciGc == NULL ) return FALSE;
01759 if ((popup = SciGc->popup)== NULL) return FALSE;
01760 *outer=XtNameToWidget(popup,"*.scigForm.scigmForm");
01761 if (*outer == NULL) return FALSE;
01762 }
01763 iargs=0;
01764 XtSetArg(args[iargs], XtNnumChildren, &nc1); iargs++;
01765 XtSetArg(args[iargs], XtNchildren, wL); iargs++;
01766 XtGetValues(*outer, args, iargs);
01767 *nc=nc1;
01768 *name_pos = -1;
01769 if ( name != NULL)
01770 {
01771 int i;
01772 for (i=0; i < (int)nc1;i++)
01773 {
01774 iargs=0;
01775 label=NULL;
01776 XtSetArg(args[iargs], XtNlabel,&label); iargs++;
01777 XtGetValues( (*wL)[i], args, iargs);
01778 if ( label != NULL && (strcmp(label,name)==0))
01779 {
01780 *name_pos = i;
01781 break;
01782 }
01783 }
01784 }
01785 return TRUE;
01786 }
01787
01788
01789
01790
01791 int getNbSubMenus( int winNumber, char * menuName )
01792 {
01793 int nbMenus ;
01794 WidgetList subMenus ;
01795 Widget menu ;
01796 Widget subMenu ;
01797 int menuId ;
01798 int nbSubMenus = 0 ;
01799 String mname = NULL ;
01800
01801 if ( GetChilds( winNumber ,
01802 &nbMenus ,
01803 &subMenus ,
01804 &menu ,
01805 menuName ,
01806 &menuId ) == FALSE )
01807 {
01808 return 0 ;
01809 }
01810
01811
01812
01813 iargs=0;
01814 XtSetArg(args[iargs], XtNmenuName, &mname);
01815 iargs++;
01816 XtGetValues(subMenus[menuId], args, iargs);
01817
01818 if ( mname == NULL )
01819 {
01820 return 0 ;
01821 }
01822
01823 subMenu = XtNameToWidget(subMenus[menuId],mname) ;
01824 iargs = 0 ;
01825 XtSetArg(args[iargs], XtNnumChildren, &nbSubMenus);
01826 iargs++;
01827 XtGetValues( subMenu , args, iargs);
01828
01829 return nbSubMenus ;
01830 }
01831
01832
01833 void refreshMenus( struct BCG * ScilabGC ) {}
01834