Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
8.6 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Sizer"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. 'Usage:
  16. '
  17. 'Private Sub Form_Activate()
  18. ' p_SetSizingInfo
  19. 'End Sub
  20. '
  21. 'Private Sub Form_Resize()
  22. ' p_clsSizer.Resize
  23. 'End Sub
  24. '
  25. 'Private Sub p_SetSizingInfo()
  26. '
  27. ' ' treTaxonomy.Height - Me.Height = constant
  28. ' ' treTaxonomy.Top, Left and Width do not change
  29. ' p_clsSizer.AddControl treTaxonomy
  30. ' Set p_clsSizer.ReferenceControl(DIM_HEIGHT_E) = Me
  31. ' ' treTaxonmy.Width / Me.Width = constant
  32. ' Set p_clsSizer.ReferenceControl(DIM_WIDTH_E) = Me
  33. ' p_clsSizer.Operation(DIM_WIDTH_E) = OP_MULTIPLY_E
  34. '
  35. ' ' cmdCreateGroup.Top - treTaxonomy.Bottom = constaant
  36. ' p_clsSizer.AddControl cmdCreateGroup
  37. ' Set p_clsSizer.ReferenceControl(DIM_TOP_E) = treTaxonomy
  38. ' p_clsSizer.ReferenceDimension(DIM_TOP_E) = DIM_BOTTOM_E
  39. '
  40. ' ' cmdCreateLeaf.Top - cmdCreateGroup.Top = constant
  41. ' p_clsSizer.AddControl cmdCreateLeaf
  42. ' Set p_clsSizer.ReferenceControl(DIM_TOP_E) = cmdCreateGroup
  43. '
  44. ' ' txtTitle.Left - lblTitle.Left = constant
  45. ' p_clsSizer.AddControl txtTitle
  46. ' Set p_clsSizer.ReferenceControl(DIM_LEFT_E) = lblTitle
  47. ' ' txtTitle.Right - Me.Width = constant
  48. ' ' Do not use Me.Right, since Me contains txtTitle.
  49. ' ' The containing control's Left and Top are to be ignored.
  50. ' ' The contained control assumes that the containing control's Left and Top are 0.
  51. ' Set p_clsSizer.ReferenceControl(DIM_RIGHT_E) = Me
  52. ' p_clsSizer.ReferenceDimension(DIM_RIGHT_E) = DIM_WIDTH_E
  53. '
  54. ' ' cmdNavigateLink.Left - txtTitle.Right = constant
  55. ' p_clsSizer.AddControl cmdNavigateLink
  56. ' Set p_clsSizer.ReferenceControl(DIM_LEFT_E) = txtTitle
  57. ' p_clsSizer.ReferenceDimension(DIM_LEFT_E) = DIM_RIGHT_E
  58. '
  59. ' ' chkServer.Left / fraSKU.Width = constant
  60. ' ' Here fraSKU is the containing control.
  61. ' ' Hence we use DIM_WIDTH_E instead of DIM_RIGHT_E.
  62. ' p_clsSizer.AddControl chkServer
  63. ' Set p_clsSizer.ReferenceControl(DIM_LEFT_E) = fraSKU
  64. ' p_clsSizer.ReferenceDimension(DIM_LEFT_E) = DIM_WIDTH_E
  65. ' p_clsSizer.Operation(DIM_LEFT_E) = OP_MULTIPLY_E
  66. '
  67. 'End Sub
  68. Private Const COUNT_CHUNK_C As Long = 10
  69. Private Type RESTRICTION_S
  70. ReferenceControl As Object
  71. ReferenceDimension As DIMENSION_E
  72. Operation As OPERATION_E
  73. Amount As Single
  74. End Type
  75. Private Type SIZING_INFO_S
  76. Control As Object
  77. Restriction(DIM_MAX_E) As RESTRICTION_S
  78. End Type
  79. ' We ignore index 0 and go from 1 to p_Count
  80. Private p_SizingInfo() As SIZING_INFO_S
  81. Private p_Count As Long
  82. Private p_Index As Long
  83. Private Sub Class_Initialize()
  84. p_Count = COUNT_CHUNK_C
  85. ReDim p_SizingInfo(p_Count)
  86. p_Index = 1
  87. End Sub
  88. Public Sub AddControl(ByVal i_ctr As Object)
  89. Dim intIndex As Long
  90. If (Not p_SizingInfo(p_Index).Control Is Nothing) Then
  91. p_MoveNext
  92. End If
  93. With p_SizingInfo(p_Index)
  94. Set .Control = i_ctr
  95. For intIndex = DIM_MIN_E To DIM_MAX_E
  96. With .Restriction(intIndex)
  97. Set .ReferenceControl = Nothing
  98. End With
  99. Next
  100. End With
  101. End Sub
  102. Public Property Set ReferenceControl(ByVal i_dim As DIMENSION_E, ByVal i_ctr As Object)
  103. Dim ctr As Object
  104. With p_SizingInfo(p_Index)
  105. Set ctr = .Control
  106. With .Restriction(i_dim)
  107. Set .ReferenceControl = i_ctr
  108. .ReferenceDimension = i_dim
  109. .Operation = OP_ADD_E
  110. .Amount = p_CalculateAmount(ctr, i_ctr, i_dim, i_dim, OP_ADD_E)
  111. End With
  112. End With
  113. End Property
  114. Public Property Let ReferenceDimension( _
  115. ByVal i_dim As DIMENSION_E, _
  116. ByVal i_dimRef As DIMENSION_E _
  117. )
  118. Dim ctr As Object
  119. With p_SizingInfo(p_Index)
  120. Set ctr = .Control
  121. With .Restriction(i_dim)
  122. .ReferenceDimension = i_dimRef
  123. .Amount = p_CalculateAmount(ctr, .ReferenceControl, i_dim, i_dimRef, .Operation)
  124. End With
  125. End With
  126. End Property
  127. Public Property Let Operation(ByVal i_dim As DIMENSION_E, ByVal i_op As OPERATION_E)
  128. Dim ctr As Object
  129. With p_SizingInfo(p_Index)
  130. Set ctr = .Control
  131. With .Restriction(i_dim)
  132. .Operation = i_op
  133. .Amount = p_CalculateAmount(ctr, .ReferenceControl, _
  134. i_dim, .ReferenceDimension, i_op)
  135. End With
  136. End With
  137. End Property
  138. Public Property Let Amount(ByVal i_dim As DIMENSION_E, ByVal i_sngAmount As Single)
  139. p_SizingInfo(p_Index).Restriction(i_dim).Amount = i_sngAmount
  140. End Property
  141. Public Sub Resize()
  142. Dim intIndex As Long
  143. Dim dimension As DIMENSION_E
  144. Dim ctr As Object
  145. For intIndex = 1 To p_Count
  146. With p_SizingInfo(intIndex)
  147. Set ctr = .Control
  148. For dimension = DIM_MIN_E To DIM_MAX_E
  149. With .Restriction(dimension)
  150. p_SetDimension ctr, .ReferenceControl, dimension, _
  151. .ReferenceDimension, .Operation, .Amount
  152. End With
  153. Next
  154. End With
  155. Next
  156. End Sub
  157. Private Sub p_MoveNext()
  158. If (p_Index = p_Count) Then
  159. p_Count = p_Count + COUNT_CHUNK_C
  160. ReDim Preserve p_SizingInfo(p_Count)
  161. End If
  162. p_Index = p_Index + 1
  163. End Sub
  164. Private Function p_CalculateAmount( _
  165. ByVal i_ctr As Object, _
  166. ByVal i_ctrRef As Object, _
  167. ByVal i_dim As DIMENSION_E, _
  168. ByVal i_dimRef As DIMENSION_E, _
  169. ByVal i_op As OPERATION_E _
  170. ) As Single
  171. Dim sngAmount As Single
  172. Dim sngAmountRef As Single
  173. sngAmount = p_GetDimensionAmount(i_ctr, i_dim)
  174. sngAmountRef = p_GetDimensionAmount(i_ctrRef, i_dimRef)
  175. If (i_op = OP_ADD_E) Then
  176. p_CalculateAmount = sngAmount - sngAmountRef
  177. ElseIf (i_op = OP_MULTIPLY_E) Then
  178. p_CalculateAmount = sngAmount / sngAmountRef
  179. End If
  180. End Function
  181. Private Function p_GetDimensionAmount( _
  182. ByVal i_ctrRef As Object, _
  183. ByVal i_dimRef As DIMENSION_E _
  184. ) As Single
  185. Select Case i_dimRef
  186. Case DIM_TOP_E
  187. p_GetDimensionAmount = i_ctrRef.Top
  188. Case DIM_LEFT_E
  189. p_GetDimensionAmount = i_ctrRef.Left
  190. Case DIM_HEIGHT_E
  191. p_GetDimensionAmount = i_ctrRef.Height
  192. Case DIM_WIDTH_E
  193. p_GetDimensionAmount = i_ctrRef.Width
  194. Case DIM_BOTTOM_E
  195. p_GetDimensionAmount = i_ctrRef.Top + i_ctrRef.Height
  196. Case DIM_RIGHT_E
  197. p_GetDimensionAmount = i_ctrRef.Left + i_ctrRef.Width
  198. End Select
  199. End Function
  200. Private Sub p_SetDimension( _
  201. ByVal i_ctr As Object, _
  202. ByVal i_ctrRef As Object, _
  203. ByVal i_dim As DIMENSION_E, _
  204. ByVal i_dimRef As DIMENSION_E, _
  205. ByVal i_op As OPERATION_E, _
  206. ByVal i_sngAmount As Single _
  207. )
  208. Dim sngAmountRef As Single
  209. Dim sngAmountNew As Single
  210. If (i_ctrRef Is Nothing) Then
  211. Exit Sub
  212. End If
  213. sngAmountRef = p_GetDimensionAmount(i_ctrRef, i_dimRef)
  214. If (i_op = OP_ADD_E) Then
  215. sngAmountNew = p_Positive(sngAmountRef + i_sngAmount)
  216. Select Case i_dim
  217. Case DIM_TOP_E
  218. i_ctr.Top = sngAmountNew
  219. Case DIM_LEFT_E
  220. i_ctr.Left = sngAmountNew
  221. Case DIM_HEIGHT_E
  222. i_ctr.Height = sngAmountNew
  223. Case DIM_WIDTH_E
  224. i_ctr.Width = sngAmountNew
  225. Case DIM_BOTTOM_E
  226. i_ctr.Height = p_Positive(sngAmountNew - i_ctr.Top)
  227. Case DIM_RIGHT_E
  228. i_ctr.Width = p_Positive(sngAmountNew - i_ctr.Left)
  229. End Select
  230. ElseIf (i_op = OP_MULTIPLY_E) Then
  231. sngAmountNew = p_Positive(sngAmountRef * i_sngAmount)
  232. Select Case i_dim
  233. Case DIM_TOP_E
  234. i_ctr.Top = sngAmountNew
  235. Case DIM_LEFT_E
  236. i_ctr.Left = sngAmountNew
  237. Case DIM_HEIGHT_E
  238. i_ctr.Height = sngAmountNew
  239. Case DIM_WIDTH_E
  240. i_ctr.Width = sngAmountNew
  241. Case DIM_BOTTOM_E
  242. i_ctr.Height = p_Positive(sngAmountNew - i_ctr.Top)
  243. Case DIM_RIGHT_E
  244. i_ctr.Width = p_Positive(sngAmountNew - i_ctr.Left)
  245. End Select
  246. End If
  247. End Sub
  248. Private Function p_Positive(i_sng As Single) As Single
  249. If (i_sng < 0) Then
  250. p_Positive = 0
  251. Else
  252. p_Positive = i_sng
  253. End If
  254. End Function