2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-26 13:30:33 +00:00
|
|
|
#include <pattern/window.hxx>
|
2002-07-29 07:18:00 +00:00
|
|
|
#include <helper/persistentwindowstate.hxx>
|
2004-11-17 11:52:54 +00:00
|
|
|
|
2002-07-29 07:18:00 +00:00
|
|
|
#include <com/sun/star/awt/XWindow.hpp>
|
2004-11-17 11:52:54 +00:00
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
2012-10-16 11:10:43 +02:00
|
|
|
#include <com/sun/star/frame/ModuleManager.hpp>
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2016-02-09 14:14:22 +02:00
|
|
|
#include <comphelper/lok.hxx>
|
2012-10-16 11:10:43 +02:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2004-11-17 11:52:54 +00:00
|
|
|
#include <comphelper/configurationhelper.hxx>
|
2002-07-29 07:18:00 +00:00
|
|
|
#include <vcl/window.hxx>
|
|
|
|
#include <vcl/syswin.hxx>
|
|
|
|
|
2013-06-28 04:38:06 +02:00
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
2002-07-29 07:18:00 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2002-10-11 17:08:29 +00:00
|
|
|
#include <vcl/wrkwin.hxx>
|
2011-03-11 15:50:36 +01:00
|
|
|
#include <rtl/string.hxx>
|
2004-11-17 11:52:54 +00:00
|
|
|
|
2002-07-29 07:18:00 +00:00
|
|
|
namespace framework{
|
|
|
|
|
2013-05-27 15:33:07 +02:00
|
|
|
PersistentWindowState::PersistentWindowState(const css::uno::Reference< css::uno::XComponentContext >& xContext)
|
2014-03-18 14:46:29 +01:00
|
|
|
: m_xContext (xContext )
|
2014-04-04 15:53:21 +02:00
|
|
|
, m_bWindowStateAlreadySet(false )
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PersistentWindowState::~PersistentWindowState()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
void SAL_CALL PersistentWindowState::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
|
|
|
|
{
|
|
|
|
// check arguments
|
|
|
|
css::uno::Reference< css::frame::XFrame > xFrame;
|
|
|
|
if (lArguments.getLength() < 1)
|
|
|
|
throw css::lang::IllegalArgumentException(
|
2013-09-09 00:58:15 +03:00
|
|
|
"Empty argument list!",
|
2004-11-17 11:52:54 +00:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this),
|
|
|
|
1);
|
|
|
|
|
|
|
|
lArguments[0] >>= xFrame;
|
|
|
|
if (!xFrame.is())
|
|
|
|
throw css::lang::IllegalArgumentException(
|
2013-09-09 00:58:15 +03:00
|
|
|
"No valid frame specified!",
|
2004-11-17 11:52:54 +00:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this),
|
|
|
|
1);
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2014-03-18 14:46:29 +01:00
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
m_xFrame = xFrame;
|
|
|
|
}
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
// start listening
|
|
|
|
xFrame->addFrameActionListener(this);
|
|
|
|
}
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
void SAL_CALL PersistentWindowState::frameAction(const css::frame::FrameActionEvent& aEvent)
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2016-02-09 14:14:22 +02:00
|
|
|
// We don't want to do this stuff when being used through LibreOfficeKit
|
|
|
|
if( comphelper::LibreOfficeKit::isActive() )
|
|
|
|
return;
|
|
|
|
|
2014-03-18 14:46:29 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > xContext;
|
|
|
|
css::uno::Reference< css::frame::XFrame > xFrame;
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bRestoreWindowState;
|
2014-03-18 14:46:29 +01:00
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
xContext = m_xContext;
|
|
|
|
xFrame.set(m_xFrame.get(), css::uno::UNO_QUERY);
|
|
|
|
bRestoreWindowState = !m_bWindowStateAlreadySet;
|
|
|
|
}
|
2004-11-17 11:52:54 +00:00
|
|
|
|
|
|
|
// frame already gone ? We hold it weak only ...
|
|
|
|
if (!xFrame.is())
|
|
|
|
return;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
// no window -> no position and size available
|
|
|
|
css::uno::Reference< css::awt::XWindow > xWindow = xFrame->getContainerWindow();
|
|
|
|
if (!xWindow.is())
|
|
|
|
return;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
// unknown module -> no configuration available!
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sModuleName = PersistentWindowState::implst_identifyModule(xContext, xFrame);
|
2011-12-26 14:20:50 -02:00
|
|
|
if (sModuleName.isEmpty())
|
2004-11-17 11:52:54 +00:00
|
|
|
return;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
switch(aEvent.Action)
|
|
|
|
{
|
|
|
|
case css::frame::FrameAction_COMPONENT_ATTACHED :
|
|
|
|
{
|
2004-12-03 13:04:39 +00:00
|
|
|
if (bRestoreWindowState)
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sWindowState = PersistentWindowState::implst_getWindowStateFromConfig(xContext, sModuleName);
|
2004-12-03 13:04:39 +00:00
|
|
|
PersistentWindowState::implst_setWindowStateOnWindow(xWindow,sWindowState);
|
2014-03-18 14:46:29 +01:00
|
|
|
SolarMutexGuard g;
|
2014-04-04 15:53:21 +02:00
|
|
|
m_bWindowStateAlreadySet = true;
|
2004-12-03 13:04:39 +00:00
|
|
|
}
|
2004-11-17 11:52:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case css::frame::FrameAction_COMPONENT_REATTACHED :
|
|
|
|
{
|
2016-10-02 00:28:47 +02:00
|
|
|
// nothing todo here, because it's not allowed to change position and size
|
2015-06-15 19:44:53 +02:00
|
|
|
// of an already existing frame!
|
2004-11-17 11:52:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case css::frame::FrameAction_COMPONENT_DETACHING :
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sWindowState = PersistentWindowState::implst_getWindowStateFromWindow(xWindow);
|
2012-10-16 14:05:41 +02:00
|
|
|
PersistentWindowState::implst_setWindowStateOnConfig(xContext, sModuleName, sWindowState);
|
2004-11-17 11:52:54 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-06-19 10:19:28 +00:00
|
|
|
default:
|
|
|
|
break;
|
2004-11-17 11:52:54 +00:00
|
|
|
}
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 10:19:28 +00:00
|
|
|
void SAL_CALL PersistentWindowState::disposing(const css::lang::EventObject&)
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2004-11-17 11:52:54 +00:00
|
|
|
// nothing todo here - because we hold the frame as weak reference only
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString PersistentWindowState::implst_identifyModule(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
2004-11-17 11:52:54 +00:00
|
|
|
const css::uno::Reference< css::frame::XFrame >& xFrame)
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sModuleName;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2012-10-16 11:10:43 +02:00
|
|
|
css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
|
|
|
|
css::frame::ModuleManager::create( rxContext );
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
try
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2004-11-17 11:52:54 +00:00
|
|
|
sModuleName = xModuleManager->identify(xFrame);
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
2012-02-05 11:53:47 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-11-17 11:52:54 +00:00
|
|
|
catch(const css::uno::Exception&)
|
2014-11-12 14:24:10 +05:30
|
|
|
{ sModuleName.clear(); }
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
return sModuleName;
|
|
|
|
}
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2015-12-26 12:27:56 +01:00
|
|
|
OUString PersistentWindowState::implst_getWindowStateFromConfig(
|
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
|
|
|
const OUString& sModuleName)
|
2004-11-17 11:52:54 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sWindowState;
|
2004-11-17 11:52:54 +00:00
|
|
|
try
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2012-10-16 14:05:41 +02:00
|
|
|
::comphelper::ConfigurationHelper::readDirectKey(rxContext,
|
2015-12-26 12:27:56 +01:00
|
|
|
"org.openoffice.Setup/",
|
|
|
|
"Office/Factories/*[\"" + sModuleName + "\"]",
|
|
|
|
"ooSetupFactoryWindowAttributes",
|
2016-02-23 13:32:21 +02:00
|
|
|
::comphelper::EConfigurationModes::ReadOnly) >>= sWindowState;
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
2012-02-05 11:53:47 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-11-17 11:52:54 +00:00
|
|
|
catch(const css::uno::Exception&)
|
2014-11-12 14:24:10 +05:30
|
|
|
{ sWindowState.clear(); }
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
return sWindowState;
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
2015-12-26 12:27:56 +01:00
|
|
|
void PersistentWindowState::implst_setWindowStateOnConfig(
|
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
|
|
|
const OUString& sModuleName, const OUString& sWindowState)
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2004-11-17 11:52:54 +00:00
|
|
|
try
|
|
|
|
{
|
2012-10-16 14:05:41 +02:00
|
|
|
::comphelper::ConfigurationHelper::writeDirectKey(rxContext,
|
2015-12-26 12:27:56 +01:00
|
|
|
"org.openoffice.Setup/",
|
|
|
|
"Office/Factories/*[\"" + sModuleName + "\"]",
|
|
|
|
"ooSetupFactoryWindowAttributes",
|
|
|
|
css::uno::makeAny(sWindowState),
|
2016-02-23 13:32:21 +02:00
|
|
|
::comphelper::EConfigurationModes::Standard);
|
2004-11-17 11:52:54 +00:00
|
|
|
}
|
2012-02-05 11:53:47 +01:00
|
|
|
catch(const css::uno::RuntimeException&)
|
|
|
|
{ throw; }
|
2004-11-17 11:52:54 +00:00
|
|
|
catch(const css::uno::Exception&)
|
|
|
|
{}
|
|
|
|
}
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString PersistentWindowState::implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow)
|
2004-11-17 11:52:54 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sWindowState;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
if (xWindow.is())
|
|
|
|
{
|
|
|
|
// SOLAR SAFE -> ------------------------
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2004-11-17 11:52:54 +00:00
|
|
|
|
2016-11-10 12:53:02 +02:00
|
|
|
VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
|
2013-03-03 17:11:39 +01:00
|
|
|
// check for system window is necessary to guarantee correct pointer cast!
|
2017-07-06 14:49:15 +02:00
|
|
|
if ( pWindow && pWindow->IsSystemWindow() )
|
2004-11-17 11:52:54 +00:00
|
|
|
{
|
2017-07-06 14:49:15 +02:00
|
|
|
WindowStateMask const nMask = WindowStateMask::All & ~WindowStateMask::Minimized;
|
2014-11-06 17:24:13 +01:00
|
|
|
sWindowState = OStringToOUString(
|
2016-11-10 12:53:02 +02:00
|
|
|
static_cast<SystemWindow*>(pWindow.get())->GetWindowState(nMask),
|
2014-11-06 17:24:13 +01:00
|
|
|
RTL_TEXTENCODING_UTF8);
|
2004-11-17 11:52:54 +00:00
|
|
|
}
|
|
|
|
// <- SOLAR SAFE ------------------------
|
|
|
|
}
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
return sWindowState;
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
2007-04-16 15:41:24 +00:00
|
|
|
void PersistentWindowState::implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow ,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sWindowState)
|
2002-07-29 07:18:00 +00:00
|
|
|
{
|
2004-11-17 11:52:54 +00:00
|
|
|
if (
|
|
|
|
(!xWindow.is() ) ||
|
2011-12-26 14:20:50 -02:00
|
|
|
( sWindowState.isEmpty() )
|
2004-11-17 11:52:54 +00:00
|
|
|
)
|
|
|
|
return;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
// SOLAR SAFE -> ------------------------
|
2010-10-14 22:09:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2016-11-10 12:53:02 +02:00
|
|
|
VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
|
2004-11-17 11:52:54 +00:00
|
|
|
if (!pWindow)
|
|
|
|
return;
|
2002-10-11 17:08:29 +00:00
|
|
|
|
2013-03-03 17:11:39 +01:00
|
|
|
// check for system and work window - its necessary to guarantee correct pointer cast!
|
2014-04-04 15:53:21 +02:00
|
|
|
bool bSystemWindow = pWindow->IsSystemWindow();
|
2017-02-13 19:08:14 +02:00
|
|
|
bool bWorkWindow = (pWindow->GetType() == WindowType::WORKWINDOW);
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2004-11-17 11:52:54 +00:00
|
|
|
if (!bSystemWindow && !bWorkWindow)
|
|
|
|
return;
|
2002-07-29 07:18:00 +00:00
|
|
|
|
2016-11-10 12:53:02 +02:00
|
|
|
SystemWindow* pSystemWindow = static_cast<SystemWindow*>(pWindow.get());
|
|
|
|
WorkWindow* pWorkWindow = static_cast<WorkWindow* >(pWindow.get());
|
2004-11-17 11:52:54 +00:00
|
|
|
|
2015-09-29 17:53:53 +02:00
|
|
|
// don't save this special state!
|
2004-11-17 11:52:54 +00:00
|
|
|
if (pWorkWindow->IsMinimized())
|
2002-07-29 07:18:00 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sOldWindowState = OStringToOUString( pSystemWindow->GetWindowState(), RTL_TEXTENCODING_ASCII_US );
|
2011-03-11 15:50:36 +01:00
|
|
|
if ( sOldWindowState != sWindowState )
|
2013-04-07 12:06:47 +02:00
|
|
|
pSystemWindow->SetWindowState(OUStringToOString(sWindowState,RTL_TEXTENCODING_UTF8));
|
2004-11-17 11:52:54 +00:00
|
|
|
// <- SOLAR SAFE ------------------------
|
2002-07-29 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace framework
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|