From 726606df8c82de8a69f80c0f0ca7d4fa6fba4dc2 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 14 Jun 2016 10:38:28 +0000 Subject: [PATCH] tvplanit: In WavDlg play sound asynchronously and add option to turn it off. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4746 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/source/vpbase.pas | 2 +- components/tvplanit/source/vpbaseds.pas | 3 ++- components/tvplanit/source/vpwavdlg.lfm | 2 ++ components/tvplanit/source/vpwavdlg.pas | 32 +++++++++++++++++++++---- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/components/tvplanit/source/vpbase.pas b/components/tvplanit/source/vpbase.pas index 56fdee706..20b9cc438 100644 --- a/components/tvplanit/source/vpbase.pas +++ b/components/tvplanit/source/vpbase.pas @@ -72,7 +72,7 @@ type TVpTimeFormat = (tf24Hour, tf12Hour); - TVpPlaySoundMode = (psmSync, psmASync); + TVpPlaySoundMode = (psmSync, psmAsync, psmStop); { XML definitions } DOMString = WideString; diff --git a/components/tvplanit/source/vpbaseds.pas b/components/tvplanit/source/vpbaseds.pas index 45cc4552c..7f09c1c77 100644 --- a/components/tvplanit/source/vpbaseds.pas +++ b/components/tvplanit/source/vpbaseds.pas @@ -892,7 +892,8 @@ begin {$IFDEF WINDOWS} case APlaySoundMode of psmSync : SndPlaySound(PChar(AWavFile), SND_SYNC); - psmASync : SndPlaySound(PChar(AWavFile), SND_ASYNC); + psmAsync : SndPlaySound(PChar(AWavFile), SND_ASYNC); + psmStop : SndPlaySound(nil, 0); end; {$ENDIF} end; diff --git a/components/tvplanit/source/vpwavdlg.lfm b/components/tvplanit/source/vpwavdlg.lfm index 57e76aaa8..44db520ce 100644 --- a/components/tvplanit/source/vpwavdlg.lfm +++ b/components/tvplanit/source/vpwavdlg.lfm @@ -102,6 +102,7 @@ object FrmSoundDialog: TFrmSoundDialog Caption = 'OkBtn' Default = True ModalResult = 1 + OnClick = OkBtnClick TabOrder = 0 end object CancelBtn: TButton @@ -113,6 +114,7 @@ object FrmSoundDialog: TFrmSoundDialog Cancel = True Caption = 'CancelBtn' ModalResult = 2 + OnClick = CancelBtnClick TabOrder = 1 end end diff --git a/components/tvplanit/source/vpwavdlg.pas b/components/tvplanit/source/vpwavdlg.pas index 415df892d..ddc6ca6fe 100644 --- a/components/tvplanit/source/vpwavdlg.pas +++ b/components/tvplanit/source/vpwavdlg.pas @@ -62,12 +62,16 @@ type CBDefault: TCheckBox; OkBtn: TButton; CancelBtn: TButton; + procedure CancelBtnClick(Sender: TObject); procedure CBDefaultClick(Sender: TObject); procedure FormCreate(Sender: TObject); + procedure OkBtnClick(Sender: TObject); procedure PlayButtonClick(Sender: TObject); private FOnPlaySound: TVpPlaySoundEvent; function FindFileItem(AFilename: String): TListItem; + procedure PlaySound; + procedure StopSound; public DingPath: string; MediaFolder: String; @@ -88,6 +92,11 @@ uses {$R *.dfm} {$ENDIF} +procedure TFrmSoundDialog.CancelBtnClick(Sender: TObject); +begin + StopSound; +end; + procedure TFrmSoundDialog.CBDefaultClick(Sender: TObject); begin ShellTreeview.Visible := not CBDefault.Checked; @@ -126,17 +135,24 @@ begin Result := ''; end; +procedure TFrmSoundDialog.OkBtnClick(Sender: TObject); +begin + StopSound; +end; + procedure TFrmSoundDialog.PlayButtonClick(Sender: TObject); begin DingPath := GetSelectedFileName; - if Assigned(FOnPlaySound) then begin - PlayButton.Enabled := false; - FOnPlaySound(self, DingPath, psmSync); - PlayButton.Enabled := true; - end; + PlaySound; end; {=====} +procedure TFrmSoundDialog.PlaySound; +begin + if Assigned(FOnPlaySound) then + FOnPlaySound(self, DingPath, psmAsync); +end; + procedure TFrmSoundDialog.Populate; begin TabSheet1.Caption := RSSelectASound; @@ -160,5 +176,11 @@ begin end; {=====} +procedure TFrmSoundDialog.StopSound; +begin + if Assigned(FOnPlaySound) then + FOnPlaySound(self, '', psmStop); +end; + end.