Attribute VB_Name = "modul_Calaym_TimerList"
' Copyright (C) 2002-2011 Jan Vorel
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.

' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' If you have any questions, suggestions or bug reports about this product,
' contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
' language or A.P.I. issues

Option Explicit
Option Base 0

Private xLocked As Boolean
Private xTimerDisplayExtraLen As Long
Private xTimerDisplayExtraLenT As Long
Private Const xTimerDisplaySpace1 As Long = 16&
Private Const xTimerDisplaySpace2 As Long = 16&
'Private Const eSPLeft As Long = 8&
'Private Const eSPTop As Long = 3&

Private xPopupMenu2 As Long
Private xMenu As Long
Private xMenu2 As Long


Private Const Interface_Control_Timer_Add As Long = 0&
Private Const Interface_Control_Timer_Edit As Long = 1&
Private Const Interface_Control_Timer_Remove As Long = 2&
Public Const Interface_Control_Timer_RemoveAll As Long = 3&
Private Const Interface_Control_Timer_Close As Long = 4&
Public Const Interface_Control_Timer_List As Long = 5&

Public Interface_Control(Interface_Control_Timer_List) As Long
Private Interface_Control_Hook(Interface_Control_Timer_List) As Long

Private xAccelTimerList(4) As Long

Public Sub ShowTimerListWin()
  Dim xLong1 As Long
  'Dim xType1 As RECT
  'Dim xType2 As POINTAPI

  If Not TimerListClassRegistered Then
    RegClass
    End If
  TimerListMainHWnd = CreateWindowEx(&H10004, TimerListWindowClassName, Replace(LoadResEx_String(2600&), "$", time$), &H6CC0000, 0&, 0&, 438&, 279&, MainHWnd, 0&, 0&)
  If Not TimerListMainHWnd = 0& Then
    EnableWindow MainHWnd, 0&
    
    xMenu = LoadResEx_Menu(2600&)
    xMenu2 = LoadResEx_Menu(2610&)
    'xPopupMenu2 = CreatePopupMenu()
    
    If Not xMenu = 0& Then
      SetMenu TimerListMainHWnd, xMenu
      DrawMenuBar TimerListMainHWnd
      End If
    
    xPopupMenu2 = LoadResEx_Menu_MakePopupMenu(xMenu2)
    '#If DontHookForTesting = 0 Then
    '  xOldProcTM = SetWindowLongAnsi(Me.hwnd, -4&, AddressOf MenuHookTM)
    '  #End If
    If xSecureMode Then Call EnableMenuItem(xMenu, 2601&, 3&)
    If xSecureMode Then Call EnableMenuItem(xMenu2, 2601&, 3&)
    'SetWindowText TimerListMainHWnd, Replace(LoadResEx_String(2600&), "$", getformatedtime)
    
    
    Interface_Control(Interface_Control_Timer_List) = CreateWindowEx(&H200&, W_LISTBOX, "", &H56301988, 0&, 0&, 409&, 220&, TimerListMainHWnd, 0&, 0&)
    
    For xLong1 = 0& To Interface_Control_Timer_Close
      Interface_Control(xLong1) = CreateWindowEx(0&, W_BUTTON, LoadResEx_String(2605& + xLong1), &H56010000, 8& + 80& * xLong1, 224&, 80&, 25&, TimerListMainHWnd, 0&, 0&)
      If Not Interface_Control(xLong1) = 0& Then
        SetAccel xLong1, 2605& + xLong1
        Interface_Control_Hook(xLong1) = SetWindowLong(Interface_Control(xLong1), -4&, AddressOf ButtonProc)
        End If
      Next

    UpdateTimerListWinFont hFontGFix
    
    If Not Interface_Control(Interface_Control_Timer_List) = 0& Then
      Interface_Control_Hook(Interface_Control_Timer_List) = SetWindowLong(Interface_Control(Interface_Control_Timer_List), -4&, AddressOf TimerListListProc)
      End If
    
    RePosWindow xMWindowID_Timer, TimerListMainHWnd
    Call LoadResEx_WindowIcon(TimerListMainHWnd, 2600&)
    
    
    TimerList_ListUpdate
    'UpdateTimerListWinFont hfontgfix
    DragAcceptFiles TimerListMainHWnd, 1&
    
    ShowWindow TimerListMainHWnd, 5&
    If Not Interface_Control(Interface_Control_Timer_List) = 0& Then SetFocusAPI Interface_Control(Interface_Control_Timer_List)
    End If
  
  End Sub

