NCBI C++ ToolKit
pt_item.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: pt_item.cpp 46504 2021-06-15 17:33:09Z shkeda $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <gui/core/pt_item.hpp>
35 
36 #include <wx/treectrl.h>
37 
39 
40 using namespace PT;
41 
42 #ifdef _DEBUG
43 size_t CItem::m_InstanceCount = 0;
44 #endif
45 
47 {
48 #ifdef _DEBUG
49  LOG_POST(Info << "Number of CItem instances: " << m_InstanceCount);
50 #endif
51 }
52 
53 
55 {
56 #ifdef _DEBUG
58 #endif
59 }
60 
62 {
63 #ifdef _DEBUG
65 #endif
66 }
67 
68 
69 wxString CItem::GetLabel(wxTreeCtrl& treeCtrl) const
70 {
71  return treeCtrl.GetItemText(m_TreeItemId);
72 }
73 
74 CItem* CItem::GetParent(wxTreeCtrl& treeCtrl) const
75 {
76  wxTreeItemId pId = treeCtrl.GetItemParent(m_TreeItemId);
77  if (!pId.IsOk()) return 0;
78  return dynamic_cast<CItem*>(treeCtrl.GetItemData(pId));
79 }
80 
81 
82 void CItem::AppendChildItem(wxTreeCtrl& treeCtrl, CItem& ch_item)
83 {
84  ch_item.m_TreeItemId =
85  treeCtrl.AppendItem(m_TreeItemId, wxT("item"), -1, -1, &ch_item);
86 }
87 
88 void CItem::InsertChildItem(wxTreeCtrl& treeCtrl, CItem& ch_item, size_t pos)
89 {
90  if (pos > treeCtrl.GetChildrenCount(m_TreeItemId, false))
91  AppendChildItem(treeCtrl, ch_item);
92  else {
93  ch_item.m_TreeItemId =
94  treeCtrl.InsertItem(m_TreeItemId, pos, wxT("item"), -1, -1, &ch_item);
95  }
96 }
97 
98 CChildIterator::CChildIterator(wxTreeCtrl& treeCtrl, const CItem& item)
99  : m_TreeCtrl(treeCtrl), m_Item(item.GetTreeItemId())
100 {
101  if (m_TreeCtrl.ItemHasChildren(m_Item))
102  m_Child = m_TreeCtrl.GetFirstChild(m_Item, m_Cookie);
103 }
104 
106 {
107  if (!m_Child.IsOk())
108  throw std::out_of_range("Invalid index");
109  m_Child = m_TreeCtrl.GetNextChild(m_Item, m_Cookie);
110  return *this;
111 }
112 
113 CChildIterator::operator bool() const
114 {
115  return m_Child.IsOk();
116 }
117 
119 {
120  if (!m_Child.IsOk())
121  throw std::out_of_range("Invalid index");
122 
123  CItem* item = dynamic_cast<CItem*>(m_TreeCtrl.GetItemData(m_Child));
124  _ASSERT(item);
125  return *item;
126 }
127 
wxTreeCtrl & m_TreeCtrl
Definition: pt_item.hpp:107
CItem & operator*(void) const
Definition: pt_item.cpp:118
wxTreeItemId m_Item
Definition: pt_item.hpp:109
wxTreeItemId m_Child
Definition: pt_item.hpp:110
CChildIterator(wxTreeCtrl &treeCtrl, const CItem &item)
Definition: pt_item.cpp:98
wxTreeItemIdValue m_Cookie
Definition: pt_item.hpp:108
CChildIterator & operator++(void)
Definition: pt_item.cpp:105
void InsertChildItem(wxTreeCtrl &treeCtrl, CItem &ch_item, size_t pos)
Definition: pt_item.cpp:88
void AppendChildItem(wxTreeCtrl &treeCtrl, CItem &ch_item)
Definition: pt_item.cpp:82
virtual ~CItem()
Definition: pt_item.cpp:61
wxString GetLabel(wxTreeCtrl &treeCtrl) const
Definition: pt_item.cpp:69
static size_t m_InstanceCount
Definition: pt_item.hpp:93
static void LogInstanceCount()
Definition: pt_item.cpp:46
wxTreeItemId m_TreeItemId
Definition: pt_item.hpp:90
CItem * GetParent(wxTreeCtrl &treeCtrl) const
Definition: pt_item.cpp:74
#define bool
Definition: bool.h:34
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define wxT(x)
Definition: muParser.cpp:41
#define _ASSERT
Modified on Sun Jul 14 04:54:15 2024 by modify_doxy.py rev. 669887