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>
23 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
25 const Standard_Integer MAXCOLOR = 15;
27 typedef unsigned long Window;
28 typedef unsigned long Pixmap;
29 typedef unsigned long Drawable;
31 // Definition de la class Base_Window (Definie dans Draw_Window.cxx)
32 //===================================
35 // Definition de la classe Segment
36 //================================
44 void Init(short x1, short y1, short x2, short y2) {
45 xx1 = x1; yy1 = y1; xx2 = x2; yy2 = y2;
50 // Definition de la structure Event
51 //=================================
54 Standard_Integer type;
56 Standard_Integer button;
61 // Definition de la classe Draw_Window
62 //====================================
68 * Type of the callback function that is to be passed to the method
69 * AddCallbackBeforeTerminate().
71 typedef void (*FCallbackBeforeTerminate)();
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.
78 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
81 * Just in case method for un-registering a callback previously registered by
82 * AddCallbackBeforeTerminate()
84 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
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);
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);
97 void Init (Standard_Integer X = 0, Standard_Integer Y = 0,
98 Standard_Integer DX = 50, Standard_Integer DY = 50);
100 void Init (Window mother,
101 Standard_Integer X = 0, Standard_Integer Y = 0,
102 Standard_Integer DX = 50, Standard_Integer DY = 50);
105 void StopWinManager();
107 void SetPosition (Standard_Integer NewXpos,
108 Standard_Integer NewYpos);
110 void SetDimension(Standard_Integer NewDx,
111 Standard_Integer NewDy);
113 void GetPosition(Standard_Integer &PosX,
114 Standard_Integer &PosY);
116 Standard_Integer HeightWin() const;
117 Standard_Integer WidthWin() const;
119 void SetTitle(const char* title);
122 void DisplayWindow();
126 void Wait(Standard_Boolean wait = Standard_True);
128 Drawable GetDrawable() const;
129 // Initializes off-screen image buffer according to current window size
132 static Standard_Boolean DefineColor(const Standard_Integer, const char*);
135 void DrawString(int, int, char*);
136 void DrawSegments(Segment* ,int);
141 Standard_Boolean Save(const char* theFileName) const;
143 virtual ~Draw_Window ();
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);
157 virtual void WConfigureNotify(const Standard_Integer X,
158 const Standard_Integer Y,
159 const Standard_Integer dx,
160 const Standard_Integer dy);
162 virtual void WUnmapNotify();
166 Window myMother; // default : myMother is the root window
169 static Draw_Window* firstWindow;
171 Draw_Window* previous;
173 Standard_Boolean myUseBuffer;
174 Standard_Boolean withWindowManager;
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 //======================================================
185 void Run_Appli(Standard_Boolean (*inteprete) (const char*));
187 //======================================================
188 // funtion : Init_Appli
190 //======================================================
191 Standard_Boolean Init_Appli();
193 //======================================================
194 // funtion : Destroy_Appli()
196 //======================================================
197 void Destroy_Appli();
199 //======================================================
200 // funtion : GetNextEvent()
202 //======================================================
203 void GetNextEvent(Event&);
205 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
207 const Standard_Integer MAXCOLOR = 15;
211 Standard_Integer myXStart;
212 Standard_Integer myYStart;
213 Standard_Integer myXEnd;
214 Standard_Integer myYEnd;
216 void Init(short theXStart, short theYStart, short theXEnd, short theYEnd) {
217 myXStart = theXStart; myYStart = theYStart; myXEnd = theXEnd; myYEnd = theYEnd;
226 @class Draw_CocoaView;
231 struct Draw_CocoaView;
240 * Type of the callback function that is to be passed to the method
241 * AddCallbackBeforeTerminate().
243 typedef void (*FCallbackBeforeTerminate)();
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.
250 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
253 * Just in case method for un-registering a callback previously registered by
254 * AddCallbackBeforeTerminate()
256 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
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);
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);
267 void Init (const Standard_Integer& theXLeft = 0, const Standard_Integer& theYLeft = 0,
268 const Standard_Integer& theWidth = 50, const Standard_Integer& theHeight = 50);
270 virtual ~Draw_Window ();
272 void SetPosition (const Standard_Integer& theNewXpos,
273 const Standard_Integer& theNewYpos);
275 void SetDimension (const Standard_Integer& theNewWidth,
276 const Standard_Integer& theNewHeight);
278 void GetPosition (Standard_Integer &thePosX,
279 Standard_Integer &thePosY);
281 Standard_Integer HeightWin() const;
282 Standard_Integer WidthWin() const;
284 void SetTitle (Standard_CString theTitle);
285 Standard_CString GetTitle ();
287 void DisplayWindow();
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);
303 Standard_Boolean Save (Standard_CString theFileName) const;
305 Standard_Boolean IsEqualWindows (const Standard_Integer& theWindowNumber);
309 Draw_CocoaView* myView;
310 NSImage* myImageBuffer;
311 Standard_Boolean myUseBuffer;
312 Standard_Integer myCurrentColor;
314 static Draw_Window* firstWindow;
315 Draw_Window* nextWindow;
316 Draw_Window* previousWindow;
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 //======================================================
327 void Run_Appli(Standard_Boolean (*inteprete) (const char*));
329 //======================================================
330 // funtion : Init_Appli
332 //======================================================
333 Standard_Boolean Init_Appli();
335 //======================================================
336 // funtion : Destroy_Appli()
338 //======================================================
339 void Destroy_Appli();
341 //======================================================
342 // funtion : GetNextEvent()
344 //======================================================
345 void GetNextEvent (Standard_Boolean theWait,
346 Standard_Integer& theWindowNumber,
347 Standard_Integer& theX,
348 Standard_Integer& theY,
349 Standard_Integer& theButton);
356 #define DRAWCLASS "DRAWWINDOW"
357 #define DRAWTITLE "Draw View"
360 #if !defined(__Draw_API) && !defined(HAVE_NO_DLL)
362 # define __Draw_API __declspec( dllexport )
364 # define __Draw_API __declspec( dllimport )
368 // definition de la classe Segment
373 friend class DrawWindow;
381 void Init(Standard_Integer,
393 //definition de la classe DRAWWINDOW
401 * Type of the callback function that is to be passed to the method
402 * AddCallbackBeforeTerminate().
404 typedef void (*FCallbackBeforeTerminate)();
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.
411 Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
414 * Just in case method for un-registering a callback previously registered by
415 * AddCallbackBeforeTerminate()
417 Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
419 __Draw_API DrawWindow();
420 __Draw_API DrawWindow(const char*, Standard_Integer, Standard_Integer,
421 Standard_Integer, Standard_Integer);
422 __Draw_API DrawWindow(const char*, Standard_Integer, Standard_Integer,
423 Standard_Integer, Standard_Integer, HWND);
425 __Draw_API virtual ~DrawWindow();
429 __Draw_API void Init(Standard_Integer, Standard_Integer,
430 Standard_Integer, Standard_Integer);
432 __Draw_API void SetUseBuffer(Standard_Boolean);
433 // Turns on/off usage of off-screen image buffer (can be used for redrawing optimization)
435 Standard_Boolean GetUseBuffer() const { return myUseBuffer; }
436 // Returns Standard_True if off-screen image buffer is being used
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;
446 __Draw_API void SetTitle(const char*);
447 __Draw_API char* GetTitle();
450 __Draw_API void DisplayWindow();
451 __Draw_API void Hide();
452 __Draw_API void Destroy();
453 __Draw_API void Clear();
454 static void Flush() {} ;
457 __Draw_API Standard_Boolean Save(const char* theFileName) const;
460 __Draw_API void DrawString(int,int,char*);
461 __Draw_API void DrawSegments(Segment*,int);
463 __Draw_API void InitBuffer();
464 // Initializes off-screen image buffer according to current window size
466 __Draw_API void Redraw();
467 // Copies an image from memory buffer to screen
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*);
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();
486 __Draw_API static void SelectWait (HANDLE&,int&,int&,int&);
487 __Draw_API static void SelectNoWait (HANDLE&,int&,int&,int&);
489 // Procedure de fenetre
490 __Draw_API static LRESULT APIENTRY DrawProc (HWND,UINT,WPARAM,LPARAM);
494 __Draw_API static HWND CreateDrawWindow(HWND,int);
495 __Draw_API HDC GetMemDC(HDC);
496 __Draw_API void ReleaseMemDC(HDC);
501 static HWND hWndClientMDI;
504 static DrawWindow* firstWindow;
506 DrawWindow* previous;
509 Standard_Boolean myUseBuffer;
510 Standard_Integer myCurrPen;
511 Standard_Integer myCurrMode;
514 typedef DrawWindow Draw_Window;
517 WAIT_CONSOLE_COMMAND,
518 HAS_CONSOLE_COMMAND} console_semaphore_value;
520 // PROCEDURE DE DRAW WINDOW
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);