Private Sub RegClass()
  Dim xType1 As WNDCLASSEX
  
  With xType1
    '.cbSize = 48&
    .Style = &H83&
    '.hInstance = App.hInstance
    .hCursor = LoadCursor(&H7F00&)
    .hbrBackground = 16&
    .ClassName = TimerListWindowClassName
    End With
  Call RegisterClassEx(xType1, AddressOf TimerListMainProc)
  TimerListClassRegistered = True
  End Sub

Private Function TimerListMainProc(ByVal hwnd As Long, ByVal Message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case Message
    Case &H5&
      ResizeTimerList
    Case &H10&
      UnloadThisWindow
    Case &H100&
      Select Case wParam
        Case 9&
          LoadResEx_Window_ManualTab TimerListMainHWnd, hwnd
          Exit Function
        Case 27&
          UnloadThisWindow
        End Select
    Case &H105& 'syskeyup
      TryAccel wParam
    Case &H111&
      If lParam = 0& Then
        'Debug.Print "MenuEvent:", wParam
        TimerList_MenuEvent wParam
        Else
        TimerList_ButtonEvent lParam ', wParam
        End If
      If IsUnicode Then
        TimerListMainProc = DefWindowProcWide(hwnd, Message, wParam, lParam)
        Else
        TimerListMainProc = DefWindowProcAnsi(hwnd, Message, wParam, lParam)
        End If
    Case &H233&
      TimerList_DropFiles wParam
    Case Else
      If IsUnicode Then
        TimerListMainProc = DefWindowProcWide(hwnd, Message, wParam, lParam)
        Else
        TimerListMainProc = DefWindowProcAnsi(hwnd, Message, wParam, lParam)
        End If
    End Select
  End Function

Private Sub LoadTimerDlg()
  Dim xChar1 As String
  
  xChar1 = CommonDLG_OpenFiles(TimerListMainHWnd, LoadResEx_String(1605&) + vbNullChar + "*.cpt", &H81004, LoadResEx_String(1600&), TimerDir)
  If Not xChar1 = "" Then
    MainForm_LoadTimers TimerListMainHWnd, xChar1, False
    End If
  End Sub

Private Sub ResizeTimerList()

  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xType1 As RECT
  Const eSpX As Long = 4&
  'Const eSpX_2 As Long = eSpX * 2&
  Const eSpX_6 As Long = eSpX * 6&
  
  Call GetClientRect(TimerListMainHWnd, xType1)
  If xType1.Right < 0& Then xType1.Right = 0&
  
  xLong1 = (xType1.Right - eSpX_6) / 5&
  If xLong1 < 0& Then xLong1 = 0&
  
  xType1.Bottom = xType1.Bottom - 25& - eSpX '- 20&
  For xLong2 = 0& To 4&
    xLong3 = (xLong1 + eSpX) * xLong2 + eSpX
    Call SetWindowPos(Interface_Control(xLong2), 0&, xLong3, xType1.Bottom, xLong1, 25&, &H214&)
    Next
  
  xLong1 = xType1.Bottom - eSpX '_2
  If xLong1 < 0& Then xLong1 = 0&
  Call SetWindowPos(Interface_Control(Interface_Control_Timer_List), 0&, 0&, 0&, xType1.Right, xLong1, &H216&)
  End Sub

Private Function TimerListListProc(ByVal hwnd As Long, ByVal Message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case Message
    Case &H100&
      Select Case wParam
        Case 46&
          Call TimerList_ButtonEventEx(TimerListMainHWnd, 2&)
        Case 93&
          If (lParam And &H40000000) = 0& Then
            'TimerList_MenuEvent TrackListBox(xStaticIconsHWnd(xStaticIcons_ShowIR), hWnd, , True, xMenu2, 1&)
            TimerList_MenuEvent GetAPIPopupMenu(TimerListMainHWnd, xMenu2, Interface_Control(Interface_Control_Timer_List))
            End If
        Case 9&
          LoadResEx_Window_ManualTab TimerListMainHWnd, hwnd
          Exit Function
        Case 27&
          UnloadThisWindow
        End Select
    Case &H105& 'syskeyup
      TryAccel wParam
    Case &H205& 'rightmouseup
      If Not xLocked Then
        TimerList_MenuEvent TrackListBox(xStaticIconsHWnd(xStaticIcons_ShowIR), hwnd, ((lParam And &HFFFF0000) \ &H10000), True, xMenu2, 1&)
        End If
    Case &H203 ' l-dblclick
      If Not xTimerEvCount = 0& Then
        Call TimerList_ButtonEventEx(TimerListMainHWnd, 1&)
        'eButton_Click 1&
        End If
    Case Else
      If IsUnicode Then
        TimerListListProc = CallWindowProcWide(Interface_Control_Hook(Interface_Control_Timer_List), hwnd, Message, wParam, lParam)
        Else
        TimerListListProc = CallWindowProcAnsi(Interface_Control_Hook(Interface_Control_Timer_List), hwnd, Message, wParam, lParam)
        End If
    End Select
  End Function

Private Sub TimerList_ButtonEvent(ByVal hwnd As Long) ', ByVal wParam As Long)
  ' -> TimerList_ButtonEventEx
  Dim xLong1 As Long
  
  For xLong1 = 0& To Interface_Control_Timer_Close
    If Interface_Control(xLong1) = hwnd Then
      TimerList_ButtonEventEx TimerListMainHWnd, xLong1
      Exit For
      End If
    Next
  End Sub

Public Sub TimerList_ButtonEventEx(ByVal hWndOwner As Long, ByVal Index As Long)
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String
  Dim xChar2 As String
  Dim xLong4 As Long
  
  If Not xLocked Then
    Select Case Index
      Case 0&
        xTimerEvMode = -1&
        ShowTimerEditor
        DoneEditing
      Case 1&
        If GetListIndexMS(Interface_Control(Interface_Control_Timer_List), xTimerEvMode) Then
        'If eList.SelCount = 1 Then
          'xTimerEvMode = eList.ListIndex
          'If Not xTimerEvMode = -1& Or xTimerEvMode = xTimerEvIR Then
          If Not xTimerEvMode = xTimerEvIR Then
            'TimerList_LockMe True
            ShowTimerEditor
            DoneEditing
            End If
          End If
      Case 2&
        xTimerEditing = True
        xLong1 = xTimerEvCount - 1&
        xTimerEvCount = 0&
        Call SelectObject(xSharedDC, hFontGSys)
        For xLong1 = 0& To xLong1
          If SendMessage(Interface_Control(Interface_Control_Timer_List), &H187&, xTimerEvCount, 0&) = 0& Then
            If xLong1 = xTimerEvIR Then xTimerEvIR = xTimerEvCount
            xTimerEvTime(xTimerEvCount) = xTimerEvTime(xLong1)
            xTimerEv(xTimerEvCount) = xTimerEv(xLong1)
            
            xChar1 = xTimerDisplay(xLong1, 0&, xChar2)
            xLong4 = GetTextOutWidth(xSharedDC, xChar1)
            If xLong4 > xLong2 Then xLong2 = xLong4
            If Not xChar2 = "" Then
              xLong4 = GetTextOutWidth(xSharedDC, xChar2)
              If xLong4 > xLong3 Then xLong3 = xLong4
              End If
            xTimerEvCount = xTimerEvCount + 1&
            Else
            If xLong1 = xTimerEvIR Then xTimerEvIR = -1&
            'eList.RemoveItem xTimerEvCount
            Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H182&, xTimerEvCount, 0&)
            End If
          Next
        
        'If xTimerEvCount = 0& Then
        '  Call EnableMenuItem(xMenu, 2602&, 3&)
        '  Call EnableMenuItem(xMenu2, 2602&, 3&)
        '  eButton(1).Enabled = False
        '  eButton(2).Enabled = False
        '  eButton(3).Enabled = False
        '  Call EnableMenuItem(xMenu, 2612&, 3&)
        '  Call EnableMenuItem(xMenu2, 2612&, 3&)
        '  Call EnableMenuItem(xMenu, 2613&, 3&)
        '  Call EnableMenuItem(xMenu2, 2613&, 3&)
        '  Call EnableMenuItem(xMenu, 2614&, 3&)
        '  Call EnableMenuItem(xMenu2, 2614&, 3&)
        '  End If
        'xTimerEditing = (xTimerEvCount < xTimerEvMax Or xTimerEvCount = xTimerEvMax And Not xTimerEvIR = -1&)
        'eButton(0).Enabled = xTimerEditing 'xBool1
        'If xTimerEditing Then
        '  Call EnableMenuItem(xMenu, 2610&, 0&)
        '  Call EnableMenuItem(xMenu2, 2610&, 0&)
        '  Else
        '  Call EnableMenuItem(xMenu, 2610&, 3&)
        '  Call EnableMenuItem(xMenu2, 2610&, 3&)
        '  End If
        DoneEditing
        UpdateTimerListWidths xLong2, xLong3
        MainForm_SetTimerImage
        xTimerEditing = False
      Case 3&
        If Not xTimerEvIR = -1& Then
          If MessageBox(hWndOwner, LoadResEx_String(1619&), LoadResEx_String(1618&), 68&) = vbNo Then
            xTimerEvIR = -1&
            End If
          End If
        Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H184&, 0&, 0&)
        If xTimerEvIR = -1& Then
          xTimerEvCount = 0&
          'DoneEditing
          'Call EnableMenuItem(xMenu, 2602&, 3&)
          'eButton(0).Enabled = True
          'eButton(1).Enabled = False
          'eButton(2).Enabled = False
          'eButton(3).Enabled = False
          'Call EnableMenuItem(xMenu, 2611&, 0&)
          'Call EnableMenuItem(xMenu2, 2611&, 0&)
          'Call EnableMenuItem(xMenu, 2612&, 3&)
          'Call EnableMenuItem(xMenu2, 2612&, 3&)
          'Call EnableMenuItem(xMenu, 2613&, 3&)
          'Call EnableMenuItem(xMenu2, 2613&, 3&)
          'Call EnableMenuItem(xMenu, 2614&, 3&)
          'Call EnableMenuItem(xMenu2, 2614&, 3&)
          Else
          xTimerEv(0&) = xTimerEv(xTimerEvIR)
          xTimerEvTime(0&) = xTimerEvTime(xTimerEvIR)
          xChar1 = xTimerDisplay(0&, 1&)
          Call SendMessage_String(Interface_Control(Interface_Control_Timer_List), &H180&, 0&, xChar1)
          'eList.AddItem xChar1
          xChar1 = xTimerDisplay(0&, 0&, xChar2)
          Call SelectObject(xSharedDC, hFontGFix)
          xLong1 = GetTextOutWidth(xSharedDC, xChar1)
          If xChar2 = "" Then
            xLong1 = 0&
            Else
            xLong1 = GetTextOutWidth(xSharedDC, xChar2)
            End If
          xTimerEvCount = 1&
          xTimerEvIR = 0&
          End If
        DoneEditing
        UpdateTimerListWidths xLong1, xLong1
        MainForm_SetTimerImage
      Case 4&
        UnloadThisWindow
      End Select
    End If
  End Sub

