Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / svx / source / tbxctrls / layctrl.cxx
blobb723139efe3790ef42c76a486d2e9b2783378166
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
32 #include <string>
33 #include <vcl/toolbox.hxx>
34 #include <vcl/button.hxx>
35 #include <svl/intitem.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/app.hxx>
39 #include <svx/dialogs.hrc>
40 #include "svx/layctrl.hxx"
41 #include <svx/dialmgr.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <comphelper/string.hxx>
44 #include <svtools/colorcfg.hxx>
46 // namespaces
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::util;
50 using namespace ::com::sun::star::frame;
52 SFX_IMPL_TOOLBOX_CONTROL(SvxTableToolBoxControl,SfxUInt16Item);
53 SFX_IMPL_TOOLBOX_CONTROL(SvxColumnsToolBoxControl,SfxUInt16Item);
55 // class TableWindow -----------------------------------------------------
57 const long TABLE_CELL_WIDTH = 15;
58 const long TABLE_CELL_HEIGHT = 15;
60 const long TABLE_CELLS_HORIZ = 10;
61 const long TABLE_CELLS_VERT = 15;
63 const long TABLE_POS_X = 2;
64 const long TABLE_POS_Y = 2;
66 const long TABLE_WIDTH = TABLE_POS_X + TABLE_CELLS_HORIZ*TABLE_CELL_WIDTH;
67 const long TABLE_HEIGHT = TABLE_POS_Y + TABLE_CELLS_VERT*TABLE_CELL_HEIGHT;
69 class TableWindow : public SfxPopupWindow
71 private:
72 PushButton aTableButton;
73 ::Color aLineColor;
74 ::Color aFillColor;
75 ::Color aHighlightFillColor;
76 ::Color aBackgroundColor;
77 long nCol;
78 long nLine;
79 sal_Bool bInitialKeyInput;
80 sal_Bool m_bMod1;
81 ToolBox& rTbx;
82 Reference< XFrame > mxFrame;
83 rtl::OUString maCommand;
85 DECL_LINK( SelectHdl, void * );
87 public:
88 TableWindow( sal_uInt16 nSlotId,
89 const rtl::OUString& rCmd,
90 const String& rText,
91 ToolBox& rParentTbx,
92 const Reference< XFrame >& rFrame );
93 ~TableWindow();
95 void KeyInput( const KeyEvent& rKEvt );
96 virtual void MouseMove( const MouseEvent& rMEvt );
97 virtual void MouseButtonUp( const MouseEvent& rMEvt );
98 virtual void Paint( const Rectangle& );
99 virtual void PopupModeEnd();
100 virtual SfxPopupWindow* Clone() const;
102 private:
103 void Update( long nNewCol, long nNewLine );
104 void TableDialog( const Sequence< PropertyValue >& rArgs );
105 void CloseAndShowTableDialog();
108 // -----------------------------------------------------------------------
110 IMPL_LINK_NOARG(TableWindow, SelectHdl)
112 CloseAndShowTableDialog();
113 return 0;
116 // -----------------------------------------------------------------------
118 TableWindow::TableWindow( sal_uInt16 nSlotId, const rtl::OUString& rCmd, const String& rText, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ) :
119 SfxPopupWindow( nSlotId, rFrame, WinBits( WB_STDPOPUP ) ),
120 aTableButton( this ),
121 nCol( 0 ),
122 nLine( 0 ),
123 rTbx(rParentTbx),
124 mxFrame( rFrame ),
125 maCommand( rCmd )
127 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
128 svtools::ColorConfig aColorConfig;
130 aLineColor = rStyles.GetShadowColor();
131 aFillColor = rStyles.GetWindowColor();
132 aHighlightFillColor = rStyles.GetHighlightColor();
133 aBackgroundColor = GetSettings().GetStyleSettings().GetFaceColor();
135 SetBackground( aBackgroundColor );
136 Font aFont = GetFont();
137 aFont.SetColor( ::Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor ) );
138 aFont.SetFillColor( aBackgroundColor );
139 aFont.SetTransparent( sal_False );
140 SetFont( aFont );
142 SetText( rText );
144 aTableButton.SetPosSizePixel( Point( TABLE_POS_X + TABLE_CELL_WIDTH, TABLE_HEIGHT + 5 ),
145 Size( TABLE_WIDTH - TABLE_POS_X - 2*TABLE_CELL_WIDTH, 24 ) );
146 aTableButton.SetText( String( SVX_RESSTR( RID_SVXSTR_MORE ) ) );
147 aTableButton.SetClickHdl( LINK( this, TableWindow, SelectHdl ) );
148 aTableButton.Show();
150 SetOutputSizePixel( Size( TABLE_WIDTH + 3, TABLE_HEIGHT + 33 ) );
153 // -----------------------------------------------------------------------
155 TableWindow::~TableWindow()
159 // -----------------------------------------------------------------------
161 SfxPopupWindow* TableWindow::Clone() const
163 return new TableWindow( GetId(), maCommand, GetText(), rTbx, mxFrame );
166 // -----------------------------------------------------------------------
168 void TableWindow::MouseMove( const MouseEvent& rMEvt )
170 SfxPopupWindow::MouseMove( rMEvt );
171 Point aPos = rMEvt.GetPosPixel();
172 Point aMousePos( aPos );
174 long nNewCol = ( aMousePos.X() - TABLE_POS_X + TABLE_CELL_WIDTH ) / TABLE_CELL_WIDTH;
175 long nNewLine = ( aMousePos.Y() - TABLE_POS_Y + TABLE_CELL_HEIGHT ) / TABLE_CELL_HEIGHT;
177 Update( nNewCol, nNewLine );
180 // -----------------------------------------------------------------------
182 void TableWindow::KeyInput( const KeyEvent& rKEvt )
184 bool bHandled = false;
185 sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
186 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
187 if ( !nModifier )
189 bHandled = true;
190 long nNewCol = nCol;
191 long nNewLine = nLine;
192 switch(nKey)
194 case KEY_UP:
195 if ( nNewLine > 1 )
196 nNewLine--;
197 else
198 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
199 break;
200 case KEY_DOWN:
201 if ( nNewLine < TABLE_CELLS_VERT )
202 nNewLine++;
203 else
204 CloseAndShowTableDialog();
205 break;
206 case KEY_LEFT:
207 if ( nNewCol > 1 )
208 nNewCol--;
209 else
210 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
211 break;
212 case KEY_RIGHT:
213 if ( nNewCol < TABLE_CELLS_HORIZ )
214 nNewCol++;
215 else
216 CloseAndShowTableDialog();
217 break;
218 case KEY_ESCAPE:
219 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
220 break;
221 case KEY_RETURN:
222 EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
223 break;
224 case KEY_TAB:
225 CloseAndShowTableDialog();
226 break;
227 default:
228 bHandled = false;
230 if ( bHandled )
232 //make sure that a table can initially be created
233 if(bInitialKeyInput)
235 bInitialKeyInput = sal_False;
236 if(!nNewLine)
237 nNewLine = 1;
238 if(!nNewCol)
239 nNewCol = 1;
241 Update( nNewCol, nNewLine );
244 else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
246 m_bMod1 = sal_True;
247 EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
250 if(!bHandled)
251 SfxPopupWindow::KeyInput(rKEvt);
254 // -----------------------------------------------------------------------
256 void TableWindow::MouseButtonUp( const MouseEvent& rMEvt )
258 SfxPopupWindow::MouseButtonUp( rMEvt );
259 EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
262 // -----------------------------------------------------------------------
264 void TableWindow::Paint( const Rectangle& )
266 const long nSelectionWidth = TABLE_POS_X + nCol*TABLE_CELL_WIDTH;
267 const long nSelectionHeight = TABLE_POS_Y + nLine*TABLE_CELL_HEIGHT;
269 // the non-selected parts of the table
270 SetLineColor( aLineColor );
271 SetFillColor( aFillColor );
272 DrawRect( Rectangle( nSelectionWidth, TABLE_POS_Y, TABLE_WIDTH, nSelectionHeight ) );
273 DrawRect( Rectangle( TABLE_POS_X, nSelectionHeight, nSelectionWidth, TABLE_HEIGHT ) );
274 DrawRect( Rectangle( nSelectionWidth, nSelectionHeight, TABLE_WIDTH, TABLE_HEIGHT ) );
276 // the selection
277 if ( nCol > 0 && nLine > 0 )
279 SetFillColor( aHighlightFillColor );
280 DrawRect( Rectangle( TABLE_POS_X, TABLE_POS_Y,
281 nSelectionWidth, nSelectionHeight ) );
284 // lines inside of the table
285 SetLineColor( aLineColor );
286 for ( long i = 1; i < TABLE_CELLS_VERT; ++i )
287 DrawLine( Point( TABLE_POS_X, TABLE_POS_Y + i*TABLE_CELL_HEIGHT ),
288 Point( TABLE_WIDTH, TABLE_POS_Y + i*TABLE_CELL_HEIGHT ) );
290 for ( long i = 1; i < TABLE_CELLS_HORIZ; ++i )
291 DrawLine( Point( TABLE_POS_X + i*TABLE_CELL_WIDTH, TABLE_POS_Y ),
292 Point( TABLE_POS_X + i*TABLE_CELL_WIDTH, TABLE_HEIGHT ) );
294 // the text near the mouse cursor telling the table dimensions
295 if ( nCol && nLine )
297 String aText;
298 aText += String::CreateFromInt32( nCol );
299 aText.AppendAscii( " x " );
300 aText += String::CreateFromInt32( nLine );
301 if(GetId() == FN_SHOW_MULTIPLE_PAGES)
303 aText += ' ';
304 aText += String(SVX_RESSTR(RID_SVXSTR_PAGES));
307 Size aTextSize( GetTextWidth( aText ), GetTextHeight() );
309 long nTextX = nSelectionWidth + TABLE_CELL_WIDTH;
310 long nTextY = nSelectionHeight + TABLE_CELL_HEIGHT;
311 const long nTipBorder = 2;
313 if ( aTextSize.Width() + TABLE_POS_X + TABLE_CELL_WIDTH + 2*nTipBorder < nSelectionWidth )
314 nTextX = nSelectionWidth - TABLE_CELL_WIDTH - aTextSize.Width();
316 if ( aTextSize.Height() + TABLE_POS_Y + TABLE_CELL_HEIGHT + 2*nTipBorder < nSelectionHeight )
317 nTextY = nSelectionHeight - TABLE_CELL_HEIGHT - aTextSize.Height();
319 SetLineColor( aLineColor );
320 SetFillColor( aBackgroundColor );
321 DrawRect( Rectangle ( nTextX - 2*nTipBorder, nTextY - 2*nTipBorder,
322 nTextX + aTextSize.Width() + nTipBorder, nTextY + aTextSize.Height() + nTipBorder ) );
324 // #i95350# force RTL output
325 if ( IsRTLEnabled() )
326 aText.Insert( 0x202D, 0 );
328 DrawText( Point( nTextX, nTextY ), aText );
332 // -----------------------------------------------------------------------
334 void TableWindow::PopupModeEnd()
336 if ( !IsPopupModeCanceled() && nCol && nLine )
338 Sequence< PropertyValue > aArgs( 2 );
339 aArgs[0].Name = ::rtl::OUString( "Columns" );
340 aArgs[0].Value = makeAny( sal_Int16( nCol ));
341 aArgs[1].Name = ::rtl::OUString( "Rows" );
342 aArgs[1].Value = makeAny( sal_Int16( nLine ));
344 TableDialog( aArgs );
347 SfxPopupWindow::PopupModeEnd();
350 // -----------------------------------------------------------------------
352 void TableWindow::Update( long nNewCol, long nNewLine )
354 if ( nNewCol < 0 || nNewCol > TABLE_CELLS_HORIZ )
355 nNewCol = 0;
357 if ( nNewLine < 0 || nNewLine > TABLE_CELLS_VERT )
358 nNewLine = 0;
360 if ( nNewCol != nCol || nNewLine != nLine )
362 nCol = nNewCol;
363 nLine = nNewLine;
364 Invalidate( Rectangle( TABLE_POS_X, TABLE_POS_Y, TABLE_WIDTH, TABLE_HEIGHT ) );
368 // -----------------------------------------------------------------------
370 void TableWindow::TableDialog( const Sequence< PropertyValue >& rArgs )
372 Window* pParent = rTbx.GetParent();
373 sal_uInt16 nId = GetId();
374 pParent->UserEvent(SVX_EVENT_COLUM_WINDOW_EXECUTE, reinterpret_cast<void*>(nId));
376 Reference< XDispatchProvider > xDispatchProvider( mxFrame, UNO_QUERY );
377 if ( xDispatchProvider.is() )
379 com::sun::star::util::URL aTargetURL;
380 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
381 rtl::OUString("com.sun.star.util.URLTransformer")),
382 UNO_QUERY );
383 aTargetURL.Complete = maCommand;
384 xTrans->parseStrict( aTargetURL );
386 Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, rtl::OUString(), 0 );
387 if ( xDispatch.is() )
388 xDispatch->dispatch( aTargetURL, rArgs );
392 // -----------------------------------------------------------------------
394 void TableWindow::CloseAndShowTableDialog()
396 // close the toolbar tool
397 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
399 // and open the table dialog instead
400 TableDialog( Sequence< PropertyValue >() );
403 // class ColumnsWindow ---------------------------------------------------
405 class ColumnsWindow : public SfxPopupWindow
407 private:
408 ::Color aLineColor;
409 ::Color aHighlightLineColor;
410 ::Color aFillColor;
411 ::Color aHighlightFillColor;
412 ::Color aFaceColor;
413 long nCol;
414 long nWidth;
415 long nMX;
416 long nTextHeight;
417 sal_Bool bInitialKeyInput;
418 sal_Bool m_bMod1;
419 ToolBox& rTbx;
420 Reference< XFrame > mxFrame;
421 ::rtl::OUString maCommand;
423 void UpdateSize_Impl( long nNewCol );
424 public:
425 ColumnsWindow( sal_uInt16 nId, const ::rtl::OUString& rCmd, const String &rText, ToolBox& rParentTbx, const Reference< XFrame >& rFrame );
427 void KeyInput( const KeyEvent& rKEvt );
428 virtual void MouseMove( const MouseEvent& rMEvt );
429 virtual void MouseButtonDown( const MouseEvent& rMEvt );
430 virtual void MouseButtonUp( const MouseEvent& rMEvt );
431 virtual void Paint( const Rectangle& );
432 virtual void PopupModeEnd();
433 virtual SfxPopupWindow* Clone() const;
435 sal_uInt16 GetColCount() const { return (sal_uInt16)nCol; }
438 // -----------------------------------------------------------------------
440 ColumnsWindow::ColumnsWindow( sal_uInt16 nId, const ::rtl::OUString& rCmd, const String& rText, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ) :
441 SfxPopupWindow( nId, rFrame, WB_STDPOPUP ),
442 bInitialKeyInput(sal_True),
443 m_bMod1(sal_False),
444 rTbx(rParentTbx),
445 mxFrame(rFrame),
446 maCommand( rCmd )
448 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
449 svtools::ColorConfig aColorConfig;
450 aLineColor = ::Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
451 aHighlightLineColor = rStyles.GetHighlightTextColor();
452 aFillColor = rStyles.GetWindowColor();
453 aHighlightFillColor = rStyles.GetHighlightColor();
454 aFaceColor = rStyles.GetFaceColor();
456 nTextHeight = GetTextHeight()+1;
457 SetBackground();
458 Font aFont( GetFont() );
459 aFont.SetColor( aLineColor );
460 aFont.SetFillColor( aFaceColor );
461 aFont.SetTransparent( sal_False );
462 SetFont( aFont );
464 nCol = 0;
465 nWidth = 4;
467 SetText( rText );
469 Size aLogicSize = LogicToPixel( Size( 95, 155 ), MapMode( MAP_10TH_MM ) );
470 nMX = aLogicSize.Width();
471 SetOutputSizePixel( Size( nMX*nWidth-1, aLogicSize.Height()+nTextHeight ) );
472 StartCascading();
475 // -----------------------------------------------------------------------
477 SfxPopupWindow* ColumnsWindow::Clone() const
479 return new ColumnsWindow( GetId(), maCommand, GetText(), rTbx, mxFrame );
482 // -----------------------------------------------------------------------
484 void ColumnsWindow::MouseMove( const MouseEvent& rMEvt )
486 SfxPopupWindow::MouseMove( rMEvt );
487 Point aPos = rMEvt.GetPosPixel();
488 Point aMousePos = aPos;
490 if ( rMEvt.IsEnterWindow() )
491 CaptureMouse();
492 else if ( aMousePos.X() < 0 || aMousePos.Y() < 0 )
494 nCol = 0;
495 ReleaseMouse();
496 Invalidate();
497 return;
500 long nNewCol = 0;
501 if ( aPos.X() > 0 )
502 nNewCol = aPos.X() / nMX + 1;
503 if ( aPos.Y() < 0 )
504 nNewCol = 0;
505 if ( nNewCol > 20 )
506 nNewCol = 20;
507 UpdateSize_Impl( nNewCol );
510 void ColumnsWindow::UpdateSize_Impl( long nNewCol )
512 Size aWinSize = GetOutputSizePixel();
513 Point aWinPos;// = GetPosPixel();
515 if ( nWidth <= nNewCol )
517 Point aMaxPos = OutputToScreenPixel( GetDesktopRectPixel().BottomRight() );
519 if ( nWidth <= nNewCol )
521 nWidth = nNewCol;
522 nWidth++;
525 while ( nWidth > 0 &&
526 (short)(aWinPos.X()+(nMX*nWidth-1)) >= aMaxPos.X()-3 )
527 nWidth--;
529 if ( nNewCol > nWidth )
530 nNewCol = nWidth;
532 Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2,
533 aWinSize.Width(), aWinSize.Height() ) );
534 SetOutputSizePixel( Size( nMX*nWidth-1, aWinSize.Height() ) );
538 if ( nNewCol != nCol )
540 Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2,
541 aWinSize.Width(), aWinSize.Height() ) );
543 long nMinCol = 0, nMaxCol = 0;
545 if ( nNewCol < nCol )
547 nMinCol = nNewCol;
548 nMaxCol = nCol;
550 else
552 nMinCol = nCol;
553 nMaxCol = nNewCol;
556 Invalidate( Rectangle( nMinCol*nMX-1, 0,
557 nMaxCol*nMX+1, aWinSize.Height()-nTextHeight+2 ) );
558 nCol = nNewCol;
560 Update();
562 // -----------------------------------------------------------------------
564 void ColumnsWindow::MouseButtonDown( const MouseEvent& rMEvt )
566 SfxPopupWindow::MouseButtonDown( rMEvt );
567 CaptureMouse();
570 void ColumnsWindow::KeyInput( const KeyEvent& rKEvt )
572 sal_Bool bHandled = sal_False;
573 sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
574 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
575 if(!nModifier)
577 if( KEY_LEFT == nKey || KEY_RIGHT == nKey ||
578 KEY_RETURN == nKey ||KEY_ESCAPE == nKey ||
579 KEY_UP == nKey)
581 bHandled = sal_True;
582 long nNewCol = nCol;
583 switch(nKey)
585 case KEY_LEFT :
586 if(nNewCol)
587 nNewCol--;
588 break;
589 case KEY_RIGHT :
590 nNewCol++;
591 break;
592 case KEY_RETURN :
593 if(IsMouseCaptured())
594 ReleaseMouse();
595 EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL );
596 break;
597 case KEY_ESCAPE :
598 case KEY_UP :
599 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL);
600 break;
602 //make sure that a table can initially be created
603 if(bInitialKeyInput)
605 bInitialKeyInput = sal_False;
606 if(!nNewCol)
607 nNewCol = 1;
609 UpdateSize_Impl( nNewCol );
612 else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
614 m_bMod1 = sal_True;
615 if(IsMouseCaptured())
616 ReleaseMouse();
617 EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL );
619 if(!bHandled)
620 SfxPopupWindow::KeyInput(rKEvt);
623 // -----------------------------------------------------------------------
625 void ColumnsWindow::MouseButtonUp( const MouseEvent& rMEvt )
627 SfxPopupWindow::MouseButtonUp( rMEvt );
628 ReleaseMouse();
630 if ( IsInPopupMode() )
631 EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
634 // -----------------------------------------------------------------------
636 void ColumnsWindow::Paint( const Rectangle& )
638 long i;
639 long j;
640 long nLineWidth;
641 Size aSize = GetOutputSizePixel();
643 for ( i = 0; i < nWidth; i++ )
645 if ( i < nCol )
647 SetLineColor( aHighlightLineColor );
648 SetFillColor( aHighlightFillColor );
650 else
652 SetLineColor( aLineColor );
653 SetFillColor( aFillColor );
656 DrawRect( Rectangle( i*nMX-1, -1,
657 i*nMX+nMX, aSize.Height()-nTextHeight+1 ) );
659 j = 4;
660 while ( j < aSize.Height()-nTextHeight-4 )
662 if ( !(j % 16) )
663 nLineWidth = 10;
664 else
665 nLineWidth = 4;
666 DrawLine( Point( i*nMX+4, j ), Point( i*nMX+nMX-nLineWidth-4, j ) );
667 j += 4;
671 SetLineColor();
672 SetFillColor( aFaceColor );
673 String aText;
674 if ( nCol )
675 aText = String::CreateFromInt32(nCol);
676 else
677 aText = comphelper::string::remove(Button::GetStandardText(BUTTON_CANCEL), '~');
679 Size aTextSize(GetTextWidth( aText ), GetTextHeight());
680 DrawText( Point( ( aSize.Width() - aTextSize.Width() ) / 2, aSize.Height() - nTextHeight + 2 ), aText );
682 DrawRect( Rectangle( 0, aSize.Height()-nTextHeight+2, (aSize.Width()-aTextSize.Width())/2-1, aSize.Height() ) );
683 DrawRect( Rectangle( (aSize.Width()-aTextSize.Width())/2+aTextSize.Width(), aSize.Height()-nTextHeight+2, aSize.Width(), aSize.Height() ) );
685 SetLineColor( aLineColor );
686 SetFillColor();
687 DrawRect( Rectangle( 0, 0, aSize.Width() - 1, aSize.Height() - nTextHeight + 1 ) );
690 // -----------------------------------------------------------------------
692 void ColumnsWindow::PopupModeEnd()
694 if ( !IsPopupModeCanceled() && nCol )
696 sal_uInt16 nId = GetId();
697 Window* pParent = rTbx.GetParent();
698 pParent->UserEvent(SVX_EVENT_COLUM_WINDOW_EXECUTE, reinterpret_cast<void*>(nId));
700 Sequence< PropertyValue > aArgs( 2 );
701 aArgs[0].Name = ::rtl::OUString( "Columns" );
702 aArgs[0].Value = makeAny( sal_Int16( nCol ));
703 aArgs[1].Name = ::rtl::OUString( "Modifier" );
704 aArgs[1].Value = makeAny( sal_Int16( m_bMod1 ? KEY_MOD1 : 0 ));
706 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
707 maCommand,
708 aArgs );
710 else if ( IsPopupModeCanceled() )
711 ReleaseMouse();
712 SfxPopupWindow::PopupModeEnd();
715 // class SvxTableToolBoxControl ------------------------------------------
717 SvxTableToolBoxControl::SvxTableToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
718 SfxToolBoxControl( nSlotId, nId, rTbx ),
719 bEnabled( sal_True )
721 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
722 rTbx.Invalidate();
725 // -----------------------------------------------------------------------
727 SvxTableToolBoxControl::~SvxTableToolBoxControl()
731 // -----------------------------------------------------------------------
733 SfxPopupWindowType SvxTableToolBoxControl::GetPopupWindowType() const
735 return SFX_POPUPWINDOW_ONTIMEOUTANDMOVE;
738 // -----------------------------------------------------------------------
740 SfxPopupWindow* SvxTableToolBoxControl::CreatePopupWindow()
742 if ( bEnabled )
744 ToolBox& rTbx = GetToolBox();
745 TableWindow* pWin = new TableWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), rTbx, m_xFrame );
746 pWin->StartPopupMode( &rTbx, FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_NOKEYCLOSE );
747 SetPopupWindow( pWin );
748 return pWin;
750 return 0;
753 // -----------------------------------------------------------------------
755 SfxPopupWindow* SvxTableToolBoxControl::CreatePopupWindowCascading()
757 if ( bEnabled )
758 return new TableWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), GetToolBox(), m_xFrame );
759 return 0;
762 // -----------------------------------------------------------------------
764 void SvxTableToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
766 if ( pState && pState->ISA(SfxUInt16Item) )
768 sal_Int16 nValue = static_cast< const SfxUInt16Item* >( pState )->GetValue();
769 bEnabled = ( nValue != 0 );
771 else
772 bEnabled = SFX_ITEM_DISABLED != eState;
774 sal_uInt16 nId = GetId();
775 ToolBox& rTbx = GetToolBox();
777 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState );
778 rTbx.SetItemState( nId,
779 ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK );
782 // class SvxColumnsToolBoxControl ------------------------------------------
784 SvxColumnsToolBoxControl::SvxColumnsToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
785 SfxToolBoxControl( nSlotId, nId, rTbx )
787 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
788 rTbx.Invalidate();
791 // -----------------------------------------------------------------------
793 SvxColumnsToolBoxControl::~SvxColumnsToolBoxControl()
797 // -----------------------------------------------------------------------
799 SfxPopupWindowType SvxColumnsToolBoxControl::GetPopupWindowType() const
801 return SFX_POPUPWINDOW_ONTIMEOUTANDMOVE;
804 // -----------------------------------------------------------------------
806 SfxPopupWindow* SvxColumnsToolBoxControl::CreatePopupWindow()
808 ColumnsWindow* pWin = 0;
809 if(bEnabled)
811 pWin = new ColumnsWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), GetToolBox(), m_xFrame );
812 pWin->StartPopupMode( &GetToolBox(),
813 FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_NOKEYCLOSE );
814 SetPopupWindow( pWin );
816 return pWin;
819 // -----------------------------------------------------------------------
821 SfxPopupWindow* SvxColumnsToolBoxControl::CreatePopupWindowCascading()
823 ColumnsWindow* pWin = 0;
824 if(bEnabled)
826 pWin = new ColumnsWindow( GetSlotId(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), GetToolBox(), m_xFrame );
828 return pWin;
831 void SvxColumnsToolBoxControl::StateChanged( sal_uInt16 nSID,
832 SfxItemState eState,
833 const SfxPoolItem* pState )
835 bEnabled = SFX_ITEM_DISABLED != eState;
836 SfxToolBoxControl::StateChanged(nSID, eState, pState );
839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */