NCBI C++ ToolKit
rearrange_list.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: rearrange_list.hpp 47374 2023-02-23 00:42:16Z evgeniev $
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: Igor Filippov, based on wxRearrangeCtrl
27  */
28 
29 
30 #ifndef _GUI_WIDGETS_REARRANGECTRL_H_
31 #define _GUI_WIDGETS_REARRANGECTRL_H_
32 
33 
34 #include <corelib/ncbistd.hpp>
35 
36 #include <gui/gui_export.h>
37 
38 
39 #include "wx/checklst.h"
40 #include "wx/panel.h"
41 #include "wx/arrstr.h"
42 
44 
46 {
47 public:
48  virtual void UpdateCheckedState(size_t checked) {}
50 };
51 
53 {
54 public:
55  virtual void DoubleClick(int n) {}
56  virtual ~CDoubleClickConsumer() {}
57 };
58 
59 class NCBI_GUIWIDGETS_EDIT_EXPORT CRearrangeList : public wxCheckListBox
60 {
61 public:
62  // ctors and such
63  // --------------
64 
65  // default ctor, call Create() later
67 
68  // ctor creating the control, the arguments are the same as for
69  // wxCheckListBox except for the extra order array which defines the
70  // (initial) display order of the items as well as their statuses, see the
71  // description above
72  CRearrangeList(wxWindow *parent,
73  wxWindowID id,
74  const wxPoint& pos,
75  const wxSize& size,
76  const wxArrayInt& order,
77  const wxArrayString& items,
78  long style = 0,
79  const wxValidator& validator = wxDefaultValidator,
80  const wxString& name = wxListBoxNameStr )
81  {
82  Create(parent, id, pos, size, order, items, style, validator, name);
83  }
84 
85  // Create() function takes the same parameters as the base class one and
86  // the order array determining the initial display order
87  bool Create(wxWindow *parent,
88  wxWindowID id,
89  const wxPoint& pos,
90  const wxSize& size,
91  const wxArrayInt& order,
92  const wxArrayString& items,
93  long style = 0,
94  const wxValidator& validator = wxDefaultValidator,
95  const wxString& name = wxListBoxNameStr );
96 
97 
98  // items order
99  // -----------
100 
101  // get the current items order; the returned array uses the same convention
102  // as the one passed to the ctor
103  const wxArrayInt& GetCurrentOrder() const { return m_order; }
104 
105  // return true if the current item can be moved up or down (i.e. just that
106  // it's not the first or the last one)
107  bool CanMoveCurrentUp() const;
108  bool CanMoveCurrentDown() const;
109 
110  // move the current item one position up or down, return true if it was moved
111  // or false if the current item was the first/last one and so nothing was done
112  bool MoveCurrentUp();
113  bool MoveCurrentDown();
114 
115 
116  // Override this to keep our m_order array in sync with the real item state.
117  virtual void Check(unsigned int item, bool check = true) override;
118  virtual void Clear() override;
119  virtual void Set(const wxArrayInt& order, const wxArrayString& items);
120  void SetCheckListListener(CCheckListBoxListener *win) {m_Listener = win;}
121  void SetDoubleClickConsumer(CDoubleClickConsumer *win) {m_DoubleClickConsumer = win;}
122 private:
123  // swap two items at the given positions in the listbox
124  void Swap(int pos1, int pos2);
125 
126  // event handler for item checking/unchecking
127  void OnCheck(wxCommandEvent& event);
128 
129  void OnDoubleClick(wxCommandEvent& event);
130 
131  // the current order array
132  wxArrayInt m_order;
133  size_t m_checked;
136 
139 };
140 
141 // ----------------------------------------------------------------------------
142 // CRearrangeCtrl: composite control containing a CRearrangeList and buttons
143 // ----------------------------------------------------------------------------
144 
146 {
147 public:
148  // ctors/Create function are the same as for wxRearrangeList
150  {
151  Init();
152  }
153 
154  CRearrangeCtrl(wxWindow *parent,
155  wxWindowID id,
156  const wxPoint& pos,
157  const wxSize& size,
158  const wxArrayInt& order,
159  const wxArrayString& items,
160  long style = 0,
161  const wxValidator& validator = wxDefaultValidator,
162  const wxString& name = wxListBoxNameStr)
163  {
164  Init();
165 
166  Create(parent, id, pos, size, order, items, style, validator, name);
167  }
168 
169  bool Create(wxWindow *parent,
170  wxWindowID id,
171  const wxPoint& pos,
172  const wxSize& size,
173  const wxArrayInt& order,
174  const wxArrayString& items,
175  long style = 0,
176  const wxValidator& validator = wxDefaultValidator,
177  const wxString& name = wxListBoxNameStr);
178 
179  // get the underlying listbox
180  CRearrangeList *GetList() const { return m_list; }
181 
182 private:
183  // common part of all ctors
184  void Init();
185 
186  // event handlers for the buttons
187  void OnUpdateButtonUI(wxUpdateUIEvent& event);
188  void OnButton(wxCommandEvent& event);
189 
190 
192 
195 };
196 
198 #endif // _GUI_WIDGETS_REARRANGECTRL_H_
199 
200 
virtual void UpdateCheckedState(size_t checked)
virtual ~CCheckListBoxListener()
virtual void DoubleClick(int n)
virtual ~CDoubleClickConsumer()
CRearrangeCtrl(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayInt &order, const wxArrayString &items, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxListBoxNameStr)
wxDECLARE_NO_COPY_CLASS(CRearrangeCtrl)
CRearrangeList * GetList() const
CRearrangeList * m_list
CDoubleClickConsumer * m_DoubleClickConsumer
wxArrayInt m_order
bool Create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayInt &order, const wxArrayString &items, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxListBoxNameStr)
wxDECLARE_NO_COPY_CLASS(CRearrangeList)
CCheckListBoxListener * m_Listener
void SetCheckListListener(CCheckListBoxListener *win)
const wxArrayInt & GetCurrentOrder() const
void SetDoubleClickConsumer(CDoubleClickConsumer *win)
CRearrangeList(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayInt &order, const wxArrayString &items, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxListBoxNameStr)
Include a standard set of the NCBI C++ Toolkit most basic headers.
static void Init(void)
Definition: cursor6.c:76
#define check(s)
Definition: describecol2.c:21
#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 NCBI_GUIWIDGETS_EDIT_EXPORT
Definition: gui_export.h:526
Defines to provide correct exporting from DLLs in Windows.
yy_size_t n
void Check(const string &value)
const struct ncbi::grid::netcache::search::fields::SIZE size
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
Modified on Sun Jul 14 04:57:12 2024 by modify_doxy.py rev. 669887