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