bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / drviewsc.cxx
blobd3508a692f97c7523cb9424adf9fc64fb99c7723
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "DrawViewShell.hxx"
21 #include "ViewShellImplementation.hxx"
22 #include <vcl/waitobj.hxx>
24 #include <svx/svxids.hrc>
25 #include <svx/dialogs.hrc>
26 #include <svx/imapdlg.hxx>
27 #include <vcl/msgbox.hxx>
28 #include <sfx2/request.hxx>
29 #include <svx/svdogrp.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/svdograf.hxx>
32 #include <svx/svxdlg.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <svl/style.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svx/grafctrl.hxx>
38 #include "stlsheet.hxx"
40 #include <sfx2/viewfrm.hxx>
42 #include "app.hrc"
43 #include "strings.hrc"
44 #include "helpids.h"
45 #include "Window.hxx"
46 #include "imapinfo.hxx"
47 #include "sdresid.hxx"
48 #include "drawdoc.hxx"
49 #include "DrawDocShell.hxx"
50 #include "drawview.hxx"
51 #include "sdabstdlg.hxx"
52 namespace sd {
54 /**
55 * Returns the global/main ID, i.e. the ID, which is used to execute the toolbox
57 sal_uInt16 DrawViewShell::GetIdBySubId( sal_uInt16 nSId )
59 sal_uInt16 nMappedSId = 0;
60 switch( nSId )
62 case SID_OBJECT_ROTATE:
63 case SID_OBJECT_MIRROR:
64 case SID_OBJECT_TRANSPARENCE:
65 case SID_OBJECT_GRADIENT:
66 case SID_OBJECT_SHEAR:
67 case SID_OBJECT_CROOK_ROTATE:
68 case SID_OBJECT_CROOK_SLANT:
69 case SID_OBJECT_CROOK_STRETCH:
70 case SID_CONVERT_TO_3D_LATHE:
72 nMappedSId = SID_OBJECT_CHOOSE_MODE;
74 break;
76 case SID_OBJECT_ALIGN_LEFT:
77 case SID_OBJECT_ALIGN_CENTER:
78 case SID_OBJECT_ALIGN_RIGHT:
79 case SID_OBJECT_ALIGN_UP:
80 case SID_OBJECT_ALIGN_MIDDLE:
81 case SID_OBJECT_ALIGN_DOWN:
83 nMappedSId = SID_OBJECT_ALIGN;
85 break;
87 case SID_FRAME_TO_TOP:
88 case SID_MOREFRONT:
89 case SID_MOREBACK:
90 case SID_FRAME_TO_BOTTOM:
91 case SID_BEFORE_OBJ:
92 case SID_BEHIND_OBJ:
93 case SID_REVERSE_ORDER:
95 nMappedSId = SID_POSITION;
97 break;
99 case SID_ZOOM_OUT:
100 case SID_ZOOM_IN:
101 case SID_SIZE_REAL:
102 case SID_ZOOM_PANNING:
103 case SID_SIZE_PAGE:
104 case SID_SIZE_PAGE_WIDTH:
105 case SID_SIZE_ALL:
106 case SID_SIZE_OPTIMAL:
107 case SID_ZOOM_NEXT:
108 case SID_ZOOM_PREV:
109 case SID_ZOOM_MODE:
111 nMappedSId = SID_ZOOM_TOOLBOX;
113 break;
115 case SID_ATTR_CHAR:
116 case SID_TEXT_FITTOSIZE:
117 case SID_DRAW_CAPTION:
118 case SID_DRAW_FONTWORK:
119 case SID_DRAW_FONTWORK_VERTICAL:
121 nMappedSId = SID_DRAWTBX_TEXT;
123 break;
125 case SID_DRAW_RECT:
126 case SID_DRAW_SQUARE:
127 case SID_DRAW_RECT_ROUND:
128 case SID_DRAW_SQUARE_ROUND:
129 case SID_DRAW_RECT_NOFILL:
130 case SID_DRAW_SQUARE_NOFILL:
131 case SID_DRAW_RECT_ROUND_NOFILL:
132 case SID_DRAW_SQUARE_ROUND_NOFILL:
134 nMappedSId = SID_DRAWTBX_RECTANGLES;
136 break;
138 case SID_DRAW_ELLIPSE:
139 case SID_DRAW_CIRCLE:
140 case SID_DRAW_PIE:
141 case SID_DRAW_CIRCLEPIE:
142 case SID_DRAW_ELLIPSECUT:
143 case SID_DRAW_CIRCLECUT:
144 case SID_DRAW_ARC:
145 case SID_DRAW_CIRCLEARC:
146 case SID_DRAW_ELLIPSE_NOFILL:
147 case SID_DRAW_CIRCLE_NOFILL:
148 case SID_DRAW_PIE_NOFILL:
149 case SID_DRAW_CIRCLEPIE_NOFILL:
150 case SID_DRAW_ELLIPSECUT_NOFILL:
151 case SID_DRAW_CIRCLECUT_NOFILL:
153 nMappedSId = SID_DRAWTBX_ELLIPSES;
155 break;
157 case SID_DRAW_BEZIER_NOFILL:
158 case SID_DRAW_POLYGON_NOFILL:
159 case SID_DRAW_XPOLYGON_NOFILL:
160 case SID_DRAW_FREELINE_NOFILL:
161 case SID_DRAW_BEZIER_FILL:
162 case SID_DRAW_POLYGON:
163 case SID_DRAW_XPOLYGON:
164 case SID_DRAW_FREELINE:
166 nMappedSId = SID_DRAWTBX_LINES;
168 break;
170 case SID_DRAW_LINE:
171 case SID_DRAW_XLINE:
172 case SID_DRAW_MEASURELINE:
173 case SID_LINE_ARROW_START:
174 case SID_LINE_ARROW_END:
175 case SID_LINE_ARROWS:
176 case SID_LINE_ARROW_CIRCLE:
177 case SID_LINE_CIRCLE_ARROW:
178 case SID_LINE_ARROW_SQUARE:
179 case SID_LINE_SQUARE_ARROW:
181 nMappedSId = SID_DRAWTBX_ARROWS;
183 break;
185 case SID_3D_CUBE:
186 case SID_3D_TORUS:
187 case SID_3D_SPHERE:
188 case SID_3D_SHELL:
189 case SID_3D_HALF_SPHERE:
190 case SID_3D_CYLINDER:
191 case SID_3D_CONE:
192 case SID_3D_PYRAMID:
194 nMappedSId = SID_DRAWTBX_3D_OBJECTS;
196 break;
198 case SID_INSERT_DIAGRAM:
199 case SID_ATTR_TABLE:
200 case SID_INSERTFILE:
201 case SID_INSERT_GRAPHIC:
202 case SID_INSERT_AVMEDIA:
203 case SID_INSERTPAGE:
204 case SID_INSERT_MATH:
205 case SID_INSERT_FLOATINGFRAME:
206 case SID_INSERT_OBJECT:
207 case SID_INSERT_PLUGIN:
208 case SID_INSERT_SOUND:
209 case SID_INSERT_VIDEO:
210 case SID_INSERT_TABLE:
212 nMappedSId = SID_DRAWTBX_INSERT;
214 break;
216 case SID_TOOL_CONNECTOR:
217 case SID_CONNECTOR_ARROW_START:
218 case SID_CONNECTOR_ARROW_END:
219 case SID_CONNECTOR_ARROWS:
220 case SID_CONNECTOR_CIRCLE_START:
221 case SID_CONNECTOR_CIRCLE_END:
222 case SID_CONNECTOR_CIRCLES:
223 case SID_CONNECTOR_LINE:
224 case SID_CONNECTOR_LINE_ARROW_START:
225 case SID_CONNECTOR_LINE_ARROW_END:
226 case SID_CONNECTOR_LINE_ARROWS:
227 case SID_CONNECTOR_LINE_CIRCLE_START:
228 case SID_CONNECTOR_LINE_CIRCLE_END:
229 case SID_CONNECTOR_LINE_CIRCLES:
230 case SID_CONNECTOR_CURVE:
231 case SID_CONNECTOR_CURVE_ARROW_START:
232 case SID_CONNECTOR_CURVE_ARROW_END:
233 case SID_CONNECTOR_CURVE_ARROWS:
234 case SID_CONNECTOR_CURVE_CIRCLE_START:
235 case SID_CONNECTOR_CURVE_CIRCLE_END:
236 case SID_CONNECTOR_CURVE_CIRCLES:
237 case SID_CONNECTOR_LINES:
238 case SID_CONNECTOR_LINES_ARROW_START:
239 case SID_CONNECTOR_LINES_ARROW_END:
240 case SID_CONNECTOR_LINES_ARROWS:
241 case SID_CONNECTOR_LINES_CIRCLE_START:
242 case SID_CONNECTOR_LINES_CIRCLE_END:
243 case SID_CONNECTOR_LINES_CIRCLES:
245 nMappedSId = SID_DRAWTBX_CONNECTORS;
248 return nMappedSId;
252 * Fills the SlotArray in order to get the current mapping of the ToolboxSlots
254 void DrawViewShell::MapSlot( sal_uInt16 nSId )
256 sal_uInt16 nMappedSId = GetIdBySubId( nSId );
258 if( nMappedSId > 0 )
260 sal_uInt16 nID = GetArrayId( nMappedSId ) + 1;
261 mpSlotArray[ nID ] = nSId;
266 * Allows a ImageMapping via SlotArray
268 void DrawViewShell::UpdateToolboxImages( SfxItemSet &rSet, bool bPermanent )
270 if( !bPermanent )
272 sal_uInt16 nId = GetArrayId( SID_ZOOM_TOOLBOX ) + 1;
273 rSet.Put( TbxImageItem( SID_ZOOM_TOOLBOX, mpSlotArray[nId] ) );
275 nId = GetArrayId( SID_DRAWTBX_INSERT ) + 1;
276 rSet.Put( TbxImageItem( SID_DRAWTBX_INSERT, mpSlotArray[nId] ) );
278 nId = GetArrayId( SID_POSITION ) + 1;
279 rSet.Put( TbxImageItem( SID_POSITION, mpSlotArray[nId] ) );
281 nId = GetArrayId( SID_OBJECT_ALIGN ) + 1;
282 rSet.Put( TbxImageItem( SID_OBJECT_ALIGN, mpSlotArray[nId] ) );
284 else
286 for( sal_uInt16 nId = 0; nId < SLOTARRAY_COUNT; nId += 2 )
288 rSet.Put( TbxImageItem( mpSlotArray[nId], mpSlotArray[nId+1] ) );
293 sal_uInt16 DrawViewShell::GetMappedSlot( sal_uInt16 nSId )
295 sal_uInt16 nSlot = 0;
296 sal_uInt16 nId = GetArrayId( nSId );
297 if( nId != USHRT_MAX )
298 nSlot = mpSlotArray[ nId+1 ];
300 /* If the slot is mapped to itself, we have to return 0. Otherwise the slot
301 would be executed over and over again. The slot is initial available in
302 the array in order to show the image correct. */
303 if( nSId == nSlot )
304 return 0;
306 return nSlot;
310 * @returns number of the main slot in the slot array
312 sal_uInt16 DrawViewShell::GetArrayId( sal_uInt16 nSId )
314 for( sal_uInt16 i = 0; i < SLOTARRAY_COUNT; i += 2 )
316 if( mpSlotArray[ i ] == nSId )
317 return i;
319 OSL_FAIL( "Slot in array not found!" );
320 return USHRT_MAX;
323 void DrawViewShell::UpdateIMapDlg( SdrObject* pObj )
325 if( ( pObj->ISA( SdrGrafObj ) || pObj->ISA( SdrOle2Obj ) ) && !mpDrawView->IsTextEdit() &&
326 GetViewFrame()->HasChildWindow( SvxIMapDlgChildWindow::GetChildWindowId() ) )
328 Graphic aGraphic;
329 ImageMap* pIMap = NULL;
330 TargetList* pTargetList = NULL;
331 SdIMapInfo* pIMapInfo = GetDoc()->GetIMapInfo( pObj );
333 // get graphic from shape
334 SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >( pObj );
335 if( pGrafObj )
336 aGraphic = pGrafObj->GetGraphic();
338 if ( pIMapInfo )
340 pIMap = const_cast<ImageMap*>(&pIMapInfo->GetImageMap());
341 pTargetList = new TargetList;
342 GetViewFrame()->GetTargetList( *pTargetList );
345 SvxIMapDlgChildWindow::UpdateIMapDlg( aGraphic, pIMap, pTargetList, pObj );
347 // We can delete the target list
348 if ( pTargetList )
350 delete pTargetList;
355 IMPL_LINK( DrawViewShell, NameObjectHdl, AbstractSvxNameDialog*, pDialog )
357 OUString aName;
359 if( pDialog )
360 pDialog->GetName( aName );
362 return ( aName.isEmpty() || ( GetDoc() && !GetDoc()->GetObj( aName ) ) ) ? 1 : 0;
365 } // end of namespace sd
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */