RxFPC:new property TRxPopupNotifier.MessageCorner

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6343 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2018-04-23 08:59:59 +00:00
parent 9abd5d704b
commit d5ee38b712
5 changed files with 202 additions and 27 deletions

View File

@ -6,7 +6,7 @@
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/> <MainUnit Value="0"/>
<AutoCreateForms Value="False"/> <AutoCreateForms Value="False"/>
<Title Value="project1"/> <Title Value="RxPopupNotifier demo"/>
<Scaled Value="True"/> <Scaled Value="True"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>

View File

@ -12,6 +12,7 @@ uses
{$R *.res} {$R *.res}
begin begin
Application.Title:='RxPopupNotifier demo';
RequireDerivedFormResource:=True; RequireDerivedFormResource:=True;
Application.Scaled:=True; Application.Scaled:=True;
Application.Initialize; Application.Initialize;

View File

@ -3,61 +3,136 @@ object Form1: TForm1
Height = 381 Height = 381
Top = 449 Top = 449
Width = 577 Width = 577
Caption = 'Form1' Caption = 'RxPopupNotifier demo'
ClientHeight = 381 ClientHeight = 381
ClientWidth = 577 ClientWidth = 577
LCLVersion = '1.9.0.0' LCLVersion = '1.9.0.0'
object Button4: TButton object Button4: TButton
Left = 224 AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Button1
AnchorSideTop.Side = asrBottom
Left = 232
Height = 36 Height = 36
Top = 48 Top = 48
Width = 113 Width = 113
AutoSize = True AutoSize = True
BorderSpacing.Top = 6
Caption = 'Static message' Caption = 'Static message'
OnClick = Button4Click OnClick = Button4Click
TabOrder = 0 TabOrder = 0
end end
object Button5: TButton object Button5: TButton
Left = 216 AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Button4
AnchorSideTop.Side = asrBottom
Left = 225
Height = 36 Height = 36
Top = 96 Top = 90
Width = 127 Width = 127
AutoSize = True AutoSize = True
BorderSpacing.Top = 6
Caption = 'Dinamic message' Caption = 'Dinamic message'
OnClick = Button5Click OnClick = Button5Click
TabOrder = 1 TabOrder = 1
end end
object Button6: TButton object Button6: TButton
Left = 176 AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = ColorBox1
AnchorSideTop.Side = asrBottom
Left = 191
Height = 36 Height = 36
Top = 152 Top = 158
Width = 195 Width = 195
AutoSize = True AutoSize = True
BorderSpacing.Top = 6
Caption = 'Message without auto close' Caption = 'Message without auto close'
OnClick = Button6Click OnClick = Button6Click
TabOrder = 2 TabOrder = 2
end end
object Label1: TLabel object Label1: TLabel
Left = 384 AnchorSideTop.Control = Button4
AnchorSideTop.Side = asrBottom
Left = 416
Height = 20 Height = 20
Top = 112 Top = 90
Width = 34 Width = 147
Caption = 'Color' BorderSpacing.Around = 6
Caption = 'Dinamic message color'
ParentColor = False ParentColor = False
end end
object ColorBox1: TColorBox object ColorBox1: TColorBox
Left = 424 AnchorSideLeft.Control = Label1
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 422
Height = 36 Height = 36
Top = 96 Top = 116
Width = 100 Width = 149
Selected = clYellow Selected = clYellow
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
ItemHeight = 0 ItemHeight = 0
TabOrder = 3 TabOrder = 3
end end
object RadioGroup1: TRadioGroup
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 6
Height = 117
Top = 6
Width = 140
AutoFill = True
AutoSize = True
BorderSpacing.Around = 6
Caption = 'Message positon'
ChildSizing.LeftRightSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 96
ClientWidth = 138
ItemIndex = 3
Items.Strings = (
'rpcTopLeft'
'rpcTopRight'
'rpcBootomLeft'
'rpcBottomRight'
)
OnClick = RadioGroup1Click
TabOrder = 4
end
object Button1: TButton
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner
Left = 228
Height = 36
Top = 6
Width = 121
AutoSize = True
BorderSpacing.Top = 6
Caption = 'Design message'
OnClick = Button1Click
TabOrder = 5
end
object RxPopupNotifier1: TRxPopupNotifier object RxPopupNotifier1: TRxPopupNotifier
Items = <> Items = <
item
Active = False
Color = clAqua
Caption = 'Design message'
Message = 'Design time message'
end>
OnNotifiClick = RxPopupNotifier1NotifiClick OnNotifiClick = RxPopupNotifier1NotifiClick
Left = 56 Left = 176
Top = 38 Top = 16
end end
end end

