OCC22250 Windows lost focus with DRAWEXE launched in 'virtual windows' mode
authorKGV <>
Thu, 28 Apr 2011 15:47:42 +0000 (15:47 +0000)
committerbugmaster <bugmaster@opencascade.com>
Mon, 5 Mar 2012 15:28:14 +0000 (19:28 +0400)
src/Draw/Draw_Window.cxx
src/DrawResources/DrawDefault

index 1bc18cd..587ef5f 100755 (executable)
@@ -1301,8 +1301,11 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
                               WS_OVERLAPPEDWINDOW,
                               1,1,1,1,
                               NULL, NULL,::GetModuleHandle(NULL), NULL);
                               WS_OVERLAPPEDWINDOW,
                               1,1,1,1,
                               NULL, NULL,::GetModuleHandle(NULL), NULL);
-    SetWindowPos(aWin, HWND_TOPMOST, 1,1,1,1, SWP_NOMOVE);
-    SetWindowPos(aWin, HWND_NOTOPMOST, 1,1,1,1, SWP_NOMOVE);
+    if (!Draw_VirtualWindows)
+    {
+      SetWindowPos(aWin, HWND_TOPMOST, 1,1,1,1, SWP_NOMOVE);
+      SetWindowPos(aWin, HWND_NOTOPMOST, 1,1,1,1, SWP_NOMOVE);
+    }
     return aWin;
   }
   else {
     return aWin;
   }
   else {
@@ -1955,7 +1958,6 @@ Standard_Boolean Init_Appli(HINSTANCE hInst,
   DWORD IDThread;
   HANDLE hThread;
   console_semaphore = STOP_CONSOLE;
   DWORD IDThread;
   HANDLE hThread;
   console_semaphore = STOP_CONSOLE;
-
   theCommands.Init();
   interp = theCommands.Interp();
   Tcl_Init(interp) ;
   theCommands.Init();
   interp = theCommands.Interp();
   Tcl_Init(interp) ;
@@ -1994,11 +1996,6 @@ Standard_Boolean Init_Appli(HINSTANCE hInst,
     if(!RegisterAppClass(hInst))
       return(Standard_False);
 
     if(!RegisterAppClass(hInst))
       return(Standard_False);
 
-  if (Draw_VirtualWindows) {
-    // main window will never shown
-    Tcl_Eval(theCommands.Interp(), "wm withdraw .");
-  }
-
   /*
    ** Enter the application message-polling loop.  This is the anchor for
    ** the application.
   /*
    ** Enter the application message-polling loop.  This is the anchor for
    ** the application.
@@ -2052,7 +2049,6 @@ void exitProc(ClientData /*dc*/)
 static DWORD WINAPI tkLoop(VOID)
 {
   Tcl_CreateExitHandler(exitProc, 0);
 static DWORD WINAPI tkLoop(VOID)
 {
   Tcl_CreateExitHandler(exitProc, 0);
-
 #if (TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5))
   Tcl_RegisterChannel(theCommands.Interp(),  Tcl_GetStdChannel(TCL_STDIN));
   Tcl_RegisterChannel(theCommands.Interp(),  Tcl_GetStdChannel(TCL_STDOUT));
 #if (TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5))
   Tcl_RegisterChannel(theCommands.Interp(),  Tcl_GetStdChannel(TCL_STDIN));
   Tcl_RegisterChannel(theCommands.Interp(),  Tcl_GetStdChannel(TCL_STDOUT));
@@ -2060,38 +2056,40 @@ static DWORD WINAPI tkLoop(VOID)
 #endif
 
 #ifdef _TK
 #endif
 
 #ifdef _TK
-  try {
-    OCC_CATCH_SIGNALS
-    Standard_Integer res = Tk_Init(interp) ;
-    if (res != TCL_OK)
-      cout << "tkLoop: error in Tk initialization. Tcl reported: " << interp->result << endl;
-
-  } catch  (Standard_Failure) {
-    cout <<"tkLoop: exception in TK_Init "<<endl;
-  }
-  Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL);
-
-  mainWindow =
-    Tk_MainWindow(interp) ;
-  if (mainWindow == NULL) {
-        fprintf(stderr, "%s\n", interp->result);
-        cout << "tkLoop: Tk_MainWindow() returned NULL. Exiting..." << endl;
-        Tcl_Exit(0);
-   }
-  Tk_Name(mainWindow) =
-    Tk_GetUid(Tk_SetAppName(mainWindow,
-                          "Draw")) ;
-
-  if (Draw_VirtualWindows) {
-    // main window will never shown
-    Tcl_Eval(theCommands.Interp(), "wm withdraw .");
+  // initialize the Tk library if not in 'virtual windows' mode
+  // (virtual windows are created by OCCT with native APIs,
+  // thus Tk will be useless)
+  if (!Draw_VirtualWindows)
+  {
+    try
+    {
+      OCC_CATCH_SIGNALS
+      Standard_Integer res = Tk_Init (interp);
+      if (res != TCL_OK)
+      {
+        cout << "tkLoop: error in Tk initialization. Tcl reported: " << interp->result << endl;
+      }
+    }
+    catch (Standard_Failure)
+    {
+      cout << "tkLoop: exception in TK_Init\n";
+    }
+    Tcl_StaticPackage (interp, "Tk", Tk_Init, (Tcl_PackageInitProc* ) NULL);
+    mainWindow = Tk_MainWindow (interp);
+    if (mainWindow == NULL)
+    {
+      fprintf (stderr, "%s\n", interp->result);
+      cout << "tkLoop: Tk_MainWindow() returned NULL. Exiting...\n";
+      Tcl_Exit (0);
+    }
+    Tk_Name(mainWindow) = Tk_GetUid (Tk_SetAppName (mainWindow, "Draw"));
   }
   }
-#endif  //#ifdef _TK
+#endif //#ifdef _TK
 
 
-  // msv - 16/09/2004 - set signal handler in the new thread
+  // set signal handler in the new thread
   OSD::SetSignal();
 
   OSD::SetSignal();
 
-  // san - 06/08/2002 - inform the others that we have started
+  // inform the others that we have started
   isTkLoopStarted = true;
 
   while (console_semaphore == STOP_CONSOLE)
   isTkLoopStarted = true;
 
   while (console_semaphore == STOP_CONSOLE)
@@ -2101,27 +2099,32 @@ static DWORD WINAPI tkLoop(VOID)
     Prompt(interp, 0);
 
   //process a command
     Prompt(interp, 0);
 
   //process a command
-#ifdef _TK
-  // san - 10/07/02 -- We should not exit until the Main Tk window is closed
-  while (Tk_GetNumMainWindows() > 0) {
-#else
-  while (1) {
-#endif
+  Standard_Boolean toLoop = Standard_True;
+  while (toLoop)
+  {
     while(Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT));
     while(Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT));
-    if (console_semaphore == HAS_CONSOLE_COMMAND) {
-      if (Draw_Interprete(console_command))
-        if (Draw_IsConsoleSubsystem) Prompt(interp, 0);
+    if (console_semaphore == HAS_CONSOLE_COMMAND)
+    {
+      if (Draw_Interprete (console_command))
+      {
+        if (Draw_IsConsoleSubsystem) Prompt (interp, 0);
+      }
       else
       else
-        if (Draw_IsConsoleSubsystem) Prompt(interp, 1);
+      {
+        if (Draw_IsConsoleSubsystem) Prompt (interp, 1);
+      }
       console_semaphore = WAIT_CONSOLE_COMMAND;
     }
     else
       console_semaphore = WAIT_CONSOLE_COMMAND;
     }
     else
+    {
       Sleep(100);
       Sleep(100);
-
+    }
+  #ifdef _TK
+    // We should not exit until the Main Tk window is closed
+    toLoop = (Tk_GetNumMainWindows() > 0) || Draw_VirtualWindows;
+  #endif
   }
   }
-
   Tcl_Exit(0);
   Tcl_Exit(0);
-
   return 0;
 }
 
   return 0;
 }
 
