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/
|
2006-12-28 22:18:35 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @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"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <assert.h>
|
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>
|
|
|
|
#include <wx/window.h>
|
|
|
|
#endif
|
2009-09-10 12:26:50 +02:00
|
|
|
|
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"
|
|
|
|
#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))
|
|
|
|
def = std::max(lua_tonumber(L, -1), def);
|
|
|
|
}
|
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))
|
2011-11-07 05:14:09 +01:00
|
|
|
def = std::max<int>(lua_tointeger(L, -1), def);
|
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))
|
|
|
|
{
|
|
|
|
LOG_D("automation/lua/dialog") << "created control: '" << STD_STR(name) << "', (" << x << "," << y << ")(" << width << "," << height << "), "<< STD_STR(hint);
|
|
|
|
}
|
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
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
void ControlReadBack() { }
|
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"))
|
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);
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlReadBack()
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
text = cw->GetValue();
|
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;
|
2011-09-28 21:49:27 +02:00
|
|
|
ColourButton *cw;
|
|
|
|
public:
|
2008-03-12 08:04:07 +01:00
|
|
|
|
|
|
|
Color(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: LuaDialogControl(L)
|
|
|
|
, text(get_field(L, "value"))
|
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)
|
|
|
|
{
|
2009-05-12 17:32:11 +02:00
|
|
|
AssColor colour;
|
|
|
|
colour.Parse(text);
|
|
|
|
cw = new ColourButton(parent, -1, wxSize(50*width,10*height), colour.GetWXColor());
|
2008-03-12 08:04:07 +01:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlReadBack()
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
text = cw->GetColour().GetAsString(wxC2S_HTML_SYNTAX);
|
2008-03-12 08:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
cw = new wxTextCtrl(parent, -1, text, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
|
|
|
|
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)
|
|
|
|
, value(get_field(L, "value", 0))
|
|
|
|
, min(get_field(L, "min", 0))
|
|
|
|
, max(get_field(L, "max", 0))
|
|
|
|
{
|
|
|
|
if (min <= max) {
|
|
|
|
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);
|
|
|
|
cw->SetToolTip(hint);
|
2007-06-28 19:59:27 +02:00
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlReadBack()
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
value = cw->GetValue();
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaReadBack(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Float only edit
|
|
|
|
class FloatEdit : public Edit {
|
|
|
|
public:
|
2011-09-28 21:49:27 +02:00
|
|
|
double value;
|
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
|
|
|
FloatEdit(lua_State *L)
|
2011-09-28 21:49:27 +02:00
|
|
|
: Edit(L)
|
|
|
|
, value(get_field(L, "value", 0))
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
// TODO: spin button support
|
|
|
|
}
|
|
|
|
|
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: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)
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
cw = new wxTextCtrl(parent, -1, SerialiseValue());
|
2007-06-28 19:59:27 +02:00
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlReadBack()
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
text = cw->GetValue();
|
|
|
|
UnserialiseValue(text);
|
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;
|
|
|
|
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"))
|
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)
|
|
|
|
{
|
2007-06-28 19:59:27 +02:00
|
|
|
cw = new wxComboBox(parent, -1, value, wxDefaultPosition, wxDefaultSize, items, wxCB_READONLY);
|
|
|
|
cw->SetToolTip(hint);
|
|
|
|
return cw;
|
2006-12-28 22:18:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlReadBack()
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
value = cw->GetValue();
|
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))
|
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);
|
|
|
|
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 ControlReadBack()
|
|
|
|
{
|
2011-09-28 21:49:27 +02:00
|
|
|
value = cw->GetValue();
|
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)
|
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") {
|
|
|
|
ctl = new LuaControl::Color(L);
|
|
|
|
} else if (controlclass == "coloralpha") {
|
|
|
|
// FIXME
|
|
|
|
ctl = new LuaControl::Edit(L);
|
|
|
|
} 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
|
|
|
{
|
|
|
|
wxWindow *w = new wxPanel(parent);
|
|
|
|
wxGridBagSizer *s = new wxGridBagSizer(4, 4);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i) {
|
2011-09-28 21:49:27 +02:00
|
|
|
LuaDialogControl *c = controls[i];
|
|
|
|
s->Add(c->Create(w), 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) {
|
2011-09-28 21:43:48 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "button '" << STD_STR(buttons[i]) << "' gets id " << 1001+(wxWindowID)i;
|
2010-06-09 01:21:39 +02:00
|
|
|
|
2006-12-28 22:18:35 +01:00
|
|
|
bs->Add(new wxButton(w, 1001+(wxWindowID)i, buttons[i]));
|
|
|
|
}
|
|
|
|
} else {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "creating default buttons";
|
2006-12-28 22:18:35 +01:00
|
|
|
bs->Add(new wxButton(w, wxID_OK));
|
|
|
|
bs->Add(new wxButton(w, wxID_CANCEL));
|
|
|
|
}
|
|
|
|
bs->Realize();
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
w->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);
|
|
|
|
w->SetSizerAndFit(ms);
|
|
|
|
} else {
|
|
|
|
w->SetSizerAndFit(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
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) {
|
2010-06-09 01:21:39 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "was zero, cancelled";
|
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 {
|
2011-09-28 21:43:48 +02:00
|
|
|
LOG_D("automation/lua/dialog") << "user button: " << STD_STR(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);
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i) {
|
|
|
|
controls[i]->LuaReadBack(L);
|
2011-09-28 21:49:27 +02:00
|
|
|
lua_setfield(L, -2, controls[i]->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|"
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i) {
|
|
|
|
if (controls[i]->CanSerialiseValue()) {
|
|
|
|
wxString sn = inline_string_encode(controls[i]->name);
|
|
|
|
wxString sv = controls[i]->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
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i) {
|
|
|
|
if (controls[i]->name == name && controls[i]->CanSerialiseValue()) {
|
|
|
|
controls[i]->UnserialiseValue(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:49:27 +02:00
|
|
|
void LuaDialog::ReadBack()
|
2006-12-28 22:18:35 +01:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < controls.size(); ++i) {
|
|
|
|
controls[i]->ControlReadBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// only do this for non-colour buttons
|
2011-09-28 21:49:27 +02:00
|
|
|
if (dynamic_cast<ColourButton*> (evt.GetEventObject())) return;
|
2008-03-12 08:19:05 +01:00
|
|
|
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
|