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