Private Sub UnloadThisWindow()
  'Dim xLong1 As Long
  
  If Not TimerListMainHWnd = 0& Then
    Call GetMyWindowEx(TimerListMainHWnd, xMWindowID_Timer)
   
    MainForm_SetTimerImage
    
    '#If DontHookForTesting = 0 Then
    '  Call SetWindowLongAnsi(Me.hwnd, -4&, xOldProcTM)
    '  #End If
    DragAcceptFiles TimerListMainHWnd, 0&
    
    EnableWindow MainHWnd, 1&
    Call LoadResEx_WindowIcon(TimerListMainHWnd, -1&)
    DestroyWindow TimerListMainHWnd
    'If xMenu Then DestroyMenu xMenu
    If xMenu2 Then DestroyMenu xMenu2
    If xPopupMenu2 Then DestroyMenu xPopupMenu2
    TimerListMainHWnd = 0&
    SetForegroundWindow MainHWnd
    SetFocusAPI MainHWnd
    End If
  End Sub

Private Function ButtonProc(ByVal hwnd As Long, ByVal Message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Dim xLong1 As Long
  
  If Message = &H100& And wParam = 9& Then
    LoadResEx_Window_ManualTab TimerListMainHWnd, hwnd
    ElseIf Message = &H100 And wParam = 27& Then
    UnloadThisWindow
    ElseIf Message = &H105& Then
    TryAccel wParam
    Else
    For xLong1 = 0& To Interface_Control_Timer_Close
      If Interface_Control(xLong1) = hwnd Then
        If IsUnicode Then
          ButtonProc = CallWindowProcWide(Interface_Control_Hook(xLong1), hwnd, Message, wParam, lParam)
          Else
          ButtonProc = CallWindowProcAnsi(Interface_Control_Hook(xLong1), hwnd, Message, wParam, lParam)
          End If
        Exit For
        End If
      Next
    End If
  End Function







Private Sub SetAccel(ByVal Index As Long, ByVal ResID As Long)
  Dim xChar1 As String
  
  xChar1 = Replace(LoadResEx_String(ResID), "&&", "")
  ResID = InStr(xChar1, "&")
  If ResID = Len(xChar1) Then
    ResID = 0&
    ElseIf Not ResID = 0& Then
    ResID = Asc(UCase(Mid(xChar1, ResID + 1&, 1&)))
    End If
  xAccelTimerList(Index) = ResID
  End Sub

Private Sub TryAccel(ByVal wParam As Long)
  Dim xLong1 As Long
  
  If wParam = 40& Or wParam = 38& Then
    ShowWindow Interface_Control(Interface_Control_Timer_List), 5&
    SetFocusAPI Interface_Control(Interface_Control_Timer_List)
    ElseIf wParam = 93& And Not xLocked Then
    'TimerList_MenuEvent GetAPIPopupMenu(TimerListMainHWnd, xMenu2, Interface_Control(Interface_Control_Timer_List), 11&)
    xLong1 = GetAPIPopupMenu(TimerListMainHWnd, xMenu2, Interface_Control(Interface_Control_Timer_List))
    If Not xLong1 = 0& Then
      TimerListListProc Interface_Control(Interface_Control_Timer_List), &H111&, 0&, xLong1
      End If
    Else
    For xLong1 = 0& To Interface_Control_Timer_Close
      If xAccelTimerList(xLong1) = wParam Then
        'SetFocusapi Interface_Control(xLong1)
        SetFocusAPI Interface_Control(Interface_Control_Timer_List)
        If Not xLong1 = Interface_Control_Timer_List Then
          Call TimerList_ButtonEventEx(TimerListMainHWnd, xLong1)
          End If
        'If Not xLong1 = 5& Then
        '  SetFocusapi Interface_Control(Interface_Control_Timer_list)
        '  End If
        Exit For
        End If
      Next
    End If
  End Sub


Public Sub UpdateTimerListWinFont(ByVal xFont As Long)
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xChar1 As String

  For xLong1 = 0& To Interface_Control_Timer_List
    Call SendMessage(Interface_Control(xLong1), &H30&, xFont, 1&)
    Next
  xTimerDisplayExtraLen = 0&
  Call SelectObject(xSharedDC, xFont)
  For xLong1 = 0& To 9&
    xChar1 = String(2&, Chr(48& + xLong1)) + ":" + String(2&, Chr(48& + xLong1))
    xLong2 = GetTextOutWidth(xSharedDC, xChar1) + xTimerDisplaySpace1
    If xLong2 > xTimerDisplayExtraLen Then xTimerDisplayExtraLen = xLong2
    
    xChar1 = Replace(LoadResEx_String(2655&), "$", xChar1)
    xLong2 = GetTextOutWidth(xSharedDC, xChar1)
    If xLong2 > xLong3 Then xLong3 = xLong2
    Next
  xTimerDisplayExtraLenT = xTimerDisplayExtraLen + xLong3 + xTimerDisplaySpace2
  'Debug.Print "WidthInitial:", xTimerDisplayExtraLen, xLong3, xTimerDisplayExtraLenT
  End Sub

Private Sub UpdateTimerListWidths(ByVal xLen As Long, ByVal xLenPL As Long)
  Static xLongA1(2) As Long

  'Debug.Print "WidthsFilled:", xLen, xLenPL

  If xLen = 0& Then
    'xLongA1(0) = 0&
    Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H192&, 0&, 0&)  'xLongA1(0))
    Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H194&, 0&, 0&)
    Else
    xLongA1(0) = xTimerDisplayExtraLen * xGlobalDialogUnitsGFix '* 4
    xLongA1(1) = (xTimerDisplayExtraLen + xLen + xTimerDisplaySpace2) * xGlobalDialogUnitsGFix '* 4
    If xLenPL = 0& Then
      Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H192&, 2&, ByVal VarPtr(xLongA1(0)))
      Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H194&, xLen + 4& + xTimerDisplayExtraLenT, 0&)
      Else
      xLongA1(2) = (xTimerDisplayExtraLenT + xLen + xTimerDisplaySpace2) * xGlobalDialogUnitsGFix  '* 4
      Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H192&, 3&, ByVal VarPtr(xLongA1(0)))
      Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H194&, xLen + 4& + xTimerDisplayExtraLenT + xLenPL + xTimerDisplaySpace2, 0&)
      End If
    End If
  End Sub

