home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 2001-09-09 | 7.1 KB | 261 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- Persistable = 0 'NotPersistable
- DataBindingBehavior = 0 'vbNone
- DataSourceBehavior = 0 'vbNone
- MTSTransactionMode = 0 'NotAnMTSObject
- END
- Attribute VB_Name = "CGrid"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- '-----------------------------------------------------------------------------
- ' This is a part of the BeeGrid ActiveX control.
- ' Copyright ⌐ 2000 Stinga
- ' All rights reserved.
- '
- ' You have a right to use and distribute the BeeGrid sample files in original
- ' form or modified, provided that you agree that Stinga has no warranty,
- ' obligations, or liability for any sample application files.
- '-----------------------------------------------------------------------------
- Option Explicit
-
- Private mcolPageColumns As New Collection
- Private Const EASTEUROPE_CHARSET = 238
-
- Private miGridScaleMode As Integer
- Private mGrid As SGGrid
-
-
- Private Declare Function OleTranslateColor Lib "oleaut32.dll" _
- (ByVal lOleColor As Long, ByVal lHPalette As Long, _
- lColorRef As Long) As Long
-
- Private Enum EConversions
- TwipsPerPoint = 20
- TwipsPerCharX = 120
- TwipsPerCharY = 240
- TwipsPerInch = 1440
- TwipsPerDecimeter = 5669
- End Enum
-
- Private mhFontOld As Long
- Private mhFont As Long
-
- Public Function GetColAlignment(col As SGColumn, _
- Optional bHeader As Boolean = False) As Long
- Dim lAlignment As sgAlignment
- Dim bWordWrap As Boolean
-
- If bHeader Then
- lAlignment = col.HeadingStyle.TextAlignment
- bWordWrap = col.HeadingStyle.WordWrap
- Else
- lAlignment = col.Style.TextAlignment
- bWordWrap = col.Style.WordWrap
- End If
-
- Select Case lAlignment
- Case sgAlignGeneral
- Select Case col.DataType
- Case sgtString
- GetColAlignment = DT_LEFT + DT_TOP
- Case Else
- GetColAlignment = DT_RIGHT + DT_TOP
- End Select
- Case sgAlignLeftTop
- GetColAlignment = DT_LEFT + DT_TOP
- Case sgAlignRightTop
- GetColAlignment = DT_RIGHT + DT_TOP
- Case sgAlignCenterTop
- GetColAlignment = DT_CENTER + DT_TOP
- Case sgAlignLeftCenter
- GetColAlignment = DT_LEFT + DT_VCENTER
- Case sgAlignRightCenter
- GetColAlignment = DT_RIGHT + DT_VCENTER
- Case sgAlignCenterCenter
- GetColAlignment = DT_CENTER + DT_VCENTER
- Case sgAlignLeftBottom
- GetColAlignment = DT_LEFT + DT_BOTTOM
- Case sgAlignRightBottom
- GetColAlignment = DT_RIGHT + DT_BOTTOM
- Case sgAlignCenterBottom
- GetColAlignment = DT_CENTER + DT_BOTTOM
- End Select
-
- If bWordWrap Then
- GetColAlignment = GetColAlignment + DT_WORDBREAK
- Else
- GetColAlignment = GetColAlignment + DT_SINGLELINE
- End If
- End Function
-
- Public Function AddPageColumns() As PageColumns
- Dim pcs As New PageColumns
-
- mcolPageColumns.Add pcs
- Set AddPageColumns = pcs
- Set pcs = Nothing
- End Function
-
- Public Sub ClearPageCols()
- Set mcolPageColumns = Nothing
- Set mcolPageColumns = New Collection
- End Sub
-
- Public Property Get Columns(vntIndexKey As Variant) As PageColumns
- Set Columns = mcolPageColumns(vntIndexKey)
- End Property
-
-
-
- Public Function ConvertToPixelX() As Single
- ConvertToPixelX = 1
-
- Select Case miGridScaleMode
- Case 1
- ConvertToPixelX = Screen.TwipsPerPixelX
- Case 2
- Case 3
- End Select
- End Function
-
- Public Sub DeleteFont(hdc As Long)
- Call SelectObject(hdc, mhFontOld)
- Call DeleteObject(mhFont)
- End Sub
-
- Public Function CalculateWidth(lWidth As Long)
- Select Case miGridScaleMode
- Case 1
- CalculateWidth = lWidth
- Case 2
- Case 3
- CalculateWidth = lWidth * ConvertToPixelX
- End Select
- End Function
-
- Public Function GetPadding(col As SGColumn) As Long
- GetPadding = col.Style.Padding
- End Function
-
- Public Function ConvertToPixelY() As Single
- ConvertToPixelY = 1
-
- Select Case miGridScaleMode
- Case 1
- ConvertToPixelY = Screen.TwipsPerPixelY
- Case 2
- Case 3
- End Select
- End Function
-
-
- Public Function GetPictureAlignment(col As SGColumn) As Long
- GetPictureAlignment = col.Style.PictureAlignment
- End Function
-
- Friend Function GetStyleAppearance _
- (sStyle As String, sytapp As sgStyleAppearance) As Boolean
-
- OleTranslateColor mGrid.Styles(sStyle).BackColor, 0, sytapp.BackColor
-
- sytapp.Flat = (mGrid.Styles(sStyle).Appearance = sgFlat)
-
- If sStyle = "Heading" Then
- If sytapp.Flat Then
- OleTranslateColor mGrid.HeadingGridLinesColor, 0, sytapp.BorderColor
- Else
- sytapp.BorderColor = GetSysColor(COLOR_BTNSHADOW)
- sytapp.BorderHighlight = GetSysColor(COLOR_BTNHIGHLIGHT)
- End If
- sytapp.GridLines = Not (mGrid.HeadingGridLines = sgGridLineNone)
- ElseIf sStyle = "Normal" Then
- OleTranslateColor mGrid.GridLinesColor, 0, sytapp.BorderColor
- sytapp.GridLines = Not (mGrid.GridLines = sgGridLineNone)
- End If
- End Function
-
-
- Public Function SetFontFromStyle(dvc As ISGDevice, sStyle As String) As Long
- Dim i%, byLett As Byte
- Dim clsFont As StdFont
- Dim lColor As Long
- Dim plf As LOGFONT
-
- Set clsFont = mGrid.Styles(sStyle).Font
-
- For i = 0 To 32
- plf.lfFaceName(i) = 0
- Next
-
- For i = 0 To Len(clsFont.Name) - 1
- byLett = Asc(Mid$(clsFont.Name, i + 1, 1))
- plf.lfFaceName(i) = byLett
- Next
- '1 point=20 twips
- plf.lfHeight = (clsFont.Size * 20) / dvc.TwipsPerPixelY
-
- plf.lfWeight = IIf(clsFont.Bold, 800, 400)
- plf.lfItalic = IIf(clsFont.Italic, 1, 0)
- plf.lfUnderline = IIf(clsFont.Underline, 1, 0)
- plf.lfStrikeOut = IIf(clsFont.Strikethrough, 1, 0)
-
- plf.lfCharSet = EASTEUROPE_CHARSET
-
- OleTranslateColor mGrid.Styles(sStyle).ForeColor, 0, lColor
-
- mhFont = CreateFontIndirect(plf)
-
- SetBkMode dvc.hdc, TRANSPARENT
- SetTextColor dvc.hdc, lColor
- mhFontOld = SelectObject(dvc.hdc, mhFont)
- SetFontFromStyle = mhFont
- End Function
-
- Public Function CalculateHeight(ByVal lHeight As Long) As Long
- Select Case miGridScaleMode
- Case 1
- CalculateHeight = lHeight
- Case 2
- Case 3
- CalculateHeight = lHeight * ConvertToPixelY
- End Select
- End Function
-
- Private Sub Class_Terminate()
- Set mcolPageColumns = Nothing
- Set mGrid = Nothing
- End Sub
-
- Public Property Get Grid() As SGGrid
- Set Grid = mGrid
- End Property
-
- Public Property Set Grid(ByVal vNewValue As SGGrid)
- Set mGrid = vNewValue
- SetScaleMode
- End Property
-
- Friend Function GetPageColumns(lPage As Long) As PageColumns
- Dim iCurrCols As Integer
-
- iCurrCols = (lPage - 1) Mod mcolPageColumns.Count
- Set GetPageColumns = mcolPageColumns(iCurrCols + 1)
- End Function
-
- Private Sub SetScaleMode()
-
- On Error Resume Next
-
- Err = 0
-
- miGridScaleMode = mGrid.Parent.ScaleMode
-
- If Err <> 0 Then miGridScaleMode = 3
-
- End Sub
-
-