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>
|
|
|
|
// Licence: wxWindows license
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _OWNERDRW_H
|
|
|
|
#define _OWNERDRW_H
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
#if wxUSE_OWNER_DRAWN
|
|
|
|
|
1998-07-03 12:36:10 -04:00
|
|
|
#ifdef __GNUG__
|
1999-10-25 11:51:37 -04:00
|
|
|
#pragma interface "ownerdrw.h"
|
1998-07-03 12:36:10 -04:00
|
|
|
#endif
|
|
|
|
|
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,
|
1998-07-17 16:52:40 -04:00
|
|
|
bool bCheckable = FALSE,
|
1999-04-03 17:25:12 -05:00
|
|
|
bool bMenuItem = FALSE); // FIXME kludge for colors
|
1998-05-22 13:09:19 -04:00
|
|
|
virtual ~wxOwnerDrawn() { }
|
|
|
|
|
|
|
|
// fix appearance
|
1999-04-03 17:25:12 -05:00
|
|
|
void SetFont(const wxFont& font)
|
|
|
|
{ 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)
|
|
|
|
{ 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)
|
|
|
|
{ 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;
|
|
|
|
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;
|
|
|
|
m_bOwnerDrawn = TRUE; }
|
|
|
|
|
1999-04-03 17:25:12 -05:00
|
|
|
const wxBitmap& GetBitmap(bool bChecked = TRUE) const
|
|
|
|
{ return (bChecked ? m_bmpChecked : m_bmpUnchecked); }
|
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 )
|
|
|
|
m_bOwnerDrawn = TRUE;
|
|
|
|
}
|
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; }
|
|
|
|
|
1998-05-22 13:09:19 -04:00
|
|
|
// this function might seem strange, but if it returns FALSE it means that
|
|
|
|
// no non-standard attribute are set, so there is no need for this control
|
|
|
|
// to be owner-drawn. Moreover, you can force owner-drawn to FALSE if you
|
|
|
|
// 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; }
|
|
|
|
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
|
1999-07-29 00:56:34 -04:00
|
|
|
wxODDefault = 0x0020 // item is the default item
|
1998-05-22 13:09:19 -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:
|
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
|
|
|
|
m_bOwnerDrawn; // true if something is non standard
|
|
|
|
|
|
|
|
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
|
|
|
|
m_bmpUnchecked; // (checked is used also for 'uncheckable' items)
|
|
|
|
|
1999-10-25 11:51:37 -04:00
|
|
|
size_t m_nHeight, // font height
|
2002-08-04 15:03:56 -04:00
|
|
|
m_nMinHeight, // minimum height, as determined by user's system settings
|
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
|