1998-05-22 13:09:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: ownerdrw.h
|
|
|
|
// Purpose: interface for owner-drawn GUI elements
|
|
|
|
// Author: Vadim Zeitlin
|
1999-07-29 00:56:34 -04:00
|
|
|
// Modified by:
|
1998-05-22 13:09:19 -04:00
|
|
|
// Created: 11.11.97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-22 13:09:19 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _OWNERDRW_H
|
|
|
|
#define _OWNERDRW_H
|
|
|
|
|
2005-03-16 11:18:31 -05:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
#if wxUSE_OWNER_DRAWN
|
|
|
|
|
1999-12-02 09:47:49 -05:00
|
|
|
#include "wx/bitmap.h"
|
|
|
|
#include "wx/colour.h"
|
|
|
|
#include "wx/font.h"
|
|
|
|
|
1998-05-22 13:09:19 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn
|
|
|
|
// behaviour
|
|
|
|
//
|
|
|
|
// wxOwnerDrawn supports drawing of an item with non standard font, color and
|
|
|
|
// also supports 3 bitmaps: either a checked/unchecked bitmap for a checkable
|
|
|
|
// element or one unchangeable bitmap otherwise.
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-10-25 11:51:37 -04:00
|
|
|
|
1998-05-22 13:09:19 -04:00
|
|
|
class WXDLLEXPORT wxOwnerDrawn
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor & dtor
|
1999-10-25 11:51:37 -04:00
|
|
|
wxOwnerDrawn(const wxString& str = wxEmptyString,
|
2004-09-20 07:31:49 -04:00
|
|
|
bool bCheckable = false,
|
|
|
|
bool bMenuItem = false); // FIXME kludge for colors
|
2005-06-07 14:28:48 -04:00
|
|
|
virtual ~wxOwnerDrawn();
|
1998-05-22 13:09:19 -04:00
|
|
|
|
|
|
|
// fix appearance
|
1999-04-03 17:25:12 -05:00
|
|
|
void SetFont(const wxFont& font)
|
2004-09-20 07:31:49 -04:00
|
|
|
{ m_font = font; m_bOwnerDrawn = true; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
wxFont& GetFont() const { return (wxFont &)m_font; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
void SetTextColour(const wxColour& colText)
|
2004-09-20 07:31:49 -04:00
|
|
|
{ m_colText = colText; m_bOwnerDrawn = true; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
wxColour& GetTextColour() const { return (wxColour&) m_colText; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
void SetBackgroundColour(const wxColour& colBack)
|
2004-09-20 07:31:49 -04:00
|
|
|
{ m_colBack = colBack; m_bOwnerDrawn = true; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
wxColour& GetBackgroundColour() const
|
|
|
|
{ return (wxColour&) m_colBack ; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-07-29 00:56:34 -04:00
|
|
|
void SetBitmaps(const wxBitmap& bmpChecked,
|
1999-04-03 17:25:12 -05:00
|
|
|
const wxBitmap& bmpUnchecked = wxNullBitmap)
|
|
|
|
{ m_bmpChecked = bmpChecked;
|
|
|
|
m_bmpUnchecked = bmpUnchecked;
|
2004-09-20 07:31:49 -04:00
|
|
|
m_bOwnerDrawn = true; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
2000-09-01 05:13:41 -04:00
|
|
|
void SetBitmap(const wxBitmap& bmpChecked)
|
2000-09-01 04:35:30 -04:00
|
|
|
{ m_bmpChecked = bmpChecked;
|
2004-09-20 07:31:49 -04:00
|
|
|
m_bOwnerDrawn = true; }
|
2000-09-01 04:35:30 -04:00
|
|
|
|
2003-09-21 20:43:36 -04:00
|
|
|
void SetDisabledBitmap( const wxBitmap& bmpDisabled )
|
|
|
|
{ m_bmpDisabled = bmpDisabled;
|
2004-09-20 07:31:49 -04:00
|
|
|
m_bOwnerDrawn = true; }
|
2003-09-21 20:43:36 -04:00
|
|
|
|
2004-09-20 07:31:49 -04:00
|
|
|
const wxBitmap& GetBitmap(bool bChecked = true) const
|
1999-04-03 17:25:12 -05:00
|
|
|
{ return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
2003-09-21 20:43:36 -04:00
|
|
|
const wxBitmap& GetDisabledBitmap() const
|
|
|
|
{ return m_bmpDisabled; }
|
|
|
|
|
1998-05-22 13:09:19 -04:00
|
|
|
// the height of the menu checkmark (or bitmap) is determined by the font
|
|
|
|
// for the current item, but the width should be always the same (for the
|
|
|
|
// items to be aligned), so by default it's taken to be the same as for
|
|
|
|
// the last item (and default width for the first one).
|
|
|
|
//
|
|
|
|
// NB: default is too small for bitmaps, but ok for checkmarks.
|
1999-04-03 17:25:12 -05:00
|
|
|
void SetMarginWidth(int nWidth)
|
|
|
|
{
|
|
|
|
ms_nLastMarginWidth = m_nMarginWidth = (size_t) nWidth;
|
|
|
|
if ( ((size_t) nWidth) != ms_nDefaultMarginWidth )
|
2004-09-20 07:31:49 -04:00
|
|
|
m_bOwnerDrawn = true;
|
1999-04-03 17:25:12 -05:00
|
|
|
}
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
int GetMarginWidth() const { return (int) m_nMarginWidth; }
|
|
|
|
static int GetDefaultMarginWidth() { return (int) ms_nDefaultMarginWidth; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
|
|
|
// accessors
|
1999-10-25 11:51:37 -04:00
|
|
|
void SetName(const wxString& strName) { m_strName = strName; }
|
|
|
|
const wxString& GetName() const { return m_strName; }
|
|
|
|
void SetCheckable(bool checkable) { m_bCheckable = checkable; }
|
|
|
|
bool IsCheckable() const { return m_bCheckable; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
2001-05-21 19:58:58 -04:00
|
|
|
// this is for menu items only: accel string is drawn right aligned after the
|
|
|
|
// menu item if not empty
|
|
|
|
void SetAccelString(const wxString& strAccel) { m_strAccel = strAccel; }
|
|
|
|
|
2004-09-20 07:31:49 -04:00
|
|
|
// this function might seem strange, but if it returns false it means that
|
1998-05-22 13:09:19 -04:00
|
|
|
// no non-standard attribute are set, so there is no need for this control
|
2004-09-20 07:31:49 -04:00
|
|
|
// to be owner-drawn. Moreover, you can force owner-drawn to false if you
|
1998-05-22 13:09:19 -04:00
|
|
|
// want to change, say, the color for the item but only if it is owner-drawn
|
|
|
|
// (see wxMenuItem::wxMenuItem for example)
|
1999-10-25 11:51:37 -04:00
|
|
|
bool IsOwnerDrawn() const { return m_bOwnerDrawn; }
|
2003-09-21 20:43:36 -04:00
|
|
|
|
|
|
|
// switch on/off owner-drawing the item
|
2004-09-20 07:31:49 -04:00
|
|
|
void SetOwnerDrawn(bool ownerDrawn = true) { m_bOwnerDrawn = ownerDrawn; }
|
|
|
|
void ResetOwnerDrawn() { m_bOwnerDrawn = false; }
|
1998-05-22 13:09:19 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
// constants used in OnDrawItem
|
|
|
|
// (they have the same values as corresponding Win32 constants)
|
|
|
|
enum wxODAction
|
1999-07-29 00:56:34 -04:00
|
|
|
{
|
1998-05-22 13:09:19 -04:00
|
|
|
wxODDrawAll = 0x0001, // redraw entire control
|
|
|
|
wxODSelectChanged = 0x0002, // selection changed (see Status.Select)
|
1999-07-29 00:56:34 -04:00
|
|
|
wxODFocusChanged = 0x0004 // keyboard focus changed (see Status.Focus)
|
1998-05-22 13:09:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum wxODStatus
|
|
|
|
{
|
|
|
|
wxODSelected = 0x0001, // control is currently selected
|
|
|
|
wxODGrayed = 0x0002, // item is to be grayed
|
|
|
|
wxODDisabled = 0x0004, // item is to be drawn as disabled
|
|
|
|
wxODChecked = 0x0008, // item is to be checked
|
|
|
|
wxODHasFocus = 0x0010, // item has the keyboard focus
|
2005-02-19 12:25:37 -05:00
|
|
|
wxODDefault = 0x0020, // item is the default item
|
|
|
|
wxODHidePrefix= 0x0100 // hide keyboard cues (w2k and xp only)
|
1998-05-22 13:09:19 -04:00
|
|
|
};
|
|
|
|
|
2004-09-20 07:31:49 -04:00
|
|
|
// virtual functions to implement drawing (return true if processed)
|
1998-08-18 11:36:12 -04:00
|
|
|
virtual bool OnMeasureItem(size_t *pwidth, size_t *pheight);
|
1998-05-22 13:09:19 -04:00
|
|
|
virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat);
|
|
|
|
|
|
|
|
protected:
|
2005-06-07 14:28:48 -04:00
|
|
|
// return true if this is a menu item
|
|
|
|
bool IsMenuItem() const;
|
|
|
|
|
|
|
|
// get the font to use, whether m_font is set or not
|
|
|
|
wxFont GetFontToUse() const;
|
|
|
|
|
|
|
|
|
2001-05-21 19:58:58 -04:00
|
|
|
wxString m_strName, // label for a manu item
|
|
|
|
m_strAccel; // the accel string ("Ctrl-F17") if any
|
1998-05-22 13:09:19 -04:00
|
|
|
|
|
|
|
private:
|
1998-08-18 11:36:12 -04:00
|
|
|
static size_t ms_nDefaultMarginWidth; // menu check mark width
|
|
|
|
static size_t ms_nLastMarginWidth; // handy for aligning all items
|
1998-05-22 13:09:19 -04:00
|
|
|
|
|
|
|
bool m_bCheckable, // used only for menu or check listbox items
|
2005-09-25 16:43:35 -04:00
|
|
|
m_bOwnerDrawn, // true if something is non standard
|
|
|
|
m_isMenuItem; // true if this is a menu item
|
1998-05-22 13:09:19 -04:00
|
|
|
|
|
|
|
wxFont m_font; // font to use for drawing
|
1999-10-25 11:51:37 -04:00
|
|
|
wxColour m_colText, // color ----"---"---"----
|
1998-05-22 13:09:19 -04:00
|
|
|
m_colBack; // background color
|
|
|
|
wxBitmap m_bmpChecked, // bitmap to put near the item
|
2003-09-21 20:43:36 -04:00
|
|
|
m_bmpUnchecked, // (checked is used also for 'uncheckable' items)
|
|
|
|
m_bmpDisabled;
|
1998-05-22 13:09:19 -04:00
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
size_t m_nHeight, // font height
|
1998-05-22 13:09:19 -04:00
|
|
|
m_nMarginWidth; // space occupied by bitmap to the left of the item
|
|
|
|
};
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
#endif // wxUSE_OWNER_DRAWN
|
|
|
|
|
1998-12-18 18:18:59 -05:00
|
|
|
#endif
|
|
|
|
// _OWNERDRW_H
|