X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/494492906358a8041c95e950b63b4c4d345b08cc..14619f10b0bdb630206607abd0ce0319d45e095a:/samples/popup/popup.cpp?ds=sidebyside diff --git a/samples/popup/popup.cpp b/samples/popup/popup.cpp index 547a1bf1a0..ed0097e955 100644 --- a/samples/popup/popup.cpp +++ b/samples/popup/popup.cpp @@ -39,7 +39,7 @@ // the application icon (under Windows and OS/2 it is in resources and even // though we could still include the XPM here it would be unused) -#if !defined(__WXMSW__) && !defined(__WXPM__) +#ifndef wxHAS_IMAGES_IN_RESOURCES #include "../sample.xpm" #endif @@ -66,7 +66,7 @@ enum class SimpleTransientPopup: public wxPopupTransientWindow { public: - SimpleTransientPopup( wxWindow *parent ); + SimpleTransientPopup( wxWindow *parent, bool scrolled ); virtual ~SimpleTransientPopup(); // wxPopupTransientWindow virtual methods are all overridden to log them @@ -75,8 +75,6 @@ public: virtual bool ProcessLeftDown(wxMouseEvent& event); virtual bool Show( bool show = true ); - wxScrolledWindow* GetChild() { return m_panel; } - private: wxScrolledWindow *m_panel; wxButton *m_button; @@ -110,7 +108,7 @@ BEGIN_EVENT_TABLE(SimpleTransientPopup,wxPopupTransientWindow) EVT_SPINCTRL( Minimal_PopupSpinctrl, SimpleTransientPopup::OnSpinCtrl ) END_EVENT_TABLE() -SimpleTransientPopup::SimpleTransientPopup( wxWindow *parent ) +SimpleTransientPopup::SimpleTransientPopup( wxWindow *parent, bool scrolled ) :wxPopupTransientWindow( parent ) { m_panel = new wxScrolledWindow( this, wxID_ANY ); @@ -142,9 +140,30 @@ SimpleTransientPopup::SimpleTransientPopup( wxWindow *parent ) topSizer->Add( m_spinCtrl, 0, wxALL, 5 ); topSizer->Add( m_mouseText, 0, wxCENTRE|wxALL, 5 ); + if ( scrolled ) + { + // Add a big window to ensure that scrollbars are shown when we set the + // panel size to a lesser size below. + topSizer->Add(new wxPanel(m_panel, wxID_ANY, wxDefaultPosition, + wxSize(600, 900))); + } + m_panel->SetSizer( topSizer ); - topSizer->Fit(m_panel); - topSizer->Fit(this); + if ( scrolled ) + { + // Set the fixed size to ensure that the scrollbars are shown. + m_panel->SetSize(300, 300); + + // And also actually enable them. + m_panel->SetScrollRate(10, 10); + } + else + { + // Use the fitting size for the panel if we don't need scrollbars. + topSizer->Fit(m_panel); + } + + SetClientSize(m_panel->GetSize()); } SimpleTransientPopup::~SimpleTransientPopup() @@ -295,7 +314,7 @@ bool MyApp::OnInit() return false; // create the main application window - m_frame = new MyFrame(_T("Popup wxWidgets App")); + m_frame = new MyFrame(wxT("Popup wxWidgets App")); // and show it (the frames, unlike simple controls, are not shown when // created initially) @@ -332,15 +351,15 @@ MyFrame::MyFrame(const wxString& title) // the "About" item should be in the help menu wxMenu *helpMenu = new wxMenu; - helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog")); + helpMenu->Append(Minimal_About, wxT("&About\tF1"), wxT("Show about dialog")); - menuFile->Append(Minimal_TestDialog, _T("&Test dialog\tAlt-T"), _T("Test dialog")); - menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); + menuFile->Append(Minimal_TestDialog, wxT("&Test dialog\tAlt-T"), wxT("Test dialog")); + menuFile->Append(Minimal_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program")); // now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); - menuBar->Append(menuFile, _T("&File")); - menuBar->Append(helpMenu, _T("&Help")); + menuBar->Append(menuFile, wxT("&File")); + menuBar->Append(helpMenu, wxT("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); @@ -349,7 +368,7 @@ MyFrame::MyFrame(const wxString& title) #if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) CreateStatusBar(2); - SetStatusText(_T("Welcome to wxWidgets!")); + SetStatusText(wxT("Welcome to wxWidgets!")); #endif // wxUSE_STATUSBAR wxPanel *panel = new wxPanel(this, -1); @@ -389,7 +408,7 @@ void MyFrame::OnStartSimplePopup(wxCommandEvent& event) { wxLogMessage( wxT("================================================") ); delete m_simplePopup; - m_simplePopup = new SimpleTransientPopup( this ); + m_simplePopup = new SimpleTransientPopup( this, false ); wxWindow *btn = (wxWindow*) event.GetEventObject(); wxPoint pos = btn->ClientToScreen( wxPoint(0,0) ); wxSize sz = btn->GetSize(); @@ -402,8 +421,7 @@ void MyFrame::OnStartScrolledPopup(wxCommandEvent& event) { wxLogMessage( wxT("================================================") ); delete m_scrolledPopup; - m_scrolledPopup = new SimpleTransientPopup( this ); - m_scrolledPopup->GetChild()->SetScrollbars(1, 1, 1000, 1000); + m_scrolledPopup = new SimpleTransientPopup( this, true ); wxWindow *btn = (wxWindow*) event.GetEventObject(); wxPoint pos = btn->ClientToScreen( wxPoint(0,0) ); wxSize sz = btn->GetSize(); @@ -427,10 +445,10 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxString msg; - msg.Printf( _T("This is the About dialog of the popup sample.\n") - _T("Welcome to %s"), wxVERSION_STRING); + msg.Printf( wxT("This is the About dialog of the popup sample.\n") + wxT("Welcome to %s"), wxVERSION_STRING); - wxMessageBox(msg, _T("About Popup"), wxOK | wxICON_INFORMATION, this); + wxMessageBox(msg, wxT("About Popup"), wxOK | wxICON_INFORMATION, this); } // ---------------------------------------------------------------------------- @@ -466,7 +484,7 @@ void MyDialog::OnStartSimplePopup(wxCommandEvent& event) { wxLogMessage( wxT("================================================") ); delete m_simplePopup; - m_simplePopup = new SimpleTransientPopup( this ); + m_simplePopup = new SimpleTransientPopup( this, false ); wxWindow *btn = (wxWindow*) event.GetEventObject(); wxPoint pos = btn->ClientToScreen( wxPoint(0,0) ); wxSize sz = btn->GetSize(); @@ -479,8 +497,7 @@ void MyDialog::OnStartScrolledPopup(wxCommandEvent& event) { wxLogMessage( wxT("================================================") ); delete m_scrolledPopup; - m_scrolledPopup = new SimpleTransientPopup( this ); - m_scrolledPopup->GetChild()->SetScrollbars(1, 1, 1000, 1000); + m_scrolledPopup = new SimpleTransientPopup( this, true ); wxWindow *btn = (wxWindow*) event.GetEventObject(); wxPoint pos = btn->ClientToScreen( wxPoint(0,0) ); wxSize sz = btn->GetSize();