Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <string>
30 : : #include <vcl/toolbox.hxx>
31 : : #include <vcl/button.hxx>
32 : : #include <svl/intitem.hxx>
33 : : #include <sfx2/dispatch.hxx>
34 : : #include <sfx2/app.hxx>
35 : :
36 : : #include <svx/dialogs.hrc>
37 : : #include "svx/layctrl.hxx"
38 : : #include <svx/dialmgr.hxx>
39 : : #include <comphelper/processfactory.hxx>
40 : : #include <comphelper/string.hxx>
41 : : #include <svtools/colorcfg.hxx>
42 : : #include <com/sun/star/util/URLTransformer.hpp>
43 : :
44 : : // namespaces
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::com::sun::star::beans;
47 : : using namespace ::com::sun::star::util;
48 : : using namespace ::com::sun::star::frame;
49 : :
50 [ + - ]: 965 : SFX_IMPL_TOOLBOX_CONTROL(SvxTableToolBoxControl,SfxUInt16Item);
51 [ # # ]: 219 : SFX_IMPL_TOOLBOX_CONTROL(SvxColumnsToolBoxControl,SfxUInt16Item);
52 : :
53 : : // class TableWindow -----------------------------------------------------
54 : :
55 : : const long TABLE_CELL_WIDTH = 15;
56 : : const long TABLE_CELL_HEIGHT = 15;
57 : :
58 : : const long TABLE_CELLS_HORIZ = 10;
59 : : const long TABLE_CELLS_VERT = 15;
60 : :
61 : : const long TABLE_POS_X = 2;
62 : : const long TABLE_POS_Y = 2;
63 : :
64 : : const long TABLE_WIDTH = TABLE_POS_X + TABLE_CELLS_HORIZ*TABLE_CELL_WIDTH;
65 : : const long TABLE_HEIGHT = TABLE_POS_Y + TABLE_CELLS_VERT*TABLE_CELL_HEIGHT;
66 : :
67 : : class TableWindow : public SfxPopupWindow
68 : : {
69 : : private:
70 : : PushButton aTableButton;
71 : : ::Color aLineColor;
72 : : ::Color aFillColor;
73 : : ::Color aHighlightFillColor;
74 : : ::Color aBackgroundColor;
75 : : long nCol;
76 : : long nLine;
77 : : sal_Bool bInitialKeyInput;
78 : : sal_Bool m_bMod1;
79 : : ToolBox& rTbx;
80 : : Reference< XFrame > mxFrame;
81 : : rtl::OUString maCommand;
82 : :
83 : : DECL_LINK( SelectHdl, void * );
84 : :
85 : : public:
86 : : TableWindow( sal_uInt16 nSlotId,
87 : : const rtl::OUString& rCmd,
88 : : const String& rText,
89 : : ToolBox& rParentTbx,
90 : : const Reference< XFrame >& rFrame );
91 : : ~TableWindow();
92 : :
93 : : void KeyInput( const KeyEvent& rKEvt );
94 : : virtual void MouseMove( const MouseEvent& rMEvt );
95 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
96 : : virtual void Paint( const Rectangle& );
97 : : virtual void PopupModeEnd();
98 : : virtual SfxPopupWindow* Clone() const;
99 : :
100 : : private:
101 : : void Update( long nNewCol, long nNewLine );
102 : : void TableDialog( const Sequence< PropertyValue >& rArgs );
103 : : void CloseAndShowTableDialog();
104 : : };
105 : :
106 : : // -----------------------------------------------------------------------
107 : :
108 : 0 : IMPL_LINK_NOARG(TableWindow, SelectHdl)
109 : : {
110 : 0 : CloseAndShowTableDialog();
111 : 0 : return 0;
112 : : }
113 : :
114 : : // -----------------------------------------------------------------------
115 : :
116 : 0 : TableWindow::TableWindow( sal_uInt16 nSlotId, const rtl::OUString& rCmd, const String& rText, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ) :
117 : : SfxPopupWindow( nSlotId, rFrame, WinBits( WB_STDPOPUP ) ),
118 : : aTableButton( this ),
119 : : nCol( 0 ),
120 : : nLine( 0 ),
121 : : rTbx(rParentTbx),
122 : : mxFrame( rFrame ),
123 [ # # ]: 0 : maCommand( rCmd )
124 : : {
125 [ # # ]: 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
126 [ # # ]: 0 : svtools::ColorConfig aColorConfig;
127 : :
128 : 0 : aLineColor = rStyles.GetShadowColor();
129 : 0 : aFillColor = rStyles.GetWindowColor();
130 : 0 : aHighlightFillColor = rStyles.GetHighlightColor();
131 : 0 : aBackgroundColor = GetSettings().GetStyleSettings().GetFaceColor();
132 : :
133 [ # # ][ # # ]: 0 : SetBackground( aBackgroundColor );
[ # # ]
134 [ # # ]: 0 : Font aFont = GetFont();
135 [ # # ][ # # ]: 0 : aFont.SetColor( ::Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor ) );
136 [ # # ]: 0 : aFont.SetFillColor( aBackgroundColor );
137 [ # # ]: 0 : aFont.SetTransparent( sal_False );
138 [ # # ]: 0 : SetFont( aFont );
139 : :
140 [ # # ]: 0 : SetText( rText );
141 : :
142 : : aTableButton.SetPosSizePixel( Point( TABLE_POS_X + TABLE_CELL_WIDTH, TABLE_HEIGHT + 5 ),
143 [ # # ]: 0 : Size( TABLE_WIDTH - TABLE_POS_X - 2*TABLE_CELL_WIDTH, 24 ) );
144 [ # # ][ # # ]: 0 : aTableButton.SetText( String( SVX_RESSTR( RID_SVXSTR_MORE ) ) );
[ # # ][ # # ]
[ # # ]
145 [ # # ]: 0 : aTableButton.SetClickHdl( LINK( this, TableWindow, SelectHdl ) );
146 [ # # ]: 0 : aTableButton.Show();
147 : :
148 [ # # ][ # # ]: 0 : SetOutputSizePixel( Size( TABLE_WIDTH + 3, TABLE_HEIGHT + 33 ) );
[ # # ]
149 : 0 : }
150 : :
151 : : // -----------------------------------------------------------------------
152 : :
153 [ # # ]: 0 : TableWindow::~TableWindow()
154 : : {
155 [ # # ]: 0 : }
156 : :
157 : : // -----------------------------------------------------------------------
158 : :
159 : 0 : SfxPopupWindow* TableWindow::Clone() const
160 : : {
161 [ # # ][ # # ]: 0 : return new TableWindow( GetId(), maCommand, GetText(), rTbx, mxFrame );
162 : : }
163 : :
164 : : // -----------------------------------------------------------------------
165 : :
166 : 0 : void TableWindow::MouseMove( const MouseEvent& rMEvt )
167 : : {
168 [ # # ]: 0 : SfxPopupWindow::MouseMove( rMEvt );
169 : 0 : Point aPos = rMEvt.GetPosPixel();
170 : 0 : Point aMousePos( aPos );
171 : :
172 : 0 : long nNewCol = ( aMousePos.X() - TABLE_POS_X + TABLE_CELL_WIDTH ) / TABLE_CELL_WIDTH;
173 : 0 : long nNewLine = ( aMousePos.Y() - TABLE_POS_Y + TABLE_CELL_HEIGHT ) / TABLE_CELL_HEIGHT;
174 : :
175 [ # # ]: 0 : Update( nNewCol, nNewLine );
176 : 0 : }
177 : :
178 : : // -----------------------------------------------------------------------
179 : :
180 : 0 : void TableWindow::KeyInput( const KeyEvent& rKEvt )
181 : : {
182 : 0 : bool bHandled = false;
183 : 0 : sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
184 : 0 : sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
185 [ # # ]: 0 : if ( !nModifier )
186 : : {
187 : 0 : bHandled = true;
188 : 0 : long nNewCol = nCol;
189 : 0 : long nNewLine = nLine;
190 [ # # # # : 0 : switch(nKey)
# # # # ]
191 : : {
192 : : case KEY_UP:
193 [ # # ]: 0 : if ( nNewLine > 1 )
194 : 0 : nNewLine--;
195 : : else
196 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
197 : 0 : break;
198 : : case KEY_DOWN:
199 [ # # ]: 0 : if ( nNewLine < TABLE_CELLS_VERT )
200 : 0 : nNewLine++;
201 : : else
202 : 0 : CloseAndShowTableDialog();
203 : 0 : break;
204 : : case KEY_LEFT:
205 [ # # ]: 0 : if ( nNewCol > 1 )
206 : 0 : nNewCol--;
207 : : else
208 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
209 : 0 : break;
210 : : case KEY_RIGHT:
211 [ # # ]: 0 : if ( nNewCol < TABLE_CELLS_HORIZ )
212 : 0 : nNewCol++;
213 : : else
214 : 0 : CloseAndShowTableDialog();
215 : 0 : break;
216 : : case KEY_ESCAPE:
217 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
218 : 0 : break;
219 : : case KEY_RETURN:
220 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
221 : 0 : break;
222 : : case KEY_TAB:
223 : 0 : CloseAndShowTableDialog();
224 : 0 : break;
225 : : default:
226 : 0 : bHandled = false;
227 : : }
228 [ # # ]: 0 : if ( bHandled )
229 : : {
230 : : //make sure that a table can initially be created
231 [ # # ]: 0 : if(bInitialKeyInput)
232 : : {
233 : 0 : bInitialKeyInput = sal_False;
234 [ # # ]: 0 : if(!nNewLine)
235 : 0 : nNewLine = 1;
236 [ # # ]: 0 : if(!nNewCol)
237 : 0 : nNewCol = 1;
238 : : }
239 : 0 : Update( nNewCol, nNewLine );
240 : : }
241 : : }
242 [ # # ][ # # ]: 0 : else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
243 : : {
244 : 0 : m_bMod1 = sal_True;
245 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
246 : : }
247 : :
248 [ # # ]: 0 : if(!bHandled)
249 : 0 : SfxPopupWindow::KeyInput(rKEvt);
250 : 0 : }
251 : :
252 : : // -----------------------------------------------------------------------
253 : :
254 : 0 : void TableWindow::MouseButtonUp( const MouseEvent& rMEvt )
255 : : {
256 : 0 : SfxPopupWindow::MouseButtonUp( rMEvt );
257 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
258 : 0 : }
259 : :
260 : : // -----------------------------------------------------------------------
261 : :
262 : 0 : void TableWindow::Paint( const Rectangle& )
263 : : {
264 : 0 : const long nSelectionWidth = TABLE_POS_X + nCol*TABLE_CELL_WIDTH;
265 : 0 : const long nSelectionHeight = TABLE_POS_Y + nLine*TABLE_CELL_HEIGHT;
266 : :
267 : : // the non-selected parts of the table
268 : 0 : SetLineColor( aLineColor );
269 : 0 : SetFillColor( aFillColor );
270 [ # # ]: 0 : DrawRect( Rectangle( nSelectionWidth, TABLE_POS_Y, TABLE_WIDTH, nSelectionHeight ) );
271 [ # # ]: 0 : DrawRect( Rectangle( TABLE_POS_X, nSelectionHeight, nSelectionWidth, TABLE_HEIGHT ) );
272 [ # # ]: 0 : DrawRect( Rectangle( nSelectionWidth, nSelectionHeight, TABLE_WIDTH, TABLE_HEIGHT ) );
273 : :
274 : : // the selection
275 [ # # ][ # # ]: 0 : if ( nCol > 0 && nLine > 0 )
276 : : {
277 : 0 : SetFillColor( aHighlightFillColor );
278 : : DrawRect( Rectangle( TABLE_POS_X, TABLE_POS_Y,
279 [ # # ]: 0 : nSelectionWidth, nSelectionHeight ) );
280 : : }
281 : :
282 : : // lines inside of the table
283 : 0 : SetLineColor( aLineColor );
284 [ # # ]: 0 : for ( long i = 1; i < TABLE_CELLS_VERT; ++i )
285 : : DrawLine( Point( TABLE_POS_X, TABLE_POS_Y + i*TABLE_CELL_HEIGHT ),
286 [ # # ]: 0 : Point( TABLE_WIDTH, TABLE_POS_Y + i*TABLE_CELL_HEIGHT ) );
287 : :
288 [ # # ]: 0 : for ( long i = 1; i < TABLE_CELLS_HORIZ; ++i )
289 : : DrawLine( Point( TABLE_POS_X + i*TABLE_CELL_WIDTH, TABLE_POS_Y ),
290 [ # # ]: 0 : Point( TABLE_POS_X + i*TABLE_CELL_WIDTH, TABLE_HEIGHT ) );
291 : :
292 : : // the text near the mouse cursor telling the table dimensions
293 [ # # ][ # # ]: 0 : if ( nCol && nLine )
294 : : {
295 [ # # ]: 0 : String aText;
296 [ # # ][ # # ]: 0 : aText += String::CreateFromInt32( nCol );
[ # # ]
297 [ # # ]: 0 : aText.AppendAscii( " x " );
298 [ # # ][ # # ]: 0 : aText += String::CreateFromInt32( nLine );
[ # # ]
299 [ # # ]: 0 : if(GetId() == FN_SHOW_MULTIPLE_PAGES)
300 : : {
301 [ # # ]: 0 : aText += ' ';
302 [ # # ][ # # ]: 0 : aText += String(SVX_RESSTR(RID_SVXSTR_PAGES));
[ # # ][ # # ]
[ # # ]
303 : : }
304 : :
305 [ # # ][ # # ]: 0 : Size aTextSize( GetTextWidth( aText ), GetTextHeight() );
306 : :
307 : 0 : long nTextX = nSelectionWidth + TABLE_CELL_WIDTH;
308 : 0 : long nTextY = nSelectionHeight + TABLE_CELL_HEIGHT;
309 : 0 : const long nTipBorder = 2;
310 : :
311 [ # # ]: 0 : if ( aTextSize.Width() + TABLE_POS_X + TABLE_CELL_WIDTH + 2*nTipBorder < nSelectionWidth )
312 : 0 : nTextX = nSelectionWidth - TABLE_CELL_WIDTH - aTextSize.Width();
313 : :
314 [ # # ]: 0 : if ( aTextSize.Height() + TABLE_POS_Y + TABLE_CELL_HEIGHT + 2*nTipBorder < nSelectionHeight )
315 : 0 : nTextY = nSelectionHeight - TABLE_CELL_HEIGHT - aTextSize.Height();
316 : :
317 [ # # ]: 0 : SetLineColor( aLineColor );
318 [ # # ]: 0 : SetFillColor( aBackgroundColor );
319 : : DrawRect( Rectangle ( nTextX - 2*nTipBorder, nTextY - 2*nTipBorder,
320 [ # # ][ # # ]: 0 : nTextX + aTextSize.Width() + nTipBorder, nTextY + aTextSize.Height() + nTipBorder ) );
321 : :
322 : : // #i95350# force RTL output
323 [ # # ]: 0 : if ( IsRTLEnabled() )
324 [ # # ]: 0 : aText.Insert( 0x202D, 0 );
325 : :
326 [ # # ][ # # ]: 0 : DrawText( Point( nTextX, nTextY ), aText );
327 : : }
328 : 0 : }
329 : :
330 : : // -----------------------------------------------------------------------
331 : :
332 : 0 : void TableWindow::PopupModeEnd()
333 : : {
334 [ # # ][ # # ]: 0 : if ( !IsPopupModeCanceled() && nCol && nLine )
[ # # ][ # # ]
335 : : {
336 [ # # ]: 0 : Sequence< PropertyValue > aArgs( 2 );
337 [ # # ]: 0 : aArgs[0].Name = ::rtl::OUString( "Columns" );
338 [ # # ][ # # ]: 0 : aArgs[0].Value = makeAny( sal_Int16( nCol ));
339 [ # # ]: 0 : aArgs[1].Name = ::rtl::OUString( "Rows" );
340 [ # # ][ # # ]: 0 : aArgs[1].Value = makeAny( sal_Int16( nLine ));
341 : :
342 [ # # ][ # # ]: 0 : TableDialog( aArgs );
343 : : }
344 : :
345 : 0 : SfxPopupWindow::PopupModeEnd();
346 : 0 : }
347 : :
348 : : // -----------------------------------------------------------------------
349 : :
350 : 0 : void TableWindow::Update( long nNewCol, long nNewLine )
351 : : {
352 [ # # ][ # # ]: 0 : if ( nNewCol < 0 || nNewCol > TABLE_CELLS_HORIZ )
353 : 0 : nNewCol = 0;
354 : :
355 [ # # ][ # # ]: 0 : if ( nNewLine < 0 || nNewLine > TABLE_CELLS_VERT )
356 : 0 : nNewLine = 0;
357 : :
358 [ # # ][ # # ]: 0 : if ( nNewCol != nCol || nNewLine != nLine )
359 : : {
360 : 0 : nCol = nNewCol;
361 : 0 : nLine = nNewLine;
362 [ # # ]: 0 : Invalidate( Rectangle( TABLE_POS_X, TABLE_POS_Y, TABLE_WIDTH, TABLE_HEIGHT ) );
363 : : }
364 : 0 : }
365 : :
366 : : // -----------------------------------------------------------------------
367 : :
368 : 0 : void TableWindow::TableDialog( const Sequence< PropertyValue >& rArgs )
369 : : {
370 [ # # ]: 0 : Window* pParent = rTbx.GetParent();
371 : 0 : sal_uInt16 nId = GetId();
372 [ # # ]: 0 : pParent->UserEvent(SVX_EVENT_COLUM_WINDOW_EXECUTE, reinterpret_cast<void*>(nId));
373 : :
374 [ # # ]: 0 : Reference< XDispatchProvider > xDispatchProvider( mxFrame, UNO_QUERY );
375 [ # # ]: 0 : if ( xDispatchProvider.is() )
376 : : {
377 : 0 : com::sun::star::util::URL aTargetURL;
378 [ # # ][ # # ]: 0 : Reference < XURLTransformer > xTrans( URLTransformer::create(::comphelper::getProcessComponentContext()) );
379 : 0 : aTargetURL.Complete = maCommand;
380 [ # # ][ # # ]: 0 : xTrans->parseStrict( aTargetURL );
381 : :
382 [ # # ][ # # ]: 0 : Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, rtl::OUString(), 0 );
383 [ # # ]: 0 : if ( xDispatch.is() )
384 [ # # ][ # # ]: 0 : xDispatch->dispatch( aTargetURL, rArgs );
385 : 0 : }
386 : 0 : }
387 : :
388 : : // -----------------------------------------------------------------------
389 : :
390 : 0 : void TableWindow::CloseAndShowTableDialog()
391 : : {
392 : : // close the toolbar tool
393 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
394 : :
395 : : // and open the table dialog instead
396 [ # # ]: 0 : TableDialog( Sequence< PropertyValue >() );
397 : 0 : }
398 : :
399 : : // class ColumnsWindow ---------------------------------------------------
400 : :
401 [ # # ]: 0 : class ColumnsWindow : public SfxPopupWindow
402 : : {
403 : : private:
404 : : ::Color aLineColor;
405 : : ::Color aHighlightLineColor;
406 : : ::Color aFillColor;
407 : : ::Color aHighlightFillColor;
408 : : ::Color aFaceColor;
409 : : long nCol;
410 : : long nWidth;
411 : : long nMX;
412 : : long nTextHeight;
413 : : sal_Bool bInitialKeyInput;
414 : : sal_Bool m_bMod1;
415 : : ToolBox& rTbx;
416 : : Reference< XFrame > mxFrame;
417 : : ::rtl::OUString maCommand;
418 : :
419 : : void UpdateSize_Impl( long nNewCol );
420 : : public:
421 : : ColumnsWindow( sal_uInt16 nId, const ::rtl::OUString& rCmd, const String &rText, ToolBox& rParentTbx, const Reference< XFrame >& rFrame );
422 : :
423 : : void KeyInput( const KeyEvent& rKEvt );
424 : : virtual void MouseMove( const MouseEvent& rMEvt );
425 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
426 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
427 : : virtual void Paint( const Rectangle& );
428 : : virtual void PopupModeEnd();
429 : : virtual SfxPopupWindow* Clone() const;
430 : :
431 : : sal_uInt16 GetColCount() const { return (sal_uInt16)nCol; }
432 : : };
433 : :
434 : : // -----------------------------------------------------------------------
435 : :
436 : 0 : ColumnsWindow::ColumnsWindow( sal_uInt16 nId, const ::rtl::OUString& rCmd, const String& rText, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ) :
437 : : SfxPopupWindow( nId, rFrame, WB_STDPOPUP ),
438 : : bInitialKeyInput(sal_True),
439 : : m_bMod1(sal_False),
440 : : rTbx(rParentTbx),
441 : : mxFrame(rFrame),
442 : 0 : maCommand( rCmd )
443 : : {
444 [ # # ]: 0 : const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
445 [ # # ]: 0 : svtools::ColorConfig aColorConfig;
446 [ # # ]: 0 : aLineColor = ::Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
447 : 0 : aHighlightLineColor = rStyles.GetHighlightTextColor();
448 : 0 : aFillColor = rStyles.GetWindowColor();
449 : 0 : aHighlightFillColor = rStyles.GetHighlightColor();
450 : 0 : aFaceColor = rStyles.GetFaceColor();
451 : :
452 [ # # ]: 0 : nTextHeight = GetTextHeight()+1;
453 [ # # ]: 0 : SetBackground();
454 [ # # ]: 0 : Font aFont( GetFont() );
455 [ # # ]: 0 : aFont.SetColor( aLineColor );
456 [ # # ]: 0 : aFont.SetFillColor( aFaceColor );
457 [ # # ]: 0 : aFont.SetTransparent( sal_False );
458 [ # # ]: 0 : SetFont( aFont );
459 : :
460 : 0 : nCol = 0;
461 : 0 : nWidth = 4;
462 : :
463 [ # # ]: 0 : SetText( rText );
464 : :
465 [ # # ][ # # ]: 0 : Size aLogicSize = LogicToPixel( Size( 95, 155 ), MapMode( MAP_10TH_MM ) );
[ # # ]
466 : 0 : nMX = aLogicSize.Width();
467 [ # # ]: 0 : SetOutputSizePixel( Size( nMX*nWidth-1, aLogicSize.Height()+nTextHeight ) );
468 [ # # ][ # # ]: 0 : StartCascading();
[ # # ]
469 : 0 : }
470 : :
471 : : // -----------------------------------------------------------------------
472 : :
473 : 0 : SfxPopupWindow* ColumnsWindow::Clone() const
474 : : {
475 [ # # ][ # # ]: 0 : return new ColumnsWindow( GetId(), maCommand, GetText(), rTbx, mxFrame );
476 : : }
477 : :
478 : : // -----------------------------------------------------------------------
479 : :
480 : 0 : void ColumnsWindow::MouseMove( const MouseEvent& rMEvt )
481 : : {
482 [ # # ]: 0 : SfxPopupWindow::MouseMove( rMEvt );
483 : 0 : Point aPos = rMEvt.GetPosPixel();
484 : 0 : Point aMousePos = aPos;
485 : :
486 [ # # ]: 0 : if ( rMEvt.IsEnterWindow() )
487 [ # # ]: 0 : CaptureMouse();
488 [ # # ][ # # ]: 0 : else if ( aMousePos.X() < 0 || aMousePos.Y() < 0 )
[ # # ]
489 : : {
490 : 0 : nCol = 0;
491 [ # # ]: 0 : ReleaseMouse();
492 [ # # ]: 0 : Invalidate();
493 : 0 : return;
494 : : }
495 : :
496 : 0 : long nNewCol = 0;
497 [ # # ]: 0 : if ( aPos.X() > 0 )
498 : 0 : nNewCol = aPos.X() / nMX + 1;
499 [ # # ]: 0 : if ( aPos.Y() < 0 )
500 : 0 : nNewCol = 0;
501 [ # # ]: 0 : if ( nNewCol > 20 )
502 : 0 : nNewCol = 20;
503 [ # # ]: 0 : UpdateSize_Impl( nNewCol );
504 : : }
505 : :
506 : 0 : void ColumnsWindow::UpdateSize_Impl( long nNewCol )
507 : : {
508 : 0 : Size aWinSize = GetOutputSizePixel();
509 : 0 : Point aWinPos;// = GetPosPixel();
510 : :
511 [ # # ]: 0 : if ( nWidth <= nNewCol )
512 : : {
513 [ # # ][ # # ]: 0 : Point aMaxPos = OutputToScreenPixel( GetDesktopRectPixel().BottomRight() );
[ # # ]
514 : :
515 [ # # ]: 0 : if ( nWidth <= nNewCol )
516 : : {
517 : 0 : nWidth = nNewCol;
518 : 0 : nWidth++;
519 : : }
520 : :
521 [ # # # # ]: 0 : while ( nWidth > 0 &&
[ # # ]
522 : 0 : (short)(aWinPos.X()+(nMX*nWidth-1)) >= aMaxPos.X()-3 )
523 : 0 : nWidth--;
524 : :
525 [ # # ]: 0 : if ( nNewCol > nWidth )
526 : 0 : nNewCol = nWidth;
527 : :
528 : 0 : Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2,
529 [ # # ][ # # ]: 0 : aWinSize.Width(), aWinSize.Height() ) );
530 [ # # ]: 0 : SetOutputSizePixel( Size( nMX*nWidth-1, aWinSize.Height() ) );
531 : : }
532 : :
533 : :
534 [ # # ]: 0 : if ( nNewCol != nCol )
535 : : {
536 : 0 : Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2,
537 [ # # ][ # # ]: 0 : aWinSize.Width(), aWinSize.Height() ) );
538 : :
539 : 0 : long nMinCol = 0, nMaxCol = 0;
540 : :
541 [ # # ]: 0 : if ( nNewCol < nCol )
542 : : {
543 : 0 : nMinCol = nNewCol;
544 : 0 : nMaxCol = nCol;
545 : : }
546 : : else
547 : : {
548 : 0 : nMinCol = nCol;
549 : 0 : nMaxCol = nNewCol;
550 : : }
551 : :
552 : : Invalidate( Rectangle( nMinCol*nMX-1, 0,
553 [ # # ][ # # ]: 0 : nMaxCol*nMX+1, aWinSize.Height()-nTextHeight+2 ) );
554 : 0 : nCol = nNewCol;
555 : : }
556 [ # # ]: 0 : Update();
557 : 0 : }
558 : : // -----------------------------------------------------------------------
559 : :
560 : 0 : void ColumnsWindow::MouseButtonDown( const MouseEvent& rMEvt )
561 : : {
562 : 0 : SfxPopupWindow::MouseButtonDown( rMEvt );
563 : 0 : CaptureMouse();
564 : 0 : }
565 : :
566 : 0 : void ColumnsWindow::KeyInput( const KeyEvent& rKEvt )
567 : : {
568 : 0 : sal_Bool bHandled = sal_False;
569 : 0 : sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
570 : 0 : sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
571 [ # # ]: 0 : if(!nModifier)
572 : : {
573 [ # # ][ # # ]: 0 : if( KEY_LEFT == nKey || KEY_RIGHT == nKey ||
[ # # ][ # # ]
[ # # ]
574 : : KEY_RETURN == nKey ||KEY_ESCAPE == nKey ||
575 : : KEY_UP == nKey)
576 : : {
577 : 0 : bHandled = sal_True;
578 : 0 : long nNewCol = nCol;
579 [ # # # # : 0 : switch(nKey)
# ]
580 : : {
581 : : case KEY_LEFT :
582 [ # # ]: 0 : if(nNewCol)
583 : 0 : nNewCol--;
584 : 0 : break;
585 : : case KEY_RIGHT :
586 : 0 : nNewCol++;
587 : 0 : break;
588 : : case KEY_RETURN :
589 [ # # ]: 0 : if(IsMouseCaptured())
590 : 0 : ReleaseMouse();
591 : 0 : EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL );
592 : 0 : break;
593 : : case KEY_ESCAPE :
594 : : case KEY_UP :
595 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL);
596 : 0 : break;
597 : : }
598 : : //make sure that a table can initially be created
599 [ # # ]: 0 : if(bInitialKeyInput)
600 : : {
601 : 0 : bInitialKeyInput = sal_False;
602 [ # # ]: 0 : if(!nNewCol)
603 : 0 : nNewCol = 1;
604 : : }
605 : 0 : UpdateSize_Impl( nNewCol );
606 : : }
607 : : }
608 [ # # ][ # # ]: 0 : else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
609 : : {
610 : 0 : m_bMod1 = sal_True;
611 [ # # ]: 0 : if(IsMouseCaptured())
612 : 0 : ReleaseMouse();
613 : 0 : EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL );
614 : : }
615 [ # # ]: 0 : if(!bHandled)
616 : 0 : SfxPopupWindow::KeyInput(rKEvt);
617 : 0 : }
618 : :
619 : : // -----------------------------------------------------------------------
620 : :
621 : 0 : void ColumnsWindow::MouseButtonUp( const MouseEvent& rMEvt )
622 : : {
623 : 0 : SfxPopupWindow::MouseButtonUp( rMEvt );
624 : 0 : ReleaseMouse();
625 : :
626 [ # # ]: 0 : if ( IsInPopupMode() )
627 : 0 : EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
628 : 0 : }
629 : :
630 : : // -----------------------------------------------------------------------
631 : :
632 : 0 : void ColumnsWindow::Paint( const Rectangle& )
633 : : {
634 : : long i;
635 : : long j;
636 : : long nLineWidth;
637 : 0 : Size aSize = GetOutputSizePixel();
638 : :
639 [ # # ]: 0 : for ( i = 0; i < nWidth; i++ )
640 : : {
641 [ # # ]: 0 : if ( i < nCol )
642 : : {
643 [ # # ]: 0 : SetLineColor( aHighlightLineColor );
644 [ # # ]: 0 : SetFillColor( aHighlightFillColor );
645 : : }
646 : : else
647 : : {
648 [ # # ]: 0 : SetLineColor( aLineColor );
649 [ # # ]: 0 : SetFillColor( aFillColor );
650 : : }
651 : :
652 : : DrawRect( Rectangle( i*nMX-1, -1,
653 [ # # ][ # # ]: 0 : i*nMX+nMX, aSize.Height()-nTextHeight+1 ) );
654 : :
655 : 0 : j = 4;
656 [ # # ]: 0 : while ( j < aSize.Height()-nTextHeight-4 )
657 : : {
658 [ # # ]: 0 : if ( !(j % 16) )
659 : 0 : nLineWidth = 10;
660 : : else
661 : 0 : nLineWidth = 4;
662 [ # # ]: 0 : DrawLine( Point( i*nMX+4, j ), Point( i*nMX+nMX-nLineWidth-4, j ) );
663 : 0 : j += 4;
664 : : }
665 : : }
666 : :
667 [ # # ]: 0 : SetLineColor();
668 [ # # ]: 0 : SetFillColor( aFaceColor );
669 [ # # ]: 0 : String aText;
670 [ # # ]: 0 : if ( nCol )
671 [ # # ][ # # ]: 0 : aText = String::CreateFromInt32(nCol);
[ # # ]
672 : : else
673 [ # # ][ # # ]: 0 : aText = comphelper::string::remove(Button::GetStandardText(BUTTON_CANCEL), '~');
[ # # ][ # # ]
674 : :
675 [ # # ][ # # ]: 0 : Size aTextSize(GetTextWidth( aText ), GetTextHeight());
676 [ # # ]: 0 : DrawText( Point( ( aSize.Width() - aTextSize.Width() ) / 2, aSize.Height() - nTextHeight + 2 ), aText );
677 : :
678 [ # # ][ # # ]: 0 : DrawRect( Rectangle( 0, aSize.Height()-nTextHeight+2, (aSize.Width()-aTextSize.Width())/2-1, aSize.Height() ) );
679 [ # # ][ # # ]: 0 : DrawRect( Rectangle( (aSize.Width()-aTextSize.Width())/2+aTextSize.Width(), aSize.Height()-nTextHeight+2, aSize.Width(), aSize.Height() ) );
680 : :
681 [ # # ]: 0 : SetLineColor( aLineColor );
682 [ # # ]: 0 : SetFillColor();
683 [ # # ][ # # ]: 0 : DrawRect( Rectangle( 0, 0, aSize.Width() - 1, aSize.Height() - nTextHeight + 1 ) );
[ # # ]
684 : 0 : }
685 : :
686 : : // -----------------------------------------------------------------------
687 : :
688 : 0 : void ColumnsWindow::PopupModeEnd()
689 : : {
690 [ # # ][ # # ]: 0 : if ( !IsPopupModeCanceled() && nCol )
[ # # ]
691 : : {
692 : 0 : sal_uInt16 nId = GetId();
693 [ # # ]: 0 : Window* pParent = rTbx.GetParent();
694 [ # # ]: 0 : pParent->UserEvent(SVX_EVENT_COLUM_WINDOW_EXECUTE, reinterpret_cast<void*>(nId));
695 : :
696 [ # # ]: 0 : Sequence< PropertyValue > aArgs( 2 );
697 [ # # ]: 0 : aArgs[0].Name = ::rtl::OUString( "Columns" );
698 [ # # ][ # # ]: 0 : aArgs[0].Value = makeAny( sal_Int16( nCol ));
699 [ # # ]: 0 : aArgs[1].Name = ::rtl::OUString( "Modifier" );
700 [ # # ][ # # ]: 0 : aArgs[1].Value = makeAny( sal_Int16( m_bMod1 ? KEY_MOD1 : 0 ));
[ # # ]
701 : :
702 [ # # ]: 0 : SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
703 : : maCommand,
704 [ # # ][ # # ]: 0 : aArgs );
[ # # ][ # # ]
705 : : }
706 [ # # ]: 0 : else if ( IsPopupModeCanceled() )
707 : 0 : ReleaseMouse();
708 : 0 : SfxPopupWindow::PopupModeEnd();
709 : 0 : }
710 : :
711 : : // class SvxTableToolBoxControl ------------------------------------------
712 : :
713 : 794 : SvxTableToolBoxControl::SvxTableToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
714 : : SfxToolBoxControl( nSlotId, nId, rTbx ),
715 : 794 : bEnabled( sal_True )
716 : : {
717 [ + - ][ + - ]: 794 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
718 [ + - ]: 794 : rTbx.Invalidate();
719 : 794 : }
720 : :
721 : : // -----------------------------------------------------------------------
722 : :
723 : 794 : SvxTableToolBoxControl::~SvxTableToolBoxControl()
724 : : {
725 [ - + ]: 1588 : }
726 : :
727 : : // -----------------------------------------------------------------------
728 : :
729 : 0 : SfxPopupWindowType SvxTableToolBoxControl::GetPopupWindowType() const
730 : : {
731 : 0 : return SFX_POPUPWINDOW_ONTIMEOUTANDMOVE;
732 : : }
733 : :
734 : : // -----------------------------------------------------------------------
735 : :
736 : 0 : SfxPopupWindow* SvxTableToolBoxControl::CreatePopupWindow()
737 : : {
738 [ # # ]: 0 : if ( bEnabled )
739 : : {
740 : 0 : ToolBox& rTbx = GetToolBox();
741 [ # # ]: 0 : TableWindow* pWin = new TableWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), rTbx, m_xFrame );
742 : 0 : pWin->StartPopupMode( &rTbx, FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_NOKEYCLOSE );
743 : 0 : SetPopupWindow( pWin );
744 : 0 : return pWin;
745 : : }
746 : 0 : return 0;
747 : : }
748 : :
749 : : // -----------------------------------------------------------------------
750 : :
751 : 0 : SfxPopupWindow* SvxTableToolBoxControl::CreatePopupWindowCascading()
752 : : {
753 [ # # ]: 0 : if ( bEnabled )
754 [ # # ]: 0 : return new TableWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), GetToolBox(), m_xFrame );
755 : 0 : return 0;
756 : : }
757 : :
758 : : // -----------------------------------------------------------------------
759 : :
760 : 1263 : void SvxTableToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
761 : : {
762 [ + + ][ - + ]: 1263 : if ( pState && pState->ISA(SfxUInt16Item) )
[ - + ]
763 : : {
764 : 0 : sal_Int16 nValue = static_cast< const SfxUInt16Item* >( pState )->GetValue();
765 : 0 : bEnabled = ( nValue != 0 );
766 : : }
767 : : else
768 : 1263 : bEnabled = SFX_ITEM_DISABLED != eState;
769 : :
770 : 1263 : sal_uInt16 nId = GetId();
771 : 1263 : ToolBox& rTbx = GetToolBox();
772 : :
773 : 1263 : rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
774 : : rTbx.SetItemState( nId,
775 [ - + ]: 1263 : ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
776 : 1263 : }
777 : :
778 : : // class SvxColumnsToolBoxControl ------------------------------------------
779 : :
780 : 0 : SvxColumnsToolBoxControl::SvxColumnsToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
781 : 0 : SfxToolBoxControl( nSlotId, nId, rTbx )
782 : : {
783 [ # # ][ # # ]: 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
784 [ # # ]: 0 : rTbx.Invalidate();
785 : 0 : }
786 : :
787 : : // -----------------------------------------------------------------------
788 : :
789 : 0 : SvxColumnsToolBoxControl::~SvxColumnsToolBoxControl()
790 : : {
791 [ # # ]: 0 : }
792 : :
793 : : // -----------------------------------------------------------------------
794 : :
795 : 0 : SfxPopupWindowType SvxColumnsToolBoxControl::GetPopupWindowType() const
796 : : {
797 : 0 : return SFX_POPUPWINDOW_ONTIMEOUTANDMOVE;
798 : : }
799 : :
800 : : // -----------------------------------------------------------------------
801 : :
802 : 0 : SfxPopupWindow* SvxColumnsToolBoxControl::CreatePopupWindow()
803 : : {
804 : 0 : ColumnsWindow* pWin = 0;
805 [ # # ]: 0 : if(bEnabled)
806 : : {
807 [ # # ]: 0 : pWin = new ColumnsWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), GetToolBox(), m_xFrame );
808 : 0 : pWin->StartPopupMode( &GetToolBox(),
809 : 0 : FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_NOKEYCLOSE );
810 : 0 : SetPopupWindow( pWin );
811 : : }
812 : 0 : return pWin;
813 : : }
814 : :
815 : : // -----------------------------------------------------------------------
816 : :
817 : 0 : SfxPopupWindow* SvxColumnsToolBoxControl::CreatePopupWindowCascading()
818 : : {
819 : 0 : ColumnsWindow* pWin = 0;
820 [ # # ]: 0 : if(bEnabled)
821 : : {
822 [ # # ]: 0 : pWin = new ColumnsWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), GetToolBox(), m_xFrame );
823 : : }
824 : 0 : return pWin;
825 : : }
826 : :
827 : 0 : void SvxColumnsToolBoxControl::StateChanged( sal_uInt16 nSID,
828 : : SfxItemState eState,
829 : : const SfxPoolItem* pState )
830 : : {
831 : 0 : bEnabled = SFX_ITEM_DISABLED != eState;
832 : 0 : SfxToolBoxControl::StateChanged(nSID, eState, pState );
833 : 0 : }
834 : :
835 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|