Attribute VB_Name = "modul_Calaym_SMControl_WA"
' 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 private 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 private License for more details.

' You should have received a copy of the GNU General private 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

Public xNoIRMode As Boolean
Public vCanVolume As Boolean


Public Function MainForm_DoCommand(ByVal EventID As Long) As Long
  'private Sub MainForm_DoCommand(ByVal EventID As Long, ByVal Flags As Long)
  Dim xLong1 As Long
  'Dim xChar1 As String
  
  'If xNoIRMode = 1& Or EventID = 0& Or xIsCrossFading Or PlayerIsLocked Or xAutoDoing Then Exit Sub
  'If Not (xNoIRMode = 1& Or EventID = 0& Or xIsCrossFading Or PlayerIsLocked Or xAutoDoing) Then
  'If Not (xNoIRMode = 1& Or EventID = 0& Or PlayerIsLocked Or xAutoDoing) Then
  If IsDialoging = 0& And Not (xNoIRMode Or EventID = 0& Or PlayerIsLocked Or xAutoDoing) Then
    'If vKioskMode And Not xNoIRMode = 2& Then
    If vKioskMode Then
      Select Case EventID
        Case 510&, 512&, 513&, 515& To 518&, 520& To 522&, 590&
          'If InStr(CommandX, "/SHUTDOWN") = 0 Then Exit Sub
          If Not (xCmdQuitMode = 1& Or xCmdQuitMode = 3& Or xCmdQuitMode = 4&) Then GoTo OutFnc
        Case 222&, 223&, 230& To 240&
          If Not vCanVolume Then GoTo OutFnc
        Case 320&, 330&, 331&, 340&, 360&
          GoTo OutFnc
        End Select
      End If
    If vKioskMode Then
      Select Case EventID
        Case 220&, 221&, 390& To 392&, _
             400& To 403&, 420& To 422&, 430& To 432&, _
             440& To 442&, 450&, 460& To 463&, 470& To 472&
          GoTo OutFnc
        Case 302& To 304&
          If EventID - 302& > PlDClickAction Then GoTo OutFnc
        End Select
      End If
    If EventID > 510& And EventID < 518& Or EventID > 519& And EventID < 523& Then
      If xTimerEditing Then GoTo OutFnc
      End If
    MainForm_DoCommand = 1&
    Select Case EventID
      'Case 1&
      'Case 2&
      'Case 100&
      'Case 101&
      'xOldIconState
      Case 200& To 205&
        xNoRemove = True
        MainForm_IconsMouseUp EventID - 200&
        xNoRemove = False
      'seek back/volume
      Case 220&
        xTrackSeekA -1&
      Case 221&
        xTrackSeekA 1&
      Case 222&
        MainForm_ProcessKey KbdC_GVolUp
        ChangeVolumeMenu 0&
      Case 223&
        MainForm_ProcessKey KbdC_GVolDown
        ChangeVolumeMenu 1&
      Case 230& To 240&
        DoVolume CLng((EventID - 230&) * 25.5), True
      Case 300&
        MainForm_ProcessKey KbdC_GPrevSel
  '      xMarkSong xFindNextItem(-1&, True, False, True, False), False, False
  '      xFollowCurSongLast = DoEventsEx_GetTickCount
  '      xFollowCurSongLastDiff = xFollowCurSongLastDiffDef
      'play song
      Case 301&: MainForm_PlayListDoubleClickEvent
      'find current
      Case 302& To 304& 'play song ...
        MainForm_MenuEventPlaylist EventID - 302&
      'play next
      Case 305&
      'next item
        MainForm_ProcessKey KbdC_GNextSel, False
  '      xMarkSong xFindNextItem(1&, True, False, True, False), False, False
  '      xFollowCurSongLast = DoEventsEx_GetTickCount
  '      xFollowCurSongLastDiff = xFollowCurSongLastDiffDef
      'Find Current:
      Case 306&
        MainForm_ProcessKey KbdC_PFindCurrent, False
      'select random
      Case 307&
        MainForm_ProcessKey KbdC_PSelRnd, False
      'page up/down
      Case 318&
        MainForm_ProcessKey KbdC_GPrevPage, False
      Case 319&
        MainForm_ProcessKey KbdC_GNextPage, False
  #If 0 Then
        If Not PLCount = 0& Then
        'If PLCount > 0& And SendMessage(xListHWnd(2), &H190&, 0&, 0&) > 0& Then
        '  xLong1 = SendMessage(xListHWnd(2), &H19F&, 0&, 0&)
          Call GetListIndexMS(xListHWnd(2), xLong1)
          If xLong1 = -1& Then xLong1 = 0&
          If EventID = 319& Then
            xLong1 = xLong1 - 10&
            If xLong1 < 0 Then xLong1 = PLCount - 1&
            Else
            xLong1 = xLong1 + 10&
            If xLong1 > PLCount - 1& Then xLong1 = 0&
            End If
          xMarkSong xLong1, False, False
          xFollowCurSongLast = DoEventsEx_GetTickCount
          xFollowCurSongLastDiff = xFollowCurSongLastDiffDef
          End If
      ' Performautorefresh
  #End If
      Case 320&
        MainForm_xAutoRefreshNow False, False, False, False, False
      Case 330&, 331&
        Call xRemoveItems(EventID = 330&)
      Case 340& 'Stop, AutoRefresh, Start(Random)Song
        AutoRefreshHandler 4&
      Case 360& ' abortreading
        AbortReading = True
      Case 390&
        MP3GetID3Tag = Not MP3GetID3Tag
      Case 391&
        MP3GetID3Tag = True
      Case 392&
        MP3GetID3Tag = False
      Case 400&
          xRep = (xRep + 1&) Mod 3&
          MainForm_ApplyRepMode
      Case 401& To 403&: xRep = EventID - 401&
      'Fading
      Case 410&: xGenFading = Not xGenFading
      Case 411&: xGenFading = True
      Case 412&: xGenFading = False
      'SpectrumToggle
      Case 420&: SpektrumToggleEvent
      Case 421&: If Not xShowSpectrum Then SpektrumToggleEvent
      Case 422&: If xShowSpectrum Then SpektrumToggleEvent
      'RemoveMissing
      Case 430&: xRemoveMissingSongs = Not xRemoveMissingSongs
      Case 431&: xRemoveMissingSongs = True
      Case 432&: xRemoveMissingSongs = False
      'RemoveSkippedSongs
      Case 440&: xRemoveSkippedSongs = Not xRemoveSkippedSongs
      Case 441&: xRemoveSkippedSongs = True
      Case 442&: xRemoveSkippedSongs = False
      'RemovePlayed
      Case 450&: xRemovePlayedSongs = Not xRemovePlayedSongs
      Case 451&: xRemovePlayedSongs = True
      Case 452&: xRemovePlayedSongs = False
      'EndSongMode
      Case 460&
        xProcessMode = (xProcessMode + 1&) Mod 4&
      Case 461& To 464&
        xProcessMode = EventID - 461&
      Case 465& To 467&
        If xProcessMode = EventID - 464& Then
          xProcessMode = 0
          Else
          xProcessMode = EventID - 464&
          End If
      'Intromode
      Case 480&: IntroModeActive = Not IntroModeActive
      Case 481&: IntroModeActive = True
      Case 482&: IntroModeActive = False
      
      Case 510& 'off
        If Not xTimerEvIR = -1& Then
          xTimerRemove xTimerEvIR
          xTimerEvIR = -1&
          If InterfaceMode = Interface_Mode_Timer Then
            TimerListForm_ListUpdate
            Else
            ResortTimers
            MainForm_SetTimerImage
            End If
          End If
      Case 512& '+30
        GrabError
        If xTimerEvIR = -1& Then
          xTimerEvIR = xTimerChange(-1&, (Timer \ 60& + 30&) Mod 1440&, LoadResEx_String(2799&) & "=" & CStr(KbdCTm_FShutDown))
          Else
          xLong1 = (xTimerEvTime(xTimerEvIR - Timer \ 60&) + 30& + 1440&) Mod 1440&
          If xLong1 > 1410& Then xLong1 = 1410&
          xTimerEvIR = xTimerChange(xTimerEvIR, (Timer \ 60& + xLong1) Mod 1440&)
          End If
        If InterfaceMode = Interface_Mode_Timer Then
          TimerListForm_ListUpdate
          Else
          ResortTimers
          MainForm_SetTimerImage
          End If
      Case 513& '-30
        GrabError
        If Not xTimerEvIR = -1& Then
          xLong1 = (xTimerEvTime(xTimerEvIR) - Timer \ 60& - 30& + 1440&) Mod 1440&
          If Not xLong1 > 0& Then
            xTimerEvIR = -1&
            xTimerRemove xTimerEvIR
            Else
            xTimerEvIR = xTimerChange(xTimerEvIR, (xLong1 + Timer \ 60&) Mod 1440&)
            End If
          If InterfaceMode = Interface_Mode_Timer Then
            TimerListForm_ListUpdate
            Else
            ResortTimers
            MainForm_SetTimerImage
            End If
          End If
      Case 515& To 518& '30-60-90-120
        GrabError
        If xTimerEvIR = -1& Then
          xTimerEvIR = xTimerChange(-1&, (Timer \ 60& + (EventID - 514&) * 30&) Mod 1440&, LoadResEx_String(2799&) & "=" & CStr(KbdCTm_FShutDown))
          Else
          xTimerEvIR = xTimerChange(xTimerEvIR, (Timer \ 60& + (EventID - 514&) * 30&) Mod 1440&)
          End If
        If InterfaceMode = Interface_Mode_Timer Then
          TimerListForm_ListUpdate
          Else
          ResortTimers
          MainForm_SetTimerImage
          End If
      Case 590&
        Call PostMessage(xStaticIconsHWnd(xStaticIcons_ShowIR), &H400&, -1&, 2&)
        GoTo OutFnc
      Case 600&
        MainForm_ProcessKey KbdC_GShowPlayer, False
      Case 601&
        If xTrayIconEnabled Then
          'Me.Visible = False
          Call ShowWindow(MainHWnd, 0&)
          xTrayIconIndicator = True
          MainForm_ShowTray False
          Else
          Call ShowWindow(MainHWnd, 7&)
          End If
      Case 610&
        If xPStateIconPlaying And Not (CurMusic = ctSSLayer_MusicTypeNone Or PlayerIsLocked) Then
          ShowIR_Do False
          End If
      End Select
    
    
    Select Case EventID
      Case 390& To 392&
        CheckApiMenu 303&, MP3GetID3Tag
        If MP3GetID3Tag Then
          Call ShowWindow(xStaticIconsHWnd(xStaticIcons_Tags), 5&)
          Else
          Call ShowWindow(xStaticIconsHWnd(xStaticIcons_Tags), 0&)
          End If
        'ePic(7).Visible = MP3GetID3Tag
        If MP3GetID3Tag Then MainForm_ReadLate "", True
        SetPanelSize
      Case 400& To 403&
        MainForm_ApplyRepMode
      Case 410& To 412&
        CheckApiMenu 301&, xGenFading
      Case 430& To 432&
        CheckApiMenu 320&, xRemoveMissingSongs
      Case 440& To 442&
        CheckApiMenu 321&, xRemoveSkippedSongs
      Case 450& To 452&
        CheckApiMenu 322&, xRemovePlayedSongs
      Case 460& To 467& ', 470& To 472&
        MainForm_ApplyProcessMode
      Case 480& To 482&
        'CheckApiMenu 119&, IntroModeActive
        MainForm_ApplyRepMode
      End Select
    End If

