1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

0028110: Configuration - specify Unicode charset instead of multibyte in project files for Visual Studio

Eliminated usage of ANSI methods.
All Visual Studio projects generated by genproj or CMake use Unicode character set.

Draw Harness now handles Unicode input on Windows.
Tcl test scripts are now expected in UTF-8 encoding by default.
This commit is contained in:
ski 2016-11-14 14:31:00 +03:00 committed by apn
parent 0a40a30da5
commit ad03c23449
27 changed files with 728 additions and 755 deletions

View File

@ -37,6 +37,11 @@ endif()
# the name of the project # the name of the project
project (OCCT) project (OCCT)
if (WIN32)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)
endif()
# include occt macros # include occt macros
OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros") OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros")

View File

@ -1154,7 +1154,7 @@ proc osutils:vcproj:readtemplate {theVcVer isexec} {
set aVerExt "v${aVerExt}0" set aVerExt "v${aVerExt}0"
set aCmpl32 "" set aCmpl32 ""
set aCmpl64 "" set aCmpl64 ""
set aCharSet "MultiByte" set aCharSet "Unicode"
if { $isexec } { if { $isexec } {
set anExt "${anExt}x" set anExt "${anExt}x"
set what "$what executable" set what "$what executable"
@ -1175,7 +1175,6 @@ proc osutils:vcproj:readtemplate {theVcVer isexec} {
} }
set aCmpl${bitness} "[set aCmpl${bitness}]${indent}${UwpWinRt}" set aCmpl${bitness} "[set aCmpl${bitness}]${indent}${UwpWinRt}"
} }
set aCharSet "Unicode"
} }
foreach bitness {32 64} { foreach bitness {32 64} {

View File

@ -17,12 +17,12 @@
#ifdef _WIN32 #ifdef _WIN32
#define COMMANDCLASS "COMMANDWINDOW" #define COMMANDCLASS L"COMMANDWINDOW"
#define COMMANDTITLE "Command Window" #define COMMANDTITLE L"Command Window"
HWND CreateCommandWindow(HWND, int); HWND CreateCommandWindow(HWND, int);
LONG APIENTRY CommandProc(HWND, UINT, WPARAM, LONG); LRESULT APIENTRY CommandProc(HWND, UINT, WPARAM, LPARAM);
BOOL CommandCreateProc(HWND); BOOL CommandCreateProc(HWND);
VOID CommandDestroyProc(HWND); VOID CommandDestroyProc(HWND);
BOOL CommandHandler(HWND, WPARAM, LPARAM); BOOL CommandHandler(HWND, WPARAM, LPARAM);

View File

@ -17,50 +17,36 @@
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#define COMMANDCLASS "COMMANDWINDOW"
#define COMMANDTITLE "Command Window"
#include <CommandWindow.h> #include <CommandWindow.h>
#include <Draw_Window.hxx> #include <Draw_Window.hxx>
#include <MainWindow.h> #include <MainWindow.h>
#include <Draw_Appli.hxx> #include <Draw_Appli.hxx>
#include <TCollection_AsciiString.hxx>
/****************************************************\
* CommandWindow.cxx :
*
\****************************************************/
#define CLIENTWND 0 #define CLIENTWND 0
#define PROMPT "Command >> " #define THE_PROMPT L"Command >> "
#define COMMANDSIZE 1000 // Max nb of characters for a command #define COMMANDSIZE 1000 // Max nb of characters for a command
Standard_Boolean Draw_Interprete (const char* command);
// Definition of global variables namespace
#ifdef STRICT {
WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class) // Definition of global variables
#else static WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class)
FARPROC OldEditProc; }
#endif
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| CREATE COMMAND WINDOW PROCEDURE | CREATE COMMAND WINDOW PROCEDURE
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
HWND CreateCommandWindow(HWND hWnd, int /*nitem*/) HWND CreateCommandWindow(HWND hWnd, int /*nitem*/)
{ {
HINSTANCE hInstance; HINSTANCE hInstance = (HINSTANCE )GetWindowLongPtrW (hWnd, GWLP_HINSTANCE);
hInstance = (HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE);
HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE, HWND hWndCommand = CreateWindowW (COMMANDCLASS, COMMANDTITLE,
WS_CLIPCHILDREN | WS_OVERLAPPED | WS_CLIPCHILDREN | WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION,
WS_THICKFRAME | WS_CAPTION , 0, 0, 400, 100,
0, 0, hWnd, NULL, hInstance, NULL);
400, 100,
hWnd, NULL, hInstance, NULL));
ShowWindow(hWndCommand, SW_SHOW); ShowWindow(hWndCommand, SW_SHOW);
return hWndCommand; return hWndCommand;
@ -72,185 +58,180 @@ HWND CreateCommandWindow(HWND hWnd, int /*nitem*/)
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
{ {
HWND hWndEdit; switch (wMsg)
MINMAXINFO* lpmmi;
switch(wMsg)
{ {
case WM_CREATE : case WM_CREATE:
CommandCreateProc(hWnd); {
hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND); CommandCreateProc (hWnd);
SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT); HWND hWndEdit = (HWND )GetWindowLongPtrW (hWnd, CLIENTWND);
break; SendMessageW (hWndEdit, EM_REPLACESEL, 0, (LPARAM )THE_PROMPT);
return 0;
case WM_GETMINMAXINFO : }
lpmmi = (LPMINMAXINFO)lParam; case WM_GETMINMAXINFO:
{
MINMAXINFO* lpmmi = (MINMAXINFO* )lParam;
lpmmi->ptMinTrackSize.x = 200; lpmmi->ptMinTrackSize.x = 200;
lpmmi->ptMinTrackSize.y = 50; lpmmi->ptMinTrackSize.y = 50;
break; return 0;
}
case WM_SIZE : case WM_SIZE:
{ {
hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND); HWND hWndEdit = (HWND )GetWindowLongPtrW(hWnd, CLIENTWND);
MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); MoveWindow (hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
// Place the cursor at the end of the buffer // Place the cursor at the end of the buffer
// Nb of characters in the buffer of hWndEdit // Nb of characters in the buffer of hWndEdit
LRESULT index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l); LRESULT index = SendMessageW (hWnd, WM_GETTEXTLENGTH, 0l, 0l);
SendMessage(hWnd, EM_SETSEL, index, index); SendMessageW (hWnd, EM_SETSEL, index, index);
break; return 0;
} }
case WM_SETFOCUS:
case WM_SETFOCUS : {
hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND); HWND hWndEdit = (HWND )GetWindowLongPtrW (hWnd, CLIENTWND);
SetFocus(hWndEdit); SetFocus (hWndEdit);
break; return 0;
default :
return(DefWindowProc(hWnd, wMsg, wParam, lParam));
} }
return(0l); }
return DefWindowProcW(hWnd, wMsg, wParam, lParam);
} }
LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM); LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| COMMAND CREATE PROCEDURE | COMMAND CREATE PROCEDURE
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
BOOL CommandCreateProc(HWND hWnd) BOOL CommandCreateProc(HWND hWnd)
{ {
HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE);
HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); HWND hWndEdit = CreateWindowW (L"EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
HWND hWndEdit = CreateWindow("EDIT",NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
0, 0, 0, 0, 0, 0, 0, 0,
hWnd, 0, hWnd, 0,
hInstance, NULL); hInstance, NULL);
// Save hWndEdit in the extra memory in 0 of CommandWindow // Save hWndEdit in the extra memory in 0 of CommandWindow
if (hWndEdit) if (hWndEdit != NULL)
SetWindowLongPtr(hWnd, CLIENTWND, (LONG_PTR)hWndEdit); {
SetWindowLongPtrW (hWnd, CLIENTWND, (LONG_PTR )hWndEdit);
}
// Sub-Class of the window // Sub-Class of the window
//------- //-------
// Save the pointer on the existing procedure // Save the pointer on the existing procedure
#ifdef STRICT OldEditProc = (WNDPROC )GetWindowLongPtrW (hWndEdit, GWLP_WNDPROC);
OldEditProc = (WNDPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC);
#else
OldEditProc = (FARPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC);
#endif
// Implement the new function // Implement the new function
SetWindowLongPtr(hWndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc); SetWindowLongPtrW (hWndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc);
return TRUE;
return(TRUE);
} }
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| GET COMMAND | GET COMMAND
| |
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
int GetCommand(HWND hWnd, char* buffer) int GetCommand (HWND hWnd, wchar_t* theBuffer)
{ {
int again = 1; bool isAgain = true;
char temp[COMMANDSIZE]=""; wchar_t aTempBuff[COMMANDSIZE] = L"";
int nbLine = (int )SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l); int aNbLine = (int )SendMessageW (hWnd, EM_GETLINECOUNT, 0l, 0l);
int aNbChar = 0;
int nbChar = 0; theBuffer[0] = L'\0';
buffer[0]='\0'; while (isAgain && aNbLine > -1 && aNbChar < COMMANDSIZE - 1)
while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1)
{ {
strcat(buffer, strrev(temp)); wcscat (theBuffer, _wcsrev (aTempBuff));
// Initialization of the 1st WORD to the nb of characters to read // Initialization of the 1st WORD to the nb of characters to read
WORD* nbMaxChar = (WORD*)temp; WORD* aNbMaxChar = (WORD* )aTempBuff;
*nbMaxChar = COMMANDSIZE-1; *aNbMaxChar = COMMANDSIZE - 1;
int nbCharRead = (int )SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp); const int aNbCharRead = (int )SendMessageW (hWnd, EM_GETLINE, aNbLine - 1, (LPARAM )aTempBuff);
nbChar += nbCharRead ; aNbChar += aNbCharRead;
int cmp = strncmp(temp, PROMPT, 10); const bool isPromp = wcsncmp (aTempBuff, THE_PROMPT, 10) == 0;
temp[nbCharRead]='\0'; aTempBuff[aNbCharRead]='\0';
if( cmp == 0 ) if (isPromp)
{ {
strcat(buffer, strrev(temp)); wcscat (theBuffer, _wcsrev (aTempBuff));
again = 0; isAgain = false;
} }
nbLine -= 1; aNbLine -= 1;
} }
strrev(buffer); _wcsrev (theBuffer);
return nbChar; return aNbChar;
} }
extern console_semaphore_value volatile console_semaphore; extern console_semaphore_value volatile console_semaphore;
extern char console_command[1000]; extern wchar_t console_command[1000];
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| EDIT WINDOW PROCEDURE | EDIT WINDOW PROCEDURE
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
LRESULT APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) LRESULT APIENTRY EditProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
{ {
char buffer[COMMANDSIZE];
POINT pos;
BOOL rep = 0;
static LRESULT nbline; // Process the buffer of the edit window static LRESULT nbline; // Process the buffer of the edit window
LRESULT index; switch (wMsg)
{
switch(wMsg) case WM_CHAR:
{ {
case WM_CHAR :
if (console_semaphore != WAIT_CONSOLE_COMMAND) if (console_semaphore != WAIT_CONSOLE_COMMAND)
return 0l; {
switch(LOWORD(wParam)) return 0;
}
switch (LOWORD(wParam))
{ {
// Overload of character \n // Overload of character \n
case 0x0d : case 0x0d:
GetCommand(hWnd, buffer); {
wchar_t aCmdBuffer[COMMANDSIZE];
GetCommand (hWnd, aCmdBuffer);
// Standard processing // Standard processing
CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam); CallWindowProcW (OldEditProc, hWnd, wMsg, wParam, lParam);
// Display of PROMPT // Display of PROMPT
rep = GetCaretPos(&pos); POINT pos;
SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT); GetCaretPos (&pos);
SendMessageW (hWnd, EM_REPLACESEL, 0, (LPARAM )THE_PROMPT);
// Display the command in the console // Display the command in the console
cout << buffer << endl; std::wcout << aCmdBuffer << std::endl;
/*if (Draw_Interprete(buffer+strlen(PROMPT))== -2) //TCollection_AsciiString aCmdUtf8 (aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1);
DestroyProc(hWnd); */ //Draw_Interprete (aCmdUtf8.ToCString());
strcpy(console_command, buffer+strlen(PROMPT)); //if (toExit) { DestroyProc (hWnd); }
wcscpy (console_command, aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1);
console_semaphore = HAS_CONSOLE_COMMAND; console_semaphore = HAS_CONSOLE_COMMAND;
// Purge the buffer // Purge the buffer
nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l); nbline = SendMessageW (hWnd, EM_GETLINECOUNT, 0l, 0l);
if(nbline > 200) if (nbline > 200)
{ {
nbline = 0; nbline = 0;
GetCommand(hWnd, buffer); GetCommand (hWnd, aCmdBuffer);
index = SendMessage(hWnd, EM_LINEINDEX, 100, 0); LRESULT index = SendMessageW (hWnd, EM_LINEINDEX, 100, 0);
SendMessage(hWnd, EM_SETSEL, 0, index); SendMessageW (hWnd, EM_SETSEL, 0, index);
SendMessage(hWnd, WM_CUT, 0, 0); SendMessageW (hWnd, WM_CUT, 0, 0);
// Place the cursor at the end of text // Place the cursor at the end of text
index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l); index = SendMessageW (hWnd, WM_GETTEXTLENGTH, 0l, 0l);
SendMessage(hWnd, EM_SETSEL, index, index); SendMessageW (hWnd, EM_SETSEL, index, index);
} }
return(0l); return 0;
break; }
default : default:
if (IsAlphanumeric((Standard_Character)LOWORD(wParam))) {
if (IsAlphanumeric ((Standard_Character)LOWORD(wParam)))
{ {
// Place the cursor at the end of text before display // Place the cursor at the end of text before display
index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l); LRESULT index = SendMessageW (hWnd, WM_GETTEXTLENGTH, 0l, 0l);
SendMessage(hWnd, EM_SETSEL, index, index); SendMessageW (hWnd, EM_SETSEL, index, index);
CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam); CallWindowProcW (OldEditProc, hWnd, wMsg, wParam, lParam);
return 0l; return 0;
} }
break; break;
} }
}
break; break;
}
case WM_KEYDOWN: case WM_KEYDOWN:
{
if (console_semaphore != WAIT_CONSOLE_COMMAND) if (console_semaphore != WAIT_CONSOLE_COMMAND)
return 0l; {
return 0;
} }
return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam); break;
}
}
return CallWindowProcW (OldEditProc, hWnd, wMsg, wParam, lParam);
} }
#endif #endif

