~registry/codeblocks/trunk

« back to all changes in this revision

Viewing changes to src/sdk/propgrid/include/wx/propgrid/odcombo.h

  • Committer: mandrav
  • Date: 2007-02-12 14:55:28 UTC
  • Revision ID: svn-v4:98b59c6a-2706-0410-b7d6-d2fa1a1880c9:trunk:3594
* First part of directories layout re-organization: moved all sdk header files to a new dir named "include".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
///////////////////////////////////////////////////////////////////////////////
2
 
// Name:        odcombo.h
3
 
// Purpose:     wxPGOwnerDrawnComboBox and related classes interface
4
 
// Author:      Jaakko Salli
5
 
// Modified by:
6
 
// Created:     Jan-25-2005
7
 
// RCS-ID:      $Id:
8
 
// Copyright:   (c) 2005 Jaakko Salli
9
 
// Licence:     wxWindows licence
10
 
///////////////////////////////////////////////////////////////////////////////
11
 
 
12
 
#ifndef _WX_ODCOMBO_H_
13
 
#define _WX_ODCOMBO_H_
14
 
 
15
 
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16
 
    #pragma interface "odcombobox.h"
17
 
#endif
18
 
 
19
 
#include "wx/choice.h"
20
 
//#include "wx/popupwin.h"
21
 
 
22
 
// Item counts in GUI components were changed in 2.8.0
23
 
#if wxCHECK_VERSION(2,8,0)
24
 
    #define wxODCCount  unsigned int
25
 
    #define wxODCIndex  unsigned int
26
 
#else
27
 
    #define wxODCCount  int
28
 
    #define wxODCIndex  int
29
 
#endif
30
 
 
31
 
class WXDLLEXPORT wxVListBox;
32
 
class WXDLLEXPORT wxTextCtrl;
33
 
class WXDLLEXPORT wxButton;
34
 
 
35
 
// Temp stuff
36
 
#ifdef WXMAKINGDLL_PROPGRID
37
 
    #define WXDLLEXPORT_PGODC WXEXPORT
38
 
//#elif defined(WXUSINGDLL)
39
 
//    #define WXDLLEXPORT_PGODC WXIMPORT
40
 
#else // not making nor using DLL
41
 
    #define WXDLLEXPORT_PGODC
42
 
#endif
43
 
 
44
 
class WXDLLEXPORT_PGODC wxPGOwnerDrawnComboBox;
45
 
 
46
 
// ----------------------------------------------------------------------------
47
 
// wxComboPopupInterface is the interface class that lies between
48
 
// the wxPGOwnerDrawnComboBox and its popup window.
49
 
// ----------------------------------------------------------------------------
50
 
 
51
 
//
52
 
// Callback flags
53
 
//
54
 
 
55
 
// when set, we are painting the selected item in control, not in the popup
56
 
#define wxODCB_CB_PAINTING_CONTROL  0x0001
57
 
 
58
 
 
59
 
typedef void (wxEvtHandler::* wxComboPaintCallback)(wxPGOwnerDrawnComboBox* pCb,
60
 
                                                    int item,
61
 
                                                    wxDC& dc,
62
 
                                                    wxRect& rect,
63
 
                                                    int flags );
64
 
 
65
 
class WXDLLEXPORT_PGODC wxComboPopupInterface : public wxEvtHandler
66
 
