/***************************************************************************** # 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 "hideSomeTagTypes.h" #include #include #include #include #include "assert.h" #include "tagTypes.h" #include "handleWindowManagerDelete2.h" #include #include #include "consedParameters.h" #include "tagTypes.h" #include "consed.h" #include "hp_exception_kludge.h" hideSomeTagTypes* hideSomeTagTypes::pGlobalHideSomeTagTypes_ = 0; static void cbUserPushedOK( Widget wid, XtPointer pClientData, XtPointer pCallData ) { TRY_CATCH_WRAPPER( hideSomeTagTypes* pHideSomeTagTypes = (hideSomeTagTypes*) pClientData; pHideSomeTagTypes->userPushedOK(); ); } static void cbUserPushedCancel( Widget wid, XtPointer pClientData, XtPointer pCallData ) { TRY_CATCH_WRAPPER( hideSomeTagTypes* pHideSomeTagTypes = (hideSomeTagTypes*) pClientData; delete pHideSomeTagTypes; ); } hideSomeTagTypes :: hideSomeTagTypes( Widget widParentShell ) { if ( pGlobalHideSomeTagTypes_ ) { // raise window pGlobalHideSomeTagTypes_->raiseWindow(); // get rid of the memory we just allocated InputDataError ide; ide.setUserNotified(); throw ide; // throw exception } pGlobalHideSomeTagTypes_ = this; // create the scrolling list widPopupShell_ = XtVaCreatePopupShell( "hideSomeTagTypes", topLevelShellWidgetClass, widParentShell, XmNtitle, (char*) "Select Tag Types to Hide", XmNtransient, False, XmNdeleteResponse, XmDO_NOTHING, // XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE, NULL ); handleWindowManagerDelete2( widPopupShell_, cbUserPushedCancel, this ); Widget widMainWin = XtVaCreateManagedWidget( "mainwin", xmMainWindowWidgetClass, widPopupShell_, XmNancestorSensitive, True, NULL ); // // create the form widget // Widget widForm = XtVaCreateManagedWidget( "form", xmFormWidgetClass, widMainWin, XmNshadowThickness, 0, XmNborderWidth, 0, NULL ); widOKButton_ = XtVaCreateManagedWidget( "OK", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 35, XmNrightPosition, 45, NULL ); XtAddCallback( widOKButton_, XmNactivateCallback, cbUserPushedOK, 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, cbUserPushedCancel, this ); int nNumberOfTagTypes = tagTypes::pGetTagTypes()->nGetNumberOfTagTypes(); // nNumberOfTagTypes is perhaps longer than needed, but that is ok XmStringTable ppXtString = (XmStringTable) XtMalloc( nNumberOfTagTypes * sizeof( XmString ) ); XmStringTable ppXtStringOfSelectedItems = (XmStringTable) XtMalloc( nNumberOfTagTypes * sizeof( XmString ) ); // list items start with index 1 aTranslateTagTypeIndexFromListItemIndex_.reshape( nNumberOfTagTypes + 1, 0 ); //initial value int nNumberOfTagTypesDisplayed = 0; int nNumberOfSelectedTagTypes = 0; int nTagType; for( nTagType = 0; nTagType < nNumberOfTagTypes; ++nTagType ) { RWCString soTagType = tagTypes::pGetTagTypes()->soGetTagType( nTagType ); if ( soTagType == "tagsOverlap" ) continue; ppXtString[ nNumberOfTagTypesDisplayed ] = XmStringCreateLocalized( (char*) soTagType.data() ); if ( tagTypes::pGetTagTypes()->bAreTagsOfThisTypeHidden( soTagType ) ) { ppXtStringOfSelectedItems[ nNumberOfSelectedTagTypes ] = ppXtString[ nNumberOfTagTypesDisplayed ]; ++nNumberOfSelectedTagTypes; } ++nNumberOfTagTypesDisplayed; aTranslateTagTypeIndexFromListItemIndex_[ nNumberOfTagTypesDisplayed ] = nTagType; } // subtract one because of tagsOverlap assert( nNumberOfTagTypesDisplayed == ( nNumberOfTagTypes - 1 )); int nArgs; Arg aArg[50]; nArgs = 0; XtSetArg( aArg[nArgs], XmNbottomAttachment, XmATTACH_WIDGET ); ++nArgs; XtSetArg( aArg[nArgs], XmNbottomWidget, widOKButton_ ); ++nArgs; XtSetArg( aArg[nArgs], XmNtopAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNleftAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNrightAttachment, XmATTACH_FORM ); ++nArgs; XtSetArg( aArg[nArgs], XmNvisibleItemCount, 35 ); ++nArgs; XtSetArg( aArg[nArgs], XmNtraversalOn, True ); ++nArgs; XtSetArg( aArg[nArgs], XmNitems, ppXtString ); ++nArgs; XtSetArg( aArg[nArgs], XmNitemCount, nNumberOfTagTypesDisplayed ); ++nArgs; XtSetArg( aArg[nArgs], XmNselectionPolicy, XmMULTIPLE_SELECT ); ++nArgs; XtSetArg( aArg[nArgs], XmNselectedItemCount, nNumberOfSelectedTagTypes ); ++nArgs; XtSetArg( aArg[nArgs], XmNselectedItems, ppXtStringOfSelectedItems ); ++nArgs; widTagTypesList_ = XmCreateScrolledList( widForm, "tagTypes", aArg, nArgs ); XtManageChild( widTagTypesList_ ); XtPopup( widPopupShell_, XtGrabNone ); XmProcessTraversal( widTagTypesList_, XmTRAVERSE_CURRENT ); for( nTagType = 0; nTagType < nNumberOfTagTypesDisplayed; ++nTagType ) { XmStringFree( ppXtString[ nTagType ] ); } XtFree( (char*) ppXtString ); XtFree( (char*) ppXtStringOfSelectedItems ); } hideSomeTagTypes :: ~hideSomeTagTypes() { XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); // flag that it is ok to create a hideSomeTagTypes window again pGlobalHideSomeTagTypes_ = NULL; } void hideSomeTagTypes :: userPushedOK() { int* pPositionList; int nNumberOfSelectedItems; if ( !XmListGetSelectedPos( widTagTypesList_, &pPositionList, &nNumberOfSelectedItems ) ) { nNumberOfSelectedItems = 0; } // add the selected items to the list in the tagTypes class RWCString soListOfTagTypes; for( int nSelected = 0; nSelected < nNumberOfSelectedItems; ++nSelected ) { int nPositionInDisplayedList = pPositionList[ nSelected ]; int nTagType = aTranslateTagTypeIndexFromListItemIndex_[ nPositionInDisplayedList ]; RWCString soTagType = tagTypes::pGetTagTypes()->soGetTagType( nTagType ); soListOfTagTypes += soTagType; soListOfTagTypes += " "; } tagTypes::pGetTagTypes()->setTagTypesToHide( (char*) soListOfTagTypes.data() ); if ( !tagTypes::pGetTagTypes()->bCurrentlyShowAllTagTypes_ ) ConsEd::pGetConsEd()->refreshAllContigWinsAndAllTeditors(); delete this; } void hideSomeTagTypes :: raiseWindow() { XtMapWidget( widPopupShell_ ); XRaiseWindow( XtDisplay( widPopupShell_ ), XtWindow( widPopupShell_ ) ); }