wxUICanceller: Move upstream and make reusable
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
3bd2d1fd09
commit
cd0a99c518
@ -463,6 +463,30 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Closes active window if exists
|
||||||
|
///
|
||||||
|
class wxUICanceller
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Send WM_CLOSE to the active window if it exists.
|
||||||
|
///
|
||||||
|
/// \param[inout] hWndCurrent Reference to a handle of the active window is stored. The variable should be shared between threads.
|
||||||
|
/// \param[in] hWnd Handle of a new window to be activated
|
||||||
|
///
|
||||||
|
wxUICanceller(_Inout_ HWND volatile &hWndCurrent, _In_ HWND hWnd);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Clears the active window handle.
|
||||||
|
///
|
||||||
|
~wxUICanceller();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HWND volatile &m_hWndCurrent;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// EAP general note
|
/// EAP general note
|
||||||
///
|
///
|
||||||
|
@ -600,3 +600,24 @@ wxInitializerPeer::~wxInitializerPeer()
|
|||||||
wxCriticalSection wxInitializerPeer::s_lock;
|
wxCriticalSection wxInitializerPeer::s_lock;
|
||||||
unsigned long wxInitializerPeer::s_init_ref_count = 0;
|
unsigned long wxInitializerPeer::s_init_ref_count = 0;
|
||||||
wxLocale *wxInitializerPeer::s_locale = NULL;
|
wxLocale *wxInitializerPeer::s_locale = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// wxUICanceller
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
wxUICanceller::wxUICanceller(_Inout_ HWND volatile &hWndCurrent, _In_ HWND hWnd) :
|
||||||
|
m_hWndCurrent(hWndCurrent)
|
||||||
|
{
|
||||||
|
HWND hWndPrev = (HWND)InterlockedCompareExchangePointer((PVOID volatile *)&m_hWndCurrent, hWnd, NULL);
|
||||||
|
if (hWndPrev) {
|
||||||
|
PostMessage(hWndPrev, WM_CLOSE, 0, 0);
|
||||||
|
throw winstd::win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Aborted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxUICanceller::~wxUICanceller()
|
||||||
|
{
|
||||||
|
InterlockedExchangePointer((PVOID volatile *)&m_hWndCurrent, NULL);
|
||||||
|
}
|
||||||
|
@ -83,28 +83,10 @@ void eap::peer_ttls_ui::invoke_identity_ui(
|
|||||||
_Out_ DWORD *pdwUserDataOutSize,
|
_Out_ DWORD *pdwUserDataOutSize,
|
||||||
_Out_ LPWSTR *ppwszIdentity)
|
_Out_ LPWSTR *ppwszIdentity)
|
||||||
{
|
{
|
||||||
static HWND volatile hWndCurrent = NULL;
|
|
||||||
|
|
||||||
class ui_canceller
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ui_canceller(_In_ HWND hWnd)
|
|
||||||
{
|
|
||||||
HWND hWndPrev = (HWND)InterlockedCompareExchangePointer((PVOID volatile *)&hWndCurrent, hWnd, NULL);
|
|
||||||
if (hWndPrev) {
|
|
||||||
PostMessage(hWndPrev, WM_CLOSE, 0, 0);
|
|
||||||
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Aborted.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~ui_canceller()
|
|
||||||
{
|
|
||||||
InterlockedExchangePointer((PVOID volatile *)&hWndCurrent, NULL);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
assert(ppwszIdentity);
|
assert(ppwszIdentity);
|
||||||
|
|
||||||
|
static HWND volatile hWndCurrent = NULL;
|
||||||
|
|
||||||
// Unpack configuration.
|
// Unpack configuration.
|
||||||
config_connection cfg(*this);
|
config_connection cfg(*this);
|
||||||
unpack(cfg, pConnectionData, dwConnectionDataSize);
|
unpack(cfg, pConnectionData, dwConnectionDataSize);
|
||||||
@ -129,7 +111,7 @@ void eap::peer_ttls_ui::invoke_identity_ui(
|
|||||||
if (cfg.m_providers.size() > 1) {
|
if (cfg.m_providers.size() > 1) {
|
||||||
// Multiple identity providers: User has to select one first.
|
// Multiple identity providers: User has to select one first.
|
||||||
wxEAPProviderSelectDialog dlg(cfg, init.m_parent);
|
wxEAPProviderSelectDialog dlg(cfg, init.m_parent);
|
||||||
ui_canceller lock(dlg.GetHWND());
|
wxUICanceller lock(hWndCurrent, dlg.GetHWND());
|
||||||
|
|
||||||
// Centre and display dialog.
|
// Centre and display dialog.
|
||||||
dlg.Centre(wxBOTH);
|
dlg.Centre(wxBOTH);
|
||||||
@ -186,7 +168,7 @@ void eap::peer_ttls_ui::invoke_identity_ui(
|
|||||||
{
|
{
|
||||||
// Build dialog to prompt for outer credentials.
|
// Build dialog to prompt for outer credentials.
|
||||||
wxEAPCredentialsDialog dlg(*cfg_prov, init.m_parent);
|
wxEAPCredentialsDialog dlg(*cfg_prov, init.m_parent);
|
||||||
ui_canceller lock(dlg.GetHWND());
|
wxUICanceller lock(hWndCurrent, dlg.GetHWND());
|
||||||
if (eap::config_method::status_t::cred_begin <= cfg_method->m_last_status && cfg_method->m_last_status < eap::config_method::status_t::cred_end)
|
if (eap::config_method::status_t::cred_begin <= cfg_method->m_last_status && cfg_method->m_last_status < eap::config_method::status_t::cred_end)
|
||||||
dlg.AddContent(new wxEAPCredentialWarningPanel(*cfg_prov, cfg_method->m_last_status, &dlg));
|
dlg.AddContent(new wxEAPCredentialWarningPanel(*cfg_prov, cfg_method->m_last_status, &dlg));
|
||||||
auto panel = new wxTLSCredentialsPanel(*cfg_prov, *cfg_method, *cred, &dlg, false);
|
auto panel = new wxTLSCredentialsPanel(*cfg_prov, *cfg_method, *cred, &dlg, false);
|
||||||
@ -275,7 +257,7 @@ void eap::peer_ttls_ui::invoke_identity_ui(
|
|||||||
{
|
{
|
||||||
// Native inner methods. Build dialog to prompt for inner credentials.
|
// Native inner methods. Build dialog to prompt for inner credentials.
|
||||||
wxEAPCredentialsDialog dlg(*cfg_prov, init.m_parent);
|
wxEAPCredentialsDialog dlg(*cfg_prov, init.m_parent);
|
||||||
ui_canceller lock(dlg.GetHWND());
|
wxUICanceller lock(hWndCurrent, dlg.GetHWND());
|
||||||
if (eap::config_method::status_t::cred_begin <= cfg_method->m_inner->m_last_status && cfg_method->m_inner->m_last_status < eap::config_method::status_t::cred_end)
|
if (eap::config_method::status_t::cred_begin <= cfg_method->m_inner->m_last_status && cfg_method->m_inner->m_last_status < eap::config_method::status_t::cred_end)
|
||||||
dlg.AddContent(new wxEAPCredentialWarningPanel(*cfg_prov, cfg_method->m_inner->m_last_status, &dlg));
|
dlg.AddContent(new wxEAPCredentialWarningPanel(*cfg_prov, cfg_method->m_inner->m_last_status, &dlg));
|
||||||
wxEAPCredentialsPanelBase *panel = NULL;
|
wxEAPCredentialsPanelBase *panel = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user