2013-10-14 21:11:50 +02:00
|
|
|
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2013-10-14 21:11:50 +02:00
|
|
|
// 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.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2013-10-14 21:11:50 +02:00
|
|
|
// 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.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2013-01-11 18:35:39 +01:00
|
|
|
#include <libaegisub/exception.h>
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <string>
|
|
|
|
|
2013-01-11 18:35:39 +01:00
|
|
|
#include <wx/radiobox.h>
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/validate.h>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class IntValidator final : public wxValidator {
|
2013-10-14 21:11:50 +02:00
|
|
|
int value;
|
|
|
|
bool allow_negative;
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
bool CheckCharacter(int chr, bool is_first) const;
|
|
|
|
void OnChar(wxKeyEvent& event);
|
2007-06-17 23:12:28 +02:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
bool Validate(wxWindow *) override { return true; }
|
|
|
|
wxObject* Clone() const override { return new IntValidator(*this); }
|
|
|
|
bool TransferToWindow() override;
|
|
|
|
bool TransferFromWindow() override { return true; }
|
2007-06-17 23:12:28 +02:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
IntValidator(IntValidator const& rgt);
|
2007-06-17 23:12:28 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
public:
|
2013-10-16 01:02:25 +02:00
|
|
|
explicit IntValidator(int val=0, bool allow_negative=false);
|
2013-10-14 21:11:50 +02:00
|
|
|
};
|
2011-12-22 22:23:07 +01:00
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class DoubleValidator final : public wxValidator {
|
2013-10-14 21:11:50 +02:00
|
|
|
double *value;
|
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
wxChar decimal_sep;
|
2011-12-22 22:23:07 +01:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
bool Validate(wxWindow* parent) override { return true; }
|
|
|
|
bool CheckCharacter(int chr, bool is_first, bool *got_decimal) const;
|
|
|
|
void OnChar(wxKeyEvent& event);
|
2012-01-18 23:51:17 +01:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
DoubleValidator(DoubleValidator const& rgt);
|
2011-01-20 06:57:30 +01:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
wxObject* Clone() const override { return new DoubleValidator(*this); }
|
|
|
|
bool TransferToWindow() override;
|
|
|
|
bool TransferFromWindow() override;
|
2007-06-17 23:12:28 +02:00
|
|
|
|
2013-10-14 21:11:50 +02:00
|
|
|
public:
|
|
|
|
explicit DoubleValidator(double *val, bool allow_negative=false);
|
|
|
|
explicit DoubleValidator(double *val, double min, double max);
|
2006-01-16 22:02:54 +01:00
|
|
|
};
|
2013-01-11 18:35:39 +01:00
|
|
|
|
2014-04-28 16:07:07 +02:00
|
|
|
class DoubleSpinValidator final : public wxValidator {
|
|
|
|
double *value;
|
|
|
|
wxValidator *Clone() const override { return new DoubleSpinValidator(value); }
|
|
|
|
bool Validate(wxWindow*) override { return true; }
|
|
|
|
bool TransferToWindow() override;
|
|
|
|
bool TransferFromWindow() override;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DoubleSpinValidator(double *value) : value(value) { }
|
|
|
|
};
|
|
|
|
|
2013-01-11 18:35:39 +01:00
|
|
|
template<typename T>
|
2014-03-13 02:39:07 +01:00
|
|
|
class EnumBinder final : public wxValidator {
|
2013-01-11 18:35:39 +01:00
|
|
|
T *value;
|
|
|
|
|
|
|
|
wxObject *Clone() const override { return new EnumBinder<T>(value); }
|
2014-05-16 18:20:30 +02:00
|
|
|
bool Validate(wxWindow *) override { return true; }
|
2013-01-11 18:35:39 +01:00
|
|
|
|
|
|
|
bool TransferFromWindow() override {
|
|
|
|
if (wxRadioBox *rb = dynamic_cast<wxRadioBox*>(GetWindow()))
|
|
|
|
*value = static_cast<T>(rb->GetSelection());
|
|
|
|
else
|
2013-11-21 18:13:36 +01:00
|
|
|
throw agi::InternalError("Control type not supported by EnumBinder", nullptr);
|
2013-01-11 18:35:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TransferToWindow() override {
|
|
|
|
if (wxRadioBox *rb = dynamic_cast<wxRadioBox*>(GetWindow()))
|
|
|
|
rb->SetSelection(static_cast<int>(*value));
|
|
|
|
else
|
2013-11-21 18:13:36 +01:00
|
|
|
throw agi::InternalError("Control type not supported by EnumBinder", nullptr);
|
2013-01-11 18:35:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit EnumBinder(T *value) : value(value) { }
|
2014-01-01 19:28:10 +01:00
|
|
|
EnumBinder(EnumBinder const& rhs) : wxValidator(rhs), value(rhs.value) { }
|
2013-01-11 18:35:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
EnumBinder<T> MakeEnumBinder(T *value) {
|
|
|
|
return EnumBinder<T>(value);
|
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class StringBinder final : public wxValidator {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string *value;
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
wxObject* Clone() const override { return new StringBinder(value); }
|
|
|
|
bool Validate(wxWindow*) override { return true;}
|
|
|
|
bool TransferToWindow() override;
|
|
|
|
bool TransferFromWindow() override;
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit StringBinder(std::string *value) : value(value) { }
|
|
|
|
};
|