Public Sub TimerList_ListUpdate()
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim xLong5 As Long
  Dim xChar1 As String
  Dim xChar2 As String
  'Dim xType1 As POINTAPI
  
  If xTimerEvCount = 0& Then
    xLong2 = -1&
    Else
    Call GetListIndexMS(Interface_Control(Interface_Control_Timer_List), xLong2)
    End If
  
  ResortTimers
  
  Call SendMessage(Interface_Control(Interface_Control_Timer_List), &H184&, 0&, 0&)
  #If TimeTestDebug Then
    MainForm_ctConsoleA_AddLog "TimeDebug: Refreshing list"
    #End If
  Call SelectObject(xSharedDC, hFontGFix)
  For xLong1 = 0& To xTimerEvCount - 1&
    xChar1 = xTimerDisplay(xLong1, 1&)
    Call SendMessage_String(Interface_Control(Interface_Control_Timer_List), &H180&, 0&, xChar1)
    xChar1 = xTimerDisplay(xLong1, 0&, xChar2)
    xLong5 = GetTextOutWidth(xSharedDC, xChar1)
    If xLong5 > xLong3 Then xLong3 = xLong5
    If Not xChar2 = "" Then
      xLong5 = GetTextOutWidth(xSharedDC, xChar2)
      If xLong5 > xLong4 Then xLong4 = xLong5
      End If
    'If xLong3 > xLong4 Then xLong4 = xLong3
    #If TimeTestDebug Then
      MainForm_ctConsoleA_AddLog "           " & "(" & CStr(xTimerEvTime(xLong1)) & "): " & xTimerDisplay(xLong1, 2&)
      #End If
    Next
  
  If Not xTimerEvCount = 0& Then
    If xLong2 = -1& Then xLong2 = 0&
    SetListIndexMS Interface_Control(Interface_Control_Timer_List), xLong2
    End If
  
  DoneEditing
  GrabError
  xTimerEvUpdateTimer = Timer \ 60&
  UpdateTimerListWidths xLong3, xLong4
  MainForm_SetTimerImage
  End Sub