OutFnc:
  Select Case EventID
    Case 1&, 200& To 205&
      MainForm_DoCommand = 0&
      If xPStateIconPlaying Then
        If xPStateIconPaused Then
          MainForm_DoCommand = 2&
          Else
          MainForm_DoCommand = 1&
          End If
        End If
    Case 2&
      'MainForm_DoCommand = 0&
      If xOldIconState = -1& Then
        MainForm_DoCommand = 3&
        Else
        MainForm_DoCommand = xOldIconState
        End If
    Case 222&, 223&, 230& To 240&
      MainForm_DoCommand = xSetVolume
    Case 390& To 392&: MainForm_DoCommand = -CLng(MP3GetID3Tag)
    Case 400& To 403&: MainForm_DoCommand = xRep
    Case 410& To 412&: MainForm_DoCommand = -CLng(xGenFading)
    Case 420& To 422&: MainForm_DoCommand = -CLng(xShowSpectrum)
    Case 430& To 432&: MainForm_DoCommand = -CLng(xRemoveMissingSongs)
    Case 440& To 442&: MainForm_DoCommand = -CLng(xRemoveSkippedSongs)
    Case 450& To 452&: MainForm_DoCommand = -CLng(xRemovePlayedSongs)
    Case 460& To 467&: MainForm_DoCommand = xProcessMode
    Case 480& To 482&: MainForm_DoCommand = -CLng(IntroModeActive)
    End Select
  End Function


