Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pglistbox.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2008-05-24 18:21:04 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pglistbox.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.3 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pglistbox.h"
00030 #include "pglistboxbaseitem.h"
00031 #include "pgscrollarea.h"
00032 #include "pglog.h"
00033 
00034 #include "propstrings_priv.h"
00035 
00036 PG_ListBox::PG_ListBox(PG_Widget* parent, const PG_Rect& r, const std::string& style) : PG_WidgetList(parent, r, style),
00037 my_selectedItem(NULL), my_alignment(PG_Label::LEFT) {
00038         my_multiselect = false;
00039         my_indent = 0;
00040         my_selectindex = -1;
00041         PG_ThemeWidget::LoadThemeStyle(style, PG_PropStr::ListBox);
00042         EnableScrollBar(false, PG_ScrollBar::HORIZONTAL);
00043 }
00044 
00045 PG_ListBox::~PG_ListBox() {}
00046 
00047 void PG_ListBox::AddChild(PG_Widget* item) {
00048         if(item == NULL) {
00049                 return;
00050         }
00051 
00052         item->SizeWidget(Width(), item->Height());
00053 
00054         PG_WidgetList::AddChild(item);
00055 
00056         item->SetID(my_scrollarea->GetChildList()->size() - 1);
00057 }
00058 
00059 void PG_ListBox::SetMultiSelect(bool multi) {
00060         my_multiselect = multi;
00061 }
00062 
00063 bool PG_ListBox::GetMultiSelect() {
00064         return my_multiselect;
00065 }
00066 
00067 void PG_ListBox::SelectItem(PG_ListBoxBaseItem* item, bool select, bool fireEvent ) {
00068 
00069         if(item == NULL) {
00070                 if(my_selectedItem != NULL) {
00071                         my_selectedItem->Select(false);
00072                         my_selectedItem->Update();
00073                         my_selectedItem = NULL;
00074                 }
00075                 return;
00076         }
00077 
00078         if(!my_multiselect) {
00079                 if((my_selectedItem != NULL) && (my_selectedItem != item)) {
00080                         my_selectedItem->Select(false);
00081                         my_selectedItem->Update();
00082                 }
00083 
00084                 my_selectedItem = item;
00085                 my_selectindex = item->GetID();
00086                 my_selectedItem->Update();
00087         } else
00088       item->Update();
00089 
00090         if ( fireEvent ) {
00091            sigSelectItem(item);
00092            eventSelectItem(item);
00093         }
00094 }
00095 
00096 bool PG_ListBox::eventSelectItem(PG_ListBoxBaseItem* item) {
00097         return false;
00098 }
00099 
00100 bool PG_ListBox::eventMouseButtonUp(const SDL_MouseButtonEvent* button) {
00101         return true;
00102 }
00103 
00104 bool PG_ListBox::eventMouseButtonDown(const SDL_MouseButtonEvent* button) {
00105         return true;
00106 }
00107 
00108 bool PG_ListBox::eventMouseMotion(const SDL_MouseMotionEvent* motion) {
00109         return true;
00110 }
00111 
00112 void PG_ListBox::RemoveAll() {
00113    my_selectindex = -1;
00114    my_selectedItem = NULL;
00115         my_scrollarea->RemoveAll();
00116 }
00117 
00118 void PG_ListBox::DeleteAll() {
00119    my_selectindex = -1;
00120         my_selectedItem = NULL;
00121         my_scrollarea->DeleteAll();
00122         my_scrollarea->ScrollTo(0,0);
00123         Update();
00124 }
00125 
00126 PG_ListBoxBaseItem* PG_ListBox::GetSelectedItem() {
00127         return my_selectedItem;
00128 }
00129 
00130 void PG_ListBox::SetIndent(Uint16 indent) {
00131         my_indent = indent;
00132         PG_RectList* list = my_scrollarea->GetChildList();
00133         if(list == NULL) {
00134                 return;
00135         }
00136 
00137         for(PG_Widget* w = list->first(); w != NULL; w = w->next()) {
00138                 PG_ListBoxBaseItem* item = static_cast<PG_ListBoxBaseItem*>(w);
00139                 item->SetIndent(my_indent);
00140         }
00141         Update();
00142 }
00143 
00144 void PG_ListBox::SelectFirstItem( bool fireEvent ) {
00145         my_selectindex = 0;
00146    PG_ListBoxBaseItem* item = dynamic_cast<PG_ListBoxBaseItem*>(FindWidget(0));
00147 
00148         if(item == NULL) {
00149                 return;
00150         }
00151 
00152         item->Select(fireEvent);
00153 }
00154 
00155 void PG_ListBox::SelectNextItem( bool fireEvent ) {
00156    PG_ListBoxBaseItem* item = dynamic_cast<PG_ListBoxBaseItem*>(FindWidget(my_selectindex+1));
00157 
00158         if(item == NULL) {
00159                 return;
00160         }
00161 
00162         my_selectindex++;
00163         item->Select(fireEvent);
00164 }
00165 
00166 void PG_ListBox::SelectPrevItem( bool fireEvent ) {
00167    PG_ListBoxBaseItem* item = dynamic_cast<PG_ListBoxBaseItem*>(FindWidget(my_selectindex-1));
00168 
00169         if(item == NULL) {
00170                 return;
00171         }
00172 
00173         my_selectindex--;
00174         item->Select(fireEvent);
00175 }
00176 
00177 int PG_ListBox::GetSelectedIndex() {
00178         return my_selectindex;
00179 }
00180 
00181 void PG_ListBox::GetSelectedItems(std::vector<PG_ListBoxBaseItem*>& items) {
00182         PG_RectList* list = my_scrollarea->GetChildList();
00183         if(list == NULL) {
00184                 return;
00185         }
00186 
00187         for(PG_Widget* i = list->first(); i != NULL; i = i->next()) {
00188                 PG_ListBoxBaseItem* item = static_cast<PG_ListBoxBaseItem*>(i);
00189                 if (item->IsSelected()) {
00190                         items.push_back(item);
00191                 }
00192         }
00193 }
00194 
00195 Uint16 PG_ListBox::GetIndent() {
00196         return my_indent;
00197 }
00198 
00199 void PG_ListBox::SetAlignment(PG_Label::TextAlign style) {
00200         my_alignment = style;
00201 
00202         PG_RectList* list = my_scrollarea->GetChildList();
00203         if(list == NULL) {
00204                 return;
00205         }
00206 
00207         for(PG_Widget* i = list->first(); i != NULL; i = i->next()) {
00208                 static_cast<PG_ListBoxBaseItem*>(i)->SetAlignment(style);
00209         }
00210         Update();
00211 }
00212 
00213 PG_Label::TextAlign PG_ListBox::GetAlignment() {
00214         return my_alignment;
00215 }

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2