/***************************************************************************** # Copyright (C) 1994-2008 by David Gordon. # All rights reserved. # # This software is part of a beta-test version of the Consed/Autofinish # package. It should not be redistributed or # used for any commercial purpose, including commercially funded # sequencing, without written permission from the author and the # University of Washington. # # This software is provided ``AS IS'' and any express or implied # warranties, including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose, are disclaimed. # In no event shall the authors or the University of Washington be # liable for any direct, indirect, incidental, special, exemplary, or # consequential damages (including, but not limited to, procurement of # substitute goods or services; loss of use, data, or profits; or # business interruption) however caused and on any theory of liability, # whether in contract, strict liability, or tort (including negligence # or otherwise) arising in any way out of the use of this software, even # if advised of the possibility of such damage. # # Building Consed from source is error prone and not simple which is # why I provide executables. Due to time limitations I cannot # provide any assistance in building Consed. Even if you do not # modify the source, you may introduce errors due to using a # different version of the compiler, a different version of motif, # different versions of other libraries than I used, etc. For this # reason, if you discover Consed bugs, I can only offer help with # those bugs if you first reproduce those bugs with an executable # provided by me--not an executable you have built. # # Modifying Consed is also difficult. Although Consed is modular, # some modules are used by many other modules. Thus making a change # in one place can have unforeseen effects on many other features. # It may takes months for you to notice these other side-effects # which may not seen connected at all. It is not feasable for me to # provide help with modifying Consed sources because of the # potentially huge amount of time involved. # #*****************************************************************************/ #include "guiAskUserToSelectReadListOptions.h" #include #include #include #include #include "guiapp.h" #include "rwcstring.h" #include #include "handleWindowManagerDelete.h" #include "consedParameters.h" #include "rwctokenizer.h" #include #include using namespace std; static void cbGetReadListOptionsOKButtonPressed( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiAskUserToSelectReadListOptions* pAsk = (guiAskUserToSelectReadListOptions*)pClientData; pAsk->bBlockApplication_ = false; } static void cbGetReadListOptionsCancelButtonPressed( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiAskUserToSelectReadListOptions* pAsk = (guiAskUserToSelectReadListOptions*)pClientData; pAsk->bUserPushedCancel_ = true; pAsk->bBlockApplication_ = false; } guiAskUserToSelectReadListOptions :: ~guiAskUserToSelectReadListOptions() { XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); } void guiAskUserToSelectReadListOptions :: popupBoxAndWaitForUserToSelectReadListOptions( const RWCString soReadName, RWCString& soReadListOptions, bool& bUserPushedCancel ) { RWCString soTitle = "select read list options for read " + soReadName; widPopupShell_ = XtVaCreatePopupShell( "select read list", topLevelShellWidgetClass, GuiApp::pGetGuiApp()->widGetTopLevel(), XmNdeleteResponse, XmDO_NOTHING, XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE, XmNtitle, soTitle.data(), NULL ); // I tried to allow the window manager to call // cbGetReadListOptionsCancelButtonPressed to close the window but // cbGetReadListOptionsCancelButtonPressed requires that arguments // be correctly set and I didn't figure out how to do that with // handleWindowManagerDelete2. // In short, it just isn't that easy. handleWindowManagerDelete( widPopupShell_ ); Widget widForm = XtVaCreateManagedWidget( "form", xmFormWidgetClass, widPopupShell_, XmNshadowThickness, 0, XmNborderWidth, 0, NULL ); XmString xmsWarningMessage = XmStringCreateLtoR( "YOU MUST RESPOND TO THIS\nBEFORE USING ANY OTHER WINDOW", XmFONTLIST_DEFAULT_TAG ); Widget widWarningLabel = XtVaCreateManagedWidget( "WarningLabel", xmLabelWidgetClass, widForm, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNalignment, XmALIGNMENT_CENTER, XmNlabelString, xmsWarningMessage, NULL ); XmStringFree( xmsWarningMessage ); widOKButton_ = XtVaCreateManagedWidget( "OK", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 35, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 45, NULL ); XtAddCallback( widOKButton_, XmNactivateCallback, (XtCallbackProc) cbGetReadListOptionsOKButtonPressed, this ); widCancelButton_ = XtVaCreateManagedWidget( "Cancel", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 55, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 65, NULL ); XtAddCallback( widCancelButton_, XmNactivateCallback, (XtCallbackProc) cbGetReadListOptionsCancelButtonPressed, this ); int nNumberOfReadListOptions = aListOfOptions_.length(); XmStringTable ppXtString = (XmStringTable) XtMalloc( nNumberOfReadListOptions * sizeof( XmString ) ); int nReadListOption; for( nReadListOption = 0; nReadListOption < nNumberOfReadListOptions; ++nReadListOption ) { RWCString soOneOption = aListOfOptions_[ nReadListOption ]; ppXtString[ nReadListOption ] = XmStringCreateLocalized( (char*) soOneOption.data() ); } int nArgs; Arg aArg[100]; nArgs = 0; XtSetArg( aArg[nArgs], XmNbottomAttachment, XmATTACH_WIDGET ); ++nArgs; XtSetArg( aArg[nArgs], XmNbottomWidget, widOKButton_ ); ++nArgs; XtSetArg( aArg[nArgs], XmNtopAttachment, XmATTACH_WIDGET ); ++nArgs; XtSetArg( aArg[nArgs], XmNtopWidget, widWarningLabel ); ++nArgs; XtSetArg( aArg[nArgs], XmNleftAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNrightAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNvisibleItemCount, 20 ); ++nArgs; XtSetArg( aArg[nArgs], XmNtraversalOn, True ); ++nArgs; XtSetArg( aArg[nArgs], XmNitems, ppXtString ); ++nArgs; XtSetArg( aArg[nArgs], XmNitemCount, nNumberOfReadListOptions ); ++nArgs; XtSetArg( aArg[nArgs], XmNselectionPolicy, XmMULTIPLE_SELECT ); ++nArgs; widScrolledListOfReadListOptions_ = XmCreateScrolledList( widForm, "scrolled list", aArg, nArgs ); XtManageChild( widScrolledListOfReadListOptions_ ); setOptionsTheUserSetLastTime(); XtPopup( widPopupShell_, XtGrabNone ); // free all the memory used for the array of XmStrings for( nReadListOption = 0; nReadListOption < nNumberOfReadListOptions; ++nReadListOption ) { XmStringFree( ppXtString[ nReadListOption ] ); } XtFree( (char*) ppXtString ); // wait until user answers the question--don't let him do anything else! bUserPushedCancel_ = false; // will be set by cancel callback bBlockApplication_ = true; // xt callback must clear XEvent xevent; while( bBlockApplication_ ) { XtAppNextEvent( GuiApp::pGetGuiApp()->ctxGetAppContext(), &xevent); XtDispatchEvent( &xevent); } if ( bUserPushedCancel_ ) { bUserPushedCancel = true; return; } bUserPushedCancel = false; // find out which read list options were selected by the user int* pPositionList; int nNumberOfSelectedItems; if ( !XmListGetSelectedPos( widScrolledListOfReadListOptions_, &pPositionList, &nNumberOfSelectedItems ) ) { nNumberOfSelectedItems = 0; } consedParameters::pGetConsedParameters()->soSavedReadListOptions_ = ""; soReadListOptions = ""; for( int nSelected = 0; nSelected < nNumberOfSelectedItems; ++nSelected ) { int nPositionInDisplayedList = pPositionList[ nSelected ]; // nPositionInDisplayedList starts at 1 while aListOfOptions_ starts // at zero RWCString soOneSelectedItem = aListOfOptions_[ nPositionInDisplayedList - 1 ]; if ( nSelected != 0 ) { soReadListOptions += " "; consedParameters::pGetConsedParameters()->soSavedReadListOptions_ += " "; } soReadListOptions += soOneSelectedItem; consedParameters::pGetConsedParameters()->soSavedReadListOptions_ += RWCString( (long) nPositionInDisplayedList ); } } guiAskUserToSelectReadListOptions :: guiAskUserToSelectReadListOptions() { aListOfOptions_.clear(); RWCTokenizer tokReadOption( consedParameters::pGetConsedParameters()->soListOfOptionalWordsToSaveInListOfReadNames_ ); RWCString soOneReadOption; while( ! ( soOneReadOption = tokReadOption() ).isNull() ) { aListOfOptions_.insert( soOneReadOption ); } } void guiAskUserToSelectReadListOptions :: setOptionsTheUserSetLastTime() { if ( consedParameters::pGetConsedParameters()->soSavedReadListOptions_.isNull() ) return; RWCTokenizer tok( consedParameters::pGetConsedParameters()->soSavedReadListOptions_ ); RWCString soNumber; while( ! (soNumber = tok() ).isNull() ) { int nListIndex = atoi( (char*) soNumber.data() ); XmListSelectPos( widScrolledListOfReadListOptions_, nListIndex, False ); // do not call selection callback } }