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