From 7897e65d106854d65e502ccafdcc216670e6b251 Mon Sep 17 00:00:00 2001 From: Mark Hessling Date: Thu, 4 Jul 2002 10:23:50 +0000 Subject: [PATCH] Changes to make scrollbars under X11 work better --- x11/ScrollBox.c | 44 ++++++++++++++------------------------------ x11/ScrollBoxP.h | 1 + x11/pdcx11.c | 47 ++++++++++++++++++++++++++--------------------- x11/process/x11.c | 14 +++++--------- x11/sb.c | 8 ++++---- 5 files changed, 50 insertions(+), 64 deletions(-) diff --git a/x11/ScrollBox.c b/x11/ScrollBox.c index 67030718..411c8c89 100644 --- a/x11/ScrollBox.c +++ b/x11/ScrollBox.c @@ -19,6 +19,7 @@ #include #include +#include #include "x11/ScrollBoxP.h" @@ -33,11 +34,16 @@ * ****************************************************************/ -static XtResource resources[] = { - {XtNhSpace, XtCHSpace, XtRDimension, sizeof(Dimension), - XtOffset(ScrollBoxWidget, scrollBox.h_space), XtRImmediate, (XtPointer)4}, - {XtNvSpace, XtCVSpace, XtRDimension, sizeof(Dimension), - XtOffset(ScrollBoxWidget, scrollBox.v_space), XtRImmediate, (XtPointer)4}, +static XtResource resources[] = +{ + { XtNhSpace, XtCHSpace, XtRDimension, sizeof(Dimension), + XtOffset(ScrollBoxWidget, scrollBox.h_space), XtRImmediate, (XtPointer)4}, + { XtNvSpace, XtCVSpace, XtRDimension, sizeof(Dimension), + XtOffset(ScrollBoxWidget, scrollBox.v_space), XtRImmediate, (XtPointer)4}, + { XtNheightInc, XtCHeightInc, XtRDimension, sizeof(Dimension), + XtOffset(ScrollBoxWidget, scrollBox.increment_height), XtRImmediate, (XtPointer)13}, + { XtNwidthInc, XtCWidthInc, XtRDimension, sizeof(Dimension), + XtOffset(ScrollBoxWidget, scrollBox.increment_width), XtRImmediate, (XtPointer)7}, }; /**************************************************************** @@ -132,8 +138,6 @@ Boolean doit; Dimension th; Dimension tw; #endif - long supp=0; - XSizeHints hints; int i; if (sbw->composite.num_children != 3) @@ -158,25 +162,6 @@ Boolean doit; vscroll = sbw->composite.children[1]; hscroll = sbw->composite.children[2]; -#if 1 -fprintf(stderr,"%s %d:\n",__FILE__,__LINE__); - if ( XtIsRealized(wmain) ) - { - if ( !XGetWMNormalHints( XtDisplay(wmain), XtWindow(wmain), &hints, &supp ) ) - { - hints.height_inc = 13; - hints.width_inc = 7; -fprintf(stderr,"%s %d:\n",__FILE__,__LINE__); - } - } - else - { - hints.height_inc = 13; - hints.width_inc = 7; - } -fprintf(stderr,"%s %d: height: %d width: %d\n",__FILE__,__LINE__,hints.height_inc,hints.width_inc); -#endif - /* * Size all three widgets so that space is fully utilized. */ @@ -193,8 +178,8 @@ fprintf(stderr,"%s %d: height: %d width: %d\n",__FILE__,__LINE__,hints.height_in /* * Force the main window to be sized to the appropriate increments */ - mw = (mw/hints.width_inc)*hints.width_inc; - mh = ((mh/hints.height_inc)*hints.height_inc)+hints.height_inc; + mw = (mw/sbw->scrollBox.increment_width)*sbw->scrollBox.increment_width; + mh = ((mh/sbw->scrollBox.increment_height)*sbw->scrollBox.increment_height)+sbw->scrollBox.increment_height; vx = wmain->core.x + mw + sbw->scrollBox.h_space + wmain->core.border_width + vscroll->core.border_width; @@ -202,7 +187,7 @@ fprintf(stderr,"%s %d: height: %d width: %d\n",__FILE__,__LINE__,hints.height_in vh = mh; /* scrollbars are always same length as main window */ hw = mw; -fprintf(stderr,"%s %d: mw %d mh %d vx %d hy %d hinc %d winc %d\n",__FILE__,__LINE__,mw,mh,vx,hy,hints.height_inc,hints.width_inc); +fprintf(stderr,"%s %d: mw %d mh %d vx %d hy %d hinc %d winc %d hspace %d\n",__FILE__,__LINE__,mw,mh,vx,hy,sbw->scrollBox.increment_height,sbw->scrollBox.increment_width,sbw->scrollBox.h_space); if (doit) { XtResizeWidget(wmain, mw, mh, 1); @@ -219,7 +204,6 @@ fprintf(stderr,"%s %d: mw %d mh %d vx %d hy %d hinc %d winc %d\n",__FILE__,__LIN vh = mh = wmain->core.height; vx = wmain->core.x + mw + sbw->scrollBox.h_space + wmain->core.border_width + vscroll->core.border_width; - hy = wmain->core.y + mh + sbw->scrollBox.v_space + wmain->core.border_width + hscroll->core.border_width; if (doit) { diff --git a/x11/ScrollBoxP.h b/x11/ScrollBoxP.h index c78a1cef..62fdebe7 100644 --- a/x11/ScrollBoxP.h +++ b/x11/ScrollBoxP.h @@ -50,6 +50,7 @@ typedef struct { Dimension h_space, v_space; Dimension preferred_width, preferred_height; Dimension last_query_width, last_query_height; + Dimension increment_width, increment_height; XtGeometryMask last_query_mode; } ScrollBoxPart; diff --git a/x11/pdcx11.c b/x11/pdcx11.c index 2cf751a5..066b303a 100644 --- a/x11/pdcx11.c +++ b/x11/pdcx11.c @@ -24,6 +24,11 @@ #if defined(XCURSES) #include "pdcx11.h" +#if NeedWidePrototypes +# define PDC_SCROLLBAR_TYPE double +#else +# define PDC_SCROLLBAR_TYPE float +#endif /***************************************************************************/ /* Default icons for XCurses applications. */ @@ -1353,34 +1358,34 @@ int XCursesRefreshScrollbar() #endif /***********************************************************************/ { - double total_y=(double)(SP->sb_total_y); - double viewport_y=(double)(SP->sb_viewport_y); - double cur_y=(double)(SP->sb_cur_y); - double total_x=(double)(SP->sb_total_x*XCursesFontWidth); - double viewport_x=(double)(SP->sb_viewport_x*XCursesFontWidth); - double cur_x=(double)(SP->sb_cur_x*XCursesFontWidth); - double vtop=(double)(cur_y/total_y); - double vlength=(double)(viewport_y/total_y); - double htop=(double)(cur_x/total_x); - double hlength=(double)(viewport_x/total_x); + PDC_SCROLLBAR_TYPE total_y=(PDC_SCROLLBAR_TYPE)(SP->sb_total_y*XCursesFontHeight); + PDC_SCROLLBAR_TYPE viewport_y=(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_y*XCursesFontHeight); + PDC_SCROLLBAR_TYPE cur_y=(PDC_SCROLLBAR_TYPE)(SP->sb_cur_y*XCursesFontHeight); + PDC_SCROLLBAR_TYPE total_x=(PDC_SCROLLBAR_TYPE)(SP->sb_total_x*XCursesFontWidth); + PDC_SCROLLBAR_TYPE viewport_x=(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_x*XCursesFontWidth); + PDC_SCROLLBAR_TYPE cur_x=(PDC_SCROLLBAR_TYPE)(SP->sb_cur_x*XCursesFontWidth); + PDC_SCROLLBAR_TYPE vtop=(PDC_SCROLLBAR_TYPE)(cur_y/total_y); + PDC_SCROLLBAR_TYPE vlength=(PDC_SCROLLBAR_TYPE)(viewport_y/total_y); + PDC_SCROLLBAR_TYPE htop=(PDC_SCROLLBAR_TYPE)(cur_x/total_x); + PDC_SCROLLBAR_TYPE hlength=(PDC_SCROLLBAR_TYPE)(viewport_x/total_x); #ifdef PDCDEBUG - if (trace_on) PDC_debug("%s:XCursesRefreshScrollbar() - called: \n",(XCursesProcess)?" X":"CURSES"); + if (trace_on) PDC_debug("%s:XCursesRefreshScrollbar() - called: \n",(XCursesProcess)?" X":"CURSES"); #endif - if (!SP->sb_on) - return(ERR); -#if 1 + if (!SP->sb_on) + return(ERR); +#if 0 fprintf(stderr,"%s:XCursesRefreshScrollbar() - vert: %d %f %f %f %f %f\n",(XCursesProcess)?" X":"CURSES", SP->sb_total_y,total_y,viewport_y,cur_y, vtop,vlength); -fprintf(stderr,"%s:XCursesRefreshScrollbar() - horz: %d %d %f %f %f %f %f\n",(XCursesProcess)?" X":"CURSES", - SP->sb_total_x,XCursesFontWidth,total_x,viewport_x,cur_x, +fprintf(stderr,"%s:XCursesRefreshScrollbar() - horz: %d %f %f %f %f %f\n",(XCursesProcess)?" X":"CURSES", + SP->sb_total_x,total_x,viewport_x,cur_x, htop,hlength); #endif - if (SP->sb_total_y != (double)0) - XawScrollbarSetThumb( scrollVert, (double)vtop, (double)vlength ); - if (SP->sb_total_x != (double)0) - XawScrollbarSetThumb( scrollHoriz, (double)htop, (double)hlength ); - return(OK); + if (SP->sb_total_y != (PDC_SCROLLBAR_TYPE)0) + XawScrollbarSetThumb( scrollVert, (PDC_SCROLLBAR_TYPE)vtop, (PDC_SCROLLBAR_TYPE)vlength ); + if (SP->sb_total_x != (PDC_SCROLLBAR_TYPE)0) + XawScrollbarSetThumb( scrollHoriz, (PDC_SCROLLBAR_TYPE)htop, (PDC_SCROLLBAR_TYPE)hlength ); + return(OK); } /***********************************************************************/ #ifdef HAVE_PROTO diff --git a/x11/process/x11.c b/x11/process/x11.c index 851871d5..6fcd8cec 100644 --- a/x11/process/x11.c +++ b/x11/process/x11.c @@ -258,12 +258,6 @@ XtInputId *id; break; case CURSES_REFRESH_SCROLLBAR: /* request from curses draw scrollbar */ XCursesRefreshScrollbar(); -#if 0 - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); -#endif break; case CURSES_CURSOR: /* display cursor */ say("CURSES_CURSOR received from child\n"); @@ -590,8 +584,6 @@ printf("Width %d Height %d\n",XCURSESGEOMETRY.width,XCURSESGEOMETRY.height); XCursesGetIcon(); XtVaSetValues(topLevel, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, XtNminWidth,minwidth, XtNminHeight,minheight, XtNiconPixmap,icon_pixmap, @@ -612,6 +604,8 @@ printf("Width %d Height %d\n",XCURSESGEOMETRY.width,XCURSESGEOMETRY.height); scrollBox = XtVaCreateManagedWidget(XCursesProgramName,scrollBoxWidgetClass,topLevel, XtNwidth,XCursesWindowWidth+XCURSESSCROLLBARWIDTH, XtNheight,XCursesWindowHeight+XCURSESSCROLLBARWIDTH, + XtNwidthInc,XCursesFontWidth, + XtNheightInc,XCursesFontHeight, NULL); drawing = XtVaCreateManagedWidget(XCursesProgramName,boxWidgetClass, scrollBox, @@ -642,10 +636,12 @@ printf("Width %d Height %d\n",XCURSESGEOMETRY.width,XCURSESGEOMETRY.height); drawing = XtVaCreateManagedWidget(XCursesProgramName,boxWidgetClass,topLevel, XtNwidth,XCursesWindowWidth, XtNheight,XCursesWindowHeight, + XtNwidthInc,XCursesFontWidth, + XtNheightInc,XCursesFontHeight, NULL); } -#if 1 +#if 0 fprintf(stderr,"Width: %d Height: %d FontWidth: %d FontHeight: %d\n",XCursesWindowWidth+XCURSESSCROLLBARWIDTH, XCursesWindowHeight+XCURSESSCROLLBARWIDTH, XCursesFontWidth, diff --git a/x11/sb.c b/x11/sb.c index 7630201a..7ba3ada5 100644 --- a/x11/sb.c +++ b/x11/sb.c @@ -36,7 +36,7 @@ #endif #ifdef PDCDEBUG -char *rcsid_sb = "$Id: sb.c,v 1.1 2001/01/10 08:29:56 mark Exp $"; +char *rcsid_sb = "$Id: sb.c,v 1.2 2002/07/04 10:23:50 mark Exp $"; #endif /*man-start********************************************************************* @@ -98,9 +98,9 @@ int PDC_CDECL sb_init() /* sb_set_horz() Used to set horizontal scrollbar. - total = total number of lines - viewport = size of viewport in lines - cur = current line in total + total = total number of columns + viewport = size of viewport in columns + cur = current column in total */ #ifdef HAVE_PROTO int PDC_CDECL sb_set_horz(int total, int viewport, int cur)