1 // File: Draw_Window.cxx
2 // Created: Wed Jul 27 17:52:01 1994
3 // Author: Remi LEQUETTE
6 // Updated by DPF Fri Mar 21 18:40:58 1997
7 // Added casting in void to compile
8 // on AO1 int 32 bits -> pointer 64 bits ????
10 // Robert Boehne 30 May 2000 : Dec Osf
12 // include windows.h first to have all definitions available
17 #include <Standard_ErrorHandler.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <Draw_Appli.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <Image_PixMap.hxx>
25 extern Draw_Interpretor theCommands;
26 Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
27 static Tcl_Interp *interp; /* Interpreter for this application. */
30 *----------------------------------------------------------------------
34 * Issue a prompt on standard output, or invoke a script
35 * to issue the prompt.
41 * A prompt gets output, and a Tcl script may be evaluated
44 *----------------------------------------------------------------------
47 static void Prompt(Tcl_Interp *Interp, int partial)
51 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST)
52 const char *promptCmd;
57 Tcl_Channel outChannel, errChannel;
58 outChannel = Tcl_GetStdChannel(TCL_STDOUT);
59 promptCmd = Tcl_GetVar(Interp,(char*)
60 (partial ? "tcl_prompt2" : "tcl_prompt1"), TCL_GLOBAL_ONLY);
62 if (promptCmd == NULL) {
64 if (!partial && outChannel) {
65 Tcl_Write(outChannel, "% ", 2);
68 code = Tcl_Eval(Interp, promptCmd);
69 outChannel = Tcl_GetStdChannel(TCL_STDOUT);
70 errChannel = Tcl_GetStdChannel(TCL_STDERR);
73 Tcl_Write(errChannel, Interp->result, -1);
74 Tcl_Write(errChannel, "\n", 1);
76 Tcl_AddErrorInfo(Interp,
77 "\n (script that generates prompt)");
82 Tcl_Flush(outChannel);
92 #include <OSD_Timer.hxx>
94 #ifdef HAVE_SYS_TIME_H
95 # include <sys/time.h>
98 #ifdef HAVE_SYS_TYPES_H
99 # include <sys/types.h>
102 #ifdef HAVE_SYS_SELECT_H
103 #include <sys/select.h>
106 #ifdef HAVE_SYS_FILIO_H
107 #include <sys/filio.h>
109 #include <sys/ioctl.h>
118 #include <Draw_Window.hxx>
120 #ifdef HAVE_STRINGS_H
121 # include <strings.h>
125 #include <Draw_WindowBase.hxx>
126 #include <X11/XWDFile.h>
132 * Global variables used by the main program:
135 static Tk_Window mainWindow; /* The main window for the application. If
136 * NULL then the application no longer
138 char *tcl_RcFileName = NULL; /* Name of a user-specific startup script
139 * to source if the application is being run
140 * interactively (e.g. "~/.wishrc"). Set
141 * by Tcl_AppInit. NULL means don't source
144 static Tcl_DString command; /* Used to assemble lines of terminal input
145 * into Tcl commands. */
146 static Tcl_DString line; /* Used to read the next line from the
148 //static char errorExitCmd[] = "exit 1";
151 * Forward declarations for procedures defined later in this file:
154 static void StdinProc (ClientData clientData, int mask);
156 static void Prompt (Tcl_Interp *Interp, int partial);
158 static Standard_Boolean tty; /* Non-zero means standard input is a
159 * terminal-like device. Zero means it's
162 static unsigned long thePixels[MAXCOLOR];
165 Display* Draw_WindowDisplay = NULL;
166 Standard_Integer Draw_WindowScreen = 0;
167 Colormap Draw_WindowColorMap;
168 Standard_Boolean Draw_BlackBackGround = Standard_True;
169 Standard_Boolean Draw_LowWindows = Standard_False;
172 // Initialization of static variables of Draw_Window
173 //======================================================
174 Draw_Window* Draw_Window::firstWindow = NULL;
177 //=======================================================================
178 //function : Draw_Window
180 //=======================================================================
181 Draw_Window::Draw_Window() :
182 base(*new Base_Window()),
187 myUseBuffer(Standard_False),
188 withWindowManager(Standard_True)
190 myMother = RootWindow(Draw_WindowDisplay,
193 if (firstWindow) firstWindow->previous = this;
197 //=======================================================================
198 //function : Draw_Window
200 //=======================================================================
201 Draw_Window::Draw_Window(Window mother) :
202 base(*new Base_Window()),
207 myUseBuffer(Standard_False),
208 withWindowManager(Standard_True)
212 if (firstWindow) firstWindow->previous = this;
216 //=======================================================================
217 //function : Draw_Window
219 //=======================================================================
220 Draw_Window::Draw_Window (const char* title,
221 Standard_Integer X, Standard_Integer Y,
222 Standard_Integer DX, Standard_Integer DY) :
223 base(*new Base_Window()),
228 myUseBuffer(Standard_False),
229 withWindowManager(Standard_True)
231 myMother = RootWindow(Draw_WindowDisplay,
234 if (firstWindow) firstWindow->previous = this;
240 //=======================================================================
241 //function : Draw_Window
243 //=======================================================================
244 Draw_Window::Draw_Window (const char* window ) :
245 base(*new Base_Window()),
250 myUseBuffer(Standard_False),
251 withWindowManager(Standard_True)
253 sscanf(window,"%lx",&win);
254 Standard_Integer X,Y,DX,DY;
256 if (firstWindow) firstWindow->previous = this;
265 //=======================================================================
266 //function : Draw_Window
268 //=======================================================================
269 Draw_Window::Draw_Window (Window mother,
271 Standard_Integer X, Standard_Integer Y,
272 Standard_Integer DX, Standard_Integer DY) :
273 base(*new Base_Window()),
278 myUseBuffer(Standard_False),
279 withWindowManager(Standard_True)
283 if (firstWindow) firstWindow->previous = this;
289 //=======================================================================
290 //function : ~Draw_Window
292 //=======================================================================
293 Draw_Window::~Draw_Window()
296 previous->next = next;
300 next->previous = previous;
304 XFreePixmap(Draw_WindowDisplay, myBuffer);
307 // Liberation pointer on Base_Window
311 //=======================================================================
314 //=======================================================================
315 void Draw_Window::Init(Standard_Integer X, Standard_Integer Y,
316 Standard_Integer DX, Standard_Integer DY)
318 unsigned long setmask;
320 if (Draw_BlackBackGround)
322 base.xswa.background_pixel = BlackPixel(Draw_WindowDisplay,Draw_WindowScreen);
323 base.xswa.border_pixel = WhitePixel(Draw_WindowDisplay,Draw_WindowScreen);
327 base.xswa.background_pixel = WhitePixel(Draw_WindowDisplay,Draw_WindowScreen);
328 base.xswa.border_pixel = BlackPixel(Draw_WindowDisplay,Draw_WindowScreen);
330 base.xswa.colormap = Draw_WindowColorMap;
331 setmask = CWBackPixel | CWBorderPixel ;
334 myHints.flags = USPosition;
340 win = XCreateWindow(Draw_WindowDisplay,
343 (unsigned int) DX,(unsigned int) DY,
345 DefaultDepth(Draw_WindowDisplay,Draw_WindowScreen),
347 DefaultVisual(Draw_WindowDisplay,Draw_WindowScreen),
349 XSelectInput(Draw_WindowDisplay, win, ButtonPressMask|ExposureMask|
350 StructureNotifyMask);
352 // advise to the window manager to place it where I need
353 XSetWMNormalHints(Draw_WindowDisplay,win,&myHints);
355 if (Draw_VirtualWindows)
357 myUseBuffer = Standard_True;
362 base.gc = XCreateGC(Draw_WindowDisplay, win, 0, NULL);
364 XSetPlaneMask(Draw_WindowDisplay,base.gc,AllPlanes);
365 XSetForeground(Draw_WindowDisplay,
366 base.gc, WhitePixel(Draw_WindowDisplay,Draw_WindowScreen));
367 XSetBackground(Draw_WindowDisplay,
368 base.gc, BlackPixel(Draw_WindowDisplay,Draw_WindowScreen));
369 // save in case of window recovery
371 base.xswa.backing_store = Always;
372 XChangeWindowAttributes(Draw_WindowDisplay, win,
373 CWBackingStore, &base.xswa);
375 XSetLineAttributes (Draw_WindowDisplay, base.gc,
376 0, LineSolid, CapButt, JoinMiter);
379 //=======================================================================
380 //function : InitBuffer
382 //=======================================================================
383 void Draw_Window::InitBuffer()
387 XFreePixmap (Draw_WindowDisplay, myBuffer);
389 XWindowAttributes winAttr;
390 XGetWindowAttributes (Draw_WindowDisplay, win, &winAttr);
391 myBuffer = XCreatePixmap (Draw_WindowDisplay, win, winAttr.width, winAttr.height, winAttr.depth);
393 else if (myBuffer != 0)
395 XFreePixmap (Draw_WindowDisplay, myBuffer);
400 //=======================================================================
401 //function : StopWinManager
403 //=======================================================================
404 void Draw_Window::StopWinManager()
407 XWindowAttributes winAttr;
408 XGetWindowAttributes (Draw_WindowDisplay, win, &winAttr);
412 myHints.flags = USPosition;
413 myHints.x = (int) 30;
414 myHints.y = (int) 100;
416 base.xswa.override_redirect = 1;
417 base.xswa.border_pixel = BlackPixel(Draw_WindowDisplay,
419 base.xswa.background_pixel = WhitePixel(Draw_WindowDisplay,
422 withWindowManager = Standard_False;
424 win = XCreateWindow(Draw_WindowDisplay, myMother,
425 winAttr.x, winAttr.y,
426 winAttr.width, winAttr.height,
428 CopyFromParent, InputOutput, CopyFromParent,
429 CWBorderPixel|CWOverrideRedirect|CWBackPixel, &base.xswa);
432 // adwise to the window manager to place it where I wish
433 XSetWMNormalHints(Draw_WindowDisplay,win,&myHints);
435 // all masks of the old window are reassigned to the new one.
436 XSelectInput(Draw_WindowDisplay,win,winAttr.your_event_mask);
439 //=======================================================================
440 //function : SetPosition
442 //=======================================================================
443 void Draw_Window::SetPosition(Standard_Integer NewXpos,
444 Standard_Integer NewYpos)
446 Standard_Integer x,y;
449 if ( (x != NewXpos) || (y != NewYpos) )
450 XMoveWindow(Draw_WindowDisplay, win, NewXpos, NewYpos);
453 //=======================================================================
454 //function : SetDimension
456 //=======================================================================
457 void Draw_Window::SetDimension(Standard_Integer NewDx,
458 Standard_Integer NewDy)
460 if ( (NewDx != WidthWin() ) || (NewDy != HeightWin() ) )
461 XResizeWindow(Draw_WindowDisplay, win, NewDx, NewDy);
464 //=======================================================================
465 //function : GetPosition
467 //=======================================================================
468 void Draw_Window::GetPosition(Standard_Integer &PosX,
469 Standard_Integer &PosY)
471 XWindowAttributes winAttr;
472 XGetWindowAttributes(Draw_WindowDisplay, win, &winAttr);
478 //=======================================================================
479 //function : HeightWin
481 //=======================================================================
482 Standard_Integer Draw_Window::HeightWin() const
485 XWindowAttributes winAttr;
486 XGetWindowAttributes(Draw_WindowDisplay, win, &winAttr);
492 //=======================================================================
493 //function : WidthWin
495 //=======================================================================
496 Standard_Integer Draw_Window::WidthWin() const
499 XWindowAttributes winAttr;
500 XGetWindowAttributes(Draw_WindowDisplay, win, &winAttr);
506 //=======================================================================
507 //function : SetTitle
509 //=======================================================================
510 void Draw_Window::SetTitle(const char* title)
512 XStoreName(Draw_WindowDisplay, win, title);
515 //=======================================================================
516 //function : GetTitle
518 //=======================================================================
519 char* Draw_Window::GetTitle()
522 XFetchName(Draw_WindowDisplay, win, &title);
526 //=======================================================================
527 //function : GetDrawable
529 //=======================================================================
530 Drawable Draw_Window::GetDrawable() const
532 return myUseBuffer ? myBuffer : win;
535 //=======================================================================
536 //function :DefineColor
538 //=======================================================================
539 Standard_Boolean Draw_Window::DefineColor(const Standard_Integer i, const char* colorName)
543 if (!XParseColor(Draw_WindowDisplay,Draw_WindowColorMap,colorName,&color))
544 return Standard_False;
545 if (!XAllocColor(Draw_WindowDisplay,Draw_WindowColorMap,&color))
546 return Standard_False;
547 thePixels[i % MAXCOLOR] = color.pixel;
548 return Standard_True;
551 //=======================================================================
552 //function : DisplayWindow
554 //=======================================================================
555 void Draw_Window::DisplayWindow()
557 if (Draw_VirtualWindows)
561 else if (Draw_LowWindows)
563 // the window <win> will be displayed so that not to be hidden
564 // by any other window (on top)
565 XMapWindow(Draw_WindowDisplay, win);
566 XLowerWindow(Draw_WindowDisplay, win);
570 XMapRaised(Draw_WindowDisplay, win);
572 XFlush(Draw_WindowDisplay);
575 //=======================================================================
578 //=======================================================================
579 void Draw_Window::Hide()
581 XUnmapWindow(Draw_WindowDisplay, win);
584 //=======================================================================
587 //=======================================================================
588 void Draw_Window::Destroy()
590 XDestroyWindow(Draw_WindowDisplay, win);
594 XFreePixmap(Draw_WindowDisplay, myBuffer);
599 //=======================================================================
602 //=======================================================================
603 void Draw_Window::Clear()
607 // XClearArea only applicable for windows
608 XGCValues currValues;
609 XGetGCValues(Draw_WindowDisplay, base.gc, GCBackground | GCForeground, &currValues);
610 XSetForeground(Draw_WindowDisplay, base.gc, currValues.background);
611 XFillRectangle(Draw_WindowDisplay, myBuffer, base.gc, 0, 0, WidthWin(), HeightWin());
612 XSetForeground(Draw_WindowDisplay, base.gc, currValues.foreground);
616 XClearArea(Draw_WindowDisplay, win, 0, 0, 0, 0, False);
620 //=======================================================================
623 //=======================================================================
624 void Draw_Window::Flush()
626 XFlush(Draw_WindowDisplay);
629 //=======================================================================
630 //function : DrawString
632 //=======================================================================
633 void Draw_Window::DrawString(int X, int Y, char *text)
635 XDrawString(Draw_WindowDisplay, GetDrawable(), base.gc, X, Y, text, strlen(text));
638 //=======================================================================
639 //function : DrawSegments
641 //=======================================================================
642 void Draw_Window::DrawSegments(Segment *tab, int nbElem)
644 XDrawSegments(Draw_WindowDisplay, GetDrawable(), base.gc, (XSegment*) tab, nbElem);
647 //=======================================================================
650 //=======================================================================
651 void Draw_Window::Redraw()
654 XCopyArea (Draw_WindowDisplay,
655 myBuffer, win, // source, destination Drawables
658 WidthWin(), HeightWin(),
659 0, 0); // destination x, y
663 //=======================================================================
664 //function : SetColor
666 //=======================================================================
667 void Draw_Window::SetColor(Standard_Integer color)
669 XSetForeground(Draw_WindowDisplay, base.gc, thePixels[color]);
672 //=======================================================================
675 //=======================================================================
676 void Draw_Window::SetMode( int mode)
678 XSetFunction(Draw_WindowDisplay, base.gc, mode);
681 //=======================================================================
684 //=======================================================================
685 Standard_Boolean Draw_Window::Save (const char* theFileName) const
687 // make sure all draw operations done
688 XSync (Draw_WindowDisplay, True);
691 XWindowAttributes winAttr;
692 XGetWindowAttributes (Draw_WindowDisplay, win, &winAttr);
696 // make sure that the whole window fit on display to prevent BadMatch error
697 XWindowAttributes winAttrRoot;
698 XGetWindowAttributes (Draw_WindowDisplay, XRootWindowOfScreen (winAttr.screen), &winAttrRoot);
700 Window winChildDummy;
703 XTranslateCoordinates (Draw_WindowDisplay, win, XRootWindowOfScreen (winAttr.screen),
704 0, 0, &winLeft, &winTop, &winChildDummy);
706 if (((winLeft + winAttr.width) > winAttrRoot.width) || winLeft < winAttrRoot.x ||
707 ((winTop + winAttr.height) > winAttrRoot.height) || winTop < winAttrRoot.y)
709 std::cerr << "The window not fully visible! Can't create the snapshot.\n";
710 return Standard_False;
715 XImage* pximage = XGetImage (Draw_WindowDisplay, GetDrawable(),
716 0, 0, winAttr.width, winAttr.height,
720 return Standard_False;
723 if (winAttr.visual->c_class == TrueColor)
725 Standard_Byte* aDataPtr = (Standard_Byte* )pximage->data;
726 Handle(Image_PixMap) anImagePixMap = new Image_PixMap (aDataPtr,
727 pximage->width, pximage->height,
728 pximage->bytes_per_line,
729 pximage->bits_per_pixel,
732 XDestroyImage (pximage);
735 return anImagePixMap->Dump (theFileName);
739 std::cerr << "Visual Type not supported!";
741 XDestroyImage (pximage);
742 return Standard_False;
747 //=======================================================================
748 //function : ProcessEvent
750 //=======================================================================
752 void ProcessEvent(Draw_Window& win, XEvent& xev)
754 Standard_Integer X,Y,button,lenk;
770 button = xev.xbutton.button;
771 win.WButtonPress(X,Y,button);
777 button = xev.xbutton.button;
778 win.WButtonRelease(X,Y,button);
782 lenk = XLookupString(&(xev.xkey),
792 //WKeyPress(c,keysym);
798 win.WMotionNotify(X,Y);
801 case ConfigureNotify :
802 if (win.withWindowManager)
803 win.WConfigureNotify(xev.xconfigure.x, xev.xconfigure.y,
804 xev.xconfigure.width,
805 xev.xconfigure.height);
815 //=======================================================================
818 //=======================================================================
819 void Draw_Window::WExpose()
823 //=======================================================================
824 //function : WButtonPress
826 //=======================================================================
827 void Draw_Window::WButtonPress(const Standard_Integer,
828 const Standard_Integer,
829 const Standard_Integer&)
833 //=======================================================================
834 //function : WButtonRelease
836 //=======================================================================
837 void Draw_Window::WButtonRelease(const Standard_Integer,
838 const Standard_Integer,
839 const Standard_Integer&)
843 /**************************
844 //=======================================================================
845 //function : WKeyPress
847 //=======================================================================
849 void Draw_Window::WKeyPress(char, KeySym&)
852 ***************************/
854 //=======================================================================
855 //function : WMotionNotify
857 //=======================================================================
858 void Draw_Window::WMotionNotify(const Standard_Integer ,
859 const Standard_Integer )
863 //=======================================================================
864 //function : WConfigureNotify
866 //=======================================================================
868 void Draw_Window::WConfigureNotify(const Standard_Integer,
869 const Standard_Integer,
870 const Standard_Integer,
871 const Standard_Integer)
875 //=======================================================================
878 //=======================================================================
880 void Draw_Window::Wait (Standard_Boolean wait)
884 XSelectInput(Draw_WindowDisplay,win,
885 ButtonPressMask|ExposureMask | StructureNotifyMask |
889 XSelectInput(Draw_WindowDisplay,win,
890 ButtonPressMask|ExposureMask | StructureNotifyMask);
894 //=======================================================================
895 //function : WUnmapNotify
897 //=======================================================================
899 void Draw_Window::WUnmapNotify()
904 //======================================================
905 // funtion : ProcessEvents
906 // purpose : process pending X events
907 //======================================================
909 static void ProcessEvents(ClientData,int)
913 while (XPending(Draw_WindowDisplay)) {
918 XNextEvent(Draw_WindowDisplay,&xev);
920 /* search the window in the window list */
921 Draw_Window* w = Draw_Window::firstWindow;
922 Standard_Integer found=0;
924 if (xev.xany.window == w->win) {
925 ProcessEvent(*w, xev);
932 Tk_HandleEvent(&xev);
937 //======================================================
938 // funtion :Run_Appli
940 //======================================================
943 static Standard_Boolean(*Interprete) (char*);
945 void Run_Appli(Standard_Boolean (*interprete) (char*))
947 Tcl_Channel outChannel, inChannel ;
948 Interprete = interprete;
953 * Commands will come from standard input, so set up an event
954 * handler for standard input. If the input device is aEvaluate the
955 * .rc file, if one has been specified, set up an event handler
956 * for standard input, and print a prompt if the input
957 * device is a terminal.
959 inChannel = Tcl_GetStdChannel(TCL_STDIN);
961 Tcl_CreateChannelHandler(inChannel, TCL_READABLE, StdinProc,
962 (ClientData) inChannel);
965 // Create a handler for the draw display
967 // Adding of the casting into void* to be able to compile on AO1
968 // ConnectionNumber(Draw_WindowDisplay) is an int 32 bits
969 // (void*) is a pointer 64 bits ???????
971 #if TCL_MAJOR_VERSION < 8
972 Tk_CreateFileHandler((void*) ConnectionNumber(Draw_WindowDisplay),
973 TK_READABLE, ProcessEvents,(ClientData) 0 );
975 Tk_CreateFileHandler(ConnectionNumber(Draw_WindowDisplay),
976 TK_READABLE, ProcessEvents,(ClientData) 0 );
981 if (tty) Prompt(theCommands.Interp(), 0);
982 Prompt(theCommands.Interp(), 0);
984 outChannel = Tcl_GetStdChannel(TCL_STDOUT);
986 Tcl_Flush(outChannel);
988 Tcl_DStringInit(&command);
991 * Loop infinitely, waiting for commands to execute. When there
992 * are no windows left, Tk_MainLoop returns and we exit.
997 if (Draw_VirtualWindows) {
998 // main window will never shown
999 // but main loop will parse all Xlib messages
1000 Tcl_Eval(theCommands.Interp(), "wm withdraw .");
1007 Standard_Integer count = ConnectionNumber(Draw_WindowDisplay);
1008 Standard_Integer numfd;
1012 FD_SET(count,&readset);
1014 numfd = select(count+1,(Integer*)&readset,NULL,NULL,NULL);
1016 numfd = select(count+1,&readset,NULL,NULL,NULL);
1018 if (FD_ISSET(0,&readset)) StdinProc((ClientData)0,0);
1019 if (FD_ISSET(count,&readset)) ProcessEvents((ClientData)0,0);
1025 //======================================================
1026 // funtion : Init_Appli()
1028 //======================================================
1029 Standard_Boolean Init_Appli()
1032 interp = theCommands.Interp();
1038 } catch (Standard_Failure) {
1039 cout <<" Pb au lancement de TK_Init "<<endl;
1042 Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
1045 Tk_MainWindow(interp) ;
1046 if (mainWindow == NULL) {
1047 fprintf(stderr, "%s\n", interp->result);
1050 Tk_Name(mainWindow) =
1051 Tk_GetUid(Tk_SetAppName(mainWindow,
1054 Tk_GeometryRequest(mainWindow, 200, 200);
1056 if (Draw_WindowDisplay == NULL) {
1057 Draw_WindowDisplay = Tk_Display(mainWindow);
1059 if (Draw_WindowDisplay == NULL) {
1060 cout << "Cannot open display : "<<XDisplayName(NULL)<<endl;
1061 cout << "Interpret commands in batch mode."<<endl;
1062 return Standard_False;
1065 // synchronize the display server : could be done within Tk_Init
1067 XSynchronize(Draw_WindowDisplay, True);
1068 XSetInputFocus(Draw_WindowDisplay,
1070 RevertToPointerRoot,
1073 Draw_WindowScreen = DefaultScreen(Draw_WindowDisplay);
1074 Draw_WindowColorMap = DefaultColormap(Draw_WindowDisplay,
1077 Tcl_SetVar(interp,"tcl_interactive",(char*)(tty ? "1" : "0"), TCL_GLOBAL_ONLY);
1078 // Tcl_SetVar(interp,"tcl_interactive",tty ? "1" : "0", TCL_GLOBAL_ONLY);
1079 return Standard_True;
1082 //======================================================
1083 // funtion : Destroy_Appli()
1085 //======================================================
1086 void Destroy_Appli()
1088 //XCloseDisplay(Draw_WindowDisplay);
1091 //======================================================
1092 // funtion : GetNextEvent()
1094 //======================================================
1095 void GetNextEvent(Event& ev)
1098 XNextEvent(Draw_WindowDisplay, &xev);
1103 ev.window = xev.xbutton.window;
1104 ev.button = xev.xbutton.button;
1105 ev.x = xev.xbutton.x;
1106 ev.y = xev.xbutton.y;
1111 ev.window = xev.xmotion.window;
1113 ev.x = xev.xmotion.x;
1114 ev.y = xev.xmotion.y;
1120 *----------------------------------------------------------------------
1124 * This procedure is invoked by the event dispatcher whenever
1125 * standard input becomes readable. It grabs the next line of
1126 * input characters, adds them to a command being assembled, and
1127 * executes the command if it's complete.
1133 * Could be almost arbitrary, depending on the command that's
1136 *----------------------------------------------------------------------
1140 //static void StdinProc(ClientData clientData, int mask)
1141 static void StdinProc(ClientData clientData, int )
1143 static int gotPartial = 0;
1147 Tcl_Channel chan = (Tcl_Channel) clientData;
1149 // MSV Nov 2, 2001: patch for TCL 8.3: initialize line to avoid exception
1150 // when first user input is an empty string
1151 Tcl_DStringFree(&line);
1152 count = Tcl_Gets(chan, &line);
1155 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
1156 Tcl_DString linetmp;
1157 Tcl_DStringInit(&linetmp);
1158 Tcl_UniChar * UniCharString;
1159 UniCharString = Tcl_UtfToUniCharDString(Tcl_DStringValue(&line),-1,&linetmp);
1160 Standard_Integer l = Tcl_UniCharLen(UniCharString);
1161 TCollection_AsciiString AsciiString("");
1162 Standard_Character Character;
1164 for (i=0; i<l; i++) {
1165 Character = UniCharString[i];
1166 AsciiString.AssignCat(Character);
1168 Tcl_DStringInit(&line);
1169 Tcl_DStringAppend(&line, AsciiString.ToCString(), -1);
1176 Tcl_DeleteChannelHandler(chan, StdinProc, (ClientData) chan);
1184 (void) Tcl_DStringAppend(&command, Tcl_DStringValue(&line), -1);
1185 cmd = Tcl_DStringAppend(&command, "\n", -1);
1186 Tcl_DStringFree(&line);
1189 if (!Tcl_CommandComplete(cmd)) {
1196 * Disable the stdin channel handler while evaluating the command;
1197 * otherwise if the command re-enters the event loop we might
1198 * process commands from stdin before the current command is
1199 * finished. Among other things, this will trash the text of the
1200 * command being evaluated.
1203 Tcl_CreateChannelHandler(chan, 0, StdinProc, (ClientData) chan);
1207 * Disable the stdin file handler while evaluating the command;
1208 * otherwise if the command re-enters the event loop we might
1209 * process commands from stdin before the current command is
1210 * finished. Among other things, this will trash the text of the
1211 * command being evaluated.
1215 // Tk_CreateFileHandler(0, 0, StdinProc, (ClientData) 0);
1218 // xab average to avoid an output SIGBUS of DRAW
1219 // to ultimately prescise or remove once
1220 // the problem of free on the global variable at the average
1227 Tcl_CreateChannelHandler(chan, TCL_READABLE, StdinProc,
1229 Tcl_DStringFree(&command);
1236 if (tty) Prompt(interp, gotPartial);
1238 } catch (Standard_Failure) {}
1244 // Source Specifique WNT
1246 /****************************************************\
1249 \****************************************************/
1251 #include "Draw_Window.hxx"
1252 #include "DrawRessource.h"
1255 #include <Draw_Appli.hxx>
1262 // Position of information in the extra memory
1264 // indicates SUBSYSTEM:CONSOLE linker option, to be set to True in main()
1266 Standard_Boolean Draw_IsConsoleSubsystem = Standard_False;
1269 Standard_Boolean Draw_BlackBackGround = Standard_True;
1271 // Creation of color stylos
1272 HPEN colorPenTab[MAXCOLOR] = {CreatePen(PS_SOLID, PENWIDTH, RGB(255,255,255)),
1273 CreatePen(PS_SOLID, PENWIDTH, RGB(255,0,0)),
1274 CreatePen(PS_SOLID, PENWIDTH, RGB(0,255,0)),
1275 CreatePen(PS_SOLID, PENWIDTH, RGB(0,0,255)),
1276 CreatePen(PS_SOLID, PENWIDTH, RGB(0,255,255)),
1277 CreatePen(PS_SOLID, PENWIDTH, RGB(255,215,0)),
1278 CreatePen(PS_SOLID, PENWIDTH, RGB(255,0,255)),
1279 CreatePen(PS_SOLID, PENWIDTH, RGB(255,52,179)),
1280 CreatePen(PS_SOLID, PENWIDTH, RGB(255,165,0)),
1281 CreatePen(PS_SOLID, PENWIDTH, RGB(255,228,225)),
1282 CreatePen(PS_SOLID, PENWIDTH, RGB(255,160,122)),
1283 CreatePen(PS_SOLID, PENWIDTH, RGB(199,21,133)),
1284 CreatePen(PS_SOLID, PENWIDTH, RGB(255,255,0)),
1285 CreatePen(PS_SOLID, PENWIDTH, RGB(240,230,140)),
1286 CreatePen(PS_SOLID, PENWIDTH, RGB(255,127,80))};
1288 // Correspondance mode X11 and WINDOWS NT
1289 int modeTab[16] = {R2_BLACK, R2_MASKPEN, R2_MASKPENNOT, R2_COPYPEN,
1290 R2_MASKNOTPEN, R2_NOP, R2_XORPEN, R2_MERGEPEN,
1291 R2_NOTMASKPEN, R2_NOTXORPEN, R2_NOT, R2_MERGEPENNOT,
1292 R2_NOTCOPYPEN, R2_MERGENOTPEN, R2_NOTMERGEPEN, R2_WHITE};
1294 /*--------------------------------------------------------*\
1295 | CREATE DRAW WINDOW PROCEDURE
1296 \*--------------------------------------------------------*/
1297 HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
1299 if (Draw_IsConsoleSubsystem) {
1300 HWND aWin = CreateWindow (DRAWCLASS, DRAWTITLE,
1301 WS_OVERLAPPEDWINDOW,
1303 NULL, NULL,::GetModuleHandle(NULL), NULL);
1304 if (!Draw_VirtualWindows)
1306 SetWindowPos(aWin, HWND_TOPMOST, 1,1,1,1, SWP_NOMOVE);
1307 SetWindowPos(aWin, HWND_NOTOPMOST, 1,1,1,1, SWP_NOMOVE);
1314 hInstance = (HANDLE)GetWindowLong(hWndClient,GWL_HINSTANCE);
1316 hInstance = (HANDLE)GetWindowLong(hWndClient,GWLP_HINSTANCE);
1319 return CreateMDIWindow(DRAWCLASS, DRAWTITLE,
1320 WS_CAPTION | WS_CHILD | WS_THICKFRAME,
1322 hWndClient, (HINSTANCE)hInstance, nitem);
1327 /*--------------------------------------------------------*\
1328 | DRAW WINDOW PROCEDURE
1329 \*--------------------------------------------------------*/
1330 LONG APIENTRY DrawWindow::DrawProc(HWND hWnd, UINT wMsg, WPARAM wParam, LONG lParam )
1332 DrawWindow* localObjet = (DrawWindow*)GetWindowLong(hWnd, CLIENTWND);
1335 if (Draw_IsConsoleSubsystem)
1336 return (DefWindowProc(hWnd, wMsg, wParam, lParam));
1338 return(DefMDIChildProc(hWnd, wMsg, wParam, lParam));
1346 BeginPaint(hWnd, &ps);
1347 if (localObjet->GetUseBuffer())
1348 localObjet->Redraw();
1350 localObjet->WExpose();
1351 EndPaint(hWnd, &ps);
1356 if (localObjet->GetUseBuffer()) {
1357 localObjet->InitBuffer();
1358 localObjet->WExpose();
1359 localObjet->Redraw();
1365 if (Draw_IsConsoleSubsystem)
1366 return (DefWindowProc(hWnd, wMsg, wParam, lParam));
1368 return(DefMDIChildProc(hWnd, wMsg, wParam, lParam));
1376 ** IMPLEMENTATION of the CLASS DRAWWINDOW
1379 /*--------------------------------------------------------*\
1380 | Initialization of static variables of DrawWindow
1381 \*--------------------------------------------------------*/
1383 DrawWindow* DrawWindow::firstWindow = NULL;
1384 HWND DrawWindow::hWndClientMDI = 0;
1386 /*--------------------------------------------------------*\
1387 | Constructors of Draw_Window
1388 \*--------------------------------------------------------*/
1390 // Default Constructor
1391 //________________________
1392 DrawWindow::DrawWindow() :
1397 myUseBuffer(Standard_False)
1399 if (firstWindow) firstWindow->previous = this;
1403 //________________________
1404 DrawWindow::DrawWindow(char* title,
1405 Standard_Integer X, Standard_Integer Y,
1406 Standard_Integer dX,Standard_Integer dY) :
1407 win(0), next(firstWindow), previous(NULL), myMemHbm(NULL), myUseBuffer(Standard_False)
1409 if (firstWindow) firstWindow->previous = this;
1414 DrawWindow::DrawWindow(char* title,
1415 Standard_Integer X, Standard_Integer Y,
1416 Standard_Integer dX,Standard_Integer dY,
1418 win(theWin),next(firstWindow), previous(NULL), myMemHbm(NULL), myUseBuffer(Standard_False)
1420 if (firstWindow) firstWindow->previous = this;
1428 /*--------------------------------------------------------*\
1429 | Destructor of DrawWindow
1430 \*--------------------------------------------------------*/
1431 DrawWindow::~DrawWindow()
1434 previous->next = next;
1438 next->previous = previous;
1440 // Delete 'off-screen drawing'-related objects
1442 DeleteObject(myMemHbm);
1449 /*--------------------------------------------------------*\
1451 \*--------------------------------------------------------*/
1452 void DrawWindow::Init(Standard_Integer theXLeft, Standard_Integer theYTop,
1453 Standard_Integer theWidth, Standard_Integer theHeight)
1457 win = CreateDrawWindow(hWndClientMDI, 0);
1460 // include decorations in the window dimensions
1461 // to reproduce same behaviour of Xlib window.
1462 theXLeft -= GetSystemMetrics(SM_CXSIZEFRAME);
1463 theYTop -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
1464 theWidth += 2 * GetSystemMetrics(SM_CXSIZEFRAME);
1465 theHeight += 2 * GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);
1467 SetPosition (theXLeft, theYTop);
1468 SetDimension (theWidth, theHeight);
1469 // Save the pointer at the instance associated to the window
1470 SetWindowLong(win, CLIENTWND, (LONG)this);
1471 HDC hDC = GetDC(win);
1472 SetBkColor(hDC, RGB(0, 0, 0));
1475 SelectObject(hDC, colorPenTab[myCurrPen]); // Default pencil
1476 SelectObject(hDC, GetStockObject(BLACK_BRUSH));
1477 SetTextColor(hDC, RGB(0,0,255));
1478 ReleaseDC(win, hDC);
1480 if (Draw_VirtualWindows)
1482 // create a virtual window
1483 SetUseBuffer (Standard_True);
1487 /*--------------------------------------------------------*\
1489 \*--------------------------------------------------------*/
1490 void DrawWindow::SetUseBuffer(Standard_Boolean use)
1496 /*--------------------------------------------------------*\
1498 \*--------------------------------------------------------*/
1499 void DrawWindow::InitBuffer()
1503 HDC hDC = GetDC(win);
1504 GetClientRect(win, &rc);
1507 GetObject(myMemHbm, sizeof(BITMAP), &aBmp);
1508 if (rc.right-rc.left == aBmp.bmWidth && rc.bottom-rc.top == aBmp.bmHeight) return;
1509 DeleteObject(myMemHbm);
1511 myMemHbm = (HBITMAP)CreateCompatibleBitmap(hDC,
1514 HDC aMemDC = GetMemDC(hDC);
1515 FillRect(aMemDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
1516 ReleaseMemDC(aMemDC);
1517 ReleaseDC(win, hDC);
1521 DeleteObject(myMemHbm);
1527 /*--------------------------------------------------------*\
1529 \*--------------------------------------------------------*/
1530 HDC DrawWindow::GetMemDC(HDC theWinDC)
1532 if (!myUseBuffer) return NULL;
1534 HDC aWorkDC = CreateCompatibleDC(theWinDC);
1535 myOldHbm = (HBITMAP)SelectObject(aWorkDC, myMemHbm);
1536 SetROP2(aWorkDC, modeTab[myCurrMode]);
1537 SelectObject(aWorkDC, colorPenTab[myCurrPen]);
1538 SetBkColor(aWorkDC, RGB(0, 0, 0));
1539 SelectObject(aWorkDC, GetStockObject(BLACK_BRUSH));
1540 SetTextColor(aWorkDC, RGB(0,0,255));
1545 /*--------------------------------------------------------*\
1547 \*--------------------------------------------------------*/
1548 void DrawWindow::ReleaseMemDC(HDC theMemDC)
1550 if (!myUseBuffer || !theMemDC) return;
1552 if (myOldHbm) SelectObject(theMemDC, myOldHbm);
1557 /*--------------------------------------------------------*\
1559 \*--------------------------------------------------------*/
1560 void DrawWindow::SetPosition(Standard_Integer posX, Standard_Integer posY)
1562 SetWindowPos(win, 0,
1565 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
1569 /*--------------------------------------------------------*\
1571 \*--------------------------------------------------------*/
1572 void DrawWindow::SetDimension(Standard_Integer dimX, Standard_Integer dimY)
1574 SetWindowPos(win, 0,
1577 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
1581 /*--------------------------------------------------------*\
1583 \*--------------------------------------------------------*/
1584 void DrawWindow::GetPosition(Standard_Integer &dimX,
1585 Standard_Integer &dimY)
1588 GetWindowRect(win, &rect);
1591 point.x = rect.left;
1594 ScreenToClient(hWndClientMDI, &point);
1600 /*--------------------------------------------------------*\
1602 \*--------------------------------------------------------*/
1603 Standard_Integer DrawWindow::HeightWin() const
1606 GetClientRect(win, &rect);
1607 return(rect.bottom-rect.top);
1611 /*--------------------------------------------------------*\
1613 \*--------------------------------------------------------*/
1614 Standard_Integer DrawWindow::WidthWin() const
1617 GetClientRect(win, &rect);
1618 return(rect.right-rect.left);
1622 /*--------------------------------------------------------*\
1624 \*--------------------------------------------------------*/
1625 void DrawWindow::SetTitle(char* title)
1627 SetWindowText(win, title);
1631 /*--------------------------------------------------------*\
1633 | Attention do not forget to unallocate the memory
1634 \*--------------------------------------------------------*/
1635 char* DrawWindow::GetTitle()
1637 char* title=new char[31];
1638 GetWindowText(win, title, 30);
1643 /*--------------------------------------------------------*\
1645 \*--------------------------------------------------------*/
1646 void DrawWindow::DisplayWindow()
1648 if (Draw_VirtualWindows)
1652 ShowWindow (win, SW_SHOW);
1657 /*--------------------------------------------------------*\
1659 \*--------------------------------------------------------*/
1660 void DrawWindow::Hide()
1662 ShowWindow(win, SW_HIDE);
1666 /*--------------------------------------------------------*\
1668 \*--------------------------------------------------------*/
1669 void DrawWindow::Destroy()
1676 /*--------------------------------------------------------*\
1678 \*--------------------------------------------------------*/
1679 void DrawWindow::Clear()
1681 HDC hDC = GetDC(win);
1682 HDC aWorkDC = myUseBuffer ? GetMemDC(hDC) : hDC;
1684 int debug = GetROP2(aWorkDC);
1686 SelectObject(aWorkDC,GetStockObject(BLACK_PEN));
1687 Rectangle(aWorkDC, 0, 0, WidthWin(), HeightWin());
1688 RestoreDC(aWorkDC,-1);
1690 if (myUseBuffer) ReleaseMemDC(aWorkDC);
1694 /*--------------------------------------------------------*\
1696 \*--------------------------------------------------------*/
1697 static Standard_Boolean SaveBitmap (HBITMAP theHBitmap,
1698 const char* theFileName)
1700 // Copy data from HBITMAP
1703 // Get informations about the bitmap
1704 GetObject (theHBitmap, sizeof(BITMAP), (LPSTR )&aBitmap);
1705 Standard_Integer aWidth = aBitmap.bmWidth;
1706 Standard_Integer aHeight = aBitmap.bmHeight;
1709 BITMAPINFOHEADER aBitmapInfo;
1710 memset (&aBitmapInfo, 0, sizeof(BITMAPINFOHEADER));
1711 aBitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
1712 aBitmapInfo.biWidth = aWidth;
1713 aBitmapInfo.biHeight = aHeight; // positive means bottom-up!
1714 aBitmapInfo.biPlanes = 1;
1715 aBitmapInfo.biBitCount = 32;
1716 aBitmapInfo.biCompression = BI_RGB;
1718 Standard_Integer aBytesPerLine = aWidth * 4;
1719 Standard_Byte* aDataPtr = new Standard_Byte[aBytesPerLine * aHeight];
1722 HDC aDC = GetDC (NULL);
1723 Standard_Boolean isSuccess
1724 = GetDIBits (aDC, // handle to DC
1725 theHBitmap, // handle to bitmap
1726 0, // first scan line to set
1727 aHeight, // number of scan lines to copy
1728 aDataPtr, // array for bitmap bits
1729 (LPBITMAPINFO )&aBitmapInfo, // bitmap data info
1730 DIB_RGB_COLORS // RGB
1735 Handle(Image_PixMap) anImagePixMap = new Image_PixMap (aDataPtr,
1738 aBitmapInfo.biBitCount,
1739 Standard_False); // bottom-up!
1741 // Release dump memory here
1745 anImagePixMap->Dump (theFileName);
1749 // Release dump memory
1752 ReleaseDC (NULL, aDC);
1756 /*--------------------------------------------------------*\
1758 \*--------------------------------------------------------*/
1759 Standard_Boolean DrawWindow::Save (const char* theFileName) const
1763 return SaveBitmap (myMemHbm, theFileName);
1767 GetClientRect (win, &aRect);
1768 int aWidth = aRect.right - aRect.left;
1769 int aHeight = aRect.bottom - aRect.top;
1772 HDC aDstDC = GetDC (NULL);
1773 HDC aSrcDC = GetDC (win); // we copy only client area
1774 HDC aMemDC = CreateCompatibleDC (aDstDC);
1776 // Copy the screen to the bitmap
1777 HBITMAP anHBitmapDump = CreateCompatibleBitmap (aDstDC, aWidth, aHeight);
1778 HBITMAP anHBitmapOld = (HBITMAP )SelectObject (aMemDC, anHBitmapDump);
1779 BitBlt (aMemDC, 0, 0, aWidth, aHeight, aSrcDC, 0, 0, SRCCOPY);
1781 Standard_Boolean isSuccess = SaveBitmap (anHBitmapDump, theFileName);
1784 DeleteObject (SelectObject (aMemDC, anHBitmapOld));
1790 /*--------------------------------------------------------*\
1792 \*--------------------------------------------------------*/
1793 void DrawWindow::DrawString(int x,int y, char* text)
1795 HDC hDC = GetDC(win);
1796 HDC aWorkDC = myUseBuffer ? GetMemDC(hDC) : hDC;
1798 TextOut(aWorkDC, x, y, text, strlen(text));
1800 if (myUseBuffer) ReleaseMemDC(aWorkDC);
1804 /*--------------------------------------------------------*\
1806 \*--------------------------------------------------------*/
1807 void DrawWindow::DrawSegments(Segment *tab, int nbElem)
1809 HDC hDC = GetDC(win);
1810 HDC aWorkDC = myUseBuffer ? GetMemDC(hDC) : hDC;
1812 for(int i = 0 ; i < nbElem ; i++)
1814 MoveToEx(aWorkDC, tab[i].x1, tab[i].y1, NULL);
1815 LineTo(aWorkDC, tab[i].x2, tab[i].y2);
1818 if (myUseBuffer) ReleaseMemDC(aWorkDC);
1822 /*--------------------------------------------------------*\
1824 \*--------------------------------------------------------*/
1825 void DrawWindow::Redraw()
1828 HDC hDC = GetDC(win);
1830 GetClientRect(win, &rc);
1831 HDC aMemDC = GetMemDC(hDC);
1834 rc.right-rc.left, rc.bottom-rc.top,
1837 ReleaseMemDC(aMemDC);
1842 /*--------------------------------------------------------*\
1844 \*--------------------------------------------------------*/
1845 void DrawWindow::SetMode(int mode)
1847 HDC hDC = GetDC(win);
1849 SetROP2(hDC, modeTab[mode]);
1854 /*--------------------------------------------------------*\
1856 \*--------------------------------------------------------*/
1857 void DrawWindow::SetColor(Standard_Integer color)
1859 HDC hDC = GetDC(win);
1861 SelectObject(hDC,colorPenTab[color]);
1866 /*--------------------------------------------------------*\
1868 \*--------------------------------------------------------*/
1869 void DrawWindow::WExpose()
1874 /*--------------------------------------------------------*\
1876 \*--------------------------------------------------------*/
1877 void DrawWindow::WButtonPress(const Standard_Integer,
1878 const Standard_Integer,
1879 const Standard_Integer&)
1884 /*--------------------------------------------------------*\
1886 \*--------------------------------------------------------*/
1887 void DrawWindow::WButtonRelease(const Standard_Integer,
1888 const Standard_Integer,
1889 const Standard_Integer&)
1894 /*--------------------------------------------------------*\
1896 \*--------------------------------------------------------*/
1897 void Draw_Window::WMotionNotify(const Standard_Integer ,
1898 const Standard_Integer )
1903 /*--------------------------------------------------------*\
1905 \*--------------------------------------------------------*/
1906 void DrawWindow::WConfigureNotify(const Standard_Integer,
1907 const Standard_Integer,
1908 const Standard_Integer,
1909 const Standard_Integer)
1914 /*--------------------------------------------------------*\
1916 \*--------------------------------------------------------*/
1917 void DrawWindow::WUnmapNotify()
1924 ** IMPLEMENTATION of the CLASS SEGMENT
1927 /*--------------------------------------------------------*\
1929 \*--------------------------------------------------------*/
1931 void Segment::Init(Standard_Integer a1, Standard_Integer a2,
1932 Standard_Integer a3, Standard_Integer a4)
1940 static DWORD WINAPI tkLoop(VOID);
1942 static Tk_Window mainWindow;
1945 //* threads sinchronization *//
1946 DWORD dwMainThreadId;
1947 console_semaphore_value volatile console_semaphore = WAIT_CONSOLE_COMMAND;
1948 char console_command[1000];
1950 bool volatile isTkLoopStarted = false;
1952 /*--------------------------------------------------------*\
1954 \*--------------------------------------------------------*/
1955 Standard_Boolean Init_Appli(HINSTANCE hInst,
1956 HINSTANCE hPrevInst, int nShow, HWND& hWndFrame )
1960 console_semaphore = STOP_CONSOLE;
1962 interp = theCommands.Interp();
1965 dwMainThreadId = GetCurrentThreadId();
1967 //necessary for normal Tk operation
1968 hThread = CreateThread(NULL, // no security attributes
1969 0, // use default stack size
1970 (LPTHREAD_START_ROUTINE) tkLoop, // thread function
1971 NULL, // no thread function argument
1972 0, // use default creation flags
1975 cout << "Tcl/Tk main loop thread not created. Switching to batch mode..." << endl;
1980 } catch (Standard_Failure) {
1981 cout <<" Pb au lancement de TK_Init "<<endl;
1984 Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
1986 //since the main Tcl/Tk loop wasn't created --> switch to batch mode
1987 return Standard_False;
1990 // san - 06/08/2002 - Time for tkLoop to start; Tk fails to initialize otherwise
1991 while (!isTkLoopStarted)
1994 // Saving of window classes
1996 if(!RegisterAppClass(hInst))
1997 return(Standard_False);
2000 ** Enter the application message-polling loop. This is the anchor for
2003 if(Draw_IsConsoleSubsystem)
2007 else if (hWndFrame = CreateAppWindow(hInst))
2009 ShowWindow(hWndFrame,nShow);
2010 UpdateWindow(hWndFrame);
2013 return Standard_True;
2016 Standard_Boolean Draw_Interprete (char*);
2018 /*--------------------------------------------------------*\
2019 | readStdinThreadFunc
2020 \*--------------------------------------------------------*/
2021 static DWORD WINAPI readStdinThreadFunc(VOID)
2023 if (!Draw_IsConsoleSubsystem) return 1;
2026 while (console_semaphore != WAIT_CONSOLE_COMMAND)
2028 if (gets(console_command))
2030 console_semaphore = HAS_CONSOLE_COMMAND;
2037 /*--------------------------------------------------------*\
2038 | exitProc: finalization handler for Tcl/Tk thread. Forces parent process to die
2039 \*--------------------------------------------------------*/
2040 void exitProc(ClientData /*dc*/)
2042 HANDLE proc = GetCurrentProcess();
2043 TerminateProcess(proc, 0);
2046 /*--------------------------------------------------------*\
2047 | tkLoop: implements Tk_Main()-like behaviour in a separate thread
2048 \*--------------------------------------------------------*/
2049 static DWORD WINAPI tkLoop(VOID)
2051 Tcl_CreateExitHandler(exitProc, 0);
2052 #if (TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5))
2053 Tcl_RegisterChannel(theCommands.Interp(), Tcl_GetStdChannel(TCL_STDIN));
2054 Tcl_RegisterChannel(theCommands.Interp(), Tcl_GetStdChannel(TCL_STDOUT));
2055 Tcl_RegisterChannel(theCommands.Interp(), Tcl_GetStdChannel(TCL_STDERR));
2059 // initialize the Tk library if not in 'virtual windows' mode
2060 // (virtual windows are created by OCCT with native APIs,
2061 // thus Tk will be useless)
2062 if (!Draw_VirtualWindows)
2067 Standard_Integer res = Tk_Init (interp);
2070 cout << "tkLoop: error in Tk initialization. Tcl reported: " << interp->result << endl;
2073 catch (Standard_Failure)
2075 cout << "tkLoop: exception in TK_Init\n";
2077 Tcl_StaticPackage (interp, "Tk", Tk_Init, (Tcl_PackageInitProc* ) NULL);
2078 mainWindow = Tk_MainWindow (interp);
2079 if (mainWindow == NULL)
2081 fprintf (stderr, "%s\n", interp->result);
2082 cout << "tkLoop: Tk_MainWindow() returned NULL. Exiting...\n";
2085 Tk_Name(mainWindow) = Tk_GetUid (Tk_SetAppName (mainWindow, "Draw"));
2089 // set signal handler in the new thread
2092 // inform the others that we have started
2093 isTkLoopStarted = true;
2095 while (console_semaphore == STOP_CONSOLE)
2096 Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT);
2098 if (Draw_IsConsoleSubsystem && console_semaphore == WAIT_CONSOLE_COMMAND)
2102 Standard_Boolean toLoop = Standard_True;
2105 while(Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT));
2106 if (console_semaphore == HAS_CONSOLE_COMMAND)
2108 if (Draw_Interprete (console_command))
2110 if (Draw_IsConsoleSubsystem) Prompt (interp, 0);
2114 if (Draw_IsConsoleSubsystem) Prompt (interp, 1);
2116 console_semaphore = WAIT_CONSOLE_COMMAND;
2123 // We should not exit until the Main Tk window is closed
2124 toLoop = (Tk_GetNumMainWindows() > 0) || Draw_VirtualWindows;
2132 /*--------------------------------------------------------*\
2134 \*--------------------------------------------------------*/
2135 void Run_Appli(HWND hWnd)
2138 HACCEL hAccel = NULL;
2142 // if (!(hAccel = LoadAccelerators (hInstance, MAKEINTRESOURCE(ACCEL_ID))))
2143 // MessageBox(hWnd, "MDI: Load Accel failure!", "Error", MB_OK);
2146 if (Draw_IsConsoleSubsystem) {
2147 hThread = CreateThread(NULL, // no security attributes
2148 0, // use default stack size
2149 (LPTHREAD_START_ROUTINE) readStdinThreadFunc, // thread function
2150 NULL, // no thread function argument
2151 0, // use default creation flags
2152 &IDThread); // returns thread identifier
2154 cout << "pb in creation of the thread reading stdin" << endl;
2155 Draw_IsConsoleSubsystem = Standard_False;
2156 Init_Appli(GetModuleHandle(NULL),
2157 GetModuleHandle(NULL),
2158 1, hWnd); // reinit => create MDI client wnd
2162 //turn on the command interpretation mechanism (regardless of the mode)
2163 if (console_semaphore == STOP_CONSOLE)
2164 console_semaphore = WAIT_CONSOLE_COMMAND;
2166 //simple Win32 message loop
2167 while (GetMessage(&msg, NULL, 0, 0) > 0)
2169 if (!TranslateAccelerator(hWnd, hAccel, &msg))
2171 TranslateMessage(&msg);
2172 DispatchMessage(&msg);
2179 /*--------------------------------------------------------*\
2181 \*--------------------------------------------------------*/
2182 void Destroy_Appli(HINSTANCE hInst)
2184 UnregisterAppClass(hInst);
2185 for (int i = 0 ; i < MAXCOLOR ; i++)
2186 DeleteObject(colorPenTab[i]);
2189 /*--------------------------------------------------------*\
2191 \*--------------------------------------------------------*/
2192 void DrawWindow::SelectWait(HANDLE& hWnd, int& x, int& y, int& button)
2198 GetMessage(&msg,NULL,0,0);
2199 while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN) ||
2200 ! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd)) )
2201 GetMessage(&msg,NULL,0,0);
2204 x = LOWORD(msg.lParam);
2205 y = HIWORD(msg.lParam);
2206 if (msg.message == WM_LBUTTONDOWN)
2212 /*--------------------------------------------------------*\
2214 \*--------------------------------------------------------*/
2215 void DrawWindow::SelectNoWait(HANDLE& hWnd, int& x, int& y, int& button)
2221 GetMessage(&msg,NULL,0,0);
2222 while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN &&
2223 msg.message != WM_MOUSEMOVE) ||
2224 ! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd) ) )
2225 GetMessage(&msg,NULL,0,0);
2227 x = LOWORD(msg.lParam);
2228 y = HIWORD(msg.lParam);
2229 switch (msg.message)
2231 case WM_LBUTTONDOWN :
2235 case WM_RBUTTONDOWN :
2245 Standard_Boolean DrawWindow::DefineColor (const Standard_Integer, const char*)
2247 return Standard_True;