LibreOffice Module vcl (master)  1
spinfld.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 <vcl/commandevent.hxx>
21 #include <vcl/event.hxx>
22 #include <vcl/decoview.hxx>
23 #include <vcl/spinfld.hxx>
24 #include <vcl/settings.hxx>
25 #include <vcl/uitest/uiobject.hxx>
26 #include <sal/log.hxx>
27 
28 #include <controldata.hxx>
29 #include <spin.hxx>
30 #include <svdata.hxx>
31 
32 namespace {
33 
34 void ImplGetSpinbuttonValue(vcl::Window* pWin,
35  const tools::Rectangle& rUpperRect, const tools::Rectangle& rLowerRect,
36  bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled,
37  bool bHorz, SpinbuttonValue& rValue )
38 {
39  // convert spinbutton data to a SpinbuttonValue structure for native painting
40 
41  rValue.maUpperRect = rUpperRect;
42  rValue.maLowerRect = rLowerRect;
43 
44  Point aPointerPos = pWin->GetPointerPosPixel();
45 
47  if (bUpperIn)
48  nState |= ControlState::PRESSED;
49  if (!pWin->IsEnabled() || !bUpperEnabled)
50  nState &= ~ControlState::ENABLED;
51  if (pWin->HasFocus())
52  nState |= ControlState::FOCUSED;
53  if (pWin->IsMouseOver() && rUpperRect.IsInside(aPointerPos))
54  nState |= ControlState::ROLLOVER;
55  rValue.mnUpperState = nState;
56 
57  nState = ControlState::ENABLED;
58  if (bLowerIn)
59  nState |= ControlState::PRESSED;
60  if (!pWin->IsEnabled() || !bLowerEnabled)
61  nState &= ~ControlState::ENABLED;
62  if (pWin->HasFocus())
63  nState |= ControlState::FOCUSED;
64  // for overlapping spins: highlight only one
65  if (pWin->IsMouseOver() && rLowerRect.IsInside(aPointerPos) && !rUpperRect.IsInside(aPointerPos))
66  nState |= ControlState::ROLLOVER;
67  rValue.mnLowerState = nState;
68 
71 }
72 
73 bool ImplDrawNativeSpinfield(vcl::RenderContext& rRenderContext, vcl::Window const * pWin, const SpinbuttonValue& rSpinbuttonValue)
74 {
75  bool bNativeOK = false;
76 
78  // there is just no useful native support for spinfields with dropdown
79  !(pWin->GetStyle() & WB_DROPDOWN))
80  {
81  if (rRenderContext.IsNativeControlSupported(ControlType::Spinbox, rSpinbuttonValue.mnUpperPart) &&
82  rRenderContext.IsNativeControlSupported(ControlType::Spinbox, rSpinbuttonValue.mnLowerPart))
83  {
84  // only paint the embedded spin buttons, all buttons are painted at once
85  tools::Rectangle aUpperAndLowerButtons( rSpinbuttonValue.maUpperRect.GetUnion( rSpinbuttonValue.maLowerRect ) );
86  bNativeOK = rRenderContext.DrawNativeControl(ControlType::Spinbox, ControlPart::AllButtons, aUpperAndLowerButtons,
87  ControlState::ENABLED, rSpinbuttonValue, OUString());
88  }
89  else
90  {
91  // paint the spinbox as a whole, use borderwindow to have proper clipping
93 
94  // to not overwrite everything, set the button region as clipregion to the border window
95  tools::Rectangle aClipRect(rSpinbuttonValue.maLowerRect);
96  aClipRect.Union(rSpinbuttonValue.maUpperRect);
97 
98  vcl::RenderContext* pContext = &rRenderContext;
99  vcl::Region oldRgn;
100  Point aPt;
101  Size aSize(pBorder->GetOutputSizePixel()); // the size of the border window, i.e., the whole control
102  tools::Rectangle aNatRgn(aPt, aSize);
103 
104  if (!pWin->SupportsDoubleBuffering())
105  {
106  // convert from screen space to borderwin space
107  aClipRect.SetPos(pBorder->ScreenToOutputPixel(pWin->OutputToScreenPixel(aClipRect.TopLeft())));
108 
109  oldRgn = pBorder->GetClipRegion();
110  pBorder->SetClipRegion(vcl::Region(aClipRect));
111 
112  pContext = pBorder;
113  }
114 
115  tools::Rectangle aBound, aContent;
116  if (!ImplGetSVData()->maNWFData.mbCanDrawWidgetAnySize &&
118  aNatRgn, ControlState::NONE, rSpinbuttonValue,
119  aBound, aContent))
120  {
121  aSize = aContent.GetSize();
122  }
123 
124  tools::Rectangle aRgn(aPt, aSize);
125  if (pWin->SupportsDoubleBuffering())
126  {
127  // convert from borderwin space, to the pWin's space
128  aRgn.SetPos(pWin->ScreenToOutputPixel(pBorder->OutputToScreenPixel(aRgn.TopLeft())));
129  }
130 
131  bNativeOK = pContext->DrawNativeControl(ControlType::Spinbox, ControlPart::Entire, aRgn,
132  ControlState::ENABLED, rSpinbuttonValue, OUString());
133 
134  if (!pWin->SupportsDoubleBuffering())
135  pBorder->SetClipRegion(oldRgn);
136  }
137  }
138  return bNativeOK;
139 }
140 
141 bool ImplDrawNativeSpinbuttons(vcl::RenderContext& rRenderContext, const SpinbuttonValue& rSpinbuttonValue)
142 {
143  bool bNativeOK = false;
144 
146  {
147  tools::Rectangle aArea = rSpinbuttonValue.maUpperRect.GetUnion(rSpinbuttonValue.maLowerRect);
148  // only paint the standalone spin buttons, all buttons are painted at once
149  bNativeOK = rRenderContext.DrawNativeControl(ControlType::SpinButtons, ControlPart::AllButtons, aArea,
150  ControlState::ENABLED, rSpinbuttonValue, OUString());
151  }
152  return bNativeOK;
153 }
154 
155 }
156 
157 void ImplDrawSpinButton(vcl::RenderContext& rRenderContext, vcl::Window* pWindow,
158  const tools::Rectangle& rUpperRect, const tools::Rectangle& rLowerRect,
159  bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled,
160  bool bHorz, bool bMirrorHorz)
161 {
162  bool bNativeOK = false;
163 
164  if (pWindow)
165  {
166  // are we drawing standalone spin buttons or members of a spinfield ?
168  switch (pWindow->GetType())
169  {
170  case WindowType::EDIT:
171  case WindowType::MULTILINEEDIT:
172  case WindowType::PATTERNFIELD:
173  case WindowType::METRICFIELD:
174  case WindowType::CURRENCYFIELD:
175  case WindowType::DATEFIELD:
176  case WindowType::TIMEFIELD:
177  case WindowType::SPINFIELD:
178  case WindowType::FORMATTEDFIELD:
179  aControl = ControlType::Spinbox;
180  break;
181  default:
182  aControl = ControlType::SpinButtons;
183  break;
184  }
185 
186  SpinbuttonValue aValue;
187  ImplGetSpinbuttonValue(pWindow, rUpperRect, rLowerRect,
188  bUpperIn, bLowerIn, bUpperEnabled, bLowerEnabled,
189  bHorz, aValue);
190 
191  if( aControl == ControlType::Spinbox )
192  bNativeOK = ImplDrawNativeSpinfield(rRenderContext, pWindow, aValue);
193  else if( aControl == ControlType::SpinButtons )
194  bNativeOK = ImplDrawNativeSpinbuttons(rRenderContext, aValue);
195  }
196 
197  if (bNativeOK)
198  return;
199 
200  ImplDrawUpDownButtons(rRenderContext,
201  rUpperRect, rLowerRect,
202  bUpperIn, bLowerIn, bUpperEnabled, bLowerEnabled,
203  bHorz, bMirrorHorz);
204 }
205 
207  const tools::Rectangle& rUpperRect, const tools::Rectangle& rLowerRect,
208  bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled,
209  bool bHorz, bool bMirrorHorz)
210 {
211  DecorationView aDecoView(&rRenderContext);
212 
213  SymbolType eType1, eType2;
214 
215  if ( bHorz )
216  {
217  eType1 = bMirrorHorz ? SymbolType::SPIN_RIGHT : SymbolType::SPIN_LEFT;
218  eType2 = bMirrorHorz ? SymbolType::SPIN_LEFT : SymbolType::SPIN_RIGHT;
219  }
220  else
221  {
222  eType1 = SymbolType::SPIN_UP;
223  eType2 = SymbolType::SPIN_DOWN;
224  }
225 
227  // draw upper/left Button
228  if (bUpperIn)
229  nStyle |= DrawButtonFlags::Pressed;
230 
231  tools::Rectangle aUpRect = aDecoView.DrawButton(rUpperRect, nStyle);
232 
234  // draw lower/right Button
235  if (bLowerIn)
236  nStyle |= DrawButtonFlags::Pressed;
237 
238  tools::Rectangle aLowRect = aDecoView.DrawButton(rLowerRect, nStyle);
239 
240  // make use of additional default edge
241  aUpRect.AdjustLeft( -1 );
242  aUpRect.AdjustTop( -1 );
243  aUpRect.AdjustRight( 1 );
244  aUpRect.AdjustBottom( 1 );
245  aLowRect.AdjustLeft( -1 );
246  aLowRect.AdjustTop( -1 );
247  aLowRect.AdjustRight( 1 );
248  aLowRect.AdjustBottom( 1 );
249 
250  // draw into the edge, so that something is visible if the rectangle is too small
251  if (aUpRect.GetHeight() < 4)
252  {
253  aUpRect.AdjustRight( 1 );
254  aUpRect.AdjustBottom( 1 );
255  aLowRect.AdjustRight( 1 );
256  aLowRect.AdjustBottom( 1 );
257  }
258 
259  // calculate Symbol size
260  long nTempSize1 = aUpRect.GetWidth();
261  long nTempSize2 = aLowRect.GetWidth();
262  if (std::abs( nTempSize1-nTempSize2 ) == 1)
263  {
264  if (nTempSize1 > nTempSize2)
265  aUpRect.AdjustLeft( 1 );
266  else
267  aLowRect.AdjustLeft( 1 );
268  }
269  nTempSize1 = aUpRect.GetHeight();
270  nTempSize2 = aLowRect.GetHeight();
271  if (std::abs(nTempSize1 - nTempSize2) == 1)
272  {
273  if (nTempSize1 > nTempSize2)
274  aUpRect.AdjustTop( 1 );
275  else
276  aLowRect.AdjustTop( 1 );
277  }
278 
279  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
280 
282  if (!bUpperEnabled)
283  nSymStyle |= DrawSymbolFlags::Disable;
284  aDecoView.DrawSymbol(aUpRect, eType1, rStyleSettings.GetButtonTextColor(), nSymStyle);
285 
286  nSymStyle = DrawSymbolFlags::NONE;
287  if (!bLowerEnabled)
288  nSymStyle |= DrawSymbolFlags::Disable;
289  aDecoView.DrawSymbol(aLowRect, eType2, rStyleSettings.GetButtonTextColor(), nSymStyle);
290 }
291 
293 {
295  mbSpin = false;
296  mbRepeat = false;
297  mbUpperIn = false;
298  mbLowerIn = false;
299  mbInitialUp = false;
300  mbInitialDown = false;
301  mbInDropDown = false;
302 }
303 
304 void SpinField::ImplInit(vcl::Window* pParent, WinBits nWinStyle)
305 {
306  Edit::ImplInit( pParent, nWinStyle );
307 
308  if (nWinStyle & (WB_SPIN | WB_DROPDOWN))
309  {
310  mbSpin = true;
311 
312  // Some themes want external spin buttons, therefore the main
313  // spinfield should not overdraw the border between its encapsulated
314  // edit field and the spin buttons
315  if ((nWinStyle & WB_SPIN) && ImplUseNativeBorder(*this, nWinStyle))
316  {
317  SetBackground();
320  }
321  else
323 
324  mpEdit->EnableRTL(false);
326  mpEdit->Show();
327 
329 
330  maRepeatTimer.SetInvokeHandler(LINK( this, SpinField, ImplTimeout));
332  if (nWinStyle & WB_REPEAT)
333  mbRepeat = true;
334 
335  SetCompoundControl(true);
336  }
337 }
338 
339 SpinField::SpinField(vcl::Window* pParent, WinBits nWinStyle, WindowType nType) :
340  Edit(nType)
341 {
343  ImplInit(pParent, nWinStyle);
344 }
345 
347 {
348  disposeOnce();
349 }
350 
352 {
354 
355  Edit::dispose();
356 }
357 
359 {
361 }
362 
364 {
366 }
367 
369 {
371 }
372 
374 {
376 }
377 
379 {
380  if (!HasFocus() && (!mpEdit || !mpEdit->HasFocus()))
381  {
382  GrabFocus();
383  }
384 
385  if (!IsReadOnly())
386  {
387  if (maUpperRect.IsInside(rMEvt.GetPosPixel()))
388  {
389  mbUpperIn = true;
390  mbInitialUp = true;
392  }
393  else if (maLowerRect.IsInside(rMEvt.GetPosPixel()))
394  {
395  mbLowerIn = true;
396  mbInitialDown = true;
398  }
399  else if (maDropDownRect.IsInside(rMEvt.GetPosPixel()))
400  {
401  // put DropDownButton to the right
404  }
405 
406  if (mbUpperIn || mbLowerIn)
407  {
408  CaptureMouse();
409  if (mbRepeat)
411  return;
412  }
413  }
414 
415  Edit::MouseButtonDown(rMEvt);
416 }
417 
419 {
420  ReleaseMouse();
421  mbInitialUp = mbInitialDown = false;
424 
425  if (mbUpperIn)
426  {
427  mbUpperIn = false;
429  Up();
430  }
431  else if (mbLowerIn)
432  {
433  mbLowerIn = false;
435  Down();
436  }
437 
438  Edit::MouseButtonUp(rMEvt);
439 }
440 
442 {
443  if (rMEvt.IsLeft())
444  {
445  if (mbInitialUp)
446  {
447  bool bNewUpperIn = maUpperRect.IsInside(rMEvt.GetPosPixel());
448  if (bNewUpperIn != mbUpperIn)
449  {
450  if (bNewUpperIn)
451  {
452  if (mbRepeat)
454  }
455  else
457 
458  mbUpperIn = bNewUpperIn;
460  }
461  }
462  else if (mbInitialDown)
463  {
464  bool bNewLowerIn = maLowerRect.IsInside(rMEvt.GetPosPixel());
465  if (bNewLowerIn != mbLowerIn)
466  {
467  if (bNewLowerIn)
468  {
469  if (mbRepeat)
471  }
472  else
474 
475  mbLowerIn = bNewLowerIn;
477  }
478  }
479  }
480 
481  Edit::MouseMove(rMEvt);
482 }
483 
485 {
486  bool bDone = false;
487  if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
488  {
489  const KeyEvent& rKEvt = *rNEvt.GetKeyEvent();
490  if (!IsReadOnly())
491  {
492  sal_uInt16 nMod = rKEvt.GetKeyCode().GetModifier();
493  switch (rKEvt.GetKeyCode().GetCode())
494  {
495  case KEY_UP:
496  {
497  if (!nMod)
498  {
499  Up();
500  bDone = true;
501  }
502  }
503  break;
504  case KEY_DOWN:
505  {
506  if (!nMod)
507  {
508  Down();
509  bDone = true;
510  }
511  else if ((nMod == KEY_MOD2) && !mbInDropDown && (GetStyle() & WB_DROPDOWN))
512  {
513  mbInDropDown = ShowDropDown(true);
515  bDone = true;
516  }
517  }
518  break;
519  case KEY_PAGEUP:
520  {
521  if (!nMod)
522  {
523  Last();
524  bDone = true;
525  }
526  }
527  break;
528  case KEY_PAGEDOWN:
529  {
530  if (!nMod)
531  {
532  First();
533  bDone = true;
534  }
535  }
536  break;
537  }
538  }
539  }
540 
541  if (rNEvt.GetType() == MouseNotifyEvent::COMMAND)
542  {
544  {
545  MouseWheelBehaviour nWheelBehavior(GetSettings().GetMouseSettings().GetWheelBehavior());
546  if (nWheelBehavior == MouseWheelBehaviour::ALWAYS
547  || (nWheelBehavior == MouseWheelBehaviour::FocusOnly && HasChildPathFocus()))
548  {
550  if (pData->GetMode() == CommandWheelMode::SCROLL)
551  {
552  if (pData->GetDelta() < 0)
553  Down();
554  else
555  Up();
556  bDone = true;
557  }
558  }
559  else
560  bDone = false; // don't eat this event, let the default handling happen (i.e. scroll the context)
561  }
562  }
563 
564  return bDone || Edit::EventNotify(rNEvt);
565 }
566 
568 {
569  if (mbSpin)
570  {
571  mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
574  }
575  else
577 }
578 
579 void SpinField::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
580 {
581  if (mbSpin)
582  {
583  bool bEnable = IsEnabled();
584  ImplDrawSpinButton(rRenderContext, this, maUpperRect, maLowerRect,
585  mbUpperIn, mbLowerIn, bEnable, bEnable);
586  }
587 
588  if (GetStyle() & WB_DROPDOWN)
589  {
590  DecorationView aView(&rRenderContext);
591 
593  if (mbInDropDown)
594  nStyle |= DrawButtonFlags::Pressed;
595  tools::Rectangle aInnerRect = aView.DrawButton(maDropDownRect, nStyle);
596 
598  aView.DrawSymbol(aInnerRect, SymbolType::SPIN_DOWN, rRenderContext.GetSettings().GetStyleSettings().GetButtonTextColor(), nSymbolStyle);
599  }
600 
601  Edit::Paint(rRenderContext, rRect);
602 }
603 
605  tools::Rectangle& rSpinUpArea, tools::Rectangle& rSpinDownArea)
606 {
607  const StyleSettings& rStyleSettings = pDev->GetSettings().GetStyleSettings();
608 
609  Size aSize = rOutSz;
610  Size aDropDownSize;
611 
612  if (GetStyle() & WB_DROPDOWN)
613  {
614  long nW = rStyleSettings.GetScrollBarSize();
615  nW = GetDrawPixel( pDev, nW );
616  aDropDownSize = Size( CalcZoom( nW ), aSize.Height() );
617  aSize.AdjustWidth( -(aDropDownSize.Width()) );
618  rDDArea = tools::Rectangle( Point( aSize.Width(), 0 ), aDropDownSize );
619  rDDArea.AdjustTop( -1 );
620  }
621  else
622  rDDArea.SetEmpty();
623 
624  // calculate sizes according to the height
625  if (GetStyle() & WB_SPIN)
626  {
627  long nBottom1 = aSize.Height()/2;
628  long nBottom2 = aSize.Height()-1;
629  long nTop2 = nBottom1;
630  if ( !(aSize.Height() & 0x01) )
631  nBottom1--;
632 
633  bool bNativeRegionOK = false;
634  tools::Rectangle aContentUp, aContentDown;
635 
636  if ((pDev->GetOutDevType() == OUTDEV_WINDOW) &&
637  // there is just no useful native support for spinfields with dropdown
638  ! (GetStyle() & WB_DROPDOWN) &&
640  {
641  vcl::Window *pWin = static_cast<vcl::Window*>(pDev);
642  vcl::Window *pBorder = pWin->GetWindow( GetWindowType::Border );
643 
644  // get the system's spin button size
645  ImplControlValue aControlValue;
646  tools::Rectangle aBound;
647  Point aPoint;
648 
649  // use the full extent of the control
650  tools::Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
651 
652  bNativeRegionOK =
654  aArea, ControlState::NONE, aControlValue, aBound, aContentUp) &&
656  aArea, ControlState::NONE, aControlValue, aBound, aContentDown);
657 
658  if (bNativeRegionOK)
659  {
660  // convert back from border space to local coordinates
661  aPoint = pBorder->ScreenToOutputPixel( pWin->OutputToScreenPixel( aPoint ) );
662  aContentUp.Move(-aPoint.X(), -aPoint.Y());
663  aContentDown.Move(-aPoint.X(), -aPoint.Y());
664  }
665  }
666 
667  if (bNativeRegionOK)
668  {
669  rSpinUpArea = aContentUp;
670  rSpinDownArea = aContentDown;
671  }
672  else
673  {
674  aSize.AdjustWidth( -(CalcZoom( GetDrawPixel( pDev, rStyleSettings.GetSpinSize() ) )) );
675 
676  rSpinUpArea = tools::Rectangle( aSize.Width(), 0, rOutSz.Width()-aDropDownSize.Width()-1, nBottom1 );
677  rSpinDownArea = tools::Rectangle( rSpinUpArea.Left(), nTop2, rSpinUpArea.Right(), nBottom2 );
678  }
679  }
680  else
681  {
682  rSpinUpArea.SetEmpty();
683  rSpinDownArea.SetEmpty();
684  }
685 }
686 
688 {
689  if (mbSpin)
690  {
691  Control::Resize();
692  Size aSize = GetOutputSizePixel();
693  bool bSubEditPositioned = false;
694 
695  if (GetStyle() & (WB_SPIN | WB_DROPDOWN))
696  {
698 
699  ImplControlValue aControlValue;
700  Point aPoint;
701  tools::Rectangle aContent, aBound;
702 
703  // use the full extent of the control
705  tools::Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
706 
707  // adjust position and size of the edit field
709  aControlValue, aBound, aContent) &&
710  // there is just no useful native support for spinfields with dropdown
711  !(GetStyle() & WB_DROPDOWN))
712  {
713  // convert back from border space to local coordinates
714  aPoint = pBorder->ScreenToOutputPixel(OutputToScreenPixel(aPoint));
715  aContent.Move(-aPoint.X(), -aPoint.Y());
716 
717  // use the themes drop down size
718  mpEdit->SetPosPixel( aContent.TopLeft() );
719  bSubEditPositioned = true;
720  aSize = aContent.GetSize();
721  }
722  else
723  {
724  if (maUpperRect.IsEmpty())
725  {
726  SAL_WARN_IF( maDropDownRect.IsEmpty(), "vcl", "SpinField::Resize: SPIN && DROPDOWN, but all empty rects?" );
727  aSize.setWidth( maDropDownRect.Left() );
728  }
729  else
730  aSize.setWidth( maUpperRect.Left() );
731  }
732  }
733 
734  if (!bSubEditPositioned)
735  {
736  // this moves our sub edit if RTL gets switched
738  }
739  mpEdit->SetSizePixel(aSize);
740 
741  if (GetStyle() & WB_SPIN)
743  if (GetStyle() & WB_DROPDOWN)
745  }
746 }
747 
749 {
750  Edit::StateChanged(nType);
751 
752  if (nType == StateChangedType::Enable)
753  {
754  if (mbSpin || (GetStyle() & WB_DROPDOWN))
755  {
756  mpEdit->Enable(IsEnabled());
757 
758  if (mbSpin)
759  {
762  }
763  if (GetStyle() & WB_DROPDOWN)
765  }
766  }
767  else if (nType == StateChangedType::Style)
768  {
769  if (GetStyle() & WB_REPEAT)
770  mbRepeat = true;
771  else
772  mbRepeat = false;
773  }
774  else if (nType == StateChangedType::Zoom)
775  {
776  Resize();
777  if (mpEdit)
778  mpEdit->SetZoom(GetZoom());
779  Invalidate();
780  }
781  else if (nType == StateChangedType::ControlFont)
782  {
783  if (mpEdit)
785  Invalidate();
786  }
787  else if (nType == StateChangedType::ControlForeground)
788  {
789  if (mpEdit)
791  Invalidate();
792  }
793  else if (nType == StateChangedType::ControlBackground)
794  {
795  if (mpEdit)
797  Invalidate();
798  }
799  else if( nType == StateChangedType::Mirroring )
800  {
801  if (mpEdit)
803  Resize();
804  }
805 }
806 
808 {
809  Edit::DataChanged(rDCEvt);
810 
811  if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
812  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
813  {
814  Resize();
815  Invalidate();
816  }
817 }
818 
820 {
821  if (maUpperRect.IsInside(rPt))
822  return &maUpperRect;
823  else if (maLowerRect.IsInside(rPt))
824  return &maLowerRect;
825  else
826  return nullptr;
827 }
828 
830 {
831  if (rNEvt.GetType() == MouseNotifyEvent::MOUSEMOVE)
832  {
833  const MouseEvent* pMouseEvt = rNEvt.GetMouseEvent();
834  if (pMouseEvt && !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged())
835  {
836  // trigger redraw if mouse over state has changed
839  {
842  if( pRect != pLastRect || (pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) )
843  {
844  // FIXME: this is currently only on macOS
845  // check for other platforms that need similar handling
848  {
850  }
851  else
852  {
853  // paint directly
855  if (pLastRect)
856  {
857  SetClipRegion(vcl::Region(*pLastRect));
858  Invalidate(*pLastRect);
859  SetClipRegion( aRgn );
860  }
861  if (pRect)
862  {
863  SetClipRegion(vcl::Region(*pRect));
864  Invalidate(*pRect);
865  SetClipRegion( aRgn );
866  }
867  }
868  }
869  }
870  }
871  }
872 
873  return Edit::PreNotify(rNEvt);
874 }
875 
877 {
878  mbInDropDown = false;
880 }
881 
883 {
884  return false;
885 }
886 
887 Size SpinField::CalcMinimumSizeForText(const OUString &rString) const
888 {
889  Size aSz = Edit::CalcMinimumSizeForText(rString);
890 
891  if ( GetStyle() & WB_DROPDOWN )
892  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
893  if ( GetStyle() & WB_SPIN )
894  {
895  ImplControlValue aControlValue;
896  tools::Rectangle aArea( Point(), Size(100, aSz.Height()));
897  tools::Rectangle aEntireBound, aEntireContent, aEditBound, aEditContent;
898  if (
900  aArea, ControlState::NONE, aControlValue, aEntireBound, aEntireContent) &&
902  aArea, ControlState::NONE, aControlValue, aEditBound, aEditContent)
903  )
904  {
905  aSz.AdjustWidth(aEntireContent.GetWidth() - aEditContent.GetWidth());
906  }
907  else
908  {
910  }
911  }
912 
913  return aSz;
914 }
915 
917 {
919 }
920 
922 {
923  return CalcMinimumSize();
924 }
925 
926 Size SpinField::CalcSize(sal_Int32 nChars) const
927 {
928  Size aSz = Edit::CalcSize( nChars );
929 
930  if ( GetStyle() & WB_DROPDOWN )
931  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
932  if ( GetStyle() & WB_SPIN )
933  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetSpinSize() );
934 
935  return aSz;
936 }
937 
938 IMPL_LINK( SpinField, ImplTimeout, Timer*, pTimer, void )
939 {
940  if ( pTimer->GetTimeout() == MouseSettings::GetButtonStartRepeat() )
941  {
942  pTimer->SetTimeout( GetSettings().GetMouseSettings().GetButtonRepeat() );
943  pTimer->Start();
944  }
945  else
946  {
947  if ( mbInitialUp )
948  Up();
949  else
950  Down();
951  }
952 }
953 
954 void SpinField::Draw(OutputDevice* pDev, const Point& rPos, DrawFlags nFlags)
955 {
956  Edit::Draw(pDev, rPos, nFlags);
957 
958  WinBits nFieldStyle = GetStyle();
959  if ( (nFlags & DrawFlags::NoControls ) || !( nFieldStyle & (WB_SPIN|WB_DROPDOWN) ) )
960  return;
961 
962  Point aPos = pDev->LogicToPixel( rPos );
963  Size aSize = GetSizePixel();
964  AllSettings aOldSettings = pDev->GetSettings();
965 
966  pDev->Push();
967  pDev->SetMapMode();
968 
969  tools::Rectangle aDD, aUp, aDown;
970  ImplCalcButtonAreas(pDev, aSize, aDD, aUp, aDown);
971  aDD.Move(aPos.X(), aPos.Y());
972  aUp.Move(aPos.X(), aPos.Y());
973  aUp.AdjustTop( 1 );
974  aDown.Move(aPos.X(), aPos.Y());
975 
976  Color aButtonTextColor;
977  if (nFlags & DrawFlags::Mono)
978  aButtonTextColor = COL_BLACK;
979  else
980  aButtonTextColor = GetSettings().GetStyleSettings().GetButtonTextColor();
981 
982  if (GetStyle() & WB_DROPDOWN)
983  {
984  DecorationView aView( pDev );
987  aView.DrawSymbol(aInnerRect, SymbolType::SPIN_DOWN, aButtonTextColor, nSymbolStyle);
988  }
989 
990  if (GetStyle() & WB_SPIN)
991  {
992  ImplDrawSpinButton(*pDev, this, aUp, aDown, false, false);
993  }
994 
995  pDev->Pop();
996  pDev->SetSettings(aOldSettings);
997 
998 }
999 
1001 {
1003 }
1004 
1005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: edit.cxx:1716
Point TopLeft() const
long Width() const
vcl::Region GetClipRegion() const
OutDevType GetOutDevType() const
Definition: outdev.hxx:524
virtual void EnableRTL(bool bEnable=true) override
Definition: ctrl.cxx:65
bool ImplCallEventListenersAndHandler(VclEventId nEvent, std::function< void()> const &callHandler)
this calls both our event listeners, and a specified handler
Definition: ctrl.cxx:305
long GetWidth() const
void CaptureMouse()
Definition: mouse.cxx:440
Point GetPointerPosPixel()
Definition: mouse.cxx:549
IMPL_LINK(SpinField, ImplTimeout, Timer *, pTimer, void)
Definition: spinfld.cxx:938
long GetHeight() const
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
tools::Rectangle GetUnion(const tools::Rectangle &rRect) const
bool mbUpperIn
Definition: spinfld.hxx:87
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption)
Request rendering of a particular control and/or part.
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: spinfld.cxx:378
long AdjustWidth(long n)
bool GetNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) const
Query the native control's actual drawing region (including adornment)
const CommandEvent * GetCommandEvent() const
Definition: event.hxx:327
std::unique_ptr< ContentProperties > pData
Edit * GetSubEdit() const
Definition: edit.hxx:223
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
long Height() const
virtual Size GetOptimalSize() const override
Definition: spinfld.cxx:921
void ImplDrawSpinButton(vcl::RenderContext &rRenderContext, vcl::Window *pWindow, const tools::Rectangle &rUpperRect, const tools::Rectangle &rLowerRect, bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled, bool bHorz, bool bMirrorHorz)
Definition: spinfld.cxx:157
void ImplDrawUpDownButtons(vcl::RenderContext &rRenderContext, const tools::Rectangle &rUpperRect, const tools::Rectangle &rLowerRect, bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled, bool bHorz, bool bMirrorHorz)
Definition: spinfld.cxx:206
virtual Size CalcMinimumSizeForText(const OUString &rString) const
Definition: edit.cxx:2617
long AdjustLeft(long nHorzMoveDelta)
void disposeAndClear()
Definition: vclptr.hxx:200
const StyleSettings & GetStyleSettings() const
ImplSVNWFData maNWFData
Definition: svdata.hxx:398
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
virtual Size GetSizePixel() const
Definition: window.cxx:2396
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1262
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: spinfld.cxx:579
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
Definition: spinfld.cxx:418
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: edit.cxx:216
void CompatStateChanged(StateChangedType nStateChange)
Definition: window.cxx:3874
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
ControlPart mnLowerPart
DataChangedEventType GetType() const
Definition: event.hxx:357
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:311
DrawButtonFlags
Definition: decoview.hxx:68
SAL_DLLPRIVATE void ImplCalcButtonAreas(OutputDevice *pDev, const Size &rOutSz, tools::Rectangle &rDDArea, tools::Rectangle &rSpinUpArea, tools::Rectangle &rSpinDownArea)
Definition: spinfld.cxx:604
long CalcZoom(long n) const
Definition: window2.cxx:397
void AppendLayoutData(const Control &rSubControl) const
Definition: ctrl.cxx:273
virtual void SetSettings(const AllSettings &rSettings)
Definition: outdev.cxx:213
bool mbInDropDown
Definition: spinfld.hxx:87
virtual void Up()
Definition: spinfld.cxx:358
const Color & GetControlBackground() const
Definition: window2.cxx:1082
const CommandWheelData * GetWheelData() const
tools::Rectangle * ImplFindPartRect(const Point &rPt)
Definition: spinfld.cxx:819
tools::Rectangle DrawButton(const tools::Rectangle &rRect, DrawButtonFlags nStyle)
Definition: decoview.cxx:931
virtual void Draw(OutputDevice *pDev, const Point &rPos, DrawFlags nFlags) override
Definition: spinfld.cxx:954
tools::Rectangle maLowerRect
bool HasChildPathFocus(bool bSystemWindow=false) const
Definition: window.cxx:3034
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
void SetMapMode()
Definition: map.cxx:655
constexpr sal_uInt16 KEY_UP
Definition: keycodes.hxx:111
long AdjustBottom(long nVertMoveDelta)
void Move(long nHorzMoveDelta, long nVertMoveDelta)
bool IsEmpty() const
const Fraction & GetZoom() const
Definition: window2.cxx:1210
StateChangedType
Definition: window.hxx:310
tools::Rectangle maUpperRect
sal_Int64 WinBits
void SetBackground()
void SetControlFont()
Definition: window2.cxx:409
long Right() const
virtual void FillLayoutData() const override
Definition: edit.cxx:1710
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: spinfld.cxx:351
bool mbInitialDown
Definition: spinfld.hxx:87
AutoTimer maRepeatTimer
Definition: spinfld.hxx:84
void Enable(bool bEnable=true, bool bChild=true)
Definition: window.cxx:2427
sal_uInt16 GetButtons() const
Definition: event.hxx:144
SymbolType
Definition: vclenum.hxx:73
bool IsEnterWindow() const
Definition: event.hxx:135
tools::Rectangle maDropDownRect
Definition: spinfld.hxx:66
tools::Rectangle maLowerRect
Definition: spinfld.hxx:65
Link< SpinField &, void > maDownHdlLink
Definition: spinfld.hxx:86
virtual ~SpinField() override
Definition: spinfld.cxx:346
AllSettingsFlags GetFlags() const
Definition: event.hxx:358
constexpr sal_uInt16 KEY_PAGEUP
Definition: keycodes.hxx:116
virtual void MouseMove(const MouseEvent &rMEvt) override
Definition: spinfld.cxx:441
void SetCompoundControl(bool bCompound)
Definition: window2.cxx:947
virtual void Draw(OutputDevice *pDev, const Point &rPos, DrawFlags nFlags) override
Definition: edit.cxx:1735
sal_uInt16 GetModifier() const
Definition: keycod.hxx:56
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
Definition: edit.cxx:1352
virtual bool ShowDropDown(bool bShow)
Definition: spinfld.cxx:882
Definition: edit.hxx:56
virtual FactoryFunction GetUITestFactory() const override
Definition: spinfld.cxx:1000
virtual void Down()
Definition: spinfld.cxx:363
const Color & GetControlForeground() const
Definition: window2.cxx:1072
long GetDrawPixel(::OutputDevice const *pDev, long nPixels) const
Definition: window2.cxx:563
SAL_DLLPRIVATE bool ImplUseNativeBorder(vcl::RenderContext const &rRenderContext, WinBits nStyle)
Definition: edit.cxx:283
ControlPart mnUpperPart
ControlState mnUpperState
constexpr sal_uInt16 KEY_DOWN
Definition: keycodes.hxx:110
Point BottomRight() const
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:76
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: spinfld.cxx:484
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
bool IsLeaveWindow() const
Definition: event.hxx:137
DrawFlags
Definition: window.hxx:353
The edit field part of a control, e.g.
bool IsNativeWidgetEnabled() const
Definition: window.cxx:3725
bool mbInitialUp
Definition: spinfld.hxx:87
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2152
void SetControlBackground()
Definition: window2.cxx:497
void SetControlForeground()
Definition: window2.cxx:457
CommandWheelMode GetMode() const
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1162
ControlState mnLowerState
virtual OUString GetText() const override
Definition: edit.cxx:2562
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
CommandEventId GetCommand() const
void SetZoom(const Fraction &rZoom)
Definition: window2.cxx:365
virtual void FillLayoutData() const override
Definition: spinfld.cxx:567
constexpr sal_uInt16 KEY_PAGEDOWN
Definition: keycodes.hxx:117
DrawSymbolFlags
Definition: decoview.hxx:34
virtual void Start() override
Activates the timer task.
Definition: timer.cxx:83
MouseNotifyEvent GetType() const
Definition: event.hxx:303
bool IsInside(const Point &rPOINT) const
void SetSubEdit(Edit *pEdit)
Definition: edit.cxx:2602
WinBits const WB_DROPDOWN
const AllSettings & GetSettings() const
Definition: outdev.hxx:418
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
constexpr sal_uInt16 KEY_MOD2
Definition: keycodes.hxx:32
void SetTimeout(sal_uInt64 nTimeoutMs)
Definition: timer.cxx:89
Point ScreenToOutputPixel(const Point &rPos) const
Definition: window.cxx:2856
void GrabFocus()
Definition: window.cxx:3006
virtual Size CalcSize(sal_Int32 nChars) const override
Definition: spinfld.cxx:926
Size GetSize() const
WinBits const WB_REPEAT
WinBits const WB_NOBORDER
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1046
SAL_DLLPRIVATE void ImplInitSpinFieldData()
Definition: spinfld.cxx:292
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:942
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
void ReleaseMouse()
Definition: mouse.cxx:458
virtual Size CalcSize(sal_Int32 nChars) const
Definition: edit.cxx:2685
bool IsModifierChanged() const
Definition: event.hxx:141
void EndDropDown()
Definition: spinfld.cxx:876
bool mbSpin
Definition: spinfld.hxx:87
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:54
static SAL_DLLPRIVATE void ImplInvalidateOutermostBorder(vcl::Window *pWin)
Definition: edit.cxx:1826
virtual void First()
Definition: spinfld.cxx:368
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: spinfld.cxx:807
bool IsMouseOver() const
Definition: mouse.cxx:605
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: spinfld.cxx:304
virtual void Resize() override
Definition: ctrl.cxx:74
long AdjustRight(long nHorzMoveDelta)
void Stop()
Definition: scheduler.cxx:593
WindowType
long GetDelta() const
bool IsSynthetic() const
Definition: event.hxx:139
Link< SpinField &, void > maUpHdlLink
Definition: spinfld.hxx:85
const Color & GetButtonTextColor() const
bool mbNoFocusRects
Definition: svdata.hxx:320
#define SAL_WARN_IF(condition, area, stream)
SpinField(vcl::Window *pParent, WinBits nWinStyle, WindowType nType=WindowType::SPINFIELD)
Definition: spinfld.cxx:339
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2233
const MouseEvent * GetMouseEvent() const
Definition: event.hxx:319
std::unique_ptr< vcl::ImplControlData > mpControlData
Definition: ctrl.hxx:36
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: edit.cxx:1311
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
bool IsLeft() const
Definition: event.hxx:146
virtual Size CalcMinimumSize() const override
Definition: spinfld.cxx:916
bool mbLowerIn
Definition: spinfld.hxx:87
virtual void Last()
Definition: spinfld.cxx:373
long AdjustTop(long nVertMoveDelta)
virtual void Resize() override
Definition: spinfld.cxx:687
bool mbRepeat
Definition: spinfld.hxx:87
long GetSpinSize() const
void SetInvokeHandler(const Link< Timer *, void > &rLink)
Definition: timer.hxx:56
const Point & GetPosPixel() const
Definition: event.hxx:120
long Left() const
void set(reference_type *pBody)
Definition: vclptr.hxx:148
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: spinfld.cxx:829
WindowType GetType() const
Definition: window2.cxx:974
virtual vcl::Region GetActiveClipRegion() const override
bool IsEnabled() const
Definition: window2.cxx:1122
virtual void MouseMove(const MouseEvent &rMEvt)
Definition: mouse.cxx:408
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
Definition: decoview.cxx:794
MouseWheelBehaviour
Definition: settings.hxx:80
WinBits GetStyle() const
Definition: window2.cxx:953
Definition: timer.hxx:26
Point OutputToScreenPixel(const Point &rPos) const
Definition: window.cxx:2850
virtual bool IsReadOnly() const
Definition: edit.hxx:180
Point GetLastPointerPosPixel()
Definition: mouse.cxx:561
long GetScrollBarSize() const
virtual Size CalcMinimumSizeForText(const OUString &rString) const override
Definition: spinfld.cxx:887
vcl::Font GetControlFont() const
Definition: window2.cxx:438
bool HasFocus() const
Definition: window.cxx:3011
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
WinBits const WB_SPIN
bool SupportsDoubleBuffering() const
Can the widget derived from this Window do the double-buffering via RenderContext properly...
Definition: window.cxx:3836
void setWidth(long nWidth)
sal_Int32 nState
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1257
VclPtr< Edit > mpEdit
Definition: spinfld.hxx:83
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: edit.cxx:299
tools::Rectangle maUpperRect
Definition: spinfld.hxx:64
virtual void StateChanged(StateChangedType nType) override
Definition: spinfld.cxx:748
void SetLayoutDataParent(const Control *pParent) const
Definition: ctrl.cxx:324
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:225
static sal_uLong GetButtonStartRepeat()
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2182