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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef Draw_Window_HeaderFile
18 #define Draw_Window_HeaderFile
20 #include <Standard_Boolean.hxx>
21 #include <Standard_Integer.hxx>
22 #include <TCollection_AsciiString.hxx>
24 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
26 const Standard_Integer MAXCOLOR = 15;
28 typedef unsigned long Window;
29 typedef unsigned long Pixmap;
30 typedef unsigned long Drawable;
32 // Definition de la class Base_Window (Definie dans Draw_Window.cxx)
33 //===================================
36 // Definition de la classe Segment
37 //================================
45 void Init(short x1, short y1, short x2, short y2) {
46 xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2;
51 // Definition de la structure Event
52 //=================================
55 Standard_Integer type;
57 Standard_Integer button;
62 // Definition de la classe Draw_Window
63 //====================================
69 * Type of the callback function that is to be passed to the method
70 * AddCallbackBeforeTerminate().
72 typedef void (*FCallbackBeforeTerminate)();
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.
79 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
82 * Just in case method for un-registering a callback previously registered by
83 * AddCallbackBeforeTerminate()
85 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
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);
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);
98 void Init (Standard_Integer X = 0, Standard_Integer Y = 0,
99 Standard_Integer DX = 50, Standard_Integer DY = 50);
101 void Init (Window mother,
102 Standard_Integer X = 0, Standard_Integer Y = 0,
103 Standard_Integer DX = 50, Standard_Integer DY = 50);
106 void StopWinManager();
108 void SetPosition (Standard_Integer NewXpos,
109 Standard_Integer NewYpos);
111 void SetDimension(Standard_Integer NewDx,
112 Standard_Integer NewDy);
114 void GetPosition(Standard_Integer &PosX,
115 Standard_Integer &PosY);
117 Standard_Integer HeightWin() const;
118 Standard_Integer WidthWin() const;
120 void SetTitle (const TCollection_AsciiString& theTitle);
121 TCollection_AsciiString GetTitle() const;
123 //! Return true if window is displayed on the screen.
124 bool IsMapped() const;
125 void DisplayWindow();
129 void Wait(Standard_Boolean wait = Standard_True);
131 Drawable GetDrawable() const;
132 // Initializes off-screen image buffer according to current window size
135 static Standard_Boolean DefineColor(const Standard_Integer, const char*);
138 void DrawString(int, int, char*);
139 void DrawSegments(Segment* ,int);
144 Standard_Boolean Save(const char* theFileName) const;
146 virtual ~Draw_Window ();
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);
160 virtual void WConfigureNotify(const Standard_Integer X,
161 const Standard_Integer Y,
162 const Standard_Integer dx,
163 const Standard_Integer dy);
165 virtual void WUnmapNotify();
169 Window myMother; // default : myMother is the root window
172 static Draw_Window* firstWindow;
174 Draw_Window* previous;
176 Standard_Boolean myUseBuffer;
177 Standard_Boolean withWindowManager;
181 //======================================================
182 // funtion : 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 //======================================================
188 void Run_Appli(Standard_Boolean (*inteprete) (const char*));
190 //======================================================
191 // funtion : Init_Appli
193 //======================================================
194 Standard_Boolean Init_Appli();
196 //======================================================
197 // funtion : Destroy_Appli()
199 //======================================================
200 void Destroy_Appli();
202 //======================================================
203 // funtion : GetNextEvent()
205 //======================================================
206 void GetNextEvent(Event&);
208 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
210 const Standard_Integer MAXCOLOR = 15;
214 Standard_Integer myXStart;
215 Standard_Integer myYStart;
216 Standard_Integer myXEnd;
217 Standard_Integer myYEnd;
219 void Init(short theXStart, short theYStart, short theXEnd, short theYEnd) {
220 myXStart = theXStart; myYStart = theYStart; myXEnd = theXEnd; myYEnd = theYEnd;
229 @class Draw_CocoaView;
234 struct Draw_CocoaView;
243 * Type of the callback function that is to be passed to the method
244 * AddCallbackBeforeTerminate().
246 typedef void (*FCallbackBeforeTerminate)();
249 * This method registers a callback function that will be called just before exit.
250 * This is usefull especially for Windows platform, on which Draw is normally
251 * self-terminated instead of exiting.
253 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
256 * Just in case method for un-registering a callback previously registered by
257 * AddCallbackBeforeTerminate()
259 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
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);
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);
270 void Init (const Standard_Integer& theXLeft = 0, const Standard_Integer& theYLeft = 0,
271 const Standard_Integer& theWidth = 50, const Standard_Integer& theHeight = 50);
273 virtual ~Draw_Window ();
275 void SetPosition (const Standard_Integer& theNewXpos,
276 const Standard_Integer& theNewYpos);
278 void SetDimension (const Standard_Integer& theNewWidth,
279 const Standard_Integer& theNewHeight);
281 void GetPosition (Standard_Integer &thePosX,
282 Standard_Integer &thePosY);
284 Standard_Integer HeightWin() const;
285 Standard_Integer WidthWin() const;
287 void SetTitle (const TCollection_AsciiString& theTitle);
288 TCollection_AsciiString GetTitle() const;
290 //! Return true if window is displayed on the screen.
291 bool IsMapped() const;
292 void DisplayWindow();
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);
308 Standard_Boolean Save (Standard_CString theFileName) const;
310 Standard_Boolean IsEqualWindows (const Standard_Integer& theWindowNumber);
314 Draw_CocoaView* myView;
315 NSImage* myImageBuffer;
316 Standard_Boolean myUseBuffer;
317 Standard_Integer myCurrentColor;
319 static Draw_Window* firstWindow;
320 Draw_Window* nextWindow;
321 Draw_Window* previousWindow;
325 //======================================================
326 // funtion : 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 //======================================================
332 void Run_Appli(Standard_Boolean (*inteprete) (const char*));
334 //======================================================
335 // funtion : Init_Appli
337 //======================================================
338 Standard_Boolean Init_Appli();
340 //======================================================
341 // funtion : Destroy_Appli()
343 //======================================================
344 void Destroy_Appli();
346 //======================================================
347 // funtion : GetNextEvent()
349 //======================================================
350 void GetNextEvent (Standard_Boolean theWait,
351 Standard_Integer& theWindowNumber,
352 Standard_Integer& theX,
353 Standard_Integer& theY,
354 Standard_Integer& theButton);
361 #define DRAWCLASS L"DRAWWINDOW"
362 #define DRAWTITLE L"Draw View"
365 #if !defined(__Draw_API) && !defined(HAVE_NO_DLL)
367 # define __Draw_API __declspec( dllexport )
369 # define __Draw_API __declspec( dllimport )
373 // definition de la classe Segment
378 friend class DrawWindow;
386 void Init(Standard_Integer,
398 //definition de la classe DRAWWINDOW
406 * Type of the callback function that is to be passed to the method
407 * AddCallbackBeforeTerminate().
409 typedef void (*FCallbackBeforeTerminate)();
412 * This method registers a callback function that will be called just before exit.
413 * This is usefull especially for Windows platform, on which Draw is normally
414 * self-terminated instead of exiting.
416 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
419 * Just in case method for un-registering a callback previously registered by
420 * AddCallbackBeforeTerminate()
422 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
424 __Draw_API DrawWindow();
425 __Draw_API DrawWindow(const char*, Standard_Integer, Standard_Integer,
426 Standard_Integer, Standard_Integer);
427 __Draw_API DrawWindow(const char*, Standard_Integer, Standard_Integer,
428 Standard_Integer, Standard_Integer, HWND);
430 __Draw_API virtual ~DrawWindow();
434 __Draw_API void Init(Standard_Integer, Standard_Integer,
435 Standard_Integer, Standard_Integer);
437 __Draw_API void SetUseBuffer(Standard_Boolean);
438 // Turns on/off usage of off-screen image buffer (can be used for redrawing optimization)
440 Standard_Boolean GetUseBuffer() const { return myUseBuffer; }
441 // Returns Standard_True if off-screen image buffer is being used
444 __Draw_API void SetPosition (Standard_Integer,Standard_Integer);
445 __Draw_API void SetDimension(Standard_Integer,Standard_Integer);
446 __Draw_API void GetPosition (Standard_Integer&,Standard_Integer&);
447 __Draw_API Standard_Integer HeightWin() const;
448 __Draw_API Standard_Integer WidthWin() const;
451 __Draw_API void SetTitle (const TCollection_AsciiString& );
452 __Draw_API TCollection_AsciiString GetTitle() const;
455 //! Return true if window is displayed on the screen.
456 bool IsMapped() const;
457 __Draw_API void DisplayWindow();
458 __Draw_API void Hide();
459 __Draw_API void Destroy();
460 __Draw_API void Clear();
461 static void Flush() {} ;
464 __Draw_API Standard_Boolean Save(const char* theFileName) const;
467 __Draw_API void DrawString(int,int,char*);
468 __Draw_API void DrawSegments(Segment*,int);
470 __Draw_API void InitBuffer();
471 // Initializes off-screen image buffer according to current window size
473 __Draw_API void Redraw();
474 // Copies an image from memory buffer to screen
477 __Draw_API void SetColor(Standard_Integer);
478 __Draw_API void SetMode(int);
479 __Draw_API static Standard_Boolean DefineColor ( const Standard_Integer,const char*);
481 //Gestion des Messages
482 __Draw_API virtual void WExpose ();
483 __Draw_API virtual void WButtonPress(const Standard_Integer,const Standard_Integer,
484 const Standard_Integer&);
485 __Draw_API virtual void WButtonRelease(const Standard_Integer,const Standard_Integer,
486 const Standard_Integer&);
487 __Draw_API virtual void WMotionNotify(const Standard_Integer,const Standard_Integer);
488 __Draw_API virtual void WConfigureNotify(const Standard_Integer,const Standard_Integer,
489 const Standard_Integer,const Standard_Integer);
490 __Draw_API virtual void WUnmapNotify();
493 __Draw_API static void SelectWait (HANDLE&,int&,int&,int&);
494 __Draw_API static void SelectNoWait (HANDLE&,int&,int&,int&);
496 // Procedure de fenetre
497 __Draw_API static LRESULT APIENTRY DrawProc (HWND,UINT,WPARAM,LPARAM);
501 __Draw_API static HWND CreateDrawWindow(HWND,int);
502 __Draw_API HDC GetMemDC(HDC);
503 __Draw_API void ReleaseMemDC(HDC);
508 static HWND hWndClientMDI;
511 static DrawWindow* firstWindow;
513 DrawWindow* previous;
516 Standard_Boolean myUseBuffer;
517 Standard_Integer myCurrPen;
518 Standard_Integer myCurrMode;
521 typedef DrawWindow Draw_Window;
524 WAIT_CONSOLE_COMMAND,
525 HAS_CONSOLE_COMMAND} console_semaphore_value;
527 // PROCEDURE DE DRAW WINDOW
529 __Draw_API Standard_Boolean Init_Appli(HINSTANCE,HINSTANCE,int,HWND&);
530 __Draw_API void Run_Appli(HWND);
531 __Draw_API void Destroy_Appli(HINSTANCE);