#include #include #include #include #include using namespace raleigh; void dialog::show_modal() { show(); do { _wait_for_action(); _yield_task(); consume_actions(); } while (!result); to_be_deleted.add_back(*this); } static bool on_diag_close(window_tag_t) { return false; } struct diag_and_result { dialog *d; diag_result_t r; diag_and_result(dialog *d, diag_result_t r) : d(d), r(r) {} }; static void set_diag_result(button_tag_t tag) { const diag_and_result *const cast = (const diag_and_result *)tag; cast->d->result = cast->r; //TODO: go through all of raleigh and add destructors //in this case, delete all of these tags when the window is closed } dialog::dialog(widget &top_part, alist> buttons) : window(*new vbox(), RGB(bf, bf, bf), &on_diag_close), result(0), main_box((vbox *)&root) { dllist *button_row = new dllist(); for (duple *i = buttons.buf; i < buttons.buf + buttons.n_entries; ++i) { label *l = new label(i->a); padding *p = new padding(*l, 4); button *b = new button(*p, &set_diag_result, new diag_and_result(this, i->b)); padding *pb = new padding(*b, 2); button_row->add_back(*pb); } hbox *button_box = new hbox(*button_row); padding *ptop = new padding(top_part, 2); padding *pbot = new padding(*button_box, 2); main_box->add_end(*ptop); main_box->add_end(*pbot); } alist> &mk_yes_no_cancel() { alist> *list = new alist>(3, 1); list->add_back(duple("Yes", YES)); list->add_back(duple("No", NO)); list->add_back(duple("Cancel", CANCEL)); return *list; } alist> &mk_yes_no_retry() { alist> *list = new alist>(3, 1); list->add_back(duple("Yes", YES)); list->add_back(duple("No", NO)); list->add_back(duple("Retry", RETRY)); return *list; } alist> &raleigh::yes_no_cancel(mk_yes_no_cancel()); alist> &raleigh::yes_no_retry(mk_yes_no_retry());