bool wxDialogBase::SendCloseButtonClickEvent() { int idCancel = GetEscapeId(); switch ( idCancel ) { case wxID_NONE: // The user doesn't want this dialog to close "implicitly". break; case wxID_ANY: // this value is special: it means translate Esc to wxID_CANCEL // but if there is no such button, then fall back to wxID_OK if ( EmulateButtonClickIfPresent(wxID_CANCEL) ) return true; idCancel = GetAffirmativeId(); wxFALLTHROUGH; default: // translate Esc to button press for the button with given id if ( EmulateButtonClickIfPresent(idCancel) ) return true; } return false; }
void wxDialogBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { // We'll send a Cancel message by default, which may close the dialog. // Check for looping if the Cancel event handler calls Close(). // Note that if a cancel button and handler aren't present in the dialog, // nothing will happen when you close the dialog via the window manager, or // via Close(). We wouldn't want to destroy the dialog by default, since // the dialog may have been created on the stack. However, this does mean // that calling dialog->Close() won't delete the dialog unless the handler // for wxID_CANCEL does so. So use Destroy() if you want to be sure to // destroy the dialog. The default OnCancel (above) simply ends a modal // dialog, and hides a modeless dialog. int idCancel = GetEscapeId(); if ( idCancel == wxID_NONE ) return; if ( idCancel == wxID_ANY ) idCancel = wxID_CANCEL; // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global // lists here? don't dare to change it now, but should be done later! static wxList closing; if ( closing.Member(this) ) return; closing.Append(this); wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, idCancel); cancelEvent.SetEventObject( this ); GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog closing.DeleteObject(this); }
void wxDialogBase::OnCharHook(wxKeyEvent& event) { if ( event.GetKeyCode() == WXK_ESCAPE ) { int idCancel = GetEscapeId(); switch ( idCancel ) { case wxID_NONE: // don't handle Esc specially at all break; case wxID_ANY: // this value is special: it means translate Esc to wxID_CANCEL // but if there is no such button, then fall back to wxID_OK if ( EmulateButtonClickIfPresent(wxID_CANCEL) ) return; idCancel = GetAffirmativeId(); // fall through default: // translate Esc to button press for the button with given id if ( EmulateButtonClickIfPresent(idCancel) ) return; } } event.Skip(); }
void wxDialogBase::OnButton(wxCommandEvent& event) { const int id = event.GetId(); if ( id == GetAffirmativeId() ) { AcceptAndClose(); } else if ( id == wxID_APPLY ) { if ( Validate() ) TransferDataFromWindow(); // TODO: disable the Apply button until things change again } else if ( id == GetEscapeId() || (id == wxID_CANCEL && GetEscapeId() == wxID_ANY) ) { EndDialog(wxID_CANCEL); } else // not a standard button { event.Skip(); } }
void frmExtract::onExtract(wxCommandEvent &e) { if(m_bIsDirectory) { RainString sFolder = m_pDestinationPath->GetValue(); if(!_ensureDirectoryExists(sFolder)) return; wxSizer *pMainSizer = GetSizer(); if(m_pButtonsSizer) { FindWindow(wxID_OK)->Hide(); FindWindow(wxID_CANCEL)->Hide(); pMainSizer->Detach(m_pButtonsSizer); } pMainSizer->Add(new wxStaticLine(this), 0, wxEXPAND | wxALL, 4); wxGauge *pProgressBar = new wxGauge(this, wxID_ANY, 1, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL | wxGA_SMOOTH); wxStaticText *pCurrentItem = new wxStaticText(this, wxID_ANY, L"Initialising extraction..."); pMainSizer->Add(pProgressBar, 0, wxEXPAND | wxALL, 2); pMainSizer->Add(pCurrentItem, 0, wxEXPAND | wxALL, 2); pMainSizer->RecalcSizes(); SetSize(pMainSizer->GetMinSize()); Layout(); ::wxSafeYield(this); int iTotalCount = 1, iDoneCount = 0; std::queue<IDirectory*> qTodo; try { qTodo.push(m_pArchive->openDirectory(m_sPathToExtract)); iTotalCount += static_cast<int>(qTodo.front()->getItemCount()); size_t iSkipLength = qTodo.front()->getPath().length(); pProgressBar->SetRange(iTotalCount); while(!qTodo.empty()) { IDirectory *pDirectory = qTodo.front(); pCurrentItem->SetLabel(pDirectory->getPath()); pProgressBar->SetValue(++iDoneCount); ::wxSafeYield(this); RainString sDirectoryBase = pDirectory->getPath(); sDirectoryBase = sFolder + sDirectoryBase.mid(iSkipLength, sDirectoryBase.length() - iSkipLength); if(!RainDoesDirectoryExist(sDirectoryBase)) RainCreateDirectory(sDirectoryBase); for(IDirectory::iterator itr = pDirectory->begin(), itrEnd = pDirectory->end(); itr != itrEnd; ++itr) { if(itr->isDirectory()) { IDirectory *pChild = itr->open(); iTotalCount += 1 + static_cast<int>(pChild->getItemCount()); qTodo.push(pChild); pProgressBar->SetRange(iTotalCount); } else { std::auto_ptr<IFile> pFile; pCurrentItem->SetLabel(pDirectory->getPath() + itr->name()); pProgressBar->SetValue(++iDoneCount); ::wxSafeYield(this); pFile.reset(RainOpenFile(sDirectoryBase + itr->name(), FM_Write)); itr->pump(&*pFile); } } delete pDirectory; qTodo.pop(); } } catch(RainException *pE) { while(!qTodo.empty()) { delete qTodo.front(); qTodo.pop(); } EXCEPTION_MESSAGE_BOX_1(L"Error extracting directory \'%s\'", m_sPathToExtract.getCharacters(), pE); SetReturnCode(GetEscapeId()); return; } } else { wxFileName oFilename(m_pDestinationPath->GetValue()); RainString sFolder = oFilename.GetPath(); IFile *pFile = 0; try { if(!_ensureDirectoryExists(sFolder)) return; pFile = RainOpenFile(m_pDestinationPath->GetValue(), FM_Write); m_pArchive->pumpFile(m_sPathToExtract, pFile); } catch(RainException *pE) { delete pFile; EXCEPTION_MESSAGE_BOX_1(L"Error extracting \'%s\'", m_sPathToExtract.getCharacters(), pE); return; } delete pFile; } wxString sMessage = L"Extracted " + m_sPathToExtract; if(m_pPositiveResultNoficiationBar) m_pPositiveResultNoficiationBar->SetStatusText(sMessage); else ::wxMessageBox(sMessage, GetLabel(), wxOK | wxCENTER | wxICON_INFORMATION, this); EndModal(GetAffirmativeId()); }