Commit c875f00a authored by Benoît Minisini's avatar Benoît Minisini

TimeBox is a new control that allows to enter a duration. Maybe the name of...

TimeBox is a new control that allows to enter a duration. Maybe the name of the control is not very good.

[GB.FORM]
* NEW: TimeBox is a new control that allows to enter a duration. Maybe the name of the control is not very good.
parent 92a09ad1
# Gambas Project File 3.0 # Gambas Project File 3.0
Title=More controls for graphical components Title=More controls for graphical components
Startup=FSpinner Startup=FTestTimeBox
Version=3.12.90 Version=3.12.90
VersionFile=1 VersionFile=1
Component=gb.image Component=gb.image
Component=gb.gui Component=gb.gui
Component=gb.settings Component=gb.settings
Authors="Benoît Minisini" Authors="Benoît Minisini"
Environment="GB_GUI=gb.gtk3" Environment="GB_GUI=gb.qt5"
TabSize=2 TabSize=2
Translate=1 Translate=1
Language=en Language=en
......
' Gambas class file
Export
Inherits UserControl
Public Const _Properties As String = "*,Action,Value,ReadOnly,Border=True,ShowHour=true"
'Public Const _DefaultEvent As String = "Click"
Public Const _DefaultSize As String = "24,4"
Public Const _Similar As String = "TextBox"
Property Value As Date
Property ReadOnly As Boolean
Property Border As Boolean
Property ShowHour As Boolean
Private $hBorder As DrawingArea
Private $hHour As SpinBox
Private $hMinute As SpinBox
Private $hSecond As SpinBox
Private $bBorder As Boolean = True
Private $hLabelHour As Label
Private Sub CreateSpinBox(sName As String) As SpinBox
Dim hSpinBox As SpinBox
hSpinBox = New SpinBox($hBorder)
Object.Attach(hSpinBox, Me, sName)
hSpinBox.Expand = True
hSpinBox.Border = False
hSpinBox.Alignment = Align.Right
hSpinBox.ShowZero = True
Return hSpinBox
End
Public Sub _new()
Dim hLabel As Label
$hBorder = New DrawingArea(Me) As "Border"
$hBorder.Arrangement = Arrange.Horizontal
$hBorder.Padding = Style.FrameWidth
$hBorder.Margin = True
$hHour = CreateSpinBox("HourBox")
$hHour.MinValue = 0
$hHour.MaxValue = 24
GoSub CREATE_LABEL
$hLabelHour = hLabel
$hMinute = CreateSpinBox("MinuteBox")
$hMinute.MinValue = 0
$hMinute.MaxValue = 59
GoSub CREATE_LABEL
$hSecond = CreateSpinBox("SecondBox")
$hSecond.MinValue = 0
$hSecond.MaxValue = 59
Return
CREATE_LABEL:
hLabel = New Label($hBorder)
hLabel.Text = " :"
hLabel.AutoResize = True
Return
End
Private Function Value_Read() As Date
Try Return Time($hHour.Value, $hMinute.Value, $hSecond.Value)
End
Private Sub Value_Write(Value As Date)
$hHour.Value = Hour(Value)
$hMinute.Value = Minute(Value)
$hSecond.Value = Second(Value)
End
Private Function ReadOnly_Read() As Boolean
Return $hMinute.ReadOnly
End
Private Sub ReadOnly_Write(Value As Boolean)
$hHour.ReadOnly = Value
$hMinute.ReadOnly = Value
$hSecond.ReadOnly = Value
End
Private Function Border_Read() As Boolean
Return $bBorder
End
Private Sub Border_Write(Value As Boolean)
$bBorder = Value
$hBorder.Padding = If($bBorder, Max(Style.BoxFrameWidth, Style.BoxFrameHeight), 0)
$hBorder.Margin = $bBorder
End
Public Sub HourBox_GotFocus()
$hBorder.Refresh
'$hHour.SelectAll
End
Public Sub MinuteBox_GotFocus()
$hBorder.Refresh
'$hMinute.SelectAll
End
Public Sub SecondBox_GotFocus()
$hBorder.Refresh
'$hSecond.SelectAll
End
Public Sub HourBox_LostFocus()
$hBorder.Refresh
End
Public Sub MinuteBox_LostFocus()
$hBorder.Refresh
End
Public Sub SecondBox_LostFocus()
$hBorder.Refresh
End
Public Sub SecondBox_Limit()
If $hSecond.Value = $hSecond.MaxValue Then
Try Me.Value = DateAdd(Me.Value, gb.Second, 1)
Else If $hSecond.Value = $hSecond.MinValue Then
Try Me.Value = DateAdd(Me.Value, gb.Second, -1)
Endif
$hSecond.SetFocus
$hSecond.SelectAll
End
Public Sub MinuteBox_Limit()
If $hMinute.Value = $hMinute.MaxValue Then
Try Me.Value = DateAdd(Me.Value, gb.Minute, 1)
Else If $hMinute.Value = $hMinute.MinValue Then
Try Me.Value = DateAdd(Me.Value, gb.Minute, -1)
Endif
$hMinute.SetFocus
End
' Public Sub MinuteBox_MouseWheel()
'
' $hMinute.Text = Format(Max(0, Min(59, CInt($hMinute.Text) + If(Mouse.Forward, 1, -1))), "00")
'
' End
'
' Public Sub SecondBox_MouseWheel()
'
' Dim dVal As Date
'
' dVal = Value_Read()
' Try dVal = DateAdd(dVal, gb.Second, If(Mouse.Forward, 10, -10))
' If Not Error Then Value_Write(dVal)
'
' End
Public Sub Border_Draw()
Dim iBg As Integer = Color.TextBackground
If Me.Background <> Color.Default Then iBg = Me.Background
If $bBorder Then
Style.PaintBox(0, 0, Me.W, Me.H, Style.StateOf($hMinute) Or Style.StateOf($hSecond) Or Style.StateOf($hHour), iBg)
Else
Paint.FillRect(0, 0, Me.W, Me.H, iBg)
Endif
End
Private Function ShowHour_Read() As Boolean
Return $hHour.Visible
End
Private Sub ShowHour_Write(Value As Boolean)
$hHour.Visible = Value
$hLabelHour.Visible = Value
If Not Value Then $hHour.Value = 0
End
# Gambas Form File 3.0
{ Form Form
MoveScaled(0,0,64,64)
{ TimeBox1 TimeBox
MoveScaled(8,6,21,4)
}
{ SpinBox1 SpinBox
MoveScaled(9,13,9,4)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment