0024157: Parallelization of assembly part of BO
[occt.git] / src / Draw / CommandWindow.cxx
CommitLineData
b311480e 1// Created on: 1998-08-06
2// Created by: Administrateur Atelier MDL
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#ifdef WNT
18#include <windows.h>
19
20#define COMMANDCLASS "COMMANDWINDOW"
21#define COMMANDTITLE "Command Window"
22
23#include <CommandWindow.h>
24#include <Draw_Window.hxx>
25#include <MainWindow.h>
26#include <Draw_Appli.hxx>
27
28
29
30/****************************************************\
31* CommandWindow.cxx :
32*
33\****************************************************/
34
35
36
7fd59977 37#define CLIENTWND 0
38
39#define PROMPT "Command >> "
0d969553 40#define COMMANDSIZE 1000 // Max nb of characters for a command
7fd59977 41
42
0d969553 43// Definition of global variables
7fd59977 44#ifdef STRICT
0d969553 45 WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class)
7fd59977 46#else
47 FARPROC OldEditProc;
48#endif
49
50/*--------------------------------------------------------*\
51| CREATE COMMAND WINDOW PROCEDURE
52\*--------------------------------------------------------*/
35e08fe8 53HWND CreateCommandWindow(HWND hWnd, int /*nitem*/)
7fd59977 54{
55 HINSTANCE hInstance;
56
57#ifndef _WIN64
58 hInstance = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
59#else
60 hInstance = (HINSTANCE)GetWindowLong(hWnd,GWLP_HINSTANCE);
61#endif
62 HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE,
63 WS_CLIPCHILDREN | WS_OVERLAPPED |
64 WS_THICKFRAME | WS_CAPTION ,
65 0, 0,
66 400, 100,
67 hWnd, NULL, hInstance, NULL));
68
69 ShowWindow(hWndCommand, SW_SHOW);
70 return hWndCommand;
71}
72
73
74/*--------------------------------------------------------*\
75| COMMAND WINDOW PROCEDURE
76\*--------------------------------------------------------*/
6a7d83c4 77LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
7fd59977 78{
79 HWND hWndEdit;
7fd59977 80 MINMAXINFO* lpmmi;
81
82 switch(wMsg)
83 {
84 case WM_CREATE :
85 CommandCreateProc(hWnd);
86 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
87 SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT);
88 break;
89
90 case WM_GETMINMAXINFO :
91 lpmmi = (LPMINMAXINFO)lParam;
92 lpmmi->ptMinTrackSize.x = 200;
93 lpmmi->ptMinTrackSize.y = 50;
94 break;
95
96 case WM_SIZE :
6a7d83c4 97 {
7fd59977 98 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
99 MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
6a7d83c4 100 // Place the cursor at the end of the buffer
101 // Nb of characters in the buffer of hWndEdit
102 LRESULT index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
7fd59977 103 SendMessage(hWnd, EM_SETSEL, index, index);
104 break;
6a7d83c4 105 }
7fd59977 106
107 case WM_SETFOCUS :
108 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
109 SetFocus(hWndEdit);
110 break;
111
112 default :
113 return(DefWindowProc(hWnd, wMsg, wParam, lParam));
114 }
115 return(0l);
116}
117
118
119
6a7d83c4 120LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
7fd59977 121/*--------------------------------------------------------*\
122| COMMAND CREATE PROCEDURE
123\*--------------------------------------------------------*/
124BOOL CommandCreateProc(HWND hWnd)
125{
126
127#ifndef _WIN64
128 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
129#else
130 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
131#endif
132 HWND hWndEdit = CreateWindow("EDIT",NULL,
133 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
134 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
135 0, 0, 0, 0,
136 hWnd, 0,
137 hInstance, NULL);
138
0d969553 139 // Save hWndEdit in the extra memory in 0 of CommandWindow
7fd59977 140 if (hWndEdit)
141 SetWindowLong(hWnd, CLIENTWND, (LONG)hWndEdit);
142
0d969553 143 // Sub-Class of the window
7fd59977 144 //-------
0d969553 145 // Save the pointer on the existing procedure
7fd59977 146 #ifdef STRICT
147 #ifndef _WIN64
148 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
149 #else
150 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
151 #endif // _WIN64
152 #else
153 OldEditProc = (FARPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
154 #endif
0d969553 155 // Implement the new function
7fd59977 156#ifndef _WIN64
157 SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG) EditProc);
158#else
159 SetWindowLong(hWndEdit, GWLP_WNDPROC, (LONG) EditProc);
160#endif
161 return(TRUE);
162}
163
164
165/*--------------------------------------------------------*\
166| GET COMMAND
167|
168\*--------------------------------------------------------*/
169int GetCommand(HWND hWnd, char* buffer)
170{
171 int again = 1;
172 char temp[COMMANDSIZE]="";
173
6a7d83c4 174 int nbLine = (int )SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
7fd59977 175
176 int nbChar = 0;
177 buffer[0]='\0';
178 while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1)
179 {
180 strcat(buffer, strrev(temp));
0d969553 181 // Initialization of the 1st WORD to the nb of characters to read
7fd59977 182 WORD* nbMaxChar = (WORD*)temp;
183 *nbMaxChar = COMMANDSIZE-1;
184
6a7d83c4 185 int nbCharRead = (int )SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp);
7fd59977 186 nbChar += nbCharRead ;
187 int cmp = strncmp(temp, PROMPT, 10);
188 temp[nbCharRead]='\0';
189 if( cmp == 0 )
190 {
191 strcat(buffer, strrev(temp));
192 again = 0;
193 }
194 nbLine -= 1;
195 }
196 strrev(buffer);
197 return nbChar;
198}
199
200extern console_semaphore_value volatile console_semaphore;
201extern char console_command[1000];
202
203/*--------------------------------------------------------*\
204| EDIT WINDOW PROCEDURE
205\*--------------------------------------------------------*/
6a7d83c4 206LRESULT APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
7fd59977 207{
208 char buffer[COMMANDSIZE];
209 POINT pos;
210 BOOL rep;
6a7d83c4 211 static LRESULT nbline; // Process the buffer of the edit window
212 LRESULT index;
213
7fd59977 214 switch(wMsg)
215 {
216 case WM_CHAR :
217 if (console_semaphore != WAIT_CONSOLE_COMMAND)
218 return 0l;
219 switch(LOWORD(wParam))
220 {
0d969553 221 // Overload of character \n
7fd59977 222 case 0x0d :
223 GetCommand(hWnd, buffer);
0d969553 224 // Standard processing
7fd59977 225 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
0d969553 226 // Display of PROMPT
7fd59977 227 rep = GetCaretPos(&pos);
228 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT);
0d969553 229 // Display the command in the console
7fd59977 230 cout << buffer << endl;
231 /*if (Draw_Interprete(buffer+strlen(PROMPT))== -2)
232 DestroyProc(hWnd); */
233 strcpy(console_command, buffer+strlen(PROMPT));
234 console_semaphore = HAS_CONSOLE_COMMAND;
0d969553 235 // Purge the buffer
7fd59977 236 nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
237 if(nbline > 200)
238 {
239 nbline = 0;
240 GetCommand(hWnd, buffer);
241 index = SendMessage(hWnd, EM_LINEINDEX, 100, 0);
242 SendMessage(hWnd, EM_SETSEL, 0, index);
243 SendMessage(hWnd, WM_CUT, 0, 0);
0d969553 244 // Place the cursor at the end of text
7fd59977 245 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
246 SendMessage(hWnd, EM_SETSEL, index, index);
247 }
248 return(0l);
249 break;
250 default :
251 if (IsAlphanumeric((Standard_Character)LOWORD(wParam)))
252 {
0d969553 253 // Place the cursor at the end of text before display
7fd59977 254 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
255 SendMessage(hWnd, EM_SETSEL, index, index);
256 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
257 return 0l;
258 }
259 break;
260 }
261 break;
262 case WM_KEYDOWN:
263 if (console_semaphore != WAIT_CONSOLE_COMMAND)
264 return 0l;
265 }
266 return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
267}
268#endif
269
270