LibreOffice Module svx (master)  1
layctrl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <string>
21 #include <vcl/button.hxx>
22 #include <vcl/toolbox.hxx>
23 #include <vcl/stdtext.hxx>
24 #include <vcl/event.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svl/intitem.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/app.hxx>
30 
31 #include <svx/strings.hrc>
32 #include <svx/svxids.hrc>
33 #include <svx/layctrl.hxx>
34 #include <svx/dialmgr.hxx>
36 #include <svtools/colorcfg.hxx>
37 #include <com/sun/star/util/URLTransformer.hpp>
38 #include <com/sun/star/frame/XDispatchProvider.hpp>
39 #include <com/sun/star/frame/XFrame.hpp>
40 
41 // namespaces
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::util;
45 using namespace ::com::sun::star::frame;
46 
49 
50 namespace {
51 
52 class TableWindow : public SfxPopupWindow
53 {
54 private:
55  VclPtr<PushButton> aTableButton;
56  ::Color aLineColor;
57  ::Color aFillColor;
58  ::Color aHighlightFillColor;
59  ::Color aBackgroundColor;
60  long nCol;
61  long nLine;
62  Reference< XFrame > mxFrame;
63  OUString const maCommand;
64 
65  static const long TABLE_CELLS_HORIZ;
66  static const long TABLE_CELLS_VERT;
67 
68  long mnTableCellWidth;
69  long mnTableCellHeight;
70 
71  long mnTableWidth;
72  long mnTableHeight;
73 
74  DECL_LINK( SelectHdl, Button*, void );
75 
76 public:
77  TableWindow( sal_uInt16 nSlotId,
78  vcl::Window* pParent,
79  const OUString& rCmd,
80  const OUString& rText,
81  const Reference< XFrame >& rFrame );
82  virtual ~TableWindow() override;
83  virtual void dispose() override;
84 
85  void KeyInput( const KeyEvent& rKEvt ) override;
86  virtual void MouseMove( const MouseEvent& rMEvt ) override;
87  virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
88  virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& ) override;
89  virtual void PopupModeEnd() override;
90  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
91 
92 private:
93  void Update( long nNewCol, long nNewLine );
94  void TableDialog( const Sequence< PropertyValue >& rArgs );
95  void CloseAndShowTableDialog();
96 };
97 
98 }
99 
100 const long TableWindow::TABLE_CELLS_HORIZ = 10;
101 const long TableWindow::TABLE_CELLS_VERT = 15;
102 
103 
104 IMPL_LINK_NOARG(TableWindow, SelectHdl, Button*, void)
105 {
106  CloseAndShowTableDialog();
107 }
108 
109 constexpr long nTablePosX = 2;
110 constexpr long nTablePosY = 2;
111 
112 TableWindow::TableWindow( sal_uInt16 nSlotId, vcl::Window* pParent, const OUString& rCmd,
113  const OUString& rText, const Reference< XFrame >& rFrame )
114  : SfxPopupWindow( nSlotId, pParent, rFrame, WB_STDPOPUP )
115  , aTableButton( VclPtr<PushButton>::Create(this) )
116  , nCol( 0 )
117  , nLine( 0 )
118  , mxFrame( rFrame )
119  , maCommand( rCmd )
120 {
121  float fScaleFactor = GetDPIScaleFactor();
122 
123  mnTableCellWidth = 15 * fScaleFactor;
124  mnTableCellHeight = 15 * fScaleFactor;
125 
126  mnTableWidth = nTablePosX + TABLE_CELLS_HORIZ*mnTableCellWidth;
127  mnTableHeight = nTablePosY + TABLE_CELLS_VERT*mnTableCellHeight;
128 
130  svtools::ColorConfig aColorConfig;
131 
132  aLineColor = rStyles.GetShadowColor();
133  aFillColor = rStyles.GetWindowColor();
134  aHighlightFillColor = rStyles.GetHighlightColor();
135  aBackgroundColor = GetSettings().GetStyleSettings().GetFaceColor();
136 
137  SetBackground( aBackgroundColor );
138  vcl::Font aFont = GetFont();
139  aFont.SetColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
140  aFont.SetFillColor( aBackgroundColor );
141  aFont.SetTransparent( false );
142  SetFont( aFont );
143 
144  SetText( rText );
145 
146  // if parent window is a toolbox only display table button when mouse activated
147  ToolBox* pToolBox = nullptr;
148  if (pParent->GetType() == WindowType::TOOLBOX)
149  pToolBox = dynamic_cast<ToolBox*>( pParent );
150  if ( !pToolBox || !pToolBox->IsKeyEvent() )
151  {
152  aTableButton->SetPosSizePixel( Point( nTablePosX, mnTableHeight + 5 ),
153  Size( mnTableWidth - nTablePosX, 24 ) );
154  aTableButton->SetText( SvxResId( RID_SVXSTR_MORE ) );
155  aTableButton->SetClickHdl( LINK( this, TableWindow, SelectHdl ) );
156  aTableButton->Show();
157 
158  SetOutputSizePixel( Size( mnTableWidth + 3, mnTableHeight + 33 ) );
159  }
160  else
161  SetOutputSizePixel( Size( mnTableWidth + 3, mnTableHeight + 3 ) );
162 }
163 
164 
165 TableWindow::~TableWindow()
166 {
167  disposeOnce();
168 }
169 
170 void TableWindow::dispose()
171 {
172  aTableButton.disposeAndClear();
174 }
175 
176 void TableWindow::MouseMove( const MouseEvent& rMEvt )
177 {
178  SfxPopupWindow::MouseMove( rMEvt );
179  Point aPos = rMEvt.GetPosPixel();
180  Point aMousePos( aPos );
181 
182  long nNewCol = ( aMousePos.X() - nTablePosX + mnTableCellWidth ) / mnTableCellWidth;
183  long nNewLine = ( aMousePos.Y() - nTablePosY + mnTableCellHeight ) / mnTableCellHeight;
184 
185  Update( nNewCol, nNewLine );
186 }
187 
188 
189 void TableWindow::KeyInput( const KeyEvent& rKEvt )
190 {
191  bool bHandled = false;
192  sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
193  sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
194  if ( !nModifier )
195  {
196  bHandled = true;
197  long nNewCol = nCol;
198  long nNewLine = nLine;
199  switch(nKey)
200  {
201  case KEY_UP:
202  if ( nNewLine > 1 )
203  nNewLine--;
204  else
205  EndPopupMode( FloatWinPopupEndFlags::Cancel );
206  break;
207  case KEY_DOWN:
208  if ( nNewLine < TABLE_CELLS_VERT )
209  nNewLine++;
210  else
211  CloseAndShowTableDialog();
212  break;
213  case KEY_LEFT:
214  if ( nNewCol > 1 )
215  nNewCol--;
216  else
217  EndPopupMode( FloatWinPopupEndFlags::Cancel );
218  break;
219  case KEY_RIGHT:
220  if ( nNewCol < TABLE_CELLS_HORIZ )
221  nNewCol++;
222  else
223  CloseAndShowTableDialog();
224  break;
225  case KEY_ESCAPE:
226  EndPopupMode( FloatWinPopupEndFlags::Cancel );
227  break;
228  case KEY_RETURN:
229  EndPopupMode( FloatWinPopupEndFlags::CloseAll );
230  GrabFocusToDocument();
231  return;
232  case KEY_TAB:
233  CloseAndShowTableDialog();
234  break;
235  default:
236  bHandled = false;
237  }
238  if ( bHandled )
239  {
240  Update( nNewCol, nNewLine );
241  }
242  }
243  else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
244  {
245  EndPopupMode( FloatWinPopupEndFlags::CloseAll );
246  GrabFocusToDocument();
247  return;
248  }
249 
250  if(!bHandled)
251  SfxPopupWindow::KeyInput(rKEvt);
252 }
253 
254 
255 void TableWindow::MouseButtonUp( const MouseEvent& rMEvt )
256 {
257  SfxPopupWindow::MouseButtonUp( rMEvt );
258  EndPopupMode( FloatWinPopupEndFlags::CloseAll );
259  GrabFocusToDocument();
260 }
261 
262 
263 void TableWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
264 {
265  const long nSelectionWidth = nTablePosX + nCol * mnTableCellWidth;
266  const long nSelectionHeight = nTablePosY + nLine * mnTableCellHeight;
267 
268  // the non-selected parts of the table
269  rRenderContext.SetLineColor(aLineColor);
270  rRenderContext.SetFillColor(aFillColor);
271  rRenderContext.DrawRect(tools::Rectangle(nSelectionWidth, nTablePosY, mnTableWidth, nSelectionHeight));
272  rRenderContext.DrawRect(tools::Rectangle(nTablePosX, nSelectionHeight, nSelectionWidth, mnTableHeight));
273  rRenderContext.DrawRect(tools::Rectangle(nSelectionWidth, nSelectionHeight, mnTableWidth, mnTableHeight));
274 
275  // the selection
276  if (nCol > 0 && nLine > 0)
277  {
278  rRenderContext.SetFillColor(aHighlightFillColor);
279  rRenderContext.DrawRect(tools::Rectangle(nTablePosX, nTablePosY, nSelectionWidth, nSelectionHeight));
280  }
281 
282  // lines inside of the table
283  rRenderContext.SetLineColor(aLineColor);
284  for (long i = 1; i < TABLE_CELLS_VERT; ++i)
285  {
286  rRenderContext.DrawLine(Point(nTablePosX, nTablePosY + i*mnTableCellHeight),
287  Point(mnTableWidth, nTablePosY + i*mnTableCellHeight));
288  }
289 
290  for (long i = 1; i < TABLE_CELLS_HORIZ; ++i)
291  {
292  rRenderContext.DrawLine(Point( nTablePosX + i*mnTableCellWidth, nTablePosY),
293  Point( nTablePosX + i*mnTableCellWidth, mnTableHeight));
294  }
295 
296  // the text near the mouse cursor telling the table dimensions
297  if (!nCol || !nLine)
298  return;
299 
300  OUString aText = OUString::number( nCol ) + " x " + OUString::number( nLine );
301  if(GetId() == FN_SHOW_MULTIPLE_PAGES)
302  {
303  aText += " " + SvxResId(RID_SVXSTR_PAGES);
304  }
305 
306  Size aTextSize(rRenderContext.GetTextWidth(aText), rRenderContext.GetTextHeight());
307 
308  long nTextX = nSelectionWidth + mnTableCellWidth;
309  long nTextY = nSelectionHeight + mnTableCellHeight;
310  const long nTipBorder = 2;
311 
312  if (aTextSize.Width() + nTablePosX + mnTableCellWidth + 2 * nTipBorder < nSelectionWidth)
313  nTextX = nSelectionWidth - mnTableCellWidth - aTextSize.Width();
314 
315  if (aTextSize.Height() + nTablePosY + mnTableCellHeight + 2 * nTipBorder < nSelectionHeight)
316  nTextY = nSelectionHeight - mnTableCellHeight - aTextSize.Height();
317 
318  rRenderContext.SetLineColor(aLineColor);
319  rRenderContext.SetFillColor(aBackgroundColor);
320  rRenderContext.DrawRect(tools::Rectangle(nTextX - 2 * nTipBorder,
321  nTextY - 2 * nTipBorder,
322  nTextX + aTextSize.Width() + nTipBorder,
323  nTextY + aTextSize.Height() + nTipBorder));
324 
325  // #i95350# force RTL output
326  if (IsRTLEnabled())
327  aText = u"\u202D" + aText;
328 
329  rRenderContext.DrawText(Point(nTextX, nTextY), aText);
330 }
331 
332 
333 void TableWindow::PopupModeEnd()
334 {
335  if ( !IsPopupModeCanceled() && nCol && nLine )
336  {
337  Sequence< PropertyValue > aArgs( 2 );
338  aArgs[0].Name = "Columns";
339  aArgs[0].Value <<= sal_Int16( nCol );
340  aArgs[1].Name = "Rows";
341  aArgs[1].Value <<= sal_Int16( nLine );
342 
343  TableDialog( aArgs );
344  }
345 
347 }
348 
349 
350 void TableWindow::Update( long nNewCol, long nNewLine )
351 {
352  if ( nNewCol < 0 || nNewCol > TABLE_CELLS_HORIZ )
353  nNewCol = 0;
354 
355  if ( nNewLine < 0 || nNewLine > TABLE_CELLS_VERT )
356  nNewLine = 0;
357 
358  if ( nNewCol != nCol || nNewLine != nLine )
359  {
360  nCol = nNewCol;
361  nLine = nNewLine;
362  Invalidate(tools::Rectangle(nTablePosX, nTablePosY, mnTableWidth, mnTableHeight));
363  }
364 }
365 
366 
367 void TableWindow::TableDialog( const Sequence< PropertyValue >& rArgs )
368 {
369  Reference< XDispatchProvider > xDispatchProvider( mxFrame, UNO_QUERY );
370  if ( xDispatchProvider.is() )
371  {
372  css::util::URL aTargetURL;
373  Reference < XURLTransformer > xTrans( URLTransformer::create(::comphelper::getProcessComponentContext()) );
374  aTargetURL.Complete = maCommand;
375  xTrans->parseStrict( aTargetURL );
376 
377  Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
378  if ( xDispatch.is() )
379  xDispatch->dispatch( aTargetURL, rArgs );
380  }
381 }
382 
383 
384 void TableWindow::CloseAndShowTableDialog()
385 {
386  // close the toolbar tool
387  EndPopupMode( FloatWinPopupEndFlags::Cancel );
388 
389  // and open the table dialog instead
390  TableDialog( Sequence< PropertyValue >() );
391 }
392 
393 bool TableWindow::EventNotify( NotifyEvent& rNEvt )
394 {
395  // handle table button key input
396  if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
397  {
398  const vcl::KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
399  const sal_uInt16 nCode = rKey.GetCode();
400  if ( nCode != KEY_RETURN && nCode != KEY_SPACE && nCode != KEY_ESCAPE )
401  {
402  return true;
403  }
404  }
405  return SfxPopupWindow::EventNotify( rNEvt );
406 }
407 
408 namespace {
409 
410 class ColumnsWindow : public SfxPopupWindow
411 {
412 private:
413  ::Color aLineColor;
414  ::Color aHighlightLineColor;
415  ::Color aFillColor;
416  ::Color aHighlightFillColor;
417  ::Color aFaceColor;
418  long nCol;
419  long nWidth;
420  long nMX;
421  long nTextHeight;
422  bool bInitialKeyInput;
423  bool m_bMod1;
424  Reference< XFrame > mxFrame;
425  OUString const maCommand;
426 
427  void UpdateSize_Impl( long nNewCol );
428 public:
429  ColumnsWindow( sal_uInt16 nId, vcl::Window* pParent, const OUString& rCmd,
430  const OUString &rText, const Reference< XFrame >& rFrame );
431 
432  void KeyInput( const KeyEvent& rKEvt ) override;
433  virtual void MouseMove( const MouseEvent& rMEvt ) override;
434  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
435  virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
436  virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& ) override;
437  virtual void PopupModeEnd() override;
438 };
439 
440 }
441 
442 ColumnsWindow::ColumnsWindow( sal_uInt16 nId, vcl::Window* pParent, const OUString& rCmd,
443  const OUString& rText, const Reference< XFrame >& rFrame ) :
444  SfxPopupWindow( nId, pParent, rFrame, WB_STDPOPUP ),
445  bInitialKeyInput(true),
446  m_bMod1(false),
447  mxFrame(rFrame),
448  maCommand( rCmd )
449 {
451  svtools::ColorConfig aColorConfig;
452  aLineColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
453  aHighlightLineColor = rStyles.GetHighlightTextColor();
454  aFillColor = rStyles.GetWindowColor();
455  aHighlightFillColor = rStyles.GetHighlightColor();
456  aFaceColor = rStyles.GetFaceColor();
457 
458  nTextHeight = GetTextHeight()+1;
459  SetBackground();
460  vcl::Font aFont( GetFont() );
461  aFont.SetColor( aLineColor );
462  aFont.SetFillColor( aFaceColor );
463  aFont.SetTransparent( false );
464  SetFont( aFont );
465 
466  nCol = 0;
467  nWidth = 4;
468 
469  SetText( rText );
470 
471  Size aLogicSize = LogicToPixel( Size( 95, 155 ), MapMode( MapUnit::Map10thMM ) );
472  nMX = aLogicSize.Width();
473  SetOutputSizePixel( Size( nMX*nWidth-1, aLogicSize.Height()+nTextHeight ) );
474  StartCascading();
475 }
476 
477 
478 void ColumnsWindow::MouseMove( const MouseEvent& rMEvt )
479 {
480  SfxPopupWindow::MouseMove( rMEvt );
481  Point aPos = rMEvt.GetPosPixel();
482  Point aMousePos = aPos;
483 
484  if ( rMEvt.IsEnterWindow() )
485  CaptureMouse();
486  else if ( aMousePos.X() < 0 || aMousePos.Y() < 0 )
487  {
488  nCol = 0;
489  ReleaseMouse();
490  Invalidate();
491  return;
492  }
493 
494  long nNewCol = 0;
495  if ( aPos.X() > 0 )
496  nNewCol = aPos.X() / nMX + 1;
497  if ( aPos.Y() < 0 )
498  nNewCol = 0;
499  if ( nNewCol > 20 )
500  nNewCol = 20;
501  UpdateSize_Impl( nNewCol );
502 }
503 
504 void ColumnsWindow::UpdateSize_Impl( long nNewCol )
505 {
506  Size aWinSize = GetOutputSizePixel();
507  Point aWinPos;// = GetPosPixel();
508 
509  if ( nWidth <= nNewCol )
510  {
511  Point aMaxPos = OutputToScreenPixel( GetDesktopRectPixel().BottomRight() );
512 
513  if ( nWidth <= nNewCol )
514  {
515  nWidth = nNewCol;
516  nWidth++;
517  }
518 
519  while ( nWidth > 0 &&
520  static_cast<short>(aWinPos.X()+(nMX*nWidth-1)) >= aMaxPos.X()-3 )
521  nWidth--;
522 
523  if ( nNewCol > nWidth )
524  nNewCol = nWidth;
525 
526  Invalidate( tools::Rectangle( 0, aWinSize.Height()-nTextHeight+2,
527  aWinSize.Width(), aWinSize.Height() ) );
528  SetOutputSizePixel( Size( nMX*nWidth-1, aWinSize.Height() ) );
529  }
530 
531 
532  if ( nNewCol != nCol )
533  {
534  Invalidate( tools::Rectangle( 0, aWinSize.Height()-nTextHeight+2,
535  aWinSize.Width(), aWinSize.Height() ) );
536 
537  long nMinCol = 0, nMaxCol = 0;
538 
539  if ( nNewCol < nCol )
540  {
541  nMinCol = nNewCol;
542  nMaxCol = nCol;
543  }
544  else
545  {
546  nMinCol = nCol;
547  nMaxCol = nNewCol;
548  }
549 
550  Invalidate( tools::Rectangle( nMinCol*nMX-1, 0,
551  nMaxCol*nMX+1, aWinSize.Height()-nTextHeight+2 ) );
552  nCol = nNewCol;
553  }
554  Update();
555 }
556 
557 
558 void ColumnsWindow::MouseButtonDown( const MouseEvent& rMEvt )
559 {
560  SfxPopupWindow::MouseButtonDown( rMEvt );
561  CaptureMouse();
562 }
563 
564 void ColumnsWindow::KeyInput( const KeyEvent& rKEvt )
565 {
566  bool bHandled = false;
567  sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier();
568  sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
569  if(!nModifier)
570  {
571  if( KEY_LEFT == nKey || KEY_RIGHT == nKey ||
572  KEY_RETURN == nKey ||KEY_ESCAPE == nKey ||
573  KEY_UP == nKey)
574  {
575  bHandled = true;
576  long nNewCol = nCol;
577  switch(nKey)
578  {
579  case KEY_LEFT :
580  if(nNewCol)
581  nNewCol--;
582  break;
583  case KEY_RIGHT :
584  nNewCol++;
585  break;
586  case KEY_RETURN :
587  if(IsMouseCaptured())
588  ReleaseMouse();
589  EndPopupMode(FloatWinPopupEndFlags::CloseAll );
590  break;
591  case KEY_ESCAPE :
592  case KEY_UP :
593  EndPopupMode( FloatWinPopupEndFlags::Cancel);
594  break;
595  }
596  //make sure that a table can initially be created
597  if(bInitialKeyInput)
598  {
599  bInitialKeyInput = false;
600  if(!nNewCol)
601  nNewCol = 1;
602  }
603  UpdateSize_Impl( nNewCol );
604  }
605  }
606  else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey)
607  {
608  m_bMod1 = true;
609  if(IsMouseCaptured())
610  ReleaseMouse();
611  EndPopupMode(FloatWinPopupEndFlags::CloseAll );
612  }
613  if(!bHandled)
614  SfxPopupWindow::KeyInput(rKEvt);
615 }
616 
617 
618 void ColumnsWindow::MouseButtonUp( const MouseEvent& rMEvt )
619 {
620  SfxPopupWindow::MouseButtonUp( rMEvt );
621  ReleaseMouse();
622 
623  if ( IsInPopupMode() )
624  EndPopupMode( FloatWinPopupEndFlags::CloseAll );
625 }
626 
627 
628 void ColumnsWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
629 {
630  long i;
631  long nLineWidth;
632  Size aSize(GetOutputSizePixel());
633 
634  for (i = 0; i < nWidth; i++)
635  {
636  if (i < nCol)
637  {
638  rRenderContext.SetLineColor(aHighlightLineColor);
639  rRenderContext.SetFillColor(aHighlightFillColor);
640  }
641  else
642  {
643  rRenderContext.SetLineColor(aLineColor);
644  rRenderContext.SetFillColor(aFillColor);
645  }
646 
647  rRenderContext.DrawRect(tools::Rectangle(i * nMX - 1, -1, i * nMX + nMX, aSize.Height() - nTextHeight + 1));
648 
649  long j = 4;
650  while (j < aSize.Height() - nTextHeight - 4)
651  {
652  if (!(j % 16))
653  nLineWidth = 10;
654  else
655  nLineWidth = 4;
656  rRenderContext.DrawLine(Point(i * nMX + 4, j), Point(i * nMX + nMX - nLineWidth - 4, j));
657  j += 4;
658  }
659  }
660 
661  rRenderContext.SetLineColor();
662  rRenderContext.SetFillColor(aFaceColor);
663  OUString aText;
664  if (nCol)
665  aText = OUString::number(nCol);
666  else
667  aText = GetStandardText(StandardButtonType::Cancel).replaceAll("~", "");
668 
669  Size aTextSize(rRenderContext.GetTextWidth(aText), rRenderContext.GetTextHeight());
670  rRenderContext.DrawText(Point((aSize.Width() - aTextSize.Width()) / 2, aSize.Height() - nTextHeight + 2), aText);
671 
672  rRenderContext.DrawRect(tools::Rectangle(0,
673  aSize.Height() - nTextHeight + 2,
674  (aSize.Width() - aTextSize.Width()) / 2 - 1,
675  aSize.Height()));
676 
677  rRenderContext.DrawRect(tools::Rectangle((aSize.Width() - aTextSize.Width()) / 2 + aTextSize.Width(),
678  aSize.Height() - nTextHeight + 2,
679  aSize.Width(),
680  aSize.Height()));
681 
682  rRenderContext.SetLineColor(aLineColor);
683  rRenderContext.SetFillColor();
684  rRenderContext.DrawRect(tools::Rectangle( 0, 0, aSize.Width() - 1, aSize.Height() - nTextHeight + 1));
685 }
686 
687 
688 void ColumnsWindow::PopupModeEnd()
689 {
690  if ( !IsPopupModeCanceled() && nCol )
691  {
692  Sequence< PropertyValue > aArgs( 2 );
693  aArgs[0].Name = "Columns";
694  aArgs[0].Value <<= sal_Int16( nCol );
695  aArgs[1].Name = "Modifier";
696  aArgs[1].Value <<= sal_Int16( m_bMod1 ? KEY_MOD1 : 0 );
697 
698  SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
699  maCommand,
700  aArgs );
701  }
702  else if ( IsPopupModeCanceled() )
703  ReleaseMouse();
705 }
706 
707 SvxTableToolBoxControl::SvxTableToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
708  SfxToolBoxControl( nSlotId, nId, rTbx ),
709  bEnabled( true )
710 {
711  rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWNONLY | rTbx.GetItemBits( nId ) );
712  rTbx.Invalidate();
713 }
714 
715 
717 {
718 }
719 
720 
722 {
723  if ( bEnabled )
724  {
725  ToolBox& rTbx = GetToolBox();
726  VclPtr<TableWindow> pWin = VclPtr<TableWindow>::Create( GetSlotId(), &GetToolBox(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), m_xFrame );
727  pWin->StartPopupMode( &rTbx, FloatWinPopupFlags::GrabFocus|FloatWinPopupFlags::NoKeyClose );
728  SetPopupWindow( pWin );
729  return pWin;
730  }
731  return nullptr;
732 }
733 
734 void SvxTableToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
735 {
736  if ( auto pUInt16Item = dynamic_cast<const SfxUInt16Item* >(pState) )
737  {
738  sal_Int16 nValue = pUInt16Item->GetValue();
739  bEnabled = ( nValue != 0 );
740  }
741  else
742  bEnabled = SfxItemState::DISABLED != eState;
743 
744  sal_uInt16 nId = GetId();
745  ToolBox& rTbx = GetToolBox();
746 
747  rTbx.EnableItem( nId, SfxItemState::DISABLED != eState );
748  rTbx.SetItemState( nId,
749  ( SfxItemState::DONTCARE == eState ) ? TRISTATE_INDET : TRISTATE_FALSE );
750 }
751 
752 SvxColumnsToolBoxControl::SvxColumnsToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
753  : SfxToolBoxControl(nSlotId, nId, rTbx)
754  , bEnabled(false)
755 {
756  rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
757  rTbx.Invalidate();
758 }
759 
760 
762 {
763 }
764 
765 
767 {
769  if(bEnabled)
770  {
771  pWin = VclPtr<ColumnsWindow>::Create( GetSlotId(), &GetToolBox(), m_aCommandURL, GetToolBox().GetItemText( GetId() ), m_xFrame );
772  pWin->StartPopupMode( &GetToolBox(),
773  FloatWinPopupFlags::GrabFocus|FloatWinPopupFlags::NoKeyClose );
774  SetPopupWindow( pWin );
775  }
776  return pWin;
777 }
778 
780  SfxItemState eState,
781  const SfxPoolItem* pState )
782 {
783  bEnabled = SfxItemState::DISABLED != eState;
784  SfxToolBoxControl::StateChanged(nSID, eState, pState );
785 }
786 
787 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const Color & GetShadowColor() const
void SetFillColor(const Color &)
void SetPopupWindow(SfxPopupWindow *pWindow)
#define KEY_TAB
const Color & GetHighlightTextColor() const
ToolBox & GetToolBox() const
OUString GetStandardText(StandardButtonType eButton)
long Height() const
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
const Color & GetFaceColor() const
css::uno::Reference< css::lang::XComponent > m_xFrame
sal_uInt16 GetCode() const
const KeyEvent * GetKeyEvent() const
bool IsKeyEvent() const
#define KEY_LEFT
const Color & GetHighlightColor() const
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
bool IsEnterWindow() const
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
virtual void PopupModeEnd() override
void SetItemState(sal_uInt16 nItemId, TriState eState)
virtual ~SvxTableToolBoxControl() override
Definition: layctrl.cxx:716
sal_uInt16 GetModifier() const
constexpr long nTablePosX
Definition: layctrl.cxx:109
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
WinBits const WB_STDPOPUP
void DrawLine(const Point &rStartPt, const Point &rEndPt)
sal_uInt16 nCode
TRISTATE_INDET
void DrawRect(const tools::Rectangle &rRect)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState)
void SetLineColor()
int i
#define KEY_ESCAPE
TRISTATE_FALSE
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
virtual ~SvxColumnsToolBoxControl() override
Definition: layctrl.cxx:761
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
void Create(SvxOrientationItem &rItem, SvStream &rStrm, sal_uInt16)
Definition: legacyitem.cxx:34
void SetFillColor()
IMPL_LINK_NOARG(TableWindow, SelectHdl, Button *, void)
Definition: layctrl.cxx:104
MouseNotifyEvent GetType() const
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: layctrl.cxx:779
virtual VclPtr< SfxPopupWindow > CreatePopupWindow() override
Definition: layctrl.cxx:766
virtual VclPtr< SfxPopupWindow > CreatePopupWindow() override
Definition: layctrl.cxx:721
long GetTextHeight() const
long X() const
sal_Int32 nLineWidth
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
void SetColor(const Color &)
#define KEY_RETURN
const vcl::KeyCode & GetKeyCode() const
Reference< XDispatch > xDispatch
#define KEY_DOWN
SfxItemState
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
SvxTableToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: layctrl.cxx:707
constexpr long nTablePosY
Definition: layctrl.cxx:110
unsigned short GetId() const
void SetTransparent(bool bTransparent)
static VclPtr< reference_type > Create(Arg &&...arg)
SvxColumnsToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: layctrl.cxx:752
virtual void MouseMove(const MouseEvent &rMEvt) override
unsigned short GetSlotId() const
Reference< XComponentContext > getProcessComponentContext()
const Color & GetWindowColor() const
const Point & GetPosPixel() const
long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
WindowType GetType() const
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: layctrl.cxx:734
OUString aTargetURL
SFX_IMPL_TOOLBOX_CONTROL(SvxTableToolBoxControl, SfxUInt16Item)
virtual void dispose() override
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
#define KEY_RIGHT
long Y() const
#define KEY_UP