merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / app / tbxww.cxx
blob63021a95e6dca950b508b8b8ab0e9575473d7a1e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbxww.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
35 #include <sfx2/bindings.hxx>
36 #include <svx/svxids.hrc>
37 #include <svx/grafctrl.hxx>
38 #include <svtools/cjkoptions.hxx>
39 #include <sfx2/viewsh.hxx>
40 #ifndef _SFX_IMAGEMGR_HXX
41 #include <sfx2/imagemgr.hxx>
42 #endif
43 #include <rtl/ustring.hxx>
44 #include <rtl/ustrbuf.hxx>
46 #include "sddll.hxx"
47 #include "GraphicDocShell.hxx"
49 #include <vcl/toolbox.hxx>
51 #include "app.hxx"
52 #include "app.hrc"
53 #include "res_bmp.hrc"
54 #include "sdresid.hxx"
55 #include "tbx_ww.hxx"
56 #include "tbx_ww.hrc"
58 SFX_IMPL_TOOLBOX_CONTROL( SdTbxControl, TbxImageItem )
60 /*************************************************************************
62 |* PopUp-Window
64 \************************************************************************/
66 SdPopupWindowTbx::SdPopupWindowTbx( USHORT nId, WindowAlign eAlign,
67 SdResId aRIdWin, SdResId aRIdTbx,
68 SfxBindings& rBindings ) :
69 SfxPopupWindow ( nId, aRIdWin, rBindings ),
70 aTbx ( this, GetBindings(), aRIdTbx ),
71 aSdResIdWin ( aRIdWin ),
72 aSdResIdTbx ( aRIdTbx ),
73 eTbxAlign ( eAlign )
75 aTbx.UseDefault();
76 aSelectLink = aTbx.GetToolBox().GetSelectHdl();
77 aTbx.GetToolBox().SetSelectHdl( LINK( this, SdPopupWindowTbx, TbxSelectHdl ) );
79 FreeResource();
81 if( ( eAlign == WINDOWALIGN_TOP ) || ( eAlign == WINDOWALIGN_BOTTOM ) )
83 if ( aSdResIdWin.GetId() != RID_TEXT )
84 aTbx.GetToolBox().SetAlign( WINDOWALIGN_LEFT );
86 SetText( String() );
89 AdaptToCTL();
93 void SdPopupWindowTbx::AdaptToCTL (void)
95 Size aSize = aTbx.CalcWindowSizePixel();
96 if (aSdResIdWin.GetId() == RID_TEXT)
98 SvtCJKOptions aCJKOptions;
99 if ( ! aCJKOptions.IsVerticalTextEnabled())
101 ToolBox& aToolBox = aTbx.GetToolBox();
103 // Iterate over all tool box items and remove those that are
104 // specific to complex text layout.
105 USHORT i=0;
106 while (i < aToolBox.GetItemCount())
108 USHORT nIndex = aToolBox.GetItemId(i);
109 switch (nIndex)
111 case 0: // Line break.
112 case SID_ATTR_CHAR_VERTICAL:
113 case SID_TEXT_FITTOSIZE_VERTICAL:
114 case SID_DRAW_CAPTION_VERTICAL:
115 case SID_DRAW_FONTWORK_VERTICAL:
116 aToolBox.RemoveItem (i);
117 break;
119 default:
120 // Leave the item unmodified. Advance to the next one.
121 i+=1;
124 aToolBox.RecalcItems();
125 // Why is this necessary?
126 aToolBox.SetLineCount(1);
127 USHORT nLineCount = aToolBox.GetLineCount();
128 aSize = aToolBox.CalcWindowSizePixel(nLineCount);
131 aTbx.SetPosSizePixel( Point(), aSize );
132 SetOutputSizePixel( aSize );
136 /*-------------------------------------------------------------------------*/
138 SdPopupWindowTbx::~SdPopupWindowTbx()
142 /*-------------------------------------------------------------------------*/
144 SfxPopupWindow* SdPopupWindowTbx::Clone() const
146 SfxBindings& rBindings = (SfxBindings&)GetBindings();
148 return( new SdPopupWindowTbx( GetId(), eTbxAlign,
149 aSdResIdWin, aSdResIdTbx, rBindings ) );
151 //return( SfxPopupWindow::Clone() );
154 /*-------------------------------------------------------------------------*/
156 void SdPopupWindowTbx::Update()
158 AdaptToCTL();
160 ToolBox *pBox = &aTbx.GetToolBox();
161 aTbx.Activate( pBox );
162 aTbx.Deactivate( pBox );
165 /*-------------------------------------------------------------------------*/
167 void SdPopupWindowTbx::PopupModeEnd()
169 aTbx.GetToolBox().EndSelection();
171 SfxPopupWindow::PopupModeEnd();
174 /*-------------------------------------------------------------------------*/
176 IMPL_LINK( SdPopupWindowTbx, TbxSelectHdl, ToolBox*, pBox)
178 if( IsInPopupMode() )
179 EndPopupMode();
181 aSelectLink.Call( &aTbx.GetToolBox() );
183 if ( pBox->GetModifier() & KEY_MOD1 )
185 // #99013# if selected with control key, return focus to current view
186 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
187 if ( pShellWnd )
188 pShellWnd->GrabFocus();
191 return( 0L );
194 /*************************************************************************
196 |* Klasse fuer Toolbox
198 \************************************************************************/
200 SdTbxControl::SdTbxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :
201 SfxToolBoxControl( nSlotId, nId, rTbx )
203 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
204 rTbx.Invalidate();
207 /*-------------------------------------------------------------------------*/
209 SfxPopupWindowType SdTbxControl::GetPopupWindowType() const
211 return( SFX_POPUPWINDOW_ONTIMEOUT );
214 /*************************************************************************
216 |* Hier wird das Fenster erzeugt
217 |* Lage der Toolbox mit GetToolBox() abfragbar
218 |* rItemRect sind die Screen-Koordinaten
220 \************************************************************************/
222 SfxPopupWindow* SdTbxControl::CreatePopupWindow()
224 SfxPopupWindow *pWin = NULL;
225 rtl::OUString aToolBarResStr;
226 rtl::OUStringBuffer aTbxResName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" )));
227 switch( GetSlotId() )
229 case SID_OBJECT_ALIGN:
230 aTbxResName.appendAscii( "alignmentbar" );
231 aToolBarResStr = aTbxResName.makeStringAndClear();
232 break;
233 case SID_ZOOM_TOOLBOX:
234 aTbxResName.appendAscii( "zoombar" );
235 aToolBarResStr = aTbxResName.makeStringAndClear();
236 break;
237 case SID_OBJECT_CHOOSE_MODE:
238 aTbxResName.appendAscii( "choosemodebar" );
239 aToolBarResStr = aTbxResName.makeStringAndClear();
240 break;
241 case SID_POSITION:
242 aTbxResName.appendAscii( "positionbar" );
243 aToolBarResStr = aTbxResName.makeStringAndClear();
244 break;
245 case SID_DRAWTBX_TEXT:
246 aTbxResName.appendAscii( "textbar" );
247 aToolBarResStr = aTbxResName.makeStringAndClear();
248 break;
249 case SID_DRAWTBX_RECTANGLES:
250 aTbxResName.appendAscii( "rectanglesbar" );
251 aToolBarResStr = aTbxResName.makeStringAndClear();
252 break;
253 case SID_DRAWTBX_ELLIPSES:
254 aTbxResName.appendAscii( "ellipsesbar" );
255 aToolBarResStr = aTbxResName.makeStringAndClear();
256 break;
257 case SID_DRAWTBX_LINES:
258 aTbxResName.appendAscii( "linesbar" );
259 aToolBarResStr = aTbxResName.makeStringAndClear();
260 break;
261 case SID_DRAWTBX_ARROWS:
262 aTbxResName.appendAscii( "arrowsbar" );
263 aToolBarResStr = aTbxResName.makeStringAndClear();
264 break;
265 case SID_DRAWTBX_3D_OBJECTS:
266 aTbxResName.appendAscii( "3dobjectsbar" );
267 aToolBarResStr = aTbxResName.makeStringAndClear();
268 break;
269 case SID_DRAWTBX_CONNECTORS:
270 aTbxResName.appendAscii( "connectorsbar" );
271 aToolBarResStr = aTbxResName.makeStringAndClear();
272 break;
273 case SID_DRAWTBX_INSERT:
274 aTbxResName.appendAscii( "insertbar" );
275 aToolBarResStr = aTbxResName.makeStringAndClear();
276 break;
279 if ( aToolBarResStr.getLength() > 0 )
280 createAndPositionSubToolBar( aToolBarResStr );
282 return( pWin );
285 /*-------------------------------------------------------------------------*/
287 void SdTbxControl::StateChanged( USHORT nSId,
288 SfxItemState eState, const SfxPoolItem* pState )
290 SfxToolBoxControl::StateChanged( nSId, eState, pState );
292 if( eState == SFX_ITEM_AVAILABLE )
294 TbxImageItem* pItem = PTR_CAST( TbxImageItem, pState );
295 //DBG_ASSERT( pItem, "TbxImageItem erwartet!" );
296 // Im StarDesktop kann jetzt auch ein anderes Item ankommen,
297 // das nicht ausgewertet werden darf (#33802# und #33838#)
298 if( pItem )
300 ToolBox& rTbx = GetToolBox();
301 USHORT nImage = pItem->GetValue();
302 if( nImage == 0 )
304 if( rTbx.IsItemChecked( nSId ) )
305 rTbx.CheckItem( nSId, FALSE );
307 else
309 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
310 aSlotURL += rtl::OUString::valueOf( sal_Int32( nImage ));
311 Image aImage = GetImage( m_xFrame,
312 aSlotURL,
313 hasBigImages(),
314 GetToolBox().GetDisplayBackground().GetColor().IsDark() );
316 // !-Operator prueft, ob Image nicht vorhanden ist
317 if( !!aImage )
319 rTbx.SetItemImage( GetId(), aImage );
320 rTbx.CheckItem( GetId(), IsCheckable( nImage ) );
322 if( nSId != SID_ZOOM_TOOLBOX &&
323 nSId != SID_DRAWTBX_INSERT &&
324 nSId != SID_POSITION &&
325 nSId != SID_OBJECT_ALIGN )
327 if( nSId != SID_OBJECT_CHOOSE_MODE &&
328 rTbx.IsItemChecked( SID_OBJECT_CHOOSE_MODE ) )
329 rTbx.CheckItem( SID_OBJECT_CHOOSE_MODE, FALSE );
330 if( nSId != SID_DRAWTBX_TEXT &&
331 rTbx.IsItemChecked( SID_DRAWTBX_TEXT ) )
332 rTbx.CheckItem( SID_DRAWTBX_TEXT, FALSE );
333 if( nSId != SID_DRAWTBX_RECTANGLES &&
334 rTbx.IsItemChecked( SID_DRAWTBX_RECTANGLES ) )
335 rTbx.CheckItem( SID_DRAWTBX_RECTANGLES, FALSE );
336 if( nSId != SID_DRAWTBX_ELLIPSES &&
337 rTbx.IsItemChecked( SID_DRAWTBX_ELLIPSES ) )
338 rTbx.CheckItem( SID_DRAWTBX_ELLIPSES, FALSE );
339 if( nSId != SID_DRAWTBX_LINES &&
340 rTbx.IsItemChecked( SID_DRAWTBX_LINES ) )
341 rTbx.CheckItem( SID_DRAWTBX_LINES, FALSE );
342 if( nSId != SID_DRAWTBX_ARROWS &&
343 rTbx.IsItemChecked( SID_DRAWTBX_ARROWS ) )
344 rTbx.CheckItem( SID_DRAWTBX_ARROWS, FALSE );
345 if( nSId != SID_DRAWTBX_3D_OBJECTS &&
346 rTbx.IsItemChecked( SID_DRAWTBX_3D_OBJECTS ) )
347 rTbx.CheckItem( SID_DRAWTBX_3D_OBJECTS, FALSE );
348 if( nSId != SID_DRAWTBX_CONNECTORS &&
349 rTbx.IsItemChecked( SID_DRAWTBX_CONNECTORS ) )
350 rTbx.CheckItem( SID_DRAWTBX_CONNECTORS, FALSE );
358 /*-------------------------------------------------------------------------*/
360 BOOL SdTbxControl::IsCheckable( USHORT nSId )
362 switch( nSId )
364 case SID_OBJECT_ROTATE:
365 case SID_OBJECT_MIRROR:
366 case SID_OBJECT_CROP:
367 case SID_OBJECT_TRANSPARENCE:
368 case SID_OBJECT_GRADIENT:
369 case SID_OBJECT_SHEAR:
370 case SID_OBJECT_CROOK_ROTATE:
371 case SID_OBJECT_CROOK_SLANT:
372 case SID_OBJECT_CROOK_STRETCH:
373 case SID_CONVERT_TO_3D_LATHE:
375 case SID_ATTR_CHAR:
376 case SID_ATTR_CHAR_VERTICAL:
377 case SID_TEXT_FITTOSIZE:
378 case SID_TEXT_FITTOSIZE_VERTICAL:
379 case SID_DRAW_CAPTION:
380 case SID_DRAW_CAPTION_VERTICAL:
381 case SID_DRAW_FONTWORK:
382 case SID_DRAW_FONTWORK_VERTICAL:
384 case SID_DRAW_RECT:
385 case SID_DRAW_SQUARE:
386 case SID_DRAW_RECT_ROUND:
387 case SID_DRAW_SQUARE_ROUND:
388 case SID_DRAW_RECT_NOFILL:
389 case SID_DRAW_SQUARE_NOFILL:
390 case SID_DRAW_RECT_ROUND_NOFILL:
391 case SID_DRAW_SQUARE_ROUND_NOFILL:
393 case SID_DRAW_ELLIPSE:
394 case SID_DRAW_CIRCLE:
395 case SID_DRAW_PIE:
396 case SID_DRAW_CIRCLEPIE:
397 case SID_DRAW_ELLIPSECUT:
398 case SID_DRAW_CIRCLECUT:
399 case SID_DRAW_ARC:
400 case SID_DRAW_CIRCLEARC:
401 case SID_DRAW_ELLIPSE_NOFILL:
402 case SID_DRAW_CIRCLE_NOFILL:
403 case SID_DRAW_PIE_NOFILL:
404 case SID_DRAW_CIRCLEPIE_NOFILL:
405 case SID_DRAW_ELLIPSECUT_NOFILL:
406 case SID_DRAW_CIRCLECUT_NOFILL:
408 case SID_DRAW_BEZIER_NOFILL:
409 case SID_DRAW_POLYGON_NOFILL:
410 case SID_DRAW_XPOLYGON_NOFILL:
411 case SID_DRAW_BEZIER_FILL:
412 case SID_DRAW_POLYGON:
413 case SID_DRAW_XPOLYGON:
414 case SID_DRAW_FREELINE:
415 case SID_DRAW_FREELINE_NOFILL:
417 case SID_DRAW_LINE:
418 case SID_DRAW_XLINE:
419 case SID_DRAW_MEASURELINE:
420 case SID_LINE_ARROW_START:
421 case SID_LINE_ARROW_END:
422 case SID_LINE_ARROWS:
423 case SID_LINE_ARROW_CIRCLE:
424 case SID_LINE_CIRCLE_ARROW:
425 case SID_LINE_ARROW_SQUARE:
426 case SID_LINE_SQUARE_ARROW:
428 case SID_3D_CUBE:
429 case SID_3D_SPHERE:
430 case SID_3D_CYLINDER:
431 case SID_3D_CONE:
432 case SID_3D_PYRAMID:
433 case SID_3D_TORUS:
434 case SID_3D_SHELL:
435 case SID_3D_HALF_SPHERE:
437 case SID_TOOL_CONNECTOR:
438 case SID_CONNECTOR_ARROW_START:
439 case SID_CONNECTOR_ARROW_END:
440 case SID_CONNECTOR_ARROWS:
441 case SID_CONNECTOR_CIRCLE_START:
442 case SID_CONNECTOR_CIRCLE_END:
443 case SID_CONNECTOR_CIRCLES:
444 case SID_CONNECTOR_LINE:
445 case SID_CONNECTOR_LINE_ARROW_START:
446 case SID_CONNECTOR_LINE_ARROW_END:
447 case SID_CONNECTOR_LINE_ARROWS:
448 case SID_CONNECTOR_LINE_CIRCLE_START:
449 case SID_CONNECTOR_LINE_CIRCLE_END:
450 case SID_CONNECTOR_LINE_CIRCLES:
451 case SID_CONNECTOR_CURVE:
452 case SID_CONNECTOR_CURVE_ARROW_START:
453 case SID_CONNECTOR_CURVE_ARROW_END:
454 case SID_CONNECTOR_CURVE_ARROWS:
455 case SID_CONNECTOR_CURVE_CIRCLE_START:
456 case SID_CONNECTOR_CURVE_CIRCLE_END:
457 case SID_CONNECTOR_CURVE_CIRCLES:
458 case SID_CONNECTOR_LINES:
459 case SID_CONNECTOR_LINES_ARROW_START:
460 case SID_CONNECTOR_LINES_ARROW_END:
461 case SID_CONNECTOR_LINES_ARROWS:
462 case SID_CONNECTOR_LINES_CIRCLE_START:
463 case SID_CONNECTOR_LINES_CIRCLE_END:
464 case SID_CONNECTOR_LINES_CIRCLES:
468 //case SID_ZOOM_OUT:
469 return( TRUE );
471 return( FALSE );