2005-10-19 08:52:47 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-02 07:18:35 -04:00
|
|
|
// Name: wx/richtext/richtextstyles.h
|
2005-10-19 08:52:47 -04:00
|
|
|
// Purpose: Style management for wxRichTextCtrl
|
|
|
|
// Author: Julian Smart
|
2006-09-12 06:19:45 -04:00
|
|
|
// Modified by:
|
2005-10-19 08:52:47 -04:00
|
|
|
// Created: 2005-09-30
|
2006-10-20 03:48:31 -04:00
|
|
|
// RCS-ID: $Id$
|
2005-10-19 08:52:47 -04:00
|
|
|
// Copyright: (c) Julian Smart
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_RICHTEXTSTYLES_H_
|
|
|
|
#define _WX_RICHTEXTSTYLES_H_
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Includes
|
|
|
|
*/
|
|
|
|
|
2006-10-02 07:18:35 -04:00
|
|
|
#include "wx/defs.h"
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
#if wxUSE_RICHTEXT
|
|
|
|
|
2006-10-02 07:18:35 -04:00
|
|
|
#include "wx/richtext/richtextbuffer.h"
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
#if wxUSE_HTML
|
|
|
|
#include "wx/htmllbox.h"
|
|
|
|
#endif
|
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
#if wxUSE_COMBOCTRL
|
|
|
|
#include "wx/combo.h"
|
|
|
|
#endif
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
#include "wx/choice.h"
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/*!
|
|
|
|
* Forward declarations
|
|
|
|
*/
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl;
|
|
|
|
class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxRichTextStyleDefinition class declaration
|
|
|
|
* A base class for paragraph and character styles.
|
|
|
|
*/
|
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition: public wxObject
|
2005-10-19 08:52:47 -04:00
|
|
|
{
|
|
|
|
DECLARE_CLASS(wxRichTextStyleDefinition)
|
|
|
|
public:
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Copy constructors
|
2006-10-02 07:18:35 -04:00
|
|
|
wxRichTextStyleDefinition(const wxRichTextStyleDefinition& def)
|
|
|
|
: wxObject()
|
|
|
|
{
|
2006-10-17 10:09:14 -04:00
|
|
|
Init();
|
2006-10-02 07:18:35 -04:00
|
|
|
Copy(def);
|
|
|
|
}
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Default constructor
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextStyleDefinition(const wxString& name = wxEmptyString) { Init(); m_name = name; }
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Destructor
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxRichTextStyleDefinition() {}
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Initialises members
|
2005-10-19 08:52:47 -04:00
|
|
|
void Init() {}
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Copies from def
|
2006-09-29 04:53:23 -04:00
|
|
|
void Copy(const wxRichTextStyleDefinition& def);
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Equality test
|
2006-09-29 04:53:23 -04:00
|
|
|
bool Eq(const wxRichTextStyleDefinition& def) const;
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Assignment operator
|
2006-09-29 04:53:23 -04:00
|
|
|
void operator =(const wxRichTextStyleDefinition& def) { Copy(def); }
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Equality operator
|
2006-09-29 04:53:23 -04:00
|
|
|
bool operator ==(const wxRichTextStyleDefinition& def) const { return Eq(def); }
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Override to clone the object
|
2006-10-08 10:02:28 -04:00
|
|
|
virtual wxRichTextStyleDefinition* Clone() const = 0;
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Sets and gets the name of the style
|
2005-10-19 08:52:47 -04:00
|
|
|
void SetName(const wxString& name) { m_name = name; }
|
|
|
|
const wxString& GetName() const { return m_name; }
|
|
|
|
|
2006-11-08 09:05:50 -05:00
|
|
|
/// Sets and gets the style description
|
|
|
|
void SetDescription(const wxString& descr) { m_description = descr; }
|
|
|
|
const wxString& GetDescription() const { return m_description; }
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Sets and gets the name of the style that this style is based on
|
2005-10-19 08:52:47 -04:00
|
|
|
void SetBaseStyle(const wxString& name) { m_baseStyle = name; }
|
|
|
|
const wxString& GetBaseStyle() const { return m_baseStyle; }
|
|
|
|
|
2006-07-24 14:20:18 -04:00
|
|
|
/// Sets and gets the style
|
2005-10-19 08:52:47 -04:00
|
|
|
void SetStyle(const wxRichTextAttr& style) { m_style = style; }
|
|
|
|
const wxRichTextAttr& GetStyle() const { return m_style; }
|
|
|
|
wxRichTextAttr& GetStyle() { return m_style; }
|
|
|
|
|
2006-07-24 14:20:18 -04:00
|
|
|
/// Gets the style combined with the base style
|
|
|
|
virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const;
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
protected:
|
|
|
|
wxString m_name;
|
|
|
|
wxString m_baseStyle;
|
2006-11-08 09:05:50 -05:00
|
|
|
wxString m_description;
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextAttr m_style;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxRichTextCharacterStyleDefinition class declaration
|
|
|
|
*/
|
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition
|
2005-10-19 08:52:47 -04:00
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition)
|
|
|
|
public:
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Copy constructor
|
2006-09-29 04:53:23 -04:00
|
|
|
wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {}
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Default constructor
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString):
|
|
|
|
wxRichTextStyleDefinition(name) {}
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Destructor
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxRichTextCharacterStyleDefinition() {}
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Clones the object
|
2006-10-08 10:02:28 -04:00
|
|
|
virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); }
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxRichTextParagraphStyleDefinition class declaration
|
|
|
|
*/
|
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition
|
2005-10-19 08:52:47 -04:00
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition)
|
|
|
|
public:
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Copy constructor
|
2006-09-29 04:53:23 -04:00
|
|
|
wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; }
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Default constructor
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString):
|
|
|
|
wxRichTextStyleDefinition(name) {}
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
// Destructor
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxRichTextParagraphStyleDefinition() {}
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Sets and gets the next style
|
2005-10-19 08:52:47 -04:00
|
|
|
void SetNextStyle(const wxString& name) { m_nextStyle = name; }
|
|
|
|
const wxString& GetNextStyle() const { return m_nextStyle; }
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Copies from def
|
2006-09-29 04:53:23 -04:00
|
|
|
void Copy(const wxRichTextParagraphStyleDefinition& def);
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Assignment operator
|
2006-09-29 04:53:23 -04:00
|
|
|
void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); }
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Equality operator
|
2006-09-29 04:53:23 -04:00
|
|
|
bool operator ==(const wxRichTextParagraphStyleDefinition& def) const;
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Clones the object
|
2006-10-08 10:02:28 -04:00
|
|
|
virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); }
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/// The next style to use when adding a paragraph after this style.
|
|
|
|
wxString m_nextStyle;
|
|
|
|
};
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/*!
|
|
|
|
* wxRichTextListStyleDefinition class declaration
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition: public wxRichTextParagraphStyleDefinition
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxRichTextListStyleDefinition)
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Copy constructor
|
|
|
|
wxRichTextListStyleDefinition(const wxRichTextListStyleDefinition& def): wxRichTextParagraphStyleDefinition(def) { Init(); Copy(def); }
|
|
|
|
|
|
|
|
/// Default constructor
|
|
|
|
wxRichTextListStyleDefinition(const wxString& name = wxEmptyString):
|
|
|
|
wxRichTextParagraphStyleDefinition(name) { Init(); }
|
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
virtual ~wxRichTextListStyleDefinition() {}
|
|
|
|
|
|
|
|
/// Copies from def
|
|
|
|
void Copy(const wxRichTextListStyleDefinition& def);
|
|
|
|
|
|
|
|
/// Assignment operator
|
|
|
|
void operator =(const wxRichTextListStyleDefinition& def) { Copy(def); }
|
|
|
|
|
|
|
|
/// Equality operator
|
|
|
|
bool operator ==(const wxRichTextListStyleDefinition& def) const;
|
|
|
|
|
|
|
|
/// Clones the object
|
|
|
|
virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextListStyleDefinition(*this); }
|
|
|
|
|
|
|
|
/// Sets/gets the attributes for the given level
|
2006-10-26 02:32:47 -04:00
|
|
|
void SetLevelAttributes(int i, const wxRichTextAttr& attr);
|
|
|
|
wxRichTextAttr* GetLevelAttributes(int i);
|
|
|
|
const wxRichTextAttr* GetLevelAttributes(int i) const;
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Convenience function for setting the major attributes for a list level specification
|
|
|
|
void SetAttributes(int i, int leftIndent, int leftSubIndent, int bulletStyle, const wxString& bulletSymbol = wxEmptyString);
|
|
|
|
|
|
|
|
/// Finds the level corresponding to the given indentation
|
|
|
|
int FindLevelForIndent(int indent) const;
|
|
|
|
|
|
|
|
/// Combine the base and list style with a paragraph style, using the given indent (from which
|
|
|
|
/// an appropriate level is found)
|
2006-07-24 14:20:18 -04:00
|
|
|
wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet = NULL);
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Combine the base and list style, using the given indent (from which
|
|
|
|
/// an appropriate level is found)
|
2006-07-24 14:20:18 -04:00
|
|
|
wxRichTextAttr GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet = NULL);
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Combine the base and list style, using the given level from which
|
|
|
|
/// an appropriate level is found)
|
2006-07-24 14:20:18 -04:00
|
|
|
wxRichTextAttr GetCombinedStyleForLevel(int level, wxRichTextStyleSheet* styleSheet = NULL);
|
2006-10-17 10:09:14 -04:00
|
|
|
|
|
|
|
/// Gets the number of available levels
|
|
|
|
int GetLevelCount() const { return 10; }
|
|
|
|
|
|
|
|
/// Is this a numbered list?
|
|
|
|
bool IsNumbered(int i) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/// The styles for each level (up to 10)
|
2006-10-26 02:32:47 -04:00
|
|
|
wxRichTextAttr m_levelStyles[10];
|
2006-10-17 10:09:14 -04:00
|
|
|
};
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/*!
|
|
|
|
* The style sheet
|
|
|
|
*/
|
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet: public wxObject
|
2005-10-19 08:52:47 -04:00
|
|
|
{
|
|
|
|
DECLARE_CLASS( wxRichTextStyleSheet )
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Constructors
|
2006-10-02 07:18:35 -04:00
|
|
|
wxRichTextStyleSheet(const wxRichTextStyleSheet& sheet)
|
|
|
|
: wxObject()
|
|
|
|
{
|
2007-06-07 16:28:50 -04:00
|
|
|
Init();
|
2006-10-02 07:18:35 -04:00
|
|
|
Copy(sheet);
|
|
|
|
}
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextStyleSheet() { Init(); }
|
2006-10-17 10:09:14 -04:00
|
|
|
virtual ~wxRichTextStyleSheet();
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
/// Initialisation
|
|
|
|
void Init();
|
|
|
|
|
2006-09-29 04:53:23 -04:00
|
|
|
/// Copy
|
|
|
|
void Copy(const wxRichTextStyleSheet& sheet);
|
|
|
|
|
|
|
|
/// Assignment
|
|
|
|
void operator=(const wxRichTextStyleSheet& sheet) { Copy(sheet); }
|
|
|
|
|
|
|
|
/// Equality
|
|
|
|
bool operator==(const wxRichTextStyleSheet& sheet) const;
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Add a definition to the character style list
|
2006-09-29 04:53:23 -04:00
|
|
|
bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def);
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
/// Add a definition to the paragraph style list
|
2006-09-29 04:53:23 -04:00
|
|
|
bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def);
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Add a definition to the list style list
|
|
|
|
bool AddListStyle(wxRichTextListStyleDefinition* def);
|
|
|
|
|
2006-07-24 14:20:18 -04:00
|
|
|
/// Add a definition to the appropriate style list
|
|
|
|
bool AddStyle(wxRichTextStyleDefinition* def);
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Remove a character style
|
|
|
|
bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); }
|
|
|
|
|
|
|
|
/// Remove a paragraph style
|
2006-09-29 04:53:23 -04:00
|
|
|
bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); }
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Remove a list style
|
|
|
|
bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); }
|
|
|
|
|
2006-07-24 14:20:18 -04:00
|
|
|
/// Remove a style
|
|
|
|
bool RemoveStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false);
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Find a character definition by name
|
2006-10-17 10:09:14 -04:00
|
|
|
wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); }
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
/// Find a paragraph definition by name
|
2006-10-17 10:09:14 -04:00
|
|
|
wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); }
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Find a list definition by name
|
|
|
|
wxRichTextListStyleDefinition* FindListStyle(const wxString& name, bool recurse = true) const { return (wxRichTextListStyleDefinition*) FindStyle(m_listStyleDefinitions, name, recurse); }
|
|
|
|
|
2006-07-24 14:20:18 -04:00
|
|
|
/// Find any definition by name
|
|
|
|
wxRichTextStyleDefinition* FindStyle(const wxString& name, bool recurse = true) const;
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Return the number of character styles
|
2005-10-19 08:52:47 -04:00
|
|
|
size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); }
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Return the number of paragraph styles
|
2005-10-19 08:52:47 -04:00
|
|
|
size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); }
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Return the number of list styles
|
|
|
|
size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); }
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Return the nth character style
|
|
|
|
wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const { return (wxRichTextCharacterStyleDefinition*) m_characterStyleDefinitions.Item(n)->GetData(); }
|
|
|
|
|
|
|
|
/// Return the nth paragraph style
|
|
|
|
wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const { return (wxRichTextParagraphStyleDefinition*) m_paragraphStyleDefinitions.Item(n)->GetData(); }
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Return the nth list style
|
|
|
|
wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); }
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Delete all styles
|
|
|
|
void DeleteStyles();
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Insert into list of style sheets
|
|
|
|
bool InsertSheet(wxRichTextStyleSheet* before);
|
|
|
|
|
|
|
|
/// Append to list of style sheets
|
|
|
|
bool AppendSheet(wxRichTextStyleSheet* after);
|
|
|
|
|
|
|
|
/// Unlink from the list of style sheets
|
|
|
|
void Unlink();
|
|
|
|
|
|
|
|
/// Get/set next sheet
|
|
|
|
wxRichTextStyleSheet* GetNextSheet() const { return m_nextSheet; }
|
|
|
|
void SetNextSheet(wxRichTextStyleSheet* sheet) { m_nextSheet = sheet; }
|
|
|
|
|
|
|
|
/// Get/set previous sheet
|
|
|
|
wxRichTextStyleSheet* GetPreviousSheet() const { return m_previousSheet; }
|
|
|
|
void SetPreviousSheet(wxRichTextStyleSheet* sheet) { m_previousSheet = sheet; }
|
|
|
|
|
2006-11-08 09:05:50 -05:00
|
|
|
/// Sets and gets the name of the style sheet
|
|
|
|
void SetName(const wxString& name) { m_name = name; }
|
|
|
|
const wxString& GetName() const { return m_name; }
|
|
|
|
|
|
|
|
/// Sets and gets the style description
|
|
|
|
void SetDescription(const wxString& descr) { m_description = descr; }
|
|
|
|
const wxString& GetDescription() const { return m_description; }
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Implementation
|
|
|
|
|
|
|
|
/// Add a definition to one of the style lists
|
|
|
|
bool AddStyle(wxList& list, wxRichTextStyleDefinition* def);
|
|
|
|
|
|
|
|
/// Remove a style
|
|
|
|
bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle);
|
|
|
|
|
|
|
|
/// Find a definition by name
|
2006-10-17 10:09:14 -04:00
|
|
|
wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const;
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2006-11-08 09:05:50 -05:00
|
|
|
wxString m_description;
|
|
|
|
wxString m_name;
|
|
|
|
|
|
|
|
wxList m_characterStyleDefinitions;
|
|
|
|
wxList m_paragraphStyleDefinitions;
|
|
|
|
wxList m_listStyleDefinitions;
|
2006-10-17 10:09:14 -04:00
|
|
|
|
2006-11-08 09:05:50 -05:00
|
|
|
wxRichTextStyleSheet* m_previousSheet;
|
|
|
|
wxRichTextStyleSheet* m_nextSheet;
|
2005-10-19 08:52:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#if wxUSE_HTML
|
|
|
|
/*!
|
|
|
|
* wxRichTextStyleListBox class declaration
|
|
|
|
* A listbox to display styles.
|
|
|
|
*/
|
|
|
|
|
2006-06-29 03:16:39 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox
|
2005-10-19 08:52:47 -04:00
|
|
|
{
|
|
|
|
DECLARE_CLASS(wxRichTextStyleListBox)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
|
|
|
public:
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Which type of style definition is currently showing?
|
|
|
|
enum wxRichTextStyleType
|
|
|
|
{
|
|
|
|
wxRICHTEXT_STYLE_ALL,
|
|
|
|
wxRICHTEXT_STYLE_PARAGRAPH,
|
|
|
|
wxRICHTEXT_STYLE_CHARACTER,
|
|
|
|
wxRICHTEXT_STYLE_LIST
|
|
|
|
};
|
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
wxRichTextStyleListBox()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0);
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxRichTextStyleListBox();
|
2005-10-19 08:52:47 -04:00
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_styleSheet = NULL;
|
|
|
|
m_richTextCtrl = NULL;
|
2006-10-17 10:09:14 -04:00
|
|
|
m_applyOnSelection = false;
|
|
|
|
m_styleType = wxRICHTEXT_STYLE_PARAGRAPH;
|
2006-10-19 10:04:13 -04:00
|
|
|
m_autoSetSelection = true;
|
2006-09-12 06:19:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0);
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Creates a suitable HTML fragment for a definition
|
|
|
|
wxString CreateHTML(wxRichTextStyleDefinition* def) const;
|
|
|
|
|
2006-11-09 15:22:33 -05:00
|
|
|
/// Associates the control with a style sheet
|
2005-10-19 08:52:47 -04:00
|
|
|
void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
|
|
|
|
wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
|
|
|
|
|
|
|
|
/// Associates the control with a wxRichTextCtrl
|
|
|
|
void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; }
|
|
|
|
wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; }
|
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
/// Get style for index
|
2005-10-19 08:52:47 -04:00
|
|
|
wxRichTextStyleDefinition* GetStyle(size_t i) const ;
|
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
/// Get index for style name
|
|
|
|
int GetIndexForStyle(const wxString& name) const ;
|
|
|
|
|
|
|
|
/// Set selection for string, returning the index.
|
|
|
|
int SetStyleSelection(const wxString& name);
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Updates the list
|
|
|
|
void UpdateStyles();
|
|
|
|
|
2006-10-08 10:02:28 -04:00
|
|
|
/// Apply the style
|
|
|
|
void ApplyStyle(int i);
|
2006-09-12 06:19:45 -04:00
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
/// Left click
|
|
|
|
void OnLeftDown(wxMouseEvent& event);
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Left double-click
|
|
|
|
void OnLeftDoubleClick(wxMouseEvent& event);
|
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
/// Auto-select from style under caret in idle time
|
|
|
|
void OnIdle(wxIdleEvent& event);
|
|
|
|
|
|
|
|
/// Convert units in tends of a millimetre to device units
|
2005-10-19 08:52:47 -04:00
|
|
|
int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
|
|
|
|
|
2006-09-12 06:19:45 -04:00
|
|
|
/// Can we set the selection based on the editor caret position?
|
|
|
|
/// Need to override this if being used in a combobox popup
|
2006-10-19 10:04:13 -04:00
|
|
|
virtual bool CanAutoSetSelection() { return m_autoSetSelection; }
|
|
|
|
virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; }
|
2006-09-12 06:19:45 -04:00
|
|
|
|
2006-10-08 10:02:28 -04:00
|
|
|
/// Set whether the style should be applied as soon as the item is selected (the default)
|
|
|
|
void SetApplyOnSelection(bool applyOnSel) { m_applyOnSelection = applyOnSel; }
|
|
|
|
bool GetApplyOnSelection() const { return m_applyOnSelection; }
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
/// Set the style type to display
|
|
|
|
void SetStyleType(wxRichTextStyleType styleType) { m_styleType = styleType; UpdateStyles(); }
|
|
|
|
wxRichTextStyleType GetStyleType() const { return m_styleType; }
|
|
|
|
|
|
|
|
/// Helper for listbox and combo control
|
|
|
|
static wxString GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType);
|
|
|
|
|
2006-02-08 16:47:09 -05:00
|
|
|
protected:
|
|
|
|
/// Returns the HTML for this item
|
|
|
|
virtual wxString OnGetItem(size_t n) const;
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
wxRichTextStyleSheet* m_styleSheet;
|
|
|
|
wxRichTextCtrl* m_richTextCtrl;
|
2006-10-08 10:02:28 -04:00
|
|
|
bool m_applyOnSelection; // if true, applies style on selection
|
2006-10-17 10:09:14 -04:00
|
|
|
wxRichTextStyleType m_styleType; // style type to display
|
2006-10-19 10:04:13 -04:00
|
|
|
bool m_autoSetSelection;
|
2006-11-26 07:47:53 -05:00
|
|
|
wxArrayString m_styleNames;
|
2006-10-17 10:09:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxRichTextStyleListCtrl class declaration
|
|
|
|
* This is a container for the list control plus a combobox to switch between
|
|
|
|
* style types.
|
|
|
|
*/
|
|
|
|
|
2006-10-19 10:04:13 -04:00
|
|
|
#define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000
|
|
|
|
|
2006-10-17 10:09:14 -04:00
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListCtrl: public wxControl
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(wxRichTextStyleListCtrl)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Constructors
|
|
|
|
wxRichTextStyleListCtrl()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0);
|
|
|
|
|
|
|
|
/// Constructors
|
|
|
|
virtual ~wxRichTextStyleListCtrl();
|
|
|
|
|
|
|
|
/// Member initialisation
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_styleListBox = NULL;
|
|
|
|
m_styleChoice = NULL;
|
|
|
|
m_dontUpdate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates the windows
|
|
|
|
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0);
|
|
|
|
|
2006-10-19 10:04:13 -04:00
|
|
|
/// Updates the style list box
|
|
|
|
void UpdateStyles();
|
|
|
|
|
2006-11-09 15:22:33 -05:00
|
|
|
/// Associates the control with a style sheet
|
2006-10-17 10:09:14 -04:00
|
|
|
void SetStyleSheet(wxRichTextStyleSheet* styleSheet);
|
|
|
|
wxRichTextStyleSheet* GetStyleSheet() const;
|
|
|
|
|
|
|
|
/// Associates the control with a wxRichTextCtrl
|
|
|
|
void SetRichTextCtrl(wxRichTextCtrl* ctrl);
|
|
|
|
wxRichTextCtrl* GetRichTextCtrl() const;
|
|
|
|
|
|
|
|
/// Set/get the style type to display
|
|
|
|
void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType);
|
|
|
|
wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const;
|
|
|
|
|
|
|
|
/// Get the choice index for style type
|
|
|
|
int StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType);
|
|
|
|
|
|
|
|
/// Get the style type for choice index
|
|
|
|
wxRichTextStyleListBox::wxRichTextStyleType StyleIndexToType(int i);
|
|
|
|
|
|
|
|
/// Get the listbox
|
|
|
|
wxRichTextStyleListBox* GetStyleListBox() const { return m_styleListBox; }
|
|
|
|
|
|
|
|
/// Get the choice
|
|
|
|
wxChoice* GetStyleChoice() const { return m_styleChoice; }
|
|
|
|
|
|
|
|
/// React to style type choice
|
|
|
|
void OnChooseType(wxCommandEvent& event);
|
|
|
|
|
|
|
|
/// Lay out the controls
|
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
wxRichTextStyleListBox* m_styleListBox;
|
|
|
|
wxChoice* m_styleChoice;
|
|
|
|
bool m_dontUpdate;
|
2005-10-19 08:52:47 -04:00
|
|
|
};
|
2006-09-12 06:19:45 -04:00
|
|
|
|
|
|
|
#if wxUSE_COMBOCTRL
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Style drop-down for a wxComboCtrl
|
|
|
|
*/
|
|
|
|
|
|
|
|
class wxRichTextStyleComboPopup : public wxRichTextStyleListBox, public wxComboPopup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Init()
|
|
|
|
{
|
|
|
|
m_itemHere = -1; // hot item in list
|
|
|
|
m_value = -1;
|
|
|
|
}
|
|
|
|
|
2007-08-07 15:22:43 -04:00
|
|
|
virtual bool Create( wxWindow* parent );
|
2006-09-12 06:19:45 -04:00
|
|
|
|
|
|
|
virtual wxWindow *GetControl() { return this; }
|
|
|
|
|
|
|
|
virtual void SetStringValue( const wxString& s );
|
|
|
|
|
|
|
|
virtual wxString GetStringValue() const;
|
|
|
|
|
|
|
|
/// Can we set the selection based on the editor caret position?
|
|
|
|
// virtual bool CanAutoSetSelection() { return ((m_combo == NULL) || !m_combo->IsPopupShown()); }
|
|
|
|
virtual bool CanAutoSetSelection() { return false; }
|
|
|
|
|
|
|
|
//
|
|
|
|
// Popup event handlers
|
|
|
|
//
|
|
|
|
|
|
|
|
// Mouse hot-tracking
|
|
|
|
void OnMouseMove(wxMouseEvent& event);
|
|
|
|
|
|
|
|
// On mouse left, set the value and close the popup
|
|
|
|
void OnMouseClick(wxMouseEvent& WXUNUSED(event));
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int m_itemHere; // hot item in popup
|
|
|
|
int m_value;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* wxRichTextStyleComboCtrl
|
|
|
|
* A combo for applying styles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleComboCtrl: public wxComboCtrl
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(wxRichTextStyleComboCtrl)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
|
|
|
public:
|
|
|
|
wxRichTextStyleComboCtrl()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxRichTextStyleComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = wxCB_READONLY)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
Create(parent, id, pos, size, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~wxRichTextStyleComboCtrl() {}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_stylePopup = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0);
|
|
|
|
|
|
|
|
/// Updates the list
|
|
|
|
void UpdateStyles() { m_stylePopup->UpdateStyles(); }
|
|
|
|
|
2006-11-09 15:22:33 -05:00
|
|
|
/// Associates the control with a style sheet
|
2006-09-12 06:19:45 -04:00
|
|
|
void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_stylePopup->SetStyleSheet(styleSheet); }
|
|
|
|
wxRichTextStyleSheet* GetStyleSheet() const { return m_stylePopup->GetStyleSheet(); }
|
|
|
|
|
|
|
|
/// Associates the control with a wxRichTextCtrl
|
|
|
|
void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_stylePopup->SetRichTextCtrl(ctrl); }
|
|
|
|
wxRichTextCtrl* GetRichTextCtrl() const { return m_stylePopup->GetRichTextCtrl(); }
|
|
|
|
|
|
|
|
/// Gets the style popup
|
|
|
|
wxRichTextStyleComboPopup* GetStylePopup() const { return m_stylePopup; }
|
|
|
|
|
|
|
|
/// Auto-select from style under caret in idle time
|
|
|
|
void OnIdle(wxIdleEvent& event);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxRichTextStyleComboPopup* m_stylePopup;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// wxUSE_COMBOCTRL
|
|
|
|
|
2005-10-19 08:52:47 -04:00
|
|
|
#endif
|
2006-09-12 06:19:45 -04:00
|
|
|
// wxUSE_HTML
|
2005-10-19 08:52:47 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
// wxUSE_RICHTEXT
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// _WX_RICHTEXTSTYLES_H_
|