diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c2510ee1b..174cdeea6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,11 @@ endif() # the name of the project project (OCCT) +if (WIN32) + add_definitions(-DUNICODE) + add_definitions(-D_UNICODE) +endif() + # include occt macros OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/occt_macros") diff --git a/adm/genproj.tcl b/adm/genproj.tcl index 88fb1e091b..57848aa3bc 100644 --- a/adm/genproj.tcl +++ b/adm/genproj.tcl @@ -1154,7 +1154,7 @@ proc osutils:vcproj:readtemplate {theVcVer isexec} { set aVerExt "v${aVerExt}0" set aCmpl32 "" set aCmpl64 "" - set aCharSet "MultiByte" + set aCharSet "Unicode" if { $isexec } { set anExt "${anExt}x" set what "$what executable" @@ -1175,7 +1175,6 @@ proc osutils:vcproj:readtemplate {theVcVer isexec} { } set aCmpl${bitness} "[set aCmpl${bitness}]${indent}${UwpWinRt}" } - set aCharSet "Unicode" } foreach bitness {32 64} { diff --git a/src/Draw/COMMANDWINDOW.h b/src/Draw/COMMANDWINDOW.h index 6077ca198d..01304f33f7 100644 --- a/src/Draw/COMMANDWINDOW.h +++ b/src/Draw/COMMANDWINDOW.h @@ -17,12 +17,12 @@ #ifdef _WIN32 -#define COMMANDCLASS "COMMANDWINDOW" -#define COMMANDTITLE "Command Window" +#define COMMANDCLASS L"COMMANDWINDOW" +#define COMMANDTITLE L"Command Window" HWND CreateCommandWindow(HWND, int); -LONG APIENTRY CommandProc(HWND, UINT, WPARAM, LONG); +LRESULT APIENTRY CommandProc(HWND, UINT, WPARAM, LPARAM); BOOL CommandCreateProc(HWND); VOID CommandDestroyProc(HWND); BOOL CommandHandler(HWND, WPARAM, LPARAM); diff --git a/src/Draw/CommandWindow.cxx b/src/Draw/CommandWindow.cxx index 52f2f91a13..e7bf906535 100644 --- a/src/Draw/CommandWindow.cxx +++ b/src/Draw/CommandWindow.cxx @@ -17,50 +17,36 @@ #ifdef _WIN32 #include -#define COMMANDCLASS "COMMANDWINDOW" -#define COMMANDTITLE "Command Window" - #include #include #include #include - - - -/****************************************************\ -* CommandWindow.cxx : -* -\****************************************************/ - - +#include #define CLIENTWND 0 -#define PROMPT "Command >> " +#define THE_PROMPT L"Command >> " #define COMMANDSIZE 1000 // Max nb of characters for a command +Standard_Boolean Draw_Interprete (const char* command); -// Definition of global variables -#ifdef STRICT - WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class) -#else - FARPROC OldEditProc; -#endif +namespace +{ + // Definition of global variables + static WNDPROC OldEditProc; // Save the standard procedure of the edition (sub-class) +} /*--------------------------------------------------------*\ | CREATE COMMAND WINDOW PROCEDURE \*--------------------------------------------------------*/ HWND CreateCommandWindow(HWND hWnd, int /*nitem*/) { - HINSTANCE hInstance; - hInstance = (HINSTANCE)GetWindowLongPtr(hWnd,GWLP_HINSTANCE); + HINSTANCE hInstance = (HINSTANCE )GetWindowLongPtrW (hWnd, GWLP_HINSTANCE); - HWND hWndCommand = (CreateWindow(COMMANDCLASS, COMMANDTITLE, - WS_CLIPCHILDREN | WS_OVERLAPPED | - WS_THICKFRAME | WS_CAPTION , - 0, 0, - 400, 100, - hWnd, NULL, hInstance, NULL)); + HWND hWndCommand = CreateWindowW (COMMANDCLASS, COMMANDTITLE, + WS_CLIPCHILDREN | WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION, + 0, 0, 400, 100, + hWnd, NULL, hInstance, NULL); ShowWindow(hWndCommand, SW_SHOW); return hWndCommand; @@ -72,185 +58,180 @@ HWND CreateCommandWindow(HWND hWnd, int /*nitem*/) \*--------------------------------------------------------*/ LRESULT APIENTRY CommandProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam ) { - HWND hWndEdit; - MINMAXINFO* lpmmi; - - switch(wMsg) + switch (wMsg) { - case WM_CREATE : - CommandCreateProc(hWnd); - hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND); - SendMessage(hWndEdit,EM_REPLACESEL, 0,(LPARAM)PROMPT); - break; - - case WM_GETMINMAXINFO : - lpmmi = (LPMINMAXINFO)lParam; - lpmmi->ptMinTrackSize.x = 200; - lpmmi->ptMinTrackSize.y = 50; - break; - - case WM_SIZE : + case WM_CREATE: { - hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND); - MoveWindow(hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); - // Place the cursor at the end of the buffer - // Nb of characters in the buffer of hWndEdit - LRESULT index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l); - SendMessage(hWnd, EM_SETSEL, index, index); - break; + CommandCreateProc (hWnd); + HWND hWndEdit = (HWND )GetWindowLongPtrW (hWnd, CLIENTWND); + SendMessageW (hWndEdit, EM_REPLACESEL, 0, (LPARAM )THE_PROMPT); + return 0; + } + case WM_GETMINMAXINFO: + { + MINMAXINFO* lpmmi = (MINMAXINFO* )lParam; + lpmmi->ptMinTrackSize.x = 200; + lpmmi->ptMinTrackSize.y = 50; + return 0; + } + case WM_SIZE: + { + HWND hWndEdit = (HWND )GetWindowLongPtrW(hWnd, CLIENTWND); + MoveWindow (hWndEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); + // Place the cursor at the end of the buffer + // Nb of characters in the buffer of hWndEdit + LRESULT index = SendMessageW (hWnd, WM_GETTEXTLENGTH, 0l, 0l); + SendMessageW (hWnd, EM_SETSEL, index, index); + return 0; + } + case WM_SETFOCUS: + { + HWND hWndEdit = (HWND )GetWindowLongPtrW (hWnd, CLIENTWND); + SetFocus (hWndEdit); + return 0; } - - case WM_SETFOCUS : - hWndEdit = (HWND)GetWindowLongPtr(hWnd, CLIENTWND); - SetFocus(hWndEdit); - break; - - default : - return(DefWindowProc(hWnd, wMsg, wParam, lParam)); } - return(0l); + return DefWindowProcW(hWnd, wMsg, wParam, lParam); } - - LRESULT APIENTRY EditProc(HWND, UINT, WPARAM, LPARAM); /*--------------------------------------------------------*\ | COMMAND CREATE PROCEDURE \*--------------------------------------------------------*/ BOOL CommandCreateProc(HWND hWnd) { + HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE); + HWND hWndEdit = CreateWindowW (L"EDIT", NULL, + WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, + 0, 0, 0, 0, + hWnd, 0, + hInstance, NULL); - HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); + // Save hWndEdit in the extra memory in 0 of CommandWindow + if (hWndEdit != NULL) + { + SetWindowLongPtrW (hWnd, CLIENTWND, (LONG_PTR )hWndEdit); + } - HWND hWndEdit = CreateWindow("EDIT",NULL, - WS_CHILD | WS_VISIBLE | WS_VSCROLL | - ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, - 0, 0, 0, 0, - hWnd, 0, - hInstance, NULL); - - // Save hWndEdit in the extra memory in 0 of CommandWindow - if (hWndEdit) - SetWindowLongPtr(hWnd, CLIENTWND, (LONG_PTR)hWndEdit); - - // Sub-Class of the window - //------- - // Save the pointer on the existing procedure - #ifdef STRICT - OldEditProc = (WNDPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC); - #else - OldEditProc = (FARPROC)GetWindowLongPtr(hWndEdit, GWLP_WNDPROC); - #endif - // Implement the new function - SetWindowLongPtr(hWndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc); - - return(TRUE); + // Sub-Class of the window + //------- + // Save the pointer on the existing procedure + OldEditProc = (WNDPROC )GetWindowLongPtrW (hWndEdit, GWLP_WNDPROC); + // Implement the new function + SetWindowLongPtrW (hWndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc); + return TRUE; } - /*--------------------------------------------------------*\ | GET COMMAND | \*--------------------------------------------------------*/ -int GetCommand(HWND hWnd, char* buffer) +int GetCommand (HWND hWnd, wchar_t* theBuffer) { - int again = 1; - char temp[COMMANDSIZE]=""; + bool isAgain = true; + wchar_t aTempBuff[COMMANDSIZE] = L""; - int nbLine = (int )SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l); - - int nbChar = 0; - buffer[0]='\0'; - while ( again && nbLine > -1 && nbChar < COMMANDSIZE-1) - { - strcat(buffer, strrev(temp)); - // Initialization of the 1st WORD to the nb of characters to read - WORD* nbMaxChar = (WORD*)temp; - *nbMaxChar = COMMANDSIZE-1; + int aNbLine = (int )SendMessageW (hWnd, EM_GETLINECOUNT, 0l, 0l); + int aNbChar = 0; + theBuffer[0] = L'\0'; + while (isAgain && aNbLine > -1 && aNbChar < COMMANDSIZE - 1) + { + wcscat (theBuffer, _wcsrev (aTempBuff)); + // Initialization of the 1st WORD to the nb of characters to read + WORD* aNbMaxChar = (WORD* )aTempBuff; + *aNbMaxChar = COMMANDSIZE - 1; - int nbCharRead = (int )SendMessage(hWnd, EM_GETLINE, nbLine-1, (LPARAM)temp); - nbChar += nbCharRead ; - int cmp = strncmp(temp, PROMPT, 10); - temp[nbCharRead]='\0'; - if( cmp == 0 ) - { - strcat(buffer, strrev(temp)); - again = 0; - } - nbLine -= 1; - } - strrev(buffer); - return nbChar; + const int aNbCharRead = (int )SendMessageW (hWnd, EM_GETLINE, aNbLine - 1, (LPARAM )aTempBuff); + aNbChar += aNbCharRead; + const bool isPromp = wcsncmp (aTempBuff, THE_PROMPT, 10) == 0; + aTempBuff[aNbCharRead]='\0'; + if (isPromp) + { + wcscat (theBuffer, _wcsrev (aTempBuff)); + isAgain = false; + } + aNbLine -= 1; + } + _wcsrev (theBuffer); + return aNbChar; } extern console_semaphore_value volatile console_semaphore; -extern char console_command[1000]; +extern wchar_t console_command[1000]; /*--------------------------------------------------------*\ | EDIT WINDOW PROCEDURE \*--------------------------------------------------------*/ 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 - LRESULT index; - - switch(wMsg) + switch (wMsg) { - case WM_CHAR : - if (console_semaphore != WAIT_CONSOLE_COMMAND) - return 0l; - switch(LOWORD(wParam)) - { - // Overload of character \n - case 0x0d : - GetCommand(hWnd, buffer); - // Standard processing - CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam); - // Display of PROMPT - rep = GetCaretPos(&pos); - SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)PROMPT); - // Display the command in the console - cout << buffer << endl; - /*if (Draw_Interprete(buffer+strlen(PROMPT))== -2) - DestroyProc(hWnd); */ - strcpy(console_command, buffer+strlen(PROMPT)); - console_semaphore = HAS_CONSOLE_COMMAND; - // Purge the buffer - nbline = SendMessage(hWnd, EM_GETLINECOUNT, 0l, 0l); - if(nbline > 200) - { - nbline = 0; - GetCommand(hWnd, buffer); - index = SendMessage(hWnd, EM_LINEINDEX, 100, 0); - SendMessage(hWnd, EM_SETSEL, 0, index); - SendMessage(hWnd, WM_CUT, 0, 0); - // Place the cursor at the end of text - index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l); - SendMessage(hWnd, EM_SETSEL, index, index); - } - return(0l); - break; - default : - if (IsAlphanumeric((Standard_Character)LOWORD(wParam))) - { - // Place the cursor at the end of text before display - index = SendMessage(hWnd, WM_GETTEXTLENGTH, 0l, 0l); - SendMessage(hWnd, EM_SETSEL, index, index); - CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam); - return 0l; - } - break; - } - break; - case WM_KEYDOWN: - if (console_semaphore != WAIT_CONSOLE_COMMAND) - return 0l; + case WM_CHAR: + { + if (console_semaphore != WAIT_CONSOLE_COMMAND) + { + return 0; + } + switch (LOWORD(wParam)) + { + // Overload of character \n + case 0x0d: + { + wchar_t aCmdBuffer[COMMANDSIZE]; + GetCommand (hWnd, aCmdBuffer); + // Standard processing + CallWindowProcW (OldEditProc, hWnd, wMsg, wParam, lParam); + // Display of PROMPT + POINT pos; + GetCaretPos (&pos); + SendMessageW (hWnd, EM_REPLACESEL, 0, (LPARAM )THE_PROMPT); + // Display the command in the console + std::wcout << aCmdBuffer << std::endl; + //TCollection_AsciiString aCmdUtf8 (aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1); + //Draw_Interprete (aCmdUtf8.ToCString()); + //if (toExit) { DestroyProc (hWnd); } + wcscpy (console_command, aCmdBuffer + sizeof(THE_PROMPT) / sizeof(wchar_t) - 1); + console_semaphore = HAS_CONSOLE_COMMAND; + // Purge the buffer + nbline = SendMessageW (hWnd, EM_GETLINECOUNT, 0l, 0l); + if (nbline > 200) + { + nbline = 0; + GetCommand (hWnd, aCmdBuffer); + LRESULT index = SendMessageW (hWnd, EM_LINEINDEX, 100, 0); + SendMessageW (hWnd, EM_SETSEL, 0, index); + SendMessageW (hWnd, WM_CUT, 0, 0); + // Place the cursor at the end of text + index = SendMessageW (hWnd, WM_GETTEXTLENGTH, 0l, 0l); + SendMessageW (hWnd, EM_SETSEL, index, index); + } + return 0; + } + default: + { + if (IsAlphanumeric ((Standard_Character)LOWORD(wParam))) + { + // Place the cursor at the end of text before display + LRESULT index = SendMessageW (hWnd, WM_GETTEXTLENGTH, 0l, 0l); + SendMessageW (hWnd, EM_SETSEL, index, index); + CallWindowProcW (OldEditProc, hWnd, wMsg, wParam, lParam); + return 0; + } + break; + } + } + break; + } + case WM_KEYDOWN: + { + if (console_semaphore != WAIT_CONSOLE_COMMAND) + { + return 0; + } + break; + } } - return CallWindowProc(OldEditProc, hWnd, wMsg, wParam, lParam); + return CallWindowProcW (OldEditProc, hWnd, wMsg, wParam, lParam); } #endif - - diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index 216ade1ec0..f1d79898d6 100644 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -78,21 +78,27 @@ Standard_EXPORT Standard_Boolean Draw_Interprete(const char* command); // ******************************************************************* #ifdef _WIN32 extern console_semaphore_value volatile console_semaphore; -extern char console_command[1000]; +extern wchar_t console_command[1000]; #endif static void ReadInitFile (const TCollection_AsciiString& theFileName) { TCollection_AsciiString aPath = theFileName; #ifdef _WIN32 - if (!Draw_Batch) { - try { + if (!Draw_Batch) + { + try + { 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; while (console_semaphore == HAS_CONSOLE_COMMAND) + { Sleep(10); + } } catch(...) { cout << "Error while reading a script file." << endl; @@ -100,8 +106,8 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName) } } else { #endif - char* com = new char [aPath.Length() + strlen ("source ") + 2]; - Sprintf (com, "source %s", aPath.ToCString()); + char* com = new char [aPath.Length() + strlen ("source -encoding utf-8 ") + 2]; + Sprintf (com, "source -encoding utf-8 %s", aPath.ToCString()); Draw_Interprete (com); delete [] com; #ifdef _WIN32 @@ -140,32 +146,31 @@ void exitProc(ClientData /*dc*/) // main // ******************************************************************* #ifdef _WIN32 -//Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lps -Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszLine, int nShow,const FDraw_InitAppli Draw_InitAppli) +Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, int nShow, int argc, wchar_t** argv, const FDraw_InitAppli Draw_InitAppli) #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 { // prepend extra DLL search path to override system libraries like opengl32.dll #ifdef _WIN32 OSD_Environment aUserDllEnv ("CSF_UserDllPath"); - TCollection_AsciiString aUserDllPath = aUserDllEnv.Value(); + const TCollection_ExtendedString aUserDllPath (aUserDllEnv.Value()); if (!aUserDllPath.IsEmpty()) { // This function available since Win XP SP1 #if (_WIN32_WINNT >= 0x0502). // We retrieve dynamically here (kernel32 should be always preloaded). - typedef BOOL (WINAPI *SetDllDirectoryA_t)(const char* thePathName); - HMODULE aKern32Module = GetModuleHandleA ("kernel32"); - SetDllDirectoryA_t aFunc = (aKern32Module != NULL) - ? (SetDllDirectoryA_t )GetProcAddress (aKern32Module, "SetDllDirectoryA") : NULL; + typedef BOOL (WINAPI *SetDllDirectoryW_t)(const wchar_t* thePathName); + HMODULE aKern32Module = GetModuleHandleW (L"kernel32"); + SetDllDirectoryW_t aFunc = (aKern32Module != NULL) + ? (SetDllDirectoryW_t )GetProcAddress (aKern32Module, "SetDllDirectoryW") : NULL; if (aFunc != NULL) { - aFunc (aUserDllPath.ToCString()); + aFunc (aUserDllPath.ToWideString()); } else { - //std::cerr << "SetDllDirectoryA() is not available on this system!\n"; + //std::cerr << "SetDllDirectoryW() is not available on this system!\n"; } if (aKern32Module != NULL) { @@ -179,64 +184,71 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In // ***************************************************************** Draw_Batch = Standard_False; TCollection_AsciiString aRunFile, aCommand; - Standard_Integer i; 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 - for (i = 1; i < argc; i++) { - if (strcasecmp (argv[i], "-h") == 0 || strcasecmp (argv[i], "--help") == 0) + for (int anArgIter = 1; anArgIter < argc; ++anArgIter) + { + TCollection_AsciiString anArg (argv[anArgIter]); + anArg.LowerCase(); + if (anArg == "-h" + || anArg == "--help") { - cout << "Open CASCADE " << OCC_VERSION_STRING_EXT << " DRAW Test Harness" << endl << endl; - cout << "Options: " << endl; - cout << " -b: batch mode (no GUI, no viewers)" << endl; - cout << " -v: no GUI, use virtual (off-screen) windows for viewers" << endl; - cout << " -i: interactive mode" << endl; - cout << " -f file: execute script from file" << endl; - cout << " -c command args...: execute command (with optional arguments)" << endl << endl; - cout << "Options -b, -v, and -i are mutually exclusive." << endl; - cout << "If -c or -f are given, -v is default; otherwise default is -i." << endl; - cout << "Options -c and -f are alternatives and should be at the end " << endl; - cout << "of the command line. " << endl; - cout << "Option -c can accept set of commands separated by ';'." << endl; + std::cout << "Open CASCADE " << OCC_VERSION_STRING_EXT << " DRAW Test Harness\n\n"; + std::cout << "Options:\n"; + std::cout << " -b: batch mode (no GUI, no viewers)\n"; + std::cout << " -v: no GUI, use virtual (off-screen) windows for viewers\n"; + std::cout << " -i: interactive mode\n"; + std::cout << " -f file: execute script from file\n"; + 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; } - else if (strcasecmp (argv[i], "-b") == 0) + else if (anArg == "-b") + { Draw_Batch = Standard_True; - else if (strcasecmp (argv[i], "-v") == 0) { + } + else if (anArg == "-v") + { // force virtual windows Draw_VirtualWindows = Standard_True; - } else if (strcasecmp (argv[i], "-i") == 0) { + } + else if (anArg == "-i") + { // force interactive Draw_VirtualWindows = Standard_False; 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; - if (++i < argc) { - aRunFile = TCollection_AsciiString (argv[i]); + if (++anArgIter < argc) + { + aRunFile = TCollection_AsciiString (argv[anArgIter]); } break; - } else if (strcasecmp (argv[i], "-c") == 0) { // -c option should be LAST! + } + else if (anArg == "-c") // -c option should be LAST! + { Draw_VirtualWindows = !isInteractiveForced; - if (++i < argc) { - aCommand = TCollection_AsciiString (argv[i]); + if (++anArgIter < argc) + { + aCommand = TCollection_AsciiString (argv[anArgIter]); } - while (++i < argc) { + while (++anArgIter < argc) + { aCommand.AssignCat (" "); - aCommand.AssignCat (argv[i]); + aCommand.AssignCat (argv[anArgIter]); } 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; XLoop = !Draw_Batch; - if (XLoop) { + if (XLoop) + { // Default colors - for (i=0;i"; - i = -1; + int i = -1; do { cin.get(cmd[++i]); } while ((cmd[i] != '\n') && (!cin.fail())); @@ -396,7 +412,10 @@ Standard_Boolean Draw_Interprete(const char* com) 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 Tcl_ExternalToUtfDString ( NULL, com, -1, &command ); #else @@ -435,7 +454,14 @@ Standard_Boolean Draw_Interprete(const char* com) dout.Flush(); 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) { tictac.Stop(); diff --git a/src/Draw/Draw_Appli.hxx b/src/Draw/Draw_Appli.hxx index 4df133cf8e..f529b2c935 100644 --- a/src/Draw/Draw_Appli.hxx +++ b/src/Draw/Draw_Appli.hxx @@ -14,16 +14,9 @@ // Alternatively, this file may be used under the terms of Open CASCADE // 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 #define Draw_Appli_HeaderFile - #include #include @@ -31,11 +24,11 @@ typedef void (*FDraw_InitAppli)(Draw_Interpretor&); #ifdef _WIN32 #include -//extern void Draw_Appli(HINSTANCE,HINSTANCE,LPSTR,int); -Standard_EXPORT void Draw_Appli(HINSTANCE,HINSTANCE,LPSTR,int, - const FDraw_InitAppli Draw_InitAppli); +Standard_EXPORT void Draw_Appli(HINSTANCE,HINSTANCE,int, + int argc, wchar_t** argv, + const FDraw_InitAppli Draw_InitAppli); #else -extern void Draw_Appli(Standard_Integer argc, char** argv, +extern void Draw_Appli(int argc, char** argv, const FDraw_InitAppli Draw_InitAppli); #endif diff --git a/src/Draw/Draw_Main.cxx b/src/Draw/Draw_Main.cxx index c33a54f77a..de9ad382bf 100644 --- a/src/Draw/Draw_Main.cxx +++ b/src/Draw/Draw_Main.cxx @@ -14,35 +14,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // 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 -#include /* SW_SHOW */ +#include #endif #include @@ -50,6 +23,7 @@ #include #include #include +#include #include @@ -94,18 +68,18 @@ extern Standard_Boolean Draw_IsConsoleSubsystem; Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDraw_InitAppli fDraw_InitAppli) { Draw_IsConsoleSubsystem = Standard_True; - //return _WinMain_(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli); theDraw_InitAppli = fDraw_InitAppli; - //ParseCommandLine(GetCommandLine()); // MKV 01.02.05 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) Tcl_FindExecutable(argv[0]); #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; - } //======================================================================= @@ -113,11 +87,13 @@ Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDr //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; -// ParseCommandLine (lpCmdLine); -// Draw_Appli(hInstance, hPrevinstance, lpCmdLine, nCmdShow, Draw_InitAppli); // for C30; + theDraw_InitAppli = fDraw_InitAppli; + int aNbArgs = 0; + wchar_t** anArgVec = CommandLineToArgvW(GetCommandLineW(), &aNbArgs); + Draw_Appli (hInstance, hPrevinstance, nCmdShow, aNbArgs, anArgVec, fDraw_InitAppli); + LocalFree (anArgVec); return 0; } #else @@ -136,4 +112,3 @@ Standard_Integer _main_ (Standard_Integer argc, char* argv[], const FDraw_InitAp return 0; } #endif - diff --git a/src/Draw/Draw_Viewer.cxx b/src/Draw/Draw_Viewer.cxx index 9f5f031a5e..ec9848f662 100644 --- a/src/Draw/Draw_Viewer.cxx +++ b/src/Draw/Draw_Viewer.cxx @@ -14,11 +14,6 @@ // Alternatively, this file may be used under the terms of Open CASCADE // 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 #include @@ -26,7 +21,7 @@ #include #include #include - +#include #define precpers 0.95 #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) { if (Draw_Batch) return; - if(myViews[id]) myViews[id]->SetTitle((char*)name); + if(myViews[id]) myViews[id]->SetTitle (name); } //======================================================================= diff --git a/src/Draw/Draw_Window.cxx b/src/Draw/Draw_Window.cxx index 1948e0aca6..ab84f6976c 100644 --- a/src/Draw/Draw_Window.cxx +++ b/src/Draw/Draw_Window.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -526,20 +527,20 @@ Standard_Integer Draw_Window::WidthWin() const //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); } //======================================================================= @@ -1332,7 +1333,7 @@ int modeTab[16] = {R2_BLACK, R2_MASKPEN, R2_MASKPENNOT, R2_COPYPEN, 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); @@ -1344,10 +1345,9 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int nitem) 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); @@ -1360,43 +1360,46 @@ HWND DrawWindow::CreateDrawWindow(HWND hWndClient, int 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) - { - if (Draw_IsConsoleSubsystem) - return (DefWindowProc(hWnd, wMsg, wParam, lParam)); - else - return(DefMDIChildProc(hWnd, wMsg, wParam, lParam)); - } - - 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; - } - - 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); } + + switch (wMsg) + { + case WM_PAINT: + { + PAINTSTRUCT ps; + BeginPaint (hWnd, &ps); + if (localObjet->GetUseBuffer()) + { + localObjet->Redraw(); + } + else + { + localObjet->WExpose(); + } + EndPaint (hWnd, &ps); + return 0; + } + case WM_SIZE: + { + if (localObjet->GetUseBuffer()) + { + localObjet->InitBuffer(); + localObjet->WExpose(); + localObjet->Redraw(); + return 0; + } + break; + } + } + 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 // 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; @@ -1502,7 +1505,7 @@ void DrawWindow::Init(Standard_Integer theXLeft, Standard_Integer theYTop, 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; @@ -1657,21 +1660,21 @@ Standard_Integer DrawWindow::WidthWin() const /*--------------------------------------------------------*\ | 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 -| 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); } @@ -1810,7 +1813,8 @@ void DrawWindow::DrawString(int x,int y, char* text) 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); @@ -1960,9 +1964,8 @@ static Tk_Window mainWindow; //* 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; /*--------------------------------------------------------*\ @@ -2031,16 +2034,41 @@ Standard_Boolean Draw_Interprete (const char*); /*--------------------------------------------------------*\ | 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; + } } } @@ -2065,9 +2093,23 @@ static DWORD WINAPI tkLoop(VOID) { 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 @@ -2128,7 +2170,8 @@ static DWORD WINAPI tkLoop(VOID) 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); } @@ -2176,9 +2219,9 @@ void Run_Appli(HWND hWnd) 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 } } @@ -2187,12 +2230,12 @@ void Run_Appli(HWND hWnd) 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); @@ -2218,10 +2261,12 @@ void DrawWindow::SelectWait(HANDLE& hWnd, int& x, int& y, int& button) 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); @@ -2241,11 +2286,13 @@ void DrawWindow::SelectNoWait(HANDLE& hWnd, int& x, int& y, int& button) 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); diff --git a/src/Draw/Draw_Window.hxx b/src/Draw/Draw_Window.hxx index 6bab470838..55c9629763 100644 --- a/src/Draw/Draw_Window.hxx +++ b/src/Draw/Draw_Window.hxx @@ -19,6 +19,7 @@ #include #include +#include #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) @@ -116,8 +117,8 @@ class Draw_Window Standard_Integer HeightWin() const; Standard_Integer WidthWin() const; - void SetTitle(const char* title); - char* GetTitle(); + void SetTitle (const TCollection_AsciiString& theTitle); + TCollection_AsciiString GetTitle() const; void DisplayWindow(); void Hide(); @@ -281,8 +282,8 @@ class Draw_Window Standard_Integer HeightWin() const; Standard_Integer WidthWin() const; - void SetTitle (Standard_CString theTitle); - Standard_CString GetTitle (); + void SetTitle (const TCollection_AsciiString& theTitle); + TCollection_AsciiString GetTitle() const; void DisplayWindow(); void Hide(); @@ -353,8 +354,8 @@ void GetNextEvent (Standard_Boolean theWait, #include -#define DRAWCLASS "DRAWWINDOW" -#define DRAWTITLE "Draw View" +#define DRAWCLASS L"DRAWWINDOW" +#define DRAWTITLE L"Draw View" #define MAXCOLOR 15 #if !defined(__Draw_API) && !defined(HAVE_NO_DLL) @@ -443,8 +444,8 @@ public: __Draw_API Standard_Integer WidthWin() const; //Title - __Draw_API void SetTitle(const char*); - __Draw_API char* GetTitle(); + __Draw_API void SetTitle (const TCollection_AsciiString& ); + __Draw_API TCollection_AsciiString GetTitle() const; //Affichage __Draw_API void DisplayWindow(); diff --git a/src/Draw/Draw_Window_1.mm b/src/Draw/Draw_Window_1.mm index 222d72881a..cb3c72964e 100644 --- a/src/Draw/Draw_Window_1.mm +++ b/src/Draw/Draw_Window_1.mm @@ -301,9 +301,9 @@ Standard_Integer Draw_Window::WidthWin() const //function : SetTitle //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]; [aTitleNs release]; } @@ -312,10 +312,10 @@ void Draw_Window::SetTitle (Standard_CString theTitle) //function : GetTitle //purpose : //======================================================================= -Standard_CString Draw_Window::GetTitle() +TCollection_AsciiString Draw_Window::GetTitle() const { Standard_CString aTitle = [[myWindow title] UTF8String]; - return aTitle; + return TCollection_AsciiString (aTitle); } //======================================================================= diff --git a/src/Draw/MainWindow.cxx b/src/Draw/MainWindow.cxx index ccbc4611ac..17ea35e2e4 100644 --- a/src/Draw/MainWindow.cxx +++ b/src/Draw/MainWindow.cxx @@ -35,33 +35,33 @@ extern Standard_Boolean Draw_IsConsoleSubsystem; \*--------------------------------------------------------*/ 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); + HWND hWndClient = (HWND )GetWindowLongPtrW (hWndFrame, CLIENTWND); + DrawWindow::hWndClientMDI = hWndClient; + if (!Draw_IsConsoleSubsystem) { - CreateProc(hWndFrame); - hWndClient = (HWND)GetWindowLongPtr(hWndFrame, CLIENTWND); - DrawWindow::hWndClientMDI = hWndClient; - if (!Draw_IsConsoleSubsystem) - CreateCommandWindow(hWndFrame,0); + CreateCommandWindow (hWndFrame, 0); } - break; - - 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 0; + } + case WM_COMMAND: + { + CmdProc (hWndFrame, LOWORD(wParam), wParam, lParam); + return 0; + } + case WM_DESTROY: + { + Draw_Interprete ("exit"); + DestroyProc (hWndFrame); + return 0; + } } - return(0l); + HWND hWndClient = (HWND)GetWindowLongPtrW(hWndFrame, CLIENTWND); + return DefFrameProcW(hWndFrame, hWndClient, wMsg, wParam, lParam); } @@ -76,7 +76,7 @@ BOOL CreateProc(HWND hWndFrame) if (hWnd != NULL) { // 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); } @@ -91,40 +91,50 @@ BOOL CreateProc(HWND hWndFrame) LRESULT APIENTRY CmdProc(HWND hWndFrame, UINT wMsg, WPARAM /*wParam*/, LPARAM /*lParam*/) { // Handle on window MDI - HWND hWndClient = (HWND)GetWindowLongPtr (hWndFrame, CLIENTWND); + HWND hWndClient = (HWND )GetWindowLongPtrW (hWndFrame, CLIENTWND); switch (wMsg) - { - case IDM_WINDOW_NEXT : - if(hWndClient) - { - HWND hWndActive = (HWND)SendMessage(hWndClient, WM_MDIGETACTIVE, 0, 0l); - SendMessage(hWndClient, WM_MDINEXT, (WPARAM)hWndActive, 0l); - } - break; - - case IDM_WINDOW_CASCADE : - if(hWndClient) - SendMessage(hWndClient, WM_MDICASCADE, 0, 0l); - break; - - 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; + { + case IDM_WINDOW_NEXT: + { + if (hWndClient != NULL) + { + HWND hWndActive = (HWND )SendMessageW (hWndClient, WM_MDIGETACTIVE, 0, 0l); + SendMessageW (hWndClient, WM_MDINEXT, (WPARAM )hWndActive, 0l); + } + break; + } + case IDM_WINDOW_CASCADE: + { + if (hWndClient != NULL) + { + SendMessageW (hWndClient, WM_MDICASCADE, 0, 0l); + } + break; + } + 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(0l); + return 0; } @@ -135,7 +145,7 @@ LRESULT APIENTRY CmdProc(HWND hWndFrame, UINT wMsg, WPARAM /*wParam*/, LPARAM /* \*--------------------------------------------------------------------------*/ VOID DestroyProc(HWND hWnd) { - HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); + HINSTANCE hInst = (HINSTANCE )GetWindowLongPtrW (hWnd, GWLP_HINSTANCE); Destroy_Appli(hInst); PostQuitMessage(0); diff --git a/src/Draw/init.cxx b/src/Draw/init.cxx index b61919814b..34d2176910 100644 --- a/src/Draw/init.cxx +++ b/src/Draw/init.cxx @@ -37,55 +37,55 @@ d\*--------------------------------------------------------*/ BOOL RegisterAppClass(HINSTANCE hInstance) { - WNDCLASS wndClass; + WNDCLASSW wndClass; // Parametres communs aux classes //----- wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC; wndClass.cbClsExtra = 0; - wndClass.hCursor = LoadCursor(NULL,IDC_ARROW); + wndClass.hCursor = LoadCursorW (NULL, IDC_ARROW); wndClass.hInstance = hInstance; // Enregistrement de la fenetre principale //----- - wndClass.cbWndExtra = sizeof(LONG); + wndClass.cbWndExtra = sizeof(void*); 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.lpszMenuName = MAKEINTRESOURCE(APPMENU); + wndClass.lpszMenuName = MAKEINTRESOURCEW(APPMENU); wndClass.lpszClassName = APPCLASS; - if(!RegisterClass(&wndClass)) + if(!RegisterClassW(&wndClass)) return(FALSE); // Enregistrement de la fenetre DrawWindow //------ - wndClass.cbWndExtra = sizeof(LONG); // Extra Memory + wndClass.cbWndExtra = sizeof(void*); // Extra Memory wndClass.lpfnWndProc = (WNDPROC)DrawWindow::DrawProc; wndClass.hIcon = 0; wndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = DRAWCLASS; - if(!RegisterClass(&wndClass)) + if(!RegisterClassW(&wndClass)) { - UnregisterClass(APPCLASS, hInstance); + UnregisterClassW(APPCLASS, hInstance); return(FALSE); } // Enregistrement de la fenetre CommandWindow //------ - wndClass.lpfnWndProc = (WNDPROC)CmdProc; + wndClass.lpfnWndProc = (WNDPROC)CommandProc; wndClass.hIcon = 0; wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = COMMANDCLASS; - if(!RegisterClass(&wndClass)) + if(!RegisterClassW(&wndClass)) { - UnregisterClass(APPCLASS, hInstance); - UnregisterClass(DRAWCLASS, hInstance); + UnregisterClassW(APPCLASS, hInstance); + UnregisterClassW(DRAWCLASS, hInstance); return(FALSE); } @@ -100,8 +100,8 @@ BOOL RegisterAppClass(HINSTANCE hInstance) \*--------------------------------------------------------*/ VOID UnregisterAppClass(HINSTANCE hInstance) { - UnregisterClass(APPCLASS, hInstance); - UnregisterClass(DRAWCLASS, hInstance); + UnregisterClassW(APPCLASS, hInstance); + UnregisterClassW(DRAWCLASS, hInstance); } @@ -112,7 +112,7 @@ VOID UnregisterAppClass(HINSTANCE hInstance) \*--------------------------------------------------------*/ HWND CreateAppWindow(HINSTANCE hInstance) { - return(CreateWindow(APPCLASS, APPTITLE, + return(CreateWindowW(APPCLASS, APPTITLE, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 400,0, 623,767, @@ -135,9 +135,9 @@ HWND CreateMDIClientWindow(HWND hWndFrame) ccs.hWindowMenu = NULL; 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_VISIBLE | MDIS_ALLCHILDSTYLES, 0, 0, 1, 1, diff --git a/src/Draw/init.h b/src/Draw/init.h index 4e41748624..478a0eb6a3 100644 --- a/src/Draw/init.h +++ b/src/Draw/init.h @@ -16,8 +16,8 @@ #ifdef _WIN32 -#define APPCLASS "TDRAW" -#define APPTITLE "Windows NT TDRAW" +#define APPCLASS L"TDRAW" +#define APPTITLE L"Windows NT TDRAW" #include BOOL RegisterAppClass(HINSTANCE); diff --git a/src/IVtkDraw/IVtkDraw.cxx b/src/IVtkDraw/IVtkDraw.cxx index 042626a299..8e7b04c559 100644 --- a/src/IVtkDraw/IVtkDraw.cxx +++ b/src/IVtkDraw/IVtkDraw.cxx @@ -251,15 +251,15 @@ Standard_Integer GenerateId() // Function : WClass // 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 if (aWindowClass.IsNull()) { aWindowClass = new WNT_WClass ("GWVTK_Class", DefWindowProc, CS_VREDRAW | CS_HREDRAW, 0, 0, - ::LoadCursor (NULL, IDC_ARROW)); + ::LoadCursorW (NULL, IDC_ARROW)); } #endif return aWindowClass; diff --git a/src/IVtkDraw/IVtkDraw.hxx b/src/IVtkDraw/IVtkDraw.hxx index 16f3eda0f5..6c485bea5e 100644 --- a/src/IVtkDraw/IVtkDraw.hxx +++ b/src/IVtkDraw/IVtkDraw.hxx @@ -16,12 +16,11 @@ #ifndef _IVtkDraw_HeaderFile #define _IVtkDraw_HeaderFile -#include +#include #include #include class Draw_Interpretor; -class MMgt_TShared; class IVtkDraw { @@ -38,7 +37,7 @@ public: Standard_EXPORT static void Commands (Draw_Interpretor& theCommands); private: - Standard_EXPORT static const Handle(MMgt_TShared)& WClass(); + Standard_EXPORT static const Handle(Standard_Transient)& WClass(); }; #endif diff --git a/src/OSD/OSD_Environment.cxx b/src/OSD/OSD_Environment.cxx index 8a4e4e9eb5..dfa7ecf398 100644 --- a/src/OSD/OSD_Environment.cxx +++ b/src/OSD/OSD_Environment.cxx @@ -14,7 +14,6 @@ #ifndef _WIN32 - #include #include #include @@ -234,20 +233,16 @@ Standard_Integer OSD_Environment::Error() const //------------------------------------------------------------------------ #define STRICT +#include + #include #include -#include - #include #include #include -#if defined(_MSC_VER) - #pragma warning( disable : 4700 ) -#endif - #ifdef OCCT_UWP namespace { @@ -381,28 +376,22 @@ Standard_Integer OSD_Environment :: Error () const { } // end OSD_Environment :: Error #ifndef OCCT_UWP -static void __fastcall _set_error ( OSD_Error& err, DWORD code ) { - - DWORD errCode; - Standard_Character buffer[ 2048 ]; - - errCode = code ? code : GetLastError (); - - if ( !FormatMessage ( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, - 0, errCode, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ), - buffer, 2048, NULL - ) - ) { - - sprintf ( buffer, "error code %d", (Standard_Integer)errCode ); - SetLastError ( errCode ); - - } // end if - - err.SetValue ( errCode, OSD_WEnvironment, buffer ); - -} // end _set_error +static void __fastcall _set_error (OSD_Error& theErr, DWORD theCode) +{ + wchar_t aBuffer[2048]; + const DWORD anErrCode = theCode != 0 ? theCode : GetLastError(); + if (!FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, + 0, anErrCode, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ), + aBuffer, 2048, NULL)) + { + theErr.SetValue (anErrCode, OSD_WEnvironment, TCollection_AsciiString ("error code ") + (Standard_Integer)anErrCode); + SetLastError (anErrCode); + } + else + { + theErr.SetValue (anErrCode, OSD_WEnvironment, TCollection_AsciiString (aBuffer)); + } +} #endif #endif diff --git a/src/OSD/OSD_File.cxx b/src/OSD/OSD_File.cxx index 1b5e64ad1b..61e90711c6 100644 --- a/src/OSD/OSD_File.cxx +++ b/src/OSD/OSD_File.cxx @@ -1430,7 +1430,7 @@ OSD_KindFile OSD_File :: KindOfFile () const { typedef struct _osd_wnt_key { HKEY hKey; - const char* keyPath; + wchar_t* keyPath; } OSD_WNT_KEY; @@ -1448,17 +1448,17 @@ typedef struct _osd_wnt_key { OSD_WNT_KEY regKey[ 2 ] = { { HKEY_LOCAL_MACHINE, - "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" + L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" }, { HKEY_USERS, - ".DEFAULT\\Environment" + L".DEFAULT\\Environment" } }; for ( int i = 0; i < 2; ++i ) { - if ( RegOpenKeyEx ( + if ( RegOpenKeyExW ( regKey[ i ].hKey, regKey[ i ].keyPath, 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS ) { diff --git a/src/OSD/OSD_Host.cxx b/src/OSD/OSD_Host.cxx index 4ab93a99a8..8b5c8850a6 100644 --- a/src/OSD/OSD_Host.cxx +++ b/src/OSD/OSD_Host.cxx @@ -14,7 +14,6 @@ #ifndef _WIN32 - #include #include #include @@ -202,13 +201,13 @@ static Standard_Integer memSize; OSD_Host :: OSD_Host () { #ifndef OCCT_UWP DWORD nSize; - Standard_Character szHostName[ MAX_COMPUTERNAME_LENGTH + 1 ]; + char szHostName[MAX_COMPUTERNAME_LENGTH + 1]; char* hostAddr = 0; MEMORYSTATUS ms; WSADATA wd; PHOSTENT phe; IN_ADDR inAddr; - OSVERSIONINFO osVerInfo; + OSVERSIONINFOW osVerInfo; if ( !fInit ) { @@ -216,25 +215,24 @@ OSD_Host :: OSD_Host () { osVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO ); ZeroMemory (&ms, sizeof(ms)); - ZeroMemory ( szHostName, sizeof ( Standard_Character ) * (MAX_COMPUTERNAME_LENGTH + 1) ); + ZeroMemory (szHostName, sizeof(char) * (MAX_COMPUTERNAME_LENGTH + 1)); #ifdef _MSC_VER // suppress GetVersionEx() deprecation warning #pragma warning(disable : 4996) #endif - if ( !GetVersionEx ( &osVerInfo ) ) { - - _osd_wnt_set_error ( myError, OSD_WHost ); - - } else if ( !GetComputerName ( szHostName, &nSize ) ) { - - _osd_wnt_set_error ( myError, OSD_WHost ); - - } else { - - ms.dwLength = sizeof ( MEMORYSTATUS ); - GlobalMemoryStatus ( &ms ); - + if (!GetVersionExW (&osVerInfo)) + { + _osd_wnt_set_error (myError, OSD_WHost); + } + else if (!GetComputerNameA (szHostName, &nSize)) + { + _osd_wnt_set_error (myError, OSD_WHost); + } + else + { + ms.dwLength = sizeof(MEMORYSTATUS); + GlobalMemoryStatus (&ms); } // end else #ifdef _MSC_VER #pragma warning(default : 4996) @@ -248,7 +246,7 @@ OSD_Host :: OSD_Host () { _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 ); diff --git a/src/OSD/OSD_Process.cxx b/src/OSD/OSD_Process.cxx index 17ed7074c7..c2373463b5 100644 --- a/src/OSD/OSD_Process.cxx +++ b/src/OSD/OSD_Process.cxx @@ -14,7 +14,6 @@ #ifndef _WIN32 - #include #include #include @@ -195,65 +194,60 @@ Standard_Integer OSD_Process::Error()const{ #include #include -#include /// pour UNLEN ( see MSDN about GetUserName() ) - -#if defined(_MSC_VER) - #pragma warning( disable : 4700 ) -#endif +#include // for UNLEN - maximum user name length GetUserName() void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... ); -OSD_Process :: OSD_Process () { +// ======================================================================= +// function : OSD_Process +// purpose : +// ======================================================================= +OSD_Process::OSD_Process() +{ + // +} -} // end constructor - - -Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& cmd, - const Standard_Boolean ShowWindow /* = Standard_True */) { +// ======================================================================= +// function : Spawn +// purpose : +// ======================================================================= +Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& theCmd, + const Standard_Boolean theToShowWindow) +{ #ifndef OCCT_UWP - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD aRes = 0; + STARTUPINFOW aStartupInfo; + ZeroMemory (&aStartupInfo, sizeof(STARTUPINFO)); + aStartupInfo.cb = sizeof(STARTUPINFO); + if (!theToShowWindow) + { + aStartupInfo.dwFlags = STARTF_USESHOWWINDOW; + aStartupInfo.wShowWindow = SW_HIDE; + } - ZeroMemory ( &si, sizeof ( STARTUPINFO ) ); + DWORD aRes = 0; + TCollection_ExtendedString aCmdWide (theCmd); + wchar_t* aCmdWidePtr = const_cast(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); + aRes = myError.Error(); + } + else + { + CloseHandle (aProcessInfo.hThread); + WaitForSingleObject (aProcessInfo.hProcess, INFINITE); + GetExitCodeProcess (aProcessInfo.hProcess, &aRes); + CloseHandle (aProcessInfo.hProcess); + } - 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; - si.wShowWindow = SW_HIDE; - } - //<--- End Added by Stephane Routelous ( stephane.routelous@altavista.net ) [16.03.01] - //============================================ - - if (!CreateProcess ( - NULL, (char *)cmd.ToCString (), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi - ) - ) { - - _osd_wnt_set_error ( myError, OSD_WProcess ); - aRes = myError.Error(); - } - else { - - CloseHandle ( pi.hThread ); - - WaitForSingleObject ( pi.hProcess, INFINITE ); - GetExitCodeProcess (pi.hProcess, &aRes); - CloseHandle ( pi.hProcess ); - - } // end else - - return aRes; + return aRes; #else - (void)cmd; - (void)ShowWindow; + (void )theCmd; + (void )theToShowWindow; return 0; #endif -} // end OSD_Process :: Spawn +} void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) { @@ -276,27 +270,26 @@ Quantity_Date OSD_Process :: SystemDate () { } // end OSD_Process :: SystemDate -TCollection_AsciiString OSD_Process :: UserName () +// ======================================================================= +// function : UserName +// purpose : +// ======================================================================= +TCollection_AsciiString OSD_Process::UserName() { #ifndef OCCT_UWP - Standard_PCharacter pBuff = new char[UNLEN + 1]; - DWORD dwSize = UNLEN + 1; - TCollection_AsciiString retVal; - if ( !GetUserName ( pBuff, &dwSize ) ) - { - _osd_wnt_set_error ( myError, OSD_WProcess ); - } - else - { - TCollection_AsciiString theTmpUserName(pBuff,(int)dwSize -1 ); - retVal = theTmpUserName; - } - delete [] pBuff; - return retVal; + wchar_t aUserName[UNLEN + 1]; + DWORD aNameSize = UNLEN + 1; + TCollection_AsciiString retVal; + if (!GetUserNameW (aUserName, &aNameSize)) + { + _osd_wnt_set_error(myError, OSD_WProcess); + return TCollection_AsciiString(); + } + return TCollection_AsciiString (aUserName); #else - return ""; + return TCollection_AsciiString(); #endif -} // end OSD_Process :: UserName +} Standard_Boolean OSD_Process :: IsSuperUser () { #ifndef OCCT_UWP @@ -341,31 +334,41 @@ Standard_Boolean OSD_Process :: IsSuperUser () { #endif } // 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 (); - -} // end OSD_Process :: ProcessId - -OSD_Path OSD_Process :: CurrentDirectory () { +// ======================================================================= +// function : CurrentDirectory +// purpose : +// ======================================================================= +OSD_Path OSD_Process::CurrentDirectory() +{ OSD_Path anCurrentDirectory; #ifndef OCCT_UWP - DWORD dwSize = PATHLEN + 1; - Standard_WideChar* pBuff = new wchar_t[dwSize]; - - if (GetCurrentDirectoryW (dwSize, pBuff) > 0) + const DWORD aBuffLen = GetCurrentDirectoryW (0, NULL); + if (aBuffLen > 0) { - // conversion to UTF-8 is performed inside - TCollection_AsciiString aPath (pBuff); - anCurrentDirectory = OSD_Path ( aPath ); + wchar_t* aBuff = new wchar_t[aBuffLen + 1]; + GetCurrentDirectoryW (aBuffLen, aBuff); + aBuff[aBuffLen] = L'\0'; + const TCollection_AsciiString aPath (aBuff); + delete[] aBuff; + + anCurrentDirectory = OSD_Path (aPath); } else - _osd_wnt_set_error ( myError, OSD_WProcess ); - - delete[] pBuff; + { + _osd_wnt_set_error (myError, OSD_WProcess); + } #endif return anCurrentDirectory; -} // end OSD_Process :: CurrentDirectory +} void OSD_Process :: SetCurrentDirectory ( const OSD_Path& where ) { diff --git a/src/ViewerTest/ViewerTest.hxx b/src/ViewerTest/ViewerTest.hxx index 1e16d9a71b..e4d57833a4 100644 --- a/src/ViewerTest/ViewerTest.hxx +++ b/src/ViewerTest/ViewerTest.hxx @@ -208,7 +208,7 @@ private: //! Ctrl+MB2 for pan, etc) and keyboard shortcuts. //! This method is relevant for MS Windows only and respectively //! returns WNT_WClass handle. - Standard_EXPORT static const Handle(MMgt_TShared)& WClass(); + static const Handle(Standard_Transient)& WClass(); }; #endif // _ViewerTest_HeaderFile diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 417771ce22..b107406d00 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -247,15 +247,15 @@ static LRESULT WINAPI AdvViewerWindowProc( //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 (theWClass.IsNull()) { theWClass = new WNT_WClass ("GW3D_Class", (Standard_Address )AdvViewerWindowProc, - CS_VREDRAW | CS_HREDRAW, 0, 0, - ::LoadCursor (NULL, IDC_ARROW)); + CS_VREDRAW | CS_HREDRAW, 0, 0, + ::LoadCursorW (NULL, IDC_ARROW)); } #endif return theWClass; @@ -451,8 +451,8 @@ void SetWindowTitle (const Handle(Aspect_Window)& theWindow, Standard_CString theTitle) { #if defined(_WIN32) - SetWindowText ((HWND)Handle(WNT_Window)::DownCast(theWindow)->HWindow(), - theTitle); + const TCollection_ExtendedString theTitleW (theTitle); + SetWindowTextW ((HWND )Handle(WNT_Window)::DownCast(theWindow)->HWindow(), theTitleW.ToWideString()); #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) SetCocoaWindowTitle (Handle(Cocoa_Window)::DownCast(theWindow), theTitle); #else @@ -2007,7 +2007,7 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, const Handle(V3d_View)& aView = ViewerTest::CurrentView(); if (aView.IsNull()) { - return DefWindowProc( hwnd, Msg, wParam, lParam ); + return DefWindowProcW (hwnd, Msg, wParam, lParam); } PAINTSTRUCT ps; @@ -2175,14 +2175,11 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, break; default: - return( DefWindowProc( hwnd, Msg, wParam, lParam )); + return DefWindowProcW (hwnd, Msg, wParam, lParam); } return 0L; } - - - //============================================================================== //function : ViewerMainLoop //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 ) { // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0 - if (GetMessage(&msg, NULL, 0, 0) ) { - TranslateMessage(&msg); - DispatchMessage(&msg); + if (GetMessageW (&msg, NULL, 0, 0)) + { + TranslateMessage (&msg); + DispatchMessageW (&msg); } } @@ -9489,7 +9487,7 @@ static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/, Standard_Boolean toExit = Standard_False; 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)) { @@ -9497,7 +9495,7 @@ static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/, } TranslateMessage (&aMsg); - DispatchMessage (&aMsg); + DispatchMessageW (&aMsg); } if (toExit) diff --git a/src/WNT/FILES b/src/WNT/FILES index 9a673ac539..2054f3b034 100755 --- a/src/WNT/FILES +++ b/src/WNT/FILES @@ -4,7 +4,6 @@ WNT_OrientationType.hxx WNT_Uint.hxx WNT_WClass.cxx WNT_WClass.hxx -WNT_WClass.lxx WNT_Window.cxx WNT_Window.hxx WNT_Window.lxx diff --git a/src/WNT/WNT_WClass.cxx b/src/WNT/WNT_WClass.cxx index e3f7271727..519cbae8f7 100644 --- a/src/WNT/WNT_WClass.cxx +++ b/src/WNT/WNT_WClass.cxx @@ -16,69 +16,62 @@ #include -#include -#include +#include #include #include #if defined(_WIN32) && !defined(OCCT_UWP) -#include -IMPLEMENT_STANDARD_RTTIEXT(WNT_WClass,MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT(WNT_WClass, Standard_Transient) //======================================================================= //function : WNT_WClass -//purpose : +//purpose : //======================================================================= -WNT_WClass::WNT_WClass ( - const Standard_CString aClassName, - const Standard_Address aWndProc, - const WNT_Uint& aStyle, - const Standard_Integer aClassExtra, - const Standard_Integer aWindowExtra, - const Aspect_Handle aCursor, - const Aspect_Handle anIcon, - const Standard_CString aMenuName - ) { - - WNDCLASS wc; - - hInstance = GetModuleHandle ( NULL ); - - wc.style = aStyle; - wc.lpfnWndProc = ( aWndProc ) ? ( WNDPROC )aWndProc : DefWindowProc; - wc.cbClsExtra = aClassExtra; - wc.cbWndExtra = aWindowExtra; - wc.hInstance = ( HINSTANCE )hInstance; - wc.hIcon = ( anIcon ) ? ( HICON )anIcon : - LoadIcon ( NULL, IDI_APPLICATION ); - wc.hCursor = ( aCursor ) ? ( HCURSOR )aCursor : - LoadCursor ( NULL, IDC_NO ); - wc.hbrBackground = 0; - wc.lpszMenuName = aMenuName; - wc.lpszClassName = aClassName; - - if ( !RegisterClass ( &wc ) ) - - WNT_ClassDefinitionError :: Raise ( "Unable to register window class" ); - - lpszName = new char[ strlen ( aClassName ) + 1 ]; - strcpy ( (Standard_PCharacter)lpszName, aClassName ); - lpfnWndProc = (void* )wc.lpfnWndProc; - -} // end constructor +WNT_WClass::WNT_WClass (const TCollection_AsciiString& theClassName, + const Standard_Address theWndProc, + const WNT_Uint& theStyle, + const Standard_Integer theClassExtra, + const Standard_Integer theWindowExtra, + const Aspect_Handle theCursor, + const Aspect_Handle theIcon, + const TCollection_AsciiString& theMenuName) +: myClassName (theClassName), + myAppInstance (GetModuleHandleW (NULL)), + myWndProc (NULL) +{ + const TCollection_ExtendedString aClassNameW (theClassName); + const TCollection_ExtendedString aMenuNameW (theMenuName); + WNDCLASSW aWinClass; + aWinClass.style = theStyle; + aWinClass.lpfnWndProc = theWndProc != NULL ? (WNDPROC )theWndProc : DefWindowProcW; + aWinClass.cbClsExtra = theClassExtra; + aWinClass.cbWndExtra = theWindowExtra; + aWinClass.hInstance = (HINSTANCE )myAppInstance; + aWinClass.hIcon = theIcon != NULL ? (HICON )theIcon : LoadIconW (NULL, IDI_APPLICATION); + aWinClass.hCursor = theCursor != NULL ? (HCURSOR )theCursor : LoadCursorW (NULL, IDC_NO); + aWinClass.hbrBackground = 0; + aWinClass.lpszMenuName = !aMenuNameW.IsEmpty() ? aMenuNameW.ToWideString() : NULL; + aWinClass.lpszClassName = aClassNameW.ToWideString(); + if (!RegisterClassW (&aWinClass)) + { + myClassName.Clear(); + WNT_ClassDefinitionError::Raise ("Unable to register window class"); + } + myWndProc = (Standard_Address )aWinClass.lpfnWndProc; +} //======================================================================= //function : ~WNT_WClass -//purpose : +//purpose : //======================================================================= - -WNT_WClass::~WNT_WClass () +WNT_WClass::~WNT_WClass() { - - UnregisterClass ( lpszName, ( HINSTANCE )hInstance ); - delete [] (Standard_PCharacter)lpszName; - -} // end WNT_WClass :: Destroy + if (!myClassName.IsEmpty()) + { + const TCollection_ExtendedString aClassNameW (myClassName); + UnregisterClassW (aClassNameW.ToWideString(), (HINSTANCE )myAppInstance); + } +} #endif // _WIN32 diff --git a/src/WNT/WNT_WClass.hxx b/src/WNT/WNT_WClass.hxx index b6809b1766..b2c339e776 100644 --- a/src/WNT/WNT_WClass.hxx +++ b/src/WNT/WNT_WClass.hxx @@ -21,19 +21,14 @@ #if defined(_WIN32) && !defined(OCCT_UWP) -#include -#include #include #include -#include -#include +#include #include -class WNT_ClassDefinitionError; -class WNT_Window; - - -class WNT_WClass; -DEFINE_STANDARD_HANDLE(WNT_WClass, MMgt_TShared) +#include +#include +#include +#include //! This class defines a Windows NT window class. //! 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. //! We implemented this class for sake of flexibility of //! 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: - //! 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 Standard_EXPORT ~WNT_WClass(); - + //! Returns address of window procedure. - Standard_Address WndProc() const; - + Standard_Address WndProc() const { return myWndProc; } + //! Returns a class name. - Standard_CString Name() const; - + const TCollection_AsciiString& Name() const { return myClassName; } + //! Returns a program instance handle. - Aspect_Handle Instance() const; - -friend class WNT_Window; - - - DEFINE_STANDARD_RTTIEXT(WNT_WClass,MMgt_TShared) + Aspect_Handle Instance() const { return myAppInstance; } protected: - Standard_CString lpszName; - Aspect_Handle hInstance; - Standard_Address lpfnWndProc; + TCollection_AsciiString myClassName; + Aspect_Handle myAppInstance; + Standard_Address myWndProc; }; -#include +DEFINE_STANDARD_HANDLE(WNT_WClass, Standard_Transient) #endif // _WIN32 #endif // _WNT_WClass_HeaderFile diff --git a/src/WNT/WNT_WClass.lxx b/src/WNT/WNT_WClass.lxx deleted file mode 100644 index 6240eca092..0000000000 --- a/src/WNT/WNT_WClass.lxx +++ /dev/null @@ -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 diff --git a/src/WNT/WNT_Window.cxx b/src/WNT/WNT_Window.cxx index 99f3bbd811..31e7c8a8bb 100644 --- a/src/WNT/WNT_Window.cxx +++ b/src/WNT/WNT_Window.cxx @@ -22,13 +22,11 @@ #include #include #include -#include #include +#include #include -#include - -IMPLEMENT_STANDARD_RTTIEXT(WNT_Window,Aspect_Window) +IMPLEMENT_STANDARD_RTTIEXT(WNT_Window, Aspect_Window) // ======================================================================= // function : WNT_Window @@ -53,45 +51,43 @@ WNT_Window::WNT_Window (const Standard_CString theTitle, myWClass (theClass), myIsForeign (Standard_False) { - DWORD dwStyle = theStyle; - if (thePxWidth <= 0 || thePxHeight <= 0) { Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range"); } + DWORD aStyle = theStyle; if (theParent && !(theStyle & WS_CHILD)) { - dwStyle |= WS_CHILD | WS_CLIPSIBLINGS; + aStyle |= WS_CHILD | WS_CLIPSIBLINGS; } else if (!theParent && !(theStyle & WS_CLIPCHILDREN)) { - dwStyle |= WS_CLIPCHILDREN; + aStyle |= WS_CLIPCHILDREN; } - // include decorations in the window dimensions - // to reproduce same behaviour of Xw_Window. + // include decorations in the window dimensions to reproduce same behavior of Xw_Window RECT aRect; aRect.top = aYTop; aRect.bottom = aYBottom; aRect.left = aXLeft; aRect.right = aXRight; - AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE); + AdjustWindowRect (&aRect, aStyle, theMenu != NULL ? TRUE : FALSE); aXLeft = aRect.left; aYTop = aRect.top; aXRight = aRect.right; aYBottom = aRect.bottom; - myHWindow = CreateWindow ( - myWClass->Name(), // window's class name - theTitle, // window's name - dwStyle, // window's style - aXLeft, aYTop, // window's coordinates - (aXRight - aXLeft), (aYBottom - aYTop), - (HWND )theParent, // window's parent - (HMENU )theMenu, // window's menu - (HINSTANCE )myWClass->Instance(), // application's instance - theClientStruct); // pointer to CLIENTCREATESTRUCT + const TCollection_ExtendedString aTitleW (theTitle); + const TCollection_ExtendedString aClassNameW (myWClass->Name()); + myHWindow = CreateWindowW (aClassNameW.ToWideString(), aTitleW.ToWideString(), + aStyle, + aXLeft, aYTop, + (aXRight - aXLeft), (aYBottom - aYTop), + (HWND )theParent, + (HMENU )theMenu, + (HINSTANCE )myWClass->Instance(), + theClientStruct); if (!myHWindow) { Aspect_WindowDefinitionError::Raise ("Unable to create window"); @@ -146,7 +142,7 @@ WNT_Window::~WNT_Window() // ======================================================================= 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); } // =======================================================================