2010-07-19 19:53:29 +02:00
|
|
|
// Copyright (c) 2010, Amar Takhar <verm@aegisub.org>
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
/// @file preferences_base.cpp
|
|
|
|
/// @brief Base preferences dialogue classes
|
|
|
|
/// @ingroup configuration_ui
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef AGI_PRE
|
2011-10-11 02:06:44 +02:00
|
|
|
#include <wx/any.h>
|
2010-07-19 19:53:29 +02:00
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/combobox.h>
|
2011-10-28 22:15:10 +02:00
|
|
|
#include <wx/dirdlg.h>
|
2011-10-11 02:06:44 +02:00
|
|
|
#include <wx/event.h>
|
2010-07-19 19:53:29 +02:00
|
|
|
#include <wx/filefn.h>
|
2011-10-11 02:06:44 +02:00
|
|
|
#include <wx/fontdlg.h>
|
|
|
|
#include <wx/listctrl.h>
|
2010-07-19 19:53:29 +02:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/spinctrl.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/stdpaths.h>
|
|
|
|
#include <wx/treebook.h>
|
2011-10-11 02:06:44 +02:00
|
|
|
#include <wx/treebook.h>
|
2010-07-19 19:53:29 +02:00
|
|
|
#endif
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
#include "preferences_base.h"
|
|
|
|
|
2010-07-19 19:53:29 +02:00
|
|
|
#include "colour_button.h"
|
|
|
|
#include "compat.h"
|
2010-08-02 08:31:38 +02:00
|
|
|
#include "include/aegisub/audio_player.h"
|
|
|
|
#include "include/aegisub/audio_provider.h"
|
2011-10-11 02:06:44 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "preferences.h"
|
|
|
|
#include "standard_paths.h"
|
2010-07-19 19:53:29 +02:00
|
|
|
#include "video_provider_manager.h"
|
|
|
|
|
2012-02-28 02:22:40 +01:00
|
|
|
#define OPTION_UPDATER(type, evttype, opt, body) \
|
|
|
|
class type { \
|
|
|
|
std::string name; \
|
|
|
|
Preferences *parent; \
|
|
|
|
public: \
|
|
|
|
type(std::string const& n, Preferences *p) : name(n), parent(p) { } \
|
|
|
|
void operator()(evttype& evt) { \
|
|
|
|
evt.Skip(); \
|
|
|
|
parent->SetOption(new agi::opt(name, body)); \
|
|
|
|
} \
|
2010-08-26 20:38:20 +02:00
|
|
|
}
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2011-12-24 01:36:19 +01:00
|
|
|
OPTION_UPDATER(StringUpdater, wxCommandEvent, OptionValueString, STD_STR(evt.GetString()));
|
|
|
|
OPTION_UPDATER(IntUpdater, wxSpinEvent, OptionValueInt, evt.GetInt());
|
|
|
|
OPTION_UPDATER(IntCBUpdater, wxCommandEvent, OptionValueInt, evt.GetInt());
|
|
|
|
OPTION_UPDATER(DoubleUpdater, wxSpinEvent, OptionValueDouble, evt.GetInt());
|
|
|
|
OPTION_UPDATER(BoolUpdater, wxCommandEvent, OptionValueBool, !!evt.GetInt());
|
2010-08-26 20:38:20 +02:00
|
|
|
class ColourUpdater {
|
|
|
|
const char *name;
|
|
|
|
Preferences *parent;
|
|
|
|
public:
|
|
|
|
ColourUpdater(const char *n = "", Preferences *p = NULL) : name(n), parent(p) { }
|
|
|
|
void operator()(wxCommandEvent& evt) {
|
|
|
|
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
|
2012-02-28 02:22:40 +01:00
|
|
|
if (btn)
|
2012-10-26 16:09:14 +02:00
|
|
|
parent->SetOption(new agi::OptionValueColor(name, btn->GetColor()));
|
2012-02-28 02:22:40 +01:00
|
|
|
evt.Skip();
|
2010-08-26 20:38:20 +02:00
|
|
|
}
|
|
|
|
};
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
static void browse_button(wxTextCtrl *ctrl) {
|
2012-01-08 02:34:37 +01:00
|
|
|
wxString def = StandardPaths::DecodePath(ctrl->GetValue());
|
2011-10-11 02:06:44 +02:00
|
|
|
wxDirDialog dlg(0, _("Please choose the folder:"), def);
|
|
|
|
if (dlg.ShowModal() == wxID_OK) {
|
2012-01-08 02:34:37 +01:00
|
|
|
wxString dir = dlg.GetPath();
|
2011-10-11 02:06:44 +02:00
|
|
|
if (!dir.empty())
|
|
|
|
ctrl->SetValue(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void font_button(Preferences *parent, wxTextCtrl *name, wxSpinCtrl *size) {
|
|
|
|
wxFont font;
|
|
|
|
font.SetFaceName(name->GetValue());
|
|
|
|
font.SetPointSize(size->GetValue());
|
|
|
|
font = wxGetFontFromUser(parent, font);
|
|
|
|
if (font.IsOk()) {
|
|
|
|
name->SetValue(font.GetFaceName());
|
2012-01-20 16:14:41 +01:00
|
|
|
size->SetValue(font.GetPointSize());
|
|
|
|
// wxGTK doesn't generate wxEVT_COMMAND_SPINCTRL_UPDATED from SetValue
|
|
|
|
wxSpinEvent evt(wxEVT_COMMAND_SPINCTRL_UPDATED);
|
|
|
|
evt.SetInt(font.GetPointSize());
|
|
|
|
size->ProcessWindowEvent(evt);
|
2011-10-11 02:06:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-26 20:38:20 +02:00
|
|
|
OptionPage::OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style)
|
2011-10-11 02:06:44 +02:00
|
|
|
: wxScrolled<wxPanel>(book, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL)
|
2011-12-26 23:20:49 +01:00
|
|
|
, sizer(new wxBoxSizer(wxVERTICAL))
|
2010-08-26 20:38:20 +02:00
|
|
|
, parent(parent)
|
|
|
|
{
|
2011-10-11 02:06:44 +02:00
|
|
|
if (style & PAGE_SUB)
|
2010-07-19 19:53:29 +02:00
|
|
|
book->AddSubPage(this, name, true);
|
2011-10-11 02:06:44 +02:00
|
|
|
else
|
2010-07-19 19:53:29 +02:00
|
|
|
book->AddPage(this, name, true);
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
if (style & PAGE_SCROLL)
|
2010-07-19 19:53:29 +02:00
|
|
|
SetScrollbars(0, 20, 0, 50);
|
2011-10-11 02:06:44 +02:00
|
|
|
else
|
2010-07-19 19:53:29 +02:00
|
|
|
SetScrollbars(0, 0, 0, 0);
|
2012-01-20 16:14:47 +01:00
|
|
|
DisableKeyboardScrolling();
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
template<class T>
|
|
|
|
void OptionPage::Add(wxSizer *sizer, wxString const& label, T *control) {
|
2012-05-15 16:07:14 +02:00
|
|
|
sizer->Add(new wxStaticText(this, -1, label), 1, wxALIGN_CENTRE_VERTICAL);
|
2011-11-16 22:59:39 +01:00
|
|
|
sizer->Add(control, wxSizerFlags().Expand());
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
void OptionPage::CellSkip(wxFlexGridSizer *flex) {
|
2012-04-27 21:07:36 +02:00
|
|
|
flex->AddStretchSpacer();
|
2011-10-11 02:06:44 +02:00
|
|
|
}
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2012-02-28 02:22:40 +01:00
|
|
|
wxControl *OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, double min, double max, double inc) {
|
2012-04-11 05:43:08 +02:00
|
|
|
parent->AddChangeableOption(opt_name);
|
2010-11-08 06:08:24 +01:00
|
|
|
const agi::OptionValue *opt = OPT_GET(opt_name);
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
switch (opt->GetType()) {
|
2010-07-19 19:53:29 +02:00
|
|
|
case agi::OptionValue::Type_Bool: {
|
2011-10-11 02:06:44 +02:00
|
|
|
wxCheckBox *cb = new wxCheckBox(this, -1, name);
|
2010-07-19 19:53:29 +02:00
|
|
|
flex->Add(cb, 1, wxEXPAND, 0);
|
|
|
|
cb->SetValue(opt->GetBool());
|
2010-08-26 20:38:20 +02:00
|
|
|
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, BoolUpdater(opt_name, parent));
|
2012-02-28 02:22:40 +01:00
|
|
|
return cb;
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
2010-08-26 20:38:20 +02:00
|
|
|
case agi::OptionValue::Type_Int: {
|
2012-05-15 15:39:50 +02:00
|
|
|
wxSpinCtrl *sc = new wxSpinCtrl(this, -1, wxString::Format("%d", (int)opt->GetInt()), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetInt());
|
2010-08-26 20:38:20 +02:00
|
|
|
sc->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, IntUpdater(opt_name, parent));
|
2011-10-11 02:06:44 +02:00
|
|
|
Add(flex, name, sc);
|
2012-02-28 02:22:40 +01:00
|
|
|
return sc;
|
2010-08-26 20:38:20 +02:00
|
|
|
}
|
2011-10-11 02:06:44 +02:00
|
|
|
|
2010-07-19 19:53:29 +02:00
|
|
|
case agi::OptionValue::Type_Double: {
|
2012-05-15 15:39:50 +02:00
|
|
|
wxSpinCtrlDouble *scd = new wxSpinCtrlDouble(this, -1, wxString::Format("%g", opt->GetDouble()), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetDouble(), inc);
|
2010-08-26 20:38:20 +02:00
|
|
|
scd->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, DoubleUpdater(opt_name, parent));
|
2011-10-11 02:06:44 +02:00
|
|
|
Add(flex, name, scd);
|
2012-02-28 02:22:40 +01:00
|
|
|
return scd;
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case agi::OptionValue::Type_String: {
|
2011-10-11 02:06:44 +02:00
|
|
|
wxTextCtrl *text = new wxTextCtrl(this, -1 , lagi_wxString(opt->GetString()));
|
2010-08-26 20:38:20 +02:00
|
|
|
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
|
2011-10-11 02:06:44 +02:00
|
|
|
Add(flex, name, text);
|
2012-02-28 02:22:40 +01:00
|
|
|
return text;
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-26 16:09:14 +02:00
|
|
|
case agi::OptionValue::Type_Color: {
|
|
|
|
ColourButton *cb = new ColourButton(this, -1, wxSize(40,10), opt->GetColor());
|
2010-08-26 20:38:20 +02:00
|
|
|
cb->Bind(wxEVT_COMMAND_BUTTON_CLICKED, ColourUpdater(opt_name, parent));
|
2011-10-11 02:06:44 +02:00
|
|
|
Add(flex, name, cb);
|
2012-02-28 02:22:40 +01:00
|
|
|
return cb;
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw PreferenceNotSupported("Unsupported type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
void OptionPage::OptionChoice(wxFlexGridSizer *flex, const wxString &name, const wxArrayString &choices, const char *opt_name) {
|
2012-04-11 05:43:08 +02:00
|
|
|
parent->AddChangeableOption(opt_name);
|
2010-11-08 06:08:24 +01:00
|
|
|
const agi::OptionValue *opt = OPT_GET(opt_name);
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
wxComboBox *cb = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY | wxCB_DROPDOWN);
|
|
|
|
Add(flex, name, cb);
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2010-08-26 20:38:20 +02:00
|
|
|
switch (opt->GetType()) {
|
2010-07-19 19:53:29 +02:00
|
|
|
case agi::OptionValue::Type_Int: {
|
2010-11-11 05:48:29 +01:00
|
|
|
int val = opt->GetInt();
|
2011-11-28 21:01:58 +01:00
|
|
|
cb->Select(val < (int)choices.size() ? val : opt->GetDefaultInt());
|
2010-08-26 20:38:20 +02:00
|
|
|
cb->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, IntCBUpdater(opt_name, parent));
|
2010-07-19 19:53:29 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-10-13 01:08:29 +02:00
|
|
|
case agi::OptionValue::Type_String: {
|
|
|
|
wxString val(lagi_wxString(opt->GetString()));
|
|
|
|
if (cb->FindString(val) != wxNOT_FOUND)
|
|
|
|
cb->SetStringSelection(val);
|
2012-05-13 02:58:11 +02:00
|
|
|
else if (!choices.empty())
|
2011-10-13 01:08:29 +02:00
|
|
|
cb->SetSelection(0);
|
2010-08-26 20:38:20 +02:00
|
|
|
cb->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, StringUpdater(opt_name, parent));
|
2010-07-19 19:53:29 +02:00
|
|
|
break;
|
2011-10-13 01:08:29 +02:00
|
|
|
}
|
2011-10-11 02:06:44 +02:00
|
|
|
|
2010-07-19 19:53:29 +02:00
|
|
|
default:
|
|
|
|
throw PreferenceNotSupported("Unsupported type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFlexGridSizer* OptionPage::PageSizer(wxString name) {
|
|
|
|
wxSizer *tmp_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, name);
|
|
|
|
sizer->Add(tmp_sizer, 0,wxEXPAND, 5);
|
|
|
|
wxFlexGridSizer *flex = new wxFlexGridSizer(2,5,5);
|
|
|
|
flex->AddGrowableCol(0,1);
|
|
|
|
tmp_sizer->Add(flex, 1, wxEXPAND, 5);
|
|
|
|
sizer->AddSpacer(8);
|
|
|
|
return flex;
|
|
|
|
}
|
|
|
|
|
2012-02-28 02:22:40 +01:00
|
|
|
void OptionPage::OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, wxControl *enabler, bool do_enable) {
|
2012-04-11 05:43:08 +02:00
|
|
|
parent->AddChangeableOption(opt_name);
|
2010-11-08 06:08:24 +01:00
|
|
|
const agi::OptionValue *opt = OPT_GET(opt_name);
|
2010-07-19 19:53:29 +02:00
|
|
|
|
|
|
|
if (opt->GetType() != agi::OptionValue::Type_String)
|
|
|
|
throw PreferenceIncorrectType("Option must be agi::OptionValue::Type_String for BrowseButton.");
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
wxTextCtrl *text = new wxTextCtrl(this, -1 , opt->GetString());
|
2012-05-15 16:06:34 +02:00
|
|
|
text->SetMinSize(wxSize(160, -1));
|
2011-10-11 02:06:44 +02:00
|
|
|
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
|
|
|
|
|
|
|
|
wxButton *browse = new wxButton(this, -1, _("Browse..."));
|
2012-09-25 01:35:27 +02:00
|
|
|
browse->Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(browse_button, text));
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
button_sizer->Add(text, wxSizerFlags(1).Expand());
|
|
|
|
button_sizer->Add(browse, wxSizerFlags().Expand());
|
2010-07-19 19:53:29 +02:00
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
Add(flex, name, button_sizer);
|
2012-02-28 02:22:40 +01:00
|
|
|
|
|
|
|
if (enabler) {
|
|
|
|
if (do_enable) {
|
|
|
|
EnableIfChecked(enabler, text);
|
|
|
|
EnableIfChecked(enabler, browse);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DisableIfChecked(enabler, text);
|
|
|
|
DisableIfChecked(enabler, browse);
|
|
|
|
}
|
|
|
|
}
|
2010-07-19 19:53:29 +02:00
|
|
|
}
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
void OptionPage::OptionFont(wxSizer *sizer, std::string opt_prefix) {
|
|
|
|
const agi::OptionValue *face_opt = OPT_GET(opt_prefix + "Font Face");
|
|
|
|
const agi::OptionValue *size_opt = OPT_GET(opt_prefix + "Font Size");
|
|
|
|
|
2012-04-11 05:43:08 +02:00
|
|
|
parent->AddChangeableOption(face_opt->GetName());
|
|
|
|
parent->AddChangeableOption(size_opt->GetName());
|
|
|
|
|
2011-10-11 02:06:44 +02:00
|
|
|
wxTextCtrl *font_name = new wxTextCtrl(this, -1, face_opt->GetString());
|
2012-05-15 16:06:34 +02:00
|
|
|
font_name->SetMinSize(wxSize(160, -1));
|
2011-10-11 02:06:44 +02:00
|
|
|
font_name->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(face_opt->GetName().c_str(), parent));
|
|
|
|
|
2012-05-18 07:03:21 +02:00
|
|
|
wxSpinCtrl *font_size = new wxSpinCtrl(this, -1, wxString::Format("%d", (int)size_opt->GetInt()), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 3, 42, size_opt->GetInt());
|
2011-10-11 02:06:44 +02:00
|
|
|
font_size->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, IntUpdater(size_opt->GetName().c_str(), parent));
|
|
|
|
|
2011-10-11 06:33:41 +02:00
|
|
|
wxButton *pick_btn = new wxButton(this, -1, _("Choose..."));
|
2012-09-25 01:35:27 +02:00
|
|
|
pick_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::bind(font_button, parent, font_name, font_size));
|
2011-10-11 02:06:44 +02:00
|
|
|
|
|
|
|
wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
button_sizer->Add(font_name, wxSizerFlags(1).Expand());
|
|
|
|
button_sizer->Add(pick_btn, wxSizerFlags().Expand());
|
|
|
|
|
|
|
|
Add(sizer, _("Font Face"), button_sizer);
|
|
|
|
Add(sizer, _("Font Size"), font_size);
|
|
|
|
}
|
2012-02-28 02:22:40 +01:00
|
|
|
|
|
|
|
struct disabler {
|
|
|
|
wxControl *ctrl;
|
|
|
|
bool enable;
|
|
|
|
|
|
|
|
disabler(wxControl *ctrl, bool enable) : ctrl(ctrl), enable(enable) { }
|
|
|
|
void operator()(wxCommandEvent &evt) {
|
|
|
|
ctrl->Enable(!!evt.GetInt() == enable);
|
|
|
|
evt.Skip();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void OptionPage::EnableIfChecked(wxControl *cbx, wxControl *ctrl) {
|
|
|
|
wxCheckBox *cb = dynamic_cast<wxCheckBox*>(cbx);
|
|
|
|
if (!cb) return;
|
|
|
|
|
|
|
|
ctrl->Enable(cb->IsChecked());
|
|
|
|
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, disabler(ctrl, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionPage::DisableIfChecked(wxControl *cbx, wxControl *ctrl) {
|
|
|
|
wxCheckBox *cb = dynamic_cast<wxCheckBox*>(cbx);
|
|
|
|
if (!cb) return;
|
|
|
|
|
|
|
|
ctrl->Enable(!cb->IsChecked());
|
|
|
|
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, disabler(ctrl, false));
|
|
|
|
}
|