Code::Blocks  SVN r11506
switcherdlg.h
Go to the documentation of this file.
1 // Name: switcherdlg.h
3 // Purpose: Pane switcher dialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2007-08-19
7 // RCS-ID: $Id: switcherdlg.h 7106 2011-04-15 11:06:39Z mortenmacfly $
8 // Copyright: (c) Julian Smart
9 // Licence: wxWidgets licence
11 
12 #ifndef _WX_SWITCHERDLG_H_
13 #define _WX_SWITCHERDLG_H_
14 
15 #include <wx/dynarray.h>
16 #include <wx/html/htmlwin.h>
17 
18 #include "scrollingdialog.h"
19 
25 class wxSwitcherItem: public wxObject
26 {
27  DECLARE_CLASS(wxSwitcherItem)
28 public:
30  wxSwitcherItem(const wxSwitcherItem& item) : wxObject(item)
31  {
32  Init();
33  Copy(item);
34  }
35 
36  bool operator== (const wxSwitcherItem& item) const;
37 
38  void operator= (const wxSwitcherItem& item) { Copy(item); }
39 
40  void Init();
41 
42  void Copy(const wxSwitcherItem& item);
43 
44  wxSwitcherItem& SetTitle(const wxString& title) { m_title = title; return (*this); }
45  const wxString& GetTitle() const { return m_title; }
46 
47  wxSwitcherItem& SetName(const wxString& name) { m_name = name; return (*this); }
48  const wxString& GetName() const { return m_name; }
49 
50  wxSwitcherItem& SetDescription(const wxString& descr) { m_description = descr; return (*this); }
51  const wxString& GetDescription() const { return m_description; }
52 
53  wxSwitcherItem& SetId(int id) { m_id = id; return (*this); }
54  int GetId() const { return m_id; }
55 
56  wxSwitcherItem& SetIsGroup(bool isGroup) { m_isGroup = isGroup; return (*this); }
57  bool GetIsGroup() const { return m_isGroup; }
58 
59  wxSwitcherItem& BreakColumn(bool breakCol = true) { m_breakColumn = breakCol; return (*this); }
60  bool GetBreakColumn() const { return m_breakColumn; }
61 
62  wxSwitcherItem& SetRect(const wxRect& rect) { m_rect = rect; return (*this); }
63  const wxRect& GetRect() const { return m_rect; }
64 
65  wxSwitcherItem& SetTextColour(const wxColour& colour) { m_textColour = colour; return (*this); }
66  const wxColour& GetTextColour() const { return m_textColour; }
67 
68  wxSwitcherItem& SetFont(const wxFont& font) { m_font = font; return (*this); }
69  const wxFont& GetFont() const { return m_font; }
70 
71  wxSwitcherItem& SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; return (*this); }
72  const wxBitmap& GetBitmap() const { return m_bitmap; }
73 
74  wxSwitcherItem& SetRowPos(int pos) { m_rowPos = pos; return (*this); }
75  int GetRowPos() const { return m_rowPos; }
76 
77  wxSwitcherItem& SetColPos(int pos) { m_colPos = pos; return (*this); }
78  int GetColPos() const { return m_colPos; }
79 
80  wxSwitcherItem& SetWindow(wxWindow* win) { m_window = win; return (*this); }
81  wxWindow* GetWindow() const { return m_window; }
82 
83 protected:
84 
88  int m_id;
89  bool m_isGroup;
95  int m_rowPos;
96  int m_colPos;
98 };
99 
100 WX_DECLARE_OBJARRAY(wxSwitcherItem, wxSwitcherItemArray);
101 
108 {
109  DECLARE_CLASS(wxSwitcherItems)
110 public:
112  wxSwitcherItems(const wxSwitcherItems& items) : wxObject(items)
113  {
114  Init();
115  Copy(items);
116  }
117 
118  bool operator== (const wxSwitcherItems& items) const;
119 
120  void operator= (const wxSwitcherItems& items) { Copy(items); }
121 
122  void Init();
123 
124  void Copy(const wxSwitcherItems& items);
125 
126  // Public API
127 
128  wxSwitcherItem& AddItem(const wxString& title, const wxString& name, int id = 0, const wxBitmap& bitmap = wxNullBitmap);
129  wxSwitcherItem& AddItem(const wxString& title, const wxString& name, const wxString& descr, int id = 0, const wxBitmap& bitmap = wxNullBitmap);
130  wxSwitcherItem& AddItem(const wxSwitcherItem& item);
131  wxSwitcherItem& AddGroup(const wxString& title, const wxString& name, int id = 0, const wxBitmap& bitmap = wxNullBitmap);
132 
133  void Clear();
134 
135  int FindItemByName(const wxString& name) const;
136  int FindItemById(int id) const;
137 
138  void SetSelection(int sel);
139  void SetSelection(const wxString& name); // by name
140  int GetSelection() const { return m_selection; }
141 
142  // Find the index for the item associated with the current focus
143  int GetIndexForFocus() const;
144 
145  // Hit test, returning an index or -1
146  int HitTest(const wxPoint& pt) const;
147 
148  const wxSwitcherItem& GetItem(int i) const;
149  wxSwitcherItem& GetItem(int i);
150 
151  int GetItemCount() const { return m_items.GetCount(); }
152 
153  void SetRowCount(int rows) { m_rowCount = rows; }
154  int GetRowCount() const { return m_rowCount; }
155 
156  void SetColumnCount(int cols) { m_columnCount = cols; }
157  int GetColumnCount() const { return m_columnCount; }
158 
159  void SetBackgroundColour(const wxColour& colour) { m_backgroundColour = colour; }
160  const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
161 
162  void SetTextColour(const wxColour& colour) { m_textColour = colour; }
163  const wxColour& GetTextColour() const { return m_textColour; }
164 
165  void SetSelectionColour(const wxColour& colour) { m_selectionColour = colour; }
166  const wxColour& GetSelectionColour() const { return m_selectionColour; }
167 
168  void SetSelectionOutlineColour(const wxColour& colour) { m_selectionOutlineColour = colour; }
169  const wxColour& GetSelectionOutlineColour() const { return m_selectionOutlineColour; }
170 
171  void SetSelectionTextColour(const wxColour& colour) { m_selectionTextColour = colour; }
172  const wxColour& GetSelectionTextColour() const { return m_selectionTextColour; }
173 
174  void SetItemFont(const wxFont& font) { m_itemFont = font; }
175  const wxFont& GetItemFont() const { return m_itemFont; }
176 
177  // Implementation
178 
179  void PaintItems(wxDC& dc, wxWindow* win);
180  wxSize CalculateItemSize(wxDC& dc);
181 
182 protected:
183 
184  wxSwitcherItemArray m_items;
188 
194 
196 };
197 
198 
205 {
206  DECLARE_CLASS(wxMultiColumnListCtrl)
207 public:
208  wxMultiColumnListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
210 
211  bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
212 
213  // Public API
214 
215  void SetItems(const wxSwitcherItems& items) { m_items = items; }
216  const wxSwitcherItems& GetItems() const { return m_items; }
217  wxSwitcherItems& GetItems() { return m_items; }
218 
219  // Set an extra key that can be used to cycle through items,
220  // in case not using the Ctrl+Tab combination
221  void SetExtraNavigationKey(int keyCode) { m_extraNavigationKey = keyCode; }
222  int GetExtraNavigationKey() const { return m_extraNavigationKey; }
223 
224  // Set the modifier used to invoke the dialog, and therefore to test for
225  // release
226  void SetModifierKey(int modifierKey) { m_modifierKey = modifierKey; }
227  int GetModifierKey() const { return m_modifierKey; }
228 
229  // Event handlers
230 
231  void OnPaint(wxPaintEvent& event);
232  void OnMouseEvent(wxMouseEvent& event);
233  void OnChar(wxKeyEvent& event);
234  void OnKey(wxKeyEvent& event);
235  void OnEraseBackground(wxEraseEvent& event);
236 
237  // Overrides
238  virtual wxSize DoGetBestSize() const ;
239 
240  // Implementation
241 
242  void CalculateLayout();
243  void CalculateLayout(wxDC& dc);
244  void InvalidateLayout() { m_items.SetColumnCount(0); Refresh(); }
245  void Init();
246  void GenerateSelectionEvent();
247  void AdvanceToNextSelectableItem(int direction);
248  void SendCloseEvent();
249 
250 protected:
251 
265 
266 DECLARE_EVENT_TABLE()
267 };
268 
269 
276 {
277 public:
278  // constructors and destructors
280  wxSwitcherDialog( const wxSwitcherItems& items, wxWindow *parent,
281  wxWindowID id = -1, const wxString& title = _("Pane Switcher"),
282  const wxPoint& pos = wxDefaultPosition,
283  const wxSize& size = wxDefaultSize,
285 
286  bool Create(const wxSwitcherItems& items, wxWindow *parent,
287  wxWindowID id = -1, const wxString& title = _("Pane Switcher"),
288  const wxPoint& pos = wxDefaultPosition,
289  const wxSize& size = wxDefaultSize,
291 
292  void Init();
293 
294  void OnCloseWindow(wxCloseEvent& event);
295  void OnActivate(wxActivateEvent& event);
296  void OnSelectItem(wxCommandEvent& event);
297  void OnPaint(wxPaintEvent& event);
298 
299  // Get the selected item
300  int GetSelection() const;
301 
302  void ShowDescription(int i);
303 
304  void SetBorderColour(const wxColour& colour) { m_borderColour = colour; }
305 
306  // Set an extra key that can be used to cycle through items,
307  // in case not using the Ctrl+Tab combination
308  void SetExtraNavigationKey(int keyCode);
309  int GetExtraNavigationKey() const { return m_extraNavigationKey; }
310 
311  // Set the modifier used to invoke the dialog, and therefore to test for
312  // release
313  void SetModifierKey(int modifierKey);
314  int GetModifierKey() const { return m_modifierKey; }
315 
316 private:
317 
320  bool m_closing;
325 
326  DECLARE_EVENT_TABLE()
327 };
328 
329 
330 #endif
331  // _WX_SWITCHERDLG_H_
332 
const wxString & GetDescription() const
Definition: switcherdlg.h:51
int GetRowCount() const
Definition: switcherdlg.h:154
int GetExtraNavigationKey() const
Definition: switcherdlg.h:309
void SetSelectionOutlineColour(const wxColour &colour)
Definition: switcherdlg.h:168
void SetSelectionColour(const wxColour &colour)
Definition: switcherdlg.h:165
int GetModifierKey() const
Definition: switcherdlg.h:227
const wxRect & GetRect() const
Definition: switcherdlg.h:63
wxWindow * GetWindow() const
Definition: switcherdlg.h:81
wxColour m_selectionOutlineColour
Definition: switcherdlg.h:192
const wxColour & GetSelectionOutlineColour() const
Definition: switcherdlg.h:169
wxWindow * m_window
Definition: switcherdlg.h:97
wxSwitcherItem & SetName(const wxString &name)
Definition: switcherdlg.h:47
wxSwitcherItem & SetTextColour(const wxColour &colour)
Definition: switcherdlg.h:65
void Copy(const wxSwitcherItem &item)
Definition: switcherdlg.cpp:47
const wxFont & GetFont() const
Definition: switcherdlg.h:69
wxColour m_borderColour
Definition: switcherdlg.h:322
const wxBitmap & GetBitmap() const
Definition: switcherdlg.h:72
wxSwitcherItem & SetFont(const wxFont &font)
Definition: switcherdlg.h:68
wxSwitcherItem & SetTitle(const wxString &title)
Definition: switcherdlg.h:44
wxSwitcherItem & SetWindow(wxWindow *win)
Definition: switcherdlg.h:80
wxColour m_selectionColour
Definition: switcherdlg.h:191
wxSwitcherItem & BreakColumn(bool breakCol=true)
Definition: switcherdlg.h:59
wxSwitcherItem & SetRowPos(int pos)
Definition: switcherdlg.h:74
int GetModifierKey() const
Definition: switcherdlg.h:314
const wxColour & GetTextColour() const
Definition: switcherdlg.h:163
int GetRowPos() const
Definition: switcherdlg.h:75
void SetRowCount(int rows)
Definition: switcherdlg.h:153
wxHtmlWindow * m_descriptionCtrl
Definition: switcherdlg.h:319
void SetSelectionTextColour(const wxColour &colour)
Definition: switcherdlg.h:171
wxSwitcherItemArray m_items
Definition: switcherdlg.h:184
const wxString & GetTitle() const
Definition: switcherdlg.h:45
wxPoint m_ptMouse
Mouse point initialized on Init function.
Definition: switcherdlg.h:260
wxColour m_backgroundColour
Definition: switcherdlg.h:189
wxSwitcherItem & SetRect(const wxRect &rect)
Definition: switcherdlg.h:62
int GetColumnCount() const
Definition: switcherdlg.h:157
wxSwitcherItem(const wxSwitcherItem &item)
Definition: switcherdlg.h:30
wxSwitcherItem & SetDescription(const wxString &descr)
Definition: switcherdlg.h:50
wxSwitcherItems & GetItems()
Definition: switcherdlg.h:217
wxString m_title
Definition: switcherdlg.h:85
wxBitmap m_bitmap
Definition: switcherdlg.h:92
const wxSwitcherItems & GetItems() const
Definition: switcherdlg.h:216
bool operator==(const wxSwitcherItem &item) const
Definition: switcherdlg.cpp:64
int GetSelection() const
Definition: switcherdlg.h:140
long m_switcherBorderStyle
Definition: switcherdlg.h:321
wxString m_description
Definition: switcherdlg.h:87
int GetExtraNavigationKey() const
Definition: switcherdlg.h:222
int GetId() const
Definition: switcherdlg.h:54
wxColour m_selectionTextColour
Definition: switcherdlg.h:193
const wxColour & GetSelectionTextColour() const
Definition: switcherdlg.h:172
void SetItemFont(const wxFont &font)
Definition: switcherdlg.h:174
void SetItems(const wxSwitcherItems &items)
Definition: switcherdlg.h:215
wxSwitcherItem & SetColPos(int pos)
Definition: switcherdlg.h:77
wxColour m_textColour
Definition: switcherdlg.h:190
wxSwitcherItem & SetBitmap(const wxBitmap &bitmap)
Definition: switcherdlg.h:71
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
const wxFont & GetItemFont() const
Definition: switcherdlg.h:175
const wxColour & GetSelectionColour() const
Definition: switcherdlg.h:166
wxSwitcherItems m_items
Definition: switcherdlg.h:261
wxColour m_textColour
Definition: switcherdlg.h:93
#define wxSTAY_ON_TOP
const wxColour & GetBackgroundColour() const
Definition: switcherdlg.h:160
const wxString & _(const wxString &string)
void SetTextColour(const wxColour &colour)
Definition: switcherdlg.h:162
void SetColumnCount(int cols)
Definition: switcherdlg.h:156
#define wxDIALOG_NO_PARENT
wxSwitcherItem & SetId(int id)
Definition: switcherdlg.h:53
wxString m_name
Definition: switcherdlg.h:86
bool GetIsGroup() const
Definition: switcherdlg.h:57
bool m_breakColumn
Definition: switcherdlg.h:90
const wxColour & GetTextColour() const
Definition: switcherdlg.h:66
wxBitmap wxNullBitmap
int GetItemCount() const
Definition: switcherdlg.h:151
wxSwitcherItems(const wxSwitcherItems &items)
Definition: switcherdlg.h:112
int GetColPos() const
Definition: switcherdlg.h:78
void SetBorderColour(const wxColour &colour)
Definition: switcherdlg.h:304
WX_DECLARE_OBJARRAY(wxSwitcherItem, wxSwitcherItemArray)
void SetBackgroundColour(const wxColour &colour)
Definition: switcherdlg.h:159
void SetExtraNavigationKey(int keyCode)
Definition: switcherdlg.h:221
int wxWindowID
wxMultiColumnListCtrl * m_listCtrl
Definition: switcherdlg.h:318
const wxString & GetName() const
Definition: switcherdlg.h:48
bool GetBreakColumn() const
Definition: switcherdlg.h:60
wxSwitcherItem & SetIsGroup(bool isGroup)
Definition: switcherdlg.h:56
void operator=(const wxSwitcherItem &item)
Definition: switcherdlg.h:38
void SetModifierKey(int modifierKey)
Definition: switcherdlg.h:226