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
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svl/aeitem.hxx>
27
28 #include <svx/dialmgr.hxx>
29 #include <svx/dialogs.hrc>
30
31 #include "svx/tbxalign.hxx"
32 #include "svx/tbxdraw.hxx"
33 #include "tbxdraw.hrc"
34 #include <tools/shl.hxx>
35 #ifndef _SFX_IMAGEMGR_HXX
36 #include <sfx2/imagemgr.hxx>
37 #endif
38 #include <vcl/svapp.hxx>
39 #include <vos/mutex.hxx>
40
41 #include <sfx2/app.hxx>
42 #include <vcl/toolbox.hxx>
43
44 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlAlign, SfxAllEnumItem);
45
46 /*************************************************************************
47 |*
48 |* Klasse fuer SwToolbox
49 |*
50 \************************************************************************/
51
SvxTbxCtlAlign(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)52 SvxTbxCtlAlign::SvxTbxCtlAlign( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
53 SfxToolBoxControl( nSlotId, nId, rTbx )
54 , m_aSubTbName( RTL_CONSTASCII_USTRINGPARAM( "alignmentbar" ))
55 , m_aSubTbResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/alignmentbar" ))
56 {
57 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
58 rTbx.Invalidate();
59
60 m_aCommand = m_aCommandURL;
61 }
62
63 /*************************************************************************
64 |*
65 |* Wenn man ein PopupWindow erzeugen will
66 |*
67 \************************************************************************/
68
GetPopupWindowType() const69 SfxPopupWindowType SvxTbxCtlAlign::GetPopupWindowType() const
70 {
71 return(SFX_POPUPWINDOW_ONCLICK);
72 }
73
74 /*************************************************************************
75 |*
76 |* Hier wird das Fenster erzeugt
77 |* Lage der Toolbox mit GetToolBox() abfragbar
78 |* rItemRect sind die Screen-Koordinaten
79 |*
80 \************************************************************************/
81
CreatePopupWindow()82 SfxPopupWindow* SvxTbxCtlAlign::CreatePopupWindow()
83 {
84 ::vos::OGuard aGuard( Application::GetSolarMutex() );
85 if ( GetSlotId() == SID_OBJECT_ALIGN )
86 createAndPositionSubToolBar( m_aSubTbResName );
87 return NULL;
88 }
89
90 //========================================================================
91 // XSubToolbarController
92 //========================================================================
93
opensSubToolbar()94 ::sal_Bool SAL_CALL SvxTbxCtlAlign::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
95 {
96 // We control a sub-toolbar therefor, we have to return true.
97 return sal_True;
98 }
99
getSubToolbarName()100 ::rtl::OUString SAL_CALL SvxTbxCtlAlign::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
101 {
102 // Provide the controlled sub-toolbar name, so we are notified whenever
103 // this toolbar executes a function.
104 ::vos::OGuard aGuard( Application::GetSolarMutex() );
105 return m_aSubTbName;
106 }
107
functionSelected(const::rtl::OUString & aCommand)108 void SAL_CALL SvxTbxCtlAlign::functionSelected( const ::rtl::OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException)
109 {
110 // Our sub-toolbar wants to executes a function. We have to change
111 // the image of our toolbar button to reflect the new function.
112 ::vos::OGuard aGuard( Application::GetSolarMutex() );
113 if ( !m_bDisposed )
114 {
115 if ( aCommand.getLength() > 0 )
116 {
117 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
118 Image aImage = GetImage( xFrame, aCommand, hasBigImages(), isHighContrast() );
119 if ( !!aImage )
120 GetToolBox().SetItemImage( GetId(), aImage );
121 }
122 }
123 }
124
updateImage()125 void SAL_CALL SvxTbxCtlAlign::updateImage() throw (::com::sun::star::uno::RuntimeException)
126 {
127 // We should update the button image of our parent (toolbar). Use the stored
128 // command to set the correct current image.
129 ::vos::OGuard aGuard( Application::GetSolarMutex() );
130 if ( m_aCommand.getLength() > 0 )
131 {
132 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
133 Image aImage = GetImage( xFrame, m_aCommand, hasBigImages(), isHighContrast() );
134 if ( !!aImage )
135 GetToolBox().SetItemImage( GetId(), aImage );
136 }
137 }
138