From: andrew7 <bd...@us...> - 2005-10-24 23:06:35
|
Update of /cvsroot/smartwin/SmartWin/include/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9952/include/io Modified Files: InDialog.h InDialogClasses.h Log Message: Add COLORREF and dates to variables that InDialog can handle. Check the menu option in the iolib sample. Index: InDialogClasses.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/io/InDialogClasses.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- InDialogClasses.h 15 Sep 2005 01:18:06 -0000 1.1 +++ InDialogClasses.h 24 Oct 2005 23:06:27 -0000 1.2 @@ -133,9 +133,14 @@ /// Constructor accepting vector< tstring > ChoiceString ( const vector< tstring > & inPossibleStrings, int inChossenIndex = 0 ) - : itsChoosenIndex( inChossenIndex ), - itsPossibleStrings( inPossibleStrings ) + : itsChoosenIndex( inChossenIndex ) +// , itsPossibleStrings( inPossibleStrings ) { + for ( unsigned int i= 0; i < inPossibleStrings.size(); i++ ) { + itsPossibleStrings.push_back( inPossibleStrings[i] ); + } + + } /// Constructor accepting "scissors|rock|paper" Index: InDialog.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/io/InDialog.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- InDialog.h 21 Sep 2005 10:58:20 -0000 1.4 +++ InDialog.h 24 Oct 2005 23:06:27 -0000 1.5 @@ -31,6 +31,7 @@ tstring str1= "hello"; PasswordString pass1; bool bool1= true; + COLORREF background= RGB( 20, 40, 80 ); ChoiceString cs( "scissors|rock|paper", 2 ); @@ -62,6 +63,7 @@ * - can optionally take a font in the constructor and size the fields accordingly. * - has tab control between input fields. * +* Need to add dates, colors */ class InDialog : public WidgetFactory<WidgetModalDialog, InDialog, ModalDialogWidget> @@ -102,6 +104,7 @@ itsChecks.clear(); itsCombos.clear(); itsPrompts.clear(); + itsColors.clear(); maxLabel= maxInputArea= Point( 0, 0); } @@ -112,14 +115,14 @@ * bool *, <br> * int *, float *, double *, <br> * tstring * <br> - * - /** The specially defined types (See InDialogClasses.h) are: <br> + * SYSTEMTIME * <br> + * The specially defined types (See InDialogClasses.h) are: <br> * PasswordString *, FileString *, BoundedLong *, ChoiceString * * * * The initial contents are displayed as a default, * and the input result is returned in the variable if the dialog is commited. - */ + **/ template < typename TypeIn > InDialog & add( const tstring & prompt, TypeIn val ) { @@ -166,7 +169,11 @@ cs.exStyle = 0; WidgetRichTextBox *wtb = createRichTextBox( cs ); wtb->setText( initalVal ); - if ( setFont ) wtb->setFont( itsFont ); + if ( setFont ) + wtb->setFont( itsFont ); + else + wtb->setFont( SystemFont ); + Point textSize; if ( initalVal.size() > 4 ) { textSize= wtb->getTextSize( initalVal );// The actual size of the initial value. @@ -192,7 +199,10 @@ cs.exStyle = 0; WidgetStatic *ws = createStatic( cs ); ws->setText( prompt ); - if ( setFont ) ws->setFont( itsFont ); + if ( setFont ) + ws->setFont( itsFont ); + else + ws->setFont( SystemFont ); itsStatics.push_back( ws ); maxLabel.maxOf( ws->getTextSize( prompt ) ); } @@ -205,7 +215,7 @@ stringstream ss; numtype * val= boost::any_cast<numtype *>( itsVariables.at( b ) ); ss << *val; - addPromptAndText( itsPrompts.at( b ), ss.str(), 0 ); + addPromptAndText( itsPrompts.at( b ), ss.str(), ES_NUMBER ); } @@ -279,9 +289,13 @@ // We calculate that the Combo needs enough space for 2 lines at least. WidgetComboBox *combo= createComboBox(); combo->addRemoveStyle( WS_TABSTOP, true ); - if ( setFont ) combo->setFont( itsFont ); + if ( setFont ) + combo->setFont( itsFont ); + else + combo->setFont( SystemFont ); - for ( unsigned int i= 0; i < valptr->itsPossibleStrings.size(); i++ ) { + int numChoices= (int)valptr->itsPossibleStrings.size(); + for ( int i= 0; i < numChoices; i++ ) { combo->addValue( valptr->itsPossibleStrings[ i ] ); Point OptionSize= combo->getTextSize( valptr->itsPossibleStrings[ i ] ); OptionSize.x += 24; // Account for \/ at right of combo box. @@ -302,7 +316,10 @@ WidgetCheckBox *check= createCheckBox(); check->setChecked( *val ); check->addRemoveStyle( BS_TOP | WS_TABSTOP, true ); // BS_LEFTTEXT BS_VCENTER | - if ( setFont ) check->setFont( itsFont ); + if ( setFont ) + check->setFont( itsFont ); + else + check->setFont( SystemFont ); itsIndicies.push_back( (int)itsChecks.size() ); itsChecks.push_back( check ); @@ -311,6 +328,39 @@ } + // SYSTEMTIME * + if ( itsVariables.at( b ).type() == typeid(SYSTEMTIME *) ) { + addPrompt( itsPrompts.at( b ) ); + SYSTEMTIME * st= boost::any_cast<SYSTEMTIME *>( itsVariables.at( b ) ); + + WidgetDateTimePicker *date= createDateTimePicker(); + date->setDateTime( *st ); + if ( setFont ) { + date->setFont( itsFont ); + } else { + date->setFont( SystemFont ); + } + + itsIndicies.push_back( (int)itsDates.size() ); + itsDates.push_back( date ); + maxInputArea.maxOf( itsStatics.at( b )->getTextSize( "12/12/1999" ) ); + } + + + // COLORREF * + if ( itsVariables.at( b ).type() == typeid(COLORREF *) ) { + // Put the starting color in itsColors + addPromptAndText( itsPrompts.at( b ), "", 0 ); + COLORREF * colorPtr= boost::any_cast<COLORREF *>( itsVariables.at( b ) ); + + WidgetRichTextBox *wtb = itsBoxes[ itsIndicies[ b ] ]; + wtb->setBackgroundColor( *colorPtr ); + itsColors.insert( pair< int, COLORREF >( b, *colorPtr ) ); + itsStatics.at( b )->onClicked( &InDialog::chooseColor ); + } + + + } // Add the Cancel and OK buttons. @@ -318,13 +368,19 @@ itsCancelBut->setText( "cancel" ); itsCancelBut->addRemoveStyle( WS_TABSTOP, true ); itsCancelBut->onClicked( &InDialog::OnCancel ); - if ( setFont ) itsCancelBut->setFont( itsFont ); + if ( setFont ) + itsCancelBut->setFont( itsFont ); + else + itsCancelBut->setFont( SystemFont ); itsOkBut= createButton(); itsOkBut->setText( "ok" ); itsOkBut->addRemoveStyle( WS_TABSTOP, true ); itsOkBut->onClicked( &InDialog::OnOk ); - if ( setFont ) itsOkBut->setFont( itsFont ); + if ( setFont ) + itsOkBut->setFont( itsFont ); + else + itsOkBut->setFont( SystemFont ); onClosing( &InDialog::isClosing ); @@ -337,7 +393,9 @@ return false; // Indicate that the focus was set. } - + + + // Bring up another dialog to accept a file name by browsing the file system. // ( used by FileString variables ) // @@ -387,6 +445,27 @@ } + // Use the WidgetChooseCOlor to get a color, + // Color the textbox, and store the color in itsColors + void chooseColor( WidgetStaticPtr prompt ) + { + WidgetChooseColor dlg = createChooseColor(); + WidgetChooseColor::ColorParams color = dlg.showDialog( true ); + if( color.userPressedOk() ) + { + for( unsigned b= 0; b < itsPrompts.size(); b++ ) { + if ( prompt == itsStatics[b] ) { + WidgetRichTextBox *wtb = itsBoxes[ itsIndicies[ b ] ]; + wtb->setBackgroundColor( color.getColor() ); + map< int, COLORREF>::iterator it = itsColors.find( b ); + if ( it != itsColors.end() ) { + it->second= color.getColor(); + } + } + } + } + + } void isResized( const WidgetSizedEventResult & sz ) @@ -459,6 +538,10 @@ itsChecks.at( itsIndicies[b] )->setBounds( pos_size ); } else + if ( itsVariables.at( b ).type() == typeid(SYSTEMTIME *) ) { + itsDates.at( itsIndicies[b] )->setBounds( pos_size ); + } else + if ( itsVariables.at( b ).type() == typeid(ChoiceString *) ) { itsCombos[ itsIndicies[b] ]->setBounds( pos_size.pos, Point( pos_size.size.x, pos_size.size.y * 5 ) ); @@ -622,6 +705,28 @@ valptr->itsChoosenIndex= itsCombos[ itsIndicies[b] ]->getSelectedIndex(); } + // SYSTEMTIME + if ( itsVariables.at( b ).type() == typeid(SYSTEMTIME *) ) { + SYSTEMTIME * st= boost::any_cast<SYSTEMTIME *>( itsVariables.at( b ) ); + *st= itsDates[ itsIndicies[b] ]->getDateTime(); + } + + + + + // COLORREF + if ( itsVariables.at( b ).type() == typeid(COLORREF *) ) { + COLORREF * colorPtr= boost::any_cast<COLORREF *>( itsVariables.at( b ) ); + map< int, COLORREF>::iterator it = itsColors.find( b ); + if ( it != itsColors.end() ) { + *colorPtr= it->second; + } + } + + + + + } endDialog( IDOK ); // The dialog will close. @@ -650,15 +755,20 @@ FontPtr itsFont; bool setFont; - vector< tstring > itsPrompts; // Before InitDialog - vector< boost::any > itsVariables; // Initial Value and final value - vector< int > itsIndicies; // Index into widget per variable type. + vector< tstring > itsPrompts; // Before InitDialog + vector< boost::any > itsVariables; // Initial Value and final value + vector< int > itsIndicies; // Index into widget per variable type. - vector< WidgetStaticPtr > itsStatics; // After InitDialog - vector< WidgetRichTextBox * > itsBoxes; // For numbers and strings - vector< WidgetCheckBox * > itsChecks; // For boolean - vector< WidgetComboBox * > itsCombos; // For ChoiceString - vector< WidgetButton * > itsButtons; // For FileString [...] file dialogs + // Each variable type has a static in the left column and + // a known widget on the right column. itsIndicies maps the instance + // of the variable to a particular widget in the vectors below. + + vector< WidgetStaticPtr > itsStatics; // After InitDialog + vector< WidgetRichTextBox * > itsBoxes; // For numbers and strings + vector< WidgetCheckBox * > itsChecks; // For boolean + vector< WidgetComboBox * > itsCombos; // For ChoiceString + vector< WidgetDateTimePicker * > itsDates; // For SYSTEMTIME + map< int, COLORREF> itsColors; WidgetButton *itsOkBut, *itsCancelBut; |