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