00001
00002
00003
00004
00005
00007
00008
00009
00010
00011
00012
00013
00014
00016
00017 #ifndef _WXXTRA_ODCOMBO_H_
00018 #define _WXXTRA_ODCOMBO_H_
00019
00020 #include <wx/wx.h>
00021
00022 #if wxUSE_ODCOMBOBOX
00023 #undef wxXTRA_ODCOMBOBOX
00024 #include <wx/odcombo.h>
00025 #else
00026 #define wxXTRA_ODCOMBOBOX 1
00027
00028 #include <wx/ctrlsub.h>
00029 #include <wx/vlbox.h>
00030 #include "combo.h"
00031
00032
00033
00034
00035
00036 enum
00037 {
00038
00039 wxODCB_DCLICK_CYCLES = wxCC_SPECIAL_DCLICK,
00040
00041
00042
00043
00044 wxODCB_STD_CONTROL_PAINT = 0x1000
00045 };
00046
00047
00048
00049
00050
00051 enum
00052 {
00053
00054
00055 wxODCB_PAINTING_CONTROL = 0x0001
00056 };
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 class WXDLLIMPEXP_ADV wxVListBoxComboPopup : public wxVListBox,
00072 public wxComboPopup
00073 {
00074 friend class wxOwnerDrawnComboBox;
00075 public:
00076
00077
00078 wxVListBoxComboPopup() : wxVListBox(), wxComboPopup() { }
00079 virtual ~wxVListBoxComboPopup();
00080
00081
00082 virtual void Init();
00083 virtual bool Create(wxWindow* parent);
00084 virtual wxWindow *GetControl() { return this; }
00085 virtual void SetStringValue( const wxString& value );
00086 virtual wxString GetStringValue() const;
00087
00088
00089 virtual void OnPopup();
00090 virtual wxSize GetAdjustedSize( int minWidth, int prefHeight, int maxHeight );
00091 virtual void PaintComboControl( wxDC& dc, const wxRect& rect );
00092 virtual void OnComboKeyEvent( wxKeyEvent& event );
00093 virtual void OnComboDoubleClick();
00094 virtual bool LazyCreate();
00095
00096
00097 void SetSelection( int item );
00098 void Insert( const wxString& item, int pos );
00099 int Append(const wxString& item);
00100 void Clear();
00101 void Delete( unsigned int item );
00102 void SetItemClientData(unsigned int n, void* clientData, wxClientDataType clientDataItemsType);
00103 void *GetItemClientData(unsigned int n) const;
00104 void SetString( int item, const wxString& str );
00105 wxString GetString( int item ) const;
00106 unsigned int GetCount() const;
00107 int FindString(const wxString& s, bool bCase = false) const;
00108 int GetSelection() const;
00109
00110
00111 void Populate( const wxArrayString& choices );
00112 void ClearClientDatas();
00113
00114
00115 int GetItemAtPosition( const wxPoint& pos ) { return HitTest(pos); }
00116 wxCoord GetTotalHeight() const { return EstimateTotalHeight(); }
00117 wxCoord GetLineHeight(int line) const { return OnGetLineHeight(line); }
00118
00119 protected:
00120
00121
00122 bool HandleKey( int keycode, bool saturate, wxChar unicode = 0 );
00123
00124
00125 void SendComboBoxEvent( int selection );
00126
00127
00128 void DismissWithEvent();
00129
00130
00131 void ItemWidthChanged(unsigned int item)
00132 {
00133 m_widths[item] = -1;
00134 m_widthsDirty = true;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
00147
00148
00149 virtual wxCoord OnMeasureItem( size_t item ) const;
00150
00151
00152 virtual wxCoord OnMeasureItemWidth( size_t item ) const;
00153
00154
00155
00156 virtual void OnDrawBg(wxDC& dc, const wxRect& rect, int item, int flags) const;
00157
00158
00159 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
00160 void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
00161
00162
00163
00164 void OnMouseMove(wxMouseEvent& event);
00165 void OnMouseWheel(wxMouseEvent& event);
00166 void OnKey(wxKeyEvent& event);
00167 void OnLeftClick(wxMouseEvent& event);
00168
00169
00170 int GetWidestItemWidth() { CalcWidths(); return m_widestWidth; }
00171
00172
00173 int GetWidestItem() { CalcWidths(); return m_widestItem; }
00174
00175
00176 void StopPartialCompletion();
00177
00178 wxArrayString m_strings;
00179 wxArrayPtrVoid m_clientDatas;
00180
00181 wxFont m_useFont;
00182
00183
00184 int m_value;
00185 int m_itemHover;
00186 int m_itemHeight;
00187
00188 wxClientDataType m_clientDataItemsType;
00189
00190 private:
00191
00192
00193 wxArrayInt m_widths;
00194
00195
00196 int m_widestWidth;
00197
00198
00199 int m_widestItem;
00200
00201
00202 bool m_widthsDirty;
00203
00204
00205 bool m_findWidest;
00206
00207
00208 bool m_clicked;
00209
00210
00211 void CalcWidths();
00212
00213
00214 wxString m_partialCompletionString;
00215
00216 #if wxUSE_TIMER
00217
00218 wxTimer m_partialCompletionTimer;
00219 #endif // wxUSE_TIMER
00220
00221 DECLARE_EVENT_TABLE()
00222 };
00223
00224
00225
00226
00227
00228
00229
00230
00231 class WXDLLIMPEXP_ADV wxOwnerDrawnComboBox : public wxComboCtrl,
00232 public wxItemContainer
00233 {
00234
00235 friend class wxVListBoxComboPopup;
00236 public:
00237
00238
00239 wxOwnerDrawnComboBox() : wxComboCtrl() { Init(); }
00240
00241 wxOwnerDrawnComboBox(wxWindow *parent,
00242 wxWindowID id,
00243 const wxString& value,
00244 const wxPoint& pos,
00245 const wxSize& size,
00246 int n,
00247 const wxString choices[],
00248 long style = 0,
00249 const wxValidator& validator = wxDefaultValidator,
00250 const wxString& name = wxComboBoxNameStr)
00251 : wxComboCtrl()
00252 {
00253 Init();
00254
00255 (void)Create(parent, id, value, pos, size, n,
00256 choices, style, validator, name);
00257 }
00258
00259 bool Create(wxWindow *parent,
00260 wxWindowID id,
00261 const wxString& value = wxEmptyString,
00262 const wxPoint& pos = wxDefaultPosition,
00263 const wxSize& size = wxDefaultSize,
00264 long style = 0,
00265 const wxValidator& validator = wxDefaultValidator,
00266 const wxString& name = wxComboBoxNameStr);
00267
00268 wxOwnerDrawnComboBox(wxWindow *parent,
00269 wxWindowID id,
00270 const wxString& value,
00271 const wxPoint& pos,
00272 const wxSize& size,
00273 const wxArrayString& choices,
00274 long style,
00275 const wxValidator& validator = wxDefaultValidator,
00276 const wxString& name = wxComboBoxNameStr);
00277
00278 bool Create(wxWindow *parent,
00279 wxWindowID id,
00280 const wxString& value,
00281 const wxPoint& pos,
00282 const wxSize& size,
00283 int n,
00284 const wxString choices[],
00285 long style = 0,
00286 const wxValidator& validator = wxDefaultValidator,
00287 const wxString& name = wxComboBoxNameStr);
00288
00289 bool Create(wxWindow *parent,
00290 wxWindowID id,
00291 const wxString& value,
00292 const wxPoint& pos,
00293 const wxSize& size,
00294 const wxArrayString& choices,
00295 long style = 0,
00296 const wxValidator& validator = wxDefaultValidator,
00297 const wxString& name = wxComboBoxNameStr);
00298
00299 virtual ~wxOwnerDrawnComboBox();
00300
00301
00302 void SetPopupControl(wxVListBoxComboPopup* popup)
00303 {
00304 DoSetPopupControl(popup);
00305 }
00306
00307
00308 virtual void Clear();
00309 virtual void Delete(wxIndex n);
00310 virtual wxIndex GetCount() const;
00311 virtual wxString GetString(wxIndex n) const;
00312 virtual void SetString(wxIndex n, const wxString& s);
00313 virtual int FindString(const wxString& s, bool bCase ) const;
00314 virtual int FindString(const wxString& s) const {return FindString (s, false);}
00315 virtual void Select(int n);
00316 virtual int GetSelection() const;
00317 virtual void SetSelection(int n) { Select(n); }
00318
00319
00320
00321 virtual void SetSelection(long from, long to)
00322 {
00323 wxComboCtrl::SetSelection(from,to);
00324 }
00325
00326
00327 virtual int GetWidestItemWidth() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItemWidth(); }
00328
00329
00330 virtual int GetWidestItem() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItem(); }
00331
00332 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
00333
00334 protected:
00335
00336
00337
00338
00339
00340
00341 virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const;
00342
00343
00344 virtual wxCoord OnMeasureItem( size_t item ) const;
00345
00346
00347 virtual wxCoord OnMeasureItemWidth( size_t item ) const;
00348
00349
00350
00351 virtual void OnDrawBackground( wxDC& dc, const wxRect& rect, int item, int flags ) const;
00352
00353
00354 virtual void DoSetPopupControl(wxComboPopup* popup);
00355
00356
00357 void ClearClientDatas();
00358
00359 wxVListBoxComboPopup* GetVListBoxComboPopup() const
00360 {
00361 return (wxVListBoxComboPopup*) m_popupInterface;
00362 }
00363
00364 virtual int DoAppend(const wxString& item);
00365 virtual int DoInsert(const wxString& item, wxIndex pos);
00366 virtual void DoSetItemClientData(wxIndex n, void* clientData);
00367 virtual void* DoGetItemClientData(wxIndex n) const;
00368 virtual void DoSetItemClientObject(wxIndex n, wxClientData* clientData);
00369 virtual wxClientData* DoGetItemClientObject(wxIndex n) const;
00370
00371
00372
00373
00374 wxArrayString m_initChs;
00375
00376 private:
00377 void Init();
00378
00379 DECLARE_EVENT_TABLE()
00380
00381 DECLARE_DYNAMIC_CLASS(wxOwnerDrawnComboBox)
00382 };
00383
00384 #endif
00385
00386 #endif
00387
00388