/////////////////////////////////////////////////////////////////////////////
-// Name: minimal.cpp
+// Name: popup.cpp
// Purpose: Popup wxWidgets sample
// Author: Robert Roebling
// Modified by:
// 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
wxScrolledWindow *m_panel;
wxButton *m_button;
wxSpinCtrl *m_spinCtrl;
+ wxStaticText *m_mouseText;
private:
void OnMouse( wxMouseEvent &event );
m_panel = new wxScrolledWindow( this, wxID_ANY );
m_panel->SetBackgroundColour( *wxLIGHT_GREY );
- // Keep this code to verify if mouse events work, they're required if
+ // Keep this code to verify if mouse events work, they're required if
// you're making a control like a combobox where the items are highlighted
// under the cursor, the m_panel is set focus in the Popup() function
- //m_panel->Connect(wxEVT_MOTION,
- // wxMouseEventHandler(SimpleTransientPopup::OnMouse),
- // NULL, this);
+ m_panel->Connect(wxEVT_MOTION,
+ wxMouseEventHandler(SimpleTransientPopup::OnMouse),
+ NULL, this);
wxStaticText *text = new wxStaticText( m_panel, wxID_ANY,
- wxT("wx.PopupTransientWindow is a\n")
- wxT("wx.PopupWindow which disappears\n")
+ wxT("wxPopupTransientWindow is a\n")
+ wxT("wxPopupWindow which disappears\n")
wxT("automatically when the user\n")
wxT("clicks the mouse outside it or if it\n")
wxT("(or its first child) loses focus in \n")
- wxT("any other way."), wxPoint( 10,10) );
- wxSize size = text->GetBestSize();
+ wxT("any other way.") );
- 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_button = new wxButton(m_panel, Minimal_PopupButton, wxT("Press Me"));
+ m_spinCtrl = new wxSpinCtrl(m_panel, Minimal_PopupSpinctrl, wxT("Hello"));
+ m_mouseText = new wxStaticText(m_panel, wxID_ANY,
+ wxT("<- Test Mouse ->"));
- m_panel->SetSize( size.x+20, size.y+20 );
- SetClientSize( size.x+20, size.y+20 );
+ wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
+ topSizer->Add( text, 0, wxALL, 5 );
+ topSizer->Add( m_button, 0, wxALL, 5 );
+ topSizer->Add( m_spinCtrl, 0, wxALL, 5 );
+ topSizer->Add( m_mouseText, 0, wxCENTRE|wxALL, 5 );
+
+ m_panel->SetSizer( topSizer );
+ topSizer->Fit(m_panel);
+ topSizer->Fit(this);
}
SimpleTransientPopup::~SimpleTransientPopup()
{
}
-void SimpleTransientPopup::Popup(wxWindow *focus)
+void SimpleTransientPopup::Popup(wxWindow* WXUNUSED(focus))
{
wxLogMessage( wxT("0x%lx SimpleTransientPopup::Popup"), long(this) );
- wxPopupTransientWindow::Popup(focus ? focus : m_panel);
+ wxPopupTransientWindow::Popup();
}
void SimpleTransientPopup::OnDismiss()
void SimpleTransientPopup::OnMouse(wxMouseEvent &event)
{
- wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnMouse pos(%d, %d)"), long(event.GetEventObject()), event.GetX(), event.GetY());
+ wxRect rect(m_mouseText->GetRect());
+ rect.SetX(-100000);
+ rect.SetWidth(1000000);
+ wxColour colour(*wxLIGHT_GREY);
+
+ if (rect.Contains(event.GetPosition()))
+ {
+ colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnMouse pos(%d, %d)"),
+ long(event.GetEventObject()), event.GetX(), event.GetY());
+ }
+
+ if (colour != m_mouseText->GetBackgroundColour())
+ {
+ m_mouseText->SetBackgroundColour(colour);
+ m_mouseText->Refresh();
+ }
event.Skip();
}
void SimpleTransientPopup::OnSpinCtrl(wxSpinEvent& event)
{
- wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSpinCtrl ID %d Value %ld"), long(this), event.GetId(), event.GetInt());
+ wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSpinCtrl ID %d Value %d"),
+ long(this), event.GetId(), event.GetInt());
event.Skip();
}
void OnTestDialog(wxCommandEvent& event);
void OnStartSimplePopup(wxCommandEvent& event);
void OnStartScrolledPopup(wxCommandEvent& event);
+ void OnActivate(wxActivateEvent& event);
private:
SimpleTransientPopup *m_simplePopup;
// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
+ if ( !wxApp::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)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
EVT_MENU(Minimal_TestDialog, MyFrame::OnTestDialog)
+ EVT_ACTIVATE(MyFrame::OnActivate)
EVT_BUTTON(Minimal_StartSimplePopup, MyFrame::OnStartSimplePopup)
EVT_BUTTON(Minimal_StartScrolledPopup, MyFrame::OnStartScrolledPopup)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title)
- : wxFrame(NULL, wxID_ANY, title)
+: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(500,300))
{
m_simplePopup = m_scrolledPopup = NULL;
// 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);
#endif // wxUSE_MENUS
+#if wxUSE_STATUSBAR
+ // create a status bar just for fun (by default with 1 pane only)
+ CreateStatusBar(2);
+ SetStatusText(wxT("Welcome to wxWidgets!"));
+#endif // wxUSE_STATUSBAR
+
wxPanel *panel = new wxPanel(this, -1);
wxButton *button1 = new wxButton( panel, Minimal_StartSimplePopup, wxT("Show simple popup"), wxPoint(20,20) );
wxButton *button2 = new wxButton( panel, Minimal_StartScrolledPopup, wxT("Show scrolled popup"), wxPoint(20,70) );
m_logWin->SetEditable(false);
wxLogTextCtrl* logger = new wxLogTextCtrl( m_logWin );
m_logOld = logger->SetActiveTarget( logger );
- logger->SetTimestamp( NULL );
+ logger->DisableTimestamp();
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
topSizer->Add( button1, 0, wxALL, 5 );
topSizer->Add( button2, 0, wxALL, 5 );
topSizer->Add( m_logWin, 1, wxEXPAND|wxALL, 5 );
- panel->SetAutoLayout( true );
panel->SetSizer( topSizer );
-#if wxUSE_STATUSBAR
- // create a status bar just for fun (by default with 1 pane only)
- CreateStatusBar(2);
- SetStatusText(_T("Welcome to wxWidgets!"));
-#endif // wxUSE_STATUSBAR
}
MyFrame::~MyFrame()
// event handlers
+void MyFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
+{
+ wxLogMessage( wxT("In activate...") );
+}
+
void MyFrame::OnStartSimplePopup(wxCommandEvent& event)
{
wxLogMessage( wxT("================================================") );
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);
}
// ----------------------------------------------------------------------------
topSizer->AddSpacer(40);
topSizer->Add( okButton, 0, wxALL, 5 );
- panel->SetAutoLayout( true );
- panel->SetSizer( topSizer );
- topSizer->Fit(this);
+ panel->SetSizerAndFit( topSizer );
}
void MyDialog::OnStartSimplePopup(wxCommandEvent& event)