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