1998-08-27 17:08:39 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dynamic.cpp
|
2004-05-25 07:20:37 -04:00
|
|
|
// Purpose: Dynamic events wxWidgets sample
|
1998-08-27 17:08:39 -04:00
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 06:55:54 -05:00
|
|
|
// Copyright: (c) Julian Smart
|
1999-02-05 11:44:52 -05:00
|
|
|
// Licence: wxWindows license
|
1998-08-27 17:08:39 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
#include "wx/clntdata.h"
|
|
|
|
|
2005-08-23 11:54:39 -04:00
|
|
|
#ifndef __WXMSW__
|
1998-08-27 17:08:39 -04:00
|
|
|
#include "mondrian.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Define a new application type
|
|
|
|
class MyApp: public wxApp
|
2005-08-22 15:50:54 -04:00
|
|
|
{
|
2005-06-26 11:48:02 -04:00
|
|
|
public:
|
1998-08-27 17:08:39 -04:00
|
|
|
bool OnInit(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type
|
|
|
|
class MyFrame: public wxFrame
|
2005-08-22 15:50:54 -04:00
|
|
|
{
|
2005-06-26 11:48:02 -04:00
|
|
|
public:
|
2002-12-14 13:13:27 -05:00
|
|
|
MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
|
1999-02-05 11:44:52 -05:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
public:
|
1998-08-27 17:08:39 -04:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
2005-06-26 11:48:02 -04:00
|
|
|
void OnTest(wxCommandEvent& event);
|
1998-08-27 17:08:39 -04:00
|
|
|
void OnAbout(wxCommandEvent& event);
|
2005-08-22 15:50:54 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
protected:
|
|
|
|
wxShadowObject m_shadow;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define another new frame type
|
|
|
|
class MySecondFrame: public MyFrame
|
2005-08-22 15:50:54 -04:00
|
|
|
{
|
2005-06-26 11:48:02 -04:00
|
|
|
public:
|
|
|
|
MySecondFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
|
1998-08-27 17:08:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ID for the menu commands
|
2005-06-02 08:04:48 -04:00
|
|
|
#define DYNAMIC_QUIT wxID_EXIT
|
2005-06-26 11:48:02 -04:00
|
|
|
#define DYNAMIC_TEST 101
|
2005-06-02 08:04:48 -04:00
|
|
|
#define DYNAMIC_ABOUT wxID_ABOUT
|
1998-08-27 17:08:39 -04:00
|
|
|
|
|
|
|
// Create a new application object
|
1999-02-05 11:44:52 -05:00
|
|
|
IMPLEMENT_APP (MyApp)
|
1998-08-27 17:08:39 -04:00
|
|
|
|
|
|
|
// `Main program' equivalent, creating windows and returning main app frame
|
|
|
|
bool MyApp::OnInit(void)
|
|
|
|
{
|
2005-06-26 11:48:02 -04:00
|
|
|
// Create the main frame window
|
|
|
|
MyFrame *frame = new MyFrame(NULL, _T("Dynamic wxWidgets App"), 50, 50, 450, 340);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
// Show the frame
|
|
|
|
frame->Show(true);
|
2005-08-22 15:50:54 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
// Create the main frame window
|
|
|
|
MySecondFrame *frame2 = new MySecondFrame(NULL, _T("Dynamic wxWidgets App"), 150, 150, 450, 340);
|
2005-08-22 15:50:54 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
// Show the frame
|
|
|
|
frame2->Show(true);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
SetTopWindow(frame);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
return true;
|
|
|
|
}
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
// -------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// -------------------------------------
|
1999-02-05 11:44:52 -05:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
// Callback from wxShadowObject
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-08-22 15:50:54 -04:00
|
|
|
int cb_MyFrame_InitStatusbar( void* window, void* WXUNUSED(param) )
|
2005-06-26 11:48:02 -04:00
|
|
|
{
|
|
|
|
MyFrame *frame = (MyFrame*) window;
|
|
|
|
frame->SetStatusText( wxT("Hello from MyFrame"), 0 );
|
|
|
|
return 0;
|
1998-08-27 17:08:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// My frame constructor
|
2002-12-14 13:13:27 -05:00
|
|
|
MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
2004-05-28 06:43:39 -04:00
|
|
|
wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
2005-06-26 11:48:02 -04:00
|
|
|
{
|
|
|
|
// Give it an icon
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
SetIcon(wxIcon(_T("mondrian")));
|
|
|
|
#else
|
|
|
|
SetIcon(wxIcon(mondrian_xpm));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
|
|
|
file_menu->Append(DYNAMIC_ABOUT, _T("&About"));
|
|
|
|
file_menu->Append(DYNAMIC_TEST, _T("&Test"));
|
|
|
|
file_menu->Append(DYNAMIC_QUIT, _T("E&xit"));
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
|
|
|
SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
// Make a panel with a message
|
|
|
|
wxPanel *panel = new wxPanel(this, wxID_ANY, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
|
|
|
|
|
|
|
|
(void)new wxStaticText(panel, 311, _T("Hello!"), wxPoint(10, 10), wxDefaultSize, 0);
|
|
|
|
|
|
|
|
// You used to have to do some casting for param 4, but now there are type-safe handlers
|
|
|
|
Connect( DYNAMIC_QUIT, wxID_ANY,
|
|
|
|
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) );
|
|
|
|
Connect( DYNAMIC_TEST, wxID_ANY,
|
|
|
|
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnTest) );
|
|
|
|
Connect( DYNAMIC_ABOUT, wxID_ANY,
|
|
|
|
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) );
|
2005-08-22 15:50:54 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
CreateStatusBar();
|
|
|
|
m_shadow.AddMethod( wxT("OnTest"), &cb_MyFrame_InitStatusbar );
|
|
|
|
}
|
1998-08-27 17:08:39 -04:00
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2005-06-26 11:48:02 -04:00
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnTest(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
m_shadow.InvokeMethod( wxT("OnTest"), this, NULL, NULL );
|
1998-08-27 17:08:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2005-06-26 11:48:02 -04:00
|
|
|
wxMessageDialog dialog(this, _T("This demonstrates dynamic event handling"),
|
|
|
|
_T("About Dynamic"), wxYES_NO|wxCANCEL);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
dialog.ShowModal();
|
1998-08-27 17:08:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-26 11:48:02 -04:00
|
|
|
// -------------------------------------
|
|
|
|
// MySecondFrame
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
// Callback from wxShadowObject
|
|
|
|
|
2005-08-22 15:50:54 -04:00
|
|
|
int cb_MySecondFrame_InitStatusbar( void* window, void* WXUNUSED(param) )
|
2005-06-26 11:48:02 -04:00
|
|
|
{
|
|
|
|
MySecondFrame *frame = (MySecondFrame*) window;
|
|
|
|
frame->SetStatusText( wxT("Hello from MySecondFrame"), 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// My frame constructor
|
|
|
|
MySecondFrame::MySecondFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
|
|
|
|
MyFrame(frame, title, x, y, w, h )
|
|
|
|
{
|
|
|
|
m_shadow.AddMethod( wxT("OnTest"), &cb_MySecondFrame_InitStatusbar );
|
|
|
|
}
|