Author: mordante
Date: Sun Mar 13 08:49:06 2011
New Revision: 48867
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48867&view=rev
Log:
Add a new register_text function.
This version also allows to set the focus to a widget. The goal is to
extend the number of helper functions so less pre and post show
functions are needed.
Modified:
trunk/src/gui/dialogs/dialog.cpp
trunk/src/gui/dialogs/dialog.hpp
Modified: trunk/src/gui/dialogs/dialog.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/dialog.cpp?rev=48867&r1=48866&r2=48867&view=diff
==============================================================================
--- trunk/src/gui/dialogs/dialog.cpp (original)
+++ trunk/src/gui/dialogs/dialog.cpp Sun Mar 13 08:49:06 2011
@@ -163,6 +163,20 @@
return field;
}
+tfield_text* tdialog::register_text2(const std::string& id
+ , const bool mandatory
+ , std::string& linked_variable
+ , const bool capture_focus)
+{
+ assert(!capture_focus || focus_.empty());
+
+ if(capture_focus) {
+ focus_ = id;
+ }
+
+ return tdialog::register_text(id, !mandatory, linked_variable);
+}
+
twindow* tdialog::build_window(CVideo& video) const
{
return build(video, window_id());
@@ -172,6 +186,12 @@
{
foreach(tfield_* field, fields_) {
field->widget_init(window);
+ }
+
+ if(!focus_.empty()) {
+ if(twidget* widget = window.find(focus_, false)) {
+ window.keyboard_capture(widget);
+ }
}
}
Modified: trunk/src/gui/dialogs/dialog.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/dialog.hpp?rev=48867&r1=48866&r2=48867&view=diff
==============================================================================
--- trunk/src/gui/dialogs/dialog.hpp (original)
+++ trunk/src/gui/dialogs/dialog.hpp Sun Mar 13 08:49:06 2011
@@ -134,6 +134,7 @@
tdialog() :
retval_(0),
fields_(),
+ focus_(),
restore_(true)
{}
@@ -240,10 +241,40 @@
* Creates a new text field.
*
* See @ref register_bool for more info.
+ *
+ * @deprecated Use @ref register_text2 instead.
*/
tfield_text* register_text(const std::string& id
, const bool optional
, std::string& linked_variable);
+
+ /**
+ * Creates a new text field.
+ *
+ * The field created is owned by tdialog, the returned pointer can be
used
+ * in the child classes as access to a field.
+ *
+ * @note This function uses @p mandatory instead of @p optional as in
other
+ * functions, the other functions need to be converted to use @p
mandatory
+ * as well.
+ *
+ * @todo Convert more functions to this new style once done drop the 2
from
+ * the function name.
+ *
+ * @param id Id of the widget, same value as in WML.
+ * @param mandatory Is the widget mandatory or optional.
+ * @param linked_variable The variable the widget is linked to. See
+ * @ref tfield::tfield for more information.
+ * @param capture_focus Does this widget need to capture the focus
+ * when created? @warning Only one widget may
+ * capture the focus.
+ *
+ * @returns Pointer to the created widget.
+ */
+ tfield_text* register_text2(const std::string& id
+ , const bool mandatory
+ , std::string& linked_variable
+ , const bool capture_focus = false);
private:
/** Returns the window exit status, 0 means not shown. */
int retval_;
@@ -258,6 +289,11 @@
std::vector<tfield_*> fields_;
/**
+ * Contains the widget that should get the focus when the window is
shown.
+ */
+ std::string focus_;
+
+ /**
* Restore the screen after showing?
*
* Most windows should restore the display after showing so this value
@@ -307,7 +343,7 @@
virtual void post_show(twindow& /*window*/) {}
/**
- * Initializes all fields in the dialog.
+ * Initializes all fields in the dialog and set the keyboard focus.
*
* @param window The window which has been shown.
*/
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits