2007-01-10 02:36:05 +01:00
|
|
|
// Copyright (c) 2006, 2007, Niels Martin Hansen
|
2006-12-28 22:18:35 +01:00
|
|
|
// 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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file auto4_lua_dialog.cpp
|
|
|
|
/// @brief Lua 5.1-based scripting engine (configuration-dialogue interface)
|
|
|
|
/// @ingroup scripting
|
|
|
|
///
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-03-05 00:17:07 +01:00
|
|
|
#ifdef WITH_AUTO4_LUA
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
#include "auto4_lua.h"
|
|
|
|
|
2012-02-28 02:23:24 +01:00
|
|
|
#include <cassert>
|
2008-03-05 05:10:20 +01:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
#include <wx/button.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
#include <wx/checkbox.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/combobox.h>
|
|
|
|
#include <wx/gbsizer.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/panel.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/spinctrl.h>
|
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
#include <wx/validate.h>
|
2012-03-25 06:04:59 +02:00
|
|
|
#include <wx/valgen.h>
|
2012-02-28 02:23:24 +01:00
|
|
|
#include <wx/valnum.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/window.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
|
2012-02-28 02:23:24 +01:00
|
|
|
#include <cfloat>
|
|
|
|
|
2010-06-09 01:21:39 +02:00
|
|
|
#include <libaegisub/log.h>
|
|
|
|
|
2009-05-12 17:32:11 +02:00
|
|
|
#include "ass_style.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "colour_button.h"
|
2012-01-18 21:08:42 +01:00
|
|
|
#include "compat.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "string_codec.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
// These must be after the headers above.
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#include "../../contrib/lua51/src/lualib.h"
|
|
|
|
#include "../../contrib/lua51/src/lauxlib.h"
|
|
|
|
#else
|
2011-11-08 02:18:16 +01:00
|
|
|
#include <lua.hpp>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
namespace {
|
|
|
|
inline void get_if_right_type(lua_State *L, wxString &def)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
if (lua_isstring(L, -1))
|
|
|
|
def = wxString(lua_tostring(L, -1), wxConvUTF8);
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
inline void get_if_right_type(lua_State *L, double &def)
|
|
|
|
{
|
|
|
|
if (lua_isnumber(L, -1))
|
2012-02-28 02:23:24 +01:00
|
|
|
def = lua_tonumber(L, -1);
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
inline void get_if_right_type(lua_State *L, int &def)
|
|
|
|
{
|
|
|
|
if (lua_isnumber(L, -1))
|
2012-02-28 02:23:24 +01:00
|
|
|
def = lua_tointeger(L, -1);
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
inline void get_if_right_type(lua_State *L, bool &def)
|
|
|
|
{
|
|
|
|
if (lua_isboolean(L, -1))
|
|
|
|
def = !!lua_toboolean(L, -1);
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
template<class T>
|
|
|
|
T get_field(lua_State *L, const char *name, T def)
|
|
|
|
{
|
|
|
|
lua_getfield(L, -1, name);
|
|
|
|
get_if_right_type(L, def);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pop(L, 1);
|
2011-09-28 21:49:27 +02:00
|
|
|
return def;
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
inline wxString get_field(lua_State *L, const char *name)
|
|
|
|
{
|
|
|
|
return get_field(L, name, wxString());
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
template<class T>
|
|
|
|
void read_string_array(lua_State *L, T &cont)
|
|
|
|
{
|
|
|
|
lua_pushnil(L);
|
|
|
|
while (lua_next(L, -2)) {
|
|
|
|
if (lua_isstring(L, -1))
|
|
|
|
cont.push_back(wxString(lua_tostring(L, -1), wxConvUTF8));
|
|
|
|
lua_pop(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
namespace Automation4 {
|
|
|
|
// LuaDialogControl
|
|
|
|
LuaDialogControl::LuaDialogControl(lua_State *L)
|
|
|
|
// Assume top of stack is a control table (don't do checking)
|
|
|
|
: name(get_field(L, "name"))
|
|
|
|
, hint(get_field(L, "hint"))
|
|
|
|
, x(get_field(L, "x", 0))
|
|
|
|
, y(get_field(L, "y", 0))
|
|
|
|
, width(get_field(L, "width", 1))
|
|
|
|
, height(get_field(L, "height", 1))
|
|
|
|
{
|
2012-12-23 00:18:38 +01:00
|
|
|
LOG_D("automation/lua/dialog") << "created control: '" << from_wx(name) << "', (" << x << "," << y << ")(" << width << "," << height << "), "<< from_wx(hint);
|
2011-09-28 21:49:27 +02:00
|
|
|
}
|
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
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
namespace LuaControl {
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A static text label
|
|
|
|
class Label : public LuaDialogControl {
|
2006-12-28 22:18:35 +01:00
|
|
|
wxString label;
|
2011-09-28 21:49:27 +02:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
Label(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, label(get_field(L, "label"))
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
return new wxStaticText(parent, -1, label);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
int GetSizerFlags() const { return wxALIGN_CENTRE_VERTICAL | wxALIGN_LEFT; }
|
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
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
|
|
|
// Label doesn't produce output, so let it be nil
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A single-line text edit control
|
|
|
|
class Edit : public LuaDialogControl {
|
|
|
|
protected:
|
2006-12-28 22:18:35 +01:00
|
|
|
wxString text;
|
2011-09-28 21:49:27 +02:00
|
|
|
wxTextCtrl *cw;
|
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
Edit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, text(get_field(L, "value"))
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2009-05-12 17:32:11 +02:00
|
|
|
// Undocumented behaviour, 'value' is also accepted as key for text,
|
|
|
|
// mostly so a text control can stand in for other things.
|
|
|
|
// This shouldn't be exploited and might change later.
|
2011-09-28 21:49:27 +02:00
|
|
|
text = get_field(L, "text", text);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString SerialiseValue() const
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
return inline_string_encode(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnserialiseValue(const wxString &serialised)
|
|
|
|
{
|
|
|
|
text = inline_string_decode(serialised);
|
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
cw = new wxTextCtrl(parent, -1, text);
|
2012-03-07 02:30:52 +01:00
|
|
|
cw->SetValidator(wxGenericValidator(&text));
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_pushstring(L, text.utf8_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A color-picker button
|
|
|
|
class Color : public LuaDialogControl {
|
2008-03-12 08:04:07 +01:00
|
|
|
wxString text;
|
2013-01-13 20:20:44 +01:00
|
|
|
bool alpha;
|
2008-03-12 08:04:07 +01:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
struct ColorValidator : public wxValidator {
|
|
|
|
wxString *text;
|
|
|
|
ColorValidator(wxString *text) : text(text) { }
|
|
|
|
wxValidator *Clone() const { return new ColorValidator(text); }
|
|
|
|
bool Validate(wxWindow*) { return true; }
|
|
|
|
bool TransferToWindow() { return true; }
|
|
|
|
|
|
|
|
bool TransferFromWindow()
|
|
|
|
{
|
2012-10-26 16:09:14 +02:00
|
|
|
*text = to_wx(static_cast<ColourButton*>(GetWindow())->GetColor().GetHexFormatted());
|
2012-03-07 02:30:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public:
|
2013-01-13 20:20:44 +01:00
|
|
|
Color(lua_State *L, bool alpha)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, text(get_field(L, "value"))
|
2013-01-13 20:20:44 +01:00
|
|
|
, alpha(alpha)
|
2008-03-12 08:04:07 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString SerialiseValue() const
|
2008-03-12 08:04:07 +01:00
|
|
|
{
|
|
|
|
return inline_string_encode(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnserialiseValue(const wxString &serialised)
|
|
|
|
{
|
|
|
|
text = inline_string_decode(serialised);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2012-10-26 16:09:14 +02:00
|
|
|
agi::Color colour(from_wx(text));
|
2013-01-13 20:20:44 +01:00
|
|
|
wxControl *cw = new ColourButton(parent, wxSize(50*width,10*height), alpha, colour, ColorValidator(&text));
|
2008-03-12 08:04:07 +01:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_pushstring(L, text.utf8_str());
|
2008-03-12 08:04:07 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A multiline text edit control
|
2006-12-28 22:18:35 +01:00
|
|
|
class Textbox : public Edit {
|
|
|
|
public:
|
|
|
|
Textbox(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: Edit(L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-04-04 02:01:17 +02:00
|
|
|
// Same serialisation interface as single-line edit
|
2006-12-28 22:18:35 +01:00
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2012-03-07 02:30:52 +01:00
|
|
|
cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, wxGenericValidator(&text));
|
2006-12-28 22:18:35 +01:00
|
|
|
cw->SetMinSize(wxSize(0, 30));
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
2006-12-28 22:18:35 +01:00
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// Integer only edit
|
2006-12-28 22:18:35 +01:00
|
|
|
class IntEdit : public Edit {
|
2011-09-28 21:49:27 +02:00
|
|
|
wxSpinCtrl *cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
int value;
|
|
|
|
int min, max;
|
2011-09-28 21:49:27 +02:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
IntEdit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: Edit(L)
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2011-09-28 21:49:27 +02:00
|
|
|
, value(get_field(L, "value", 0))
|
2012-02-28 02:23:15 +01:00
|
|
|
, min(get_field(L, "min", INT_MIN))
|
|
|
|
, max(get_field(L, "max", INT_MAX))
|
2011-09-28 21:49:27 +02:00
|
|
|
{
|
2012-02-28 02:23:15 +01:00
|
|
|
if (min >= max) {
|
2011-09-28 21:49:27 +02:00
|
|
|
max = INT_MAX;
|
|
|
|
min = INT_MIN;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString SerialiseValue() const
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
2011-09-28 21:43:11 +02:00
|
|
|
return wxString::Format("%d", value);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnserialiseValue(const wxString &serialised)
|
|
|
|
{
|
|
|
|
long tmp;
|
|
|
|
if (serialised.ToLong(&tmp))
|
|
|
|
value = tmp;
|
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
cw = new wxSpinCtrl(parent, -1, wxString::Format("%d", value), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, value);
|
2012-03-07 02:30:52 +01:00
|
|
|
cw->SetValidator(wxGenericValidator(&value));
|
2011-09-28 21:49:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Float only edit
|
|
|
|
class FloatEdit : public Edit {
|
2011-09-28 21:49:27 +02:00
|
|
|
double value;
|
2012-02-28 02:23:24 +01:00
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
double step;
|
|
|
|
wxSpinCtrlDouble *scd;
|
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
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
struct DoubleValidator : public wxValidator {
|
|
|
|
double *value;
|
|
|
|
DoubleValidator(double *value) : value(value) { }
|
|
|
|
wxValidator *Clone() const { return new DoubleValidator(value); }
|
|
|
|
bool Validate(wxWindow*) { return true; }
|
|
|
|
bool TransferToWindow() { return true; }
|
|
|
|
|
|
|
|
bool TransferFromWindow()
|
|
|
|
{
|
|
|
|
*value = static_cast<wxSpinCtrlDouble*>(GetWindow())->GetValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-28 02:23:24 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
FloatEdit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: Edit(L)
|
2011-12-28 22:27:22 +01:00
|
|
|
, value(get_field(L, "value", 0.0))
|
2012-02-28 02:23:24 +01:00
|
|
|
, min(get_field(L, "min", -DBL_MAX))
|
|
|
|
, max(get_field(L, "max", DBL_MAX))
|
|
|
|
, step(get_field(L, "step", 0.0))
|
|
|
|
, scd(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2012-02-28 02:23:24 +01:00
|
|
|
if (min >= max) {
|
|
|
|
max = DBL_MAX;
|
|
|
|
min = -DBL_MAX;
|
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2012-02-28 02:23:24 +01:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString SerialiseValue() const
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
return wxString::Format("%g", value);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnserialiseValue(const wxString &serialised)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
double newval;
|
|
|
|
if (serialised.ToDouble(&newval))
|
|
|
|
value = newval;
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2012-02-28 02:23:24 +01:00
|
|
|
if (step > 0) {
|
|
|
|
scd = new wxSpinCtrlDouble(parent, -1,
|
|
|
|
wxString::Format("%g", value), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxSP_ARROW_KEYS, min, max, value, step);
|
2012-03-07 02:30:52 +01:00
|
|
|
scd->SetValidator(DoubleValidator(&value));
|
2012-02-28 02:23:24 +01:00
|
|
|
scd->SetToolTip(hint);
|
|
|
|
return scd;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFloatingPointValidator<double> val(4, &value, wxNUM_VAL_NO_TRAILING_ZEROES);
|
|
|
|
val.SetRange(min, max);
|
|
|
|
|
|
|
|
cw = new wxTextCtrl(parent, -1, SerialiseValue(), wxDefaultPosition, wxDefaultSize, 0, val);
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushnumber(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
/// A dropdown list
|
|
|
|
class Dropdown : public LuaDialogControl {
|
2006-12-28 22:18:35 +01:00
|
|
|
wxArrayString items;
|
|
|
|
wxString value;
|
2011-09-28 21:49:27 +02:00
|
|
|
wxComboBox *cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
Dropdown(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, value(get_field(L, "value"))
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
lua_getfield(L, -1, "items");
|
2011-09-28 21:49:27 +02:00
|
|
|
read_string_array(L, items);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString SerialiseValue() const
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
return inline_string_encode(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnserialiseValue(const wxString &serialised)
|
|
|
|
{
|
|
|
|
value = inline_string_decode(serialised);
|
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2012-03-07 02:30:52 +01:00
|
|
|
cw = new wxComboBox(parent, -1, value, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY, wxGenericValidator(&value));
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_pushstring(L, value.utf8_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
class Checkbox : public LuaDialogControl {
|
2006-12-28 22:18:35 +01:00
|
|
|
wxString label;
|
|
|
|
bool value;
|
2011-09-28 21:49:27 +02:00
|
|
|
wxCheckBox *cw;
|
|
|
|
public:
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
Checkbox(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, label(get_field(L, "label"))
|
|
|
|
, value(get_field(L, "value", false))
|
2012-10-15 06:37:14 +02:00
|
|
|
, cw(0)
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
bool CanSerialiseValue() const { return true; }
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString SerialiseValue() const
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
2011-09-28 21:43:11 +02:00
|
|
|
return value ? "1" : "0";
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnserialiseValue(const wxString &serialised)
|
|
|
|
{
|
|
|
|
// fixme? should this allow more different "false" values?
|
2011-09-28 21:49:27 +02:00
|
|
|
value = serialised != "0";
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
wxControl *Create(wxWindow *parent)
|
|
|
|
{
|
2007-06-28 19:59:27 +02:00
|
|
|
cw = new wxCheckBox(parent, -1, label);
|
2012-03-07 02:30:52 +01:00
|
|
|
cw->SetValidator(wxGenericValidator(&value));
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
2011-09-28 21:49:27 +02:00
|
|
|
cw->SetValue(value);
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, value);
|
|
|
|
}
|
|
|
|
};
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2006-12-28 22:18:35 +01:00
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
// LuaDialog
|
|
|
|
LuaDialog::LuaDialog(lua_State *L, bool include_buttons)
|
|
|
|
: use_buttons(include_buttons)
|
|
|
|
, button_pushed(0)
|
2012-10-15 06:37:14 +02:00
|
|
|
, window(0)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "creating LuaDialoug, addr: " << this;
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// assume top of stack now contains a dialog table
|
2011-09-28 21:49:27 +02:00
|
|
|
if (!lua_istable(L, 1))
|
|
|
|
luaL_error(L, "Cannot create config dialog from something non-table");
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
// Ok, so there is a table with controls
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_pushvalue(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pushnil(L); // initial key
|
|
|
|
while (lua_next(L, -2)) {
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString controlclass;
|
|
|
|
|
|
|
|
if (lua_istable(L, -1))
|
|
|
|
controlclass = get_field(L, "class");
|
|
|
|
|
|
|
|
controlclass.LowerCase();
|
|
|
|
|
|
|
|
LuaDialogControl *ctl;
|
|
|
|
|
|
|
|
// Check control class and create relevant control
|
|
|
|
if (controlclass == "label") {
|
|
|
|
ctl = new LuaControl::Label(L);
|
|
|
|
} else if (controlclass == "edit") {
|
|
|
|
ctl = new LuaControl::Edit(L);
|
|
|
|
} else if (controlclass == "intedit") {
|
|
|
|
ctl = new LuaControl::IntEdit(L);
|
|
|
|
} else if (controlclass == "floatedit") {
|
|
|
|
ctl = new LuaControl::FloatEdit(L);
|
|
|
|
} else if (controlclass == "textbox") {
|
|
|
|
ctl = new LuaControl::Textbox(L);
|
|
|
|
} else if (controlclass == "dropdown") {
|
|
|
|
ctl = new LuaControl::Dropdown(L);
|
|
|
|
} else if (controlclass == "checkbox") {
|
|
|
|
ctl = new LuaControl::Checkbox(L);
|
|
|
|
} else if (controlclass == "color") {
|
2013-01-13 20:20:44 +01:00
|
|
|
ctl = new LuaControl::Color(L, false);
|
2011-09-28 21:49:27 +02:00
|
|
|
} else if (controlclass == "coloralpha") {
|
2013-01-13 20:20:44 +01:00
|
|
|
ctl = new LuaControl::Color(L, true);
|
2011-09-28 21:49:27 +02:00
|
|
|
} else if (controlclass == "alpha") {
|
|
|
|
// FIXME
|
|
|
|
ctl = new LuaControl::Edit(L);
|
2006-12-28 22:18:35 +01:00
|
|
|
} else {
|
2011-09-28 21:49:27 +02:00
|
|
|
luaL_error(L, "bad control table entry");
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2011-09-28 21:49:27 +02:00
|
|
|
|
|
|
|
controls.push_back(ctl);
|
2006-12-28 22:18:35 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
if (include_buttons && lua_istable(L, 2)) {
|
|
|
|
lua_pushvalue(L, 2);
|
|
|
|
read_string_array(L, buttons);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
LuaDialog::~LuaDialog()
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
delete_clear(controls);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxWindow* LuaDialog::CreateWindow(wxWindow *parent)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
2012-03-07 02:30:52 +01:00
|
|
|
window = new wxPanel(parent);
|
2006-12-28 22:18:35 +01:00
|
|
|
wxGridBagSizer *s = new wxGridBagSizer(4, 4);
|
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto c : controls)
|
2012-03-07 02:30:52 +01:00
|
|
|
s->Add(c->Create(window), wxGBPosition(c->y, c->x), wxGBSpan(c->height, c->width), c->GetSizerFlags());
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
if (use_buttons) {
|
|
|
|
wxStdDialogButtonSizer *bs = new wxStdDialogButtonSizer();
|
|
|
|
if (buttons.size() > 0) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "creating user buttons";
|
2006-12-28 22:18:35 +01:00
|
|
|
for (size_t i = 0; i < buttons.size(); ++i) {
|
2012-12-23 00:18:38 +01:00
|
|
|
LOG_D("automation/lua/dialog") << "button '" << from_wx(buttons[i]) << "' gets id " << 1001+(wxWindowID)i;
|
2010-06-09 01:21:39 +02:00
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
bs->Add(new wxButton(window, 1001+(wxWindowID)i, buttons[i]));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "creating default buttons";
|
2012-03-07 02:30:52 +01:00
|
|
|
bs->Add(new wxButton(window, wxID_OK));
|
|
|
|
bs->Add(new wxButton(window, wxID_CANCEL));
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
bs->Realize();
|
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
window->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &LuaDialog::OnButtonPush, this);
|
2006-12-28 22:18:35 +01:00
|
|
|
|
|
|
|
wxBoxSizer *ms = new wxBoxSizer(wxVERTICAL);
|
|
|
|
ms->Add(s, 0, wxBOTTOM, 5);
|
|
|
|
ms->Add(bs);
|
2012-03-07 02:30:52 +01:00
|
|
|
window->SetSizerAndFit(ms);
|
2006-12-28 22:18:35 +01:00
|
|
|
} else {
|
2012-03-07 02:30:52 +01:00
|
|
|
window->SetSizerAndFit(s);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2012-03-07 02:30:52 +01:00
|
|
|
return window;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
int LuaDialog::LuaReadBack(lua_State *L)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// First read back which button was pressed, if any
|
|
|
|
if (use_buttons) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "reading back button_pushed";
|
2006-12-28 22:18:35 +01:00
|
|
|
int btn = button_pushed;
|
|
|
|
if (btn == 0) {
|
2012-02-28 02:23:24 +01:00
|
|
|
LOG_D("automation/lua/dialog") << "was zero, canceled";
|
2006-12-28 22:18:35 +01:00
|
|
|
// Always cancel/closed
|
|
|
|
lua_pushboolean(L, 0);
|
2009-05-12 17:32:11 +02:00
|
|
|
} else if (buttons.size() == 0 && btn == 1) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "default buttons, button 1 bushed, Ok button";
|
2009-05-12 17:32:11 +02:00
|
|
|
lua_pushboolean(L, 1);
|
2006-12-28 22:18:35 +01:00
|
|
|
} else {
|
2012-12-23 00:18:38 +01:00
|
|
|
LOG_D("automation/lua/dialog") << "user button: " << from_wx(buttons.at(btn-1));
|
2009-05-12 17:32:11 +02:00
|
|
|
// button_pushed is index+1 to reserve 0 for Cancel
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_pushstring(L, buttons.at(btn-1).utf8_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then read controls back
|
|
|
|
lua_newtable(L);
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto control : controls) {
|
|
|
|
control->LuaReadBack(L);
|
|
|
|
lua_setfield(L, -2, control->name.utf8_str());
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (use_buttons) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
wxString LuaDialog::Serialise()
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
wxString res;
|
|
|
|
|
|
|
|
// Format into "name1:value1|name2:value2|name3:value3|"
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto control : controls) {
|
|
|
|
if (control->CanSerialiseValue()) {
|
|
|
|
wxString sn = inline_string_encode(control->name);
|
|
|
|
wxString sv = control->SerialiseValue();
|
2011-09-28 21:43:48 +02:00
|
|
|
res += wxString::Format("%s:%s|", sn, sv);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove trailing pipe
|
2011-09-28 21:49:27 +02:00
|
|
|
if (!res.empty())
|
2007-04-04 02:01:17 +02:00
|
|
|
res.RemoveLast();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
void LuaDialog::Unserialise(const wxString &serialised)
|
2007-04-04 02:01:17 +02:00
|
|
|
{
|
|
|
|
// Split by pipe
|
2011-09-28 21:43:11 +02:00
|
|
|
wxStringTokenizer tk(serialised, "|");
|
2007-04-04 02:01:17 +02:00
|
|
|
while (tk.HasMoreTokens()) {
|
|
|
|
// Split by colon
|
|
|
|
wxString pair = tk.GetNextToken();
|
2011-09-28 21:43:11 +02:00
|
|
|
wxString name = inline_string_decode(pair.BeforeFirst(':'));
|
|
|
|
wxString value = pair.AfterFirst(':');
|
2007-04-04 02:01:17 +02:00
|
|
|
|
|
|
|
// Hand value to all controls matching name
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto control : controls) {
|
|
|
|
if (control->name == name && control->CanSerialiseValue())
|
|
|
|
control->UnserialiseValue(value);
|
2007-04-04 02:01:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
void LuaDialog::OnButtonPush(wxCommandEvent &evt)
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// Let button_pushed == 0 mean "cancelled", such that pushing Cancel or closing the dialog
|
|
|
|
// will both result in button_pushed == 0
|
|
|
|
if (evt.GetId() == wxID_OK) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "was wxID_OK";
|
2011-09-28 21:49:27 +02:00
|
|
|
button_pushed = 1;
|
2006-12-28 22:18:35 +01:00
|
|
|
} else if (evt.GetId() == wxID_CANCEL) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "was wxID_CANCEL";
|
2011-09-28 21:49:27 +02:00
|
|
|
button_pushed = 0;
|
2006-12-28 22:18:35 +01:00
|
|
|
} else {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "was user button";
|
2006-12-28 22:18:35 +01:00
|
|
|
// Therefore, when buttons are numbered from 1001 to 1000+n, make sure to set it to i+1
|
2011-09-28 21:49:27 +02:00
|
|
|
button_pushed = evt.GetId() - 1000;
|
2008-03-12 08:19:05 +01:00
|
|
|
|
|
|
|
// hack to make sure the dialog will be closed
|
|
|
|
evt.SetId(wxID_OK);
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
2011-09-28 21:49:27 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "button_pushed set to: " << button_pushed;
|
2006-12-28 22:18:35 +01:00
|
|
|
evt.Skip();
|
|
|
|
}
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2007-12-31 07:46:22 +01:00
|
|
|
|
2008-03-05 00:17:07 +01:00
|
|
|
#endif // WITH_AUTO4_LUA
|