LCOV - code coverage report
Current view: top level - include/svx - dialcontrol.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 4 75.0 %
Date: 2015-06-13 12:38:46 Functions: 4 7 57.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SVX_DIALCONTROL_HXX
      21             : #define INCLUDED_SVX_DIALCONTROL_HXX
      22             : 
      23             : #include <memory>
      24             : #include <vcl/ctrl.hxx>
      25             : #include <sfx2/itemconnect.hxx>
      26             : #include <svx/svxdllapi.h>
      27             : 
      28             : class NumericField;
      29             : 
      30             : namespace svx {
      31             : 
      32             : 
      33             : 
      34           6 : class SAL_WARN_UNUSED DialControlBmp : public VirtualDevice
      35             : {
      36             : public:
      37             :     explicit            DialControlBmp( vcl::Window& rParent );
      38             : 
      39             :     void                InitBitmap(const vcl::Font& rFont);
      40             :     void                SetSize(const Size& rSize);
      41             :     void                CopyBackground( const DialControlBmp& rSrc );
      42             :     void                DrawBackground( const Size& rSize, bool bEnabled );
      43             :     void                DrawBackground();
      44             :     void                DrawElements( const OUString& rText, sal_Int32 nAngle );
      45             : 
      46             : protected:
      47             :     Rectangle           maRect;
      48             :     bool                mbEnabled;
      49             : 
      50             : private:
      51             :     const Color&        GetBackgroundColor() const;
      52             :     const Color&        GetTextColor() const;
      53             :     const Color&        GetScaleLineColor() const;
      54             :     const Color&        GetButtonLineColor() const;
      55             :     const Color&        GetButtonFillColor( bool bMain ) const;
      56             : 
      57             :     void                Init();
      58             : 
      59             :     vcl::Window&        mrParent;
      60             :     long                mnCenterX;
      61             :     long                mnCenterY;
      62             : };
      63             : 
      64             : /** This control allows to input a rotation angle, visualized by a dial.
      65             : 
      66             :     Usage: A single click sets a rotation angle rounded to steps of 15 degrees.
      67             :     Dragging with the left mouse button sets an exact rotation angle. Pressing
      68             :     the ESCAPE key during mouse drag cancels the operation and restores the old
      69             :     state of the control.
      70             : 
      71             :     It is possible to link a numeric field to this control using the function
      72             :     SetLinkedField(). The DialControl will take full control of this numeric
      73             :     field:
      74             :     -   Sets the rotation angle to the numeric field in mouse operations.
      75             :     -   Shows the value entered/modified in the numeric field.
      76             :     -   Enables/disables/shows/hides the field according to own state changes.
      77             :  */
      78           1 : class SVX_DLLPUBLIC SAL_WARN_UNUSED DialControl : public Control
      79             : {
      80             : public:
      81             :     explicit            DialControl( vcl::Window* pParent, WinBits nBits );
      82             : 
      83             :     virtual void        Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
      84             : 
      85             :     virtual void        StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
      86             :     virtual void        DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
      87             : 
      88             :     virtual void        MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
      89             :     virtual void        MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
      90             :     virtual void        MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
      91             :     virtual void        KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
      92             :     virtual void        LoseFocus() SAL_OVERRIDE;
      93             : 
      94             :     virtual Size        GetOptimalSize() const SAL_OVERRIDE;
      95             :     virtual void        Resize() SAL_OVERRIDE;
      96             : 
      97             :     /** Returns true, if the control is not in "don't care" state. */
      98             :     bool                HasRotation() const;
      99             :     /** Sets the control to "don't care" state. */
     100             :     void                SetNoRotation();
     101             : 
     102             :     /** Returns the current rotation angle in 1/100 degrees. */
     103             :     sal_Int32           GetRotation() const;
     104             :     /** Sets the rotation to the passed value (in 1/100 degrees). */
     105             :     void                SetRotation( sal_Int32 nAngle );
     106             : 
     107             :     /** Links the passed numeric edit field to the control (bi-directional).
     108             :      *  nDecimalPlaces:
     109             :      *     field value is usign given decimal places
     110             :      *     default is 0 which means field values are in degrees,
     111             :      *     2 means 100th of degree
     112             :      */
     113             :     void                SetLinkedField( NumericField* pField, sal_Int32 nDecimalPlaces = 0);
     114             : 
     115             :     /** The passed handler is called whenever the totation value changes. */
     116             :     void                SetModifyHdl( const Link<>& rLink );
     117             : 
     118             :     /** Save value for later comparison */
     119             :     void                SaveValue();
     120             : 
     121             :     /** Compare value with the saved value */
     122             :     bool                IsValueModified();
     123             : 
     124             : protected:
     125           1 :     struct DialControl_Impl
     126             :     {
     127             :         ScopedVclPtr<DialControlBmp> mxBmpEnabled;
     128             :         ScopedVclPtr<DialControlBmp> mxBmpDisabled;
     129             :         ScopedVclPtr<DialControlBmp> mxBmpBuffered;
     130             :         Link<>              maModifyHdl;
     131             :         VclPtr<NumericField>       mpLinkField;
     132             :         sal_Int32           mnLinkedFieldValueMultiplyer;
     133             :         Size                maWinSize;
     134             :         vcl::Font           maWinFont;
     135             :         sal_Int32           mnAngle;
     136             :         sal_Int32           mnInitialAngle;
     137             :         sal_Int32           mnOldAngle;
     138             :         long                mnCenterX;
     139             :         long                mnCenterY;
     140             :         bool                mbNoRot;
     141             : 
     142             :         explicit            DialControl_Impl( vcl::Window& rParent );
     143             :         void                Init( const Size& rWinSize, const vcl::Font& rWinFont );
     144             :         void                SetSize( const Size& rWinSize );
     145             :     };
     146             :     std::unique_ptr< DialControl_Impl > mpImpl;
     147             : 
     148             :     virtual void        HandleMouseEvent( const Point& rPos, bool bInitial );
     149             :     void                HandleEscapeEvent();
     150             : 
     151             :     void                SetRotation( sal_Int32 nAngle, bool bBroadcast );
     152             : 
     153             :     void                Init( const Size& rWinSize, const vcl::Font& rWinFont );
     154             :     void                Init( const Size& rWinSize );
     155             : 
     156             : private:
     157             :     void                InvalidateControl();
     158             : 
     159             :     void                ImplSetFieldLink( const Link<>& rLink );
     160             : 
     161             : 
     162             :     DECL_LINK( LinkedFieldModifyHdl, NumericField* );
     163             : };
     164             : 
     165             : /** Wrapper for usage of a DialControl in item connections. */
     166           0 : class SVX_DLLPUBLIC SAL_WARN_UNUSED DialControlWrapper : public sfx::SingleControlWrapper< DialControl, sal_Int32 >
     167             : {
     168             : public:
     169             :     explicit            DialControlWrapper( DialControl& rDial );
     170             : 
     171             :     virtual bool        IsControlDontKnow() const SAL_OVERRIDE;
     172             :     virtual void        SetControlDontKnow( bool bSet ) SAL_OVERRIDE;
     173             : 
     174             :     virtual sal_Int32   GetControlValue() const SAL_OVERRIDE;
     175             :     virtual void        SetControlValue( sal_Int32 nValue ) SAL_OVERRIDE;
     176             : };
     177             : 
     178             : /** An item<->control connection for a DialControl. */
     179             : typedef sfx::ItemControlConnection< sfx::Int32ItemWrapper, DialControlWrapper > DialControlConnection;
     180             : 
     181             : }
     182             : 
     183             : #endif
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11