[GB.DB.FORM]
NEW: Add DataComboMulti.class git-svn-id: svn://localhost/gambas/trunk@1313 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
472d81fd5d
commit
3c7450fe2b
@ -5,6 +5,6 @@ Needs=Form
|
||||
Requires=gb.db,gb.form
|
||||
|
||||
[Data]
|
||||
Control=DataBrowser,DataCombo,DataControl,DataSource,DataView,DataComboMulti
|
||||
Control=DataBrowser,DataCombo,DataComboMulti,DataControl,DataSource,DataView
|
||||
Container=DataSource
|
||||
|
||||
|
@ -118,7 +118,7 @@ C
|
||||
_Properties
|
||||
C
|
||||
s
|
||||
*, Tag,Filter,Fields,Display,DataField,Table,Header,ReadOnly=True,Value,MaxLine=8,WidthList,FormatString
|
||||
*,Tag,Filter,Fields,Display,DataField,Table,Header,ReadOnly=True,Value,MaxLine=8,WidthList,FormatString
|
||||
_DefaultEvent
|
||||
C
|
||||
s
|
||||
|
@ -14,6 +14,7 @@ Language=en
|
||||
KeepDebugInfo=1
|
||||
MakeComponent=1
|
||||
Maintainer=fabien
|
||||
Vendor=Princeton
|
||||
Address=fabien@arcalis
|
||||
License=General Public Licence
|
||||
Prefix=1
|
||||
|
301
comp/src/gb.db.form/DataComboMulti.class
Normal file
301
comp/src/gb.db.form/DataComboMulti.class
Normal file
@ -0,0 +1,301 @@
|
||||
' Gambas class file
|
||||
Inherits UserControl
|
||||
Export
|
||||
Public Const _Properties As String = "*,Tag,Filter,Fields,Display,DataField,Table,Header,ReadOnly=True,Value,MaxLine=8,WidthList,FormatString"
|
||||
Public Const _DefaultEvent As String = "Change"
|
||||
Public Const _DefaultSize As String = "20,4"
|
||||
Public Const _DrawWith As String = "ComboBox"
|
||||
Private $hForm As Form
|
||||
Private $htvw As ColumnView
|
||||
Private $hObserver As Observer
|
||||
|
||||
Private $sTable As String
|
||||
Private $sFilter As String ' = " order by art_code"
|
||||
Private $aDisplay As String[]
|
||||
Private $aFields As New String[]
|
||||
Private $hResult As Result
|
||||
Private $vValue As Variant
|
||||
Private $sDataField As String
|
||||
Private $hCombo As ComboBox
|
||||
Private $iWidthList As Integer
|
||||
Private $iMaxLine As Integer
|
||||
Private $hList As Integer
|
||||
Private $sFormat As String
|
||||
Private htimer As timer
|
||||
Private isActivate As Boolean
|
||||
Property Filter As String
|
||||
Property Fields As String[]
|
||||
Property Display As String[]
|
||||
Property DataField As String
|
||||
Property Table As String
|
||||
Property Tag As Variant
|
||||
Property Header As Boolean
|
||||
Property ReadOnly As Boolean
|
||||
Property Value As Variant
|
||||
Property MaxLine As Integer
|
||||
Property WidthList As Integer
|
||||
Property FormatString As String
|
||||
|
||||
Event Change()
|
||||
|
||||
Public Sub _New()
|
||||
|
||||
Dim hPanel As Panel
|
||||
$hCombo = New ComboBox(Me) As "Combo"
|
||||
|
||||
$hCombo.Add("")
|
||||
|
||||
hTimer = New timer As "hTimer"
|
||||
htimer.delay = 100
|
||||
|
||||
$hForm = New Form As "LstForm"
|
||||
Object.Attach($hForm, Me, "LstForm")
|
||||
$hForm.Border = Form.None
|
||||
$hForm.SkipTaskbar = True
|
||||
$hForm.Arrangement = Arrange.Fill
|
||||
$hForm.Stacking = Form.Above
|
||||
|
||||
HPanel = New Panel($hForm)
|
||||
HPanel.Arrangement = Arrange.Fill
|
||||
hPanel.Border = Border.Plain
|
||||
$htvw = New ColumnView(hPanel) As "ColumnView"
|
||||
$htvw.Header = True
|
||||
$htvw.AutoResize = True
|
||||
$htvw.Border = False
|
||||
$htvw.Mode = Select.Single
|
||||
$hObserver = New Observer(Me.Window) As "OBS"
|
||||
Me.MaxLine = 8
|
||||
Me.ReadOnly = True
|
||||
$hList = ($htvw.Font.Height("0lp§") + 3) * ($iMaxLine + Abs(CInt($htvw.Header))) + 7
|
||||
End
|
||||
|
||||
Public Sub Form_Resize()
|
||||
$hForm.Resize($iWidthList, $hList)
|
||||
End
|
||||
|
||||
Public Sub Refresh()
|
||||
LoadValues()
|
||||
End
|
||||
|
||||
Private Sub LoadValues()
|
||||
Dim i, j, c As Integer
|
||||
Dim s As String
|
||||
$hResult = DB.Find($sTable, $sFilter)
|
||||
$htvw.Columns.Count = $aFields.count
|
||||
For i = 0 To $htvw.Columns.Count - 1
|
||||
|
||||
If i >= $aDisplay.Count Then
|
||||
$htvw.Columns[i].Text = $aFields[i]
|
||||
Else
|
||||
$htvw.Columns[i].Text = $aDisplay[i]
|
||||
Endif
|
||||
Next
|
||||
$htvw.Clear
|
||||
i = 0
|
||||
For Each $hResult
|
||||
$htvw.Add(i, $hResult[$aFields[0]])
|
||||
For j = 1 To $aFields.Max
|
||||
$htvw[i][j] = $hResult[$aFields[j]]
|
||||
Next
|
||||
Inc i
|
||||
Next
|
||||
If $htvw.Count < $iMaxLine Then
|
||||
c = $htvw.Count
|
||||
Else
|
||||
c = $iMaxLine
|
||||
Endif
|
||||
If $iWidthList = 0 Then $iWidthList = Me.Width
|
||||
|
||||
$hList = ($htvw.Font.Height("0lp§") + 3) * (c + Abs(CInt($htvw.Header))) + 7
|
||||
$hForm.Resize($iWidthList, $hList)
|
||||
$htvw.MoveFirst
|
||||
ColumnView_Select()
|
||||
End
|
||||
|
||||
Public Sub LstForm_DeACtivate()
|
||||
htimer.Start
|
||||
$hForm.hide
|
||||
End
|
||||
|
||||
|
||||
Private Function Filter_Read() As String
|
||||
Return $sFilter
|
||||
End
|
||||
|
||||
Private Sub Filter_Write(Value As String)
|
||||
$sFilter = Value
|
||||
End
|
||||
|
||||
Private Function Table_Read() As String
|
||||
Return $sTable
|
||||
End
|
||||
|
||||
Private Sub Table_Write(Value As String)
|
||||
$sTable = Value
|
||||
End
|
||||
|
||||
Private Function Fields_Read() As String[]
|
||||
Return $aFields
|
||||
End
|
||||
|
||||
Private Sub Fields_Write(Value As String[])
|
||||
$aFields = Value
|
||||
End
|
||||
|
||||
|
||||
Private Function Tag_Read() As Variant
|
||||
Return $hCombo.Tag
|
||||
End
|
||||
|
||||
Private Sub Tag_Write(Value As Variant)
|
||||
$hCombo.Tag = Value
|
||||
End
|
||||
|
||||
Private Function Display_Read() As String[]
|
||||
Return $aDisplay
|
||||
End
|
||||
|
||||
Private Sub Display_Write(Value As String[])
|
||||
$aDisplay = Value
|
||||
End
|
||||
|
||||
Private Function Header_Read() As Boolean
|
||||
Return $htvw.Header
|
||||
End
|
||||
|
||||
Private Sub Header_Write(Value As Boolean)
|
||||
$htvw.Header = Value
|
||||
End
|
||||
|
||||
Private Function ReadOnly_Read() As Boolean
|
||||
Return $hCombo.ReadOnly
|
||||
End
|
||||
|
||||
Private Sub ReadOnly_Write(Value As Boolean)
|
||||
$hCombo.ReadOnly = Value
|
||||
End
|
||||
|
||||
Public Sub ColumnView_KeyPress()
|
||||
If key.Code = key.Esc Then LstForm_DeACtivate
|
||||
End
|
||||
|
||||
Public Sub ColumnView_Click()
|
||||
ColumnView_Select
|
||||
Raise Change
|
||||
LstForm_DeACtivate
|
||||
End
|
||||
|
||||
Public Sub ColumnView_Select()
|
||||
$hResult.MoveTo(Val($htvw.Current.Key))
|
||||
Value_Refresh($hResult)
|
||||
End
|
||||
|
||||
Private Sub Value_Refresh(h As Result)
|
||||
Dim s, sRes As String
|
||||
$vValue = h[$sDataField]
|
||||
|
||||
If Not $sFormat Then
|
||||
For Each s In $aFields
|
||||
sRes &= h[s] & " | "
|
||||
Next
|
||||
sRes = Left(sRes, Len(sRes) - 3)
|
||||
Else
|
||||
sRes = $sFormat
|
||||
For Each s In $aFields
|
||||
sRes = Replace$(sres, "%" & s & "%", CStr(h[s]))
|
||||
Next
|
||||
Endif
|
||||
|
||||
If $hCombo.ReadOnly Then
|
||||
$hCombo.Clear
|
||||
$hCombo.Add(sRes)
|
||||
Else
|
||||
$hCombo.Text = sRes
|
||||
$hCombo.Pos = 0
|
||||
Endif
|
||||
End
|
||||
|
||||
Private Function Value_Read() As Variant
|
||||
Return $vValue
|
||||
End
|
||||
|
||||
Private Sub Value_Write(st As Variant)
|
||||
If st = "" Then
|
||||
$hCombo.Clear
|
||||
Return
|
||||
Endif
|
||||
$hResult = DB.Find($sTable, $sDataField & " LIKE " & st)
|
||||
Value_Refresh($hResult)
|
||||
End
|
||||
|
||||
Private Function DataField_Read() As String
|
||||
Return $sDataField
|
||||
End
|
||||
|
||||
Private Sub DataField_Write(Value As String)
|
||||
$sDataField = Value
|
||||
End
|
||||
|
||||
Private Function MaxLine_Read() As Integer
|
||||
Return $iMaxLine
|
||||
End
|
||||
|
||||
Private Sub MaxLine_Write(Value As Integer)
|
||||
$iMaxLine = Value
|
||||
End
|
||||
|
||||
Private Function WidthList_Read() As Integer
|
||||
Return $iWidthList
|
||||
End
|
||||
|
||||
Private Sub WidthList_Write(Value As Integer)
|
||||
$iWidthList = Value
|
||||
$hForm.Resize($iWidthList, $hList)
|
||||
End
|
||||
|
||||
Private Function FormatString_Read() As String
|
||||
Return $sFormat
|
||||
End
|
||||
|
||||
Private Sub FormatString_Write(Value As String)
|
||||
$sFormat = Value
|
||||
End
|
||||
|
||||
Private Sub ColumnView_MouseMove()
|
||||
$htvw.Find(Mouse.X, Mouse.Y)
|
||||
Try $htvw.Item.Selected = True
|
||||
End
|
||||
|
||||
Public Sub Combo_KeyPress()
|
||||
If key.Code = key.Esc Then LstForm_DeACtivate
|
||||
If key.Code = key.Enter Or key.code = key.Down Then
|
||||
Combo_MouseDown
|
||||
Endif
|
||||
End
|
||||
|
||||
Public Sub Combo_MouseDown()
|
||||
LoadValues
|
||||
If $hCombo.ScreenY + $hCombo.Height + $hForm.Height < Desktop.Height Then
|
||||
$hForm.Move($hCombo.ScreenX, $hCombo.ScreenY + $hCombo.Height)
|
||||
Else
|
||||
$hForm.Move($hCombo.ScreenX, $hCombo.ScreenY - $hForm.Height)
|
||||
Endif
|
||||
$hForm.visible = Not (isActivate Or $hForm.visible)
|
||||
isActivate = $hForm.visible
|
||||
Stop Event
|
||||
End
|
||||
|
||||
Public Sub OBS_Move()
|
||||
If $hForm.Visible Then
|
||||
If $hCombo.ScreenY + $hCombo.Height + $hForm.Height < Desktop.Height Then
|
||||
$hForm.Move($hCombo.ScreenX, $hCombo.ScreenY + $hCombo.Height)
|
||||
Else
|
||||
$hForm.Move($hCombo.ScreenX, $hCombo.ScreenY - $hForm.Height)
|
||||
Endif
|
||||
Endif
|
||||
End
|
||||
|
||||
Public Sub hTimer_Timer()
|
||||
hTimer.Stop
|
||||
isActivate = False
|
||||
End
|
Loading…
x
Reference in New Issue
Block a user