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 :
21 : #include <string>
22 :
23 : #include <svx/svxids.hrc>
24 : #include <tools/shl.hxx>
25 : #include <svl/eitem.hxx>
26 : #include <sfx2/dispatch.hxx>
27 : #include <sfx2/viewsh.hxx>
28 : #include <sfx2/viewfrm.hxx>
29 : #include <vcl/toolbox.hxx>
30 : #include <osl/mutex.hxx>
31 :
32 : #include <sfx2/imagemgr.hxx>
33 : #include <vcl/svapp.hxx>
34 : #include "svx/tbxcustomshapes.hxx"
35 :
36 108 : SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes, SfxBoolItem);
37 :
38 0 : SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
39 : SfxToolBoxControl( nSlotId, nId, rTbx ),
40 0 : m_aSubTbxResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ) )
41 : {
42 0 : switch( nSlotId )
43 : {
44 : default :
45 : {
46 : DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
47 : }
48 : case SID_DRAWTBX_CS_BASIC :
49 : {
50 0 : m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes.diamond" ) );
51 0 : m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "basicshapes" ) );
52 : }
53 0 : break;
54 :
55 : case SID_DRAWTBX_CS_SYMBOL :
56 : {
57 0 : m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes.smiley" ) );
58 0 : m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "symbolshapes" ) );
59 : }
60 0 : break;
61 :
62 : case SID_DRAWTBX_CS_ARROW :
63 : {
64 0 : m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes.left-right-arrow" ) );
65 0 : m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "arrowshapes" ) );
66 : }
67 0 : break;
68 : case SID_DRAWTBX_CS_FLOWCHART :
69 : {
70 0 : m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes.flowchart-internal-storage" ) );
71 0 : m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flowchartshapes" ) );
72 : }
73 0 : break;
74 : case SID_DRAWTBX_CS_CALLOUT :
75 : {
76 0 : m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes.round-rectangular-callout" ) );
77 0 : m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calloutshapes" ) );
78 : }
79 0 : break;
80 : case SID_DRAWTBX_CS_STAR :
81 : {
82 0 : m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes.star5" ) );
83 0 : m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "starshapes" ) );
84 : }
85 0 : break;
86 : }
87 0 : m_aSubTbxResName += m_aSubTbName;
88 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
89 0 : rTbx.Invalidate();
90 0 : }
91 :
92 : /*************************************************************************
93 : |*
94 : |* Notification when the application status has changed
95 : |*
96 : \************************************************************************/
97 :
98 0 : void SvxTbxCtlCustomShapes::StateChanged( sal_uInt16 nSID, SfxItemState eState,
99 : const SfxPoolItem* pState )
100 : {
101 0 : SfxToolBoxControl::StateChanged( nSID, eState, pState );
102 0 : }
103 :
104 : /*************************************************************************
105 : |*
106 : |* when one wants to create a popup window
107 : |*
108 : \************************************************************************/
109 :
110 0 : SfxPopupWindowType SvxTbxCtlCustomShapes::GetPopupWindowType() const
111 : {
112 0 : return( m_aCommand.isEmpty() ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT);
113 : }
114 :
115 : /*************************************************************************
116 : |*
117 : |* Here is the window created
118 : |* The location of the Toolbox is queried through GetToolBox()
119 : |* rItemRect are the screen coordinates
120 : |*
121 : \************************************************************************/
122 :
123 0 : SfxPopupWindow* SvxTbxCtlCustomShapes::CreatePopupWindow()
124 : {
125 0 : createAndPositionSubToolBar( m_aSubTbxResName );
126 0 : return NULL;
127 : }
128 :
129 : // -----------------------------------------------------------------------
130 :
131 0 : void SvxTbxCtlCustomShapes::Select( sal_Bool /*bMod1*/ )
132 : {
133 0 : if ( !m_aCommand.isEmpty() )
134 : {
135 0 : com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aParamSeq( 0 );
136 0 : Dispatch( m_aCommand, aParamSeq );
137 : }
138 0 : }
139 :
140 :
141 0 : ::sal_Bool SAL_CALL SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
142 : {
143 : // We control a sub-toolbar therefore we have to return true.
144 0 : return sal_True;
145 : }
146 :
147 0 : ::rtl::OUString SAL_CALL SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
148 : {
149 : // Provide the controlled sub-toolbar name, so we are notified whenever
150 : // this toolbar executes a function.
151 0 : return m_aSubTbName;
152 : }
153 :
154 0 : void SAL_CALL SvxTbxCtlCustomShapes::functionSelected( const ::rtl::OUString& rCommand ) throw (::com::sun::star::uno::RuntimeException)
155 : {
156 : // remind the new command
157 0 : m_aCommand = rCommand;
158 : // Our sub-toolbar wants to execute a function.
159 : // We have to change the image of our toolbar button to reflect the new function.
160 0 : SolarMutexGuard aGuard;
161 0 : if ( !m_bDisposed )
162 : {
163 0 : if ( !m_aCommand.isEmpty() )
164 : {
165 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
166 0 : Image aImage = GetImage( xFrame, m_aCommand, hasBigImages() );
167 0 : if ( !!aImage )
168 0 : GetToolBox().SetItemImage( GetId(), aImage );
169 : }
170 0 : }
171 0 : }
172 :
173 0 : void SAL_CALL SvxTbxCtlCustomShapes::updateImage( ) throw (::com::sun::star::uno::RuntimeException)
174 : {
175 : // We should update the button image of our parent (toolbar).
176 : // Use the stored command to set the correct current image.
177 0 : SolarMutexGuard aGuard;
178 0 : if ( !m_aCommand.isEmpty() )
179 : {
180 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
181 0 : Image aImage = GetImage( xFrame, m_aCommand, hasBigImages() );
182 0 : if ( !!aImage )
183 0 : GetToolBox().SetItemImage( GetId(), aImage );
184 0 : }
185 0 : }
186 :
187 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|