Private Sub DoneEditing()
  Dim xBool1 As Boolean
  
  xBool1 = ((xTimerEvCount < xTimerEvMax Or xTimerEvCount = xTimerEvMax And Not xTimerEvIR = -1&))
  EnableWindow Interface_Control(Interface_Control_Timer_Add), -CLng(xBool1)
  Call EnableMenuItem(xMenu, 2600&, 3& * (1& + CLng(xBool1)))
  Call EnableMenuItem(xMenu2, 2600&, 3& * (1& + CLng(xBool1)))
  xBool1 = Not xTimerEvCount = 0&
  EnableWindow Interface_Control(Interface_Control_Timer_Edit), -CLng(xBool1)
  EnableWindow Interface_Control(Interface_Control_Timer_Remove), -CLng(xBool1)
  EnableWindow Interface_Control(Interface_Control_Timer_RemoveAll), -CLng(xBool1)
  If xBool1 Then
    Call EnableMenuItem(xMenu, 2601&, 0&)
    Call EnableMenuItem(xMenu2, 2012&, 0&)
    Call EnableMenuItem(xMenu, 2602&, 0&)
    Call EnableMenuItem(xMenu2, 2602&, 0&)
    Call EnableMenuItem(xMenu, 2603&, 0&)
    Call EnableMenuItem(xMenu2, 2603&, 0&)
    If Not xSecureMode Then Call EnableMenuItem(xMenu, 2609&, 0&)
    If Not xSecureMode Then Call EnableMenuItem(xMenu2, 2609&, 0&)
    Else
    Call EnableMenuItem(xMenu, 2601&, 3&)
    Call EnableMenuItem(xMenu2, 2601&, 3&)
    Call EnableMenuItem(xMenu, 2602&, 3&)
    Call EnableMenuItem(xMenu2, 2602&, 3&)
    Call EnableMenuItem(xMenu, 2603&, 3&)
    Call EnableMenuItem(xMenu2, 2603&, 3&)
    Call EnableMenuItem(xMenu, 2609&, 3&)
    Call EnableMenuItem(xMenu2, 2609&, 3&)
    End If
  End Sub

