0023885: Inclusion of X11 header should be protected with macro
[occt.git] / src / Draw / Draw_Window.cxx
index ab3c504..539bab4 100755 (executable)
@@ -79,7 +79,11 @@ defaultPrompt:
       errChannel = Tcl_GetStdChannel(TCL_STDERR);
       if (code != TCL_OK) {
         if (errChannel) {
+#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5)))
+          Tcl_Write(errChannel, Tcl_GetStringResult(Interp), -1);
+#else
           Tcl_Write(errChannel, Interp->result, -1);
+#endif
           Tcl_Write(errChannel, "\n", 1);
         }
         Tcl_AddErrorInfo(Interp,
@@ -130,10 +134,6 @@ defaultPrompt:
 # include <strings.h>
 #endif
 
-
-#include <Draw_WindowBase.hxx>
-#include <X11/XWDFile.h>
-
 #include <stdio.h>
 #include <tk.h>
 
@@ -170,10 +170,7 @@ static Standard_Boolean tty;        /* Non-zero means standard input is a
 
 static unsigned long thePixels[MAXCOLOR];
 
-
-Display*         Draw_WindowDisplay = NULL;
 Standard_Integer Draw_WindowScreen = 0;
-Colormap         Draw_WindowColorMap;
 Standard_Boolean Draw_BlackBackGround = Standard_True;
 
 
@@ -181,7 +178,23 @@ Standard_Boolean Draw_BlackBackGround = Standard_True;
 //======================================================
 Draw_Window* Draw_Window::firstWindow = NULL;
 
+// X11 specific part
 #if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
+#include <X11/Xutil.h>
+#include <Aspect_DisplayConnection.hxx>
+
+Display* Draw_WindowDisplay = NULL;
+Colormap Draw_WindowColorMap;
+static Handle(Aspect_DisplayConnection) Draw_DisplayConnection;
+
+// Base_Window struct definition
+//===================================
+struct Base_Window
+{
+  GC gc;
+  XSetWindowAttributes xswa;
+};
+
 //=======================================================================
 //function : Draw_Window
 //purpose  :
@@ -588,6 +601,7 @@ void Draw_Window::Hide()
 //=======================================================================
 void Draw_Window::Destroy()
 {
+  XFreeGC (Draw_WindowDisplay, base.gc);
   XDestroyWindow(Draw_WindowDisplay, win);
   win = 0;
   if (myBuffer != 0)
@@ -1081,7 +1095,11 @@ Standard_Boolean Init_Appli()
   mainWindow =
   Tk_MainWindow(interp) ;
   if (mainWindow == NULL) {
+#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5)))
+    fprintf(stderr, "%s\n", Tcl_GetStringResult(interp));
+#else
     fprintf(stderr, "%s\n", interp->result);
+#endif
     exit(1);
   }
   Tk_Name(mainWindow) =
@@ -1091,17 +1109,21 @@ Standard_Boolean Init_Appli()
   Tk_GeometryRequest(mainWindow, 200, 200);
 
 #if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
-  if (Draw_WindowDisplay == NULL) {
-    Draw_WindowDisplay = XOpenDisplay(NULL);
-    // Replaced Tk_Display(mainWindow) with XOpenDisplay; On Mac OS X Tk_Display
-    // returns a pointer to Display structure defined in system Tcl/Tk libraries.
-    // This structure differs from structure defined in X11 library and
-    // this caused DRAWEXE crash on startup.
+  if (Draw_DisplayConnection.IsNull())
+  {
+    try
+    {
+      Draw_DisplayConnection = new Aspect_DisplayConnection();
+    }
+    catch (Standard_Failure)
+    {
+      std::cout << "Cannot open display. Interpret commands in batch mode." << std::endl;
+      return Standard_False;      
+    }
   }
-  if (Draw_WindowDisplay == NULL) {
-    cout << "Cannot open display : "<<XDisplayName(NULL)<<endl;
-    cout << "Interpret commands in batch mode."<<endl;
-    return Standard_False;
+  if (Draw_WindowDisplay == NULL)
+  {
+    Draw_WindowDisplay = Draw_DisplayConnection->GetDisplay();
   }
   //
   // synchronize the display server : could be done within Tk_Init
@@ -2072,7 +2094,11 @@ static DWORD WINAPI tkLoop(VOID)
       Standard_Integer res = Tk_Init (interp);
       if (res != TCL_OK)
       {
+#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5)))
+        cout << "tkLoop: error in Tk initialization. Tcl reported: " << Tcl_GetStringResult(interp) << endl;
+#else
         cout << "tkLoop: error in Tk initialization. Tcl reported: " << interp->result << endl;
+#endif
       }
     }
     catch (Standard_Failure)
@@ -2083,7 +2109,11 @@ static DWORD WINAPI tkLoop(VOID)
     mainWindow = Tk_MainWindow (interp);
     if (mainWindow == NULL)
     {
+#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5)))
+      fprintf (stderr, "%s\n", Tcl_GetStringResult(interp));
+#else
       fprintf (stderr, "%s\n", interp->result);
+#endif
       cout << "tkLoop: Tk_MainWindow() returned NULL. Exiting...\n";
       Tcl_Exit (0);
     }