00001 #ifndef RADIO_BOX_CLASS 00002 #define RADIO_BOX_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : radio_box * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * Allow a user to choose a button from a mutually exclusive set of * 00012 * buttons. * 00013 * * 00014 * * 00015 ******************************************************************************* 00016 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00017 * redistribute it and/or modify it under the terms of the GNU General Public * 00018 * License as published by the Free Software Foundation; either version 2 of * 00019 * the License or (at your option) any later version. This is online at: * 00020 * http://www.fsf.org/copyleft/gpl.html * 00021 * Please send any updates to: fred@gruntose.com * 00022 \*****************************************************************************/ 00023 00024 // Description: 00025 // 00026 // A radio box is a window filled with radio buttons. A radio button is 00027 // an object that the user can press to turn on. Only one radio button is 00028 // turned on at a time. When the user selects a radio button, that one is 00029 // turned on and the previously on button is turned off. When the user 00030 // selects a button, the event function button_press_event is invoked. 00031 00032 #include "mouse.h" 00033 00034 #include <basis/istring.h> 00035 #include <wp_passive/worker.h> 00036 00037 class radio_box_button; 00038 00039 enum radio_box_outcomes { RB_NO_BUTTON = -1 }; 00040 00041 class WP_ACTIVE_CLASS_STYLE radio_box 00042 : public worker, private array<radio_box_button *> 00043 { 00044 public: 00045 radio_box(manager &parent, const c_point &origin, 00046 const color &foreground, const color &background); 00047 // Creates a radio box. This supplements the abstraction provided by Motif 00048 // radio boxes. The application creates a radio and can add buttons to it. 00049 // Then the user of the application can press the buttons. The event 00050 // function button_pressed is called when the user presses a button. 00051 // The user can assume that the the selected button is the ONLY button that 00052 // is "on" (i.e. all other buttons are off). 00053 00054 ~radio_box(); 00055 00056 IMPLEMENT_CLASS_NAME("radio_box"); 00057 00058 int add(const istring &button_name); 00059 // Attaches a new button to this radio box. The button number for this 00060 // "button_name" is returned. By default, the first button added to the 00061 // radio_box is selected. Note that button names should be unique. 00062 00063 void press(int button_number, bool trigger_event = true); 00064 // Imitates the action that occurs when a user presses the specified 00065 // button. If "trigger_event" is true, then the button_event 00066 // method is also invoked. Otherwise, only the appearance of the radio box 00067 // is changed to reflect the button being pressed (and none of the other's 00068 // being pressed). 00069 00070 virtual void button_event(int button_number); 00071 // this is called when the user selects a button from the radio box. 00072 // the button selected is passed in "pressed". 00073 00074 int current() const; 00075 // returns the number of the button currently selected in the box. 00076 // RB_NO_BUTTON is returned if there are no buttons yet. 00077 00078 int lookup(const istring &to_find) const; 00079 // returns the index of the button in the button list or RB_NO_BUTTON 00080 // if the button could not be found. 00081 00082 istring lookup(int index) const; 00083 // returns the name for the button at "index", or an empty string if that 00084 // index is not valid. 00085 00086 int buttons() const; 00087 // returns the current number of buttons in the radio_box. 00088 00089 static void radio_box_callback(window_handle w, radio_box_button *the_button, 00090 XmToggleButtonCallbackStruct *); 00091 00092 private: 00093 radio_box_button *active; 00094 mouse *touched_box_manager; 00095 }; 00096 00097 class WP_ACTIVE_CLASS_STYLE radio_box_button : public worker 00098 { 00099 public: 00100 radio_box_button(radio_box *parent, const istring &button_name, int number); 00101 ~radio_box_button(); 00102 00103 private: 00104 istring _name; 00105 int button_number; 00106 bool interactive_press; 00107 friend class radio_box; 00108 radio_box *_parent; 00109 }; 00110 00111 #endif
1.5.1