home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axcool / axbutton.ctl < prev    next >
Encoding:
Text File  |  1998-10-26  |  34.4 KB  |  902 lines

  1. VERSION 5.00
  2. Begin VB.UserControl axCoolButton 
  3.    AutoRedraw      =   -1  'True
  4.    CanGetFocus     =   0   'False
  5.    ClientHeight    =   615
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   2115
  9.    DefaultCancel   =   -1  'True
  10.    ForwardFocus    =   -1  'True
  11.    ScaleHeight     =   41
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   141
  14.    ToolboxBitmap   =   "axButton.ctx":0000
  15. End
  16. Attribute VB_Name = "axCoolButton"
  17. Attribute VB_GlobalNameSpace = False
  18. Attribute VB_Creatable = True
  19. Attribute VB_PredeclaredId = False
  20. Attribute VB_Exposed = False
  21. Option Explicit
  22. 'Default Property Values:
  23. Const m_def_Style = 0
  24. Const m_def_DropDown = False
  25. Const m_def_MaskColor = vbButtonFace
  26. Const m_def_PictureAlign = 2
  27. Const m_def_Caption = ""
  28.  
  29. 'Enums
  30. Enum envbuPictureAlign
  31.     vbPicLeft = 0
  32.     vbPicRight = 1
  33.     vbPicTop = 2
  34.     vbPicBottom = 3
  35. End Enum
  36.  
  37. 'kdq 10/19/98 added new styles
  38. Enum vbuStyle
  39.     [Cool Button] = 0
  40.     [Toolbar Button] = 1
  41.     [Separator] = 2
  42.     [Toolbar Handle] = 3
  43.     [Standard Button] = 4
  44. End Enum
  45.  
  46. 'Property Variables:
  47. Dim m_Style As vbuStyle
  48. Dim m_DropDown As Boolean
  49. Dim m_MaskColor As OLE_COLOR
  50. Dim m_Picture As Picture
  51. Dim m_PictureAlign As envbuPictureAlign
  52. Dim m_Caption As String
  53. 'Event Declarations:
  54. Event MouseEnter()
  55. Attribute MouseEnter.VB_Description = "Fires when the mouse cursor enters the boundaries of the control."
  56. Event MouseExit()
  57. Attribute MouseExit.VB_Description = "Fires when the mouse leaves the boundaries of the control."
  58. Event DropDownClick()
  59. Attribute DropDownClick.VB_Description = "Fires whenever the Drop Down Button is Clicked."
  60. Event Click() 'MappingInfo=UserControl,UserControl,-1,Click
  61. Attribute Click.VB_Description = "Occurs when the user presses and then releases a mouse button over an object."
  62. Event DblClick() 'MappingInfo=UserControl,UserControl,-1,DblClick
  63. Attribute DblClick.VB_Description = "Occurs when the user presses and releases a mouse button and then presses and releases it again over an object."
  64. Event KeyDown(KeyCode As Integer, Shift As Integer) 'MappingInfo=UserControl,UserControl,-1,KeyDown
  65. Attribute KeyDown.VB_Description = "Occurs when the user presses a key while an object has the focus."
  66. Event KeyPress(KeyAscii As Integer) 'MappingInfo=UserControl,UserControl,-1,KeyPress
  67. Attribute KeyPress.VB_Description = "Occurs when the user presses and releases an ANSI key."
  68. Event KeyUp(KeyCode As Integer, Shift As Integer) 'MappingInfo=UserControl,UserControl,-1,KeyUp
  69. Attribute KeyUp.VB_Description = "Occurs when the user releases a key while an object has the focus."
  70. Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseDown
  71. Attribute MouseDown.VB_Description = "Occurs when the user presses the mouse button while an object has the focus."
  72. Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseMove
  73. Attribute MouseMove.VB_Description = "Occurs when the user moves the mouse."
  74. Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseUp
  75. Attribute MouseUp.VB_Description = "Occurs when the user releases the mouse button while an object has the focus."
  76.  
  77. Private mbButtonDown As Boolean
  78. Private mbMouseDown As Boolean
  79. Private miXOffset As Integer
  80. Private miYOffset As Integer
  81. Private mbHasFocus As Boolean
  82. Private mbMouseOver As Boolean
  83. Private mbDropDownPressed As Boolean
  84. Private miCurrentButtonPressed As Integer
  85. Private WithEvents ExitTimer As objTimer
  86. Attribute ExitTimer.VB_VarHelpID = -1
  87.  
  88. Private miClientWidth As Integer
  89. Private miClientHeight As Integer
  90. Private miClientTop As Integer
  91. Private miClientLeft As Integer
  92. Private m_ButtonFace As OLE_COLOR, m_ButtonLightShadow As OLE_COLOR
  93. Private m_ButtonDarkShadow As OLE_COLOR, m_ButtonHighlight As OLE_COLOR
  94. Private m_DownPicture As Picture
  95. Private m_FlatPicture As Picture, m_ShowFlatGrey As Boolean
  96.  
  97. Private Sub Leave()
  98.     mbMouseOver = False
  99.     
  100.     Set ExitTimer = Nothing
  101.     DrawButton
  102.     
  103.     RaiseEvent MouseExit
  104. End Sub
  105.  
  106. Private Function UnderMouse() As Boolean
  107.     Dim ptMouse As POINTAPI
  108.  
  109.     GetCursorPos ptMouse
  110.     If WindowFromPoint(ptMouse.x, ptMouse.y) = UserControl.hwnd Then
  111.         UnderMouse = True
  112.     Else
  113.         UnderMouse = False
  114.     End If
  115.  
  116. End Function
  117.  
  118. Private Sub DrawButton()
  119.     Dim iWidth As Integer
  120.     Dim iHeight As Integer
  121.     Dim iTextWidth As Integer, iTextHeight As Integer, iTextTop As Integer, iTextLeft As Integer
  122.     Dim iPicWidth As Integer, iPicHeight As Integer, iPicTop As Integer, iPicLeft As Integer
  123.     Dim iFocusOffset As Integer
  124.     Dim clsPaint As New PaintEffects
  125.     Dim iDownOffset As Integer
  126.     Dim udtRect As RECT
  127.     Dim udtTextRect As RECT
  128.     Dim lReturn As Long
  129.     Dim lArrowTop As Long
  130.     Dim lArrowLeft As Long
  131.     Dim picButton As Picture
  132.     
  133.     UserControl.Cls
  134.     If m_DropDown Then
  135.         iWidth = UserControl.ScaleWidth - 10
  136.         iHeight = UserControl.ScaleHeight
  137.     Else
  138.         iWidth = UserControl.ScaleWidth
  139.         iHeight = UserControl.ScaleHeight
  140.     End If
  141.     
  142.     'These client variable describe the area
  143.     'inside the button to draw the picture.
  144.     'You can think of these like page margins
  145.     'in a word processor
  146.     miClientWidth = iWidth - 6
  147.     miClientHeight = iHeight - 8
  148.     miClientTop = 3
  149.     miClientLeft = 3
  150.     
  151.     If (mbHasFocus Or UserControl.Ambient.DisplayAsDefault) And m_Style = [Standard Button] Then
  152.         iFocusOffset = 1
  153.         UserControl.Line (0, 0)-(UserControl.ScaleWidth - 1, UserControl.ScaleHeight - 1), vb3DDKShadow, B
  154.     Else
  155.         iFocusOffset = 0
  156.     End If
  157.     
  158.     udtRect.Top = iFocusOffset
  159.     udtRect.Left = iFocusOffset
  160.     udtRect.Right = iWidth - iFocusOffset - IIf(iFocusOffset = 1, 1, 0)
  161.     udtRect.Bottom = iHeight - iFocusOffset - IIf(iFocusOffset = 1, 1, 0)
  162.     
  163.     'kdq 10/19/98 added DrawShadowBox for new styles of buttons. Coolbutton should
  164.     'have thinner border than a regular button
  165.     Select Case m_Style
  166.     Case [Cool Button]
  167.         If mbMouseOver Or miCurrentButtonPressed > -1 Then
  168.             If mbButtonDown Then
  169.                 'Draw Button Down State
  170.                 DrawShadowBox udtRect, True, False
  171.                 'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH Or DFCS_PUSHED)
  172.                 iDownOffset = 1
  173.             Else
  174.                 'Draw Button Up State
  175.                 DrawShadowBox udtRect, False, False
  176.                 'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH)
  177.                 iDownOffset = 0
  178.             End If
  179.         End If
  180.  
  181.     Case [Toolbar Button]
  182.         If mbButtonDown Then
  183.             'Draw Button Down State
  184.             DrawShadowBox udtRect, True, False
  185.             'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH Or DFCS_PUSHED)
  186.             iDownOffset = 1
  187.         Else
  188.             'Draw Button Up State
  189.             DrawShadowBox udtRect, False, False
  190.             'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH)
  191.             iDownOffset = 0
  192.         End If
  193.     
  194.     Case [Standard Button]
  195.         If mbButtonDown Then
  196.             'Draw Button Down State
  197.             DrawShadowBox udtRect, True, True
  198.             'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH Or DFCS_PUSHED)
  199.             iDownOffset = 1
  200.         Else
  201.             'Draw Button Up State
  202.             DrawShadowBox udtRect, False, True
  203.             'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH)
  204.             iDownOffset = 0
  205.         End If
  206.     
  207.     Case [Separator]
  208.         Line (0, 0)-(ScaleWidth, ScaleHeight), BackColor, BF
  209.         DrawVLine ScaleWidth \ 2 - 1, 0, 2, ScaleHeight
  210.     
  211.     Case [Toolbar Handle]
  212.         Line (0, 0)-(ScaleWidth, ScaleHeight), BackColor, BF
  213.         DrawRaisedVLine ScaleWidth \ 2 - 4, 0, 3, ScaleHeight
  214.         DrawRaisedVLine ScaleWidth \ 2, 0, 3, ScaleHeight
  215.     
  216.     End Select
  217.     
  218.     'Draw the DropDown button
  219.     If m_DropDown Then
  220.         udtRect.Top = iFocusOffset
  221.         udtRect.Left = iWidth '- iFocusOffset
  222.         udtRect.Right = 10 - iFocusOffset
  223.         udtRect.Bottom = iHeight - iFocusOffset - IIf(iFocusOffset = 1, 1, 0)
  224.         Select Case m_Style
  225.         Case [Cool Button]   'Soft Button
  226.             If mbMouseOver Or miCurrentButtonPressed > -1 Then
  227.                 If mbDropDownPressed Then
  228.                     'Draw Button Down State
  229.                     DrawShadowBox udtRect, True, False
  230.                     'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH Or DFCS_PUSHED)
  231.                     iDownOffset = 0
  232.                 Else
  233.                     'Draw Button Up State
  234.                     DrawShadowBox udtRect, False, False
  235.                     'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH)
  236.                 End If
  237.             End If
  238.         Case [Toolbar Button], [Standard Button]       'toolbar, standard
  239.             If mbDropDownPressed Then
  240.                 'Draw Button Down State
  241.                 DrawShadowBox udtRect, True, True
  242.                 'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH Or DFCS_PUSHED)
  243.                 iDownOffset = 0
  244.             Else
  245.                 'Draw Button Up State
  246.                 DrawShadowBox udtRect, False, True
  247.                 'lReturn = DrawFrameControl(UserControl.hDC, udtRect, DFC_BUTTON, DFCS_BUTTONPUSH)
  248.             End If
  249.         End Select
  250.     End If
  251.  
  252.     'Draw the Dropdown arrow
  253.     If m_DropDown And (m_Style = [Cool Button] Or m_Style = [Toolbar Button] Or m_Style = [Standard Button]) Then
  254.         lArrowTop = (UserControl.ScaleHeight / 2) '- 2
  255.         lArrowLeft = iWidth + 1 - iFocusOffset
  256.         UserControl.Line ((lArrowLeft) + 1, lArrowTop)-((lArrowLeft) + 6, lArrowTop), vbBlack
  257.         UserControl.Line ((lArrowLeft) + 2, lArrowTop + 1)-((lArrowLeft) + 5, lArrowTop + 1), vbBlack
  258.         UserControl.Line ((lArrowLeft) + 3, lArrowTop + 2)-((lArrowLeft) + 4, lArrowTop + 2), vbBlack
  259.     End If
  260.     'Draw The Button Face
  261.  
  262.     'Get the Caption Width and Height
  263.     iTextWidth = UserControl.TextWidth(m_Caption)
  264.     iTextHeight = UserControl.TextHeight(m_Caption)
  265.  
  266.     'kdq 10/19/98
  267.     'figure out which picture to display
  268.     If mbMouseOver And mbMouseDown And Not m_DownPicture Is Nothing And m_Style = [Cool Button] Then
  269.       Set picButton = m_DownPicture
  270.     ElseIf Not mbMouseOver And Not m_FlatPicture Is Nothing And m_Style = [Cool Button] Then
  271.       Set picButton = m_FlatPicture
  272.     Else
  273.       Set picButton = m_Picture
  274.     End If
  275.     
  276.     If Not picButton Is Nothing And m_Caption > "" Then
  277.         'Get the Pictures Width and Height
  278.         iPicWidth = ScaleX(picButton.Width, vbHimetric, vbPixels)
  279.         iPicHeight = ScaleY(picButton.Height, vbHimetric, vbPixels)
  280.  
  281.         'Set locations for the Picture and the Caption
  282.         Select Case m_PictureAlign
  283.         Case vbPicLeft
  284.             iPicLeft = miClientLeft
  285.             iPicTop = miClientTop + (miClientHeight / 2) - (iPicHeight / 2) + 1
  286.             udtTextRect.Top = miClientTop
  287.             udtTextRect.Bottom = miClientTop + miClientHeight
  288.             udtTextRect.Left = miClientLeft + iPicWidth
  289.             udtTextRect.Right = miClientLeft + miClientWidth
  290.         Case vbPicRight
  291.             iPicLeft = miClientLeft + miClientWidth - iPicWidth
  292.             iPicTop = miClientTop + (miClientHeight / 2) - (iPicHeight / 2) + 1
  293.             udtTextRect.Top = miClientTop
  294.             udtTextRect.Bottom = miClientTop + miClientHeight
  295.             udtTextRect.Left = miClientLeft ' + iPicWidth
  296.             udtTextRect.Right = miClientLeft + miClientWidth - iPicWidth
  297.         Case vbPicTop
  298.             iPicLeft = miClientLeft + (miClientWidth / 2) - (iPicWidth / 2) + 1
  299.             iPicTop = miClientTop
  300.             udtTextRect.Top = miClientTop + iPicHeight + iPicTop
  301.             udtTextRect.Bottom = miClientTop + miClientHeight
  302.             udtTextRect.Left = miClientLeft
  303.             udtTextRect.Right = miClientLeft + miClientWidth
  304.         Case vbPicBottom
  305.             iPicLeft = miClientLeft + (miClientWidth / 2) - (iPicWidth / 2) + 1
  306.             iPicTop = miClientTop + miClientHeight - iPicHeight
  307.             udtTextRect.Top = miClientTop
  308.             udtTextRect.Bottom = miClientTop + miClientHeight - iPicHeight
  309.             udtTextRect.Left = miClientLeft
  310.             udtTextRect.Right = miClientLeft + miClientWidth
  311.         End Select
  312.     'kdq 10/19/98 center picture if no caption
  313.     ElseIf Not picButton Is Nothing And m_Caption = "" Then
  314.             'Get the Pictures Width and Height
  315.             iPicWidth = ScaleX(picButton.Width, vbHimetric, vbPixels)
  316.             iPicHeight = ScaleY(picButton.Height, vbHimetric, vbPixels)
  317.             iPicLeft = miClientLeft + (miClientWidth / 2) - (iPicWidth / 2)
  318.             iPicTop = miClientTop + (miClientHeight / 2) - (iPicHeight / 2) + 1
  319.             udtTextRect.Top = miClientTop
  320.             udtTextRect.Bottom = miClientTop + miClientHeight
  321.             udtTextRect.Left = miClientLeft
  322.             udtTextRect.Right = miClientLeft + miClientWidth
  323.     'kdq 10/19/98 center caption if not picture
  324.     ElseIf picButton Is Nothing And m_Caption > "" Then
  325.             udtTextRect.Top = miClientTop
  326.             udtTextRect.Bottom = miClientTop + miClientHeight
  327.             udtTextRect.Left = miClientLeft
  328.             udtTextRect.Right = miClientLeft + miClientWidth
  329.     End If
  330.  
  331.     '10/19/98 kdq the rect values were changed so Standard buttom displays correctly when it has focus
  332.     'Draw The Dotted Focus lines, but not for the soft button
  333.     If m_Style = [Standard Button] Then
  334.         If mbHasFocus Then
  335.             udtRect.Top = udtTextRect.Top    'iTextTop - 1
  336.             udtRect.Left = udtTextRect.Left + 1 'iTextLeft - 1
  337.             udtRect.Right = udtTextRect.Right - 1 'iTextLeft + iTextWidth + 1
  338.             udtRect.Bottom = udtTextRect.Bottom + 1 'iTextTop + iTextHeight + 1
  339.             lReturn = DrawFocusRect(UserControl.hdc, udtRect)
  340.         Else
  341.             UserControl.DrawWidth = 2
  342.             UserControl.Line (miClientLeft - 1, miClientTop - 1)-(miClientLeft + miClientWidth, miClientTop + miClientHeight), vb3DFace, B
  343.             UserControl.DrawWidth = 1
  344.         End If
  345.     End If
  346.  
  347.     'Draw the Picture
  348.     If Not picButton Is Nothing And (m_Style = [Cool Button] Or m_Style = [Toolbar Button] Or m_Style = [Standard Button]) Then
  349.         If UserControl.Enabled Then
  350.             'kdq 10/19/98 added GreyScaling for Coolbutton when mouse is not over it (user defined)
  351.             If m_Style = [Cool Button] And Not mbMouseOver And m_ShowFlatGrey Then
  352.                'clsPaint.PaintGreyScaleCornerStdPic UserControl.hdc, iPicLeft + iDownOffset, iPicTop + iDownOffset, iPicWidth, iPicHeight, picButton, 0, 0, m_MaskColor
  353.                clsPaint.PaintGreyScaleStdPic UserControl.hdc, iPicLeft + iDownOffset, iPicTop + iDownOffset, iPicWidth, iPicHeight, picButton, 0, 0
  354.             Else
  355.                'clsPaint.PaintTransparentStdPic UserControl.hdc, iPicLeft + iDownOffset, iPicTop + iDownOffset, iPicWidth, iPicHeight, picButton, 0, 0, m_MaskColor
  356.                clsPaint.PaintNormalStdPic UserControl.hdc, iPicLeft + iDownOffset, iPicTop + iDownOffset, iPicWidth, iPicHeight, picButton, 0, 0
  357.             End If
  358.         Else
  359.             clsPaint.PaintDisabledStdPic UserControl.hdc, iPicLeft + iDownOffset, iPicTop + iDownOffset, iPicWidth, iPicHeight, picButton, 0, 0, m_MaskColor
  360.         End If
  361.     End If
  362.  
  363.     'Print the caption on the button
  364.     If m_Style = [Cool Button] Or m_Style = [Toolbar Button] Or m_Style = [Standard Button] Then
  365.         udtTextRect.Top = udtTextRect.Top + iDownOffset ' + (udtTextRect.Top Mod 2)
  366.         udtTextRect.Left = udtTextRect.Left + iDownOffset ' + (udtTextRect.Left Mod 2)
  367.         udtTextRect.Bottom = udtTextRect.Bottom + iDownOffset
  368.         udtTextRect.Right = udtTextRect.Right + iDownOffset
  369.         If UserControl.Enabled Then
  370.             lReturn = DrawText(UserControl.hdc, m_Caption, Len(m_Caption), udtTextRect, DT_CENTER Or DT_SINGLELINE Or DT_VCENTER)
  371.         Else
  372.             UserControl.ForeColor = vbGrayText
  373.             lReturn = DrawText(UserControl.hdc, m_Caption, Len(m_Caption), udtTextRect, DT_CENTER Or DT_SINGLELINE Or DT_VCENTER)
  374.             UserControl.ForeColor = vbButtonText
  375.         End If
  376.     End If
  377.     
  378.     Refresh
  379.     Set clsPaint = Nothing
  380.     Set picButton = Nothing
  381. End Sub
  382.  
  383. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  384. 'MappingInfo=UserControl,UserControl,-1,BackColor
  385. Public Property Get BackColor() As OLE_COLOR
  386. Attribute BackColor.VB_Description = "Returns/sets the background color used to display text and graphics in an object."
  387. Attribute BackColor.VB_UserMemId = -501
  388.     BackColor = UserControl.BackColor
  389. End Property
  390.  
  391. Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
  392.     UserControl.BackColor() = New_BackColor
  393.     PropertyChanged "BackColor"
  394.     DrawButton
  395. End Property
  396.  
  397. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  398. 'MappingInfo=UserControl,UserControl,-1,ForeColor
  399. Public Property Get ForeColor() As OLE_COLOR
  400. Attribute ForeColor.VB_Description = "Returns/sets the foreground color used to display text and graphics in an object."
  401.     ForeColor = UserControl.ForeColor
  402. End Property
  403.  
  404. Public Property Let ForeColor(ByVal New_ForeColor As OLE_COLOR)
  405.     UserControl.ForeColor() = New_ForeColor
  406.     PropertyChanged "ForeColor"
  407.     DrawButton
  408. End Property
  409.  
  410. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  411. 'MappingInfo=UserControl,UserControl,-1,Enabled
  412. Public Property Get Enabled() As Boolean
  413. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  414.     Enabled = UserControl.Enabled
  415. End Property
  416.  
  417. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  418.     UserControl.Enabled() = New_Enabled
  419.     PropertyChanged "Enabled"
  420.     DrawButton
  421. End Property
  422.  
  423. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  424. 'MappingInfo=UserControl,UserControl,-1,Font
  425. Public Property Get Font() As Font
  426. Attribute Font.VB_Description = "Returns a Font object."
  427. Attribute Font.VB_UserMemId = -512
  428.     Set Font = UserControl.Font
  429. End Property
  430.  
  431. Public Property Set Font(ByVal New_Font As Font)
  432.     Set UserControl.Font = New_Font
  433.     PropertyChanged "Font"
  434.     DrawButton
  435. End Property
  436.  
  437.  
  438. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  439. 'MappingInfo=UserControl,UserControl,-1,Refresh
  440. Public Sub Refresh()
  441. Attribute Refresh.VB_Description = "Forces a complete repaint of a object."
  442.     UserControl.Refresh
  443. End Sub
  444.  
  445. Private Sub ExitTimer_Timer()
  446.     If Not UnderMouse Then Leave
  447. End Sub
  448.  
  449. Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
  450.     'kdq 10/19/98 only Click when control is a button
  451.     If m_Style <> [Separator] And m_Style <> [Toolbar Handle] Then RaiseEvent Click
  452. End Sub
  453.  
  454. Private Sub UserControl_AmbientChanged(PropertyName As String)
  455.     If PropertyName = "DisplayAsDefault" Then
  456.         DrawButton
  457.     End If
  458. End Sub
  459.  
  460. Private Sub UserControl_DblClick()
  461.     RaiseEvent DblClick
  462. End Sub
  463.  
  464. Private Sub UserControl_EnterFocus()
  465.     mbHasFocus = True
  466.     DrawButton
  467. End Sub
  468.  
  469. Private Sub UserControl_ExitFocus()
  470.     mbHasFocus = False
  471.     DrawButton
  472.     Refresh
  473. End Sub
  474.  
  475. Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
  476.     If KeyCode = 32 Then
  477.       miCurrentButtonPressed = 0
  478.       mbButtonDown = True
  479.       DrawButton
  480.     End If
  481.     RaiseEvent KeyDown(KeyCode, Shift)
  482. End Sub
  483.  
  484. Private Sub UserControl_KeyPress(KeyAscii As Integer)
  485.     RaiseEvent KeyPress(KeyAscii)
  486. End Sub
  487.  
  488. Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
  489.     If KeyCode = 32 Then
  490.       miCurrentButtonPressed = -1
  491.       mbButtonDown = False
  492.       DrawButton
  493.       'kdq 10/19/98 only Click when control is a button
  494.       If m_Style <> [Separator] And m_Style <> [Toolbar Handle] Then RaiseEvent Click
  495.     End If
  496.     RaiseEvent KeyUp(KeyCode, Shift)
  497. End Sub
  498.  
  499. Private Sub UserControl_LostFocus()
  500.     mbHasFocus = False
  501.     DrawButton
  502. End Sub
  503.  
  504. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  505.     If m_DropDown Then
  506.         If x > (UserControl.ScaleWidth - 11) Then
  507.             mbDropDownPressed = True
  508.             miCurrentButtonPressed = 1
  509.         Else
  510.             mbButtonDown = True
  511.             miCurrentButtonPressed = 0
  512.         End If
  513.     Else
  514.         mbButtonDown = True
  515.         miCurrentButtonPressed = 0
  516.     End If
  517.     mbMouseDown = True
  518.     DrawButton
  519.     RaiseEvent MouseDown(Button, Shift, x, y)
  520. End Sub
  521.  
  522. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  523.     If Button = 1 Then
  524.         If (x < 0 Or y < 0 Or x >= UserControl.ScaleWidth Or y >= UserControl.ScaleHeight) Then
  525.             If miCurrentButtonPressed = 0 Then
  526.                 mbButtonDown = False
  527.             Else
  528.                 mbDropDownPressed = False
  529.             End If
  530.             DrawButton
  531.         Else
  532.             If miCurrentButtonPressed = 0 Then
  533.                 mbButtonDown = True
  534.             Else
  535.                 mbDropDownPressed = True
  536.             End If
  537.             DrawButton
  538.         End If
  539.     End If
  540.     
  541.     If mbMouseOver Then
  542.         If Not UnderMouse Then
  543.             Leave
  544.         End If
  545.     Else
  546.         If UnderMouse Then
  547.             mbMouseOver = True
  548.             RaiseEvent MouseEnter
  549.             DrawButton
  550.             
  551.             'Set up the ExitTimer
  552.             Set ExitTimer = New objTimer
  553.             ExitTimer.Interval = 50
  554.             ExitTimer.Enabled = True
  555.         End If
  556.     End If
  557.     RaiseEvent MouseMove(Button, Shift, x, y)
  558. End Sub
  559.  
  560. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  561.     Dim bOverButton As Boolean
  562.     
  563.     RaiseEvent MouseUp(Button, Shift, x, y)
  564.     
  565.     'Check the position of the mouse when in was released.
  566.     'We only want to call the click events when the
  567.     'mouse was released over the button.
  568.     If (x < 0 Or y < 0 Or x >= UserControl.ScaleWidth Or y >= UserControl.ScaleHeight) Then
  569.         bOverButton = False
  570.     Else
  571.         bOverButton = True
  572.     End If
  573.     
  574.     If miCurrentButtonPressed = 1 Then
  575.         If bOverButton And x > (UserControl.ScaleWidth - 10) Then
  576.             RaiseEvent DropDownClick
  577.         End If
  578.     End If
  579.     mbButtonDown = False
  580.     mbDropDownPressed = False
  581.     mbMouseDown = False
  582.     DrawButton
  583.     If miCurrentButtonPressed = 0 Then
  584.         If bOverButton And x < (UserControl.ScaleWidth - 10) And m_DropDown Then
  585.                 'kdq 10/19/98 only Click when control is a button
  586.                 If m_Style <> [Separator] And m_Style <> [Toolbar Handle] Then RaiseEvent Click
  587.         'kdq 10/19/98 added this because click event wasnt firing for nondropdown buttons all the time
  588.         ElseIf bOverButton And Not m_DropDown Then
  589.                 'kdq 10/19/98 only Click when control is a button
  590.                 If m_Style <> [Separator] And m_Style <> [Toolbar Handle] Then RaiseEvent Click
  591.         End If
  592.     End If
  593.     miCurrentButtonPressed = -1
  594.     DrawButton
  595. End Sub
  596.  
  597.  
  598. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  599. 'MemberInfo=11,0,0,0
  600. Public Property Get Picture() As Picture
  601. Attribute Picture.VB_Description = "Image to be displayed on the button."
  602.     Set Picture = m_Picture
  603. End Property
  604.  
  605. Public Property Set Picture(ByVal New_Picture As Picture)
  606.     Set m_Picture = New_Picture
  607.     PropertyChanged "Picture"
  608.     DrawButton
  609. End Property
  610.  
  611. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  612. 'MemberInfo=7,0,0,0
  613. Public Property Get PictureAlign() As envbuPictureAlign
  614. Attribute PictureAlign.VB_Description = "Specifies alignment of the picture property."
  615.     PictureAlign = m_PictureAlign
  616. End Property
  617.  
  618. Public Property Let PictureAlign(ByVal New_PictureAlign As envbuPictureAlign)
  619.     m_PictureAlign = New_PictureAlign
  620.     PropertyChanged "PictureAlign"
  621.     DrawButton
  622. End Property
  623.  
  624. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  625. 'MemberInfo=13,0,0,
  626. Public Property Get Caption() As String
  627. Attribute Caption.VB_Description = "Text displayed on the face of the button."
  628. Attribute Caption.VB_UserMemId = -518
  629.     Caption = m_Caption
  630. End Property
  631.  
  632. Public Property Let Caption(ByVal New_Caption As String)
  633.     m_Caption = New_Caption
  634.     PropertyChanged "Caption"
  635.     SetAccessKey
  636.     DrawButton
  637. End Property
  638. Private Sub SetAccessKey()
  639.     Dim iPos As Integer
  640.     Dim sChar As String
  641.     
  642.     iPos = InStr(1, m_Caption, "&")
  643.     If iPos > 0 Then
  644.         sChar = Mid$(m_Caption, iPos + 1, 1)
  645.         If sChar <> "&" Then
  646.             UserControl.AccessKeys = LCase(sChar)
  647.         End If
  648.     End If
  649. End Sub
  650. 'Initialize Properties for User Control
  651. Private Sub UserControl_InitProperties()
  652.     Set UserControl.Font = Ambient.Font
  653.     Set m_Picture = LoadPicture("")
  654.     m_PictureAlign = m_def_PictureAlign
  655.     m_Caption = m_def_Caption
  656.     m_MaskColor = m_def_MaskColor
  657.     m_Style = m_def_Style
  658.     m_DropDown = m_def_DropDown
  659.     m_ButtonFace = vbButtonFace
  660.     m_ButtonLightShadow = vbButtonShadow
  661.     m_ButtonDarkShadow = vb3DDKShadow
  662.     m_ButtonHighlight = vb3DHighlight
  663.     m_ShowFlatGrey = False
  664.     
  665.     miCurrentButtonPressed = -1
  666.     mbMouseOver = False
  667.     mbButtonDown = False
  668.     mbMouseDown = False
  669.     mbHasFocus = False
  670.     mbDropDownPressed = False
  671. End Sub
  672.  
  673. Private Sub UserControl_Paint()
  674.     DrawButton
  675. End Sub
  676.  
  677. 'Load property values from storage
  678. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  679.  
  680.     UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
  681.     UserControl.ForeColor = PropBag.ReadProperty("ForeColor", &H80000012)
  682.     UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
  683.     Set UserControl.Font = PropBag.ReadProperty("Font", Ambient.Font)
  684. '    UserControl.BackStyle = PropBag.ReadProperty("BackStyle", 1)
  685. '    UserControl.BorderStyle = PropBag.ReadProperty("BorderStyle", 0)
  686.     Set m_Picture = PropBag.ReadProperty("Picture", Nothing)
  687.     Set m_DownPicture = PropBag.ReadProperty("DownPicture", Nothing)
  688.     Set m_FlatPicture = PropBag.ReadProperty("FlatPicture", Nothing)
  689.     m_PictureAlign = PropBag.ReadProperty("PictureAlign", m_def_PictureAlign)
  690.     m_Caption = PropBag.ReadProperty("Caption", m_def_Caption)
  691.     m_MaskColor = PropBag.ReadProperty("MaskColor", &HC0C0C0)
  692.     m_Style = PropBag.ReadProperty("Style", m_def_Style)
  693.     m_DropDown = PropBag.ReadProperty("DropDown", m_def_DropDown)
  694.     m_ButtonDarkShadow = PropBag.ReadProperty("ColorDarkShadow", vb3DDKShadow)
  695.     m_ButtonLightShadow = PropBag.ReadProperty("ColorLightShadow", vbButtonShadow)
  696.     m_ButtonHighlight = PropBag.ReadProperty("ColorHighlight", vb3DHighlight)
  697.     m_ShowFlatGrey = PropBag.ReadProperty("ShowFlatGrey", False)
  698.     SetAccessKey
  699.     miCurrentButtonPressed = -1
  700.     DrawButton
  701. End Sub
  702.  
  703. Private Sub UserControl_Resize()
  704.     DrawButton
  705. End Sub
  706.  
  707. 'Write property values to storage
  708. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  709.  
  710.     Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
  711.     Call PropBag.WriteProperty("ForeColor", UserControl.ForeColor, &H80000012)
  712.     Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
  713.     Call PropBag.WriteProperty("Font", UserControl.Font, Ambient.Font)
  714. '    Call PropBag.WriteProperty("BackStyle", UserControl.BackStyle, 1)
  715. '    Call PropBag.WriteProperty("BorderStyle", UserControl.BorderStyle, 0)
  716.     Call PropBag.WriteProperty("Picture", m_Picture, Nothing)
  717.     Call PropBag.WriteProperty("DownPicture", m_DownPicture, Nothing)
  718.     Call PropBag.WriteProperty("FlatPicture", m_FlatPicture, Nothing)
  719.     Call PropBag.WriteProperty("PictureAlign", m_PictureAlign, m_def_PictureAlign)
  720.     Call PropBag.WriteProperty("Caption", m_Caption, m_def_Caption)
  721.     Call PropBag.WriteProperty("MaskColor", m_MaskColor, &HC0C0C0)
  722.     Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
  723.     Call PropBag.WriteProperty("DropDown", m_DropDown, m_def_DropDown)
  724.     Call PropBag.WriteProperty("ColorDarkShadow", m_ButtonDarkShadow, vb3DDKShadow)
  725.     Call PropBag.WriteProperty("ColorLightShadow", m_ButtonLightShadow, vbButtonShadow)
  726.     Call PropBag.WriteProperty("ColorHighlight", m_ButtonHighlight, vb3DHighlight)
  727.     Call PropBag.WriteProperty("ShowFlatGrey", m_ShowFlatGrey, False)
  728. End Sub
  729.  
  730. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  731. 'MemberInfo=10,0,0,0
  732. Public Property Get MaskColor() As OLE_COLOR
  733.     MaskColor = m_MaskColor
  734. End Property
  735.  
  736. Public Property Let MaskColor(ByVal New_MaskColor As OLE_COLOR)
  737.     m_MaskColor = New_MaskColor
  738.     PropertyChanged "MaskColor"
  739.     DrawButton
  740. End Property
  741.  
  742. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  743. 'MemberInfo=7,0,0,0
  744. Public Property Get Style() As vbuStyle
  745. Attribute Style.VB_Description = "Gets/Sets the style of the button"
  746.     Style = m_Style
  747. End Property
  748.  
  749. Public Property Let Style(ByVal New_Style As vbuStyle)
  750.     m_Style = New_Style
  751.     PropertyChanged "Style"
  752.     DrawButton
  753. End Property
  754.  
  755. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  756. 'MemberInfo=0,0,0,False
  757. Public Property Get DropDown() As Boolean
  758. Attribute DropDown.VB_Description = "Determines whether or not to display the Drop Down Button."
  759.     DropDown = m_DropDown
  760. End Property
  761.  
  762. Public Property Let DropDown(ByVal New_DropDown As Boolean)
  763.     m_DropDown = New_DropDown
  764.     PropertyChanged "DropDown"
  765.     DrawButton
  766. End Property
  767.  
  768. 'kdq 10/19/98 added for seperator/handle
  769. Private Sub DrawVLine(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single)
  770.     Line (x + 1, y)-(x + 1, y + cy), m_ButtonHighlight
  771.     Line (x, y)-(x, y + cy), m_ButtonLightShadow
  772. End Sub
  773.  
  774. 'kdq 10/19/98 added for seperator/handle
  775. Private Sub DrawRaisedVLine(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single)
  776.     Line (x, y)-(x, y + cy), m_ButtonHighlight
  777.     Line (x + 1, y)-(x + 1, y + cy), m_ButtonHighlight
  778.     Line (x + 2, y)-(x + 2, y + cy), m_ButtonHighlight
  779.     Line (x, y + 1)-(x, y + cy), m_ButtonLightShadow
  780.     Line (x + 1, y + 1)-(x + 1, y + cy), m_ButtonLightShadow
  781.     Line (x + 2, y + 1)-(x + 2, y + cy), m_ButtonLightShadow
  782.     Line (x, y)-(x, y + cy - 1), m_ButtonHighlight
  783.     Line (x + 1, y + 1)-(x + 1, y + cy - 1), m_ButtonFace
  784. End Sub
  785.  
  786. 'kdq 10/19/98 added to make thinner border for CoolButton
  787. Private Sub DrawShadowBox(RectSize As RECT, ByVal Pressed As Boolean, ByVal DKShadow As Boolean)
  788.     Dim x As Integer, y As Integer, cx As Integer, cy As Integer
  789.     x = RectSize.Left
  790.     y = RectSize.Top
  791.     cx = RectSize.Right
  792.     cy = RectSize.Bottom
  793.     
  794.     If DKShadow Then
  795.         If Pressed Then
  796.             Line (x, y)-(x + cx - 1, y), m_ButtonDarkShadow
  797.             Line (x, y)-(x, y + cy - 1), m_ButtonDarkShadow
  798.             Line (x + 1, y + 1)-(x + cx - 2, y + 1), m_ButtonLightShadow
  799.             Line (x + 1, y + 1)-(x + 1, y + cy - 2), m_ButtonLightShadow
  800.             Line (x + cx - 1, y)-(x + cx - 1, y + cy), m_ButtonHighlight
  801.             Line (x, y + cy - 1)-(x + cx, y + cy - 1), m_ButtonHighlight
  802.         Else
  803.             Line (x, y)-(x + cx - 1, y), m_ButtonHighlight
  804.             Line (x, y)-(x, y + cy - 1), m_ButtonHighlight
  805.             Line (x + cx - 2, y + 1)-(x + cx - 2, y + cy - 1), m_ButtonLightShadow
  806.             Line (x + 1, y + cy - 2)-(x + cx - 1, y + cy - 2), m_ButtonLightShadow
  807.             Line (x + cx - 1, y)-(x + cx - 1, y + cy), m_ButtonDarkShadow
  808.             Line (x, y + cy - 1)-(x + cx, y + cy - 1), m_ButtonDarkShadow
  809.         End If
  810.     Else
  811.         Dim Color1 As Long
  812.         Dim Color2 As Long
  813.         If Pressed Then
  814.             Color1 = m_ButtonLightShadow
  815.             Color2 = m_ButtonHighlight
  816.         Else
  817.             Color1 = m_ButtonHighlight
  818.             Color2 = m_ButtonLightShadow
  819.         End If
  820.         Line (x, y)-(x + cx - 1, y), Color1
  821.         Line (x, y)-(x, y + cy - 1), Color1
  822.         Line (x + cx - 1, y)-(x + cx - 1, y + cy), Color2
  823.         Line (x, y + cy - 1)-(x + cx, y + cy - 1), Color2
  824.     End If
  825. End Sub
  826.  
  827. Public Property Get ColorLightShadow() As OLE_COLOR
  828.     ColorLightShadow = m_ButtonLightShadow
  829. End Property
  830.  
  831. Public Property Let ColorLightShadow(ByVal New_Value As OLE_COLOR)
  832.     If Not (m_ButtonLightShadow = New_Value) Then
  833.         m_ButtonLightShadow = New_Value
  834.         DrawButton
  835.     End If
  836.     PropertyChanged "ColorLightShadow"
  837. End Property
  838.  
  839. 'kdq 10/19/98
  840. Public Property Get ColorDarkShadow() As OLE_COLOR
  841.     ColorDarkShadow = m_ButtonDarkShadow
  842. End Property
  843.  
  844. Public Property Let ColorDarkShadow(ByVal New_Value As OLE_COLOR)
  845.     If Not (m_ButtonDarkShadow = New_Value) Then
  846.         m_ButtonDarkShadow = New_Value
  847.         DrawButton
  848.     End If
  849.     PropertyChanged "ColorDarkShadow"
  850. End Property
  851.  
  852. 'kdq 10/19/98
  853. Public Property Get ColorHighlight() As OLE_COLOR
  854.     ColorHighlight = m_ButtonHighlight
  855. End Property
  856.  
  857. Public Property Let ColorHighlight(ByVal New_Value As OLE_COLOR)
  858.     If Not (m_ButtonHighlight = New_Value) Then
  859.         m_ButtonHighlight = New_Value
  860.         DrawButton
  861.     End If
  862.     PropertyChanged "ColorHighlight"
  863. End Property
  864.  
  865. 'kdq 10/19/98
  866. Public Sub ShowAbout()
  867. Attribute ShowAbout.VB_UserMemId = -552
  868.     frmAbout.Show vbModal
  869. End Sub
  870.  
  871. 'kdq 10/19/98 picture to display when mousedown on cool button
  872. Public Property Get DownPicture() As Picture
  873.     Set DownPicture = m_DownPicture
  874. End Property
  875.  
  876. Public Property Set DownPicture(ByVal New_DownPicture As Picture)
  877.     Set m_DownPicture = New_DownPicture
  878.     PropertyChanged "DownPicture"
  879. End Property
  880.  
  881. 'kdq 10/19/98 picture to display when mouse is not over button on cool button
  882. Public Property Get FlatPicture() As Picture
  883.     Set FlatPicture = m_FlatPicture
  884. End Property
  885.  
  886. Public Property Set FlatPicture(ByVal New_FlatPicture As Picture)
  887.     Set m_FlatPicture = New_FlatPicture
  888.     DrawButton
  889.     PropertyChanged "FlatPicture"
  890. End Property
  891.  
  892. 'kdq 10/19/98 display picture as greyscale when mouse is not over Cool Button
  893. Public Property Get ShowFlatGrey() As Boolean
  894.     ShowFlatGrey = m_ShowFlatGrey
  895. End Property
  896.  
  897. Public Property Let ShowFlatGrey(ByVal New_Value As Boolean)
  898.     m_ShowFlatGrey = New_Value
  899.     PropertyChanged "DropDown"
  900.     DrawButton
  901. End Property
  902.