native wxBitmapComboBox implementation for MSW (patch 1941399)
[wxWidgets.git] / include / wx / bmpcbox.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/bmpcbox.h
3 // Purpose: wxBitmapComboBox base header
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: Aug-31-2006
7 // Copyright: (c) Jaakko Salli
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_BMPCBOX_H_BASE_
13 #define _WX_BMPCBOX_H_BASE_
14
15
16 #include "wx/defs.h"
17
18 #if wxUSE_BITMAPCOMBOBOX
19
20 #include "wx/bitmap.h"
21
22 // Define wxBITMAPCOMBOBOX_OWNERDRAWN_BASED for platforms which
23 // wxBitmapComboBox implementation utilizes ownerdrawn combobox
24 // (either native or generic).
25 #if 1
26 #define wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
27 #endif
28
29 extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxBitmapComboBoxNameStr[];
30
31
32 class WXDLLIMPEXP_ADV wxBitmapComboBoxBase
33 {
34 public:
35 // ctors and such
36 wxBitmapComboBoxBase() { Init(); }
37
38 virtual ~wxBitmapComboBoxBase() { }
39
40 // Sets the image for the given item.
41 virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap) = 0;
42
43 #if !defined(wxBITMAPCOMBOBOX_OWNERDRAWN_BASED)
44
45 // Returns the image of the item with the given index.
46 virtual wxBitmap GetItemBitmap(unsigned int n) const = 0;
47
48 // Returns size of the image used in list
49 virtual wxSize GetBitmapSize() const = 0;
50
51 private:
52 void Init() {}
53
54 #else // wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
55
56 // Returns the image of the item with the given index.
57 virtual wxBitmap GetItemBitmap(unsigned int n) const;
58
59 // Returns size of the image used in list
60 virtual wxSize GetBitmapSize() const
61 {
62 return m_usedImgSize;
63 }
64
65 protected:
66
67 // Returns pointer to the combobox item container
68 virtual wxItemContainer* GetItemContainer() = 0;
69
70 // Return pointer to the owner-drawn combobox control
71 virtual wxWindow* GetControl() = 0;
72
73 // wxItemContainer functions
74 void BCBDoClear();
75 void BCBDoDeleteOneItem(unsigned int n);
76
77 void DoSetItemBitmap(unsigned int n, const wxBitmap& bitmap);
78
79 void DrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const;
80 void DrawItem(wxDC& dc, const wxRect& rect, int item, const wxString& text,
81 int flags) const;
82 wxCoord MeasureItem(size_t item) const;
83
84 // Returns true if image size was affected
85 virtual bool OnAddBitmap(const wxBitmap& bitmap);
86
87 // Recalculates amount of empty space needed in front of text
88 // in control itself. Returns number that can be passed to
89 // wxOwnerDrawnComboBox::SetCustomPaintWidth() and similar
90 // functions.
91 virtual int DetermineIndent();
92
93 void UpdateInternals();
94
95 wxArrayPtrVoid m_bitmaps; // Images associated with items
96 wxSize m_usedImgSize; // Size of bitmaps
97
98 int m_imgAreaWidth; // Width and height of area next to text field
99 int m_fontHeight;
100 int m_indent;
101
102 private:
103 void Init();
104 #endif // !wxBITMAPCOMBOBOX_OWNERDRAWN_BASED/wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
105 };
106
107
108 #if defined(__WXUNIVERSAL__)
109 #include "wx/generic/bmpcbox.h"
110 #elif defined(__WXMSW__)
111 #include "wx/msw/bmpcbox.h"
112 #else
113 #include "wx/generic/bmpcbox.h"
114 #endif
115
116 #endif // wxUSE_BITMAPCOMBOBOX
117
118 #endif // _WX_BMPCBOX_H_BASE_