ToolMap
Loading...
Searching...
No Matches
tmchecklistbox.h
1/***************************************************************************
2 tmchecklistbox.cpp
3 Base class for dealing with checklistbox with long
4 item associed to every item
5 -------------------
6 copyright : (C) 2007 CREALP Lucien Schreiber
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18// comment doxygen
19
20#ifndef _TM_CHECKLISTBOX_H_
21#define _TM_CHECKLISTBOX_H_
22
23// For compilers that support precompilation, includes "wx/wx.h".
24#include <wx/wxprec.h>
25
26// Include wxWidgets' headers
27#ifndef WX_PRECOMP
28#include <wx/wx.h>
29#endif
30
31#include <wx/checklst.h> // for checklistbox
32#include <wx/listctrl.h> // for event
33
34// check box list styles
35#define tmLB_MENU 0x10000 // we want menu
36
37// check box event list
38const int tmCHECK_MENU_MOVE_TOP = 13001;
39const int tmCHECK_MENU_MOVE_BOTTOM = 13002;
40const int tmCHECK_MENU_MOVE_UP = 13003;
41const int tmCHECK_MENU_MOVE_DOWN = 13004;
42const int tmCHECK_MENU_TOGGLE_FREQUENT = 13005;
43
44/***************************************************************************/
56class tmCheckListBox : public wxCheckListBox {
57 private:
58 wxArrayLong m_ids;
59 wxArrayLong m_originalIds;
60 wxArrayString m_originalLabels;
61 wxArrayShort m_originalChecks;
62 wxMenu* m_PopupMenu;
63
64 bool CreateStandardMenu();
65
66 // event functions
67 void OnDisplayPopupMenu(wxMouseEvent& event);
68
69 void OnMoveItemInList(wxCommandEvent& event);
70
71 void OnToggleFrequent(wxCommandEvent& event);
72
73 protected:
74 bool m_IsFiltered;
75 // wxArrayInt m_Selections;
76
77 void Init() {
78 m_PopupMenu = nullptr;
79 m_IsFiltered = false;
80 }
81
82 wxMenu* GetPopupMenu() {
83 return m_PopupMenu;
84 }
85
86 virtual void EnableRelevantMenuEntries();
87
88 public:
89 // ctor
91 Init();
92 }
93
95
96 tmCheckListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
97 const wxSize& size = wxDefaultSize, int nStrings = 0, const wxString* choices = nullptr,
98 long style = 0, const wxValidator& validator = wxDefaultValidator,
99 const wxString& name = wxListBoxNameStr) {
100 Init();
101 Create(parent, id, pos, size, nStrings, choices, style, validator, name);
102 }
103
104 bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
105 const wxSize& size = wxDefaultSize, int nStrings = 0, const wxString* choices = nullptr, long style = 0,
106 const wxValidator& validator = wxDefaultValidator, const wxString& name = wxListBoxNameStr);
107
108 // functions
109 bool AddItem(long index = -1, long id = -1, const wxString& name = wxEmptyString, bool checked = false,
110 bool keepFilters = false);
111
112 bool RemoveItem(long index = -1);
113
114 bool EditItem(long index, long id = -1, const wxString& name = wxEmptyString, short checked = 2);
115
116 bool SwapItem(long index1, long index2 = -1);
117
118 bool MoveItem(long index1, long index2);
119
120 bool GetItem(long index, long& id, wxString& name, bool& bcheck);
121
122 bool GetItemId(long index, long& id);
123
124 bool SetItemCheck(long index, short checked = 2);
125
126 void ClearItems();
127
128 void ClearFilters();
129
130 void ClearCheckMarks();
131
132 void Filter(wxString filter);
133
134 void ResetOriginalArrays();
135
136 bool StoreActualChecks();
137};
138
139#endif
Deals with checkbox list.
Definition tmchecklistbox.h:56
bool EditItem(long index, long id=-1, const wxString &name=wxEmptyString, short checked=2)
Modify an item.
Definition tmchecklistbox.cpp:279
void Filter(wxString filter)
Filter the list and keep only the labels containing the string.
Definition tmchecklistbox.cpp:481
void ClearCheckMarks()
Uncheck all items.
Definition tmchecklistbox.cpp:470
void ClearItems()
Empty the checklist and associated array.
Definition tmchecklistbox.cpp:438
~tmCheckListBox()
Destructor.
Definition tmchecklistbox.cpp:58
void ClearFilters()
Clear the filters and restore original arrays.
Definition tmchecklistbox.cpp:451
bool AddItem(long index=-1, long id=-1, const wxString &name=wxEmptyString, bool checked=false, bool keepFilters=false)
Add an item in the list.
Definition tmchecklistbox.cpp:212
bool Create(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int nStrings=0, const wxString *choices=nullptr, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxListBoxNameStr)
Creator for two steps creation.
Definition tmchecklistbox.cpp:30
bool RemoveItem(long index=-1)
Remove an item in the list.
Definition tmchecklistbox.cpp:242
bool MoveItem(long index1, long index2)
Move an items to a specified position.
Definition tmchecklistbox.cpp:352
bool SwapItem(long index1, long index2=-1)
Switch two items.
Definition tmchecklistbox.cpp:319
bool GetItem(long index, long &id, wxString &name, bool &bcheck)
Get value for item at the specified position.
Definition tmchecklistbox.cpp:382