index 124ed18..9e44917 100755 (executable)
@@ -8,11 +8,11 @@ set dir ""
 if { [info exists env(DRAWHOME) ] } { 
   set dir $env(DRAWHOME)  
 } else {
 if { [info exists env(DRAWHOME) ] } { 
   set dir $env(DRAWHOME)  
 } else {
-    if { [info exists env(CASROOT) ] } {
-  set dir [file join $env(CASROOT) src DrawResources]
-    } else {
-  puts " CASROOT is Mandatory to Run OpenCascade"
-    }
+  if { [info exists env(CASROOT) ] } {
+    set dir [file join $env(CASROOT) src DrawResources]
+  } else {
+    puts " CASROOT is Mandatory to Run OpenCascade"
+  }
 }
 
 # san - 02/08/2002 - In Tcl8.3 it is no longer necessary to load Tix explicitly on WNT
 }
 
 # san - 02/08/2002 - In Tcl8.3 it is no longer necessary to load Tix explicitly on WNT
@@ -23,15 +23,19 @@ if { [info exists env(DRAWHOME) ] } {
 #}
 
 if { [file exist  $dir] } { 
 #}
 
 if { [file exist  $dir] } { 
-   source [file join $dir StandardCommands.tcl]
-   source [file join $dir StandardViews.tcl]
-   source [file join $dir Geometry.tcl]
-   if [info exists tk_version] {source [file join $dir DrawTK.tcl]}
-   if [file readable DrawAppliInit] {
-  source DrawAppliInit
-   }
-   set stationname $tcl_platform(platform)
-   if { ${stationname} == "windows" } {
+  source [file join $dir StandardCommands.tcl]
+  source [file join $dir StandardViews.tcl]
+  source [file join $dir Geometry.tcl]
+
+  set stationname $tcl_platform(platform)
+  if [info exists tk_version] {
+    source [file join $dir DrawTK.tcl]
+    # setup the icon for main window
+    if { ${stationname} == "windows" } {
       wm iconbitmap . -default [file join $dir lamp.ico]
       wm iconbitmap . -default [file join $dir lamp.ico]
-   }
+    }
+  }
+  if [file readable DrawAppliInit] {
+    source DrawAppliInit
+  }
 } 
 }