scrolling list widgets - Motif
This is a discussion on scrolling list widgets - Motif ; I'm wondering if anyone can give me a definitive "Yes" or "No" to what I'm
trying to accomplish in Motif. I want to have two list widgets side-by-side and
scroll them as a single widget using a single vertical scrollbar. ...
-
scrolling list widgets
I'm wondering if anyone can give me a definitive "Yes" or "No" to what I'm
trying to accomplish in Motif. I want to have two list widgets side-by-side and
scroll them as a single widget using a single vertical scrollbar. Both list
widgets ALWAYS contain the same number of lines.
If I put the two list widgets into a scrolling window with XmAUTOMATIC, I run
into the size restriction problem, i.e., both list widgets may have hundreds or
thousands of lines, which must be scrolled. Rather than defining my own
scrolling window with XmAPPLICATION_DEFINED to circumvent the size restriction,
I want to investigate a simpler approach.
The simpler approach is to take advantage of the ScrolledList, which is already
XmAPPLICATION_DEFINED and can handle large numbers of lines. I want to put two
ScrolledList widgets side-by-side in a form widget but have only a single
vertical scrollbar for the right list-widget, and have this single scrollbar
drive the scrolling for the left list-widget. Hence, both ScrolledList widgets
appear to behave like a single scrolled window. The program below illustrates
exactly what I want to accomplish, and it works perfectly except for one flaw.
The flaw is that I cannot unmanage the left vertical scrollbar for the
ScrolledList and make it disappear. I cannot destroy the scrollbar either
because it must still exist to scroll the left ScrolledList widget in response
to events on the right scrollbar. If I could get this left vertical scrollbar
to disappear, I would have a simple solution for my application.
Interestingly, if the example program is changed from using ScrolledList
widgets to ScrolledText widgets, it works perfectly. That is, a ScrolledText
widget does allow its vertical scrollbar to be unmanaged (made invisible) and
yet still scroll the underlying text widget.
So is it or is it not possible to make the vertical scrollbar of a ScrolledList
invisible? And if so, how is it done?
================================================== =========================
#include
#include
#include
#include
#include
#include
#include
#include
#include
void CloseCB( Widget, void *, XmAnyCallbackStruct * ) {
exit( 0 );
}
Widget vertSB1, vertSB2;
void adjust() {
int SBvalue, SBsliderSize, SBincrement, SBpageIncrement;
XmScrollBarGetValues( vertSB2, &SBvalue, &SBsliderSize, &SBincrement, &SBpageIncrement );
// fprintf( stderr, "SBvalue:%d SBsliderSize:%d SBincrement:%d SBpageIncrement:%d\n",
// SBvalue, SBsliderSize, SBincrement, SBpageIncrement );
XmScrollBarSetValues( vertSB1, SBvalue, SBsliderSize, SBincrement, SBpageIncrement, True );
}
void ChangeDec( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNdecrementCallback\n" );
adjust();
}
void ChangeDrag( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNdragCallback\n" );
adjust();
}
void ChangeInc( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNincrementCallback\n" );
adjust();
}
void ChangePageDec( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNpageDecrementCallback\n" );
adjust();
}
void ChangePageInc( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNpageIncrementCallback\n" );
adjust();
}
void ChangeToBot( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNtoBottomCallback\n" );
adjust();
}
void ChangeToTop( Widget, void *, XmAnyCallbackStruct * ) {
// fprintf( stderr, "XmNtoTopCallback\n" );
adjust();
}
void singleSelection( Widget list, void *, XmListCallbackStruct *cb ) {
// fprintf( stderr, "singleSelection widget:0x%p cb:0x%p\n", list, cb );
XmListDeselectPos( list, cb->item_position );
}
int main( int argc, char *argv[] ) {
char helpString[256];
XtAppContext app;
Widget shell = XtVaAppInitialize( &app, "abc", NULL, 0, // create a root window
&argc, (char **)argv, NULL,
XmNkeyboardFocusPolicy, XmPOINTER, // make text field point (not click) sensitive
NULL );
Widget mainWindow = XtVaCreateWidget( "main", xmMainWindowWidgetClass, shell,
XmNshadowThickness, 0,
XmNshowSeparator, True,
XmNwidth, 500,
XmNheight, 400,
NULL );
// create menu-bar
Widget menuBar = XmCreateMenuBar( mainWindow, "menuBar", NULL, 0 );
// close button in menu bar
Widget close = XtVaCreateManagedWidget( "Close", xmCascadeButtonGadgetClass, menuBar,
XmNmnemonic, 'C',
XmNaccelerator, "AltC",
XmNborderWidth, 0,
NULL );
XtAddCallback( close, XmNactivateCallback, (XtCallbackProc)CloseCB, NULL );
// create work area
Widget workarea = XtVaCreateWidget( "workarea", xmFormWidgetClass, mainWindow,
XmNborderWidth, 0,
NULL );
// create cycle info section
Widget scroller1 = XtVaCreateWidget( "scroller1", xmScrolledWindowWidgetClass, workarea,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 50,
XmNbottomAttachment, XmATTACH_FORM,
XmNscrollingPolicy, XmAPPLICATION_DEFINED,
NULL );
Widget list1 = XtVaCreateManagedWidget( "list1", xmListWidgetClass, scroller1,
XmNborderWidth, 0,
XmNtopItemPosition, 1,
XmNitemCount, 0,
XmNhighlightOnEnter, False,
XmNselectionPolicy, XmMULTIPLE_SELECT,
NULL );
Widget scroller2 = XtVaCreateWidget( "scroller2", xmScrolledWindowWidgetClass, workarea,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 50,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNscrollingPolicy, XmAPPLICATION_DEFINED,
NULL );
Widget list2 = XtVaCreateManagedWidget( "list2", xmListWidgetClass, scroller2,
XmNborderWidth, 0,
XmNtopItemPosition, 1,
XmNselectionPolicy, XmSINGLE_SELECT,
NULL );
XtAddCallback( list2, XmNsingleSelectionCallback, (XtCallbackProc)singleSelection, NULL );
XmString itemString;
int i;
for ( i = 0; i < 40; i += 1 ) {
sprintf( helpString, "Line %d:", i);
itemString = XmStringCreateLtoR( helpString, XmSTRING_DEFAULT_CHARSET );
XmListAddItemUnselected( list1, itemString, i + 1 );
XmListAddItemUnselected( list2, itemString, i + 1 );
XmStringFree( itemString );
} // for
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNdecrementCallback, (XtCallbackProc)ChangeDec, NULL );
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNdragCallback, (XtCallbackProc)ChangeDrag, NULL );
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNincrementCallback, (XtCallbackProc)ChangeInc, NULL );
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNpageDecrementCallback, (XtCallbackProc)ChangePageDec, NULL );
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNpageIncrementCallback, (XtCallbackProc)ChangePageInc, NULL );
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNtoBottomCallback, (XtCallbackProc)ChangeToBot, NULL );
XtAddCallback( XtNameToWidget( scroller2, "VertScrollBar" ), XmNtoTopCallback, (XtCallbackProc)ChangeToTop, NULL );
XmMainWindowSetAreas( mainWindow, menuBar, (Widget)NULL, (Widget)NULL, (Widget)NULL, workarea );
XtManageChild( scroller1 );
XtManageChild( scroller2 );
XtManageChild( workarea );
XtManageChild( menuBar );
XtManageChild( mainWindow );
XtRealizeWidget( shell ); // realize shell
XtVaGetValues( scroller1,
XmNverticalScrollBar, &vertSB1,
NULL );
/*********************/
XtUnmanageChild( vertSB1 ); // make vertical scrollbar invisible
/*********************/
XtVaGetValues( scroller2,
XmNverticalScrollBar, &vertSB2,
NULL );
XtAppMainLoop( app );
}
// Local variables: //
// compile-command: "g++ test6.cc -L/opt/SUNWmotif/lib -lXm -lX11 -lXt" //
// End: //
-
Re: scrolling list widgets
Peter A. Buhr wrote:
> So is it or is it not possible to make the vertical scrollbar of a ScrolledList
> invisible? And if so, how is it done?
> /*********************/
> XtUnmanageChild( vertSB1 ); // make vertical scrollbar invisible
> /*********************/
XtSetMappedWhenManaged(vertSB1, False);