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