From 561216d4c8ff0dd8c55a2ff8127b0e65051f329a Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 29 Jul 2011 23:16:55 +0000 Subject: [PATCH] Make hotkey::check take a project context and make FrameMain::context private Originally committed to SVN as r5532. --- aegisub/src/audio_box.cpp | 2 +- aegisub/src/audio_display.cpp | 6 ++-- aegisub/src/audio_display.h | 21 ++++---------- aegisub/src/base_grid.cpp | 4 +-- aegisub/src/dialog_detached_video.cpp | 2 +- aegisub/src/dialog_styling_assistant.cpp | 2 +- aegisub/src/dialog_translation.cpp | 2 +- aegisub/src/frame_main.cpp | 2 +- aegisub/src/frame_main.h | 22 +++++++-------- aegisub/src/hotkey.cpp | 16 ++--------- aegisub/src/include/aegisub/hotkey.h | 7 ++--- aegisub/src/subs_edit_box.cpp | 2 +- aegisub/src/video_display.cpp | 2 +- aegisub/src/video_slider.cpp | 35 ++++++++++++------------ aegisub/src/video_slider.h | 5 ++-- 15 files changed, 53 insertions(+), 77 deletions(-) diff --git a/aegisub/src/audio_box.cpp b/aegisub/src/audio_box.cpp index b59a21de3..0406430e7 100644 --- a/aegisub/src/audio_box.cpp +++ b/aegisub/src/audio_box.cpp @@ -95,7 +95,7 @@ static void add_option(wxWindow *parent, wxSizer *sizer, int border, const char /// AudioBox::AudioBox(wxWindow *parent, agi::Context *context) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxBORDER_RAISED) -, audioDisplay(new AudioDisplay(this, context->audioController)) +, audioDisplay(new AudioDisplay(this, context->audioController, context)) , controller(context->audioController) , timing_controller_dialogue(CreateDialogueTimingController(controller, context->selectionController, context->ass)) , context(context) diff --git a/aegisub/src/audio_display.cpp b/aegisub/src/audio_display.cpp index 857869a10..20fcc1bbb 100644 --- a/aegisub/src/audio_display.cpp +++ b/aegisub/src/audio_display.cpp @@ -54,7 +54,6 @@ #include "audio_renderer_waveform.h" #include "audio_timing.h" #include "block_cache.h" -#include "include/aegisub/audio_player.h" #include "include/aegisub/audio_provider.h" #include "include/aegisub/hotkey.h" #include "main.h" @@ -529,8 +528,9 @@ public: -AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller) +AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller, agi::Context *context) : wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxBORDER_SIMPLE) +, context(context) , audio_renderer(new AudioRenderer) , audio_spectrum_renderer(new AudioSpectrumRenderer) , audio_waveform_renderer(new AudioWaveformRenderer) @@ -1154,7 +1154,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) void AudioDisplay::OnKeyDown(wxKeyEvent& event) { - if (!hotkey::check("Audio", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) + if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) event.Skip(); event.StopPropagation(); } diff --git a/aegisub/src/audio_display.h b/aegisub/src/audio_display.h index c763b4cac..e8b605889 100644 --- a/aegisub/src/audio_display.h +++ b/aegisub/src/audio_display.h @@ -35,43 +35,31 @@ /// @ingroup audio_ui /// -#pragma once - #ifndef AGI_PRE #include #include -#include -#include -#include +#include +#include #include #endif #include #include +namespace agi { struct Context; } class AudioRenderer; class AudioSpectrumRenderer; class AudioWaveformRenderer; class AudioKaraoke; class AudioProvider; -class AudioPlayer; -class SubtitlesGrid; -class VideoProvider; - -class AudioBox; -class SubtitlesGrid; -class AssDialogue; -class wxScrollBar; // Helper classes used in implementation of the audio display class AudioDisplayScrollbar; class AudioDisplayTimeline; class AudioDisplaySelection; - - /// @class AudioDisplayInteractionObject /// @brief Interface for objects on the audio display that can respond to mouse events class AudioDisplayInteractionObject { @@ -113,6 +101,7 @@ public: class AudioDisplay: public wxWindow { private: std::list slots; + agi::Context *context; /// The audio renderer manager agi::scoped_ptr audio_renderer; @@ -209,7 +198,7 @@ private: public: - AudioDisplay(wxWindow *parent, AudioController *controller); + AudioDisplay(wxWindow *parent, AudioController *controller, agi::Context *context); ~AudioDisplay(); diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index add770304..7085e5ece 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -909,7 +909,7 @@ bool BaseGrid::IsDisplayed(const AssDialogue *line) const { void BaseGrid::OnKeyDown(wxKeyEvent &event) { event.StopPropagation(); - if (hotkey::check("Subtitle Grid", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) + if (hotkey::check("Subtitle Grid", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) return; int w,h; @@ -983,7 +983,7 @@ void BaseGrid::OnKeyDown(wxKeyEvent &event) { return; } } - else if (!hotkey::check("Audio", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) { + else if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) { event.Skip(); } } diff --git a/aegisub/src/dialog_detached_video.cpp b/aegisub/src/dialog_detached_video.cpp index 64563a9c3..f7a4b482a 100644 --- a/aegisub/src/dialog_detached_video.cpp +++ b/aegisub/src/dialog_detached_video.cpp @@ -119,7 +119,7 @@ void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) { void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) { evt.StopPropagation(); - hotkey::check("Video Display", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers()); + hotkey::check("Video Display", context, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers()); } void DialogDetachedVideo::OnVideoOpen() { diff --git a/aegisub/src/dialog_styling_assistant.cpp b/aegisub/src/dialog_styling_assistant.cpp index 38b634b4d..107b3c876 100644 --- a/aegisub/src/dialog_styling_assistant.cpp +++ b/aegisub/src/dialog_styling_assistant.cpp @@ -256,7 +256,7 @@ void DialogStyling::OnPlayAudioButton(wxCommandEvent &) { } void DialogStyling::OnKeyDown(wxKeyEvent &evt) { - if (!hotkey::check("Styling Assistant", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) { + if (!hotkey::check("Styling Assistant", c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) { // Move the beginning of the selection back one character so that backspace // actually does something if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) { diff --git a/aegisub/src/dialog_translation.cpp b/aegisub/src/dialog_translation.cpp index 1de3705ad..bf3c11d9f 100644 --- a/aegisub/src/dialog_translation.cpp +++ b/aegisub/src/dialog_translation.cpp @@ -254,7 +254,7 @@ void DialogTranslation::InsertOriginal() { void DialogTranslation::OnKeyDown(wxKeyEvent &evt) { - if (!hotkey::check("Translation Assistant", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) + if (!hotkey::check("Translation Assistant", c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) evt.Skip(); evt.StopPropagation(); } diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index c577da6d7..9d17e7e82 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -1048,6 +1048,6 @@ void FrameMain::OnSubtitlesSave() { } void FrameMain::OnKeyDown(wxKeyEvent &event) { - if (!hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) + if (!hotkey::check("Main Frame", context.get(), event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) event.Skip(); } diff --git a/aegisub/src/frame_main.h b/aegisub/src/frame_main.h index 8f5f6a345..4b82e194f 100644 --- a/aegisub/src/frame_main.h +++ b/aegisub/src/frame_main.h @@ -74,20 +74,8 @@ namespace Automation4 { class FeatureMacro; class ScriptManager; } class FrameMain: public wxFrame { friend class AegisubFileDropTarget; -public: - /// Set the status bar text - /// @param text New status bar text - /// @param ms Time in milliseconds that the message should be visible - void StatusTimeout(wxString text,int ms=10000); - /// @brief Set the video and audio display visibility - /// @param video -1: leave unchanged; 0: hide; 1: show - /// @param audio -1: leave unchanged; 0: hide; 1: show - void SetDisplayMode(int showVid, int showAudio); - void LoadSubtitles(wxString filename,wxString charset=""); - agi::scoped_ptr context; -private: // XXX: Make Freeze()/Thaw() noops on GTK, this seems to be buggy #ifdef __WXGTK__ void Freeze(void) {} @@ -160,5 +148,15 @@ public: bool HasASSDraw(); + /// Set the status bar text + /// @param text New status bar text + /// @param ms Time in milliseconds that the message should be visible + void StatusTimeout(wxString text,int ms=10000); + /// @brief Set the video and audio display visibility + /// @param video -1: leave unchanged; 0: hide; 1: show + /// @param audio -1: leave unchanged; 0: hide; 1: show + void SetDisplayMode(int showVid,int showAudio); + void LoadSubtitles(wxString filename,wxString charset=""); + DECLARE_EVENT_TABLE() }; diff --git a/aegisub/src/hotkey.cpp b/aegisub/src/hotkey.cpp index 05858d23e..f0e13e3c4 100644 --- a/aegisub/src/hotkey.cpp +++ b/aegisub/src/hotkey.cpp @@ -20,22 +20,12 @@ #include "config.h" -#ifndef AGI_PRE -#include - -#include -#include -#endif - -#include #include #include "include/aegisub/hotkey.h" -#include "include/aegisub/toolbar.h" #include "libresrc/libresrc.h" #include "command/command.h" -#include "frame_main.h" #include "main.h" namespace hotkey { @@ -57,7 +47,7 @@ static std::string const& keycode_name(int code) { return keycode_names[code]; } -bool check(std::string const& context, int key_code, wchar_t key_char, int modifier) { +bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier) { std::string combo; if ((modifier != wxMOD_NONE)) { if ((modifier & wxMOD_CMD) != 0) combo.append("Ctrl-"); @@ -73,7 +63,7 @@ bool check(std::string const& context, int key_code, wchar_t key_char, int modif /// The bottom line should be removed after all the hotkey commands are fixed. /// This is to avoid pointless exceptions. if (command.find("/") != std::string::npos) { - (*cmd::get(command))(wxGetApp().frame->context.get()); + (*cmd::get(command))(c); return true; } } @@ -187,5 +177,5 @@ static void init_keycode_names() { } -} // namespace toolbar +} // namespace hotkey diff --git a/aegisub/src/include/aegisub/hotkey.h b/aegisub/src/include/aegisub/hotkey.h index 72f510683..b04e59cbc 100644 --- a/aegisub/src/include/aegisub/hotkey.h +++ b/aegisub/src/include/aegisub/hotkey.h @@ -19,16 +19,15 @@ /// @ingroup hotkey menu event window #ifndef AGI_PRE -#include - -#include #include #include #endif +namespace agi { struct Context; } + namespace hotkey { -bool check(std::string const& context, int key_code, wchar_t key_char, int modifier); +bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier); std::string get_hotkey_str_first(std::string const& context, std::string const& command); std::vector get_hotkey_strs(std::string const& context, std::string const& command); diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 4e029fe69..713a9575c 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -424,7 +424,7 @@ void SubsEditBox::UpdateFrameTiming(agi::vfr::Framerate const& fps) { void SubsEditBox::OnKeyDown(wxKeyEvent &event) { event.StopPropagation(); - if (hotkey::check("Subtitle Edit Box", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) + if (hotkey::check("Subtitle Edit Box", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) return; int key = event.GetKeyCode(); diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 05e0e6a62..ddd64f31d 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -464,7 +464,7 @@ void VideoDisplay::OnKeyDown(wxKeyEvent &event) { else if (kc == 'J') SetMode(Video_Mode_Vector_Clip); else { event.StopPropagation(); - if (hotkey::check("Video Display", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) + if (hotkey::check("Video Display", con, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) return; } } diff --git a/aegisub/src/video_slider.cpp b/aegisub/src/video_slider.cpp index fa659a35f..f5a5c45b5 100644 --- a/aegisub/src/video_slider.cpp +++ b/aegisub/src/video_slider.cpp @@ -50,19 +50,18 @@ VideoSlider::VideoSlider (wxWindow* parent, agi::Context *c) : wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE) -, vc(c->videoController) -, grid(c->subsGrid) +, c(c) , val(0) , max(1) { SetClientSize(20,25); SetMinSize(wxSize(20, 25)); slots.push_back(OPT_SUB("Video/Slider/Show Keyframes", &wxWindow::Refresh, this, false, (wxRect*)NULL)); - slots.push_back(vc->AddSeekListener(&VideoSlider::SetValue, this)); - slots.push_back(vc->AddVideoOpenListener(&VideoSlider::VideoOpened, this)); - slots.push_back(vc->AddKeyframesListener(&VideoSlider::KeyframesChanged, this)); + slots.push_back(c->videoController->AddSeekListener(&VideoSlider::SetValue, this)); + slots.push_back(c->videoController->AddVideoOpenListener(&VideoSlider::VideoOpened, this)); + slots.push_back(c->videoController->AddKeyframesListener(&VideoSlider::KeyframesChanged, this)); - if (vc->IsLoaded()) { + if (c->videoController->IsLoaded()) { VideoOpened(); } } @@ -74,8 +73,8 @@ void VideoSlider::SetValue(int value) { } void VideoSlider::VideoOpened() { - max = vc->GetLength() - 1; - keyframes = vc->GetKeyFrames(); + max = c->videoController->GetLength() - 1; + keyframes = c->videoController->GetKeyFrames(); Refresh(false); } @@ -143,13 +142,13 @@ void VideoSlider::OnMouse(wxMouseEvent &event) { SetValue(go); } - if (vc->IsPlaying()) { - vc->Stop(); - vc->JumpToFrame(val); - vc->Play(); + if (c->videoController->IsPlaying()) { + c->videoController->Stop(); + c->videoController->JumpToFrame(val); + c->videoController->Play(); } else - vc->JumpToFrame(val); + c->videoController->JumpToFrame(val); SetFocus(); return; } @@ -158,20 +157,20 @@ void VideoSlider::OnMouse(wxMouseEvent &event) { SetFocus(); } - else if (!vc->IsPlaying()) + else if (!c->videoController->IsPlaying()) event.Skip(); } void VideoSlider::OnKeyDown(wxKeyEvent &event) { - if (vc->IsPlaying()) return; + if (c->videoController->IsPlaying()) return; - if (hotkey::check("Video", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) + if (hotkey::check("Video", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) return; // Forward up/down to grid if (event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN) { - grid->GetEventHandler()->ProcessEvent(event); - grid->SetFocus(); + c->subsGrid->GetEventHandler()->ProcessEvent(event); + c->subsGrid->SetFocus(); return; } diff --git a/aegisub/src/video_slider.h b/aegisub/src/video_slider.h index 442bf6899..45862dd0c 100644 --- a/aegisub/src/video_slider.h +++ b/aegisub/src/video_slider.h @@ -42,6 +42,8 @@ #include +namespace agi { struct Context; } + class VideoContext; class SubtitlesGrid; @@ -51,8 +53,7 @@ class SubtitlesGrid; /// /// DOCME class VideoSlider: public wxWindow { - VideoContext *vc; ///< Video controller - SubtitlesGrid *grid; ///< temp hack; remove this once event forwarding is killed + agi::Context *c; std::vector keyframes; ///< Currently loaded keyframes std::vector slots;