native wxBitmapComboBox implementation for MSW (patch 1941399)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53626 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -19,6 +19,12 @@
|
||||
|
||||
#include "wx/bitmap.h"
|
||||
|
||||
// Define wxBITMAPCOMBOBOX_OWNERDRAWN_BASED for platforms which
|
||||
// wxBitmapComboBox implementation utilizes ownerdrawn combobox
|
||||
// (either native or generic).
|
||||
#if 1
|
||||
#define wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
|
||||
#endif
|
||||
|
||||
extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxBitmapComboBoxNameStr[];
|
||||
|
||||
@@ -27,22 +33,85 @@ class WXDLLIMPEXP_ADV wxBitmapComboBoxBase
|
||||
{
|
||||
public:
|
||||
// ctors and such
|
||||
wxBitmapComboBoxBase() { }
|
||||
wxBitmapComboBoxBase() { Init(); }
|
||||
|
||||
virtual ~wxBitmapComboBoxBase() { }
|
||||
|
||||
// Returns the image of the item with the given index.
|
||||
virtual wxBitmap GetItemBitmap(unsigned int n) const = 0;
|
||||
|
||||
// Sets the image for the given item.
|
||||
virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap) = 0;
|
||||
|
||||
#if !defined(wxBITMAPCOMBOBOX_OWNERDRAWN_BASED)
|
||||
|
||||
// Returns the image of the item with the given index.
|
||||
virtual wxBitmap GetItemBitmap(unsigned int n) const = 0;
|
||||
|
||||
// Returns size of the image used in list
|
||||
virtual wxSize GetBitmapSize() const = 0;
|
||||
|
||||
private:
|
||||
void Init() {}
|
||||
|
||||
#else // wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
|
||||
|
||||
// Returns the image of the item with the given index.
|
||||
virtual wxBitmap GetItemBitmap(unsigned int n) const;
|
||||
|
||||
// Returns size of the image used in list
|
||||
virtual wxSize GetBitmapSize() const
|
||||
{
|
||||
return m_usedImgSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// Returns pointer to the combobox item container
|
||||
virtual wxItemContainer* GetItemContainer() = 0;
|
||||
|
||||
// Return pointer to the owner-drawn combobox control
|
||||
virtual wxWindow* GetControl() = 0;
|
||||
|
||||
// wxItemContainer functions
|
||||
void BCBDoClear();
|
||||
void BCBDoDeleteOneItem(unsigned int n);
|
||||
|
||||
void DoSetItemBitmap(unsigned int n, const wxBitmap& bitmap);
|
||||
|
||||
void DrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const;
|
||||
void DrawItem(wxDC& dc, const wxRect& rect, int item, const wxString& text,
|
||||
int flags) const;
|
||||
wxCoord MeasureItem(size_t item) const;
|
||||
|
||||
// Returns true if image size was affected
|
||||
virtual bool OnAddBitmap(const wxBitmap& bitmap);
|
||||
|
||||
// Recalculates amount of empty space needed in front of text
|
||||
// in control itself. Returns number that can be passed to
|
||||
// wxOwnerDrawnComboBox::SetCustomPaintWidth() and similar
|
||||
// functions.
|
||||
virtual int DetermineIndent();
|
||||
|
||||
void UpdateInternals();
|
||||
|
||||
wxArrayPtrVoid m_bitmaps; // Images associated with items
|
||||
wxSize m_usedImgSize; // Size of bitmaps
|
||||
|
||||
int m_imgAreaWidth; // Width and height of area next to text field
|
||||
int m_fontHeight;
|
||||
int m_indent;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
#endif // !wxBITMAPCOMBOBOX_OWNERDRAWN_BASED/wxBITMAPCOMBOBOX_OWNERDRAWN_BASED
|
||||
};
|
||||
|
||||
|
||||
#include "wx/generic/bmpcbox.h"
|
||||
#if defined(__WXUNIVERSAL__)
|
||||
#include "wx/generic/bmpcbox.h"
|
||||
#elif defined(__WXMSW__)
|
||||
#include "wx/msw/bmpcbox.h"
|
||||
#else
|
||||
#include "wx/generic/bmpcbox.h"
|
||||
#endif
|
||||
|
||||
#endif // wxUSE_BITMAPCOMBOBOX
|
||||
|
||||
|
@@ -98,21 +98,9 @@ public:
|
||||
int Insert(const wxString& item, const wxBitmap& bitmap,
|
||||
unsigned int pos, wxClientData *clientData);
|
||||
|
||||
// Returns size of image used in list.
|
||||
virtual wxSize GetBitmapSize() const
|
||||
{
|
||||
return m_usedImgSize;
|
||||
}
|
||||
|
||||
// Returns the image of the item with the given index.
|
||||
virtual wxBitmap GetItemBitmap(unsigned int n) const;
|
||||
|
||||
// Sets the image for the given item.
|
||||
virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap);
|
||||
|
||||
virtual void DoClear();
|
||||
virtual void DoDeleteOneItem(unsigned int n);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const;
|
||||
@@ -120,38 +108,26 @@ protected:
|
||||
virtual wxCoord OnMeasureItem(size_t item) const;
|
||||
virtual wxCoord OnMeasureItemWidth(size_t item) const;
|
||||
|
||||
virtual int DoInsertItems(const wxArrayStringsAdapter & items,
|
||||
unsigned int pos,
|
||||
void **clientData, wxClientDataType type);
|
||||
|
||||
virtual bool SetFont(const wxFont& font);
|
||||
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
// Event handlers
|
||||
void OnSize(wxSizeEvent& event);
|
||||
|
||||
// Recalculates amount of empty space needed in front of
|
||||
// text in control itself.
|
||||
void DetermineIndent();
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
virtual bool SetFont(const wxFont& font);
|
||||
|
||||
bool OnAddBitmap(const wxBitmap& bitmap);
|
||||
virtual wxItemContainer* GetItemContainer() { return this; }
|
||||
virtual wxWindow* GetControl() { return this; }
|
||||
|
||||
// Adds image to position - called in Append/Insert before
|
||||
// string is added.
|
||||
bool DoInsertBitmap(const wxBitmap& image, unsigned int pos);
|
||||
|
||||
|
||||
wxArrayPtrVoid m_bitmaps; // Images associated with items
|
||||
wxSize m_usedImgSize; // Size of bitmaps
|
||||
// wxItemContainer implementation
|
||||
virtual int DoInsertItems(const wxArrayStringsAdapter & items,
|
||||
unsigned int pos,
|
||||
void **clientData, wxClientDataType type);
|
||||
virtual void DoClear();
|
||||
virtual void DoDeleteOneItem(unsigned int n);
|
||||
|
||||
private:
|
||||
int m_imgAreaWidth; // Width and height of area next to text field
|
||||
int m_fontHeight;
|
||||
bool m_inResize;
|
||||
|
||||
void Init();
|
||||
void PostCreate();
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
|
135
include/wx/msw/bmpcbox.h
Normal file
135
include/wx/msw/bmpcbox.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/msw/bmpcbox.h
|
||||
// Purpose: wxBitmapComboBox
|
||||
// Author: Jaakko Salli
|
||||
// Created: 2008-04-06
|
||||
// RCS-ID: $Id:$
|
||||
// Copyright: (c) 2008 Jaakko Salli
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_MSW_BMPCBOX_H_
|
||||
#define _WX_MSW_BMPCBOX_H_
|
||||
|
||||
|
||||
#include "wx/combobox.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapComboBox: a wxComboBox that allows images to be shown
|
||||
// in front of string items.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_ADV wxBitmapComboBox : public wxComboBox,
|
||||
public wxBitmapComboBoxBase
|
||||
{
|
||||
public:
|
||||
// ctors and such
|
||||
wxBitmapComboBox() : wxComboBox(), wxBitmapComboBoxBase()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxBitmapComboBox(wxWindow *parent,
|
||||
wxWindowID id = wxID_ANY,
|
||||
const wxString& value = wxEmptyString,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
int n = 0,
|
||||
const wxString choices[] = NULL,
|
||||
long style = 0,
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxBitmapComboBoxNameStr)
|
||||
: wxComboBox(),
|
||||
wxBitmapComboBoxBase()
|
||||
{
|
||||
Init();
|
||||
|
||||
(void)Create(parent, id, value, pos, size, n,
|
||||
choices, style, validator, name);
|
||||
}
|
||||
|
||||
wxBitmapComboBox(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString& value,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
const wxArrayString& choices,
|
||||
long style,
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxBitmapComboBoxNameStr);
|
||||
|
||||
bool Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString& value,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
int n,
|
||||
const wxString choices[],
|
||||
long style = 0,
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxBitmapComboBoxNameStr);
|
||||
|
||||
bool Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString& value,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
const wxArrayString& choices,
|
||||
long style = 0,
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxBitmapComboBoxNameStr);
|
||||
|
||||
virtual ~wxBitmapComboBox();
|
||||
|
||||
// Sets the image for the given item.
|
||||
virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap);
|
||||
|
||||
// Adds item with image to the end of the combo box.
|
||||
int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap);
|
||||
int Append(const wxString& item, const wxBitmap& bitmap, void *clientData);
|
||||
int Append(const wxString& item, const wxBitmap& bitmap, wxClientData *clientData);
|
||||
|
||||
// Inserts item with image into the list before pos. Not valid for wxCB_SORT
|
||||
// styles, use Append instead.
|
||||
int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos);
|
||||
int Insert(const wxString& item, const wxBitmap& bitmap,
|
||||
unsigned int pos, void *clientData);
|
||||
int Insert(const wxString& item, const wxBitmap& bitmap,
|
||||
unsigned int pos, wxClientData *clientData);
|
||||
|
||||
protected:
|
||||
|
||||
WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
|
||||
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
|
||||
virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
|
||||
|
||||
// Event handlers
|
||||
void OnSize(wxSizeEvent& event);
|
||||
|
||||
virtual bool SetFont(const wxFont& font);
|
||||
|
||||
virtual wxItemContainer* GetItemContainer() { return this; }
|
||||
virtual wxWindow* GetControl() { return this; }
|
||||
|
||||
// wxItemContainer implementation
|
||||
virtual int DoInsertItems(const wxArrayStringsAdapter & items,
|
||||
unsigned int pos,
|
||||
void **clientData, wxClientDataType type);
|
||||
virtual void DoClear();
|
||||
virtual void DoDeleteOneItem(unsigned int n);
|
||||
|
||||
virtual bool OnAddBitmap(const wxBitmap& bitmap);
|
||||
void RecreateControl();
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
bool m_inResize;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxBitmapComboBox)
|
||||
};
|
||||
|
||||
#endif // _WX_MSW_BMPCBOX_H_
|
Reference in New Issue
Block a user