Tag: cws_src680_qiq User: fs Date: 06/05/11 03:39:41 Modified: /dba/dbaccess/source/ui/dlg/ sqlmessage.cxx
Log: #51143# some refactoring - should now display the More button only when (halfway) needed; should now also allow for message boxes displaying one text only File Changes: Directory: /dba/dbaccess/source/ui/dlg/ ======================================= File [changed]: sqlmessage.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/dlg/sqlmessage.cxx?r1=1.20.118.1&r2=1.20.118.2 Delta lines: +165 -232 ----------------------- --- sqlmessage.cxx 10 May 2006 10:59:32 -0000 1.20.118.1 +++ sqlmessage.cxx 11 May 2006 10:39:37 -0000 1.20.118.2 @@ -4,9 +4,9 @@ * * $RCSfile: sqlmessage.cxx,v $ * - * $Revision: 1.20.118.1 $ + * $Revision: 1.20.118.2 $ * - * last change: $Author: fs $ $Date: 2006/05/10 10:59:32 $ + * last change: $Author: fs $ $Date: 2006/05/11 10:39:37 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -84,8 +84,7 @@ #define DLG_LIMIT 320 // max dialog size #define BTN_HEIGHT 14 #define BTN_WIDTH 50 -#define BORDER_HEIGHT 6 // default distance control - dialog -#define BORDER_WIDTH 6 // default distance control - dialog +#define OUTER_MARGIN 6 using namespace dbtools; using namespace com::sun::star::uno; @@ -286,43 +285,109 @@ } //------------------------------------------------------------------------------ -void OSQLMessageBox::Construct(const UniString& rTitle, - const UniString& rMessage, - WinBits nStyle, - MessageType _eImage) +namespace { - // Changed as per BugID 79541 Branding/Configuration - ::utl::ConfigManager* pMgr = ::utl::ConfigManager::GetConfigManager(); - Any aProductName = pMgr->GetDirectConfigProperty(::utl::ConfigManager::PRODUCTNAME); + ::rtl::OUString lcl_getProductName() + { ::rtl::OUString sProductName; - aProductName >>= sProductName; + ::utl::ConfigManager* pConfigManager = ::utl::ConfigManager::GetConfigManager(); + OSL_ENSURE( pConfigManager, "lcl_getProductName: no config manager!" ); + OSL_VERIFY( pConfigManager->GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ) >>= sProductName ); + return sProductName; + } - String aTitle = sProductName; - aTitle.AppendAscii(" Base"); - SetText(aTitle); - SetSizePixel(LogicToPixel(Size(220, 30),MAP_APPFONT)); + void lcl_positionInAppFont( const Window& _rParent, Window& _rChild, long _X, long _Y, long _Width, long _Height ) + { + Point aPos = _rParent.LogicToPixel( Point( _X, _Y ), MAP_APPFONT ); + Size aSize = _rParent.LogicToPixel( Size( _Width, _Height ), MAP_APPFONT ); + _rChild.SetPosSizePixel( aPos, aSize ); + } - m_aInfoImage.SetPosSizePixel(LogicToPixel(Point(6, 6),MAP_APPFONT), - LogicToPixel(Size(20, 20),MAP_APPFONT)); - m_aInfoImage.Show(); + void lcl_addButton( ButtonDialog& _rDialog, StandardButtonType _eType, bool _bDefault ) + { + USHORT nButtonID = 0; + switch ( _eType ) + { + case BUTTON_YES: nButtonID = BUTTONID_YES; break; + case BUTTON_NO: nButtonID = BUTTONID_NO; break; + case BUTTON_OK: nButtonID = BUTTONID_OK; break; + case BUTTON_CANCEL: nButtonID = BUTTONID_CANCEL; break; + case BUTTON_RETRY: nButtonID = BUTTONID_RETRY; break; + default: + OSL_ENSURE( false, "lcl_addButton: invalid button id!" ); + break; + } + _rDialog.AddButton( _eType, nButtonID, _bDefault ? BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_FOCUSBUTTON : 0 ); + } +} + +//------------------------------------------------------------------------------ +void OSQLMessageBox::impl_positionControls() +{ + // one or two texts to display? + String sPrimary, sSecondary; + if ( m_aExceptionInfo.isKindOf( SQLExceptionInfo::SQL_CONTEXT ) ) + { + SQLContext aContext; + OSL_VERIFY( m_aExceptionInfo.get() >>= aContext ); + sPrimary = aContext.Message; + sSecondary = aContext.Details; + } + else + { + SQLException aError; + OSL_VERIFY( m_aExceptionInfo.get() >>= aError ); + sPrimary = aError.Message; + + if ( aError.NextException >>= aError ) + sSecondary = aError.Message; + } + +#define DIALOG_WIDTH 220 +#define TEXT_POS_X 45 - m_aTitle.SetPosSizePixel(LogicToPixel(Point(45, 6),MAP_APPFONT), - LogicToPixel(Size(169, 20),MAP_APPFONT)); + // image + lcl_positionInAppFont( *this, m_aInfoImage, OUTER_MARGIN, OUTER_MARGIN, 20, 20 ); + m_aInfoImage.Show(); + // primary text + lcl_positionInAppFont( *this, m_aTitle, TEXT_POS_X, OUTER_MARGIN, DIALOG_WIDTH - TEXT_POS_X - 2 * OUTER_MARGIN, 20 ); + m_aTitle.SetText( sPrimary ); m_aTitle.Show(); + // secondary text (if applicable) m_aMessage.SetStyle( m_aMessage.GetStyle() | WB_NOLABEL ); - m_aMessage.SetPosSizePixel(LogicToPixel(Point(45, 29),MAP_APPFONT), - LogicToPixel(Size(169, 1),MAP_APPFONT)); - m_aMessage.Show(); + m_aMessage.SetText( sSecondary ); - m_pInfoButton = NULL; + lcl_positionInAppFont( *this, m_aMessage, TEXT_POS_X, OUTER_MARGIN + 20 + 3, DIALOG_WIDTH - TEXT_POS_X - 2 * OUTER_MARGIN, 8 ); + Rectangle aSecondaryRect( m_aMessage.GetPosPixel(), m_aMessage.GetSizePixel() ); - // Image festlegen + // determine which space the secondary text would occupy + if ( sSecondary.Len() ) + aSecondaryRect = GetTextRect( aSecondaryRect, sSecondary, TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE | TEXT_DRAW_LEFT ); + else + aSecondaryRect.Bottom() = aSecondaryRect.Top(); + + // adjust secondary control height accordingly + m_aMessage.SetSizePixel( aSecondaryRect.GetSize() ); + m_aMessage.Show( aSecondaryRect.GetHeight() > 0 ); + + // adjust dialog size accordingly + Size aBorderSize = LogicToPixel( Size( OUTER_MARGIN, OUTER_MARGIN ), MAP_APPFONT ); + Size aDialogSize( LogicToPixel( Size( DIALOG_WIDTH, 30 ), MAP_APPFONT ) ); + aDialogSize.Height() = aSecondaryRect.Bottom() + aBorderSize.Height() * 2; + + SetSizePixel( aDialogSize ); + SetPageSizePixel( aDialogSize ); +} + +//------------------------------------------------------------------------------ +void OSQLMessageBox::impl_initImage( MessageType _eImage ) +{ switch (_eImage) { default: - DBG_ERROR( "OSQLMessageBox::Construct: unsupported image type!" ); + DBG_ERROR( "OSQLMessageBox::impl_initImage: unsupported image type!" ); case Info: m_aInfoImage.SetImage(InfoBox::GetStandardImage()); @@ -337,202 +402,82 @@ m_aInfoImage.SetImage(QueryBox::GetStandardImage()); break; } +} - // Title setzen - m_aTitle.SetText(rTitle); - - // Ermitteln der Hoehe des Textfeldes und des Dialogs - Size aBorderSize = LogicToPixel(Size(BORDER_WIDTH, BORDER_HEIGHT),MAP_APPFONT); - Rectangle aDlgRect(GetPosPixel(),GetSizePixel()); - Rectangle aMessageRect(m_aMessage.GetPosPixel(),m_aMessage.GetSizePixel()); - Rectangle aTextRect = - GetTextRect(aMessageRect,rMessage, TEXT_DRAW_WORDBREAK | - TEXT_DRAW_MULTILINE | TEXT_DRAW_LEFT); - - long nHText = aTextRect.Bottom() > aMessageRect.Bottom() ? aTextRect.Bottom() - aMessageRect.Bottom() : 0; - - aDlgRect.Bottom() += nHText + 2 * aBorderSize.Height(); - aMessageRect.Bottom() += nHText; - - // Dialog anpassen - SetSizePixel(aDlgRect.GetSize()); - SetPageSizePixel(aDlgRect.GetSize()); - - // Message Text anpassen und setzen - m_aMessage.SetSizePixel(aMessageRect.GetSize()); - m_aMessage.SetText(rMessage); - - // Buttons anlegen - long nBtnCount = 0; - sal_Bool bHelp = sal_False; //aHelpBtn.IsVisible(); - - sal_uInt16 nDefId = 0; - - if (nStyle & WB_DEF_YES) - nDefId = BUTTONID_YES; - else if (nStyle & WB_DEF_NO) - nDefId = BUTTONID_NO; - else if (nStyle & WB_DEF_CANCEL) - nDefId = BUTTONID_CANCEL; - else if (nStyle & WB_DEF_RETRY) - nDefId = BUTTONID_RETRY; - else - nDefId = BUTTONID_OK; - - if (nStyle & WB_YES_NO_CANCEL) - { - if (nStyle & WB_DEF_YES) - AddButton(BUTTON_YES,BUTTONID_YES,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_YES,BUTTONID_YES,0); - - if (nStyle & WB_DEF_NO) - AddButton(BUTTON_NO,BUTTONID_NO,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_NO,BUTTONID_NO, 0); - - if (nStyle & WB_DEF_CANCEL) - AddButton(BUTTON_CANCEL,BUTTONID_CANCEL,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_CANCEL,BUTTONID_CANCEL, 0); - } - else if (nStyle & WB_OK_CANCEL) - { - if (nStyle & WB_DEF_CANCEL) +//------------------------------------------------------------------------------ +void OSQLMessageBox::impl_createStandardButtons( WinBits _nStyle ) +{ + if ( _nStyle & WB_YES_NO_CANCEL ) { - AddButton(BUTTON_OK,BUTTONID_OK,0); - AddButton(BUTTON_CANCEL,BUTTONID_CANCEL,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); + lcl_addButton( *this, BUTTON_YES, ( _nStyle & WB_DEF_YES ) != 0 ); + lcl_addButton( *this, BUTTON_NO, ( _nStyle & WB_DEF_NO ) != 0 ); + lcl_addButton( *this, BUTTON_CANCEL, ( _nStyle & WB_DEF_CANCEL ) != 0 ); } - else + else if ( _nStyle & WB_OK_CANCEL ) { - AddButton(BUTTON_OK,BUTTONID_OK,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - AddButton(BUTTON_CANCEL,BUTTONID_CANCEL,0); - } + lcl_addButton( *this, BUTTON_OK, ( _nStyle & WB_DEF_OK ) != 0 ); + lcl_addButton( *this, BUTTON_CANCEL, ( _nStyle & WB_DEF_CANCEL ) != 0 ); } - else if (nStyle & WB_YES_NO) + else if ( _nStyle & WB_YES_NO ) { - if (nStyle & WB_DEF_YES) - AddButton(BUTTON_YES,BUTTONID_YES,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_YES,BUTTONID_YES,0); - - if (nStyle & WB_DEF_NO) - AddButton(BUTTON_NO,BUTTONID_NO,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_NO,BUTTONID_NO, 0); + lcl_addButton( *this, BUTTON_YES, ( _nStyle & WB_DEF_YES ) != 0 ); + lcl_addButton( *this, BUTTON_NO, ( _nStyle & WB_DEF_NO ) != 0 ); } - else if (nStyle & WB_RETRY_CANCEL) + else if ( _nStyle & WB_RETRY_CANCEL ) { - if (nStyle & WB_DEF_RETRY) - AddButton(BUTTON_RETRY,BUTTONID_RETRY,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_YES,BUTTONID_YES,0); - - if (nStyle & WB_DEF_CANCEL) - AddButton(BUTTON_CANCEL,BUTTONID_CANCEL,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); - else - AddButton(BUTTON_CANCEL,BUTTONID_CANCEL, 0); + lcl_addButton( *this, BUTTON_RETRY, ( _nStyle & WB_DEF_RETRY ) != 0 ); + lcl_addButton( *this, BUTTON_CANCEL, ( _nStyle & WB_DEF_CANCEL ) != 0 ); } else { - DBG_ASSERT(WB_OK & nStyle, "kein Button gesetzt"); - AddButton(BUTTON_OK,BUTTONID_OK,BUTTONDIALOG_DEFBUTTON|BUTTONDIALOG_FOCUSBUTTON); + OSL_ENSURE( WB_OK & _nStyle, "OSQLMessageBox::impl_createStandardButtons: unsupported dialog style requested!" ); + AddButton( BUTTON_OK, BUTTONID_OK, BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_FOCUSBUTTON ); } - sal_Bool bAtLeastTwo = m_aNextChainElement.hasValue() && ((SQLException*)m_aNextChainElement.getValue())->NextException.getValue(); - if (bAtLeastTwo) - { - m_pInfoButton = new PushButton(this); - m_pInfoButton->SetText(Button::GetStandardText(BUTTON_MORE)); - m_pInfoButton->SetClickHdl(LINK(this,OSQLMessageBox,ButtonClickHdl)); - m_pInfoButton->SetUniqueId(UID_SQLERROR_BUTTONMORE); - m_pInfoButton->Show(); - AddButton(m_pInfoButton, BUTTONID_MORE, 0); - } } //------------------------------------------------------------------------------ -void OSQLMessageBox::Construct(const SQLExceptionInfo& _rException, WinBits _nStyle, MessageType _eImage) +void OSQLMessageBox::impl_addDetailsButton() { - const SQLException* pFirst = NULL; - if (_rException.isKindOf(SQLExceptionInfo::SQL_EXCEPTION)) - pFirst = (const SQLException*)_rException; - - // get the first two strings in the chain - String sTitle, sMessage; - if (pFirst) - { - sTitle = pFirst->Message; - // we assume this to be not empty, so in reall we're searching the only te second string, the first - // one is always the Message of the first exception) - - if (_rException.isKindOf(SQLExceptionInfo::SQL_CONTEXT)) - { // take the detailed message - const SQLContext* pContext = (const SQLContext*)_rException; - sMessage = pContext->Details.getStr(); + SQLException aError; + OSL_VERIFY( m_aExceptionInfo.get() >>= aError ); + bool bMoreDetailsAvailable = aError.NextException.hasValue(); + if ( bMoreDetailsAvailable ) + { + AddButton( BUTTON_MORE, BUTTONID_MORE, 0 ); + PushButton* pButton = GetPushButton( BUTTONID_MORE ); + OSL_ENSURE( pButton, "OSQLMessageBox::impl_addDetailsButton: just added this button, why isn't it there?" ); + pButton->SetClickHdl( LINK( this, OSQLMessageBox, ButtonClickHdl ) ); + pButton->SetUniqueId( UID_SQLERROR_BUTTONMORE ); } +} - if (!sMessage.Len()) - { - // loop through all the remaining exceptions - SQLExceptionIteratorHelper aIter((const SQLException*)pFirst); - // skip the first one - if(aIter.hasMoreElements()) - aIter.next(); - // note that this leaves aIter in a state where it's current exception is only an SQLException, - // even if _rException was more than this. But this is irrelevant here, as we always handled - // this first chain element - while (aIter.hasMoreElements() && !sMessage.Len()) - { - SQLExceptionInfo aInfo(*aIter.next()); - if (aInfo.isValid()) - { // first take the normal message of the exception - const SQLException* pException = (const SQLException*)aInfo; - sMessage = pException->Message.getStr(); - // the, if necessary and possible, the details - if (aInfo.isKindOf(SQLExceptionInfo::SQL_CONTEXT)) - { // check if we have a detailed message - const SQLContext* pContext = (const SQLContext*)aInfo; - sMessage = pContext->Details.getStr(); - } - } - } - } - } +//------------------------------------------------------------------------------ +void OSQLMessageBox::Construct( WinBits _nStyle, MessageType _eImage ) +{ + // Changed as per BugID 79541 Branding/Configuration + String sDialogTitle( lcl_getProductName() ); + SetText( sDialogTitle.AppendAscii( " Base" ) ); - if (!sMessage.Len()) - { // use the only string we have as message and an default title - sMessage = sTitle; - sTitle = ModuleRes(STR_GENERAL_SDB_ERROR); - } + // position and size the controls and the dialog, depending on whether we have one or two texts to display + impl_positionControls(); - if ( _eImage == AUTO ) + // init the image + MessageType eType( _eImage ); + if ( eType == AUTO ) { - switch ( _rException.getType() ) + switch ( m_aExceptionInfo.getType() ) { - case SQLExceptionInfo::SQL_EXCEPTION: _eImage = Error; break; - case SQLExceptionInfo::SQL_WARNING: _eImage = Warning; break; - case SQLExceptionInfo::SQL_CONTEXT: _eImage = Info; break; + case SQLExceptionInfo::SQL_EXCEPTION: eType = Error; break; + case SQLExceptionInfo::SQL_WARNING: eType = Warning; break; + case SQLExceptionInfo::SQL_CONTEXT: eType = Info; break; } } + impl_initImage( eType ); - Construct(sTitle, sMessage, _nStyle, _eImage); -} - -DBG_NAME(OSQLMessageBox) -//------------------------------------------------------------------------------ -OSQLMessageBox::OSQLMessageBox(Window* _pParent, const UniString& _rTitle, const SQLException& _rError, WinBits _nStyle, - MessageType _eImage) - :ButtonDialog(_pParent,WB_HORZ | WB_STDDIALOG) - ,m_aInfoImage(this) - ,m_aTitle(this,WB_WORDBREAK | WB_LEFT) - ,m_aMessage(this,WB_WORDBREAK | WB_LEFT) - ,m_pInfoButton(NULL) - ,m_aNextChainElement(SQLExceptionInfo(_rError).get()) -{ - DBG_CTOR(OSQLMessageBox,NULL); - - Construct(_rTitle, _rError.Message, _nStyle, _eImage == AUTO ? Error : _eImage ); + // create buttons + impl_createStandardButtons( _nStyle ); + impl_addDetailsButton(); } //------------------------------------------------------------------------------ @@ -541,53 +486,41 @@ ,m_aInfoImage(this) ,m_aTitle(this,WB_WORDBREAK | WB_LEFT) ,m_aMessage(this,WB_WORDBREAK | WB_LEFT) - ,m_pInfoButton(NULL) - ,m_aNextChainElement(SQLExceptionInfo(_rError).get()) + ,m_aExceptionInfo( _rError ) { - DBG_CTOR(OSQLMessageBox,NULL); - - Construct(SQLExceptionInfo(_rError), _nStyle, _eImage); + Construct( _nStyle, _eImage ); } //------------------------------------------------------------------------------ OSQLMessageBox::OSQLMessageBox(Window* _pParent, const SQLExceptionInfo& _rException, WinBits _nStyle, MessageType _eImage) - :ButtonDialog(_pParent,WB_HORZ | WB_STDDIALOG) - ,m_aInfoImage(this) - ,m_aTitle(this,WB_WORDBREAK | WB_LEFT) - ,m_aMessage(this,WB_WORDBREAK | WB_LEFT) - ,m_pInfoButton(NULL) - ,m_aNextChainElement(_rException.get()) -{ - DBG_CTOR(OSQLMessageBox,NULL); - - Construct(_rException, _nStyle, _eImage); -} - -//------------------------------------------------------------------------------ -OSQLMessageBox::OSQLMessageBox(Window* pParent, const UniString& rTitle, const UniString& rMessage, WinBits nStyle, MessageType eImage) - :ButtonDialog(pParent,WB_HORZ | WB_STDDIALOG) - ,m_aInfoImage(this) - ,m_aTitle(this,WB_WORDBREAK | WB_LEFT) - ,m_aMessage(this,WB_WORDBREAK | WB_LEFT) - ,m_pInfoButton(NULL) + :ButtonDialog( _pParent, WB_HORZ | WB_STDDIALOG ) + ,m_aInfoImage( this ) + ,m_aTitle( this, WB_WORDBREAK | WB_LEFT ) + ,m_aMessage( this, WB_WORDBREAK | WB_LEFT ) + ,m_aExceptionInfo( _rException ) { - DBG_CTOR(OSQLMessageBox,NULL); - - Construct(rTitle, rMessage, nStyle, eImage); + Construct( _nStyle, _eImage ); } //------------------------------------------------------------------------------ -OSQLMessageBox::~OSQLMessageBox() -{ - delete m_pInfoButton; +OSQLMessageBox::OSQLMessageBox( Window* _pParent, const UniString& _rTitle, const UniString& _rMessage, WinBits _nStyle, MessageType _eImage ) + :ButtonDialog( _pParent, WB_HORZ | WB_STDDIALOG ) + ,m_aInfoImage( this ) + ,m_aTitle( this, WB_WORDBREAK | WB_LEFT ) + ,m_aMessage( this, WB_WORDBREAK | WB_LEFT ) +{ + SQLContext aError; + aError.Message = _rTitle; + aError.Details = _rMessage; + m_aExceptionInfo = aError; - DBG_DTOR(OSQLMessageBox,NULL); + Construct( _nStyle, _eImage ); } //-------------------------------------------------------------------------- IMPL_LINK( OSQLMessageBox, ButtonClickHdl, Button *, pButton ) { - OExceptionChainDialog aDlg( this, m_aNextChainElement ); + OExceptionChainDialog aDlg( this, m_aExceptionInfo.get() ); aDlg.Execute(); return 0; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
