| 1 |
/* button.cc |
| 2 |
* This file is part of NDK++ library |
| 3 |
* Copyright (c) 2003,2004 by Stanislav Ievlev |
| 4 |
* |
| 5 |
* This file is covered by the GNU Library General Public License, |
| 6 |
* which should be included with libndk as the file COPYING. |
| 7 |
*/ |
| 8 |
#include <ndk/pen.hh> |
| 9 |
#include <ndk/application.hh> |
| 10 |
#include <ndk/button.hh> |
| 11 |
#include <ndk/palette.hh> |
| 12 |
|
| 13 |
using ndk::mini_button; |
| 14 |
using ndk::button; |
| 15 |
|
| 16 |
namespace |
| 17 |
{ |
| 18 |
struct run_callback |
| 19 |
{ |
| 20 |
/**< functor to run callback functions */ |
| 21 |
template<typename CallbackT> |
| 22 |
void |
| 23 |
operator () (CallbackT &callback) |
| 24 |
{ |
| 25 |
callback (); |
| 26 |
} |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
mini_button::mini_button (std::string const &str, ndk::panel *parent, bool accept) |
| 32 |
: label (str, parent) |
| 33 |
{ |
| 34 |
} |
| 35 |
|
| 36 |
button::button (std::string const &str, panel *parent, bool accept) |
| 37 |
: label (str, parent) |
| 38 |
, state_ (engine::leave_focus) |
| 39 |
{ |
| 40 |
events ()->on_system (slot (&button::at_system, this)); |
| 41 |
} |
| 42 |
|
| 43 |
void |
| 44 |
button::set_color (ndk::pen &p) |
| 45 |
{ |
| 46 |
p.set_color (palette::instance ().find (colors::button_focused)->second); |
| 47 |
} |
| 48 |
|
| 49 |
/* |
| 50 |
* Note: |
| 51 |
* There are following reason to move widget's panel to the top: |
| 52 |
* ncurses has strange algorithm of moving cursor |
| 53 |
* if widget on the top, it's cursor is active and visible on the screen |
| 54 |
* I need this feature for the Line Edit |
| 55 |
*/ |
| 56 |
ndk::event::result |
| 57 |
button::at_system (event const &ev) /**< system event processor */ |
| 58 |
{ |
| 59 |
event::result res = event::ignored; |
| 60 |
|
| 61 |
if (!ev.sender_) |
| 62 |
{ |
| 63 |
state_ = ev.type_; |
| 64 |
res = event::accepted; |
| 65 |
draw (); |
| 66 |
} |
| 67 |
|
| 68 |
return res; |
| 69 |
} |