1 // Created on: 1998-08-06
2 // Created by: Administrateur Atelier MDL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
20 #define COMMANDCLASS "COMMANDWINDOW"
21 #define COMMANDTITLE "Command Window"
23 #include <CommandWindow.h>
24 #include <Draw_Window.hxx>
25 #include <MainWindow.h>
26 #include <Draw_Appli.hxx>
30 /****************************************************\
33 \****************************************************/
39 #define PROMPT "Command >> "
40 #define COMMANDSIZE 1000 // Max nb of characters for a command
43 // Definition of global variables
45 WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class)
50 /*--------------------------------------------------------*\
51 | CREATE COMMAND WINDOW PROCEDURE
52 \*--------------------------------------------------------*/
53 HWND CreateCommandWindow(HWND hWnd, int /*nitem*/)
56 hInstance = (HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
58 HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE,
59 WS_CLIPCHILDREN | WS_OVERLAPPED |
60 WS_THICKFRAME | WS_CAPTION ,
63 hWnd, NULL, hInstance, NULL));
65 ShowWindow(hWndCommand, SW_SHOW);
70 /*--------------------------------------------------------*\
71 | COMMAND WINDOW PROCEDURE
72 \*--------------------------------------------------------*/
73 LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
81 CommandCreateProc(hWnd);
82 hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND);
83 SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT);
86 case WM_GETMINMAXINFO :
87 lpmmi = (LPMINMAXINFO)lParam;
88 lpmmi->ptMinTrackSize.x = 200;
89 lpmmi->ptMinTrackSize.y = 50;
94 hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND);
95 MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
96 // Place the cursor at the end of the buffer
97 // Nb of characters in the buffer of hWndEdit
98 LRESULT index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
99 SendMessage(hWnd, EM_SETSEL, index, index);
104 hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND);
109 return(DefWindowProc(hWnd, wMsg, wParam, lParam));
116 LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
117 /*--------------------------------------------------------*\
118 | COMMAND CREATE PROCEDURE
119 \*--------------------------------------------------------*/
120 BOOL CommandCreateProc(HWND hWnd)
123 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
125 HWND hWndEdit = CreateWindow("EDIT",NULL,
126 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
127 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
132 // Save hWndEdit in the extra memory in 0 of CommandWindow
134 SetWindowLongPtr(hWnd, CLIENTWND, (LONG_PTR)hWndEdit);
136 // Sub-Class of the window
138 // Save the pointer on the existing procedure
140 OldEditProc = (WNDPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC);
142 OldEditProc = (FARPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC);
144 // Implement the new function
145 SetWindowLongPtr(hWndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc);
151 /*--------------------------------------------------------*\
154 \*--------------------------------------------------------*/
155 int GetCommand(HWND hWnd, char* buffer)
158 char temp[COMMANDSIZE]="";
160 int nbLine = (int )SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
164 while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1)
166 strcat(buffer, strrev(temp));
167 // Initialization of the 1st WORD to the nb of characters to read
168 WORD* nbMaxChar = (WORD*)temp;
169 *nbMaxChar = COMMANDSIZE-1;
171 int nbCharRead = (int )SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp);
172 nbChar += nbCharRead ;
173 int cmp = strncmp(temp, PROMPT, 10);
174 temp[nbCharRead]='\0';
177 strcat(buffer, strrev(temp));
186 extern console_semaphore_value volatile console_semaphore;
187 extern char console_command[1000];
189 /*--------------------------------------------------------*\
190 | EDIT WINDOW PROCEDURE
191 \*--------------------------------------------------------*/
192 LRESULT APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
194 char buffer[COMMANDSIZE];
197 static LRESULT nbline; // Process the buffer of the edit window
203 if (console_semaphore != WAIT_CONSOLE_COMMAND)
205 switch(LOWORD(wParam))
207 // Overload of character \n
209 GetCommand(hWnd, buffer);
210 // Standard processing
211 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
213 rep = GetCaretPos(&pos);
214 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT);
215 // Display the command in the console
216 cout << buffer << endl;
217 /*if (Draw_Interprete(buffer+strlen(PROMPT))== -2)
218 DestroyProc(hWnd); */
219 strcpy(console_command, buffer+strlen(PROMPT));
220 console_semaphore = HAS_CONSOLE_COMMAND;
222 nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
226 GetCommand(hWnd, buffer);
227 index = SendMessage(hWnd, EM_LINEINDEX, 100, 0);
228 SendMessage(hWnd, EM_SETSEL, 0, index);
229 SendMessage(hWnd, WM_CUT, 0, 0);
230 // Place the cursor at the end of text
231 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
232 SendMessage(hWnd, EM_SETSEL, index, index);
237 if (IsAlphanumeric((Standard_Character)LOWORD(wParam)))
239 // Place the cursor at the end of text before display
240 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
241 SendMessage(hWnd, EM_SETSEL, index, index);
242 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
249 if (console_semaphore != WAIT_CONSOLE_COMMAND)
252 return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);