00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma comment(lib, "shell32.lib")
00025 #include <ShlObj.h>
00026 #include <Windowsx.h>
00027 #include "wmenu.h"
00028
00029 #include "Messages.h"
00030 #include "Warnings.h"
00031 #include "Errors.h"
00032 #include "periScreen.h"
00033
00034 #include "win_mem_alloc.h"
00035 #include "setgetSCIpath.h"
00036
00037 #ifndef STRICT
00038 #define STRICT
00039 #endif
00040
00041 #define putenv _putenv
00042
00043 extern HINSTANCE hdllInstance;
00044 extern HDC TryToGetDC(HWND hWnd);
00045
00046 extern void SwitchConsole(void);
00047
00048 extern void ClearCommandWindow(LPTW lptw,BOOL Clearfirstline);
00049 extern void reset_history(void);
00050 extern void HideGraphToolBar(struct BCG * ScilabGC);
00051 extern void ShowGraphToolBar(struct BCG * ScilabGC);
00052 extern void SaveCurrentLine(BOOL RewriteLineAtPrompt);
00053 extern void GetCurrentPrompt(char *CurrentPrompt);
00054 extern BOOL ConvertPathUnixToWindowsFormat(char *pathunix,char *pathwindows);
00055 extern char *GetScilabDirectory(BOOL UnixStyle);
00056 extern DWORD GetIhmTextBackgroundColor(void);
00057 extern void InitIhmDefaultColor(void);
00058 extern DWORD GetIhmTextColor(void);
00059 extern BOOL SetIhmSystemDefaultTextBackgroundColor(void);
00060 extern BOOL SetIhmSystemDefaultTextColor(void);
00061 extern BOOL ConfigurePrinterDialogBox(void);
00062 extern BOOL ChooseColorBox(int *R,int *G,int *B);
00063 extern BOOL SetIhmTextBackgroundColor(int R,int G,int B,BOOL Refresh);
00064 extern BOOL SetIhmTextColor(int R,int G,int B,BOOL Refresh);
00065 extern LPTW GetTextWinScilab(void);
00066 extern BOOL IsEmptyClipboard(LPTW lptw);
00067 extern void PasteFunction(LPTW lptw,BOOL special);
00068 extern BOOL IsAFile(char *chainefichier);
00069 extern BOOL IsWindowInterface(void);
00070 extern void AddHistory (char *line);
00071 extern void GetCommentDateSession(char *line,int BeginSession);
00072 extern void WINAPI FilesAssociationBox (HWND hwnd);
00073
00074 static integer lab_count = 0;
00075 static char gwin_name[100], gwin_name1[100];
00076 static void Countp ();
00077 static void Countm ();
00078 static void SendCountDelete ();
00079
00080
00081 void Callback_NEWSCILAB(void)
00082 {
00083 STARTUPINFO start;
00084 SECURITY_ATTRIBUTES sec_attrs;
00085 PROCESS_INFORMATION child;
00086 char ScilexName[MAX_PATH];
00087
00088 char *VarEnvironmnt=NULL;
00089 extern char ScilexWindowName[MAX_PATH];
00090
00091 GetModuleFileName (NULL,ScilexName, MAX_PATH);
00092
00093 memset (&start, 0, sizeof (start));
00094 start.cb = sizeof (start);
00095 start.dwFlags = STARTF_USESHOWWINDOW;
00096 start.wShowWindow = SW_SHOWMINIMIZED;
00097 sec_attrs.nLength = sizeof (sec_attrs);
00098 sec_attrs.lpSecurityDescriptor = NULL;
00099 sec_attrs.bInheritHandle = FALSE;
00100
00101
00102 VarEnvironmnt=(char*)MALLOC((strlen("SCILAB_CREATOR=")+strlen(ScilexWindowName)+1)*sizeof(char));
00103 wsprintf(VarEnvironmnt,"SCILAB_CREATOR=%s",ScilexWindowName);
00104 putenv(VarEnvironmnt);
00105 if (VarEnvironmnt)
00106 {
00107 FREE(VarEnvironmnt);
00108 VarEnvironmnt=NULL;
00109 }
00110
00111 if (CreateProcess (ScilexName,"",&sec_attrs, NULL, FALSE, CREATE_NEW_CONSOLE,NULL, NULL, &start, &child))
00112 {
00113 CloseHandle (child.hThread);
00114 CloseHandle (child.hProcess);
00115 }
00116 else MessageBox(NULL,MSG_WARNING23,MSG_WARNING22,MB_ICONWARNING);
00117 }
00118
00119 void Callback_OPEN(void)
00120 {
00121 char File[MAX_PATH];
00122 char ShortFile[MAX_PATH];
00123 char command[MAX_PATH];
00124 char TitleText[32];
00125
00126 LPTW lptw=GetTextWinScilab();
00127
00128
00129 switch (lptw->lpmw->CodeLanguage)
00130 {
00131 case 1:
00132 strcpy(TitleText,MSG_SCIMSG32);
00133 break;
00134 case 0:default:
00135 strcpy(TitleText,MSG_SCIMSG33);
00136 break;
00137 }
00138
00139 if ( OpenSaveSCIFile(lptw->hWndParent,TitleText,TRUE,"Files *.sce;*.sci\0*.sci;*.sce\0Files *.sci\0*.sci\0Files *.sce\0*.sce\0All *.*\0*.*\0",File) == TRUE)
00140 {
00141 extern BOOL PutLineInBuffer;
00142 char CommandBis[512];
00143 GetShortPathName(File,ShortFile,MAX_PATH);
00144 wsprintf(command,"%cscipad('%s');",CTRLU,ShortFile);
00145 wsprintf(CommandBis,"scipad('%s');",ShortFile);
00146
00147 PutLineInBuffer=FALSE;
00148 if (IsToThePrompt ()) StoreCommand1(command,1);
00149 else StoreCommand(CommandBis);
00150 PutLineInBuffer=FALSE;
00151
00152 }
00153 }
00154
00155 void Callback_EXEC(void)
00156 {
00157 char Fichier[MAX_PATH];
00158 char command[MAX_PATH];
00159
00160 LPTW lptw=GetTextWinScilab();
00161
00162 _try {
00163 if ( OpenSaveSCIFile(lptw->hWndParent,"Exec",TRUE,"Files *.sce;*.sci\0*.sci;*.sce\0Files *.sci\0*.sci\0Files *.sce\0*.sce\0All *.*\0*.*\0",Fichier) == TRUE)
00164 {
00165 SendCTRLandAKey(CTRLU);
00166 wsprintf(command,MSG_SCIMSG34,Fichier);
00167 StoreCommand1 (command,1);
00168 }
00169 }
00170 _except (EXCEPTION_EXECUTE_HANDLER)
00171 {
00172
00173 }
00174
00175
00176 }
00177
00178 void Callback_GETF(void)
00179 {
00180 char Fichier[MAX_PATH];
00181 char command[MAX_PATH];
00182
00183 LPTW lptw=GetTextWinScilab();
00184
00185 if ( OpenSaveSCIFile(lptw->hWndParent,"Getf",TRUE,"Files *.sci\0*.sci\0All *.*\0*.*\0",Fichier) == TRUE)
00186 {
00187 SendCTRLandAKey(CTRLU);
00188 wsprintf(command,MSG_SCIMSG35,Fichier);
00189 StoreCommand1 (command,1);
00190 }
00191 }
00192
00193 void Callback_LOAD(void)
00194 {
00195 char Fichier[MAX_PATH];
00196 char command[MAX_PATH];
00197
00198 LPTW lptw=GetTextWinScilab();
00199
00200 if ( OpenSaveSCIFile(lptw->hWndParent,"Load",TRUE,"Files *.sav;*.bin\0*.sav;*.bin\0Files *.sav\0*.sav\0Files *.bin\0*.bin\0All *.*\0*.*\0",Fichier) == TRUE)
00201 {
00202 SendCTRLandAKey(CTRLU);
00203 wsprintf(command,MSG_SCIMSG36,Fichier);
00204 StoreCommand1 (command,1);
00205 }
00206 }
00207
00208 void Callback_SAVE(void)
00209 {
00210 char Fichier[MAX_PATH];
00211 char command[MAX_PATH];
00212
00213 LPTW lptw=GetTextWinScilab();
00214
00215 if (OpenSaveSCIFile(lptw->hWndParent,"Save",FALSE,"Files *.sav\0*.sav\0Files *.bin\0*.bin\0All *.*\0*.*\0",Fichier) == TRUE)
00216 {
00217 SendCTRLandAKey(CTRLU);
00218 wsprintf(command,MSG_SCIMSG37,Fichier);
00219 StoreCommand1 (command,1);
00220 }
00221 }
00222
00223 void Callback_CHDIR(void)
00224 {
00225 #define NumberCharByLineInChdirBox 56
00226 BROWSEINFO InfoBrowserDirectory;
00227 char Path[MAX_PATH];
00228 char PathToDisplay[MAX_PATH*2];
00229 char command[MAX_PATH];
00230 char TextPath[MAX_PATH*2];
00231
00232 LPITEMIDLIST pidl;
00233
00234 LPTW lptw=GetTextWinScilab();
00235
00236 GetCurrentDirectory(MAX_PATH,Path);
00237 CutLineForDisplay(PathToDisplay,Path,NumberCharByLineInChdirBox);
00238 InfoBrowserDirectory.hwndOwner = lptw->hWndParent;
00239 InfoBrowserDirectory.pidlRoot = NULL;
00240 switch (lptw->lpmw->CodeLanguage)
00241 {
00242 case 1:
00243 if (lstrlen(Path) < NumberCharByLineInChdirBox)
00244 {
00245 wsprintf(TextPath,"%s\n\n%s",MSG_SCIMSG38,PathToDisplay);
00246 }
00247 else
00248 {
00249 if ( lstrlen(Path) > (NumberCharByLineInChdirBox*2) )
00250 {
00251 wsprintf(TextPath,"%s",MSG_SCIMSG38);
00252 }
00253 else
00254 wsprintf(TextPath,"%s\n%s",MSG_SCIMSG38,PathToDisplay);
00255 }
00256 break;
00257
00258 case 0:default:
00259 if (lstrlen(Path)<NumberCharByLineInChdirBox)
00260 {
00261 wsprintf(TextPath,"%s\n\n%s",MSG_SCIMSG39,PathToDisplay);
00262 }
00263 else
00264 {
00265 if ( lstrlen(Path) > (NumberCharByLineInChdirBox*2) )
00266 {
00267 wsprintf(TextPath,"%s",MSG_SCIMSG39);
00268 }
00269 else
00270 wsprintf(TextPath,"%s\n%s",MSG_SCIMSG39,PathToDisplay);
00271 }
00272 break;
00273 }
00274
00275 InfoBrowserDirectory.lpszTitle=TextPath;
00276 InfoBrowserDirectory.pszDisplayName=Path;
00277 InfoBrowserDirectory.ulFlags = BIF_STATUSTEXT|BIF_RETURNONLYFSDIRS;
00278 InfoBrowserDirectory.lpfn =NULL;
00279
00280
00281 pidl=SHBrowseForFolder(&InfoBrowserDirectory);
00282 if (pidl!=NULL)
00283 {
00284 SHGetPathFromIDList(pidl, Path);
00285 SendCTRLandAKey(CTRLU);
00286 wsprintf(command,"chdir('%s');",Path);
00287 StoreCommand1 (command,1);
00288
00289 }
00290
00291 }
00292
00293 void Callback_GETCWD(void)
00294 {
00295 char *command=NULL;
00296 if (IsToThePrompt())
00297 {
00298 char save_prompt[10];
00299 SendCTRLandAKey(CTRLU);
00300 GetCurrentPrompt(save_prompt);
00301 command=(char*)MALLOC((strlen("printf('\n\n %%s\n\n%s',getcwd())")+strlen(save_prompt))*sizeof(char));
00302 wsprintf(command,"printf('\n\n %%s\n\n%s',getcwd())",save_prompt);
00303 }
00304 else
00305 {
00306 command=(char*)MALLOC((strlen("printf('\n\n %%s\n\n%s',getcwd())"))*sizeof(char));
00307 wsprintf(command,"printf('\n\n %%s\n\n',getcwd())");
00308 }
00309
00310 StoreCommand (command);
00311 if (command) { FREE(command);command=NULL; }
00312
00313 }
00314
00315 void Callback_MCOPY(void)
00316 {
00317 LPTW lptw=GetTextWinScilab();
00318
00319 if ( HasAZoneTextSelected(lptw) == TRUE )TextCopyClip (lptw);
00320 else
00321 {
00322 if (lptw->lpmw->CodeLanguage == 0)
00323 {
00324 MessageBox(lptw->hWndParent,MSG_SCIMSG40,MSG_SCIMSG42,MB_ICONINFORMATION);
00325 }
00326 else
00327 {
00328 MessageBox(lptw->hWndParent,MSG_SCIMSG41,MSG_SCIMSG42,MB_ICONINFORMATION);
00329 }
00330 }
00331 }
00332
00333 void Callback_PASTE(void)
00334 {
00335 LPTW lptw=GetTextWinScilab();
00336
00337 if ( !IsEmptyClipboard(lptw) ) PasteFunction(lptw,FALSE);
00338 else
00339 {
00340 if (lptw->lpmw->CodeLanguage == 0)
00341 {
00342 MessageBox(lptw->hWndParent,MSG_SCIMSG43,MSG_SCIMSG42,MB_ICONINFORMATION);
00343 }
00344 else
00345 {
00346 MessageBox(lptw->hWndParent,MSG_SCIMSG44,MSG_SCIMSG42,MB_ICONINFORMATION);
00347 }
00348 }
00349 }
00350
00351 void Callback_PRINTSETUP(void)
00352 {
00353 ConfigurePrinterDialogBox();
00354 }
00355
00356 void Callback_PRINT(void)
00357 {
00358 LPTW lptw=GetTextWinScilab();
00359 SelectAll(lptw,FALSE);
00360 TextCopyClip (lptw);
00361 UnSelect(lptw);
00362
00363
00364 if (lptw->lpmw->CodeLanguage == 0)
00365 {
00366 PrintSelectionGUI(lptw,MSG_SCIMSG44);
00367 }
00368 else
00369 {
00370 PrintSelectionGUI(lptw,MSG_SCIMSG45);
00371 }
00372 }
00373
00374 void Callback_TOOLBAR(void)
00375 {
00376 LPTW lptw=GetTextWinScilab();
00377
00378 if (lptw->lpmw->LockToolBar == FALSE)
00379 {
00380 lptw->lpmw->ShowToolBar=!lptw->lpmw->ShowToolBar;
00381 ToolBarOnOff(lptw);
00382 }
00383 }
00384
00385 void Callback_FRENCH(void)
00386 {
00387 LPTW lptw=GetTextWinScilab();
00388
00389 if (lptw->lpmw->CodeLanguage!=1)
00390 {
00391 StoreCommand1 ("setlanguage('fr');",0);
00392 }
00393 }
00394
00395 void Callback_ENGLISH(void)
00396 {
00397 LPTW lptw=GetTextWinScilab();
00398
00399 if (lptw->lpmw->CodeLanguage!=0)
00400 {
00401 StoreCommand1 ("setlanguage('en');",0);
00402 }
00403 }
00404
00405 void Callback_TEXTCOLOR(void)
00406 {
00407 int R,G,B;
00408
00409 R=GetRValue(GetIhmTextColor());
00410 G=GetGValue(GetIhmTextColor());
00411 B=GetBValue(GetIhmTextColor());
00412
00413 if (ChooseColorBox(&R,&G,&B))
00414 {
00415 LPTW lptw=GetTextWinScilab();
00416
00417 SetIhmTextColor(R,G,B,TRUE);
00418 lptw->bSysColors=0;
00419 }
00420 }
00421
00422 void Callback_BACKGROUNDCOLOR(void)
00423 {
00424 int R,G,B;
00425
00426 R=GetRValue(GetIhmTextBackgroundColor());
00427 G=GetGValue(GetIhmTextBackgroundColor());
00428 B=GetBValue(GetIhmTextBackgroundColor());
00429
00430 if (ChooseColorBox(&R,&G,&B))
00431 {
00432 LPTW lptw=GetTextWinScilab();
00433
00434 SetIhmTextBackgroundColor(R,G,B,TRUE);
00435 lptw->bSysColors=0;
00436 }
00437 }
00438
00439 void Callback_SYSTEMCOLOR(void)
00440 {
00441 LPTW lptw=GetTextWinScilab();
00442
00443 lptw->bSysColors=1;
00444 SetIhmSystemDefaultTextColor();
00445 SetIhmSystemDefaultTextBackgroundColor();
00446 }
00447
00448 void Callback_FILESASSOCIATIONBOX(void)
00449 {
00450 if (IsWindowInterface())
00451 {
00452 LPTW lptw=GetTextWinScilab();
00453 FilesAssociationBox(lptw->hWndParent);
00454 }
00455 else
00456 {
00457 FilesAssociationBox(NULL);
00458 }
00459 }
00460
00461 void Callback_CHOOSETHEFONT(void)
00462 {
00463 LPTW lptw=GetTextWinScilab();
00464
00465 TextSelectFont (lptw);
00466 }
00467
00468 void Callback_RESTART(void)
00469 {
00470 LPTW lptw=GetTextWinScilab();
00471
00472 SendCTRLandAKey(CTRLU);
00473
00474 ClearCommandWindow(lptw,TRUE);
00475
00476 SendCTRLandAKey(CTRLU);
00477 StoreCommand1("abort;",1);
00478
00479 SendCTRLandAKey(CTRLU);
00480 StoreCommand1("savehistory();",1);
00481
00482 SendCTRLandAKey(CTRLU);
00483 StoreCommand1("resethistory();",1);
00484
00485 SendCTRLandAKey(CTRLU);
00486 write_scilab("exec('SCI/etc/scilab.start',-1);\n");
00487 }
00488
00489 void Callback_ABORT(void)
00490 {
00491 SendCTRLandAKey(CTRLU);
00492 StoreCommand1("abort;",1);
00493 }
00494
00495 void Callback_PAUSE(void)
00496 {
00497 SendCTRLandAKey(CTRLU);
00498 StoreCommand1("pause;",1);
00499 }
00500
00501 void Callback_RESUME(void)
00502 {
00503 SendCTRLandAKey(CTRLU);
00504 StoreCommand1("resume;",1);
00505
00506 }
00507
00508 void Callback_CONSOLE(void)
00509 {
00510 SwitchConsole();
00511 }
00512
00513 void Callback_SCIPAD(void)
00514 {
00515 char Command[512];
00516 extern BOOL PutLineInBuffer;
00517 wsprintf(Command,"%cscipad();",CTRLU);
00518
00519 PutLineInBuffer=FALSE;
00520 if (IsToThePrompt ()) StoreCommand1(Command,1);
00521 else StoreCommand("scipad();");
00522 PutLineInBuffer=FALSE;
00523 }
00524
00525 void Callback_HELP(void)
00526 {
00527 char Command[512];
00528 extern BOOL PutLineInBuffer;
00529 wsprintf(Command,"%chelp();",CTRLU);
00530
00531 PutLineInBuffer=FALSE;
00532 if (IsToThePrompt ()) StoreCommand1(Command,1);
00533 else StoreCommand("help();");
00534 PutLineInBuffer=FALSE;
00535 }
00536
00537 void Callback_DEMOS(void)
00538 {
00539 LPTW lptw=GetTextWinScilab();
00540
00541 SendCTRLandAKey(CTRLU);
00542 WriteIntoScilab(lptw,"scilab_demos();");
00543 }
00544
00545 void Callback_WEB(void)
00546 {
00547 int error =(int)ShellExecute(NULL, "open", URL, NULL, NULL, SW_SHOWNORMAL);
00548 if (error<= 32) MessageBox(NULL,MSG_WARNING24,MSG_WARNING22,MB_ICONWARNING);
00549 }
00550
00551 void Callback_CONTRIBUTIONS(void)
00552 {
00553 int error =(int)ShellExecute(NULL, "open", URLCONTRIBUTIONS, NULL, NULL, SW_SHOWNORMAL);
00554 if (error<= 32) MessageBox(NULL,MSG_WARNING24,MSG_WARNING22,MB_ICONWARNING);
00555 }
00556
00557 void Callback_BUGZILLA(void)
00558 {
00559 int error =(int)ShellExecute(NULL, "open", URLBUGZILLA, NULL, NULL, SW_SHOWNORMAL);
00560 if (error<= 32) MessageBox(NULL,MSG_WARNING24,MSG_WARNING22,MB_ICONWARNING);
00561 }
00562
00563 void Callback_EMAIL(void)
00564 {
00565 char Message[MAX_PATH];
00566 int error;
00567
00568 wsprintf(Message,"mailto:%s?Subject=%s&CC=%s&body=%s",MAILTO, SUBJECT,CCMAILTO,"Message to Doctor Scilab");
00569 error =(int)ShellExecute(NULL, "open",Message,NULL,NULL,SW_SHOWNORMAL);
00570 if (error<= 32) MessageBox(NULL,MSG_WARNING25,MSG_WARNING22,MB_ICONWARNING);
00571 }
00572
00573 void Callback_NEWSGROUP(void)
00574 {
00575 int error =(int)ShellExecute(NULL, "open", URLNEWSGROUP, NULL, NULL, SW_SHOWNORMAL);
00576 if (error<= 32) MessageBox(NULL,MSG_WARNING24,MSG_WARNING22,MB_ICONWARNING);
00577 }
00578
00579 void Callback_ABOUT(void)
00580 {
00581 if (IsWindowInterface())
00582 {
00583 LPTW lptw=GetTextWinScilab();
00584 AboutBox(lptw->hWndParent);
00585 }
00586 else AboutBox(NULL);
00587 }
00588
00589 void Callback_CLEARCOMMANDWINDOW(void)
00590 {
00591 LPTW lptw=GetTextWinScilab();
00592
00593 ClearCommandWindow(lptw,TRUE);
00594 }
00595
00596 void Callback_CONFIGUREBROWSER(void)
00597 {
00598 SendCTRLandAKey(CTRLU);
00599 StoreCommand1("help_menu(3);",0);
00600 }
00601
00602 void Callback_CLEARHISTORY(void)
00603 {
00604 #define MAXBUF 1024
00605 char Commentline[MAXBUF];
00606
00607 reset_history();
00608
00609 GetCommentDateSession(Commentline,TRUE);
00610 AddHistory (Commentline);
00611
00612 }
00613
00614 void Callback_SELECTALL(void)
00615 {
00616 LPTW lptw=GetTextWinScilab();
00617 SelectAll(lptw,TRUE);
00618 }
00619
00620 void Callback_EMPTYCLIPBOARD(void)
00621 {
00622 LPTW lptw=GetTextWinScilab();
00623 CleanClipboard(lptw);
00624
00625 }
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 void SendMacro (LPTW lptw, UINT m)
00638 {
00639
00640 BYTE *s;
00641 char *d;
00642 char *buf;
00643 BOOL flag = TRUE;
00644
00645 LPMW lpmw = lptw->lpmw;
00646
00647 if ((buf = LocalAlloc (LPTR, MAXSTR + 1)) == (char *) NULL) return;
00648
00649 if (m >= NUMMENU || (int)m < 0) return;
00650
00651 s = lpmw->macro[m];
00652 d = buf;
00653 *d = '\0';
00654 while (s && *s && (d - buf < MAXSTR))
00655 {
00656 if (*s >= CMDMIN && *s <= CMDMAX)
00657 {
00658
00660 switch (*s)
00661 {
00662 case NEWSCILAB:
00663 Callback_NEWSCILAB();
00664 return;
00665 break;
00666 case OPEN:
00667 SaveCurrentLine(TRUE);
00668 Callback_OPEN();
00669 return;
00670 case EXEC:
00671 Callback_EXEC();
00672 return;
00673 break;
00674 case GETF:
00675 Callback_GETF();
00676 return;
00677 break;
00678 case LOAD:
00679 Callback_LOAD();
00680 return;
00681 break;
00682 case SAVE:
00683 Callback_SAVE();
00684 return;
00685 break;
00686 case CHDIR:
00687 Callback_CHDIR();
00688 return;
00689 break;
00690 case GETCWD:
00691 Callback_GETCWD();
00692 return;
00693 break;
00694 case EXIT:
00695 ExitWindow();
00696 return;
00697 break;
00698 case SELECTALL:
00699 Callback_SELECTALL();
00700 return;
00701 break;
00702 case MCOPY:
00703 Callback_MCOPY();
00704 s++;
00705 break;
00706 case PASTE:
00707 Callback_PASTE();
00708 return;
00709 break;
00710 case EMPTYCLIPBOARD:
00711 Callback_EMPTYCLIPBOARD();
00712 return;
00713 break;
00714 case PRINTSETUP:
00715 Callback_PRINTSETUP();
00716 return;
00717 break;
00718 case PRINT:
00719 Callback_PRINT();
00720 return;
00721 break;
00722 case TOOLBAR:
00723 Callback_TOOLBAR();
00724 return;
00725 break;
00726 case FRENCH:
00727 Callback_FRENCH();
00728 return;
00729 break;
00730 case ENGLISH:
00731 Callback_ENGLISH();
00732 return;
00733 break;
00734 case TEXTCOLOR:
00735 Callback_TEXTCOLOR();
00736 return;
00737 case BACKGROUNDCOLOR:
00738 Callback_BACKGROUNDCOLOR();
00739 return;
00740 case SYSTEMCOLOR:
00741 Callback_SYSTEMCOLOR();
00742 return;
00743 case FILESASSOCIATION:
00744 Callback_FILESASSOCIATIONBOX();
00745 return;
00746 case CHOOSETHEFONT:
00747 Callback_CHOOSETHEFONT();
00748 s++;
00749 break;
00750 case RESTART:
00751 Callback_RESTART();
00752 return;
00753 break;
00754 case ABORT:
00755 Callback_ABORT();
00756 return;
00757 break;
00758 case PAUSE:
00759 Callback_PAUSE();
00760 return;
00761 break;
00762 case RESUME:
00763 Callback_RESUME();
00764 return;
00765 break;
00766 case CONSOLE:
00767 Callback_CONSOLE();
00768 return;
00769 break;
00770 case SCIPAD:
00771 SaveCurrentLine(TRUE);
00772 Callback_SCIPAD();
00773 return;
00774 break;
00775 case HELP:
00776 SaveCurrentLine(TRUE);
00777 Callback_HELP();
00778 return;
00779 break;
00780 case CONFIGBROWSER:
00781 SaveCurrentLine(TRUE);
00782 Callback_CONFIGUREBROWSER();
00783 return;
00784 break;
00785 case CLEARHISTORY:
00786 Callback_CLEARHISTORY();
00787 return;
00788 break;
00789 case DEMOS:
00790 Callback_DEMOS();
00791 return;
00792 break;
00793 case WEB:
00794 Callback_WEB();
00795 return;
00796 break;
00797 case CONTRIBUTIONS:
00798 Callback_CONTRIBUTIONS();
00799 return;
00800 break;
00801 case BUGZILLA:
00802 Callback_BUGZILLA();
00803 return;
00804 break;
00805 case EMAIL:
00806 Callback_EMAIL();
00807 return;
00808 break;
00809 case NEWSGROUP:
00810 Callback_NEWSGROUP();
00811 return;
00812 break;
00813 case ABOUT:
00814 Callback_ABOUT();
00815 return;
00816 break;
00817 case M_CTRL_C:
00818 {
00819 SignalCtrC ();
00820 write_scilab("\n");
00821 }
00822 return;
00823 break;
00824
00825 case M_CTRL_U:
00826 {
00827 SendCTRLandAKey(CTRLU);
00828 }
00829 return;
00830 break;
00831
00832 case M_CTRL_P:
00833 {
00834 SendCTRLandAKey(CTRLP);
00835 }
00836 return;
00837 break;
00838 case M_CTRL_B:
00839 {
00840 SendCTRLandAKey(CTRLB);
00841 }
00842 return;
00843 break;
00844 case M_CTRL_F:
00845 {
00846 SendCTRLandAKey(CTRLF);
00847 }
00848 return;
00849 break;
00850 case M_CTRL_A:
00851 {
00852 SendCTRLandAKey(CTRLA);
00853 }
00854 return;
00855 break;
00856 case M_CTRL_E:
00857 {
00858 SendCTRLandAKey(CTRLE);
00859 }
00860 return;
00861 break;
00862 case M_CTRL_H:
00863 {
00864 SendCTRLandAKey(CTRLH);
00865 }
00866 return;
00867 break;
00868 case M_CTRL_D:
00869 {
00870 SendCTRLandAKey(CTRLD);
00871 }
00872 return;
00873 break;
00874 case M_CTRL_W:
00875 {
00876 SendCTRLandAKey(CTRLW);
00877 }
00878 return;
00879 break;
00880 case M_CTRL_K:
00881 {
00882 SendCTRLandAKey(CTRLK);
00883 }
00884 return;
00885 break;
00886 case M_CTRL_L:
00887 {
00888 SendCTRLandAKey(CTRLL);
00889 }
00890 return;
00891 break;
00892 case CLEARCOMMANDWINDOW:
00893 {
00894 Callback_CLEARCOMMANDWINDOW();
00895 }
00896 return;
00897 break;
00898
00899 return;
00900 break;
00901 case EOS:
00902 default:
00903 s++;
00904 break;
00905
00906
00907 }
00908 if (!flag)
00909 {
00910 d = buf;
00911 s = (BYTE *) "";
00912 }
00913 }
00914 else
00915 {
00916 *d++ = *s++;
00917 }
00918 }
00919 *d = '\0';
00921 ScilabMenuAction (buf);
00922 LocalFree (buf);
00923 }
00924
00925
00926
00927
00928
00929 void MenuFixCurrentWin (int ivalue)
00930 {
00931 static int firstentry = 0, top = -1;
00932 int i;
00933 if (firstentry == 0)
00934 {
00935 strcpy (gwin_name, "&Graphic Window 0");
00936 firstentry++;
00937 }
00938 if (lab_count != ivalue)
00939 {
00940 C2F (xscion) (&i);
00941 if (i == 1)
00942 {
00943 lab_count = ivalue;
00944 strcpy (gwin_name1, gwin_name);
00945 sprintf (gwin_name, "&Graphic Window %d", (int) ivalue);
00946 C2F (chmenu) (&top, gwin_name1, gwin_name);
00947 }
00948 }
00949 }
00950
00951
00952
00953
00954
00955 static void Countp ()
00956 {
00957 MenuFixCurrentWin (lab_count + 1);
00958 }
00959
00960 static void Countm ()
00961 {
00962 MenuFixCurrentWin ((lab_count == 0) ? 0 : lab_count - 1);
00963 }
00964
00965 static void SendCountDelete ()
00966 {
00967 DeleteSGWin (lab_count);
00968 }
00969
00970
00971
00972
00973 GFILE * Gfopen (LPSTR lpszFileName, int fnOpenMode)
00974 {
00975 GFILE *gfile;
00976 gfile = (GFILE *) LocalAlloc (LPTR, sizeof (GFILE));
00977 if (!gfile)
00978 return NULL;
00979 gfile->hfile = _lopen (lpszFileName, fnOpenMode);
00980 if (gfile->hfile == HFILE_ERROR)
00981 {
00982 LocalFree (gfile);
00983 return NULL;
00984 }
00985 gfile->getleft = 0;
00986 gfile->getnext = 0;
00987 return gfile;
00988 }
00989
00990 void Gfclose (GFILE * gfile)
00991 {
00992 _lclose (gfile->hfile);
00993 LocalFree (gfile);
00994 return;
00995 }
00996
00997
00998 int Gfgets (LPSTR lp, int size, GFILE * gfile)
00999 {
01000 int i;
01001 int ch;
01002 for (i = 0; i < size; i++)
01003 {
01004 if (gfile->getleft <= 0)
01005 {
01006 if ((gfile->getleft
01007 = _lread (gfile->hfile, gfile->getbuf, GBUFSIZE)) == 0)
01008 break;
01009 gfile->getnext = 0;
01010 }
01011 ch = *lp++ = gfile->getbuf[gfile->getnext++];
01012 gfile->getleft--;
01013 if (ch == '\r')
01014 {
01015 i--;
01016 lp--;
01017 }
01018 if (ch == '\n')
01019 {
01020 i++;
01021 break;
01022 }
01023 }
01024 if (i < size)
01025 *lp++ = '\0';
01026 return i;
01027 }
01028
01029
01030
01031 int GetLine (char *buffer, int len, GFILE * gfile)
01032 {
01033 BOOL status;
01034 int nLine = 0;
01035
01036 status = (Gfgets (buffer, len, gfile) != 0);
01037 nLine++;
01038 while (status && (buffer[0] == '\0' || buffer[0] == '\n' || buffer[0] == ';'))
01039 {
01040
01041 status = (Gfgets (buffer, len, gfile) != 0);
01042 nLine++;
01043 }
01044 if (lstrlen (buffer) > 0)
01045 buffer[lstrlen (buffer) - 1] = '\0';
01046 if (!status)
01047 nLine = 0;
01048 return nLine;
01049 }
01050
01051
01052 void LeftJustify (char *d, char *s)
01053 {
01054 while (*s && (*s == ' ' || *s == '\t'))
01055 s++;
01056 do
01057 {
01058 *d++ = *s;
01059 }
01060 while (*s++);
01061 }
01062
01063
01064 void TranslateMacro (char *string)
01065 {
01066 int i, len;
01067 LPSTR ptr;
01068 for (i = 0; keyword[i] != (char *) NULL; i++)
01069 {
01070 if ((ptr = strstr (string, keyword[i])) != NULL)
01071 {
01072 len = lstrlen (keyword[i]);
01073 *ptr = keyeq[i];
01074 lstrcpy (ptr + 1, ptr + len);
01075 i--;
01076 }
01077 }
01078 }
01079
01080
01081
01082
01083 void LoadMacros (LPTW lptw)
01084 {
01085 GFILE *menufile;
01086 BYTE *macroptr;
01087 char *buf;
01088 int nMenuLevel;
01089 HMENU hMenu[MENUDEPTH + 1+1];
01090 LPMW lpmw;
01091 int nLine = 1;
01092 int nInc;
01093 int nCountMenu;
01094 HGLOBAL hmacro;
01095 int i;
01096 HDC hdc;
01097 TEXTMETRIC tm;
01098 RECT rect;
01099 int ButtonX, ButtonY;
01100 char *ButtonText[BUTTONMAX];
01101
01102 lpmw = lptw->lpmw;
01103
01104
01105 buf = (char *) NULL;
01106 hmacro = 0;
01107 lpmw->macro = (BYTE **) NULL;
01108 lpmw->szPrompt = (char *) NULL;
01109 lpmw->szAnswer = (char *) NULL;
01110 menufile = (GFILE *) NULL;
01111
01112
01113 if ((menufile = Gfopen (lpmw->szMenuName, OF_READ)) == (GFILE *) NULL)
01114 goto errorcleanup;
01115
01116
01117 if ((buf = LocalAlloc (LPTR, MAXSTR)) == (char *) NULL)
01118 goto nomemory;
01119 hmacro = GlobalAlloc (GHND, (NUMMENU) * sizeof (BYTE *));
01120 if ((lpmw->macro = (BYTE **) GlobalLock (hmacro)) == (BYTE **) NULL)
01121 goto nomemory;
01122 if ((lpmw->szPrompt = LocalAlloc (LPTR, MAXSTR)) == (char *) NULL)
01123 goto nomemory;
01124 if ((lpmw->szAnswer = LocalAlloc (LPTR, MAXSTR)) == (char *) NULL)
01125 goto nomemory;
01126
01127
01128 for (i = 0; i < NUMMENU; i++)
01129 {
01130 lpmw->macro[i] = (BYTE *) 0;
01131 }
01132 lpmw->nCountMenu = 0;
01133 lpmw->nButton = 0;
01134 lpmw->hMenu = hMenu[0] = CreateMenu ();
01135 nMenuLevel = 0;
01136
01137 while ((nInc = GetLine (buf, MAXSTR, menufile)) != 0)
01138 {
01139 nLine += nInc;
01140 LeftJustify (buf, buf);
01141 if (buf[0] == '\0')
01142 {
01143
01144 }
01145 else if (!lstrcmpi (buf, "[Menu]"))
01146 {
01147
01148 if (!(nInc = GetLine (buf, MAXSTR, menufile)))
01149 {
01150 nLine += nInc;
01151 BUGGOTOCLEAN ("Problem on line %d of %s\n");
01152 }
01153 LeftJustify (buf, buf);
01154 if (nMenuLevel < MENUDEPTH+1)
01155 nMenuLevel++;
01156 else
01157 {
01158 BUGGOTOCLEAN (MSG_ERROR43);
01159 }
01160 hMenu[nMenuLevel] = CreateMenu ();
01161 AppendMenu (hMenu[nMenuLevel > 0 ? nMenuLevel - 1 : 0],
01162 MF_STRING | MF_POPUP, (UINT) hMenu[nMenuLevel],
01163 (LPCSTR) buf);
01164 }
01165 else if (!lstrcmpi (buf, "[EndMenu]"))
01166 {
01167 if (nMenuLevel > 0)
01168 nMenuLevel--;
01169 }
01170 else if (!lstrcmpi (buf, "[Button]"))
01171 {
01172
01173 if (lpmw->nButton >= BUTTONMAX)
01174 {
01175 BUGGOTOCLEAN (MSG_ERROR44);
01176 }
01177 if (!(nInc = GetLine (buf, MAXSTR, menufile)))
01178 {
01179 nLine += nInc;
01180 BUGGOTOCLEAN (MSG_ERROR45);
01181 }
01182 LeftJustify (buf, buf);
01183 if ((macroptr = LocalAlloc (LPTR, lstrlen (buf) + 1)) != (BYTE *) NULL)
01184 {
01185 lstrcpy ((char *) macroptr, buf);
01186 }
01187 else
01188 {
01189 BUGGOTOCLEAN (MSG_ERROR46);
01190 }
01191 ButtonText[lpmw->nButton] = (char *) macroptr;
01192 if (!(nInc = GetLine (buf, MAXSTR, menufile)))
01193 {
01194 nLine += nInc;
01195 BUGGOTOCLEAN (MSG_ERROR45);
01196 }
01197 LeftJustify (buf, buf);
01198 TranslateMacro (buf);
01199 if ((macroptr = LocalAlloc (LPTR, lstrlen (buf) + 1)) != (BYTE *) NULL)
01200 lstrcpy ((char *) macroptr, buf);
01201 else
01202 {
01203 BUGGOTOCLEAN (MSG_ERROR46);
01204 }
01205 nCountMenu = WGFindMenuPos (lpmw->macro);
01206 lpmw->nCountMenu++;
01207 lpmw->hButtonID[lpmw->nButton] = nCountMenu;
01208 lpmw->macro[nCountMenu] = macroptr;
01209 lpmw->nButton++;
01210 }
01211 else
01212 {
01213 nCountMenu = WGFindMenuPos (lpmw->macro);
01214
01215 if (nCountMenu >= NUMMENU)
01216 {
01217 BUGGOTOCLEAN (MSG_ERROR44);
01218 }
01219 LeftJustify (buf, buf);
01220 if (buf[0] == '-')
01221 {
01222 if (nMenuLevel == 0)
01223 AppendMenu (hMenu[0], MF_MENUBREAK, 0, (LPSTR) NULL);
01224 else
01225 AppendMenu (hMenu[nMenuLevel], MF_SEPARATOR, 0, (LPSTR) NULL);
01226 }
01227 else if (buf[0] == '|')
01228 {
01229 AppendMenu (hMenu[nMenuLevel], MF_MENUBARBREAK, 0, (LPSTR) NULL);
01230 }
01231 else
01232 {
01233 AppendMenu (hMenu[nMenuLevel], MF_STRING, nCountMenu, (LPSTR) buf);
01234 if (!(nInc = GetLine (buf, MAXSTR, menufile)))
01235 {
01236 nLine += nInc;
01237 BUGGOTOCLEAN (MSG_ERROR45);
01238 }
01239 LeftJustify (buf, buf);
01240 TranslateMacro (buf);
01241 if ((macroptr = LocalAlloc (LPTR, lstrlen (buf) + 1)) != (BYTE *) NULL)
01242 {
01243 lstrcpy ((char *) macroptr, buf);
01244 }
01245 else
01246 {
01247 BUGGOTOCLEAN ("Out of space for storing menu macros\n at line %d of %s\n");
01248 }
01249 lpmw->macro[nCountMenu] = macroptr;
01250 lpmw->nCountMenu++;
01251 }
01252 }
01253 }
01254 nCountMenu = WGFindMenuPos (lpmw->macro);
01255 if ((nCountMenu - lpmw->nButton) > 0)
01256 {
01257
01258 SetMenu (lptw->hWndParent, lpmw->hMenu);
01259 DrawMenuBar (lptw->hWndParent);
01260 }
01261
01262 if (!lpmw->nButton) goto cleanup;
01263
01264
01265
01266
01267 hdc = (HDC)TryToGetDC (lptw->hWndParent);
01268
01269 SelectFont (hdc, GetStockFont (SYSTEM_FIXED_FONT));
01270 GetTextMetrics (hdc, &tm);
01271 ButtonX = 10 * tm.tmAveCharWidth;
01272
01273 ButtonY = 24;
01274 ReleaseDC (lptw->hWndParent, hdc);
01275
01276
01277 lptw->ButtonHeight = ButtonY + 1;
01278 GetClientRect (lptw->hWndParent, &rect);
01279 SetWindowPos (lptw->hWndText, (HWND) NULL, 0, lptw->ButtonHeight,
01280 rect.right, rect.bottom - lptw->ButtonHeight,
01281 SWP_NOZORDER | SWP_NOACTIVATE);
01282
01283
01284
01285 lpmw->lpfnMenuButtonProc = (WNDPROC) MyGetProcAddress ("MenuButtonProc", MenuButtonProc);
01286 for (i = 0; i < lpmw->nButton; i++)
01287 {
01288 CreateButton(lptw,ButtonText, i,ButtonX, ButtonY);
01289 }
01290
01291
01292 goto cleanup;
01293
01294 nomemory:
01295 MessageBox (lptw->hWndParent, MSG_ERROR40, lptw->Title, MB_ICONEXCLAMATION);
01296
01297 errorcleanup:
01298 if (hmacro)
01299 {
01300 for (i = 0; i < NUMMENU; i++)
01301 {
01302 if (lpmw->macro[i] != (BYTE *) 0)
01303 {
01304 LocalFree (lpmw->macro[i]);
01305 lpmw->macro[i] = (BYTE *) 0;
01306 }
01307 }
01308 GlobalUnlock (hmacro);
01309 GlobalFree (hmacro);
01310 lpmw->macro = (BYTE **) NULL;
01311 }
01312 if (lpmw->szPrompt != (char *) NULL)
01313 {
01314 LocalFree (lpmw->szPrompt);
01315 lpmw->szPrompt = (char *) NULL;
01316 }
01317 if (lpmw->szAnswer != (char *) NULL)
01318 {
01319 LocalFree (lpmw->szAnswer);
01320 lpmw->szAnswer = (char *) NULL;
01321 }
01322
01323 cleanup:
01324 if (buf != (char *) NULL)
01325 LocalFree (buf);
01326 if (menufile != (GFILE *) NULL)
01327 Gfclose (menufile);
01328 return;
01329 }
01330
01331 void CreateButton(LPTW lptw, char *ButtonText[BUTTONMAX], int index,int ButtonSizeX, int ButtonSizeY)
01332 {
01333 LPMW lpmw;
01334 lpmw = lptw->lpmw;
01335
01336 if (strcmp(ButtonText[index],"--")==0)
01337 {
01338 lpmw->IsAIcon[index]=TRUE;
01339 GetXPosButton(lptw,index, 24,ButtonSizeY);
01340
01341 }
01342 else
01343 if ( ButtonText[index][0]=='|')
01344 {
01345 char LineTmp[MAX_PATH];
01346 char NameButton[MAX_PATH];
01347 char PathIconButton[MAX_PATH];
01348 char *Token=NULL;
01349 HICON IconButton;
01350
01351 int i=0;
01352
01353
01354
01355 strcpy(LineTmp,ButtonText[index]);
01356
01357 Token=strtok(LineTmp,"|");
01358 strcpy(NameButton,Token);
01359
01360 Token=strtok(NULL,"|");
01361 strcpy(PathIconButton,Token);
01362
01363 if ( ( IsAFile(PathIconButton)==TRUE) ||
01364 ( strcmp(PathIconButton,"METANET_ICON")==0) ||
01365 ( strcmp(PathIconButton,"SCICOS_ICON")==0) ||
01366 ( strcmp(PathIconButton,"PRINT_ICON")==0) ||
01367 ( strcmp(PathIconButton,"CONSOLE_ICON")==0) ||
01368 ( strcmp(PathIconButton,"DIRECTORY_ICON")==0) ||
01369 ( strcmp(PathIconButton,"EXIT_ICON")==0) ||
01370 ( strcmp(PathIconButton,"FONT_ICON")==0) ||
01371 ( strcmp(PathIconButton,"HELP_ICON")==0) ||
01372 ( strcmp(PathIconButton,"NEW_ICON")==0) ||
01373 ( strcmp(PathIconButton,"COPY_ICON")==0) ||
01374 ( strcmp(PathIconButton,"PASTE_ICON")==0) ||
01375 ( strcmp(PathIconButton,"OPEN_ICON")==0) ||
01376 ( strcmp(PathIconButton,"SCILAB_ICON")==0) )
01377 {
01378
01379 if ( IsAFile(PathIconButton) == TRUE )
01380 {
01381 IconButton=(HICON)LoadImage( GetModuleHandle(NULL), PathIconButton,IMAGE_ICON,24,24, LR_DEFAULTCOLOR|LR_LOADFROMFILE);
01382 }
01383 else
01384 if ( strcmp(PathIconButton,"SCICOS_ICON")==0 )
01385 {
01386 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_SCICOS24,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01387
01388 }
01389 else
01390 if ( strcmp(PathIconButton,"METANET_ICON")==0 )
01391 {
01392 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_METANET24,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01393
01394 }
01395 if ( strcmp(PathIconButton,"PRINT_ICON")==0 )
01396 {
01397 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_PRINT,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01398 }
01399 else
01400 if ( strcmp(PathIconButton,"CONSOLE_ICON")==0 )
01401 {
01402 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_CONSOLE,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01403 }
01404 else
01405 if ( strcmp(PathIconButton,"DIRECTORY_ICON")==0 )
01406 {
01407 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_CHDIR,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01408 }
01409 else
01410 if ( strcmp(PathIconButton,"EXIT_ICON")==0 )
01411 {
01412 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_EXIT24,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01413 }
01414 else
01415 if ( strcmp(PathIconButton,"FONT_ICON")==0 )
01416 {
01417 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_FONTS,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01418 }
01419 else
01420 if ( strcmp(PathIconButton,"HELP_ICON")==0 )
01421 {
01422 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_HELP,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01423 }
01424 else
01425 if ( strcmp(PathIconButton,"SCILAB_ICON")==0 )
01426 {
01427 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_SCILAB24,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01428 }
01429 else
01430 if ( strcmp(PathIconButton,"NEW_ICON")==0 )
01431 {
01432 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_NEWFILE,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01433 }
01434 else
01435 if ( strcmp(PathIconButton,"COPY_ICON")==0 )
01436 {
01437 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_COPY,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01438 }
01439 else
01440 if ( strcmp(PathIconButton,"PASTE_ICON")==0 )
01441 {
01442 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_PASTE,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01443 }
01444 else
01445 if ( strcmp(PathIconButton,"OPEN_ICON")==0 )
01446 {
01447 IconButton=(HICON)LoadImage( hdllInstance, (LPCSTR)IDI_OPEN,IMAGE_ICON,24,24, LR_DEFAULTCOLOR);
01448 }
01449
01450 lpmw->IsAIcon[index]=TRUE;
01451 lpmw->hButton[index] = CreateWindow("button",NameButton,WS_CHILD|WS_VISIBLE|BS_ICON ,
01452 GetXPosButton(lptw,index, 24,ButtonSizeY), 0,
01453 24, ButtonSizeY,
01454 lptw->hWndParent, (HMENU) index,
01455 lptw->hInstance, lptw);
01456
01457
01458 CreateMyTooltip (lpmw->hButton[index], NameButton);
01459
01460
01461 lpmw->lpfnButtonProc[index] = (WNDPROC) GetWindowLong (lpmw->hButton[index], GWL_WNDPROC);
01462 SetWindowLong(lpmw->hButton[index], GWL_WNDPROC, (LONG) lpmw->lpfnMenuButtonProc);
01463
01464
01465 SendMessage(lpmw->hButton[index],BM_SETIMAGE, IMAGE_ICON, (LPARAM)IconButton);
01466
01467 }
01468 else
01469 {
01470 char MsgErr[MAX_PATH];
01471 wsprintf(MsgErr,MSG_ERROR47,ButtonText[index]);
01472 MessageBox(NULL,MsgErr,MSG_ERROR48,MB_ICONEXCLAMATION);
01473 exit(1);
01474 }
01475
01476
01477
01478 }
01479 else
01480 {
01481 lpmw->IsAIcon[index]=FALSE;
01482 lpmw->hButton[index] = CreateWindow ("button",ButtonText[index],WS_CHILD|WS_VISIBLE,
01483 GetXPosButton(lptw,index,ButtonSizeX,ButtonSizeY), 0,
01484 ButtonSizeX, ButtonSizeY,
01485 lptw->hWndParent, (HMENU) index,
01486 lptw->hInstance, lptw);
01487
01488 CreateMyTooltip (lpmw->hButton[index], ButtonText[index]);
01489 lpmw->lpfnButtonProc[index] = (WNDPROC) GetWindowLong (lpmw->hButton[index], GWL_WNDPROC);
01490 SetWindowLong (lpmw->hButton[index], GWL_WNDPROC, (LONG) lpmw->lpfnMenuButtonProc);
01491
01492 }
01493 }
01494
01495
01496
01497 int GetXPosButton(LPTW lptw,int index,int SizeXButtonText,int SizeXButtonIcon)
01498 {
01499 LPMW lpmw;
01500 int PosXButton=0;
01501 lpmw = lptw->lpmw;
01502
01503 if (index==0) lpmw->PositionX[index]=0;
01504 else
01505 {
01506 if (lpmw->IsAIcon[index-1]==TRUE)
01507 {
01508 lpmw->PositionX[index]=lpmw->PositionX[index-1]+24;
01509 }
01510 else
01511 {
01512 lpmw->PositionX[index]=lpmw->PositionX[index-1]+80;
01513 }
01514 }
01515 return lpmw->PositionX[index];
01516 }
01517
01518
01519
01520
01521
01522 EXPORT LRESULT CALLBACK MenuButtonProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
01523 {
01524 LPTW lptw;
01525 LPMW lpmw;
01526 LONG n = GetWindowLong (hwnd, GWL_ID);
01527
01528 lptw = (LPTW) GetWindowLong (GetParent (hwnd), 0);
01529 lpmw = lptw->lpmw;
01530
01531
01532
01533 switch (message)
01534 {
01535
01536 case WM_LBUTTONUP:
01537 {
01538 RECT rect;
01539 POINT pt;
01540 GetWindowRect (hwnd, &rect);
01541 GetCursorPos (&pt);
01542 if (PtInRect (&rect, pt)) SendMessage (lptw->hWndText, WM_COMMAND, lpmw->hButtonID[n], 0L);
01543 SetFocus (lptw->hWndText);
01544 }
01545 break;
01546
01547 break;
01548
01549 }
01550 return CallWindowProc ((lpmw->lpfnButtonProc[n]), hwnd, message, wParam, lParam);
01551 }
01552
01553
01554
01555
01556
01557
01558
01559 void CloseMacros (LPTW lptw)
01560 {
01561 int i;
01562 HGLOBAL hglobal;
01563 LPMW lpmw;
01564 lpmw = lptw->lpmw;
01565
01566
01567 if (lpmw->macro != (BYTE **) NULL)
01568 {
01569 hglobal = GlobalHandle (lpmw->macro);
01570 if (hglobal)
01571 {
01572 for (i = 0; i < NUMMENU; i++)
01573 if (lpmw->macro[i] != (BYTE *) 0)
01574 {
01575 LocalFree (lpmw->macro[i]);
01576 lpmw->macro[i] = (BYTE *) 0;
01577 }
01578 GlobalUnlock (hglobal);
01579 GlobalFree (hglobal);
01580 lpmw->macro = (BYTE **) NULL;
01581 }
01582 }
01583 if (lpmw->szPrompt != (char *) NULL)
01584 {
01585 LocalFree (lpmw->szPrompt);
01586 lpmw->szPrompt = (char *) NULL;
01587 }
01588 if (lpmw->szAnswer != (char *) NULL)
01589 {
01590 LocalFree (lpmw->szAnswer);
01591 lpmw->szAnswer = (char *) NULL;
01592 }
01593 }
01594
01595
01596
01597
01598 EXPORT BOOL CALLBACK InputBoxDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
01599 {
01600 LPTW lptw;
01601 LPMW lpmw;
01602 lptw = (LPTW) GetWindowLong (GetParent (hDlg), 0);
01603 lpmw = lptw->lpmw;
01604
01605 switch (message)
01606 {
01607 case WM_INITDIALOG:
01608 SetDlgItemText (hDlg, ID_PROMPT, lpmw->szPrompt);
01609 return (TRUE);
01610
01611 case WM_COMMAND:
01612 switch (LOWORD (wParam))
01613 {
01614 case ID_ANSWER:
01615 return (TRUE);
01616
01617 case IDOK:
01618 lpmw->nChar = GetDlgItemText (hDlg, ID_ANSWER, lpmw->szAnswer, MAXSTR);
01619 EndDialog (hDlg, TRUE);
01620 return (TRUE);
01621
01622 case IDCANCEL:
01623 lpmw->szAnswer[0] = '\0';
01624 EndDialog (hDlg, FALSE);
01625 return (TRUE);
01626
01627 default:
01628 return (FALSE);
01629 }
01630 default:
01631 return (FALSE);
01632 }
01633 }
01634
01635
01636 BOOL OpenSaveSCIFile(HWND hWndParent,char *titre,BOOL read,char *FileExt,char *file)
01637 {
01638 BOOL Retour=FALSE;
01639 char szBuffer[MAX_PATH] = "";
01640 OPENFILENAME OFN;
01641
01642 ZeroMemory(&OFN, sizeof(OFN));
01643 OFN.lStructSize = sizeof(OFN);
01644
01645 OFN.hwndOwner = hWndParent;
01646 OFN.hInstance = NULL;
01647 OFN.lpstrFilter = FileExt;
01648 OFN.nFilterIndex=1;
01649 OFN.lpstrFile = NULL;
01650 OFN.nMaxFile = 0;
01651 OFN.lpstrFile = szBuffer;
01652 OFN.nMaxFile = MAX_PATH;
01653 OFN.lpstrTitle = titre;
01654
01655 if (read == TRUE)
01656 {
01657
01658 OFN.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
01659 if( GetOpenFileName( &OFN ) )
01660 {
01661 lstrcpy(file,OFN.lpstrFile);
01662 Retour=TRUE;
01663 }
01664 else Retour=FALSE;
01665 }
01666 else
01667 {
01668
01669 OFN.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR|OFN_HIDEREADONLY;
01670 if(GetSaveFileName ( &OFN ) )
01671 {
01672 lstrcpy(file,OFN.lpstrFile);
01673 Retour=TRUE;
01674 }
01675 else Retour=FALSE;
01676 }
01677
01678 return Retour;
01679 }
01680
01681
01682 void ReplaceSlash(char *pathout,char *pathin)
01683 {
01684 int i=0;
01685 for (i=0;i < (int)strlen(pathin);i++)
01686 {
01687
01688 if (pathin[i]=='\\')
01689 {
01690 pathout[i]='/';
01691 }
01692 else
01693 {
01694 pathout[i]=pathin[i];
01695 }
01696
01697 }
01698 pathout[i]='\0';
01699 }
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709 BOOL SciOpenSave (HWND hWndParent, BYTE ** s,BOOL save, char **d, int *ierr)
01710 {
01711 int i, nChar;
01712 OPENFILENAME ofn;
01713 char *szTitle;
01714 char *szFile;
01715 char *szFileTitle;
01716 char *szFilter;
01717 BOOL flag;
01718
01719 NEWSTRING (szTitle);
01720 NEWSTRING (szFile);
01721 NEWSTRING (szFileTitle);
01722 NEWSTRING (szFilter);
01723
01724 (*s)++;
01725 for (i = 0; (**s >= 32 && **s <= 126); i++)
01726 {
01727 szTitle[i] = **s;
01728 (*s)++;
01729 }
01730 szTitle[i] = '\0';
01731 (*s)++;
01732 for (i = 0; (**s >= 32 && **s <= 126); i++)
01733 {
01734 szFile[i] = **s;
01735 (*s)++;
01736 }
01737 szFile[i++] = '\0';
01738 lstrcpy (szFilter, "Default (");
01739 lstrcat (szFilter, szFile);
01740 lstrcat (szFilter, ")");
01741 i = lstrlen (szFilter);
01742 i++;
01743 lstrcpy (szFilter + i, szFile);
01744 i += lstrlen (szFilter + i);
01745 i++;
01746 lstrcpy (szFilter + i, "All Files (*.*)");
01747 i += lstrlen (szFilter + i);
01748 i++;
01749 lstrcpy (szFilter + i, "*.*");
01750 i += lstrlen (szFilter + i);
01751 i++;
01752 szFilter[i++] = '\0';
01753
01754 szFile[0] = '\0';
01755
01756
01757 ZeroMemory(&ofn, sizeof(ofn));
01758 ofn.lStructSize = sizeof (ofn);
01759 ofn.hwndOwner = hWndParent;
01760 ofn.lpstrFilter = szFilter;
01761 ofn.nFilterIndex = 1;
01762 ofn.lpstrFile = szFile;
01763 ofn.nMaxFile = MAXSTR;
01764 ofn.lpstrFileTitle = szFileTitle;
01765 ofn.nMaxFileTitle = MAXSTR;
01766 ofn.lpstrTitle = szTitle;
01767 ofn.lpstrInitialDir = (LPSTR) NULL;
01768
01769 if (save)
01770 {
01771 ofn.Flags = OFN_PATHMUSTEXIST;
01772 flag=GetSaveFileName (&ofn);
01773 }
01774 else
01775 {
01776 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
01777 flag=GetOpenFileName (&ofn);
01778 }
01779
01780 if (flag)
01781 {
01782 nChar = lstrlen (ofn.lpstrFile);
01783 for (i = 0; i < nChar; i++)
01784 {
01785 **d = ofn.lpstrFile[i];
01786 (*d)++;
01787 }
01788 }
01789
01790 FREE (szTitle);
01791 FREE (szFilter);
01792 FREE (szFile);
01793 FREE (szFileTitle);
01794
01795 return (flag);
01796 }
01797
01798
01799 void SendCTRLandAKey(int code)
01800 {
01801 extern TW textwin;
01802 char command[MAX_PATH];
01803 char *d;
01804
01805 wsprintf(command,"%c",(char)code);
01806 if ( IsToThePrompt () && (command[0] != '\0') )
01807 {
01808 d = command;
01809 while (*d)
01810 {
01811 SendMessage (textwin.hWndText, WM_CHAR, *d, 1L);
01812 d++;
01813 }
01814 }
01815 }
01816
01817
01818 void ReLoadMenus(LPTW lptw)
01819 {
01820 int i=0;
01821 LPMW lpmw;
01822
01823 lpmw = lptw->lpmw;
01824
01825
01826 CloseMacros (lptw);
01827
01828 for (i = 0; i < lpmw->nButton; i++)
01829 {
01830 DestroyWindow(lpmw->hButton[i]);
01831 }
01832
01833 UpdateFileNameMenu(lptw);
01834 LoadMacros (lptw);
01835
01836 ToolBarOnOff(lptw);
01837 }
01838
01839 void UpdateFileNameMenu(LPTW lptw)
01840 {
01841 #define FILEMENUFRENCH "wscilabF.mnu"
01842 #define FILEMENUENGLISH "wscilabE.mnu"
01843
01844 char *ScilabDirectory=NULL;
01845
01846 LPMW lpmw= lptw->lpmw;
01847
01848 ScilabDirectory=GetScilabDirectory(FALSE);
01849
01850 if (lpmw->szMenuName!=NULL) FREE(lpmw->szMenuName);
01851 lpmw->szMenuName = (LPSTR) MALLOC (strlen (ScilabDirectory) +strlen("\\bin\\") +strlen (FILEMENUENGLISH) + 1);
01852
01853 switch (lpmw->CodeLanguage)
01854 {
01855 case 1:
01856 wsprintf(lpmw->szMenuName,"%s\\bin\\%s",ScilabDirectory, FILEMENUFRENCH);
01857 break;
01858 default : case 0:
01859 wsprintf(lpmw->szMenuName,"%s\\bin\\%s",ScilabDirectory,FILEMENUENGLISH);
01860 break;
01861 }
01862
01863 if (ScilabDirectory){FREE(ScilabDirectory);ScilabDirectory=NULL;}
01864 }
01865
01866 void SwitchLanguage(LPTW lptw)
01867 {
01868 char commandline[256];
01869
01870 strcpy(commandline,"global LANGUAGE;%helps=initial_help_chapters(LANGUAGE);");
01871
01872 StoreCommand1 (commandline, 0);
01873 switch (lptw->lpmw->CodeLanguage)
01874 {
01875 case 1:
01876 StoreCommand1 ("LANGUAGE=\"fr\";", 0);
01877 break;
01878
01879 default: case 0:
01880 StoreCommand1 ("LANGUAGE=\"eng\";", 0);
01881 break;
01882 }
01883 StoreCommand1 (commandline, 0);
01884
01885 strcpy(commandline,"global LANGUAGE;%helps=initial_help_chapters(LANGUAGE);");
01886 StoreCommand1 (commandline, 0);
01887
01888 ReLoadMenus(lptw);
01889 ToolBarOnOff(lptw);
01890 OnRightClickMenu(lptw);
01891
01892 }
01893
01894 void ResetMenu(void)
01895 {
01896 LPTW lptw=GetTextWinScilab();
01897 ReLoadMenus(lptw);
01898 }
01899
01900 void ConfigureScilabStar(int LangCode)
01901 {
01902 #define SCILABSTAR "scilab.start"
01903
01904 char scilabstarfullpath[MAX_PATH];
01905 char scilabstartmpfullpath[MAX_PATH];
01906 char *WSCIPath=NULL;
01907 char wscitmp[MAX_PATH+1];
01908
01909 int CodeRetour=-2;
01910
01911 WSCIPath=getSCIpath();
01912 ConvertPathUnixToWindowsFormat(WSCIPath,wscitmp);
01913
01914 if (WSCIPath)
01915 {
01916 strcpy(scilabstarfullpath,wscitmp);
01917 strcat(scilabstarfullpath,"\\etc\\");
01918 strcat(scilabstarfullpath,SCILABSTAR);
01919
01920 strcpy(scilabstartmpfullpath,scilabstarfullpath);
01921 strcat(scilabstartmpfullpath,".tmp");
01922
01923 switch (LangCode)
01924 {
01925 case 1:
01926 CodeRetour=ModifyFile(scilabstarfullpath,"LANGUAGE=","LANGUAGE=\"fr\"\n");
01927 break;
01928
01929 default : case 0:
01930 CodeRetour=ModifyFile(scilabstarfullpath,"LANGUAGE=","LANGUAGE=\"eng\"\n");
01931 break;
01932 }
01933
01934 if (CodeRetour == 0 )
01935 {
01936 DeleteFile(scilabstarfullpath);
01937 if ( ! MoveFile(scilabstartmpfullpath,scilabstarfullpath) ) DeleteFile(scilabstartmpfullpath);
01938 }
01939 else
01940 {
01941
01942 }
01943 }
01944 }
01945
01946 int ModifyFile(char *fichier,char *motclef,char *chaine)
01947 {
01948 int Retour=1;
01949 FILE *fileR,*fileW;
01950 char Ligne[MAX_PATH];
01951 char cmpchaine[MAX_PATH];
01952
01953 fileR=NULL;
01954 fileW=NULL;
01955
01956 fileR= fopen(fichier, "rt");
01957 strcpy(cmpchaine,fichier);
01958 strcat(cmpchaine,".tmp");
01959
01960 fileW= fopen(cmpchaine, "wt");
01961 strcpy(cmpchaine,"");
01962
01963 if ( (fileR) && (fileW) )
01964 {
01965 while( fgets(Ligne, MAX_PATH, fileR) != NULL)
01966 {
01967 strncpy(cmpchaine,Ligne,strlen(motclef));
01968 cmpchaine[strlen(motclef)]='\0';
01969 if (strcmp(cmpchaine,motclef)==0)
01970 {
01971 fputs(chaine,fileW);
01972 Retour=0;
01973 }
01974 else
01975 {
01976 fputs(Ligne,fileW);
01977 }
01978 strcpy(Ligne,"\0");
01979 }
01980
01981 fclose(fileR);
01982 fclose(fileW);
01983 }
01984 else
01985 {
01986 Retour=-1;
01987 }
01988 return Retour;
01989 }
01990
01991
01992 void SetLanguageMenu(char *Language)
01993 {
01994 if (IsWindowInterface())
01995 {
01996 int LanguageCode=0;
01997 char *LanguageInScilabDotStar=NULL;
01998 LPTW lptw=GetTextWinScilab();
01999
02000 if (strcmp(Language,"fr") == 0) LanguageCode=1;
02001 if (strcmp(Language,"en") == 0) LanguageCode=0;
02002
02003 if (lptw->lpmw->CodeLanguage != LanguageCode)
02004 {
02005 SendCTRLandAKey(CTRLU);
02006 lptw->lpmw->CodeLanguage=LanguageCode;
02007 SwitchLanguage(lptw);
02008 ConfigureScilabStar(lptw->lpmw->CodeLanguage);
02009 StoreCommand1 ("exec(SCI+'/contrib/loader.sce');",0);
02010 }
02011
02012 }
02013 else
02014 {
02015
02016
02017 }
02018 }
02019
02020 int GetLanguageCodeInScilabDotStar(void)
02021 {
02022 int ReturnLanguageCode=-1;
02023 char *WSCIPath=NULL;
02024
02025 WSCIPath=getSCIpath();
02026
02027 if (WSCIPath)
02028 {
02029 #define SCILABSTAR "scilab.start"
02030 #define MOTCLEF "LANGUAGE="""
02031
02032 FILE *fileR=NULL;
02033 char wscitmp[MAX_PATH+1];
02034 char Ligne[MAX_PATH];
02035 char scilabstarfullpath[MAX_PATH];
02036 char cmpchaine[MAX_PATH];
02037
02038 ConvertPathUnixToWindowsFormat(WSCIPath,wscitmp);
02039
02040 strcpy(scilabstarfullpath,wscitmp);
02041 strcat(scilabstarfullpath,"\\etc\\");
02042 strcat(scilabstarfullpath,SCILABSTAR);
02043
02044 fileR= fopen(scilabstarfullpath, "rt");
02045 if (fileR)
02046 {
02047 while( fgets(Ligne, MAX_PATH, fileR) != NULL)
02048 {
02049 strncpy(cmpchaine,Ligne,strlen(MOTCLEF));
02050 cmpchaine[strlen(MOTCLEF)]='\0';
02051 if (strcmp(cmpchaine,MOTCLEF)==0)
02052 {
02053 int i=0,j=0;
02054 char LanguageTemp[MAX_PATH];
02055
02056 strcpy(LanguageTemp,"\0");
02057
02058 for (i=(int)strlen(MOTCLEF)+1;i<(int)strlen(Ligne)-2;i++)
02059 {
02060 LanguageTemp[j]=Ligne[i];
02061 j++;
02062 }
02063 LanguageTemp[j]='\0';
02064
02065 if (strcmp(LanguageTemp,"fr")==0) ReturnLanguageCode=1;
02066 if (strcmp(LanguageTemp,"eng")==0) ReturnLanguageCode=0;
02067
02068 fclose(fileR);
02069 if (WSCIPath) {FREE(WSCIPath);WSCIPath=NULL;}
02070 return ReturnLanguageCode;
02071 }
02072
02073 strcpy(Ligne,"\0");
02074 }
02075 }
02076 fclose(fileR);
02077 }
02078 if (WSCIPath) {FREE(WSCIPath);WSCIPath=NULL;}
02079 return ReturnLanguageCode;
02080 }
02081