1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "tree.cpp"
21 #pragma interface "tree.cpp"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
31 // for all others, include the necessary headers (this file is usually all you
32 // need because it includes almost all "standard" wxWindows headers)
37 #include "wx/imaglist.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
43 // the application icon
44 #if defined(__WXGTK__) || defined(__WXMOTIF__)
45 #include "mondrian.xpm"
48 // ----------------------------------------------------------------------------
49 // event tables and other macros for wxWindows
50 // ----------------------------------------------------------------------------
52 // the event tables connect the wxWindows events with the functions (event
53 // handlers) which process them. It can be also done at run-time, but for the
54 // simple menu events like this the static method is much simpler.
55 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
56 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
57 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
60 // Create a new application object: this macro will allow wxWindows to create
61 // the application object during program execution (it's better than using a
62 // static object for many reasons) and also declares the accessor function
63 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
72 // the application class
73 // ----------------------------------------------------------------------------
75 // 'Main program' equivalent: the program execution "starts" here
78 // create the main application window
79 MyFrame
*frame
= new MyFrame("Tree Testing",
80 wxPoint(50, 50), wxSize(450, 340));
82 // and show it (the frames, unlike simple controls, are not shown when
86 // success: wxApp::OnRun() will be called which will enter the main message
87 // loop and the application will run. If we returned FALSE here, the
88 // application would exit immediately.
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
97 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
98 : wxFrame((wxFrame
*)NULL
, idMAIN_FRAME
, title
, pos
, size
)
101 m_scrolledWindow
= NULL
;
103 m_valueWindow
= NULL
;
105 // we need this in order to allow the about menu relocation, since ABOUT is
106 // not the default id of the about menu
107 wxApp::s_macAboutMenuItemId
= Minimal_About
;
110 m_scrolledWindow
= new wxSplitterScrolledWindow(this, idSCROLLED_WINDOW
, wxDefaultPosition
,
111 wxDefaultSize
, wxNO_BORDER
| wxCLIP_CHILDREN
| wxVSCROLL
);
112 m_splitter
= new wxThinSplitterWindow(m_scrolledWindow
, idSPLITTER_WINDOW
, wxDefaultPosition
,
113 wxDefaultSize
, wxSP_3DBORDER
| wxCLIP_CHILDREN
/* | wxSP_LIVE_UPDATE */);
114 m_splitter
->SetSashSize(2);
115 m_tree
= new TestTree(m_splitter
, idTREE_CTRL
, wxDefaultPosition
,
116 wxDefaultSize
, wxTR_HAS_BUTTONS
| wxTR_NO_LINES
| wxNO_BORDER
);
117 m_valueWindow
= new TestValueWindow(m_splitter
, idVALUE_WINDOW
, wxDefaultPosition
,
118 wxDefaultSize
, wxNO_BORDER
);
119 m_splitter
->SplitVertically(m_tree
, m_valueWindow
);
120 //m_splitter->AdjustScrollbars();
121 m_splitter
->SetSashPosition(200);
122 m_scrolledWindow
->SetTargetWindow(m_tree
);
124 m_scrolledWindow
->EnableScrolling(FALSE
, FALSE
);
126 // Let the two controls know about each other
127 m_valueWindow
->SetTreeCtrl(m_tree
);
128 m_tree
->SetCompanionWindow(m_valueWindow
);
130 // set the frame icon
131 SetIcon(wxICON(mondrian
));
134 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
136 // the "About" item should be in the help menu
137 wxMenu
*helpMenu
= new wxMenu
;
138 helpMenu
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
140 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
142 // now append the freshly created menu to the menu bar...
143 wxMenuBar
*menuBar
= new wxMenuBar();
144 menuBar
->Append(menuFile
, "&File");
145 menuBar
->Append(helpMenu
, "&Help");
147 // ... and attach this menu bar to the frame
154 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
156 // TRUE is to force the frame to close
160 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
163 msg
.Printf( _T("This is the about dialog of tree sample.\n")
164 _T("Welcome to %s"), wxVERSION_STRING
);
166 wxMessageBox(msg
, "About Tree Test", wxOK
| wxICON_INFORMATION
, this);
173 IMPLEMENT_CLASS(TestTree
, wxRemotelyScrolledTreeCtrl
)
175 BEGIN_EVENT_TABLE(TestTree
, wxRemotelyScrolledTreeCtrl
)
176 EVT_PAINT(TestTree::OnPaint
)
179 TestTree::TestTree(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pt
,
180 const wxSize
& sz
, long style
):
181 wxRemotelyScrolledTreeCtrl(parent
, id
, pt
, sz
, style
)
183 m_imageList
= new wxImageList(16, 16, TRUE
);
184 #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW
185 m_imageList
->Add(wxIcon(icon1_xpm
));
186 m_imageList
->Add(wxIcon(icon2_xpm
));
187 m_imageList
->Add(wxIcon(icon3_xpm
));
188 m_imageList
->Add(wxIcon(icon4_xpm
));
189 m_imageList
->Add(wxIcon(icon5_xpm
));
190 m_imageList
->Add(wxIcon(icon6_xpm
));
191 m_imageList
->Add(wxIcon(icon7_xpm
));
192 m_imageList
->Add(wxIcon(icon8_xpm
));
193 #elif defined(__WXMSW__)
194 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
195 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
196 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE
));
197 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_ICO_RESOURCE
));
198 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_ICO_RESOURCE
));
199 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_ICO_RESOURCE
));
200 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_ICO_RESOURCE
));
201 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_ICO_RESOURCE
));
203 #error "Sorry, we don't have icons available for this platforms."
205 SetImageList(m_imageList
);
208 // Add some dummy items
209 wxTreeItemId rootId
= AddRoot(_("Root"), 3, -1);
211 for (i
= 1; i
<= 20; i
++)
214 label
.Printf(wxT("Item %d"), i
);
215 wxTreeItemId id
= AppendItem(rootId
, label
, 0);
216 SetItemImage( id
, 1, wxTreeItemIcon_Expanded
);
219 for (j
= 0; j
< 10; j
++)
220 AppendItem(id
, _("Child"), 2);
225 TestTree::~TestTree()
231 void TestTree::OnPaint(wxPaintEvent
& event
)
235 wxTreeCtrl::OnPaint(event
);
237 // Reset the device origin since it may have been set
238 dc
.SetDeviceOrigin(0, 0);
240 wxSize sz
= GetClientSize();
242 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
244 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
246 wxSize clientSize
= GetClientSize();
249 wxTreeItemId h
, lastH
;
250 for(h
=GetFirstVisibleItem();h
;h
=GetNextVisible(h
))
252 if (GetBoundingRect(h
, itemRect
))
254 cy
= itemRect
.GetTop();
255 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
259 if (GetBoundingRect(lastH
, itemRect
))
261 cy
= itemRect
.GetBottom();
262 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
270 //IMPLEMENT_CLASS(TestValueWindow, wxWindow)
272 BEGIN_EVENT_TABLE(TestValueWindow
, wxTreeCompanionWindow
)
275 TestValueWindow::TestValueWindow(wxWindow
* parent
, wxWindowID id
,
279 wxTreeCompanionWindow(parent
, id
, pos
, sz
, style
)
281 SetBackgroundColour(* wxWHITE
);