Skip to content

Commit

Permalink
gui: cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalak committed Aug 29, 2024
1 parent 238449d commit 6f11d8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions bld/gui/win/c/guirange.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void SetVScrollRange( gui_window *wnd, guix_ord range, guix_ord text_rang
void GUIAPI GUISetHScrollRangeCols( gui_window *wnd, gui_text_ord text_range )
{
if( IS_HSCROLL_ON( wnd ) ) {
wnd->flags |= HRANGE_COL;
wnd->flags |= HRANGE_CHAR_UNIT;
SetHScrollRange( wnd, GUITextToScreenH( text_range, wnd ), text_range );
}
}
Expand All @@ -85,7 +85,7 @@ void GUIAPI GUISetHScrollRangeCols( gui_window *wnd, gui_text_ord text_range )
void GUIAPI GUISetVScrollRangeRows( gui_window *wnd, gui_text_ord text_range )
{
if( IS_VSCROLL_ON( wnd ) ) {
wnd->flags |= VRANGE_ROW;
wnd->flags |= VRANGE_CHAR_UNIT;
SetVScrollRange( wnd, GUITextToScreenV( text_range, wnd ), text_range );
}
}
Expand All @@ -99,7 +99,7 @@ void GUIAPI GUISetHScrollRange( gui_window *wnd, gui_ord range )
guix_ord scr_range;

if( IS_HSCROLL_ON( wnd ) ) {
wnd->flags &= ~HRANGE_COL;
wnd->flags &= ~HRANGE_CHAR_UNIT;
scr_range = GUIScaleToScreenH( range );
SetHScrollRange( wnd, scr_range, scr_range );
}
Expand All @@ -114,7 +114,7 @@ void GUIAPI GUISetVScrollRange( gui_window *wnd, gui_ord range )
guix_ord scr_range;

if( IS_VSCROLL_ON( wnd ) ) {
wnd->flags &= ~VRANGE_ROW;
wnd->flags &= ~VRANGE_CHAR_UNIT;
scr_range = GUIScaleToScreenV( range );
SetVScrollRange( wnd, scr_range, scr_range );
}
Expand Down
16 changes: 8 additions & 8 deletions bld/gui/win/c/guiscrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void GUIProcessScrollMsg( gui_window *wnd, WPI_MSG msg, WPI_PARAM1 wparam, WPI_P
}

static void DoSetScroll( gui_window *wnd, int bar, bool range_set,
bool chars, unsigned *p_range )
bool char_unit, unsigned *prange )
{
guix_ord range;
guix_ord pos;
Expand All @@ -314,8 +314,8 @@ static void DoSetScroll( gui_window *wnd, int bar, bool range_set,
* app explicitly set scroll range
* need to adjust range if size changed
*/
range = *p_range;
if( chars ) {
range = *prange;
if( char_unit ) {
range *= GUIGetScrollInc( wnd, bar );
}
if( range < screen_size ) {
Expand All @@ -327,12 +327,12 @@ static void DoSetScroll( gui_window *wnd, int bar, bool range_set,
if( range < pos ) {
GUIScroll( wnd, bar, range - pos );
}
if( !chars ) {
*p_range = range + screen_size;
if( !char_unit ) {
*prange = range + screen_size;
}
} else {
range = screen_size + GUIGetScrollPos( wnd, bar );
*p_range = range + screen_size;
*prange = range + screen_size;
}
GUISetScrollRange( wnd, bar, 0, range, true );
}
Expand All @@ -343,9 +343,9 @@ static void DoSetScroll( gui_window *wnd, int bar, bool range_set,
void GUISetScroll( gui_window *wnd )
{
if( GUI_DO_HSCROLL( wnd ) ) {
DoSetScroll( wnd, SB_HORZ, GUI_HRANGE_SET( wnd ), (wnd->flags & HRANGE_COL) != 0, &wnd->hscroll_range );
DoSetScroll( wnd, SB_HORZ, GUI_HRANGE_SET( wnd ), GUI_HRANGE_CHAR_UNIT( wnd ), &wnd->hscroll_range );
}
if( GUI_DO_VSCROLL( wnd ) ) {
DoSetScroll( wnd, SB_VERT, GUI_VRANGE_SET( wnd ), (wnd->flags & VRANGE_ROW) != 0, &wnd->vscroll_range );
DoSetScroll( wnd, SB_VERT, GUI_VRANGE_SET( wnd ), GUI_VRANGE_CHAR_UNIT( wnd ), &wnd->vscroll_range );
}
}
7 changes: 5 additions & 2 deletions bld/gui/win/h/guiwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
#define GUI_DO_HSCROLL(x) (IS_HSCROLL_ON(x) && (((x)->style & GUI_HSCROLL_EVENTS) == 0))
#define GUI_DO_VSCROLL(x) (IS_VSCROLL_ON(x) && (((x)->style & GUI_VSCROLL_EVENTS) == 0))

#define GUI_HRANGE_CHAR_UNIT(x) (((x)->flags & HRANGE_CHAR_UNIT) != 0)
#define GUI_VRANGE_CHAR_UNIT(x) (((x)->flags & VRANGE_CHAR_UNIT) != 0)

#define GUI_HSCROLL_COLS(x) (((x)->scroll_style & GUI_HCOLS) != 0)
#define GUI_VSCROLL_ROWS(x) (((x)->scroll_style & GUI_VROWS) != 0)

Expand Down Expand Up @@ -96,8 +99,8 @@ typedef enum flags {
VRANGE_SET = 0x0002,
NEEDS_RESIZE_REDRAW = 0x0004,
NEEDS_RESIZE_NOTIFY = 0x0008,
VRANGE_ROW = 0x0010,
HRANGE_COL = 0x0020,
VRANGE_CHAR_UNIT = 0x0010,
HRANGE_CHAR_UNIT = 0x0020,
DOING_CLOSE = 0x0040,
SENT_INIT = 0x0080,
IS_DIALOG = 0x0100,
Expand Down

0 comments on commit 6f11d8f

Please sign in to comment.