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

Go to the SVN repository for this file.

1 /* $Id: app_explorer_data_object.cpp 43778 2019-08-29 19:19:00Z katargir $
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 
35 
36 #include <wx/treectrl.h>
37 
38 
40 
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 /// CAppExplorerDataObject
44 
45 wxDataFormat CAppExplorerDataObject::m_ItemsFormat(wxT("gbench/app_explorer_items"));
46 
48  : m_TreeCtrl() , m_Cut()
49 {
50  SetFormat(m_ItemsFormat);
51 }
52 
53 CAppExplorerDataObject::CAppExplorerDataObject(wxTreeCtrl* treeCtrl, wxArrayTreeItemIds& items, bool cut)
54  : m_TreeCtrl(treeCtrl), m_Items(items), m_Cut(cut)
55 {
56  SetFormat(m_ItemsFormat);
57 }
58 
59 
60 //TODO In all functions check whether text object is full (see if it can do it itself)
61 
63 {
64  return sizeof(TData) + sizeof(wxTreeItemId)*m_Items.size();
65 }
66 
68 {
69  TData* data = (TData*)buf;
70  data->m_Pid = CCurrentProcess::GetPid();
71  data->m_TreeCtrl = m_TreeCtrl;
72  data->m_Cut = m_Cut;
73  data->m_ItemCount = m_Items.size();
74  wxTreeItemId* items = (wxTreeItemId*)(data + 1);
75  std::copy(m_Items.begin(), m_Items.end(), items);
76  return true;
77 }
78 
79 bool CAppExplorerDataObject::SetData(size_t len, const void *buf)
80 {
81  bool ok = buf && (len >= sizeof(TData));
82  _ASSERT(ok);
83  if (!ok) return false;
84 
85  m_Items.clear();
86 
87  const TData* data = (const TData*)buf;
88  if (data->m_Pid != CCurrentProcess::GetPid())
89  return false;
90 
91  m_TreeCtrl = data->m_TreeCtrl;
92  m_Cut = data->m_Cut;
93  wxTreeItemId* items = (wxTreeItemId*)(data + 1);
94 
95  for (size_t i = 0; i < data->m_ItemCount; ++i)
96  m_Items.push_back(items[i]);
97 
98  return true;
99 }
100 
101 void CAppExplorerDataObject::GetItems(wxTreeCtrl& treeCtrl, PT::TItems& items)
102 {
103  if (&treeCtrl != m_TreeCtrl) return;
104 
105  ITERATE (wxArrayTreeItemIds, it, m_Items) {
106  wxTreeItemId id = *it;
107  PT::CItem* item = dynamic_cast<PT::CItem*>(treeCtrl.GetItemData(id));
108  if (item) items.push_back(item);
109  }
110 }
111 
static wxDataFormat m_ItemsFormat
CAppExplorerDataObject.
virtual size_t GetDataSize() const
void GetItems(wxTreeCtrl &treeCtrl, PT::TItems &items)
virtual bool SetData(size_t len, const void *buf)
virtual bool GetDataHere(void *buf) const
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
static TPid GetPid(void)
Get process identifier (pid) for the current process.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
char * buf
int i
int len
#define wxT(x)
Definition: muParser.cpp:41
vector< CItem * > TItems
Definition: pt_item.hpp:113
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
#define _ASSERT
Modified on Fri Sep 20 14:57:35 2024 by modify_doxy.py rev. 669887