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