00001 #include "wgmenu.h"
00002
00003 #include "Messages.h"
00004 #include "Warnings.h"
00005 #include "Errors.h"
00006 #include "WindowList.h"
00007 #include "Actions.h"
00008 #include "periScreen.h"
00009
00010 #include "MALLOC.h"
00011
00012 void scig_savesg( int win_num, char * filename ) ;
00013
00014
00015 extern HINSTANCE hdllInstance;
00016
00017 extern BOOL IsWindowInterface();
00018 extern void Write_Scilab_Console (char *buf);
00019 extern void Write_Scilab_Window (char *buf);
00020 extern void ResetMenu(void);
00021 extern void HideGraphToolBar(struct BCG * ScilabGC);
00022 extern void ShowGraphToolBar(struct BCG * ScilabGC);
00023 extern void SaveCurrentLine(BOOL RewriteLineAtPrompt);
00024 extern void ExportBMP(struct BCG *ScilabGC,char *pszflname);
00025 extern void ExportEMF(struct BCG *ScilabGC,char *pszflname);
00026 extern HDC GetPrinterDC(void);
00027 extern char GetPrinterOrientation(void);
00028 extern void SavePs (struct BCG *ScilabGC);
00029 extern void PrintPs (struct BCG *ScilabGC);
00030 extern char *GetScilabDirectory(BOOL UnixStyle);
00031 extern void Callback_PRINTSETUP(void);
00032 extern LPTW GetTextWinScilab(void);
00033 void ModifyEntityPickerToolbar(struct BCG * ScilabGC,BOOL Pressed);
00034
00035
00036
00037
00038 void SendGraphMacro (struct BCG *ScilabGC, UINT m)
00039 {
00040 BYTE *s;
00041 char *d;
00042 char *buf;
00043 BOOL flag = TRUE;
00044 wininfo (" ");
00045 if ((buf = LocalAlloc (LPTR, MAXSTR + 1)) == (char *) NULL)
00046 return;
00047 if (m >= NUMMENU || (int)m < 0)
00048 return;
00049 s = ScilabGC->lpmw.macro[m];
00050 d = buf;
00051 *d = '\0';
00052 while (s && *s && (d - buf < MAXSTR))
00053 {
00054 if (*s >= CMDMIN && *s <= CMDMAX)
00055 {
00056 int ierr = 0;
00057
00059 switch (*s)
00060 {
00061 case TOOLBARGRAPH:
00062 if (ScilabGC->lpmw.LockToolBar == FALSE)
00063 {
00064 if (ScilabGC->lpmw.ShowToolBar) HideGraphToolBar(ScilabGC);
00065 else ShowGraphToolBar(ScilabGC);
00066 }
00067 s++;
00068 break;
00069 case NEWFIG:
00070 SaveCurrentLine(TRUE);
00071 NewFigure(ScilabGC);
00072 s++;
00073 break;
00074 case ZOOM:
00075 scig_2dzoom (ScilabGC->CurWindow);
00076
00077 s++;
00078 break;
00079 case UNZOOM:
00080 scig_unzoom (ScilabGC->CurWindow);
00081
00082 s++;
00083 break;
00084 case ROT3D:
00085 scig_3drot (ScilabGC->CurWindow);
00086
00087 s++;
00088 break;
00089 case PRINTSETUP:
00090 Callback_PRINTSETUP();
00091 s++;
00092 break;
00093 case PRINT:
00094 CopyPrint (ScilabGC);
00095 s++;
00096 break;
00097 case COPYCLIP:
00098 {
00099 CopyToClipboardEMF (ScilabGC);
00100 s++;
00101 }
00102 break;
00103 case COPYCLIP1:
00104 CopyToClipboardBitmap (ScilabGC);
00105 s++;
00106 break;
00107 case REDRAW:
00108 scig_replay (ScilabGC->CurWindow);
00109 s++;
00110 break;
00111 case CLEARWG:
00112 scig_erase (ScilabGC->CurWindow);
00113 s++;
00114 break;
00115 case SCIPS:
00116 {
00117 char *SaveCurrentPath=NULL;
00118 SaveCurrentPath=_getcwd( NULL, 0 );
00119 SavePs (ScilabGC);
00120 if (SaveCurrentPath)
00121 {
00122 _chdir(SaveCurrentPath);
00123 free(SaveCurrentPath);
00124 SaveCurrentPath=NULL;
00125 }
00126 s++;
00127 }
00128 break;
00129 case SCIPR:
00130 PrintPs (ScilabGC);
00131 s++;
00132 break;
00133 case SCIGSEL:
00134 scig_sel (ScilabGC->CurWindow);
00135 s++;
00136 break;
00137 case LOADSCG:
00138 flag = SciOpenSave (ScilabGC->hWndParent, &s,FALSE,&d, &ierr);
00139 if (flag == 0 || ierr == 1)
00140 {
00141 LocalFree (buf);
00142 return;
00143 }
00144 *d = '\0';
00145 scig_loadsg (ScilabGC->CurWindow, buf);
00146 break;
00147 case SAVESCG:
00148 flag = SciOpenSave (ScilabGC->hWndParent, &s,TRUE,&d, &ierr);
00149 if (flag == 0 || ierr == 1)
00150 {
00151 LocalFree (buf);
00152 return;
00153 }
00154 *d = '\0';
00155
00156 scig_savesg( ScilabGC->CurWindow, buf ) ;
00157 break;
00158 case UPDINI:
00159 SendMessage (ScilabGC->CWindow, WM_COMMAND, M_WRITEINI, 0L);
00160 s++;
00161 break;
00162 case CLOSE:
00163 C2F (deletewin) (&(ScilabGC->CurWindow));
00164 s++;
00165 break;
00166 default:
00167 s++;
00168 break;
00169 }
00173 d = buf;
00174 s = (BYTE *) "";
00175 }
00176 else
00177 {
00178 *d++ = *s++;
00179 }
00180 }
00181 *d = '\0';
00186 ScilabMenuAction (buf);
00187 LocalFree (buf);
00188
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 void ScilabMenuAction (char *buf)
00198 {
00199 if (strlen (buf) > 2 && buf[0] == '@')
00200 {
00202 if (buf[1] == '0')
00203 {
00204
00205 StoreCommand1 (buf + 2, 0);
00206 }
00207 else
00208 {
00209
00210 int rep, win, entry;
00211 char *tmp=NULL;
00212 char *LocalBuf=(char*)MALLOC((strlen(buf)+1)*sizeof(char));
00213 char *FunctionName=(char*)MALLOC((strlen(buf)+1)*sizeof(char));
00214 wsprintf(LocalBuf,"%s",buf+strlen("@1")+strlen("execstr("));
00215
00216 LocalBuf[strlen(LocalBuf)-1]='\0';
00217
00218 if ( ( tmp = strchr (LocalBuf, '_') ) != NULL )
00219 {
00220 sscanf (tmp + 1, "%d(%d)", &win, &entry);
00221 entry--;
00222 strncpy(FunctionName,LocalBuf,strlen(LocalBuf)-strlen(tmp));
00223 *tmp = '\0';
00224 }
00225 else
00226 {
00227 win = -1;
00228 if ((tmp = strchr (LocalBuf, '(')) != NULL)
00229 {
00230 char *tmpbis=NULL;
00231 sscanf (tmp, "(%d)", &entry);
00232
00233 if ( ( tmpbis = strchr (LocalBuf, '(') ) != NULL )
00234 {
00235 strncpy(FunctionName,LocalBuf,strlen(LocalBuf)-strlen(tmpbis));
00236 }
00237
00238 entry--;
00239 *tmp = '\0';
00240 }
00241 }
00242
00243 C2F (setfbutn) (FunctionName, &rep);
00244 if (rep == 0)
00245 {
00246 F2C (fbutn) (FunctionName, &(win), &(entry));
00247 }
00248
00249 if (FunctionName) {FREE(FunctionName);FunctionName=NULL;}
00250 if (LocalBuf) {FREE(LocalBuf);LocalBuf=NULL;}
00251 }
00252 }
00253 else
00254 {
00255 if (buf[0] != '\0')
00256 {
00258 if (strlen (buf) == 1 && buf[0] <= 31 && buf[0] >= 1)
00259 {
00260 StoreCommand1 (buf, 0);
00261 }
00262 else
00263 {
00264 StoreCommand1 (buf, 1);
00265 }
00266 }
00267 }
00268 }
00269
00270
00271
00272
00273
00274 void write_scilab (char *buf)
00275 {
00276 if ( IsWindowInterface() ) Write_Scilab_Window(buf);
00277 else Write_Scilab_Console(buf);
00278
00279 }
00280
00281 void CallTranslateMacroGraphicWindow(char *string)
00282 {
00283 TranslateMacro(string);
00284 }
00285
00286
00287
00288
00289 static void TranslateMacro (char *string)
00290 {
00291 int i, len;
00292 LPSTR ptr;
00293 for (i = 0; keyword[i] != (char *) NULL; i++)
00294 {
00295 if ((ptr = strstr (string, keyword[i])) != NULL)
00296 {
00297 len = lstrlen (keyword[i]);
00298 *ptr = keyeq[i];
00299 lstrcpy (ptr + 1, ptr + len);
00300 i--;
00301 }
00302 }
00303 }
00304
00305
00306
00307
00308 void LoadGraphMacros (struct BCG *ScilabGC)
00309 {
00310 GFILE *menufile;
00311 BYTE *macroptr;
00312 char *buf;
00313 HMENU hMenu[MENUDEPTH + 1];
00314 int nLine = 1, nInc, i, nMenuLevel, nCountMenu;
00315 HGLOBAL hmacro;
00316
00317 buf = (char *) NULL;
00318 hmacro = 0;
00319 ScilabGC->lpmw.macro = (BYTE **) NULL;
00320 menufile = (GFILE *) NULL;
00321
00322
00323 if ((menufile = Gfopen (ScilabGC->lpgw->szMenuName, OF_READ)) == (GFILE *) NULL)
00324 goto errorcleanup;
00325
00326
00327 if ((buf = LocalAlloc (LPTR, MAXSTR)) == (char *) NULL)
00328 goto nomemory;
00329 hmacro = GlobalAlloc (GHND, (NUMMENU) * sizeof (BYTE *));
00330 if ((ScilabGC->lpmw.macro = (BYTE **) GlobalLock (hmacro)) == (BYTE **) NULL)
00331 goto nomemory;
00332
00333
00334 for (i = 0; i < NUMMENU; i++)
00335 {
00336 ScilabGC->lpmw.macro[i] = (BYTE *) 0;
00337 }
00340 ScilabGC->lpmw.nCountMenu = 0;
00341 ScilabGC->lpmw.nButton = 0;
00342 ScilabGC->lpmw.hMenu = hMenu[0] = CreateMenu ();
00343 nMenuLevel = 0;
00344
00345 while ((nInc = GetLine (buf, MAXSTR, menufile)) != 0)
00346 {
00347 nLine += nInc;
00348 LeftJustify (buf, buf);
00349 if (buf[0] == '\0')
00350 {
00351
00352 }
00353 else if (!lstrcmpi (buf, "[Menu]"))
00354 {
00355
00356 if (!(nInc = GetLine (buf, MAXSTR, menufile)))
00357 {
00358 nLine += nInc;
00359 BUGGOTOCLEAN (MSG_WARNING5);
00360 }
00361 LeftJustify (buf, buf);
00362 if (nMenuLevel < MENUDEPTH)
00363 {
00364 nMenuLevel++;
00365 }
00366 else
00367 {
00368 BUGGOTOCLEAN (MSG_WARNING6);
00369 }
00370 hMenu[nMenuLevel] = CreateMenu ();
00371 AppendMenu (hMenu[nMenuLevel > 0 ? nMenuLevel - 1 : 0],
00372 MF_STRING | MF_POPUP, (UINT) hMenu[nMenuLevel],
00373 (LPCSTR) buf);
00374 }
00375 else if (!lstrcmpi (buf, "[EndMenu]"))
00376 {
00377 if (nMenuLevel > 0)
00378 nMenuLevel--;
00379 }
00380 else
00381 {
00382 nCountMenu = WGFindMenuPos (ScilabGC->lpmw.macro);
00383
00384 if (nCountMenu >= NUMMENU)
00385 {
00386 BUGGOTOCLEAN ( MSG_WARNING7 );
00387 }
00388 LeftJustify (buf, buf);
00389 if (buf[0] == '-')
00390 {
00391 if (nMenuLevel == 0)
00392 AppendMenu (hMenu[0], MF_MENUBREAK, 0, (LPSTR) NULL);
00393 else
00394 AppendMenu (hMenu[nMenuLevel], MF_SEPARATOR, 0, (LPSTR) NULL);
00395 }
00396 else if (buf[0] == '|')
00397 {
00398 AppendMenu (hMenu[nMenuLevel], MF_MENUBARBREAK, 0, (LPSTR) NULL);
00399 }
00400 else
00401 {
00402 AppendMenu (hMenu[nMenuLevel], MF_STRING, nCountMenu, (LPSTR) buf);
00403 ScilabGC->lpmw.nCountMenu++;
00404 if (!(nInc = GetLine (buf, MAXSTR, menufile)))
00405 {
00406 nLine += nInc;
00407 BUGGOTOCLEAN (MSG_WARNING8);
00408 }
00409 LeftJustify (buf, buf);
00410 TranslateMacro (buf);
00411 if ((macroptr = LocalAlloc (LPTR, lstrlen (buf) + 1)) != (BYTE *) NULL)
00412 {
00413 lstrcpy ((char *) macroptr, buf);
00414 }
00415 else
00416 {
00417 BUGGOTOCLEAN (MSG_WARNING9);
00418 }
00419 ScilabGC->lpmw.macro[nCountMenu] = macroptr;
00420 }
00421 }
00422 }
00423 nCountMenu = WGFindMenuPos (ScilabGC->lpmw.macro);
00424 if ((nCountMenu - ScilabGC->lpmw.nButton) > 0)
00425 {
00426
00427 SetMenu (ScilabGC->hWndParent, ScilabGC->lpmw.hMenu);
00428 DrawMenuBar (ScilabGC->hWndParent);
00429 }
00430
00431 goto cleanup;
00432
00433 nomemory:
00434 MessageBox (ScilabGC->hWndParent, MSG_ERROR77,
00435 ScilabGC->lpgw->Title, MB_ICONEXCLAMATION);
00436
00437 errorcleanup:
00438 if (hmacro)
00439 {
00440 for (i = 0; i < NUMMENU; i++)
00441 {
00442 if (ScilabGC->lpmw.macro[i] != (BYTE *) 0)
00443 {
00444 LocalFree (ScilabGC->lpmw.macro[i]);
00445 ScilabGC->lpmw.macro[i] = (BYTE *) 0;
00446 }
00447 }
00448 GlobalUnlock (hmacro);
00449 GlobalFree (hmacro);
00450 ScilabGC->lpmw.macro = (BYTE **) NULL;
00451 }
00452
00453 cleanup:
00454 if (buf != (char *) NULL)
00455 LocalFree (buf);
00456 if (menufile != (GFILE *) NULL)
00457 Gfclose (menufile);
00458 return;
00459 }
00460
00461
00462
00463
00464
00465 int WGFindMenuPos (BYTE ** macros)
00466 {
00467 int i;
00468 for (i = 0; i < NUMMENU; i++)
00469 {
00470 if (macros[i] == (BYTE *) 0)
00471 return (i);
00472 }
00473 return (NUMMENU);
00474 }
00475
00476
00477
00478
00479
00480 void CloseGraphMacros (struct BCG *ScilabGC)
00481 {
00482 int i;
00483 HGLOBAL hglobal;
00484 if (ScilabGC->lpmw.macro != (BYTE **) NULL)
00485 {
00486 hglobal = GlobalHandle (ScilabGC->lpmw.macro);
00487 if (hglobal)
00488 {
00489 for (i = 0; i < NUMMENU; i++)
00490 if (ScilabGC->lpmw.macro[i] != (BYTE *) 0)
00491 {
00492 LocalFree (ScilabGC->lpmw.macro[i]);
00493 ScilabGC->lpmw.macro[i] = (BYTE *) 0;
00494 }
00495 GlobalUnlock (hglobal);
00496 GlobalFree (hglobal);
00497 ScilabGC->lpmw.macro = (BYTE **) NULL;
00498 }
00499 }
00500
00501 if ( ScilabGC->lpmw.szMenuName != NULL )
00502 {
00503 FREE( ScilabGC->lpmw.szMenuName ) ;
00504 ScilabGC->lpmw.szMenuName = NULL ;
00505 }
00506 }
00507
00508
00509
00510
00511
00512 static void ExploreMenu (HMENU hmen, BYTE ** hmacro)
00513 {
00514 int i, is, id, Nums = GetMenuItemCount (hmen);
00515 sciprint ("Nombre d'Items %d\r\n", Nums);
00516 for (i = 0; i < Nums; i++)
00517 {
00518 char buf[256];
00519 HMENU hSubMenu;
00520 hSubMenu = GetSubMenu (hmen, i);
00521 is = GetMenuString (hmen, i, buf, 256, MF_BYPOSITION);
00522 buf[is] = '\0';
00523 sciprint (" submenu %d, [%s]", i, buf);
00524 id = GetMenuItemID (hmen, i);
00525 sciprint (" ID %d\r\n", is);
00526 if (id >= 0 && is != 0)
00527 sciprint ("String %d %s\r\n", id, (char *) hmacro[id]);
00528 if (hSubMenu != NULL)
00529 {
00530 ExploreMenu (hSubMenu, hmacro);
00531 }
00532 }
00533 }
00534
00535
00536
00537
00538
00539
00540
00541 int C2F (setmen) (integer * win_num, char *button_name,
00542 integer * entries, integer * ptrentries,
00543 integer * ne, integer * ierr)
00544 {
00545 struct BCG *ScilabGC;
00546 if (*win_num == -1)
00547 {
00548 SciSetMenu (textwin.lpmw->hMenu, button_name, *ne, MF_ENABLED);
00549 DrawMenuBar (textwin.hWndParent);
00550 }
00551 else
00552 {
00553 ScilabGC = getWindowXgcNumber (*win_num);
00554 if (ScilabGC != (struct BCG *) 0)
00555 {
00556 SciSetMenu (ScilabGC->lpmw.hMenu, button_name, *ne, MF_ENABLED);
00557 DrawMenuBar (ScilabGC->hWndParent);
00558 }
00559 }
00560 return (0);
00561 }
00562
00563 int C2F (unsmen) (integer * win_num, char *button_name, integer * entries,
00564 integer * ptrentries, integer * ne, integer * ierr)
00565 {
00566 struct BCG *ScilabGC;
00567 if (*win_num == -1)
00568 {
00569 SciSetMenu (textwin.lpmw->hMenu, button_name, *ne, MF_GRAYED);
00570 DrawMenuBar (textwin.hWndParent);
00571 }
00572 else
00573 {
00574 ScilabGC = getWindowXgcNumber (*win_num);
00575 if (ScilabGC != (struct BCG *) 0)
00576 {
00577 SciSetMenu (ScilabGC->lpmw.hMenu, button_name, *ne, MF_GRAYED);
00578 DrawMenuBar (ScilabGC->hWndParent);
00579 }
00580 }
00581 return (0);
00582 }
00583
00584 static void SciSetMenu (HMENU hmen, char *name, int num, int flag)
00585 {
00586 int i, is, Nums = GetMenuItemCount (hmen);
00587 for (i = 0; i < Nums; i++)
00588 {
00589 char buf[256], *ptr;
00590 is = GetMenuString (hmen, i, buf, 256, MF_BYPOSITION);
00591 buf[is] = '\0';
00593 if ((ptr = strstr (buf, "&")) != NULL)
00594 lstrcpy (ptr, ptr + 1);
00595 if (strcmp (buf, name) == 0)
00596 {
00597 if (num == 0)
00598 EnableMenuItem (hmen, i, flag | MF_BYPOSITION);
00599 else
00600 {
00601 HMENU hSubMenu;
00602 hSubMenu = GetSubMenu (hmen, i);
00603 if (hSubMenu != NULL)
00604 {
00605 EnableMenuItem (hSubMenu, num - 1, flag | MF_BYPOSITION);
00606 }
00607 }
00608 }
00609 }
00610 }
00611
00612
00613
00614
00615
00616
00617
00618 int C2F (chmenu) (integer * win_num, char *old_name, char *new_name)
00619 {
00620 struct BCG *ScilabGC;
00621 if (*win_num == -1)
00622 {
00623 SciChMenu (textwin.lpmw, old_name, new_name);
00624 DrawMenuBar (textwin.hWndParent);
00625 }
00626 else
00627 {
00628 ScilabGC = getWindowXgcNumber (*win_num);
00629 if (ScilabGC != (struct BCG *) 0)
00630 {
00631 SciChMenu (&(ScilabGC->lpmw), old_name, new_name);
00632 DrawMenuBar (ScilabGC->hWndParent);
00633 }
00634 }
00635 return (0);
00636 }
00637
00638 static void SciChMenu (LPMW lpmw, char *name, char *new_name)
00639 {
00640 int i, is, id, Nums = GetMenuItemCount (lpmw->hMenu);
00641 for (i = 0; i < Nums; i++)
00642 {
00643 char buf[256];
00644 is = GetMenuString (lpmw->hMenu, i, buf, 256, MF_BYPOSITION);
00645 buf[is] = '\0';
00646 if (strcmp (buf, name) == 0)
00647 {
00648 id = GetMenuItemID (lpmw->hMenu, i);
00649 ModifyMenu (lpmw->hMenu, i, MF_BYPOSITION | MF_STRING, id, new_name);
00650 }
00651 }
00652 }
00653
00654
00655
00656
00657
00658 int C2F (delbtn) (integer * win_num, char *button_name)
00659 {
00660 struct BCG *ScilabGC;
00661 if (*win_num == -1)
00662 {
00663 SciDelMenu (textwin.lpmw, button_name);
00664 DrawMenuBar (textwin.hWndParent);
00665 }
00666 else
00667 {
00668 ScilabGC = getWindowXgcNumber (*win_num);
00669 if (ScilabGC != (struct BCG *) 0)
00670 {
00671 SciDelMenu (&(ScilabGC->lpmw), button_name);
00672 DrawMenuBar (ScilabGC->hWndParent);
00673 }
00674 }
00675 return (0);
00676 }
00677
00678 static void SciDelMenu (LPMW lpmw, char *name)
00679 {
00680 int i, is, id, Nums = GetMenuItemCount (lpmw->hMenu);
00681 for (i = 0; i < Nums; i++)
00682 {
00683 char buf[256];
00684 is = GetMenuString (lpmw->hMenu, i, buf, 256, MF_BYPOSITION);
00685 buf[is] = '\0';
00686 if (strcmp (buf, name) == 0)
00687 {
00688 int j, Nums1;
00689 HMENU hSubMenu;
00690 hSubMenu = GetSubMenu (lpmw->hMenu, i);
00691 if (hSubMenu != NULL)
00692 {
00693 Nums1 = GetMenuItemCount (hSubMenu);
00694 for (j = 0; j < Nums1; j++)
00695 {
00696 id = GetMenuItemID (hSubMenu, j);
00698 if (id < 0 || is == 0)
00699 continue;
00707 if (lpmw->macro[id] != (BYTE *) 0)
00708 {
00709 LocalFree (lpmw->macro[id]);
00710 lpmw->macro[id] = (BYTE *) 0;
00711 }
00712 }
00713 }
00714 else
00715 {
00716 id = GetMenuItemID (lpmw->hMenu, i);
00718 if (id < 0 || is == 0)
00719 continue;
00727 if (lpmw->macro[id] != (BYTE *) 0)
00728 {
00729 LocalFree (lpmw->macro[id]);
00730 lpmw->macro[id] = (BYTE *) 0;
00731 }
00732 }
00733 DeleteMenu (lpmw->hMenu, i, MF_BYPOSITION);
00734 return;
00735 }
00736 }
00737 }
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751 void AddMenu (integer * win_num, char *button_name, char **entries,
00752 integer * ne, integer * typ, char *fname, integer * ierr)
00753 {
00754 BYTE *macroptr;
00755 struct BCG *ScilabGC;
00756 HWND hwnd;
00757 LPMW lpmw;
00758 int number, nCountMenu;
00759 number = *win_num;
00760 if (*win_num == -1)
00761 {
00762 lpmw = textwin.lpmw;
00763 hwnd = textwin.hWndParent;
00764 nCountMenu = WGFindMenuPos (lpmw->macro);
00765 if (nCountMenu >= NUMMENU)
00766 {
00767 sciprint (MSG_WARNING10);
00768 return;
00769 }
00770 }
00771 else
00772 {
00773 ScilabGC = getWindowXgcNumber (*win_num);
00774 if (ScilabGC != (struct BCG *) 0)
00775 {
00776 lpmw = &(ScilabGC->lpmw);
00777 hwnd = ScilabGC->hWndParent;
00778 nCountMenu = WGFindMenuPos (lpmw->macro);
00779 if (nCountMenu >= NUMMENU)
00780 {
00781 sciprint (MSG_WARNING11,*win_num);
00782 return;
00783 }
00784 }
00785 else return;
00786 }
00787
00788 if (*ne == 0)
00789 {
00790 AppendMenu (lpmw->hMenu, MF_STRING, nCountMenu, button_name);
00791 if ((macroptr = LocalAlloc (LPTR, lstrlen ("@%dexecstr(%s_%d(%d))")+ lstrlen (fname) + 1)) != (BYTE *) NULL)
00792 {
00793 if (*win_num < 0)
00794 if (*typ==0)
00795 sprintf ((char *) macroptr, "@%dexecstr(%s(%d))", *typ, fname, 1);
00796 else
00797 if (*typ==2) sprintf ((char *) macroptr, "@0%s(%d,%d)",fname, 1,*win_num);
00798 else sprintf ((char *) macroptr, "@%dexecstr(%s(%d))", *typ,fname, 1);
00799 else
00800 if (*typ==0) sprintf ((char *) macroptr, "@0execstr(%s_%d(%d))",fname, *win_num, 1);
00801 else
00802 if (*typ==2) sprintf ((char *) macroptr, "@0%s(%d,%d)",fname, 1,*win_num);
00803 else sprintf ((char *) macroptr, "@%dexecstr(%s_%d(%d))", *typ,fname, *win_num, 1);
00804 }
00805 else
00806 {
00807 sciprint (MSG_WARNING12);
00808 return;
00809 }
00810
00811 lpmw->macro[nCountMenu] = macroptr;
00812 }
00813 else
00814 {
00815 int i=0;
00816 int j=0;
00817 HMENU hMenu;
00818 hMenu = CreateMenu ();
00819
00820
00821 AppendMenu (lpmw->hMenu, MF_STRING | MF_POPUP, (UINT) hMenu, button_name);
00822 for (i = 0; i < *ne; i++)
00823 {
00824
00825 nCountMenu = WGFindMenuPos (lpmw->macro);
00826 if (nCountMenu >= NUMMENU)
00827 {
00828 sciprint (MSG_WARNING13);
00829 return;
00830 }
00831 if ( strcmp("[--]",entries[i])==0 )
00832 {
00833 AppendMenu (hMenu, MF_SEPARATOR, 0, (LPSTR) NULL);
00834 }
00835 else
00836 {
00837 AppendMenu (hMenu, MF_STRING, nCountMenu, entries[i]);
00838 if ((macroptr = LocalAlloc (LPTR, lstrlen ("@%dexecstr(%s_%d(%d))")+ lstrlen (fname) + 1)) != (BYTE *) NULL)
00839 {
00840 if (*win_num < 0)
00841 if (*typ==0)
00842 sprintf ((char *) macroptr, "@%dexecstr(%s(%d))", *typ, fname, j + 1);
00843 else
00844 if (*typ==2) sprintf ((char *) macroptr, "@0%s(%d)",fname, j + 1);
00845 else sprintf ((char *) macroptr, "@%dexecstr(%s(%d))", *typ,fname, j + 1);
00846 else
00847 if (*typ==0) sprintf ((char *) macroptr, "@0execstr(%s_%d(%d))",fname, *win_num, j + 1);
00848 else
00849 if (*typ==2) sprintf ((char *) macroptr, "@0%s(%d,%d)",fname, j + 1,*win_num);
00850 else sprintf ((char *) macroptr, "@%dexecstr(%s_%d(%d))", *typ,fname, *win_num, j + 1);
00851 j++;
00852 }
00853 else
00854 {
00855 sciprint (MSG_WARNING14);
00856 return;
00857 }
00858 lpmw->macro[nCountMenu] = macroptr;
00859 }
00860 }
00861 }
00862 DrawMenuBar (hwnd);
00863 }
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879 int C2F (addmen) (integer * win_num, char *button_name, integer * entries,
00880 integer * ptrentries, integer * ne, integer * typ, char *fname,
00881 integer * ierr)
00882 {
00883 char **menu_entries;
00884 menu_entries=NULL;
00885 *ierr = 0;
00886 if (*ne != 0)
00887 {
00888 ScilabMStr2CM (entries, ne, ptrentries, &menu_entries, ierr);
00889 if (*ierr == 1)
00890 return (0);
00891 }
00892
00893
00894 if ( (strcmp(button_name,"RESETMENU")==0) && (*win_num==-1) )
00895 {
00896 ResetMenu();
00897 }
00898 else AddMenu (win_num, button_name, menu_entries, ne, typ, fname, ierr);
00899 return (0);
00900 }
00901
00902
00903
00904 static void scig_command_scilabgc (int number, void f (struct BCG *))
00905 {
00906 struct BCG *ScilabGC = getWindowXgcNumber (number);
00907 if (ScilabGC != NULL && ScilabGC->CWindow && IsWindow (ScilabGC->CWindow))
00908 f (ScilabGC);
00909 }
00910
00911 void scig_h_copyclip (integer number)
00912 {
00913 scig_command_scilabgc (number, CopyToClipboardEMF);
00914 }
00915
00916 void scig_h_copyclip1 (integer number)
00917 {
00918 scig_command_scilabgc (number, CopyToClipboardBitmap);
00919 }
00920
00921 void scig_print (integer number)
00922 {
00923 scig_command_scilabgc (number, PrintPs);
00924 }
00925
00926 void scig_export (integer number)
00927 {
00928 scig_command_scilabgc (number, SavePs);
00929 }
00930
00931 void UpdateFileGraphNameMenu(struct BCG *ScilabGC)
00932 {
00933 #define FILEGRAPHMENUFRENCH "wgscilabF.mnu"
00934 #define FILEGRAPHMENUENGLISH "wgscilabE.mnu"
00935 extern char ScilexWindowName[MAX_PATH];
00936 char *ScilabDirectory=NULL;
00937
00938 HWND hWndTmpScilex=FindWindow(NULL,ScilexWindowName);
00939 int LangCode=0;
00940
00941 if (IsWindowInterface())
00942 {
00943 if (hWndTmpScilex)
00944 {
00945 LPTW lptw=GetTextWinScilab();
00946 LangCode=lptw->lpmw->CodeLanguage;
00947 }
00948 else LangCode=0;
00949 }
00950 else LangCode=0;
00951 ScilabGC->lpmw.CodeLanguage=LangCode;
00952
00953 ScilabDirectory=GetScilabDirectory(FALSE);
00954
00955 if (ScilabGC->lpgw->szMenuName!=NULL) FREE(ScilabGC->lpgw->szMenuName);
00956 ScilabGC->lpgw->szMenuName = (LPSTR) MALLOC (strlen (ScilabDirectory) +strlen("\\bin\\")+ strlen (FILEGRAPHMENUENGLISH) + 1);
00957
00958 switch (LangCode)
00959 {
00960 case 1:
00961 wsprintf(ScilabGC->lpgw->szMenuName,"%s\\bin\\%s",ScilabDirectory, FILEGRAPHMENUFRENCH);
00962 break;
00963 default : case 0:
00964 wsprintf(ScilabGC->lpgw->szMenuName,"%s\\bin\\%s",ScilabDirectory, FILEGRAPHMENUENGLISH);
00965 break;
00966 }
00967
00968 if (ScilabDirectory){FREE(ScilabDirectory);ScilabDirectory=NULL;}
00969 }
00970
00971 void NewFigure(struct BCG * ScilabGC)
00972 {
00973
00974 char Command[MAX_PATH];
00975 int FreeWindow=0;
00976
00977 FreeWindow=FindFreeGraphicWindow(ScilabGC);
00978 wsprintf(Command,"xset(\"window\",%d);",FreeWindow);
00979 StoreCommand1(Command,0);
00980
00981 }
00982
00983
00984
00985 int FindFreeGraphicWindow(struct BCG * ScilabGC)
00986 {
00987 int FreeNumber=-1;
00988 integer iflag =0,ids,num,un=1;
00989
00990 integer *tab=NULL;
00991 int sizetab=0;
00992 int i=0;
00993
00994 iflag = 0;
00995 getWins(&num,&ids ,&iflag);
00996 sizetab=num;
00997
00998 tab=(integer*)MALLOC(sizeof(integer)*sizetab);
00999 for(i=0;i<sizetab;i++) tab[i]=0;
01000
01001 iflag = 1;
01002 getWins(&num,tab,&iflag);
01003
01004 for(i=0;i<sizetab;i++)
01005 {
01006 if(FreeNumber<tab[i]) FreeNumber=tab[i];
01007 }
01008 FreeNumber=FreeNumber+1;
01009 FREE(tab);
01010 return FreeNumber;
01011 }
01012
01013 void RefreshMenus(struct BCG * ScilabGC)
01014 {
01015
01016 int WinNum=ScilabGC->CurWindow;
01017 BOOL LockToolBar=ScilabGC->lpmw.LockToolBar;
01018 int nButton=ScilabGC->lpmw.nButton;
01019 BOOL StateToolBar=ScilabGC->lpmw.ShowToolBar;
01020
01021 DestroyMenu(GetMenu(ScilabGC->hWndParent));
01022 ScilabGC->hMenuRoot=NULL;
01023 ScilabGC->IDM_Count=1;
01024 SetMenu(ScilabGC->hWndParent,NULL);
01025
01026 CloseGraphMacros (ScilabGC);
01027 CreateGedMenus(ScilabGC);
01028
01029 ScilabGC->lpmw.nButton=nButton;
01030 ScilabGC->lpmw.ShowToolBar=StateToolBar;
01031 ScilabGC->lpmw.LockToolBar=LockToolBar;
01032
01033 }
01034
01035 void CreateGedMenus(struct BCG * ScilabGC)
01036 {
01037 int WinNum=ScilabGC->CurWindow;
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047 #ifdef WITH_TK
01048 integer ne=14, menutyp=2, ierr;
01049 char *EditMenusE[]={"&Select figure as current","&Redraw figure","&Erase figure","[--]","&Copy object","&Paste object","Move object","Delete object","[--]","Figure properties","Current &axes properties","[--]",MSG_SCIMSG116,MSG_SCIMSG117};
01050 char *EditMenusF[]={"&Selectionner figure comme courante","&Redessiner figure","[--]","&Effacer figure","Copier objet","Coller objet","D�placer objet","D�truire objet","[--]","Propri�t�s de la &figure","Propri�t�s des &axes courants","[--]",MSG_SCIMSG118,MSG_SCIMSG119};
01051
01052
01053 integer ni=6;
01054 char *InsertMenusE[]={"&Line","&Polyline","&Arrow","&Text","&Rectangle","&Circle"};
01055 char *InsertMenusF[]={"&Ligne","L&igne bris�e","&Fleche","&Texte","&Rectangle","&Cercle"};
01056 #else
01057 integer ne=3, menutyp=2, ierr;
01058 char *EditMenusE[]={"&Select figure","&Redraw figure","&Erase figure"};
01059 char *EditMenusF[]={"&Selectionner figure","&Redessiner figure","&Effacer figure"};
01060 #endif
01061
01062 UpdateFileGraphNameMenu(ScilabGC);
01063 LoadGraphMacros(ScilabGC);
01064
01065 switch( ScilabGC->lpmw.CodeLanguage)
01066 {
01067 case 1:
01068 AddMenu(&WinNum,"&Editer", EditMenusF, &ne, &menutyp, "ged", &ierr);
01069 #ifdef WITH_TK
01070
01071 #endif
01072 break;
01073 default:
01074 AddMenu(&WinNum,"&Edit", EditMenusE, &ne, &menutyp, "ged", &ierr);
01075 #ifdef WITH_TK
01076
01077 #endif
01078 break;
01079 }
01080
01081 }
01082
01083 BOOL SendMacroEntityPicker(struct BCG * ScilabGC,int id)
01084 {
01085 BOOL bOK=FALSE;
01086 char command[1024];
01087
01088 if (IsEntityPickerMenu(ScilabGC,id))
01089 {
01090 if (id == 23)
01091 {
01092 wsprintf(command,"ged(10,%d);",ScilabGC->CurWindow);
01093 ModifyEntityPickerToolbar(ScilabGC,TRUE);
01094 StoreCommand(command);
01095 bOK=TRUE;
01096 }
01097
01098 if (id == 24)
01099 {
01100 wsprintf(command,"ged(11,%d);",ScilabGC->CurWindow);
01101 ModifyEntityPickerToolbar(ScilabGC,FALSE);
01102 StoreCommand(command);
01103 bOK=TRUE;
01104 }
01105 }
01106
01107 return bOK;
01108 }
01109
01110 BOOL IsEntityPickerMenu(struct BCG * ScilabGC,int id)
01111 {
01112 BOOL bOK=FALSE;
01113 if (id == 23)
01114 {
01115 #define lenStringMenu 64
01116 char CurrentStringMenu[lenStringMenu];
01117 GetMenuString(ScilabGC->lpmw.hMenu,id,CurrentStringMenu,lenStringMenu-1,MF_BYCOMMAND);
01118 switch (ScilabGC->lpmw.CodeLanguage)
01119 {
01120 case 1:
01121 if (strcmp(CurrentStringMenu,MSG_SCIMSG118)==0) bOK=TRUE;
01122 break;
01123
01124 case 0: default:
01125 if (strcmp(CurrentStringMenu,MSG_SCIMSG116)==0) bOK=TRUE;
01126 break;
01127 }
01128 }
01129
01130 if (id == 24)
01131 {
01132 #define lenStringMenu 64
01133 char CurrentStringMenu[lenStringMenu];
01134 GetMenuString(ScilabGC->lpmw.hMenu,id,CurrentStringMenu,lenStringMenu-1,MF_BYCOMMAND);
01135 switch (ScilabGC->lpmw.CodeLanguage)
01136 {
01137 case 1:
01138 if (strcmp(CurrentStringMenu,MSG_SCIMSG119)==0) bOK=TRUE;
01139 break;
01140
01141 case 0: default:
01142 if (strcmp(CurrentStringMenu,MSG_SCIMSG117)==0) bOK=TRUE;
01143 break;
01144 }
01145 }
01146
01147 return bOK;
01148 }
01149