Debian Codegraph @

components/extension/youtube/videolist.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2016 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include "videolist.h"
14
15 BoCA::VideoList::VideoList(const Point &iPos, const Size &iSize)
16 {
17 scrollbar = NIL;
18 scrollbarPos = 0;
19
20 visibleEntriesChecksum = 0;
21
22 SetBackgroundColor(Setup::ClientColor);
23 SetMetrics(iPos, iSize);
24
25 if (GetWidth() == 0) SetWidth(120);
26 if (GetHeight() == 0) SetHeight(80);
27
28 onChangeSize.Connect(&VideoList::OnChangeSize, this);
29
30 scrollbar = new Scrollbar(Point(), Size(), OR_HORZ, &scrollbarPos, 0, 1);
31 scrollbar->SetOrientation(OR_LOWERLEFT);
32 scrollbar->SetStepSize(15);
33 scrollbar->onValueChange.Connect(&VideoList::OnScrollbarValueChange, this);
34 scrollbar->Hide();
35
36 Add(scrollbar);
37 }
38
39 BoCA::VideoList::~VideoList()
40 {
41 DeleteObject(scrollbar);
42 }
43
44 Int BoCA::VideoList::Paint(Int message)
45 {
46 if (!IsRegistered()) return Error();
47 if (!IsVisible()) return Success();
48
49 Surface *surface = GetDrawSurface();
50 Rect frame = Rect(GetRealPosition(), GetRealSize());
51
52 String visibleEntries;
53
54 Int entriesWidth = 0;
55
56 switch (message)
57 {
58 case SP_PAINT:
59 surface->StartPaint(frame);
60
61 entriesWidth = GetEntriesWidth();
62
63 if (entriesWidth > GetWidth() - 4)
64 {
65 scrollbar->SetMetrics(Point(1, 18), Size(GetWidth() - 2, scrollbar->GetHeight()));
66 scrollbar->SetRange(0, entriesWidth - (GetWidth() - 4));
67
68 scrollbar->SetPageSize(GetWidth() - 4);
69
70 scrollbar->Show();
71 }
72 else
73 {
74 scrollbar->Hide();
75
76 scrollbarPos = 0;
77 }
78
79 if (IsActive()) surface->Box(frame - Size(0, scrollbar->IsVisible() ? 18 : 0), Setup::ClientColor, Rect::Filled);
80 else surface->Box(frame - Size(0, scrollbar->IsVisible() ? 18 : 0), Setup::BackgroundColor, Rect::Filled);
81
82 surface->Frame(frame, FRAME_DOWN);
83
84 frame.left = -scrollbarPos;
85 frame.right = frame.left;
86
87 for (Int i = 0; i < Length(); i++)
88 {
89 ListEntry *operat = GetNthEntry(i);
90
91 frame.right += operat->GetRealSize().cx;
92
93 if (frame.right >= 0 && frame.left <= GetRealSize().cx - 4)
94 {
95 operat->SetMetrics(Point(frame.left + 2, 2), Size(operat->GetWidth(), GetHeight() - 4 - (scrollbar->IsVisible() ? 17 : 0)));
96 operat->Show();
97
98 visibleEntries.Append(operat->GetName());
99 }
100 else
101 {
102 operat->Hide();
103 }
104
105 frame.left += operat->GetRealSize().cx;
106 }
107
108 visibleEntriesChecksum = visibleEntries.ComputeCRC32();
109
110 Widget::Paint(message);
111
112 surface->EndPaint();
113
114 break;
115 case SP_UPDATE:
116 entriesWidth = GetEntriesWidth();
117
118 if (entriesWidth > GetWidth() - 4)
119 {
120 if (!scrollbar->IsVisible()) Paint(SP_PAINT);
121 else scrollbar->SetRange(0, entriesWidth - (GetWidth() - 4));
122 }
123
124 frame.left = -scrollbarPos;
125 frame.right = frame.left;
126
127 for (Int i = 0; i < Length(); i++)
128 {
129 ListEntry *operat = GetNthEntry(i);
130
131 frame.right += operat->GetRealSize().cx;
132
133 if (frame.right >= 0 && frame.left <= GetRealSize().cx - 4)
134 {
135 visibleEntries.Append(operat->GetName());
136 }
137
138 frame.left += operat->GetRealSize().cx;
139 }
140
141 if (visibleEntriesChecksum != visibleEntries.ComputeCRC32()) Paint(SP_PAINT);
142
143 break;
144 }
145
146 return Success();
147 }
148
149 Bool BoCA::VideoList::ScrollToEndOfList()
150 {
151 Int entriesWidth = GetEntriesWidth();
152
153 scrollbar->SetValue(entriesWidth - (GetWidth() - 4));
154
155 return True;
156 }
157
158 Rect BoCA::VideoList::GetVisibleArea() const
159 {
160 if (!IsVisible()) return Widget::GetVisibleArea();
161 else return Widget::GetVisibleArea() + Point(2, 0) - Size(4, 0);
162 }
163
164 Int BoCA::VideoList::GetEntriesWidth() const
165 {
166 Int entriesWidth = 0;
167
168 for (Int i = 0; i < GetNOfObjects(); i++)
169 {
170 if (GetNthObject(i)->GetObjectType() != ListEntry::classID) continue;
171
172 entriesWidth += GetNthObject(i)->GetWidth();
173 }
174
175 return entriesWidth;
176 }
177
178 Void BoCA::VideoList::OnScrollbarValueChange()
179 {
180 Paint(SP_PAINT);
181 }
182
183 Void BoCA::VideoList::OnChangeSize(const Size &nSize)
184 {
185 if (scrollbar->IsVisible())
186 {
187 scrollbar->SetWidth(nSize.cx - 2);
188 scrollbar->SetRange(0, GetEntriesWidth() - (GetWidth() - 4));
189
190 scrollbar->SetPageSize(GetWidth() - 4);
191 }
192 }