00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "../intl.h"
00022 #include "button.h"
00023 #include "colors.h"
00024 #include "basewindow.h"
00025
00026 using namespace YAPETUI;
00027
00028 void
00029 Button::createWindow() throw(UIException) {
00030 window = newwin (1, BASE_SIZE + label.length(), start_y, start_x);
00031 if (window == NULL)
00032 throw UIException (_("Error creating button"));
00033
00034
00035 }
00036
00037 Button::Button (std::string l, int x, int y) : window (NULL),
00038 label (l),
00039 start_x (x),
00040 start_y (y) {
00041 createWindow();
00042 }
00043
00044 Button::~Button() {
00045 wclear(window);
00046 delwin (window);
00047 }
00048
00049
00050 void
00051 Button::setLabel (std::string l) throw (UIException) {
00052 label = l;
00053 int retval = wclear (window);
00054 if (retval == ERR)
00055 throw UIException (_("Error clearing button"));
00056 retval = wrefresh (window);
00057 if (retval == ERR)
00058 throw UIException (_("Error refreshing button"));
00059 retval = delwin (window);
00060 if (retval == ERR)
00061 throw UIException (_("Error deleting button"));
00062
00063
00064 }
00065
00066 void
00067 Button::refresh() throw (UIException) {
00068 Colors::setcolor(window, BUTTON_NOFOCUS);
00069 int retval = werase(window);
00070 if (retval == ERR)
00071 throw UIException (_("Error erasing button"));
00072
00073 mvwprintw (window, 0, 0, "[ %s ]", label.c_str());
00074
00075 retval = wrefresh (window);
00076 if (retval == ERR)
00077 throw UIException (_("Error refreshing button"));
00078 }
00079
00080 int
00081 Button::focus() throw (UIException) {
00082 Colors::setcolor(window, BUTTON_FOCUS);
00083 mvwprintw (window, 0, 0, "[ %s ]", label.c_str());
00084
00085 int retval = touchwin (window);
00086 if (retval == ERR)
00087 throw UIException (_("Error touching window"));
00088
00089 retval = wrefresh (window);
00090 if (retval == ERR)
00091 throw UIException (_("Error refreshing button"));
00092
00093 retval = keypad (window, TRUE);
00094 if (retval == ERR)
00095 throw UIException (_("Error setting keypad"));
00096
00097 int ch;
00098 while (true) {
00099 ch = wgetch (window);
00100
00101 switch (ch) {
00102 case '\n':
00103 case KEY_ENTER:
00104 ch = '\n';
00105 onClick();
00106 goto BAILOUT;
00107 break;
00108 case '\t':
00109 case KEY_LEFT:
00110 case KEY_RIGHT:
00111 case KEY_UP:
00112 case KEY_DOWN:
00113 ch = '\t';
00114 goto BAILOUT;
00115 break;
00116 case KEY_REFRESH:
00117 BaseWindow::refreshAll();
00118 break;
00119 #ifdef HAVE_WRESIZE
00120 case KEY_RESIZE:
00121 goto BAILOUT;
00122 break;
00123 #endif // HAVE_WRESIZE
00124 }
00125 }
00126
00127 BAILOUT:
00128 Colors::setcolor(window, BUTTON_NOFOCUS);
00129
00130 mvwprintw (window, 0, 0, "[ %s ]", label.c_str());
00131
00132
00133 retval = touchwin (window);
00134 if (retval == ERR)
00135 throw UIException (_("Error touching window"));
00136
00137 retval = wrefresh (window);
00138 if (retval == ERR)
00139 throw UIException (_("Error refreshing button"));
00140
00141 return ch;
00142 }