/***************************************************************************** # 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 "guiAssemblyViewShowTags.h" #include #include #include #include #include #include #include #include "tagTypes.h" #include #include #include "handleWindowManagerDelete2.h" #include "popupErrorMessage.h" #include "hp_exception_kludge.h" #include "assemblyView.h" #include "breakIntoShorterLines.h" #include "bIsNumericMaybeWithWhitespace.h" const int nInitialScrolledWindowWidth = 270; const int nInitialScrollWindowHeight = 420; static void cbToggleButtonValueChanged( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiAssemblyViewShowTags* pGuiAssemblyViewShowTags = (guiAssemblyViewShowTags*) pClientData; pGuiAssemblyViewShowTags->toggleButtonValueChanged( wid ); } static void cbResizeWindow( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiAssemblyViewShowTags* pGuiAssemblyViewShowTags = (guiAssemblyViewShowTags*) pClientData; TRY_CATCH_WRAPPER( pGuiAssemblyViewShowTags->resizeWindow() ); } static void cbUserPushedDismiss( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiAssemblyViewShowTags* pGuiAssemblyViewShowTags = (guiAssemblyViewShowTags*) pClientData; TRY_CATCH_WRAPPER( delete pGuiAssemblyViewShowTags ); } static void cbUserPushedOK( Widget wid, XtPointer pClientData, XtPointer pCallData ) { guiAssemblyViewShowTags* pGuiAssemblyViewShowTags = (guiAssemblyViewShowTags*) pClientData; TRY_CATCH_WRAPPER( pGuiAssemblyViewShowTags->userPushedOK() ); } void guiAssemblyViewShowTags :: createWindow() { widPopupShell_ = XtVaCreatePopupShell( "guiAssemblyViewShowTags", topLevelShellWidgetClass, pAssemblyView_->widPopupShell_, XmNtitle, (char*) "Which Tag Types To Show In Assembly View", XmNtransient, False, XmNdeleteResponse, XmDO_NOTHING, NULL ); handleWindowManagerDelete2( widPopupShell_, cbUserPushedDismiss, this ); Widget widForm = XtVaCreateManagedWidget( "form", xmFormWidgetClass, widPopupShell_, XmNancestorSensitive, True, NULL ); // add text box at the top for instructions RWCString soInstructions = "Click to select the tags to display in Assembly View. There are "; soInstructions += RWCString( (long) pCP->nAssemblyViewNumberOfRowsOfTags_ ); soInstructions += " rows of tags below each scaffold. You must specify, for each tag type, which row, from 0 to "; soInstructions += RWCString( (long) (pCP->nAssemblyViewNumberOfRowsOfTags_ - 1 ) ); soInstructions += ", you want it displayed on. When done, click \"OK\""; const int nMaxCharsPerLine = 50; breakIntoShorterLines( soInstructions, nMaxCharsPerLine ); Widget widInstructions = XtVaCreateManagedWidget( "instructions", xmTextWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNleftAttachment, XmATTACH_WIDGET, XmNrightAttachment, XmATTACH_WIDGET, XmNcursorPositionVisible, False, XmNeditable, False, XmNeditMode, XmMULTI_LINE_EDIT, XmNrows, 4, XmNcolumns, 50, XmNvalue, soInstructions.data(), NULL ); // now add buttons at the bottom--OK and Dismiss widDismiss_ = XtVaCreateManagedWidget( "Dismiss", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 70, XmNtraversalOn, False, NULL ); XtAddCallback( widDismiss_, XmNactivateCallback, cbUserPushedDismiss, this ); widOK_ = XtVaCreateManagedWidget( "OK", xmPushButtonWidgetClass, widForm, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 10, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 30, XmNtraversalOn, False, NULL ); XtAddCallback( widOK_, XmNactivateCallback, cbUserPushedOK, this ); // between the text at the top and bottom, add the scrolled window with the // rowcol widget: Widget widScrolledWindow = XtVaCreateManagedWidget( "scrolled", xmScrolledWindowWidgetClass, widForm, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, widInstructions, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, widOK_, XmNbottomOffset, 20, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNscrollingPolicy, XmAUTOMATIC, XmNscrollBarDisplayPolicy, XmSTATIC, XmNwidth, nInitialScrolledWindowWidth, XmNheight, nInitialScrollWindowHeight, NULL ); widRowCol_ = XtVaCreateManagedWidget( "rowcol", xmRowColumnWidgetClass, widScrolledWindow, XmNorientation, XmVERTICAL, XmNnumColumns, 1, XmNpacking, XmPACK_COLUMN, NULL ); XmScrolledWindowSetAreas( widScrolledWindow, (Widget) NULL, (Widget) NULL, widRowCol_ ); XtVaGetValues( widScrolledWindow, XmNclipWindow, &widClipWindow_, NULL ); XtAddCallback( widClipWindow_, XmNresizeCallback, (XtCallbackProc) cbResizeWindow, this ); // now we load up the rowcol widget with the tag types. For // each tag type, create a form. XmString xmsEmpty = XmStringCreateLocalized( "" ); pixValueChangedBackgroundColor_ = ulGetXColorForColorName( "red" ); tagTypes* pTagTypes = tagTypes::pGetTagTypes(); for( int nTagType = 0; nTagType < pTagTypes->nGetNumberOfTagTypes(); ++nTagType ) { RWCString soTagType = pTagTypes->soGetTagType( nTagType ); // Should this tag type be shown (by default) in Assembly View? assemblyViewTagTypeAndLine aVTTLDummy( soTagType, 0 ); int nIndexOfDisplayedTagType = pCP->aAssemblyViewDisplayTheseTagTypes_.indexFast( &aVTTLDummy ); bool bShowInAssemblyView = ( nIndexOfDisplayedTagType == RW_NPOS ) ? false : true; Widget widFormForOneTagType = XtVaCreateManagedWidget( "tagTypeForm", xmFormWidgetClass, widRowCol_, XmNmarginHeight, 0, XmNmarginWidth, 0, XmNshadowThickness, 0, NULL ); if ( nTagType == 0 ) { XtVaGetValues( widFormForOneTagType, XmNbackground, &pixValueUnchangedBackgroundColor_, NULL ); } if ( bShowInAssemblyView ) { XtVaSetValues( widFormForOneTagType, XmNbackground, &pixValueChangedBackgroundColor_, NULL ); } Widget widToggleButton = XtVaCreateManagedWidget( "toggleButton", xmToggleButtonWidgetClass, widFormForOneTagType, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 10, XmNbottomAttachment, XmATTACH_FORM, XmNmarginHeight, 0, XmNmarginWidth, 0, XmNshadowThickness, 0, XmNlabelString, xmsEmpty, XmNset, bShowInAssemblyView, NULL ); XtAddCallback( widToggleButton, XmNvalueChangedCallback, cbToggleButtonValueChanged, this ); int nLine; if ( bShowInAssemblyView ) { nLine = pCP->aAssemblyViewDisplayTheseTagTypes_[ nIndexOfDisplayedTagType ]->nLine_; } else nLine = 0; RWCString soLine( (long) nLine ); Widget widLineNumber = XtVaCreateManagedWidget( "lineNumber", xmTextFieldWidgetClass, widFormForOneTagType, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, widToggleButton, XmNcolumns, 2, XmNvalue, soLine.data(), NULL ); aToggleButtons_.insert( widToggleButton ); aLineNumberTextFields_.insert( widLineNumber ); aFormsForToggleButtons_.insert( widFormForOneTagType ); Widget widTagTypeName = XtVaCreateManagedWidget( soTagType.data(), xmLabelWidgetClass, widFormForOneTagType, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, widLineNumber, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL ); } XtPopup( widPopupShell_, XtGrabNone ); bWindowUp_ = true; } guiAssemblyViewShowTags :: ~guiAssemblyViewShowTags() { XtRemoveCallback( widClipWindow_, XmNresizeCallback, (XtCallbackProc) cbResizeWindow, this ); XtPopdown( widPopupShell_ ); XtDestroyWidget( widPopupShell_ ); } void guiAssemblyViewShowTags :: userPushedOK() { // do checks int nTagType; for( nTagType = 0; nTagType < aLineNumberTextFields_.length(); ++nTagType ) { int nLine; RWCString soLine = XmTextFieldGetString( aLineNumberTextFields_[ nTagType ] ); if ( !bIsNumericMaybeWithWhitespace( soLine, nLine ) ) { RWCString soError = "tag type: "; soError += tagTypes::pGetTagTypes()->soGetTagType( nTagType ); soError += " has a line number: "; soError += soLine; soError += " which is not numeric. Please correct it."; popupErrorMessage( soError ); return; } // check that nLine is within range if ( ! ( 0 <= nLine && nLine < pCP->nAssemblyViewNumberOfRowsOfTags_ ) ) { RWCString soError = "tag type: "; soError += tagTypes::pGetTagTypes()->soGetTagType( nTagType ); soError += " has a line number: "; soError += soLine; soError += " which is not between 0 and "; soError += RWCString( (long) pCP->nAssemblyViewNumberOfRowsOfTags_ - 1 ); soError += " but it should be."; popupErrorMessage( soError ); return; } } // if reached here, passed all checks pCP->aAssemblyViewDisplayTheseTagTypes_.clearAndDestroy(); for( nTagType = 0; nTagType < aToggleButtons_.length(); ++nTagType ) { if ( XmToggleButtonGetState( aToggleButtons_[ nTagType ] ) == True ) { RWCString soLine = XmTextFieldGetString( aLineNumberTextFields_[ nTagType ] ); int nLine; assert( bIsNumericMaybeWithWhitespace( soLine, nLine ) ); assemblyViewTagTypeAndLine* pAVTTAL = new assemblyViewTagTypeAndLine( tagTypes::pGetTagTypes()->soGetTagType( nTagType ), nLine ); pCP->aAssemblyViewDisplayTheseTagTypes_.insert( pAVTTAL ); } } pCP->aAssemblyViewDisplayTheseTagTypes_.resort(); pAssemblyView_->drawEverything( true, // bCalculatePositions true ); // bFirstErase } void guiAssemblyViewShowTags :: resizeWindow() { if ( !bWindowUp_ ) return; XtVaGetValues( widClipWindow_, XmNwidth, &dimClipWindowWidth_, XmNheight, &dimClipWindowHeight_, NULL ); // // initial event before the window is up // if ( dimClipWindowHeight_ == 0 ) return; XtVaSetValues( widRowCol_, XmNwidth, dimClipWindowWidth_, XmNheight, dimClipWindowHeight_, NULL ); } void guiAssemblyViewShowTags :: toggleButtonValueChanged( Widget widToggleButton ) { if ( !bWindowUp_ ) return; bool bSet = ( XmToggleButtonGetState( widToggleButton ) == True ); // turn on or off highlighting so the user can easily see which // tags are to be shown in assembly view // first must find the form: int nIndex = aToggleButtons_.index( widToggleButton ); assert( nIndex != RW_NPOS ); Widget widForm = aFormsForToggleButtons_[ nIndex ]; if ( bSet ) { XtVaSetValues( widForm, XmNbackground, &pixValueChangedBackgroundColor_, NULL ); } else { XtVaSetValues( widForm, XmNbackground, &pixValueUnchangedBackgroundColor_, NULL ); } }