Skip to content

Commit

Permalink
Add support for left scrollbar
Browse files Browse the repository at this point in the history
Implements support for placing the vertical scrollbar on the left side
by setting scrollbar_on_left=YES on dillorc. By default, continues to be
on the right side.

See: https://www.toomanyatoms.com/software/mobilized_dillo.html
Authored-By: dogma
  • Loading branch information
rodarima committed Oct 13, 2024
1 parent 05094b9 commit 7bade29
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dillo-3.2.0 [Not released yet]
Patches: Rodrigo Arias Mallo
+- Add primitive support for SVG using the nanosvg.h library.
- Add support for ch, rem, vw, vh, vmin and vmax CSS units.
- Allow placing the scrollbar on the left side.
Patches: dogma, Rodrigo Arias Mallo
+- Avoid expensive search for multipart/form-data boundaries.
Patches: Xavier Del Campo Romero, Rodrigo Arias Mallo
Expand Down
3 changes: 3 additions & 0 deletions dillorc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
# height of the visible page area.
#scroll_step=100

# Place the vertical scrollbar on the left side (default right).
#scrollbar_on_left=NO

#-------------------------------------------------------------------------
# RENDERING SECTION
#-------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion doc/user_help.in.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ <h3 id="scrolling">Scrolling</h3>

<p>You can control the <b>size of a <em>step</em></b> by setting the
<code>scroll_step</code> option in the <a href="#dillorc">dillorc</a>
configuration file. By default it will scroll 100 pixels per step.</p>
configuration file. By default it will scroll 100 pixels per step. The vertical
scrollbar can be positioned on the left side setting the
<code>scrollbar_on_left</code> option to <code>YES</code>, by default it is on
the right side.</p>

<h3 id="find-text">Find text</h3>
<p>
Expand Down
5 changes: 5 additions & 0 deletions dw/fltkflatview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ int FltkFlatView::getVScrollbarThickness ()
return 0;
}

int FltkFlatView::getScrollbarOnLeft ()
{
return 0;
}

void FltkFlatView::scrollTo (int x, int y)
{
}
Expand Down
1 change: 1 addition & 0 deletions dw/fltkflatview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public:
bool usesViewport ();
int getHScrollbarThickness ();
int getVScrollbarThickness ();
int getScrollbarOnLeft ();
void scrollTo (int x, int y);
void setViewportSize (int width, int height,
int hScrollbarThickness, int vScrollbarThickness);
Expand Down
5 changes: 5 additions & 0 deletions dw/fltkpreview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ int FltkPreview::getVScrollbarThickness ()
return 0;
}

int FltkPreview::getScrollbarOnLeft ()
{
return 0;
}

void FltkPreview::scrollTo (int x, int y)
{
scrollX = x;
Expand Down
1 change: 1 addition & 0 deletions dw/fltkpreview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public:
bool usesViewport ();
int getHScrollbarThickness ();
int getVScrollbarThickness ();
int getScrollbarOnLeft ();
void scrollTo (int x, int y);
void scroll (dw::core::ScrollCommand cmd);
void setViewportSize (int width, int height,
Expand Down
65 changes: 54 additions & 11 deletions dw/fltkviewport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,17 @@ void FltkViewport::adjustScrollbarsAndGadgetsAllocation ()
vdiff = hscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
}

hscrollbar->resize(x (), y () + h () - SCROLLBAR_THICKNESS,
w () - hdiff, SCROLLBAR_THICKNESS);
vscrollbar->resize(x () + w () - SCROLLBAR_THICKNESS, y (),
SCROLLBAR_THICKNESS, h () - vdiff);
if (scrollbarOnLeft) {
hscrollbar->resize(x () + hdiff, y () + h () - SCROLLBAR_THICKNESS,
w () - hdiff, SCROLLBAR_THICKNESS);
vscrollbar->resize(x (), y (),
SCROLLBAR_THICKNESS, h () - vdiff);
} else {
hscrollbar->resize(x (), y () + h () - SCROLLBAR_THICKNESS,
w () - hdiff, SCROLLBAR_THICKNESS);
vscrollbar->resize(x () + w () - SCROLLBAR_THICKNESS, y (),
SCROLLBAR_THICKNESS, h () - vdiff);
}

//int X = x () + w () - SCROLLBAR_THICKNESS;
//int Y = y () + h () - SCROLLBAR_THICKNESS;
Expand All @@ -141,6 +148,8 @@ void FltkViewport::adjustScrollbarsAndGadgetsAllocation ()
}
#endif
}