View File

@ -78,30 +78,36 @@ Standard_EXPORT Standard_Boolean Draw_Interprete(const char* command);
// ******************************************************************* // *******************************************************************
#ifdef _WIN32 #ifdef _WIN32
extern console_semaphore_value volatile console_semaphore; extern console_semaphore_value volatile console_semaphore;
extern char console_command[1000]; extern wchar_t console_command[1000];
#endif #endif
static void ReadInitFile (const TCollection_AsciiString& theFileName) static void ReadInitFile (const TCollection_AsciiString& theFileName)
{ {
TCollection_AsciiString aPath = theFileName; TCollection_AsciiString aPath = theFileName;
#ifdef _WIN32 #ifdef _WIN32
if (!Draw_Batch) { if (!Draw_Batch)
try { {
try
{
aPath.ChangeAll ('\\', '/'); aPath.ChangeAll ('\\', '/');
{
Sprintf(console_command, "source \"%.980s\"", aPath.ToCString()); const TCollection_ExtendedString aCmdWide = TCollection_ExtendedString ("source -encoding utf-8 \"") + TCollection_ExtendedString (aPath) + "\"";
memcpy (console_command, aCmdWide.ToWideString(), Min (aCmdWide.Length() + 1, 980) * sizeof(wchar_t));
}
console_semaphore = HAS_CONSOLE_COMMAND; console_semaphore = HAS_CONSOLE_COMMAND;
while (console_semaphore == HAS_CONSOLE_COMMAND) while (console_semaphore == HAS_CONSOLE_COMMAND)
{
Sleep(10); Sleep(10);
} }
}
catch(...) { catch(...) {
cout << "Error while reading a script file." << endl; cout << "Error while reading a script file." << endl;
ExitProcess(0); ExitProcess(0);
} }
} else { } else {
#endif #endif
char* com = new char [aPath.Length() + strlen ("source ") + 2]; char* com = new char [aPath.Length() + strlen ("source -encoding utf-8 ") + 2];
Sprintf (com, "source %s", aPath.ToCString()); Sprintf (com, "source -encoding utf-8 %s", aPath.ToCString());
Draw_Interprete (com); Draw_Interprete (com);
delete [] com; delete [] com;
#ifdef _WIN32 #ifdef _WIN32
@ -140,32 +146,31 @@ void exitProc(ClientData /*dc*/)
// main // main
// ******************************************************************* // *******************************************************************
#ifdef _WIN32 #ifdef _WIN32
//Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lps Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, int nShow, int argc, wchar_t** argv, const FDraw_InitAppli Draw_InitAppli)
Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszLine, int nShow,const FDraw_InitAppli Draw_InitAppli)
#else #else
void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_InitAppli) void Draw_Appli(int argc, char** argv, const FDraw_InitAppli Draw_InitAppli)
#endif #endif
{ {
// prepend extra DLL search path to override system libraries like opengl32.dll // prepend extra DLL search path to override system libraries like opengl32.dll
#ifdef _WIN32 #ifdef _WIN32
OSD_Environment aUserDllEnv ("CSF_UserDllPath"); OSD_Environment aUserDllEnv ("CSF_UserDllPath");
TCollection_AsciiString aUserDllPath = aUserDllEnv.Value(); const TCollection_ExtendedString aUserDllPath (aUserDllEnv.Value());
if (!aUserDllPath.IsEmpty()) if (!aUserDllPath.IsEmpty())
{ {
// This function available since Win XP SP1 #if (_WIN32_WINNT >= 0x0502). // This function available since Win XP SP1 #if (_WIN32_WINNT >= 0x0502).
// We retrieve dynamically here (kernel32 should be always preloaded). // We retrieve dynamically here (kernel32 should be always preloaded).
typedef BOOL (WINAPI *SetDllDirectoryA_t)(const char* thePathName); typedef BOOL (WINAPI *SetDllDirectoryW_t)(const wchar_t* thePathName);
HMODULE aKern32Module = GetModuleHandleA ("kernel32"); HMODULE aKern32Module = GetModuleHandleW (L"kernel32");
SetDllDirectoryA_t aFunc = (aKern32Module != NULL) SetDllDirectoryW_t aFunc = (aKern32Module != NULL)
? (SetDllDirectoryA_t )GetProcAddress (aKern32Module, "SetDllDirectoryA") : NULL; ? (SetDllDirectoryW_t )GetProcAddress (aKern32Module, "SetDllDirectoryW") : NULL;
if (aFunc != NULL) if (aFunc != NULL)
{ {
aFunc (aUserDllPath.ToCString()); aFunc (aUserDllPath.ToWideString());
} }
else else
{ {
//std::cerr << "SetDllDirectoryA() is not available on this system!\n"; //std::cerr << "SetDllDirectoryW() is not available on this system!\n";
} }
if (aKern32Module != NULL) if (aKern32Module != NULL)
{ {
@ -179,64 +184,71 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
// ***************************************************************** // *****************************************************************
Draw_Batch = Standard_False; Draw_Batch = Standard_False;
TCollection_AsciiString aRunFile, aCommand; TCollection_AsciiString aRunFile, aCommand;
Standard_Integer i;
Standard_Boolean isInteractiveForced = Standard_False; Standard_Boolean isInteractiveForced = Standard_False;
#ifdef _WIN32
// On NT command line arguments are in the lpzline and not in argv
int argc = 0;
const int MAXARGS = 1024;
const char* argv[MAXARGS];
for (const char* p = strtok(lpszLine, " \t"); p != NULL; p = strtok(NULL, " \t")) {
argv[argc++] = p;
}
#endif
// parse command line // parse command line
for (i = 1; i < argc; i++) { for (int anArgIter = 1; anArgIter < argc; ++anArgIter)
if (strcasecmp (argv[i], "-h") == 0 || strcasecmp (argv[i], "--help") == 0)
{ {
cout << "Open CASCADE " << OCC_VERSION_STRING_EXT << " DRAW Test Harness" << endl << endl; TCollection_AsciiString anArg (argv[anArgIter]);
cout << "Options: " << endl; anArg.LowerCase();
cout << " -b: batch mode (no GUI, no viewers)" << endl; if (anArg == "-h"
cout << " -v: no GUI, use virtual (off-screen) windows for viewers" << endl; || anArg == "--help")
cout << " -i: interactive mode" << endl; {
cout << " -f file: execute script from file" << endl; std::cout << "Open CASCADE " << OCC_VERSION_STRING_EXT << " DRAW Test Harness\n\n";
cout << " -c command args...: execute command (with optional arguments)" << endl << endl; std::cout << "Options:\n";
cout << "Options -b, -v, and -i are mutually exclusive." << endl; std::cout << " -b: batch mode (no GUI, no viewers)\n";
cout << "If -c or -f are given, -v is default; otherwise default is -i." << endl; std::cout << " -v: no GUI, use virtual (off-screen) windows for viewers\n";
cout << "Options -c and -f are alternatives and should be at the end " << endl; std::cout << " -i: interactive mode\n";
cout << "of the command line. " << endl; std::cout << " -f file: execute script from file\n";
cout << "Option -c can accept set of commands separated by ';'." << endl; std::cout << " -c command args...: execute command (with optional arguments)\n\n";
std::cout << "Options -b, -v, and -i are mutually exclusive.\n";
std::cout << "If -c or -f are given, -v is default; otherwise default is -i.\n";
std::cout << "Options -c and -f are alternatives and should be at the end \n";
std::cout << "of the command line.\n";
std::cout << "Option -c can accept set of commands separated by ';'.\n";
return; return;
} }
else if (strcasecmp (argv[i], "-b") == 0) else if (anArg == "-b")
{
Draw_Batch = Standard_True; Draw_Batch = Standard_True;
else if (strcasecmp (argv[i], "-v") == 0) { }
else if (anArg == "-v")
{
// force virtual windows // force virtual windows
Draw_VirtualWindows = Standard_True; Draw_VirtualWindows = Standard_True;
} else if (strcasecmp (argv[i], "-i") == 0) { }
else if (anArg == "-i")
{
// force interactive // force interactive
Draw_VirtualWindows = Standard_False; Draw_VirtualWindows = Standard_False;
isInteractiveForced = Standard_True; isInteractiveForced = Standard_True;
} else if (strcasecmp (argv[i], "-f") == 0) { // -f option should be LAST! }
else if (anArg == "-f") // -f option should be LAST!
{
Draw_VirtualWindows = !isInteractiveForced; Draw_VirtualWindows = !isInteractiveForced;
if (++i < argc) { if (++anArgIter < argc)
aRunFile = TCollection_AsciiString (argv[i]); {
aRunFile = TCollection_AsciiString (argv[anArgIter]);
} }
break; break;
} else if (strcasecmp (argv[i], "-c") == 0) { // -c option should be LAST!
Draw_VirtualWindows = !isInteractiveForced;
if (++i < argc) {
aCommand = TCollection_AsciiString (argv[i]);
} }
while (++i < argc) { else if (anArg == "-c") // -c option should be LAST!
{
Draw_VirtualWindows = !isInteractiveForced;
if (++anArgIter < argc)
{
aCommand = TCollection_AsciiString (argv[anArgIter]);
}
while (++anArgIter < argc)
{
aCommand.AssignCat (" "); aCommand.AssignCat (" ");
aCommand.AssignCat (argv[i]); aCommand.AssignCat (argv[anArgIter]);
} }
break; break;
} else { }
cout << "Error: unsupported option " << argv[i] << endl; else
{
std::cout << "Error: unsupported option " << TCollection_AsciiString (argv[anArgIter]) << "\n";
} }
} }
@ -268,11 +280,15 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
cout << "DRAW is running in batch mode" << endl; cout << "DRAW is running in batch mode" << endl;
XLoop = !Draw_Batch; XLoop = !Draw_Batch;
if (XLoop) { if (XLoop)
{
// Default colors // Default colors
for (i=0;i<MAXCOLOR;i++) { for (int i = 0; i < MAXCOLOR; ++i)
if (!dout.DefineColor(i,ColorNames[i])) {
cout <<"Could not allocate default color "<<ColorNames[i]<<endl; if (!dout.DefineColor (i, ColorNames[i]))
{
std::cout <<"Could not allocate default color " << ColorNames[i] << std::endl;
}
} }
} }
@ -366,7 +382,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In
for (;;) for (;;)
{ {
cout << "Viewer>"; cout << "Viewer>";
i = -1; int i = -1;
do { do {
cin.get(cmd[++i]); cin.get(cmd[++i]);
} while ((cmd[i] != '\n') && (!cin.fail())); } while ((cmd[i] != '\n') && (!cin.fail()));
@ -396,7 +412,10 @@ Standard_Boolean Draw_Interprete(const char* com)
Tcl_DStringInit(&command); Tcl_DStringInit(&command);
} }
#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 1))) #ifdef _WIN32
// string is already converted into UTF-8
Tcl_DStringAppend(&command, com, -1);
#elif ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 1)))
// OCC63: Since Tcl 8.1 it uses UTF-8 encoding for internal representation of strings // OCC63: Since Tcl 8.1 it uses UTF-8 encoding for internal representation of strings
Tcl_ExternalToUtfDString ( NULL, com, -1, &command ); Tcl_ExternalToUtfDString ( NULL, com, -1, &command );
#else #else
@ -435,7 +454,14 @@ Standard_Boolean Draw_Interprete(const char* com)
dout.Flush(); dout.Flush();
if (*theCommands.Result()) if (*theCommands.Result())
cout << theCommands.Result() << endl; {
#ifdef _WIN32
const TCollection_ExtendedString aResWide (theCommands.Result());
std::wcout << aResWide.ToWideString() << std::endl;
#else
std::cout << theCommands.Result() << std::endl;
#endif
}
if (Draw_Chrono && hadchrono) { if (Draw_Chrono && hadchrono) {
tictac.Stop(); tictac.Stop();

View File

@ -14,16 +14,9 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
// JR 21 Oct 1999 : Change for Draw_Init_Appli which is in main and is
// called from Draw ===> undefined symbol on UNIX
// ===> duplication of code on NT :
// One argument added to DrawAppli : Draw_Init_Appli ===>
// Draw_Appli of Draw/TKDraw may call Draw_Init_Appli
#ifndef Draw_Appli_HeaderFile #ifndef Draw_Appli_HeaderFile
#define Draw_Appli_HeaderFile #define Draw_Appli_HeaderFile
#include <Draw_Viewer.hxx> #include <Draw_Viewer.hxx>
#include <Draw.hxx> #include <Draw.hxx>
@ -31,11 +24,11 @@ typedef void (*FDraw_InitAppli)(Draw_Interpretor&);
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
//extern void Draw_Appli(HINSTANCE,HINSTANCE,LPSTR,int); Standard_EXPORT void Draw_Appli(HINSTANCE,HINSTANCE,int,
Standard_EXPORT void Draw_Appli(HINSTANCE,HINSTANCE,LPSTR,int, int argc, wchar_t** argv,
const FDraw_InitAppli Draw_InitAppli); const FDraw_InitAppli Draw_InitAppli);
#else #else
extern void Draw_Appli(Standard_Integer argc, char** argv, extern void Draw_Appli(int argc, char** argv,
const FDraw_InitAppli Draw_InitAppli); const FDraw_InitAppli Draw_InitAppli);
#endif #endif

View File

@ -14,35 +14,8 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
// *******************************************************************
// RLN 06 January 2000
// *******************************************************************
// This file is built from former NTMain.pxx duplicated in many executables
// extending DRAW Test Harness.
// Now is implemented only in one instance.
// Differences between CAS.CADE versions:
// - in C21 Draw_Appli is defined in Draw.cxx (DRAW UL) and calls externally
// defined Draw_InitAppli. Moreover, on WNT Draw_Appli was not declared as
// Standard_EXPORT and therefore it has to be duplicated explicitly in this
// code as in Draw.cxx.
// - in C30 Draw_Appli accepts Draw_InitAppli as parameter which is given to
// it in each executable. Draw_Appli is declared as Standard_EXPORT and
// therefore it needs not to be duplicated.
// To have only one instance of this file and to call it from all the executables
// thereare defined macros in .hxx that replace main/WinMain functions and which
// calls _main_/_WinMain_ defined in this file with specified Draw_InitAppli.
// To avoid Unresolved symbols on WNT, Draw_InitAppli is explicitly defined in this
// is initialized by main/_WinMain_.
// WARNING: Although versions C21 and C30 are synchronised as much as they can,
// there are two versions of this file for both configurations. This is explained by:
// - Standard_IMPOR is differently defined,
// - Draw_Appli is differently declared.
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> /* SW_SHOW */ #include <windows.h>
#endif #endif
#include <Draw_Main.hxx> #include <Draw_Main.hxx>
@ -50,6 +23,7 @@
#include <string.h> #include <string.h>
#include <Draw_Appli.hxx> #include <Draw_Appli.hxx>
#include <OSD.hxx> #include <OSD.hxx>
#include <TCollection_AsciiString.hxx>
#include <tcl.h> #include <tcl.h>
@ -94,18 +68,18 @@ extern Standard_Boolean Draw_IsConsoleSubsystem;
Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDraw_InitAppli fDraw_InitAppli) Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDraw_InitAppli fDraw_InitAppli)
{ {
Draw_IsConsoleSubsystem = Standard_True; Draw_IsConsoleSubsystem = Standard_True;
//return _WinMain_(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli);
theDraw_InitAppli = fDraw_InitAppli; theDraw_InitAppli = fDraw_InitAppli;
//ParseCommandLine(GetCommandLine());
// MKV 01.02.05 // MKV 01.02.05
#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
Tcl_FindExecutable(argv[0]); Tcl_FindExecutable(argv[0]);
#endif #endif
Draw_Appli(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli); int aNbArgs = 0;
wchar_t** anArgVec = CommandLineToArgvW (GetCommandLineW(), &aNbArgs);
Draw_Appli (::GetModuleHandleW (NULL), NULL, SW_SHOW, aNbArgs, anArgVec, fDraw_InitAppli);
LocalFree (anArgVec);
return 0; return 0;
} }
//======================================================================= //=======================================================================
@ -113,11 +87,13 @@ Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDr
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer _WinMain_ (HINSTANCE /*hInstance*/, HINSTANCE /*hPrevinstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/, const FDraw_InitAppli /*fDraw_InitAppli*/) Standard_Integer _WinMain_ (HINSTANCE hInstance, HINSTANCE hPrevinstance, LPSTR /*lpCmdLine*/, int nCmdShow, const FDraw_InitAppli fDraw_InitAppli)
{ {
// theDraw_InitAppli = fDraw_InitAppli; theDraw_InitAppli = fDraw_InitAppli;
// ParseCommandLine (lpCmdLine); int aNbArgs = 0;
// Draw_Appli(hInstance, hPrevinstance, lpCmdLine, nCmdShow, Draw_InitAppli); // for C30; wchar_t** anArgVec = CommandLineToArgvW(GetCommandLineW(), &aNbArgs);
Draw_Appli (hInstance, hPrevinstance, nCmdShow, aNbArgs, anArgVec, fDraw_InitAppli);
LocalFree (anArgVec);
return 0; return 0;
} }
#else #else
@ -136,4 +112,3 @@ Standard_Integer _main_ (Standard_Integer argc, char* argv[], const FDraw_InitAp
return 0; return 0;
} }
#endif #endif

View File

@ -14,11 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE // Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement. // commercial license or contractual agreement.
// Updated by GG Tue Oct 22 16:22:10 1996
// reason : Try to compress the pixel image
// in PseudoColor 8 planes format
// see : SaveView(filename)
#include <Draw_Viewer.hxx> #include <Draw_Viewer.hxx>
#include <Draw_View.hxx> #include <Draw_View.hxx>
@ -26,7 +21,7 @@
#include <gp_Pnt2d.hxx> #include <gp_Pnt2d.hxx>
#include <Draw_Window.hxx> #include <Draw_Window.hxx>
#include <Draw_Display.hxx> #include <Draw_Display.hxx>
#include <TCollection_AsciiString.hxx>
#define precpers 0.95 #define precpers 0.95
#define ButtonPress 4 #define ButtonPress 4
@ -179,7 +174,7 @@ void Draw_Viewer::MakeView (const Standard_Integer id,
void Draw_Viewer::SetTitle (const Standard_Integer id, const char* name) void Draw_Viewer::SetTitle (const Standard_Integer id, const char* name)
{ {
if (Draw_Batch) return; if (Draw_Batch) return;
if(myViews[id]) myViews[id]->SetTitle((char*)name); if(myViews[id]) myViews[id]->SetTitle (name);
} }
//======================================================================= //=======================================================================

View File

@ -26,6 +26,7 @@
#include <Draw_Window.hxx> #include <Draw_Window.hxx>
#include <Draw_Appli.hxx> #include <Draw_Appli.hxx>
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Image_AlienPixMap.hxx> #include <Image_AlienPixMap.hxx>
#include <NCollection_List.hxx> #include <NCollection_List.hxx>
@ -526,20 +527,20 @@ Standard_Integer Draw_Window::WidthWin() const
//function : SetTitle //function : SetTitle
//purpose : //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 //function : GetTitle
//purpose : //purpose :
//======================================================================= //=======================================================================
char* Draw_Window::GetTitle() TCollection_AsciiString Draw_Window::GetTitle() const
{ {
char* title; char* aTitle = NULL;
XFetchName(Draw_WindowDisplay, win, &title); XFetchName (Draw_WindowDisplay, win, &aTitle);
return title; return TCollection_AsciiString (aTitle);
} }
//======================================================================= //=======================================================================
@ -1332,7 +1333,7 @@ int modeTab[16] = {R2_BLACK, R2_MASKPEN, R2_MASKPENNOT, R2_COPYPEN,
HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem) HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
{ {
if (Draw_IsConsoleSubsystem) { if (Draw_IsConsoleSubsystem) {
HWND aWin = CreateWindow (DRAWCLASS, DRAWTITLE, HWND aWin = CreateWindowW (DRAWCLASS, DRAWTITLE,
WS_OVERLAPPEDWINDOW, WS_OVERLAPPEDWINDOW,
1,1,1,1, 1,1,1,1,
NULL, NULL,::GetModuleHandle(NULL), NULL); NULL, NULL,::GetModuleHandle(NULL), NULL);
@ -1344,10 +1345,9 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
return aWin; return aWin;
} }
else { else {
HANDLE hInstance; HANDLE hInstance = (HANDLE )GetWindowLongPtrW (hWndClient, GWLP_HINSTANCE);
hInstance = (HANDLE)GetWindowLongPtr(hWndClient,GWLP_HINSTANCE);
return CreateMDIWindow(DRAWCLASS, DRAWTITLE, return CreateMDIWindowW(DRAWCLASS, DRAWTITLE,
WS_CAPTION | WS_CHILD | WS_THICKFRAME, WS_CAPTION | WS_CHILD | WS_THICKFRAME,
1,1,0,0, 1,1,0,0,
hWndClient, (HINSTANCE)hInstance, nitem); hWndClient, (HINSTANCE)hInstance, nitem);
@ -1360,43 +1360,46 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem)
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
LRESULT APIENTRY DrawWindow::DrawProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) 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) if (!localObjet)
{ {
if (Draw_IsConsoleSubsystem) return Draw_IsConsoleSubsystem
return (DefWindowProc(hWnd, wMsg, wParam, lParam)); ? DefWindowProcW (hWnd, wMsg, wParam, lParam)
else : DefMDIChildProcW (hWnd, wMsg, wParam, lParam);
return(DefMDIChildProc(hWnd, wMsg, wParam, lParam));
} }
PAINTSTRUCT ps; switch (wMsg)
switch(wMsg)
{ {
case WM_PAINT : case WM_PAINT:
BeginPaint(hWnd, &ps); {
PAINTSTRUCT ps;
BeginPaint (hWnd, &ps);
if (localObjet->GetUseBuffer()) if (localObjet->GetUseBuffer())
{
localObjet->Redraw(); localObjet->Redraw();
}
else else
{
localObjet->WExpose(); localObjet->WExpose();
EndPaint(hWnd, &ps); }
return 0l; EndPaint (hWnd, &ps);
break; return 0;
}
case WM_SIZE: case WM_SIZE:
if (localObjet->GetUseBuffer()) { {
if (localObjet->GetUseBuffer())
{
localObjet->InitBuffer(); localObjet->InitBuffer();
localObjet->WExpose(); localObjet->WExpose();
localObjet->Redraw(); localObjet->Redraw();
return 0l; 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);
} }
@ -1488,8 +1491,8 @@ void DrawWindow::Init(Standard_Integer theXLeft, Standard_Integer theYTop,
// include decorations in the window dimensions // include decorations in the window dimensions
// to reproduce same behaviour of Xlib window. // to reproduce same behaviour of Xlib window.
DWORD aWinStyle = GetWindowLong (win, GWL_STYLE); DWORD aWinStyle = GetWindowLongW (win, GWL_STYLE);
DWORD aWinStyleEx = GetWindowLong (win, GWL_EXSTYLE); DWORD aWinStyleEx = GetWindowLongW (win, GWL_EXSTYLE);
HMENU aMenu = GetMenu (win); HMENU aMenu = GetMenu (win);
RECT aRect; RECT aRect;
@ -1502,7 +1505,7 @@ void DrawWindow::Init(Standard_Integer theXLeft, Standard_Integer theYTop,
SetPosition (aRect.left, aRect.top); SetPosition (aRect.left, aRect.top);
SetDimension (aRect.right - aRect.left, aRect.bottom - aRect.top); SetDimension (aRect.right - aRect.left, aRect.bottom - aRect.top);
// Save the pointer at the instance associated to the window // 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); HDC hDC = GetDC(win);
SetBkColor(hDC, RGB(0, 0, 0)); SetBkColor(hDC, RGB(0, 0, 0));
myCurrPen = 3; myCurrPen = 3;
@ -1657,21 +1660,21 @@ Standard_Integer DrawWindow::WidthWin() const
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| SetTitle | SetTitle
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
void DrawWindow::SetTitle(const char* title) void DrawWindow::SetTitle (const TCollection_AsciiString& theTitle)
{ {
SetWindowText(win, title); const TCollection_ExtendedString aTitleW (theTitle);
SetWindowTextW (win, aTitleW.ToWideString());
} }
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| GetTitle | GetTitle
| Attention do not forget to unallocate the memory
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
char* DrawWindow::GetTitle() TCollection_AsciiString DrawWindow::GetTitle() const
{ {
char* title=new char[31]; wchar_t aTitleW[32];
GetWindowText(win, title, 30); GetWindowTextW (win, aTitleW, 30);
return title; return TCollection_AsciiString (aTitleW);
} }
@ -1810,7 +1813,8 @@ void DrawWindow::DrawString(int x,int y, char* text)
HDC hDC = GetDC(win); HDC hDC = GetDC(win);
HDC aWorkDC = myUseBuffer ? GetMemDC(hDC) : hDC; 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); if (myUseBuffer) ReleaseMemDC(aWorkDC);
ReleaseDC(win,hDC); ReleaseDC(win,hDC);
@ -1960,9 +1964,8 @@ static Tk_Window mainWindow;
//* threads sinchronization *// //* threads sinchronization *//
DWORD dwMainThreadId; DWORD dwMainThreadId;
console_semaphore_value volatile console_semaphore = WAIT_CONSOLE_COMMAND; console_semaphore_value volatile console_semaphore = WAIT_CONSOLE_COMMAND;
//char console_command[1000]; #define THE_COMMAND_SIZE 1000 /* Console Command size */
#define COMMAND_SIZE 1000 /* Console Command size */ wchar_t console_command[THE_COMMAND_SIZE];
char console_command[COMMAND_SIZE];
bool volatile isTkLoopStarted = false; bool volatile isTkLoopStarted = false;
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
@ -2031,14 +2034,39 @@ Standard_Boolean Draw_Interprete (const char*);
/*--------------------------------------------------------*\ /*--------------------------------------------------------*\
| readStdinThreadFunc | readStdinThreadFunc
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
static DWORD WINAPI readStdinThreadFunc(VOID) static DWORD WINAPI readStdinThreadFunc()
{ {
if (!Draw_IsConsoleSubsystem) return 1; if (!Draw_IsConsoleSubsystem)
for(;;) {
while (console_semaphore != WAIT_CONSOLE_COMMAND)
Sleep(100);
if (fgets(console_command,COMMAND_SIZE,stdin))
{ {
return 1;
}
// set console locale
//setlocale (LC_ALL, ".OCP");
for (;;)
{
while (console_semaphore != WAIT_CONSOLE_COMMAND)
{
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)
{
if (console_command[aNbRead] == L'\r'
|| console_command[aNbRead] == L'\n')
{
console_command[aNbRead] = '\0';
continue;
}
break;
}*/
console_semaphore = HAS_CONSOLE_COMMAND; console_semaphore = HAS_CONSOLE_COMMAND;
} }
} }
@ -2065,9 +2093,23 @@ static DWORD WINAPI tkLoop(VOID)
{ {
Tcl_CreateExitHandler(exitProc, 0); Tcl_CreateExitHandler(exitProc, 0);
#if (TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 5)) #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_Channel aChannelIn = Tcl_GetStdChannel (TCL_STDIN);
Tcl_RegisterChannel(theCommands.Interp(), Tcl_GetStdChannel(TCL_STDERR)); 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 #endif
#ifdef _TK #ifdef _TK
@ -2128,7 +2170,8 @@ static DWORD WINAPI tkLoop(VOID)
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 (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 (Draw_IsConsoleSubsystem) Prompt (interp, 0);
} }
@ -2176,8 +2219,8 @@ void Run_Appli(HWND hWnd)
if (!hThread) { if (!hThread) {
cout << "pb in creation of the thread reading stdin" << endl; cout << "pb in creation of the thread reading stdin" << endl;
Draw_IsConsoleSubsystem = Standard_False; Draw_IsConsoleSubsystem = Standard_False;
Init_Appli(GetModuleHandle(NULL), Init_Appli (GetModuleHandleW (NULL),
GetModuleHandle(NULL), GetModuleHandleW (NULL),
1, hWnd); // reinit => create MDI client wnd 1, hWnd); // reinit => create MDI client wnd
} }
} }
@ -2187,12 +2230,12 @@ void Run_Appli(HWND hWnd)
console_semaphore = WAIT_CONSOLE_COMMAND; console_semaphore = WAIT_CONSOLE_COMMAND;
//simple Win32 message loop //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); TranslateMessage (&msg);
DispatchMessage(&msg); DispatchMessageW (&msg);
} }
} }
ExitProcess(0); ExitProcess(0);
@ -2218,10 +2261,12 @@ void DrawWindow::SelectWait(HANDLE& hWnd, int& x, int& y, int& button)
msg.wParam = 1; msg.wParam = 1;
GetMessage(&msg,NULL,0,0); GetMessageW (&msg, NULL, 0, 0);
while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN) || while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN) ||
! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd)) ) ! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd)) )
GetMessage(&msg,NULL,0,0); {
GetMessageW (&msg, NULL, 0, 0);
}
hWnd = msg.hwnd; hWnd = msg.hwnd;
x = LOWORD(msg.lParam); x = LOWORD(msg.lParam);
@ -2241,11 +2286,13 @@ void DrawWindow::SelectNoWait(HANDLE& hWnd, int& x, int& y, int& button)
msg.wParam = 1; msg.wParam = 1;
GetMessage(&msg,NULL,0,0); GetMessageW (&msg,NULL,0,0);
while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN && while((msg.message != WM_RBUTTONDOWN && msg.message != WM_LBUTTONDOWN &&
msg.message != WM_MOUSEMOVE) || msg.message != WM_MOUSEMOVE) ||
! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd) ) ) ! ( Draw_IsConsoleSubsystem || IsChild(DrawWindow::hWndClientMDI,msg.hwnd) ) )
GetMessage(&msg,NULL,0,0); {
GetMessageW(&msg,NULL,0,0);
}
hWnd = msg.hwnd; hWnd = msg.hwnd;
x = LOWORD(msg.lParam); x = LOWORD(msg.lParam);
y = HIWORD(msg.lParam); y = HIWORD(msg.lParam);

