1 // Created on: 1998-08-06
2 // Created by: Administrateur Atelier MDL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
27 #define COMMANDCLASS "COMMANDWINDOW"
28 #define COMMANDTITLE "Command Window"
30 #include <CommandWindow.h>
31 #include <Draw_Window.hxx>
32 #include <MainWindow.h>
33 #include <Draw_Appli.hxx>
37 /****************************************************\
40 \****************************************************/
46 #define PROMPT "Command >> "
47 #define COMMANDSIZE 1000 // Max nb of characters for a command
50 // Definition of global variables
52 WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class)
57 /*--------------------------------------------------------*\
58 | CREATE COMMAND WINDOW PROCEDURE
59 \*--------------------------------------------------------*/
60 HWND CreateCommandWindow(HWND hWnd, int nitem)
65 hInstance = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
67 hInstance = (HINSTANCE)GetWindowLong(hWnd,GWLP_HINSTANCE);
69 HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE,
70 WS_CLIPCHILDREN | WS_OVERLAPPED |
71 WS_THICKFRAME | WS_CAPTION ,
74 hWnd, NULL, hInstance, NULL));
76 ShowWindow(hWndCommand, SW_SHOW);
81 /*--------------------------------------------------------*\
82 | COMMAND WINDOW PROCEDURE
83 \*--------------------------------------------------------*/
84 LONG APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam )
87 int index; // Nb of characters in the buffer of hWndEdit
93 CommandCreateProc(hWnd);
94 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
95 SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT);
98 case WM_GETMINMAXINFO :
99 lpmmi = (LPMINMAXINFO)lParam;
100 lpmmi->ptMinTrackSize.x = 200;
101 lpmmi->ptMinTrackSize.y = 50;
105 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
106 MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
107 // Place the cursor at the end of the buffer
108 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
109 SendMessage(hWnd, EM_SETSEL, index, index);
113 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
118 return(DefWindowProc(hWnd, wMsg, wParam, lParam));
125 LONG APIENTRY EditProc(HWND, UINT, WPARAM, LONG);
126 /*--------------------------------------------------------*\
127 | COMMAND CREATE PROCEDURE
128 \*--------------------------------------------------------*/
129 BOOL CommandCreateProc(HWND hWnd)
133 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
135 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
137 HWND hWndEdit = CreateWindow("EDIT",NULL,
138 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
139 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
144 // Save hWndEdit in the extra memory in 0 of CommandWindow
146 SetWindowLong(hWnd, CLIENTWND, (LONG)hWndEdit);
148 // Sub-Class of the window
150 // Save the pointer on the existing procedure
153 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
155 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
158 OldEditProc = (FARPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
160 // Implement the new function
162 SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG) EditProc);
164 SetWindowLong(hWndEdit, GWLP_WNDPROC, (LONG) EditProc);
170 /*--------------------------------------------------------*\
173 \*--------------------------------------------------------*/
174 int GetCommand(HWND hWnd, char* buffer)
177 char temp[COMMANDSIZE]="";
179 int nbLine = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
183 while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1)
185 strcat(buffer, strrev(temp));
186 // Initialization of the 1st WORD to the nb of characters to read
187 WORD* nbMaxChar = (WORD*)temp;
188 *nbMaxChar = COMMANDSIZE-1;
190 int nbCharRead = SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp);
191 nbChar += nbCharRead ;
192 int cmp = strncmp(temp, PROMPT, 10);
193 temp[nbCharRead]='\0';
196 strcat(buffer, strrev(temp));
205 extern console_semaphore_value volatile console_semaphore;
206 extern char console_command[1000];
208 /*--------------------------------------------------------*\
209 | EDIT WINDOW PROCEDURE
210 \*--------------------------------------------------------*/
211 LONG APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam )
213 char buffer[COMMANDSIZE];
216 static int nbline; // Process the buffer of the edit window
222 if (console_semaphore != WAIT_CONSOLE_COMMAND)
224 switch(LOWORD(wParam))
226 // Overload of character \n
228 GetCommand(hWnd, buffer);
229 // Standard processing
230 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
232 rep = GetCaretPos(&pos);
233 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT);
234 // Display the command in the console
235 cout << buffer << endl;
236 /*if (Draw_Interprete(buffer+strlen(PROMPT))== -2)
237 DestroyProc(hWnd); */
238 strcpy(console_command, buffer+strlen(PROMPT));
239 console_semaphore = HAS_CONSOLE_COMMAND;
241 nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
245 GetCommand(hWnd, buffer);
246 index = SendMessage(hWnd, EM_LINEINDEX, 100, 0);
247 SendMessage(hWnd, EM_SETSEL, 0, index);
248 SendMessage(hWnd, WM_CUT, 0, 0);
249 // Place the cursor at the end of text
250 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
251 SendMessage(hWnd, EM_SETSEL, index, index);
256 if (IsAlphanumeric((Standard_Character)LOWORD(wParam)))
258 // Place the cursor at the end of text before display
259 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
260 SendMessage(hWnd, EM_SETSEL, index, index);
261 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
268 if (console_semaphore != WAIT_CONSOLE_COMMAND)
271 return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);