#endif
#include "wx/popupwin.h"
+#include "wx/spinctrl.h"
// ----------------------------------------------------------------------------
// resources
#include "../sample.xpm"
#endif
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// IDs for the controls and the menu commands
+enum
+{
+ Minimal_Quit = wxID_EXIT,
+ Minimal_About = wxID_ABOUT,
+ Minimal_TestDialog,
+ Minimal_StartSimplePopup,
+ Minimal_StartScrolledPopup,
+ Minimal_LogWindow,
+ Minimal_PopupButton,
+ Minimal_PopupSpinctrl
+};
+
+//----------------------------------------------------------------------------
+// SimpleTransientPopup
+//----------------------------------------------------------------------------
class SimpleTransientPopup: public wxPopupTransientWindow
{
public:
SimpleTransientPopup( wxWindow *parent );
virtual ~SimpleTransientPopup();
-
- void OnDismiss();
-
+
+ // wxPopupTransientWindow virtual methods are all overridden to log them
+ virtual void Popup(wxWindow *focus = NULL);
+ virtual void OnDismiss();
+ virtual bool ProcessLeftDown(wxMouseEvent& event);
+ virtual bool Show( bool show = true );
+
+ wxScrolledWindow* GetChild() { return m_panel; }
+
private:
- wxPanel *m_panel;
-
+ wxScrolledWindow *m_panel;
+ wxButton *m_button;
+ wxSpinCtrl *m_spinCtrl;
+
private:
void OnMouse( wxMouseEvent &event );
void OnSize( wxSizeEvent &event );
void OnSetFocus( wxFocusEvent &event );
void OnKillFocus( wxFocusEvent &event );
+ void OnButton( wxCommandEvent& event );
+ void OnSpinCtrl( wxSpinEvent& event );
private:
DECLARE_CLASS(SimpleTransientPopup)
DECLARE_EVENT_TABLE()
};
-
//----------------------------------------------------------------------------
// SimpleTransientPopup
//----------------------------------------------------------------------------
-
IMPLEMENT_CLASS(SimpleTransientPopup,wxPopupTransientWindow)
BEGIN_EVENT_TABLE(SimpleTransientPopup,wxPopupTransientWindow)
EVT_SIZE( SimpleTransientPopup::OnSize )
EVT_SET_FOCUS( SimpleTransientPopup::OnSetFocus )
EVT_KILL_FOCUS( SimpleTransientPopup::OnKillFocus )
+ EVT_BUTTON( Minimal_PopupButton, SimpleTransientPopup::OnButton )
+ EVT_SPINCTRL( Minimal_PopupSpinctrl, SimpleTransientPopup::OnSpinCtrl )
END_EVENT_TABLE()
SimpleTransientPopup::SimpleTransientPopup( wxWindow *parent ) :
wxPopupTransientWindow( parent )
{
- m_panel = new wxPanel( this, -1 );
+ m_panel = new wxScrolledWindow( this, wxID_ANY );
m_panel->SetBackgroundColour( *wxLIGHT_GREY );
- wxStaticText *text = new wxStaticText( m_panel, -1,
+ wxStaticText *text = new wxStaticText( m_panel, wxID_ANY,
wxT("wx.PopupTransientWindow is a\n")
wxT("wx.PopupWindow which disappears\n")
wxT("automatically when the user\n")
wxT("(or its first child) loses focus in \n")
wxT("any other way."), wxPoint( 10,10) );
wxSize size = text->GetBestSize();
+
+ m_button = new wxButton(m_panel, Minimal_PopupButton, wxT("Press Me"), wxPoint(0, size.y + 10));
+ size.y = m_button->GetRect().GetBottom();
+ m_spinCtrl = new wxSpinCtrl(m_panel, Minimal_PopupSpinctrl, wxT("Hello"), wxPoint(0, size.y + 5));
+ size.y = m_spinCtrl->GetRect().GetBottom();
+
m_panel->SetSize( size.x+20, size.y+20 );
SetClientSize( size.x+20, size.y+20 );
}
{
}
+void SimpleTransientPopup::Popup(wxWindow *focus)
+{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::Popup"), long(this) );
+ wxPopupTransientWindow::Popup(focus);
+}
+
void SimpleTransientPopup::OnDismiss()
{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnDismiss"), long(this) );
+ wxPopupTransientWindow::OnDismiss();
+}
+
+bool SimpleTransientPopup::ProcessLeftDown(wxMouseEvent& event)
+{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::ProcessLeftDown pos(%d, %d)"), long(this), event.GetX(), event.GetY());
+ return wxPopupTransientWindow::ProcessLeftDown(event);
+}
+bool SimpleTransientPopup::Show( bool show )
+{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::Show %d"), long(this), int(show));
+ return wxPopupTransientWindow::Show(show);
}
void SimpleTransientPopup::OnSize(wxSizeEvent &event)
{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSize"), long(this) );
event.Skip();
}
void SimpleTransientPopup::OnSetFocus(wxFocusEvent &event)
{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSetFocus"), long(this) );
event.Skip();
}
void SimpleTransientPopup::OnKillFocus(wxFocusEvent &event)
{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnKillFocus"), long(this) );
event.Skip();
}
void SimpleTransientPopup::OnMouse(wxMouseEvent &event)
{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnMouse pos(%d, %d)"), long(this), event.GetX(), event.GetY());
+ event.Skip();
+}
+
+void SimpleTransientPopup::OnButton(wxCommandEvent& event)
+{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnButton ID %d"), long(this), event.GetId());
+
+ wxButton *button = wxDynamicCast(event.GetEventObject(), wxButton);
+ if (button->GetLabel() == wxT("Press Me"))
+ button->SetLabel(wxT("Pressed"));
+ else
+ button->SetLabel(wxT("Press Me"));
+
+ event.Skip();
+}
+
+void SimpleTransientPopup::OnSpinCtrl(wxSpinEvent& event)
+{
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSpinCtrl ID %d Value %ld"), long(this), event.GetId(), event.GetInt());
event.Skip();
}
// private classes
// ----------------------------------------------------------------------------
-class MyApp : public wxApp
-{
-public:
- virtual bool OnInit();
-};
-
class MyDialog : public wxDialog
{
public:
MyDialog(const wxString& title);
void OnStartSimplePopup(wxCommandEvent& event);
- void OnStartComplexPopup(wxCommandEvent& event);
+ void OnStartScrolledPopup(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
{
public:
MyFrame(const wxString& title);
+ virtual ~MyFrame();
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnTestDialog(wxCommandEvent& event);
void OnStartSimplePopup(wxCommandEvent& event);
- void OnStartComplexPopup(wxCommandEvent& event);
+ void OnStartScrolledPopup(wxCommandEvent& event);
private:
+ wxTextCtrl *m_logWin;
+ wxLog *m_logOld;
DECLARE_EVENT_TABLE()
};
-// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-// IDs for the controls and the menu commands
-enum
+class MyApp : public wxApp
{
- Minimal_Quit = wxID_EXIT,
- Minimal_About = wxID_ABOUT,
- Minimal_TestDialog,
- Minimal_StartSimplePopup,
- Minimal_StartComplexPopup,
+public:
+ virtual bool OnInit();
+
+ MyFrame *m_frame;
};
// ----------------------------------------------------------------------------
bool MyApp::OnInit()
{
// create the main application window
- MyFrame *frame = new MyFrame(_T("Popup wxWidgets App"));
+ m_frame = new MyFrame(_T("Popup wxWidgets App"));
// and show it (the frames, unlike simple controls, are not shown when
// created initially)
- frame->Show(true);
+ m_frame->Show(true);
// success: wxApp::OnRun() will be called which will enter the main message
// loop and the application will run. If we returned false here, the
EVT_MENU(Minimal_About, MyFrame::OnAbout)
EVT_MENU(Minimal_TestDialog, MyFrame::OnTestDialog)
EVT_BUTTON(Minimal_StartSimplePopup, MyFrame::OnStartSimplePopup)
- EVT_BUTTON(Minimal_StartComplexPopup, MyFrame::OnStartComplexPopup)
+ EVT_BUTTON(Minimal_StartScrolledPopup, MyFrame::OnStartScrolledPopup)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title)
SetMenuBar(menuBar);
#endif // wxUSE_MENUS
- new wxButton( this, Minimal_StartSimplePopup, wxT("Show simple popup"), wxPoint(20,20) );
- new wxButton( this, Minimal_StartComplexPopup, wxT("Show complex popup"), wxPoint(20,120) );
+ wxButton *button1 = new wxButton( this, Minimal_StartSimplePopup, wxT("Show simple popup"), wxPoint(20,20) );
+ wxButton *button2 = new wxButton( this, Minimal_StartScrolledPopup, wxT("Show scrolled popup"), wxPoint(20,70) );
+
+ m_logWin = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+ wxDefaultSize, wxTE_MULTILINE );
+ m_logWin->SetEditable(false);
+ wxLogTextCtrl* logger = new wxLogTextCtrl( m_logWin );
+ m_logOld = logger->SetActiveTarget( logger );
+ logger->SetTimestamp( NULL );
+
+ wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
+ topSizer->Add( button1, 0 );
+ topSizer->Add( button2, 0 );
+ topSizer->Add( m_logWin, 1, wxEXPAND );
+ SetAutoLayout( true );
+ SetSizer( topSizer );
#if wxUSE_STATUSBAR
// create a status bar just for fun (by default with 1 pane only)
#endif // wxUSE_STATUSBAR
}
+MyFrame::~MyFrame()
+{
+ delete wxLog::SetActiveTarget(m_logOld);
+}
+
+
// event handlers
void MyFrame::OnStartSimplePopup(wxCommandEvent& event)
{
+ wxLogMessage( wxT("================================================") );
SimpleTransientPopup* popup = new SimpleTransientPopup( this );
wxWindow *btn = (wxWindow*) event.GetEventObject();
wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
wxSize sz = btn->GetSize();
popup->Position( pos, sz );
+ wxLogMessage( wxT("0x%lx Simple Popup Shown pos(%d, %d) size(%d, %d)"), long(popup), pos.x, pos.y, sz.x, sz.y );
popup->Popup();
}
-void MyFrame::OnStartComplexPopup(wxCommandEvent& WXUNUSED(event))
+void MyFrame::OnStartScrolledPopup(wxCommandEvent& event)
{
+ wxLogMessage( wxT("================================================") );
+ SimpleTransientPopup* popup = new SimpleTransientPopup( this );
+ popup->GetChild()->SetScrollbars(1, 1, 1000, 1000);
+ wxWindow *btn = (wxWindow*) event.GetEventObject();
+ wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
+ wxSize sz = btn->GetSize();
+ popup->Position( pos, sz );
+ wxLogMessage( wxT("0x%lx Scrolled Popup Shown pos(%d, %d) size(%d, %d)"), long(popup), pos.x, pos.y, sz.x, sz.y );
+ popup->Popup();
}
void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
BEGIN_EVENT_TABLE(MyDialog, wxDialog)
EVT_BUTTON(Minimal_StartSimplePopup, MyDialog::OnStartSimplePopup)
- EVT_BUTTON(Minimal_StartComplexPopup, MyDialog::OnStartComplexPopup)
+ EVT_BUTTON(Minimal_StartScrolledPopup, MyDialog::OnStartScrolledPopup)
END_EVENT_TABLE()
MyDialog::MyDialog(const wxString& title)
{
new wxButton( this, Minimal_StartSimplePopup, wxT("Show simple popup"), wxPoint(20,20) );
- new wxButton( this, Minimal_StartComplexPopup, wxT("Show complex popup"), wxPoint(20,80) );
+ new wxButton( this, Minimal_StartScrolledPopup, wxT("Show scrolled popup"), wxPoint(20,60) );
new wxButton( this, wxID_OK, wxT("OK"), wxPoint(20,200) );
}
void MyDialog::OnStartSimplePopup(wxCommandEvent& event)
{
+ wxLogMessage( wxT("================================================") );
SimpleTransientPopup* popup = new SimpleTransientPopup( this );
wxWindow *btn = (wxWindow*) event.GetEventObject();
wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
wxSize sz = btn->GetSize();
popup->Position( pos, sz );
+ wxLogMessage( wxT("0x%lx Dialog Simple Popup Shown pos(%d, %d) size(%d, %d)"), long(popup), pos.x, pos.y, sz.x, sz.y );
popup->Popup();
}
-void MyDialog::OnStartComplexPopup(wxCommandEvent& WXUNUSED(event))
+void MyDialog::OnStartScrolledPopup(wxCommandEvent& event)
{
+ wxLogMessage( wxT("================================================") );
+ SimpleTransientPopup* popup = new SimpleTransientPopup( this );
+ popup->GetChild()->SetScrollbars(1, 1, 1000, 1000);
+ wxWindow *btn = (wxWindow*) event.GetEventObject();
+ wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
+ wxSize sz = btn->GetSize();
+ popup->Position( pos, sz );
+ wxLogMessage( wxT("0x%lx Dialog Scrolled Popup Shown pos(%d, %d) size(%d, %d)"), long(popup), pos.x, pos.y, sz.x, sz.y );
+ popup->Popup();
}
-