2005-02-05 06:35:48 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: minimal.cpp
|
|
|
|
// Purpose: Popup wxWidgets sample
|
2005-02-05 13:38:26 -05:00
|
|
|
// Author: Robert Roebling
|
2005-02-05 06:35:48 -05:00
|
|
|
// Modified by:
|
2005-02-05 13:38:26 -05:00
|
|
|
// Created: 2005-02-04
|
2005-02-05 06:35:48 -05:00
|
|
|
// RCS-ID: $Id$
|
2005-02-05 13:38:26 -05:00
|
|
|
// Copyright: (c) 2005 Robert Roebling
|
2005-02-05 06:35:48 -05:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/popupwin.h"
|
2005-02-16 17:36:54 -05:00
|
|
|
#include "wx/spinctrl.h"
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 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__)
|
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2005-02-16 17:36:54 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
2005-02-05 13:44:25 -05:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// SimpleTransientPopup
|
|
|
|
//----------------------------------------------------------------------------
|
2005-02-05 06:35:48 -05:00
|
|
|
class SimpleTransientPopup: public wxPopupTransientWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SimpleTransientPopup( wxWindow *parent );
|
|
|
|
virtual ~SimpleTransientPopup();
|
2005-02-05 13:44:25 -05:00
|
|
|
|
|
|
|
// 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 );
|
2005-02-08 15:58:19 -05:00
|
|
|
|
2005-02-05 13:44:25 -05:00
|
|
|
wxScrolledWindow* GetChild() { return m_panel; }
|
2005-02-08 15:58:19 -05:00
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
private:
|
2005-02-05 13:44:25 -05:00
|
|
|
wxScrolledWindow *m_panel;
|
2005-02-16 17:36:54 -05:00
|
|
|
wxButton *m_button;
|
|
|
|
wxSpinCtrl *m_spinCtrl;
|
2005-04-14 23:04:30 -04:00
|
|
|
wxStaticText *m_mouseText;
|
2005-02-08 15:58:19 -05:00
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
private:
|
|
|
|
void OnMouse( wxMouseEvent &event );
|
|
|
|
void OnSize( wxSizeEvent &event );
|
|
|
|
void OnSetFocus( wxFocusEvent &event );
|
|
|
|
void OnKillFocus( wxFocusEvent &event );
|
2005-02-16 17:36:54 -05:00
|
|
|
void OnButton( wxCommandEvent& event );
|
|
|
|
void OnSpinCtrl( wxSpinEvent& event );
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_CLASS(SimpleTransientPopup)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// SimpleTransientPopup
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
IMPLEMENT_CLASS(SimpleTransientPopup,wxPopupTransientWindow)
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(SimpleTransientPopup,wxPopupTransientWindow)
|
|
|
|
EVT_MOUSE_EVENTS( SimpleTransientPopup::OnMouse )
|
|
|
|
EVT_SIZE( SimpleTransientPopup::OnSize )
|
|
|
|
EVT_SET_FOCUS( SimpleTransientPopup::OnSetFocus )
|
|
|
|
EVT_KILL_FOCUS( SimpleTransientPopup::OnKillFocus )
|
2005-02-16 17:36:54 -05:00
|
|
|
EVT_BUTTON( Minimal_PopupButton, SimpleTransientPopup::OnButton )
|
|
|
|
EVT_SPINCTRL( Minimal_PopupSpinctrl, SimpleTransientPopup::OnSpinCtrl )
|
2005-02-05 06:35:48 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2005-04-12 00:28:40 -04:00
|
|
|
SimpleTransientPopup::SimpleTransientPopup( wxWindow *parent )
|
|
|
|
:wxPopupTransientWindow( parent )
|
2005-02-05 06:35:48 -05:00
|
|
|
{
|
2005-02-08 15:58:19 -05:00
|
|
|
m_panel = new wxScrolledWindow( this, wxID_ANY );
|
2005-02-05 06:35:48 -05:00
|
|
|
m_panel->SetBackgroundColour( *wxLIGHT_GREY );
|
2005-04-12 00:28:40 -04:00
|
|
|
|
|
|
|
// 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
|
2005-04-14 23:04:30 -04:00
|
|
|
m_panel->Connect(wxEVT_MOTION,
|
|
|
|
wxMouseEventHandler(SimpleTransientPopup::OnMouse),
|
|
|
|
NULL, this);
|
2005-04-12 00:28:40 -04:00
|
|
|
|
2005-02-08 15:58:19 -05:00
|
|
|
wxStaticText *text = new wxStaticText( m_panel, wxID_ANY,
|
2005-02-05 06:35:48 -05:00
|
|
|
wxT("wx.PopupTransientWindow is a\n")
|
|
|
|
wxT("wx.PopupWindow 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")
|
2005-04-14 23:04:30 -04:00
|
|
|
wxT("any other way.") );
|
2005-02-16 17:36:54 -05:00
|
|
|
|
2005-04-14 23:04:30 -04:00
|
|
|
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 ->"));
|
2005-03-01 11:53:22 -05:00
|
|
|
|
2005-04-14 23:04:30 -04:00
|
|
|
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->SetAutoLayout( true );
|
|
|
|
m_panel->SetSizer( topSizer );
|
|
|
|
topSizer->Fit(m_panel);
|
|
|
|
topSizer->Fit(this);
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTransientPopup::~SimpleTransientPopup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-02-05 13:44:25 -05:00
|
|
|
void SimpleTransientPopup::Popup(wxWindow *focus)
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::Popup"), long(this) );
|
2005-04-12 00:28:40 -04:00
|
|
|
wxPopupTransientWindow::Popup(focus ? focus : m_panel);
|
2005-02-05 13:44:25 -05:00
|
|
|
}
|
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
void SimpleTransientPopup::OnDismiss()
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnDismiss"), long(this) );
|
2005-02-05 13:44:25 -05:00
|
|
|
wxPopupTransientWindow::OnDismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleTransientPopup::ProcessLeftDown(wxMouseEvent& event)
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::ProcessLeftDown pos(%d, %d)"), long(this), event.GetX(), event.GetY());
|
2005-02-05 13:44:25 -05:00
|
|
|
return wxPopupTransientWindow::ProcessLeftDown(event);
|
|
|
|
}
|
|
|
|
bool SimpleTransientPopup::Show( bool show )
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::Show %d"), long(this), int(show));
|
2005-02-05 13:44:25 -05:00
|
|
|
return wxPopupTransientWindow::Show(show);
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTransientPopup::OnSize(wxSizeEvent &event)
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSize"), long(this) );
|
2005-02-05 06:35:48 -05:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTransientPopup::OnSetFocus(wxFocusEvent &event)
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSetFocus"), long(this) );
|
2005-02-05 13:38:26 -05:00
|
|
|
event.Skip();
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTransientPopup::OnKillFocus(wxFocusEvent &event)
|
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnKillFocus"), long(this) );
|
2005-02-05 13:38:26 -05:00
|
|
|
event.Skip();
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTransientPopup::OnMouse(wxMouseEvent &event)
|
|
|
|
{
|
2005-04-14 23:04:30 -04:00
|
|
|
wxRect rect(m_mouseText->GetRect());
|
|
|
|
rect.SetX(-100000);
|
|
|
|
rect.SetWidth(1000000);
|
|
|
|
wxColour colour(*wxLIGHT_GREY);
|
|
|
|
|
2006-10-02 01:31:21 -04:00
|
|
|
if (rect.Contains(event.GetPosition()))
|
2005-04-14 23:04:30 -04:00
|
|
|
{
|
|
|
|
colour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
|
2005-04-12 00:28:40 -04:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnMouse pos(%d, %d)"), long(event.GetEventObject()), event.GetX(), event.GetY());
|
2005-04-14 23:04:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (colour != m_mouseText->GetBackgroundColour())
|
|
|
|
{
|
|
|
|
m_mouseText->SetBackgroundColour(colour);
|
|
|
|
m_mouseText->Refresh();
|
|
|
|
}
|
2005-02-05 13:44:25 -05:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2005-02-16 17:36:54 -05:00
|
|
|
void SimpleTransientPopup::OnButton(wxCommandEvent& event)
|
2005-02-05 13:44:25 -05:00
|
|
|
{
|
2005-03-03 16:07:12 -05:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnButton ID %d"), long(this), event.GetId());
|
2005-02-08 15:58:19 -05:00
|
|
|
|
2005-02-16 17:36:54 -05:00
|
|
|
wxButton *button = wxDynamicCast(event.GetEventObject(), wxButton);
|
|
|
|
if (button->GetLabel() == wxT("Press Me"))
|
|
|
|
button->SetLabel(wxT("Pressed"));
|
2005-02-08 15:58:19 -05:00
|
|
|
else
|
2005-02-16 17:36:54 -05:00
|
|
|
button->SetLabel(wxT("Press Me"));
|
2005-02-05 13:44:25 -05:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2005-02-16 17:36:54 -05:00
|
|
|
void SimpleTransientPopup::OnSpinCtrl(wxSpinEvent& event)
|
2005-02-05 13:44:25 -05:00
|
|
|
{
|
2006-10-02 01:36:31 -04:00
|
|
|
wxLogMessage( wxT("0x%lx SimpleTransientPopup::OnSpinCtrl ID %d Value %d"), long(this), event.GetId(), event.GetInt());
|
2005-02-05 06:35:48 -05:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyDialog : public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyDialog(const wxString& title);
|
|
|
|
|
|
|
|
void OnStartSimplePopup(wxCommandEvent& event);
|
2005-02-05 13:44:25 -05:00
|
|
|
void OnStartScrolledPopup(wxCommandEvent& event);
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
private:
|
2005-04-12 00:28:40 -04:00
|
|
|
SimpleTransientPopup *m_simplePopup;
|
|
|
|
SimpleTransientPopup *m_scrolledPopup;
|
2005-02-05 06:35:48 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame(const wxString& title);
|
2005-02-05 13:44:25 -05:00
|
|
|
virtual ~MyFrame();
|
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnTestDialog(wxCommandEvent& event);
|
|
|
|
void OnStartSimplePopup(wxCommandEvent& event);
|
2005-02-05 13:44:25 -05:00
|
|
|
void OnStartScrolledPopup(wxCommandEvent& event);
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
private:
|
2005-04-12 00:28:40 -04:00
|
|
|
SimpleTransientPopup *m_simplePopup;
|
|
|
|
SimpleTransientPopup *m_scrolledPopup;
|
2005-02-16 17:36:54 -05:00
|
|
|
wxTextCtrl *m_logWin;
|
2005-02-05 13:44:25 -05:00
|
|
|
wxLog *m_logOld;
|
2005-02-05 06:35:48 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2005-02-16 17:36:54 -05:00
|
|
|
class MyApp : public wxApp
|
2005-02-05 06:35:48 -05:00
|
|
|
{
|
2005-02-16 17:36:54 -05:00
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
|
|
|
|
MyFrame *m_frame;
|
2005-02-05 06:35:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables and other macros for wxWidgets
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
// create the main application window
|
2005-02-16 17:36:54 -05:00
|
|
|
m_frame = new MyFrame(_T("Popup wxWidgets App"));
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
// and show it (the frames, unlike simple controls, are not shown when
|
|
|
|
// created initially)
|
2005-02-16 17:36:54 -05:00
|
|
|
m_frame->Show(true);
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
// success: wxApp::OnRun() will be called which will enter the main message
|
|
|
|
// loop and the application will run. If we returned false here, the
|
|
|
|
// application would exit immediately.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(Minimal_About, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(Minimal_TestDialog, MyFrame::OnTestDialog)
|
|
|
|
EVT_BUTTON(Minimal_StartSimplePopup, MyFrame::OnStartSimplePopup)
|
2005-02-05 13:44:25 -05:00
|
|
|
EVT_BUTTON(Minimal_StartScrolledPopup, MyFrame::OnStartScrolledPopup)
|
2005-02-05 06:35:48 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyFrame::MyFrame(const wxString& title)
|
|
|
|
: wxFrame(NULL, wxID_ANY, title)
|
|
|
|
{
|
2005-04-12 00:28:40 -04:00
|
|
|
m_simplePopup = m_scrolledPopup = NULL;
|
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
|
|
|
#if wxUSE_MENUS
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
|
|
|
|
// the "About" item should be in the help menu
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
|
|
|
helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("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"));
|
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
|
|
|
menuBar->Append(menuFile, _T("&File"));
|
|
|
|
menuBar->Append(helpMenu, _T("&Help"));
|
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
2005-04-14 23:04:30 -04:00
|
|
|
#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
|
|
|
|
|
2005-04-12 00:28:40 -04:00
|
|
|
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) );
|
2005-02-05 13:44:25 -05:00
|
|
|
|
2005-04-12 00:28:40 -04:00
|
|
|
m_logWin = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxTE_MULTILINE );
|
2005-02-16 17:36:54 -05:00
|
|
|
m_logWin->SetEditable(false);
|
|
|
|
wxLogTextCtrl* logger = new wxLogTextCtrl( m_logWin );
|
2005-02-05 13:44:25 -05:00
|
|
|
m_logOld = logger->SetActiveTarget( logger );
|
|
|
|
logger->SetTimestamp( NULL );
|
2005-02-08 15:58:19 -05:00
|
|
|
|
2005-02-05 13:44:25 -05:00
|
|
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
2005-04-12 00:28:40 -04:00
|
|
|
topSizer->Add( button1, 0, wxALL, 5 );
|
|
|
|
topSizer->Add( button2, 0, wxALL, 5 );
|
|
|
|
topSizer->Add( m_logWin, 1, wxEXPAND|wxALL, 5 );
|
2005-02-05 06:35:48 -05:00
|
|
|
|
2005-04-12 00:28:40 -04:00
|
|
|
panel->SetAutoLayout( true );
|
|
|
|
panel->SetSizer( topSizer );
|
2005-02-05 06:35:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-02-08 15:58:19 -05:00
|
|
|
MyFrame::~MyFrame()
|
|
|
|
{
|
|
|
|
delete wxLog::SetActiveTarget(m_logOld);
|
|
|
|
}
|
2005-02-05 13:44:25 -05:00
|
|
|
|
|
|
|
|
2005-02-05 06:35:48 -05:00
|
|
|
// event handlers
|
|
|
|
|
|
|
|
void MyFrame::OnStartSimplePopup(wxCommandEvent& event)
|
|
|
|
{
|
2005-02-16 17:36:54 -05:00
|
|
|
wxLogMessage( wxT("================================================") );
|
2005-04-12 00:28:40 -04:00
|
|
|
delete m_simplePopup;
|
|
|
|
m_simplePopup = new SimpleTransientPopup( this );
|
2005-02-05 06:35:48 -05:00
|
|
|
wxWindow *btn = (wxWindow*) event.GetEventObject();
|
|
|
|
wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
|
|
|
|
wxSize sz = btn->GetSize();
|
2005-04-12 00:28:40 -04:00
|
|
|
m_simplePopup->Position( pos, sz );
|
|
|
|
wxLogMessage( wxT("0x%lx Simple Popup Shown pos(%d, %d) size(%d, %d)"), long(m_simplePopup), pos.x, pos.y, sz.x, sz.y );
|
|
|
|
m_simplePopup->Popup();
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
2005-02-05 13:44:25 -05:00
|
|
|
void MyFrame::OnStartScrolledPopup(wxCommandEvent& event)
|
2005-02-05 06:35:48 -05:00
|
|
|
{
|
2005-02-05 13:44:25 -05:00
|
|
|
wxLogMessage( wxT("================================================") );
|
2005-04-12 00:28:40 -04:00
|
|
|
delete m_scrolledPopup;
|
|
|
|
m_scrolledPopup = new SimpleTransientPopup( this );
|
|
|
|
m_scrolledPopup->GetChild()->SetScrollbars(1, 1, 1000, 1000);
|
2005-02-05 13:44:25 -05:00
|
|
|
wxWindow *btn = (wxWindow*) event.GetEventObject();
|
|
|
|
wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
|
|
|
|
wxSize sz = btn->GetSize();
|
2005-04-12 00:28:40 -04:00
|
|
|
m_scrolledPopup->Position( pos, sz );
|
|
|
|
wxLogMessage( wxT("0x%lx Scrolled Popup Shown pos(%d, %d) size(%d, %d)"), long(m_scrolledPopup), pos.x, pos.y, sz.x, sz.y );
|
|
|
|
m_scrolledPopup->Popup();
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
MyDialog dialog( wxT("Test") );
|
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
wxMessageBox(msg, _T("About Popup"), wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test dialog
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyDialog, wxDialog)
|
|
|
|
EVT_BUTTON(Minimal_StartSimplePopup, MyDialog::OnStartSimplePopup)
|
2005-02-05 13:44:25 -05:00
|
|
|
EVT_BUTTON(Minimal_StartScrolledPopup, MyDialog::OnStartScrolledPopup)
|
2005-02-05 06:35:48 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyDialog::MyDialog(const wxString& title)
|
2005-04-12 00:28:40 -04:00
|
|
|
:wxDialog(NULL, wxID_ANY, title, wxPoint(50,50), wxSize(400,300))
|
2005-02-05 06:35:48 -05:00
|
|
|
{
|
2005-04-12 00:28:40 -04:00
|
|
|
m_simplePopup = m_scrolledPopup = NULL;
|
|
|
|
wxPanel *panel = new wxPanel(this, -1);
|
2005-02-05 06:35:48 -05:00
|
|
|
|
2005-04-12 00:28:40 -04:00
|
|
|
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,60) );
|
2005-02-05 06:35:48 -05:00
|
|
|
|
2005-04-12 00:28:40 -04:00
|
|
|
wxButton *okButton = new wxButton( panel, wxID_OK, wxT("OK"), wxPoint(20,200) );
|
|
|
|
|
|
|
|
wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
topSizer->Add( button1, 0, wxALL, 5 );
|
|
|
|
topSizer->Add( button2, 0, wxALL, 5 );
|
|
|
|
topSizer->AddSpacer(40);
|
|
|
|
topSizer->Add( okButton, 0, wxALL, 5 );
|
|
|
|
|
|
|
|
panel->SetAutoLayout( true );
|
|
|
|
panel->SetSizer( topSizer );
|
|
|
|
topSizer->Fit(this);
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyDialog::OnStartSimplePopup(wxCommandEvent& event)
|
|
|
|
{
|
2005-02-16 17:36:54 -05:00
|
|
|
wxLogMessage( wxT("================================================") );
|
2005-04-12 00:28:40 -04:00
|
|
|
delete m_simplePopup;
|
|
|
|
m_simplePopup = new SimpleTransientPopup( this );
|
2005-02-05 06:35:48 -05:00
|
|
|
wxWindow *btn = (wxWindow*) event.GetEventObject();
|
|
|
|
wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
|
|
|
|
wxSize sz = btn->GetSize();
|
2005-04-12 00:28:40 -04:00
|
|
|
m_simplePopup->Position( pos, sz );
|
|
|
|
wxLogMessage( wxT("0x%lx Dialog Simple Popup Shown pos(%d, %d) size(%d, %d)"), long(m_simplePopup), pos.x, pos.y, sz.x, sz.y );
|
|
|
|
m_simplePopup->Popup();
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|
|
|
|
|
2005-02-05 13:44:25 -05:00
|
|
|
void MyDialog::OnStartScrolledPopup(wxCommandEvent& event)
|
2005-02-05 06:35:48 -05:00
|
|
|
{
|
2005-02-05 13:44:25 -05:00
|
|
|
wxLogMessage( wxT("================================================") );
|
2005-04-12 00:28:40 -04:00
|
|
|
delete m_scrolledPopup;
|
|
|
|
m_scrolledPopup = new SimpleTransientPopup( this );
|
|
|
|
m_scrolledPopup->GetChild()->SetScrollbars(1, 1, 1000, 1000);
|
2005-02-05 13:44:25 -05:00
|
|
|
wxWindow *btn = (wxWindow*) event.GetEventObject();
|
|
|
|
wxPoint pos = btn->ClientToScreen( wxPoint(0,0) );
|
|
|
|
wxSize sz = btn->GetSize();
|
2005-04-12 00:28:40 -04:00
|
|
|
m_scrolledPopup->Position( pos, sz );
|
|
|
|
wxLogMessage( wxT("0x%lx Dialog Scrolled Popup Shown pos(%d, %d) size(%d, %d)"), long(m_scrolledPopup), pos.x, pos.y, sz.x, sz.y );
|
|
|
|
m_scrolledPopup->Popup();
|
2005-02-05 06:35:48 -05:00
|
|
|
}
|