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 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);
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);
79 void Init (Standard_Integer X = 0, Standard_Integer Y = 0,
80 Standard_Integer DX = 50, Standard_Integer DY = 50);
82 void Init (Window mother,
83 Standard_Integer X = 0, Standard_Integer Y = 0,
84 Standard_Integer DX = 50, Standard_Integer DY = 50);
87 void StopWinManager();
89 void SetPosition (Standard_Integer NewXpos,
90 Standard_Integer NewYpos);
92 void SetDimension(Standard_Integer NewDx,
93 Standard_Integer NewDy);
95 void GetPosition(Standard_Integer &PosX,
96 Standard_Integer &PosY);
98 Standard_Integer HeightWin() const;
99 Standard_Integer WidthWin() const;
101 void SetTitle(const char* title);
104 void DisplayWindow();
108 void Wait(Standard_Boolean wait = Standard_True);
110 Drawable GetDrawable() const;
111 // Initializes off-screen image buffer according to current window size
114 static Standard_Boolean DefineColor(const Standard_Integer, const char*);
117 void DrawString(int, int, char*);
118 void DrawSegments(Segment* ,int);
123 Standard_Boolean Save(const char* theFileName) const;
125 virtual ~Draw_Window ();
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);
139 virtual void WConfigureNotify(const Standard_Integer X,
140 const Standard_Integer Y,
141 const Standard_Integer dx,
142 const Standard_Integer dy);
144 virtual void WUnmapNotify();
148 Window myMother; // default : myMother is the root window
151 static Draw_Window* firstWindow;
153 Draw_Window* previous;
155 Standard_Boolean myUseBuffer;
156 Standard_Boolean withWindowManager;
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 //======================================================
167 void Run_Appli(Standard_Boolean (*inteprete) (const char*));
169 //======================================================
170 // funtion : Init_Appli
172 //======================================================
173 Standard_Boolean Init_Appli();
175 //======================================================
176 // funtion : Destroy_Appli()
178 //======================================================
179 void Destroy_Appli();
181 //======================================================
182 // funtion : GetNextEvent()
184 //======================================================
185 void GetNextEvent(Event&);
187 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
189 const Standard_Integer MAXCOLOR = 15;
193 Standard_Integer myXStart;
194 Standard_Integer myYStart;
195 Standard_Integer myXEnd;
196 Standard_Integer myYEnd;
198 void Init(short theXStart, short theYStart, short theXEnd, short theYEnd) {
199 myXStart = theXStart; myYStart = theYStart; myXEnd = theXEnd; myYEnd = theYEnd;
208 @class Draw_CocoaView;
213 struct Draw_CocoaView;
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);
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);
230 void Init (const Standard_Integer& theXLeft = 0, const Standard_Integer& theYLeft = 0,
231 const Standard_Integer& theWidth = 50, const Standard_Integer& theHeight = 50);
233 virtual ~Draw_Window ();
235 void SetPosition (const Standard_Integer& theNewXpos,
236 const Standard_Integer& theNewYpos);
238 void SetDimension (const Standard_Integer& theNewWidth,
239 const Standard_Integer& theNewHeight);
241 void GetPosition (Standard_Integer &thePosX,
242 Standard_Integer &thePosY);
244 Standard_Integer HeightWin() const;
245 Standard_Integer WidthWin() const;
247 void SetTitle (Standard_CString theTitle);
248 Standard_CString GetTitle ();
250 void DisplayWindow();
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);
266 Standard_Boolean Save (Standard_CString theFileName) const;
268 Standard_Boolean IsEqualWindows (const Standard_Integer& theWindowNumber);
272 Draw_CocoaView* myView;
273 NSImage* myImageBuffer;
274 Standard_Boolean myUseBuffer;
275 Standard_Integer myCurrentColor;
277 static Draw_Window* firstWindow;
278 Draw_Window* nextWindow;
279 Draw_Window* previousWindow;
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 //======================================================
290 void Run_Appli(Standard_Boolean (*inteprete) (const char*));
292 //======================================================
293 // funtion : Init_Appli
295 //======================================================
296 Standard_Boolean Init_Appli();
298 //======================================================
299 // funtion : Destroy_Appli()
301 //======================================================
302 void Destroy_Appli();
304 //======================================================
305 // funtion : GetNextEvent()
307 //======================================================
308 void GetNextEvent (Standard_Boolean theWait,
309 Standard_Integer& theWindowNumber,
310 Standard_Integer& theX,
311 Standard_Integer& theY,
312 Standard_Integer& theButton);
319 #define DRAWCLASS "DRAWWINDOW"
320 #define DRAWTITLE "Draw View"
323 #if !defined(__Draw_API) && !defined(HAVE_NO_DLL)
325 # define __Draw_API __declspec( dllexport )
327 # define __Draw_API __declspec( dllimport )
331 // definition de la classe Segment
336 friend class DrawWindow;
344 void Init(Standard_Integer,
356 //definition de la classe DRAWWINDOW
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);
368 __Draw_API ~DrawWindow();
372 __Draw_API void Init(Standard_Integer, Standard_Integer,
373 Standard_Integer, Standard_Integer);
375 __Draw_API void SetUseBuffer(Standard_Boolean);
376 // Turns on/off usage of off-screen image buffer (can be used for redrawing optimization)
378 __Draw_API Standard_Boolean GetUseBuffer() const { return myUseBuffer; }
379 // Returns Standard_True if off-screen image buffer is being used
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;
389 __Draw_API void SetTitle(char*);
390 __Draw_API char* GetTitle();
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() {} ;
400 __Draw_API Standard_Boolean Save(const char* theFileName) const;
403 __Draw_API void DrawString(int,int,char*);
404 __Draw_API void DrawSegments(Segment*,int);
406 __Draw_API void InitBuffer();
407 // Initializes off-screen image buffer according to current window size
409 __Draw_API void Redraw();
410 // Copies an image from memory buffer to screen
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*);
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();
429 __Draw_API static void SelectWait (HANDLE&,int&,int&,int&);
430 __Draw_API static void SelectNoWait (HANDLE&,int&,int&,int&);
432 // Procedure de fenetre
433 __Draw_API static LRESULT APIENTRY DrawProc (HWND,UINT,WPARAM,LPARAM);
437 __Draw_API static HWND CreateDrawWindow(HWND,int);
438 __Draw_API HDC GetMemDC(HDC);
439 __Draw_API void ReleaseMemDC(HDC);
444 static HWND hWndClientMDI;
447 static DrawWindow* firstWindow;
449 DrawWindow* previous;
452 Standard_Boolean myUseBuffer;
453 Standard_Integer myCurrPen;
454 Standard_Integer myCurrMode;
457 typedef DrawWindow Draw_Window;
460 WAIT_CONSOLE_COMMAND,
461 HAS_CONSOLE_COMMAND} console_semaphore_value;
463 // PROCEDURE DE DRAW WINDOW
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);