Go to the documentation of this file.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 <colors.h>
00023 #include "searchdialog.h"
00024
00025 void
00026 SearchDialog::createWindow() throw (YAPET::UI::UIException) {
00027 if (window != NULL)
00028 throw YAPET::UI::UIException (_ ("May you consider deleting the window before reallocating") );
00029
00030 window = newwin (getHeight(), getWidth(), getStartY(), getStartX() );
00031
00032 if (window == NULL)
00033 throw YAPET::UI::UIException (_ ("Error creating search dialog") );
00034
00035 searchtermw = new YAPET::UI::InputWidget (getStartX() + 1,
00036 getStartY() + 2,
00037 getWidth() - 2);
00038 okbutton = new YAPET::UI::Button (_ ("OK"),
00039 getStartX() + 1,
00040 getStartY() + getHeight() - 2);
00041 cancelbutton = new YAPET::UI::Button (_ ("Cancel"),
00042 getStartX() + okbutton->getLength() + 2,
00043 getStartY() + getHeight() - 2);
00044 }
00045
00046 SearchDialog::SearchDialog() throw (YAPET::UI::UIException) : window (NULL),
00047 searchtermw (NULL),
00048 okbutton (NULL),
00049 cancelbutton (NULL),
00050 searchterm (""),
00051 canceled (true) {
00052 createWindow();
00053 }
00054
00055 SearchDialog::~SearchDialog() {
00056 delete searchtermw;
00057 delete okbutton;
00058 delete cancelbutton;
00059 delwin (window);
00060 }
00061
00062 void
00063 SearchDialog::run() throw (YAPET::UI::UIException) {
00064 refresh();
00065
00066 while (true) {
00067 int ch = 0;
00068 #ifdef HAVE_WRESIZE
00069
00070 while ( (ch = searchtermw->focus() ) == KEY_RESIZE)
00071 YAPET::UI::BaseWindow::resizeAll();
00072
00073 #else // HAVE_WRESIZE
00074 ch = searchtermw->focus();
00075 #endif // HAVE_WRESIZE
00076
00077 if (ch == KEY_ESC) {
00078 canceled = true;
00079 return;
00080 }
00081
00082 #ifdef HAVE_WRESIZE
00083
00084 while ( (ch = okbutton->focus() ) == KEY_RESIZE)
00085 YAPET::UI::BaseWindow::resizeAll();
00086
00087 #else // HAVE_WRESIZE
00088 ch = okbutton->focus();
00089 #endif // HAVE_WRESIZE
00090
00091 switch (ch) {
00092 case KEY_ESC:
00093 canceled = true;
00094 return;
00095 case '\n':
00096 canceled = false;
00097 return;
00098 }
00099
00100 #ifdef HAVE_WRESIZE
00101
00102 while ( (ch = cancelbutton->focus() ) == KEY_RESIZE)
00103 YAPET::UI::BaseWindow::resizeAll();
00104
00105 #else // HAVE_WRESIZE
00106 ch = cancelbutton->focus();
00107 #endif // HAVE_WRESIZE
00108
00109 if (ch == '\n' || ch == KEY_ESC) {
00110 canceled = true;
00111 return;
00112 }
00113 }
00114 }
00115
00116 void
00117 SearchDialog::resize() throw (YAPET::UI::UIException) {
00118 int retval = delwin (window);
00119
00120 if (retval == ERR)
00121 throw YAPET::UI::UIException (_ ("Error deleting search dialog window") );
00122
00123 delete searchtermw;
00124 delete okbutton;
00125 delete cancelbutton;
00126 window = NULL;
00127 searchtermw = NULL;
00128 okbutton = NULL;
00129 cancelbutton = NULL;
00130 createWindow();
00131 }
00132
00133 void
00134 SearchDialog::refresh() throw (YAPET::UI::UIException) {
00135 YAPET::UI::Colors::setcolor (window, YAPET::UI::MESSAGEBOX);
00136 int retval = werase (window);
00137
00138 if (retval == ERR)
00139 throw YAPET::UI::UIException (_ ("Error clearing search dialog") );
00140
00141 retval = box (window, 0, 0);
00142
00143 if (retval == ERR)
00144 throw YAPET::UI::UIException (_ ("Error adding box") );
00145
00146 retval = mymvwaddstr (window, 0, 2, _ ("S E A R C H") );
00147
00148 if (retval == ERR)
00149 throw YAPET::UI::UIException (_ ("Error setting title") );
00150
00151
00152 #ifdef HAVE_STRCASESTR
00153 retval = mymvwaddstr (window, 1, 1, _ ("Please enter the search term") );
00154 #else
00155 # ifdef HAVE_TOLOWER
00156 retval = mymvwaddstr (window, 1, 1, _ ("Please enter the search term") );
00157 # else
00158 retval = mymvwaddstr (window, 1, 1, _ ("Please enter the search term (case-sensitive)") );
00159 # endif // HAVE_TOLOWER
00160 #endif
00161
00162 if (retval == ERR)
00163 throw YAPET::UI::UIException (_ ("Error setting label") );
00164
00165 retval = wrefresh (window);
00166
00167 if (retval == ERR)
00168 throw YAPET::UI::UIException (_ ("Error refreshing the search dialog") );
00169
00170 searchtermw->refresh();
00171 okbutton->refresh();
00172 cancelbutton->refresh();
00173 }