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 "searchdialog.h"
00023
00024 void
00025 SearchDialog::createWindow() throw(YAPETUI::UIException) {
00026 if (window != NULL)
00027 throw YAPETUI::UIException(_("May you consider deleting the window before reallocating"));
00028
00029 window = newwin(getHeight(), getWidth(), getStartY(), getStartX());
00030 if (window == NULL)
00031 throw YAPETUI::UIException(_("Error creating search dialog"));
00032
00033 searchtermw = new YAPETUI::InputWidget(getStartX() + 1,
00034 getStartY() + 2,
00035 getWidth() - 2);
00036
00037 okbutton = new YAPETUI::Button(_("OK"),
00038 getStartX() + 1,
00039 getStartY() + getHeight() - 2);
00040
00041 cancelbutton = new YAPETUI::Button(_("Cancel"),
00042 getStartX() + okbutton->getLength() + 2,
00043 getStartY() + getHeight() - 2);
00044 }
00045
00046 SearchDialog::SearchDialog() throw(YAPETUI::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(YAPETUI::UIException) {
00064 refresh();
00065 while (true) {
00066 int ch = 0;
00067 #ifdef HAVE_WRESIZE
00068 while ( (ch = searchtermw->focus()) == KEY_RESIZE)
00069 YAPETUI::BaseWindow::resizeAll();
00070 #else // HAVE_WRESIZE
00071 searchtermw->focus();
00072 #endif // HAVE_WRESIZE
00073
00074 #ifdef HAVE_WRESIZE
00075 while ( (ch = okbutton->focus()) == KEY_RESIZE)
00076 YAPETUI::BaseWindow::resizeAll();
00077 #else // HAVE_WRESIZE
00078 ch = okbutton->focus();
00079 #endif // HAVE_WRESIZE
00080 if (ch == '\n') {
00081 canceled = false;
00082 return;
00083 }
00084 #ifdef HAVE_WRESIZE
00085 while ( (ch = cancelbutton->focus()) == KEY_RESIZE)
00086 YAPETUI::BaseWindow::resizeAll();
00087 #else // HAVE_WRESIZE
00088 ch = cancelbutton->focus();
00089 #endif // HAVE_WRESIZE
00090 if (ch == '\n') {
00091 canceled = true;
00092 return;
00093 }
00094 }
00095
00096 }
00097
00098 void
00099 SearchDialog::resize() throw(YAPETUI::UIException) {
00100 int retval = delwin(window);
00101 if (retval == ERR)
00102 throw YAPETUI::UIException(_("Error deleting search dialog window"));
00103
00104 delete searchtermw;
00105 delete okbutton;
00106 delete cancelbutton;
00107
00108 window = NULL;
00109 searchtermw = NULL;
00110 okbutton = NULL;
00111 cancelbutton = NULL;
00112
00113 createWindow();
00114 }
00115
00116 void
00117 SearchDialog::refresh() throw(YAPETUI::UIException) {
00118 YAPETUI::Colors::setcolor(window, YAPETUI::MESSAGEBOX);
00119 int retval = werase(window);
00120 if (retval == ERR)
00121 throw YAPETUI::UIException(_("Error clearing search dialog"));
00122
00123 retval = box(window, 0, 0);
00124 if (retval == ERR)
00125 throw YAPETUI::UIException(_("Error adding box"));
00126
00127 retval = mymvwaddstr(window, 0, 2, _("S E A R C H"));
00128 if (retval == ERR)
00129 throw YAPETUI::UIException(_("Error setting title"));
00130
00131
00132 #ifdef HAVE_STRCASESTR
00133 retval = mymvwaddstr(window, 1, 1, _("Please enter the search term"));
00134 #else
00135 retval = mymvwaddstr(window, 1, 1, _("Please enter the search term (case-sensitive)"));
00136 #endif
00137 if (retval == ERR)
00138 throw YAPETUI::UIException(_("Error setting label"));
00139
00140 retval = wrefresh(window);
00141 if (retval == ERR)
00142 throw YAPETUI::UIException(_("Error refreshing the search dialog"));
00143
00144 searchtermw->refresh();
00145 okbutton->refresh();
00146 cancelbutton->refresh();
00147 }