]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/gizmos/dynsash/dynsash.cpp
some basic docs for wxBase
[wxWidgets.git] / contrib / samples / gizmos / dynsash / dynsash.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dynsash.cpp
3 // Purpose: Test the wxDynamicSash class by creating a dynamic sash which
4 // contains an HTML view
5 // Author: Matt Kimball
6 // Modified by:
7 // Created: 7/15/2001
8 // RCS-ID: $Id$
9 // Copyright: (c) 2001 Matt Kimball
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #include <wx/app.h>
14 #include <wx/gizmos/dynamicsash.h>
15 #include <wx/html/htmlwin.h>
16 #include <wx/image.h>
17
18 class Demo : public wxApp {
19 public:
20 bool OnInit();
21 };
22
23 class SashHtmlWindow : public wxHtmlWindow {
24 public:
25 SashHtmlWindow(wxWindow *parent, wxWindowID id = -1,
26 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
27 long style = wxHW_SCROLLBAR_NEVER, const wxString& name = "sashHtmlWindow");
28
29 wxSize DoGetBestSize() const;
30
31 private:
32 void OnSplit(wxDynamicSashSplitEvent& event);
33
34 wxWindow *m_dyn_sash;
35 };
36
37 IMPLEMENT_APP(Demo)
38
39 char *HTML_content =
40 "<P><H1>wxDynamicSashWindow demo</H1>"
41 "<P>Here is an example of how you can use <TT>wxDynamicSashWindow</TT> to allow your users to "
42 "dynamically split and unify the views of your windows. Try dragging out a few splits "
43 "and then reunifying the window."
44 "<P>Also, see the <TT>dynsash_switch</TT> sample for an example of an application which "
45 "manages the scrollbars provided by <TT>wxDynamicSashWindow</TT> itself."
46 ;
47
48 bool Demo::OnInit() {
49 wxInitAllImageHandlers();
50
51 wxFrame *frame = new wxFrame(NULL, -1, "Dynamic Sash Demo");
52 frame->SetSize(480, 480);
53
54 wxDynamicSashWindow *sash = new wxDynamicSashWindow(frame, -1);
55 wxHtmlWindow *html = new SashHtmlWindow(sash, -1);
56 html->SetPage(HTML_content);
57
58 frame->Show();
59
60 return TRUE;
61 }
62
63
64 SashHtmlWindow::SashHtmlWindow(wxWindow *parent, wxWindowID id,
65 const wxPoint& pos, const wxSize& size, long style, const wxString& name) :
66 wxHtmlWindow(parent, id, pos, size, style, name) {
67 Connect(-1, wxEVT_DYNAMIC_SASH_SPLIT, (wxObjectEventFunction)&SashHtmlWindow::OnSplit);
68
69 m_dyn_sash = parent;
70 }
71
72 wxSize SashHtmlWindow::DoGetBestSize() const {
73 wxHtmlContainerCell *cell = GetInternalRepresentation();
74 wxSize size = GetSize();
75
76 if (cell) {
77 cell->Layout(size.GetWidth());
78 return wxSize(cell->GetWidth(), cell->GetHeight());
79 } else
80 return wxHtmlWindow::GetBestSize();
81 }
82
83 void SashHtmlWindow::OnSplit(wxDynamicSashSplitEvent& event) {
84 wxHtmlWindow *html = new SashHtmlWindow(m_dyn_sash, -1);
85 html->SetPage(HTML_content);
86 }