X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bcedac446992587c7805623eac66b36de05686bb..4b5ac600de03bec2a73610f7fa566aa2cf2ce9f8:/src/richtext/richtextstyledlg.cpp diff --git a/src/richtext/richtextstyledlg.cpp b/src/richtext/richtextstyledlg.cpp index d8ed49fd09..e31fbc1b03 100644 --- a/src/richtext/richtextstyledlg.cpp +++ b/src/richtext/richtextstyledlg.cpp @@ -1,12 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richtextstyledlg.cpp -// Purpose: +// Name: src/richtext/richtextstyledlg.cpp +// Purpose: // Author: Julian Smart -// Modified by: +// Modified by: // Created: 10/5/2006 12:05:31 PM -// RCS-ID: +// RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". @@ -16,19 +16,15 @@ #pragma hdrstop #endif +#if wxUSE_RICHTEXT + #ifndef WX_PRECOMP #include "wx/wx.h" #endif -////@begin includes -////@end includes - #include "wx/richtext/richtextstyledlg.h" #include "wx/richtext/richtextformatdlg.h" -////@begin XPM images -////@end XPM images - /*! * wxRichTextStyleOrganiserDialog type definition */ @@ -97,7 +93,7 @@ void wxRichTextStyleOrganiserDialog::Init() m_dontUpdate = false; m_flags = 0; m_restartNumbering = true; - + ////@begin wxRichTextStyleOrganiserDialog member initialisation m_innerSizer = NULL; m_buttonSizerParent = NULL; @@ -128,7 +124,7 @@ bool wxRichTextStyleOrganiserDialog::Create( int flags, wxRichTextStyleSheet* sh m_richTextStyleSheet = sheet; m_richTextCtrl = ctrl; m_flags = flags; - + ////@begin wxRichTextStyleOrganiserDialog creation SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP); wxDialog::Create( parent, id, caption, pos, size, style ); @@ -148,10 +144,10 @@ bool wxRichTextStyleOrganiserDialog::Create( int flags, wxRichTextStyleSheet* sh */ void wxRichTextStyleOrganiserDialog::CreateControls() -{ +{ bool hideTypeSelector = false; wxRichTextStyleListBox::wxRichTextStyleType typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL; - + if ((m_flags & wxRICHTEXT_ORGANISER_SHOW_CHARACTER) != 0) { typesToShow = wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER; @@ -171,11 +167,11 @@ void wxRichTextStyleOrganiserDialog::CreateControls() { // wxRICHTEXT_ORGANISER_SHOW_ALL is implied if the other styles aren't included } - + long listCtrlStyle = 0; if (hideTypeSelector) listCtrlStyle = wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR; - + ////@begin wxRichTextStyleOrganiserDialog content construction wxRichTextStyleOrganiserDialog* itemDialog1 = this; @@ -192,7 +188,7 @@ void wxRichTextStyleOrganiserDialog::CreateControls() m_buttonSizerParent->Add(itemBoxSizer5, 1, wxGROW, 5); wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("&Styles:"), wxDefaultPosition, wxDefaultSize, 0 ); - itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); + itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); m_stylesListBox = new wxRichTextStyleListCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_STYLES, wxDefaultPosition, wxSize(200, 350), wxSIMPLE_BORDER|listCtrlStyle ); m_stylesListBox->SetHelpText(_("The available styles.")); @@ -204,7 +200,7 @@ void wxRichTextStyleOrganiserDialog::CreateControls() m_buttonSizerParent->Add(itemBoxSizer8, 0, wxGROW, 5); wxStaticText* itemStaticText9 = new wxStaticText( itemDialog1, wxID_STATIC, _(" "), wxDefaultPosition, wxDefaultSize, 0 ); - itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); + itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); m_previewCtrl = new wxRichTextCtrl( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_PREVIEW, wxEmptyString, wxDefaultPosition, wxSize(310, 200), wxSIMPLE_BORDER|wxTE_READONLY ); m_previewCtrl->SetHelpText(_("The style preview.")); @@ -216,7 +212,7 @@ void wxRichTextStyleOrganiserDialog::CreateControls() m_buttonSizerParent->Add(m_buttonSizer, 0, wxGROW, 5); wxStaticText* itemStaticText12 = new wxStaticText( itemDialog1, wxID_STATIC, _(" "), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonSizer->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5); + m_buttonSizer->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5); m_newCharacter = new wxButton( itemDialog1, ID_RICHTEXTSTYLEORGANISERDIALOG_NEW_CHAR, _("New &Character Style..."), wxDefaultPosition, wxDefaultSize, 0 ); m_newCharacter->SetHelpText(_("Click to create a new character style.")); @@ -340,18 +336,18 @@ void wxRichTextStyleOrganiserDialog::CreateControls() { m_buttonSizerParent->Show(m_buttonSizer, false); } - + // No buttons in the horizontal group are shown, so hide the whole sizer if ((m_flags & (wxRICHTEXT_ORGANISER_OK_CANCEL|wxRICHTEXT_ORGANISER_RENUMBER)) == 0) { m_innerSizer->Show(m_bottomButtonSizer, false); } - + if (hideTypeSelector) { m_stylesListBox->GetStyleListBox()->SetStyleType(typesToShow); } - + m_stylesListBox->SetStyleSheet(m_richTextStyleSheet); m_stylesListBox->SetRichTextCtrl(m_richTextCtrl); m_stylesListBox->UpdateStyles(); @@ -389,9 +385,9 @@ bool wxRichTextStyleOrganiserDialog::TransferDataFromWindow() { if (!wxDialog::TransferDataFromWindow()) return false; - + m_restartNumbering = m_restartNumberingCtrl->GetValue(); - + return true; } @@ -399,9 +395,9 @@ bool wxRichTextStyleOrganiserDialog::TransferDataToWindow() { if (!wxDialog::TransferDataToWindow()) return false; - + m_restartNumberingCtrl->SetValue(m_restartNumbering); - + return true; } @@ -423,22 +419,14 @@ iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n"); { sel = m_stylesListBox->GetStyleListBox()->GetSelection(); if (sel == -1) - return; + return; } wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); - + wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); - //wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition); - //wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition); - - wxTextAttrEx attr(def->GetStyle()); -#if 0 - attr.SetFlags(attr.GetFlags() & - (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER| - wxTEXT_ATTR_LINE_SPACING| - wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL)); -#endif + + wxTextAttrEx attr(def->GetStyleMergedWithBase(GetStyleSheet())); wxFont font(m_previewCtrl->GetFont()); font.SetPointSize(9); @@ -449,16 +437,17 @@ iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n"); normalParaAttr.SetTextColour(wxColour(wxT("LIGHT GREY"))); m_previewCtrl->Freeze(); - m_previewCtrl->Clear(); + m_previewCtrl->Clear(); m_previewCtrl->BeginStyle(normalParaAttr); m_previewCtrl->WriteText(s_para1); m_previewCtrl->EndStyle(); - + m_previewCtrl->BeginStyle(attr); - + if (listDef) { + long listStart = m_previewCtrl->GetInsertionPoint() + 1; int i; for (i = 0; i < 10; i++) { @@ -468,12 +457,14 @@ iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n"); m_previewCtrl->WriteText(wxString::Format(wxT("\nList level %d. "), i+1) + s_para2List); m_previewCtrl->EndStyle(); } + long listEnd = m_previewCtrl->GetInsertionPoint(); + m_previewCtrl->NumberList(wxRichTextRange(listStart, listEnd), listDef); } else { m_previewCtrl->WriteText(wxString(wxT("\n")) + s_para2); } - + m_previewCtrl->EndStyle(); m_previewCtrl->BeginStyle(normalParaAttr); @@ -482,11 +473,11 @@ iaculis malesuada. Donec bibendum ipsum ut ante porta fringilla.\n"); m_previewCtrl->Thaw(); } - + /// Clears the preview void wxRichTextStyleOrganiserDialog::ClearPreview() { - m_richTextCtrl->Clear(); + m_previewCtrl->Clear(); } bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl* ctrl) @@ -500,9 +491,9 @@ bool wxRichTextStyleOrganiserDialog::ApplyStyle(wxRichTextCtrl* ctrl) return false; if (!ctrl->HasSelection()) return false; - - wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); + + wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition); if (listDef && m_restartNumberingCtrl->GetValue()) @@ -575,9 +566,9 @@ void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent& WXUNUSED(ev wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); return; } - + wxRichTextCharacterStyleDefinition* style = new wxRichTextCharacterStyleDefinition(styleName); - + int pages = wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_STYLE_EDITOR; wxRichTextFormattingDialog formatDlg; formatDlg.SetStyleDefinition(*style, GetStyleSheet()); @@ -586,9 +577,9 @@ void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent& WXUNUSED(ev if (formatDlg.ShowModal() == wxID_OK) { wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextCharacterStyleDefinition); - + (*((wxRichTextCharacterStyleDefinition* ) style)) = (*charDef); - + GetStyleSheet()->AddCharacterStyle(style); m_stylesListBox->UpdateStyles(); @@ -596,7 +587,7 @@ void wxRichTextStyleOrganiserDialog::OnNewCharClick( wxCommandEvent& WXUNUSED(ev } else delete style; - } + } } /*! @@ -623,9 +614,9 @@ void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent& WXUNUSED(ev wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); return; } - + wxRichTextParagraphStyleDefinition* style = new wxRichTextParagraphStyleDefinition(styleName); - + int pages = wxRICHTEXT_FORMAT_STYLE_EDITOR|wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS; wxRichTextFormattingDialog formatDlg; formatDlg.SetStyleDefinition(*style, GetStyleSheet()); @@ -634,9 +625,9 @@ void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent& WXUNUSED(ev if (formatDlg.ShowModal() == wxID_OK) { wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextParagraphStyleDefinition); - + (*((wxRichTextParagraphStyleDefinition* ) style)) = (*paraDef); - + GetStyleSheet()->AddParagraphStyle(style); m_stylesListBox->UpdateStyles(); @@ -644,7 +635,7 @@ void wxRichTextStyleOrganiserDialog::OnNewParaClick( wxCommandEvent& WXUNUSED(ev } else delete style; - } + } } /*! @@ -667,9 +658,9 @@ void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent& WXUNUSED(event if (sel != wxNOT_FOUND) { wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); - + int pages = wxRICHTEXT_FORMAT_STYLE_EDITOR; - + if (def->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition))) { pages |= wxRICHTEXT_FORMAT_FONT; @@ -682,7 +673,7 @@ void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent& WXUNUSED(event { pages |= wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING|wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS; } - + wxRichTextFormattingDialog formatDlg; formatDlg.SetStyleDefinition(*def, GetStyleSheet()); formatDlg.Create(pages, this); @@ -692,7 +683,7 @@ void wxRichTextStyleOrganiserDialog::OnEditClick( wxCommandEvent& WXUNUSED(event wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextParagraphStyleDefinition); wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextCharacterStyleDefinition); wxRichTextListStyleDefinition* listDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextListStyleDefinition); - + if (listDef) { (*((wxRichTextListStyleDefinition* ) def)) = (*listDef); @@ -733,17 +724,17 @@ void wxRichTextStyleOrganiserDialog::OnDeleteClick( wxCommandEvent& WXUNUSED(eve { wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); wxString name(def->GetName()); - if (wxYES == wxMessageBox(wxString::Format(_("Delete style %s?"), (const wxChar*) name), _("Delete Style"), wxYES_NO|wxICON_QUESTION, this)) + if (wxYES == wxMessageBox(wxString::Format(_("Delete style %s?"), name), _("Delete Style"), wxYES_NO|wxICON_QUESTION, this)) { m_stylesListBox->GetStyleListBox()->SetItemCount(0); - + if (def->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition))) GetStyleSheet()->RemoveListStyle((wxRichTextListStyleDefinition*) def, true); else if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition))) GetStyleSheet()->RemoveParagraphStyle((wxRichTextParagraphStyleDefinition*) def, true); else if (def->IsKindOf(CLASSINFO(wxRichTextCharacterStyleDefinition))) GetStyleSheet()->RemoveCharacterStyle((wxRichTextCharacterStyleDefinition*) def, true); - + m_stylesListBox->UpdateStyles(); if (m_stylesListBox->GetStyleListBox()->GetSelection() != -1) @@ -777,9 +768,9 @@ void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent& WXUNUSED(ev wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); return; } - + wxRichTextListStyleDefinition* style = new wxRichTextListStyleDefinition(styleName); - + // Initialize the style to make it easier to edit int i; for (i = 0; i < 10; i++) @@ -798,7 +789,7 @@ void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent& WXUNUSED(ev style->SetAttributes(i, (i+1)*60, 60, wxTEXT_ATTR_BULLET_STYLE_SYMBOL, bulletSymbol); } - + int pages = wxRICHTEXT_FORMAT_LIST_STYLE|wxRICHTEXT_FORMAT_STYLE_EDITOR|wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING; wxRichTextFormattingDialog formatDlg; formatDlg.SetStyleDefinition(*style, GetStyleSheet()); @@ -807,9 +798,9 @@ void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent& WXUNUSED(ev if (formatDlg.ShowModal() == wxID_OK) { wxRichTextListStyleDefinition* listDef = wxDynamicCast(formatDlg.GetStyleDefinition(), wxRichTextListStyleDefinition); - + (*((wxRichTextListStyleDefinition* ) style)) = (*listDef); - + GetStyleSheet()->AddListStyle(style); m_stylesListBox->UpdateStyles(); @@ -817,7 +808,7 @@ void wxRichTextStyleOrganiserDialog::OnNewListClick( wxCommandEvent& WXUNUSED(ev } else delete style; - } + } } /*! @@ -835,6 +826,28 @@ void wxRichTextStyleOrganiserDialog::OnNewListUpdate( wxUpdateUIEvent& event ) void wxRichTextStyleOrganiserDialog::OnRenameClick( wxCommandEvent& WXUNUSED(event) ) { + int sel = m_stylesListBox->GetStyleListBox()->GetSelection(); + if (sel == -1) + return; + wxRichTextStyleDefinition* def = m_stylesListBox->GetStyleListBox()->GetStyle(sel); + if (!def) + return; + + wxString styleName = wxGetTextFromUser(_("Enter a new style name"), _("New Style"), def->GetName()); + if (!styleName.IsEmpty()) + { + if (styleName == def->GetName()) + return; + + if (GetStyleSheet()->FindParagraphStyle(styleName) || GetStyleSheet()->FindCharacterStyle(styleName) || GetStyleSheet()->FindListStyle(styleName)) + { + wxMessageBox(_("Sorry, that name is taken. Please choose another."), _("New Style"), wxICON_EXCLAMATION|wxOK, this); + return; + } + + def->SetName(styleName); + m_stylesListBox->UpdateStyles(); + } } /*! @@ -855,3 +868,6 @@ void wxRichTextStyleOrganiserDialog::OnListSelection(wxCommandEvent& event) event.Skip(); } +#endif + // wxUSE_RICHTEXT +