View File

@ -13,15 +13,19 @@ type
{ TForm1 } { TForm1 }
TForm1 = class(TForm) TForm1 = class(TForm)
Button1: TButton;
Button4: TButton; Button4: TButton;
Button5: TButton; Button5: TButton;
Button6: TButton; Button6: TButton;
ColorBox1: TColorBox; ColorBox1: TColorBox;
Label1: TLabel; Label1: TLabel;
RadioGroup1: TRadioGroup;
RxPopupNotifier1: TRxPopupNotifier; RxPopupNotifier1: TRxPopupNotifier;
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject); procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject); procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject); procedure Button6Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure RxPopupNotifier1NotifiClick(Sender: TRxPopupNotifier; procedure RxPopupNotifier1NotifiClick(Sender: TRxPopupNotifier;
AItem: TRxPopupNotifierItem); AItem: TRxPopupNotifierItem);
private private
@ -49,6 +53,18 @@ begin
FR:=RxPopupNotifier1.AddNotifyItem('Information', 'Static text information'); FR:=RxPopupNotifier1.AddNotifyItem('Information', 'Static text information');
end; end;
procedure TForm1.Button1Click(Sender: TObject);
var
R: TRxPopupNotifierItem;
begin
if RxPopupNotifier1.Items.Count>0 then
begin
R:=RxPopupNotifier1.Items[0];
R.Active:=true;
end;
end;
procedure TForm1.Button5Click(Sender: TObject); procedure TForm1.Button5Click(Sender: TObject);
var var
R1: TRxPopupNotifierItem; R1: TRxPopupNotifierItem;
@ -70,6 +86,11 @@ begin
end end
end; end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
RxPopupNotifier1.MessageCorner:=TRxPopupNotifierCorner(RadioGroup1.ItemIndex);
end;
procedure TForm1.RxPopupNotifier1NotifiClick(Sender: TRxPopupNotifier; procedure TForm1.RxPopupNotifier1NotifiClick(Sender: TRxPopupNotifier;
AItem: TRxPopupNotifierItem); AItem: TRxPopupNotifierItem);
begin begin

View File