View File

@ -19,6 +19,7 @@
#include <Standard_Boolean.hxx> #include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
#include <TCollection_AsciiString.hxx>
#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
@ -116,8 +117,8 @@ class Draw_Window
Standard_Integer HeightWin() const; Standard_Integer HeightWin() const;
Standard_Integer WidthWin() const; Standard_Integer WidthWin() const;
void SetTitle(const char* title); void SetTitle (const TCollection_AsciiString& theTitle);
char* GetTitle(); TCollection_AsciiString GetTitle() const;
void DisplayWindow(); void DisplayWindow();
void Hide(); void Hide();
@ -281,8 +282,8 @@ class Draw_Window
Standard_Integer HeightWin() const; Standard_Integer HeightWin() const;
Standard_Integer WidthWin() const; Standard_Integer WidthWin() const;
void SetTitle (Standard_CString theTitle); void SetTitle (const TCollection_AsciiString& theTitle);
Standard_CString GetTitle (); TCollection_AsciiString GetTitle() const;
void DisplayWindow(); void DisplayWindow();
void Hide(); void Hide();
@ -353,8 +354,8 @@ void GetNextEvent (Standard_Boolean theWait,
#include <windows.h> #include <windows.h>
#define DRAWCLASS "DRAWWINDOW" #define DRAWCLASS L"DRAWWINDOW"
#define DRAWTITLE "Draw View" #define DRAWTITLE L"Draw View"
#define MAXCOLOR 15 #define MAXCOLOR 15
#if !defined(__Draw_API) && !defined(HAVE_NO_DLL) #if !defined(__Draw_API) && !defined(HAVE_NO_DLL)
@ -443,8 +444,8 @@ public:
__Draw_API Standard_Integer WidthWin() const; __Draw_API Standard_Integer WidthWin() const;
//Title //Title
__Draw_API void SetTitle(const char*); __Draw_API void SetTitle (const TCollection_AsciiString& );
__Draw_API char* GetTitle(); __Draw_API TCollection_AsciiString GetTitle() const;
//Affichage //Affichage
__Draw_API void DisplayWindow(); __Draw_API void DisplayWindow();

View File

@ -301,9 +301,9 @@ Standard_Integer Draw_Window::WidthWin() const
//function : SetTitle //function : SetTitle
//purpose : //purpose :
//======================================================================= //=======================================================================
void Draw_Window::SetTitle (Standard_CString theTitle) void Draw_Window::SetTitle (const TCollection_AsciiString& theTitle)
{ {
NSString* aTitleNs = [[NSString alloc] initWithUTF8String: theTitle]; NSString* aTitleNs = [[NSString alloc] initWithUTF8String: theTitle.ToCString()];
[myWindow setTitle: aTitleNs]; [myWindow setTitle: aTitleNs];
[aTitleNs release]; [aTitleNs release];
} }
@ -312,10 +312,10 @@ void Draw_Window::SetTitle (Standard_CString theTitle)
//function : GetTitle //function : GetTitle
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_CString Draw_Window::GetTitle() TCollection_AsciiString Draw_Window::GetTitle() const
{ {
Standard_CString aTitle = [[myWindow title] UTF8String]; Standard_CString aTitle = [[myWindow title] UTF8String];
return aTitle; return TCollection_AsciiString (aTitle);
} }
//======================================================================= //=======================================================================

View File

@ -35,33 +35,33 @@ extern Standard_Boolean Draw_IsConsoleSubsystem;
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
LRESULT APIENTRY WndProc(HWND hWndFrame, UINT wMsg, WPARAM wParam, LPARAM lParam ) LRESULT APIENTRY WndProc(HWND hWndFrame, UINT wMsg, WPARAM wParam, LPARAM lParam )
{ {
HWND hWndClient; switch (wMsg)
switch(wMsg)
{ {
case WM_CREATE : case WM_CREATE:
{ {
CreateProc(hWndFrame); CreateProc (hWndFrame);
hWndClient = (HWND)GetWindowLongPtr(hWndFrame, CLIENTWND); HWND hWndClient = (HWND )GetWindowLongPtrW (hWndFrame, CLIENTWND);
DrawWindow::hWndClientMDI = hWndClient; DrawWindow::hWndClientMDI = hWndClient;
if (!Draw_IsConsoleSubsystem) if (!Draw_IsConsoleSubsystem)
CreateCommandWindow(hWndFrame,0); {
CreateCommandWindow (hWndFrame, 0);
} }
break; return 0;
case WM_COMMAND :
CmdProc(hWndFrame, LOWORD(wParam), wParam, lParam);
break;
case WM_DESTROY :
Draw_Interprete("exit");
DestroyProc(hWndFrame);
break;
default :
hWndClient = (HWND)GetWindowLongPtr(hWndFrame, CLIENTWND);
return(DefFrameProc(hWndFrame, hWndClient, wMsg, wParam, lParam));
} }
return(0l); case WM_COMMAND:
{
CmdProc (hWndFrame, LOWORD(wParam), wParam, lParam);
return 0;
}
case WM_DESTROY:
{
Draw_Interprete ("exit");
DestroyProc (hWndFrame);
return 0;
}
}
HWND hWndClient = (HWND)GetWindowLongPtrW(hWndFrame, CLIENTWND);
return DefFrameProcW(hWndFrame, hWndClient, wMsg, wParam, lParam);
} }
@ -76,7 +76,7 @@ BOOL CreateProc(HWND hWndFrame)
if (hWnd != NULL) if (hWnd != NULL)
{ {
// Save hWnd in the main window in extra memory in 0 // Save hWnd in the main window in extra memory in 0
SetWindowLongPtr(hWndFrame, CLIENTWND, (LONG_PTR)hWnd); SetWindowLongPtrW (hWndFrame, CLIENTWND, (LONG_PTR)hWnd);
} }
return(TRUE); return(TRUE);
} }
@ -91,40 +91,50 @@ BOOL CreateProc(HWND hWndFrame)
LRESULT APIENTRY CmdProc(HWND hWndFrame, UINT wMsg, WPARAM /*wParam*/, LPARAM /*lParam*/) LRESULT APIENTRY CmdProc(HWND hWndFrame, UINT wMsg, WPARAM /*wParam*/, LPARAM /*lParam*/)
{ {
// Handle on window MDI // Handle on window MDI
HWND hWndClient = (HWND)GetWindowLongPtr (hWndFrame, CLIENTWND); HWND hWndClient = (HWND )GetWindowLongPtrW (hWndFrame, CLIENTWND);
switch (wMsg) switch (wMsg)
{ {
case IDM_WINDOW_NEXT : case IDM_WINDOW_NEXT:
if(hWndClient)
{ {
HWND hWndActive = (HWND)SendMessage(hWndClient, WM_MDIGETACTIVE, 0, 0l); if (hWndClient != NULL)
SendMessage(hWndClient, WM_MDINEXT, (WPARAM)hWndActive, 0l); {
HWND hWndActive = (HWND )SendMessageW (hWndClient, WM_MDIGETACTIVE, 0, 0l);
SendMessageW (hWndClient, WM_MDINEXT, (WPARAM )hWndActive, 0l);
} }
break; break;
}
case IDM_WINDOW_CASCADE : case IDM_WINDOW_CASCADE:
if(hWndClient) {
SendMessage(hWndClient, WM_MDICASCADE, 0, 0l); if (hWndClient != NULL)
break; {
SendMessageW (hWndClient, WM_MDICASCADE, 0, 0l);
case IDM_WINDOW_TILEHOR : }
if(hWndClient)
SendMessage(hWndClient, WM_MDITILE, MDITILE_HORIZONTAL, 0l);
break;
case IDM_WINDOW_TILEVERT :
if(hWndClient)
SendMessage(hWndClient, WM_MDITILE, MDITILE_VERTICAL, 0l);
break;
case IDM_FILE_EXIT :
Draw_Interprete("exit");
//compat_unlink(NULL);
DestroyProc(hWndFrame);
break; break;
} }
return(0l); case IDM_WINDOW_TILEHOR:
{
if (hWndClient != NULL)
{
SendMessageW (hWndClient, WM_MDITILE, MDITILE_HORIZONTAL, 0l);
}
break;
}
case IDM_WINDOW_TILEVERT:
{
if (hWndClient != NULL)
{
SendMessageW (hWndClient, WM_MDITILE, MDITILE_VERTICAL, 0l);
}
break;
}
case IDM_FILE_EXIT:
{
Draw_Interprete ("exit");
DestroyProc (hWndFrame);
break;
}
}
return 0;
} }
@ -135,7 +145,7 @@ LRESULT APIENTRY CmdProc(HWND hWndFrame, UINT wMsg, WPARAM /*wParam*/, LPARAM /*
\*--------------------------------------------------------------------------*/ \*--------------------------------------------------------------------------*/
VOID DestroyProc(HWND hWnd) VOID DestroyProc(HWND hWnd)
{ {
HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); HINSTANCE hInst = (HINSTANCE )GetWindowLongPtrW (hWnd, GWLP_HINSTANCE);
Destroy_Appli(hInst); Destroy_Appli(hInst);
PostQuitMessage(0); PostQuitMessage(0);

View File

@ -37,55 +37,55 @@ d\*--------------------------------------------------------*/
BOOL RegisterAppClass(HINSTANCE hInstance) BOOL RegisterAppClass(HINSTANCE hInstance)
{ {
WNDCLASS wndClass; WNDCLASSW wndClass;
// Parametres communs aux classes // Parametres communs aux classes
//----- //-----
wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC; wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC;
wndClass.cbClsExtra = 0; wndClass.cbClsExtra = 0;
wndClass.hCursor = LoadCursor(NULL,IDC_ARROW); wndClass.hCursor = LoadCursorW (NULL, IDC_ARROW);
wndClass.hInstance = hInstance; wndClass.hInstance = hInstance;
// Enregistrement de la fenetre principale // Enregistrement de la fenetre principale
//----- //-----
wndClass.cbWndExtra = sizeof(LONG); wndClass.cbWndExtra = sizeof(void*);
wndClass.lpfnWndProc = (WNDPROC)WndProc; wndClass.lpfnWndProc = (WNDPROC)WndProc;
wndClass.hIcon = (HICON)LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); wndClass.hIcon = (HICON )LoadIconW (hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName = MAKEINTRESOURCE(APPMENU); wndClass.lpszMenuName = MAKEINTRESOURCEW(APPMENU);
wndClass.lpszClassName = APPCLASS; wndClass.lpszClassName = APPCLASS;
if(!RegisterClass(&wndClass)) if(!RegisterClassW(&wndClass))
return(FALSE); return(FALSE);
// Enregistrement de la fenetre DrawWindow // Enregistrement de la fenetre DrawWindow
//------ //------
wndClass.cbWndExtra = sizeof(LONG); // Extra Memory wndClass.cbWndExtra = sizeof(void*); // Extra Memory
wndClass.lpfnWndProc = (WNDPROC)DrawWindow::DrawProc; wndClass.lpfnWndProc = (WNDPROC)DrawWindow::DrawProc;
wndClass.hIcon = 0; wndClass.hIcon = 0;
wndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndClass.lpszMenuName = NULL; wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = DRAWCLASS; wndClass.lpszClassName = DRAWCLASS;
if(!RegisterClass(&wndClass)) if(!RegisterClassW(&wndClass))
{ {
UnregisterClass(APPCLASS, hInstance); UnregisterClassW(APPCLASS, hInstance);
return(FALSE); return(FALSE);
} }
// Enregistrement de la fenetre CommandWindow // Enregistrement de la fenetre CommandWindow
//------ //------
wndClass.lpfnWndProc = (WNDPROC)CmdProc; wndClass.lpfnWndProc = (WNDPROC)CommandProc;
wndClass.hIcon = 0; wndClass.hIcon = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName = NULL; wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = COMMANDCLASS; wndClass.lpszClassName = COMMANDCLASS;
if(!RegisterClass(&wndClass)) if(!RegisterClassW(&wndClass))
{ {
UnregisterClass(APPCLASS, hInstance); UnregisterClassW(APPCLASS, hInstance);
UnregisterClass(DRAWCLASS, hInstance); UnregisterClassW(DRAWCLASS, hInstance);
return(FALSE); return(FALSE);
} }
@ -100,8 +100,8 @@ BOOL RegisterAppClass(HINSTANCE hInstance)
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
VOID UnregisterAppClass(HINSTANCE hInstance) VOID UnregisterAppClass(HINSTANCE hInstance)
{ {
UnregisterClass(APPCLASS, hInstance); UnregisterClassW(APPCLASS, hInstance);
UnregisterClass(DRAWCLASS, hInstance); UnregisterClassW(DRAWCLASS, hInstance);
} }
@ -112,7 +112,7 @@ VOID UnregisterAppClass(HINSTANCE hInstance)
\*--------------------------------------------------------*/ \*--------------------------------------------------------*/
HWND CreateAppWindow(HINSTANCE hInstance) HWND CreateAppWindow(HINSTANCE hInstance)
{ {
return(CreateWindow(APPCLASS, APPTITLE, return(CreateWindowW(APPCLASS, APPTITLE,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
400,0, 400,0,
623,767, 623,767,
@ -135,9 +135,9 @@ HWND CreateMDIClientWindow(HWND hWndFrame)
ccs.hWindowMenu = NULL; ccs.hWindowMenu = NULL;
ccs.idFirstChild = 0; ccs.idFirstChild = 0;
hInstance = (HANDLE)GetWindowLongPtr(hWndFrame, GWLP_HINSTANCE); hInstance = (HANDLE)GetWindowLongPtrW(hWndFrame, GWLP_HINSTANCE);
hWndClient = CreateWindow("MDICLIENT",NULL, hWndClient = CreateWindowW(L"MDICLIENT",NULL,
WS_CHILD | WS_CLIPSIBLINGS | WS_CHILD | WS_CLIPSIBLINGS |
WS_VISIBLE | MDIS_ALLCHILDSTYLES, WS_VISIBLE | MDIS_ALLCHILDSTYLES,
0, 0, 1, 1, 0, 0, 1, 1,

View File

@ -16,8 +16,8 @@
#ifdef _WIN32 #ifdef _WIN32
#define APPCLASS "TDRAW" #define APPCLASS L"TDRAW"
#define APPTITLE "Windows NT TDRAW" #define APPTITLE L"Windows NT TDRAW"
#include <windows.h> #include <windows.h>
BOOL RegisterAppClass(HINSTANCE); BOOL RegisterAppClass(HINSTANCE);

View File

@ -251,15 +251,15 @@ Standard_Integer GenerateId()
// Function : WClass // Function : WClass
// Purpose : // Purpose :
//========================================================= //=========================================================
const Handle(MMgt_TShared)& IVtkDraw::WClass() const Handle(Standard_Transient)& IVtkDraw::WClass()
{ {
static Handle(MMgt_TShared) aWindowClass; static Handle(Standard_Transient) aWindowClass;
#ifdef _WIN32 #ifdef _WIN32
if (aWindowClass.IsNull()) if (aWindowClass.IsNull())
{ {
aWindowClass = new WNT_WClass ("GWVTK_Class", DefWindowProc, aWindowClass = new WNT_WClass ("GWVTK_Class", DefWindowProc,
CS_VREDRAW | CS_HREDRAW, 0, 0, CS_VREDRAW | CS_HREDRAW, 0, 0,
::LoadCursor (NULL, IDC_ARROW)); ::LoadCursorW (NULL, IDC_ARROW));
} }
#endif #endif
return aWindowClass; return aWindowClass;

View File

@ -16,12 +16,11 @@
#ifndef _IVtkDraw_HeaderFile #ifndef _IVtkDraw_HeaderFile
#define _IVtkDraw_HeaderFile #define _IVtkDraw_HeaderFile
#include <MMgt_TShared.hxx> #include <Standard_Transient.hxx>
#include <Standard.hxx> #include <Standard.hxx>
#include <Standard_Macro.hxx> #include <Standard_Macro.hxx>
class Draw_Interpretor; class Draw_Interpretor;
class MMgt_TShared;
class IVtkDraw class IVtkDraw
{ {
@ -38,7 +37,7 @@ public:
Standard_EXPORT static void Commands (Draw_Interpretor& theCommands); Standard_EXPORT static void Commands (Draw_Interpretor& theCommands);
private: private:
Standard_EXPORT static const Handle(MMgt_TShared)& WClass(); Standard_EXPORT static const Handle(Standard_Transient)& WClass();
}; };
#endif #endif

View File

@ -14,7 +14,6 @@
#ifndef _WIN32 #ifndef _WIN32
#include <OSD_Environment.hxx> #include <OSD_Environment.hxx>
#include <OSD_OSDError.hxx> #include <OSD_OSDError.hxx>
#include <OSD_WhoAmI.hxx> #include <OSD_WhoAmI.hxx>
@ -234,20 +233,16 @@ Standard_Integer OSD_Environment::Error() const
//------------------------------------------------------------------------ //------------------------------------------------------------------------
#define STRICT #define STRICT
#include <windows.h>
#include <OSD_Environment.hxx> #include <OSD_Environment.hxx>
#include <OSD_WNT.hxx> #include <OSD_WNT.hxx>
#include <windows.h>
#include <NCollection_DataMap.hxx> #include <NCollection_DataMap.hxx>
#include <NCollection_UtfString.hxx> #include <NCollection_UtfString.hxx>
#include <Standard_Mutex.hxx> #include <Standard_Mutex.hxx>
#if defined(_MSC_VER)
#pragma warning( disable : 4700 )
#endif
#ifdef OCCT_UWP #ifdef OCCT_UWP
namespace namespace
{ {
@ -381,28 +376,22 @@ Standard_Integer OSD_Environment :: Error () const {
} // end OSD_Environment :: Error } // end OSD_Environment :: Error
#ifndef OCCT_UWP #ifndef OCCT_UWP
static void __fastcall _set_error ( OSD_Error& err, DWORD code ) { static void __fastcall _set_error (OSD_Error& theErr, DWORD theCode)
{
DWORD errCode; wchar_t aBuffer[2048];
Standard_Character buffer[ 2048 ]; const DWORD anErrCode = theCode != 0 ? theCode : GetLastError();
if (!FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
errCode = code ? code : GetLastError (); 0, anErrCode, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ),
aBuffer, 2048, NULL))
if ( !FormatMessage ( {
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, theErr.SetValue (anErrCode, OSD_WEnvironment, TCollection_AsciiString ("error code ") + (Standard_Integer)anErrCode);
0, errCode, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ), SetLastError (anErrCode);
buffer, 2048, NULL }
) else
) { {
theErr.SetValue (anErrCode, OSD_WEnvironment, TCollection_AsciiString (aBuffer));
sprintf ( buffer, "error code %d", (Standard_Integer)errCode ); }
SetLastError ( errCode ); }
} // end if
err.SetValue ( errCode, OSD_WEnvironment, buffer );
} // end _set_error
#endif #endif
#endif #endif

View File

@ -1430,7 +1430,7 @@ OSD_KindFile OSD_File :: KindOfFile () const {
typedef struct _osd_wnt_key { typedef struct _osd_wnt_key {
HKEY hKey; HKEY hKey;
const char* keyPath; wchar_t* keyPath;
} OSD_WNT_KEY; } OSD_WNT_KEY;
@ -1448,17 +1448,17 @@ typedef struct _osd_wnt_key {
OSD_WNT_KEY regKey[ 2 ] = { OSD_WNT_KEY regKey[ 2 ] = {
{ HKEY_LOCAL_MACHINE, { HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
}, },
{ HKEY_USERS, { HKEY_USERS,
".DEFAULT\\Environment" L".DEFAULT\\Environment"
} }
}; };
for ( int i = 0; i < 2; ++i ) { for ( int i = 0; i < 2; ++i ) {
if ( RegOpenKeyEx ( if ( RegOpenKeyExW (
regKey[ i ].hKey, regKey[ i ].keyPath, 0, KEY_QUERY_VALUE, &hKey regKey[ i ].hKey, regKey[ i ].keyPath, 0, KEY_QUERY_VALUE, &hKey
) == ERROR_SUCCESS ) == ERROR_SUCCESS
) { ) {

View File

@ -14,7 +14,6 @@
#ifndef _WIN32 #ifndef _WIN32
#include <OSD_Host.hxx> #include <OSD_Host.hxx>
#include <OSD_OSDError.hxx> #include <OSD_OSDError.hxx>
#include <OSD_WhoAmI.hxx> #include <OSD_WhoAmI.hxx>
@ -202,13 +201,13 @@ static Standard_Integer memSize;
OSD_Host :: OSD_Host () { OSD_Host :: OSD_Host () {
#ifndef OCCT_UWP #ifndef OCCT_UWP
DWORD nSize; DWORD nSize;
Standard_Character szHostName[ MAX_COMPUTERNAME_LENGTH + 1 ]; char szHostName[MAX_COMPUTERNAME_LENGTH + 1];
char* hostAddr = 0; char* hostAddr = 0;
MEMORYSTATUS ms; MEMORYSTATUS ms;
WSADATA wd; WSADATA wd;
PHOSTENT phe; PHOSTENT phe;
IN_ADDR inAddr; IN_ADDR inAddr;
OSVERSIONINFO osVerInfo; OSVERSIONINFOW osVerInfo;
if ( !fInit ) { if ( !fInit ) {
@ -216,25 +215,24 @@ OSD_Host :: OSD_Host () {
osVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO ); osVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
ZeroMemory (&ms, sizeof(ms)); ZeroMemory (&ms, sizeof(ms));
ZeroMemory ( szHostName, sizeof ( Standard_Character ) * (MAX_COMPUTERNAME_LENGTH + 1) ); ZeroMemory (szHostName, sizeof(char) * (MAX_COMPUTERNAME_LENGTH + 1));
#ifdef _MSC_VER #ifdef _MSC_VER
// suppress GetVersionEx() deprecation warning // suppress GetVersionEx() deprecation warning
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
#endif #endif
if ( !GetVersionEx ( &osVerInfo ) ) { if (!GetVersionExW (&osVerInfo))
{
_osd_wnt_set_error ( myError, OSD_WHost ); _osd_wnt_set_error (myError, OSD_WHost);
}
} else if ( !GetComputerName ( szHostName, &nSize ) ) { else if (!GetComputerNameA (szHostName, &nSize))
{
_osd_wnt_set_error ( myError, OSD_WHost ); _osd_wnt_set_error (myError, OSD_WHost);
}
} else { else
{
ms.dwLength = sizeof ( MEMORYSTATUS ); ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus ( &ms ); GlobalMemoryStatus (&ms);
} // end else } // end else
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(default : 4996) #pragma warning(default : 4996)
@ -248,7 +246,7 @@ OSD_Host :: OSD_Host () {
_osd_wnt_set_error ( myError, OSD_WHost ); _osd_wnt_set_error ( myError, OSD_WHost );
} else if ( ( phe = gethostbyname ( szHostName ) ) == NULL ) { } else if ( ( phe = gethostbyname (szHostName) ) == NULL ) {
_osd_wnt_set_error ( myError, OSD_WHost ); _osd_wnt_set_error ( myError, OSD_WHost );

View File

@ -14,7 +14,6 @@
#ifndef _WIN32 #ifndef _WIN32
#include <OSD_Environment.hxx> #include <OSD_Environment.hxx>
#include <OSD_OSDError.hxx> #include <OSD_OSDError.hxx>
#include <OSD_Path.hxx> #include <OSD_Path.hxx>
@ -195,65 +194,60 @@ Standard_Integer OSD_Process::Error()const{
#include <TCollection_ExtendedString.hxx> #include <TCollection_ExtendedString.hxx>
#include <OSD_WNT_1.hxx> #include <OSD_WNT_1.hxx>
#include <LMCONS.H> /// pour UNLEN ( see MSDN about GetUserName() ) #include <LMCONS.H> // for UNLEN - maximum user name length GetUserName()
#if defined(_MSC_VER)
#pragma warning( disable : 4700 )
#endif
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... ); void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
OSD_Process :: OSD_Process () { // =======================================================================
// function : OSD_Process
// purpose :
// =======================================================================
OSD_Process::OSD_Process()
{
//
}
} // end constructor // =======================================================================
// function : Spawn
// purpose :
Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& cmd, // =======================================================================
const Standard_Boolean ShowWindow /* = Standard_True */) { Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& theCmd,
const Standard_Boolean theToShowWindow)
{
#ifndef OCCT_UWP #ifndef OCCT_UWP
STARTUPINFO si; STARTUPINFOW aStartupInfo;
PROCESS_INFORMATION pi; ZeroMemory (&aStartupInfo, sizeof(STARTUPINFO));
DWORD aRes = 0; aStartupInfo.cb = sizeof(STARTUPINFO);
if (!theToShowWindow)
ZeroMemory ( &si, sizeof ( STARTUPINFO ) );
si.cb = sizeof ( STARTUPINFO );
//============================================
//---> Added by Stephane Routelous ( stephane.routelous@altavista.net ) [16.03.01]
//---> Reason : to allow to hide the window
if ( !ShowWindow )
{ {
si.dwFlags = STARTF_USESHOWWINDOW; aStartupInfo.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; aStartupInfo.wShowWindow = SW_HIDE;
} }
//<--- End Added by Stephane Routelous ( stephane.routelous@altavista.net ) [16.03.01]
//============================================
if (!CreateProcess ( DWORD aRes = 0;
NULL, (char *)cmd.ToCString (), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi TCollection_ExtendedString aCmdWide (theCmd);
) wchar_t* aCmdWidePtr = const_cast<wchar_t*>(aCmdWide.ToWideString()); // CreateProcessW() can modify content of this string
) { PROCESS_INFORMATION aProcessInfo;
if (!CreateProcessW (NULL, aCmdWidePtr, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &aStartupInfo, &aProcessInfo))
_osd_wnt_set_error ( myError, OSD_WProcess ); {
_osd_wnt_set_error (myError, OSD_WProcess);
aRes = myError.Error(); aRes = myError.Error();
} }
else { else
{
CloseHandle ( pi.hThread ); CloseHandle (aProcessInfo.hThread);
WaitForSingleObject (aProcessInfo.hProcess, INFINITE);
WaitForSingleObject ( pi.hProcess, INFINITE ); GetExitCodeProcess (aProcessInfo.hProcess, &aRes);
GetExitCodeProcess (pi.hProcess, &aRes); CloseHandle (aProcessInfo.hProcess);
CloseHandle ( pi.hProcess ); }
} // end else
return aRes; return aRes;
#else #else
(void)cmd; (void )theCmd;
(void)ShowWindow; (void )theToShowWindow;
return 0; return 0;
#endif #endif
} // end OSD_Process :: Spawn }
void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) { void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) {
@ -276,27 +270,26 @@ Quantity_Date OSD_Process :: SystemDate () {
} // end OSD_Process :: SystemDate } // end OSD_Process :: SystemDate
TCollection_AsciiString OSD_Process :: UserName () // =======================================================================
// function : UserName
// purpose :
// =======================================================================
TCollection_AsciiString OSD_Process::UserName()
{ {
#ifndef OCCT_UWP #ifndef OCCT_UWP
Standard_PCharacter pBuff = new char[UNLEN + 1]; wchar_t aUserName[UNLEN + 1];
DWORD dwSize = UNLEN + 1; DWORD aNameSize = UNLEN + 1;
TCollection_AsciiString retVal; TCollection_AsciiString retVal;
if ( !GetUserName ( pBuff, &dwSize ) ) if (!GetUserNameW (aUserName, &aNameSize))
{ {
_osd_wnt_set_error ( myError, OSD_WProcess ); _osd_wnt_set_error(myError, OSD_WProcess);
return TCollection_AsciiString();
} }
else return TCollection_AsciiString (aUserName);
{
TCollection_AsciiString theTmpUserName(pBuff,(int)dwSize -1 );
retVal = theTmpUserName;
}
delete [] pBuff;
return retVal;
#else #else
return ""; return TCollection_AsciiString();
#endif #endif
} // end OSD_Process :: UserName }
Standard_Boolean OSD_Process :: IsSuperUser () { Standard_Boolean OSD_Process :: IsSuperUser () {
#ifndef OCCT_UWP #ifndef OCCT_UWP
@ -341,31 +334,41 @@ Standard_Boolean OSD_Process :: IsSuperUser () {
#endif #endif
} // end OSD_Process :: IsSuperUser } // end OSD_Process :: IsSuperUser
Standard_Integer OSD_Process :: ProcessId () { // =======================================================================
// function : ProcessId
// purpose :
// =======================================================================
Standard_Integer OSD_Process::ProcessId()
{
return (Standard_Integer )GetCurrentProcessId();
}
return ( Standard_Integer )GetCurrentProcessId (); // =======================================================================
// function : CurrentDirectory
} // end OSD_Process :: ProcessId // purpose :
// =======================================================================
OSD_Path OSD_Process :: CurrentDirectory () { OSD_Path OSD_Process::CurrentDirectory()
{
OSD_Path anCurrentDirectory; OSD_Path anCurrentDirectory;
#ifndef OCCT_UWP #ifndef OCCT_UWP
DWORD dwSize = PATHLEN + 1; const DWORD aBuffLen = GetCurrentDirectoryW (0, NULL);
Standard_WideChar* pBuff = new wchar_t[dwSize]; if (aBuffLen > 0)
if (GetCurrentDirectoryW (dwSize, pBuff) > 0)
{ {
// conversion to UTF-8 is performed inside wchar_t* aBuff = new wchar_t[aBuffLen + 1];
TCollection_AsciiString aPath (pBuff); GetCurrentDirectoryW (aBuffLen, aBuff);
anCurrentDirectory = OSD_Path ( aPath ); aBuff[aBuffLen] = L'\0';
const TCollection_AsciiString aPath (aBuff);
delete[] aBuff;
anCurrentDirectory = OSD_Path (aPath);
} }
else else
_osd_wnt_set_error ( myError, OSD_WProcess ); {
_osd_wnt_set_error (myError, OSD_WProcess);
delete[] pBuff; }
#endif #endif
return anCurrentDirectory; return anCurrentDirectory;
} // end OSD_Process :: CurrentDirectory }
void OSD_Process :: SetCurrentDirectory ( const OSD_Path& where ) { void OSD_Process :: SetCurrentDirectory ( const OSD_Path& where ) {

View File

@ -208,7 +208,7 @@ private:
//! Ctrl+MB2 for pan, etc) and keyboard shortcuts. //! Ctrl+MB2 for pan, etc) and keyboard shortcuts.
//! This method is relevant for MS Windows only and respectively //! This method is relevant for MS Windows only and respectively
//! returns WNT_WClass handle. //! returns WNT_WClass handle.
Standard_EXPORT static const Handle(MMgt_TShared)& WClass(); static const Handle(Standard_Transient)& WClass();
}; };
#endif // _ViewerTest_HeaderFile #endif // _ViewerTest_HeaderFile

View File

@ -247,15 +247,15 @@ static LRESULT WINAPI AdvViewerWindowProc(
//purpose : //purpose :
//============================================================================== //==============================================================================
const Handle(MMgt_TShared)& ViewerTest::WClass() const Handle(Standard_Transient)& ViewerTest::WClass()
{ {
static Handle(MMgt_TShared) theWClass; static Handle(Standard_Transient) theWClass;
#if defined(_WIN32) #if defined(_WIN32)
if (theWClass.IsNull()) if (theWClass.IsNull())
{ {
theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc,
CS_VREDRAW | CS_HREDRAW, 0, 0, CS_VREDRAW | CS_HREDRAW, 0, 0,
::LoadCursor (NULL, IDC_ARROW)); ::LoadCursorW (NULL, IDC_ARROW));
} }
#endif #endif
return theWClass; return theWClass;
@ -451,8 +451,8 @@ void SetWindowTitle (const Handle(Aspect_Window)& theWindow,
Standard_CString theTitle) Standard_CString theTitle)
{ {
#if defined(_WIN32) #if defined(_WIN32)
SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), const TCollection_ExtendedString theTitleW (theTitle);
theTitle); SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString());
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle);
#else #else
@ -2007,7 +2007,7 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
const Handle(V3d_View)& aView = ViewerTest::CurrentView(); const Handle(V3d_View)& aView = ViewerTest::CurrentView();
if (aView.IsNull()) if (aView.IsNull())
{ {
return DefWindowProc( hwnd, Msg, wParam, lParam ); return DefWindowProcW (hwnd, Msg, wParam, lParam);
} }
PAINTSTRUCT ps; PAINTSTRUCT ps;
@ -2175,14 +2175,11 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
break; break;
default: default:
return( DefWindowProc( hwnd, Msg, wParam, lParam )); return DefWindowProcW (hwnd, Msg, wParam, lParam);
} }
return 0L; return 0L;
} }
//============================================================================== //==============================================================================
//function : ViewerMainLoop //function : ViewerMainLoop
//purpose : Get a Event on the view and dispatch it //purpose : Get a Event on the view and dispatch it
@ -2203,9 +2200,10 @@ int ViewerMainLoop(Standard_Integer argc, const char** argv)
while ( Ppick == 1 ) { while ( Ppick == 1 ) {
// Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
if (GetMessage(&msg, NULL, 0, 0) ) { if (GetMessageW (&msg, NULL, 0, 0))
TranslateMessage(&msg); {
DispatchMessage(&msg); TranslateMessage (&msg);
DispatchMessageW (&msg);
} }
} }
@ -9489,7 +9487,7 @@ static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
Standard_Boolean toExit = Standard_False; Standard_Boolean toExit = Standard_False;
MSG aMsg; MSG aMsg;
while (PeekMessage (&aMsg, NULL, 0, 0, PM_REMOVE)) while (PeekMessageW (&aMsg, NULL, 0, 0, PM_REMOVE))
{ {
if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b)) if (aMsg.message == WM_KEYDOWN && (aMsg.wParam == 0x0d || aMsg.wParam == 0x1b))
{ {
@ -9497,7 +9495,7 @@ static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
} }
TranslateMessage (&aMsg); TranslateMessage (&aMsg);
DispatchMessage (&aMsg); DispatchMessageW (&aMsg);
} }
if (toExit) if (toExit)

View File

@ -4,7 +4,6 @@ WNT_OrientationType.hxx
WNT_Uint.hxx WNT_Uint.hxx
WNT_WClass.cxx WNT_WClass.cxx
WNT_WClass.hxx WNT_WClass.hxx
WNT_WClass.lxx
WNT_Window.cxx WNT_Window.cxx
WNT_Window.hxx WNT_Window.hxx
WNT_Window.lxx WNT_Window.lxx

View File

@ -16,69 +16,62 @@
#include <WNT_WClass.hxx> #include <WNT_WClass.hxx>
#include <Standard_PCharacter.hxx> #include <TCollection_ExtendedString.hxx>
#include <Standard_Type.hxx>
#include <WNT_ClassDefinitionError.hxx> #include <WNT_ClassDefinitionError.hxx>
#include <WNT_Window.hxx> #include <WNT_Window.hxx>
#if defined(_WIN32) && !defined(OCCT_UWP) #if defined(_WIN32) && !defined(OCCT_UWP)
#include <string.h> IMPLEMENT_STANDARD_RTTIEXT(WNT_WClass, Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT(WNT_WClass,MMgt_TShared)
//======================================================================= //=======================================================================
//function : WNT_WClass //function : WNT_WClass
//purpose : //purpose :
//======================================================================= //=======================================================================
WNT_WClass::WNT_WClass ( WNT_WClass::WNT_WClass (const TCollection_AsciiString& theClassName,
const Standard_CString aClassName, const Standard_Address theWndProc,
const Standard_Address aWndProc, const WNT_Uint& theStyle,
const WNT_Uint& aStyle, const Standard_Integer theClassExtra,
const Standard_Integer aClassExtra, const Standard_Integer theWindowExtra,
const Standard_Integer aWindowExtra, const Aspect_Handle theCursor,
const Aspect_Handle aCursor, const Aspect_Handle theIcon,
const Aspect_Handle anIcon, const TCollection_AsciiString& theMenuName)
const Standard_CString aMenuName : myClassName (theClassName),
) { myAppInstance (GetModuleHandleW (NULL)),
myWndProc (NULL)
WNDCLASS wc; {
const TCollection_ExtendedString aClassNameW (theClassName);
hInstance = GetModuleHandle ( NULL ); const TCollection_ExtendedString aMenuNameW (theMenuName);
WNDCLASSW aWinClass;
wc.style = aStyle; aWinClass.style = theStyle;
wc.lpfnWndProc = ( aWndProc ) ? ( WNDPROC )aWndProc : DefWindowProc; aWinClass.lpfnWndProc = theWndProc != NULL ? (WNDPROC )theWndProc : DefWindowProcW;
wc.cbClsExtra = aClassExtra; aWinClass.cbClsExtra = theClassExtra;
wc.cbWndExtra = aWindowExtra; aWinClass.cbWndExtra = theWindowExtra;
wc.hInstance = ( HINSTANCE )hInstance; aWinClass.hInstance = (HINSTANCE )myAppInstance;
wc.hIcon = ( anIcon ) ? ( HICON )anIcon : aWinClass.hIcon = theIcon != NULL ? (HICON )theIcon : LoadIconW (NULL, IDI_APPLICATION);
LoadIcon ( NULL, IDI_APPLICATION ); aWinClass.hCursor = theCursor != NULL ? (HCURSOR )theCursor : LoadCursorW (NULL, IDC_NO);
wc.hCursor = ( aCursor ) ? ( HCURSOR )aCursor : aWinClass.hbrBackground = 0;
LoadCursor ( NULL, IDC_NO ); aWinClass.lpszMenuName = !aMenuNameW.IsEmpty() ? aMenuNameW.ToWideString() : NULL;
wc.hbrBackground = 0; aWinClass.lpszClassName = aClassNameW.ToWideString();
wc.lpszMenuName = aMenuName; if (!RegisterClassW (&aWinClass))
wc.lpszClassName = aClassName; {
myClassName.Clear();
if ( !RegisterClass ( &wc ) ) WNT_ClassDefinitionError::Raise ("Unable to register window class");
}
WNT_ClassDefinitionError :: Raise ( "Unable to register window class" ); myWndProc = (Standard_Address )aWinClass.lpfnWndProc;
}
lpszName = new char[ strlen ( aClassName ) + 1 ];
strcpy ( (Standard_PCharacter)lpszName, aClassName );
lpfnWndProc = (void* )wc.lpfnWndProc;
} // end constructor
//======================================================================= //=======================================================================
//function : ~WNT_WClass //function : ~WNT_WClass
//purpose : //purpose :
//======================================================================= //=======================================================================
WNT_WClass::~WNT_WClass()
WNT_WClass::~WNT_WClass ()
{ {
if (!myClassName.IsEmpty())
UnregisterClass ( lpszName, ( HINSTANCE )hInstance ); {
delete [] (Standard_PCharacter)lpszName; const TCollection_ExtendedString aClassNameW (myClassName);
UnregisterClassW (aClassNameW.ToWideString(), (HINSTANCE )myAppInstance);
} // end WNT_WClass :: Destroy }
}
#endif // _WIN32 #endif // _WIN32

View File

@ -21,19 +21,14 @@
#if defined(_WIN32) && !defined(OCCT_UWP) #if defined(_WIN32) && !defined(OCCT_UWP)
#include <Standard_Type.hxx>
#include <Standard_CString.hxx>
#include <Aspect_Handle.hxx> #include <Aspect_Handle.hxx>
#include <Standard_Address.hxx> #include <Standard_Address.hxx>
#include <MMgt_TShared.hxx> #include <Standard_CString.hxx>
#include <WNT_Uint.hxx>
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
class WNT_ClassDefinitionError; #include <Standard_Transient.hxx>
class WNT_Window; #include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
#include <WNT_Uint.hxx>
class WNT_WClass;
DEFINE_STANDARD_HANDLE(WNT_WClass, MMgt_TShared)
//! This class defines a Windows NT window class. //! This class defines a Windows NT window class.
//! A window in Windows NT is always created based on a //! A window in Windows NT is always created based on a
@ -54,41 +49,43 @@ DEFINE_STANDARD_HANDLE(WNT_WClass, MMgt_TShared)
//! the Window class and do not use the WClass at all. //! the Window class and do not use the WClass at all.
//! We implemented this class for sake of flexibility of //! We implemented this class for sake of flexibility of
//! event processing. //! event processing.
class WNT_WClass : public MMgt_TShared class WNT_WClass : public Standard_Transient
{ {
friend class WNT_Window;
DEFINE_STANDARD_RTTIEXT(WNT_WClass, Standard_Transient)
public: public:
//! Creates a Windows NT window class and registers it. //! Creates a Windows NT window class and registers it.
Standard_EXPORT WNT_WClass(const Standard_CString aClassName, const Standard_Address aWndProc, const WNT_Uint& aStyle, const Standard_Integer aClassExtra = 0, const Standard_Integer aWindowExtra = 0, const Aspect_Handle aCursor = 0, const Aspect_Handle anIcon = 0, const Standard_CString aMenuName = 0); Standard_EXPORT WNT_WClass (const TCollection_AsciiString& theClassName,
const Standard_Address theWndProc,
const WNT_Uint& theStyle,
const Standard_Integer theClassExtra = 0,
const Standard_Integer theWindowExtra = 0,
const Aspect_Handle theCursor = NULL,
const Aspect_Handle theIcon = NULL,
const TCollection_AsciiString& theMenuName = TCollection_AsciiString());
//! Destroys all resources attached to the class //! Destroys all resources attached to the class
Standard_EXPORT ~WNT_WClass(); Standard_EXPORT ~WNT_WClass();
//! Returns address of window procedure. //! Returns address of window procedure.
Standard_Address WndProc() const; Standard_Address WndProc() const { return myWndProc; }
//! Returns a class name. //! Returns a class name.
Standard_CString Name() const; const TCollection_AsciiString& Name() const { return myClassName; }
//! Returns a program instance handle. //! Returns a program instance handle.
Aspect_Handle Instance() const; Aspect_Handle Instance() const { return myAppInstance; }
friend class WNT_Window;
DEFINE_STANDARD_RTTIEXT(WNT_WClass,MMgt_TShared)
protected: protected:
Standard_CString lpszName; TCollection_AsciiString myClassName;
Aspect_Handle hInstance; Aspect_Handle myAppInstance;
Standard_Address lpfnWndProc; Standard_Address myWndProc;
}; };
#include <WNT_WClass.lxx> DEFINE_STANDARD_HANDLE(WNT_WClass, Standard_Transient)
#endif // _WIN32 #endif // _WIN32
#endif // _WNT_WClass_HeaderFile #endif // _WNT_WClass_HeaderFile

View File

@ -1,31 +0,0 @@
// Copyright (c) 1996-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// 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 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.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
inline Standard_CString WNT_WClass :: Name () const {
return lpszName;
} // end WNT_WClass :: Name
inline Aspect_Handle WNT_WClass :: Instance () const {
return hInstance;
} // end WNT_WClass :: Instance
inline Standard_Address WNT_WClass :: WndProc () const {
return lpfnWndProc;
} // end WNT_WClass :: WndProc

View File

@ -22,13 +22,11 @@
#include <Aspect_Convert.hxx> #include <Aspect_Convert.hxx>
#include <Aspect_WindowDefinitionError.hxx> #include <Aspect_WindowDefinitionError.hxx>
#include <Aspect_WindowError.hxx> #include <Aspect_WindowError.hxx>
#include <Image_AlienPixMap.hxx>
#include <Standard_Type.hxx> #include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
#include <WNT_WClass.hxx> #include <WNT_WClass.hxx>
#include <stdio.h> IMPLEMENT_STANDARD_RTTIEXT(WNT_Window, Aspect_Window)
IMPLEMENT_STANDARD_RTTIEXT(WNT_Window,Aspect_Window)
// ======================================================================= // =======================================================================
// function : WNT_Window // function : WNT_Window
@ -53,45 +51,43 @@ WNT_Window::WNT_Window (const Standard_CString theTitle,
myWClass (theClass), myWClass (theClass),
myIsForeign (Standard_False) myIsForeign (Standard_False)
{ {
DWORD dwStyle = theStyle;
if (thePxWidth <= 0 || thePxHeight <= 0) if (thePxWidth <= 0 || thePxHeight <= 0)
{ {
Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range"); Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
} }
DWORD aStyle = theStyle;
if (theParent && !(theStyle & WS_CHILD)) if (theParent && !(theStyle & WS_CHILD))
{ {
dwStyle |= WS_CHILD | WS_CLIPSIBLINGS; aStyle |= WS_CHILD | WS_CLIPSIBLINGS;
} }
else if (!theParent && !(theStyle & WS_CLIPCHILDREN)) else if (!theParent && !(theStyle & WS_CLIPCHILDREN))
{ {
dwStyle |= WS_CLIPCHILDREN; aStyle |= WS_CLIPCHILDREN;
} }
// include decorations in the window dimensions // include decorations in the window dimensions to reproduce same behavior of Xw_Window
// to reproduce same behaviour of Xw_Window.
RECT aRect; RECT aRect;
aRect.top = aYTop; aRect.top = aYTop;
aRect.bottom = aYBottom; aRect.bottom = aYBottom;
aRect.left = aXLeft; aRect.left = aXLeft;
aRect.right = aXRight; aRect.right = aXRight;
AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE); AdjustWindowRect (&aRect, aStyle, theMenu != NULL ? TRUE : FALSE);
aXLeft = aRect.left; aXLeft = aRect.left;
aYTop = aRect.top; aYTop = aRect.top;
aXRight = aRect.right; aXRight = aRect.right;
aYBottom = aRect.bottom; aYBottom = aRect.bottom;
myHWindow = CreateWindow ( const TCollection_ExtendedString aTitleW (theTitle);
myWClass->Name(), // window's class name const TCollection_ExtendedString aClassNameW (myWClass->Name());
theTitle, // window's name myHWindow = CreateWindowW (aClassNameW.ToWideString(), aTitleW.ToWideString(),
dwStyle, // window's style aStyle,
aXLeft, aYTop, // window's coordinates aXLeft, aYTop,
(aXRight - aXLeft), (aYBottom - aYTop), (aXRight - aXLeft), (aYBottom - aYTop),
(HWND )theParent, // window's parent (HWND )theParent,
(HMENU )theMenu, // window's menu (HMENU )theMenu,
(HINSTANCE )myWClass->Instance(), // application's instance (HINSTANCE )myWClass->Instance(),
theClientStruct); // pointer to CLIENTCREATESTRUCT theClientStruct);
if (!myHWindow) if (!myHWindow)
{ {
Aspect_WindowDefinitionError::Raise ("Unable to create window"); Aspect_WindowDefinitionError::Raise ("Unable to create window");
@ -146,7 +142,7 @@ WNT_Window::~WNT_Window()
// ======================================================================= // =======================================================================
void WNT_Window::SetCursor (const Aspect_Handle theCursor) const void WNT_Window::SetCursor (const Aspect_Handle theCursor) const
{ {
::SetClassLongPtr ((HWND )myHWindow, GCLP_HCURSOR, (LONG_PTR )theCursor); ::SetClassLongPtrW ((HWND )myHWindow, GCLP_HCURSOR, (LONG_PTR )theCursor);
} }
// ======================================================================= // =======================================================================