/* -*- 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 .
*/
constexpr OUStringLiteral FIXEDTEXT_SERVICENAME = u"com.sun.star.awt.UnoControlFixedText";
constexpr OUStringLiteral FIXEDTEXT_MODELNAME = u"com.sun.star.awt.UnoControlFixedTextModel";
constexpr OUStringLiteral CONTROLNAME_TEXT = u"Text"; // identifier the control in container
constexpr OUStringLiteral CONTROLNAME_PROGRESSBAR = u"ProgressBar"; // -||-
namespace unocontrols {
// construct/destruct
StatusIndicator::StatusIndicator( const css::uno::Reference< XComponentContext >& rxContext )
: StatusIndicator_BASE(rxContext)
{ // It's not allowed to work with member in this method (refcounter !!!) // But with a HACK (++refcount) its "OK" :-(
osl_atomic_increment(&m_refCount);
// Create instances for fixedtext and progress ...
m_xText.set( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
m_xProgressBar = new ProgressBar(rxContext); // ... cast controls to css::uno::Reference< XControl > and set model ... // ( ProgressBar has no model !!! )
css::uno::Reference< XControl > xTextControl ( m_xText , UNO_QUERY );
xTextControl->setModel( css::uno::Reference< XControlModel >( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); // ... and add controls to basecontainercontrol!
addControl( CONTROLNAME_TEXT, xTextControl );
addControl( CONTROLNAME_PROGRESSBAR, m_xProgressBar ); // FixedText make it automatically visible by himself ... but not the progressbar !!! // it must be set explicitly
m_xProgressBar->setVisible( true ); // Reset to defaults !!! // (progressbar take automatically its own defaults)
m_xText->setText( u""_ustr );
// Clear values of status controls. // (Don't hide the window! User will reset current values ... but he will not finish using of indicator!)
m_xText->setText( OUString() );
m_xProgressBar->setValue( 0 );
}
// get information about required place of child controls
css::uno::Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY );
Size aTextSize = xTextLayout->getPreferredSize();
aGuard.clear ();
// calc preferred size of status indicator
sal_Int32 nWidth = impl_getWidth();
sal_Int32 nHeight = (2*STATUSINDICATOR_FREEBORDER)+aTextSize.Height;
// norm to minimum if ( nWidth<STATUSINDICATOR_DEFAULT_WIDTH )
{
nWidth = STATUSINDICATOR_DEFAULT_WIDTH;
} if ( nHeight<STATUSINDICATOR_DEFAULT_HEIGHT )
{
nHeight = STATUSINDICATOR_DEFAULT_HEIGHT;
}
// If user forget to call "setPosSize()", we have still a correct size. // And a "MinimumSize" IS A "MinimumSize"! // We change not the position of control at this point.
Size aDefaultSize = getMinimumSize ();
setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE );
}
}
// XControl
sal_Bool SAL_CALL StatusIndicator::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ )
{ // We have no model. returnfalse;
}
// XControl
css::uno::Reference< XControlModel > SAL_CALL StatusIndicator::getModel ()
{ // We have no model. // return (XControlModel*)this; return css::uno::Reference< XControlModel > ();
}
// don't use "...->clear ()" or "... = XFixedText ()" // when other hold a reference at this object !!!
xTextControl->dispose();
m_xProgressBar->dispose();
m_xProgressBar.clear();
m_xText.clear();
BaseContainerControl::dispose();
}
// if position or size changed if (
( nWidth != aBasePosSize.Width ) ||
( nHeight != aBasePosSize.Height)
)
{ // calc new layout for controls
impl_recalcLayout ( WindowEvent(getXWeak(),0,0,nWidth,nHeight,0,0,0,0) ); // clear background (!) // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
getPeer()->invalidate(2); // and repaint the control
impl_paint ( 0, 0, impl_getGraphicsPeer() );
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.