]> git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/customcombo.h
many fixes; now the application correctly starts up
[wxWidgets.git] / utils / screenshotgen / src / customcombo.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: custom_combo.h
3 // Purpose: Define some custom wxComboCtrls
4 // Author: Utensil Candel (UtensilCandel@@gmail.com)
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifndef WX_CUSTOM_COMBO_H
10 #define WX_CUSTOM_COMBO_H
11
12 // ----------------------------------------------------------------------------
13 // class PenStyleComboBox
14 // This class is a modified version of the one from samples/combo.cpp
15 // ----------------------------------------------------------------------------
16
17 #include <wx/odcombo.h>
18
19 class PenStyleComboBox : public wxOwnerDrawnComboBox
20 {
21 public:
22 virtual void OnDrawItem( wxDC& dc,
23 const wxRect& rect,
24 int item,
25 int flags ) const;
26
27
28 virtual void OnDrawBackground( wxDC& dc, const wxRect& rect,
29 int item, int flags ) const;
30
31 virtual wxCoord OnMeasureItem( size_t item ) const;
32
33 virtual wxCoord OnMeasureItemWidth( size_t WXUNUSED(item) ) const;
34
35 static PenStyleComboBox* CreateSample(wxWindow* parent);
36 };
37
38
39 // ----------------------------------------------------------------------------
40 // wxListView Custom popup interface
41 // This class is a modified version of the one from samples/combo.cpp
42 // ----------------------------------------------------------------------------
43
44 #include <wx/listctrl.h>
45
46 class ListViewComboPopup : public wxListView, public wxComboPopup
47 {
48 public:
49
50 virtual void Init()
51 {
52 m_value = -1;
53 m_itemHere = -1; // hot item in list
54 }
55
56 virtual bool Create( wxWindow* parent )
57 {
58 return wxListView::Create(parent,1,
59 wxPoint(0,0),wxDefaultSize,
60 wxLC_LIST|wxLC_VRULES|wxBORDER_THEME);
61 }
62
63 virtual wxWindow *GetControl() { return this; }
64
65 virtual void SetStringValue( const wxString& s )
66 {
67 int n = wxListView::FindItem(-1,s);
68 if ( n >= 0 && n < GetItemCount() )
69 wxListView::Select(n);
70 }
71
72 virtual wxString GetStringValue() const
73 {
74 if ( m_value >= 0 )
75 return wxListView::GetItemText(m_value);
76 return wxEmptyString;
77 }
78
79 //
80 // Popup event handlers
81 //
82
83 // Mouse hot-tracking
84 void OnMouseMove(wxMouseEvent& event)
85 {
86 // Move selection to cursor if it is inside the popup
87
88 int resFlags;
89 int itemHere = HitTest(event.GetPosition(),resFlags);
90 if ( itemHere >= 0 )
91 {
92 wxListView::Select(itemHere,true);
93 m_itemHere = itemHere;
94 }
95 event.Skip();
96 }
97
98 // On mouse left, set the value and close the popup
99 void OnMouseClick(wxMouseEvent& WXUNUSED(event))
100 {
101 m_value = m_itemHere;
102 // TODO: Send event
103 Dismiss();
104 }
105
106 //
107 // Utilies for item manipulation
108 //
109
110 void AddSelection( const wxString& selstr )
111 {
112 wxListView::InsertItem(GetItemCount(),selstr);
113 }
114
115 protected:
116 int m_value; // current item index
117 int m_itemHere; // hot item in popup
118
119 private:
120 DECLARE_EVENT_TABLE()
121 };
122
123
124 // ----------------------------------------------------------------------------
125 // wxTreeCtrl Custom popup interface
126 // This class is a modified version of the one from samples/combo.cpp
127 // ----------------------------------------------------------------------------
128
129 #include <wx/treectrl.h>
130
131 class TreeCtrlComboPopup : public wxTreeCtrl, public wxComboPopup
132 {
133 public:
134
135 virtual void Init()
136 {
137 }
138
139 virtual bool Create( wxWindow* parent )
140 {
141 return wxTreeCtrl::Create(parent,1,
142 wxPoint(0,0),wxDefaultSize,
143 wxTR_HAS_BUTTONS|wxTR_SINGLE|
144 wxTR_LINES_AT_ROOT|wxBORDER_THEME);
145 }
146
147 virtual void OnShow()
148 {
149 // make sure selected item is visible
150 if ( m_value.IsOk() )
151 EnsureVisible(m_value);
152 }
153
154 virtual wxSize GetAdjustedSize( int minWidth,
155 int WXUNUSED(prefHeight),
156 int maxHeight )
157 {
158 return wxSize(minWidth, wxMin(80, maxHeight));
159 }
160
161 virtual wxWindow *GetControl() { return this; }
162
163 // Needed by SetStringValue
164 wxTreeItemId FindItemByText( wxTreeItemId parent, const wxString& text )
165 {
166 wxTreeItemIdValue cookie;
167 wxTreeItemId child = GetFirstChild(parent,cookie);
168 while ( child.IsOk() )
169 {
170 if ( GetItemText(child) == text )
171 {
172 return child;
173 }
174 if ( ItemHasChildren(child) )
175 {
176 wxTreeItemId found = FindItemByText(child,text);
177 if ( found.IsOk() )
178 return found;
179 }
180 child = GetNextChild(parent,cookie);
181 }
182 return wxTreeItemId();
183 }
184
185 virtual void SetStringValue( const wxString& s )
186 {
187 wxTreeItemId root = GetRootItem();
188 if ( !root.IsOk() )
189 return;
190
191 wxTreeItemId found = FindItemByText(root,s);
192 if ( found.IsOk() )
193 {
194 m_value = m_itemHere = found;
195 wxTreeCtrl::SelectItem(found);
196 }
197 }
198
199 virtual wxString GetStringValue() const
200 {
201 if ( m_value.IsOk() )
202 return wxTreeCtrl::GetItemText(m_value);
203 return wxEmptyString;
204 }
205
206 //
207 // Popup event handlers
208 //
209
210 // Mouse hot-tracking
211 void OnMouseMove(wxMouseEvent& event)
212 {
213 int resFlags;
214 wxTreeItemId itemHere = HitTest(event.GetPosition(),resFlags);
215 if ( itemHere.IsOk() && (resFlags & wxTREE_HITTEST_ONITEMLABEL) )
216 {
217 wxTreeCtrl::SelectItem(itemHere,true);
218 m_itemHere = itemHere;
219 }
220 event.Skip();
221 }
222
223 // On mouse left, set the value and close the popup
224 void OnMouseClick(wxMouseEvent& event)
225 {
226 int resFlags;
227 wxTreeItemId itemHere = HitTest(event.GetPosition(),resFlags);
228 if ( itemHere.IsOk() && (resFlags & wxTREE_HITTEST_ONITEMLABEL) )
229 {
230 m_itemHere = itemHere;
231 m_value = itemHere;
232 Dismiss();
233 // TODO: Send event
234 }
235 event.Skip();
236 }
237
238 protected:
239
240 wxTreeItemId m_value; // current item index
241 wxTreeItemId m_itemHere; // hot item in popup
242
243 private:
244 DECLARE_EVENT_TABLE()
245 };
246
247
248 #endif // WX_CUSTOM_COMBO_H