Don't crash while in the lobby when receiving an error IQ stanza without an error...
[0ad.git] / source / gui / CList.h
blobab046fb020104878532fa826bb7e44f47208aa77
1 /* Copyright (C) 2017 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_CLIST
19 #define INCLUDED_CLIST
21 #include "IGUIScrollBar.h"
23 /**
24 * Create a list of elements, where one can be selected
25 * by the user. The control will use a pre-processed
26 * text-object for each element, which will be managed
27 * by the IGUITextOwner structure.
29 * A scroll-bar will appear when needed. This will be
30 * achieved with the IGUIScrollBarOwner structure.
32 class CList : public IGUIScrollBarOwner, public IGUITextOwner
34 GUI_OBJECT(CList)
36 public:
37 CList();
38 virtual ~CList();
40 /**
41 * @see IGUIObject#ResetStates()
43 virtual void ResetStates() { IGUIScrollBarOwner::ResetStates(); }
45 /**
46 * Adds an item last to the list.
48 virtual void AddItem(const CStrW& str, const CStrW& data);
50 protected:
51 /**
52 * Sets up text, should be called every time changes has been
53 * made that can change the visual.
55 virtual void SetupText();
57 /**
58 * @see IGUIObject#HandleMessage()
60 virtual void HandleMessage(SGUIMessage& Message);
62 /**
63 * Handle events manually to catch keyboard inputting.
65 virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev);
67 /**
68 * Draws the List box
70 virtual void Draw();
72 /**
73 * Easy select elements functions
75 virtual void SelectNextElement();
76 virtual void SelectPrevElement();
77 virtual void SelectFirstElement();
78 virtual void SelectLastElement();
80 /**
81 * Handle the \<item\> tag.
83 virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile);
85 // Called every time the auto-scrolling should be checked.
86 void UpdateAutoScroll();
88 // Extended drawing interface, this is so that classes built on the this one
89 // can use other sprite names.
90 virtual void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor);
92 // Get the area of the list. This is so that it can easily be changed, like in CDropDown
93 // where the area is not equal to m_CachedActualSize.
94 virtual CRect GetListRect() const { return m_CachedActualSize; }
96 // Returns whether SetupText() has run since the last message was received
97 // (and thus whether list items have possibly changed).
98 virtual bool GetModified() const { return m_Modified; }
101 * List of each element's relative y position. Will be
102 * one larger than m_Items, because it will end with the
103 * bottom of the last element. First element will always
104 * be zero, but still stored for easy handling.
106 std::vector<float> m_ItemsYPositions;
108 virtual int GetHoveredItem();
110 private:
111 // Whether the list's items have been modified since last handling a message.
112 bool m_Modified;
114 // Used for doubleclick registration
115 int m_PrevSelectedItem;
117 // Last time a click on an item was issued
118 double m_LastItemClickTime;
121 #endif // INCLUDED_CLIST