]>
git.saurik.com Git - wxWidgets.git/blob - samples/scrollsub/scrollsub.cpp
4 * Author: Robert Roebling
6 * Copyright: (C) 1999, Robert Roebling
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
22 #include "wx/listctrl.h"
30 class MyScrolledWindow
;
36 class MyScrolledWindow
: public wxScrolledWindow
40 MyScrolledWindow( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
42 void OnPaint( wxPaintEvent
&event
);
47 DECLARE_DYNAMIC_CLASS(MyScrolledWindow
)
53 class MyCanvas
: public wxPanel
57 MyCanvas( wxScrolledWindow
*parent
, wxWindowID id
, const wxPoint
&pos
, const wxSize
&size
);
59 void OnPaint( wxPaintEvent
&event
);
62 wxScrolledWindow
*m_owner
;
64 DECLARE_DYNAMIC_CLASS(MyCanvas
)
70 class MyFrame
: public wxFrame
75 void OnAbout( wxCommandEvent
&event
);
76 void OnQuit( wxCommandEvent
&event
);
78 wxScrolledWindow
*m_scrolled
;
82 DECLARE_DYNAMIC_CLASS(MyFrame
)
88 class MyApp
: public wxApp
91 virtual bool OnInit();
100 IMPLEMENT_DYNAMIC_CLASS(MyScrolledWindow
, wxScrolledWindow
)
102 BEGIN_EVENT_TABLE(MyScrolledWindow
, wxScrolledWindow
)
103 EVT_PAINT( MyScrolledWindow::OnPaint
)
106 MyScrolledWindow::MyScrolledWindow( wxWindow
*parent
, wxWindowID id
,
107 const wxPoint
&pos
, const wxSize
&size
)
108 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
, "test canvas" )
110 m_canvas
= new MyCanvas( this, -1, wxDefaultPosition
, wxDefaultSize
);
112 SetTargetWindow( m_canvas
);
114 SetBackgroundColour( "WHEAT" );
116 SetCursor( wxCursor( wxCURSOR_HAND
) );
119 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
121 topsizer
->Add( m_canvas
, 1, wxEXPAND
|wxALL
, 30 );
123 SetAutoLayout( TRUE
);
124 SetSizer( topsizer
);
127 MyScrolledWindow::~MyScrolledWindow()
131 void MyScrolledWindow::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
133 wxPaintDC
dc( this );
135 wxSize
size( GetClientSize() );
138 dc
.GetTextExtent( wxT("Headline"), &w
, &h
);
140 dc
.DrawText( wxT("Headline"), long (size
.x
/ 2 - w
/ 2), 10 );
145 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxPanel
)
147 BEGIN_EVENT_TABLE(MyCanvas
, wxPanel
)
148 EVT_PAINT( MyCanvas::OnPaint
)
151 MyCanvas::MyCanvas( wxScrolledWindow
*parent
, wxWindowID id
,
152 const wxPoint
&pos
, const wxSize
&size
)
153 : wxPanel( parent
, id
, pos
, size
, wxSUNKEN_BORDER
, "test canvas" )
157 (void)new wxButton( this, -1, "Hallo I", wxPoint(20,20), wxSize(100,30) );
158 (void)new wxButton( this, -1, "Hallo II", wxPoint(220,20), wxSize(100,30) );
160 SetBackgroundColour( *wxWHITE
);
162 SetCursor( wxCursor( wxCURSOR_IBEAM
) );
165 MyCanvas::~MyCanvas()
169 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
171 wxPaintDC
dc( this );
172 m_owner
->PrepareDC( dc
);
174 dc
.SetPen( *wxBLACK_PEN
);
176 dc
.DrawText( "Some text", 140, 140 );
178 dc
.DrawRectangle( 100, 160, 200, 200 );
180 dc
.SetBrush( *wxTRANSPARENT_BRUSH
);
182 dc
.DrawRectangle( 10, 10, 480, 980 );
188 const int ID_QUIT
= 108;
189 const int ID_ABOUT
= 109;
191 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
193 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
194 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
195 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
199 : wxFrame( (wxFrame
*)NULL
, -1, "wxScrolledWindow sample",
200 wxPoint(20,20), wxSize(470,500) )
202 wxMenu
*file_menu
= new wxMenu();
203 file_menu
->Append( ID_ABOUT
, "&About..");
204 file_menu
->Append( ID_QUIT
, "E&xit\tAlt-X");
206 wxMenuBar
*menu_bar
= new wxMenuBar();
207 menu_bar
->Append(file_menu
, "&File");
209 SetMenuBar( menu_bar
);
212 int widths
[] = { -1, 100 };
213 SetStatusWidths( 2, widths
);
215 m_scrolled
= new MyScrolledWindow( this, -1, wxPoint(0,0), wxSize(100,100) );
216 m_scrolled
->SetScrollbars( 10, 10, 50, 100 );
218 m_log
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
219 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
222 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
224 topsizer
->Add( m_scrolled
, 1, wxEXPAND
);
225 topsizer
->Add( m_log
, 0, wxEXPAND
);
227 SetAutoLayout( TRUE
);
228 SetSizer( topsizer
);
231 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
236 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
238 (void)wxMessageBox( "wxScroll demo II\n"
239 "Robert Roebling (c) 1998",
240 "About wxScroll II Demo", wxICON_INFORMATION
| wxOK
);
243 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------
249 wxFrame
*frame
= new MyFrame();