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: 2007-04-13 16:16:03 $ 00024 Source File: $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pglistboxbaseitem.cpp,v $ 00025 CVS/RCS Revision: $Revision: 1.2 $ 00026 Status: $State: Exp $ 00027 */ 00028 00029 #include "pglistboxbaseitem.h" 00030 #include "pglistbox.h" 00031 00032 PG_ListBoxBaseItem::PG_ListBoxBaseItem(PG_Widget* parent, Uint16 height, void* userdata) : PG_Label(parent, PG_Rect(0,0,0,height)) { 00033 my_userdata = userdata; 00034 my_selected = false; 00035 my_hover = false; 00036 //my_itemheight = height; 00037 00038 if (parent != NULL) { 00039 SetIndent(GetParent()->GetIndent()); 00040 SetAlignment(GetParent()->GetAlignment()); 00041 } 00042 } 00043 00044 PG_ListBoxBaseItem::~PG_ListBoxBaseItem() { 00045 if(GetParent() == NULL) { 00046 return; 00047 } 00048 00049 if(GetParent()->GetSelectedItem() == this) { 00050 GetParent()->SelectItem(NULL); 00051 //GetParent()->RemoveWidget(this, true, true); 00052 } 00053 00054 for (PG_Widget* w = next(); w != NULL; w = w->next()) { 00055 w->SetID(w->GetID() - 1); 00056 } 00057 } 00058 00059 void PG_ListBoxBaseItem::SetUserData(void* userdata) { 00060 my_userdata = userdata; 00061 } 00062 00063 void* PG_ListBoxBaseItem::GetUserData() { 00064 return my_userdata; 00065 } 00066 00067 bool PG_ListBoxBaseItem::IsSelected() { 00068 return my_selected; 00069 } 00070 00071 void PG_ListBoxBaseItem::Select(bool select) { 00072 my_selected = select; 00073 00074 if(GetParent() != NULL) { 00075 if(select) { 00076 GetParent()->SelectItem(this); 00077 // SelectItem will call Update... 00078 } else 00079 Update(); 00080 } 00081 } 00082 00083 void PG_ListBoxBaseItem::eventSizeWidget(Uint16 w, Uint16 h) { 00084 //my_itemheight = h; 00085 } 00086 00087 void PG_ListBoxBaseItem::eventMouseEnter() { 00088 my_hover = true; 00089 Update(); 00090 } 00091 00092 void PG_ListBoxBaseItem::eventMouseLeave() { 00093 my_hover = false; 00094 PG_Label::eventMouseLeave(); 00095 Update(); 00096 } 00097 00098 void PG_ListBoxBaseItem::eventHide() { 00099 my_hover = false; 00100 } 00101 00102 bool PG_ListBoxBaseItem::eventMouseButtonUp(const SDL_MouseButtonEvent* button) { 00103 00104 if(button->button == 4 && this != PG_Label::GetParent()->GetChildList()->first()) { 00105 SDL_WarpMouse(button->x, button->y - my_height); 00106 return true; 00107 } 00108 00109 if(button->button == 5 && this != PG_Label::GetParent()->GetChildList()->last()) { 00110 SDL_WarpMouse(button->x, button->y + my_height); 00111 return true; 00112 } 00113 00114 if(button->button != 1) { 00115 return false; 00116 } 00117 00118 if(GetParent() == NULL || !GetParent()->IsVisible()) { 00119 return true; 00120 } 00121 00122 if(GetParent()->GetMultiSelect()) { 00123 Select(!IsSelected()); 00124 } else { 00125 Select(true); 00126 } 00127 00128 return true; 00129 } 00130 00131 PG_ListBox* PG_ListBoxBaseItem::GetParent() { 00132 if(PG_Label::GetParent() == NULL) { 00133 return NULL; 00134 } 00135 // oh, oh,... close your eyes 00136 // hack hack 00137 return dynamic_cast<PG_ListBox*>(PG_Label::GetParent()->GetParent()); 00138 }
1.4.2