From 13f052317e6b1caa9e25d85c5318dff735613a2e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 7 Dec 2010 19:09:15 +0000 Subject: [PATCH] Convert OptionValue over to agi::signal Originally committed to SVN as r4899. --- .../libaegisub_vs2008.vcproj | 4 -- aegisub/libaegisub/common/option_value.cpp | 45 ------------------- .../include/libaegisub/option_value.h | 24 +++------- aegisub/src/base_grid.cpp | 33 +++++++------- aegisub/src/frame_main.cpp | 10 ++--- aegisub/src/main.h | 2 +- aegisub/src/subs_edit_ctrl.cpp | 28 ++++++------ aegisub/src/video_context.cpp | 15 +++---- aegisub/src/video_context.h | 1 - aegisub/src/video_slider.cpp | 3 +- aegisub/src/video_slider.h | 10 ----- 11 files changed, 48 insertions(+), 127 deletions(-) delete mode 100644 aegisub/libaegisub/common/option_value.cpp diff --git a/aegisub/build/libaegisub_vs2008/libaegisub_vs2008.vcproj b/aegisub/build/libaegisub_vs2008/libaegisub_vs2008.vcproj index a6f8013ac..4eefbdc4b 100644 --- a/aegisub/build/libaegisub_vs2008/libaegisub_vs2008.vcproj +++ b/aegisub/build/libaegisub_vs2008/libaegisub_vs2008.vcproj @@ -287,10 +287,6 @@ RelativePath="..\..\libaegisub\common\option.cpp" > - - diff --git a/aegisub/libaegisub/common/option_value.cpp b/aegisub/libaegisub/common/option_value.cpp deleted file mode 100644 index 7f5984401..000000000 --- a/aegisub/libaegisub/common/option_value.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2010, Niels M Hansen -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -// -// $Id$ - -/// @file option_value.cpp -/// @brief Container for holding an actual option value. -/// @ingroup libaegisub - -#ifndef LAGI_PRE -#include -#endif - -#include "libaegisub/option_value.h" - -namespace agi { - -void OptionValue::NotifyChanged() { - for (ChangeListenerSet::const_iterator nfcb = listeners.begin(); nfcb != listeners.end(); ++nfcb) { - nfcb->second(*this); - } -} - -void OptionValue::Subscribe(void *key, ChangeListener listener) { - assert(listeners.find(key) == listeners.end()); - listeners[key] = listener; -} - -void OptionValue::Unsubscribe(void *key) { - assert(listeners.find(key) != listeners.end()); - listeners.erase(key); -} - -} diff --git a/aegisub/libaegisub/include/libaegisub/option_value.h b/aegisub/libaegisub/include/libaegisub/option_value.h index 080cdb6d2..8e0016480 100644 --- a/aegisub/libaegisub/include/libaegisub/option_value.h +++ b/aegisub/libaegisub/include/libaegisub/option_value.h @@ -18,22 +18,17 @@ /// @brief Container for holding an actual option value. /// @ingroup libaegisub -#ifndef LAGI_PRE +#if !defined(AGI_PRE) && !defined(LAGI_PRE) #include #include #include #include - -#ifdef _WIN32 -#include -#else -#include -#endif #endif -#include #include +#include +#include namespace agi { @@ -49,15 +44,9 @@ class ConfigVisitor; /// @class OptionValue /// Holds an actual option. class OptionValue { -public: - typedef std::tr1::function ChangeListener; - -private: - typedef std::map ChangeListenerSet; - ChangeListenerSet listeners; - + agi::signal::Signal ValueChanged; protected: - void NotifyChanged(); + void NotifyChanged() { ValueChanged(*this); } OptionValueErrorInvalidType TypeError(std::string type, std::string op = " retrieve ") const { return OptionValueErrorInvalidType("Attempt to" + op + type + " with non-" + type + " value " + GetName()); @@ -129,8 +118,7 @@ public: virtual void GetDefaultListBool(std::vector &out) const { throw ListTypeError("string"); } - void Subscribe(void *key, ChangeListener listener); - void Unsubscribe(void *key); + DEFINE_SIGNAL_ADDERS(ValueChanged, Subscribe); }; #define CONFIG_OPTIONVALUE(type_name, type) \ diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 748908c6e..b292ac62e 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -106,24 +106,23 @@ BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wx // Set style UpdateStyle(); - agi::OptionValue::ChangeListener UpdateStyle(std::tr1::bind(&BaseGrid::UpdateStyle, this)); - OPT_SUB("Subtitle/Grid/Font Face", this, UpdateStyle); - OPT_SUB("Subtitle/Grid/Font Size", this, UpdateStyle); + OPT_SUB("Subtitle/Grid/Font Face", &BaseGrid::UpdateStyle, this); + OPT_SUB("Subtitle/Grid/Font Size", &BaseGrid::UpdateStyle, this); - agi::OptionValue::ChangeListener Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL)); - OPT_SUB("Colour/Subtitle Grid/Active Border", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Background/Background", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Background/Comment", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Background/Inframe", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Background/Selection", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Collision", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Header", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Left Column", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Lines", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Selection", this, Refresh); - OPT_SUB("Colour/Subtitle Grid/Standard", this, Refresh); - OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", this, Refresh); + std::tr1::function Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL)); + OPT_SUB("Colour/Subtitle Grid/Active Border", Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Background", Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Comment", Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Inframe", Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", Refresh); + OPT_SUB("Colour/Subtitle Grid/Background/Selection", Refresh); + OPT_SUB("Colour/Subtitle Grid/Collision", Refresh); + OPT_SUB("Colour/Subtitle Grid/Header", Refresh); + OPT_SUB("Colour/Subtitle Grid/Left Column", Refresh); + OPT_SUB("Colour/Subtitle Grid/Lines", Refresh); + OPT_SUB("Colour/Subtitle Grid/Selection", Refresh); + OPT_SUB("Colour/Subtitle Grid/Standard", Refresh); + OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh); } diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 69b83088f..6f410ce61 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -91,7 +91,7 @@ #define StartupLog(a) #endif -static void autosave_timer_changed(wxTimer &timer, const agi::OptionValue &opt); +static void autosave_timer_changed(wxTimer *timer, const agi::OptionValue &opt); FrameMain::FrameMain (wxArrayString args) : wxFrame ((wxFrame*)NULL,-1,_T(""),wxDefaultPosition,wxSize(920,700),wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN) @@ -167,7 +167,7 @@ FrameMain::FrameMain (wxArrayString args) if (time > 0) { AutoSave.Start(time*1000); } - OPT_SUB("App/Auto/Save Every Seconds", this, std::tr1::bind(autosave_timer_changed, std::tr1::ref(AutoSave), std::tr1::placeholders::_1)); + OPT_SUB("App/Auto/Save Every Seconds", autosave_timer_changed, &AutoSave, agi::signal::_1); // Set accelerator keys StartupLog(_T("Install hotkeys")); @@ -1337,12 +1337,12 @@ bool FrameMain::HasASSDraw() { #endif } -static void autosave_timer_changed(wxTimer &timer, const agi::OptionValue &opt) { +static void autosave_timer_changed(wxTimer *timer, const agi::OptionValue &opt) { int freq = opt.GetInt(); if (freq <= 0) { - timer.Stop(); + timer->Stop(); } else { - timer.Start(freq * 1000); + timer->Start(freq * 1000); } } diff --git a/aegisub/src/main.h b/aegisub/src/main.h index 4f1816a0c..52770954a 100644 --- a/aegisub/src/main.h +++ b/aegisub/src/main.h @@ -69,7 +69,7 @@ namespace config { namespace Automation4 { class AutoloadScriptManager; } /// Macro to get OptionValue object. -#define OPT_GET(x) const_cast(config::opt->Get(x)) +#define OPT_GET(x) const_cast(config::opt->Get(x)) /// Macro to set OptionValue object. #define OPT_SET(x) config::opt->Get(x) diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index e8a3c831b..829157092 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -181,23 +181,21 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, S Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this); - agi::OptionValue::ChangeListener SetStyles = bind(&SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Subtitle/Edit Box/Font Face", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Subtitle/Edit Box/Font Size", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Normal", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Brackets", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Slashes", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Highlight Tags", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Error", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Background/Error", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Parameters", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Line Break", &SubsTextEditCtrl::SetStyles, this); + OPT_SUB("Colour/Subtitle/Syntax/Karaoke Template", &SubsTextEditCtrl::SetStyles, this); - OPT_SUB("Subtitle/Edit Box/Font Face", this, SetStyles); - OPT_SUB("Subtitle/Edit Box/Font Size", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Normal", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Brackets", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Slashes", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Highlight Tags", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Error", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Background/Error", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Parameters", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Line Break", this, SetStyles); - OPT_SUB("Colour/Subtitle/Syntax/Karaoke Template", this, SetStyles); - - OPT_SUB("Subtitle/Highlight/Syntax", this, bind(&SubsTextEditCtrl::UpdateStyle, this, 0, -1)); + OPT_SUB("Subtitle/Highlight/Syntax", &SubsTextEditCtrl::UpdateStyle, this, 0, -1); static wxStyledTextEvent evt; - OPT_SUB("App/Call Tips", this, bind(&SubsTextEditCtrl::UpdateCallTip, this, ref(evt))); + OPT_SUB("App/Call Tips", &SubsTextEditCtrl::UpdateCallTip, this, ref(evt)); } diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index d8b35a4ce..5e2a6e4aa 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -109,16 +109,15 @@ VideoContext::VideoContext() Bind(EVT_VIDEO_ERROR, &VideoContext::OnVideoError, this); Bind(EVT_SUBTITLES_ERROR, &VideoContext::OnSubtitlesError, this); - agi::OptionValue::ChangeListener providerChanged(std::tr1::bind(&VideoContext::Reload, this)); - OPT_SUB("Subtitle/Provider", this, providerChanged); - OPT_SUB("Video/Provider", this, providerChanged); + OPT_SUB("Subtitle/Provider", &VideoContext::Reload, this); + OPT_SUB("Video/Provider", &VideoContext::Reload, this); // It would be nice to find a way to move these to the individual providers - OPT_SUB("Provider/Avisynth/Allow Ancient", this, providerChanged); - OPT_SUB("Provider/Avisynth/Memory Max", this, providerChanged); + OPT_SUB("Provider/Avisynth/Allow Ancient", &VideoContext::Reload, this); + OPT_SUB("Provider/Avisynth/Memory Max", &VideoContext::Reload, this); - OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", this, providerChanged); - OPT_SUB("Provider/Video/FFmpegSource/Unsafe Seeking", this, providerChanged); + OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", &VideoContext::Reload, this); + OPT_SUB("Provider/Video/FFmpegSource/Unsafe Seeking", &VideoContext::Reload, this); } VideoContext::~VideoContext () { @@ -126,8 +125,6 @@ VideoContext::~VideoContext () { delete audio->provider; delete audio->player; } - // Don't unsubscribe from option change notifications as the options object - // might not even exist anymore } VideoContext *VideoContext::Get() { diff --git a/aegisub/src/video_context.h b/aegisub/src/video_context.h index 42576862d..b732644e9 100644 --- a/aegisub/src/video_context.h +++ b/aegisub/src/video_context.h @@ -76,7 +76,6 @@ class VideoContext : public wxEvtHandler { friend class AudioProvider; friend class KeyFrameFile; -private: /// DOCME std::list displayList; diff --git a/aegisub/src/video_slider.cpp b/aegisub/src/video_slider.cpp index 673074bba..53ff1b836 100644 --- a/aegisub/src/video_slider.cpp +++ b/aegisub/src/video_slider.cpp @@ -73,11 +73,10 @@ VideoSlider::VideoSlider (wxWindow* parent, wxWindowID id) SetMinSize(wxSize(20, 25)); locked = false; SetRange(0,1); - OPT_SUB("Video/Slider/Show Keyframes", this, std::tr1::bind(&wxWindow::Refresh, this, false, (wxRect*)NULL)); + OPT_SUB("Video/Slider/Show Keyframes", &wxWindow::Refresh, this, false, (wxRect*)NULL); } VideoSlider::~VideoSlider() { - OPT_UNSUB("Video/Slider/Show Keyframes", this); } /// @brief Set value diff --git a/aegisub/src/video_slider.h b/aegisub/src/video_slider.h index 83138c8c6..c127ebbce 100644 --- a/aegisub/src/video_slider.h +++ b/aegisub/src/video_slider.h @@ -34,23 +34,13 @@ /// @ingroup custom_control /// - - - -//////////// -// Includes #ifndef AGI_PRE #include #endif - -//////////////////// -// Class prototypes class VideoDisplay; class SubtitlesGrid; - - /// DOCME /// @class VideoSlider /// @brief DOCME