bool wxEventLoopBase::YieldFor(long eventsToProcess) { #if wxUSE_THREADS if ( !wxThread::IsMain() ) { // Don't ever dispatch events from non-main threads. return false; } #endif // wxUSE_THREADS // set the flag and don't forget to reset it before returning m_isInsideYield = true; m_eventsToProcessInsideYield = eventsToProcess; wxON_BLOCK_EXIT_SET(m_isInsideYield, false); #if wxUSE_LOG // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c wxLog::Suspend(); // ensure the logs will be flashed again when we exit wxON_BLOCK_EXIT0(wxLog::Resume); #endif DoYieldFor(eventsToProcess); return true; }
wxObject* wxRibbonXmlHandler::Handle_bar() { XRC_MAKE_INSTANCE (ribbonBar, wxRibbonBar); Handle_RibbonArtProvider (ribbonBar); if ( !ribbonBar->Create(wxDynamicCast(m_parent, wxWindow), GetID(), GetPosition(), GetSize(), GetStyle("style", wxRIBBON_BAR_DEFAULT_STYLE)) ) { ReportError ("could not create ribbonbar"); } else { // Currently the art provider style must be explicitly set to the // ribbon style too. ribbonBar->GetArtProvider() ->SetFlags(GetStyle("style", wxRIBBON_BAR_DEFAULT_STYLE)); const wxClassInfo* const wasInside = m_isInside; wxON_BLOCK_EXIT_SET(m_isInside, wasInside); m_isInside = &wxRibbonBar::ms_classInfo; CreateChildren (ribbonBar, true); ribbonBar->Realize(); } return ribbonBar; }
void wxGtkFileChooser::SetWildcard( const wxString& wildCard ) { m_wildcards.Empty(); // parse filters wxArrayString wildDescriptions, wildFilters; if ( !wxParseCommonDialogsFilter( wildCard, wildDescriptions, wildFilters ) ) { wxFAIL_MSG( wxT( "wxGtkFileChooser::SetWildcard - bad wildcard string" ) ); } else { // Parsing went fine. Set m_wildCard to be returned by wxGtkFileChooserBase::GetWildcard GtkFileChooser* chooser = m_widget; // empty current filter list: GSList* ifilters = gtk_file_chooser_list_filters( chooser ); GSList* filters = ifilters; m_ignoreNextFilterEvent = true; wxON_BLOCK_EXIT_SET(m_ignoreNextFilterEvent, false); while ( ifilters ) { gtk_file_chooser_remove_filter( chooser, GTK_FILE_FILTER( ifilters->data ) ); ifilters = ifilters->next; } g_slist_free( filters ); if (!wildCard.empty()) { // add parsed to GtkChooser for ( size_t n = 0; n < wildFilters.GetCount(); ++n ) { GtkFileFilter* filter = gtk_file_filter_new(); gtk_file_filter_set_name( filter, wxGTK_CONV_SYS( wildDescriptions[n] ) ); wxStringTokenizer exttok( wildFilters[n], wxT( ";" ) ); int n1 = 1; while ( exttok.HasMoreTokens() ) { wxString token = exttok.GetNextToken(); gtk_file_filter_add_pattern( filter, wxGTK_CONV_SYS( token ) ); if (n1 == 1) m_wildcards.Add( token ); // Only add first pattern to list, used later when saving n1++; } gtk_file_chooser_add_filter( chooser, filter ); } // Reset the filter index SetFilterIndex( 0 ); } } }
bool wxEventLoopBase::YieldFor(long eventsToProcess) { #if wxUSE_THREADS if ( !wxThread::IsMain() ) { // Don't ever dispatch events from non-main threads. return false; } #endif // wxUSE_THREADS // set the flag and don't forget to reset it before returning const int yieldLevelOld = m_yieldLevel; const long eventsToProcessOld = m_eventsToProcessInsideYield; m_yieldLevel++; wxON_BLOCK_EXIT_SET(m_yieldLevel, yieldLevelOld); m_eventsToProcessInsideYield = eventsToProcess; wxON_BLOCK_EXIT_SET(m_eventsToProcessInsideYield, eventsToProcessOld); #if wxUSE_LOG // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c wxLog::Suspend(); // ensure the logs will be flashed again when we exit wxON_BLOCK_EXIT0(wxLog::Resume); #endif DoYieldFor(eventsToProcess); #if wxUSE_EXCEPTIONS // If any handlers called from inside DoYieldFor() threw exceptions, they // may have been stored for later rethrow as it's unsafe to let them escape // from inside DoYieldFor() itself, as it calls native functions through // which the exceptions can't propagate. But now that we're back to our own // code, we may rethrow them. if ( wxTheApp ) wxTheApp->RethrowStoredException(); #endif // wxUSE_EXCEPTIONS return true; }
void ScopeGuardTestCase::BlockExitSetVar() { m_count = 1; { wxON_BLOCK_EXIT_SET(m_count, 17); CPPUNIT_ASSERT_EQUAL( 1, m_count ); } CPPUNIT_ASSERT_EQUAL( 17, m_count ); int count = 1; { wxON_BLOCK_EXIT_SET(count, 17); CPPUNIT_ASSERT_EQUAL( 1, count ); } CPPUNIT_ASSERT_EQUAL( 17, count ); wxString s("hi"); { wxON_BLOCK_EXIT_SET(s, "bye"); CPPUNIT_ASSERT_EQUAL( "hi", s ); } CPPUNIT_ASSERT_EQUAL( "bye", s ); ScopeGuardTestCase *p = this; { wxON_BLOCK_EXIT_NULL(p); CPPUNIT_ASSERT( p ); } CPPUNIT_ASSERT( !p ); }
int wxEventLoopBase::Run() { // event loops are not recursive, you need to create another loop! wxCHECK_MSG( !IsInsideRun(), -1, wxT("can't reenter a message loop") ); // ProcessIdle() and ProcessEvents() below may throw so the code here should // be exception-safe, hence we must use local objects for all actions we // should undo wxEventLoopActivator activate(this); // We might be called again, after a previous call to ScheduleExit(), so // reset this flag. m_shouldExit = false; // Set this variable to true for the duration of this method. m_isInsideRun = true; wxON_BLOCK_EXIT_SET(m_isInsideRun, false); // Finally really run the loop. return DoRun(); }
wxObject* wxRibbonXmlHandler::Handle_gallery() { XRC_MAKE_INSTANCE (ribbonGallery, wxRibbonGallery); if (!ribbonGallery->Create (wxDynamicCast(m_parent, wxWindow), GetID(), GetPosition(), GetSize(), GetStyle())) { ReportError("could not create ribbon gallery"); } else { const wxClassInfo* const wasInside = m_isInside; wxON_BLOCK_EXIT_SET(m_isInside, wasInside); m_isInside = &wxRibbonGallery::ms_classInfo; CreateChildren (ribbonGallery); ribbonGallery->Realize(); } return ribbonGallery; }
wxObject* wxRibbonXmlHandler::Handle_page() { XRC_MAKE_INSTANCE (ribbonPage, wxRibbonPage); if (!ribbonPage->Create (wxDynamicCast(m_parent, wxRibbonBar), GetID(), GetText ("label"), GetBitmap ("icon"), GetStyle())) { ReportError("could not create ribbon page"); } else { const wxClassInfo* const wasInside = m_isInside; wxON_BLOCK_EXIT_SET(m_isInside, wasInside); m_isInside = &wxRibbonPage::ms_classInfo; CreateChildren (ribbonPage); ribbonPage->Realize(); } return ribbonPage; }
wxObject* wxRibbonXmlHandler::Handle_buttonbar() { XRC_MAKE_INSTANCE (buttonBar, wxRibbonButtonBar); if (!buttonBar->Create (wxDynamicCast(m_parent, wxWindow), GetID(), GetPosition(), GetSize(), GetStyle())) { ReportError("could not create ribbon panel"); } else { const wxClassInfo* const wasInside = m_isInside; wxON_BLOCK_EXIT_SET(m_isInside, wasInside); m_isInside = &wxRibbonButtonBar::ms_classInfo; CreateChildren (buttonBar, true); buttonBar->Realize(); } return buttonBar; }
bool wxGUIEventLoop::YieldFor(long eventsToProcess) { // set the flag and don't forget to reset it before returning m_isInsideYield = true; m_eventsToProcessInsideYield = eventsToProcess; wxON_BLOCK_EXIT_SET(m_isInsideYield, false); #if wxUSE_LOG // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c wxLog::Suspend(); // ensure the logs will be flashed again when we exit wxON_BLOCK_EXIT0(wxLog::Resume); #endif // wxUSE_LOG // we don't want to process WM_QUIT from here - it should be processed in // the main event loop in order to stop it MSG msg; int nPaintsReceived = 0; while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && msg.message != WM_QUIT ) { #if wxUSE_THREADS wxMutexGuiLeaveOrEnter(); #endif // wxUSE_THREADS if (msg.message == WM_PAINT) { // NOTE: WM_PAINTs are categorized as wxEVT_CATEGORY_UI if ((eventsToProcess & wxEVT_CATEGORY_UI) == 0) { // this msg is not going to be dispatched... // however WM_PAINT is special: until there are damaged // windows, Windows will keep sending it forever! if (nPaintsReceived > 10) { // we got 10 WM_PAINT consecutive messages... // we must have reached the tail of the message queue: // we're now getting _only_ WM_PAINT events and this will // continue forever (since we don't dispatch them // because of the user-specified eventsToProcess mask)... // break out of this loop! break; } else nPaintsReceived++; } //else: we're going to dispatch it below, // so we don't need to take any special action } else { // reset the counter of consecutive WM_PAINT messages received: nPaintsReceived = 0; } // choose a wxEventCategory for this Windows message bool processNow; switch (msg.message) { #if !defined(__WXWINCE__) case WM_NCMOUSEMOVE: case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: case WM_NCLBUTTONDBLCLK: case WM_NCRBUTTONDOWN: case WM_NCRBUTTONUP: case WM_NCRBUTTONDBLCLK: case WM_NCMBUTTONDOWN: case WM_NCMBUTTONUP: case WM_NCMBUTTONDBLCLK: #endif case WM_KEYDOWN: case WM_KEYUP: case WM_CHAR: case WM_DEADCHAR: case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_SYSCHAR: case WM_SYSDEADCHAR: #ifdef WM_UNICHAR case WM_UNICHAR: #endif case WM_HOTKEY: case WM_IME_STARTCOMPOSITION: case WM_IME_ENDCOMPOSITION: case WM_IME_COMPOSITION: case WM_COMMAND: case WM_SYSCOMMAND: case WM_IME_SETCONTEXT: case WM_IME_NOTIFY: case WM_IME_CONTROL: case WM_IME_COMPOSITIONFULL: case WM_IME_SELECT: case WM_IME_CHAR: case WM_IME_KEYDOWN: case WM_IME_KEYUP: #if !defined(__WXWINCE__) case WM_MOUSEHOVER: case WM_MOUSELEAVE: #endif #ifdef WM_NCMOUSELEAVE case WM_NCMOUSELEAVE: #endif case WM_CUT: case WM_COPY: case WM_PASTE: case WM_CLEAR: case WM_UNDO: case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MBUTTONDBLCLK: case WM_MOUSEWHEEL: processNow = (eventsToProcess & wxEVT_CATEGORY_USER_INPUT) != 0; break; case WM_TIMER: processNow = (eventsToProcess & wxEVT_CATEGORY_TIMER) != 0; break; default: if (msg.message < WM_USER) { // 0;WM_USER-1 is the range of message IDs reserved for use // by the system. // there are too many of these types of messages to handle // them in this switch processNow = (eventsToProcess & wxEVT_CATEGORY_UI) != 0; } else { // Process all the unknown messages. We must do it because // failure to process some of them can be fatal, e.g. if we // don't dispatch WM_APP+2 then embedded IE ActiveX // controls don't work any more, see #14027. And there may // be more examples like this, so dispatch all unknown // messages immediately to be safe. processNow = true; } } // should we process this event now? if ( processNow ) { if ( !wxTheApp->Dispatch() ) break; } else { // remove the message and store it ::GetMessage(&msg, NULL, 0, 0); m_arrMSG.Add(msg); } } // if there are pending events, we must process them. if (wxTheApp) wxTheApp->ProcessPendingEvents(); // put back unprocessed events in the queue DWORD id = GetCurrentThreadId(); for (size_t i=0; i<m_arrMSG.GetCount(); i++) { PostThreadMessage(id, m_arrMSG[i].message, m_arrMSG[i].wParam, m_arrMSG[i].lParam); } m_arrMSG.Clear(); return true; }