X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ea98f11c2fbcd33ffc9b9771b8046c7353f51fcf..8abbca789f34f98efa79944b1c4f6423dade2c80:/samples/widgets/widgets.cpp?ds=sidebyside diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index c5f4700478..23f5cafda4 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -4,7 +4,6 @@ // Purpose: Sample showing most of the simple wxWidgets widgets // Author: Vadim Zeitlin // Created: 27.03.01 -// Id: $Id$ // Copyright: (c) 2001 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -88,6 +87,8 @@ enum Widgets_BorderDouble, Widgets_BorderDefault, + Widgets_LayoutDirection, + Widgets_GlobalBusyCursor, Widgets_BusyCursor, @@ -99,6 +100,7 @@ enum TextEntry_DisableAutoComplete = TextEntry_Begin, TextEntry_AutoCompleteFixed, TextEntry_AutoCompleteFilenames, + TextEntry_AutoCompleteDirectories, TextEntry_AutoCompleteCustom, TextEntry_SetHint, @@ -167,6 +169,8 @@ protected: void OnEnable(wxCommandEvent& event); void OnSetBorder(wxCommandEvent& event); + void OnToggleLayoutDirection(wxCommandEvent& event); + void OnToggleGlobalBusyCursor(wxCommandEvent& event); void OnToggleBusyCursor(wxCommandEvent& event); @@ -174,6 +178,7 @@ protected: void OnDisableAutoComplete(wxCommandEvent& event); void OnAutoCompleteFixed(wxCommandEvent& event); void OnAutoCompleteFilenames(wxCommandEvent& event); + void OnAutoCompleteDirectories(wxCommandEvent& event); void OnAutoCompleteCustom(wxCommandEvent& event); void OnSetHint(wxCommandEvent& event); @@ -297,12 +302,15 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame) EVT_MENU_RANGE(Widgets_BorderNone, Widgets_BorderDefault, WidgetsFrame::OnSetBorder) + EVT_MENU(Widgets_LayoutDirection, WidgetsFrame::OnToggleLayoutDirection) + EVT_MENU(Widgets_GlobalBusyCursor, WidgetsFrame::OnToggleGlobalBusyCursor) EVT_MENU(Widgets_BusyCursor, WidgetsFrame::OnToggleBusyCursor) EVT_MENU(TextEntry_DisableAutoComplete, WidgetsFrame::OnDisableAutoComplete) EVT_MENU(TextEntry_AutoCompleteFixed, WidgetsFrame::OnAutoCompleteFixed) EVT_MENU(TextEntry_AutoCompleteFilenames, WidgetsFrame::OnAutoCompleteFilenames) + EVT_MENU(TextEntry_AutoCompleteDirectories, WidgetsFrame::OnAutoCompleteDirectories) EVT_MENU(TextEntry_AutoCompleteCustom, WidgetsFrame::OnAutoCompleteCustom) EVT_MENU(TextEntry_SetHint, WidgetsFrame::OnSetHint) @@ -344,10 +352,6 @@ bool WidgetsApp::OnInit() title += wxT("wxMAC"); #elif defined(__WXMOTIF__) title += wxT("wxMOTIF"); -#elif defined(__WXPALMOS5__) - title += wxT("wxPALMOS5"); -#elif defined(__WXPALMOS6__) - title += wxT("wxPALMOS6"); #else title += wxT("wxWidgets"); #endif @@ -401,6 +405,10 @@ WidgetsFrame::WidgetsFrame(const wxString& title) menuBorders->AppendRadioItem(Widgets_BorderSunken, wxT("S&unken\tCtrl-Shift-5")); menuWidget->AppendSubMenu(menuBorders, wxT("Set &border")); + menuWidget->AppendSeparator(); + menuWidget->AppendCheckItem(Widgets_LayoutDirection, + "Toggle &layout direction\tCtrl-L"); + menuWidget->AppendSeparator(); menuWidget->AppendCheckItem(Widgets_GlobalBusyCursor, wxT("Toggle &global busy cursor\tCtrl-Shift-U")); @@ -418,6 +426,8 @@ WidgetsFrame::WidgetsFrame(const wxString& title) wxT("Fixed-&list auto-completion")); menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFilenames, wxT("&Files names auto-completion")); + menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteDirectories, + wxT("&Directories names auto-completion")); menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteCustom, wxT("&Custom auto-completion")); menuTextEntry->AppendSeparator(); @@ -800,11 +810,11 @@ void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event)) // allow for debugging the default colour the first time this is called WidgetsPage *page = CurrentPage(); - if (!m_colFg.Ok()) + if (!m_colFg.IsOk()) m_colFg = page->GetForegroundColour(); wxColour col = GetColourFromUser(this, m_colFg); - if ( !col.Ok() ) + if ( !col.IsOk() ) return; m_colFg = col; @@ -823,11 +833,11 @@ void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event)) { WidgetsPage *page = CurrentPage(); - if ( !m_colBg.Ok() ) + if ( !m_colBg.IsOk() ) m_colBg = page->GetBackgroundColour(); wxColour col = GetColourFromUser(this, m_colBg); - if ( !col.Ok() ) + if ( !col.IsOk() ) return; m_colBg = col; @@ -845,7 +855,7 @@ void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event)) void WidgetsFrame::OnSetPageBg(wxCommandEvent& WXUNUSED(event)) { wxColour col = GetColourFromUser(this, GetBackgroundColour()); - if ( !col.Ok() ) + if ( !col.IsOk() ) return; CurrentPage()->SetBackgroundColour(col); @@ -857,11 +867,11 @@ void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event)) #if wxUSE_FONTDLG WidgetsPage *page = CurrentPage(); - if (!m_font.Ok()) + if (!m_font.IsOk()) m_font = page->GetFont(); wxFont font = wxGetFontFromUser(this, m_font); - if ( !font.Ok() ) + if ( !font.IsOk() ) return; m_font = font; @@ -874,6 +884,10 @@ void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event)) (*it)->SetFont(m_font); (*it)->Refresh(); } + + // The best size of the widget could have changed after changing its font, + // so re-layout to show it correctly. + page->Layout(); #else wxLogMessage(wxT("Font selection dialog not available in current build.")); #endif @@ -917,6 +931,21 @@ void WidgetsFrame::OnSetBorder(wxCommandEvent& event) page->RecreateWidget(); } +void WidgetsFrame::OnToggleLayoutDirection(wxCommandEvent& event) +{ + wxLayoutDirection dir = event.IsChecked() ? wxLayout_RightToLeft + : wxLayout_LeftToRight; + + const Widgets widgets = CurrentPage()->GetWidgets(); + for ( Widgets::const_iterator it = widgets.begin(); + it != widgets.end(); + ++it ) + { + (*it)->SetLayoutDirection(dir); + (*it)->Refresh(); + } +} + void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent& event) { if ( event.IsChecked() ) @@ -995,6 +1024,21 @@ void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event)) } } +void WidgetsFrame::OnAutoCompleteDirectories(wxCommandEvent& WXUNUSED(event)) +{ + wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); + wxCHECK_RET( entry, "menu item should be disabled" ); + + if ( entry->AutoCompleteDirectories() ) + { + wxLogMessage("Enabled auto completion of directories."); + } + else + { + wxLogMessage("AutoCompleteDirectories() failed."); + } +} + void WidgetsFrame::OnAutoCompleteCustom(wxCommandEvent& WXUNUSED(event)) { wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); @@ -1006,7 +1050,7 @@ void WidgetsFrame::OnAutoCompleteCustom(wxCommandEvent& WXUNUSED(event)) // known. This allows to avoid building the full 676000 item list of // possible strings all at once as the we have 1000 possibilities for the // first word (000..999) and 676 (aa..zz) for the second one. - class CustomTextCompleter : public wxTextCompleter + class CustomTextCompleter : public wxTextCompleterSimple { public: virtual void GetCompletions(const wxString& prefix, wxArrayString& res)