00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef STRICT
00029 #define STRICT
00030 #endif
00031
00032
00033 #include "WTEXT.h"
00034 #include "wmcopydata.h"
00035 #include "WinConsole.h"
00036
00037 #include "Messages.h"
00038 #include "Warnings.h"
00039 #include "Errors.h"
00040 #include "WindowList.h"
00041
00042 #include "prompt.h"
00043
00044 #include "win_mem_alloc.h"
00045
00046 BOOL ConsoleIsMinimized=FALSE;
00047 static BOOL WriteInKeyBuf=FALSE;
00048 static void CreateTextClass (LPTW lptw);
00049 static BOOL RegisterParentWindowClass (LPTW lptw);
00050 static BOOL RegisterTextWindowClass (LPTW lptw);
00051
00052 extern int C2F(sciquit)() ;
00053 extern void CreateThreadPaste(char *Text);
00054 extern BOOL IsReadyForAnewLign(void);
00055 extern void SetReadyOrNotForAnewLign(BOOL Ready);
00056 extern HANDLE GetHandleThreadPaste(void);
00057 extern BOOL GetThreadPasteRunning(void);
00058 extern void SetThreadPasteRunning(BOOL Running);
00059
00060 extern void Kill_Scilex(void);
00061
00062 extern void SendCTRLandAKey(int code);
00063 extern BOOL IsWindowInterface(void);
00064 extern void ReplaceSlash(char *pathout,char *pathin);
00065 extern BOOL IsAFile(char *chainefichier);
00066 extern void ToolBarOnOff(LPTW lptw);
00067 extern void ReLoadMenus(LPTW lptw);
00068 extern DWORD GetIhmTextBackgroundColor(void);
00069 extern void InitIhmDefaultColor(void);
00070 extern DWORD GetIhmTextColor(void);
00071 extern char *GetScilabDirectory(BOOL UnixStyle);
00072 extern LPTW GetTextWinScilab(void);
00073 extern void MessageBoxNewGraphicMode(void);
00074 extern int GetLanguageCodeInScilabDotStar(void);
00075 extern void ScilabFxFadeOut(void);
00076 extern BOOL IsEnableTransparencyMode(void);
00077 extern void C2F (tmpdirc) (void);
00078 extern EXPORT LRESULT CALLBACK WndParentProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00079 extern EXPORT LRESULT CALLBACK WndTextProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00080
00081 char ScilexWindowName[MAX_PATH];
00082 POINT ScreenMinSize = {16, 4};
00083 POINT ScrollSize = {80,360};
00084 char szNoMemory[] = "out of memory";
00085
00086 HANDLE hThreadWrite;
00087 CRITICAL_SECTION Sync;
00088 HINSTANCE hdllInstance;
00089 LPSTR szParentClass = "wscilab_parent";
00090 LPSTR szTextClass = "wscilab_text";
00091
00092
00093
00094
00095 EXPORT void WINAPI TextMessage (void)
00096 {
00097 TextMessage1 (0);
00098 return;
00099 }
00100
00101 static BOOL RegisterParentWindowClass (LPTW lptw)
00102 {
00103 BOOL bOK=FALSE;
00104 WNDCLASS Parentwndclass;
00105 Parentwndclass.lpszClassName = szParentClass;
00106 Parentwndclass.lpfnWndProc = WndParentProc;
00107 Parentwndclass.style = CS_HREDRAW | CS_VREDRAW;
00108 Parentwndclass.cbClsExtra = 0;
00109 Parentwndclass.cbWndExtra = 2 * sizeof (void FAR *);
00110 Parentwndclass.hInstance = lptw->hInstance;
00111 Parentwndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00112 Parentwndclass.hCursor = LoadCursor (NULL, IDC_WAIT);
00113 Parentwndclass.hbrBackground =(HBRUSH) CreateSolidBrush (GetIhmTextBackgroundColor()) ;
00114 Parentwndclass.lpszMenuName = NULL;
00115
00116 if (!RegisterClass(&Parentwndclass))
00117 {
00118 DWORD dwLastError = GetLastError();
00119 char buff1[1000], buff2[1000];
00120
00121 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError, 0, buff1, sizeof (buff1), NULL);
00122 sprintf(buff2, MSG_ERROR53, dwLastError);
00123
00124 MessageBox(NULL, buff1, buff2, MB_ICONERROR);
00125
00126 bOK=FALSE;
00127 }
00128 else bOK=TRUE;
00129
00130 return bOK;
00131 }
00132
00133 static BOOL RegisterTextWindowClass (LPTW lptw)
00134 {
00135 BOOL bOK=FALSE;
00136 WNDCLASS Textwndclass;
00137 Textwndclass.style = CS_HREDRAW | CS_VREDRAW;
00138 Textwndclass.lpfnWndProc = WndTextProc;
00139 Textwndclass.cbClsExtra = 0;
00140 Textwndclass.cbWndExtra = 2 * sizeof (void FAR *);
00141 Textwndclass.hInstance = lptw->hInstance;
00142 Textwndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00143 Textwndclass.hCursor = LoadCursor (NULL, IDC_WAIT);
00144 Textwndclass.hbrBackground =(HBRUSH) CreateSolidBrush (GetIhmTextBackgroundColor());
00145 Textwndclass.lpszMenuName = NULL;
00146 Textwndclass.lpszClassName = szTextClass;
00147 if (!RegisterClass(&Textwndclass))
00148 {
00149 DWORD dwLastError = GetLastError();
00150 char buff1[1000], buff2[1000];
00151
00152 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError, 0, buff1, sizeof (buff1), NULL);
00153 sprintf(buff2, MSG_ERROR53, dwLastError);
00154
00155 MessageBox(NULL, buff1, buff2, MB_ICONERROR);
00156
00157 bOK=FALSE;
00158 }
00159 else
00160 {
00161 lptw->hbrBackground =(HBRUSH) CreateSolidBrush (GetIhmTextBackgroundColor());
00162 bOK=TRUE;
00163 }
00164
00165 return bOK;
00166
00167 }
00168
00169
00170
00171
00172 static void CreateTextClass (LPTW lptw)
00173 {
00174 if (!RegisterParentWindowClass (lptw)) exit(1);
00175 if (!RegisterTextWindowClass (lptw)) exit(1);
00176 }
00177
00178
00179
00180
00181 EXPORT int WINAPI TextInit (LPTW lptw)
00182 {
00183 RECT rect;
00184 HMENU sysmenu;
00185 HGLOBAL hglobal;
00186
00187 lptw->hWndParent=NULL;
00188 lptw->hWndText=NULL;
00189
00190 ReadRegistryTxt (lptw);
00191 if (lptw->bSysColors) InitIhmDefaultColor();
00192
00193 if (!lptw->hPrevInstance) CreateTextClass (lptw);
00194
00195 if (lptw->KeyBufSize == 0) lptw->KeyBufSize = KeyBufferSize;
00196
00197
00198 if (lptw->ScreenSize.x < ScrollSize.x) lptw->ScreenSize.x = ScrollSize.x;
00199 if (lptw->ScreenSize.y < ScrollSize.y) lptw->ScreenSize.y = ScrollSize.y;
00200
00201 lptw->CursorPos.x = lptw->CursorPos.y = 0;
00202 lptw->bFocus = FALSE;
00203 lptw->bGetCh = FALSE;
00204 lptw->CaretHeight = 0;
00205 if (!lptw->nCmdShow)
00206 lptw->nCmdShow = SW_SHOWNORMAL;
00207 if (!lptw->Attr)
00208 lptw->Attr = 0xf0;
00209
00210 hglobal = GlobalAlloc (GHND, lptw->ScreenSize.x * lptw->ScreenSize.y);
00211
00212
00213 lptw->ScreenBuffer = (BYTE FAR *) GlobalLock (hglobal);
00214 if (lptw->ScreenBuffer == (BYTE FAR *) NULL)
00215 {
00216 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
00217 return (1);
00218 }
00219 _fmemset (lptw->ScreenBuffer, ' ', lptw->ScreenSize.x * lptw->ScreenSize.y);
00220 hglobal = GlobalAlloc (GHND, lptw->ScreenSize.x * lptw->ScreenSize.y);
00221 lptw->AttrBuffer = (BYTE FAR *) GlobalLock (hglobal);
00222 if (lptw->AttrBuffer == (BYTE FAR *) NULL)
00223 {
00224 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
00225 return (1);
00226 }
00227 _fmemset (lptw->AttrBuffer, NOTEXT, lptw->ScreenSize.x * lptw->ScreenSize.y);
00228
00229 hglobal = GlobalAlloc (GHND, lptw->KeyBufSize);
00230
00231
00232 lptw->KeyBuf = (BYTE FAR *) GlobalLock (hglobal);
00233
00234 if (lptw->KeyBuf == (BYTE FAR *) NULL)
00235 {
00236 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
00237 return (1);
00238 }
00239 _fmemset (lptw->KeyBuf, ' ', lptw->KeyBufSize);
00240 lptw->KeyBufIn = lptw->KeyBufOut = lptw->KeyBuf;
00241
00242
00243 lptw->hWndParent = CreateWindow (szParentClass, lptw->Title,
00244 WS_OVERLAPPEDWINDOW,
00245 lptw->Origin.x, lptw->Origin.y,
00246 lptw->Size.x, lptw->Size.y,
00247 NULL, NULL, lptw->hInstance, lptw);
00248
00249 if (lptw->hWndParent == (HWND) NULL)
00250 {
00251 MessageBox ((HWND) NULL, MSG_ERROR54, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
00252 return (1);
00253 }
00254 ShowWindow (lptw->hWndParent, lptw->nCmdShow);
00255 GetClientRect (lptw->hWndParent, &rect);
00256
00257 lptw->hWndText = CreateWindow (szTextClass, lptw->Title,
00258 WS_CHILD | WS_VSCROLL | WS_HSCROLL,
00259 0, lptw->ButtonHeight,
00260 rect.right, rect.bottom - lptw->ButtonHeight,
00261 lptw->hWndParent, NULL, lptw->hInstance, lptw);
00262
00263 if (lptw->hWndText == (HWND) NULL)
00264 {
00265 MessageBox ((HWND) NULL, MSG_ERROR55, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
00266 return (1);
00267 }
00268
00269 OnRightClickMenu(lptw) ;
00270
00271 sysmenu = GetSystemMenu (lptw->hWndParent, 0);
00272 AppendMenu (sysmenu, MF_SEPARATOR, 0, NULL);
00273 AppendMenu (sysmenu, MF_STRING, M_CONSOLE, MSG_SCIMSG56);
00274 AppendMenu (sysmenu, MF_SEPARATOR, 0, NULL);
00275 AppendMenu (sysmenu, MF_STRING, M_ABOUT, MSG_SCIMSG57);
00276
00277 if (lptw->lpmw) LoadMacros (lptw);
00278 ReLoadMenus(lptw);
00279
00280 DisableMenus(lptw);
00281
00282 ToolBarOnOff(lptw);
00283 DisableToolBar(lptw);
00284 OnRightClickMenu(lptw);
00285
00286 ShowWindow (lptw->hWndText, SW_SHOWNORMAL);
00287 BringWindowToTop (lptw->hWndText);
00288 SetFocus (lptw->hWndText);
00289 TextMessage ();
00290
00291 return (0);
00292 }
00293
00294
00295 EXPORT void WINAPI TextClose (LPTW lptw)
00296 {
00297 HGLOBAL hglobal;
00298
00299
00300 if (lptw->hWndParent)DestroyWindow (lptw->hWndParent);
00301 TextMessage ();
00302
00303 hglobal = GlobalHandle (lptw->ScreenBuffer);
00304 if (hglobal)
00305 {
00306 GlobalUnlock (hglobal);
00307 GlobalFree (hglobal);
00308 }
00309 hglobal = GlobalHandle (lptw->AttrBuffer);
00310 if (hglobal)
00311 {
00312 GlobalUnlock (hglobal);
00313 GlobalFree (hglobal);
00314 }
00315 hglobal = GlobalHandle (lptw->KeyBuf);
00316 if (hglobal)
00317 {
00318 GlobalUnlock (hglobal);
00319 GlobalFree (hglobal);
00320 }
00321
00322 if (lptw->lpmw) CloseMacros (lptw);
00323 lptw->hWndParent = (HWND) NULL;
00324 }
00325
00326
00327 EXPORT void WINAPI TextToCursor (LPTW lptw)
00328 {
00329 int nXinc = 0;
00330 int nYinc = 0;
00331 int cxCursor;
00332 int cyCursor;
00333 cyCursor = lptw->CursorPos.y * lptw->CharSize.y;
00334 if ((cyCursor + lptw->CharSize.y > lptw->ScrollPos.y + lptw->ClientSize.y)
00335 || (cyCursor < lptw->ScrollPos.y))
00336 {
00337 nYinc = max (0, cyCursor + lptw->CharSize.y - lptw->ClientSize.y) - lptw->ScrollPos.y;
00338 nYinc = min (nYinc, lptw->ScrollMax.y - lptw->ScrollPos.y);
00339 }
00340 cxCursor = lptw->CursorPos.x * lptw->CharSize.x;
00341 if ((cxCursor + lptw->CharSize.x > lptw->ScrollPos.x + lptw->ClientSize.x)
00342 || (cxCursor < lptw->ScrollPos.x))
00343 {
00344 nXinc = max (0, cxCursor + lptw->CharSize.x - lptw->ClientSize.x / 2) - lptw->ScrollPos.x;
00345 nXinc = min (nXinc, lptw->ScrollMax.x - lptw->ScrollPos.x);
00346 }
00347 if (nYinc || nXinc)
00348 {
00349 lptw->ScrollPos.y += nYinc;
00350 lptw->ScrollPos.x += nXinc;
00351 ScrollWindow (lptw->hWndText, -nXinc, -nYinc, NULL, NULL);
00352 SetScrollPos (lptw->hWndText, SB_VERT, lptw->ScrollPos.y, TRUE);
00353
00354 SetScrollPos (lptw->hWndText, SB_HORZ, lptw->ScrollPos.x, TRUE);
00355 UpdateWindow (lptw->hWndText);
00356 }
00357 }
00358
00359 void NewLine (LPTW lptw)
00360 {
00361 lptw->CursorPos.x = 0;
00362 lptw->CursorPos.y++;
00363 if (lptw->CursorPos.y >= lptw->ScreenSize.y) {
00364 int i = lptw->ScreenSize.x * (lptw->ScreenSize.y - 1);
00365 _fmemmove(lptw->ScreenBuffer, lptw->ScreenBuffer+lptw->ScreenSize.x, i);
00366 _fmemset(lptw->ScreenBuffer + i, ' ', lptw->ScreenSize.x);
00367 _fmemmove(lptw->AttrBuffer, lptw->AttrBuffer+lptw->ScreenSize.x, i);
00368 _fmemset(lptw->AttrBuffer + i, NOTEXT, lptw->ScreenSize.x);
00369 lptw->CursorPos.y--;
00370 ScrollWindow(lptw->hWndText,0,-lptw->CharSize.y,NULL,NULL);
00371 lptw->MarkBegin.y--;
00372 lptw->MarkEnd.y--;
00373 LimitMark(lptw, &lptw->MarkBegin);
00374 LimitMark(lptw, &lptw->MarkEnd);
00375 UpdateWindow(lptw->hWndText);
00376 }
00377 if (lptw->CursorFlag) TextToCursor(lptw);
00378
00379 }
00380
00381
00382
00383
00384 void UpdateText (LPTW lptw, int count)
00385 {
00386 HDC hdc;
00387
00388 int xpos, ypos;
00389 xpos = lptw->CursorPos.x * lptw->CharSize.x - lptw->ScrollPos.x;
00390 ypos = lptw->CursorPos.y * lptw->CharSize.y - lptw->ScrollPos.y;
00391 hdc = GetDC (lptw->hWndText);
00392
00393 SetTextColor (hdc, GetIhmTextColor());
00394 SetBkColor (hdc, GetIhmTextBackgroundColor());
00395
00396 SelectFont (hdc, lptw->hfont);
00397 TextOut (hdc, xpos, ypos,(LPSTR) (lptw->ScreenBuffer + lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x), count);
00398 ReleaseDC (lptw->hWndText, hdc);
00399 lptw->CursorPos.x += count;
00400 if (lptw->CursorPos.x >= lptw->ScreenSize.x) NewLine (lptw);
00401 else
00402 {
00403 RECT RectZone;
00404
00405 RectZone.left=0;
00406 RectZone.top=ypos;
00407 RectZone.bottom=ypos+lptw->CharSize.y;
00408 RectZone.right=xpos+lptw->CharSize.x;
00409
00410 InvalidateRect(lptw->hWndText,&RectZone,TRUE);
00411 }
00412 }
00413
00414 EXPORT int WINAPI TextPutCh (LPTW lptw, BYTE ch)
00415 {
00416 int pos;
00417
00418 switch (ch)
00419 {
00420 case '\r':
00421 lptw->CursorPos.x = 0;
00422 if (lptw->CursorFlag)
00423 TextToCursor (lptw);
00424 break;
00425 case '\n':
00426 NewLine (lptw);
00427 break;
00428 case 7:
00429 MessageBeep (MB_OK);
00430 if (lptw->CursorFlag)
00431 TextToCursor (lptw);
00432 break;
00433 case '\t':
00434 {
00435 int n;
00436 for (n = 8 - (lptw->CursorPos.x % 8); n > 0; n--)
00437 TextPutCh (lptw, ' ');
00438 }
00439 break;
00440 case 0x08:
00441 case 0x7f:
00442 lptw->CursorPos.x--;
00443 if (lptw->CursorPos.x < 0)
00444 {
00445 lptw->CursorPos.x = lptw->ScreenSize.x - 1;
00446 lptw->CursorPos.y--;
00447 }
00448 if (lptw->CursorPos.y < 0)
00449 lptw->CursorPos.y = 0;
00450 break;
00451 default:
00452
00453 pos = lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x;
00454 lptw->ScreenBuffer[pos] = ch;
00455 lptw->AttrBuffer[pos] = lptw->Attr;
00456 UpdateText (lptw, 1);
00457 }
00458 return ch;
00459 }
00460
00461 void TextPutStr (LPTW lptw, LPSTR str)
00462 {
00463 BYTE FAR *p, FAR * pa;
00464 int count, limit;
00465 while (*str)
00466 {
00467 p = lptw->ScreenBuffer + lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x;
00468 pa = lptw->AttrBuffer + lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x;
00469 limit = lptw->ScreenSize.x - lptw->CursorPos.x;
00470
00471 for (count = 0; (count < limit) && *str && (iswprint ((int) str[0]) || *str == '\t'); count++)
00472 {
00473 if (*str == '\t')
00474 {
00475 int n;
00476 for (n = 8 - ((lptw->CursorPos.x + count) % 8); (count < limit) & (n > 0); n--, count++)
00477 {
00478 *p++ = ' ';
00479 *pa++ = lptw->Attr;
00480 }
00481 str++;
00482 count--;
00483 }
00484 else
00485 {
00486 *p++ = *str++;
00487 *pa++ = lptw->Attr;
00488 }
00489 }
00490 if (count > 0)
00491 {
00492 UpdateText (lptw, count);
00493 }
00494 if (*str == '\n')
00495 {
00496 NewLine (lptw);
00497 str++;
00498 }
00499 else if (*str && !iswprint ((int) str[0]) && *str != '\t')
00500 {
00501 TextPutCh (lptw, *str++);
00502 }
00503 }
00504 }
00505
00506 void LimitMark (LPTW lptw, POINT FAR * lppt)
00507 {
00508 if (lppt->x < 0)
00509 lppt->x = 0;
00510 if (lppt->y < 0)
00511 {
00512 lppt->x = 0;
00513 lppt->y = 0;
00514 }
00515 if (lppt->x > lptw->ScreenSize.x)
00516 lppt->x = lptw->ScreenSize.x;
00517 if (lppt->y >= lptw->ScreenSize.y)
00518 {
00519 lppt->x = 0;
00520 lppt->y = lptw->ScreenSize.y;
00521 }
00522 }
00523
00524 void ClearMark (LPTW lptw, POINT pt)
00525 {
00526 RECT rect1, rect2, rect3;
00527 int tmp;
00528 if ((lptw->MarkBegin.x != lptw->MarkEnd.x) ||
00529 (lptw->MarkBegin.y != lptw->MarkEnd.y))
00530 {
00531 if (lptw->MarkBegin.x > lptw->MarkEnd.x)
00532 {
00533 tmp = lptw->MarkBegin.x;
00534 lptw->MarkBegin.x = lptw->MarkEnd.x;
00535 lptw->MarkEnd.x = tmp;
00536 }
00537 if (lptw->MarkBegin.y > lptw->MarkEnd.y)
00538 {
00539 tmp = lptw->MarkBegin.y;
00540 lptw->MarkBegin.y = lptw->MarkEnd.y;
00541 lptw->MarkEnd.y = tmp;
00542 }
00543
00544 if (lptw->MarkBegin.y != lptw->MarkEnd.y)
00545 {
00546 rect1.left = 0;
00547 rect1.right = lptw->ScreenSize.x;
00548 }
00549 else
00550 {
00551 rect1.left = lptw->MarkBegin.x;
00552 rect1.right = lptw->MarkEnd.x + 1;
00553 }
00554 rect1.top = lptw->MarkBegin.y;
00555 rect1.bottom = lptw->MarkEnd.y + 1;
00556
00557 rect1.left = rect1.left * lptw->CharSize.x - lptw->ScrollPos.x;
00558 rect1.right = rect1.right * lptw->CharSize.x - lptw->ScrollPos.x;
00559 rect1.top = rect1.top * lptw->CharSize.y - lptw->ScrollPos.y;
00560 rect1.bottom = rect1.bottom * lptw->CharSize.y - lptw->ScrollPos.y;
00561
00562 GetClientRect (lptw->hWndText, &rect2);
00563 IntersectRect (&rect3, &rect1, &rect2);
00564
00565 if (!IsRectEmpty (&rect3))
00566 {
00567 InvalidateRect (lptw->hWndText, &rect3, TRUE);
00568 }
00569 }
00570 LimitMark (lptw, &pt);
00571 lptw->MarkBegin.x = lptw->MarkEnd.x = pt.x;
00572 lptw->MarkBegin.y = lptw->MarkEnd.y = pt.y;
00573 UpdateWindow (lptw->hWndText);
00574 }
00575
00576
00577 void DoLine(LPTW lptw, HDC hdc, int xpos, int ypos, int offset, int count)
00578 {
00579 BYTE FAR *pa, attr;
00580 int idx, num;
00581 pa = lptw->AttrBuffer + offset;
00582 if ((offset < 0) || (offset >= lptw->ScreenSize.x*lptw->ScreenSize.y))
00583 MessageBox((HWND)NULL, MSG_ERROR56, MSG_ERROR56, MB_OK | MB_ICONEXCLAMATION);
00584 idx = 0;
00585 num = count;
00586 while (num > 0)
00587 {
00588 attr = *pa;
00589 while ((num > 0) && (attr == *pa))
00590 {
00591
00592 num--;
00593 pa++;
00594 }
00595
00596 SetTextColor(hdc, GetIhmTextColor());
00597 SetBkColor(hdc, GetIhmTextBackgroundColor());
00598
00599 TextOut(hdc,xpos,ypos, (LPSTR)(lptw->ScreenBuffer + offset + idx),
00600 count-num-idx);
00601 xpos += lptw->CharSize.x * (count-num-idx);
00602 idx = count-num;
00603 }
00604 }
00605
00606 void DoMark (LPTW lptw, POINT pt, POINT end, BOOL mark)
00607 {
00608 int xpos, ypos;
00609 HDC hdc;
00610 int count;
00611 int offset;
00612 offset = lptw->ScreenSize.x * pt.y + pt.x;
00613 hdc = GetDC (lptw->hWndText);
00614 SelectFont (hdc, lptw->hfont);
00615
00616 SetTextColor (hdc, GetSysColor (COLOR_HIGHLIGHTTEXT));
00617 SetBkColor (hdc, GetSysColor (COLOR_HIGHLIGHT));
00618
00619 while (pt.y < end.y)
00620 {
00621
00622 xpos = pt.x * lptw->CharSize.x - lptw->ScrollPos.x;
00623 ypos = pt.y * lptw->CharSize.y - lptw->ScrollPos.y;
00624 count = lptw->ScreenSize.x - pt.x;
00625 if (mark)
00626 TextOut (hdc, xpos, ypos, (LPSTR) (lptw->ScreenBuffer + offset), count);
00627 else
00628 {
00629 DoLine (lptw, hdc, xpos, ypos, offset, count);
00630
00631 SetTextColor (hdc, GetSysColor (COLOR_HIGHLIGHTTEXT));
00632 SetBkColor (hdc, GetSysColor (COLOR_HIGHLIGHT));
00633 }
00634 offset += count;
00635 pt.y++;
00636 pt.x = 0;
00637 }
00638
00639 xpos = pt.x * lptw->CharSize.x - lptw->ScrollPos.x;
00640 ypos = pt.y * lptw->CharSize.y - lptw->ScrollPos.y;
00641 count = end.x - pt.x;
00642 if (end.y != lptw->ScreenSize.y)
00643 {
00644 if (mark)
00645 TextOut (hdc, xpos, ypos, (LPSTR) (lptw->ScreenBuffer + offset), count);
00646 else
00647 DoLine (lptw, hdc, xpos, ypos, offset, count);
00648 }
00649 (void) ReleaseDC (lptw->hWndText, hdc);
00650 }
00651
00652 void UpdateMark (LPTW lptw, POINT pt)
00653 {
00654 int begin, point, end;
00655 LimitMark (lptw, &pt);
00656 begin = lptw->ScreenSize.x * lptw->MarkBegin.y + lptw->MarkBegin.x;
00657 point = lptw->ScreenSize.x * pt.y + pt.x;
00658 end = lptw->ScreenSize.x * lptw->MarkEnd.y + lptw->MarkEnd.x;
00659
00660 if (begin <= end)
00661 {
00662
00663 if (point >= end)
00664 {
00665
00666 DoMark (lptw, lptw->MarkEnd, pt, TRUE);
00667 }
00668 else if (point >= begin)
00669 {
00670
00671 DoMark (lptw, pt, lptw->MarkEnd, FALSE);
00672 }
00673 else
00674 {
00675 DoMark (lptw, lptw->MarkBegin, lptw->MarkEnd, FALSE);
00676 DoMark (lptw, pt, lptw->MarkBegin, TRUE);
00677 }
00678 }
00679 else
00680 {
00681
00682 if (point <= end)
00683 {
00684
00685 DoMark (lptw, pt, lptw->MarkEnd, TRUE);
00686 }
00687 else if (point <= begin)
00688 {
00689
00690 DoMark (lptw, lptw->MarkEnd, pt, FALSE);
00691 }
00692 else
00693 {
00694 DoMark (lptw, lptw->MarkEnd, lptw->MarkBegin, FALSE);
00695 DoMark (lptw, lptw->MarkBegin, pt, TRUE);
00696 }
00697 }
00698 lptw->MarkEnd.x = pt.x;
00699 lptw->MarkEnd.y = pt.y;
00700 }
00701
00702 void TextMakeFont (LPTW lptw)
00703 {
00704 LOGFONT lf;
00705 TEXTMETRIC tm;
00706 LPSTR p;
00707 HDC hdc;
00708
00709 hdc = GetDC (lptw->hWndText);
00710 memset (&lf, 0, sizeof (LOGFONT));
00711 strncpy (lf.lfFaceName, lptw->fontname, LF_FACESIZE);
00712 lf.lfHeight = -MulDiv (lptw->fontsize, GetDeviceCaps (hdc, LOGPIXELSY), 72);
00713 lf.lfPitchAndFamily = FIXED_PITCH;
00714 lf.lfCharSet = SCI_DEFAULT_CHARSET;
00715 if ((p = strstr (lptw->fontname, " Italic")) != (LPSTR) NULL)
00716 {
00717 lf.lfFaceName[(unsigned int) (p - lptw->fontname)] = '\0';
00718 lf.lfItalic = TRUE;
00719 }
00720 if ((p = strstr (lptw->fontname, " Bold")) != (LPSTR) NULL)
00721 {
00722 lf.lfFaceName[(unsigned int) (p - lptw->fontname)] = '\0';
00723 lf.lfWeight = FW_BOLD;
00724 }
00725 if (lptw->hfont != 0)DeleteFont (lptw->hfont);
00726 lptw->hfont = CreateFontIndirect ((LOGFONT FAR *) & lf);
00727
00728 SelectFont (hdc, lptw->hfont);
00729 GetTextMetrics (hdc, (TEXTMETRIC FAR *) & tm);
00730 lptw->CharSize.y = tm.tmHeight;
00731 lptw->CharSize.x = tm.tmAveCharWidth;
00732 lptw->CharAscent = tm.tmAscent;
00733 if (lptw->bFocus) CreateCaret (lptw->hWndText, 0, lptw->CharSize.x, 2 + lptw->CaretHeight);
00734 ReleaseDC (lptw->hWndText, hdc);
00735 return;
00736 }
00737
00738 void TextSelectFont (LPTW lptw)
00739 {
00740 LOGFONT lf;
00741 CHOOSEFONT cf;
00742 HDC hdc;
00743 char lpszStyle[LF_FACESIZE];
00744 LPSTR p;
00745
00746 memset (&cf, 0, sizeof (CHOOSEFONT));
00747 memset (&lf, 0, sizeof (LOGFONT));
00748 cf.lStructSize = sizeof (CHOOSEFONT);
00749 cf.hwndOwner = lptw->hWndParent;
00750 strncpy (lf.lfFaceName, lptw->fontname, LF_FACESIZE);
00751 if ((p = strstr (lptw->fontname, " Bold")) != (LPSTR) NULL)
00752 {
00753 strncpy (lpszStyle, p + 1, LF_FACESIZE);
00754 lf.lfFaceName[(unsigned int) (p - lptw->fontname)] = '\0';
00755 }
00756 else if ((p = strstr (lptw->fontname, " Italic")) != (LPSTR) NULL)
00757 {
00758 strncpy (lpszStyle, p + 1, LF_FACESIZE);
00759 lf.lfFaceName[(unsigned int) (p - lptw->fontname)] = '\0';
00760 }
00761 else
00762 strcpy (lpszStyle, "Regular");
00763 cf.lpszStyle = lpszStyle;
00764 hdc = GetDC (lptw->hWndText);
00765 lf.lfHeight = -MulDiv (lptw->fontsize, GetDeviceCaps (hdc, LOGPIXELSY), 72);
00766 ReleaseDC (lptw->hWndText, hdc);
00767 lf.lfPitchAndFamily = FIXED_PITCH;
00768 cf.lpLogFont = &lf;
00769 cf.nFontType = SCREEN_FONTTYPE;
00770 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT | CF_USESTYLE;
00771 if (ChooseFont (&cf))
00772 {
00773 RECT rect;
00774 strcpy (lptw->fontname, lf.lfFaceName);
00775 lptw->fontsize = cf.iPointSize / 10;
00776 if (cf.nFontType & BOLD_FONTTYPE)
00777 lstrcat (lptw->fontname, " Bold");
00778 if (cf.nFontType & ITALIC_FONTTYPE)
00779 lstrcat (lptw->fontname, " Italic");
00780 TextMakeFont (lptw);
00781
00782 GetClientRect (lptw->hWndText, (LPRECT) & rect);
00783 SendMessage (lptw->hWndText, WM_SIZE, SIZE_RESTORED,
00784 MAKELPARAM (rect.right - rect.left, rect.bottom - rect.top));
00785 GetClientRect (lptw->hWndText, (LPRECT) & rect);
00786 InvalidateRect (lptw->hWndText, (LPRECT) & rect, 1);
00787 UpdateWindow (lptw->hWndText);
00788 }
00789 }
00790
00791
00792
00793
00794
00795 EXPORT int WINAPI TextKBHit (LPTW lptw)
00796 {
00797 return (lptw->KeyBufIn != lptw->KeyBufOut);
00798 }
00799
00800
00801
00802
00803
00804
00805
00806 EXPORT int WINAPI TextGetCh (LPTW lptw)
00807 {
00808 int ch;
00809
00810 lptw->bGetCh = TRUE;
00811
00812 TextToCursor (lptw);
00813
00814 if (lptw->bFocus)
00815 {
00816 SetCaretPos (lptw->CursorPos.x * lptw->CharSize.x - lptw->ScrollPos.x,
00817 lptw->CursorPos.y * lptw->CharSize.y + lptw->CharAscent
00818 - lptw->CaretHeight - lptw->ScrollPos.y);
00819 ShowCaret (lptw->hWndText);
00820 }
00821
00832 do
00833 {
00834 if ( (!GetThreadPasteRunning()) && (!WriteInKeyBuf) ) Sleep(1);
00835 TextMessage();
00836 } while (!TextKBHit(lptw));
00837
00838 ch = *lptw->KeyBufOut++;
00839
00840
00841
00842 if (ch == (char)3)
00843 {
00844 if ( HasAZoneTextSelected(lptw) )
00845 {
00846 TextCopyClip(lptw);
00847 SendCTRLandAKey(CTRLE);
00848 return 1;
00849
00850 }
00851 }
00852
00853 if (lptw->KeyBufOut - lptw->KeyBuf >= (int) lptw->KeyBufSize) lptw->KeyBufOut = lptw->KeyBuf;
00854
00855 if (lptw->bFocus) HideCaret (lptw->hWndText);
00856
00857 lptw->bGetCh = FALSE;
00858 return ch;
00859
00860 }
00861
00862
00863
00864
00865
00866
00867 int CtrlCHit (LPTW lptw)
00868 {
00869 int ch;
00870
00871 if (TextKBHit (lptw))
00872 {
00873 ch = *lptw->KeyBufOut++;
00874 if (lptw->KeyBufOut - lptw->KeyBuf >= (int) lptw->KeyBufSize)
00875 lptw->KeyBufOut = lptw->KeyBuf;
00876 if (ch == 3)
00877 {
00878
00879 if ( HasAZoneTextSelected(lptw) )
00880 {
00881 TextCopyClip(lptw);
00882 }
00883 else
00884 {
00885 SignalCtrC ();
00886 }
00887
00888
00889 return (1);
00890 }
00891 }
00892 return (0);
00893 }
00894
00895
00896 EXPORT int WINAPI TextGetChE (LPTW lptw)
00897 {
00898 int ch;
00899 ch = TextGetCh (lptw);
00900 TextPutCh (lptw, (BYTE) ch);
00901 return ch;
00902 }
00903
00904 EXPORT LPSTR WINAPI TextGetS (LPTW lptw, LPSTR str, unsigned int size)
00905 {
00906 LPSTR next = str;
00907
00908 while (--size > 0)
00909 {
00910 switch (*next = TextGetChE (lptw))
00911 {
00912 case EOF:
00913 *next = '\0';
00914 if (next == str)
00915 return (char *) NULL;
00916 return str;
00917 case '\n':
00918 *(next + 1) = '\0';
00919 return str;
00920 case 0x08:
00921 case 0x7f:
00922 if (next > str)
00923 --next;
00924 break;
00925 default:
00926 ++next;
00927 }
00928 }
00929 *next = '\0';
00930 return str;
00931 }
00932
00933 EXPORT int WINAPI TextPutS (LPTW lptw, LPSTR str)
00934 {
00935 TextPutStr (lptw, str);
00936 return str[strlen (str) - 1];
00937 }
00938
00939
00940
00941
00942 EXPORT void WINAPI TextGotoXY (LPTW lptw, int x, int y)
00943 {
00944 lptw->CursorPos.x = x;
00945 lptw->CursorPos.y = y;
00946 }
00947
00948 EXPORT int WINAPI TextWhereX (LPTW lptw)
00949 {
00950 return lptw->CursorPos.x;
00951 }
00952
00953 EXPORT int WINAPI TextWhereY (LPTW lptw)
00954 {
00955 return lptw->CursorPos.y;
00956 }
00957
00958 EXPORT void WINAPI TextCursorHeight (LPTW lptw, int height)
00959 {
00960 lptw->CaretHeight = height;
00961 if (lptw->bFocus)
00962 CreateCaret (lptw->hWndText, 0, lptw->CharSize.x, 2 + lptw->CaretHeight);
00963 }
00964
00965 EXPORT void WINAPI TextClearEOL (LPTW lptw)
00966 {
00967 HDC hdc;
00968 int xpos, ypos;
00969 int from, len;
00970 POINT pt;
00971 pt.x = pt.y = 0;
00972 ClearMark(lptw, pt);
00973 from = lptw->CursorPos.y*lptw->ScreenSize.x + lptw->CursorPos.x;
00974 len = lptw->ScreenSize.x-lptw->CursorPos.x;
00975 _fmemset(lptw->ScreenBuffer + from, ' ', len);
00976 _fmemset(lptw->AttrBuffer + from, NOTEXT, len);
00977 xpos = lptw->CursorPos.x*lptw->CharSize.x - lptw->ScrollPos.x;
00978 ypos = lptw->CursorPos.y*lptw->CharSize.y - lptw->ScrollPos.y;
00979 hdc = GetDC(lptw->hWndText);
00980
00981 SetTextColor(hdc, GetIhmTextColor());
00982 SetBkColor(hdc, GetIhmTextBackgroundColor());
00983
00984 SelectObject(hdc, (lptw->hfont));
00985 TextOut(hdc,xpos,ypos,
00986 (LPSTR)(lptw->ScreenBuffer + lptw->CursorPos.y*lptw->ScreenSize.x +
00987 lptw->CursorPos.x), lptw->ScreenSize.x-lptw->CursorPos.x);
00988 (void)ReleaseDC(lptw->hWndText,hdc);
00989 }
00990
00991
00992
00993 EXPORT void WINAPI TextClearEOS (LPTW lptw)
00994 {
00995 RECT rect;
00996 int from, len;
00997 POINT pt;
00998 pt.x = pt.y = 0;
00999 ClearMark (lptw, pt);
01000 from = lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x;
01001 len = lptw->ScreenSize.x - lptw->CursorPos.x +
01002 (lptw->ScreenSize.y - lptw->CursorPos.y - 1) * lptw->ScreenSize.x;
01003 _fmemset(lptw->ScreenBuffer + from, ' ', len);
01004 _fmemset(lptw->AttrBuffer + from, NOTEXT, len);
01005 GetClientRect (lptw->hWndText, (LPRECT) & rect);
01006 InvalidateRect (lptw->hWndText, (LPRECT) & rect, 1);
01007 UpdateWindow (lptw->hWndText);
01008 }
01009
01010 EXPORT void WINAPI TextInsertLine (LPTW lptw)
01011 {
01012 RECT rect;
01013 int from, to, len;
01014 POINT pt;
01015 pt.x = pt.y = 0;
01016 ClearMark (lptw, pt);
01017 from = lptw->CursorPos.y * lptw->ScreenSize.x,
01018 to = (lptw->CursorPos.y + 1) * lptw->ScreenSize.x;
01019 len = (lptw->ScreenSize.y - lptw->CursorPos.y - 1) * lptw->ScreenSize.x;
01020 _fmemmove(lptw->ScreenBuffer + to, lptw->ScreenBuffer + from, len);
01021 _fmemmove(lptw->AttrBuffer + to, lptw->AttrBuffer + from, len);
01022 _fmemset(lptw->ScreenBuffer + from, ' ', lptw->ScreenSize.x);
01023 _fmemset(lptw->AttrBuffer + from, NOTEXT, lptw->ScreenSize.x);
01024 GetClientRect (lptw->hWndText, (LPRECT) & rect);
01025 InvalidateRect (lptw->hWndText, (LPRECT) & rect, 1);
01026 UpdateWindow (lptw->hWndText);
01027 if (lptw->CursorFlag) TextToCursor (lptw);
01028 }
01029
01030 EXPORT void WINAPI TextDeleteLine (LPTW lptw)
01031 {
01032 RECT rect;
01033 int from, to, len;
01034 POINT pt;
01035 pt.x = pt.y = 0;
01036 ClearMark (lptw, pt);
01037 to = lptw->CursorPos.y * lptw->ScreenSize.x,
01038 from = (lptw->CursorPos.y + 1) * lptw->ScreenSize.x;
01039 len = (lptw->ScreenSize.y - lptw->CursorPos.y - 1) * lptw->ScreenSize.x;
01040 _fmemmove(lptw->ScreenBuffer + to, lptw->ScreenBuffer + from, len);
01041 _fmemmove(lptw->AttrBuffer + to, lptw->AttrBuffer + from, len);
01042 from = lptw->ScreenSize.x * (lptw->ScreenSize.y - 1);
01043 _fmemset(lptw->ScreenBuffer + from, ' ', lptw->ScreenSize.x);
01044 _fmemset(lptw->AttrBuffer + from, NOTEXT, lptw->ScreenSize.x);
01045 GetClientRect (lptw->hWndText, (LPRECT) & rect);
01046 InvalidateRect (lptw->hWndText, (LPRECT) & rect, 1);
01047 UpdateWindow (lptw->hWndText);
01048 if (lptw->CursorFlag) TextToCursor (lptw);
01049 }
01050
01051 EXPORT void WINAPI TextScrollReverse (LPTW lptw)
01052 {
01053 RECT rect;
01054 int len = lptw->ScreenSize.x * (lptw->ScreenSize.y - 1);
01055 _fmemmove(lptw->ScreenBuffer+lptw->ScreenSize.x, lptw->ScreenBuffer, len);
01056 _fmemset(lptw->ScreenBuffer, ' ', lptw->ScreenSize.x);
01057 _fmemmove(lptw->AttrBuffer+lptw->ScreenSize.x, lptw->AttrBuffer, len);
01058 _fmemset(lptw->AttrBuffer, NOTEXT, lptw->ScreenSize.x);
01059 if (lptw->CursorPos.y)
01060 lptw->CursorPos.y--;
01061 ScrollWindow (lptw->hWndText, 0, +lptw->CharSize.y, NULL, NULL);
01062 GetClientRect (lptw->hWndText, (LPRECT) & rect);
01063 rect.top = lptw->ScreenSize.y * lptw->CharSize.y;
01064 if (rect.top < rect.bottom) InvalidateRect (lptw->hWndText, (LPRECT) & rect, 1);
01065 lptw->MarkBegin.y++;
01066 lptw->MarkEnd.y++;
01067 LimitMark (lptw, &lptw->MarkBegin);
01068 LimitMark (lptw, &lptw->MarkEnd);
01069 UpdateWindow (lptw->hWndText);
01070 }
01071
01072 EXPORT void WINAPI TextAttr (LPTW lptw, BYTE attr)
01073 {
01074 lptw->Attr = attr;
01075 }
01076
01077 void HelpOn(LPTW lptw)
01078
01079 {
01080 HDC hdc;
01081 HGLOBAL hGMem;
01082
01083 TEXTMETRIC tm;
01084 UINT type;
01085 LPSTR lpMem;
01086 char *MessagePaste=NULL;
01087 char Command[MAX_PATH];
01088
01089 strcpy(Command,"");
01090
01091
01092
01093 TextCopyClip (lptw);
01094
01095
01096
01097 hdc = GetDC (lptw->hWndText);
01098 SelectFont (hdc, lptw->hfont);
01099 GetTextMetrics (hdc, (TEXTMETRIC *) & tm);
01100 if (tm.tmCharSet == OEM_CHARSET) type = CF_OEMTEXT;
01101 else type = CF_TEXT;
01102 ReleaseDC (lptw->hWndText, hdc);
01103
01104 OpenClipboard (lptw->hWndText);
01105 hGMem = GetClipboardData (type);
01106 if (hGMem)
01107 {
01108 int i=0;
01109 int l=0;
01110
01111 lpMem= GlobalLock (hGMem);
01112 l=strlen(lpMem);
01113 MessagePaste=(char*)MALLOC( (l+1)*sizeof(char));
01114 strcpy(MessagePaste,lpMem);
01115 MessagePaste[l]='\0';
01116 GlobalUnlock (hGMem);
01117
01118
01119
01120
01121
01122 l=strlen(MessagePaste);
01123 for (i=0;i<l;i++)
01124 {
01125 if (MessagePaste[i]==':') MessagePaste[i]=' ';
01126 if (MessagePaste[i]=='\n') MessagePaste[i]=' ';
01127 if (MessagePaste[i]=='\r') MessagePaste[i]=' ';
01128 }
01129
01130 }
01131 CloseClipboard ();
01132
01133 if (MessagePaste)
01134 {
01135
01136 int minlen=strlen("help \"\"");
01137
01138 if ( strlen(MessagePaste)+minlen > MAX_PATH)
01139 {
01140 char MessageTMP[MAX_PATH];
01141 strncpy(MessageTMP,MessagePaste,MAX_PATH-minlen);
01142 wsprintf(Command,"help \"%s\"",MessageTMP);
01143 }
01144 else
01145 {
01146 wsprintf(Command,"help \"%s\"",MessagePaste);
01147 }
01148
01149 if (strcmp (Command,"help \"\"")!=0 ) StoreCommand1 (Command,0);
01150 FREE(MessagePaste);
01151 }
01152
01153 }
01154
01155
01156 void CutSelection(LPTW lptw)
01157 {
01158 }
01159
01160 void OnRightClickMenu(LPTW lptw)
01161
01162 {
01163
01164
01165 if (lptw->hPopMenu) DestroyMenu(lptw->hPopMenu);
01166 lptw->hPopMenu = CreatePopupMenu ();
01167
01168 switch (lptw->lpmw->CodeLanguage)
01169 {
01170 case 1:
01171 {
01172
01173 AppendMenu (lptw->hPopMenu, MF_STRING|MF_ENABLED, M_SELECT_ALL, MSG_SCIMSG67);
01174 AppendMenu (lptw->hPopMenu, MF_SEPARATOR, 0, NULL);
01175 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED, M_COPY_CLIP, MSG_SCIMSG68);
01176 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED, M_PASTE, MSG_SCIMSG69);
01177
01178 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_PRINTSELECTION, MSG_SCIMSG70);
01179 AppendMenu (lptw->hPopMenu, MF_SEPARATOR, 0, NULL);
01180 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_EVALSELECTION, MSG_SCIMSG71);
01181 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_OPENSELECTION, MSG_SCIMSG72);
01182 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_HELPON, MSG_SCIMSG73);
01183 }
01184 break;
01185 default: case 0:
01186 {
01187
01188 AppendMenu (lptw->hPopMenu, MF_STRING|MF_ENABLED, M_SELECT_ALL, MSG_SCIMSG74);
01189 AppendMenu (lptw->hPopMenu, MF_SEPARATOR, 0, NULL);
01190 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED, M_COPY_CLIP, MSG_SCIMSG75);
01191 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED, M_PASTE, MSG_SCIMSG76);
01192
01193 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_PRINTSELECTION, MSG_SCIMSG77);
01194 AppendMenu (lptw->hPopMenu, MF_SEPARATOR, 0, NULL);
01195 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_EVALSELECTION, MSG_SCIMSG78);
01196 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_OPENSELECTION, MSG_SCIMSG79);
01197 AppendMenu (lptw->hPopMenu, MF_STRING|MF_GRAYED,M_HELPON, MSG_SCIMSG80);
01198
01199 }
01200 break;
01201 }
01202 SendMessage (lptw->hWndText, WM_LBUTTONUP,0, 0);
01203
01204 }
01205
01206 void EvaluateSelection(LPTW lptw)
01207 {
01208 HDC hdc;
01209 HGLOBAL hGMem;
01210
01211 TEXTMETRIC tm;
01212 UINT type;
01213 LPSTR lpMem;
01214 char *MessagePaste=NULL;
01215
01216
01217
01218
01219 TextCopyClip (lptw);
01220
01221
01222
01223 hdc = GetDC (lptw->hWndText);
01224 SelectFont (hdc, lptw->hfont);
01225 GetTextMetrics (hdc, (TEXTMETRIC *) & tm);
01226 if (tm.tmCharSet == OEM_CHARSET) type = CF_OEMTEXT;
01227 else type = CF_TEXT;
01228 ReleaseDC (lptw->hWndText, hdc);
01229
01230 OpenClipboard (lptw->hWndText);
01231 hGMem = GetClipboardData (type);
01232 if (hGMem)
01233 {
01234 int i=0;
01235 int l=0;
01236
01237 lpMem= GlobalLock (hGMem);
01238 l=strlen(lpMem);
01239 MessagePaste=(char*)MALLOC(l*sizeof(char));
01240 strcpy(MessagePaste,lpMem);
01241 GlobalUnlock (hGMem);
01242 }
01243 CloseClipboard ();
01244 strcat(MessagePaste,"\n");
01245 write_scilab_synchro(MessagePaste);
01246
01247 }
01248
01249 void OpenSelection(LPTW lptw)
01250
01251 {
01252 HDC hdc;
01253 HGLOBAL hGMem;
01254
01255 TEXTMETRIC tm;
01256 UINT type;
01257 LPSTR lpMem;
01258 char *MessagePaste=NULL;
01259 char FileName[MAX_PATH];
01260 char FileNameSCE[MAX_PATH];
01261 char FileNameSCI[MAX_PATH];
01262 char Command[MAX_PATH];
01263
01264
01265
01266
01267 TextCopyClip (lptw);
01268
01269
01270
01271 hdc = GetDC (lptw->hWndText);
01272 SelectFont (hdc, lptw->hfont);
01273 GetTextMetrics (hdc, (TEXTMETRIC *) & tm);
01274 if (tm.tmCharSet == OEM_CHARSET) type = CF_OEMTEXT;
01275 else type = CF_TEXT;
01276 ReleaseDC (lptw->hWndText, hdc);
01277
01278 OpenClipboard (lptw->hWndText);
01279 hGMem = GetClipboardData (type);
01280 if (hGMem)
01281 {
01282 int i=0;
01283 int l=0;
01284
01285 lpMem= GlobalLock (hGMem);
01286 l=strlen(lpMem);
01287 MessagePaste=(char*)MALLOC(l*sizeof(char));
01288 strcpy(MessagePaste,lpMem);
01289 GlobalUnlock (hGMem);
01290
01291
01292
01293
01294
01295 l=strlen(MessagePaste);
01296 for (i=0;i<l;i++)
01297 {
01298 if (MessagePaste[i]=='\n') MessagePaste[i]='\0';
01299 if (MessagePaste[i]=='\r') MessagePaste[i]='\0';
01300 }
01301 }
01302 CloseClipboard ();
01303
01304 strcpy(FileName,MessagePaste);
01305
01306 strcpy(FileNameSCI,MessagePaste);
01307 strcat(FileNameSCI,".sci");
01308
01309 strcpy(FileNameSCE,MessagePaste);
01310 strcat(FileNameSCE,".sce");
01311
01312
01313
01314 if ( IsAFile(FileNameSCI) )
01315 {
01316 char Fichier[MAX_PATH];
01317 GetShortPathName(FileNameSCI,Fichier,MAX_PATH);
01318 ReplaceSlash(FileNameSCI,Fichier);
01319 wsprintf(Command,"scipad('%s')",FileNameSCI);
01320
01321 StoreCommand1 (Command, 0);
01322 return ;
01323 }
01324
01325 if ( IsAFile(FileNameSCE) )
01326 {
01327 char Fichier[MAX_PATH];
01328 GetShortPathName(FileNameSCE,Fichier,MAX_PATH);
01329 ReplaceSlash(FileNameSCE,Fichier);
01330 wsprintf(Command,"scipad('%s')",FileNameSCE);
01331 StoreCommand1 (Command, 0);
01332 return ;
01333 }
01334
01335 if ( IsAFile(FileName) )
01336 {
01337 char Fichier[MAX_PATH];
01338 GetShortPathName(FileName,Fichier,MAX_PATH);
01339 ReplaceSlash(FileName,Fichier);
01340
01341 wsprintf(Command,"scipad('%s')",FileName);
01342 StoreCommand1 (Command, 0);
01343 return ;
01344 }
01345 else
01346 {
01347
01348 char Message[MAX_PATH];
01349
01350 wsprintf(Message,MSG_SCIMSG81,FileNameSCI);
01351 if ( MessageBox(lptw->hWndText,Message,MSG_SCIMSG82,MB_YESNO|MB_ICONWARNING)== IDYES )
01352 {
01353 FILE *fp;
01354 char Fichier[MAX_PATH];
01355
01356 fp=fopen(FileNameSCI,"wt");
01357 if ( fp )
01358 {
01359 fclose(fp);
01360 GetShortPathName(FileNameSCI,Fichier,MAX_PATH);
01361 ReplaceSlash(FileNameSCI,Fichier);
01362 wsprintf(Command,"scipad('%s')",FileNameSCI);
01363 StoreCommand1 (Command, 0);
01364 }
01365 else
01366 {
01367 sciprint(MSG_ERROR57);
01368 SendCTRLandAKey(CTRLL);
01369 }
01370
01371 }
01372 }
01373
01374
01375 }
01376
01377 BOOL HasAZoneTextSelected(LPTW lptw)
01378 {
01379 BOOL ValRetour=FALSE;
01380
01381 if ( (lptw->ScreenSize.x * lptw->MarkBegin.y + lptw->MarkBegin.x) -
01382 (lptw->ScreenSize.x * lptw->MarkEnd.y + lptw->MarkEnd.x) != 0)
01383 {ValRetour=TRUE;}
01384
01385 return ValRetour;
01386 }
01387
01388 void ClearLinesScreenConsole(int NbrOfLines)
01389 {
01390 if (IsWindowInterface())
01391 {
01392 int X=0,Y=0;
01393 int i = 0;
01394 LPTW lptw=GetTextWinScilab();
01395
01396 X=lptw->CursorPos.x;
01397 Y=lptw->CursorPos.y-NbrOfLines;
01398 if (Y>0)
01399 {
01400 i=(Y)*lptw->ScreenSize.x;
01401
01402 _fmemset(lptw->ScreenBuffer + i, ' ', (NbrOfLines+1)*lptw->ScreenSize.x);
01403 _fmemset(lptw->AttrBuffer + i, NOTEXT, (NbrOfLines+1)*lptw->ScreenSize.x);
01404
01405 TextGotoXY (lptw, X,Y);
01406 InvalidateRect (lptw->hWndText, NULL, TRUE);
01407 }
01408 else
01409 {
01410 sciprint(MSG_WARNING28);
01411 }
01412 }
01413 }
01414
01415
01416 void ClearCommandWindow(LPTW lptw,BOOL Clearfirstline)
01417 {
01418
01419 if ( HasAZoneTextSelected(lptw) )
01420 {
01421 POINT pt;
01422 pt.x = 0;
01423 pt.y = 0;
01424 pt.x = (pt.x + lptw->ScrollPos.x)/lptw->CharSize.x;
01425 pt.y = (pt.y + lptw->ScrollPos.y)/lptw->CharSize.y;
01426 ClearMark(lptw, pt);
01427 lptw->Marking = FALSE;
01428 }
01429 if (Clearfirstline) SendCTRLandAKey(CTRLU);
01430 InitScreenBuffer(lptw);
01431
01432
01433 _fmemset (lptw->ScreenBuffer, ' ', lptw->ScreenSize.x * lptw->ScreenSize.y);
01434
01435
01436 TextGotoXY (lptw, 0, 0);
01437
01438 lptw->ScrollPos.x=0;
01439 lptw->ScrollPos.y=0;
01440 SetScrollPos (lptw->hWndText, SB_VERT, lptw->ScrollPos.y, TRUE);
01441 SetScrollPos (lptw->hWndText, SB_HORZ, lptw->ScrollPos.x, TRUE);
01442
01443 UpdateWindow (lptw->hWndText);
01444 InvalidateRect (lptw->hWndText, NULL, TRUE);
01445 }
01446
01447 void InitScreenBuffer(LPTW lptw)
01448 {
01449 HGLOBAL hglobal;
01450
01451
01452 hglobal = GlobalHandle (lptw->ScreenBuffer);
01453 if (hglobal)
01454 {
01455 GlobalUnlock (hglobal);
01456 GlobalFree (hglobal);
01457 }
01458
01459 hglobal = GlobalHandle (lptw->AttrBuffer);
01460 if (hglobal)
01461 {
01462 GlobalUnlock (hglobal);
01463 GlobalFree (hglobal);
01464 }
01465
01466
01467
01468
01469
01470 lptw->ScrollMax.y = max (0, lptw->CharSize.y * lptw->ScreenSize.y - lptw->ClientSize.y);
01471 lptw->ScrollPos.y = min (lptw->ScrollPos.y, lptw->ScrollMax.y);
01472
01473
01474 hglobal = GlobalAlloc (GHND, lptw->ScreenSize.x * lptw->ScreenSize.y);
01475
01476 lptw->ScreenBuffer = (BYTE FAR *) GlobalLock (hglobal);
01477 if (lptw->ScreenBuffer == (BYTE FAR *) NULL)
01478 {
01479 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
01480 exit(1);
01481 }
01482 _fmemset (lptw->ScreenBuffer, ' ', lptw->ScreenSize.x * lptw->ScreenSize.y);
01483
01484 hglobal = GlobalAlloc (GHND, lptw->ScreenSize.x * lptw->ScreenSize.y);
01485 lptw->AttrBuffer = (BYTE FAR *) GlobalLock (hglobal);
01486 if (lptw->AttrBuffer == (BYTE FAR *) NULL)
01487 {
01488 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
01489 exit(1);
01490 }
01491 _fmemset (lptw->AttrBuffer, NOTEXT, lptw->ScreenSize.x * lptw->ScreenSize.y);
01492
01493 SetScrollRange (lptw->hWndText, SB_VERT, 0, lptw->ScrollMax.y, FALSE);
01494 SetScrollPos (lptw->hWndText, SB_VERT, lptw->ScrollPos.y, TRUE);
01495 UpdateWindow (lptw->hWndText);
01496 }
01497
01498 void ForceToActiveWindowParent(void)
01499 {
01500 LPTW lptw=GetTextWinScilab();
01501
01502 while (GetForegroundWindow()!= lptw->hWndParent)
01503 {
01504 SetForegroundWindow(lptw->hWndParent);
01505 SetActiveWindow(lptw->hWndParent);
01506 Sleep(1);
01507 }
01508 }
01509
01510
01511
01512
01513
01514
01515
01516 void CleanPromptFromText(char *Text)
01517 {
01518 char *CleanText=NULL;
01519
01520 char prompt[6];
01521
01522 int LenText=0;
01523 int i=0;
01524
01525 LenText=strlen(Text)+1;
01526 CleanText=(char*)MALLOC(LenText*sizeof(char));
01527 strcpy(CleanText,Text);
01528
01529 strcpy(prompt,SCIPROMPT);
01530 ReplacePrompt(CleanText,prompt);
01531
01532 strcpy(prompt,SCIPROMPT_PAUSE);
01533 ReplacePrompt(CleanText,prompt);
01534
01535
01536 for (i=1;i<127;i++)
01537 {
01538 char TmpPrompt[6];
01539 wsprintf(TmpPrompt,SCIPROMPT_INTERRUPT,i);
01540 ReplacePrompt(CleanText,TmpPrompt);
01541 strcpy(TmpPrompt," ");
01542 }
01543
01544 strcpy(Text,CleanText);
01545
01546 FREE(CleanText);
01547 }
01548
01549 int ReplacePrompt(char *Text,char *prompt)
01550
01551 {
01552 int Retour=FALSE;
01553 int l=0;
01554 char *TextTMP=NULL;
01555 char *LocalPrompt=NULL;
01556
01557 char *OccurenceDebutPrompt=NULL;
01558
01559 LocalPrompt=(char*)MALLOC((strlen(prompt)+1)*sizeof(char));
01560 TextTMP=(char*)MALLOC((strlen(Text)+1)*sizeof(char));
01561
01562 strcpy(TextTMP,Text);
01563 strcpy(LocalPrompt,prompt);
01564
01565 l=strlen(LocalPrompt);
01566
01567 while ( OccurenceDebutPrompt = strstr(TextTMP,LocalPrompt) )
01568 {
01569 int j=0;
01570 if (OccurenceDebutPrompt)
01571 {
01572 for(j=0;j< (signed)( strlen(OccurenceDebutPrompt)- strlen(LocalPrompt) );j++)
01573 {
01574 OccurenceDebutPrompt[j]=OccurenceDebutPrompt[j+strlen(LocalPrompt)];
01575 }
01576 OccurenceDebutPrompt[j]='\0';
01577 Retour=TRUE;
01578 }
01579
01580 }
01581
01582 strcpy(Text,TextTMP);
01583
01584 FREE(TextTMP);
01585 FREE(LocalPrompt);
01586 return Retour;
01587
01588 }
01589
01590
01591
01592
01593 void ResizeScreenBuffer(LPTW lptw)
01594 {
01595 #define ScreenBufferSizeMaxY 25200
01596
01597
01598
01599 if (lptw->ScreenSize.y < ScreenBufferSizeMaxY )
01600 {
01601
01602 ReAllocScreenBuffer(lptw);
01603 }
01604 else
01605 {
01606
01607 ReorganizeScreenBuffer(lptw);
01608
01609 }
01610
01611
01612 SetScrollRange (lptw->hWndText, SB_VERT, 0, lptw->ScrollMax.y, FALSE);
01613
01614 SetScrollPos (lptw->hWndText, SB_VERT, lptw->ScrollPos.y, TRUE);
01615
01616 SetScrollPos (lptw->hWndText, SB_HORZ, lptw->ScrollPos.x, TRUE);
01617
01618
01619
01620 }
01621
01622 void ReAllocScreenBuffer(LPTW lptw)
01623 {
01624 #define AddLines 360
01625
01626 HGLOBAL hglobal;
01627 int NombredeCaracteres=0;
01628 BYTE *CopyOfScreenBuffer=NULL;
01629 BYTE *CopyOfAttribBuffer=NULL;
01630 int NewScreenSizeY=0;
01631
01632
01633 NombredeCaracteres=lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x;
01634 CopyOfScreenBuffer=(char*)MALLOC( (NombredeCaracteres+1)* sizeof(char));
01635 if (CopyOfScreenBuffer == NULL)
01636 {
01637 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
01638 return;
01639 }
01640
01641 strncpy(CopyOfScreenBuffer,(LPSTR)lptw->ScreenBuffer,NombredeCaracteres);
01642
01643
01644
01645 NewScreenSizeY=lptw->ScreenSize.y+AddLines;
01646
01647
01648 hglobal = GlobalHandle (lptw->ScreenBuffer);
01649 if (hglobal)
01650 {
01651 GlobalUnlock (hglobal);
01652 GlobalFree (hglobal);
01653 }
01654
01655 hglobal = GlobalAlloc (GHND, lptw->ScreenSize.x * NewScreenSizeY);
01656
01657 lptw->ScreenBuffer = (BYTE FAR *) GlobalLock (hglobal);
01658 if (lptw->ScreenBuffer == (BYTE FAR *) NULL)
01659 {
01660 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
01661 exit(1);
01662 }
01663
01664 _fmemset (lptw->ScreenBuffer, ' ', lptw->ScreenSize.x * NewScreenSizeY);
01665
01666 memcpy(lptw->ScreenBuffer,CopyOfScreenBuffer,NombredeCaracteres);
01667
01668 FREE(CopyOfScreenBuffer);
01669
01670
01671 CopyOfAttribBuffer=(char*)MALLOC( (NombredeCaracteres+1)* sizeof(char));
01672 if (CopyOfAttribBuffer == NULL)
01673 {
01674 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
01675 exit(1);
01676 }
01677 strncpy(CopyOfAttribBuffer,(LPSTR)lptw->AttrBuffer,NombredeCaracteres);
01678 hglobal = GlobalHandle (lptw->AttrBuffer);
01679 if (hglobal)
01680 {
01681 GlobalUnlock (hglobal);
01682 GlobalFree (hglobal);
01683 }
01684
01685 hglobal = GlobalAlloc (GHND, lptw->ScreenSize.x * NewScreenSizeY);
01686 lptw->AttrBuffer = (BYTE FAR *) GlobalLock (hglobal);
01687 if (lptw->AttrBuffer == (BYTE FAR *) NULL)
01688 {
01689 MessageBox ((HWND) NULL, szNoMemory, (LPSTR) NULL, MB_ICONHAND | MB_SYSTEMMODAL);
01690 exit(1);
01691 }
01692 _fmemset (lptw->AttrBuffer, NOTEXT, lptw->ScreenSize.x * NewScreenSizeY);
01693 memcpy(lptw->AttrBuffer,CopyOfAttribBuffer,NombredeCaracteres);
01694 FREE(CopyOfAttribBuffer);
01695
01696
01697 lptw->ScrollMax.y=lptw->ScrollMax.y+(lptw->CharSize.y*AddLines);
01698
01699 lptw->ScreenSize.y=NewScreenSizeY;
01700 }
01701
01702 void ReorganizeScreenBuffer(LPTW lptw)
01703 {
01704 #define RemoveLines 120
01705 int DecalageY=0;
01706 int NombredeCaracteres=0;
01707
01708 BYTE *CopyOfScreenBuffer=NULL;
01709 BYTE *CopyOfAttribBuffer=NULL;
01710
01711
01712 NombredeCaracteres=lptw->CursorPos.y * lptw->ScreenSize.x + lptw->CursorPos.x;
01713
01714 DecalageY=lptw->ScreenSize.x*RemoveLines;
01715
01716
01717 CopyOfScreenBuffer=(char*)MALLOC( (NombredeCaracteres+1)* sizeof(char));
01718
01719 strncpy(CopyOfScreenBuffer,(LPSTR)(lptw->ScreenBuffer+DecalageY),NombredeCaracteres-DecalageY);
01720 _fmemset (lptw->ScreenBuffer, ' ', lptw->ScreenSize.x * lptw->ScreenSize.y);
01721 strncpy((LPSTR)lptw->ScreenBuffer,CopyOfScreenBuffer,NombredeCaracteres-DecalageY);
01722 FREE(CopyOfScreenBuffer);
01723
01724
01725 CopyOfAttribBuffer=(char*)MALLOC( (NombredeCaracteres+1)* sizeof(char));
01726 strncpy(CopyOfAttribBuffer,(LPSTR)(lptw->AttrBuffer+DecalageY),NombredeCaracteres-DecalageY);
01727 _fmemset (lptw->AttrBuffer, NOTEXT, lptw->ScreenSize.x * lptw->ScreenSize.y);
01728 strncpy((LPSTR)lptw->AttrBuffer,CopyOfAttribBuffer,NombredeCaracteres-DecalageY);
01729 FREE(CopyOfAttribBuffer);
01730
01731
01732 lptw->CursorPos.y=lptw->CursorPos.y-RemoveLines;
01733 lptw->ScrollPos.y=lptw->ScrollPos.y-(RemoveLines*lptw->CharSize.y);
01734 }
01735
01736 void ExitWindow(void)
01737 {
01738 char Message[255];
01739 char Title[50];
01740 LPTW lptw=GetTextWinScilab();
01741
01742 if ( (get_is_reading()==FALSE) || (GetThreadPasteRunning()) )
01743 {
01744 if (GetThreadPasteRunning())SuspendThread(GetHandleThreadPaste());
01745
01746 switch (lptw->lpmw->CodeLanguage)
01747 {
01748 case 1:
01749 strcpy(Message,MSG_SCIMSG83);
01750 strcpy(Title,MSG_SCIMSG84);
01751 break;
01752 case 0:default:
01753 strcpy(Message,MSG_SCIMSG85);
01754 strcpy(Title,MSG_SCIMSG86);
01755 break;
01756 }
01757
01758 if (MessageBox(lptw->hWndParent,Message,Title,MB_SYSTEMMODAL|MB_YESNO|MB_ICONWARNING)==IDYES)
01759 {
01760
01761 ResumeThread(GetHandleThreadPaste());
01762 if (GetThreadPasteRunning())
01763 {
01764 TerminateThread(GetHandleThreadPaste(),1);
01765 SetThreadPasteRunning(FALSE);
01766 CloseHandle( GetHandleThreadPaste() );
01767 }
01768 if (IsEnableTransparencyMode()) ScilabFxFadeOut();
01769 WriteRegistryTxt (lptw);
01770 C2F(sciquit)();
01771 }
01772 else
01773 {
01774 if (GetThreadPasteRunning()) ResumeThread(GetHandleThreadPaste());
01775 }
01776 }
01777 else
01778 {
01779 if (lptw->bGetCh)
01780 {
01781 if (IsEnableTransparencyMode()) ScilabFxFadeOut();
01782 WriteRegistryTxt (lptw);
01783 C2F(sciquit)();
01784 }
01785 else
01786 {
01787 switch (lptw->lpmw->CodeLanguage)
01788 {
01789 case 1:
01790 strcpy(Message,MSG_SCIMSG83);
01791 strcpy(Title,MSG_SCIMSG84);
01792 break;
01793 case 0:default:
01794 strcpy(Message,MSG_SCIMSG85);
01795 strcpy(Title,MSG_SCIMSG86);
01796 break;
01797 }
01798
01799 if (MessageBox(lptw->hWndParent,Message,Title,MB_SYSTEMMODAL|MB_YESNO|MB_ICONWARNING)==IDYES)
01800 {
01801 if (IsEnableTransparencyMode()) ScilabFxFadeOut();
01802 WriteRegistryTxt (lptw);
01803 C2F(sciquit)();
01804 }
01805 }
01806 }
01807 }
01808
01809 void write_scilab_synchro(char *line)
01810
01811
01812 {
01813 DWORD IdThreadWrite;
01814
01815 InitializeCriticalSection(&Sync);
01816 hThreadWrite=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)WriteTextThread,line,0,(LPDWORD)&IdThreadWrite);
01817 CloseHandle(hThreadWrite);
01818
01819 }
01820
01821 DWORD WINAPI WriteTextThread(LPVOID lpParam)
01822 {
01823 #define TEMPOTOUCHE 1
01824 char *line;
01825 LPTW lptw=GetTextWinScilab();
01826
01827 line=(char *)lpParam;
01828
01829 EnterCriticalSection(&Sync);
01830 while ( C2F (ismenu) () == 1 ) {Sleep(TEMPOTOUCHE);}
01831
01832 while ( lptw->bGetCh == FALSE ) {Sleep(TEMPOTOUCHE);}
01833
01834
01835 write_scilab(line);
01836 LeaveCriticalSection(&Sync);
01837 DeleteCriticalSection(&Sync);
01838 return 0;
01839 }
01840
01841 void InvalidateCursor( void )
01842 {
01843 POINT pt;
01844 GetCursorPos( &pt );
01845 SetCursorPos( pt.x, pt.y );
01846 }
01847
01848
01849
01850 void SelectAll(LPTW lptw,BOOL DoAMark)
01851 {
01852 POINT pt;
01853 pt.x = 0;
01854 pt.y = 0;
01855 pt.x = (pt.x + lptw->ScrollPos.x)/lptw->CharSize.x;
01856 pt.y = (pt.y + lptw->ScrollPos.y)/lptw->CharSize.y;
01857 ClearMark(lptw, pt);
01858
01859 lptw->MarkBegin.x=0;
01860 lptw->MarkBegin.y=0;
01861 lptw->MarkEnd.x=lptw->CursorPos.x;
01862 lptw->MarkEnd.y=lptw->CursorPos.y;
01863
01864 SendMessage (lptw->hWndText, WM_HSCROLL,SB_LEFT, (LPARAM) 0);
01865 SendMessage (lptw->hWndText, WM_VSCROLL, SB_TOP, (LPARAM) 0);
01866
01867
01868 if (DoAMark)
01869 {
01870 DoMark (lptw, lptw->MarkBegin,lptw->MarkEnd, TRUE);
01871
01872
01873 if ((lptw->ScreenSize.x * lptw->MarkBegin.y + lptw->MarkBegin.x) >
01874 (lptw->ScreenSize.x * lptw->MarkEnd.y + lptw->MarkEnd.x))
01875 {
01876 POINT tmp;
01877 tmp.x = lptw->MarkBegin.x;
01878 tmp.y = lptw->MarkBegin.y;
01879 lptw->MarkBegin.x = lptw->MarkEnd.x;
01880 lptw->MarkBegin.y = lptw->MarkEnd.y;
01881 lptw->MarkEnd.x = tmp.x;
01882 lptw->MarkEnd.y = tmp.y;
01883 }
01884 }
01885 if ( HasAZoneTextSelected(lptw) )
01886 {
01887
01888 EnableMenuItem(lptw->hPopMenu,M_COPY_CLIP,MF_ENABLED);
01889 EnableMenuItem(lptw->hPopMenu,M_HELPON,MF_ENABLED);
01890 EnableMenuItem(lptw->hPopMenu,M_PRINTSELECTION,MF_ENABLED);
01891 EnableMenuItem(lptw->hPopMenu,M_OPENSELECTION,MF_ENABLED);
01892 EnableMenuItem(lptw->hPopMenu,M_EVALSELECTION,MF_ENABLED);
01893
01894
01895 }
01896
01897 }
01898
01899 void UnSelect(LPTW lptw)
01900 {
01901 POINT pt;
01902 pt=lptw->CursorPos;
01903
01904 ClearMark(lptw, pt);
01905 if ( !HasAZoneTextSelected(lptw) )
01906 {
01907
01908 EnableMenuItem(lptw->hPopMenu,M_COPY_CLIP,MF_GRAYED);
01909 EnableMenuItem(lptw->hPopMenu,M_HELPON,MF_GRAYED);
01910 EnableMenuItem(lptw->hPopMenu,M_PRINTSELECTION,MF_GRAYED);
01911 EnableMenuItem(lptw->hPopMenu,M_OPENSELECTION,MF_GRAYED);
01912 EnableMenuItem(lptw->hPopMenu,M_EVALSELECTION,MF_GRAYED);
01913
01914
01915 }
01916 }
01917
01918
01919
01920
01921 BOOL WriteIntoScilab(LPTW lptw,char *StringCommand)
01922 {
01923 BOOL retour=FALSE;
01924
01925 if (( ( C2F (ismenu) () == 1 ) || ( lptw->bGetCh == FALSE ) ) && (!get_is_reading()) )
01926 {
01927 StoreCommand(StringCommand);
01928 }
01929 else
01930 {
01931 int lg=0;
01932 char *CommandLine=NULL;
01933
01934 lg=strlen(StringCommand)+1+1;
01935 CommandLine=(char*)MALLOC( (lg)*sizeof(char) );
01936
01937 sprintf(CommandLine,"%s\n",StringCommand);
01938
01939 WriteIntoKeyBuffer(lptw,CommandLine);
01940
01941 if (CommandLine) {FREE(CommandLine);CommandLine=NULL;}
01942 retour=TRUE;
01943 }
01944
01945 return retour;
01946 }
01947
01948
01949 void WriteIntoKeyBuffer(LPTW lptw,char *StringCommand)
01950 {
01951 int lg=0;
01952 int i=0;
01953
01954 lg=strlen(StringCommand);
01955 WriteInKeyBuf=TRUE;
01956 while(i<lg)
01957 {
01958 long count;
01959 count = lptw->KeyBufIn - lptw->KeyBufOut;
01960
01961 if (count < 0) count = count+lptw->KeyBufSize;
01962 if (count < (long) (lptw->KeyBufSize-1))
01963 {
01964 if (StringCommand[i] == '\t') *lptw->KeyBufIn++ = ' ';
01965 else *lptw->KeyBufIn++ = StringCommand[i];
01966 if (lptw->KeyBufIn - lptw->KeyBuf >= (signed)lptw->KeyBufSize)
01967 lptw->KeyBufIn = lptw->KeyBuf;
01968 }
01969 i++;
01970 }
01971 WriteInKeyBuf=FALSE;
01972 }
01973
01974 BOOL IsToThePrompt(void)
01975 {
01976 BOOL retour=FALSE;
01977 LPTW lptw=GetTextWinScilab();
01978
01979 if (( ( C2F (ismenu) () == 1 ) || ( lptw->bGetCh == FALSE ) ) && (!get_is_reading()) ) retour=FALSE;
01980 else retour=TRUE;
01981
01982 return retour;
01983 }
01984
01985 void EnableNMenus(LPTW lptw,int numbermenus)
01986 {
01987 int i=0;
01988 for(i=0;i<numbermenus;i++)
01989 {
01990 EnableMenuItem (lptw->lpmw->hMenu, i, MF_ENABLED| MF_BYPOSITION);
01991 }
01992 DrawMenuBar(lptw->hWndParent);
01993 }
01994
01995 void EnableMenus(LPTW lptw)
01996 {
01997 int Nums = GetMenuItemCount (lptw->lpmw->hMenu);
01998 EnableNMenus(lptw,Nums);
01999 }
02000
02001 void DisableMenus(LPTW lptw)
02002 {
02003 int i=0;
02004 int Nums = GetMenuItemCount (lptw->lpmw->hMenu);
02005
02006 for(i=0;i<Nums;i++)
02007 {
02008 EnableMenuItem (lptw->lpmw->hMenu, i, MF_GRAYED| MF_BYPOSITION);
02009 }
02010 DrawMenuBar(lptw->hWndParent);
02011 }
02012
02013 int GetCurrentLanguage(void)
02014 {
02015 int ReturnLanguage=0;
02016
02017 if (IsWindowInterface())
02018 {
02019 LPTW lptw=GetTextWinScilab();
02020 int IHMLanguage=lptw->lpmw->CodeLanguage;
02021 ReturnLanguage=IHMLanguage;
02022 }
02023 else
02024 {
02025 int SCILanguague=GetLanguageCodeInScilabDotStar();
02026 ReturnLanguage=SCILanguague;
02027 }
02028
02029 return ReturnLanguage;
02030 }
02031