X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/30bf76303915c3d70e0ff9a180a48a2f80b8cd11..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/richtext/richtextformatdlg.cpp diff --git a/src/richtext/richtextformatdlg.cpp b/src/richtext/richtextformatdlg.cpp index d45b0cae23..bf976d9b4a 100644 --- a/src/richtext/richtextformatdlg.cpp +++ b/src/richtext/richtextformatdlg.cpp @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: // Created: 2006-10-01 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -52,11 +51,19 @@ #include "../../src/richtext/richtextbulletspage.cpp" #include "../../src/richtext/richtextstylepage.cpp" #include "../../src/richtext/richtextliststylepage.cpp" +#include "../../src/richtext/richtextsizepage.cpp" +#include "../../src/richtext/richtextmarginspage.cpp" +#include "../../src/richtext/richtextborderspage.cpp" +#include "../../src/richtext/richtextbackgroundpage.cpp" #else #include "richtextfontpage.cpp" #include "richtextindentspage.cpp" #include "richtexttabspage.cpp" #include "richtextbulletspage.cpp" +#include "richtextmarginspage.cpp" +#include "richtextsizepage.cpp" +#include "richtextborderspage.cpp" +#include "richtextbackgroundpage.cpp" // Digital Mars can't cope with this much code #ifndef __DMC__ #include "richtextliststylepage.cpp" @@ -72,24 +79,30 @@ bool wxRichTextFormattingDialog::sm_showToolTips = false; +IMPLEMENT_CLASS(wxRichTextDialogPage, wxPanel) + IMPLEMENT_CLASS(wxRichTextFormattingDialog, wxPropertySheetDialog) BEGIN_EVENT_TABLE(wxRichTextFormattingDialog, wxPropertySheetDialog) EVT_BOOKCTRL_PAGE_CHANGED(wxID_ANY, wxRichTextFormattingDialog::OnTabChanged) + EVT_BUTTON(wxID_HELP, wxRichTextFormattingDialog::OnHelp) + EVT_UPDATE_UI(wxID_HELP, wxRichTextFormattingDialog::OnUpdateHelp) END_EVENT_TABLE() +IMPLEMENT_HELP_PROVISION(wxRichTextFormattingDialog) + wxRichTextFormattingDialogFactory* wxRichTextFormattingDialog::ms_FormattingDialogFactory = NULL; void wxRichTextFormattingDialog::Init() { - m_imageList = NULL; m_styleDefinition = NULL; m_styleSheet = NULL; + m_object = NULL; + m_options = 0; } wxRichTextFormattingDialog::~wxRichTextFormattingDialog() { - delete m_imageList; delete m_styleDefinition; } @@ -97,6 +110,9 @@ bool wxRichTextFormattingDialog::Create(long flags, wxWindow* parent, const wxSt const wxPoint& pos, const wxSize& sz, long style) { SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); +#ifdef __WXMAC__ + SetWindowVariant(wxWINDOW_VARIANT_SMALL); +#endif int resizeBorder = wxRESIZE_BORDER; @@ -117,7 +133,7 @@ bool wxRichTextFormattingDialog::Create(long flags, wxWindow* parent, const wxSt /// Get attributes from the given range bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range) { - if (ctrl->GetBuffer().GetStyleForRange(range.ToInternal(), m_attributes)) + if (ctrl->GetFocusObject()->GetStyleForRange(range.ToInternal(), m_attributes)) return UpdateDisplay(); else return false; @@ -129,8 +145,20 @@ bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTe return ctrl->SetStyleEx(range, m_attributes, flags); } +// Apply attributes to the object being edited, if any +bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl* ctrl, int flags) +{ + if (GetObject()) + { + ctrl->SetStyle(GetObject(), m_attributes, flags); + return true; + } + else + return false; +} + /// Set the attributes and optionally update the display -bool wxRichTextFormattingDialog::SetStyle(const wxTextAttr& style, bool update) +bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr& style, bool update) { m_attributes = style; if (update) @@ -212,12 +240,19 @@ void wxRichTextFormattingDialog::OnHelp(wxCommandEvent& event) int selPage = GetBookCtrl()->GetSelection(); if (selPage != wxNOT_FOUND) { - int pageId = m_pageIds[selPage]; + int pageId = -1; + if (selPage < (int) m_pageIds.GetCount()) + pageId = m_pageIds[selPage]; if (!GetFormattingDialogFactory()->ShowHelp(pageId, this)) event.Skip(); } } +void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent& event) +{ + event.Enable(true); +} + void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory) { if (ms_FormattingDialogFactory) @@ -225,6 +260,20 @@ void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormatting ms_FormattingDialogFactory = factory; } +// Find a page by class +wxWindow* wxRichTextFormattingDialog::FindPage(wxClassInfo* info) const +{ + size_t i; + for (i = 0; i < GetBookCtrl()->GetPageCount(); i++) + { + wxWindow* w = GetBookCtrl()->GetPage(i); + if (w && w->GetClassInfo() == info) + return w; + } + return NULL; +} + + /*! * Factory for formatting dialog */ @@ -301,6 +350,30 @@ wxPanel* wxRichTextFormattingDialogFactory::CreatePage(int page, wxString& title return page; } #endif + else if (page == wxRICHTEXT_FORMAT_SIZE) + { + wxRichTextSizePage* page = new wxRichTextSizePage(dialog->GetBookCtrl(), wxID_ANY); + title = _("Size"); + return page; + } + else if (page == wxRICHTEXT_FORMAT_MARGINS) + { + wxRichTextMarginsPage* page = new wxRichTextMarginsPage(dialog->GetBookCtrl(), wxID_ANY); + title = _("Margins"); + return page; + } + else if (page == wxRICHTEXT_FORMAT_BORDERS) + { + wxRichTextBordersPage* page = new wxRichTextBordersPage(dialog->GetBookCtrl(), wxID_ANY); + title = _("Borders"); + return page; + } + else if (page == wxRICHTEXT_FORMAT_BACKGROUND) + { + wxRichTextBackgroundPage* page = new wxRichTextBackgroundPage(dialog->GetBookCtrl(), wxID_ANY); + title = _("Background"); + return page; + } else return NULL; } @@ -314,9 +387,14 @@ int wxRichTextFormattingDialogFactory::GetPageId(int i) const wxRICHTEXT_FORMAT_INDENTS_SPACING, wxRICHTEXT_FORMAT_BULLETS, wxRICHTEXT_FORMAT_TABS, - wxRICHTEXT_FORMAT_LIST_STYLE }; - - if (i < 0 || i > 5) + wxRICHTEXT_FORMAT_LIST_STYLE, + wxRICHTEXT_FORMAT_SIZE, + wxRICHTEXT_FORMAT_MARGINS, + wxRICHTEXT_FORMAT_BORDERS, + wxRICHTEXT_FORMAT_BACKGROUND + }; + + if (i < 0 || i >= GetPageIdCount()) return -1; return pages[i]; @@ -326,9 +404,9 @@ int wxRichTextFormattingDialogFactory::GetPageId(int i) const int wxRichTextFormattingDialogFactory::GetPageIdCount() const { #ifdef __DMC__ - return 5; + return 9; #else - return 6; + return 10; #endif } @@ -370,6 +448,28 @@ bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog return true; } +// Invoke help for the dialog +bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page), wxRichTextFormattingDialog* dialog) +{ + wxRichTextDialogPage* window = NULL; + int sel = dialog->GetBookCtrl()->GetSelection(); + if (sel != -1) + window = wxDynamicCast(dialog->GetBookCtrl()->GetPage(sel), wxRichTextDialogPage); + if (window && window->GetHelpId() != -1) + { + if (window->GetUICustomization()) + return window->GetUICustomization()->ShowHelp(dialog, window->GetHelpId()); + else if (dialog->GetUICustomization()) + return dialog->GetUICustomization()->ShowHelp(dialog, window->GetHelpId()); + else + return false; + } + else if (dialog->GetHelpId() != -1 && dialog->GetUICustomization()) + return dialog->ShowHelp(dialog); + else + return false; +} + /* * Module to initialise and clean up handlers */ @@ -417,7 +517,7 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) font.SetPointSize( static_cast(size) ); } - if ( font.Ok() ) + if ( font.IsOk() ) { dc.SetFont(font); // Calculate vertical and horizontal centre @@ -454,15 +554,14 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) wxRichTextFormattingDialog* wxRichTextFormattingDialog::GetDialog(wxWindow* win) { wxWindow* p = win->GetParent(); - while (p && !p->IsKindOf(CLASSINFO(wxRichTextFormattingDialog))) + while (p && !wxDynamicCast(p, wxRichTextFormattingDialog)) p = p->GetParent(); wxRichTextFormattingDialog* dialog = wxDynamicCast(p, wxRichTextFormattingDialog); return dialog; } - // Helper for pages to get the attributes -wxTextAttr* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow* win) +wxRichTextAttr* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow* win) { wxRichTextFormattingDialog* dialog = GetDialog(win); if (dialog) @@ -471,6 +570,18 @@ wxTextAttr* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow* win) return NULL; } +#if 0 +// Helper for pages to get the attributes to reset +wxRichTextAttr* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow* win) +{ + wxRichTextFormattingDialog* dialog = GetDialog(win); + if (dialog) + return & dialog->GetResetAttributes(); + else + return NULL; +} +#endif + // Helper for pages to get the style wxRichTextStyleDefinition* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow* win) { @@ -481,6 +592,95 @@ wxRichTextStyleDefinition* wxRichTextFormattingDialog::GetDialogStyleDefinition( return NULL; } +void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox) +{ + int unitsIdx = 0; + + if (!dim.IsValid()) + { + checkBox->SetValue(false); + valueCtrl->SetValue(wxT("0")); + unitsCtrl->SetSelection(0); +#if 0 + dim.SetValue(0); + dim.SetUnits(wxTEXT_ATTR_UNITS_PIXELS); +#endif + } + else + { + checkBox->SetValue(true); + if (dim.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM) + { + unitsIdx = 1; + float value = float(dim.GetValue()) / 100.0; + valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value)); + } + else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE) + { + unitsIdx = 2; + valueCtrl->SetValue(wxString::Format(wxT("%d"), (int) dim.GetValue())); + } + else + { + unitsIdx = 0; + valueCtrl->SetValue(wxString::Format(wxT("%d"), (int) dim.GetValue())); + } + + unitsCtrl->SetSelection(unitsIdx); + } +} + +void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox) +{ + if (!checkBox->GetValue()) + { + dim.Reset(); + } + else + { + if (unitsCtrl->GetSelection() == 1) + dim.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM); + else if (unitsCtrl->GetSelection() == 2) + dim.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE); + else + dim.SetUnits(wxTEXT_ATTR_UNITS_PIXELS); + + int value = 0; + if (ConvertFromString(valueCtrl->GetValue(), value, dim.GetUnits())) + dim.SetValue(value); + } +} + +bool wxRichTextFormattingDialog::ConvertFromString(const wxString& string, int& ret, int scale) +{ + const wxChar* chars = string.GetData(); + int remain = 2; + bool dot = false; + ret = 0; + + for (unsigned int i = 0; i < string.Len() && remain; i++) + { + if (!(chars[i] >= wxT('0') && chars[i] <= wxT('9')) && !(scale == wxTEXT_ATTR_UNITS_TENTHS_MM && chars[i] == wxT('.'))) + return false; + + if (chars[i] == wxT('.')) + { + dot = true; + continue; + } + + if (dot) + remain--; + + ret = ret * 10 + chars[i] - wxT('0'); + } + + while (remain-- > 0 && scale == wxTEXT_ATTR_UNITS_TENTHS_MM) + ret *= 10; + + return true; +} + /* * A control for displaying a small preview of a colour or bitmap */ @@ -499,7 +699,6 @@ wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindo wxControl::Create(parent, id, pos, size, style); SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - SetBackgroundStyle(wxBG_STYLE_COLOUR); } wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl() @@ -511,7 +710,7 @@ void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event) if (event.LeftDown()) { wxWindow* parent = GetParent(); - while (parent != NULL && !parent->IsKindOf(CLASSINFO(wxDialog)) && !parent->IsKindOf(CLASSINFO(wxFrame))) + while (parent != NULL && !wxDynamicCast(parent, wxDialog) && !wxDynamicCast(parent, wxFrame)) parent = parent->GetParent(); wxColourData data; @@ -533,7 +732,7 @@ void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event) #endif // wxUSE_COLOURDLG Refresh(); - wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); + wxCommandEvent event(wxEVT_BUTTON, GetId()); GetEventHandler()->ProcessEvent(event); } } @@ -630,7 +829,7 @@ wxString wxRichTextFontListBox::CreateHTML(const wxString& facename) const if (!facename.IsEmpty() && facename != _("(none)")) str << wxT(" face=\"") << facename << wxT("\""); /* - if (def->GetStyle().GetTextColour().Ok()) + if (def->GetStyle().GetTextColour().IsOk()) str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\""); */