From 53e31b1be7eaa1f9d0f91184f64959401bf9e044 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 26 Aug 2016 15:54:31 +0200 Subject: [PATCH] Additional resource-loading functions introduced --- lib/EAPBase_UI/include/EAP_UI.h | 78 +++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/lib/EAPBase_UI/include/EAP_UI.h b/lib/EAPBase_UI/include/EAP_UI.h index f362f29..327d925 100644 --- a/lib/EAPBase_UI/include/EAP_UI.h +++ b/lib/EAPBase_UI/include/EAP_UI.h @@ -20,8 +20,10 @@ #include #include +#include #include #include +#include #include @@ -90,11 +92,31 @@ template class wxEAPCredentialsPanelBase; /// template class wxPasswordCredentialsPanel; +/// +/// Loads icon from resource +/// +inline wxIcon wxLoadIconFromResource(HINSTANCE hinst, PCWSTR pszName, int cx, int cy); + +/// +/// Loads icon from resource +/// +inline wxIcon wxLoadIconFromResource(HINSTANCE hinst, PCWSTR pszName, const wxSize &size); + /// /// Sets icon from resource /// inline bool wxSetIconFromResource(wxStaticBitmap *bmp, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName); +/// +/// Sets icon from resource +/// +inline bool wxSetIconFromResource(wxAuiToolBarItem *bmp, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName, const wxSize &size); + +/// +/// Sets icon from resource +/// +inline bool wxSetIconFromResource(wxMenuItem *item, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName); + /// /// Returns GUI displayable provider name /// @@ -797,13 +819,36 @@ template const wxStringCharType *wxPasswordCredentialsPanel<_Tcred, _Tbase>::s_dummy_password = wxT("dummypass"); +inline wxIcon wxLoadIconFromResource(HINSTANCE hinst, PCWSTR pszName, int cx, int cy) +{ + HICON hIcon; + if (SUCCEEDED(LoadIconWithScaleDown(hinst, pszName, cx, cy, &hIcon))) { + wxIcon icon; + icon.CreateFromHICON(hIcon); + return icon; + } else + return wxNullIcon; +} + + +inline wxIcon wxLoadIconFromResource(HINSTANCE hinst, PCWSTR pszName, const wxSize &size) +{ + HICON hIcon; + if (SUCCEEDED(LoadIconWithScaleDown(hinst, pszName, size.GetWidth(), size.GetHeight(), &hIcon))) { + wxIcon icon; + icon.CreateFromHICON(hIcon); + return icon; + } else + return wxNullIcon; +} + + inline bool wxSetIconFromResource(wxStaticBitmap *bmp, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName) { wxASSERT(bmp); - HICON hIcon; - if (SUCCEEDED(LoadIconWithScaleDown(hinst, pszName, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), &hIcon))) { - icon.CreateFromHICON(hIcon); + icon = wxLoadIconFromResource(hinst, pszName, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); + if (icon.IsOk()) { bmp->SetIcon(icon); return true; } else @@ -811,6 +856,33 @@ inline bool wxSetIconFromResource(wxStaticBitmap *bmp, wxIcon &icon, HINSTANCE h } +inline bool wxSetIconFromResource(wxAuiToolBarItem *item, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName, const wxSize &size) +{ + wxASSERT(item); + + icon = wxLoadIconFromResource(hinst, pszName, size.GetWidth(), size.GetHeight()); + if (icon.IsOk()) { + item->SetBitmap(icon); + item->SetDisabledBitmap(wxBitmap(icon).ConvertToDisabled()); + return true; + } else + return false; +} + + +inline bool wxSetIconFromResource(wxMenuItem *item, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName) +{ + wxASSERT(item); + + icon = wxLoadIconFromResource(hinst, pszName, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); + if (icon.IsOk()) { + item->SetBitmaps(icon); + return true; + } else + return false; +} + + inline wxString wxEAPGetProviderName(const std::wstring &id) { return