include/vcl/btndlg.hxx | 2 include/vcl/dialog.hxx | 2 include/vcl/msgbox.hxx | 31 ---- toolkit/inc/helper/msgbox.hxx | 52 +++++++ toolkit/source/awt/vclxtoolkit.cxx | 253 ++++++++++++++++++++++++++++++++++++ toolkit/source/awt/vclxwindows.cxx | 1 vcl/source/window/dialog.cxx | 6 vcl/source/window/msgbox.cxx | 257 ------------------------------------- 8 files changed, 309 insertions(+), 295 deletions(-)
New commits: commit 22a830a4bd7384b0a636dd8e184a506bc5fdeb0b Author: Caolán McNamara <caol...@redhat.com> Date: Mon Feb 26 21:43:22 2018 +0000 cast MessBox into exile Change-Id: I2fccc06b2228c1e7fd791d049d951d3a09f0f814 Reviewed-on: https://gerrit.libreoffice.org/50432 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/btndlg.hxx b/include/vcl/btndlg.hxx index e6c54d3acca6..c449eec8a3e3 100644 --- a/include/vcl/btndlg.hxx +++ b/include/vcl/btndlg.hxx @@ -75,7 +75,7 @@ public: protected: ButtonDialog( WindowType nType ); - SAL_DLLPRIVATE long ImplGetButtonSize(); + long ImplGetButtonSize(); private: ButtonDialog( const ButtonDialog & ) = delete; diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx index e53a71782f3a..243d071b101f 100644 --- a/include/vcl/dialog.hxx +++ b/include/vcl/dialog.hxx @@ -74,7 +74,7 @@ private: protected: using Window::ImplInit; - SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag = InitFlag::Default ); + void ImplInit( vcl::Window* pParent, WinBits nStyle, InitFlag eFlag = InitFlag::Default ); /// Find and set the LOK notifier according to the pParent. void ImplLOKNotifier(vcl::Window* pParent); diff --git a/include/vcl/msgbox.hxx b/include/vcl/msgbox.hxx index 46dce1b0bc6a..57d34a41afd1 100644 --- a/include/vcl/msgbox.hxx +++ b/include/vcl/msgbox.hxx @@ -50,37 +50,6 @@ namespace o3tl { template<> struct typed_flags<MessBoxStyle> : is_typed_flags<MessBoxStyle, 0x3fff> {}; } - -class VCL_DLLPUBLIC MessBox : public ButtonDialog -{ - VclPtr<VclMultiLineEdit> mpVCLMultiLineEdit; - VclPtr<FixedImage> mpFixedImage; - Image maImage; - bool mbHelpBtn; - MessBoxStyle mnMessBoxStyle; - -protected: - OUString maMessText; - - SAL_DLLPRIVATE void ImplInitButtons(); - SAL_DLLPRIVATE void ImplPosControls(); - -public: - MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits n, - const OUString& rTitle, const OUString& rMessage); - virtual ~MessBox() override; - virtual void dispose() override; - - virtual void StateChanged( StateChangedType nStateChange ) override; - - void SetMessText( const OUString& rText ) { maMessText = rText; } - const OUString& GetMessText() const { return maMessText; } - - void SetImage( const Image& rImage ) { maImage = rImage; } - - virtual Size GetOptimalSize() const override; -}; - VCL_DLLPUBLIC Image const & GetStandardInfoBoxImage(); VCL_DLLPUBLIC OUString GetStandardInfoBoxText(); diff --git a/toolkit/inc/helper/msgbox.hxx b/toolkit/inc/helper/msgbox.hxx new file mode 100644 index 000000000000..327c87e971b9 --- /dev/null +++ b/toolkit/inc/helper/msgbox.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <vcl/btndlg.hxx> + +class MessBox : public ButtonDialog +{ + VclPtr<VclMultiLineEdit> mpVCLMultiLineEdit; + VclPtr<FixedImage> mpFixedImage; + Image maImage; + bool mbHelpBtn; + MessBoxStyle mnMessBoxStyle; + +protected: + OUString maMessText; + + void ImplInitButtons(); + void ImplPosControls(); + +public: + MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits n, const OUString& rTitle, + const OUString& rMessage); + virtual ~MessBox() override; + virtual void dispose() override; + + virtual void StateChanged(StateChangedType nStateChange) override; + + void SetMessText(const OUString& rText) { maMessText = rText; } + const OUString& GetMessText() const { return maMessText; } + + void SetImage(const Image& rImage) { maImage = rImage; } + + virtual Size GetOptimalSize() const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 272163fbc728..7e528ef1f94d 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -66,6 +66,8 @@ #endif #include <vcl/sysdata.hxx> +#include <vcl/textrectinfo.hxx> +#include <vcl/vclmedit.hxx> #include <toolkit/awt/vclxwindows.hxx> #include <toolkit/awt/vclxsystemdependentwindow.hxx> @@ -123,6 +125,7 @@ #include <toolkit/awt/scrollabledialog.hxx> #include <comphelper/profilezone.hxx> +#include <helper/msgbox.hxx> #include <helper/unowrapper.hxx> #if defined(_WIN32) @@ -133,6 +136,256 @@ #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_XWINDOW #endif +void MessBox::ImplInitButtons() +{ + ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK; + ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel; + ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE; + ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE; + ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE; + + if ( mnMessBoxStyle & MessBoxStyle::OkCancel ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) + nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else // MessBoxStyle::DefaultOk + nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::OK, RET_OK, nOKFlags ); + AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::YesNo ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultYes ) + nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else // MessBoxStyle::DefaultNo + nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + nNoFlags |= ButtonDialogFlags::Cancel; + + AddButton( StandardButtonType::Yes, RET_YES, nYesFlags ); + AddButton( StandardButtonType::No, RET_NO, nNoFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultYes ) + nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo ) + nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else + nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::Yes, RET_YES, nYesFlags ); + AddButton( StandardButtonType::No, RET_NO, nNoFlags ); + AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel ) + { + if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) + nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else // MessBoxStyle::DefaultRetry + nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags ); + AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore ) + { + ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE; + ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE; + + if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) + nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry ) + nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore ) + nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags ); + AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags ); + AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags ); + } + else if ( mnMessBoxStyle & MessBoxStyle::Ok ) + { + nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; + + AddButton( StandardButtonType::OK, RET_OK, nOKFlags ); + } +} + +MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits, + const OUString& rTitle, const OUString& rMessage) : + ButtonDialog( WindowType::MESSBOX ), + mbHelpBtn( false ), + mnMessBoxStyle( nMessBoxStyle ), + maMessText( rMessage ) +{ + ImplLOKNotifier(pParent); + ImplInit(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER); + ImplInitButtons(); + + if ( !rTitle.isEmpty() ) + SetText( rTitle ); +} + +MessBox::~MessBox() +{ + disposeOnce(); +} + +void MessBox::dispose() +{ + mpVCLMultiLineEdit.disposeAndClear(); + mpFixedImage.disposeAndClear(); + ButtonDialog::dispose(); +} + +void MessBox::ImplPosControls() +{ + if ( !GetHelpId().isEmpty() ) + { + if ( !mbHelpBtn ) + { + AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 ); + mbHelpBtn = true; + } + } + else + { + if ( mbHelpBtn ) + { + RemoveButton( RET_HELP ); + mbHelpBtn = false; + } + } + + TextRectInfo aTextInfo; + tools::Rectangle aRect( 0, 0, 30000, 30000 ); + tools::Rectangle aFormatRect; + Point aTextPos( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+IMPL_MSGBOX_OFFSET_EXTRA_Y ); + Size aImageSize; + Size aPageSize; + Size aMEditSize; + long nTitleWidth; + long nButtonSize = ImplGetButtonSize(); + long nMaxWidth = GetDesktopRectPixel().GetWidth()-8; + long nMaxLineWidth; + long nWidth; + WinBits nWinStyle = WB_LEFT | WB_NOLABEL; + DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left; + + mpVCLMultiLineEdit.disposeAndClear(); + mpFixedImage.disposeAndClear(); + + // Clean up message text with tabs + OUString aMessText(maMessText.replaceAll("\t", " ")); + + //If window too small, we make dialog box be wider + nMaxWidth = 630 * GetDPIScaleFactor(); + + // MessagBox should be at least as wide as to see the title + // Extra-Width for Close button, because Close button is set after this call + nTitleWidth = CalcTitleWidth(); + + nMaxWidth -= (IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2); + + // for an image, get its size, create a suitable control and position it + aImageSize = maImage.GetSizePixel(); + if ( aImageSize.Width() ) + { + aImageSize.AdjustWidth(4 ); + aImageSize.AdjustHeight(4 ); + aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE ); + mpFixedImage = VclPtr<FixedImage>::Create( this ); + mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X, + IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ), + aImageSize ); + mpFixedImage->SetImage( maImage ); + mpFixedImage->Show(); + nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE; + } + else + aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X ); + + // Determine maximum line length without wordbreak + aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); + nMaxLineWidth = aFormatRect.GetWidth(); + nTextStyle |= DrawTextFlags::WordBreak; + + // Determine the width for text formatting + if ( nMaxLineWidth > 450 ) + nWidth = 450; + else if ( nMaxLineWidth > 300 ) + nWidth = nMaxLineWidth+5; + else + nWidth = 300; + + nWidth *= GetDPIScaleFactor(); + + if ( nButtonSize > nWidth ) + nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET); + if ( nWidth > nMaxWidth ) + nWidth = nMaxWidth; + + aRect.SetRight( nWidth ); + aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); + if ( aTextInfo.GetMaxLineWidth() > nWidth ) + { + nWidth = aTextInfo.GetMaxLineWidth()+8; + aRect.SetRight( nWidth ); + aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); + } + + // get Style for VCLMultiLineEdit + aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 ); + aMEditSize.setHeight( aFormatRect.GetHeight() ); + aPageSize.setWidth( aImageSize.Width() ); + if ( aMEditSize.Height() < aImageSize.Height() ) + { + nWinStyle |= WB_VCENTER; + aPageSize.setHeight( aImageSize.Height() ); + aMEditSize.setHeight( aImageSize.Height() ); + } + else + { + nWinStyle |= WB_TOP; + aPageSize.setHeight( aMEditSize.Height() ); + } + if ( aImageSize.Width() ) + aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE ); + aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2) ); + aPageSize.AdjustWidth(aMEditSize.Width()+1 ); + aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y*2) ); + + if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH ) + aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH ); + if ( aPageSize.Width() < nTitleWidth ) + aPageSize.setWidth( nTitleWidth ); + + mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle ); + mpVCLMultiLineEdit->SetText( aMessText ); + mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize ); + mpVCLMultiLineEdit->Show(); + mpVCLMultiLineEdit->SetPaintTransparent(true); + mpVCLMultiLineEdit->EnableCursor(false); + SetPageSizePixel( aPageSize ); +} + +void MessBox::StateChanged( StateChangedType nType ) +{ + if ( nType == StateChangedType::InitShow ) + { + ImplPosControls(); + } + ButtonDialog::StateChanged( nType ); +} + +Size MessBox::GetOptimalSize() const +{ + // FIXME: base me on the font size ? + return Size( 250, 100 ); +} + + namespace { extern "C" typedef vcl::Window* (*FN_SvtCreateWindow)( diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx index 5cec8af4fef3..e0d435abdf7c 100644 --- a/toolkit/source/awt/vclxwindows.cxx +++ b/toolkit/source/awt/vclxwindows.cxx @@ -60,6 +60,7 @@ #include <helper/accessibilityclient.hxx> #include <helper/imagealign.hxx> +#include <helper/msgbox.hxx> #include <helper/tkresmgr.hxx> #include "vclxwindows_internal.hxx" diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index 9665fa880e5e..75d31d1f17b4 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -69,11 +69,7 @@ static OString ImplGetDialogText( Dialog* pDialog ) pDialog->GetText(), RTL_TEXTENCODING_UTF8)); OUString sMessage; - if (MessBox* pMessBox = dynamic_cast<MessBox*>(pDialog)) - { - sMessage = pMessBox->GetMessText(); - } - else if (MessageDialog* pMessDialog = dynamic_cast<MessageDialog*>(pDialog)) + if (MessageDialog* pMessDialog = dynamic_cast<MessageDialog*>(pDialog)) { sMessage = pMessDialog->get_primary_text(); } diff --git a/vcl/source/window/msgbox.cxx b/vcl/source/window/msgbox.cxx index 805eae6f8b4f..b91f3b2fb973 100644 --- a/vcl/source/window/msgbox.cxx +++ b/vcl/source/window/msgbox.cxx @@ -46,263 +46,6 @@ static void ImplInitMsgBoxImageList() } } -void MessBox::ImplInitButtons() -{ - ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK; - ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel; - ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE; - ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE; - ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE; - - if ( mnMessBoxStyle & MessBoxStyle::OkCancel ) - { - if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) - nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else // MessBoxStyle::DefaultOk - nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - - AddButton( StandardButtonType::OK, RET_OK, nOKFlags ); - AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); - } - else if ( mnMessBoxStyle & MessBoxStyle::YesNo ) - { - if ( mnMessBoxStyle & MessBoxStyle::DefaultYes ) - nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else // MessBoxStyle::DefaultNo - nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - nNoFlags |= ButtonDialogFlags::Cancel; - - AddButton( StandardButtonType::Yes, RET_YES, nYesFlags ); - AddButton( StandardButtonType::No, RET_NO, nNoFlags ); - } - else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel ) - { - if ( mnMessBoxStyle & MessBoxStyle::DefaultYes ) - nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo ) - nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else - nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - - AddButton( StandardButtonType::Yes, RET_YES, nYesFlags ); - AddButton( StandardButtonType::No, RET_NO, nNoFlags ); - AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); - } - else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel ) - { - if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) - nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else // MessBoxStyle::DefaultRetry - nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - - AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags ); - AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags ); - } - else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore ) - { - ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE; - ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE; - - if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel ) - nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry ) - nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore ) - nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - - AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags ); - AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags ); - AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags ); - } - else if ( mnMessBoxStyle & MessBoxStyle::Ok ) - { - nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus; - - AddButton( StandardButtonType::OK, RET_OK, nOKFlags ); - } -} - -MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits, - const OUString& rTitle, const OUString& rMessage) : - ButtonDialog( WindowType::MESSBOX ), - mbHelpBtn( false ), - mnMessBoxStyle( nMessBoxStyle ), - maMessText( rMessage ) -{ - ImplLOKNotifier(pParent); - ImplInit(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER); - ImplInitButtons(); - - if ( !rTitle.isEmpty() ) - SetText( rTitle ); -} - -MessBox::~MessBox() -{ - disposeOnce(); -} - -void MessBox::dispose() -{ - mpVCLMultiLineEdit.disposeAndClear(); - mpFixedImage.disposeAndClear(); - ButtonDialog::dispose(); -} - -void MessBox::ImplPosControls() -{ - if ( !GetHelpId().isEmpty() ) - { - if ( !mbHelpBtn ) - { - AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 ); - mbHelpBtn = true; - } - } - else - { - if ( mbHelpBtn ) - { - RemoveButton( RET_HELP ); - mbHelpBtn = false; - } - } - - TextRectInfo aTextInfo; - tools::Rectangle aRect( 0, 0, 30000, 30000 ); - tools::Rectangle aFormatRect; - Point aTextPos( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+IMPL_MSGBOX_OFFSET_EXTRA_Y ); - Size aImageSize; - Size aPageSize; - Size aMEditSize; - long nTitleWidth; - long nButtonSize = ImplGetButtonSize(); - long nMaxWidth = GetDesktopRectPixel().GetWidth()-8; - long nMaxLineWidth; - long nWidth; - WinBits nWinStyle = WB_LEFT | WB_NOLABEL; - DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left; - - mpVCLMultiLineEdit.disposeAndClear(); - mpFixedImage.disposeAndClear(); - - // Clean up message text with tabs - OUString aMessText(maMessText.replaceAll("\t", " ")); - - //If window too small, we make dialog box be wider - if ( mpWindowImpl->mbFrame ) - { - nMaxWidth = 630 * GetDPIScaleFactor(); - } - else if ( nMaxWidth < 120 ) - nMaxWidth = 120; - - nMaxWidth -= mpWindowImpl->mnLeftBorder+mpWindowImpl->mnRightBorder+4; - - // MessagBox should be at least as wide as to see the title - // Extra-Width for Close button, because Close button is set after this call - nTitleWidth = CalcTitleWidth(); - nTitleWidth += mpWindowImpl->mnTopBorder; - - nMaxWidth -= (IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2); - - // for an image, get its size, create a suitable control and position it - aImageSize = maImage.GetSizePixel(); - if ( aImageSize.Width() ) - { - aImageSize.AdjustWidth(4 ); - aImageSize.AdjustHeight(4 ); - aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE ); - mpFixedImage = VclPtr<FixedImage>::Create( this ); - mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X, - IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ), - aImageSize ); - mpFixedImage->SetImage( maImage ); - mpFixedImage->Show(); - nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE; - } - else - aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X ); - - // Determine maximum line length without wordbreak - aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); - nMaxLineWidth = aFormatRect.GetWidth(); - nTextStyle |= DrawTextFlags::WordBreak; - - // Determine the width for text formatting - if ( nMaxLineWidth > 450 ) - nWidth = 450; - else if ( nMaxLineWidth > 300 ) - nWidth = nMaxLineWidth+5; - else - nWidth = 300; - - nWidth *= GetDPIScaleFactor(); - - if ( nButtonSize > nWidth ) - nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET); - if ( nWidth > nMaxWidth ) - nWidth = nMaxWidth; - - aRect.SetRight( nWidth ); - aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); - if ( aTextInfo.GetMaxLineWidth() > nWidth ) - { - nWidth = aTextInfo.GetMaxLineWidth()+8; - aRect.SetRight( nWidth ); - aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo ); - } - - // get Style for VCLMultiLineEdit - aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 ); - aMEditSize.setHeight( aFormatRect.GetHeight() ); - aPageSize.setWidth( aImageSize.Width() ); - if ( aMEditSize.Height() < aImageSize.Height() ) - { - nWinStyle |= WB_VCENTER; - aPageSize.setHeight( aImageSize.Height() ); - aMEditSize.setHeight( aImageSize.Height() ); - } - else - { - nWinStyle |= WB_TOP; - aPageSize.setHeight( aMEditSize.Height() ); - } - if ( aImageSize.Width() ) - aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE ); - aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2) ); - aPageSize.AdjustWidth(aMEditSize.Width()+1 ); - aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y*2) ); - - if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH ) - aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH ); - if ( aPageSize.Width() < nTitleWidth ) - aPageSize.setWidth( nTitleWidth ); - - mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle ); - mpVCLMultiLineEdit->SetText( aMessText ); - mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize ); - mpVCLMultiLineEdit->Show(); - mpVCLMultiLineEdit->SetPaintTransparent(true); - mpVCLMultiLineEdit->EnableCursor(false); - SetPageSizePixel( aPageSize ); -} - -void MessBox::StateChanged( StateChangedType nType ) -{ - if ( nType == StateChangedType::InitShow ) - { - ImplPosControls(); - } - ButtonDialog::StateChanged( nType ); -} - -Size MessBox::GetOptimalSize() const -{ - // FIXME: base me on the font size ? - return Size( 250, 100 ); -} - Image const & GetStandardInfoBoxImage() { ImplInitMsgBoxImageList(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits