bmpcbox.h 3.4 KB

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