bmpcbox.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_BMPCBOX_H_BASE_
  11. #define _WX_BMPCBOX_H_BASE_
  12. #include "wx/defs.h"
  13. #if wxUSE_BITMAPCOMBOBOX
  14. #include "wx/bitmap.h"
  15. #include "wx/dynarray.h"
  16. class WXDLLIMPEXP_FWD_CORE wxWindow;
  17. class WXDLLIMPEXP_FWD_CORE wxItemContainer;
  18. // Define wxBITMAPCOMBOBOX_OWNERDRAWN_BASED for platforms which
  19. // wxBitmapComboBox implementation utilizes ownerdrawn combobox
  20. // (either native or generic).
  21. #if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)
  22. #define wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
  23. class WXDLLIMPEXP_FWD_CORE wxDC;
  24. #endif
  25. extern WXDLLIMPEXP_DATA_ADV(const char) wxBitmapComboBoxNameStr[];
  26. class WXDLLIMPEXP_ADV wxBitmapComboBoxBase
  27. {
  28. public:
  29. // ctors and such
  30. wxBitmapComboBoxBase() { Init(); }
  31. virtual ~wxBitmapComboBoxBase() { }
  32. // Sets the image for the given item.
  33. virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap) = 0;
  34. #if !defined(wxBITMAPCOMBOBOX_OWNERDRAWN_BASED)
  35. // Returns the image of the item with the given index.
  36. virtual wxBitmap GetItemBitmap(unsigned int n) const = 0;
  37. // Returns size of the image used in list
  38. virtual wxSize GetBitmapSize() const = 0;
  39. private:
  40. void Init() {}
  41. #else // wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
  42. // Returns the image of the item with the given index.
  43. virtual wxBitmap GetItemBitmap(unsigned int n) const;
  44. // Returns size of the image used in list
  45. virtual wxSize GetBitmapSize() const
  46. {
  47. return m_usedImgSize;
  48. }
  49. protected:
  50. // Returns pointer to the combobox item container
  51. virtual wxItemContainer* GetItemContainer() = 0;
  52. // Return pointer to the owner-drawn combobox control
  53. virtual wxWindow* GetControl() = 0;
  54. // wxItemContainer functions
  55. void BCBDoClear();
  56. void BCBDoDeleteOneItem(unsigned int n);
  57. void DoSetItemBitmap(unsigned int n, const wxBitmap& bitmap);
  58. void DrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const;
  59. void DrawItem(wxDC& dc, const wxRect& rect, int item, const wxString& text,
  60. int flags) const;
  61. wxCoord MeasureItem(size_t item) const;
  62. // Returns true if image size was affected
  63. virtual bool OnAddBitmap(const wxBitmap& bitmap);
  64. // Recalculates amount of empty space needed in front of text
  65. // in control itself. Returns number that can be passed to
  66. // wxOwnerDrawnComboBox::SetCustomPaintWidth() and similar
  67. // functions.
  68. virtual int DetermineIndent();
  69. void UpdateInternals();
  70. wxArrayPtrVoid m_bitmaps; // Images associated with items
  71. wxSize m_usedImgSize; // Size of bitmaps
  72. int m_imgAreaWidth; // Width and height of area next to text field
  73. int m_fontHeight;
  74. int m_indent;
  75. private:
  76. void Init();
  77. #endif // !wxBITMAPCOMBOBOX_OWNERDRAWN_BASED/wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
  78. };
  79. #if defined(__WXUNIVERSAL__)
  80. #include "wx/generic/bmpcbox.h"
  81. #elif defined(__WXMSW__)
  82. #include "wx/msw/bmpcbox.h"
  83. #elif defined(__WXGTK20__)
  84. #include "wx/gtk/bmpcbox.h"
  85. #else
  86. #include "wx/generic/bmpcbox.h"
  87. #endif
  88. #endif // wxUSE_BITMAPCOMBOBOX
  89. #endif // _WX_BMPCBOX_H_BASE_