1  /**************************************************************
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   *************************************************************/
21  
22  #ifndef SVX_PROPERTYPANEL_POSIZEPAGE_HXX
23  #define SVX_PROPERTYPANEL_POSIZEPAGE_HXX
24  
25  #include <vcl/ctrl.hxx>
26  #include <sfx2/sidebar/SidebarPanelBase.hxx>
27  #include <sfx2/sidebar/ControllerItem.hxx>
28  #include <sfx2/sidebar/IContextChangeReceiver.hxx>
29  #include <sfx2/sidebar/GridLayouter.hxx>
30  #include <boost/scoped_ptr.hpp>
31  #include <svx/rectenum.hxx>
32  #include <svl/poolitem.hxx>
33  #include <tools/fldunit.hxx>
34  #include <com/sun/star/ui/XSidebar.hpp>
35  
36  class DialControl;
37  class SdrView;
38  class FixedText;
39  class MetricField;
40  class CheckBox;
41  class MetricBox;
42  
43  
44  namespace svx { namespace sidebar {
45  
46  class SidebarDialControl;
47  
48  class PosSizePropertyPanel
49  :   public Control,
50      public ::sfx2::sidebar::IContextChangeReceiver,
51      public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface
52  {
53  public:
54      static PosSizePropertyPanel* Create(
55          Window* pParent,
56          const cssu::Reference<css::frame::XFrame>& rxFrame,
57          SfxBindings* pBindings,
58          const cssu::Reference<css::ui::XSidebar>& rxSidebar);
59  
60      virtual void DataChanged(
61          const DataChangedEvent& rEvent);
62  
63      virtual void HandleContextChange(
64          const ::sfx2::sidebar::EnumContext aContext);
65  
66      virtual void NotifyItemUpdate(
67          const sal_uInt16 nSId,
68          const SfxItemState eState,
69          const SfxPoolItem* pState,
70          const bool bIsEnabled);
71  
72      SfxBindings* GetBindings();
73      void ShowMenu (void);
74  
75      virtual void Resize (void);
76  
77  private:
78      //Position
79      ::boost::scoped_ptr< FixedText >        mpFtPosX;
80      ::boost::scoped_ptr< MetricField >      mpMtrPosX;
81      ::boost::scoped_ptr< FixedText >        mpFtPosY;
82      ::boost::scoped_ptr< MetricField >      mpMtrPosY;
83  
84      // size
85      ::boost::scoped_ptr< FixedText >        mpFtWidth;
86      ::boost::scoped_ptr< MetricField >      mpMtrWidth;
87      ::boost::scoped_ptr< FixedText >        mpFtHeight;
88      ::boost::scoped_ptr< MetricField >      mpMtrHeight;
89      ::boost::scoped_ptr< CheckBox >         mpCbxScale;
90  
91      //rotation
92      ::boost::scoped_ptr< FixedText >        mpFtAngle;
93      ::boost::scoped_ptr< MetricBox >        mpMtrAngle;
94  
95      //rotation control
96      ::boost::scoped_ptr<SidebarDialControl> mpDial;
97  
98      //flip
99      ::boost::scoped_ptr< FixedText >        mpFtFlip;
100      ::boost::scoped_ptr< Window >           mpFlipTbxBackground;
101      ::boost::scoped_ptr< ToolBox >          mpFlipTbx;
102  
103      // Internal variables
104      Rectangle                               maRect;
105      const SdrView*                          mpView;
106      sal_uInt32                              mlOldWidth;
107      sal_uInt32                              mlOldHeight;
108      RECT_POINT                              meRP;
109      Point                                   maAnchorPos;    //anchor position
110      long                                    mlRotX;
111      long                                    mlRotY;
112      Fraction                                maUIScale;
113      SfxMapUnit                              mePoolUnit;
114      FieldUnit                               meDlgUnit;
115  
116      // Controller Items
117      ::sfx2::sidebar::ControllerItem         maTransfPosXControl;
118      ::sfx2::sidebar::ControllerItem         maTransfPosYControl;
119      ::sfx2::sidebar::ControllerItem         maTransfWidthControl;
120      ::sfx2::sidebar::ControllerItem         maTransfHeightControl;
121  
122      ::sfx2::sidebar::ControllerItem         maSvxAngleControl;
123      ::sfx2::sidebar::ControllerItem         maRotXControl;
124      ::sfx2::sidebar::ControllerItem         maRotYControl;
125      ::sfx2::sidebar::ControllerItem         maProPosControl;
126      ::sfx2::sidebar::ControllerItem         maProSizeControl;
127      ::sfx2::sidebar::ControllerItem         maAutoWidthControl;
128      ::sfx2::sidebar::ControllerItem         maAutoHeightControl;
129      ::sfx2::sidebar::ControllerItem         m_aMetricCtl;
130  
131      cssu::Reference< css::frame::XFrame >   mxFrame;
132      ::sfx2::sidebar::EnumContext            maContext;
133      SfxBindings*                            mpBindings;
134  
135      // to remember original positions for restoring these for different layouts
136      Point                                   maFtWidthOrigPos;
137      Point                                   maMtrWidthOrigPos;
138      Point                                   maFtHeightOrigPos;
139      Point                                   maMtrHeightOrigPos;
140      Point                                   maCbxScaleOrigPos;
141      Point                                   maFtAngleOrigPos;
142      Point                                   maMtrAnglOrigPos;
143      Point                                   maFlipTbxOrigPos;
144      Point                                   maDialOrigPos;
145      Point                                   maFtFlipOrigPos;
146  
147      /// bitfield
148      bool                                    mbMtrPosXMirror : 1;
149      bool                                    mbSizeProtected : 1;
150      bool                                    mbPositionProtected : 1;
151      bool                                    mbAutoWidth : 1;
152      bool                                    mbAutoHeight : 1;
153      bool                                    mbAdjustEnabled : 1;
154      bool                                    mbIsFlip : 1;
155  
156      cssu::Reference<css::ui::XSidebar> mxSidebar;
157      ::sfx2::sidebar::GridLayouter maLayouter;
158  
159      DECL_LINK( ChangePosXHdl, void * );
160      DECL_LINK( ChangePosYHdl, void * );
161      DECL_LINK( ChangeWidthHdl, void * );
162      DECL_LINK( ChangeHeightHdl, void * );
163      DECL_LINK( ClickAutoHdl, void * );
164      DECL_LINK( AngleModifiedHdl, void * );
165      DECL_LINK( RotationHdl, void * );
166      DECL_LINK( FlipHdl, ToolBox * );
167  
168      void SetupIcons(void);
169      void Initialize();
170      void executePosX();
171      void executePosY();
172      void executeSize();
173  
174      // constructor/destuctor
175      PosSizePropertyPanel(
176          Window* pParent,
177          const cssu::Reference<css::frame::XFrame>& rxFrame,
178          SfxBindings* pBindings,
179          const cssu::Reference<css::ui::XSidebar>& rxSidebar);
180      virtual ~PosSizePropertyPanel();
181  
182      void MetricState( SfxItemState eState, const SfxPoolItem* pState );
183      FieldUnit GetCurrentUnit( SfxItemState eState, const SfxPoolItem* pState );
184      void DisableControls();
185      void AdaptWidthHeightScalePosition(bool bOriginal);
186      void AdaptAngleFlipDialPosition(bool bOriginal);
187  
188      /** Check if the UI scale has changed and handle such a change.
189          UI scale is an SD only feature.  The UI scale is represented by items
190          ATTR_OPTIONS_SCALE_X and
191          ATTR_OPTIONS_SCALE_Y.
192          As we have no direct access (there is no dependency of svx on sd) we have to
193          use a small trick (aka hack):
194          a) call this method whenever a change of the metric item is notified,
195          b) check if the UI scale has changed (strangely, the UI scale value is available at the SdrModel.
196          c) invalidate the items for position and size to trigger notifications of their current values.
197      */
198      void UpdateUIScale (void);
199  };
200  
201  
202  } } // end of namespace svx::sidebar
203  
204  
205  
206  #endif // SVX_PROPERTYPANEL_POSIZEPAGE_HXX
207  
208  // eof
209