{
67
 
    friend class wxPGOwnerDrawnComboBox;
68
 
public:
69
 
 
70
 
    wxComboPopupInterface();
71
 
    virtual ~wxComboPopupInterface();
72
 
 
73
 
    // default implementation does nothing
74
 
    virtual void Clear();
75
 
 
76
 
    // default implementation does nothing
77
 
    virtual void Delete( int item );
78
 
 
79
 
    // wxComboBox::FindString
80
 
    // default implementation returns wxNOT_FOUND
81
 
    virtual int FindString(const wxString& s) const;
82
 
 
83
 
    // default implementation returns NULL
84
 
    //virtual void* GetClientData( int item ) const;
85
 
 
86
 
    // default implementation returns 0
87
 
    virtual int GetCount() const;
88
 
 
89
 
    // wxComboBox::GetString
90
 
    // default implementation returns empty string
91
 
    virtual wxString GetString( int item ) const;
92
 
 
93
 
    // default implementation does nothing
94
 
    virtual void Insert( const wxString& item, int pos );
95
 
 
96
 
    // default implementation does nothing
97
 
    //virtual void SetClientData( int item, void* clientData );
98
 
 
99
 
    // wxComboBox::SetSelection
100
 
    // default implementation does nothing
101
 
    virtual void SetSelection( int item );
102
 
 
103
 
    // wxComboBox::SetString
104
 
    // default implementation does nothing
105
 
    virtual void SetString( int item, const wxString& str );
106
 
 
107
 
    // wxComboBox::SetValue
108
 
    // default implementation does nothing
109
 
    virtual void SetValueFromString ( const wxString& value );
110
 
 
111
 
    // default implementation returns NULL
112
 
    //virtual wxArrayString* GetArrayString();
113
 
 
114
 
    // default implementation returns false
115
 
    //virtual bool IsValueInt() const;
116
 
 
117
 
    // returns TRUE if item is hilited
118
 
    virtual bool IsHighlighted ( int item ) const;
119
 
 
120
 
    // called by wxOwnerDrawComboBox after assigned to it
121
 
    // If returns TRUE, then GeneratePopup is called immediately
122
 
    // (instead of at the first time it is shown). Default returns
123
 
    // TRUE.
124
 
    virtual bool Init( wxPGOwnerDrawnComboBox* combo );
125
 
 
126
 
    // returns pointer to created popup control
127
 
    // parent = wxPopupWindow where combo popup should be placed
128
 
    //   if NULL, then it is not necesary to create the popup
129
 
    // minWidth = preferred minimum width for window
130
 
    // maxHeight = absolute maximum height for window
131
 
    // prefHeight = preferred height. Only applies if > 0,
132
 
    //   and should only be rounded down, if necessary.
133
 
    // isVolatile = set to true if window should be destroyed
134
 
    //   when hidden. If not then this method is still called.
135
 
    //   In this case, the existing window, with adjusted
136
 
    //   dimensions should be returned.
137
 
    virtual wxWindow* GeneratePopup( wxWindow* parent, int minWidth,
138
 
                                     int maxHeight, int prefHeight ) = 0;
139
 
 
140
 
    // Returns pointer to the current value (if integer).
141
 
    // With the default popup, for example, this returns pointer
142
 
    // to int.
143
 
    virtual const int* GetIntPtr () const;
144
 
 
145
 
    // gets displayed string representation of the value
146
 
    virtual wxString GetValueAsString() const = 0;
147
 
 
148
 
    //
149
 
    // Helper methods.
150
 
    //wxPopupWindow* CreatePopupWindow () const;
151
 
 
152
 
    // Event handler handles this.
153
 
    //wxWindow*               m_handledWnd;
154
 
 
155
 
    //inline wxWindow* GetPopupControl() const { wxASSERT(m_popupAsWnd); return m_popupAsWnd; }
156
 
 
157
 
    inline wxComboPaintCallback GetCallback() const { return m_callback; }
158
 
 
159
 
protected:
160
 
 
161
 
    // TODO: Once popup transient window works Ok, remove these.
162
 
    void OnMouseEvent( wxMouseEvent& event );
163
 
    //void OnFocusChange ( wxFocusEvent& event );
164
 
 
165
 
    wxPGOwnerDrawnComboBox*   m_combo;
166
 
    //wxWindow*               m_popupAsWnd;
167
 
 
168
 
    // Must be in all interfaces to paint the combobox too (in some cases)
169
 
    wxComboPaintCallback    m_callback;
170
 
 
171
 
private:
172
 
    DECLARE_EVENT_TABLE()
173
 
};
174
 
 
175
 
 
176
 
// ----------------------------------------------------------------------------
177
 
// wxPGCustomComboBox: a generic control that looks like a wxComboBox but allows
178
 
// completely custom popup.
179
 
//
180
 
