#include <xlistbox.h>
Inheritance diagram for Ars::XListBox:


Public Member Functions | |
| XListBox (void) | |
| virtual | ~XListBox (void) |
| Standard destructor. | |
| virtual void | Init (icstring &aStr) |
| virtual const bool | SetupWindow (const Message &msg) |
| Deregister the setup_window message. | |
| unsigned int | GetItemHeight (void) |
| void | SetItemHeight (const unsigned int iItemHeight) |
| iItemHeight The height of the items in the listbox | |
| const int | AddItem (XListItem ListItem) |
| const int | AddItem (const std::string &aText) |
| XListItem & | GetItem (const int iItemIndex) |
| void | RemoveItem (const int iItemIndex) |
| void | ClearItems (void) |
| Remove all items from the list. | |
| int const | Size (void) |
| The number of items in the list. | |
| const bool | IsSelected (const int iItemIndex) |
| void | SetSelection (const int iItemIndex, const bool bSelected) |
| void | SetAllSelections (const bool bSelected) |
| virtual void | DrawBG (void) |
| virtual void | Draw (void) |
| Draws the button and renders the button label. | |
| virtual void | SetWindowRect (const XRect &WindowRect) |
| virtual const bool | evMouseButtonDown (const MouseMessage &msg) |
| virtual const bool | evMouseButtonUp (const MouseMessage &msg) |
| virtual const bool | evValueChange (const CtrlMessage &msg) |
| virtual const bool | evValueChanging (const CtrlMessage &msg) |
| virtual const bool | evKeyDown (const KeyboardMessage &msg) |
Protected Attributes | |
| XScrollBar * | vScrollBar |
| A pointer to the vertical scrollbar. | |
| int | itemHeight |
| The height of the items in the list. | |
| int | focusedItem |
| The currently focused item. | |
| std::vector< XListItem > | listItem |
| The list of items. | |
| std::vector< bool > | selectedItem |
| A vector of booleans indicating which items are selected. | |
| bool | m_bSingleSelection |
| If true, only one item can be selected at a time. | |
|
|
Constructs a new listbox
Definition at line 5 of file xlistbox.cpp. References vScrollBar.
00006 : vScrollBar( 0 ) , focusedItem( 0 ) 00007 { 00008 vScrollBar = new XScrollBar(); 00009 } |
|
|
Standard destructor.
Definition at line 12 of file xlistbox.cpp. References vScrollBar.
00013 {
00014 if( vScrollBar )
00015 delete vScrollBar;
00016 vScrollBar = 0;
00017 }
|
|
|
Definition at line 56 of file xlistbox.cpp. References AddItem(), Ars::Thing::GetFgColor(), and Ars::HPaint::GetFont().
00057 {
00058 return AddItem( XListItem( aText , 0 , GetFgColor() , GetFont() ) );
00059 }
|
|
|
Adds a new item to the list
Definition at line 61 of file xlistbox.cpp. References Ars::HPaint::GetFontSize(), Ars::XRect::Height(), listItem, selectedItem, Ars::Thing::SetDirty(), Ars::XScrollBar::SetLimits(), and vScrollBar. Referenced by AddItem(), and Ars::XDropDown::AddItem().
00062 {
00063 listItem.push_back( ListItem );
00064 selectedItem.push_back( false );
00065 int iMax = (listItem.size() - 1) < 0 ? 0 : static_cast<int>(listItem.size() - 1);
00066
00067 iMax -= (Height() / GetFontSize());
00068 vScrollBar->SetLimits(0, max( 0 , iMax ) );
00069 SetDirty( true );
00070 return static_cast<const int>(listItem.size());
00071 }
|
|
|
Remove all items from the list.
Definition at line 84 of file xlistbox.cpp. References listItem, selectedItem, Ars::Thing::SetDirty(), Ars::XScrollBar::SetLimits(), and vScrollBar. Referenced by Ars::XDropDown::ClearItems().
00085 {
00086 listItem.clear();
00087 selectedItem.clear();
00088 vScrollBar->SetLimits(0, 0);
00089 SetDirty( true );
00090 }
|
|
|
Draws the button and renders the button label.
Reimplemented from Ars::XBox. Definition at line 109 of file xlistbox.cpp. References Ars::XRect::Bottom(), Ars::XRect::ClipTo(), Ars::HPaint::DrawRect(), focusedItem, Ars::Thing::GetBgColor(), Ars::Window::GetClientRect(), Ars::Thing::GetFgColor(), Ars::XScrollBar::GetPosition(), Ars::XRect::Grow(), itemHeight, listItem, Ars::XRect::Overlaps(), selectedItem, Ars::XRect::SetBottom(), Ars::HPaint::SetFont(), Ars::HPaint::TextOutStr(), vScrollBar, and Ars::XRect::Width().
00110 {
00111 w -= 21;
00112 XBox::Draw();
00113 w += 21;
00114 XRect r( GetClientRect() );
00115 r.w -= 21;
00116 r.Grow( -1 );
00117 // DrawRect( r , true , GetFgColor().FadeColor( 64 ) , GetBgColor() );
00118 int iStartIndex = vScrollBar->GetPosition();
00119 for( int i = iStartIndex; i < (int)listItem.size(); ++i )
00120 {
00121 XRect ItemRect( r.x , r.y + (i - iStartIndex) * itemHeight, r.Width() , itemHeight );
00122 if( ItemRect.Overlaps(r ) )
00123 {
00124 ItemRect.ClipTo( r );
00125 ItemRect.SetBottom(ItemRect.Bottom() - 1);
00126 if( selectedItem[i] )
00127 DrawRect( ItemRect, true, listItem[i].ItemColor, listItem[i].ItemColor );
00128 if (i == focusedItem)
00129 {
00130 ItemRect.Grow(1);
00131 DrawRect(ItemRect, false, GetFgColor().FadeColor( 64 ), listItem[i].ItemColor );
00132 ItemRect.Grow(-1);
00133 }
00134 ItemRect.Grow(-1);
00135 FontEngine *prev = SetFont( listItem[i].fontEngine );
00136 TextOutStr( ItemRect , listItem[i].itemText , selectedItem[i] ? GetBgColor() : listItem[i].ItemColor );
00137 SetFont( prev );
00138 }
00139 }
00140 }
|
|
|
Render the background for the control Draws the background as a filled CRect Reimplemented from Ars::Window. Definition at line 102 of file xlistbox.cpp.
00103 {
00104 w -= 21;
00105 XBox::DrawBG();
00106 w += 21;
00107 }
|
|
|
Reimplemented from Ars::MessageClient. Definition at line 230 of file xlistbox.cpp. References Ars::Message::Destination(), focusedItem, Ars::Window::GetClientRect(), Ars::XScrollBar::GetPosition(), Ars::XRect::Height(), IsSelected(), itemHeight, Ars::KeyboardMessage::Key, listItem, Ars::Thing::SetDirty(), Ars::XScrollBar::SetPosition(), SetSelection(), Size(), and vScrollBar.
00231 {
00232 bool ans = XBox::evKeyDown( msg );
00233
00234 if( !listItem.empty() && msg.Destination() == this )
00235 {
00236 XRect ClientRect( GetClientRect() );
00237 switch( msg.Key )
00238 {
00239 case SDLK_DOWN:
00240 if (focusedItem + 1 < Size())
00241 {
00242 focusedItem++;
00243 int diff = focusedItem - vScrollBar->GetPosition();
00244 if( itemHeight * (vScrollBar->GetPosition() + diff + 1) > (int) ClientRect.Height())
00245 vScrollBar->SetPosition(vScrollBar->GetPosition() + 1);
00246
00247 SetDirty();
00248 ans = true;
00249 }
00250 break;
00251 case SDLK_UP:
00252 if ( focusedItem > 0 )
00253 {
00254 focusedItem--;
00255 if (focusedItem < vScrollBar->GetPosition())
00256 vScrollBar->SetPosition(vScrollBar->GetPosition() - 1);
00257 SetDirty();
00258 ans = true;
00259 }
00260 break;
00261
00262 case SDLK_PAGEDOWN:
00263 {
00264 int nSize = Size() - 1;
00265 int nItemsPerPage=ClientRect.Height() / itemHeight;
00266 if (focusedItem + nItemsPerPage < nSize)
00267 focusedItem += nItemsPerPage;
00268 else
00269 focusedItem = nSize;
00270 vScrollBar->SetPosition(focusedItem);
00271 SetDirty();
00272 ans = true;
00273 break;
00274 }
00275 case SDLK_PAGEUP:
00276 {
00277 int nItemsPerPage=ClientRect.Height() / itemHeight;
00278 if (focusedItem - nItemsPerPage > 0)
00279 focusedItem -= nItemsPerPage;
00280 else
00281 focusedItem = 0;
00282 vScrollBar->SetPosition(focusedItem);
00283 SetDirty();
00284 ans = true;
00285 break;
00286 }
00287 case SDLK_SPACE:
00288 SetSelection(focusedItem, !IsSelected(focusedItem));
00289 SetDirty();
00290 ans = true;
00291 break;
00292 default:
00293 ans = false;
00294 break;
00295 }
00296 }
00297 return ans;
00298 }
|
|
|
Reimplemented from Ars::Window. Definition at line 153 of file xlistbox.cpp. References Ars::MouseMessage::Button, focusedItem, Ars::Window::GetClientRect(), Ars::XScrollBar::GetPosition(), Ars::XRect::HitTest(), itemHeight, listItem, Ars::MouseMessage::Point, Ars::XRect::RELPOS_INSIDE, Ars::Thing::SetDirty(), vScrollBar, and Ars::XPoint::y.
00154 {
00155 bool ans = XBox::evMouseButtonDown( msg );
00156
00157 if( !listItem.empty() )
00158 {
00159 XRect ClientRect( GetClientRect() );
00160 if( msg.Button == MouseMessage::LEFT && ClientRect.HitTest( msg.Point ) == RELPOS_INSIDE )
00161 {
00162 if( ArsApplication::GetInstance()->GetKeyFocus() != this )
00163 ArsApplication::GetInstance()->SetKeyFocus( this );
00164
00165 // Prep the new selection
00166 focusedItem = max( 0 , min( (int)listItem.size() - 1 , (msg.Point.y - ClientRect.y) / itemHeight + vScrollBar->GetPosition() ) );
00167
00168 SetDirty();
00169 ans = true;
00170 }
00171 }
00172 return ans;
00173 }
|
|
|
Reimplemented from Ars::Window. Definition at line 175 of file xlistbox.cpp. References ArsSendMessage, Ars::MouseMessage::Button, focusedItem, Ars::Window::GetClientRect(), Ars::Window::GetParent(), Ars::XScrollBar::GetPosition(), Ars::XRect::HitTest(), IsSelected(), itemHeight, listItem, m_bSingleSelection, Ars::MouseMessage::Point, Ars::XRect::RELPOS_INSIDE, SetAllSelections(), Ars::Thing::SetDirty(), SetSelection(), vScrollBar, and Ars::XPoint::y.
00176 {
00177 bool ans = XBox::evMouseButtonUp( msg );
00178
00179 if( !listItem.empty() )
00180 {
00181 XRect ClientRect( GetClientRect() );
00182 if( msg.Button == MouseMessage::LEFT && ClientRect.HitTest( msg.Point ) == RELPOS_INSIDE )
00183 {
00184 // Set the new selection
00185 if( (int)focusedItem == (msg.Point.y - ClientRect.y) / itemHeight + vScrollBar->GetPosition())
00186 {
00187 if( m_bSingleSelection )
00188 SetAllSelections( false );
00189 SetSelection( focusedItem , ! IsSelected(focusedItem) );
00190 ArsSendMessage( CtrlMessage( Message::CTRL_VALUECHANGE, GetParent(), this, focusedItem ) );
00191 SetDirty();
00192 }
00193 ans = true;
00194 }
00195 }
00196
00197 return ans;
00198 }
|
|
|
Reimplemented from Ars::MessageClient. Definition at line 200 of file xlistbox.cpp. References listItem, Ars::Thing::SetDirty(), Ars::CtrlMessage::source, and vScrollBar.
00201 {
00202 bool ans = XBox::evValueChange( msg );
00203
00204 if( !listItem.empty() )
00205 {
00206 if( msg.source == vScrollBar )
00207 {
00208 SetDirty();
00209 ans = true;
00210 }
00211 }
00212 return ans;
00213 }
|
|
|
Reimplemented from Ars::MessageClient. Definition at line 215 of file xlistbox.cpp. References listItem, Ars::Thing::SetDirty(), Ars::CtrlMessage::source, and vScrollBar.
00216 {
00217 bool ans = XBox::evValueChanging( msg );
00218
00219 if( !listItem.empty() )
00220 {
00221 if( msg.source == vScrollBar )
00222 {
00223 SetDirty();
00224 ans = true;
00225 }
00226 }
00227 return ans;
00228 }
|
|
|
Returns the desired item
Definition at line 69 of file xlistbox.h. References listItem. Referenced by Ars::XDropDown::evValueChange(), and Ars::XDropDown::GetItem().
00069 { return listItem[iItemIndex]; }
|
|
|
Definition at line 53 of file xlistbox.h. References itemHeight. Referenced by Ars::XDropDown::GetItemHeight().
00053 { return itemHeight; }
|
|
|
Initialize the thing object via a string the CAR identifiers used are: itemHeight: height of all items... (default -1 for the current font height) mselect: set to 1 if multi selectionis allowed - default single select (scrollbar <s-expression> ): description of the scroll bar Reimplemented from Ars::Window. Definition at line 19 of file xlistbox.cpp. References F_MULTISELECT, F_NONE, Ars::Thing::GetBgColor(), Ars::Thing::GetFgColor(), Ars::Thing::GetFlags(), Ars::HPaint::GetFont(), Ars::HPaint::GetFontSize(), Ars::XRect::Height(), icstring, Ars::XScrollBar::Init(), itemHeight, m_bSingleSelection, Ars::XRect::Right(), S_SUNKEN, Ars::Thing::SetBgColor(), Ars::Thing::SetFgColor(), Ars::Thing::SetFlags(), Ars::HPaint::SetFont(), Ars::XScrollBar::SetLimits(), Ars::Thing::SetState(), Ars::XScrollBar::SetWindowRect(), vScrollBar, and Ars::XRect::XRect(). Referenced by Ars::XDropDown::Init().
00020 {
00021 XBox::Init( aStr );
00022
00023 icstring tmp = Rsrc::FindCrdOf( aStr , "ItemHeight" );
00024 itemHeight = Rsrc::GetInt( tmp , GetFont()->GetFontSize() );
00025
00026 m_bSingleSelection = (GetFlags() & F_MULTISELECT) == 0;
00027
00028 vScrollBar->SetFgColor( GetFgColor() );
00029 vScrollBar->SetBgColor( GetBgColor() );
00030 vScrollBar->SetFont( GetFont() );
00031 vScrollBar->SetState( S_SUNKEN );
00032 vScrollBar->SetFlags( F_NONE );
00033 vScrollBar->SetLimits( 0 , 0 );
00034 tmp = Rsrc::FindCrdOf( aStr , "scrollbar" );
00035 vScrollBar->Init( tmp );
00036
00037 vScrollBar->SetWindowRect( XRect( Right() - 20, y , 20 , Height() ) );
00038 }
|
|
|
Definition at line 85 of file xlistbox.h. References selectedItem. Referenced by evKeyDown(), evMouseButtonUp(), and Ars::XDropDown::IsSelected().
00085 { return selectedItem[iItemIndex]; }
|
|
|
Remove an item from the list
Definition at line 73 of file xlistbox.cpp. References Ars::HPaint::GetFontSize(), Ars::XRect::Height(), listItem, selectedItem, Ars::Thing::SetDirty(), Ars::XScrollBar::SetLimits(), and vScrollBar. Referenced by Ars::XDropDown::RemoveItem().
00074 {
00075 listItem.erase(listItem.begin() + iItemIndex);
00076 selectedItem.erase(selectedItem.begin() + iItemIndex);
00077 int iMax = (listItem.size() - 1) < 0 ? 0 : static_cast<int>(listItem.size() - 1);
00078 iMax -= (Height() / GetFontSize());
00079 vScrollBar->SetLimits(0, max( 0 , iMax ) );
00080 SetDirty( true );
00081 }
|
|
|
Set the selection for all of the items at once
Definition at line 92 of file xlistbox.cpp. References F_SELECTABLE, Ars::Thing::GetFlags(), listItem, selectedItem, and Ars::Thing::SetDirty(). Referenced by evMouseButtonUp(), Ars::XDropDown::evValueChange(), and Ars::XDropDown::SetAllSelections().
00093 {
00094 if( GetFlags() & F_SELECTABLE )
00095 {
00096 for( unsigned int i = 0; i < listItem.size(); ++i )
00097 selectedItem[i] = bSelected;
00098 SetDirty( true );
00099 }
00100 }
|
|
|
iItemHeight The height of the items in the listbox
Definition at line 56 of file xlistbox.h. References itemHeight, and Ars::Thing::SetDirty(). Referenced by Ars::XDropDown::SetItemHeight().
00056 { itemHeight = iItemHeight; SetDirty( true ); }
|
|
||||||||||||
|
Set an item as selected
Definition at line 90 of file xlistbox.h. References F_SELECTABLE, Ars::Thing::GetFlags(), selectedItem, and Ars::Thing::SetDirty(). Referenced by evKeyDown(), evMouseButtonUp(), and Ars::XDropDown::SetSelection().
00091 { if( GetFlags() & F_SELECTABLE )
00092 {
00093 selectedItem[iItemIndex] = bSelected;
00094 SetDirty( true );
00095 }
00096 }
|
|
|
Deregister the setup_window message.
Reimplemented from Ars::Window. Definition at line 40 of file xlistbox.cpp. References Ars::Window::SetParent(), Ars::XScrollBar::SetupWindow(), and vScrollBar. Referenced by Ars::XDropDown::SetupWindow().
00041 {
00042 XBox::SetupWindow( msg );
00043
00044 vScrollBar->SetParent( this );
00045
00046 vScrollBar->SetupWindow( msg );
00047
00048 MessageServer::Instance().RegisterMessageClient(this, Message::MOUSE_BUTTONDOWN);
00049 MessageServer::Instance().RegisterMessageClient(this, Message::MOUSE_BUTTONUP);
00050 MessageServer::Instance().RegisterMessageClient(this, Message::KEYBOARD_KEYDOWN);
00051 MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_VALUECHANGE);
00052 MessageServer::Instance().RegisterMessageClient(this, Message::CTRL_VALUECHANGING);
00053 return true;
00054 }
|
|
|
Giving a control a new WindowRect will move and resize the control
Reimplemented from Ars::Window. Definition at line 143 of file xlistbox.cpp. References Ars::Window::clientRect, Ars::XRect::Grow(), Ars::XRect::Height(), Ars::XRect::Right(), Ars::XScrollBar::SetWindowRect(), vScrollBar, Ars::XRect::Width(), and Ars::XRect::XRect(). Referenced by Ars::XDropDown::Init().
00144 {
00145 XBox::SetWindowRect( WindowRect );
00146
00147 XRect ScrollbarRect( *this );
00148 ScrollbarRect.Grow(-1);
00149 vScrollBar->SetWindowRect( XRect( ScrollbarRect.Right() - 12 , ScrollbarRect.y , ScrollbarRect.Width(), ScrollbarRect.Height() ) );
00150 clientRect = XRect( 2 , 2 , Width() - 16 , Height() - 4 );
00151 }
|
|
|
The number of items in the list.
Definition at line 79 of file xlistbox.h. References listItem. Referenced by evKeyDown(), and Ars::XDropDown::Size().
00079 { return static_cast<int>(listItem.size()); }
|
|
|
The currently focused item.
Definition at line 26 of file xlistbox.h. Referenced by Draw(), evKeyDown(), evMouseButtonDown(), and evMouseButtonUp(). |
|
|
The height of the items in the list.
Definition at line 25 of file xlistbox.h. Referenced by Draw(), evKeyDown(), evMouseButtonDown(), evMouseButtonUp(), GetItemHeight(), Init(), and SetItemHeight(). |
|
|
The list of items.
Definition at line 27 of file xlistbox.h. Referenced by AddItem(), ClearItems(), Draw(), evKeyDown(), evMouseButtonDown(), evMouseButtonUp(), evValueChange(), evValueChanging(), GetItem(), RemoveItem(), SetAllSelections(), and Size(). |
|
|
If true, only one item can be selected at a time.
Definition at line 29 of file xlistbox.h. Referenced by evMouseButtonUp(), and Init(). |
|
|
A vector of booleans indicating which items are selected.
Definition at line 28 of file xlistbox.h. Referenced by AddItem(), ClearItems(), Draw(), IsSelected(), RemoveItem(), SetAllSelections(), and SetSelection(). |
|
|
A pointer to the vertical scrollbar.
Definition at line 24 of file xlistbox.h. Referenced by AddItem(), ClearItems(), Draw(), evKeyDown(), evMouseButtonDown(), evMouseButtonUp(), evValueChange(), evValueChanging(), Init(), RemoveItem(), SetupWindow(), SetWindowRect(), XListBox(), and ~XListBox(). |
1.3.3