/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/generic/treebkg.cpp
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/src/generic/treebkg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 5 months ago) by william
File size: 24307 byte(s)
exported r3113 from ./upstream/trunk
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/treebkg.cpp
3 // Purpose: generic implementation of wxTreebook
4 // Author: Evgeniy Tarassov, Vadim Zeitlin
5 // Modified by:
6 // Created: 2005-09-15
7 // RCS-ID: $Id: treebkg.cpp 54645 2008-07-15 21:29:10Z JS $
8 // Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_TREEBOOK
28
29 #include "wx/treebook.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/settings.h"
33 #endif
34
35 #include "wx/imaglist.h"
36
37 // ----------------------------------------------------------------------------
38 // various wxWidgets macros
39 // ----------------------------------------------------------------------------
40
41 // check that the page index is valid
42 #define IS_VALID_PAGE(nPage) ((nPage) < DoInternalGetPageCount())
43
44 // ----------------------------------------------------------------------------
45 // event table
46 // ----------------------------------------------------------------------------
47
48 IMPLEMENT_DYNAMIC_CLASS(wxTreebook, wxBookCtrlBase)
49 IMPLEMENT_DYNAMIC_CLASS(wxTreebookEvent, wxNotifyEvent)
50
51 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
52 const wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING = wxNewEventType();
53 const wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED = wxNewEventType();
54 const wxEventType wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED = wxNewEventType();
55 const wxEventType wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED = wxNewEventType();
56 #endif
57
58 BEGIN_EVENT_TABLE(wxTreebook, wxBookCtrlBase)
59 EVT_TREE_SEL_CHANGED (wxID_ANY, wxTreebook::OnTreeSelectionChange)
60 EVT_TREE_ITEM_EXPANDED (wxID_ANY, wxTreebook::OnTreeNodeExpandedCollapsed)
61 EVT_TREE_ITEM_COLLAPSED(wxID_ANY, wxTreebook::OnTreeNodeExpandedCollapsed)
62
63 WX_EVENT_TABLE_CONTROL_CONTAINER(wxTreebook)
64 END_EVENT_TABLE()
65
66 // ============================================================================
67 // wxTreebook implementation
68 // ============================================================================
69
70 WX_DELEGATE_TO_CONTROL_CONTAINER(wxTreebook, wxControl)
71
72 // ----------------------------------------------------------------------------
73 // wxTreebook creation
74 // ----------------------------------------------------------------------------
75
76 void wxTreebook::Init()
77 {
78 m_container.SetContainerWindow(this);
79
80 m_selection =
81 m_actualSelection = wxNOT_FOUND;
82 }
83
84 bool
85 wxTreebook::Create(wxWindow *parent,
86 wxWindowID id,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
91 {
92 // Check the style flag to have either wxTBK_RIGHT or wxTBK_LEFT
93 if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
94 {
95 style |= wxBK_LEFT;
96 }
97 style |= wxTAB_TRAVERSAL;
98
99 // no border for this control, it doesn't look nice together with the tree
100 style &= ~wxBORDER_MASK;
101 style |= wxBORDER_NONE;
102
103 if ( !wxControl::Create(parent, id, pos, size,
104 style, wxDefaultValidator, name) )
105 return false;
106
107 #ifdef __WXMSW__
108 long treeStyle = GetThemedBorderStyle();
109 #else
110 long treeStyle = wxBORDER_SUNKEN;
111 #endif
112 m_bookctrl = new wxTreeCtrl
113 (
114 this,
115 wxID_ANY,
116 wxDefaultPosition,
117 wxDefaultSize,
118 treeStyle|
119 wxTR_DEFAULT_STYLE |
120 wxTR_HIDE_ROOT |
121 wxTR_SINGLE
122 );
123 GetTreeCtrl()->SetQuickBestSize(false); // do full size calculation
124 GetTreeCtrl()->AddRoot(wxEmptyString); // label doesn't matter, it's hidden
125
126 #ifdef __WXMSW__
127 // We need to add dummy size event to force possible scrollbar hiding
128 wxSizeEvent evt;
129 GetEventHandler()->AddPendingEvent(evt);
130 #endif
131
132 return true;
133 }
134
135
136 // insert a new page just before the pagePos
137 bool wxTreebook::InsertPage(size_t pagePos,
138 wxWindow *page,
139 const wxString& text,
140 bool bSelect,
141 int imageId)
142 {
143 return DoInsertPage(pagePos, page, text, bSelect, imageId);
144 }
145
146 bool wxTreebook::InsertSubPage(size_t pagePos,
147 wxWindow *page,
148 const wxString& text,
149 bool bSelect,
150 int imageId)
151 {
152 return DoInsertSubPage(pagePos, page, text, bSelect, imageId);
153 }
154
155 bool wxTreebook::AddPage(wxWindow *page, const wxString& text, bool bSelect,
156 int imageId)
157 {
158 return DoInsertPage(m_treeIds.GetCount(), page, text, bSelect, imageId);
159 }
160
161 // insertion time is linear to the number of top-pages
162 bool wxTreebook::AddSubPage(wxWindow *page, const wxString& text, bool bSelect, int imageId)
163 {
164 return DoAddSubPage(page, text, bSelect, imageId);
165 }
166
167
168 bool wxTreebook::DoInsertPage(size_t pagePos,
169 wxWindow *page,
170 const wxString& text,
171 bool bSelect,
172 int imageId)
173 {
174 wxCHECK_MSG( pagePos <= DoInternalGetPageCount(), false,
175 wxT("Invalid treebook page position") );
176
177 if ( !wxBookCtrlBase::InsertPage(pagePos, page, text, bSelect, imageId) )
178 return false;
179
180 wxTreeCtrl *tree = GetTreeCtrl();
181 wxTreeItemId newId;
182 if ( pagePos == DoInternalGetPageCount() )
183 {
184 // append the page to the end
185 wxTreeItemId rootId = tree->GetRootItem();
186
187 newId = tree->AppendItem(rootId, text, imageId);
188 }
189 else // insert the new page before the given one
190 {
191 wxTreeItemId nodeId = m_treeIds[pagePos];
192
193 wxTreeItemId previousId = tree->GetPrevSibling(nodeId);
194 wxTreeItemId parentId = tree->GetItemParent(nodeId);
195
196 if ( previousId.IsOk() )
197 {
198 // insert before the sibling - previousId
199 newId = tree->InsertItem(parentId, previousId, text, imageId);
200 }
201 else // no prev siblings -- insert as a first child
202 {
203 wxASSERT_MSG( parentId.IsOk(), wxT( "Tree has no root node?" ) );
204
205 newId = tree->PrependItem(parentId, text, imageId);
206 }
207 }
208
209 if ( !newId.IsOk() )
210 {
211 //something wrong -> cleaning and returning with false
212 (void)wxBookCtrlBase::DoRemovePage(pagePos);
213
214 wxFAIL_MSG( wxT("Failed to insert treebook page") );
215 return false;
216 }
217
218 DoInternalAddPage(pagePos, page, newId);
219
220 DoUpdateSelection(bSelect, pagePos);
221
222 return true;
223 }
224
225 bool wxTreebook::DoAddSubPage(wxWindow *page, const wxString& text, bool bSelect, int imageId)
226 {
227 wxTreeCtrl *tree = GetTreeCtrl();
228
229 wxTreeItemId rootId = tree->GetRootItem();
230
231 wxTreeItemId lastNodeId = tree->GetLastChild(rootId);
232
233 wxCHECK_MSG( lastNodeId.IsOk(), false,
234 _T("Can't insert sub page when there are no pages") );
235
236 // now calculate its position (should we save/update it too?)
237 size_t newPos = tree->GetCount() -
238 (tree->GetChildrenCount(lastNodeId, true) + 1);
239
240 return DoInsertSubPage(newPos, page, text, bSelect, imageId);
241 }
242
243 bool wxTreebook::DoInsertSubPage(size_t pagePos,
244 wxTreebookPage *page,
245 const wxString& text,
246 bool bSelect,
247 int imageId)
248 {
249 wxTreeItemId parentId = DoInternalGetPage(pagePos);
250 wxCHECK_MSG( parentId.IsOk(), false, wxT("invalid tree item") );
251
252 wxTreeCtrl *tree = GetTreeCtrl();
253
254 size_t newPos = pagePos + tree->GetChildrenCount(parentId, true) + 1;
255 wxASSERT_MSG( newPos <= DoInternalGetPageCount(),
256 wxT("Internal error in tree insert point calculation") );
257
258 if ( !wxBookCtrlBase::InsertPage(newPos, page, text, bSelect, imageId) )
259 return false;
260
261 wxTreeItemId newId = tree->AppendItem(parentId, text, imageId);
262
263 if ( !newId.IsOk() )
264 {
265 (void)wxBookCtrlBase::DoRemovePage(newPos);
266
267 wxFAIL_MSG( wxT("Failed to insert treebook page") );
268 return false;
269 }
270
271 DoInternalAddPage(newPos, page, newId);
272
273 DoUpdateSelection(bSelect, newPos);
274
275 return true;
276 }
277
278 bool wxTreebook::DeletePage(size_t pagePos)
279 {
280 wxCHECK_MSG( IS_VALID_PAGE(pagePos), false, wxT("Invalid tree index") );
281
282 wxTreebookPage *oldPage = DoRemovePage(pagePos);
283 if ( !oldPage )
284 return false;
285
286 delete oldPage;
287
288 return true;
289 }
290
291 wxTreebookPage *wxTreebook::DoRemovePage(size_t pagePos)
292 {
293 wxTreeItemId pageId = DoInternalGetPage(pagePos);
294 wxCHECK_MSG( pageId.IsOk(), NULL, wxT("Invalid tree index") );
295
296 wxTreebookPage * oldPage = GetPage(pagePos);
297 wxTreeCtrl *tree = GetTreeCtrl();
298
299 size_t subCount = tree->GetChildrenCount(pageId, true);
300 wxASSERT_MSG ( IS_VALID_PAGE(pagePos + subCount),
301 wxT("Internal error in wxTreebook::DoRemovePage") );
302
303 // here we are going to delete ALL the pages in the range
304 // [pagePos, pagePos + subCount] -- the page and its children
305
306 // deleting all the pages from the base class
307 for ( size_t i = 0; i <= subCount; ++i )
308 {
309 wxTreebookPage *page = wxBookCtrlBase::DoRemovePage(pagePos);
310
311 // don't delete the page itself though -- it will be deleted in
312 // DeletePage() when we return
313 if ( i )
314 {
315 delete page;
316 }
317 }
318
319 DoInternalRemovePageRange(pagePos, subCount);
320
321 tree->DeleteChildren( pageId );
322 tree->Delete( pageId );
323
324 return oldPage;
325 }
326
327 bool wxTreebook::DeleteAllPages()
328 {
329 wxBookCtrlBase::DeleteAllPages();
330 m_treeIds.Clear();
331 m_selection =
332 m_actualSelection = wxNOT_FOUND;
333
334 wxTreeCtrl *tree = GetTreeCtrl();
335 tree->DeleteChildren(tree->GetRootItem());
336
337 return true;
338 }
339
340 void wxTreebook::DoInternalAddPage(size_t newPos,
341 wxTreebookPage *page,
342 wxTreeItemId pageId)
343 {
344 wxASSERT_MSG( newPos <= m_treeIds.GetCount(), wxT("Ivalid index passed to wxTreebook::DoInternalAddPage") );
345
346 // hide newly inserted page initially (it will be shown when selected)
347 if ( page )
348 page->Hide();
349
350 if ( newPos == m_treeIds.GetCount() )
351 {
352 // append
353 m_treeIds.Add(pageId);
354 }
355 else // insert
356 {
357 m_treeIds.Insert(pageId, newPos);
358
359 if ( m_selection != wxNOT_FOUND && newPos <= (size_t)m_selection )
360 {
361 // selection has been moved one unit toward the end
362 ++m_selection;
363 if ( m_actualSelection != wxNOT_FOUND )
364 ++m_actualSelection;
365 }
366 else if ( m_actualSelection != wxNOT_FOUND &&
367 newPos <= (size_t)m_actualSelection )
368 {
369 DoSetSelection(m_selection);
370 }
371 }
372 }
373
374 void wxTreebook::DoInternalRemovePageRange(size_t pagePos, size_t subCount)
375 {
376 // Attention: this function is only for a situation when we delete a node
377 // with all its children so pagePos is the node's index and subCount is the
378 // node children count
379 wxASSERT_MSG( pagePos + subCount < m_treeIds.GetCount(),
380 wxT("Ivalid page index") );
381
382 wxTreeItemId pageId = m_treeIds[pagePos];
383
384 m_treeIds.RemoveAt(pagePos, subCount + 1);
385
386 if ( m_selection != wxNOT_FOUND )
387 {
388 if ( (size_t)m_selection > pagePos + subCount)
389 {
390 // selection is far after the deleted page, so just update the index and move on
391 m_selection -= 1 + subCount;
392 if ( m_actualSelection != wxNOT_FOUND)
393 {
394 m_actualSelection -= subCount + 1;
395 }
396 }
397 else if ( (size_t)m_selection >= pagePos )
398 {
399 wxTreeCtrl *tree = GetTreeCtrl();
400
401 // as selected page is going to be deleted, try to select the next
402 // sibling if exists, if not then the parent
403 wxTreeItemId nodeId = tree->GetNextSibling(pageId);
404
405 m_selection = wxNOT_FOUND;
406 m_actualSelection = wxNOT_FOUND;
407
408 if ( nodeId.IsOk() )
409 {
410 // selecting next siblings
411 tree->SelectItem(nodeId);
412 }
413 else // no next sibling, select the parent
414 {
415 wxTreeItemId parentId = tree->GetItemParent(pageId);
416
417 if ( parentId.IsOk() && parentId != tree->GetRootItem() )
418 {
419 tree->SelectItem(parentId);
420 }
421 else // parent is root
422 {
423 // we can't select it as it's hidden
424 DoUpdateSelection(false, wxNOT_FOUND);
425 }
426 }
427 }
428 else if ( m_actualSelection != wxNOT_FOUND &&
429 (size_t)m_actualSelection >= pagePos )
430 {
431 // nothing to do -- selection is before the deleted node, but
432 // actually shown page (the first (sub)child with page != NULL) is
433 // already deleted
434 m_actualSelection = m_selection;
435
436 // send event as documented
437 DoSetSelection(m_selection, SetSelection_SendEvent);
438 }
439 //else: nothing to do -- selection is before the deleted node
440 }
441 else
442 {
443 DoUpdateSelection(false, wxNOT_FOUND);
444 }
445 }
446
447
448 void wxTreebook::DoUpdateSelection(bool bSelect, int newPos)
449 {
450 int newSelPos;
451 if ( bSelect )
452 {
453 newSelPos = newPos;
454 }
455 else if ( m_selection == wxNOT_FOUND && DoInternalGetPageCount() > 0 )
456 {
457 newSelPos = 0;
458 }
459 else
460 {
461 newSelPos = wxNOT_FOUND;
462 }
463
464 if ( newSelPos != wxNOT_FOUND )
465 {
466 SetSelection((size_t)newSelPos);
467 }
468 }
469
470 wxTreeItemId wxTreebook::DoInternalGetPage(size_t pagePos) const
471 {
472 if ( pagePos >= m_treeIds.GetCount() )
473 {
474 // invalid position but ok here, in this internal function, don't assert
475 // (the caller will do it)
476 return wxTreeItemId();
477 }
478
479 return m_treeIds[pagePos];
480 }
481
482 int wxTreebook::DoInternalFindPageById(wxTreeItemId pageId) const
483 {
484 const size_t count = m_treeIds.GetCount();
485 for ( size_t i = 0; i < count; ++i )
486 {
487 if ( m_treeIds[i] == pageId )
488 return i;
489 }
490
491 return wxNOT_FOUND;
492 }
493
494 bool wxTreebook::IsNodeExpanded(size_t pagePos) const
495 {
496 wxTreeItemId pageId = DoInternalGetPage(pagePos);
497
498 wxCHECK_MSG( pageId.IsOk(), false, wxT("invalid tree item") );
499
500 return GetTreeCtrl()->IsExpanded(pageId);
501 }
502
503 bool wxTreebook::ExpandNode(size_t pagePos, bool expand)
504 {
505 wxTreeItemId pageId = DoInternalGetPage(pagePos);
506
507 wxCHECK_MSG( pageId.IsOk(), false, wxT("invalid tree item") );
508
509 if ( expand )
510 {
511 GetTreeCtrl()->Expand( pageId );
512 }
513 else // collapse
514 {
515 GetTreeCtrl()->Collapse( pageId );
516
517 // rely on the events generated by wxTreeCtrl to update selection
518 }
519
520 return true;
521 }
522
523 int wxTreebook::GetPageParent(size_t pagePos) const
524 {
525 wxTreeItemId nodeId = DoInternalGetPage( pagePos );
526 wxCHECK_MSG( nodeId.IsOk(), wxNOT_FOUND, wxT("Invalid page index spacified!") );
527
528 const wxTreeItemId parent = GetTreeCtrl()->GetItemParent( nodeId );
529
530 return parent.IsOk() ? DoInternalFindPageById(parent) : wxNOT_FOUND;
531 }
532
533 bool wxTreebook::SetPageText(size_t n, const wxString& strText)
534 {
535 wxTreeItemId pageId = DoInternalGetPage(n);
536
537 wxCHECK_MSG( pageId.IsOk(), false, wxT("invalid tree item") );
538
539 GetTreeCtrl()->SetItemText(pageId, strText);
540
541 return true;
542 }
543
544 wxString wxTreebook::GetPageText(size_t n) const
545 {
546 wxTreeItemId pageId = DoInternalGetPage(n);
547
548 wxCHECK_MSG( pageId.IsOk(), wxString(), wxT("invalid tree item") );
549
550 return GetTreeCtrl()->GetItemText(pageId);
551 }
552
553 int wxTreebook::GetPageImage(size_t n) const
554 {
555 wxTreeItemId pageId = DoInternalGetPage(n);
556
557 wxCHECK_MSG( pageId.IsOk(), wxNOT_FOUND, wxT("invalid tree item") );
558
559 return GetTreeCtrl()->GetItemImage(pageId);
560 }
561
562 bool wxTreebook::SetPageImage(size_t n, int imageId)
563 {
564 wxTreeItemId pageId = DoInternalGetPage(n);
565
566 wxCHECK_MSG( pageId.IsOk(), false, wxT("invalid tree item") );
567
568 GetTreeCtrl()->SetItemImage(pageId, imageId);
569
570 return true;
571 }
572
573 wxSize wxTreebook::CalcSizeFromPage(const wxSize& sizePage) const
574 {
575 const wxSize sizeTree = GetControllerSize();
576
577 wxSize size = sizePage;
578 size.x += sizeTree.x;
579
580 return size;
581 }
582
583 int wxTreebook::GetSelection() const
584 {
585 return m_selection;
586 }
587
588 int wxTreebook::DoSetSelection(size_t pagePos, int flags)
589 {
590 wxCHECK_MSG( IS_VALID_PAGE(pagePos), wxNOT_FOUND,
591 wxT("invalid page index in wxListbook::DoSetSelection()") );
592 wxASSERT_MSG( GetPageCount() == DoInternalGetPageCount(),
593 wxT("wxTreebook logic error: m_treeIds and m_pages not in sync!"));
594
595 wxTreebookEvent event(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, m_windowId);
596 const int oldSel = m_selection;
597 wxTreeCtrl *tree = GetTreeCtrl();
598 bool allowed = false;
599
600 if (flags & SetSelection_SendEvent)
601 {
602 event.SetEventObject(this);
603 event.SetSelection(pagePos);
604 event.SetOldSelection(m_selection);
605
606 // don't send the event if the old and new pages are the same; do send it
607 // otherwise and be prepared for it to be vetoed
608 allowed = (int)pagePos == m_selection ||
609 !GetEventHandler()->ProcessEvent(event) ||
610 event.IsAllowed();
611 }
612
613 if ( !(flags & SetSelection_SendEvent) || allowed )
614 {
615 // hide the previously shown page
616 wxTreebookPage * const oldPage = DoGetCurrentPage();
617 if ( oldPage )
618 oldPage->Hide();
619
620 // then show the new one
621 m_selection = pagePos;
622 wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection);
623 if ( !page )
624 {
625 // find the next page suitable to be shown: the first (grand)child
626 // of this one with a non-NULL associated page
627 wxTreeItemId childId = m_treeIds[pagePos];
628 int actualPagePos = pagePos;
629 while ( !page && childId.IsOk() )
630 {
631 wxTreeItemIdValue cookie;
632 childId = tree->GetFirstChild( childId, cookie );
633 if ( childId.IsOk() )
634 {
635 page = wxBookCtrlBase::GetPage(++actualPagePos);
636 }
637 }
638
639 m_actualSelection = page ? actualPagePos : m_selection;
640 }
641
642 if ( page )
643 page->Show();
644
645 tree->SelectItem(DoInternalGetPage(pagePos));
646
647 if (flags & SetSelection_SendEvent)
648 {
649 // notify about the (now completed) page change
650 event.SetEventType(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED);
651 (void)GetEventHandler()->ProcessEvent(event);
652 }
653 }
654 else if ( (flags & SetSelection_SendEvent) && !allowed) // page change vetoed
655 {
656 // tree selection might have already had changed
657 if ( oldSel != wxNOT_FOUND )
658 tree->SelectItem(DoInternalGetPage(oldSel));
659 }
660
661 return oldSel;
662 }
663
664 wxTreebookPage *wxTreebook::DoGetCurrentPage() const
665 {
666 if ( m_selection == wxNOT_FOUND )
667 return NULL;
668
669 wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection);
670 if ( !page && m_actualSelection != wxNOT_FOUND )
671 {
672 page = wxBookCtrlBase::GetPage(m_actualSelection);
673 }
674
675 return page;
676 }
677
678 void wxTreebook::SetImageList(wxImageList *imageList)
679 {
680 wxBookCtrlBase::SetImageList(imageList);
681 GetTreeCtrl()->SetImageList(imageList);
682 }
683
684 void wxTreebook::AssignImageList(wxImageList *imageList)
685 {
686 wxBookCtrlBase::AssignImageList(imageList);
687 GetTreeCtrl()->SetImageList(imageList);
688 }
689
690 // ----------------------------------------------------------------------------
691 // event handlers
692 // ----------------------------------------------------------------------------
693
694 void wxTreebook::OnTreeSelectionChange(wxTreeEvent& event)
695 {
696 if ( event.GetEventObject() != m_bookctrl )
697 {
698 event.Skip();
699 return;
700 }
701
702 wxTreeItemId newId = event.GetItem();
703
704 if ( (m_selection == wxNOT_FOUND &&
705 (!newId.IsOk() || newId == GetTreeCtrl()->GetRootItem())) ||
706 (m_selection != wxNOT_FOUND && newId == m_treeIds[m_selection]) )
707 {
708 // this event can only come when we modify the tree selection ourselves
709 // so we should simply ignore it
710 return;
711 }
712
713 int newPos = DoInternalFindPageById(newId);
714
715 if ( newPos != wxNOT_FOUND )
716 SetSelection( newPos );
717 }
718
719 void wxTreebook::OnTreeNodeExpandedCollapsed(wxTreeEvent & event)
720 {
721 if ( event.GetEventObject() != m_bookctrl )
722 {
723 event.Skip();
724 return;
725 }
726
727 wxTreeItemId nodeId = event.GetItem();
728 if ( !nodeId.IsOk() || nodeId == GetTreeCtrl()->GetRootItem() )
729 return;
730 int pagePos = DoInternalFindPageById(nodeId);
731 wxCHECK_RET( pagePos != wxNOT_FOUND, wxT("Internal problem in wxTreebook!..") );
732
733 wxTreebookEvent ev(GetTreeCtrl()->IsExpanded(nodeId)
734 ? wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED
735 : wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED,
736 m_windowId);
737
738 ev.SetSelection(pagePos);
739 ev.SetOldSelection(pagePos);
740 ev.SetEventObject(this);
741
742 GetEventHandler()->ProcessEvent(ev);
743 }
744
745 // ----------------------------------------------------------------------------
746 // wxTreebook geometry management
747 // ----------------------------------------------------------------------------
748
749 int wxTreebook::HitTest(wxPoint const & pt, long * flags) const
750 {
751 int pagePos = wxNOT_FOUND;
752
753 if ( flags )
754 *flags = wxBK_HITTEST_NOWHERE;
755
756 // convert from wxTreebook coorindates to wxTreeCtrl ones
757 const wxTreeCtrl * const tree = GetTreeCtrl();
758 const wxPoint treePt = tree->ScreenToClient(ClientToScreen(pt));
759
760 // is it over the tree?
761 if ( wxRect(tree->GetSize()).Contains(treePt) )
762 {
763 int flagsTree;
764 wxTreeItemId id = tree->HitTest(treePt, flagsTree);
765
766 if ( id.IsOk() && (flagsTree & wxTREE_HITTEST_ONITEM) )
767 {
768 pagePos = DoInternalFindPageById(id);
769 }
770
771 if ( flags )
772 {
773 if ( pagePos != wxNOT_FOUND )
774 *flags = 0;
775
776 if ( flagsTree & (wxTREE_HITTEST_ONITEMBUTTON |
777 wxTREE_HITTEST_ONITEMICON |
778 wxTREE_HITTEST_ONITEMSTATEICON) )
779 *flags |= wxBK_HITTEST_ONICON;
780
781 if ( flagsTree & wxTREE_HITTEST_ONITEMLABEL )
782 *flags |= wxBK_HITTEST_ONLABEL;
783 }
784 }
785 else // not over the tree
786 {
787 if ( flags && GetPageRect().Contains( pt ) )
788 *flags |= wxBK_HITTEST_ONPAGE;
789 }
790
791 return pagePos;
792 }
793
794 #endif // wxUSE_TREEBOOK

  ViewVC Help
Powered by ViewVC 1.1.22