i have a spin button in a dialog.
it will be used to incr/decr a date in a date field.
i do not want the date field’s built-in spinner - default behavior is inappropriate for my use case.
i assigned a sub to the “while adjusting” event of the standalone spinner.
i can’t see any property or method to discover which half of spin button was clicked.
thanks,
-dave
The Sub you assigned to a mouse event on the SB gets passed an event parameter. Let’s name it pEvent.
It has a .X
and a .Y
property which gives the position of the mouse relative to the top left corner of the SB’s area in the view (at the moment the event was triggered). The control itself is accessible as pEvent.Source
and hase a .Size
property. Depending on the .Orientation
you need to compare pEvent.X
with pEvent.Source.Size.Width
or pEvent.Y
with pEvent.Source.Size.Height
to get your answer.
(I don’t know for sure, but hope that Width and Heighht are forced to be odd for SB.)
=== Edit 2020-01-23 about 13:55 UTC ===
Sorry forgot to mention that I suggest to bind the Sub to onMouseButtonReleased
.
Wit onAdjusting
you don’t get mouse coordinates and you woul need to use the Value property comparing it with a previous value kept in a global variable. This would be complicated mainly due to the problem of initialization.
Code (raw example):
Sub incORdecClick(pEvent) REM onMousButtonReleased
src = pEvent.Source
ori = src.Orientation
Dim incHalf As Variant
mouseX = pEvent.X
mouseY = pEvent.Y
sizeW = src.Size.Width
sizeH = src.Size.Height
If (mouseX<0) OR (mouseX>sizeW) OR _
(mouseY<0) OR (mouseY>sizeH) Then ExitSub
Select Case ori
Case 0 REM horizontal
incHalf = (mouseX*2>sizeW) REM Hope this is not locale dependent.
Case 1 REM vertical
incHalf = (mouseY*2<sizeH) REM Y increases viewdownwards.
Case Else
Print "Unclear"
End Select
Print incHalf
End Sub
OP has a value in the date field; and a new value in the spinner. I suppose it’s enough for determining the change, and is enough for initialization. The while adjusting
event might be fine here.
Is “date field” the specific form control here, or just a chosen expression for the linked cell?
The linked cell is updated in advance of throwing the event as an experiment showed me.
The com.sun.star.awt.AdjustmentEvent only has properties not seeming to be related to the increase/decrease process.
The question starts with “i have a spin button in a dialog”, but the “spinner” also is called “standalone”.
Probably I simply didn’t understand this kind of wording.
This all looks very promising, thanks guys. (PS the standalone spinner is also in the dialog. and PSS there is no linked cell; the final date value will be assigned to a different cell on every invocation of dialog.)
okay, i got it working like this
sub spinner(event)
' today and dialog are global and initialized elsewhere
dialog.getcontrol("thedatefield").text = format(today + event.value, "mm/dd/yy")
end sub
there is one weird thing: in the init for thedatefield i can say .text = date(today) and it fills the date correctly. (today is Long). but in the sub above i have to use format() else nothing changes.
one final observation: there doesnt seem to be any “mouse button pressed” or released event that actually happens for the spinner, even though they are listed as possible events in the properties page in the dialog designer. In any event (haha) “while adjusting” does occur.