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::LONGCURRENCYFIELD:
178  case WindowType::NUMERICFIELD:
179  case WindowType::SPINFIELD:
180  aControl = ControlType::Spinbox;
181  break;
182  default:
183  aControl = ControlType::SpinButtons;
184  break;
185  }
186 
187  SpinbuttonValue aValue;
188  ImplGetSpinbuttonValue(pWindow, rUpperRect, rLowerRect,
189  bUpperIn, bLowerIn, bUpperEnabled, bLowerEnabled,
190  bHorz, aValue);
191 
192  if( aControl == ControlType::Spinbox )
193  bNativeOK = ImplDrawNativeSpinfield(rRenderContext, pWindow, aValue);
194  else if( aControl == ControlType::SpinButtons )
195  bNativeOK = ImplDrawNativeSpinbuttons(rRenderContext, aValue);
196  }
197 
198  if (bNativeOK)
199  return;
200 
201  ImplDrawUpDownButtons(rRenderContext,
202  rUpperRect, rLowerRect,
203  bUpperIn, bLowerIn, bUpperEnabled, bLowerEnabled,
204  bHorz, bMirrorHorz);
205 }
206 
208  const tools::Rectangle& rUpperRect, const tools::Rectangle& rLowerRect,
209  bool bUpperIn, bool bLowerIn, bool bUpperEnabled, bool bLowerEnabled,
210  bool bHorz, bool bMirrorHorz)
211 {
212  DecorationView aDecoView(&rRenderContext);
213 
214  SymbolType eType1, eType2;
215 
216  if ( bHorz )
217  {
218  eType1 = bMirrorHorz ? SymbolType::SPIN_RIGHT : SymbolType::SPIN_LEFT;
219  eType2 = bMirrorHorz ? SymbolType::SPIN_LEFT : SymbolType::SPIN_RIGHT;
220  }
221  else
222  {
223  eType1 = SymbolType::SPIN_UP;
224  eType2 = SymbolType::SPIN_DOWN;
225  }
226 
228  // draw upper/left Button
229  if (bUpperIn)
230  nStyle |= DrawButtonFlags::Pressed;
231 
232  tools::Rectangle aUpRect = aDecoView.DrawButton(rUpperRect, nStyle);
233 
235  // draw lower/right Button
236  if (bLowerIn)
237  nStyle |= DrawButtonFlags::Pressed;
238 
239  tools::Rectangle aLowRect = aDecoView.DrawButton(rLowerRect, nStyle);
240 
241  // make use of additional default edge
242  aUpRect.AdjustLeft( -1 );
243  aUpRect.AdjustTop( -1 );
244  aUpRect.AdjustRight( 1 );
245  aUpRect.AdjustBottom( 1 );
246  aLowRect.AdjustLeft( -1 );
247  aLowRect.AdjustTop( -1 );
248  aLowRect.AdjustRight( 1 );
249  aLowRect.AdjustBottom( 1 );
250 
251  // draw into the edge, so that something is visible if the rectangle is too small
252  if (aUpRect.GetHeight() < 4)
253  {
254  aUpRect.AdjustRight( 1 );
255  aUpRect.AdjustBottom( 1 );
256  aLowRect.AdjustRight( 1 );
257  aLowRect.AdjustBottom( 1 );
258  }
259 
260  // calculate Symbol size
261  long nTempSize1 = aUpRect.GetWidth();
262  long nTempSize2 = aLowRect.GetWidth();
263  if (std::abs( nTempSize1-nTempSize2 ) == 1)
264  {
265  if (nTempSize1 > nTempSize2)
266  aUpRect.AdjustLeft( 1 );
267  else
268  aLowRect.AdjustLeft( 1 );
269  }
270  nTempSize1 = aUpRect.GetHeight();
271  nTempSize2 = aLowRect.GetHeight();
272  if (std::abs(nTempSize1 - nTempSize2) == 1)
273  {
274  if (nTempSize1 > nTempSize2)
275  aUpRect.AdjustTop( 1 );
276  else
277  aLowRect.AdjustTop( 1 );
278  }
279 
280  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
281 
283  if (!bUpperEnabled)
284  nSymStyle |= DrawSymbolFlags::Disable;
285  aDecoView.DrawSymbol(aUpRect, eType1, rStyleSettings.GetButtonTextColor(), nSymStyle);
286 
287  nSymStyle = DrawSymbolFlags::NONE;
288  if (!bLowerEnabled)
289  nSymStyle |= DrawSymbolFlags::Disable;
290  aDecoView.DrawSymbol(aLowRect, eType2, rStyleSettings.GetButtonTextColor(), nSymStyle);
291 }
292 
294 {
296  mbSpin = false;
297  mbRepeat = false;
298  mbUpperIn = false;
299  mbLowerIn = false;
300  mbInitialUp = false;
301  mbInitialDown = false;
302  mbInDropDown = false;
303 }
304 
305 void SpinField::ImplInit(vcl::Window* pParent, WinBits nWinStyle)
306 {
307  Edit::ImplInit( pParent, nWinStyle );
308 
309  if (nWinStyle & (WB_SPIN | WB_DROPDOWN))
310  {
311  mbSpin = true;
312 
313  // Some themes want external spin buttons, therefore the main
314  // spinfield should not overdraw the border between its encapsulated
315  // edit field and the spin buttons
316  if ((nWinStyle & WB_SPIN) && ImplUseNativeBorder(*this, nWinStyle))
317  {
318  SetBackground();
321  }
322  else
324 
325  mpEdit->EnableRTL(false);
327  mpEdit->Show();
328 
330 
331  maRepeatTimer.SetInvokeHandler(LINK( this, SpinField, ImplTimeout));
333  if (nWinStyle & WB_REPEAT)
334  mbRepeat = true;
335 
336  SetCompoundControl(true);
337  }
338 }
339 
342 {
344  ImplInit(pParent, nWinStyle);
345 }
346 
348 {
349  disposeOnce();
350 }
351 
353 {
355 
356  Edit::dispose();
357 }
358 
360 {
362 }
363 
365 {
367 }
368 
370 {
372 }
373 
375 {
377 }
378 
380 {
381  if (!HasFocus() && (!mpEdit || !mpEdit->HasFocus()))
382  {
383  GrabFocus();
384  }
385 
386  if (!IsReadOnly())
387  {
388  if (maUpperRect.IsInside(rMEvt.GetPosPixel()))
389  {
390  mbUpperIn = true;
391  mbInitialUp = true;
393  }
394  else if (maLowerRect.IsInside(rMEvt.GetPosPixel()))
395  {
396  mbLowerIn = true;
397  mbInitialDown = true;
399  }
400  else if (maDropDownRect.IsInside(rMEvt.GetPosPixel()))
401  {
402  // put DropDownButton to the right
405  }
406 
407  if (mbUpperIn || mbLowerIn)
408  {
409  CaptureMouse();
410  if (mbRepeat)
412  return;
413  }
414  }
415 
416  Edit::MouseButtonDown(rMEvt);
417 }
418 
420 {
421  ReleaseMouse();
422  mbInitialUp = mbInitialDown = false;
425 
426  if (mbUpperIn)
427  {
428  mbUpperIn = false;
430  Up();
431  }
432  else if (mbLowerIn)
433  {
434  mbLowerIn = false;
436  Down();
437  }
438 
439  Edit::MouseButtonUp(rMEvt);
440 }
441 
443 {
444  if (rMEvt.IsLeft())
445  {
446  if (mbInitialUp)
447  {
448  bool bNewUpperIn = maUpperRect.IsInside(rMEvt.GetPosPixel());
449  if (bNewUpperIn != mbUpperIn)
450  {
451  if (bNewUpperIn)
452  {
453  if (mbRepeat)
455  }
456  else
458 
459  mbUpperIn = bNewUpperIn;
461  }
462  }
463  else if (mbInitialDown)
464  {
465  bool bNewLowerIn = maLowerRect.IsInside(rMEvt.GetPosPixel());
466  if (bNewLowerIn != mbLowerIn)
467  {
468  if (bNewLowerIn)
469  {
470  if (mbRepeat)
472  }
473  else
475 
476  mbLowerIn = bNewLowerIn;
478  }
479  }
480  }
481 
482  Edit::MouseMove(rMEvt);
483 }
484 
486 {
487  bool bDone = false;
488  if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
489  {
490  const KeyEvent& rKEvt = *rNEvt.GetKeyEvent();
491  if (!IsReadOnly())
492  {
493  sal_uInt16 nMod = rKEvt.GetKeyCode().GetModifier();
494  switch (rKEvt.GetKeyCode().GetCode())
495  {
496  case KEY_UP:
497  {
498  if (!nMod)
499  {
500  Up();
501  bDone = true;
502  }
503  }
504  break;
505  case KEY_DOWN:
506  {
507  if (!nMod)
508  {
509  Down();
510  bDone = true;
511  }
512  else if ((nMod == KEY_MOD2) && !mbInDropDown && (GetStyle() & WB_DROPDOWN))
513  {
514  mbInDropDown = ShowDropDown(true);
516  bDone = true;
517  }
518  }
519  break;
520  case KEY_PAGEUP:
521  {
522  if (!nMod)
523  {
524  Last();
525  bDone = true;
526  }
527  }
528  break;
529  case KEY_PAGEDOWN:
530  {
531  if (!nMod)
532  {
533  First();
534  bDone = true;
535  }
536  }
537  break;
538  }
539  }
540  }
541 
542  if (rNEvt.GetType() == MouseNotifyEvent::COMMAND)
543  {
545  {
546  MouseWheelBehaviour nWheelBehavior(GetSettings().GetMouseSettings().GetWheelBehavior());
547  if (nWheelBehavior == MouseWheelBehaviour::ALWAYS
548  || (nWheelBehavior == MouseWheelBehaviour::FocusOnly && HasChildPathFocus()))
549  {
551  if (pData->GetMode() == CommandWheelMode::SCROLL)
552  {
553  if (pData->GetDelta() < 0)
554  Down();
555  else
556  Up();
557  bDone = true;
558  }
559  }
560  else
561  bDone = false; // don't eat this event, let the default handling happen (i.e. scroll the context)
562  }
563  }
564 
565  return bDone || Edit::EventNotify(rNEvt);
566 }
567 
569 {
570  if (mbSpin)
571  {
572  mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
575  }
576  else
578 }
579 
580 void SpinField::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
581 {
582  if (mbSpin)
583  {
584  bool bEnable = IsEnabled();
585  ImplDrawSpinButton(rRenderContext, this, maUpperRect, maLowerRect,
586  mbUpperIn, mbLowerIn, bEnable, bEnable);
587  }
588 
589  if (GetStyle() & WB_DROPDOWN)
590  {
591  DecorationView aView(&rRenderContext);
592 
594  if (mbInDropDown)
595  nStyle |= DrawButtonFlags::Pressed;
596  tools::Rectangle aInnerRect = aView.DrawButton(maDropDownRect, nStyle);
597 
599  aView.DrawSymbol(aInnerRect, SymbolType::SPIN_DOWN, rRenderContext.GetSettings().GetStyleSettings().GetButtonTextColor(), nSymbolStyle);
600  }
601 
602  Edit::Paint(rRenderContext, rRect);
603 }
604 
606  tools::Rectangle& rSpinUpArea, tools::Rectangle& rSpinDownArea)
607 {
608  const StyleSettings& rStyleSettings = pDev->GetSettings().GetStyleSettings();
609 
610  Size aSize = rOutSz;
611  Size aDropDownSize;
612 
613  if (GetStyle() & WB_DROPDOWN)
614  {
615  long nW = rStyleSettings.GetScrollBarSize();
616  nW = GetDrawPixel( pDev, nW );
617  aDropDownSize = Size( CalcZoom( nW ), aSize.Height() );
618  aSize.AdjustWidth( -(aDropDownSize.Width()) );
619  rDDArea = tools::Rectangle( Point( aSize.Width(), 0 ), aDropDownSize );
620  rDDArea.AdjustTop( -1 );
621  }
622  else
623  rDDArea.SetEmpty();
624 
625  // calculate sizes according to the height
626  if (GetStyle() & WB_SPIN)
627  {
628  long nBottom1 = aSize.Height()/2;
629  long nBottom2 = aSize.Height()-1;
630  long nTop2 = nBottom1;
631  if ( !(aSize.Height() & 0x01) )
632  nBottom1--;
633 
634  bool bNativeRegionOK = false;
635  tools::Rectangle aContentUp, aContentDown;
636 
637  if ((pDev->GetOutDevType() == OUTDEV_WINDOW) &&
638  // there is just no useful native support for spinfields with dropdown
639  ! (GetStyle() & WB_DROPDOWN) &&
641  {
642  vcl::Window *pWin = static_cast<vcl::Window*>(pDev);
643  vcl::Window *pBorder = pWin->GetWindow( GetWindowType::Border );
644 
645  // get the system's spin button size
646  ImplControlValue aControlValue;
647  tools::Rectangle aBound;
648  Point aPoint;
649 
650  // use the full extent of the control
651  tools::Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
652 
653  bNativeRegionOK =
655  aArea, ControlState::NONE, aControlValue, aBound, aContentUp) &&
657  aArea, ControlState::NONE, aControlValue, aBound, aContentDown);
658 
659  if (bNativeRegionOK)
660  {
661  // convert back from border space to local coordinates
662  aPoint = pBorder->ScreenToOutputPixel( pWin->OutputToScreenPixel( aPoint ) );
663  aContentUp.Move(-aPoint.X(), -aPoint.Y());
664  aContentDown.Move(-aPoint.X(), -aPoint.Y());
665  }
666  }
667 
668  if (bNativeRegionOK)
669  {
670  rSpinUpArea = aContentUp;
671  rSpinDownArea = aContentDown;
672  }
673  else
674  {
675  aSize.AdjustWidth( -(CalcZoom( GetDrawPixel( pDev, rStyleSettings.GetSpinSize() ) )) );
676 
677  rSpinUpArea = tools::Rectangle( aSize.Width(), 0, rOutSz.Width()-aDropDownSize.Width()-1, nBottom1 );
678  rSpinDownArea = tools::Rectangle( rSpinUpArea.Left(), nTop2, rSpinUpArea.Right(), nBottom2 );
679  }
680  }
681  else
682  {
683  rSpinUpArea.SetEmpty();
684  rSpinDownArea.SetEmpty();
685  }
686 }
687 
689 {
690  if (mbSpin)
691  {
692  Control::Resize();
693  Size aSize = GetOutputSizePixel();
694  bool bSubEditPositioned = false;
695 
696  if (GetStyle() & (WB_SPIN | WB_DROPDOWN))
697  {
699 
700  ImplControlValue aControlValue;
701  Point aPoint;
702  tools::Rectangle aContent, aBound;
703 
704  // use the full extent of the control
706  tools::Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
707 
708  // adjust position and size of the edit field
710  aControlValue, aBound, aContent) &&
711  // there is just no useful native support for spinfields with dropdown
712  !(GetStyle() & WB_DROPDOWN))
713  {
714  // convert back from border space to local coordinates
715  aPoint = pBorder->ScreenToOutputPixel(OutputToScreenPixel(aPoint));
716  aContent.Move(-aPoint.X(), -aPoint.Y());
717 
718  // use the themes drop down size
719  mpEdit->SetPosPixel( aContent.TopLeft() );
720  bSubEditPositioned = true;
721  aSize = aContent.GetSize();
722  }
723  else
724  {
725  if (maUpperRect.IsEmpty())
726  {
727  SAL_WARN_IF( maDropDownRect.IsEmpty(), "vcl", "SpinField::Resize: SPIN && DROPDOWN, but all empty rects?" );
728  aSize.setWidth( maDropDownRect.Left() );
729  }
730  else
731  aSize.setWidth( maUpperRect.Left() );
732  }
733  }
734 
735  if (!bSubEditPositioned)
736  {
737  // this moves our sub edit if RTL gets switched
739  }
740  mpEdit->SetSizePixel(aSize);
741 
742  if (GetStyle() & WB_SPIN)
744  if (GetStyle() & WB_DROPDOWN)
746  }
747 }
748 
750 {
751  Edit::StateChanged(nType);
752 
753  if (nType == StateChangedType::Enable)
754  {
755  if (mbSpin || (GetStyle() & WB_DROPDOWN))
756  {
757  mpEdit->Enable(IsEnabled());
758 
759  if (mbSpin)
760  {
763  }
764  if (GetStyle() & WB_DROPDOWN)
766  }
767  }
768  else if (nType == StateChangedType::Style)
769  {
770  if (GetStyle() & WB_REPEAT)
771  mbRepeat = true;
772  else
773  mbRepeat = false;
774  }
775  else if (nType == StateChangedType::Zoom)
776  {
777  Resize();
778  if (mpEdit)
779  mpEdit->SetZoom(GetZoom());
780  Invalidate();
781  }
782  else if (nType == StateChangedType::ControlFont)
783  {
784  if (mpEdit)
786  Invalidate();
787  }
788  else if (nType == StateChangedType::ControlForeground)
789  {
790  if (mpEdit)
792  Invalidate();
793  }
794  else if (nType == StateChangedType::ControlBackground)
795  {
796  if (mpEdit)
798  Invalidate();
799  }
800  else if( nType == StateChangedType::Mirroring )
801  {
802  if (mpEdit)
804  Resize();
805  }
806 }
807 
809 {
810  Edit::DataChanged(rDCEvt);
811 
812  if ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
813  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
814  {
815  Resize();
816  Invalidate();
817  }
818 }
819 
821 {
822  if (maUpperRect.IsInside(rPt))
823  return &maUpperRect;
824  else if (maLowerRect.IsInside(rPt))
825  return &maLowerRect;
826  else
827  return nullptr;
828 }
829 
831 {
832  const MouseEvent* pMouseEvt = nullptr;
833 
834  if ((rNEvt.GetType() == MouseNotifyEvent::MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != nullptr)
835  {
836  if (!pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged())
837  {
838  // trigger redraw if mouse over state has changed
841  {
844  if( pRect != pLastRect || (pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) )
845  {
846  // FIXME: this is currently only on macOS
847  // check for other platforms that need similar handling
850  {
852  }
853  else
854  {
855  // paint directly
857  if (pLastRect)
858  {
859  SetClipRegion(vcl::Region(*pLastRect));
860  Invalidate(*pLastRect);
861  SetClipRegion( aRgn );
862  }
863  if (pRect)
864  {
865  SetClipRegion(vcl::Region(*pRect));
866  Invalidate(*pRect);
867  SetClipRegion( aRgn );
868  }
869  }
870  }
871  }
872  }
873  }
874 
875  return Edit::PreNotify(rNEvt);
876 }
877 
879 {
880  mbInDropDown = false;
882 }
883 
885 {
886  return false;
887 }
888 
889 Size SpinField::CalcMinimumSizeForText(const OUString &rString) const
890 {
891  Size aSz = Edit::CalcMinimumSizeForText(rString);
892 
893  if ( GetStyle() & WB_DROPDOWN )
894  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
895  if ( GetStyle() & WB_SPIN )
896  {
897  ImplControlValue aControlValue;
898  tools::Rectangle aArea( Point(), Size(100, aSz.Height()));
899  tools::Rectangle aEntireBound, aEntireContent, aEditBound, aEditContent;
900  if (
902  aArea, ControlState::NONE, aControlValue, aEntireBound, aEntireContent) &&
904  aArea, ControlState::NONE, aControlValue, aEditBound, aEditContent)
905  )
906  {
907  aSz.AdjustWidth(aEntireContent.GetWidth() - aEditContent.GetWidth());
908  }
909  else
910  {
912  }
913  }
914 
915  return aSz;
916 }
917 
919 {
921 }
922 
924 {
925  return CalcMinimumSize();
926 }
927 
928 Size SpinField::CalcSize(sal_Int32 nChars) const
929 {
930  Size aSz = Edit::CalcSize( nChars );
931 
932  if ( GetStyle() & WB_DROPDOWN )
933  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetScrollBarSize() );
934  if ( GetStyle() & WB_SPIN )
935  aSz.AdjustWidth(GetSettings().GetStyleSettings().GetSpinSize() );
936 
937  return aSz;
938 }
939 
940 IMPL_LINK( SpinField, ImplTimeout, Timer*, pTimer, void )
941 {
942  if ( pTimer->GetTimeout() == MouseSettings::GetButtonStartRepeat() )
943  {
944  pTimer->SetTimeout( GetSettings().GetMouseSettings().GetButtonRepeat() );
945  pTimer->Start();
946  }
947  else
948  {
949  if ( mbInitialUp )
950  Up();
951  else
952  Down();
953  }
954 }
955 
956 void SpinField::Draw(OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags)
957 {
958  Edit::Draw(pDev, rPos, rSize, nFlags);
959 
960  WinBits nFieldStyle = GetStyle();
961  if ( (nFlags & DrawFlags::NoControls ) || !( nFieldStyle & (WB_SPIN|WB_DROPDOWN) ) )
962  return;
963 
964  Point aPos = pDev->LogicToPixel( rPos );
965  Size aSize = pDev->LogicToPixel( rSize );
966  AllSettings aOldSettings = pDev->GetSettings();
967 
968  pDev->Push();
969  pDev->SetMapMode();
970 
971  tools::Rectangle aDD, aUp, aDown;
972  ImplCalcButtonAreas(pDev, aSize, aDD, aUp, aDown);
973  aDD.Move(aPos.X(), aPos.Y());
974  aUp.Move(aPos.X(), aPos.Y());
975  aUp.AdjustTop( 1 );
976  aDown.Move(aPos.X(), aPos.Y());
977 
978  Color aButtonTextColor;
979  if (nFlags & DrawFlags::Mono)
980  aButtonTextColor = COL_BLACK;
981  else
982  aButtonTextColor = GetSettings().GetStyleSettings().GetButtonTextColor();
983 
984  if (GetStyle() & WB_DROPDOWN)
985  {
986  DecorationView aView( pDev );
989  aView.DrawSymbol(aInnerRect, SymbolType::SPIN_DOWN, aButtonTextColor, nSymbolStyle);
990  }
991 
992  if (GetStyle() & WB_SPIN)
993  {
994  ImplDrawSpinButton(*pDev, this, aUp, aDown, false, false);
995  }
996 
997  pDev->Pop();
998  pDev->SetSettings(aOldSettings);
999 
1000 }
1001 
1003 {
1005 }
1006 
1007 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: edit.cxx:1714
Point TopLeft() const
long Width() const
vcl::Region GetClipRegion() const
OutDevType GetOutDevType() const
Definition: outdev.hxx:522
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:550
IMPL_LINK(SpinField, ImplTimeout, Timer *, pTimer, void)
Definition: spinfld.cxx:940
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:379
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:331
std::unique_ptr< ContentProperties > pData
Edit * GetSubEdit() const
Definition: edit.hxx:225
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:923
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:207
virtual Size CalcMinimumSizeForText(const OUString &rString) const
Definition: edit.cxx:2623
long AdjustLeft(long nHorzMoveDelta)
void disposeAndClear()
Definition: vclptr.hxx:200
const StyleSettings & GetStyleSettings() const
ImplSVNWFData maNWFData
Definition: svdata.hxx:399
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1262
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: spinfld.cxx:580
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
Definition: spinfld.cxx:419
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: edit.cxx:215
void CompatStateChanged(StateChangedType nStateChange)
Definition: window.cxx:3907
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
ControlPart mnLowerPart
DataChangedEventType GetType() const
Definition: event.hxx:361
const KeyEvent * GetKeyEvent() const
Definition: event.hxx:315
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:605
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:359
const Color & GetControlBackground() const
Definition: window2.cxx:1082
const CommandWheelData * GetWheelData() const
tools::Rectangle * ImplFindPartRect(const Point &rPt)
Definition: spinfld.cxx:820
tools::Rectangle DrawButton(const tools::Rectangle &rRect, DrawButtonFlags nStyle)
Definition: decoview.cxx:942
tools::Rectangle maLowerRect
bool HasChildPathFocus(bool bSystemWindow=false) const
Definition: window.cxx:3059
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:311
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:1708
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: spinfld.cxx:352
bool mbInitialDown
Definition: spinfld.hxx:87
AutoTimer maRepeatTimer
Definition: spinfld.hxx:84
void Enable(bool bEnable=true, bool bChild=true)
Definition: window.cxx:2446
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:347
AllSettingsFlags GetFlags() const
Definition: event.hxx:362
constexpr sal_uInt16 KEY_PAGEUP
Definition: keycodes.hxx:116
virtual void MouseMove(const MouseEvent &rMEvt) override
Definition: spinfld.cxx:442
void SetCompoundControl(bool bCompound)
Definition: window2.cxx:947
sal_uInt16 GetModifier() const
Definition: keycod.hxx:56
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
Definition: edit.cxx:1350
virtual bool ShowDropDown(bool bShow)
Definition: spinfld.cxx:884
Definition: edit.hxx:55
virtual FactoryFunction GetUITestFactory() const override
Definition: spinfld.cxx:1002
virtual void Down()
Definition: spinfld.cxx:364
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:75
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: spinfld.cxx:485
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:51
bool IsLeaveWindow() const
Definition: event.hxx:137
DrawFlags
Definition: window.hxx:354
The edit field part of a control, e.g.
bool IsNativeWidgetEnabled() const
Definition: window.cxx:3758
bool mbInitialUp
Definition: spinfld.hxx:87
virtual void StateChanged(StateChangedType nType) override
Definition: edit.cxx:2149
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:1160
ControlState mnLowerState
virtual OUString GetText() const override
Definition: edit.cxx:2568
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
CommandEventId GetCommand() const
void SetZoom(const Fraction &rZoom)
Definition: window2.cxx:365
virtual void FillLayoutData() const override
Definition: spinfld.cxx:568
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:307
bool IsInside(const Point &rPOINT) const
void SetSubEdit(Edit *pEdit)
Definition: edit.cxx:2608
WinBits const WB_DROPDOWN
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
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:2875
void GrabFocus()
Definition: window.cxx:3031
virtual Size CalcSize(sal_Int32 nChars) const override
Definition: spinfld.cxx:928
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:293
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:934
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
void ReleaseMouse()
Definition: mouse.cxx:459
virtual Size CalcSize(sal_Int32 nChars) const
Definition: edit.cxx:2691
bool IsModifierChanged() const
Definition: event.hxx:141
void EndDropDown()
Definition: spinfld.cxx:878
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:1821
virtual void First()
Definition: spinfld.cxx:369
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: spinfld.cxx:808
bool IsMouseOver() const
Definition: mouse.cxx:606
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: spinfld.cxx:305
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:321
#define SAL_WARN_IF(condition, area, stream)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: edit.cxx:2230
const MouseEvent * GetMouseEvent() const
Definition: event.hxx:323
std::unique_ptr< vcl::ImplControlData > mpControlData
Definition: ctrl.hxx:36
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: edit.cxx:1309
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
bool IsLeft() const
Definition: event.hxx:146
virtual Size CalcMinimumSize() const override
Definition: spinfld.cxx:918
bool mbLowerIn
Definition: spinfld.hxx:87
virtual void Last()
Definition: spinfld.cxx:374
long AdjustTop(long nVertMoveDelta)
virtual void Resize() override
Definition: spinfld.cxx:688
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:830
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:805
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:2869
virtual bool IsReadOnly() const
Definition: edit.hxx:180
Point GetLastPointerPosPixel()
Definition: mouse.cxx:562
long GetScrollBarSize() const
virtual Size CalcMinimumSizeForText(const OUString &rString) const override
Definition: spinfld.cxx:889
virtual void Draw(OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags) override
Definition: edit.cxx:1733
vcl::Font GetControlFont() const
Definition: window2.cxx:438
bool HasFocus() const
Definition: window.cxx:3036
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:3869
void setWidth(long nWidth)
SpinField(vcl::Window *pParent, WinBits nWinStyle)
Definition: spinfld.cxx:340
sal_Int32 nState
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1257
VclPtr< Edit > mpEdit
Definition: spinfld.hxx:83
virtual void Draw(OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags) override
Definition: spinfld.cxx:956
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:749
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:2201