adjustScrollbarValues();
}

void FltkViewport::adjustScrollbarValues ()
Expand Down Expand Up @@ -222,17 +231,29 @@ void FltkViewport::draw ()
draw_child (*hscrollbar);
if (draw && vis_vs && vis_hs) {
fl_color(FL_BACKGROUND_COLOR);
fl_rectf(x()+w()-vis_vs, y()+h()-vis_hs, vis_vs, vis_hs);
if (scrollbarOnLeft) {
fl_rectf(x(), y()+h()-vis_hs, vis_vs, vis_hs);
} else {
fl_rectf(x()+w()-vis_vs, y()+h()-vis_hs, vis_vs, vis_hs);
}
}
// main area
if (d == FL_DAMAGE_CHILD && (draw_vs || draw_hs)) {
_MSG("none\n");
} else if (d == (FL_DAMAGE_SCROLL | FL_DAMAGE_CHILD)) {
fl_scroll(x(), y(), w() - vis_vs, h() - vis_hs,
int x = this->x();

if (scrollbarOnLeft)
x += vis_vs;
fl_scroll(x, y(), w() - vis_vs, h() - vis_hs,
-scrollDX, -scrollDY, draw_area, this);
_MSG("fl_scroll()\n");
} else {
draw_area(this, x(), y(), w() - vis_vs, h() - vis_hs);
int x = this->x();

if (scrollbarOnLeft)
x += vis_vs;
draw_area(this, x, y(), w() - vis_vs, h() - vis_hs);
_MSG("draw_area()\n");
}

Expand Down Expand Up @@ -331,12 +352,27 @@ int FltkViewport::handle (int event)
break;

case FL_ENTER:
if (vscrollbar->visible() && Fl::event_inside(vscrollbar))
return vscrollbar->handle(event);
if (hscrollbar->visible() && Fl::event_inside(hscrollbar))
return hscrollbar->handle(event);
/* could be the result of, e.g., closing another window. */
mouse_x = Fl::event_x();
mouse_y = Fl::event_y();
positionChanged();
break;

case FL_MOVE:
/* Use LEAVE in order not to be over a link, etc., anymore. */
if (vscrollbar->visible() && Fl::event_inside(vscrollbar)) {
(void)FltkWidgetView::handle(FL_LEAVE);
return vscrollbar->handle(event);
}
if (hscrollbar->visible() && Fl::event_inside(hscrollbar)) {
(void)FltkWidgetView::handle(FL_LEAVE);
return hscrollbar->handle(event);
}
break;
case FL_LEAVE:
mouse_x = mouse_y = -1;
break;
Expand Down Expand Up @@ -438,13 +474,13 @@ void FltkViewport::scroll (core::ScrollCommand cmd)
} else if (cmd == core::SCREEN_RIGHT_CMD) {
scroll (w() - hscrollbar->linesize (), 0);
} else if (cmd == core::LINE_UP_CMD) {
scroll (0, (int) -vscrollbar->linesize ());
scroll (0, -vscrollbar->linesize ());
} else if (cmd == core::LINE_DOWN_CMD) {
scroll (0, (int) vscrollbar->linesize ());
scroll (0, vscrollbar->linesize ());
} else if (cmd == core::LEFT_CMD) {
scroll ((int) -hscrollbar->linesize (), 0);
scroll (-hscrollbar->linesize (), 0);
} else if (cmd == core::RIGHT_CMD) {
scroll ((int) hscrollbar->linesize (), 0);
scroll (hscrollbar->linesize (), 0);
} else if (cmd == core::TOP_CMD) {
scrollTo (scrollX, 0);
} else if (cmd == core::BOTTOM_CMD) {
Expand Down Expand Up @@ -478,6 +514,13 @@ void FltkViewport::selectionScroll (void *data)
Fl::repeat_timeout(0.025, selectionScroll, data);
}

