From d2ef10fe9f77b84af00840cfa4880203b0d9030e Mon Sep 17 00:00:00 2001 From: Phil Greenway Date: Mon, 25 Aug 2003 20:55:19 +0000 Subject: [PATCH] Initial Checkin of app by MrSiggler git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4373 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/scrollbar/fakescrollbar.cpp | 473 +++++++++++++++++++++++ src/prefs/scrollbar/fakescrollbar.h | 36 ++ src/prefs/scrollbar/knobsizeadjuster.cpp | 134 +++++++ src/prefs/scrollbar/knobsizeadjuster.h | 26 ++ src/prefs/scrollbar/messages.h | 22 ++ src/prefs/scrollbar/scrollbar.cpp | 59 +++ src/prefs/scrollbar/scrollbar.h | 29 ++ src/prefs/scrollbar/scrollbar.rsrc | Bin 0 -> 4211 bytes src/prefs/scrollbar/scrollbar_window.cpp | 415 ++++++++++++++++++++ src/prefs/scrollbar/scrollbar_window.h | 33 ++ 10 files changed, 1227 insertions(+) create mode 100644 src/prefs/scrollbar/fakescrollbar.cpp create mode 100644 src/prefs/scrollbar/fakescrollbar.h create mode 100644 src/prefs/scrollbar/knobsizeadjuster.cpp create mode 100644 src/prefs/scrollbar/knobsizeadjuster.h create mode 100644 src/prefs/scrollbar/messages.h create mode 100644 src/prefs/scrollbar/scrollbar.cpp create mode 100644 src/prefs/scrollbar/scrollbar.h create mode 100644 src/prefs/scrollbar/scrollbar.rsrc create mode 100644 src/prefs/scrollbar/scrollbar_window.cpp create mode 100644 src/prefs/scrollbar/scrollbar_window.h diff --git a/src/prefs/scrollbar/fakescrollbar.cpp b/src/prefs/scrollbar/fakescrollbar.cpp new file mode 100644 index 0000000000..a826e98e96 --- /dev/null +++ b/src/prefs/scrollbar/fakescrollbar.cpp @@ -0,0 +1,473 @@ + +#include "scrollbar.h" +#include "fakescrollbar.h" +#include "messages.h" + +FakeScrollBar::FakeScrollBar( BPoint position, bool selected, + uint32 style, uint32 type, uint32 arrow, uint32 size, BMessage *message ): + BView( BRect( position.x, position.y, position.x+132, + position.y+20 ), "FakeScrollBar", B_FOLLOW_LEFT | + B_FOLLOW_TOP, B_WILL_DRAW ) +{ + Selected=selected; + Pressed=false; + ArrowStyle=arrow; + KnobType=type; + KnobStyle=style; + KnobSize=size; + + Message=message; +} + +void FakeScrollBar::DrawArrowBox( uint32 x, bool facingleft ) +{ + // draw box + SetHighColor( 216, 216, 216 ); + FillRect( BRect( x, Bounds().top+3, + x+16, Bounds().bottom-3 ), B_SOLID_HIGH ); + + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( x, Bounds().top+3, x+16, + Bounds().bottom-3 ) , B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x+1, Bounds().top+4 ), + BPoint( x+15, Bounds().top+4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+1, Bounds().top+4 ), + BPoint( x+1, Bounds().bottom-4 ), B_SOLID_HIGH ); + + SetHighColor( 192, 192, 192 ); + StrokeLine( BPoint( x+15, Bounds().bottom-4 ), + BPoint( x+15, Bounds().top+4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+15, Bounds().bottom-4 ), + BPoint( x+1, Bounds().bottom-4 ), B_SOLID_HIGH ); + + if ( facingleft == true ) + { + // draw arrow + SetHighColor( 112, 112, 112 ); + StrokeLine( BPoint( x+4, Bounds().top+10 ), + BPoint( x+11, Bounds().top+7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+4, Bounds().top+10 ), + BPoint( x+11, Bounds().bottom-7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+11, Bounds().top+7 ), + BPoint( x+11, Bounds().bottom-7 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x+4, Bounds().top+11 ), + BPoint( x+11, Bounds().bottom-6 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+12, Bounds().top+7 ), + BPoint( x+12, Bounds().bottom-6 ), B_SOLID_HIGH ); + + SetHighColor( 192, 192, 192 ); + StrokeLine( BPoint( x+4, Bounds().top+9 ), + BPoint( x+11, Bounds().top+6 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+3, Bounds().top+10 ), + BPoint( x+3, Bounds().top+10 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+12, Bounds().top+6 ), + BPoint( x+12, Bounds().top+6 ), B_SOLID_HIGH ); + } + else + { + // draw arrow + SetHighColor( 112, 112, 112 ); + StrokeLine( BPoint( x+12, Bounds().top+10 ), + BPoint( x+5, Bounds().top+7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+12, Bounds().top+10 ), + BPoint( x+5, Bounds().bottom-7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+5, Bounds().top+7 ), + BPoint( x+5, Bounds().bottom-7 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x+12, Bounds().top+11 ), + BPoint( x+5, Bounds().bottom-6 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+4, Bounds().top+7 ), + BPoint( x+4, Bounds().bottom-6 ), B_SOLID_HIGH ); + + SetHighColor( 192, 192, 192 ); + StrokeLine( BPoint( x+12, Bounds().top+9 ), + BPoint( x+5, Bounds().top+6 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+13, Bounds().top+10 ), + BPoint( x+13, Bounds().top+10 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+4, Bounds().top+6 ), + BPoint( x+4, Bounds().top+6 ), B_SOLID_HIGH ); + } +} + +void FakeScrollBar::Draw( BRect updateRect ) +{ + SetViewColor( 216, 216, 216 ); + // Draw border. + if ( Selected == true ) + SetHighColor( 0, 0, 0 ); + else if ( Pressed == true ) + SetHighColor( 128, 128, 128 ); + else + SetHighColor( 216, 216, 216 ); + + SetPenSize( 2 ); + StrokeRect( BRect( Bounds().left, Bounds().top, + Bounds().right-1, Bounds().bottom-1 ), B_SOLID_HIGH ); + + SetPenSize( 1 ); + SetHighColor( 216, 216, 216 ); + FillRect( BRect( Bounds().left+2, Bounds().top+2, + Bounds().right-2, Bounds().bottom-2 ), B_SOLID_HIGH ); + + // Draw first arrows + if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE ) + { + DrawArrowBox( 3, true ); + DrawArrowBox( 113, false ); + } + + // If double arrows, draw another set. + if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) + { + DrawArrowBox( 3, true ); + DrawArrowBox( 113, false ); + DrawArrowBox( 19, false ); + DrawArrowBox( 97, true ); + } + + // Draw back + if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) + { + SetHighColor( 200, 200, 200 ); + FillRect( BRect( 36, 3, 96, 15 ), B_SOLID_HIGH ); + + SetHighColor( 152, 152, 152 ); + StrokeLine( BPoint( 36, 3 ), BPoint( 96, 3 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 36, 17 ), BPoint( 96, 17 ), B_SOLID_HIGH ); + SetHighColor( 216, 216, 216 ); + StrokeLine( BPoint( 36, 16 ), BPoint( 96, 16 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + FillRect( BRect( 36, 4, 37, 15 ), B_SOLID_HIGH ); + FillRect( BRect( 36, 4, 96, 5 ), B_SOLID_HIGH ); + } + else if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE ) + { + SetHighColor( 200, 200, 200 ); + FillRect( BRect( 20, 3, 112, 15 ), B_SOLID_HIGH ); + + SetHighColor( 152, 152, 152 ); + StrokeLine( BPoint( 20, 3 ), BPoint( 112, 3 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 20, 17 ), BPoint( 112, 17 ), B_SOLID_HIGH ); + SetHighColor( 216, 216, 216 ); + StrokeLine( BPoint( 20, 16 ), BPoint( 112, 16 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + FillRect( BRect( 20, 4, 21, 15 ), B_SOLID_HIGH ); + FillRect( BRect( 20, 4, 112, 5 ), B_SOLID_HIGH ); + } + else + { + SetHighColor( 152, 152, 152 ); + StrokeLine( BPoint( 4, 3 ), BPoint( Bounds().right-5, 3 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 4, 17 ), BPoint( Bounds().right-5, 17 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + FillRect( BRect( 4, 4, Bounds().right-5, 5 ), B_SOLID_HIGH ); + SetHighColor( 200, 200, 200 ); + FillRect( BRect( 4, 6, Bounds().right-5, 15), B_SOLID_HIGH ); + StrokeLine( BPoint( 3, 15 ), BPoint( 3, 13 ), B_SOLID_HIGH ); + StrokeLine( BPoint( Bounds().right-4, 7 ), BPoint( Bounds().right-4, 11 ), B_SOLID_HIGH ); + StrokeLine( BPoint( Bounds().right-3, 9 ), BPoint( Bounds().right-3, 9 ), B_SOLID_HIGH ); + SetHighColor( 216, 216, 216 ); + StrokeLine( BPoint( 4, 7 ), BPoint( 4, 11 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 5, 9 ), BPoint( 5, 9 ), B_SOLID_HIGH ); + StrokeLine( BPoint( Bounds().right-5, 15 ), BPoint( Bounds().right-5, 13 ), B_SOLID_HIGH ); + } + + // Draw knob + if ( KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL ) + { + if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) + { + SetHighColor( 216, 216, 216 ); + FillRect( BRect( 44, 3, 88, 17 ), B_SOLID_HIGH ); + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( 44, 3, 88, 17 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( 45, 4 ), BPoint( 87, 4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 45, 4 ), BPoint( 45, 16 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( 45, 16 ), BPoint( 87, 16 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 87, 16 ), BPoint( 87, 4 ), B_SOLID_HIGH ); + + SetHighColor( 96, 96, 96 ); + StrokeLine( BPoint( 88, 4 ), BPoint( 88, 16 ), B_SOLID_HIGH ); + } + else if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE ) + { + SetHighColor( 216, 216, 216 ); + FillRect( BRect( 32, 3, 100, 17 ), B_SOLID_HIGH ); + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( 32, 3, 100, 17 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( 33, 4 ), BPoint( 99, 4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 33, 4 ), BPoint( 33, 16 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( 33, 16 ), BPoint( 99, 16 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 99, 16 ), BPoint( 99, 4 ), B_SOLID_HIGH ); + + SetHighColor( 96, 96, 96 ); + StrokeLine( BPoint( 100, 4 ), BPoint( 100, 16 ), B_SOLID_HIGH ); + } + else + { + SetHighColor( 216, 216, 216 ); + FillRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH ); + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( 14, 4 ), BPoint( 118, 4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 14, 4 ), BPoint( 14, 16 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( 14, 16 ), BPoint( 118, 16 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 118, 16 ), BPoint( 118, 4 ), B_SOLID_HIGH ); + + SetHighColor( 96, 96, 96 ); + StrokeLine( BPoint( 119, 4 ), BPoint( 119, 16 ), B_SOLID_HIGH ); + } + } + else + { + if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_NONE ) + { + SetHighColor( 216, 216, 216 ); + FillRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH ); + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( 14, 4 ), BPoint( 118, 4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 14, 4 ), BPoint( 14, 16 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( 14, 16 ), BPoint( 118, 16 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 118, 16 ), BPoint( 118, 4 ), B_SOLID_HIGH ); + + SetHighColor( 96, 96, 96 ); + StrokeLine( BPoint( 119, 4 ), BPoint( 119, 16 ), B_SOLID_HIGH ); + } + else + { + SetHighColor( 216, 216, 216 ); + FillRect( BRect( (Bounds().right/2)-(KnobSize/2), 3, + (Bounds().right/2)+(KnobSize/2), 17 ), B_SOLID_HIGH ); + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( (Bounds().right/2)-(KnobSize/2), 3, + (Bounds().right/2)+(KnobSize/2), 17 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( (Bounds().right/2)-(KnobSize/2)+1, 4 ), + BPoint( (Bounds().right/2)+(KnobSize/2)-1, 4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( (Bounds().right/2)-(KnobSize/2)+1, 4 ), + BPoint( (Bounds().right/2)-(KnobSize/2)+1, 16 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( (Bounds().right/2)-(KnobSize/2)+1, 16 ), + BPoint( (Bounds().right/2)+(KnobSize/2)-1, 16 ), B_SOLID_HIGH ); + StrokeLine( BPoint( (Bounds().right/2)+(KnobSize/2)-1, 16 ), + BPoint( (Bounds().right/2)+(KnobSize/2)-1, 4 ), B_SOLID_HIGH ); + + SetHighColor( 96, 96, 96 ); + StrokeLine( BPoint( (Bounds().right/2)+(KnobSize/2), 4 ), + BPoint( (Bounds().right/2)+(KnobSize/2), 16 ), B_SOLID_HIGH ); + } + } + + // Draw knob grabber + if ( KnobStyle == SCROLLBAR_KNOB_STYLE_DOT ) + { + if ( KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL || + ArrowStyle == SCROLLBAR_ARROW_STYLE_NONE ) + DrawDotGrabber( Bounds().right/2, 100 ); + else + DrawDotGrabber( Bounds().right/2, KnobSize ); + } + else if ( KnobStyle == SCROLLBAR_KNOB_STYLE_LINE ) + { + if ( KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL || + ArrowStyle == SCROLLBAR_ARROW_STYLE_NONE ) + DrawLineGrabber( Bounds().right/2, 100 ); + else + DrawLineGrabber( Bounds().right/2, KnobSize ); + } +} + +void FakeScrollBar::DrawLineGrabber( uint32 x, uint32 size ) +{ + if ( size < 12 ) + { + // Draw nothing! + } + else if ( size < 22 ) + { + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x-1, 7 ), BPoint( x+1, 7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-1, 7 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x+1, 7 ), BPoint( x+1, 13 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+1, 13 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); + } + else + { + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x-1, 7 ), BPoint( x+1, 7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-1, 7 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x+1, 7 ), BPoint( x+1, 13 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+1, 13 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x-5, 7 ), BPoint( x-3, 7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-5, 7 ), BPoint( x-5, 13 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x-3, 7 ), BPoint( x-3, 13 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-3, 13 ), BPoint( x-5, 13 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x+3, 7 ), BPoint( x+5, 7 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+3, 7 ), BPoint( x+3, 13 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x+5, 7 ), BPoint( x+5, 13 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+5, 13 ), BPoint( x+3, 13 ), B_SOLID_HIGH ); + } +} + +void FakeScrollBar::DrawDotGrabber( uint32 x, uint32 size ) +{ + if ( size < 14 ) + { + // Draw Nothing! + } + else if ( size < 27 ) + { + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x-2, 8 ), BPoint( x+2, 8 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-2, 8 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x+2, 8 ), BPoint( x+2, 12 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+2, 12 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); + } + else + { + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x-2, 8 ), BPoint( x+2, 8 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-2, 8 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x+2, 8 ), BPoint( x+2, 12 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+2, 12 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x-9, 8 ), BPoint( x-5, 8 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-9, 8 ), BPoint( x-9, 12 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x-5, 8 ), BPoint( x-5, 12 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x-5, 12 ), BPoint( x-9, 12 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( x+5, 8 ), BPoint( x+9, 8 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+5, 8 ), BPoint( x+5, 12 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( x+9, 8 ), BPoint( x+9, 12 ), B_SOLID_HIGH ); + StrokeLine( BPoint( x+9, 12 ), BPoint( x+5, 12 ), B_SOLID_HIGH ); + } +} + +void FakeScrollBar::MouseDown( BPoint point ) +{ + SetTracking( true ); +} + +void FakeScrollBar::MouseUp( BPoint point ) +{ + if ( IsPressed() == true ) + be_app->PostMessage( Message ); + SetTracking( false ); +} + +void FakeScrollBar::MouseMoved( BPoint point, uint32 transit, const BMessage *message ) +{ + if ( transit == B_ENTERED_VIEW && IsTracking() == true ) + SetPressed( true ); + if ( transit == B_EXITED_VIEW && IsTracking() == true ) + SetPressed( false ); +} + +void FakeScrollBar::SetKnobStyle( uint32 style ) +{ + KnobStyle=style; + Invalidate(); +} + +void FakeScrollBar::SetKnobType( uint32 type ) +{ + KnobType=type; + Invalidate(); +} + +void FakeScrollBar::SetArrowStyle( uint32 arrow ) +{ + ArrowStyle=arrow; + Invalidate(); +} + +void FakeScrollBar::SetKnobSize( uint32 size ) +{ + KnobSize=size; + Invalidate(); +} + +void FakeScrollBar::SetSelected( bool selected ) +{ + Selected=selected; + Invalidate(); +} + +void FakeScrollBar::SetPressed( bool pressed ) +{ + Pressed=pressed; + Invalidate(); +} + +void FakeScrollBar::SetTracking( bool tracking ) +{ + Tracking=tracking; + + if ( IsTracking() == true ) + { + SetEventMask( B_POINTER_EVENTS ); + SetPressed( true ); + } + else + { + SetEventMask( 0 ); + SetPressed( false ); + } +} + +bool FakeScrollBar::IsSelected() +{ + return Selected; +} + +bool FakeScrollBar::IsPressed() +{ + return Pressed; +} + +bool FakeScrollBar::IsTracking() +{ + return Tracking; +} + diff --git a/src/prefs/scrollbar/fakescrollbar.h b/src/prefs/scrollbar/fakescrollbar.h new file mode 100644 index 0000000000..04d7dbc63a --- /dev/null +++ b/src/prefs/scrollbar/fakescrollbar.h @@ -0,0 +1,36 @@ +#ifndef SCROLLBAR_FAKE_H +#define SCROLLBAR_FAKE_H + +#include + + +class FakeScrollBar : public BView +{ + public: + FakeScrollBar( BPoint position, bool selected, uint32 style, + uint32 type, uint32 arrow, uint32 size, BMessage *message ); + + void SetKnobStyle( uint32 style ); + void SetKnobType( uint32 type ); + void SetArrowStyle( uint32 arrow ); + void SetKnobSize( uint32 size ); + void SetSelected( bool selected ); + void SetPressed( bool pressed ); + void SetTracking( bool tracking ); + bool IsPressed(); + bool IsSelected(); + bool IsTracking(); + private: + void Draw( BRect updateRect ); + void MouseDown( BPoint point ); + void MouseUp( BPoint point ); + void MouseMoved( BPoint point, uint32 transit, const BMessage *message ); + void DrawArrowBox( uint32 x, bool facingleft ); + void DrawDotGrabber( uint32 x, uint32 size ); + void DrawLineGrabber( uint32 x, uint32 size ); + BMessage *Message; + bool Selected, Pressed, Tracking; + uint32 ArrowStyle,KnobType,KnobStyle,KnobSize; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/scrollbar/knobsizeadjuster.cpp b/src/prefs/scrollbar/knobsizeadjuster.cpp new file mode 100644 index 0000000000..e6ae93ebd7 --- /dev/null +++ b/src/prefs/scrollbar/knobsizeadjuster.cpp @@ -0,0 +1,134 @@ +#include + +#include "scrollbar.h" +#include "knobsizeadjuster.h" +#include "messages.h" + +KnobSizeAdjuster::KnobSizeAdjuster( BPoint position, uint32 size ): + BView( BRect( position.x, position.y, position.x+133, + position.y+26 ), "KnobSizeAdjuster", B_FOLLOW_LEFT | + B_FOLLOW_TOP, B_WILL_DRAW ) +{ + KnobSize=size; +} + +void KnobSizeAdjuster::Draw( BRect updateRect ) +{ + SetViewColor( 216, 216, 216 ); + // Draw border. + SetHighColor( 216, 216, 216 ); + FillRect( Bounds(), B_SOLID_HIGH ); + + // Draw back + SetHighColor( 152, 152, 152 ); + StrokeLine( BPoint( 4, 3 ), BPoint( Bounds().right-5, 3 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 4, 17 ), BPoint( Bounds().right-5, 17 ), B_SOLID_HIGH ); + SetHighColor( 184, 184, 184 ); + FillRect( BRect( 4, 4, Bounds().right-5, 5 ), B_SOLID_HIGH ); + SetHighColor( 200, 200, 200 ); + FillRect( BRect( 4, 6, Bounds().right-5, 15), B_SOLID_HIGH ); + StrokeLine( BPoint( 3, 15 ), BPoint( 3, 13 ), B_SOLID_HIGH ); + StrokeLine( BPoint( Bounds().right-4, 7 ), BPoint( Bounds().right-4, 11 ), B_SOLID_HIGH ); + StrokeLine( BPoint( Bounds().right-3, 9 ), BPoint( Bounds().right-3, 9 ), B_SOLID_HIGH ); + SetHighColor( 216, 216, 216 ); + StrokeLine( BPoint( 4, 7 ), BPoint( 4, 11 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 5, 9 ), BPoint( 5, 9 ), B_SOLID_HIGH ); + StrokeLine( BPoint( Bounds().right-5, 15 ), BPoint( Bounds().right-5, 13 ), B_SOLID_HIGH ); + + // Draw knob + SetHighColor( 216, 216, 216 ); + FillRect( BRect( 41, 3, 41+KnobSize, 17 ), B_SOLID_HIGH ); + SetHighColor( 152, 152, 152 ); + StrokeRect( BRect( 41, 3, 41+KnobSize, 17 ), B_SOLID_HIGH ); + + SetHighColor( 255, 255, 255 ); + StrokeLine( BPoint( 42, 4 ), BPoint( 41+KnobSize-1, 4 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 42, 4 ), BPoint( 42, 16 ), B_SOLID_HIGH ); + + SetHighColor( 184, 184, 184 ); + StrokeLine( BPoint( 42, 16 ), BPoint( 41+KnobSize-1, 16 ), B_SOLID_HIGH ); + StrokeLine( BPoint( 41+KnobSize-1, 16 ), BPoint( 41+KnobSize-1, 4 ), B_SOLID_HIGH ); + + SetHighColor( 96, 96, 96 ); + StrokeLine( BPoint( 41+KnobSize, 4 ), BPoint( 41+KnobSize, 16 ), B_SOLID_HIGH ); + + // Draw slider + SetHighColor( 0, 255, 0 ); + FillTriangle( BPoint( 41+KnobSize, 18), BPoint( 41+KnobSize+5, 23 ), BPoint( 41+KnobSize-5, 23), B_SOLID_HIGH ); + SetHighColor( 0, 0, 0 ); + StrokeTriangle( BPoint( 41+KnobSize, 18), BPoint( 41+KnobSize+5, 23 ), + BPoint( 41+KnobSize-5, 23), B_SOLID_HIGH ); +} + +void KnobSizeAdjuster::MouseDown( BPoint point ) +{ + int32 newsize=0; + + if ( point.x > 41+MINIMUM_KNOB_SIZE && point.x < MAXIMUM_KNOB_SIZE+41 ) + newsize = (int)point.x-41; + if ( point.x <= 41+MINIMUM_KNOB_SIZE ) + newsize = MINIMUM_KNOB_SIZE; + if ( point.x >= 41+MAXIMUM_KNOB_SIZE ) + newsize = MAXIMUM_KNOB_SIZE; + SetKnobSize( newsize ); + + SetTracking( true ); +} + +void KnobSizeAdjuster::MouseUp( BPoint point ) +{ + SetTracking( false ); + be_app->PostMessage( SCROLLBAR_KNOB_SIZE_CHANGED ); +} + +void KnobSizeAdjuster::MouseMoved( BPoint point, uint32 transit, + const BMessage *message ) +{ + int32 newsize=0; + + if ( transit == B_INSIDE_VIEW && IsTracking() == true ) + { + if ( point.x > 41+MINIMUM_KNOB_SIZE && point.x < MAXIMUM_KNOB_SIZE+41 ) + newsize = (int)point.x-41; + if ( point.x <= 41+MINIMUM_KNOB_SIZE ) + newsize = MINIMUM_KNOB_SIZE; + if ( point.x >= 41+MAXIMUM_KNOB_SIZE ) + newsize = MAXIMUM_KNOB_SIZE; + SetKnobSize( newsize ); + } +} + +void KnobSizeAdjuster::SetKnobSize( uint32 size ) +{ + KnobSize=size; + Settings.KnobSize=KnobSize; + + Invalidate(); +} + +void KnobSizeAdjuster::SetPressed( bool pressed ) +{ + Pressed=pressed; +} + +void KnobSizeAdjuster::SetTracking( bool tracking ) +{ + Tracking=tracking; + + if ( IsTracking() == true ) + SetEventMask( B_POINTER_EVENTS ); + else + SetEventMask( 0 ); +} + +bool KnobSizeAdjuster::IsPressed() +{ + return Pressed; +} + +bool KnobSizeAdjuster::IsTracking() +{ + return Tracking; +} + + diff --git a/src/prefs/scrollbar/knobsizeadjuster.h b/src/prefs/scrollbar/knobsizeadjuster.h new file mode 100644 index 0000000000..0123061395 --- /dev/null +++ b/src/prefs/scrollbar/knobsizeadjuster.h @@ -0,0 +1,26 @@ +#ifndef SCROLLBAR_KNOB_ADJUSTER_H +#define SCROLLBAR_KNOB_ADJUSTER_H + +#include + + +class KnobSizeAdjuster : public BView +{ + public: + KnobSizeAdjuster( BPoint position, uint32 size ); + + void SetKnobSize( uint32 size ); + void SetPressed( bool pressed ); + void SetTracking( bool tracking ); + bool IsPressed(); + bool IsTracking(); + private: + void Draw( BRect updateRect ); + void MouseDown( BPoint point ); + void MouseUp( BPoint point ); + void MouseMoved( BPoint point, uint32 transit, const BMessage *message ); + uint32 KnobSize; + bool Pressed, Tracking; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/scrollbar/messages.h b/src/prefs/scrollbar/messages.h new file mode 100644 index 0000000000..f583b0175e --- /dev/null +++ b/src/prefs/scrollbar/messages.h @@ -0,0 +1,22 @@ +#ifndef SCROLLBAR_MESSAGES_H +#define SCROLLBAR_MESSAGES_H + +const uint32 SCROLLBAR_DEFAULTS = 'dflt'; +const uint32 SCROLLBAR_REVERT = 'rvrt'; + +const uint32 SCROLLBAR_ARROW_STYLE_NONE = 'anon'; +const uint32 SCROLLBAR_ARROW_STYLE_DOUBLE = 'adbl'; +const uint32 SCROLLBAR_ARROW_STYLE_SINGLE = 'asng'; + +const uint32 SCROLLBAR_KNOB_TYPE_PROPORTIONAL = 'ktpr'; +const uint32 SCROLLBAR_KNOB_TYPE_FIXED = 'ktfx'; + +const uint32 SCROLLBAR_KNOB_STYLE_FLAT = 'ksfl'; +const uint32 SCROLLBAR_KNOB_STYLE_DOT = 'ksdt'; +const uint32 SCROLLBAR_KNOB_STYLE_LINE = 'ksln'; + +const uint32 SCROLLBAR_KNOB_SIZE_CHANGED = 'ksch'; + +const uint32 TEST_MSG = 'tstm'; + +#endif \ No newline at end of file diff --git a/src/prefs/scrollbar/scrollbar.cpp b/src/prefs/scrollbar/scrollbar.cpp new file mode 100644 index 0000000000..930ab89ff0 --- /dev/null +++ b/src/prefs/scrollbar/scrollbar.cpp @@ -0,0 +1,59 @@ +#include +#include "scrollbar.h" +#include "scrollbar_window.h" +#include "messages.h" + +ScrollBarWindow *window; +ScrollBarApp MyApplication; +scrollbar_settings Settings; +scrollbar_settings RevertSettings; + +ScrollBarApp::ScrollBarApp():BApplication( "application/x-vnd.OBOS-SCRL" ) +{ + // Create Window + window = new ScrollBarWindow(); + window->Show(); +} + +void ScrollBarApp::MessageReceived( BMessage *message ) +{ + switch ( message->what ) + { + case SCROLLBAR_ARROW_STYLE_DOUBLE: + window->PostMessage( message ); + break; + case SCROLLBAR_ARROW_STYLE_SINGLE: + window->PostMessage( message ); + break; + case SCROLLBAR_KNOB_TYPE_PROPORTIONAL: + window->PostMessage( message ); + break; + case SCROLLBAR_KNOB_TYPE_FIXED: + window->PostMessage( message ); + break; + case SCROLLBAR_KNOB_STYLE_FLAT: + window->PostMessage( message ); + break; + case SCROLLBAR_KNOB_STYLE_DOT: + window->PostMessage( message ); + break; + case SCROLLBAR_KNOB_STYLE_LINE: + window->PostMessage( message ); + break; + case SCROLLBAR_KNOB_SIZE_CHANGED: + window->PostMessage( message ); + break; + case TEST_MSG: + window->PostMessage( message ); + break; + default: + BApplication::MessageReceived( message ); + } +} + +int main() +{ + MyApplication.Run(); + + return 0; +} \ No newline at end of file diff --git a/src/prefs/scrollbar/scrollbar.h b/src/prefs/scrollbar/scrollbar.h new file mode 100644 index 0000000000..51f99ab5f5 --- /dev/null +++ b/src/prefs/scrollbar/scrollbar.h @@ -0,0 +1,29 @@ +#ifndef SCROLLBAR_H +#define SCROLLBAR_H + +#include + +#define MAXIMUM_KNOB_SIZE 50 +#define MINIMUM_KNOB_SIZE 9 + +typedef struct +{ + uint32 ArrowStyle; + uint32 KnobType; + uint32 KnobStyle; + uint32 KnobSize; + +} scrollbar_settings; + +class ScrollBarApp : public BApplication +{ + public: + ScrollBarApp(); + private: + void MessageReceived( BMessage *message ); +}; + +extern scrollbar_settings Settings; +extern scrollbar_settings RevertSettings; + +#endif \ No newline at end of file diff --git a/src/prefs/scrollbar/scrollbar.rsrc b/src/prefs/scrollbar/scrollbar.rsrc new file mode 100644 index 0000000000000000000000000000000000000000..031eb5f2768ab0ecb0d1ff43396b7b1ee41c550d GIT binary patch literal 4211 zcmeHL%Wl&^6umAliH9e2!C3NaSf?eb#Ht%BZ&^y>D2^(1l@>@v1u7K+1hT|}1^>a0 z1>cYb{6%&wQ9mM_JL5-;V+4rqJeK7d-*e7=jpaC#kcetQ=Q=JOK6&yFgSiCmk1Iyw zsb%JTdxgRGFJt~uzz>93|H}=cZR3U(nA26WSlq%D@$gvOCQ@cfOUyrSnZ*a_#BhD% zGGk^3mAX4?P5tQ1RU z0nSZN}J|xZ*Pt5mZvL@_9@Kw5QFgfKDHd495H?*+ub*3PaXuVAlwbxlL04CjsIMM z>EWn(^V$5}?9uC!lljX`-Es>@&8m*90!P++>qsBwx@XMG{6Tj%Jsfw#gf +#include +#include +#include +#include + +#include "scrollbar.h" +#include "fakescrollbar.h" +#include "scrollbar_window.h" +#include "messages.h" + +ScrollBarWindow::ScrollBarWindow():BWindow( BRect(0,0,0,0), + "ScrollBarWindow", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | + B_ASYNCHRONOUS_CONTROLS ) +{ + MoveTo( 100, 100 ); + ResizeTo( 348, 275 ); + SetTitle( "OBOS Scroll Bar" ); + + // Set defaults + Settings.ArrowStyle = SCROLLBAR_ARROW_STYLE_DOUBLE; + Settings.KnobStyle = SCROLLBAR_KNOB_STYLE_DOT; + Settings.KnobType = SCROLLBAR_KNOB_TYPE_PROPORTIONAL; + Settings.KnobSize = 16; + + // Load settings + BPath path; + find_directory( B_USER_SETTINGS_DIRECTORY, &path ); + path.Append( "OBOS_ScrollBar_Settings", true ); + BFile file( path.Path(), B_READ_ONLY ); + BMessage msg; + msg.Unflatten( &file ); + LoadSettings( &msg ); + RevertSettings=Settings; + + MainBox = new BBox( BRect(0,0,348,275), "MainBox", B_FOLLOW_LEFT | + B_FOLLOW_TOP, B_WILL_DRAW, B_PLAIN_BORDER ); + AddChild( MainBox ); + + // Arrow style + BBox* ArrowStyleBox = new BBox( BRect( 12, 7, 169, 119) ); + ArrowStyleBox->SetLabel( "Arrow Style" ); + MainBox->AddChild( ArrowStyleBox ); + + BStringView* DoubleArrowLabel = new BStringView( BRect(13,13,48,31), + "DoubleArrowLabel", "Double:" ); + ArrowStyleBox->AddChild( DoubleArrowLabel ); + + DoubleArrowView = new FakeScrollBar( BPoint( 12, 31 ), false, + Settings.KnobStyle, Settings.KnobType, SCROLLBAR_ARROW_STYLE_DOUBLE, + Settings.KnobSize, (new BMessage(SCROLLBAR_ARROW_STYLE_DOUBLE)) ); + ArrowStyleBox->AddChild( DoubleArrowView ); + + BStringView* SingleArrowLabel = new BStringView( BRect(13,65,48,80), + "SingleArrowLabel", "Single:" ); + ArrowStyleBox->AddChild( SingleArrowLabel ); + + SingleArrowView = new FakeScrollBar( BPoint( 12, 80 ), false, + Settings.KnobStyle, Settings.KnobType, SCROLLBAR_ARROW_STYLE_SINGLE, + Settings.KnobSize, (new BMessage(SCROLLBAR_ARROW_STYLE_SINGLE)) ); + ArrowStyleBox->AddChild( SingleArrowView ); + + // Knob Type + BBox* KnobTypeBox = new BBox( BRect( 180, 7, 338, 119) ); + KnobTypeBox->SetLabel( "Knob Type" ); + MainBox->AddChild( KnobTypeBox ); + + BStringView* ProportionalKnobLabel = new BStringView( BRect(13,13,80,31), + "ProportionalKnobLabel", "Proportional:" ); + KnobTypeBox->AddChild( ProportionalKnobLabel ); + + ProportionalKnobView = new FakeScrollBar( BPoint( 12, 31 ), false, + Settings.KnobStyle, SCROLLBAR_KNOB_TYPE_PROPORTIONAL, Settings.ArrowStyle, + Settings.KnobSize, (new BMessage(SCROLLBAR_KNOB_TYPE_PROPORTIONAL)) ); + KnobTypeBox->AddChild( ProportionalKnobView ); + + BStringView* FixedKnobLabel = new BStringView( BRect(13,65,48,80), + "fixedStringView", "Fixed:" ); + KnobTypeBox->AddChild( FixedKnobLabel ); + + FixedKnobView = new FakeScrollBar( BPoint( 12, 80 ), false, + Settings.KnobStyle, SCROLLBAR_KNOB_TYPE_FIXED, Settings.ArrowStyle, + Settings.KnobSize, (new BMessage(SCROLLBAR_KNOB_TYPE_FIXED)) ); + KnobTypeBox->AddChild( FixedKnobView ); + + // Minimum knob size + BBox* MinKnobSizeBox = new BBox( BRect( 12, 123, 169, 232) ); + MinKnobSizeBox->SetLabel( "Minimum Knob Size" ); + MainBox->AddChild( MinKnobSizeBox ); + MinimumKnobSize = new KnobSizeAdjuster( BPoint( 12, 50 ), Settings.KnobSize ); + MinKnobSizeBox->AddChild( MinimumKnobSize ); + + // Knob Style + BBox* KnobStyleBox = new BBox( BRect( 180, 123, 338, 232) ); + KnobStyleBox->SetLabel( "Knob Style" ); + MainBox->AddChild( KnobStyleBox ); + + FlatKnobView = new FakeScrollBar( BPoint( 12, 19 ), false, + SCROLLBAR_KNOB_STYLE_FLAT, Settings.KnobType, + SCROLLBAR_ARROW_STYLE_NONE, Settings.KnobSize, (new BMessage(SCROLLBAR_KNOB_STYLE_FLAT)) ); + KnobStyleBox->AddChild( FlatKnobView ); + + DotKnobView = new FakeScrollBar( BPoint( 12, 49 ), false, + SCROLLBAR_KNOB_STYLE_DOT, Settings.KnobType, + SCROLLBAR_ARROW_STYLE_NONE, Settings.KnobSize, (new BMessage(SCROLLBAR_KNOB_STYLE_DOT)) ); + KnobStyleBox->AddChild( DotKnobView ); + + LineKnobView = new FakeScrollBar( BPoint( 12, 79 ), false, + SCROLLBAR_KNOB_STYLE_LINE, Settings.KnobType, + SCROLLBAR_ARROW_STYLE_NONE, Settings.KnobSize, (new BMessage(SCROLLBAR_KNOB_STYLE_LINE)) ); + KnobStyleBox->AddChild( LineKnobView ); + + // Set the proper things selected.. + if ( Settings.ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) + DoubleArrowView->SetSelected( true ); + else if ( Settings.ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE ) + SingleArrowView->SetSelected( true ); + + if ( Settings.KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL ) + ProportionalKnobView->SetSelected( true ); + else if ( Settings.KnobType == SCROLLBAR_KNOB_TYPE_FIXED ) + FixedKnobView->SetSelected( true ); + + if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_FLAT ) + FlatKnobView->SetSelected( true ); + else if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_DOT ) + DotKnobView->SetSelected( true ); + else if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_LINE ) + LineKnobView->SetSelected( true ); + + // Buttons + BButton* DefaultsButton = new BButton( BRect( 10, 242, 85, 265), "DefaultsButton", + "Defaults", (new BMessage(SCROLLBAR_DEFAULTS)), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ); + MainBox->AddChild( DefaultsButton ); + + RevertButton = new BButton( BRect( 95, 242, 170, 265), "RevertButton", "Revert", + (new BMessage(SCROLLBAR_REVERT)), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ); + RevertButton->SetEnabled( FALSE ); + MainBox->AddChild( RevertButton ); +} + +void ScrollBarWindow::MessageReceived( BMessage *message ) +{ + switch ( message->what ) + { + case TEST_MSG: + + break; + case SCROLLBAR_ARROW_STYLE_DOUBLE: + if ( DoubleArrowView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + ProportionalKnobView->SetArrowStyle( SCROLLBAR_ARROW_STYLE_DOUBLE ); + FixedKnobView->SetArrowStyle( SCROLLBAR_ARROW_STYLE_DOUBLE ); + DoubleArrowView->SetSelected( true ); + SingleArrowView->SetSelected( false ); + Settings.ArrowStyle=SCROLLBAR_ARROW_STYLE_DOUBLE; + } + break; + case SCROLLBAR_ARROW_STYLE_SINGLE: + if ( SingleArrowView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + ProportionalKnobView->SetArrowStyle( SCROLLBAR_ARROW_STYLE_SINGLE ); + FixedKnobView->SetArrowStyle( SCROLLBAR_ARROW_STYLE_SINGLE ); + DoubleArrowView->SetSelected( false ); + SingleArrowView->SetSelected( true ); + Settings.ArrowStyle=SCROLLBAR_ARROW_STYLE_SINGLE; + } + break; + case SCROLLBAR_KNOB_TYPE_PROPORTIONAL: + if ( ProportionalKnobView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + DoubleArrowView->SetKnobType( SCROLLBAR_KNOB_TYPE_PROPORTIONAL ); + SingleArrowView->SetKnobType( SCROLLBAR_KNOB_TYPE_PROPORTIONAL ); + ProportionalKnobView->SetSelected( true ); + FixedKnobView->SetSelected( false ); + Settings.KnobType=SCROLLBAR_KNOB_TYPE_PROPORTIONAL; + } + break; + case SCROLLBAR_KNOB_TYPE_FIXED: + if ( FixedKnobView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + DoubleArrowView->SetKnobType( SCROLLBAR_KNOB_TYPE_FIXED ); + SingleArrowView->SetKnobType( SCROLLBAR_KNOB_TYPE_FIXED ); + ProportionalKnobView->SetSelected( false ); + FixedKnobView->SetSelected( true ); + Settings.KnobType=SCROLLBAR_KNOB_TYPE_FIXED; + } + break; + case SCROLLBAR_KNOB_STYLE_FLAT: + if ( FlatKnobView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + DoubleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_FLAT ); + SingleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_FLAT ); + ProportionalKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_FLAT ); + FixedKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_FLAT ); + FlatKnobView->SetSelected( true ); + DotKnobView->SetSelected( false ); + LineKnobView->SetSelected( false ); + Settings.KnobStyle=SCROLLBAR_KNOB_STYLE_FLAT; + } + break; + case SCROLLBAR_KNOB_STYLE_DOT: + if ( DotKnobView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + DoubleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + SingleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + ProportionalKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + FixedKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + FlatKnobView->SetSelected( false ); + DotKnobView->SetSelected( true ); + LineKnobView->SetSelected( false ); + Settings.KnobStyle=SCROLLBAR_KNOB_STYLE_DOT; + } + break; + case SCROLLBAR_KNOB_STYLE_LINE: + if ( LineKnobView->IsSelected() == false ) + { + RevertButton->SetEnabled( TRUE ); + DoubleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_LINE ); + SingleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_LINE ); + ProportionalKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_LINE ); + FixedKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_LINE ); + FlatKnobView->SetSelected( false ); + DotKnobView->SetSelected( false ); + LineKnobView->SetSelected( true ); + Settings.KnobStyle=SCROLLBAR_KNOB_STYLE_LINE; + } + break; + case SCROLLBAR_KNOB_SIZE_CHANGED: + RevertButton->SetEnabled( TRUE ); + DoubleArrowView->SetKnobSize( Settings.KnobSize ); + SingleArrowView->SetKnobSize( Settings.KnobSize ); + ProportionalKnobView->SetKnobSize( Settings.KnobSize ); + FixedKnobView->SetKnobSize( Settings.KnobSize ); + break; + case SCROLLBAR_DEFAULTS: + // Load settings. Using defaults for now.. + Settings.ArrowStyle = SCROLLBAR_ARROW_STYLE_DOUBLE; + Settings.KnobStyle = SCROLLBAR_KNOB_STYLE_DOT; + Settings.KnobType = SCROLLBAR_KNOB_TYPE_PROPORTIONAL; + Settings.KnobSize = 16; + RevertButton->SetEnabled( true ); + ProportionalKnobView->SetArrowStyle( SCROLLBAR_ARROW_STYLE_DOUBLE ); + FixedKnobView->SetArrowStyle( SCROLLBAR_ARROW_STYLE_DOUBLE ); + DoubleArrowView->SetSelected( true ); + SingleArrowView->SetSelected( false ); + DoubleArrowView->SetKnobType( SCROLLBAR_KNOB_TYPE_PROPORTIONAL ); + SingleArrowView->SetKnobType( SCROLLBAR_KNOB_TYPE_PROPORTIONAL ); + ProportionalKnobView->SetSelected( true ); + FixedKnobView->SetSelected( false ); + DoubleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + SingleArrowView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + ProportionalKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + FixedKnobView->SetKnobStyle( SCROLLBAR_KNOB_STYLE_DOT ); + FlatKnobView->SetSelected( false ); + DotKnobView->SetSelected( true ); + LineKnobView->SetSelected( false ); + MinimumKnobSize->SetKnobSize( 16 ); + DoubleArrowView->SetKnobSize( Settings.KnobSize ); + SingleArrowView->SetKnobSize( Settings.KnobSize ); + ProportionalKnobView->SetKnobSize( Settings.KnobSize ); + FixedKnobView->SetKnobSize( Settings.KnobSize ); + break; + case SCROLLBAR_REVERT: + RevertButton->SetEnabled( FALSE ); + Settings=RevertSettings; + ProportionalKnobView->SetArrowStyle( Settings.ArrowStyle ); + FixedKnobView->SetArrowStyle( Settings.ArrowStyle ); + //DoubleArrowView->SetSelected( true ); + //SingleArrowView->SetSelected( false ); + DoubleArrowView->SetKnobType( Settings.KnobType ); + SingleArrowView->SetKnobType( Settings.KnobType ); + //ProportionalKnobView->SetSelected( true ); + //FixedKnobView->SetSelected( false ); + DoubleArrowView->SetKnobStyle( Settings.KnobStyle ); + SingleArrowView->SetKnobStyle( Settings.KnobStyle ); + ProportionalKnobView->SetKnobStyle( Settings.KnobStyle ); + FixedKnobView->SetKnobStyle( Settings.KnobStyle ); + //FlatKnobView->SetSelected( false ); + //DotKnobView->SetSelected( true ); + //LineKnobView->SetSelected( false ); + MinimumKnobSize->SetKnobSize( Settings.KnobSize ); + DoubleArrowView->SetKnobSize( Settings.KnobSize ); + SingleArrowView->SetKnobSize( Settings.KnobSize ); + ProportionalKnobView->SetKnobSize( Settings.KnobSize ); + FixedKnobView->SetKnobSize( Settings.KnobSize ); + + if ( Settings.ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) + { + DoubleArrowView->SetSelected( true ); + SingleArrowView->SetSelected( false ); + } + else + { + DoubleArrowView->SetSelected( false ); + SingleArrowView->SetSelected( true ); + } + + if ( Settings.KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL ) + { + ProportionalKnobView->SetSelected( true ); + FixedKnobView->SetSelected( false ); + } + else + { + ProportionalKnobView->SetSelected( false ); + FixedKnobView->SetSelected( true ); + } + + if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_FLAT ) + { + FlatKnobView->SetSelected( true ); + DotKnobView->SetSelected( false ); + LineKnobView->SetSelected( false ); + } + else if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_DOT ) + { + FlatKnobView->SetSelected( false ); + DotKnobView->SetSelected( true ); + LineKnobView->SetSelected( false ); + } + else if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_LINE ) + { + FlatKnobView->SetSelected( false ); + DotKnobView->SetSelected( false ); + LineKnobView->SetSelected( true ); + } + break; + } +} + +void ScrollBarWindow::LoadSettings( BMessage *message ) +{ + BPoint point; + int32 ArrowStyle, KnobType, KnobSize, KnobStyle; + ArrowStyle=KnobType=KnobSize=KnobStyle=0; + + if ( message->FindPoint( "position", &point ) == B_OK ) + MoveTo( point ); + + if ( message->FindInt32( "arrowstyle", &ArrowStyle ) == B_OK ) + { + if ( ArrowStyle == 0 ) + Settings.ArrowStyle=SCROLLBAR_ARROW_STYLE_DOUBLE; + else if ( ArrowStyle == 1 ) + Settings.ArrowStyle=SCROLLBAR_ARROW_STYLE_SINGLE; + } + if ( message->FindInt32( "knobtype", &KnobType ) == B_OK ) + { + if ( KnobType == 0 ) + Settings.KnobType=SCROLLBAR_KNOB_TYPE_PROPORTIONAL; + else if ( KnobType == 1 ) + Settings.KnobType=SCROLLBAR_KNOB_TYPE_FIXED; + } + if ( message->FindInt32( "knobstyle", &KnobStyle ) == B_OK ) + { + if ( KnobStyle == 0 ) + Settings.KnobStyle=SCROLLBAR_KNOB_STYLE_FLAT; + else if ( KnobStyle == 1 ) + Settings.KnobStyle=SCROLLBAR_KNOB_STYLE_DOT; + else if ( KnobStyle == 2 ) + Settings.KnobStyle=SCROLLBAR_KNOB_STYLE_LINE; + } + if ( message->FindInt32( "knobsize", &KnobSize ) == B_OK ) + Settings.KnobSize=KnobSize; +} + +void ScrollBarWindow::SaveSettings() +{ + BMessage msg; + msg.AddPoint( "position", BPoint( Frame().left, Frame().top ) ); + + // Save the arrow style + if ( Settings.ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) + msg.AddInt32( "arrowstyle", 0 ); + else if ( Settings.ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE ) + msg.AddInt32( "arrowstyle", 1 ); + + if ( Settings.KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL ) + msg.AddInt32( "knobtype", 0 ); + else if ( Settings.KnobType == SCROLLBAR_KNOB_TYPE_FIXED ) + msg.AddInt32( "knobtype", 1 ); + + if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_FLAT ) + msg.AddInt32( "knobstyle", 0 ); + else if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_DOT ) + msg.AddInt32( "knobstyle", 1 ); + else if ( Settings.KnobStyle == SCROLLBAR_KNOB_STYLE_LINE ) + msg.AddInt32( "knobstyle", 2 ); + + msg.AddInt32( "knobsize", Settings.KnobSize ); + + BPath path; + status_t result = find_directory( B_USER_SETTINGS_DIRECTORY, &path ); + if ( result == B_OK ) + { + path.Append( "OBOS_ScrollBar_Settings", true ); + BFile file( path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE ); + msg.Flatten( &file ); + } +} + +bool ScrollBarWindow::QuitRequested() +{ + SaveSettings(); + be_app->PostMessage( B_QUIT_REQUESTED ); + return true; +} + diff --git a/src/prefs/scrollbar/scrollbar_window.h b/src/prefs/scrollbar/scrollbar_window.h new file mode 100644 index 0000000000..62f0e5ff1f --- /dev/null +++ b/src/prefs/scrollbar/scrollbar_window.h @@ -0,0 +1,33 @@ +#ifndef SCROLLBAR_WINDOW_H +#define SCROLLBAR_WINDOW_H + +#include +#include +#include +#include "fakescrollbar.h" +#include "knobsizeadjuster.h" + +class ScrollBarWindow : public BWindow +{ + public: + ScrollBarWindow(); + private: + bool QuitRequested(); + void MessageReceived( BMessage *message ); + + void LoadSettings( BMessage *message ); + void SaveSettings(); + + FakeScrollBar *DoubleArrowView; + FakeScrollBar *SingleArrowView; + FakeScrollBar *ProportionalKnobView; + FakeScrollBar *FixedKnobView; + FakeScrollBar *FlatKnobView; + FakeScrollBar *DotKnobView; + FakeScrollBar *LineKnobView; + KnobSizeAdjuster *MinimumKnobSize; + BBox* MainBox; + BButton* RevertButton; +}; + +#endif \ No newline at end of file