1999-07-26 19:02:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/control.h
|
|
|
|
// Purpose: wxControl common interface
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 26.07.99
|
|
|
|
// RCS-ID: $Id$
|
2004-05-23 10:56:36 -04:00
|
|
|
// Copyright: (c) wxWidgets team
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1999-07-26 19:02:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_CONTROL_H_BASE_
|
|
|
|
#define _WX_CONTROL_H_BASE_
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-07-26 19:02:32 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-07-09 17:48:53 -04:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if wxUSE_CONTROLS
|
|
|
|
|
1999-07-26 19:02:32 -04:00
|
|
|
#include "wx/window.h" // base class
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
|
2001-06-26 16:59:19 -04:00
|
|
|
|
2009-02-08 07:56:14 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Ellipsize() constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum wxEllipsizeFlags
|
|
|
|
{
|
2009-10-16 17:32:51 -04:00
|
|
|
wxELLIPSIZE_FLAGS_NONE = 0,
|
|
|
|
wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS = 1,
|
|
|
|
wxELLIPSIZE_FLAGS_EXPAND_TABS = 2,
|
2009-02-08 07:56:14 -05:00
|
|
|
|
2009-10-16 17:32:51 -04:00
|
|
|
wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS |
|
|
|
|
wxELLIPSIZE_FLAGS_EXPAND_TABS
|
2009-02-08 07:56:14 -05:00
|
|
|
};
|
|
|
|
|
2009-10-16 17:35:26 -04:00
|
|
|
// NB: Don't change the order of these values, they're the same as in
|
|
|
|
// PangoEllipsizeMode enum.
|
2008-12-28 16:16:00 -05:00
|
|
|
enum wxEllipsizeMode
|
|
|
|
{
|
2009-10-16 17:35:26 -04:00
|
|
|
wxELLIPSIZE_NONE,
|
2008-12-28 16:16:00 -05:00
|
|
|
wxELLIPSIZE_START,
|
|
|
|
wxELLIPSIZE_MIDDLE,
|
|
|
|
wxELLIPSIZE_END
|
|
|
|
};
|
|
|
|
|
1999-07-26 19:02:32 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxControl is the base class for all controls
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
|
1999-07-26 19:02:32 -04:00
|
|
|
{
|
|
|
|
public:
|
2004-06-21 18:58:13 -04:00
|
|
|
wxControlBase() { }
|
2003-07-21 20:24:07 -04:00
|
|
|
|
2002-01-07 16:52:28 -05:00
|
|
|
virtual ~wxControlBase();
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
// Create() function adds the validator parameter
|
|
|
|
bool Create(wxWindow *parent, wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxControlNameStr);
|
|
|
|
|
|
|
|
// get the control alignment (left/right/centre, top/bottom/centre)
|
|
|
|
int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
|
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// set label with mnemonics
|
2007-04-01 10:13:15 -04:00
|
|
|
virtual void SetLabel(const wxString& label)
|
|
|
|
{
|
|
|
|
m_labelOrig = label;
|
|
|
|
|
|
|
|
InvalidateBestSize();
|
|
|
|
|
|
|
|
wxWindow::SetLabel(label);
|
|
|
|
}
|
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// return the original string, as it was passed to SetLabel()
|
|
|
|
// (i.e. with wx-style mnemonics)
|
|
|
|
virtual wxString GetLabel() const { return m_labelOrig; }
|
2008-12-31 09:14:07 -05:00
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// set label text (mnemonics will be escaped)
|
|
|
|
virtual void SetLabelText(const wxString& text)
|
2008-12-31 09:14:07 -05:00
|
|
|
{
|
2009-01-01 10:17:05 -05:00
|
|
|
SetLabel(EscapeMnemonics(text));
|
2008-12-31 09:14:07 -05:00
|
|
|
}
|
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// get just the text of the label, without mnemonic characters ('&')
|
|
|
|
virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); }
|
|
|
|
|
2011-02-27 07:47:26 -05:00
|
|
|
|
2011-02-27 07:48:07 -05:00
|
|
|
#if wxUSE_MARKUP
|
2011-02-27 07:47:26 -05:00
|
|
|
// Set the label with markup (and mnemonics). Markup is a simple subset of
|
|
|
|
// HTML with tags such as <b>, <i> and <span>. By default it is not
|
|
|
|
// supported i.e. all the markup is simply stripped and SetLabel() is
|
|
|
|
// called but some controls in some ports do support this already and in
|
|
|
|
// the future most of them should.
|
|
|
|
//
|
|
|
|
// Notice that, being HTML-like, markup also supports XML entities so '<'
|
|
|
|
// should be encoded as "<" and so on, a bare '<' in the input will
|
|
|
|
// likely result in an error. As an exception, a bare '&' is allowed and
|
|
|
|
// indicates that the next character is a mnemonic. To insert a literal '&'
|
|
|
|
// in the control you need to use "&" in the input string.
|
|
|
|
//
|
|
|
|
// Returns true if the label was set, even if the markup in it was ignored.
|
|
|
|
// False is only returned if we failed to parse the label.
|
|
|
|
bool SetLabelMarkup(const wxString& markup)
|
|
|
|
{
|
|
|
|
return DoSetLabelMarkup(markup);
|
|
|
|
}
|
2011-02-27 07:48:07 -05:00
|
|
|
#endif // wxUSE_MARKUP
|
2011-02-27 07:47:26 -05:00
|
|
|
|
|
|
|
|
2003-10-16 06:00:12 -04:00
|
|
|
// controls by default inherit the colours of their parents, if a
|
|
|
|
// particular control class doesn't want to do it, it can override
|
|
|
|
// ShouldInheritColours() to return false
|
|
|
|
virtual bool ShouldInheritColours() const { return true; }
|
|
|
|
|
2004-03-31 19:19:39 -05:00
|
|
|
|
|
|
|
// WARNING: this doesn't work for all controls nor all platforms!
|
|
|
|
//
|
|
|
|
// simulates the event of given type (i.e. wxButton::Command() is just as
|
|
|
|
// if the button was clicked)
|
|
|
|
virtual void Command(wxCommandEvent &event);
|
|
|
|
|
2004-06-24 16:09:45 -04:00
|
|
|
virtual bool SetFont(const wxFont& font);
|
|
|
|
|
2006-02-12 11:32:50 -05:00
|
|
|
// wxControl-specific processing after processing the update event
|
|
|
|
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
|
|
|
|
|
2009-02-08 07:56:14 -05:00
|
|
|
|
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// static utilities for mnemonics char (&) handling
|
|
|
|
// ------------------------------------------------
|
2009-02-08 07:56:14 -05:00
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// returns the given string without mnemonic characters ('&')
|
2009-02-08 07:56:14 -05:00
|
|
|
static wxString GetLabelText(const wxString& label);
|
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
// returns the given string without mnemonic characters ('&')
|
|
|
|
// this function is identic to GetLabelText() and is provided for clarity
|
|
|
|
// and for symmetry with the wxStaticText::RemoveMarkup() function.
|
2009-02-08 07:56:14 -05:00
|
|
|
static wxString RemoveMnemonics(const wxString& str);
|
|
|
|
|
|
|
|
// escapes (by doubling them) the mnemonics
|
|
|
|
static wxString EscapeMnemonics(const wxString& str);
|
|
|
|
|
2010-03-21 17:39:15 -04:00
|
|
|
|
|
|
|
// miscellaneous static utilities
|
|
|
|
// ------------------------------
|
|
|
|
|
|
|
|
// replaces parts of the given (multiline) string with an ellipsis if needed
|
|
|
|
static wxString Ellipsize(const wxString& label, const wxDC& dc,
|
|
|
|
wxEllipsizeMode mode, int maxWidth,
|
|
|
|
int flags = wxELLIPSIZE_FLAGS_DEFAULT);
|
|
|
|
|
2009-02-08 07:56:14 -05:00
|
|
|
// return the accel index in the string or -1 if none and puts the modified
|
|
|
|
// string into second parameter if non NULL
|
|
|
|
static int FindAccelIndex(const wxString& label,
|
|
|
|
wxString *labelOnly = NULL);
|
|
|
|
|
2009-09-26 12:43:06 -04:00
|
|
|
// this is a helper for the derived class GetClassDefaultAttributes()
|
|
|
|
// implementation: it returns the right colours for the classes which
|
|
|
|
// contain something else (e.g. wxListBox, wxTextCtrl, ...) instead of
|
|
|
|
// being simple controls (such as wxButton, wxCheckBox, ...)
|
|
|
|
static wxVisualAttributes
|
|
|
|
GetCompositeControlsDefaultAttributes(wxWindowVariant variant);
|
|
|
|
|
1999-07-26 19:02:32 -04:00
|
|
|
protected:
|
2007-11-13 07:10:34 -05:00
|
|
|
// choose the default border for this window
|
|
|
|
virtual wxBorder GetDefaultBorder() const;
|
|
|
|
|
1999-11-10 19:25:57 -05:00
|
|
|
// creates the control (calls wxWindowBase::CreateBase inside) and adds it
|
|
|
|
// to the list of parents children
|
1999-07-26 19:02:32 -04:00
|
|
|
bool CreateControl(wxWindowBase *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxValidator& validator,
|
|
|
|
const wxString& name);
|
|
|
|
|
2011-02-27 07:48:07 -05:00
|
|
|
#if wxUSE_MARKUP
|
2011-02-27 07:47:26 -05:00
|
|
|
// This function may be overridden in the derived classes to implement
|
|
|
|
// support for labels with markup. The base class version simply strips the
|
|
|
|
// markup and calls SetLabel() with the remaining text.
|
|
|
|
virtual bool DoSetLabelMarkup(const wxString& markup);
|
2011-02-27 07:48:07 -05:00
|
|
|
#endif // wxUSE_MARKUP
|
2011-02-27 07:47:26 -05:00
|
|
|
|
|
|
|
|
2000-02-25 18:49:41 -05:00
|
|
|
// initialize the common fields of wxCommandEvent
|
|
|
|
void InitCommandEvent(wxCommandEvent& event) const;
|
2003-07-21 20:24:07 -04:00
|
|
|
|
2009-02-08 07:56:14 -05:00
|
|
|
// Ellipsize() helper:
|
|
|
|
static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
|
|
|
|
wxEllipsizeMode mode, int maxWidth,
|
2011-02-09 14:51:47 -05:00
|
|
|
int replacementWidth);
|
2009-02-08 07:56:14 -05:00
|
|
|
|
2011-02-27 07:48:07 -05:00
|
|
|
#if wxUSE_MARKUP
|
2011-02-27 07:47:26 -05:00
|
|
|
// Remove markup from the given string, returns empty string on error i.e.
|
|
|
|
// if markup was syntactically invalid.
|
|
|
|
static wxString RemoveMarkup(const wxString& markup);
|
2011-02-27 07:48:07 -05:00
|
|
|
#endif // wxUSE_MARKUP
|
2011-02-27 07:47:26 -05:00
|
|
|
|
|
|
|
|
2010-03-28 18:23:38 -04:00
|
|
|
// this field contains the label in wx format, i.e. with '&' mnemonics,
|
|
|
|
// as it was passed to the last SetLabel() call
|
2007-04-01 10:13:15 -04:00
|
|
|
wxString m_labelOrig;
|
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxControlBase);
|
1999-07-26 19:02:32 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// include platform-dependent wxControl declarations
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-05-09 18:17:03 -04:00
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/univ/control.h"
|
|
|
|
#elif defined(__WXMSW__)
|
1999-07-26 19:02:32 -04:00
|
|
|
#include "wx/msw/control.h"
|
1998-07-10 10:15:17 -04:00
|
|
|
#elif defined(__WXMOTIF__)
|
1999-07-26 19:02:32 -04:00
|
|
|
#include "wx/motif/control.h"
|
2006-01-22 22:27:34 -05:00
|
|
|
#elif defined(__WXGTK20__)
|
1999-07-26 19:02:32 -04:00
|
|
|
#include "wx/gtk/control.h"
|
2006-01-22 22:27:34 -05:00
|
|
|
#elif defined(__WXGTK__)
|
|
|
|
#include "wx/gtk1/control.h"
|
1998-08-14 20:23:28 -04:00
|
|
|
#elif defined(__WXMAC__)
|
2008-06-11 15:17:41 -04:00
|
|
|
#include "wx/osx/control.h"
|
2003-03-22 01:18:36 -05:00
|
|
|
#elif defined(__WXCOCOA__)
|
|
|
|
#include "wx/cocoa/control.h"
|
1999-07-27 23:38:12 -04:00
|
|
|
#elif defined(__WXPM__)
|
|
|
|
#include "wx/os2/control.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
|
|
|
|
2001-06-26 16:59:19 -04:00
|
|
|
#endif // wxUSE_CONTROLS
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
#endif
|
1998-08-14 20:23:28 -04:00
|
|
|
// _WX_CONTROL_H_BASE_
|