summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2018-02-26 21:43:22 +0000
committerCaolán McNamara <caolanm@redhat.com>2018-02-27 21:30:05 +0100
commit22a830a4bd7384b0a636dd8e184a506bc5fdeb0b (patch)
tree05f522dd376df38296c42d787b4997cac2fd02d3 /toolkit
parentf94c5a53efb78cd7829a6ae83555a61a6e77d9fc (diff)
cast MessBox into exile
Change-Id: I2fccc06b2228c1e7fd791d049d951d3a09f0f814 Reviewed-on: https://gerrit.libreoffice.org/50432 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/inc/helper/msgbox.hxx52
-rw-r--r--toolkit/source/awt/vclxtoolkit.cxx253
-rw-r--r--toolkit/source/awt/vclxwindows.cxx1
3 files changed, 306 insertions, 0 deletions
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"