/
JvControlPanelButton.pas
200 lines (173 loc) · 5.11 KB
/
JvControlPanelButton.pas
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvControlPanel.PAS, released on 2001-02-28.
The Initial Developer of the Original Code is Sébastien Buysse [sbuysse att buypin dott com]
Portions created by Sébastien Buysse are Copyright (C) 2001 Sébastien Buysse.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
Peter Thörnqvist[peter3 at users dot sourceforge dot net]
Remko Bonte [remkobonte att myrealbox dott com]
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvControlPanelButton;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, Classes, Controls, Menus, ImgList,
JvTypes, JvButton, JvComputerInfoEx;
type
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvControlPanelButton = class(TJvCustomButton)
private
FPopup: TPopupMenu;
FDirs: TJvSystemFolders;
FOnLinkClick: TJvLinkClickEvent;
FImages: TCustomImageList;
procedure AddToPopup(Item: TMenuItem; Path: string);
procedure SetImages(const Value: TCustomImageList);
protected
procedure DoLinkClick(Sender: TObject);
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure Click; override;
procedure Refresh;
published
property Images: TCustomImageList read FImages write SetImages;
property OnLinkClick: TJvLinkClickEvent read FOnLinkClick write FOnLinkClick;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
Graphics,
JvJVCLUtils;
constructor TJvControlPanelButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDirs := TJvSystemFolders.Create;
FPopup := TPopupMenu.Create(Self);
end;
destructor TJvControlPanelButton.Destroy;
var
I: Integer;
begin
FDirs.Free;
if Images = nil then
for I := 0 to FPopup.Items.Count - 1 do
FPopup.Items[I].Bitmap.FreeImage;
FPopup.Free;
inherited Destroy;
end;
// (rom) a strange place for doing this
procedure TJvControlPanelButton.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if not (csDesigning in ComponentState) then
Refresh;
end;
procedure TJvControlPanelButton.AddToPopup(Item: TMenuItem; Path: string);
var
I: Integer;
It: TMenuItem;
S: TStringList;
B: TBitmap;
begin
S := TStringList.Create;
try
GetControlPanelApplets(Path, '*.cpl', S, Images);
S.Sort;
for I := 0 to S.Count - 1 do
begin
It := TMenuItem.Create(Self);
It.Caption := S.Names[I];
It.OnClick := DoLinkClick;
It.Hint := S.Values[S.Names[I]];
if Images <> nil then
It.ImageIndex := Integer(S.Objects[I])
else
begin
B := TBitmap(S.Objects[I]);
It.Bitmap.Assign(B);
B.Free;
end;
Item.Add(It);
// (rom) seems of no use
//Application.ProcessMessages;
end;
finally
S.Free;
end;
end;
procedure TJvControlPanelButton.Click;
var
P: TPoint;
begin
inherited Click;
if Parent <> nil then
begin
P := Parent.ClientToScreen(Point(Left, Top + Height));
FPopup.Popup(P.X, P.Y);
end;
end;
procedure TJvControlPanelButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FImages) then
Images := nil; // (p3) calls Refresh
end;
procedure TJvControlPanelButton.Refresh;
var
St: string;
begin
while FPopup.Items.Count > 0 do
FPopup.Items.Delete(0);
St := FDirs.System;
if St[Length(St)] <> '\' then
St := St + '\';
FPopup.Images := Images;
AddToPopup(TMenuItem(FPopup.Items), St);
PopupMenu := FPopup;
end;
procedure TJvControlPanelButton.SetImages(const Value: TCustomImageList);
begin
if ReplaceComponentReference(Self, Value, TComponent(FImages)) then
Refresh;
end;
procedure TJvControlPanelButton.DoLinkClick(Sender: TObject);
begin
if Assigned(FOnLinkClick) then
FOnLinkClick(Self, (Sender as TMenuItem).Hint);
end;
{$IFDEF UNITVERSIONING}
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.