0028110: Configuration - specify Unicode charset instead of multibyte in project...
[occt.git] / src / Draw / Draw_Window.hxx
CommitLineData
b311480e 1// Created on: 1994-07-27
2// Created by: Remi LEQUETTE
3// Copyright (c) 1994-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//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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#ifndef Draw_Window_HeaderFile
18#define Draw_Window_HeaderFile
19
20#include <Standard_Boolean.hxx>
21#include <Standard_Integer.hxx>
ad03c234 22#include <TCollection_AsciiString.hxx>
7fd59977 23
67d97f0e 24#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
7fd59977 25
26const Standard_Integer MAXCOLOR = 15;
27
28typedef unsigned long Window;
29typedef unsigned long Pixmap;
30typedef unsigned long Drawable;
31
32// Definition de la class Base_Window (Definie dans Draw_Window.cxx)
33//===================================
d677b214 34struct Base_Window;
7fd59977 35
36// Definition de la classe Segment
37//================================
38struct Segment
39{
40 short xx1;
41 short yy1;
42 short xx2;
43 short yy2;
44
45 void Init(short x1, short y1, short x2, short y2) {
46 xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2;
47 }
48
49};
50
51// Definition de la structure Event
52//=================================
53typedef struct Event
54{
55 Standard_Integer type;
56 Window window;
57 Standard_Integer button;
58 Standard_Integer x;
59 Standard_Integer y;
60} Event;
61
62// Definition de la classe Draw_Window
63//====================================
64class Draw_Window
65{
7fd59977 66 public :
67
a0fc422a 68 /**
69 * Type of the callback function that is to be passed to the method
70 * AddCallbackBeforeTerminate().
71 */
72 typedef void (*FCallbackBeforeTerminate)();
73
74 /**
75 * This method registers a callback function that will be called just before exit.
76 * This is usefull especially for Windows platform, on which Draw is normally
77 * self-terminated instead of exiting.
78 */
79 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
80
81 /**
82 * Just in case method for un-registering a callback previously registered by
83 * AddCallbackBeforeTerminate()
84 */
85 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
86
7fd59977 87 Draw_Window (); // the window is not initialized
88 Draw_Window (const char* title,
89 Standard_Integer X, Standard_Integer Y = 0,
90 Standard_Integer DX = 50, Standard_Integer DY = 50);
91
92 Draw_Window (Window mother);
93 Draw_Window (Window mother,char* title,
94 Standard_Integer X = 0, Standard_Integer Y = 0,
95 Standard_Integer DX = 50, Standard_Integer DY = 50);
96 Draw_Window(const char *window);
97
98 void Init (Standard_Integer X = 0, Standard_Integer Y = 0,
99 Standard_Integer DX = 50, Standard_Integer DY = 50);
100
101 void Init (Window mother,
102 Standard_Integer X = 0, Standard_Integer Y = 0,
103 Standard_Integer DX = 50, Standard_Integer DY = 50);
104
105
106 void StopWinManager();
107
108 void SetPosition (Standard_Integer NewXpos,
109 Standard_Integer NewYpos);
110
111 void SetDimension(Standard_Integer NewDx,
112 Standard_Integer NewDy);
113
114 void GetPosition(Standard_Integer &PosX,
115 Standard_Integer &PosY);
116
117 Standard_Integer HeightWin() const;
118 Standard_Integer WidthWin() const;
119
ad03c234 120 void SetTitle (const TCollection_AsciiString& theTitle);
121 TCollection_AsciiString GetTitle() const;
7fd59977 122
123 void DisplayWindow();
124 void Hide();
125 void Destroy();
126 void Clear();
127 void Wait(Standard_Boolean wait = Standard_True);
128
129 Drawable GetDrawable() const;
130 // Initializes off-screen image buffer according to current window size
131 void InitBuffer();
132
133 static Standard_Boolean DefineColor(const Standard_Integer, const char*);
134 void SetColor(int);
135 void SetMode(int);
136 void DrawString(int, int, char*);
137 void DrawSegments(Segment* ,int);
138 void Redraw();
139 static void Flush();
140
141 // save snapshot
142 Standard_Boolean Save(const char* theFileName) const;
143
144 virtual ~Draw_Window ();
145
146 // X Event management
147 virtual void WExpose();
148 virtual void WButtonPress(const Standard_Integer X,
149 const Standard_Integer Y,
150 const Standard_Integer& button);
151 virtual void WButtonRelease(const Standard_Integer X,
152 const Standard_Integer Y,
153 const Standard_Integer& button);
154 //virtual void WKeyPress(char, KeySym& );
155 virtual void WMotionNotify(const Standard_Integer X,
156 const Standard_Integer Y);
157
158 virtual void WConfigureNotify(const Standard_Integer X,
159 const Standard_Integer Y,
160 const Standard_Integer dx,
161 const Standard_Integer dy);
162
163 virtual void WUnmapNotify();
164
165 Base_Window& base;
166 Window win;
167 Window myMother; // default : myMother is the root window
168 Pixmap myBuffer;
169
170 static Draw_Window* firstWindow;
171 Draw_Window* next;
172 Draw_Window* previous;
173
174 Standard_Boolean myUseBuffer;
175 Standard_Boolean withWindowManager;
176
177};
178
179//======================================================
180// funtion : Run_Appli
181// purpose : run the application
182// interp will be called to interpret a command
183// and return True if the command is complete
184//======================================================
185
bf03eb83 186void Run_Appli(Standard_Boolean (*inteprete) (const char*));
7fd59977 187
188//======================================================
189// funtion : Init_Appli
190// purpose :
191//======================================================
192Standard_Boolean Init_Appli();
193
194//======================================================
195// funtion : Destroy_Appli()
196// purpose :
197//======================================================
198void Destroy_Appli();
199
200//======================================================
201// funtion : GetNextEvent()
202// purpose :
203//======================================================
204void GetNextEvent(Event&);
205
67d97f0e 206#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
207
208const Standard_Integer MAXCOLOR = 15;
209
210struct Segment
211{
212 Standard_Integer myXStart;
213 Standard_Integer myYStart;
214 Standard_Integer myXEnd;
215 Standard_Integer myYEnd;
216
217 void Init(short theXStart, short theYStart, short theXEnd, short theYEnd) {
218 myXStart = theXStart; myYStart = theYStart; myXEnd = theXEnd; myYEnd = theYEnd;
219 }
220
221};
222
223#ifdef __OBJC__
224 @class NSView;
225 @class NSWindow;
226 @class NSImage;
227 @class Draw_CocoaView;
7fd59977 228#else
67d97f0e 229 struct NSView;
230 struct NSWindow;
231 struct NSImage;
232 struct Draw_CocoaView;
233#endif
234
235
236class Draw_Window
237{
238 public :
239
a0fc422a 240 /**
241 * Type of the callback function that is to be passed to the method
242 * AddCallbackBeforeTerminate().
243 */
244 typedef void (*FCallbackBeforeTerminate)();
245
246 /**
247 * This method registers a callback function that will be called just before exit.
248 * This is usefull especially for Windows platform, on which Draw is normally
249 * self-terminated instead of exiting.
250 */
251 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
252
253 /**
254 * Just in case method for un-registering a callback previously registered by
255 * AddCallbackBeforeTerminate()
256 */
257 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
258
67d97f0e 259 Draw_Window (); // the window is not initialized
260 Draw_Window (Standard_CString theTitle,
261 const Standard_Integer& theXLeft = 0, const Standard_Integer& theYTop = 0,
262 const Standard_Integer& theWidth = 50, const Standard_Integer& theHeight = 50);
263
264 Draw_Window (NSWindow* theWindow, Standard_CString theTitle,
265 const Standard_Integer& theXLeft = 0, const Standard_Integer& theYTop = 0,
266 const Standard_Integer& theWidth = 50, const Standard_Integer& theHeight = 50);
267
268 void Init (const Standard_Integer& theXLeft = 0, const Standard_Integer& theYLeft = 0,
269 const Standard_Integer& theWidth = 50, const Standard_Integer& theHeight = 50);
270
271 virtual ~Draw_Window ();
272
273 void SetPosition (const Standard_Integer& theNewXpos,
274 const Standard_Integer& theNewYpos);
275
276 void SetDimension (const Standard_Integer& theNewWidth,
277 const Standard_Integer& theNewHeight);
278
279 void GetPosition (Standard_Integer &thePosX,
280 Standard_Integer &thePosY);
281
282 Standard_Integer HeightWin() const;
283 Standard_Integer WidthWin() const;
284
ad03c234 285 void SetTitle (const TCollection_AsciiString& theTitle);
286 TCollection_AsciiString GetTitle() const;
67d97f0e 287
288 void DisplayWindow();
289 void Hide();
290 void Destroy();
291 void Clear();
292
293 void InitBuffer();
294
295 static Standard_Boolean DefineColor (const Standard_Integer&, Standard_CString);
296 void SetColor (const Standard_Integer& theColor);
297 void SetMode (const Standard_Integer& theMode);
298 void DrawString (const Standard_Integer& theX, const Standard_Integer& theY, char* theText);
299 void DrawSegments (Segment* theSegment, const Standard_Integer& theNumberOfElements);
300 void Redraw();
301 static void Flush();
302
303 // save snapshot
304 Standard_Boolean Save (Standard_CString theFileName) const;
305
306 Standard_Boolean IsEqualWindows (const Standard_Integer& theWindowNumber);
307
308private:
309 NSWindow* myWindow;
310 Draw_CocoaView* myView;
311 NSImage* myImageBuffer;
312 Standard_Boolean myUseBuffer;
313 Standard_Integer myCurrentColor;
314
315 static Draw_Window* firstWindow;
316 Draw_Window* nextWindow;
317 Draw_Window* previousWindow;
318
319};
320
321//======================================================
322// funtion : Run_Appli
323// purpose : run the application
324// interp will be called to interpret a command
325// and return True if the command is complete
326//======================================================
327
328void Run_Appli(Standard_Boolean (*inteprete) (const char*));
329
330//======================================================
331// funtion : Init_Appli
332// purpose :
333//======================================================
334Standard_Boolean Init_Appli();
335
336//======================================================
337// funtion : Destroy_Appli()
338// purpose :
339//======================================================
340void Destroy_Appli();
341
342//======================================================
343// funtion : GetNextEvent()
344// purpose :
345//======================================================
346void GetNextEvent (Standard_Boolean theWait,
347 Standard_Integer& theWindowNumber,
348 Standard_Integer& theX,
349 Standard_Integer& theY,
350 Standard_Integer& theButton);
351#else
352
7fd59977 353// Specifique WNT
354
355#include <windows.h>
356
ad03c234 357#define DRAWCLASS L"DRAWWINDOW"
358#define DRAWTITLE L"Draw View"
7fd59977 359#define MAXCOLOR 15
360
361#if !defined(__Draw_API) && !defined(HAVE_NO_DLL)
362# ifdef __Draw_DLL
363# define __Draw_API __declspec( dllexport )
364# else
365# define __Draw_API __declspec( dllimport )
366# endif
367#endif
368
369// definition de la classe Segment
370
371class DrawWindow;
372class Segment
373{
374 friend class DrawWindow;
375 public :
376 //constructeur
377 Segment () {}
378 //destructeur
379 ~Segment () {}
380
381 //methods
382 void Init(Standard_Integer,
383 Standard_Integer,
384 Standard_Integer,
385 Standard_Integer);
386 private:
387 //atributs :
388 Standard_Integer x1;
389 Standard_Integer y1;
390 Standard_Integer x2;
391 Standard_Integer y2;
392};
393
394//definition de la classe DRAWWINDOW
395
396class DrawWindow
397{
398 //constructeur
399public:
a0fc422a 400
401 /**
402 * Type of the callback function that is to be passed to the method
403 * AddCallbackBeforeTerminate().
404 */
405 typedef void (*FCallbackBeforeTerminate)();
406
407 /**
408 * This method registers a callback function that will be called just before exit.
409 * This is usefull especially for Windows platform, on which Draw is normally
410 * self-terminated instead of exiting.
411 */
412 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
413
414 /**
415 * Just in case method for un-registering a callback previously registered by
416 * AddCallbackBeforeTerminate()
417 */
418 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
419
7fd59977 420 __Draw_API DrawWindow();
7c65581d 421 __Draw_API DrawWindow(const char*, Standard_Integer, Standard_Integer,
7fd59977 422 Standard_Integer, Standard_Integer);
7c65581d 423 __Draw_API DrawWindow(const char*, Standard_Integer, Standard_Integer,
7fd59977 424 Standard_Integer, Standard_Integer, HWND);
425 //destructeur
7c65581d 426 __Draw_API virtual ~DrawWindow();
7fd59977 427
428 //methods
429public:
430 __Draw_API void Init(Standard_Integer, Standard_Integer,
431 Standard_Integer, Standard_Integer);
432
433 __Draw_API void SetUseBuffer(Standard_Boolean);
434 // Turns on/off usage of off-screen image buffer (can be used for redrawing optimization)
435
7c65581d 436 Standard_Boolean GetUseBuffer() const { return myUseBuffer; }
7fd59977 437 // Returns Standard_True if off-screen image buffer is being used
438
439 //taille et position
440 __Draw_API void SetPosition (Standard_Integer,Standard_Integer);
441 __Draw_API void SetDimension(Standard_Integer,Standard_Integer);
442 __Draw_API void GetPosition (Standard_Integer&,Standard_Integer&);
443 __Draw_API Standard_Integer HeightWin() const;
444 __Draw_API Standard_Integer WidthWin() const;
445
446 //Title
ad03c234 447 __Draw_API void SetTitle (const TCollection_AsciiString& );
448 __Draw_API TCollection_AsciiString GetTitle() const;
7fd59977 449
450 //Affichage
451 __Draw_API void DisplayWindow();
452 __Draw_API void Hide();
453 __Draw_API void Destroy();
454 __Draw_API void Clear();
7c65581d 455 static void Flush() {} ;
7fd59977 456
457 // save snapshot
458 __Draw_API Standard_Boolean Save(const char* theFileName) const;
459
460 //Dessin
461 __Draw_API void DrawString(int,int,char*);
462 __Draw_API void DrawSegments(Segment*,int);
463
464 __Draw_API void InitBuffer();
465 // Initializes off-screen image buffer according to current window size
466
467 __Draw_API void Redraw();
468 // Copies an image from memory buffer to screen
469
470 //Couleur
471 __Draw_API void SetColor(Standard_Integer);
472 __Draw_API void SetMode(int);
473 __Draw_API static Standard_Boolean DefineColor ( const Standard_Integer,const char*);
474
475 //Gestion des Messages
476 __Draw_API virtual void WExpose ();
477 __Draw_API virtual void WButtonPress(const Standard_Integer,const Standard_Integer,
478 const Standard_Integer&);
479 __Draw_API virtual void WButtonRelease(const Standard_Integer,const Standard_Integer,
480 const Standard_Integer&);
481 __Draw_API virtual void WMotionNotify(const Standard_Integer,const Standard_Integer);
482 __Draw_API virtual void WConfigureNotify(const Standard_Integer,const Standard_Integer,
483 const Standard_Integer,const Standard_Integer);
484 __Draw_API virtual void WUnmapNotify();
485
486 //Gestion souris
487 __Draw_API static void SelectWait (HANDLE&,int&,int&,int&);
488 __Draw_API static void SelectNoWait (HANDLE&,int&,int&,int&);
489
490 // Procedure de fenetre
6a7d83c4 491 __Draw_API static LRESULT APIENTRY DrawProc (HWND,UINT,WPARAM,LPARAM);
7fd59977 492
493private:
494
495 __Draw_API static HWND CreateDrawWindow(HWND,int);
496 __Draw_API HDC GetMemDC(HDC);
497 __Draw_API void ReleaseMemDC(HDC);
498
499 //atributs
500public:
501 HWND win;
502 static HWND hWndClientMDI;
503
504private:
505 static DrawWindow* firstWindow;
506 DrawWindow* next;
507 DrawWindow* previous;
508 HBITMAP myMemHbm;
509 HBITMAP myOldHbm;
510 Standard_Boolean myUseBuffer;
511 Standard_Integer myCurrPen;
512 Standard_Integer myCurrMode;
513};
514
515typedef DrawWindow Draw_Window;
516typedef enum {
517 STOP_CONSOLE,
518 WAIT_CONSOLE_COMMAND,
519 HAS_CONSOLE_COMMAND} console_semaphore_value;
520
521// PROCEDURE DE DRAW WINDOW
522
523__Draw_API Standard_Boolean Init_Appli(HINSTANCE,HINSTANCE,int,HWND&);
524__Draw_API void Run_Appli(HWND);
525__Draw_API void Destroy_Appli(HINSTANCE);
526
527#endif
528
529#endif