void FltkViewport::setScrollbarOnLeft (bool enable)
{
scrollbarOnLeft = enable ? 1 : 0;
adjustScrollbarsAndGadgetsAllocation();
damage(FL_DAMAGE_ALL);
}

void FltkViewport::setViewportSize (int width, int height,
int hScrollbarThickness,
int vScrollbarThickness)
Expand Down
3 changes: 3 additions & 0 deletions dw/fltkviewport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private:

int scrollX, scrollY;
int scrollDX, scrollDY;
int scrollbarOnLeft;
int hasDragScroll, dragScrolling, dragX, dragY;
int horScrolling, verScrolling;

Expand Down Expand Up @@ -64,6 +65,7 @@ public:
bool usesViewport ();
int getHScrollbarThickness ();
int getVScrollbarThickness ();
int getScrollbarOnLeft () {return scrollbarOnLeft; };
void scroll(int dx, int dy);
void scroll(dw::core::ScrollCommand cmd);
void scrollTo (int x, int y);
Expand All @@ -75,6 +77,7 @@ public:
GadgetOrientation gadgetOrientation);
void setDragScroll (bool enable) { hasDragScroll = enable ? 1 : 0; }
void addGadget (Fl_Widget *gadget);
void setScrollbarOnLeft (bool enable);
};

} // namespace fltk
Expand Down
2 changes: 2 additions & 0 deletions dw/layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@ void Layout::resizeIdle ()
assert (topLevel->needsAllocate ());

allocation.x = allocation.y = 0;
if (usesViewport && view->getScrollbarOnLeft())
allocation.x += currVScrollbarThickness();
allocation.width = requisition.width;
allocation.ascent = requisition.ascent;
allocation.descent = requisition.descent;
Expand Down
2 changes: 2 additions & 0 deletions dw/view.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public:
*/
virtual int getVScrollbarThickness () = 0;

virtual int getScrollbarOnLeft () = 0;

/**
* \brief Scroll the vieport to the given position.
*
Expand Down
1 change: 1 addition & 0 deletions src/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void a_Prefs_init(void)
prefs.search_urls = dList_new(16);
dList_append(prefs.search_urls, dStrdup(PREFS_SEARCH_URL));
prefs.search_url_idx = 0;
prefs.scrollbar_on_left = FALSE;
prefs.show_back = TRUE;
prefs.show_bookmarks = TRUE;
prefs.show_clear_url = TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef struct {
int32_t font_max_size;
int32_t font_min_size;
int32_t scroll_step;
bool_t scrollbar_on_left;
bool_t show_back;
bool_t show_forw;
bool_t show_home;
Expand Down
1 change: 1 addition & 0 deletions src/prefsparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void PrefsParser::parse(FILE *fp)
{ "parse_embedded_css", &prefs.parse_embedded_css, PREFS_BOOL, 0 },
{ "save_dir", &prefs.save_dir, PREFS_STRING, 0 },
{ "scroll_step", &prefs.scroll_step, PREFS_INT32, 0 },
{ "scrollbar_on_left", &prefs.scrollbar_on_left, PREFS_BOOL, 0 },
{ "search_url", &prefs.search_urls, PREFS_STRINGS, 0 },
{ "show_back", &prefs.show_back, PREFS_BOOL, 0 },
{ "show_bookmarks", &prefs.show_bookmarks, PREFS_BOOL, 0 },
Expand Down
1 change: 1 addition & 0 deletions src/uicmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ static BrowserWindow *UIcmd_tab_new(CustTabs *tabs, UI *old_ui, int focus)
viewport->box(FL_NO_BOX);
viewport->setBufferedDrawing (prefs.buffered_drawing ? true : false);
viewport->setDragScroll (prefs.middle_click_drags_page ? true : false);
viewport->setScrollbarOnLeft (prefs.scrollbar_on_left ? true : false);
layout->attachView (viewport);
new_ui->set_render_layout(viewport);
viewport->setScrollStep(prefs.scroll_step);
Expand Down

0 comments on commit 7bade29

Please sign in to comment.