xref: /aoo4110/main/sd/source/ui/app/tbxww.cxx (revision b1cdbd2c)
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_sd.hxx"
26 
27 
28 #include <sfx2/bindings.hxx>
29 #include <svx/svxids.hrc>
30 #include <svx/grafctrl.hxx>
31 #include <svl/cjkoptions.hxx>
32 #include <sfx2/viewsh.hxx>
33 #ifndef _SFX_IMAGEMGR_HXX
34 #include <sfx2/imagemgr.hxx>
35 #endif
36 #include <rtl/ustring.hxx>
37 #include <rtl/ustrbuf.hxx>
38 
39 #include "sddll.hxx"
40 #include "GraphicDocShell.hxx"
41 
42 #include <vcl/toolbox.hxx>
43 
44 #include "app.hxx"
45 #include "app.hrc"
46 #include "res_bmp.hrc"
47 #include "sdresid.hxx"
48 #include "tbx_ww.hxx"
49 #include "tbx_ww.hrc"
50 
SFX_IMPL_TOOLBOX_CONTROL(SdTbxControl,TbxImageItem)51 SFX_IMPL_TOOLBOX_CONTROL( SdTbxControl, TbxImageItem )
52 
53 /*************************************************************************
54 |*
55 |* PopUp-Window
56 |*
57 \************************************************************************/
58 /*
59 SdPopupWindowTbx::SdPopupWindowTbx( sal_uInt16 nId, WindowAlign eAlign,
60                                     SdResId aRIdWin, SdResId aRIdTbx,
61 									SfxBindings& rBindings ) :
62 				SfxPopupWindow	( nId, aRIdWin, rBindings ),
63                 aTbx            ( this, GetBindings(), aRIdTbx ),
64                 aSdResIdWin       ( aRIdWin ),
65                 aSdResIdTbx       ( aRIdTbx ),
66 				eTbxAlign		( eAlign )
67 {
68 	aTbx.UseDefault();
69 	aSelectLink = aTbx.GetToolBox().GetSelectHdl();
70 	aTbx.GetToolBox().SetSelectHdl( LINK( this, SdPopupWindowTbx, TbxSelectHdl ) );
71 
72 	FreeResource();
73 
74 	if( ( eAlign == WINDOWALIGN_TOP ) || ( eAlign == WINDOWALIGN_BOTTOM ) )
75 	{
76         if ( aSdResIdWin.GetId() != RID_TEXT )
77 	        aTbx.GetToolBox().SetAlign( WINDOWALIGN_LEFT );
78 
79         SetText( String() );
80 	}
81 
82     AdaptToCTL();
83 }
84 
85 
86 void SdPopupWindowTbx::AdaptToCTL (void)
87 {
88 	Size aSize = aTbx.CalcWindowSizePixel();
89 	if (aSdResIdWin.GetId() == RID_TEXT)
90 	{
91         SvtCJKOptions aCJKOptions;
92         if ( ! aCJKOptions.IsVerticalTextEnabled())
93         {
94             ToolBox& aToolBox = aTbx.GetToolBox();
95 
96             // Iterate over all tool box items and remove those that are
97             // specific to complex text layout.
98             sal_uInt16 i=0;
99             while (i < aToolBox.GetItemCount())
100             {
101                 sal_uInt16 nIndex = aToolBox.GetItemId(i);
102                 switch (nIndex)
103                 {
104                     case 0: // Line break.
105                     case SID_ATTR_CHAR_VERTICAL:
106                     case SID_TEXT_FITTOSIZE_VERTICAL:
107                     case SID_DRAW_CAPTION_VERTICAL:
108 					case SID_DRAW_FONTWORK_VERTICAL:
109                         aToolBox.RemoveItem (i);
110                         break;
111 
112                     default:
113                         // Leave the item unmodified.  Advance to the next one.
114                         i+=1;
115                 }
116             }
117             aToolBox.RecalcItems();
118             // Why is this necessary?
119             aToolBox.SetLineCount(1);
120             sal_uInt16 nLineCount = aToolBox.GetLineCount();
121             aSize = aToolBox.CalcWindowSizePixel(nLineCount);
122         }
123     }
124 	aTbx.SetPosSizePixel( Point(), aSize );
125 	SetOutputSizePixel( aSize );
126 }
127 */
128 
129 /*-------------------------------------------------------------------------*/
130 /*
131 SdPopupWindowTbx::~SdPopupWindowTbx()
132 {
133 }
134 */
135 /*-------------------------------------------------------------------------*/
136 /*
137 SfxPopupWindow* SdPopupWindowTbx::Clone() const
138 {
139 	SfxBindings& rBindings = (SfxBindings&)GetBindings();
140 
141 	return( new SdPopupWindowTbx( GetId(), eTbxAlign,
142                     aSdResIdWin, aSdResIdTbx, rBindings ) );
143 
144 	//return( SfxPopupWindow::Clone() );
145 }
146 */
147 /*-------------------------------------------------------------------------*/
148 /*
149 void SdPopupWindowTbx::Update()
150 {
151     AdaptToCTL();
152 
153 	ToolBox *pBox = &aTbx.GetToolBox();
154 	aTbx.Activate( pBox );
155 	aTbx.Deactivate( pBox );
156 }
157 */
158 /*-------------------------------------------------------------------------*/
159 /*
160 void SdPopupWindowTbx::PopupModeEnd()
161 {
162 	aTbx.GetToolBox().EndSelection();
163 
164 	SfxPopupWindow::PopupModeEnd();
165 }
166 */
167 /*-------------------------------------------------------------------------*/
168 /*
169 IMPL_LINK( SdPopupWindowTbx, TbxSelectHdl, ToolBox*, pBox)
170 {
171 	if( IsInPopupMode() )
172 		EndPopupMode();
173 
174 	aSelectLink.Call( &aTbx.GetToolBox() );
175 
176 	if ( pBox->GetModifier() & KEY_MOD1 )
177 	{
178 		//	#99013# if selected with control key, return focus to current view
179 		Window* pShellWnd = SfxViewShell::Current()->GetWindow();
180 		if ( pShellWnd )
181 			pShellWnd->GrabFocus();
182 	}
183 
184 	return( 0L );
185 }
186 */
187 /*************************************************************************
188 |*
189 |* Klasse fuer Toolbox
190 |*
191 \************************************************************************/
192 
193 SdTbxControl::SdTbxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
194 		SfxToolBoxControl( nSlotId, nId, rTbx )
195 {
196 	rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
197 	rTbx.Invalidate();
198 }
199 
200 /*-------------------------------------------------------------------------*/
201 
GetPopupWindowType() const202 SfxPopupWindowType SdTbxControl::GetPopupWindowType() const
203 {
204 	return( SFX_POPUPWINDOW_ONTIMEOUT );
205 }
206 
207 /*************************************************************************
208 |*
209 |* Hier wird das Fenster erzeugt
210 |* Lage der Toolbox mit GetToolBox() abfragbar
211 |* rItemRect sind die Screen-Koordinaten
212 |*
213 \************************************************************************/
214 
CreatePopupWindow()215 SfxPopupWindow*	SdTbxControl::CreatePopupWindow()
216 {
217 	SfxPopupWindow *pWin = NULL;
218     rtl::OUString aToolBarResStr;
219     rtl::OUStringBuffer aTbxResName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" )));
220 	switch( GetSlotId() )
221 	{
222         case SID_OBJECT_ALIGN:
223             aTbxResName.appendAscii( "alignmentbar" );
224             aToolBarResStr = aTbxResName.makeStringAndClear();
225         break;
226 		case SID_ZOOM_TOOLBOX:
227             aTbxResName.appendAscii( "zoombar" );
228             aToolBarResStr = aTbxResName.makeStringAndClear();
229 		break;
230 		case SID_OBJECT_CHOOSE_MODE:
231             aTbxResName.appendAscii( "choosemodebar" );
232             aToolBarResStr = aTbxResName.makeStringAndClear();
233 		break;
234 		case SID_POSITION:
235             aTbxResName.appendAscii( "positionbar" );
236             aToolBarResStr = aTbxResName.makeStringAndClear();
237 		break;
238 		case SID_DRAWTBX_TEXT:
239             aTbxResName.appendAscii( "textbar" );
240             aToolBarResStr = aTbxResName.makeStringAndClear();
241 		break;
242 		case SID_DRAWTBX_RECTANGLES:
243             aTbxResName.appendAscii( "rectanglesbar" );
244             aToolBarResStr = aTbxResName.makeStringAndClear();
245 		break;
246 		case SID_DRAWTBX_ELLIPSES:
247             aTbxResName.appendAscii( "ellipsesbar" );
248             aToolBarResStr = aTbxResName.makeStringAndClear();
249 		break;
250 		case SID_DRAWTBX_LINES:
251             aTbxResName.appendAscii( "linesbar" );
252             aToolBarResStr = aTbxResName.makeStringAndClear();
253 		break;
254 		case SID_DRAWTBX_ARROWS:
255             aTbxResName.appendAscii( "arrowsbar" );
256             aToolBarResStr = aTbxResName.makeStringAndClear();
257 		break;
258 		case SID_DRAWTBX_3D_OBJECTS:
259             aTbxResName.appendAscii( "3dobjectsbar" );
260             aToolBarResStr = aTbxResName.makeStringAndClear();
261 		break;
262         case SID_DRAWTBX_CONNECTORS:
263             aTbxResName.appendAscii( "connectorsbar" );
264             aToolBarResStr = aTbxResName.makeStringAndClear();
265 		break;
266         case SID_DRAWTBX_INSERT:
267             aTbxResName.appendAscii( "insertbar" );
268             aToolBarResStr = aTbxResName.makeStringAndClear();
269 		break;
270     }
271 
272     if ( aToolBarResStr.getLength() > 0 )
273         createAndPositionSubToolBar( aToolBarResStr );
274 
275 	return( pWin );
276 }
277 
278 /*-------------------------------------------------------------------------*/
279 
StateChanged(sal_uInt16 nSId,SfxItemState eState,const SfxPoolItem * pState)280 void SdTbxControl::StateChanged( sal_uInt16 nSId,
281 						SfxItemState eState, const SfxPoolItem* pState )
282 {
283 	SfxToolBoxControl::StateChanged( nSId, eState, pState );
284 
285 	if( eState == SFX_ITEM_AVAILABLE )
286 	{
287 		TbxImageItem* pItem = PTR_CAST( TbxImageItem, pState );
288 		//DBG_ASSERT( pItem, "TbxImageItem erwartet!" );
289 		// Im StarDesktop kann jetzt auch ein anderes Item ankommen,
290 		// das nicht ausgewertet werden darf (#33802# und #33838#)
291 		if( pItem )
292 		{
293 			ToolBox& rTbx = GetToolBox();
294 			sal_uInt16 nImage = pItem->GetValue();
295 			if( nImage == 0 )
296 			{
297 				if( rTbx.IsItemChecked( nSId ) )
298 					rTbx.CheckItem( nSId, sal_False );
299 			}
300 			else
301 			{
302                 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
303                 aSlotURL += rtl::OUString::valueOf( sal_Int32( nImage ));
304                 Image aImage = GetImage( m_xFrame,
305                                          aSlotURL,
306                                          hasBigImages(),
307                                          GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode() );
308 
309 				// !-Operator prueft, ob Image nicht vorhanden ist
310 				if( !!aImage )
311 				{
312 					rTbx.SetItemImage( GetId(), aImage );
313 					rTbx.CheckItem( GetId(), IsCheckable( nImage ) );
314 
315 					if( nSId != SID_ZOOM_TOOLBOX &&
316 						nSId != SID_DRAWTBX_INSERT &&
317 						nSId != SID_POSITION &&
318 						nSId != SID_OBJECT_ALIGN )
319 					{
320 						if( nSId != SID_OBJECT_CHOOSE_MODE &&
321 							rTbx.IsItemChecked( SID_OBJECT_CHOOSE_MODE ) )
322 							rTbx.CheckItem( SID_OBJECT_CHOOSE_MODE, sal_False );
323 						if( nSId != SID_DRAWTBX_TEXT &&
324 							rTbx.IsItemChecked( SID_DRAWTBX_TEXT ) )
325 			 				rTbx.CheckItem( SID_DRAWTBX_TEXT, sal_False );
326 						if( nSId != SID_DRAWTBX_RECTANGLES &&
327 							rTbx.IsItemChecked( SID_DRAWTBX_RECTANGLES ) )
328 			   				rTbx.CheckItem( SID_DRAWTBX_RECTANGLES, sal_False );
329 						if( nSId != SID_DRAWTBX_ELLIPSES &&
330 							rTbx.IsItemChecked( SID_DRAWTBX_ELLIPSES ) )
331 			   				rTbx.CheckItem( SID_DRAWTBX_ELLIPSES, sal_False );
332 						if( nSId != SID_DRAWTBX_LINES &&
333 							rTbx.IsItemChecked( SID_DRAWTBX_LINES ) )
334 							rTbx.CheckItem( SID_DRAWTBX_LINES, sal_False );
335 						if( nSId != SID_DRAWTBX_ARROWS &&
336 							rTbx.IsItemChecked( SID_DRAWTBX_ARROWS ) )
337 							rTbx.CheckItem( SID_DRAWTBX_ARROWS, sal_False );
338 						if( nSId != SID_DRAWTBX_3D_OBJECTS &&
339 							rTbx.IsItemChecked( SID_DRAWTBX_3D_OBJECTS ) )
340 							rTbx.CheckItem( SID_DRAWTBX_3D_OBJECTS, sal_False );
341                         if( nSId != SID_DRAWTBX_CONNECTORS &&
342                             rTbx.IsItemChecked( SID_DRAWTBX_CONNECTORS ) )
343                             rTbx.CheckItem( SID_DRAWTBX_CONNECTORS, sal_False );
344                     }
345 				}
346 			}
347 		}
348 	}
349 }
350 
351 /*-------------------------------------------------------------------------*/
352 
IsCheckable(sal_uInt16 nSId)353 sal_Bool SdTbxControl::IsCheckable( sal_uInt16 nSId )
354 {
355 	switch( nSId )
356 	{
357 		case SID_OBJECT_ROTATE:
358 		case SID_OBJECT_MIRROR:
359 		case SID_OBJECT_CROP:
360 		case SID_OBJECT_TRANSPARENCE:
361 		case SID_OBJECT_GRADIENT:
362 		case SID_OBJECT_SHEAR:
363 		case SID_OBJECT_CROOK_ROTATE:
364 		case SID_OBJECT_CROOK_SLANT:
365 		case SID_OBJECT_CROOK_STRETCH:
366         case SID_CONVERT_TO_3D_LATHE:
367 
368 		case SID_ATTR_CHAR:
369 		case SID_ATTR_CHAR_VERTICAL:
370 		case SID_TEXT_FITTOSIZE:
371 		case SID_TEXT_FITTOSIZE_VERTICAL:
372 		case SID_DRAW_CAPTION:
373 		case SID_DRAW_CAPTION_VERTICAL:
374 		case SID_DRAW_FONTWORK:
375 		case SID_DRAW_FONTWORK_VERTICAL:
376 
377 		case SID_DRAW_RECT:
378 		case SID_DRAW_SQUARE:
379 		case SID_DRAW_RECT_ROUND:
380 		case SID_DRAW_SQUARE_ROUND:
381 		case SID_DRAW_RECT_NOFILL:
382 		case SID_DRAW_SQUARE_NOFILL:
383 		case SID_DRAW_RECT_ROUND_NOFILL:
384 		case SID_DRAW_SQUARE_ROUND_NOFILL:
385 
386 		case SID_DRAW_ELLIPSE:
387 		case SID_DRAW_CIRCLE:
388 		case SID_DRAW_PIE:
389 		case SID_DRAW_CIRCLEPIE:
390 		case SID_DRAW_ELLIPSECUT:
391 		case SID_DRAW_CIRCLECUT:
392 		case SID_DRAW_ARC:
393 		case SID_DRAW_CIRCLEARC:
394 		case SID_DRAW_ELLIPSE_NOFILL:
395 		case SID_DRAW_CIRCLE_NOFILL:
396 		case SID_DRAW_PIE_NOFILL:
397 		case SID_DRAW_CIRCLEPIE_NOFILL:
398 		case SID_DRAW_ELLIPSECUT_NOFILL:
399 		case SID_DRAW_CIRCLECUT_NOFILL:
400 
401         case SID_DRAW_BEZIER_NOFILL:
402 		case SID_DRAW_POLYGON_NOFILL:
403 		case SID_DRAW_XPOLYGON_NOFILL:
404         case SID_DRAW_BEZIER_FILL:
405 		case SID_DRAW_POLYGON:
406 		case SID_DRAW_XPOLYGON:
407         case SID_DRAW_FREELINE:
408         case SID_DRAW_FREELINE_NOFILL:
409 
410 		case SID_DRAW_LINE:
411 		case SID_DRAW_XLINE:
412 		case SID_DRAW_MEASURELINE:
413 		case SID_LINE_ARROW_START:
414 		case SID_LINE_ARROW_END:
415 		case SID_LINE_ARROWS:
416 		case SID_LINE_ARROW_CIRCLE:
417 		case SID_LINE_CIRCLE_ARROW:
418 		case SID_LINE_ARROW_SQUARE:
419 		case SID_LINE_SQUARE_ARROW:
420 
421 		case SID_3D_CUBE:
422 		case SID_3D_SPHERE:
423 		case SID_3D_CYLINDER:
424 		case SID_3D_CONE:
425 		case SID_3D_PYRAMID:
426 		case SID_3D_TORUS:
427 		case SID_3D_SHELL:
428 		case SID_3D_HALF_SPHERE:
429 
430         case SID_TOOL_CONNECTOR:
431         case SID_CONNECTOR_ARROW_START:
432         case SID_CONNECTOR_ARROW_END:
433         case SID_CONNECTOR_ARROWS:
434         case SID_CONNECTOR_CIRCLE_START:
435         case SID_CONNECTOR_CIRCLE_END:
436         case SID_CONNECTOR_CIRCLES:
437         case SID_CONNECTOR_LINE:
438         case SID_CONNECTOR_LINE_ARROW_START:
439         case SID_CONNECTOR_LINE_ARROW_END:
440         case SID_CONNECTOR_LINE_ARROWS:
441         case SID_CONNECTOR_LINE_CIRCLE_START:
442         case SID_CONNECTOR_LINE_CIRCLE_END:
443         case SID_CONNECTOR_LINE_CIRCLES:
444         case SID_CONNECTOR_CURVE:
445         case SID_CONNECTOR_CURVE_ARROW_START:
446         case SID_CONNECTOR_CURVE_ARROW_END:
447         case SID_CONNECTOR_CURVE_ARROWS:
448         case SID_CONNECTOR_CURVE_CIRCLE_START:
449         case SID_CONNECTOR_CURVE_CIRCLE_END:
450         case SID_CONNECTOR_CURVE_CIRCLES:
451         case SID_CONNECTOR_LINES:
452         case SID_CONNECTOR_LINES_ARROW_START:
453         case SID_CONNECTOR_LINES_ARROW_END:
454         case SID_CONNECTOR_LINES_ARROWS:
455         case SID_CONNECTOR_LINES_CIRCLE_START:
456         case SID_CONNECTOR_LINES_CIRCLE_END:
457         case SID_CONNECTOR_LINES_CIRCLES:
458 
459 
460 
461 		//case SID_ZOOM_OUT:
462 			return( sal_True );
463 	}
464 	return( sal_False );
465 }
466 
467 
468 
469