// Remarks:
181
 
//   - It accepts wxCB_READONLY to disable the wxTextCtrl (actually the control
182
 
//     is not created at all).
183
 
//
184
 
// ----------------------------------------------------------------------------
185
 
 
186
 
 
187
 
#define wxPGCustomComboBoxBase        wxControl
188
 
 
189
 
 
190
 
class WXDLLEXPORT_PGODC wxPGCustomComboBox : public wxPGCustomComboBoxBase
191
 
{
192
 
public:
193
 
    // ctors and such
194
 
    wxPGCustomComboBox() : wxPGCustomComboBoxBase() { Init(); }
195
 
 
196
 
    wxPGCustomComboBox(wxWindow *parent,
197
 
                     wxWindowID id,
198
 
                     const wxString& value = wxEmptyString,
199
 
                     const wxPoint& pos = wxDefaultPosition,
200
 
                     const wxSize& size = wxDefaultSize,
201
 
                     long style = 0,
202
 
                     const wxValidator& validator = wxDefaultValidator,
203
 
                     const wxString& name = wxComboBoxNameStr)
204
 
        : wxPGCustomComboBoxBase()
205
 
    {
206
 
        Init();
207
 
 
208
 
        (void)Create(parent, id, value, pos, size, style, validator, name);
209
 
    }
210
 
 
211
 
    bool Create(wxWindow *parent,
212
 
                wxWindowID id,
213
 
                const wxString& value = wxEmptyString,
214
 
                const wxPoint& pos = wxDefaultPosition,
215
 
                const wxSize& size = wxDefaultSize,
216
 
                long style = 0,
217
 
                const wxValidator& validator = wxDefaultValidator,
218
 
                const wxString& name = wxComboBoxNameStr);
219
 
 
220
 
    virtual ~wxPGCustomComboBox();
221
 
 
222
 
    // get the popup window containing the popup control
223
 
    wxWindow *GetPopupWindow() const { return m_winPopup; }
224
 
 
225
 
    virtual void HidePopup( bool sendEvent );
226
 
    void SendShowPopupSignal();
227
 
 
228
 
    // common code to be called on popup hide
229
 
    void OnPopupDismiss();
230
 
 
231
 
    // return true if the popup is currently shown
232
 
    bool IsPopupShown() const { return (m_isPopupShown > 0); }
233
 
 
234
 
    // get the popup control/panel in window
235
 
    wxWindow *GetPopupControl() const { return m_popup; }
236
 
 
237
 
    // Get the text control which is part of the combobox.
238
 
    wxTextCtrl *GetTextCtrl() const { return m_text; }
239
 
 
240
 
    // get the dropdown button which is part of the combobox
241
 
    // note: its not necessarily a wxButton or wxBitmapButton
242
 
    wxWindow *GetButton() const { return m_btn; }
243
 
 
244
 
    // forward these functions to all subcontrols
245
 
    virtual bool Enable(bool enable = true);
246
 
    virtual bool Show(bool show = true);
247
 
    virtual bool SetFont(const wxFont& font);
248
 
    //virtual void SetFocus();
249
 
    //virtual void SetFocusFromKbd();
250
 
    void SetId( wxWindowID winid );
251
 
 
252
 
    // Return TRUE if item is hilited in the combo
253
 
    bool IsHighlighted ( int item ) const;
254
 
 
255
 
#if wxUSE_TOOLTIPS
256
 
    virtual void DoSetToolTip( wxToolTip *tip );
257
 
#endif // wxUSE_TOOLTIPS
258
 
 
259
 
    // wxTextCtrl methods
260
 
    virtual wxString GetValue() const;
261
 
    virtual void SetValue(const wxString& value);
262
 
    virtual void Copy();
263
 
    virtual void Cut();
264
 
    virtual void Paste();
265
 
    virtual void SetInsertionPoint(long pos);
266
 
    virtual void SetInsertionPointEnd();
267
 
    virtual long GetInsertionPoint() const;
268
 
    virtual long GetLastPosition() const;
269
 
    virtual void Replace(long from, long to, const wxString& value);
270
 
    virtual void Remove(long from, long to);
271
 
    virtual void SetSelection(long from, long to);
272
 
 
273
 
    // wxPGCustomComboBox-only methods
274
 
 
275
 
    // Adjust popup size.
276
 
    //   extLeft = how many pixels the popup extends to the left
277
 
    //   extRight = how many pixels the popup extends to the right
278
 
    //   prefHeight = preferred popup height
279
 
    void SetPopupExtents( int extLeft, int extRight = 0, int prefHeight = -1 );
280
 
 
281
 
    // set width of custom paint area in writable combo
282
 
    // in read-only, used to indicate area that is not covered by the
283
 
    // focus rectangle
284
 
    void SetCustomPaintArea( int width );
285
 
 
286
 
    // This is called to custom paint the control itself (ie. not the popup).
287
 
    virtual void OnItemPaint( wxDC& dc, const wxRect& rect );
288
 
 
289
 
    /*inline void PreventNextButtonPopup()
290
 
    {
291
 
        m_isPopupShown = -1;
292
 
    }*/
293
 
 
294
 
protected:
295
 
 
296
 
    // override the base class virtuals involved into geometry calculations
297
 
    virtual void DoMoveWindow(int x, int y, int width, int height);
298
 
    virtual wxSize DoGetBestSize() const;
299
 
 
300
 
    // event handlers
301
 
    void OnMouseEvent( wxMouseEvent& event );
302
 
    void OnPaint( wxPaintEvent& event );
303
 
    void OnResize( wxSizeEvent& event );
304
 
    void OnFocusEvent( wxFocusEvent& event );
305
 
 
306
 
    // This is used when m_text is hidden (readonly).
307
 
    wxString                m_valueString;
308
 
 
309
 
    // the text control and button we show all the time
310
 
    wxTextCtrl*             m_text;
311
 
    wxWindow*               m_btn;
312
 
 
313
 
    // popup window containing the window managed by the interface .
314
 
    wxWindow*               m_winPopup;
315
 
 
316
 
    // the popup control/panel
317
 
    wxWindow*               m_popup;
318
 
 
319
 
    // this is for this control itself
320
 
    wxEvtHandler*           m_extraEvtHandler;
321
 
 
322
 
    // this is for text
323
 
    wxEvtHandler*           m_textEvtHandler;
324
 
 
325
 
    // this is for the top level window
326
 
    wxEvtHandler*   m_toplevEvtHandler;
327
 
 
328
 
    wxLongLong              m_timeLastMouseUp;
329
 
 
330
 
    // how much popup should expand to the left/right of the control
331
 
    wxCoord                 m_extLeft;
332
 
    wxCoord                 m_extRight;
333
 
 
334
 
    // preferred popup height. default is -1.
335
 
    wxCoord                 m_heightPopup;
336
 
 
337
 
    // how much of writable combo is custom-paint by callback?
338
 
    // also used to indicate area that is not covered by "blue"
339
 
    // selection indicator.
340
 
    wxCoord                 m_widthCustomPaint;
341
 
 
342
 
    // FIXME: Only necessary for GTK and its kind
343
 
    wxCoord                 m_widthCustomBorder;
344
 
 
345
 
    // is the popup window currenty shown?
346
 
    // < 0 is special value
347
 
    int                     m_isPopupShown;
348
 
 
349
 
    // TODO: Remove after real popup works ok.
350
 
    unsigned char m_fakePopupUsage;
351
 
 
352
 
    unsigned char m_ignoreNextButtonClick;
353
 
 
354
 
    // Set to 1 on mouse down, 0 on mouse up. Used to eliminate down-less mouse ups.
355
 
    unsigned char m_downReceived;
356
 
 
357
 
private:
358
 
    void Init();
359
 
 
360
 
    DECLARE_EVENT_TABLE()
361
 
 
362
 
    DECLARE_DYNAMIC_CLASS(wxPGCustomComboBox)
363
 
};
364
 
 
365
 
 
366
 
