1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0025267: Implementation of callback before DRAW exit

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
This commit is contained in:
pdn 2014-10-09 13:42:09 +04:00 committed by bugmaster
parent 50b830a09b
commit a0fc422a3a
2 changed files with 89 additions and 1 deletions

View File

@ -23,13 +23,34 @@
#include <tcl.h> #include <tcl.h>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <Draw_Window.hxx>
#include <Draw_Appli.hxx> #include <Draw_Appli.hxx>
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
#include <Image_AlienPixMap.hxx> #include <Image_AlienPixMap.hxx>
#include <NCollection_List.hxx>
extern Draw_Interpretor theCommands; extern Draw_Interpretor theCommands;
extern Standard_Boolean Draw_VirtualWindows; extern Standard_Boolean Draw_VirtualWindows;
static Tcl_Interp *interp; /* Interpreter for this application. */ 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 #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*/) void exitProc(ClientData /*dc*/)
{ {
NCollection_List<Draw_Window::FCallbackBeforeTerminate>::Iterator Iter(MyCallbacks);
for(; Iter.More(); Iter.Next())
{
(*Iter.Value())();
}
HANDLE proc = GetCurrentProcess(); HANDLE proc = GetCurrentProcess();
TerminateProcess(proc, 0); TerminateProcess(proc, 0);
} }

View File

@ -62,9 +62,27 @@ typedef struct Event
//==================================== //====================================
class Draw_Window class Draw_Window
{ {
public : 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 (); // the window is not initialized
Draw_Window (const char* title, Draw_Window (const char* title,
Standard_Integer X, Standard_Integer Y = 0, Standard_Integer X, Standard_Integer Y = 0,
@ -218,6 +236,25 @@ class Draw_Window
{ {
public : 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 (); // the window is not initialized
Draw_Window (Standard_CString theTitle, Draw_Window (Standard_CString theTitle,
const Standard_Integer& theXLeft = 0, const Standard_Integer& theYTop = 0, const Standard_Integer& theXLeft = 0, const Standard_Integer& theYTop = 0,
@ -359,6 +396,26 @@ class DrawWindow
{ {
//constructeur //constructeur
public: 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();
__Draw_API DrawWindow(char*, Standard_Integer, Standard_Integer, __Draw_API DrawWindow(char*, Standard_Integer, Standard_Integer,
Standard_Integer, Standard_Integer); Standard_Integer, Standard_Integer);