X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/97ff49b3834325cfe53813aeb53d326d7661f184..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/richtext/richtextformatdlg.cpp?ds=inline diff --git a/src/richtext/richtextformatdlg.cpp b/src/richtext/richtextformatdlg.cpp index 9a7d80afd8..3a7d7ee6c5 100644 --- a/src/richtext/richtextformatdlg.cpp +++ b/src/richtext/richtextformatdlg.cpp @@ -16,7 +16,9 @@ #pragma hdrstop #endif -#include "wx/defs.h" +#if wxUSE_RICHTEXT + +#include "wx/richtext/richtextformatdlg.h" #ifndef WX_PRECOMP #include "wx/listbox.h" @@ -30,39 +32,50 @@ #include "wx/bitmap.h" #include "wx/dcclient.h" #include "wx/frame.h" - #include "wx/imaglist.h" #include "wx/checkbox.h" #include "wx/button.h" #endif // WX_PRECOMP -#if wxUSE_RICHTEXT - #include "wx/bookctrl.h" #include "wx/colordlg.h" -#include "wx/fontenum.h" #include "wx/settings.h" #include "wx/module.h" +#include "wx/imaglist.h" -#include "wx/richtext/richtextformatdlg.h" #include "wx/richtext/richtextctrl.h" #include "wx/richtext/richtextstyles.h" +#ifdef __WXMAC__ +#include "../../src/richtext/richtextfontpage.cpp" +#include "../../src/richtext/richtextindentspage.cpp" +#include "../../src/richtext/richtexttabspage.cpp" +#include "../../src/richtext/richtextbulletspage.cpp" +#include "../../src/richtext/richtextstylepage.cpp" +#include "../../src/richtext/richtextliststylepage.cpp" +#else #include "richtextfontpage.cpp" #include "richtextindentspage.cpp" #include "richtexttabspage.cpp" #include "richtextbulletspage.cpp" +// Digital Mars can't cope with this much code +#ifndef __DMC__ + #include "richtextliststylepage.cpp" +#endif #include "richtextstylepage.cpp" +#endif -#ifdef __WXMAC__ -#define wxRICHTEXT_USE_TOOLBOOK true +#if 0 // def __WXMAC__ +#define wxRICHTEXT_USE_TOOLBOOK 1 #else -#define wxRICHTEXT_USE_TOOLBOOK false +#define wxRICHTEXT_USE_TOOLBOOK 0 #endif +bool wxRichTextFormattingDialog::sm_showToolTips = false; + IMPLEMENT_CLASS(wxRichTextFormattingDialog, wxPropertySheetDialog) BEGIN_EVENT_TABLE(wxRichTextFormattingDialog, wxPropertySheetDialog) - EVT_NOTEBOOK_PAGE_CHANGED(-1, wxRichTextFormattingDialog::OnTabChanged) + EVT_BOOKCTRL_PAGE_CHANGED(wxID_ANY, wxRichTextFormattingDialog::OnTabChanged) END_EVENT_TABLE() wxRichTextFormattingDialogFactory* wxRichTextFormattingDialog::ms_FormattingDialogFactory = NULL; @@ -90,7 +103,7 @@ bool wxRichTextFormattingDialog::Create(long flags, wxWindow* parent, const wxSt GetFormattingDialogFactory()->SetSheetStyle(this); wxPropertySheetDialog::Create(parent, id, title, pos, sz, - style | (int)wxPlatform::IfNot(wxWinCE, resizeBorder) + style | (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder) ); GetFormattingDialogFactory()->CreateButtons(this); @@ -117,7 +130,7 @@ bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTe } /// Set the attributes and optionally update the display -bool wxRichTextFormattingDialog::SetStyle(const wxTextAttrEx& style, bool update) +bool wxRichTextFormattingDialog::SetStyle(const wxTextAttr& style, bool update) { m_attributes = style; if (update) @@ -168,7 +181,7 @@ bool wxRichTextFormattingDialog::UpdateDisplay() /// Apply the styles when a different tab is selected, so the previews are /// up to date -void wxRichTextFormattingDialog::OnTabChanged(wxNotebookEvent& event) +void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent& event) { if (GetBookCtrl() != event.GetEventObject()) { @@ -193,6 +206,18 @@ void wxRichTextFormattingDialog::OnTabChanged(wxNotebookEvent& event) } } +/// Respond to help command +void wxRichTextFormattingDialog::OnHelp(wxCommandEvent& event) +{ + int selPage = GetBookCtrl()->GetSelection(); + if (selPage != wxNOT_FOUND) + { + int pageId = m_pageIds[selPage]; + if (!GetFormattingDialogFactory()->ShowHelp(pageId, this)) + event.Skip(); + } +} + void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory) { if (ms_FormattingDialogFactory) @@ -212,6 +237,7 @@ bool wxRichTextFormattingDialogFactory::CreatePages(long pages, wxRichTextFormat int availablePageCount = GetPageIdCount(); int i; + bool selected = false; for (i = 0; i < availablePageCount; i ++) { int pageId = GetPageId(i); @@ -223,10 +249,14 @@ bool wxRichTextFormattingDialogFactory::CreatePages(long pages, wxRichTextFormat if (panel) { int imageIndex = GetPageImage(pageId); - dialog->GetBookCtrl()->AddPage(panel, title, false, imageIndex); + dialog->GetBookCtrl()->AddPage(panel, title, !selected, imageIndex); + selected = true; + + dialog->AddPageId(pageId); } } } + return true; } @@ -263,6 +293,14 @@ wxPanel* wxRichTextFormattingDialogFactory::CreatePage(int page, wxString& title title = _("Bullets"); return page; } +#ifndef __DMC__ + else if (page == wxRICHTEXT_FORMAT_LIST_STYLE) + { + wxRichTextListStylePage* page = new wxRichTextListStylePage(dialog->GetBookCtrl(), wxID_ANY); + title = _("List Style"); + return page; + } +#endif else return NULL; } @@ -275,9 +313,10 @@ int wxRichTextFormattingDialogFactory::GetPageId(int i) const wxRICHTEXT_FORMAT_FONT, wxRICHTEXT_FORMAT_INDENTS_SPACING, wxRICHTEXT_FORMAT_BULLETS, - wxRICHTEXT_FORMAT_TABS }; + wxRICHTEXT_FORMAT_TABS, + wxRICHTEXT_FORMAT_LIST_STYLE }; - if (i < 0 || i > 4) + if (i < 0 || i > 5) return -1; return pages[i]; @@ -286,26 +325,30 @@ int wxRichTextFormattingDialogFactory::GetPageId(int i) const /// Get the number of available page identifiers int wxRichTextFormattingDialogFactory::GetPageIdCount() const { +#ifdef __DMC__ return 5; +#else + return 6; +#endif } /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog* dialog) { - bool useToolBook = wxRICHTEXT_USE_TOOLBOOK; - if (useToolBook) - { - int sheetStyle = wxPROPSHEET_SHRINKTOFIT; +#if wxRICHTEXT_USE_TOOLBOOK + int sheetStyle = wxPROPSHEET_SHRINKTOFIT; #ifdef __WXMAC__ - sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK; + sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK; #else - sheetStyle |= wxPROPSHEET_TOOLBOOK; + sheetStyle |= wxPROPSHEET_TOOLBOOK; #endif - dialog->SetSheetStyle(sheetStyle); - dialog->SetSheetInnerBorder(0); - dialog->SetSheetOuterBorder(0); - } + dialog->SetSheetStyle(sheetStyle); + dialog->SetSheetInnerBorder(0); + dialog->SetSheetOuterBorder(0); +#else + wxUnusedVar(dialog); +#endif // wxRICHTEXT_USE_TOOLBOOK return true; } @@ -313,16 +356,16 @@ bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog /// Create the main dialog buttons bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog* dialog) { - bool useToolBook = wxRICHTEXT_USE_TOOLBOOK; - - // If using a toolbook, also follow Mac style and don't create buttons int flags = wxOK|wxCANCEL; #ifndef __WXWINCE__ - flags |= wxHELP; + if (dialog->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON) + flags |= wxHELP; #endif - if (!useToolBook) - dialog->CreateButtons(flags); + // If using a toolbook, also follow Mac style and don't create buttons +#if !wxRICHTEXT_USE_TOOLBOOK + dialog->CreateButtons(flags); +#endif return true; } @@ -336,8 +379,8 @@ class wxRichTextFormattingDialogModule: public wxModule DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule) public: wxRichTextFormattingDialogModule() {} - bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory); return true; }; - void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL); }; + bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory); return true; } + void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL); } }; IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule, wxModule) @@ -350,6 +393,17 @@ BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl, wxWindow) EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint) END_EVENT_TABLE() +wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& sz, long style) +{ + if ((style & wxBORDER_MASK) == wxBORDER_DEFAULT) + style |= wxBORDER_THEME; + + wxWindow::Create(parent, id, pos, sz, style); + + SetBackgroundColour(*wxWHITE); + m_textEffects = 0; +} + void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); @@ -361,9 +415,11 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { dc.SetFont(font); // Calculate vertical and horizontal centre - long w = 0, h = 0; + wxCoord w = 0, h = 0; wxString text(_("ABCDEFGabcdefg12345")); + if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS) + text.MakeUpper(); dc.GetTextExtent( text, &w, &h); int cx = wxMax(2, (size.x/2) - (w/2)); @@ -372,6 +428,13 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) dc.SetTextForeground(GetForegroundColour()); dc.SetClippingRegion(2, 2, size.x-4, size.y-4); dc.DrawText(text, cx, cy); + + if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH) + { + dc.SetPen(wxPen(GetForegroundColour(), 1)); + dc.DrawLine(cx, (int) (cy + h/2 + 0.5), cx + w, (int) (cy + h/2 + 0.5)); + } + dc.DestroyClippingRegion(); } } @@ -388,7 +451,7 @@ wxRichTextFormattingDialog* wxRichTextFormattingDialog::GetDialog(wxWindow* win) // Helper for pages to get the attributes -wxTextAttrEx* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow* win) +wxTextAttr* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow* win) { wxRichTextFormattingDialog* dialog = GetDialog(win); if (dialog) @@ -417,9 +480,13 @@ END_EVENT_TABLE() IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl, wxControl) -wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style): - wxControl(parent, id, pos, size, style) +wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) { + if ((style & wxBORDER_MASK) == wxBORDER_DEFAULT) + style |= wxBORDER_THEME; + + wxControl::Create(parent, id, pos, size, style); + SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); SetBackgroundStyle(wxBG_STYLE_COLOUR); } @@ -439,10 +506,11 @@ void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event) wxColourData data; data.SetChooseFull(true); data.SetColour(m_colour); +#if wxUSE_COLOURDLG wxColourDialog *dialog = new wxColourDialog(parent, &data); // Crashes on wxMac (no m_peer) #ifndef __WXMAC__ - dialog->SetTitle(_("Background colour")); + dialog->SetTitle(_("Colour")); #endif if (dialog->ShowModal() == wxID_OK) { @@ -451,6 +519,7 @@ void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent& event) SetBackgroundColour(m_colour); } dialog->Destroy(); +#endif // wxUSE_COLOURDLG Refresh(); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId()); @@ -480,6 +549,9 @@ wxRichTextFontListBox::wxRichTextFontListBox(wxWindow* parent, wxWindowID id, co bool wxRichTextFontListBox::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) { + if ((style & wxBORDER_MASK) == wxBORDER_DEFAULT) + style |= wxBORDER_THEME; + return wxHtmlListBox::Create(parent, id, pos, size, style); } @@ -515,9 +587,7 @@ int wxRichTextFontListBox::SetFaceNameSelection(const wxString& name) /// Updates the font list void wxRichTextFontListBox::UpdateFonts() { - wxFontEnumerator enumerator; - enumerator.EnumerateFacenames(); - wxArrayString facenames = enumerator.GetFacenames(); + wxArrayString facenames = wxRichTextCtrl::GetAvailableFontNames(); m_faceNames = facenames; m_faceNames.Sort(); @@ -576,4 +646,3 @@ wxString wxRichTextFontListBox::CreateHTML(const wxString& facename) const #endif // wxUSE_RICHTEXT -