make the simple canvas larger as otherwise the simple frame couldn't be resized to make the horizontal scrollbar appear in it because of the title string width; some small cleanup

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55623 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-09-14 20:43:13 +00:00
parent 55ab5200fb
commit d9f4cc1060

View File

@@ -34,20 +34,22 @@ const long ID_INSERT_NEW = 101;
// a trivial example // a trivial example
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
class MySimpleFrame; // MySimpleCanvas: a scrolled window which draws a simple rectangle
class MySimpleCanvas;
// MySimpleCanvas
class MySimpleCanvas: public wxScrolledWindow class MySimpleCanvas: public wxScrolledWindow
{ {
public: public:
MySimpleCanvas() { } MySimpleCanvas() { }
MySimpleCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); MySimpleCanvas(wxWindow *parent);
void OnPaint( wxPaintEvent &event );
private: private:
void OnPaint(wxPaintEvent& event);
enum
{
CANVAS_WIDTH = 292,
CANVAS_HEIGHT = 297
};
DECLARE_DYNAMIC_CLASS(MyCanvas) DECLARE_DYNAMIC_CLASS(MyCanvas)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@@ -58,12 +60,14 @@ BEGIN_EVENT_TABLE(MySimpleCanvas, wxScrolledWindow)
EVT_PAINT( MySimpleCanvas::OnPaint) EVT_PAINT( MySimpleCanvas::OnPaint)
END_EVENT_TABLE() END_EVENT_TABLE()
MySimpleCanvas::MySimpleCanvas( wxWindow *parent, wxWindowID id, MySimpleCanvas::MySimpleCanvas(wxWindow *parent)
const wxPoint &pos, const wxSize &size ) : wxScrolledWindow(parent, wxID_ANY,
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER, _T("test canvas") ) wxDefaultPosition,
wxDefaultSize,
wxSUNKEN_BORDER)
{ {
SetScrollRate( 10, 10 ); SetScrollRate( 10, 10 );
SetVirtualSize( 92, 97 ); SetVirtualSize( CANVAS_WIDTH, CANVAS_HEIGHT );
SetBackgroundColour( *wxWHITE ); SetBackgroundColour( *wxWHITE );
} }
@@ -74,21 +78,18 @@ void MySimpleCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.SetPen( *wxRED_PEN ); dc.SetPen( *wxRED_PEN );
dc.SetBrush( *wxTRANSPARENT_BRUSH ); dc.SetBrush( *wxTRANSPARENT_BRUSH );
dc.DrawRectangle( 0,0,92,97 ); dc.DrawRectangle( 0, 0, CANVAS_WIDTH, CANVAS_HEIGHT );
} }
// MySimpleFrame // MySimpleFrame: a frame which contains a MySimpleCanvas
class MySimpleFrame: public wxFrame class MySimpleFrame: public wxFrame
{ {
public: public:
MySimpleFrame(); MySimpleFrame();
void OnQuit( wxCommandEvent &event );
MySimpleCanvas *m_canvas;
private: private:
void OnClose(wxCommandEvent& WXUNUSED(event)) { Close(true); }
DECLARE_DYNAMIC_CLASS(MySimpleFrame) DECLARE_DYNAMIC_CLASS(MySimpleFrame)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
@@ -97,27 +98,22 @@ private:
IMPLEMENT_DYNAMIC_CLASS( MySimpleFrame, wxFrame ) IMPLEMENT_DYNAMIC_CLASS( MySimpleFrame, wxFrame )
BEGIN_EVENT_TABLE(MySimpleFrame,wxFrame) BEGIN_EVENT_TABLE(MySimpleFrame,wxFrame)
EVT_MENU (ID_QUIT, MySimpleFrame::OnQuit) EVT_MENU(wxID_CLOSE, MySimpleFrame::OnClose)
END_EVENT_TABLE() END_EVENT_TABLE()
MySimpleFrame::MySimpleFrame() MySimpleFrame::MySimpleFrame()
: wxFrame( (wxFrame *)NULL, wxID_ANY, _T("wxScrolledWindow sample"), : wxFrame(NULL, wxID_ANY, _T("wxScrolledWindow sample"),
wxPoint(120,120), wxSize(150,150) ) wxDefaultPosition, wxSize(200, 200))
{ {
wxMenu *file_menu = new wxMenu(); wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_QUIT, _T("E&xit\tAlt-X")); file_menu->Append(wxID_CLOSE);
wxMenuBar *menu_bar = new wxMenuBar(); wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, _T("&File")); menu_bar->Append(file_menu, _T("&File"));
SetMenuBar( menu_bar ); SetMenuBar( menu_bar );
m_canvas = new MySimpleCanvas( this, wxID_ANY, wxPoint(0,0), wxSize(100,100) ); new MySimpleCanvas(this);
}
void MySimpleFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
{
Close( true );
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------