Reverted 2009-05-13T22:46:48Z!terraninfo@terraninfo.net, the code now works due to 2009-05-14T18:08:45Z!koraq@xs4all.nl.

Tested and bug #13521 no longer occurs with this code.
This commit is contained in:
Mark de Wever 2009-05-14 18:20:00 +00:00
parent 0d732da346
commit ffdbcda976
4 changed files with 196 additions and 18 deletions

View file

@ -103,6 +103,7 @@ Version 1.7.0-svn:
now causes a capture of that village.
* Rewrote the layout algoritm (still a work in progress)
* Fixed an multi-character UTF-8 handling bug in the password textbox
* Changed the tmessage dialog to be able to show four buttons
* WML Engine:
* Added [show_objectives] tag and allowed [show_if] tag in [objective]
tags. (bug #13042)

View file

@ -88,19 +88,73 @@
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
# This button will be shown or hidden depending on the
# whether or not a scrollbar is needed to show the
# text.
id = "ok"
definition = "default"
[grid]
label = "close"
[/button]
[row]
# This button will be shown or hidden depending on the
# whether or not a scrollbar is needed to show the
# text.
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
id = "left_side"
definition = "default"
label = ""
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
id = "ok"
definition = "default"
label = _ "Close"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
id = "right_side"
definition = "default"
label = ""
[/button]
[/column]
[/row]
[/grid]
[/column]
@ -111,3 +165,4 @@
[/resolution]
[/window]

View file

@ -16,6 +16,7 @@
#include "gui/dialogs/message.hpp"
#include "foreach.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
@ -23,8 +24,53 @@
namespace gui2 {
/**
* Helper to implement private functions without modifing the header.
*
* The class is a helper to avoid recompilation and only has static
* functions.
*/
struct tmessage_implementation
{
/**
* Initialiazes a button.
*
* @param window The window that contains the button.
* @param button_status The button status to modify.
* @param id The id of the button.
*/
static void
init_button(twindow& window, tmessage::tbutton_status& button_status,
const std::string& id)
{
button_status.button =
dynamic_cast<tbutton*>(window.find_widget(id, false));
VALIDATE(button_status.button, missing_widget(id));
button_status.button->set_visible(button_status.visible);
if(!button_status.caption.empty()) {
button_status.button->set_label(button_status.caption);
}
if(button_status.retval != twindow::NONE) {
button_status.button->set_retval(button_status.retval);
}
}
};
void tmessage::pre_show(CVideo& /*video*/, twindow& window)
{
// ***** Validate the required buttons ***** ***** ***** *****
tmessage_implementation::
init_button(window, buttons_[left_1], "left_side");
tmessage_implementation::
init_button(window, buttons_[cancel], "cancel");
tmessage_implementation::
init_button(window, buttons_[ok] ,"ok");
tmessage_implementation::
init_button(window, buttons_[right_1], "right_side");
// ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
if(!title_.empty()) {
tlabel* title =
dynamic_cast<tlabel*>(window.find_widget("title", false));
@ -58,18 +104,56 @@ void tmessage::pre_show(CVideo& /*video*/, twindow& window)
* and thus not need a scrollbar. Also when the button is visible
* easy_close will always return false.
*/
tbutton* button =
dynamic_cast<tbutton*>(window.find_widget("ok", false));
VALIDATE(button, missing_widget("ok"));
button->set_visible(twidget::INVISIBLE);
window.layout();
if(! window.does_easy_close()) {
button->set_visible(twidget::VISIBLE);
set_button_visible(ok, twidget::VISIBLE);
}
}
}
void tmessage::post_show(twindow& /*window*/)
{
foreach(tbutton_status& button_status, buttons_) {
button_status.button = NULL;
}
}
void tmessage::set_button_caption(const tbutton_id button,
const std::string& caption)
{
buttons_[button].caption = caption;
if(buttons_[button].button) {
buttons_[button].button->set_label(caption);
}
}
void tmessage::set_button_visible(const tbutton_id button,
const twidget::tvisible visible)
{
buttons_[button].visible = visible;
if(buttons_[button].button) {
buttons_[button].button->set_visible(visible);
}
}
void tmessage::set_button_retval(const tbutton_id button,
const int retval)
{
buttons_[button].retval = retval;
if(buttons_[button].button) {
buttons_[button].button->set_retval(retval);
}
}
tmessage::tbutton_status::tbutton_status()
: button(NULL)
, caption()
, visible(twidget::INVISIBLE)
, retval(twindow::NONE)
{
}
twindow* tmessage::build_window(CVideo& video)
{
return build(video, get_id(MESSAGE));

View file

@ -15,18 +15,22 @@
#ifndef GUI_DIALOGS_MESSAGE_HPP_INCLUDED
#define GUI_DIALOGS_MESSAGE_HPP_INCLUDED
#include "gui/widgets/widget.hpp"
#include "gui/dialogs/dialog.hpp"
namespace gui2 {
class tbutton;
/**
* Main class to show messages to the user.
*
* It can be used to show a message or ask a result from the user. For the most
* common usage cases there are helper functions defined.
* It can be used to show a message or ask a result from the user. For the
* most common usage cases there are helper functions defined.
*/
class tmessage : public tdialog
{
friend struct tmessage_implementation;
public:
tmessage(const std::string& title, const std::string& message,
const bool auto_close)
@ -34,8 +38,26 @@ public:
, image_()
, message_(message)
, auto_close_(auto_close)
, buttons_(count)
{}
enum tbutton_id {
left_1 = 0
, cancel
, ok
, right_1
, count
};
void set_button_caption(const tbutton_id button,
const std::string& caption);
void set_button_visible(const tbutton_id button,
const twidget::tvisible visible);
void set_button_retval(const tbutton_id button,
const int retval);
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_title(const std::string& title) { title_ = title; }
@ -50,6 +72,9 @@ protected:
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
private:
/** The title for the dialog. */
std::string title_;
@ -70,6 +95,19 @@ private:
*/
bool auto_close_;
struct tbutton_status
{
tbutton_status();
tbutton* button;
std::string caption;
twidget::tvisible visible;
int retval;
};
/** Holds a pointer to the buttons. */
std::vector<tbutton_status> buttons_;
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
};