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
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-08-31 18:31:03 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
2005-03-30 14:10:46 -05:00
|
|
|
#pragma implementation
|
|
|
|
#pragma interface
|
1998-08-27 17:08:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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-02-14 19:56:51 -05:00
|
|
|
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXCOCOA__)
|
1998-08-27 17:08:39 -04:00
|
|
|
#include "mondrian.xpm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Define a new application type
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{ public:
|
|
|
|
bool OnInit(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type
|
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{ 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
|
|
|
|
1998-08-27 17:08:39 -04:00
|
|
|
public:
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
};
|
|
|
|
|
|
|
|
// ID for the menu commands
|
2005-06-02 08:04:48 -04:00
|
|
|
#define DYNAMIC_QUIT wxID_EXIT
|
1999-02-05 11:44:52 -05:00
|
|
|
#define DYNAMIC_TEXT 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)
|
|
|
|
{
|
|
|
|
// Create the main frame window
|
2004-05-25 07:20:37 -04:00
|
|
|
MyFrame *frame = new MyFrame(NULL, _T("Dynamic wxWidgets App"), 50, 50, 450, 340);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2005-02-14 20:20:27 -05:00
|
|
|
// You used to have to do some casting for param 4, but now there are type-safe handlers
|
2005-03-30 14:10:46 -05:00
|
|
|
frame->Connect( DYNAMIC_QUIT, wxID_ANY,
|
2005-02-14 20:20:27 -05:00
|
|
|
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) );
|
2005-03-30 14:10:46 -05:00
|
|
|
frame->Connect( DYNAMIC_ABOUT, wxID_ANY,
|
2005-02-14 20:20:27 -05:00
|
|
|
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) );
|
1998-08-27 17:08:39 -04:00
|
|
|
|
|
|
|
// Give it an icon
|
|
|
|
#ifdef __WXMSW__
|
2002-12-14 13:13:27 -05:00
|
|
|
frame->SetIcon(wxIcon(_T("mondrian")));
|
1998-08-27 17:08:39 -04:00
|
|
|
#else
|
|
|
|
frame->SetIcon(wxIcon(mondrian_xpm));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *file_menu = new wxMenu;
|
|
|
|
|
2002-12-14 13:13:27 -05:00
|
|
|
file_menu->Append(DYNAMIC_ABOUT, _T("&About"));
|
|
|
|
file_menu->Append(DYNAMIC_QUIT, _T("E&xit"));
|
1998-08-27 17:08:39 -04:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2002-12-14 13:13:27 -05:00
|
|
|
menu_bar->Append(file_menu, _T("&File"));
|
1998-08-27 17:08:39 -04:00
|
|
|
frame->SetMenuBar(menu_bar);
|
|
|
|
|
|
|
|
// Make a panel with a message
|
2004-05-28 06:43:39 -04:00
|
|
|
wxPanel *panel = new wxPanel(frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 200), wxTAB_TRAVERSAL);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
2004-05-28 06:43:39 -04:00
|
|
|
(void)new wxStaticText(panel, 311, _T("Hello!"), wxPoint(10, 10), wxDefaultSize, 0);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
|
|
|
// Show the frame
|
2004-05-28 06:43:39 -04:00
|
|
|
frame->Show(true);
|
1999-02-05 11:44:52 -05:00
|
|
|
|
1998-08-27 17:08:39 -04:00
|
|
|
SetTopWindow(frame);
|
|
|
|
|
2004-05-28 06:43:39 -04:00
|
|
|
return true;
|
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))
|
1998-08-27 17:08:39 -04:00
|
|
|
{}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2004-05-28 06:43:39 -04:00
|
|
|
Close(true);
|
1998-08-27 17:08:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2002-12-14 13:13:27 -05:00
|
|
|
wxMessageDialog dialog(this, _T("This demonstrates dynamic event handling"),
|
|
|
|
_T("About Dynamic"), wxYES_NO|wxCANCEL);
|
1998-08-27 17:08:39 -04:00
|
|
|
|
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|