]> OCCT Git - occt.git/commitdiff
0025267: Implementation of callback before DRAW exit
authorpdn <pdn@opencascade.com>
Thu, 9 Oct 2014 09:42:09 +0000 (13:42 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 9 Oct 2014 09:43:24 +0000 (13:43 +0400)
Callback mechanism implemented.

Do the same treatment at DRAW exit on UNIX

Add comments to the new methods

Change callback type to be a function pointer

src/Draw/Draw_Window.cxx
src/Draw/Draw_Window.hxx

index 7378ca4b308bf30b225712fe0f00b1a0d8911ee7..ddebf5a682062854bdc310e40a8b3f6c6aa16faa 100644 (file)
 
 #include <tcl.h>
 #include <Draw_Interpretor.hxx>
+#include <Draw_Window.hxx>
 #include <Draw_Appli.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <Image_AlienPixMap.hxx>
+#include <NCollection_List.hxx>
 
 extern Draw_Interpretor theCommands;
 extern Standard_Boolean Draw_VirtualWindows;
 static Tcl_Interp *interp;        /* Interpreter for this application. */
+static NCollection_List<Draw_Window::FCallbackBeforeTerminate> MyCallbacks;
+
+void Draw_Window::AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB)
+{
+  MyCallbacks.Append(theCB);
+}
+
+void Draw_Window::RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB)
+{
+  NCollection_List<Draw_Window::FCallbackBeforeTerminate>::Iterator Iter(MyCallbacks);
+  for(; Iter.More(); Iter.Next())
+  {
+    if (Iter.Value() == theCB)
+    {
+      MyCallbacks.Remove(Iter);
+      break;
+    }
+  }
+}
 
 /*
  *----------------------------------------------------------------------
@@ -1041,6 +1062,11 @@ void Run_Appli(Standard_Boolean (*interprete) (const char*))
     }
 
 #endif
+  NCollection_List<Draw_Window::FCallbackBeforeTerminate>::Iterator Iter(MyCallbacks);
+  for(; Iter.More(); Iter.Next())
+  {
+      (*Iter.Value())();
+  }
 }
 
 //======================================================
@@ -2023,6 +2049,11 @@ static DWORD WINAPI readStdinThreadFunc(VOID)
 \*--------------------------------------------------------*/
 void exitProc(ClientData /*dc*/)
 {
+  NCollection_List<Draw_Window::FCallbackBeforeTerminate>::Iterator Iter(MyCallbacks);
+  for(; Iter.More(); Iter.Next())
+  {
+      (*Iter.Value())();
+  }
   HANDLE proc = GetCurrentProcess();
   TerminateProcess(proc, 0);
 }
index 2cba926b94a0cf037fe8cf11607c53627c99d1cd..41d4920ea6c9c9e0f1ced6651cd24ebf7c983302 100644 (file)
@@ -62,9 +62,27 @@ typedef struct Event
 //====================================
 class Draw_Window
 {
-
   public :
 
+    /**
+     * Type of the callback function that is to be passed to the method
+     * AddCallbackBeforeTerminate().
+     */
+    typedef void (*FCallbackBeforeTerminate)();
+
+    /**
+     * This method registers a callback function that will be called just before exit.
+     * This is usefull especially for Windows platform, on which Draw is normally 
+     * self-terminated instead of exiting.
+     */
+    Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
+
+    /**
+     * Just in case method for un-registering a callback previously registered by
+     * AddCallbackBeforeTerminate()
+     */
+    Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
+
     Draw_Window (); // the window is not initialized
     Draw_Window (const char* title,
                 Standard_Integer X, Standard_Integer Y = 0,
@@ -218,6 +236,25 @@ class Draw_Window
 {
   public :
 
+  /**
+   * Type of the callback function that is to be passed to the method
+   * AddCallbackBeforeTerminate().
+   */
+  typedef void (*FCallbackBeforeTerminate)();
+
+  /**
+   * This method registers a callback function that will be called just before exit.
+   * This is usefull especially for Windows platform, on which Draw is normally 
+   * self-terminated instead of exiting.
+   */
+  Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
+
+  /**
+   * Just in case method for un-registering a callback previously registered by
+   * AddCallbackBeforeTerminate()
+   */
+  Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
+
   Draw_Window (); // the window is not initialized
   Draw_Window (Standard_CString        theTitle,
                const Standard_Integer& theXLeft = 0,  const Standard_Integer& theYTop   = 0,
@@ -359,6 +396,26 @@ class DrawWindow
 {
   //constructeur
 public:
+
+  /**
+   * Type of the callback function that is to be passed to the method
+   * AddCallbackBeforeTerminate().
+   */
+  typedef void (*FCallbackBeforeTerminate)();
+
+  /**
+   * This method registers a callback function that will be called just before exit.
+   * This is usefull especially for Windows platform, on which Draw is normally 
+   * self-terminated instead of exiting.
+   */
+  Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
+
+  /**
+   * Just in case method for un-registering a callback previously registered by
+   * AddCallbackBeforeTerminate()
+   */
+  Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
+
   __Draw_API DrawWindow();
   __Draw_API DrawWindow(char*, Standard_Integer, Standard_Integer,
                        Standard_Integer, Standard_Integer);