Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ndk_demo.cc

Go to the documentation of this file.
00001 // * This makes emacs happy -*-Mode: C++;-*-
00002 /****************************************************************************
00003  * Copyright (c) 2002 Fabrica de Software XXI SRL - info@lafabrica.com.ar   *
00004  * Copyright (c) 2002 RaqLink SA - info@raqlink.com                         *
00005  *                                                                          *
00006  * Permission is hereby granted, free of charge, to any person obtaining a  *
00007  * copy of this software and associated documentation files (the            *
00008  * "Software"), to deal in the Software without restriction, including      *
00009  * without limitation the rights to use, copy, modify, merge, publish,      *
00010  * distribute, distribute with modifications, sublicense, and/or sell       *
00011  * copies of the Software, and to permit persons to whom the Software is    *
00012  * furnished to do so, subject to the following conditions:                 *
00013  *                                                                          *
00014  * The above copyright notice and this permission notice shall be included  *
00015  * in all copies or substantial portions of the Software.                   *
00016  *                                                                          *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00020  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00021  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00022  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00023  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00024  *                                                                          *
00025  * Except as contained in this notice, the name(s) of the above copyright   *
00026  * holders shall not be used in advertising or otherwise to promote the     *
00027  * sale, use or other dealings in this Software without prior written       *
00028  * authorization.                                                           *
00029  ****************************************************************************/
00030 
00031 /****************************************************************************
00032  *  Author Miguel Pinkas <miguel@lafabrica.com.ar>                          *
00033  ****************************************************************************/
00034 
00035 #include "ndk_demo.h"
00036 
00037 using namespace NDK_XX;
00038 
00039 /************************************************************************
00040 *   clase TestBox                                                       *
00041 *   A box we use to test the things we create... %-|                    *
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 
00052 
00053 //-----------------------------------------------------------------------
00054 BEGIN_BINDINGS(TestBox,NDKDialogBox)
00055     ON_NOTIFY(LI_SEL_CHANGE,ID_CHOICE,TestBox::on_sel_change)
00056     ON_COMMAND(ID_CLEAR,TestBox::on_clear_list)
00057     ON_COMMAND(ID_REMOVE,TestBox::on_remove)
00058 END_BINDINGS()
00059 
00060 
00061 //-----------------------------------------------------------------------
00062 TestBox::TestBox(   const string &title
00063                         ,int lines, int cols,int y, int x)
00064     : NDKDialogBox(1,title,lines,cols,y,x,okCancel)
00065         ,pEdit(0)
00066         ,pSel(0)
00067         ,pChoice(0)
00068         ,pCheckList(0)
00069         ,pCheckList2(0)
00070 {
00071 }
00072 
00073 
00074 //-----------------------------------------------------------------------
00075 void TestBox::on_dlg_init()
00076 {
00077     string s1("Name:");
00078     add_child(new NDKDlgLabel(this,-1,s1,1,s1.length(),1,1));
00079 
00080     pEdit=new NDKDlgEdit(this,ID_EDIT,"",3,40,2,1);
00081     add_child(pEdit);
00082 //  pCtrl->set_overwrite();
00083     
00084     int first = curr_child;
00085     
00086     add_child(new NDKDlgPushButton(this,ID_CLEAR,"Clear List",6,1));
00087     add_child(new NDKDlgPushButton(this,ID_REMOVE,"Remove",6,15));
00088 
00089     pSel = new NDKDlgSelectionBox(this,ID_SELECTION,"",6,10,8,1);
00090     pSel->set_vscrollbar();
00091     pSel->add_item(get_param("selection","1","First"));
00092     pSel->add_item(get_param("selection","2","Second"));
00093     pSel->add_item(get_param("selection","3","Third"));
00094     pSel->add_item(get_param("selection","4","Fourth"));
00095     pSel->add_item(get_param("selection","5","Fifth"));
00096     pSel->add_item(get_param("selection","6","Sixth"));
00097     pSel->add_item(get_param("selection","7","Seventh"));
00098     pSel->add_item(get_param("selection","8","Eighth"));
00099     pSel->add_item(get_param("selection","9","Nineth"));
00100     add_child(pSel);
00101     
00102     pChoice = new NDKDlgChoiceBox(this,ID_CHOICE,"",6,10,8,12);
00103     pChoice->add_item("First");
00104     pChoice->add_item("Last");
00105     pChoice->add_item("Middle");
00106     add_child(pChoice);
00107     refresh_choices();
00108 
00109     pChoice->set_cur_sel(get_param("default","4",0));
00110     
00111     pCheckList = new NDKDlgCheckListBox(this,ID_SINGLE_CHECK,"",6,10,8,23);
00112 //  pCheckList->add_item("Check 1");
00113 //  pCheckList->add_item("Check 2");
00114 //  pCheckList->add_item("Check 3");
00115     add_child(pCheckList);
00116     
00117     pCheckList2 = new NDKDlgCheckListBox(this,ID_MULTICHECK,"",6,10,8,34);
00118     pCheckList2->add_item("Checkme");
00119     pCheckList2->add_item("Me too");
00120     pCheckList2->add_item("lemmein");
00121     pCheckList2->set_multisel();
00122     
00123     IndexList il;
00124     il.push_back(1);
00125     il.push_back(2);
00126     pCheckList2->set_sel_items(il);
00127     add_child(pCheckList2);
00128 
00129     create_buttons(); 
00130     set_focus_to(pEdit);
00131 }
00132 
00133 
00134 //-----------------------------------------------------------------------
00135 void TestBox::on_clear_list()
00136 {
00137     long curr = curr_child;
00138     pSel->clear();
00139     set_focus_to(curr);
00140 }
00141 
00142 
00143 //-----------------------------------------------------------------------
00144 void TestBox::on_remove()
00145 {
00146     long curr = curr_child;
00147     int choice_idx =pChoice->get_cur_sel();
00148     if(choice_idx == -1)
00149         return;
00150     int sel_idx = (int)pChoice->get_item_data(choice_idx);
00151     pSel->remove_item(sel_idx);
00152     refresh_choices();
00153     set_focus_to(curr);
00154     if(pBtnOk)
00155         pBtnOk->enable(); 
00156 }
00157 
00158 
00159 //-----------------------------------------------------------------------
00160 void TestBox::refresh_choices()
00161 {
00162     pChoice->set_item_data(0,0);
00163     pChoice->set_item_data(1,(void *)(pSel->get_count()-1));
00164     int pos =(pSel->get_count()/2)-1;
00165     if(pos < 0) pos=0;
00166     pChoice->set_item_data(2,(void *)(pos));
00167 }
00168 
00169 
00170 //-----------------------------------------------------------------------
00171 void TestBox::on_sel_change(int id)
00172 {
00173     int curr = curr_child;
00174     changed=true;
00175     if(pBtnOk)
00176         pBtnOk->enable();
00177     if(id == pChoice->get_ctrl_id()){
00178         int choice_idx =pChoice->get_cur_sel();
00179         int sel_idx = (int)pChoice->get_item_data(choice_idx);
00180         if(choice_idx < 0)
00181             return; 
00182         pSel->set_cur_sel(sel_idx);     
00183         pEdit->set_text(pSel->get_item_text(sel_idx));
00184     }
00185     set_focus_to(curr);
00186 }
00187 
00188 
00189 /************************************************************************
00190 *   class APopUpCmd                                                     *
00191 ************************************************************************/
00192 //-----------------------------------------------------------------------
00193 APopUpCmd::APopUpCmd()
00194      : NDKPopUpMenu("PopUp")
00195 { 
00196     sub_menu_label = "PopUp";
00197     items.push_back(new BackCmd());
00198     items.push_back(new NonImplementedItem("Useless"));
00199     items.push_back(new ShowTestDialogCmd());
00200     items.push_back(new ClosingMarkItem());
00201 }
00202 
00203 
00204 /************************************************************************
00205 *   class AnotherPopUpCmd                                               *
00206 ************************************************************************/
00207 //-----------------------------------------------------------------------
00208 AnotherPopUpCmd::AnotherPopUpCmd()
00209     : NDKPopUpMenu ("2nd Item")
00210 {  
00211     sub_menu_label = "Second element";
00212     items.push_back(new BackCmd());
00213     items.push_back(new ShowTestDialogCmd());
00214     items.push_back(new NonImplementedItem("Second choice"));
00215     items.push_back(new NonImplementedItem("Third choice"));
00216     items.push_back(new NonImplementedItem("Fourth choice"));
00217     items.push_back(new NonImplementedItem("Fift Choice"));
00218     items.push_back(new ClosingMarkItem());
00219 }
00220 
00221 
00222 /************************************************************************
00223 *   class TestApplication                                               *
00224 ************************************************************************/
00225 //-----------------------------------------------------------------------
00226 void TestApplication::title() {
00227   const char * const title = " NDK++ Demo Application";
00228   const int len = ::strlen(title);
00229 
00230   titleWindow->bkgd(screen_titles());
00231   titleWindow->addstr(0,(titleWindow->cols()-len)/2,title);
00232   titleWindow->refresh();
00233 }
00234 
00235 
00236 //-----------------------------------------------------------------------
00237 int TestApplication::run() {
00238 try{
00239     set_param_file_name("testapp.conf");
00240     activateStatusBar();
00241 
00242     ListOfItems items;
00243     items.push_back( new APopUpCmd());
00244     items.push_back( new AnotherPopUpCmd());
00245     items.push_back( new NonImplementedItem("Third"));
00246     items.push_back( new ExitCmd());
00247     items.push_back( new ClosingMarkItem());
00248 
00249     activateMenuBar(items);
00250     ListOfItems::iterator it;
00251     for(it=items.begin();it!=items.end();it++){
00252         delete *it;
00253     }
00254 }
00255 catch(NCursesException &e){
00256     cout    << e.classname() << ":" << e.errorno 
00257             << "(" << e.message << ")" << endl;
00258 }
00259 catch(...){
00260     cout << "Unknown error" << endl;
00261 }
00262     return 0;
00263 
00264 }
00265 
00266 //-----------------------------------------------------------------------
00267 void TestApplication::activateMenuBar(ListOfItems &items)
00268 {
00269     NDKMenuBar menuBar(1,80,0,0,items);
00270 //  NDKFramedMenuBar menuBar(1,80,0,0,items);
00271     menuBar();
00272 }
00273 
00274 //-----------------------------------------------------------------------
00275 static TestApplication testApp;

Generated on Tue Aug 27 10:49:45 2002 by doxygen1.2.17