| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// |
| 3 |
// Copyright (C) 2003-2013 Fons Adriaensen <[email protected]> |
| 4 |
// |
| 5 |
// This program is free software; you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU General Public License as published by |
| 7 |
// the Free Software Foundation; either version 3 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// This program is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
// |
| 18 |
// ---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
|
| 21 |
#include "guiclass.h" |
| 22 |
|
| 23 |
|
| 24 |
typedef X_button *xbutp; |
| 25 |
|
| 26 |
|
| 27 |
Radiosel::Radiosel (X_window *parw, X_callback *xcbh) : |
| 28 |
_nbut (0), |
| 29 |
_stat (-1), |
| 30 |
_butt (0), |
| 31 |
_parw (parw), |
| 32 |
_xcbh (xcbh) |
| 33 |
{ |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
Radiosel::~Radiosel (void) |
| 38 |
{ |
| 39 |
delete[] _butt; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
void Radiosel::init (X_button_style *bst, X_textln_style *tst, const char **text, |
| 44 |
int nbut, int xpos, int ypos, int xsize, int ystep, int cbid) |
| 45 |
{ |
| 46 |
int i, x, y; |
| 47 |
|
| 48 |
_nbut = nbut; |
| 49 |
_cbid = cbid; |
| 50 |
_butt = new xbutp [nbut]; |
| 51 |
bst->size.x = 17; |
| 52 |
bst->size.y = 17; |
| 53 |
x = xpos; |
| 54 |
y = ypos; |
| 55 |
for (i = 0; i < nbut; i++) |
| 56 |
{ |
| 57 |
_butt [i] = new X_ibutton (_parw, this, bst, x, y, _parw->disp ()->image1515 (X_display::IMG_RT), i); |
| 58 |
_butt [i]->x_map (); |
| 59 |
(new X_textln (_parw, tst, x + 20, y, xsize - 20, 17, text [i], -1))->x_map (); |
| 60 |
y += ystep; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
void Radiosel::set_stat (int stat) |
| 66 |
{ |
| 67 |
if (stat != _stat) |
| 68 |
{ |
| 69 |
if (_stat >= 0) _butt [_stat]->set_stat (0); |
| 70 |
_stat = stat; |
| 71 |
if (_stat >= 0) _butt [_stat]->set_stat (1); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
void Radiosel::handle_callb (int k, X_window *W, _XEvent *E) |
| 77 |
{ |
| 78 |
switch (X_callback::cb_class (k)) |
| 79 |
{ |
| 80 |
case X_callback::BUTTON: |
| 81 |
if (X_callback::cb_event (k) == X_button::PRESS) |
| 82 |
{ |
| 83 |
set_stat (((X_button *) W)->cbid ()); |
| 84 |
if (_xcbh) _xcbh->handle_callb (_cbid, 0, 0); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|