home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Sudoku_5_12102622192008.psc / Cell.ctl < prev    next >
Text File  |  2007-07-20  |  16KB  |  522 lines

  1. VERSION 5.00
  2. Begin VB.UserControl Cell 
  3.    CanGetFocus     =   0   'False
  4.    ClientHeight    =   735
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   720
  8.    ClipBehavior    =   0  'None
  9.    ClipControls    =   0   'False
  10.    HasDC           =   0   'False
  11.    Picture         =   "Cell.ctx":0000
  12.    ScaleHeight     =   735
  13.    ScaleWidth      =   720
  14.    ToolboxBitmap   =   "Cell.ctx":2376
  15.    Begin VB.Timer tmrHiLight 
  16.       Enabled         =   0   'False
  17.       Interval        =   10
  18.       Left            =   900
  19.       Top             =   120
  20.    End
  21.    Begin VB.Image imgLib 
  22.       Height          =   720
  23.       Index           =   2
  24.       Left            =   1650
  25.       Picture         =   "Cell.ctx":2688
  26.       Top             =   1155
  27.       Width           =   720
  28.    End
  29.    Begin VB.Image imgLib 
  30.       Height          =   720
  31.       Index           =   1
  32.       Left            =   855
  33.       Picture         =   "Cell.ctx":49B4
  34.       Top             =   1140
  35.       Width           =   720
  36.    End
  37.    Begin VB.Image imgLib 
  38.       Height          =   720
  39.       Index           =   0
  40.       Left            =   60
  41.       Picture         =   "Cell.ctx":6CA8
  42.       Top             =   1140
  43.       Width           =   720
  44.    End
  45.    Begin VB.Label lblNote 
  46.       Alignment       =   2  'Center
  47.       BackColor       =   &H00000000&
  48.       BackStyle       =   0  'Transparent
  49.       BeginProperty Font 
  50.          Name            =   "Georgia"
  51.          Size            =   9
  52.          Charset         =   0
  53.          Weight          =   700
  54.          Underline       =   0   'False
  55.          Italic          =   -1  'True
  56.          Strikethrough   =   0   'False
  57.       EndProperty
  58.       ForeColor       =   &H00404040&
  59.       Height          =   260
  60.       Index           =   4
  61.       Left            =   570
  62.       TabIndex        =   4
  63.       Top             =   30
  64.       Visible         =   0   'False
  65.       Width           =   120
  66.    End
  67.    Begin VB.Label lblNote 
  68.       Alignment       =   2  'Center
  69.       BackColor       =   &H00000000&
  70.       BackStyle       =   0  'Transparent
  71.       BeginProperty Font 
  72.          Name            =   "Georgia"
  73.          Size            =   9
  74.          Charset         =   0
  75.          Weight          =   700
  76.          Underline       =   0   'False
  77.          Italic          =   -1  'True
  78.          Strikethrough   =   0   'False
  79.       EndProperty
  80.       ForeColor       =   &H00404040&
  81.       Height          =   260
  82.       Index           =   3
  83.       Left            =   435
  84.       TabIndex        =   3
  85.       Top             =   30
  86.       Visible         =   0   'False
  87.       Width           =   120
  88.    End
  89.    Begin VB.Label lblNote 
  90.       Alignment       =   2  'Center
  91.       BackColor       =   &H00000000&
  92.       BackStyle       =   0  'Transparent
  93.       BeginProperty Font 
  94.          Name            =   "Georgia"
  95.          Size            =   9
  96.          Charset         =   0
  97.          Weight          =   700
  98.          Underline       =   0   'False
  99.          Italic          =   -1  'True
  100.          Strikethrough   =   0   'False
  101.       EndProperty
  102.       ForeColor       =   &H00404040&
  103.       Height          =   260
  104.       Index           =   2
  105.       Left            =   300
  106.       TabIndex        =   2
  107.       Top             =   30
  108.       Visible         =   0   'False
  109.       Width           =   120
  110.    End
  111.    Begin VB.Label lblNote 
  112.       Alignment       =   2  'Center
  113.       BackColor       =   &H00000000&
  114.       BackStyle       =   0  'Transparent
  115.       BeginProperty Font 
  116.          Name            =   "Georgia"
  117.          Size            =   9
  118.          Charset         =   0
  119.          Weight          =   700
  120.          Underline       =   0   'False
  121.          Italic          =   -1  'True
  122.          Strikethrough   =   0   'False
  123.       EndProperty
  124.       ForeColor       =   &H00404040&
  125.       Height          =   260
  126.       Index           =   1
  127.       Left            =   165
  128.       TabIndex        =   1
  129.       Top             =   30
  130.       Visible         =   0   'False
  131.       Width           =   120
  132.    End
  133.    Begin VB.Label lblNote 
  134.       Alignment       =   2  'Center
  135.       BackColor       =   &H00000000&
  136.       BackStyle       =   0  'Transparent
  137.       BeginProperty Font 
  138.          Name            =   "Georgia"
  139.          Size            =   9
  140.          Charset         =   0
  141.          Weight          =   700
  142.          Underline       =   0   'False
  143.          Italic          =   -1  'True
  144.          Strikethrough   =   0   'False
  145.       EndProperty
  146.       ForeColor       =   &H00404040&
  147.       Height          =   260
  148.       Index           =   0
  149.       Left            =   30
  150.       TabIndex        =   0
  151.       Top             =   30
  152.       Visible         =   0   'False
  153.       Width           =   120
  154.    End
  155.    Begin VB.Label lblNumber 
  156.       Alignment       =   2  'Center
  157.       BackStyle       =   0  'Transparent
  158.       Caption         =   "8"
  159.       BeginProperty Font 
  160.          Name            =   "Harrington"
  161.          Size            =   27.75
  162.          Charset         =   0
  163.          Weight          =   700
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       ForeColor       =   &H0000FFFF&
  169.       Height          =   685
  170.       Index           =   1
  171.       Left            =   30
  172.       TabIndex        =   6
  173.       Top             =   45
  174.       Width           =   615
  175.    End
  176.    Begin VB.Label lblNumber 
  177.       Alignment       =   2  'Center
  178.       BackStyle       =   0  'Transparent
  179.       Caption         =   "8"
  180.       BeginProperty Font 
  181.          Name            =   "Harrington"
  182.          Size            =   27.75
  183.          Charset         =   0
  184.          Weight          =   700
  185.          Underline       =   0   'False
  186.          Italic          =   0   'False
  187.          Strikethrough   =   0   'False
  188.       EndProperty
  189.       Height          =   685
  190.       Index           =   0
  191.       Left            =   45
  192.       TabIndex        =   5
  193.       Top             =   60
  194.       Width           =   615
  195.    End
  196. End
  197. Attribute VB_Name = "Cell"
  198. Attribute VB_GlobalNameSpace = False
  199. Attribute VB_Creatable = True
  200. Attribute VB_PredeclaredId = False
  201. Attribute VB_Exposed = False
  202. Option Explicit
  203. '*******************************
  204. '* Title  : Cell               *
  205. '* Type   : ActiveX OCX        *
  206. '* Author : Derio              *
  207. '* Stamp  : 15 June 2007       *
  208. '* Desc   : UI for Sudoku Cell *
  209. '*******************************
  210.  
  211. Private vCaption As String
  212. Private vNoteIndex As Integer
  213. Private vCurrentNoteIndex As Integer
  214. Private vForeColor As OLE_COLOR
  215. Private vProtectedColor As OLE_COLOR
  216.  
  217. Public AddNoteSuccess As Boolean
  218.  
  219. Public Enum SUDOKU_MODE
  220.   Protected = 0
  221.   LightButton = 1
  222.   DarkButton = 2
  223. End Enum
  224. Private vMode As SUDOKU_MODE
  225.  
  226. Public Event LeftClick()
  227. Public Event RightClick()
  228. Public Event NoteClick(ByVal LastCaption As String, ByVal NoteList As String)
  229. Public Event NoteRemove(ByVal Note As String)
  230. Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  231. Public Event CaptionChange(ByVal LastCaption As String)
  232.  
  233.  
  234. Private Sub lblNote_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  235.  
  236. Dim NoteList As String
  237. Dim LastCaption As String
  238.  
  239.   'protected cell raises nothing
  240.   If vMode = Protected Then Exit Sub
  241.   
  242.   If Button = vbLeftButton Then
  243.     If lblNote(Index).Caption <> "" Then
  244.       
  245.       NoteList = GetNoteList()
  246.       LastCaption = Me.Caption
  247.       Me.Caption = lblNote(Index).Caption
  248.       Me.ClearNote
  249.       RaiseEvent NoteClick(LastCaption, NoteList)
  250.       
  251.     Else
  252.       RaiseEvent LeftClick
  253.     End If
  254.     
  255.   Else
  256.     If lblNote(Index).Caption <> "" Then
  257.       LastCaption = lblNote(Index).Caption
  258.       Me.RemoveNote lblNote(Index).Caption
  259.       RaiseEvent NoteRemove(LastCaption)
  260.     Else
  261.       RaiseEvent RightClick
  262.     End If
  263.   End If
  264. End Sub
  265.  
  266. Private Sub lblNote_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  267.   If vNoteIndex >= 0 Then
  268.     If vCurrentNoteIndex <> Index Then
  269.       If vCurrentNoteIndex <> -1 Then
  270.         With lblNote(vCurrentNoteIndex)
  271.           .ForeColor = RGB(64, 64, 64)
  272.           .BackStyle = 0 'opaque
  273.         End With
  274.       End If
  275.       
  276.       vCurrentNoteIndex = Index
  277.       With lblNote(vCurrentNoteIndex)
  278.         .ForeColor = vbYellow
  279.         .BackStyle = 1 'Opaque
  280.       End With
  281.       If Not tmrHiLight.Enabled Then tmrHiLight.Enabled = True
  282.     End If
  283.   End If
  284. End Sub
  285.  
  286. Private Sub lblNumber_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  287.   'protected cell raises nothing
  288.   If vMode = Protected Then Exit Sub
  289.   
  290.   If Button = vbLeftButton Then
  291.     RaiseEvent LeftClick
  292.   Else
  293.     RaiseEvent RightClick
  294.   End If
  295. End Sub
  296.  
  297. Private Sub lblNumber_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  298.   'protected cell raises nothing
  299.   If vMode = Protected Then Exit Sub
  300.   
  301.   RaiseEvent MouseMove(Button, Shift, X, Y)
  302. End Sub
  303.  
  304. Private Sub tmrHiLight_Timer()
  305. Dim Cur As POINT
  306.  
  307.   GetCursorPos Cur
  308.   Cur.X = Cur.X - (Extender.Parent.Left + (Extender.Parent.Width - Extender.Parent.ScaleWidth) / 2) \ Screen.TwipsPerPixelX
  309.   Cur.Y = Cur.Y - (Extender.Parent.Top + Extender.Parent.Height - Extender.Parent.ScaleHeight - 30) \ Screen.TwipsPerPixelY
  310.   
  311.   Cur.X = Cur.X * Screen.TwipsPerPixelX - Extender.Left
  312.   Cur.Y = Cur.Y * Screen.TwipsPerPixelY - Extender.Top
  313.   If Not (Cur.X >= lblNote(vCurrentNoteIndex).Left _
  314.           And Cur.X <= lblNote(vCurrentNoteIndex).Left + lblNote(vCurrentNoteIndex).Width _
  315.           And Cur.Y >= lblNote(vCurrentNoteIndex).Top _
  316.           And Cur.Y <= lblNote(vCurrentNoteIndex).Top + lblNote(vCurrentNoteIndex).Height) Then
  317.     tmrHiLight.Enabled = False
  318.     With lblNote(vCurrentNoteIndex)
  319.       .ForeColor = RGB(64, 64, 64)
  320.       .BackStyle = 0
  321.     End With
  322.     
  323.     vCurrentNoteIndex = -1
  324.   End If
  325. End Sub
  326.  
  327. Private Sub UserControl_Initialize()
  328.   vNoteIndex = -1 'no note
  329.   vCurrentNoteIndex = -1 'no selected note
  330.   vProtectedColor = RGB(8 * 16, 4 * 16, 0)
  331.   vForeColor = RGB(255, 255, 0)
  332. End Sub
  333.  
  334. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  335.   'protected cell raises nothing
  336.   If vMode = Protected Then Exit Sub
  337.   
  338.   RaiseEvent MouseMove(Button, Shift, X, Y)
  339. End Sub
  340.  
  341. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  342.   Caption = PropBag.ReadProperty("Caption", "")
  343.   Mode = PropBag.ReadProperty("Mode", SUDOKU_MODE.Protected)
  344.   ForeColor = PropBag.ReadProperty("ForeColor", vbBlack)
  345.   ProtectedColor = PropBag.ReadProperty("ProtectedColor", vbBlack)
  346. End Sub
  347.  
  348. Private Sub UserControl_Resize()
  349.   UserControl.Width = Screen.TwipsPerPixelX * 48
  350.   UserControl.Height = Screen.TwipsPerPixelY * 48
  351. End Sub
  352.  
  353. Public Property Get Caption() As String
  354. Attribute Caption.VB_UserMemId = 0
  355.   Caption = vCaption
  356. End Property
  357.  
  358. Public Property Let Caption(ByVal vNewValue As String)
  359. Dim IsChange As Boolean
  360. Dim LastCaption As String
  361.  
  362.   IsChange = (vNewValue <> vCaption)
  363.   LastCaption = vCaption
  364.   vCaption = vNewValue
  365.   UserControl.lblNumber(0).Caption = vCaption
  366.   UserControl.lblNumber(1).Caption = vCaption
  367.   Me.ClearNote
  368.   PropertyChanged "Caption"
  369.   If IsChange Then RaiseEvent CaptionChange(LastCaption)
  370. End Property
  371.  
  372. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  373.   PropBag.WriteProperty "Caption", vCaption
  374.   PropBag.WriteProperty "Mode", vMode
  375.   PropBag.WriteProperty "ForeColor", vForeColor
  376.   PropBag.WriteProperty "ProtectedColor", vProtectedColor
  377. End Sub
  378.  
  379. Public Sub AddNote(MyNote As String)
  380. '** Add note to Sudoku Cell
  381.  
  382. Dim I As Integer
  383. Dim J As Integer
  384. Dim strTemp As String
  385.  
  386.   AddNoteSuccess = False
  387.   
  388.   'check note capacity
  389.   If vNoteIndex = UserControl.lblNote.Count - 1 Then Exit Sub
  390.   
  391.   'check validitas
  392.   If InStr("123456789", MyNote) = 0 Then Exit Sub
  393.   
  394.   'check if number exist
  395.   If Me.Caption <> "" Then
  396.     strTemp = Me.Caption
  397.     Me.Caption = ""
  398.     Me.AddNote strTemp
  399.   End If
  400.   
  401.   'check if the same note exist
  402.   For I = 0 To vNoteIndex
  403.     If UserControl.lblNote(I).Caption = MyNote Then
  404.       Exit Sub
  405.     End If
  406.   Next I
  407.   
  408.   'check note possition
  409.   For I = 0 To vNoteIndex
  410.     If UserControl.lblNote(I).Caption > MyNote Then
  411.     
  412.       'insert new note if the number smaller than other
  413.       For J = vNoteIndex To I Step -1
  414.         UserControl.lblNote(J + 1).Caption = UserControl.lblNote(J).Caption
  415.         UserControl.lblNote(J + 1).Visible = True
  416.       Next J
  417.       
  418.       Exit For
  419.     End If
  420.   Next I
  421.   
  422.   'insert note
  423.   UserControl.lblNote(I).Caption = MyNote
  424.   UserControl.lblNote(I).Visible = True
  425.   vNoteIndex = vNoteIndex + 1
  426.   AddNoteSuccess = True
  427. End Sub
  428.  
  429. Public Sub RemoveNote(ByVal Note As String)
  430. '** Remove note form Sudoku Cell
  431.  
  432. Dim I As Integer
  433. Dim J As Integer
  434.  
  435.   For I = 0 To vNoteIndex
  436.     If UserControl.lblNote(I).Caption = Note Then
  437.       For J = I To vNoteIndex - 1
  438.         UserControl.lblNote(J).Caption = UserControl.lblNote(J + 1).Caption
  439.       Next J
  440.       UserControl.lblNote(vNoteIndex).Caption = ""
  441.       UserControl.lblNote(vNoteIndex).Visible = False
  442.       vNoteIndex = vNoteIndex - 1
  443.       Exit For
  444.     End If
  445.   Next I
  446. End Sub
  447.  
  448. Public Sub ClearNote()
  449. '** Clear entire note from Sudoku Cell
  450.  
  451. Dim I As Integer
  452.  
  453.   For I = 0 To vNoteIndex
  454.     UserControl.lblNote(I).Caption = ""
  455.     UserControl.lblNote(I).Visible = False
  456.   Next I
  457.   vNoteIndex = -1
  458. End Sub
  459.  
  460. Public Property Get Mode() As SUDOKU_MODE
  461.   Mode = vMode
  462. End Property
  463.  
  464. Public Property Let Mode(ByVal vNewValue As SUDOKU_MODE)
  465.   vMode = vNewValue
  466.   Select Case vMode
  467.   Case SUDOKU_MODE.Protected
  468.     UserControl.Picture = UserControl.imgLib(0).Picture
  469.     UserControl.lblNumber(1).ForeColor = vProtectedColor
  470.     If UserControl.lblNumber(0).Visible Then UserControl.lblNumber(0).Visible = False
  471.   
  472.   Case SUDOKU_MODE.LightButton
  473.     UserControl.Picture = UserControl.imgLib(1).Picture
  474.     UserControl.lblNumber(1).ForeColor = vForeColor
  475.     If Not UserControl.lblNumber(0).Visible Then UserControl.lblNumber(0).Visible = True
  476.   
  477.   Case SUDOKU_MODE.DarkButton
  478.     UserControl.Picture = UserControl.imgLib(2).Picture
  479.     UserControl.lblNumber(1).ForeColor = vForeColor
  480.     If Not UserControl.lblNumber(0).Visible Then UserControl.lblNumber(0).Visible = True
  481.   End Select
  482.   
  483.   PropertyChanged "Mode"
  484. End Property
  485.  
  486. Public Property Get ForeColor() As OLE_COLOR
  487.   ForeColor = vForeColor
  488. End Property
  489.  
  490. Public Property Let ForeColor(ByVal vNewValue As OLE_COLOR)
  491.   vForeColor = vNewValue
  492.   
  493.   If Me.Mode <> Protected Then
  494.     UserControl.lblNumber(1).ForeColor = vNewValue
  495.   End If
  496.   
  497.   PropertyChanged "ForeColor"
  498. End Property
  499.  
  500. Public Property Get ProtectedColor() As OLE_COLOR
  501.   ProtectedColor = vProtectedColor
  502. End Property
  503.  
  504. Public Property Let ProtectedColor(ByVal vNewValue As OLE_COLOR)
  505.   vProtectedColor = vNewValue
  506.   If Me.Mode = Protected Then
  507.     UserControl.lblNumber(1).ForeColor = vProtectedColor
  508.   End If
  509.   
  510.   PropertyChanged "ProtectedColor"
  511. End Property
  512.  
  513. Public Function GetNoteList() As String
  514. Dim I As Integer
  515. Dim NoteList As String
  516.  
  517.   For I = 0 To vNoteIndex
  518.     NoteList = NoteList & UserControl.lblNote(I)
  519.   Next I
  520.   GetNoteList = NoteList
  521. End Function
  522.