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 LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
92 CommandCreateProc(hWnd);
93 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
94 SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT);
97 case WM_GETMINMAXINFO :
98 lpmmi = (LPMINMAXINFO)lParam;
99 lpmmi->ptMinTrackSize.x = 200;
100 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 // Nb of characters in the buffer of hWndEdit
109 LRESULT index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
110 SendMessage(hWnd, EM_SETSEL, index, index);
115 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
120 return(DefWindowProc(hWnd, wMsg, wParam, lParam));
127 LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
128 /*--------------------------------------------------------*\
129 | COMMAND CREATE PROCEDURE
130 \*--------------------------------------------------------*/
131 BOOL CommandCreateProc(HWND hWnd)
135 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
137 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
139 HWND hWndEdit = CreateWindow("EDIT",NULL,
140 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
141 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
146 // Save hWndEdit in the extra memory in 0 of CommandWindow
148 SetWindowLong(hWnd, CLIENTWND, (LONG)hWndEdit);
150 // Sub-Class of the window
152 // Save the pointer on the existing procedure
155 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
157 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
160 OldEditProc = (FARPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
162 // Implement the new function
164 SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG) EditProc);
166 SetWindowLong(hWndEdit, GWLP_WNDPROC, (LONG) EditProc);
172 /*--------------------------------------------------------*\
175 \*--------------------------------------------------------*/
176 int GetCommand(HWND hWnd, char* buffer)
179 char temp[COMMANDSIZE]="";
181 int nbLine = (int )SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
185 while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1)
187 strcat(buffer, strrev(temp));
188 // Initialization of the 1st WORD to the nb of characters to read
189 WORD* nbMaxChar = (WORD*)temp;
190 *nbMaxChar = COMMANDSIZE-1;
192 int nbCharRead = (int )SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp);
193 nbChar += nbCharRead ;
194 int cmp = strncmp(temp, PROMPT, 10);
195 temp[nbCharRead]='\0';
198 strcat(buffer, strrev(temp));
207 extern console_semaphore_value volatile console_semaphore;
208 extern char console_command[1000];
210 /*--------------------------------------------------------*\
211 | EDIT WINDOW PROCEDURE
212 \*--------------------------------------------------------*/
213 LRESULT APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
215 char buffer[COMMANDSIZE];
218 static LRESULT nbline; // Process the buffer of the edit window
224 if (console_semaphore != WAIT_CONSOLE_COMMAND)
226 switch(LOWORD(wParam))
228 // Overload of character \n
230 GetCommand(hWnd, buffer);
231 // Standard processing
232 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
234 rep = GetCaretPos(&pos);
235 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT);
236 // Display the command in the console
237 cout << buffer << endl;
238 /*if (Draw_Interprete(buffer+strlen(PROMPT))== -2)
239 DestroyProc(hWnd); */
240 strcpy(console_command, buffer+strlen(PROMPT));
241 console_semaphore = HAS_CONSOLE_COMMAND;
243 nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
247 GetCommand(hWnd, buffer);
248 index = SendMessage(hWnd, EM_LINEINDEX, 100, 0);
249 SendMessage(hWnd, EM_SETSEL, 0, index);
250 SendMessage(hWnd, WM_CUT, 0, 0);
251 // Place the cursor at the end of text
252 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
253 SendMessage(hWnd, EM_SETSEL, index, index);
258 if (IsAlphanumeric((Standard_Character)LOWORD(wParam)))
260 // Place the cursor at the end of text before display
261 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
262 SendMessage(hWnd, EM_SETSEL, index, index);
263 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
270 if (console_semaphore != WAIT_CONSOLE_COMMAND)
273 return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);