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