hrev46986 adds 9 changesets to branch 'master' old head: ae63d4aa97090efd81e15ba5e60956dd909e5e99 new head: 0a2382e3736b944cd18277ec2ed3c49263b8a43d overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=0a2382e+%5Eae63d4a ---------------------------------------------------------------------------- b7929c0: BScrollBar: style fixes, update copyright header c4337a4: BView: style fixes related to mouse scrolling bdcfc07: BScrollView: Increase small scroll step size from 1 to 3 ... and then don't multiply by 3 in BView b9f48ef: WebPositive: style fixes related to scrolling rename dy to deltaY 5b6c94c: ShowImage: Style fixes related to scrolling b2404e2: BView: Check scroll delta isn't 0 ab5c744: BView: ScrollWithMouseWheelDelta return status code a621335: BView: scroll horizontally when holding control ... instead of vertically. This actually swaps horizontal and vertical so if you have a mouse with a fancy 2-axis scroll ball it will swap the x and y coordinates. (untested) 0a2382e: ShowImage: Scroll horizontally with control ...instead of command. See //www.freelists.org/post/haiku-commits/haiku-hrev46304-srckitsinterface,18 [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 5 files changed, 234 insertions(+), 180 deletions(-) headers/os/interface/View.h | 2 +- src/apps/showimage/ShowImageView.cpp | 50 +++-- src/apps/webpositive/BrowserWindow.cpp | 7 +- src/kits/interface/ScrollBar.cpp | 324 ++++++++++++++++------------- src/kits/interface/View.cpp | 31 +-- ############################################################################ Commit: b7929c057493bb4c4505cf2fdad06b4395b8cd59 URL: http://cgit.haiku-os.org/haiku/commit/?id=b7929c0 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 21:58:35 2014 UTC BScrollBar: style fixes, update copyright header ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ScrollBar.cpp b/src/kits/interface/ScrollBar.cpp index d15e0fe..34d9a12 100644 --- a/src/kits/interface/ScrollBar.cpp +++ b/src/kits/interface/ScrollBar.cpp @@ -1,17 +1,23 @@ /* - * Copyright 2001-2009, Haiku, Inc. All rights reserved. + * Copyright 2001-2014 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: - * Marc Flerackers (mflerackers@xxxxxxxxxx) - * DarkWyrm (bpmagic@xxxxxxxxxxxxxxx) - * Stefano Ceccherini (burton666@xxxxxxxxx) - * Stephan Aßmus <superstippi@xxxxxx> + * Stephan Aßmus, superstippi@xxxxxx + * Stefano Ceccherini, burton666@xxxxxxxxx + * DarkWyrm, bpmagic@xxxxxxxxxxxxxxx + * Marc Flerackers, mflerackers@xxxxxxxxxx + * John Scipione, jscipione@xxxxxxxxx */ #include <ScrollBar.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + #include <ControlLook.h> #include <LayoutUtils.h> #include <Message.h> @@ -19,12 +25,9 @@ #include <Shape.h> #include <Window.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - #include <binary_compatibility/Interface.h> + //#define TRACE_SCROLLBAR #ifdef TRACE_SCROLLBAR # define TRACE(x...) printf(x) @@ -41,54 +44,56 @@ typedef enum { ARROW_NONE } arrow_direction; -#define SBC_SCROLLBYVALUE 0 -#define SBC_SETDOUBLE 1 -#define SBC_SETPROPORTIONAL 2 -#define SBC_SETSTYLE 3 + +#define SBC_SCROLLBYVALUE 0 +#define SBC_SETDOUBLE 1 +#define SBC_SETPROPORTIONAL 2 +#define SBC_SETSTYLE 3 // Quick constants for determining which arrow is down and are defined with // respect to double arrow mode. ARROW1 and ARROW4 refer to the outer pair of // arrows and ARROW2 and ARROW3 refer to the inner ones. ARROW1 points left/up // and ARROW4 points right/down. -#define ARROW1 0 -#define ARROW2 1 -#define ARROW3 2 -#define ARROW4 3 -#define THUMB 4 -#define NOARROW -1 +#define ARROW1 0 +#define ARROW2 1 +#define ARROW3 2 +#define ARROW4 3 +#define THUMB 4 +#define NOARROW -1 static const bigtime_t kRepeatDelay = 300000; + // Because the R5 version kept a lot of data on server-side, we need to kludge // our way into binary compatibility class BScrollBar::Private { public: Private(BScrollBar* scrollBar) - : - fScrollBar(scrollBar), - fEnabled(true), - fRepeaterThread(-1), - fExitRepeater(false), - fRepeaterDelay(0), - fThumbFrame(0.0, 0.0, -1.0, -1.0), - fDoRepeat(false), - fClickOffset(0.0, 0.0), - fThumbInc(0.0), - fStopValue(0.0), - fUpArrowsEnabled(true), - fDownArrowsEnabled(true), - fBorderHighlighted(false), - fButtonDown(NOARROW) + : + fScrollBar(scrollBar), + fEnabled(true), + fRepeaterThread(-1), + fExitRepeater(false), + fRepeaterDelay(0), + fThumbFrame(0.0, 0.0, -1.0, -1.0), + fDoRepeat(false), + fClickOffset(0.0, 0.0), + fThumbInc(0.0), + fStopValue(0.0), + fUpArrowsEnabled(true), + fDownArrowsEnabled(true), + fBorderHighlighted(false), + fButtonDown(NOARROW) { - #ifdef TEST_MODE +#ifdef TEST_MODE fScrollBarInfo.proportional = true; fScrollBarInfo.double_arrows = true; fScrollBarInfo.knob = 0; fScrollBarInfo.min_knob_size = 15; - #else +#else get_scroll_bar_info(&fScrollBarInfo); - #endif +#endif } ~Private() @@ -100,12 +105,12 @@ public: } } - void DrawScrollBarButton(BScrollBar *owner, arrow_direction direction, - BRect frame, bool down = false); + void DrawScrollBarButton(BScrollBar* owner, arrow_direction direction, + BRect frame, bool down = false); static int32 button_repeater_thread(void* data); - int32 ButtonRepeaterThread(); + int32 ButtonRepeaterThread(); BScrollBar* fScrollBar; bool fEnabled; @@ -138,7 +143,7 @@ public: // This thread is spawned when a button is initially pushed and repeatedly scrolls // the scrollbar by a little bit after a short delay int32 -BScrollBar::Private::button_repeater_thread(void *data) +BScrollBar::Private::button_repeater_thread(void* data) { BScrollBar::Private* privateData = (BScrollBar::Private*)data; return privateData->ButtonRepeaterThread(); @@ -159,7 +164,6 @@ BScrollBar::Private::ButtonRepeaterThread() // repeat loop while (!fExitRepeater) { if (fScrollBar->LockLooper()) { - if (fDoRepeat) { float value = fScrollBar->Value() + fThumbInc; if (fButtonDown == NOARROW) { @@ -168,9 +172,8 @@ BScrollBar::Private::ButtonRepeaterThread() fScrollBar->SetValue(value); if (fThumbInc < 0.0 && value >= fStopValue) fScrollBar->SetValue(value); - } else { + } else fScrollBar->SetValue(value); - } } fScrollBar->UnlockLooper(); @@ -189,19 +192,20 @@ BScrollBar::Private::ButtonRepeaterThread() } -// #pragma mark - +// #pragma mark - BScrollBar -BScrollBar::BScrollBar(BRect frame, const char* name, BView *target, - float min, float max, orientation direction) - : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE - | B_FRAME_EVENTS), +BScrollBar::BScrollBar(BRect frame, const char* name, BView* target, + float min, float max, orientation direction) + : + BView(frame, name, B_FOLLOW_NONE, + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), fMin(min), fMax(max), - fSmallStep(1), - fLargeStep(10), + fSmallStep(1.0f), + fLargeStep(10.0f), fValue(0), - fProportion(0.0), + fProportion(0.0f), fTarget(NULL), fOrientation(direction), fTargetName(NULL) @@ -222,15 +226,16 @@ BScrollBar::BScrollBar(BRect frame, const char* name, BView *target, } -BScrollBar::BScrollBar(const char* name, BView *target, - float min, float max, orientation direction) - : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), +BScrollBar::BScrollBar(const char* name, BView* target, + float min, float max, orientation direction) + : + BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), fMin(min), fMax(max), - fSmallStep(1), - fLargeStep(10), + fSmallStep(1.0f), + fLargeStep(10.0f), fValue(0), - fProportion(0.0), + fProportion(0.0f), fTarget(NULL), fOrientation(direction), fTargetName(NULL) @@ -248,7 +253,8 @@ BScrollBar::BScrollBar(const char* name, BView *target, BScrollBar::BScrollBar(BMessage* data) - : BView(data), + : + BView(data), fTarget(NULL), fTargetName(NULL) { @@ -257,15 +263,20 @@ BScrollBar::BScrollBar(BMessage* data) // TODO: Does the BeOS implementation try to find the target // by name again? Does it archive the name at all? if (data->FindFloat("_range", 0, &fMin) < B_OK) - fMin = 0.0; + fMin = 0.0f; + if (data->FindFloat("_range", 1, &fMax) < B_OK) - fMax = 0.0; + fMax = 0.0f; + if (data->FindFloat("_steps", 0, &fSmallStep) < B_OK) - fSmallStep = 1.0; + fSmallStep = 1.0f; + if (data->FindFloat("_steps", 1, &fLargeStep) < B_OK) - fLargeStep = 10.0; + fLargeStep = 10.0f; + if (data->FindFloat("_val", &fValue) < B_OK) fValue = 0.0; + int32 orientation; if (data->FindInt32("_orient", &orientation) < B_OK) { fOrientation = B_VERTICAL; @@ -294,7 +305,7 @@ BScrollBar::~BScrollBar() BArchivable* -BScrollBar::Instantiate(BMessage *data) +BScrollBar::Instantiate(BMessage* data) { if (validate_instantiation(data, "BScrollBar")) return new BScrollBar(data); @@ -303,7 +314,7 @@ BScrollBar::Instantiate(BMessage *data) status_t -BScrollBar::Archive(BMessage *data, bool deep) const +BScrollBar::Archive(BMessage* data, bool deep) const { status_t err = BView::Archive(data, deep); if (err != B_OK) @@ -383,7 +394,6 @@ BScrollBar::SetValue(float value) return; value = roundf(value); - if (value == fValue) return; @@ -410,17 +420,16 @@ BScrollBar::ValueChanged(float newValue) { TRACE("BScrollBar(%s)::ValueChanged(%.1f)\n", Name(), newValue); - if (fTarget) { + if (fTarget != NULL) { // cache target bounds BRect targetBounds = fTarget->Bounds(); // if vertical, check bounds top and scroll if different from newValue - if (fOrientation == B_VERTICAL && targetBounds.top != newValue) { + if (fOrientation == B_VERTICAL && targetBounds.top != newValue) fTarget->ScrollBy(0.0, newValue - targetBounds.top); - } + // if horizontal, check bounds left and scroll if different from newValue - if (fOrientation == B_HORIZONTAL && targetBounds.left != newValue) { + if (fOrientation == B_HORIZONTAL && targetBounds.left != newValue) fTarget->ScrollBy(newValue - targetBounds.left, 0.0); - } } TRACE(" -> %.1f\n", newValue); @@ -432,28 +441,28 @@ BScrollBar::ValueChanged(float newValue) void BScrollBar::SetProportion(float value) { - if (value < 0.0) - value = 0.0; - if (value > 1.0) - value = 1.0; + if (value < 0.0f) + value = 0.0f; + else if (value > 1.0f) + value = 1.0f; if (value == fProportion) return; + TRACE("BScrollBar(%s)::SetProportion(%.1f)\n", Name(), value); bool oldEnabled = fPrivateData->fEnabled && fMin < fMax - && fProportion < 1.0 && fProportion >= 0.0; + && fProportion < 1.0f && fProportion >= 0.0f; fProportion = value; bool newEnabled = fPrivateData->fEnabled && fMin < fMax - && fProportion < 1.0 && fProportion >= 0.0; + && fProportion < 1.0f && fProportion >= 0.0f; _UpdateThumbFrame(); if (oldEnabled != newEnabled) Invalidate(); - } @@ -467,9 +476,10 @@ BScrollBar::Proportion() const void BScrollBar::SetRange(float min, float max) { - if (min > max || isnanf(min) || isnanf(max) || isinff(min) || isinff(max)) { - min = 0; - max = 0; + if (min > max || isnanf(min) || isnanf(max) + || isinff(min) || isinff(max)) { + min = 0.0f; + max = 0.0f; } min = roundf(min); @@ -492,7 +502,7 @@ BScrollBar::SetRange(float min, float max) void -BScrollBar::GetRange(float *min, float *max) const +BScrollBar::GetRange(float* min, float* max) const { if (min != NULL) *min = fMin; @@ -515,6 +525,7 @@ BScrollBar::SetSteps(float smallStep, float largeStep) largeStep = roundf(largeStep); if (fSmallStep == smallStep && fLargeStep == largeStep) return; + TRACE("BScrollBar(%s)::SetSteps(small=%.1f, large=%.1f)\n", Name(), smallStep, largeStep); @@ -536,9 +547,10 @@ BScrollBar::SetSteps(float smallStep, float largeStep) void BScrollBar::GetSteps(float* smallStep, float* largeStep) const { - if (smallStep) + if (smallStep != NULL) *smallStep = fSmallStep; - if (largeStep) + + if (largeStep != NULL) *largeStep = fLargeStep; } @@ -642,13 +654,16 @@ BScrollBar::MessageReceived(BMessage* message) int32 value; if (message->FindInt32("value", &value) == B_OK) ValueChanged(value); + break; } + case B_MOUSE_WHEEL_CHANGED: { // Must handle this here since BView checks for the existence of // scrollbars, which a scrollbar itself does not have - float deltaX = 0.0f, deltaY = 0.0f; + float deltaX = 0.0f; + float deltaY = 0.0f; message->FindFloat("be:wheel_delta_x", &deltaX); message->FindFloat("be:wheel_delta_y", &deltaY); @@ -660,9 +675,9 @@ BScrollBar::MessageReceived(BMessage* message) ScrollWithMouseWheelDelta(this, deltaY); } + default: BView::MessageReceived(message); - break; } } @@ -677,8 +692,9 @@ BScrollBar::MouseDown(BPoint where) int32 buttons; if (Looper() == NULL || Looper()->CurrentMessage() == NULL - || Looper()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK) + || Looper()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK) { buttons = B_PRIMARY_MOUSE_BUTTON; + } if (buttons & B_SECONDARY_MOUSE_BUTTON) { // special absolute scrolling: move thumb to where we clicked @@ -713,15 +729,19 @@ BScrollBar::MouseDown(BPoint where) case ARROW1: scrollValue = -buttonStepSize; break; + case ARROW2: scrollValue = buttonStepSize; break; + case ARROW3: scrollValue = -buttonStepSize; break; + case ARROW4: scrollValue = buttonStepSize; break; + case NOARROW: // we hit the empty area, figure out which side of the thumb if (fOrientation == B_VERTICAL) { @@ -778,9 +798,10 @@ BScrollBar::MouseUp(BPoint pt) void BScrollBar::MouseMoved(BPoint where, uint32 transit, const BMessage* message) { - if (!fPrivateData->fEnabled || fMin >= fMax || fProportion >= 1.0 - || fProportion < 0.0) + if (!fPrivateData->fEnabled || fMin >= fMax || fProportion >= 1.0f + || fProportion < 0.0f) { return; + } if (fPrivateData->fButtonDown != NOARROW) { if (fPrivateData->fButtonDown == THUMB) { @@ -854,10 +875,10 @@ BScrollBar::Draw(BRect updateRect) } else StrokeRect(bounds); - bounds.InsetBy(1.0, 1.0); + bounds.InsetBy(1.0f, 1.0f); bool enabled = fPrivateData->fEnabled && fMin < fMax - && fProportion < 1.0 && fProportion >= 0.0; + && fProportion < 1.0f && fProportion >= 0.0f; rgb_color light, dark, dark1, dark2; if (enabled) { @@ -886,7 +907,7 @@ BScrollBar::Draw(BRect updateRect) enabled, fPrivateData->fButtonDown == ARROW1); if (doubleArrows) { - buttonFrame.OffsetBy(bounds.Height() + 1, 0.0); + buttonFrame.OffsetBy(bounds.Height() + 1, 0.0f); _DrawArrowButton(ARROW_RIGHT, doubleArrows, buttonFrame, updateRect, enabled, fPrivateData->fButtonDown == ARROW2); @@ -913,7 +934,7 @@ BScrollBar::Draw(BRect updateRect) enabled, fPrivateData->fButtonDown == ARROW1); if (doubleArrows) { - buttonFrame.OffsetBy(0.0, bounds.Width() + 1); + buttonFrame.OffsetBy(0.0f, bounds.Width() + 1); _DrawArrowButton(ARROW_DOWN, doubleArrows, buttonFrame, updateRect, enabled, fPrivateData->fButtonDown == ARROW2); @@ -974,7 +995,7 @@ BScrollBar::Draw(BRect updateRect) thumbColor, 0, BControlLook::B_ALL_BORDERS, fOrientation); // TODO: Add the other thumb styles - dots and lines } else { - if (fMin >= fMax || fProportion >= 1.0 || fProportion < 0.0) { + if (fMin >= fMax || fProportion >= 1.0f || fProportion < 0.0f) { // we cannot scroll at all _DrawDisabledBackground(thumbBG, light, dark, dark1); } else { @@ -1038,7 +1059,7 @@ BScrollBar::FrameResized(float newWidth, float newHeight) BHandler* BScrollBar::ResolveSpecifier(BMessage* message, int32 index, - BMessage* specifier, int32 form, const char *property) + BMessage* specifier, int32 form, const char* property) { return BView::ResolveSpecifier(message, index, specifier, form, property); } @@ -1057,11 +1078,13 @@ BScrollBar::GetPreferredSize(float* _width, float* _height) if (fOrientation == B_VERTICAL) { if (_width) *_width = B_V_SCROLL_BAR_WIDTH; + if (_height) *_height = Bounds().Height(); } else if (fOrientation == B_HORIZONTAL) { if (_width) *_width = Bounds().Width(); + if (_height) *_height = B_H_SCROLL_BAR_HEIGHT; } @@ -1090,7 +1113,7 @@ BScrollBar::AllDetached() status_t -BScrollBar::GetSupportedSuites(BMessage *message) +BScrollBar::GetSupportedSuites(BMessage* message) { return BView::GetSupportedSuites(message); } @@ -1107,7 +1130,7 @@ BSize BScrollBar::MaxSize() { BSize maxSize = _MinSize(); - if (fOrientation == B_HORIZONTAL) + if (fOrientation == B_HORIZONTAL) maxSize.width = B_SIZE_UNLIMITED; else maxSize.height = B_SIZE_UNLIMITED; @@ -1119,10 +1142,11 @@ BSize BScrollBar::PreferredSize() { BSize preferredSize = _MinSize(); - if (fOrientation == B_HORIZONTAL) + if (fOrientation == B_HORIZONTAL) preferredSize.width *= 2; else preferredSize.height *= 2; + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), preferredSize); } @@ -1134,47 +1158,64 @@ BScrollBar::Perform(perform_code code, void* _data) case PERFORM_CODE_MIN_SIZE: ((perform_data_min_size*)_data)->return_value = BScrollBar::MinSize(); + return B_OK; + case PERFORM_CODE_MAX_SIZE: ((perform_data_max_size*)_data)->return_value = BScrollBar::MaxSize(); + return B_OK; + case PERFORM_CODE_PREFERRED_SIZE: ((perform_data_preferred_size*)_data)->return_value = BScrollBar::PreferredSize(); + return B_OK; + case PERFORM_CODE_LAYOUT_ALIGNMENT: ((perform_data_layout_alignment*)_data)->return_value = BScrollBar::LayoutAlignment(); + return B_OK; + case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH: ((perform_data_has_height_for_width*)_data)->return_value = BScrollBar::HasHeightForWidth(); + return B_OK; + case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH: { perform_data_get_height_for_width* data = (perform_data_get_height_for_width*)_data; BScrollBar::GetHeightForWidth(data->width, &data->min, &data->max, &data->preferred); + return B_OK; } + case PERFORM_CODE_SET_LAYOUT: { perform_data_set_layout* data = (perform_data_set_layout*)_data; BScrollBar::SetLayout(data->layout); + return B_OK; } + case PERFORM_CODE_LAYOUT_INVALIDATED: { perform_data_layout_invalidated* data = (perform_data_layout_invalidated*)_data; BScrollBar::LayoutInvalidated(data->descendants); + return B_OK; } + case PERFORM_CODE_DO_LAYOUT: { BScrollBar::DoLayout(); + return B_OK; } } @@ -1199,7 +1240,6 @@ void BScrollBar::_ReservedScrollBar3() {} void BScrollBar::_ReservedScrollBar4() {} - BScrollBar& BScrollBar::operator=(const BScrollBar&) { @@ -1261,6 +1301,7 @@ BScrollBar::_UpdateThumbFrame() float proportion = fProportion; if (fMin >= fMax || proportion > 1.0 || proportion < 0.0) proportion = 1.0; + if (proportion == 0.0) { // Special case a proportion of 0.0, use the large step value // in that case (NOTE: fMin == fMax already handled above) @@ -1281,16 +1322,16 @@ BScrollBar::_UpdateThumbFrame() // the thumb can be scrolled within the remaining area "maxSize - thumbSize - 1.0" float offset = 0.0; - if (fMax > fMin) { + if (fMax > fMin) { offset = floorf(((fValue - fMin) / (fMax - fMin)) * (maxSize - thumbSize - 1.0)); } if (_DoubleArrows()) { offset += buttonSize * 2; - } else { + } else offset += buttonSize; - } + // visual adjustments (room for darker line between thumb and buttons) offset++; @@ -1304,15 +1345,16 @@ BScrollBar::_UpdateThumbFrame() fPrivateData->fThumbFrame.OffsetBy(offset, 0.0); } - if (Window()) { - BRect invalid = oldFrame.IsValid() ? - oldFrame | fPrivateData->fThumbFrame + if (Window() != NULL) { + BRect invalid = oldFrame.IsValid() + ? oldFrame | fPrivateData->fThumbFrame : fPrivateData->fThumbFrame; // account for those two dark lines if (fOrientation == B_HORIZONTAL) invalid.InsetBy(-2.0, 0.0); else invalid.InsetBy(0.0, -2.0); + Invalidate(invalid); } } @@ -1322,7 +1364,7 @@ float BScrollBar::_ValueFor(BPoint where) const { BRect bounds = Bounds(); - bounds.InsetBy(1.0, 1.0); + bounds.InsetBy(1.0f, 1.0f); float offset; float thumbSize; @@ -1333,12 +1375,12 @@ BScrollBar::_ValueFor(BPoint where) const offset = where.y; thumbSize = fPrivateData->fThumbFrame.Height(); maxSize = bounds.Height(); - buttonSize = bounds.Width() + 1.0; + buttonSize = bounds.Width() + 1.0f; } else { offset = where.x; thumbSize = fPrivateData->fThumbFrame.Width(); maxSize = bounds.Width(); - buttonSize = bounds.Height() + 1.0; + buttonSize = bounds.Height() + 1.0f; } if (_DoubleArrows()) { @@ -1356,11 +1398,8 @@ BScrollBar::_ValueFor(BPoint where) const maxSize--; offset++; - float value = fMin + (offset / (maxSize - thumbSize) * (fMax - fMin + 1.0)); - if (value >= 0.0) - return floorf(value + 0.5); - else - return ceilf(value - 0.5); + return roundf(fMin + (offset / (maxSize - thumbSize) + * (fMax - fMin + 1.0f))); } @@ -1368,25 +1407,24 @@ int32 BScrollBar::_ButtonFor(BPoint where) const { BRect bounds = Bounds(); - bounds.InsetBy(1.0, 1.0); + bounds.InsetBy(1.0f, 1.0f); - float buttonSize; - if (fOrientation == B_VERTICAL) { - buttonSize = bounds.Width() + 1.0; - } else { - buttonSize = bounds.Height() + 1.0; - } + float buttonSize = fOrientation == B_VERTICAL + ? bounds.Width() + 1.0f + : bounds.Height() + 1.0f; BRect rect(bounds.left, bounds.top, - bounds.left + buttonSize, bounds.top + buttonSize); + bounds.left + buttonSize, bounds.top + buttonSize); if (fOrientation == B_VERTICAL) { if (rect.Contains(where)) return ARROW1; + if (_DoubleArrows()) { rect.OffsetBy(0.0, buttonSize); if (rect.Contains(where)) return ARROW2; + rect.OffsetTo(bounds.left, bounds.bottom - 2 * buttonSize); if (rect.Contains(where)) return ARROW3; @@ -1397,10 +1435,12 @@ BScrollBar::_ButtonFor(BPoint where) const } else { if (rect.Contains(where)) return ARROW1; + if (_DoubleArrows()) { rect.OffsetBy(buttonSize, 0.0); if (rect.Contains(where)) return ARROW2; + rect.OffsetTo(bounds.right - 2 * buttonSize, bounds.top); if (rect.Contains(where)) return ARROW3; @@ -1418,28 +1458,28 @@ BRect BScrollBar::_ButtonRectFor(int32 button) const { BRect bounds = Bounds(); - bounds.InsetBy(1.0, 1.0); + bounds.InsetBy(1.0f, 1.0f); - float buttonSize; - if (fOrientation == B_VERTICAL) { - buttonSize = bounds.Width() + 1.0; - } else { - buttonSize = bounds.Height() + 1.0; - } + float buttonSize = fOrientation == B_VERTICAL + ? bounds.Width() + 1.0f + : bounds.Height() + 1.0f; BRect rect(bounds.left, bounds.top, - bounds.left + buttonSize - 1.0, bounds.top + buttonSize - 1.0); + bounds.left + buttonSize - 1.0f, bounds.top + buttonSize - 1.0f); if (fOrientation == B_VERTICAL) { switch (button) { case ARROW1: break; + case ARROW2: rect.OffsetBy(0.0, buttonSize); break; + case ARROW3: rect.OffsetTo(bounds.left, bounds.bottom - 2 * buttonSize + 1); break; + case ARROW4: rect.OffsetTo(bounds.left, bounds.bottom - buttonSize + 1); break; @@ -1448,12 +1488,15 @@ BScrollBar::_ButtonRectFor(int32 button) const switch (button) { case ARROW1: break; + case ARROW2: rect.OffsetBy(buttonSize, 0.0); break; + case ARROW3: rect.OffsetTo(bounds.right - 2 * buttonSize + 1, bounds.top); break; + case ARROW4: rect.OffsetTo(bounds.right - buttonSize + 1, bounds.top); break; @@ -1499,13 +1542,13 @@ BScrollBar::_UpdateArrowButtons() status_t -control_scrollbar(scroll_bar_info *info, BScrollBar *bar) +control_scrollbar(scroll_bar_info* info, BScrollBar* bar) { - if (!bar || !info) + if (bar == NULL || info == NULL) return B_BAD_VALUE; if (bar->fPrivateData->fScrollBarInfo.double_arrows - != info->double_arrows) { + != info->double_arrows) { bar->fPrivateData->fScrollBarInfo.double_arrows = info->double_arrows; int8 multiplier = (info->double_arrows) ? 1 : -1; @@ -1531,9 +1574,9 @@ control_scrollbar(scroll_bar_info *info, BScrollBar *bar) return B_BAD_VALUE; if (info->min_knob_size >= SCROLL_BAR_MINIMUM_KNOB_SIZE - && info->min_knob_size <= SCROLL_BAR_MAXIMUM_KNOB_SIZE) + && info->min_knob_size <= SCROLL_BAR_MAXIMUM_KNOB_SIZE) { bar->fPrivateData->fScrollBarInfo.min_knob_size = info->min_knob_size; - else + } else return B_BAD_VALUE; return B_OK; @@ -1541,10 +1584,8 @@ control_scrollbar(scroll_bar_info *info, BScrollBar *bar) void -BScrollBar::_DrawDisabledBackground(BRect area, - const rgb_color& light, - const rgb_color& dark, - const rgb_color& fill) +BScrollBar::_DrawDisabledBackground(BRect area, const rgb_color& light, + const rgb_color& dark, const rgb_color& fill) { if (!area.IsValid()) return; @@ -1609,7 +1650,7 @@ BScrollBar::_DrawDisabledBackground(BRect area, void BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect rect, - const BRect& updateRect, bool enabled, bool down) + const BRect& updateRect, bool enabled, bool down) { if (!updateRect.Intersects(rect)) return; @@ -1617,6 +1658,7 @@ BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect rect, uint32 flags = 0; if (!enabled) flags |= BControlLook::B_DISABLED; + if (down && fPrivateData->fDoRepeat) flags |= BControlLook::B_ACTIVATED; @@ -1630,7 +1672,7 @@ BScrollBar::_DrawArrowButton(int32 direction, bool doubleArrows, BRect rect, // TODO: Why does BControlLook need this negative inset for the arrow to // look right? - rect.InsetBy(-1, -1); + rect.InsetBy(-1.0f, -1.0f); be_control_look->DrawArrowShape(this, rect, updateRect, baseColor, direction, flags, B_DARKEN_MAX_TINT); } @@ -1649,6 +1691,6 @@ BScrollBar::_MinSize() const minSize.height = 2 * B_H_SCROLL_BAR_HEIGHT + 2 * fPrivateData->fScrollBarInfo.min_knob_size; } + return minSize; } - ############################################################################ Commit: c4337a432459de06a63049b06b56ff78c442eba4 URL: http://cgit.haiku-os.org/haiku/commit/?id=c4337a4 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 22:01:41 2014 UTC BView: style fixes related to mouse scrolling ---------------------------------------------------------------------------- diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 84da3ed..99904d8 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -4405,22 +4405,24 @@ BView::MessageReceived(BMessage* message) break; } - float deltaX = 0.0f, deltaY = 0.0f; + float deltaX = 0.0f; + float deltaY = 0.0f; + if (horizontal != NULL) message->FindFloat("be:wheel_delta_x", &deltaX); + if (vertical != NULL) message->FindFloat("be:wheel_delta_y", &deltaY); if (deltaX == 0.0f && deltaY == 0.0f) break; - if (horizontal != NULL) { + if (horizontal != NULL) ScrollWithMouseWheelDelta(horizontal, deltaX); - } - if (vertical != NULL) { + if (vertical != NULL) ScrollWithMouseWheelDelta(vertical, deltaY); - } + break; } @@ -5721,7 +5723,8 @@ BView::ScrollWithMouseWheelDelta(BScrollBar* scrollBar, float delta) if (scrollBar == NULL || delta == 0.0f) return; - float smallStep, largeStep; + float smallStep; + float largeStep; scrollBar->GetSteps(&smallStep, &largeStep); // pressing the shift key scrolls faster (following the pseudo-standard set ############################################################################ Commit: bdcfc076173236ddecccfebd945530a309debdce URL: http://cgit.haiku-os.org/haiku/commit/?id=bdcfc07 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 22:02:58 2014 UTC BScrollView: Increase small scroll step size from 1 to 3 ... and then don't multiply by 3 in BView ---------------------------------------------------------------------------- diff --git a/src/kits/interface/ScrollBar.cpp b/src/kits/interface/ScrollBar.cpp index 34d9a12..56b7e68 100644 --- a/src/kits/interface/ScrollBar.cpp +++ b/src/kits/interface/ScrollBar.cpp @@ -202,7 +202,7 @@ BScrollBar::BScrollBar(BRect frame, const char* name, BView* target, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), fMin(min), fMax(max), - fSmallStep(1.0f), + fSmallStep(3.0f), fLargeStep(10.0f), fValue(0), fProportion(0.0f), @@ -232,7 +232,7 @@ BScrollBar::BScrollBar(const char* name, BView* target, BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), fMin(min), fMax(max), - fSmallStep(1.0f), + fSmallStep(3.0f), fLargeStep(10.0f), fValue(0), fProportion(0.0f), @@ -269,7 +269,7 @@ BScrollBar::BScrollBar(BMessage* data) fMax = 0.0f; if (data->FindFloat("_steps", 0, &fSmallStep) < B_OK) - fSmallStep = 1.0f; + fSmallStep = 3.0f; if (data->FindFloat("_steps", 1, &fLargeStep) < B_OK) fLargeStep = 10.0f; diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 99904d8..69d7673 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -5729,11 +5729,7 @@ BView::ScrollWithMouseWheelDelta(BScrollBar* scrollBar, float delta) // pressing the shift key scrolls faster (following the pseudo-standard set // by other desktop environments). - if ((modifiers() & B_SHIFT_KEY) != 0) - delta *= largeStep; - else - delta *= smallStep * 3; - + delta *= (modifiers() & B_SHIFT_KEY) != 0 ? largeStep : smallStep; scrollBar->SetValue(scrollBar->Value() + delta); } ############################################################################ Commit: b9f48ef8f600d03c1bb08fbb936791b0d37b47e8 URL: http://cgit.haiku-os.org/haiku/commit/?id=b9f48ef Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 22:08:40 2014 UTC WebPositive: style fixes related to scrolling rename dy to deltaY ---------------------------------------------------------------------------- diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 9bb97be..71bd484 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -736,12 +736,13 @@ BrowserWindow::DispatchMessage(BMessage* message, BHandler* target) // know the setting of the fZoomTextOnly member here. Plus other // clients of the API may not want this feature. if ((modifiers() & B_COMMAND_KEY) != 0) { - float dy; - if (message->FindFloat("be:wheel_delta_y", &dy) == B_OK) { - if (dy < 0) + float deltaY; + if (message->FindFloat("be:wheel_delta_y", &deltaY) == B_OK) { + if (deltaY < 0) CurrentWebView()->IncreaseZoomFactor(fZoomTextOnly); else CurrentWebView()->DecreaseZoomFactor(fZoomTextOnly); + return; } } ############################################################################ Commit: 5b6c94c591ac80d0580d9c803b005aae2f3aa66a URL: http://cgit.haiku-os.org/haiku/commit/?id=5b6c94c Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 22:10:40 2014 UTC ShowImage: Style fixes related to scrolling ---------------------------------------------------------------------------- diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 3a39f88..afcc3fa6 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -1340,36 +1340,41 @@ ShowImageView::KeyDown(const char* bytes, int32 numBytes) void -ShowImageView::_MouseWheelChanged(BMessage* msg) +ShowImageView::_MouseWheelChanged(BMessage* message) { // The BeOS driver does not currently support - // X wheel scrolling, therefore, dx is zero. - // |dy| is the number of notches scrolled up or down. - // When the wheel is scrolled down (towards the user) dy > 0 - // When the wheel is scrolled up (away from the user) dy < 0 + // X wheel scrolling, therefore, deltaX is zero. + // |deltaY| is the number of notches scrolled up or down. + // When the wheel is scrolled down (towards the user) deltaY > 0 + // When the wheel is scrolled up (away from the user) deltaY < 0 const float kscrollBy = 40; - float dy, dx; - float x, y; - x = 0; y = 0; - if (msg->FindFloat("be:wheel_delta_x", &dx) == B_OK) - x = dx * kscrollBy; - if (msg->FindFloat("be:wheel_delta_y", &dy) == B_OK) - y = dy * kscrollBy; - - if ((modifiers() & B_SHIFT_KEY) != 0) + float deltaY; + float deltaX; + float x = 0; + float y = 0; + + if (message->FindFloat("be:wheel_delta_x", &deltaX) == B_OK) + x = deltaX * kscrollBy; + + if (message->FindFloat("be:wheel_delta_y", &deltaY) == B_OK) + y = deltaY * kscrollBy; + + if ((modifiers() & B_SHIFT_KEY) != 0) { + // scroll up and down _ScrollRestrictedBy(x, y); - else if ((modifiers() & B_COMMAND_KEY) != 0) + } else if ((modifiers() & B_COMMAND_KEY) != 0) { + // scroll left and right _ScrollRestrictedBy(y, x); - else { - // Zoom in spot + } else { + // zoom at location BPoint where; uint32 buttons; GetMouse(&where, &buttons); if (fStickyZoomCountDown <= 0) { - if (dy < 0) + if (deltaY < 0) ZoomIn(where); - else if (dy > 0) + else if (deltaY > 0) ZoomOut(where); if (fZoom == 1.0) @@ -1415,6 +1420,7 @@ ShowImageView::MessageReceived(BMessage* message) case B_COPY_TARGET: _HandleDrop(message); break; + case B_MOUSE_WHEEL_CHANGED: _MouseWheelChanged(message); break; @@ -1782,13 +1788,13 @@ ShowImageView::_SetIcon(bool clear, icon_size which) uchar* dest = (uchar*)icon.Bits(); const int32 srcBPR = thumbnail->BytesPerRow(); const int32 destBPR = icon.BytesPerRow(); - const int32 dx = (int32)rect.left; - const int32 dy = (int32)rect.top; + const int32 deltaX = (int32)rect.left; + const int32 deltaY = (int32)rect.top; for (int32 y = 0; y <= rect.IntegerHeight(); y++) { for (int32 x = 0; x <= rect.IntegerWidth(); x++) { const uchar* s = src + y * srcBPR + x; - uchar* d = dest + (y + dy) * destBPR + (x + dx); + uchar* d = dest + (y + deltaY) * destBPR + (x + deltaX); *d = *s; } } ############################################################################ Commit: b2404e2a39b6cea96a5e36ce4dfc0bca7361271b URL: http://cgit.haiku-os.org/haiku/commit/?id=b2404e2 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 23:13:49 2014 UTC BView: Check scroll delta isn't 0 ---------------------------------------------------------------------------- diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 69d7673..4dd0641 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -4417,10 +4417,10 @@ BView::MessageReceived(BMessage* message) if (deltaX == 0.0f && deltaY == 0.0f) break; - if (horizontal != NULL) + if (horizontal != NULL && deltaX != 0.0f) ScrollWithMouseWheelDelta(horizontal, deltaX); - if (vertical != NULL) + if (vertical != NULL && deltaY != 0.0f) ScrollWithMouseWheelDelta(vertical, deltaY); break; ############################################################################ Commit: ab5c74422e898b5023f2653ba2fb630bb9952602 URL: http://cgit.haiku-os.org/haiku/commit/?id=ab5c744 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 23:15:02 2014 UTC BView: ScrollWithMouseWheelDelta return status code ---------------------------------------------------------------------------- diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index b2e183c..bda8acd 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -607,7 +607,7 @@ protected: virtual void LayoutChanged(); - void ScrollWithMouseWheelDelta(BScrollBar*, float); + status_t ScrollWithMouseWheelDelta(BScrollBar*, float); private: void _Layout(bool force, BLayoutContext* context); diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 4dd0641..9cfe1bd 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -5717,11 +5717,11 @@ BView::_SwitchServerCurrentView() const } -void +status_t BView::ScrollWithMouseWheelDelta(BScrollBar* scrollBar, float delta) { if (scrollBar == NULL || delta == 0.0f) - return; + return B_BAD_VALUE; float smallStep; float largeStep; @@ -5731,6 +5731,8 @@ BView::ScrollWithMouseWheelDelta(BScrollBar* scrollBar, float delta) // by other desktop environments). delta *= (modifiers() & B_SHIFT_KEY) != 0 ? largeStep : smallStep; scrollBar->SetValue(scrollBar->Value() + delta); + + return B_OK; } ############################################################################ Commit: a6213356bc44d42b9d5fd54c078b2445e858ba0f URL: http://cgit.haiku-os.org/haiku/commit/?id=a621335 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 23:18:13 2014 UTC BView: scroll horizontally when holding control ... instead of vertically. This actually swaps horizontal and vertical so if you have a mouse with a fancy 2-axis scroll ball it will swap the x and y coordinates. (untested) ---------------------------------------------------------------------------- diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 9cfe1bd..4526174 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -12,6 +12,7 @@ #include <View.h> +#include <algorithm> #include <new> #include <math.h> @@ -4417,6 +4418,9 @@ BView::MessageReceived(BMessage* message) if (deltaX == 0.0f && deltaY == 0.0f) break; + if ((modifiers() & B_CONTROL_KEY) != 0) + std::swap(horizontal, vertical); + if (horizontal != NULL && deltaX != 0.0f) ScrollWithMouseWheelDelta(horizontal, deltaX); ############################################################################ Revision: hrev46986 Commit: 0a2382e3736b944cd18277ec2ed3c49263b8a43d URL: http://cgit.haiku-os.org/haiku/commit/?id=0a2382e Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Mar 7 23:22:24 2014 UTC ShowImage: Scroll horizontally with control ...instead of command. See //www.freelists.org/post/haiku-commits/haiku-hrev46304-srckitsinterface,18 ---------------------------------------------------------------------------- diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index afcc3fa6..1a0faa4 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -1362,7 +1362,7 @@ ShowImageView::_MouseWheelChanged(BMessage* message) if ((modifiers() & B_SHIFT_KEY) != 0) { // scroll up and down _ScrollRestrictedBy(x, y); - } else if ((modifiers() & B_COMMAND_KEY) != 0) { + } else if ((modifiers() & B_CONTROL_KEY) != 0) { // scroll left and right _ScrollRestrictedBy(y, x); } else {