diff --git a/core/about.cpp b/core/dialog_about.cpp similarity index 99% rename from core/about.cpp rename to core/dialog_about.cpp index 9215e88db..9f200026e 100644 --- a/core/about.cpp +++ b/core/dialog_about.cpp @@ -36,7 +36,7 @@ //////////// // Includes -#include "about.h" +#include "dialog_about.h" #include "version.h" #include "options.h" #include diff --git a/core/about.h b/core/dialog_about.h similarity index 100% rename from core/about.h rename to core/dialog_about.h diff --git a/core/fonts_collector.cpp b/core/dialog_fonts_collector.cpp similarity index 99% rename from core/fonts_collector.cpp rename to core/dialog_fonts_collector.cpp index a99d105b1..2cac15490 100644 --- a/core/fonts_collector.cpp +++ b/core/dialog_fonts_collector.cpp @@ -47,7 +47,7 @@ #include "ass_file.h" #include "ass_dialogue.h" #include "ass_style.h" -#include "fonts_collector.h" +#include "dialog_fonts_collector.h" #include "utils.h" #include "options.h" #include "frame_main.h" diff --git a/core/fonts_collector.h b/core/dialog_fonts_collector.h similarity index 100% rename from core/fonts_collector.h rename to core/dialog_fonts_collector.h diff --git a/core/splash.cpp b/core/dialog_splash.cpp similarity index 98% rename from core/splash.cpp rename to core/dialog_splash.cpp index 39365d2f4..67f3f643c 100644 --- a/core/splash.cpp +++ b/core/dialog_splash.cpp @@ -38,9 +38,9 @@ // Includes #include #include -#include "splash.h" +#include "dialog_splash.h" #include "options.h" -#include "tip.h" +#include "dialog_tip.h" /////////////// diff --git a/core/splash.h b/core/dialog_splash.h similarity index 100% rename from core/splash.h rename to core/dialog_splash.h diff --git a/core/tip.cpp b/core/dialog_tip.cpp similarity index 99% rename from core/tip.cpp rename to core/dialog_tip.cpp index 4ada925a7..9556f8b22 100644 --- a/core/tip.cpp +++ b/core/dialog_tip.cpp @@ -37,7 +37,7 @@ /////////// // Headers #include -#include "tip.h" +#include "dialog_tip.h" #include "options.h" diff --git a/core/tip.h b/core/dialog_tip.h similarity index 100% rename from core/tip.h rename to core/dialog_tip.h diff --git a/core/frame_main.cpp b/core/frame_main.cpp index 816d38876..48bbf802b 100644 --- a/core/frame_main.cpp +++ b/core/frame_main.cpp @@ -55,8 +55,8 @@ #include "options.h" #include "main.h" #include "version.h" -#include "splash.h" -#include "tip.h" +#include "dialog_splash.h" +#include "dialog_tip.h" #include "automation_filter.h" #include "audio_box.h" #include "dialog_spellcheck.h" diff --git a/core/frame_main_events.cpp b/core/frame_main_events.cpp index 3a52b8877..83990978d 100644 --- a/core/frame_main_events.cpp +++ b/core/frame_main_events.cpp @@ -60,8 +60,8 @@ #include "dialog_properties.h" #include "dialog_attachments.h" #include "main.h" -#include "fonts_collector.h" -#include "about.h" +#include "dialog_fonts_collector.h" +#include "dialog_about.h" #include "automation_gui.h" #include "dialog_export.h" #include "audio_box.h" diff --git a/core/setup.cpp b/core/setup.cpp index 3239dfc76..9313f0a72 100644 --- a/core/setup.cpp +++ b/core/setup.cpp @@ -57,16 +57,12 @@ #if wxCHECK_VERSION(2, 8, 0) #ifdef __WXDEBUG__ -//#pragma comment(lib, "wxmsw28ud_richtext.lib") -//#pragma comment(lib, "wxmsw28ud_html.lib") #pragma comment(lib, "wxregexud.lib") #pragma comment(lib, "wxbase28ud.lib") #pragma comment(lib, "wxmsw28ud_media.lib") #pragma comment(lib, "wxmsw28ud_core.lib") #pragma comment(lib, "wxmsw28ud_adv.lib") #else -//#pragma comment(lib, "wxmsw28u_richtext.lib") -//#pragma comment(lib, "wxmsw28u_html.lib") #pragma comment(lib, "wxregexu.lib") #pragma comment(lib, "wxbase28u.lib") #pragma comment(lib, "wxmsw28u_media.lib") @@ -162,4 +158,15 @@ #endif +//////////// +// Hunspell +#if USE_HUNSPELL == 1 +#ifdef __WXDEBUG__ +#pragma comment(lib,"hunspelld.lib") +#else +#pragma comment(lib,"hunspell.lib") +#endif +#endif + + #endif // VisualC diff --git a/core/setup0.h b/core/setup0.h index b2b54b4e6..7501465c1 100644 --- a/core/setup0.h +++ b/core/setup0.h @@ -67,6 +67,11 @@ #define USE_ASPELL 0 +//////////////////////////////// +// Enable Hunspell spellchecker +#define USE_HUNSPELL 0 + + ////////////////////////////// // Enable LAVC video provider // Requires: FFMPEG library diff --git a/core/spellchecker.cpp b/core/spellchecker.cpp new file mode 100644 index 000000000..6295acf53 --- /dev/null +++ b/core/spellchecker.cpp @@ -0,0 +1,59 @@ +// Copyright (c) 2006, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "setup.h" +#include "spellchecker.h" +#if USE_HUNSPELL == 1 +#include "spellchecker_hunspell.h" +#endif + + +///////////////////// +// Get spell checker +SpellChecker *SpellChecker::GetSpellChecker() { + // Initialize + SpellChecker *check = NULL; + + // Try hunspell + #if USE_HUNSPELL == 1 + check = new HunspellSpellChecker(); + #endif + + // Return + return check; +} diff --git a/core/spellchecker.h b/core/spellchecker.h new file mode 100644 index 000000000..8e39ab116 --- /dev/null +++ b/core/spellchecker.h @@ -0,0 +1,59 @@ +// Copyright (c) 2006, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include + + +/////////////////////////// +// Spellchecking interface +class SpellChecker { +public: + static SpellChecker *GetSpellChecker(); + + SpellChecker() {} + virtual ~SpellChecker() {} + + virtual bool CheckWord(wxString word)=0; + virtual wxArrayString GetSuggestions(wxString word)=0; + + virtual wxArrayString GetLanguageList()=0; + virtual void SetLanguage(wxString language)=0; +}; diff --git a/core/spellchecker_hunspell.cpp b/core/spellchecker_hunspell.cpp new file mode 100644 index 000000000..7e40ee6cf --- /dev/null +++ b/core/spellchecker_hunspell.cpp @@ -0,0 +1,92 @@ +// Copyright (c) 2006, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "setup.h" +#if USE_HUNSPELL == 1 +#include +#include "spellchecker_hunspell.h" +#include "main.h" + + +/////////////// +// Constructor +HunspellSpellChecker::HunspellSpellChecker() { + wxString affpath = AegisubApp::folderName + _T("dictionaries/en_US.aff"); + wxString dpath = AegisubApp::folderName + _T("dictionaries/en_US.dic"); + hunspell = new Hunspell(affpath.mb_str(wxConvLocal),dpath.mb_str(wxConvLocal)); +} + + +////////////// +// Destructor +HunspellSpellChecker::~HunspellSpellChecker() { + delete hunspell; + hunspell = NULL; +} + + +////////////////////////////// +// Check if the word is valid +bool HunspellSpellChecker::CheckWord(wxString word) { + if (!hunspell) return true; + return (hunspell->spell(word.mb_str(wxConvUTF8)) == 1); +} + + +//////////////////////////// +// Get suggestions for word +wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) { + wxArrayString suggestions; + return suggestions; +} + + +////////////////////////////////////// +// Get list of available dictionaries +wxArrayString HunspellSpellChecker::GetLanguageList() { + wxArrayString list; + return list; +} + + +//////////////// +// Set language +void HunspellSpellChecker::SetLanguage(wxString language) { +} + +#endif diff --git a/core/spellchecker_hunspell.h b/core/spellchecker_hunspell.h new file mode 100644 index 000000000..3a4a0d7e0 --- /dev/null +++ b/core/spellchecker_hunspell.h @@ -0,0 +1,67 @@ +// Copyright (c) 2006, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "setup.h" +#if USE_HUNSPELL == 1 +#include "spellchecker.h" + + +////////////// +// Prototypes +class Hunspell; + + +////////////////// +// Hunspell class +class HunspellSpellChecker : public SpellChecker { +private: + Hunspell *hunspell; + +public: + HunspellSpellChecker(); + ~HunspellSpellChecker(); + + bool CheckWord(wxString word); + wxArrayString GetSuggestions(wxString word); + + wxArrayString GetLanguageList(); + void SetLanguage(wxString language); +}; + + +#endif diff --git a/core/stdwx.h b/core/stdwx.h index e6d0e66fe..f98528e8e 100644 --- a/core/stdwx.h +++ b/core/stdwx.h @@ -87,11 +87,18 @@ #include -/////////////////////// -// Optional components +/////////////// +// DirectSound #if USE_DIRECTSOUND == 1 #include #endif +//////////// +// Hunspell +#if USE_HUNSPELL == 1 +#include +#endif + + #endif // C++ diff --git a/core/subs_edit_ctrl.cpp b/core/subs_edit_ctrl.cpp new file mode 100644 index 000000000..e9ff8c324 --- /dev/null +++ b/core/subs_edit_ctrl.cpp @@ -0,0 +1,268 @@ +// Copyright (c) 2005, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +//////////// +// Includes +#include "subs_edit_ctrl.h" +#include "subs_edit_box.h" +#include "options.h" + + +//////////////////////// +// Edit box constructor +SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& wsize, long style, const wxValidator& validator, const wxString& name) +: wxScintilla(parent, id, pos, wsize, 0, value) +{ + // Set properties + SetWrapMode(wxSCI_WRAP_WORD); + SetMarginWidth(1,0); + CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_CTRL); + CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_NULL); + CmdKeyClear(wxSCI_KEY_TAB,wxSCI_SCMOD_NULL); + CmdKeyClear(wxSCI_KEY_TAB,wxSCI_SCMOD_SHIFT); + CmdKeyClear('D',wxSCI_SCMOD_CTRL); + CmdKeyClear('L',wxSCI_SCMOD_CTRL); + CmdKeyClear('L',wxSCI_SCMOD_CTRL | wxSCI_SCMOD_SHIFT); + CmdKeyClear('T',wxSCI_SCMOD_CTRL); + CmdKeyClear('T',wxSCI_SCMOD_CTRL | wxSCI_SCMOD_SHIFT); + CmdKeyClear('U',wxSCI_SCMOD_CTRL); + + // Styles + wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + wxString fontname = Options.AsText(_T("Font Face")); + if (fontname != _T("")) font.SetFaceName(fontname); + int size = Options.AsInt(_T("Font Size")); + + // Normal style + StyleSetFont(0,font); + StyleSetSize(0,size); + StyleSetForeground(0,Options.AsColour(_T("Syntax Highlight Normal"))); + + // Brackets style + StyleSetFont(1,font); + StyleSetSize(1,size); + StyleSetForeground(1,Options.AsColour(_T("Syntax Highlight Brackets"))); + + // Slashes/Parenthesis/Comma style + StyleSetFont(2,font); + StyleSetSize(2,size); + StyleSetForeground(2,Options.AsColour(_T("Syntax Highlight Slashes"))); + + // Tags style + StyleSetFont(3,font); + StyleSetSize(3,size); + StyleSetBold(3,true); + StyleSetForeground(3,Options.AsColour(_T("Syntax Highlight Tags"))); + + // Error style + StyleSetFont(4,font); + StyleSetSize(4,size); + StyleSetForeground(4,Options.AsColour(_T("Syntax Highlight Error"))); + + // Tag Number Parameters style + StyleSetFont(5,font); + StyleSetSize(5,size); + StyleSetForeground(5,Options.AsColour(_T("Syntax Highlight Numbers"))); + + // Set spellchecker + spellchecker = SpellChecker::GetSpellChecker(); +} + + +////////////// +// Destructor +SubsTextEditCtrl::~SubsTextEditCtrl() { + delete spellchecker; + spellchecker = NULL; +} + + +///////////////// +// Style a range +void SubsTextEditCtrl::UpdateStyle(int start, int _length) { + // Styling enabled? + if (Options.AsBool(_T("Syntax Highlight Enabled")) == 0) return; + + // Set variables + wxString text = GetText(); + int len = _length; + if (len < 0) len = text.Length(); + + // Begin styling + StartStyling(0,31); + int ran = 0; + int depth = 0; + int curStyle = 0; + wxChar curChar = 0; + wxChar prevChar = 0; + + // Loop through + for (int i=start;i 1) { + SetStyling(ran,curStyle); + ran = 0; + curStyle = 4; + } + + // Start override block + if (curChar == _T('{') && depth >= 0) { + SetStyling(ran,curStyle); + ran = 0; + depth++; + if (depth == 1) curStyle = 1; + else curStyle = 4; + } + + // End override block + else if (curChar == _T('}') && depth <= 1) { + SetStyling(ran,curStyle); + ran = 0; + depth--; + if (depth == 0) curStyle = 1; + else curStyle = 4; + } + + // Outside + else if (depth == 0 && curStyle != 0) { + SetStyling(ran,curStyle); + ran = 0; + curStyle = 0; + } + + // Inside + else if (depth == 1) { + // Special character + if (curChar == _T('\\') || curChar == _T('(') || curChar == _T(')') || curChar == _T(',')) { + if (curStyle != 2) { + SetStyling(ran,curStyle); + ran = 0; + curStyle = 2; + } + } + + // Number + else if ((curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&')) { + if (curStyle != 5) { + SetStyling(ran,curStyle); + ran = 0; + curStyle = 5; + } + } + + // Tag name + else if (curStyle != 3) { + SetStyling(ran,curStyle); + ran = 0; + curStyle = 3; + } + } + + // Increase ran length + ran++; + } + SetStyling(ran,curStyle); +} + + +/////////////////////////// +// Set text to a new value +void SubsTextEditCtrl::SetTextTo(const wxString _text) { + // Setup + control->textEditReady = false; + Freeze(); + wxString text = _text; + text.Replace(_T("\r\n"),_T("\\N")); + text.Replace(_T("\n\r"),_T("\\N")); + text.Replace(_T("\r"),_T("\\N")); + text.Replace(_T("\n"),_T("\\N")); + + // Prepare + int from=0,to=0; + GetSelection(&from,&to); + Clear(); + + // Set text + SetText(text); + + // Style + UpdateStyle(); + + // Restore selection + SetSelection(from,to); + + // Finish + Thaw(); + control->textEditReady = true; +} + + +/////////////////////// +// Control event table +BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxScintilla) + EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent) +END_EVENT_TABLE() + + +/////////////// +// Mouse event +void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) { + // Right click + if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) { + if (control->linen >= 0) { + // Popup + wxMenu menu; + menu.Append(EDIT_MENU_UNDO,_("&Undo"))->Enable(CanUndo()); + menu.AppendSeparator(); + menu.Append(EDIT_MENU_CUT,_("Cu&t"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0); + menu.Append(EDIT_MENU_COPY,_("&Copy"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0); + menu.Append(EDIT_MENU_PASTE,_("&Paste"))->Enable(CanPaste()); + menu.AppendSeparator(); + menu.Append(EDIT_MENU_SELECT_ALL,_("Select &All")); + menu.AppendSeparator(); + menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)")); + menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)")); + PopupMenu(&menu); + return; + } + } + + event.Skip(); +} diff --git a/core/subs_edit_ctrl.h b/core/subs_edit_ctrl.h new file mode 100644 index 000000000..0d483dfde --- /dev/null +++ b/core/subs_edit_ctrl.h @@ -0,0 +1,69 @@ +// Copyright (c) 2005, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +//////////// +// Includes +#include +#include +#include "spellchecker.h" + + +////////////// +// Prototypes +class SubsEditBox; + + +//////////////////// +// SubsTextEditCtrl +class SubsTextEditCtrl : public wxScintilla { +private: + SpellChecker *spellchecker; + void OnMouseEvent(wxMouseEvent &event); + +public: + SubsEditBox *control; + + SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr); + ~SubsTextEditCtrl(); + + void SetTextTo(const wxString text); + void UpdateStyle(int start=0,int length=-1); + + DECLARE_EVENT_TABLE() +};