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