X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..9ccffa515ca1a12eff8a8a7c42cd160bc9aa75ba:/src/msw/utilsgui.cpp diff --git a/src/msw/utilsgui.cpp b/src/msw/utilsgui.cpp index fcd7ce463b..e3c65df081 100644 --- a/src/msw/utilsgui.cpp +++ b/src/msw/utilsgui.cpp @@ -6,7 +6,7 @@ // Created: 21.06.2003 (extracted from msw/utils.cpp) // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// License: wxWidgets licence +// License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -30,119 +30,14 @@ #include "wx/utils.h" #endif //WX_PRECOMP +#include "wx/dynlib.h" + #include "wx/msw/private.h" // includes // ============================================================================ // implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// functions to work with .INI files -// ---------------------------------------------------------------------------- - -// Reading and writing resources (eg WIN.INI, .Xdefaults) -#if wxUSE_RESOURCES -bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) -{ - if (file != wxEmptyString) -// Don't know what the correct cast should be, but it doesn't -// compile in BC++/16-bit without this cast. -#if !defined(__WIN32__) - return (WritePrivateProfileString((const char*) section, (const char*) entry, (const char*) value, (const char*) file) != 0); -#else - return (WritePrivateProfileString((LPCTSTR)WXSTRINGCAST section, (LPCTSTR)WXSTRINGCAST entry, (LPCTSTR)value, (LPCTSTR)WXSTRINGCAST file) != 0); -#endif - else - return (WriteProfileString((LPCTSTR)WXSTRINGCAST section, (LPCTSTR)WXSTRINGCAST entry, (LPCTSTR)WXSTRINGCAST value) != 0); -} - -bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) -{ - wxString buf; - buf.Printf(wxT("%.4f"), value); - - return wxWriteResource(section, entry, buf, file); -} - -bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) -{ - wxString buf; - buf.Printf(wxT("%ld"), value); - - return wxWriteResource(section, entry, buf, file); -} - -bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) -{ - wxString buf; - buf.Printf(wxT("%d"), value); - - return wxWriteResource(section, entry, buf, file); -} - -bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file) -{ - static const wxChar defunkt[] = wxT("$$default"); - - wxChar buf[1024]; - if (file != wxEmptyString) - { - int n = GetPrivateProfileString(section, entry, defunkt, - buf, WXSIZEOF(buf), file); - if (n == 0 || wxStrcmp(buf, defunkt) == 0) - return FALSE; - } - else - { - int n = GetProfileString(section, entry, defunkt, buf, WXSIZEOF(buf)); - if (n == 0 || wxStrcmp(buf, defunkt) == 0) - return FALSE; - } - if (*value) delete[] (*value); - *value = wxStrcpy(new wxChar[wxStrlen(buf) + 1], buf); - return TRUE; -} - -bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) -{ - wxChar *s = NULL; - bool succ = wxGetResource(section, entry, (wxChar **)&s, file); - if (succ) - { - *value = (float)wxStrtod(s, NULL); - delete[] s; - return TRUE; - } - else return FALSE; -} - -bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) -{ - wxChar *s = NULL; - bool succ = wxGetResource(section, entry, (wxChar **)&s, file); - if (succ) - { - *value = wxStrtol(s, NULL, 10); - delete[] s; - return TRUE; - } - else return FALSE; -} - -bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) -{ - wxChar *s = NULL; - bool succ = wxGetResource(section, entry, (wxChar **)&s, file); - if (succ) - { - *value = (int)wxStrtol(s, NULL, 10); - delete[] s; - return TRUE; - } - else return FALSE; -} -#endif // wxUSE_RESOURCES - // --------------------------------------------------------------------------- // helper functions for showing a "busy" cursor // --------------------------------------------------------------------------- @@ -157,7 +52,7 @@ extern HCURSOR wxGetCurrentBusyCursor() } // Set the cursor to the busy cursor for all windows -void wxBeginBusyCursor(wxCursor *cursor) +void wxBeginBusyCursor(const wxCursor *cursor) { if ( gs_wxBusyCursorCount++ == 0 ) { @@ -184,7 +79,7 @@ void wxEndBusyCursor() } } -// TRUE if we're between the above two calls +// true if we're between the above two calls bool wxIsBusy() { return gs_wxBusyCursorCount > 0; @@ -194,7 +89,7 @@ bool wxIsBusy() // in long calculations. bool wxCheckForInterrupt(wxWindow *wnd) { - wxCHECK( wnd, FALSE ); + wxCHECK( wnd, false ); MSG msg; while ( ::PeekMessage(&msg, GetHwndOf(wnd), 0, 0, PM_REMOVE) ) @@ -203,7 +98,7 @@ bool wxCheckForInterrupt(wxWindow *wnd) ::DispatchMessage(&msg); } - return TRUE; + return true; } // MSW only: get user-defined resource from the .res file. @@ -212,7 +107,9 @@ bool wxCheckForInterrupt(wxWindow *wnd) #ifndef __WXMICROWIN__ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourceType) { - HRSRC hResource = ::FindResource(wxGetInstance(), resourceName, resourceType); + HRSRC hResource = ::FindResource(wxGetInstance(), + resourceName.wx_str(), + resourceType.wx_str()); if ( hResource == 0 ) return NULL; @@ -231,8 +128,6 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc wxStrncpy(s,theText,len); s[len]=0; - // wxChar *s = copystring(theText); - // Obsolete in WIN32 #ifndef __WIN32__ UnlockResource(hData); @@ -257,17 +152,17 @@ void wxGetMousePosition( int* x, int* y ) GetCursorPos( & pt ); if ( x ) *x = pt.x; if ( y ) *y = pt.y; -}; +} -// Return TRUE if we have a colour display +// Return true if we have a colour display bool wxColourDisplay() { #ifdef __WXMICROWIN__ // MICROWIN_TODO - return TRUE; + return true; #else // this function is called from wxDC ctor so it is called a *lot* of times - // hence we optimize it a bit but doign the check only once + // hence we optimize it a bit but doing the check only once // // this should be MT safe as only the GUI thread (holding the GUI mutex) // can call us @@ -398,9 +293,9 @@ wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd) return str; } -WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd) +int WXDLLEXPORT wxGetWindowId(WXHWND hWnd) { - return (WXWORD)GetWindowLong((HWND)hWnd, GWL_ID); + return ::GetWindowLong((HWND)hWnd, GWL_ID); } // ---------------------------------------------------------------------------- @@ -452,3 +347,50 @@ void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2) } +// ---------------------------------------------------------------------------- +// Shell API wrappers +// ---------------------------------------------------------------------------- + +extern bool wxEnableFileNameAutoComplete(HWND hwnd) +{ +#if wxUSE_DYNLIB_CLASS + typedef HRESULT (WINAPI *SHAutoComplete_t)(HWND, DWORD); + + static SHAutoComplete_t s_pfnSHAutoComplete = NULL; + static bool s_initialized = false; + + if ( !s_initialized ) + { + s_initialized = true; + + wxLogNull nolog; + wxDynamicLibrary dll(_T("shlwapi.dll")); + if ( dll.IsLoaded() ) + { + s_pfnSHAutoComplete = + (SHAutoComplete_t)dll.GetSymbol(_T("SHAutoComplete")); + if ( s_pfnSHAutoComplete ) + { + // won't be unloaded until the process termination, no big deal + dll.Detach(); + } + } + } + + if ( !s_pfnSHAutoComplete ) + return false; + + HRESULT hr = s_pfnSHAutoComplete(hwnd, 0x10 /* SHACF_FILESYS_ONLY */); + if ( FAILED(hr) ) + { + wxLogApiError(_T("SHAutoComplete"), hr); + return false; + } + + return true; +#else + wxUnusedVar(hwnd); + return false; +#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS +} +