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 #if !defined(__WXMSW__) || wxUSE_XPM_IN_MSW
39 static char * icon1_xpm
[] = {
40 /* width height ncolors chars_per_pixel */
68 static char * icon2_xpm
[] = {
69 /* width height ncolors chars_per_pixel */
94 #include "wx/imaglist.h"
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
100 // the application icon
101 #if defined(__WXGTK__) || defined(__WXMOTIF__)
102 #include "mondrian.xpm"
105 // ----------------------------------------------------------------------------
106 // event tables and other macros for wxWindows
107 // ----------------------------------------------------------------------------
109 // the event tables connect the wxWindows events with the functions (event
110 // handlers) which process them. It can be also done at run-time, but for the
111 // simple menu events like this the static method is much simpler.
112 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
113 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
114 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
117 // Create a new application object: this macro will allow wxWindows to create
118 // the application object during program execution (it's better than using a
119 // static object for many reasons) and also declares the accessor function
120 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
124 // ============================================================================
126 // ============================================================================
128 // ----------------------------------------------------------------------------
129 // the application class
130 // ----------------------------------------------------------------------------
132 // 'Main program' equivalent: the program execution "starts" here
135 // create the main application window
136 MyFrame
*frame
= new MyFrame("Tree Testing",
137 wxPoint(50, 50), wxSize(450, 340));
139 // and show it (the frames, unlike simple controls, are not shown when
140 // created initially)
143 // success: wxApp::OnRun() will be called which will enter the main message
144 // loop and the application will run. If we returned FALSE here, the
145 // application would exit immediately.
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
154 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
155 : wxFrame((wxFrame
*)NULL
, idMAIN_FRAME
, title
, pos
, size
)
158 m_scrolledWindow
= NULL
;
160 m_valueWindow
= NULL
;
162 // we need this in order to allow the about menu relocation, since ABOUT is
163 // not the default id of the about menu
164 wxApp::s_macAboutMenuItemId
= Minimal_About
;
167 m_scrolledWindow
= new wxSplitterScrolledWindow(this, idSCROLLED_WINDOW
, wxDefaultPosition
,
168 wxDefaultSize
, wxNO_BORDER
| wxCLIP_CHILDREN
| wxVSCROLL
);
169 m_splitter
= new wxThinSplitterWindow(m_scrolledWindow
, idSPLITTER_WINDOW
, wxDefaultPosition
,
170 wxDefaultSize
, wxSP_3DBORDER
| wxCLIP_CHILDREN
/* | wxSP_LIVE_UPDATE */);
171 m_splitter
->SetSashSize(2);
172 m_tree
= new TestTree(m_splitter
, idTREE_CTRL
, wxDefaultPosition
,
173 wxDefaultSize
, wxTR_HAS_BUTTONS
| wxTR_NO_LINES
| wxNO_BORDER
);
174 m_valueWindow
= new TestValueWindow(m_splitter
, idVALUE_WINDOW
, wxDefaultPosition
,
175 wxDefaultSize
, wxNO_BORDER
);
176 m_splitter
->SplitVertically(m_tree
, m_valueWindow
);
177 //m_splitter->AdjustScrollbars();
178 m_splitter
->SetSashPosition(200);
179 m_scrolledWindow
->SetTargetWindow(m_tree
);
181 m_scrolledWindow
->EnableScrolling(FALSE
, FALSE
);
183 // Let the two controls know about each other
184 m_valueWindow
->SetTreeCtrl(m_tree
);
185 m_tree
->SetCompanionWindow(m_valueWindow
);
187 // set the frame icon
188 SetIcon(wxICON(mondrian
));
191 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
193 // the "About" item should be in the help menu
194 wxMenu
*helpMenu
= new wxMenu
;
195 helpMenu
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
197 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
199 // now append the freshly created menu to the menu bar...
200 wxMenuBar
*menuBar
= new wxMenuBar();
201 menuBar
->Append(menuFile
, "&File");
202 menuBar
->Append(helpMenu
, "&Help");
204 // ... and attach this menu bar to the frame
211 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
213 // TRUE is to force the frame to close
217 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
220 msg
.Printf( _T("This is the about dialog of splittree sample.\n")
221 _T("Welcome to %s"), wxVERSION_STRING
);
223 wxMessageBox(msg
, "About Tree Test", wxOK
| wxICON_INFORMATION
, this);
230 IMPLEMENT_CLASS(TestTree
, wxRemotelyScrolledTreeCtrl
)
232 BEGIN_EVENT_TABLE(TestTree
, wxRemotelyScrolledTreeCtrl
)
233 EVT_PAINT(TestTree::OnPaint
)
236 TestTree::TestTree(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pt
,
237 const wxSize
& sz
, long style
):
238 wxRemotelyScrolledTreeCtrl(parent
, id
, pt
, sz
, style
)
240 m_imageList
= new wxImageList(16, 16, TRUE
);
241 #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW
242 m_imageList
->Add(wxIcon(icon1_xpm
));
243 m_imageList
->Add(wxIcon(icon2_xpm
));
244 #elif defined(__WXMSW__)
245 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE
));
246 m_imageList
->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE
));
248 #error "Sorry, we don't have icons available for this platforms."
250 SetImageList(m_imageList
);
253 // Add some dummy items
254 wxTreeItemId rootId
= AddRoot(_("Root"), -1, -1);
256 for (i
= 1; i
<= 20; i
++)
259 label
.Printf(wxT("Item %d"), i
);
260 wxTreeItemId id
= AppendItem(rootId
, label
, 0);
261 //SetItemImage( id, 1, wxTreeItemIcon_Expanded );
264 for (j
= 0; j
< 10; j
++)
265 AppendItem(id
, _("Child"), 1);
270 TestTree::~TestTree()
276 void TestTree::OnPaint(wxPaintEvent
& event
)
280 wxTreeCtrl::OnPaint(event
);
282 // Reset the device origin since it may have been set
283 dc
.SetDeviceOrigin(0, 0);
285 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
287 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
289 wxSize clientSize
= GetClientSize();
292 wxTreeItemId h
, lastH
;
293 for(h
=GetFirstVisibleItem();h
;h
=GetNextVisible(h
))
295 if (GetBoundingRect(h
, itemRect
))
297 cy
= itemRect
.GetTop();
298 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
302 if (GetBoundingRect(lastH
, itemRect
))
304 cy
= itemRect
.GetBottom();
305 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
313 //IMPLEMENT_CLASS(TestValueWindow, wxWindow)
315 BEGIN_EVENT_TABLE(TestValueWindow
, wxTreeCompanionWindow
)
318 TestValueWindow::TestValueWindow(wxWindow
* parent
, wxWindowID id
,
322 wxTreeCompanionWindow(parent
, id
, pos
, sz
, style
)
324 SetBackgroundColour(* wxWHITE
);