Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Draw / CommandWindow.cxx
CommitLineData
7fd59977 1// File: CommandWindow.cxx
2// Created: Thu Aug 6 09:59:19 1998
3// Author: Administrateur Atelier MDL
4// <mdl@efalakox.paris1.matra-dtv.fr>
5
6
7
8#ifdef WNT
9#include <windows.h>
10
11#define COMMANDCLASS "COMMANDWINDOW"
12#define COMMANDTITLE "Command Window"
13
14#include <CommandWindow.h>
15#include <Draw_Window.hxx>
16#include <MainWindow.h>
17#include <Draw_Appli.hxx>
18
19
20
21/****************************************************\
22* CommandWindow.cxx :
23*
24\****************************************************/
25
26
27
28Standard_Boolean Draw_Interprete(char*); // Implemente dans draw.cxx
29
30#define CLIENTWND 0
31
32#define PROMPT "Command >> "
33#define COMMANDSIZE 1000 // Nb caracteres maximun pour un commande
34
35
36// Definition des varaibles globales
37#ifdef STRICT
38 WNDPROC OldEditProc; // Sauvegarde la procedure standard de la fenetre d'edition (Sous Classement)
39#else
40 FARPROC OldEditProc;
41#endif
42
43/*--------------------------------------------------------*\
44| CREATE COMMAND WINDOW PROCEDURE
45\*--------------------------------------------------------*/
46HWND CreateCommandWindow(HWND hWnd, int nitem)
47{
48 HINSTANCE hInstance;
49
50#ifndef _WIN64
51 hInstance = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
52#else
53 hInstance = (HINSTANCE)GetWindowLong(hWnd,GWLP_HINSTANCE);
54#endif
55 HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE,
56 WS_CLIPCHILDREN | WS_OVERLAPPED |
57 WS_THICKFRAME | WS_CAPTION ,
58 0, 0,
59 400, 100,
60 hWnd, NULL, hInstance, NULL));
61
62 ShowWindow(hWndCommand, SW_SHOW);
63 return hWndCommand;
64}
65
66
67/*--------------------------------------------------------*\
68| COMMAND WINDOW PROCEDURE
69\*--------------------------------------------------------*/
70LONG APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam )
71{
72 HWND hWndEdit;
73 int index; // Nombre de caractere dans le buffer de hWndEdit
74 MINMAXINFO* lpmmi;
75
76 switch(wMsg)
77 {
78 case WM_CREATE :
79 CommandCreateProc(hWnd);
80 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
81 SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT);
82 break;
83
84 case WM_GETMINMAXINFO :
85 lpmmi = (LPMINMAXINFO)lParam;
86 lpmmi->ptMinTrackSize.x = 200;
87 lpmmi->ptMinTrackSize.y = 50;
88 break;
89
90 case WM_SIZE :
91 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
92 MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
93 // Place le curseur a la fin du buffer
94 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
95 SendMessage(hWnd, EM_SETSEL, index, index);
96 break;
97
98 case WM_SETFOCUS :
99 hWndEdit = (HWND)GetWindowLong(hWnd, CLIENTWND);
100 SetFocus(hWndEdit);
101 break;
102
103 default :
104 return(DefWindowProc(hWnd, wMsg, wParam, lParam));
105 }
106 return(0l);
107}
108
109
110
111LONG APIENTRY EditProc(HWND, UINT, WPARAM, LONG);
112/*--------------------------------------------------------*\
113| COMMAND CREATE PROCEDURE
114\*--------------------------------------------------------*/
115BOOL CommandCreateProc(HWND hWnd)
116{
117
118#ifndef _WIN64
119 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
120#else
121 HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
122#endif
123 HWND hWndEdit = CreateWindow("EDIT",NULL,
124 WS_CHILD | WS_VISIBLE | WS_VSCROLL |
125 ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
126 0, 0, 0, 0,
127 hWnd, 0,
128 hInstance, NULL);
129
130 // Enregistrement hWndEdit deans l'extra memory en 0 de CommandWindow
131 if (hWndEdit)
132 SetWindowLong(hWnd, CLIENTWND, (LONG)hWndEdit);
133
134 // Sous Classement de la fenetre
135 //-------
136 // Sauvegarde du pointeur sur la procedure existante
137 #ifdef STRICT
138 #ifndef _WIN64
139 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
140 #else
141 OldEditProc = (WNDPROC)GetWindowLong(hWndEdit, GWLP_WNDPROC);
142 #endif // _WIN64
143 #else
144 OldEditProc = (FARPROC)GetWindowLong(hWndEdit, GWL_WNDPROC);
145 #endif
146 // Mise en place de la nouvelle fonction
147#ifndef _WIN64
148 SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG) EditProc);
149#else
150 SetWindowLong(hWndEdit, GWLP_WNDPROC, (LONG) EditProc);
151#endif
152 return(TRUE);
153}
154
155
156/*--------------------------------------------------------*\
157| GET COMMAND
158|
159\*--------------------------------------------------------*/
160int GetCommand(HWND hWnd, char* buffer)
161{
162 int again = 1;
163 char temp[COMMANDSIZE]="";
164
165 int nbLine = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
166
167 int nbChar = 0;
168 buffer[0]='\0';
169 while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1)
170 {
171 strcat(buffer, strrev(temp));
172 // Initialisation du 1er WORD de temp au nombre de caracteres a lire
173 WORD* nbMaxChar = (WORD*)temp;
174 *nbMaxChar = COMMANDSIZE-1;
175
176 int nbCharRead = SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp);
177 nbChar += nbCharRead ;
178 int cmp = strncmp(temp, PROMPT, 10);
179 temp[nbCharRead]='\0';
180 if( cmp == 0 )
181 {
182 strcat(buffer, strrev(temp));
183 again = 0;
184 }
185 nbLine -= 1;
186 }
187 strrev(buffer);
188 return nbChar;
189}
190
191extern console_semaphore_value volatile console_semaphore;
192extern char console_command[1000];
193
194/*--------------------------------------------------------*\
195| EDIT WINDOW PROCEDURE
196\*--------------------------------------------------------*/
197LONG APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam )
198{
199 char buffer[COMMANDSIZE];
200 POINT pos;
201 BOOL rep;
202 static int nbline; // Taille du buffer de la fenetre d`edition
203 int index;
204
205 switch(wMsg)
206 {
207 case WM_CHAR :
208 if (console_semaphore != WAIT_CONSOLE_COMMAND)
209 return 0l;
210 switch(LOWORD(wParam))
211 {
212 // Surcharge du caractere \n
213 case 0x0d :
214 GetCommand(hWnd, buffer);
215 // Traitement standard
216 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
217 // Affichage du PROMPT
218 rep = GetCaretPos(&pos);
219 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT);
220 // Affiche la commande dans la console
221 cout << buffer << endl;
222 /*if (Draw_Interprete(buffer+strlen(PROMPT))== -2)
223 DestroyProc(hWnd); */
224 strcpy(console_command, buffer+strlen(PROMPT));
225 console_semaphore = HAS_CONSOLE_COMMAND;
226 // Purge du buffer
227 nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l);
228 if(nbline > 200)
229 {
230 nbline = 0;
231 GetCommand(hWnd, buffer);
232 index = SendMessage(hWnd, EM_LINEINDEX, 100, 0);
233 SendMessage(hWnd, EM_SETSEL, 0, index);
234 SendMessage(hWnd, WM_CUT, 0, 0);
235 // Place le curseur en fin de text
236 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
237 SendMessage(hWnd, EM_SETSEL, index, index);
238 }
239 return(0l);
240 break;
241 default :
242 if (IsAlphanumeric((Standard_Character)LOWORD(wParam)))
243 {
244 // Place le curseur en fin de texte avant affichage
245 index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l);
246 SendMessage(hWnd, EM_SETSEL, index, index);
247 CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
248 return 0l;
249 }
250 break;
251 }
252 break;
253 case WM_KEYDOWN:
254 if (console_semaphore != WAIT_CONSOLE_COMMAND)
255 return 0l;
256 }
257 return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam);
258}
259#endif
260
261