From 4688f2e91d709da212310a20bdaf11be4807f22a Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 13 Jun 2016 09:53:36 +0000 Subject: [PATCH] tvplanit: Introduce new datastore event OnPlaySound in order to play alarm sounds on non-Windows systems. If not assigned on Windows the mmsystem routine is used. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4736 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpbase.pas | 5 ++++ components/tvplanit/source/vpbaseds.pas | 33 +++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/components/tvplanit/source/vpbase.pas b/components/tvplanit/source/vpbase.pas index 4b6a5ecab..56fdee706 100644 --- a/components/tvplanit/source/vpbase.pas +++ b/components/tvplanit/source/vpbase.pas @@ -72,6 +72,8 @@ type TVpTimeFormat = (tf24Hour, tf12Hour); + TVpPlaySoundMode = (psmSync, psmASync); + { XML definitions } DOMString = WideString; @@ -96,6 +98,9 @@ type TVpGetEditorCaption = procedure(var Caption : string) of object; + TVpPlaySoundEvent = procedure(Sender: TObject; const AWavFile: String; + AMode: TVpPlaySoundMode) of object; + { XML exceptions } EXML = class (Exception); diff --git a/components/tvplanit/source/vpbaseds.pas b/components/tvplanit/source/vpbaseds.pas index 788435a3e..ee68adb26 100644 --- a/components/tvplanit/source/vpbaseds.pas +++ b/components/tvplanit/source/vpbaseds.pas @@ -210,6 +210,7 @@ type FOnAlert : TVpEventEvent; FOnResourceChange : TVpResourceEvent; FOnDateChanged : TVpDateChangedEvent; + FOnPlaySound : TVpPlaySoundEvent; procedure dsOnTimer(Sender: TObject); procedure dsDoOnAlert(Event: TVpEvent); @@ -258,6 +259,7 @@ type procedure PostTasks; virtual; abstract; procedure PostResources; virtual; abstract; procedure RegisterWatcher (Watcher : THandle); + procedure PlaySound(const AWavFile: String; APlaySoundMode: TVpPlaySoundMode); property Loading : Boolean read FLoading write FLoading; property Resource: TVpResource @@ -290,6 +292,8 @@ type read FOnDisconnect write FOnDisconnect; property OnResourceChange: TVpResourceEvent read FOnResourceChange write FOnResourceChange; + property OnPlaySound: TVpPlaySoundEvent + read FOnPlaySound write FOnPlaySound; end; @@ -383,7 +387,7 @@ implementation uses VpSR, VpConst, VpMisc, VpResEditDlg, VpAlarmDlg, -{$IFNDEF LCL} +{$IFDEF WINDOWS} mmSystem, {$ENDIF} VpDlg, VpSelResDlg; @@ -601,23 +605,22 @@ end; procedure TVpCustomDataStore.dsDoOnAlert(Event: TVpEvent); begin - if Event.AlertDisplayed then Exit; + if Event.AlertDisplayed then + Exit; if Assigned(FOnAlert) then FOnAlert(Self, Event) else begin {Ding!} if FPlayEventSounds then begin - {$IFNDEF LCL} - if FileExists(Event.AlarmWavPath) then + if FileExists(Event.DingPath) then { if the event has a sound of its own, then play that one. } - SndPlaySound(PChar(Event.AlarmWavPath), snd_Async) + PlaySound(Event.DingPath, psmASync) else if FileExists(FDefaultEventSound) then { otherwise, if there is a default sound assigned, then play that one } - SndPlaySound(PChar(FDefaultEventSound), snd_Async) + PlaySound(FDefaultEventSound, psmASync) else { otherwise just ding } - {$ENDIF} Beep; end; @@ -869,7 +872,21 @@ begin end; {=====} - +procedure TVpCustomDatastore.PlaySound(const AWavFile: String; + APlaySoundMode: TVpPlaySoundMode); +begin + if Assigned(FOnPlaySound) then + FOnPlaySound(Self, AWavFile, APlaySoundMode) + else begin + {$IFDEF WINDOWS} + case APlaySoundMode of + psmSync : SndPlaySound(PChar(AWavFile), SND_SYNC); + psmASync : SndPlaySound(PChar(AWavFile), SND_ASYNC); + end; + {$ENDIF} + end; +end; +{=====} { TVpResourceCombo }