diff options
| author | Greg Ercolano <erco@seriss.com> | 2017-11-02 21:14:40 +0000 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2017-11-02 21:14:40 +0000 |
| commit | 127147ca976a3151f8a6e307d0d7e482e987d29f (patch) | |
| tree | 93715f9eb43c62cfe1bb32f63d14b74759eec4c6 | |
| parent | 3256932e2a6933ec8d88322b38fc049026ad4b07 (diff) | |
Addresses STR# 3423; adds missing scrollbar_size() methods and honors global Fl::scrollbar_size().
Includes mods to unittest's scrollbar size test.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12538 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | FL/Fl_Text_Display.H | 70 | ||||
| -rw-r--r-- | src/Fl_Text_Display.cxx | 38 | ||||
| -rw-r--r-- | test/unittest_scrollbarsize.cxx | 87 |
3 files changed, 128 insertions, 67 deletions
diff --git a/FL/Fl_Text_Display.H b/FL/Fl_Text_Display.H index 2ea96dd17..22853bb46 100644 --- a/FL/Fl_Text_Display.H +++ b/FL/Fl_Text_Display.H @@ -24,6 +24,7 @@ #ifndef FL_TEXT_DISPLAY_H #define FL_TEXT_DISPLAY_H +#include <FL/Fl.H> // Fl::scrollbar_size() #include "fl_draw.H" #include "Fl_Group.H" #include "Fl_Widget.H" @@ -222,19 +223,66 @@ public: */ void cursor_color(Fl_Color n) {mCursor_color = n;} - /** - Gets the width/height of the scrollbars. - \return width of scrollbars - */ - int scrollbar_width() const { return scrollbar_width_; } - /** - Sets the width/height of the scrollbars. - \param W width of scrollbars - */ - void scrollbar_width(int W) { scrollbar_width_ = W; } + This method has been deprecated, existing for backwards compatibility only. + Use scrollbar_size() instead. + This method returns the global value Fl::scrollbar_size() unless + a specific scrollbar_width_ has been set. + \todo This method should eventually be removed. + */ + int scrollbar_width() const { + return scrollbar_width_ ? scrollbar_width_ : Fl::scrollbar_size(); + } + + /** + This method has been deprecated, existing for backwards compatibility only. + Use scrollbar_size(int) instead. + This method sets the global Fl::scrollbar_size(), and forces this + instance of the widget to use it. + \todo This method should eventually be removed + */ + void scrollbar_width(int width) { + Fl::scrollbar_size(width); + scrollbar_width_ = 0; + } /** + Gets the current size of the scrollbars' troughs, in pixels. + + If this value is zero (default), this widget will use the + Fl::scrollbar_size() value as the scrollbar's width. + + \returns Scrollbar size in pixels, or 0 if the global Fl::scrollbar_size() is being used. + \see Fl::scrollbar_size(int) + */ + int scrollbar_size() const { + return(scrollbar_width_); + } + + /** + Sets the pixel size of the scrollbars' troughs to \p newSize, in pixels. + + Normally you should not need this method, and should use + Fl::scrollbar_size(int) instead to manage the size of ALL + your widgets' scrollbars. This ensures your application + has a consistent UI, is the default behavior, and is normally + what you want. + + Only use THIS method if you really need to override the global + scrollbar size. The need for this should be rare. + + Setting \p newSize to the special value of 0 causes the widget to + track the global Fl::scrollbar_size(), which is the default. + + \param[in] newSize Sets the scrollbar size in pixels.\n + If 0 (default), scrollbar size tracks the global Fl::scrollbar_size() + \see Fl::scrollbar_size() + */ + void scrollbar_size(int newSize) { + scrollbar_width_ = newSize; + } + + /** Gets the scrollbar alignment type. \return scrollbar alignment */ @@ -522,7 +570,7 @@ protected: Fl_Scrollbar* mHScrollBar; Fl_Scrollbar* mVScrollBar; - int scrollbar_width_; + int scrollbar_width_; // size of scrollbar trough (behavior changed in 1.4) Fl_Align scrollbar_align_; int dragPos, dragType, dragging; int display_insert_position_hint; diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index 06a2763ca..a60a5dad4 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -127,8 +127,8 @@ Fl_Text_Display::Fl_Text_Display(int X, int Y, int W, int H, const char* l) end(); - scrollbar_width(Fl::scrollbar_size()); - scrollbar_align(FL_ALIGN_BOTTOM_RIGHT); + scrollbar_width_ = 0; // 0: uses Fl::scrollbar_size() + scrollbar_align_ = FL_ALIGN_BOTTOM_RIGHT; mCursorOn = 0; mCursorPos = 0; @@ -466,6 +466,7 @@ void Fl_Text_Display::recalc_display() { // did we have scrollbars initially? unsigned int hscrollbarvisible = mHScrollBar->visible(); unsigned int vscrollbarvisible = mVScrollBar->visible(); + int scrollsize = scrollbar_width_ ? scrollbar_width_ : Fl::scrollbar_size(); int oldTAWidth = text_area.w; @@ -506,7 +507,7 @@ void Fl_Text_Display::recalc_display() { if (nvlines < 1) nvlines = 1; if (nlines >= nvlines-1) { mVScrollBar->set_visible(); // we need a vertical scrollbar - text_area.w -= scrollbar_width(); + text_area.w -= scrollsize; } } @@ -552,7 +553,7 @@ void Fl_Text_Display::recalc_display() { calc_last_char(); // figure the scrollbars - if (scrollbar_width()) { + if (scrollsize) { /* Decide if the vertical scrollbar needs to be visible */ if (!mVScrollBar->visible() && @@ -560,7 +561,7 @@ void Fl_Text_Display::recalc_display() { mNBufferLines >= mNVisibleLines-(mContinuousWrap?0:1)) { mVScrollBar->set_visible(); - text_area.w -= scrollbar_width(); + text_area.w -= scrollsize; again = 1; } @@ -594,7 +595,7 @@ void Fl_Text_Display::recalc_display() { char wrap_at_bounds = mContinuousWrap && (mWrapMarginPix<text_area.w); if (!wrap_at_bounds) { mHScrollBar->set_visible(); - text_area.h -= scrollbar_width(); + text_area.h -= scrollsize; again = 1; // loop again to see if we now need vert. & recalc sizes } } @@ -605,28 +606,28 @@ void Fl_Text_Display::recalc_display() { // Note: width and height have been calculated above. text_area.x = X + mLineNumWidth + LEFT_MARGIN; if (mVScrollBar->visible() && scrollbar_align() & FL_ALIGN_LEFT) - text_area.x += scrollbar_width(); + text_area.x += scrollsize; text_area.y = Y + TOP_MARGIN; if (mHScrollBar->visible() && scrollbar_align() & FL_ALIGN_TOP) - text_area.y += scrollbar_width(); + text_area.y += scrollsize; // position and resize scrollbars if (mVScrollBar->visible()) { if (scrollbar_align() & FL_ALIGN_LEFT) { #ifdef LINENUM_LEFT_OF_VSCROLL - mVScrollBar->resize(text_area.x - LEFT_MARGIN - scrollbar_width(), + mVScrollBar->resize(text_area.x - LEFT_MARGIN - scrollsize, #else mVScrollBar->resize(X, #endif text_area.y - TOP_MARGIN, - scrollbar_width(), + scrollsize, text_area.h + TOP_MARGIN + BOTTOM_MARGIN); } else { - mVScrollBar->resize(X+W-scrollbar_width(), + mVScrollBar->resize(X+W-scrollsize, text_area.y - TOP_MARGIN, - scrollbar_width(), + scrollsize, text_area.h + TOP_MARGIN + BOTTOM_MARGIN); } } @@ -636,12 +637,12 @@ void Fl_Text_Display::recalc_display() { mHScrollBar->resize(text_area.x - LEFT_MARGIN, Y, text_area.w + LEFT_MARGIN + RIGHT_MARGIN, - scrollbar_width()); + scrollsize); } else { mHScrollBar->resize(text_area.x - LEFT_MARGIN, - Y + H - scrollbar_width(), + Y + H - scrollsize, text_area.w + LEFT_MARGIN + RIGHT_MARGIN, - scrollbar_width()); + scrollsize); } } @@ -3661,6 +3662,9 @@ void Fl_Text_Display::draw(void) { // background color -- change if inactive Fl_Color bgcolor = active_r() ? color() : fl_inactive(color()); + // scrollbar size + int scrollsize = scrollbar_width_ ? scrollbar_width_ : Fl::scrollbar_size(); + // draw the non-text, non-scrollbar areas. if (damage() & FL_DAMAGE_ALL) { recalc_display(); @@ -3674,9 +3678,9 @@ void Fl_Text_Display::draw(void) { draw_box(box(), x(), y(), W, H, bgcolor); if (mHScrollBar->visible()) - W -= scrollbar_width(); + W -= scrollsize; if (mVScrollBar->visible()) - H -= scrollbar_width(); + H -= scrollsize; // left margin fl_rectf(text_area.x-LEFT_MARGIN, text_area.y-TOP_MARGIN, diff --git a/test/unittest_scrollbarsize.cxx b/test/unittest_scrollbarsize.cxx index f8e97d6c6..3f4697814 100644 --- a/test/unittest_scrollbarsize.cxx +++ b/test/unittest_scrollbarsize.cxx @@ -20,6 +20,7 @@ #include <FL/Fl_Browser.H> #include <FL/Fl_Tree.H> #include <FL/Fl_Table.H> +#include <FL/Fl_Text_Display.H> #include <FL/Fl_Value_Slider.H> // @@ -67,50 +68,37 @@ class MyTable : public Fl_Table { ~MyTable() { } }; +static const char *phonetics[] = { + "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", + "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", + "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", + "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", NULL +}; + class ScrollBarSizeTest : public Fl_Group { - Fl_Browser *brow_a, *brow_b, *brow_c; - Fl_Tree *tree_a, *tree_b, *tree_c; - MyTable *table_a,*table_b,*table_c; + Fl_Browser *brow_a, *brow_b, *brow_c; + Fl_Tree *tree_a, *tree_b, *tree_c; + MyTable *table_a,*table_b,*table_c; + Fl_Text_Display *text_a, *text_b, *text_c; Fl_Browser *makebrowser(int X,int Y,int W,int H,const char*L=0) { Fl_Browser *b = new Fl_Browser(X,Y,W,H,L); b->type(FL_MULTI_BROWSER); b->align(FL_ALIGN_TOP); - b->add("Papa"); b->add("Delta"); b->add("Hotel"); - b->add("Long entry will show h-bar"); - b->add("Charlie"); b->add("Echo"); b->add("Foxtrot"); - b->add("Golf"); b->add("Lima"); b->add("Victor"); - b->add("Alpha"); b->add("Xray"); b->add("Yankee"); - b->add("Oscar"); b->add("India"); b->add("Juliet"); - b->add("Kilo"); b->add("Mike"); b->add("Sierra"); - b->add("November"); b->add("Tango"); b->add("Quebec"); - b->add("Bravo"); b->add("Romeo"); b->add("Uniform"); - b->add("Whisky"); b->add("Zulu"); - b->add("Papa"); b->add("Delta"); b->add("Hotel"); - b->add("Charlie"); b->add("Echo"); b->add("Foxtrot"); - b->add("Golf"); b->add("Lima"); b->add("Victor"); - b->add("Alpha"); b->add("Xray"); b->add("Yankee"); - b->add("Oscar"); b->add("India"); b->add("Juliet"); - b->add("Kilo"); b->add("Mike"); b->add("Sierra"); - b->add("November"); b->add("Tango"); b->add("Quebec"); - b->add("Bravo"); b->add("Romeo"); b->add("Uniform"); - b->add("Whisky"); b->add("Zulu"); + for (int t=0; phonetics[t]; t++ ) { + b->add(phonetics[t]); + if ( phonetics[t][0] == 'C' ) b->add("Long entry will show h-bar"); + } return(b); } Fl_Tree *maketree(int X,int Y,int W,int H,const char*L=0) { Fl_Tree *b = new Fl_Tree(X,Y,W,H,L); b->type(FL_TREE_SELECT_MULTI); b->align(FL_ALIGN_TOP); - b->add("Papa"); b->add("Delta"); b->add("Hotel"); - b->add("Long entry will show h-bar"); - b->add("Charlie"); b->add("Echo"); b->add("Foxtrot"); - b->add("Golf"); b->add("Lima"); b->add("Victor"); - b->add("Alpha"); b->add("Xray"); b->add("Yankee"); - b->add("Oscar"); b->add("India"); b->add("Juliet"); - b->add("Kilo"); b->add("Mike"); b->add("Sierra"); - b->add("November"); b->add("Tango"); b->add("Quebec"); - b->add("Bravo"); b->add("Romeo"); b->add("Uniform"); - b->add("Whisky"); b->add("Zulu"); + for (int t=0; phonetics[t]; t++ ) { + b->add(phonetics[t]); + if ( phonetics[t][0] == 'C' ) b->add("Long entry will show h-bar"); + } return(b); } MyTable *maketable(int X,int Y,int W,int H,const char*L=0) { @@ -119,6 +107,16 @@ class ScrollBarSizeTest : public Fl_Group { mta->end(); return(mta); } + Fl_Text_Display *maketextdisplay(int X,int Y,int W,int H,const char*L=0) { + Fl_Text_Display *dpy = new Fl_Text_Display(X,Y,W,H,L); + Fl_Text_Buffer *buf = new Fl_Text_Buffer(); + dpy->buffer(buf); + for (int t=0; phonetics[t]; t++ ) { + buf->printf("%s\n", phonetics[t]); + if ( phonetics[t][0] == 'C' ) buf->printf("Long entry will show h-bar\n"); + } + return(dpy); + } void slide_cb2(Fl_Value_Slider *in) { const char *label = in->label(); int val = int(in->value()); @@ -127,6 +125,7 @@ class ScrollBarSizeTest : public Fl_Group { brow_a->scrollbar_size(val); tree_a->scrollbar_size(val); table_a->scrollbar_size(val); + text_a->scrollbar_size(val); } else { Fl::scrollbar_size(val); } @@ -173,6 +172,8 @@ public: int treeh = browh; int tabley = treey + treeh + 20; int tableh = browh; + int texty = tabley + tableh + 20; + int texth = browh; brow_a = makebrowser(X+ 10,browy,100,browh,"Browser A"); brow_b = makebrowser(X+120,browy,100,browh,"Browser B"); brow_c = makebrowser(X+230,browy,100,browh,"Browser C"); @@ -182,6 +183,9 @@ public: table_a = maketable(X+ 10,tabley,100,tableh,"Table A"); table_b = maketable(X+120,tabley,100,tableh,"Table B"); table_c = maketable(X+230,tabley,100,tableh,"Table C"); + text_a = maketextdisplay(X+ 10,texty,100,texth,"Text Display A"); + text_b = maketextdisplay(X+120,texty,100,texth,"Text Display B"); + text_c = maketextdisplay(X+230,texty,100,texth,"Text Display C"); Fl_Value_Slider *slide_glob = new Fl_Value_Slider(X+100,Y,100,18,"Global Scroll Size"); slide_glob->value(16); slide_glob->type(FL_HORIZONTAL); @@ -198,14 +202,19 @@ public: slide_browa->step(1.0); slide_browa->callback(slide_cb, (void*)this); slide_browa->labelsize(12); + int msgbox_x = brow_c->x() + brow_c->w() + 20; + int msgbox_w = W-(msgbox_x-X); + Fl_Box *msgbox = new Fl_Box(msgbox_x,browy,msgbox_w,H-Y-48); + msgbox->label("\nVerify global scroll sizing and per-widget scroll sizing. " + "Scrollbar's size should change interactively as size sliders are changed. " + "Changing 'Global Scroll Size' should affect all three browser's scrollbars UNLESS " + "the 'A: Scroll Size' slider is changed, in which case its value will take precedence " + "for the 'A' group of widgets."); + msgbox->labelsize(10); + msgbox->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER|FL_ALIGN_LEFT|FL_ALIGN_WRAP); + msgbox->box(FL_FLAT_BOX); + msgbox->color(53); // 90% gray end(); - label("Verify global scroll sizing and per-widget scroll sizing.\n" - "Scrollbar's size should change interactively as size sliders are changed.\n" - "Changing 'Global Scroll Size' should affect all three browser's scrollbars UNLESS\n" - "the 'A: Scroll Size' slider is changed, in which case its value will take precedence\n" - "for the 'A' group of widgets."); - labelsize(10); - align(FL_ALIGN_INSIDE|FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_WRAP); } }; |
