00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ndk_demo.h"
00036
00037 using namespace NDK_XX;
00038
00039
00040
00041
00042
00043
00044 const int ID_CLEAR= 10001;
00045 const int ID_REMOVE=10002;
00046 const int ID_EDIT= 10003;
00047 const int ID_SELECTION=10004;
00048 const int ID_CHOICE=10005;
00049 const int ID_SINGLE_CHECK=10006;
00050 const int ID_MULTICHECK=10007;
00051 const int ID_EDIT_DATE= 10008;
00052 const int ID_EDIT_NUM= 10009;
00053 const int ID_ARROW= 10010;
00054 const int ID_SELECT= 10011;
00055
00056
00057
00058 BEGIN_BINDINGS(TestBox,DialogBox)
00059 ON_NOTIFY(LI_SEL_CHANGE,ID_CHOICE,TestBox::on_sel_change)
00060 ON_COMMAND(ID_CLEAR,TestBox::on_clear_list)
00061 ON_COMMAND(ID_REMOVE,TestBox::on_remove)
00062 ON_COMMAND(ID_ARROW,TestBox::on_arrow)
00063 ON_COMMAND(ID_SELECT,TestBox::on_select)
00064 END_BINDINGS()
00065
00066
00067
00068 TestBox::TestBox( const string &title
00069 ,int lines, int cols,int y, int x)
00070 : DialogBox(1,title,lines,cols,y,x,okCancel,Control::title|Control::framed)
00071 ,pEdit(0)
00072 ,pSel(0)
00073 ,pChoice(0)
00074 ,pCheckList(0)
00075 ,pCheckList2(0)
00076 {
00077 }
00078
00079
00080
00081 void TestBox::on_dlg_init()
00082 {
00083
00084
00085
00086 string s1("Name:");
00087 add_child(new Label(this,-1,s1,1,s1.length(),2,1));
00088
00089 pEdit=new Edit(this,ID_EDIT,"",3,40,1,9);
00090 add_child(pEdit);
00091
00092
00093 s1= "Date:";
00094 add_child(new Label(this,-1,s1,1,s1.length(),6,1));
00095
00096 pEditDate=new EditDate(this,ID_EDIT_DATE,"dd/mm/yyyy",5,10,editable|tabstop|notify|framed);
00097
00098 add_child(pEditDate);
00099
00100
00101 s1= "Age:";
00102 add_child(new Label(this,-1,s1,1,s1.length(),6,27));
00103 pEditNum=new EditDouble(this,ID_EDIT_NUM,"",3,12,5,35);
00104 add_child(pEditNum);
00105 pEditNum->use_arrow_as_tab();
00106 pEditNum->set_max_len(9);
00107
00108 int first = curr_child;
00109
00110 add_child(new PushButton(this,ID_CLEAR,"Clear List",8,1));
00111 add_child(new PushButton(this,ID_REMOVE,"Remove",8,15));
00112 add_child(pEdit, new PushButton(this,ID_ARROW,"Arrow as tab",8,25));
00113 add_child(new PushButton(this,ID_SELECT,"Search pattern",8,40));
00114
00115 pSel = new SelectionBox(this,ID_SELECTION,"",6,10,9,1);
00116 pSel->set_vscrollbar();
00117 pSel->add_item(get_param("selection","1","First"),-1,false,false);
00118 pSel->add_item(get_param("selection","2","Second"),-1,false,false);
00119 pSel->add_item(get_param("selection","3","Third"),-1,false,false);
00120 pSel->add_item(get_param("selection","4","Fourth"),-1,false,false);
00121 pSel->add_item(get_param("selection","5","Fifth"),-1,false,false);
00122 pSel->add_item(get_param("selection","6","Sixth"),-1,false,false);
00123 pSel->add_item(get_param("selection","7","Seventh"),-1,false,false);
00124 pSel->add_item(get_param("selection","8","Eighth"),-1,false,false);
00125 pSel->add_item(get_param("selection","9","Nineth"),-1,false,false);
00126 add_child(pSel);
00127
00128 pChoice = new ChoiceBox(this,ID_CHOICE,"",6,10,9,12);
00129 pChoice->add_item("First");
00130 pChoice->add_item("Last");
00131 pChoice->add_item("Middle");
00132 add_child(pChoice);
00133 refresh_choices();
00134
00135
00136
00137 pCheckList = new CheckListBox(this,ID_SINGLE_CHECK,"",6,10,9,23);
00138
00139
00140
00141 add_child(pCheckList);
00142
00143 pCheckList2 = new CheckListBox(this,ID_MULTICHECK,"",6,10,9,34);
00144 pCheckList2->add_item("Checkme");
00145 pCheckList2->add_item("Me too");
00146 pCheckList2->add_item("lemmein");
00147 pCheckList2->set_multisel();
00148
00149 IndexList il;
00150 il.push_back(1);
00151 il.push_back(2);
00152 pCheckList2->set_sel_items(il);
00153 add_child(pCheckList2);
00154
00155 create_buttons();
00156 set_focus_to(pEdit);
00157 }
00158
00159
00160
00161 void TestBox::on_clear_list()
00162 {
00163 long curr = curr_child;
00164 pSel->clear();
00165 set_focus_to(curr);
00166 }
00167
00168
00169
00170 void TestBox::on_arrow()
00171 {
00172 pEditDate->use_arrow_as_tab(!pEditDate->arrow_is_tab());
00173 }
00174
00175
00176
00177 void TestBox::on_select()
00178 {
00179 pSel->sel_string(0,pEdit->get_text());
00180 }
00181
00182
00183
00184 void TestBox::on_remove()
00185 {
00186 long curr = curr_child;
00187 int choice_idx =pChoice->get_cur_sel();
00188 if(choice_idx == -1)
00189 return;
00190 int sel_idx = (int)pChoice->get_item_data(choice_idx);
00191 pSel->remove_item(sel_idx);
00192 refresh_choices();
00193 set_focus_to(curr);
00194 if(pBtnOk)
00195 pBtnOk->enable();
00196 }
00197
00198
00199
00200 void TestBox::refresh_choices()
00201 {
00202 pChoice->set_item_data(0,0);
00203 pChoice->set_item_data(1,(void *)(pSel->get_count()-1));
00204 int pos =(pSel->get_count()/2)-1;
00205 if(pos < 0) pos=0;
00206 pChoice->set_item_data(2,(void *)(pos));
00207 }
00208
00209
00210
00211 void TestBox::on_sel_change(int id)
00212 {
00213 int curr = curr_child;
00214 changed=true;
00215 if(pBtnOk)
00216 pBtnOk->enable();
00217 if(id == pChoice->get_ctrl_id()){
00218 int choice_idx =pChoice->get_cur_sel();
00219 int sel_idx = (int)pChoice->get_item_data(choice_idx);
00220 if(choice_idx < 0)
00221 return;
00222 pSel->set_cur_sel(sel_idx);
00223 pEdit->set_text(pSel->get_item_text(sel_idx));
00224 }
00225 set_focus_to(curr);
00226 }
00227
00228
00229
00230
00231
00232
00233
00234 TabbedDlgBox::TabbedDlgBox( int id
00235 ,int lines, int cols,int y, int x)
00236 : PropertyDialog(id,"Tabbed Dialog",lines,cols,y,x)
00237 {
00238 }
00239
00240
00241
00242 void TabbedDlgBox::on_dlg_init()
00243 {
00244 add_page(new TabbedDlgPage1(this,pages.size()," Tab1 ",height()-4,width(),2,0));
00245 add_page(new TabbedDlgPage2(this,pages.size()," Tab2 ",height()-4,width(),2,0));
00246 add_page(new PropertyPage(this,pages.size()," Tab3 ",height()-4,width(),2,0));
00247 add_page(new PropertyPage(this,pages.size()," Tab4 ",height()-4,width(),2,0));
00248
00249 PropertyDialog::on_dlg_init();
00250 }
00251
00252
00253
00254
00255
00256
00257 TabbedDlgPage1::TabbedDlgPage1(PropertyDialog *parent,int id, const string &title
00258 ,int lines, int cols,int y, int x)
00259 :PropertyPage(parent,id,title,lines,cols,y,x)
00260 {
00261 do_initial_update();
00262 };
00263
00264
00265
00266 void TabbedDlgPage1::on_dlg_init()
00267 {
00268 add_child(new Label(this,-1,get_text(),1,get_text().length(),2,2));
00269 }
00270
00271
00272
00273
00274
00275
00276 BEGIN_BINDINGS(TabbedDlgPage2,PropertyPage)
00277 ON_NOTIFY(LI_SEL_CHANGE,ID_CHOICE,TabbedDlgPage2::on_sel_change)
00278 ON_COMMAND(ID_CLEAR,TabbedDlgPage2::on_clear_list)
00279 ON_COMMAND(ID_REMOVE,TabbedDlgPage2::on_remove)
00280 END_BINDINGS()
00281
00282
00283
00284 TabbedDlgPage2::TabbedDlgPage2( PropertyDialog *parent,int id, const string &tit
00285 ,int lines, int cols,int y, int x)
00286 :PropertyPage(parent,id,tit,lines,cols,y,x)
00287 ,pEdit(0)
00288 ,pSel(0)
00289 ,pChoice(0)
00290 ,pCheckList(0)
00291 ,pCheckList2(0)
00292 {
00293 do_initial_update();
00294 }
00295
00296
00297
00298 void TabbedDlgPage2::on_dlg_init()
00299 {
00300 string s1("Name:");
00301 add_child(new Label(this,-1,s1,1,s1.length(),1,1));
00302
00303 pEdit=new Edit(this,ID_EDIT,"",3,40,2,1);
00304 add_child(pEdit);
00305
00306
00307 int first = curr_child;
00308
00309 add_child(new PushButton(this,ID_CLEAR,"Clear List",5,1));
00310 add_child(new PushButton(this,ID_REMOVE,"Remove",5,15));
00311
00312
00313 pSel = new SelectionBox(this,ID_SELECTION,"",6,10,6,1);
00314 pSel->set_vscrollbar();
00315 pSel->add_item(get_param("selection","1","First"));
00316 pSel->add_item(get_param("selection","2","Second"));
00317 pSel->add_item(get_param("selection","3","Third"));
00318 pSel->add_item(get_param("selection","4","Fourth"));
00319 pSel->add_item(get_param("selection","5","Fifth"));
00320 pSel->add_item(get_param("selection","6","Sixth"));
00321 pSel->add_item(get_param("selection","7","Seventh"));
00322 pSel->add_item(get_param("selection","8","Eighth"));
00323 pSel->add_item(get_param("selection","9","Nineth"));
00324 add_child(pSel);
00325
00326 pChoice = new ChoiceBox(this,ID_CHOICE,"",6,10,6,12);
00327 pChoice->add_item("First");
00328 pChoice->add_item("Last");
00329 pChoice->add_item("Middle");
00330 add_child(pChoice);
00331 refresh_choices();
00332
00333 pChoice->set_cur_sel(get_param("default","4",0));
00334
00335 pCheckList = new CheckListBox(this,ID_SINGLE_CHECK,"",6,10,6,23);
00336
00337
00338
00339 add_child(pCheckList);
00340
00341 pCheckList2 = new CheckListBox(this,ID_MULTICHECK,"",6,10,6,34);
00342 pCheckList2->add_item("Checkme");
00343 pCheckList2->add_item("Me too");
00344 pCheckList2->add_item("lemmein");
00345 pCheckList2->set_multisel();
00346
00347 IndexList il;
00348 il.push_back(1);
00349 il.push_back(2);
00350 pCheckList2->set_sel_items(il);
00351 add_child(pCheckList2);
00352
00353 create_buttons();
00354 set_focus_to(pEdit);
00355 }
00356
00357
00358
00359 void TabbedDlgPage2::on_clear_list()
00360 {
00361 long curr = curr_child;
00362 pSel->clear();
00363 set_focus_to(curr);
00364 changed = true;
00365 on_page_change();
00366 }
00367
00368
00369
00370 void TabbedDlgPage2::on_remove()
00371 {
00372 long curr = curr_child;
00373 int choice_idx =pChoice->get_cur_sel();
00374 if(choice_idx == -1)
00375 return;
00376 int sel_idx = (int)pChoice->get_item_data(choice_idx);
00377 pSel->remove_item(sel_idx);
00378 refresh_choices();
00379 set_focus_to(curr);
00380 changed = true;
00381 on_page_change();
00382 if(pBtnOk)
00383 pBtnOk->enable();
00384 }
00385
00386
00387
00388 void TabbedDlgPage2::refresh_choices()
00389 {
00390 pChoice->set_item_data(0,0);
00391 pChoice->set_item_data(1,(void *)(pSel->get_count()-1));
00392 int pos =(pSel->get_count()/2)-1;
00393 if(pos < 0) pos=0;
00394 pChoice->set_item_data(2,(void *)(pos));
00395 }
00396
00397
00398
00399 void TabbedDlgPage2::on_sel_change(int id)
00400 {
00401 int curr = curr_child;
00402 changed = true;
00403 on_page_change();
00404 if(pBtnOk)
00405 pBtnOk->enable();
00406 if(id == pChoice->get_ctrl_id()){
00407 int choice_idx =pChoice->get_cur_sel();
00408 int sel_idx = (int)pChoice->get_item_data(choice_idx);
00409 if(choice_idx < 0)
00410 return;
00411 pSel->set_cur_sel(sel_idx);
00412 pEdit->set_text(pSel->get_item_text(sel_idx));
00413 }
00414 set_focus_to(curr);
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 APopUpCmd::APopUpCmd()
00426 : PopUpMenu("PopUp")
00427 {
00428 sub_menu_label = "PopUp";
00429 items.push_back(new NonImplementedItem("Useless"));
00430 items.push_back(new ShowTestDialogCmd());
00431 items.push_back(new ShowTabbedDialogCmd());
00432
00433 }
00434
00435
00436
00437
00438
00439
00440 AnotherPopUpCmd::AnotherPopUpCmd()
00441 : PopUpMenu ("2nd Item")
00442 {
00443 sub_menu_label = "Second element";
00444 items.push_back(new ShowTestDialogCmd());
00445 items.push_back(new NonImplementedItem("Second choice"));
00446 items.push_back(new NonImplementedItem("Third choice"));
00447 items.push_back(new NonImplementedItem("Fourth choice"));
00448 items.push_back(new NonImplementedItem("Fift Choice"));
00449
00450 }
00451
00452
00453
00454
00455
00456
00457 void TestApplication::title() {
00458 titleWindow->bkgd(screen_titles());
00459 titleWindow->addstr(0,(titleWindow->cols()-app_title.size())/2,app_title.c_str());
00460 titleWindow->refresh();
00461 }
00462
00463
00464
00465 int TestApplication::run() {
00466 try{
00467 set_param_file_name("testapp.conf");
00468 activateStatusBar();
00469
00470 #ifdef NCURSES_MOUSE_VERSION
00471 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
00472 #endif
00473
00474 activateMenuBar();
00475 }
00476 catch(NCursesException &e){
00477 cout << e.classname() << ":" << e.errorno
00478 << "(" << e.message << ")" << endl;
00479 }
00480 catch(...){
00481 cout << "Unknown error" << endl;
00482 }
00483 return 0;
00484
00485 }
00486
00487
00488 void TestApplication::activateMenuBar()
00489 {
00490 MenuBar menu_bar(-1,"",1,80,0,0,'h');
00491
00492 menu_bar.is_main_menu=true;
00493 menu_bar.add_item( new APopUpCmd());
00494 menu_bar.add_item( new AnotherPopUpCmd());
00495 menu_bar.add_item( new NonImplementedItem("Third"));
00496 menu_bar.add_item( new ExitCmd());
00497 menu_bar.execute();
00498 }
00499
00500
00501 static TestApplication testApp;