//
// This file is part of Open CASCADE Technology software library.
//
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
// commercial license or contractual agreement.
// include windows.h first to have all definitions available
-#ifdef WNT
+#ifdef _WIN32
#include <windows.h>
#endif
#include <tcl.h>
#include <Draw_Interpretor.hxx>
+#include <Draw_Window.hxx>
#include <Draw_Appli.hxx>
#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.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;
+ }
+ }
+}
/*
*----------------------------------------------------------------------
#if !defined(_WIN32) && !defined(__WIN32__)
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <OSD_Timer.hxx>
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-
-#ifdef HAVE_SYS_FILIO_H
-#include <sys/filio.h>
-#else
-#include <sys/ioctl.h>
-#endif
-
-#include <fcntl.h>
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
#include <Draw_Window.hxx>
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <stdio.h>
+#include <unistd.h>
#if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
// use forward declaration for small subset of used Tk functions
* terminal-like device. Zero means it's
* a file. */
-static unsigned long thePixels[MAXCOLOR];
-
Standard_Integer Draw_WindowScreen = 0;
Standard_Boolean Draw_BlackBackGround = Standard_True;
#include <X11/Xutil.h>
#include <Aspect_DisplayConnection.hxx>
+static unsigned long thePixels[MAXCOLOR];
+
Display* Draw_WindowDisplay = NULL;
Colormap Draw_WindowColorMap;
static Handle(Aspect_DisplayConnection) Draw_DisplayConnection;
//function : SetTitle
//purpose :
//=======================================================================
-void Draw_Window::SetTitle(const char* title)
+void Draw_Window::SetTitle(const TCollection_AsciiString& theTitle)
{
- XStoreName(Draw_WindowDisplay, win, title);
+ XStoreName (Draw_WindowDisplay, win, theTitle.ToCString());
}
//=======================================================================
//function : GetTitle
//purpose :
//=======================================================================
-char* Draw_Window::GetTitle()
+TCollection_AsciiString Draw_Window::GetTitle() const
{
- char* title;
- XFetchName(Draw_WindowDisplay, win, &title);
- return title;
+ char* aTitle = NULL;
+ XFetchName (Draw_WindowDisplay, win, &aTitle);
+ return TCollection_AsciiString (aTitle);
}
//=======================================================================
}
#endif
+ NCollection_List<Draw_Window::FCallbackBeforeTerminate>::Iterator Iter(MyCallbacks);
+ for(; Iter.More(); Iter.Next())
+ {
+ (*Iter.Value())();
+ }
}
//======================================================
HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
{
if (Draw_IsConsoleSubsystem) {
- HWND aWin = CreateWindow (DRAWCLASS, DRAWTITLE,
+ HWND aWin = CreateWindowW (DRAWCLASS, DRAWTITLE,
WS_OVERLAPPEDWINDOW,
1,1,1,1,
NULL, NULL,::GetModuleHandle(NULL), NULL);
return aWin;
}
else {
- HANDLE hInstance;
- hInstance = (HANDLE)GetWindowLongPtr(hWndClient,GWLP_HINSTANCE);
+ HANDLE hInstance = (HANDLE )GetWindowLongPtrW (hWndClient, GWLP_HINSTANCE);
- return CreateMDIWindow(DRAWCLASS, DRAWTITLE,
+ return CreateMDIWindowW(DRAWCLASS, DRAWTITLE,
WS_CAPTION | WS_CHILD | WS_THICKFRAME,
1,1,0,0,
hWndClient, (HINSTANCE)hInstance, nitem);
\*--------------------------------------------------------*/
LRESULT APIENTRY DrawWindow::DrawProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
{
- DrawWindow* localObjet = (DrawWindow*)GetWindowLongPtr(hWnd, CLIENTWND);
+ DrawWindow* localObjet = (DrawWindow* )GetWindowLongPtrW (hWnd, CLIENTWND);
if (!localObjet)
+ {
+ return Draw_IsConsoleSubsystem
+ ? DefWindowProcW (hWnd, wMsg, wParam, lParam)
+ : DefMDIChildProcW (hWnd, wMsg, wParam, lParam);
+ }
+
+ switch (wMsg)
+ {
+ case WM_PAINT:
{
- if (Draw_IsConsoleSubsystem)
- return (DefWindowProc(hWnd, wMsg, wParam, lParam));
+ PAINTSTRUCT ps;
+ BeginPaint (hWnd, &ps);
+ if (localObjet->GetUseBuffer())
+ {
+ localObjet->Redraw();
+ }
else
- return(DefMDIChildProc(hWnd, wMsg, wParam, lParam));
+ {
+ localObjet->WExpose();
+ }
+ EndPaint (hWnd, &ps);
+ return 0;
}
-
- PAINTSTRUCT ps;
-
- switch(wMsg)
- {
- case WM_PAINT :
- BeginPaint(hWnd, &ps);
- if (localObjet->GetUseBuffer())
- localObjet->Redraw();
- else
- localObjet->WExpose();
- EndPaint(hWnd, &ps);
- return 0l;
- break;
-
- case WM_SIZE:
- if (localObjet->GetUseBuffer()) {
- localObjet->InitBuffer();
- localObjet->WExpose();
- localObjet->Redraw();
- return 0l;
+ case WM_SIZE:
+ {
+ if (localObjet->GetUseBuffer())
+ {
+ localObjet->InitBuffer();
+ localObjet->WExpose();
+ localObjet->Redraw();
+ return 0;
+ }
+ break;
}
-
- default:
- if (Draw_IsConsoleSubsystem)
- return (DefWindowProc(hWnd, wMsg, wParam, lParam));
- else
- return(DefMDIChildProc(hWnd, wMsg, wParam, lParam));
}
+ return Draw_IsConsoleSubsystem
+ ? DefWindowProcW (hWnd, wMsg, wParam, lParam)
+ : DefMDIChildProcW (hWnd, wMsg, wParam, lParam);
}
}
//________________________
-DrawWindow::DrawWindow(char* title,
+DrawWindow::DrawWindow(const char* title,
Standard_Integer X, Standard_Integer Y,
Standard_Integer dX,Standard_Integer dY) :
win(0), next(firstWindow), previous(NULL), myMemHbm(NULL), myUseBuffer(Standard_False)
Init(X, Y, dX, dY);
SetTitle(title);
}
-DrawWindow::DrawWindow(char* title,
+DrawWindow::DrawWindow(const char* title,
Standard_Integer X, Standard_Integer Y,
Standard_Integer dX,Standard_Integer dY,
HWND theWin) :
// include decorations in the window dimensions
// to reproduce same behaviour of Xlib window.
- DWORD aWinStyle = GetWindowLong (win, GWL_STYLE);
- DWORD aWinStyleEx = GetWindowLong (win, GWL_EXSTYLE);
+ DWORD aWinStyle = GetWindowLongW (win, GWL_STYLE);
+ DWORD aWinStyleEx = GetWindowLongW (win, GWL_EXSTYLE);
HMENU aMenu = GetMenu (win);
RECT aRect;
SetPosition (aRect.left, aRect.top);
SetDimension (aRect.right - aRect.left, aRect.bottom - aRect.top);
// Save the pointer at the instance associated to the window
- SetWindowLongPtr(win, CLIENTWND, (LONG_PTR)this);
+ SetWindowLongPtrW (win, CLIENTWND, (LONG_PTR)this);
HDC hDC = GetDC(win);
SetBkColor(hDC, RGB(0, 0, 0));
myCurrPen = 3;
/*--------------------------------------------------------*\
| SetTitle
\*--------------------------------------------------------*/
-void DrawWindow::SetTitle(char* title)
+void DrawWindow::SetTitle (const TCollection_AsciiString& theTitle)
{
- SetWindowText(win, title);
+ const TCollection_ExtendedString aTitleW (theTitle);
+ SetWindowTextW (win, aTitleW.ToWideString());
}
/*--------------------------------------------------------*\
| GetTitle
-| Attention do not forget to unallocate the memory
\*--------------------------------------------------------*/
-char* DrawWindow::GetTitle()
+TCollection_AsciiString DrawWindow::GetTitle() const
{
- char* title=new char[31];
- GetWindowText(win, title, 30);
- return title;
+ wchar_t aTitleW[32];
+ GetWindowTextW (win, aTitleW, 30);
+ return TCollection_AsciiString (aTitleW);
}
HDC hDC = GetDC(win);
HDC aWorkDC = myUseBuffer ? GetMemDC(hDC) : hDC;
- TextOut(aWorkDC, x, y, text, (int )strlen(text));
+ TCollection_ExtendedString textW (text);
+ TextOutW(aWorkDC, x, y, (const wchar_t*)textW.ToExtString(), (int )strlen(text));
if (myUseBuffer) ReleaseMemDC(aWorkDC);
ReleaseDC(win,hDC);
//* threads sinchronization *//
DWORD dwMainThreadId;
console_semaphore_value volatile console_semaphore = WAIT_CONSOLE_COMMAND;
-//char console_command[1000];
-#define COMMAND_SIZE 1000 /* Console Command size */
-char console_command[COMMAND_SIZE];
+#define THE_COMMAND_SIZE 1000 /* Console Command size */
+wchar_t console_command[THE_COMMAND_SIZE];
bool volatile isTkLoopStarted = false;
/*--------------------------------------------------------*\
/*--------------------------------------------------------*\
| readStdinThreadFunc
\*--------------------------------------------------------*/
-static DWORD WINAPI readStdinThreadFunc(VOID)
+static DWORD WINAPI readStdinThreadFunc()
{
- if (!Draw_IsConsoleSubsystem) return 1;
- for(;;) {
+ if (!Draw_IsConsoleSubsystem)
+ {
+ return 1;
+ }
+
+ // set console locale
+ //setlocale (LC_ALL, ".OCP");
+ for (;;)
+ {
while (console_semaphore != WAIT_CONSOLE_COMMAND)
- Sleep(100);
- if (fgets(console_command,COMMAND_SIZE,stdin))
+ {
+ Sleep (100);
+ }
+
+ DWORD aNbRead = 0;
+ if (ReadConsoleW (GetStdHandle(STD_INPUT_HANDLE), console_command, THE_COMMAND_SIZE, &aNbRead, NULL))
+ //if (fgetws (console_command, THE_COMMAND_SIZE, stdin)) // fgetws() works only for characters within active locale (see setlocale())
+ {
+ console_command[aNbRead] = L'\0';
+ // tcl will skip newline symbols - no need to strip them here
+ /*--aNbRead;
+ for (; aNbRead >= 0; --aNbRead)
{
- console_semaphore = HAS_CONSOLE_COMMAND;
- }
+ if (console_command[aNbRead] == L'\r'
+ || console_command[aNbRead] == L'\n')
+ {
+ console_command[aNbRead] = '\0';
+ continue;
+ }
+ break;
+ }*/
+ console_semaphore = HAS_CONSOLE_COMMAND;
+ }
}
}
\*--------------------------------------------------------*/
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);
}
{
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));
- Tcl_RegisterChannel(theCommands.Interp(), Tcl_GetStdChannel(TCL_STDERR));
+ {
+ Tcl_Channel aChannelIn = Tcl_GetStdChannel (TCL_STDIN);
+ Tcl_Channel aChannelOut = Tcl_GetStdChannel (TCL_STDOUT);
+ Tcl_Channel aChannelErr = Tcl_GetStdChannel (TCL_STDERR);
+ if (aChannelIn != NULL)
+ {
+ Tcl_RegisterChannel (theCommands.Interp(), aChannelIn);
+ }
+ if (aChannelOut != NULL)
+ {
+ Tcl_RegisterChannel (theCommands.Interp(), aChannelOut);
+ }
+ if (aChannelErr != NULL)
+ {
+ Tcl_RegisterChannel (theCommands.Interp(), aChannelErr);
+ }
+ }
#endif
#ifdef _TK
#endif //#ifdef _TK
// set signal handler in the new thread
- OSD::SetSignal();
+ OSD::SetSignal(Standard_False);
// inform the others that we have started
isTkLoopStarted = true;
while(Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT));
if (console_semaphore == HAS_CONSOLE_COMMAND)
{
- if (Draw_Interprete (console_command))
+ TCollection_AsciiString aCmdUtf8 (console_command);
+ if (Draw_Interprete (aCmdUtf8.ToCString()))
{
if (Draw_IsConsoleSubsystem) Prompt (interp, 0);
}
if (!hThread) {
cout << "pb in creation of the thread reading stdin" << endl;
Draw_IsConsoleSubsystem = Standard_False;
- Init_Appli(GetModuleHandle(NULL),
- GetModuleHandle(NULL),
- 1, hWnd); // reinit => create MDI client wnd
+ Init_Appli (GetModuleHandleW (NULL),
+ GetModuleHandleW (NULL),
+ 1, hWnd); // reinit => create MDI client wnd
}
}
console_semaphore = WAIT_CONSOLE_COMMAND;
//simple Win32 message loop
- while (GetMessage(&msg, NULL, 0, 0) > 0)
+ while (GetMessageW (&msg, NULL, 0, 0) > 0)
{
- if (!TranslateAccelerator(hWnd, hAccel, &msg))
+ if (!TranslateAcceleratorW (hWnd, hAccel, &msg))
{
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ TranslateMessage (&msg);
+ DispatchMessageW (&msg);
}
}
ExitProcess(0);
msg.wParam = 1;
- GetMessage(&msg,NULL,0,0);
+ GetMessageW (&msg, NULL, 0, 0);
while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN) ||
! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd)) )
- GetMessage(&msg,NULL,0,0);
+ {
+ GetMessageW (&msg, NULL, 0, 0);
+ }
hWnd = msg.hwnd;
x = LOWORD(msg.lParam);
msg.wParam = 1;
- GetMessage(&msg,NULL,0,0);
+ GetMessageW (&msg,NULL,0,0);
while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN &&
msg.message != WM_MOUSEMOVE) ||
! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd) ) )
- GetMessage(&msg,NULL,0,0);
+ {
+ GetMessageW(&msg,NULL,0,0);
+ }
hWnd = msg.hwnd;
x = LOWORD(msg.lParam);
y = HIWORD(msg.lParam);