button.cpp

Go to the documentation of this file.
00001 /* $Id: button.cpp 26682 2008-05-18 07:14:57Z mordante $ */
00002 /*
00003    copyright (C) 2008 by mark de wever <koraq@xs4all.nl>
00004    part of the battle for wesnoth project http://www.wesnoth.org/
00005 
00006    this program is free software; you can redistribute it and/or modify
00007    it under the terms of the gnu general public license version 2
00008    or at your option any later version.
00009    this program is distributed in the hope that it will be useful,
00010    but without any warranty.
00011 
00012    see the copying file for more details.
00013 */
00014 
00015 #include "gui/widgets/button.hpp"
00016 
00017 #include "gui/widgets/window.hpp"
00018 #include "log.hpp"
00019 
00020 #define DBG_G LOG_STREAM_INDENT(debug, gui)
00021 #define LOG_G LOG_STREAM_INDENT(info, gui)
00022 #define WRN_G LOG_STREAM_INDENT(warn, gui)
00023 #define ERR_G LOG_STREAM_INDENT(err, gui)
00024 
00025 #define DBG_G_D LOG_STREAM_INDENT(debug, gui_draw)
00026 #define LOG_G_D LOG_STREAM_INDENT(info, gui_draw)
00027 #define WRN_G_D LOG_STREAM_INDENT(warn, gui_draw)
00028 #define ERR_G_D LOG_STREAM_INDENT(err, gui_draw)
00029 
00030 #define DBG_G_E LOG_STREAM_INDENT(debug, gui_event)
00031 #define LOG_G_E LOG_STREAM_INDENT(info, gui_event)
00032 #define WRN_G_E LOG_STREAM_INDENT(warn, gui_event)
00033 #define ERR_G_E LOG_STREAM_INDENT(err, gui_event)
00034 
00035 #define DBG_G_P LOG_STREAM_INDENT(debug, gui_parse)
00036 #define LOG_G_P LOG_STREAM_INDENT(info, gui_parse)
00037 #define WRN_G_P LOG_STREAM_INDENT(warn, gui_parse)
00038 #define ERR_G_P LOG_STREAM_INDENT(err, gui_parse)
00039 
00040 namespace gui2 {
00041 
00042 
00043 void tbutton::mouse_enter(tevent_handler&) 
00044 { 
00045     DBG_G_E << "Button: mouse enter.\n"; 
00046 
00047     set_state(FOCUSSED);
00048 }
00049 
00050 void tbutton::mouse_leave(tevent_handler&) 
00051 { 
00052     DBG_G_E << "Button: mouse leave.\n"; 
00053 
00054     set_state(ENABLED);
00055 }
00056 
00057 void tbutton::mouse_left_button_down(tevent_handler& event) 
00058 { 
00059     DBG_G_E << "Button: left mouse button down.\n"; 
00060 
00061     event.mouse_capture();
00062 
00063     set_state(PRESSED);
00064 }
00065 
00066 void tbutton::mouse_left_button_up(tevent_handler&) 
00067 { 
00068     DBG_G_E << "Button: left mouse button up.\n";
00069 
00070     set_state(FOCUSSED);
00071 }
00072 
00073 void tbutton::mouse_left_button_click(tevent_handler&) 
00074 { 
00075     DBG_G_E << "Button: left mouse button click.\n"; 
00076 
00077     // If a button has a retval do the default handling.
00078     if(retval_ != 0) {
00079         twindow* window = get_window();
00080         if(window) {
00081             window->set_retval(retval_);
00082             return;
00083         }
00084     }
00085 
00086     if(callback_mouse_left_click_) {
00087         callback_mouse_left_click_(this);
00088     }
00089 }
00090 
00091 tbutton::RETVAL tbutton::get_retval_by_id(const std::string& id)
00092 {
00093 /*WIKI
00094  * @page = GUIToolkitWML
00095  * @order = 3_widget_button_2
00096  *
00097  * List if the id's that have generate a return value:
00098  * * ok confirms the dialog.
00099  * * cancel cancels the dialog.
00100  *
00101  */
00102     //! Note it might change to a map later depending on the number
00103     //! of items.
00104     if(id == "ok") {
00105         return OK;
00106     } else if(id == "cancel") {
00107         return CANCEL;
00108     } else {
00109         return NONE;
00110     }
00111 }
00112 
00113 void tbutton::set_state(tstate state)
00114 {
00115     if(state != state_) {
00116         state_ = state;
00117         set_dirty(true);
00118     }
00119 }
00120 
00121 } // namespace gui2

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs