summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-06-04 12:46:37 +0000
committeralberth <alberth@openttd.org>2009-06-04 12:46:37 +0000
commit1a4934ef070aee3e506603707850de28c7f872cd (patch)
tree7a00edd951c0fbfc8b057822018f8f4509da56b7 /src/window.cpp
parent5c9071fcffc54eb1bf32d671cf521fadd407491d (diff)
downloadopenttd-1a4934ef070aee3e506603707850de28c7f872cd.tar.xz
(svn r16515) -Codechange: Added scrollbar handling for nested widgets, and finding widgets by type or position in the tree.
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/window.cpp b/src/window.cpp
index da14e0fd3..ec829dc5b 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -399,23 +399,24 @@ static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
{
if (widget < 0) return;
- const Widget *wi1 = &w->widget[widget];
- const Widget *wi2 = &w->widget[widget + 1];
-
- /* The listbox can only scroll if scrolling was done on the scrollbar itself,
- * or on the listbox (and the next item is (must be) the scrollbar)
- * XXX - should be rewritten as a widget-dependent scroller but that's
- * not happening until someone rewrites the whole widget-code */
- Scrollbar *sb;
- if ((sb = &w->vscroll, wi1->type == WWT_SCROLLBAR) || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR) ||
- (sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
-
- if (sb->count > sb->cap) {
- int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
- if (pos != sb->pos) {
- sb->pos = pos;
- w->SetDirty();
- }
+ Scrollbar *sb = NULL;
+ if (w->widget != NULL) {
+ const Widget *wi1 = &w->widget[widget];
+ const Widget *wi2 = &w->widget[widget + 1];
+ if (wi1->type == WWT_SCROLLBAR || wi2->type == WWT_SCROLLBAR) {
+ sb = &w->vscroll;
+ } else if (wi1->type == WWT_SCROLL2BAR || wi2->type == WWT_SCROLL2BAR) {
+ sb = &w->vscroll2;
+ }
+ }
+
+ if (w->nested_array != NULL && (uint)widget < w->nested_array_size) sb = w->nested_array[widget]->FindScrollbar(w);
+
+ if (sb != NULL && sb->count > sb->cap) {
+ int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
+ if (pos != sb->pos) {
+ sb->pos = pos;
+ w->SetDirty();
}
}
}