Advanced Strategic Command
dropdownselector.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  dropdownselector
3  -------------------
4  copyright : (C) 2006 by Martin Bickel
5  email : <bickel@asc-hq.org>
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "dropdownselector.h"
18 
19 
20 DropDownSelector::DropDownSelector( PG_Widget *parent, const PG_Rect &r, int itemnum, const char** items, const std::string &style )
21  : PG_DropDown( parent, r, -1, style ), first(true)
22 {
23  SetEditable(false);
24  sigSelectItem.connect( sigc::hide( sigc::mem_fun( *this, &DropDownSelector::itemSelected )));
25 
26  for ( int i = 0; i < itemnum; ++i )
27  AddItem( items[i] );
28 
29 }
30 
31 
32 DropDownSelector::DropDownSelector( PG_Widget *parent, const PG_Rect &r, const std::vector<ASCString>& names, const std::string &style )
33  : PG_DropDown( parent, r, -1, style ), first(true)
34 {
35  SetEditable(false);
36  sigSelectItem.connect( sigc::hide( sigc::mem_fun( *this, &DropDownSelector::itemSelected )));
37 
38  for ( std::vector<ASCString>::const_iterator i = names.begin(); i != names.end(); ++i )
39  AddItem( *i );
40 }
41 
42 
43 
44 DropDownSelector::DropDownSelector( PG_Widget *parent, const PG_Rect &r, int id, const std::string &style)
45  : PG_DropDown( parent, r, id, style ), first(true)
46 {
47  SetEditable(false);
48  sigSelectItem.connect( sigc::hide( sigc::mem_fun( *this, &DropDownSelector::itemSelected )));
49 }
50 
52 {
53  selectionSignal( GetSelectedItemIndex ());
54  return true;
55 }
56 
57 
58 void DropDownSelector::AddItem (const std::string &text, void *userdata, Uint16 height)
59 {
60  PG_DropDown::AddItem( text, userdata, height );
61  if ( first ) {
62  first = false;
63  SelectFirstItem();
64  }
65 }
66 
67 
sigc::signal< void, int > selectionSignal
void AddItem(const std::string &text, void *userdata=NULL, Uint16 height=0)
DropDownSelector(PG_Widget *parent, const PG_Rect &r=PG_Rect::null, int id=-1, const std::string &style="DropDown")