Menu

[r3207]: / trunk / Src / Notifications.UDisplayMgr.pas  Maximize  Restore  History

Download this file

115 lines (92 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a static object that manages the notification display sub-system.
}
unit Notifications.UDisplayMgr;
interface
uses
// Delphi
Controls,
// Project
Notifications.UDisplayThread, Notifications.UWindow, UBaseObjects;
type
/// <summary>Static class that manages the notification display sub-system.
/// </summary>
/// <remarks>This class manages the background thread that reads the
/// notification queue and displays the notifications sequentially in a
/// suitable pop-up window.</remarks>
TNotificationDisplayMgr = class(TNoConstructObject)
strict private
const
/// <summary>Amount of time the notification window is displayed on
/// screen before hiding itself.</summary>
WindowDisplayTime = 20 * 1000; // 20 seconds
class var
/// <summary>Notification window object.</summary>
fWindow: TNotificationWindow;
/// <summary>Thread that reads the notification queue and displays the
/// notifications sequentially in the notification window.
/// </summary>
fDisplayThread: TNotificationDisplayThread;
public
/// <summary>Class destructor. Ensures the noification window and display
/// thread are destroyed when the program closes.</summary>
class destructor Destroy;
/// <summary>Starts the notification display sub-system.</summary>
/// <param name="WindowParent">TWinControl [in] Window control that is to
/// be the parent of the notification window. Must not be nil.</param>
/// <remarks>Creates a new notification window object and a linked display
/// thread.</remarks>
class procedure Start(const WindowParent: TWinControl);
/// <summary>Stops the notification display sub-system.</summary>
/// <remarks>The display thread and notification window are destroyed.
/// </remarks>
class procedure Stop;
end;
implementation
uses
SysUtils, Classes,
// Project
Notifications.UData, Notifications.UQueue;
{ TNotificationDisplayMgr }
class destructor TNotificationDisplayMgr.Destroy;
begin
Stop;
end;
class procedure TNotificationDisplayMgr.Start(const WindowParent: TWinControl);
begin
Assert(Assigned(WindowParent), ClassName + '.Start: WindowParent is nil');
if Assigned(fWindow) or Assigned(fDisplayThread) then
Stop;
fWindow := TNotificationWindow.Create(nil);
fWindow.Parent := WindowParent;
fWindow.DisplayTime := WindowDisplayTime;
fDisplayThread := TNotificationDisplayThread.Create(
fWindow.DisplayLock,
procedure(N: TNotificationData)
begin
Assert(fWindow.State = nwsClosed,
ClassName + '.Create:AnonCallback: Window not closed');
fWindow.SlideIn(N);
end
);
fDisplayThread.FreeOnTerminate := False;
fDisplayThread.Priority := tpLowest;
fDisplayThread.Start;
end;
class procedure TNotificationDisplayMgr.Stop;
begin
// FreeAndNil is necessary here
TNotificationQueue.ReleaseLocks;
FreeAndNil(fDisplayThread);
FreeAndNil(fWindow);
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.