// ----------------------------------------------------------------------------
367
 
// wxPGOwnerDrawnComboBox: a generic wxComboBox that allows custom paint items
368
 
// and even a completely custom popup control.
369
 
// ----------------------------------------------------------------------------
370
 
 
371
 
// New window styles
372
 
 
373
 
// if used, control itself is not custom paint using callback
374
 
// even if this is not used, writable combo is never custom paint
375
 
// until SetCustomPaintArea is called
376
 
#define wxODCB_STD_CONTROL_PAINT    0x0100
377
 
 
378
 
// Causes double-clicking to cycle the item instead of showing
379
 
// the popup. Shift-pressed causes cycling direction to reverse.
380
 
#define wxODCB_DOUBLE_CLICK_CYCLES  0x0200
381
 
 
382
 
 
383
 
class WXDLLEXPORT_PGODC wxPGOwnerDrawnComboBox : public wxPGCustomComboBox, public wxItemContainer
384
 
{
385
 
    friend class wxComboPopupWindow;
386
 
    friend class wxPGCustomComboBox;
387
 
public:
388
 
    // ctors and such
389
 
    wxPGOwnerDrawnComboBox() : wxPGCustomComboBox() { Init(); }
390
 
 
391
 
    wxPGOwnerDrawnComboBox(wxWindow *parent,
392
 
               wxWindowID id,
393
 
               const wxString& value,
394
 
               const wxPoint& pos,
395
 
               const wxSize& size,
396
 
               int n,
397
 
               const wxString choices[],
398
 
               wxComboPaintCallback callback,
399
 
               long style = 0,
400
 
               const wxValidator& validator = wxDefaultValidator,
401
 
               const wxString& name = wxComboBoxNameStr)
402
 
        : wxPGCustomComboBox()
403
 
    {
404
 
        Init();
405
 
 
406
 
        (void)Create(parent, id, value, pos, size, n, choices,
407
 
                     callback, style, validator, name);
408
 
    }
409
 
 
410
 
    wxPGOwnerDrawnComboBox(wxWindow *parent,
411
 
               wxWindowID id,
412
 
               const wxString& value = wxEmptyString,
413
 
               const wxPoint& pos = wxDefaultPosition,
414
 
               const wxSize& size = wxDefaultSize,
415
 
               wxComboPopupInterface* iface = (wxComboPopupInterface*) NULL,
416
 
               long style = 0,
417
 
               const wxValidator& validator = wxDefaultValidator,
418
 
               const wxString& name = wxComboBoxNameStr)
419
 
        : wxPGCustomComboBox()
420
 
    {
421
 
        Init();
422
 
 
423
 
        (void)Create(parent, id, value, pos, size, iface,
424
 
                     style, validator, name);
425
 
    }
426
 
 
427
 
    bool Create(wxWindow *parent,
428
 
                wxWindowID id,
429
 
                const wxString& value = wxEmptyString,
430
 
                const wxPoint& pos = wxDefaultPosition,
431
 
                const wxSize& size = wxDefaultSize,
432
 
                wxComboPopupInterface* iface = (wxComboPopupInterface*) NULL,
433
 
                long style = 0,
434
 
                const wxValidator& validator = wxDefaultValidator,
435
 
                const wxString& name = wxComboBoxNameStr);
436
 
 
437
 
    wxPGOwnerDrawnComboBox(wxWindow *parent,
438
 
               wxWindowID id,
439
 
               const wxString& value,
440
 
               const wxPoint& pos,
441
 
               const wxSize& size,
442
 
               const wxArrayString& choices,
443
 
               wxComboPaintCallback callback = (wxComboPaintCallback) NULL,
444
 
               long style = 0,
445
 
               const wxValidator& validator = wxDefaultValidator,
446
 
               const wxString& name = wxComboBoxNameStr);
447
 
 
448
 
    bool Create(wxWindow *parent,
449
 
                wxWindowID id,
450
 
                const wxString& value = wxEmptyString,
451
 
                const wxPoint& pos = wxDefaultPosition,
452
 
                const wxSize& size = wxDefaultSize,
453
 
                int n = 0,
454
 
                const wxString choices[] = (const wxString *) NULL,
455
 
                wxComboPaintCallback callback = (wxComboPaintCallback) NULL,
456
 
                long style = 0,
457
 
                const wxValidator& validator = wxDefaultValidator,
458
 
                const wxString& name = wxComboBoxNameStr);
459
 
 
460
 
    bool Create(wxWindow *parent,
461
 
                wxWindowID id,
462
 
                const wxString& value,
463
 
                const wxPoint& pos,
464
 
                const wxSize& size,
465
 
                const wxArrayString& choices,
466
 
                wxComboPaintCallback callback = (wxComboPaintCallback) NULL,
467
 
                long style = 0,
468
 
                const wxValidator& validator = wxDefaultValidator,
469
 
                const wxString& name = wxComboBoxNameStr);
470
 
 
471
 
    virtual ~wxPGOwnerDrawnComboBox();
472
 
 
473
 
// a combo control needs a control for popup window it displays
474
 
    //void SetPopupControl(wxComboPopup *popup);
475
 
    wxComboPopupInterface* GetPopupInterface() const { return m_popupInterface; }
476
 
 
477
 
    // show/hide popup window
478
 
    void ShowPopup();
479
 
    void HidePopup( bool sendEvent = true );
480
 
 
481
 
    // Return TRUE if item is hilited in the combo
482
 
    bool IsHighlighted ( int item ) const;
483
 
 
484
 
    // wxControlWithItems methods
485
 
    virtual void Clear();
486
 
    virtual void Delete(wxODCIndex n);
487
 
    virtual wxODCCount GetCount() const;
488
 
    virtual wxString GetString(wxODCIndex n) const;
489
 
    virtual void SetString(wxODCIndex n, const wxString& s);
490
 
    virtual int FindString(const wxString& s) const;
491
 
    virtual void Select(int n);
492
 
    virtual int GetSelection() const;
493
 
    void SetSelection(int n) { Select(n); }
494
 
 
495
 
    // wxPGOwnerDrawnComboBox-only methods
496
 
 
497
 
    // Adjust popup size.
498
 
    //   extLeft = how many pixels the popup extends to the left
499
 
    //   extRight = how many pixels the popup extends to the right
500
 
    //   prefHeight = preferred popup height
501
 
    //void SetPopupExtents( int extLeft, int extRight = 0, int prefHeight = -1 );
502
 
 
503
 
    void SetPopupInterface( wxComboPopupInterface* iface );
504
 
 
505
 
    virtual void OnItemPaint( wxDC& dc, const wxRect& rect );
506
 
 
507
 
    wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
508
 
 
509
 
    //inline bool HasClientObjectData () const { return false; }
510
 
 
511
 
protected:
512
 
 
513
 
    // event handlers
514
 
    void OnButtonClick(wxCommandEvent& event);
515
 
 
516
 
    // clears all allocated client datas
517
 
    void ClearClientDatas();
518
 
 
519
 
    virtual int DoAppend(const wxString& item);
520
 
    virtual int DoInsert(const wxString& item, wxODCIndex pos);
521
 
    virtual void DoSetItemClientData(wxODCIndex n, void* clientData);
522
 
    virtual void* DoGetItemClientData(wxODCIndex n) const;
523
 
    virtual void DoSetItemClientObject(wxODCIndex n, wxClientData* clientData);
524
 
    virtual wxClientData* DoGetItemClientObject(wxODCIndex n) const;
525
 
 
526
 
    // popup interface
527
 
    wxComboPopupInterface*  m_popupInterface;
528
 
 
529
 
    // holder for client datas
530
 
    wxArrayPtrVoid          m_clientDatas;
531
 
 
532
 
    // is the data type of interface 'int'?
533
 
    bool                    m_hasIntValue;
534
 
 
535
 
private:
536
 
    void Init();
537
 
 
538
 
    DECLARE_EVENT_TABLE()
539
 
 
540
 
    DECLARE_DYNAMIC_CLASS(wxPGOwnerDrawnComboBox)
541
 
};
542
 
 
543
 
#endif // _WX_ODCOMBO_H_