PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/source/libs/paragui/src/widgets/pgwidgetlist.cpp

https://bitbucket.org/val_haris/asc-ai
C++ | 124 lines | 74 code | 23 blank | 27 comment | 23 complexity | 3a59acfed13ddbb757129596dd2d3a15 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. /*
  2. ParaGUI - crossplatform widgetset
  3. Copyright (C) 2000,2001,2002 Alexander Pipelka
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Alexander Pipelka
  16. pipelka@teleweb.at
  17. Last Update: $Author: mbickel $
  18. Update Date: $Date: 2009-04-18 13:48:40 $
  19. Source File: $Source: /home/martin/asc/v2/svntest/games/asc/source/libs/paragui/src/widgets/pgwidgetlist.cpp,v $
  20. CVS/RCS Revision: $Revision: 1.3 $
  21. Status: $State: Exp $
  22. */
  23. #include "pgwidgetlist.h"
  24. #include "pgapplication.h"
  25. #include "pgscrollarea.h"
  26. #include "pglog.h"
  27. PG_WidgetList::PG_WidgetList(PG_Widget* parent, const PG_Rect& r, const std::string& style) : PG_ScrollWidget(parent, r, style) {
  28. my_scrollarea->SetShiftOnRemove(false, true);
  29. if(style != "WidgetList") {
  30. LoadThemeStyle("WidgetList");
  31. }
  32. LoadThemeStyle(style);
  33. }
  34. PG_WidgetList::~PG_WidgetList() {}
  35. void PG_WidgetList::AddChild(PG_Widget* w) {
  36. if(w == NULL) {
  37. return;
  38. }
  39. if (my_objVerticalScrollbar == NULL || my_objHorizontalScrollbar == NULL || my_scrollarea == NULL) {
  40. PG_Widget::AddChild(w);
  41. return;
  42. }
  43. w->MoveRect(0, w->my_ypos + my_scrollarea->GetAreaHeight());
  44. my_scrollarea->AddChild(w);
  45. }
  46. PG_Widget* PG_WidgetList::GetWidgetFromPos(Sint32 y) {
  47. Uint32 dy = 0;
  48. Uint32 min_dy = 100000000;
  49. PG_Widget* result = NULL;
  50. PG_Widget* list = GetChildList()->first();
  51. for( ; list != NULL; list = list->next()) {
  52. dy = abs(0- (list->my_ypos - my_ypos));
  53. if(dy < min_dy) {
  54. min_dy = dy;
  55. result = list;
  56. }
  57. }
  58. return result;
  59. }
  60. PG_Widget* PG_WidgetList::FindWidget(int index) {
  61. if((index < 0) || (index >= GetWidgetCount())) {
  62. return NULL;
  63. }
  64. int i = 0;
  65. PG_Widget* list = my_scrollarea->GetChildList()->first();
  66. for( ; list != NULL; list = list->next()) {
  67. if(i == index) {
  68. return list;
  69. }
  70. i++;
  71. }
  72. return NULL;
  73. }
  74. int PG_WidgetList::FindIndex(PG_Widget* w) {
  75. int index = 0;
  76. PG_Widget* list = GetChildList()->first();
  77. for( ; list != NULL; list = list->next()) {
  78. if(list == w) {
  79. return index;
  80. }
  81. index++;
  82. }
  83. return -1;
  84. }
  85. void PG_WidgetList::ScrollTo(Uint16 ypos) {
  86. my_scrollarea->ScrollTo(my_scrollarea->GetScrollPosX(), ypos);
  87. CheckScrollBars();
  88. }
  89. void PG_WidgetList::PageUp() {
  90. my_scrollarea->ScrollTo(my_scrollarea->GetScrollPosX(), my_scrollarea->GetScrollPosY() - my_height );
  91. CheckScrollBars();
  92. }
  93. void PG_WidgetList::PageDown() {
  94. my_scrollarea->ScrollTo(my_scrollarea->GetScrollPosX(), my_scrollarea->GetScrollPosY() + my_height );
  95. CheckScrollBars();
  96. }