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