1999-07-26 23:02:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/control.h
|
|
|
|
// Purpose: wxControl common interface
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 26.07.99
|
2004-05-23 14:56:36 +00:00
|
|
|
// Copyright: (c) wxWidgets team
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-07-26 23:02:32 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_CONTROL_H_BASE_
|
|
|
|
#define _WX_CONTROL_H_BASE_
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-07-26 23:02:32 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-07-09 21:48:53 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if wxUSE_CONTROLS
|
|
|
|
|
1999-07-26 23:02:32 +00:00
|
|
|
#include "wx/window.h" // base class
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxControlNameStr[];
|
2001-06-26 20:59:19 +00:00
|
|
|
|
2009-02-08 12:56:14 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Ellipsize() constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum wxEllipsizeFlags
|
|
|
|
{
|
2009-10-16 21:32:51 +00:00
|
|
|
wxELLIPSIZE_FLAGS_NONE = 0,
|
|
|
|
wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS = 1,
|
|
|
|
wxELLIPSIZE_FLAGS_EXPAND_TABS = 2,
|
2009-02-08 12:56:14 +00:00
|
|
|
|
2009-10-16 21:32:51 +00:00
|
|
|
wxELLIPSIZE_FLAGS_DEFAULT = wxELLIPSIZE_FLAGS_PROCESS_MNEMONICS |
|
|
|
|
wxELLIPSIZE_FLAGS_EXPAND_TABS
|
2009-02-08 12:56:14 +00:00
|
|
|
};
|
|
|
|
|
2009-10-16 21:35:26 +00:00
|
|
|
// NB: Don't change the order of these values, they're the same as in
|
|
|
|
// PangoEllipsizeMode enum.
|
2008-12-28 21:16:00 +00:00
|
|
|
enum wxEllipsizeMode
|
|
|
|
{
|
2009-10-16 21:35:26 +00:00
|
|
|
wxELLIPSIZE_NONE,
|
2008-12-28 21:16:00 +00:00
|
|
|
wxELLIPSIZE_START,
|
|
|
|
wxELLIPSIZE_MIDDLE,
|
|
|
|
wxELLIPSIZE_END
|
|
|
|
};
|
|
|
|
|
1999-07-26 23:02:32 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxControl is the base class for all controls
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxControlBase : public wxWindow
|
1999-07-26 23:02:32 +00:00
|
|
|
{
|
|
|
|
public:
|
2004-06-21 22:58:13 +00:00
|
|
|
wxControlBase() { }
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2002-01-07 21:52:28 +00:00
|
|
|
virtual ~wxControlBase();
|
|
|
|
|
2001-06-26 20:59:19 +00: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 21:39:15 +00:00
|
|
|
// set label with mnemonics
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void SetLabel(const wxString& label) wxOVERRIDE
|
2007-04-01 14:13:15 +00:00
|
|
|
{
|
|
|
|
m_labelOrig = label;
|
|
|
|
|
|
|
|
InvalidateBestSize();
|
|
|
|
|
|
|
|
wxWindow::SetLabel(label);
|
|
|
|
}
|
|
|
|
|
2010-03-21 21:39:15 +00:00
|
|
|
// return the original string, as it was passed to SetLabel()
|
|
|
|
// (i.e. with wx-style mnemonics)
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxString GetLabel() const wxOVERRIDE { return m_labelOrig; }
|
2008-12-31 14:14:07 +00:00
|
|
|
|
2010-03-21 21:39:15 +00:00
|
|
|
// set label text (mnemonics will be escaped)
|
|
|
|
virtual void SetLabelText(const wxString& text)
|
2008-12-31 14:14:07 +00:00
|
|
|
{
|
2009-01-01 15:17:05 +00:00
|
|
|
SetLabel(EscapeMnemonics(text));
|
2008-12-31 14:14:07 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 21:39:15 +00:00
|
|
|
// get just the text of the label, without mnemonic characters ('&')
|
|
|
|
virtual wxString GetLabelText() const { return GetLabelText(GetLabel()); }
|
|
|
|
|
2011-02-27 12:47:26 +00:00
|
|
|
|
2011-02-27 12:48:07 +00:00
|
|
|
#if wxUSE_MARKUP
|
2011-02-27 12:47:26 +00: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 12:48:07 +00:00
|
|
|
#endif // wxUSE_MARKUP
|
2011-02-27 12:47:26 +00:00
|
|
|
|
|
|
|
|
2003-10-16 10:00:12 +00: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
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool ShouldInheritColours() const wxOVERRIDE { return true; }
|
2003-10-16 10:00:12 +00:00
|
|
|
|
2004-04-01 00:19:39 +00: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);
|
|
|
|
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool SetFont(const wxFont& font) wxOVERRIDE;
|
2004-06-24 20:09:45 +00:00
|
|
|
|
2006-02-12 16:32:50 +00:00
|
|
|
// wxControl-specific processing after processing the update event
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) wxOVERRIDE;
|
2006-02-12 16:32:50 +00:00
|
|
|
|
2012-11-09 21:11:37 +00:00
|
|
|
wxSize GetSizeFromTextSize(int xlen, int ylen = -1) const
|
|
|
|
{ return DoGetSizeFromTextSize(xlen, ylen); }
|
|
|
|
wxSize GetSizeFromTextSize(const wxSize& tsize) const
|
|
|
|
{ return DoGetSizeFromTextSize(tsize.x, tsize.y); }
|
2009-02-08 12:56:14 +00:00
|
|
|
|
|
|
|
|
2010-03-21 21:39:15 +00:00
|
|
|
// static utilities for mnemonics char (&) handling
|
|
|
|
// ------------------------------------------------
|
2009-02-08 12:56:14 +00:00
|
|
|
|
2010-03-21 21:39:15 +00:00
|
|
|
// returns the given string without mnemonic characters ('&')
|
2009-02-08 12:56:14 +00:00
|
|
|
static wxString GetLabelText(const wxString& label);
|
|
|
|
|
2010-03-21 21:39:15 +00: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 12:56:14 +00:00
|
|
|
static wxString RemoveMnemonics(const wxString& str);
|
|
|
|
|
|
|
|
// escapes (by doubling them) the mnemonics
|
|
|
|
static wxString EscapeMnemonics(const wxString& str);
|
|
|
|
|
2010-03-21 21:39:15 +00: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 12:56:14 +00: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 16:43:06 +00: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 23:02:32 +00:00
|
|
|
protected:
|
2007-11-13 12:10:34 +00:00
|
|
|
// choose the default border for this window
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxBorder GetDefaultBorder() const wxOVERRIDE;
|
2007-11-13 12:10:34 +00:00
|
|
|
|
1999-11-11 00:25:57 +00:00
|
|
|
// creates the control (calls wxWindowBase::CreateBase inside) and adds it
|
|
|
|
// to the list of parents children
|
1999-07-26 23:02:32 +00:00
|
|
|
bool CreateControl(wxWindowBase *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxValidator& validator,
|
|
|
|
const wxString& name);
|
|
|
|
|
2011-02-27 12:48:07 +00:00
|
|
|
#if wxUSE_MARKUP
|
2011-02-27 12:47:26 +00: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 12:48:07 +00:00
|
|
|
#endif // wxUSE_MARKUP
|
2011-02-27 12:47:26 +00:00
|
|
|
|
2012-11-09 21:11:37 +00:00
|
|
|
// override this to return the total control's size from a string size
|
|
|
|
virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
|
2011-02-27 12:47:26 +00:00
|
|
|
|
2000-02-25 23:49:41 +00:00
|
|
|
// initialize the common fields of wxCommandEvent
|
|
|
|
void InitCommandEvent(wxCommandEvent& event) const;
|
2003-07-22 00:24:07 +00:00
|
|
|
|
2009-02-08 12:56:14 +00:00
|
|
|
// Ellipsize() helper:
|
|
|
|
static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
|
|
|
|
wxEllipsizeMode mode, int maxWidth,
|
2011-02-09 19:51:47 +00:00
|
|
|
int replacementWidth);
|
2009-02-08 12:56:14 +00:00
|
|
|
|
2011-02-27 12:48:07 +00:00
|
|
|
#if wxUSE_MARKUP
|
2011-02-27 12:47:26 +00: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 12:48:07 +00:00
|
|
|
#endif // wxUSE_MARKUP
|
2011-02-27 12:47:26 +00:00
|
|
|
|
|
|
|
|
2010-03-28 22:23:38 +00: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 14:13:15 +00:00
|
|
|
wxString m_labelOrig;
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxControlBase);
|
1999-07-26 23:02:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// include platform-dependent wxControl declarations
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-05-09 22:17:03 +00:00
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/univ/control.h"
|
|
|
|
#elif defined(__WXMSW__)
|
1999-07-26 23:02:32 +00:00
|
|
|
#include "wx/msw/control.h"
|
1998-07-10 14:15:17 +00:00
|
|
|
#elif defined(__WXMOTIF__)
|
1999-07-26 23:02:32 +00:00
|
|
|
#include "wx/motif/control.h"
|
2006-01-23 03:27:34 +00:00
|
|
|
#elif defined(__WXGTK20__)
|
1999-07-26 23:02:32 +00:00
|
|
|
#include "wx/gtk/control.h"
|
2006-01-23 03:27:34 +00:00
|
|
|
#elif defined(__WXGTK__)
|
|
|
|
#include "wx/gtk1/control.h"
|
1998-08-15 00:23:28 +00:00
|
|
|
#elif defined(__WXMAC__)
|
2008-06-11 19:17:41 +00:00
|
|
|
#include "wx/osx/control.h"
|
2003-03-22 06:18:36 +00:00
|
|
|
#elif defined(__WXCOCOA__)
|
|
|
|
#include "wx/cocoa/control.h"
|
1999-07-28 03:38:12 +00:00
|
|
|
#elif defined(__WXPM__)
|
|
|
|
#include "wx/os2/control.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#endif // wxUSE_CONTROLS
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
1998-08-15 00:23:28 +00:00
|
|
|
// _WX_CONTROL_H_BASE_
|