Public Sub TimerList_LockMe(ByVal vBool1 As Boolean, ByVal LockButtonsAndList As Boolean)
  Dim xLong1 As Long

  xLocked = vBool1
  For xLong1 = 0& To GetMenuItemCount(xMenu) - 1&
    EnableMenuItem xMenu, xLong1, &H400& - 3& * vBool1
    Next
  DrawMenuBar TimerListMainHWnd
  If LockButtonsAndList Then
    If vBool1 Then
      For xLong1 = 0& To Interface_Control_Timer_List
        Call EnableWindow(Interface_Control(xLong1), 0&)
        Next
      Else
      Call EnableWindow(Interface_Control(Interface_Control_Timer_Add), -CLng((xTimerEvCount < xTimerEvMax Or xTimerEvCount = xTimerEvMax And Not xTimerEvIR = -1&)))
      For xLong1 = Interface_Control_Timer_Edit To Interface_Control_Timer_RemoveAll
        Call EnableWindow(Interface_Control(xLong1), 1& + CLng(xTimerEvCount = 0&))
        Next
      Call EnableWindow(Interface_Control(Interface_Control_Timer_Close), 1&)
      Call EnableWindow(Interface_Control(Interface_Control_Timer_List), 1&)
      End If
    End If
  End Sub

Private Sub TimerList_DropFiles(ByVal hDrop As Long)
  Dim xChar1 As String

  If Not (xAutoDoing Or PlayerIsLocked) Then
    If DragQueryFileCount(hDrop) = 1& Then
      If DragQueryFile(hDrop, 0&, xChar1) Then
        If MainForm_AllowedItem(xChar1) = 254& Then
          MainForm_LoadTimers TimerListMainHWnd, xChar1, False
          End If
        End If
      End If
    End If
  End Sub

Public Sub TimerList_ReDetectWidth()
  Dim xLong1 As Long
  Dim xLong3 As Long
  Dim xLong4 As Long
  Dim xLong5 As Long
  Dim xChar1 As String
  Dim xChar2 As String
  
  Call SelectObject(xSharedDC, hFontGFix)
  For xLong1 = 0& To xTimerEvCount - 1&
    xChar1 = xTimerDisplay(xLong1, 0&, xChar2)
    xLong5 = GetTextOutWidth(xSharedDC, xChar1)
    If xLong5 > xLong3 Then xLong3 = xLong5
    If Not xChar2 = "" Then
      xLong5 = GetTextOutWidth(xSharedDC, xChar2)
      If xLong5 > xLong4 Then xLong4 = xLong5
      End If
    Next
  
  UpdateTimerListWidths xLong3, xLong4
  End Sub

Private Sub TimerList_MenuEvent(ByVal wParam As Long)
  Select Case wParam
    Case 2608&
      LoadTimerDlg
    Case 2609&
      MainForm_SaveTimers TimerListMainHWnd, "", False
    Case 2600& To 2604&
      TimerList_ButtonEventEx TimerListMainHWnd, wParam - 2600&
    End Select
  End Sub
