+LoadLayoutDialog::LoadLayoutDialog(LoadLayout *load_layout)
+{
+ this->load_layout = load_layout;
+ wx = 0; wy = 0;
+ idx = -1;
+ lgui = 0;
+}
+
+LoadLayoutDialog::~LoadLayoutDialog()
+{
+ close_window();
+}
+
+void LoadLayoutDialog::handle_done_event(int result)
+{
+ if( result ) return;
+ char layout_file[BCSTRLEN];
+ BC_SubMenu *layout_submenu = load_layout->get_submenu();
+ LoadLayoutItem* item =
+ (LoadLayoutItem *) layout_submenu->get_item(idx);
+ snprintf(layout_file, sizeof(layout_file), "%s", item->layout_file);
+ load_layout->mwindow->delete_layout(layout_file);
+ int k = sprintf(layout_file, LAYOUT_FILE, idx+1);
+ const char *text = lgui->name_text->get_text();
+ if( text[0] )
+ snprintf(layout_file + k-2, sizeof(layout_file)-k+2, "%s_rc", text);
+ load_layout->mwindow->save_layout(layout_file);
+}
+
+void LoadLayoutDialog::handle_close_event(int result)
+{
+ lgui = 0;
+}
+
+BC_Window *LoadLayoutDialog::new_gui()
+{
+ lgui = new LoadLayoutConfirm(this, wx, wy);
+ lgui->create_objects();
+ return lgui;
+}
+
+void LoadLayoutDialog::start_confirm_dialog(int wx, int wy, int idx)
+{
+ close_window();
+ this->wx = wx; this->wy = wy;
+ this->idx = idx;
+ start();
+}
+
+LoadLayoutNameText::LoadLayoutNameText(LoadLayoutConfirm *confirm,
+ int x, int y, int w, const char *text)
+ : BC_TextBox(x, y, w, 1, text)
+{
+ this->confirm = confirm;
+}
+
+LoadLayoutNameText::~LoadLayoutNameText()
+{
+}
+
+int LoadLayoutNameText::handle_event()
+{
+ const char *text = get_text();
+ int len = strlen(text), k = 0;
+ char new_text[BCTEXTLEN];
+ for( int i=0; i<len; ++i ) {
+ int ch = text[i];
+ if( (ch>='A' && ch<='Z') || (ch>='a' && ch<='z') ||
+ (ch>='0' && ch<='9') || ch=='_' )
+ new_text[k++] = ch;
+ }
+ new_text[k] = 0; len = k;
+ int i = len - LAYOUT_NAME_LEN;
+ if( i >= 0 ) {
+ k = 0;
+ while( i < len ) new_text[k++] = new_text[i++];
+ new_text[k] = 0;
+ }
+ update(new_text);
+ return 1;
+}
+
+LoadLayoutConfirm::LoadLayoutConfirm(LoadLayoutDialog *layout_dialog, int x, int y)
+ : BC_Window(_(PROGRAM_NAME ": Layout"), x, y, 300,140, 300,140, 0)
+{
+ this->layout_dialog = layout_dialog;
+}
+
+LoadLayoutConfirm::~LoadLayoutConfirm()
+{
+}
+
+void LoadLayoutConfirm::create_objects()
+{
+ lock_window("LoadLayoutConfirm::create_objects");
+ int x = 10, y = 10, pad = 10;
+ BC_SubMenu *layout_submenu = layout_dialog->load_layout->get_submenu();
+ LoadLayoutItem *item = (LoadLayoutItem *)
+ layout_submenu->get_item(layout_dialog->idx);
+ BC_Title *title;
+ add_subwindow(title = new BC_Title(x, y, _("Layout Name:")));
+ int x1 = x + title->get_w() + 10;
+ add_subwindow(title = new BC_Title(x1, y, item->get_text()));
+ y += title->get_h() + pad;
+ add_subwindow(name_text = new LoadLayoutNameText(this,
+ x, y, get_w()-x-20, item->layout_text));
+ y += name_text->get_h();
+ x1 = x + 80;
+ char legend[BCTEXTLEN];
+ sprintf(legend, _("a-z,A-Z,0-9_ only, %dch max"), LAYOUT_NAME_LEN);
+ add_subwindow(title = new BC_Title(x1, y, legend));
+ add_subwindow(new BC_OKButton(this));
+ add_subwindow(new BC_CancelButton(this));
+ unlock_window();
+}
+