@ -42,6 +42,8 @@ type
TRxPopupNotifierItem = class; TRxPopupNotifierItem = class;
TRxPopupNotifier = class; TRxPopupNotifier = class;
TRxPopupNotifierState = (rpsInactive, rpsMaximazed, rpsShowing, rpsMinimized); TRxPopupNotifierState = (rpsInactive, rpsMaximazed, rpsShowing, rpsMinimized);
TRxPopupNotifierCorner = (rpcTopLeft, rpcTopRight, rpcBootomLeft, rpcBottomRight);
TRxPopupNotifierEvent = procedure(Sender:TRxPopupNotifier; AItem:TRxPopupNotifierItem) of object; TRxPopupNotifierEvent = procedure(Sender:TRxPopupNotifier; AItem:TRxPopupNotifierItem) of object;
{ TRxNotifierForm } { TRxNotifierForm }
@ -102,10 +104,13 @@ type
{ TNotifierCollection } { TNotifierCollection }
TNotifierCollection = class(TOwnedCollection) TNotifierCollection = class(TOwnedCollection)
private
function GetItems(AIndex: Integer): TRxPopupNotifierItem;
protected protected
procedure Update(Item: TCollectionItem); override; procedure Update(Item: TCollectionItem); override;
public public
constructor Create(AOwner: TPersistent); constructor Create(AOwner: TPersistent);
property Items[AIndex:Integer]:TRxPopupNotifierItem read GetItems; default;
end; end;
{ TRxPopupNotifier } { TRxPopupNotifier }
@ -118,6 +123,7 @@ type
FDefNotifierFormHeight: Cardinal; FDefNotifierFormHeight: Cardinal;
FDefNotifierFormWidth: Cardinal; FDefNotifierFormWidth: Cardinal;
FItems: TNotifierCollection; FItems: TNotifierCollection;
FMessageCorner: TRxPopupNotifierCorner;
FOnNotifiClick: TRxPopupNotifierEvent; FOnNotifiClick: TRxPopupNotifierEvent;
FTimer:TTimer; FTimer:TTimer;
procedure SetActive(AValue: boolean); procedure SetActive(AValue: boolean);
@ -137,6 +143,7 @@ type
published published
property Active:boolean read FActive write SetActive default True; property Active:boolean read FActive write SetActive default True;
property Items:TNotifierCollection read FItems write SetItems; property Items:TNotifierCollection read FItems write SetItems;
property MessageCorner:TRxPopupNotifierCorner read FMessageCorner write FMessageCorner default rpcBottomRight;
property DefaultColor:TColor read FDefaultColor write FDefaultColor default clYellow; property DefaultColor:TColor read FDefaultColor write FDefaultColor default clYellow;
property DefNotifierFormWidth:Cardinal read FDefNotifierFormWidth write FDefNotifierFormWidth default 0; property DefNotifierFormWidth:Cardinal read FDefNotifierFormWidth write FDefNotifierFormWidth default 0;
property DefNotifierFormHeight:Cardinal read FDefNotifierFormHeight write FDefNotifierFormHeight default 0; property DefNotifierFormHeight:Cardinal read FDefNotifierFormHeight write FDefNotifierFormHeight default 0;
@ -215,6 +222,11 @@ end;
{ TNotifierCollection } { TNotifierCollection }
function TNotifierCollection.GetItems(AIndex: Integer): TRxPopupNotifierItem;
begin
Result:=TRxPopupNotifierItem(GetItem(AIndex));
end;
procedure TNotifierCollection.Update(Item: TCollectionItem); procedure TNotifierCollection.Update(Item: TCollectionItem);
var var
FActive: Boolean; FActive: Boolean;
@ -301,8 +313,33 @@ begin
FNotifyForm:=TRxNotifierForm.CreateNotifierForm(Self); FNotifyForm:=TRxNotifierForm.CreateNotifierForm(Self);
FNotifyForm.Width:=TRxPopupNotifier(Collection.Owner).NotifierFormWidth; FNotifyForm.Width:=TRxPopupNotifier(Collection.Owner).NotifierFormWidth;
FNotifyForm.Height:=1; FNotifyForm.Height:=1;
FNotifyForm.Left:=Screen.Width - FNotifyForm.Width - 2;
FNotifyForm.Top:=Screen.Height - FNotifyForm.Height - 2; case TRxPopupNotifier(Collection.Owner).FMessageCorner of
rpcTopLeft:
begin
//TODO : доделать
FNotifyForm.Left := 2;
FNotifyForm.Top := 2;
end;
rpcTopRight:
begin
//TODO : доделать
FNotifyForm.Left := Screen.Width - FNotifyForm.Width - 2;
FNotifyForm.Top := 2;
end;
rpcBootomLeft:
begin
//TODO : доделать
FNotifyForm.Left := 2;
FNotifyForm.Top := Screen.Height - FNotifyForm.Height - 2;
end;
rpcBottomRight:
begin
FNotifyForm.Left:=Screen.Width - FNotifyForm.Width - 2;
FNotifyForm.Top:=Screen.Height - FNotifyForm.Height - 2;
end;
end;
FNotifyForm.BorderStyle:=bsNone; FNotifyForm.BorderStyle:=bsNone;
FNotifyForm.FormStyle:=fsStayOnTop; FNotifyForm.FormStyle:=fsStayOnTop;
FNotifyForm.ShowInTaskBar:=stNever; FNotifyForm.ShowInTaskBar:=stNever;
@ -329,7 +366,12 @@ begin
if (TRxPopupNotifier(Collection.Owner).NotifierFormHeight > FNotifyForm.Height) then if (TRxPopupNotifier(Collection.Owner).NotifierFormHeight > FNotifyForm.Height) then
begin begin
FNotifyForm.Height:=FNotifyForm.Height + 1; FNotifyForm.Height:=FNotifyForm.Height + 1;
FNotifyForm.Top:=ATop - FNotifyForm.Height; case TRxPopupNotifier(Collection.Owner).FMessageCorner of
//rpcTopLeft:;
//rpcTopRight:;
rpcBootomLeft:FNotifyForm.Top:=ATop - FNotifyForm.Height;
rpcBottomRight:FNotifyForm.Top:=ATop - FNotifyForm.Height;
end;
end end
else else
begin begin
@ -343,13 +385,21 @@ begin
if (FNotifyForm.Height > 1) then if (FNotifyForm.Height > 1) then
begin begin
FNotifyForm.Height:=FNotifyForm.Height - 1; FNotifyForm.Height:=FNotifyForm.Height - 1;
FNotifyForm.Top:=ATop - FNotifyForm.Height; case TRxPopupNotifier(Collection.Owner).FMessageCorner of
//rpcTopLeft:;
//rpcTopRight:;
rpcBootomLeft:FNotifyForm.Top:=ATop - FNotifyForm.Height;
rpcBottomRight:FNotifyForm.Top:=ATop - FNotifyForm.Height;
end;
end end
else else
FState:=rpsInactive; FState:=rpsInactive;
end; end;
ATop:=ATop - FNotifyForm.Height;
ATop:=ATop - 2; if TRxPopupNotifier(Collection.Owner).FMessageCorner in [rpcTopLeft, rpcTopRight] then
ATop:=ATop + FNotifyForm.Height + 2
else
ATop:=ATop - FNotifyForm.Height - 2;
end; end;
end; end;
@ -357,8 +407,20 @@ procedure TRxPopupNotifierItem.UpdateFormPosition(var ATop: integer);
begin begin
if Assigned(FNotifyForm) then if Assigned(FNotifyForm) then
begin begin
FNotifyForm.Top:=ATop - FNotifyForm.Height; case TRxPopupNotifier(Collection.Owner).FMessageCorner of
ATop:=ATop - FNotifyForm.Height - 2; rpcTopLeft,
rpcTopRight:
begin
FNotifyForm.Top:=ATop;
ATop:=ATop + FNotifyForm.Height + 2;
end;
rpcBootomLeft,
rpcBottomRight:
begin
FNotifyForm.Top:=ATop - FNotifyForm.Height;
ATop:=ATop - FNotifyForm.Height - 2;
end;
end;
end; end;
end; end;
@ -398,7 +460,11 @@ var
Y, i: Integer; Y, i: Integer;
FReposition: Boolean; FReposition: Boolean;
begin begin
Y:=Screen.Height - 2; if FMessageCorner in [rpcTopLeft, rpcTopRight] then
Y:=2
else
Y:=Screen.Height - 2;
FReposition:=false; FReposition:=false;
for i:=FItems.Count - 1 downto 0 do for i:=FItems.Count - 1 downto 0 do
begin begin
@ -417,7 +483,18 @@ begin
if FReposition then if FReposition then
F.UpdateFormPosition(Y) F.UpdateFormPosition(Y)
else else
Y:=Y - F.FNotifyForm.Height - 2; begin
if FMessageCorner in [rpcTopLeft, rpcTopRight] then
Y:=Y + F.FNotifyForm.Height + 2
else
Y:=Y - F.FNotifyForm.Height - 2;
end;
if Y<0 then
Y:=2
else
if Y>Screen.Height then
Y:=Screen.Height - 2;
end; end;
end; end;
end; end;
@ -480,6 +557,7 @@ begin
inherited Create(AOwner); inherited Create(AOwner);
FDefaultColor:=clYellow; FDefaultColor:=clYellow;
FCloseInterval:=5; FCloseInterval:=5;
FMessageCorner:=rpcBottomRight;
FActive:=true; FActive:=true;
FItems:=TNotifierCollection.Create(Self); FItems:=TNotifierCollection.Create(Self);
FTimer:=TTimer.Create(Self); FTimer:=TTimer.Create(Self);