-
Notifications
You must be signed in to change notification settings - Fork 2
/
uicore_ListBox.h
196 lines (157 loc) · 5.94 KB
/
uicore_ListBox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
Copyright (C) 2007 Benjamin Litzelmann
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// TODO : a special class for listitems, inherited from switch button, but
// - private inheritance with only useful functions set as public
// - not focusable (focus is for list itself, scrolling is done with arrows instead of tab)
// and add a propery to listbox that disallow to have no item selected
#ifndef _UICORE_LISTBOX_H_
#define _UICORE_LISTBOX_H_
#include "uicore_Slider.h"
#include "uicore_ListItem.h"
namespace UICore
{
class ListBox : public Panel
{
protected:
virtual void Initialize( void );
std::list<ListItem*> items;
std::map<int, ListItem*> selectedItems;
Slider *scrollbar;
bool horizontal;
bool multipleSelection;
bool itemsswitchable;
float scrollbarSize;
float itemSize;
ListItem *focusedItem;
void (*ListGotFocus) (BaseObject *target );
void (*ListLostFocus) (BaseObject *target );
void (*ItemSelected)( ListItem *target, int position, bool isSelected );
static void GotFocusHandler( BaseObject *target );
static void LostFocusHandler( BaseObject *target );
static void ItemSwitch( BaseObject *target, bool newValue );
virtual void BaseMouseDown( float x, float y, int button );
virtual void BaseKeyDown( int key, int charVal );
static void Scroll( BaseObject *target, int, int );
virtual void updateItemPositions( void );
virtual void updateScrollbarBounds( void );
virtual void trackScrollbarEnabled( void );
public:
ListBox();
ListBox( BaseObject *parent, float x, float y, float w, float h, bool horizontal );
virtual ~ListBox();
MEMORY_OPERATORS
virtual int addItem( ListItem *item, int position = -1, bool deletePrevious = false );
virtual ListItem * getItem( int position = -1 );
virtual int getItemPosition( ListItem *item ) const;
virtual bool removeItem( ListItem *item, bool deleteIt = true );
virtual bool removeItem( int position, bool deleteIt = true );
virtual void clear( bool deleteIt = true );
virtual int getNbItem( void ) const;
virtual bool selectItem( int position );
virtual void ensureItemVisible(ListItem *item, int visible = 0);
virtual bool selectItem( ListItem *item );
virtual bool unselectItem( int position );
virtual bool unselectItem( ListItem *item );
virtual void clearSelection( void );
virtual ListItem * getSelectedItem( int index = 0 );
virtual int getSelectedPosition( int index = 0 );
virtual int getNbSelectedItem( void ) const;
virtual void setSize( float w, float h );
inline virtual void setItemsSwitchable( bool v );
inline virtual void setMultipleSelection( bool v );
inline virtual void setHorizontal( bool v );
inline virtual void setScrollbarSize( float size );
inline virtual void setItemSize( float size );
/** Returns an iterator set at the first item of the list. @Remark Using this function is UNSAFE */
inline virtual std::list<ListItem*>::iterator getFirstItemIterator( void );
/** Returns an iterator set just after the last item of the list. @Remark Using this function is UNSAFE */
inline virtual std::list<ListItem*>::iterator getEndItemIterator( void );
inline virtual bool getMultipleSelection( void ) const;
inline virtual bool isHorizontal( void ) const;
inline virtual float getScrollbarSize( void ) const;
inline virtual float getItemSize( void ) const;
inline virtual void setItemSelectedHandler( void (*ItemSelected)( ListItem *target, int position, bool isSelected ) );
inline virtual void setGotFocusHandler( void (*GotFocus)( BaseObject *target ) );
inline virtual void setLostFocusHandler( void (*LostFocus)( BaseObject *target ) );
inline virtual std::string getType( void ) const;
};
void ListBox::setItemsSwitchable( bool v )
{
itemsswitchable = v;
}
void ListBox::setMultipleSelection( bool v )
{
multipleSelection = v;
}
void ListBox::setHorizontal( bool v )
{
horizontal = v;
scrollbar->setHorizontal( v );
setSize( getWidth(), getHeight() );
updateScrollbarBounds();
updateItemPositions();
}
void ListBox::setScrollbarSize( float size )
{
scrollbarSize = size;
setSize( getWidth(), getHeight() );
}
void ListBox::setItemSize( float size )
{
itemSize = size;
setSize( getWidth(), getHeight() );
}
std::list<ListItem*>::iterator ListBox::getFirstItemIterator( void )
{
return items.begin();
}
std::list<ListItem*>::iterator ListBox::getEndItemIterator( void )
{
return items.end();
}
bool ListBox::getMultipleSelection( void ) const
{
return multipleSelection;
}
bool ListBox::isHorizontal( void ) const
{
return horizontal;
}
float ListBox::getScrollbarSize( void ) const
{
return scrollbarSize;
}
float ListBox::getItemSize( void ) const
{
return itemSize;
}
void ListBox::setItemSelectedHandler( void (*ItemSelected)( ListItem *target, int position, bool isSelected ) )
{
this->ItemSelected = ItemSelected;
}
void ListBox::setGotFocusHandler( void (*GotFocus)( BaseObject *target ) )
{
ListGotFocus = GotFocus;
}
void ListBox::setLostFocusHandler( void (*LostFocus)( BaseObject *target ) )
{
ListLostFocus = LostFocus;
}
std::string ListBox::getType( void ) const
{
return UICORE_TYPE_LISTBOX;
}
}
#endif