initial commit
[rofl0r-KOL.git] / controls / cplapplet / KOLCPLApplet.pas
blob49763fb8092c7fc2d4a31c6e72468dc6a6b6ba42
1 unit KOLCPLApplet;
2 {* TKOLCPLApplet object used with TKOLCPLProject to visually create CPL applets.
3 |<br>
4 Created for KOL by Bogus³aw Brandys.
7 interface
9 uses Messages, Windows, KOL;
12 const
13 WM_CPL_LAUNCH = (WM_USER+1000);
14 WM_CPL_LAUNCHED = (WM_USER+1001);
16 // The messages CPlApplet() must handle:
17 CPL_DYNAMIC_RES = 0;
18 { This constant may be used in place of real resource IDs for the idIcon,
19 idName or idInfo members of the CPLINFO structure. Normally, the system
20 uses these values to extract copies of the resources and store them in a
21 cache. Once the resource information is in the cache, the system does not
22 need to load a CPL unless the user actually tries to use it.
24 CPL_DYNAMIC_RES tells the system not to cache the resource, but instead to
25 load the CPL every time it needs to display information about an item. This
26 allows a CPL to dynamically decide what information will be displayed, but
27 is SIGNIFICANTLY SLOWER than displaying information from a cache.
28 Typically, CPL_DYNAMIC_RES is used when a control panel must inspect the
29 runtime status of some device in order to provide text or icons to display.
32 CPL_INIT = 1;
33 { This message is sent to indicate CPlApplet() was found. lParam1 and lParam2
34 are not defined. Return TRUE or FALSE indicating whether the control panel
35 should proceed.
38 CPL_GETCOUNT = 2;
39 { This message is sent to determine the number of applets to be displayed.
40 lParam1 and lParam2 are not defined. Return the number of applets you wish
41 to display in the control
42 panel window.
45 CPL_INQUIRE = 3;
46 { This message is sent for information about each applet. lParam1 is the
47 applet number to register, a value from 0 to(CPL_GETCOUNT - 1).
48 lParam2 is a far ptr to a CPLINFO structure. Fill in CPL_INFO's idIcon,
49 idName, idInfo and lData fields with the resource id for an icon to
50 display, name and description string ids, and a long data item
51 associated with applet #lParam1.
54 CPL_SELECT = 4;
55 { This message is sent when the applet's icon has been clicked upon.
56 lParam1 is the applet number which was selected. lParam2 is the
57 applet's lData value.
60 CPL_DBLCLK = 5;
61 { This message is sent when the applet's icon has been double-clicked
62 upon. lParam1 is the applet number which was selected. lParam2 is the
63 applet's lData value. This message should initiate the applet's dialog box.
66 CPL_STOP = 6;
67 { This message is sent for each applet when the control panel is exiting.
68 lParam1 is the applet number. lParam2 is the applet's lData value.
69 Do applet specific cleaning up here.
72 CPL_EXIT = 7;
73 { This message is sent just before the control panel calls FreeLibrary.
74 lParam1 and lParam2 are not defined.
75 Do non-applet specific cleaning up here.
78 CPL_NEWINQUIRE = 8;
79 { This is the same as CPL_INQUIRE execpt lParam2 is a pointer to a
80 NEWCPLINFO structure. this will be sent before the CPL_INQUIRE
81 and if it is responed to (return != 0) CPL_INQUIRE will not be sent
84 CPL_STARTWPARMS = 9;
85 { This message parallels CPL_DBLCLK in that the applet should initiate
86 its dialog box. where it differs is that this invocation is coming
87 out of RUNDLL, and there may be some extra directions for execution.
88 lParam1: the applet number.
89 lParam2: an LPSTR to any extra directions that might exist.
90 returns: TRUE if the message was handled; FALSE if not.
93 CPL_SETUP = 200;
94 { This message is internal to the Control Panel and MAIN applets.
95 It is only sent when an applet is invoked from the Command line
96 during system installation.
99 type
100 TKOLCPLProject = Pointer;
102 //The data structure CPlApplet() must fill in.
103 PCPLInfo = ^TCPLInfo;
104 tagCPLINFO = packed record
105 idIcon: Integer; // icon resource id, provided by CPlApplet()
106 idName: Integer; // name string res. id, provided by CPlApplet()
107 idInfo: Integer; // info string res. id, provided by CPlApplet()
108 lData : Longint; // user defined data
109 end;
112 CPLINFO = tagCPLINFO;
113 TCPLInfo = tagCPLINFO;
116 PNewCPLInfoA = ^TNewCPLInfoA;
117 PNewCPLInfo = PNewCPLInfoA;
118 tagNEWCPLINFOA = packed record
119 dwSize: DWORD; // similar to the commdlg
120 dwFlags: DWORD;
121 dwHelpContext: DWORD; // help context to use
122 lData: Longint; // user defined data
123 hIcon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
124 szName: array[0..31] of AnsiChar; // short name
125 szInfo: array[0..63] of AnsiChar; // long name (status line)
126 szHelpFile: array[0..127] of AnsiChar; // path to help file to use
127 end;
129 tagNEWCPLINFO = tagNEWCPLINFOA;
130 NEWCPLINFOA = tagNEWCPLINFOA;
131 NEWCPLINFO = NEWCPLINFOA;
132 TNewCPLInfoA = tagNEWCPLINFOA;
133 TNewCPLInfo = TNewCPLInfoA;
136 TCPLExit = procedure of object;
138 TCPLInit = procedure (var Initiate : Boolean) of object;
140 TCPLSel = procedure (Number : Longint; Data : Longint) of object;
142 TCPLParams = procedure (Number : Longint; Params : PChar; var Handle : Boolean) of object;
144 TCPLStart = procedure (Number : Longint; var NewCPLInfo: TNewCPLInfo) of object;
149 PKOLCPLApplet =^TKOLCPLApplet;
150 TKOLCPLApplet = object(TObj)
152 private
153 fOnInit : TCPLInit;
154 fOnSelect,fOnExecute,fOnStop : TCPLSel;
155 fOnStart : TCPLStart;
156 fOnParams : TCPLParams;
157 fOnExit : TCPLExit;
158 fIconList : PList;
159 protected
160 public
161 destructor Destroy;virtual;
163 procedure AddIcon(IconRes,Name,InfoTip,Help : String; Data,HelpCtx : Integer);
164 {* Adds applet (icon,necessary name,description,name of help file
165 and help context and simple data sent to applet) to internal object applet's list}
166 property IconList : PList read fIconList write fIconList;
167 {* Low level access to applets list}
168 property OnInit : TCPLInit read fOnInit write fOnInit;
169 {* Initialize ALL applets. If Initiate = False applets are not loaded}
170 property OnSelect : TCPLSel read fOnSelect write fOnSelect;
171 {* Seems not working at all (CPL_SELECT is not invoked by system)}
172 property OnExecute : TCPLSel read fOnExecute write fOnExecute;
173 {* When user double-click applet icon}
174 property OnStart : TCPLStart read fOnStart write fOnStart;
175 {* After applet icon is created}
176 property OnStop : TCPLSel read fOnStop write fOnStop;
177 {* Put applet cleaning here }
178 property OnParams : TCPLParams read fOnParams write fOnParams;
179 {* When applet is invoked by rundll with params}
180 property OnExit: TCPLExit read fOnExit write fOnExit;
181 {* Just before control panel detach applet's library }
182 end;
185 function NewCPLApplet: PKOLCPLApplet;
186 function Run(hWndCpl: HWnd; Msg: Word; lParam: longint; var NewCPLInfo: TNewCPLInfo): longint;stdcall;
189 CplObj : PKOLCPLApplet;
192 implementation
194 destructor TKOLCPLApplet.Destroy;
196 CPLInfo : PNewCPLInfo;
197 i : Integer;
198 begin
199 for i:=0 to fIconList.Count-1 do begin
200 CPLInfo := PNewCPLInfo(fIconList.Items[i]);
201 // DestroyIcon(CPLInfo.hIcon);
202 Dispose(CPLInfo);
203 fIconList.Delete(i);
204 end;
205 fIconList.Free;
206 inherited;
207 end;
209 procedure TKOLCPLApplet.AddIcon(IconRes,Name,InfoTip,Help : String; Data,HelpCtx : Integer);
211 CPLInfo : PNewCPLInfo;
212 begin
213 New(CPLInfo);
214 with CPLInfo^ do begin
215 dwSize := sizeof(TNewCPLInfo);
216 dwFlags := 0;
217 dwHelpContext := HelpCtx;
218 lData := Data;
219 hIcon := LoadIcon(hInstance,PChar(UpperCase(IconRes)));
220 StrPCopy(szName,Name);
221 StrPCopy(szInfo,InfoTip);
222 StrPCopy(szHelpFile,Help);
223 end;
224 fIconList.Add(CPLInfo);
225 end;
229 function NewCPLApplet;
230 begin
231 New(Result, Create);
232 CplObj := Result;
233 Result.fIconList := NewList;
234 end;
236 function Run(hWndCpl: HWnd; Msg: Word; lParam: longint; var NewCPLInfo: TNewCPLInfo): longint;stdcall;
238 i : Boolean;
239 CPLInfo : PNewCPLInfo;
241 begin
243 Result := 0;
245 case msg of
246 CPL_INIT: begin
247 i := True;
248 Applet := NewApplet('');
249 Applet.Visible := False;
250 if Assigned(CplObj.OnInit) then CplObj.OnInit(i);
251 Result := Integer(i);
252 end;
254 CPL_GETCOUNT:
255 begin
256 Result := CplObj.fIconList.Count;
257 end;
260 CPL_NEWINQUIRE:begin
261 CPLInfo := PNewCPLInfo(CplObj.fIconList.Items[lParam]);
262 NewCPLInfo.dwSize := sizeof(TNewCPLInfo);
263 NewCPLInfo.dwFlags := 0;
264 NewCPLInfo.dwHelpContext := CPLInfo.dwHelpContext;
265 NewCPLInfo.lData := CPLInfo.lData;
266 NewCPLInfo.hIcon := CPLInfo.hIcon;
267 StrCopy(NewCPLInfo.szName,CPLInfo.szName);
268 StrCopy(NewCPLInfo.szInfo,CPLInfo.szInfo);
269 StrCopy(NewCPLInfo.szHelpFile,CPLInfo.szHelpFile);
270 if Assigned(CplObj.OnStart) then CplObj.OnStart(lParam,NewCPLInfo);
271 end;
273 CPL_STARTWPARMS:begin
274 i := True;
275 if Assigned(CplObj.OnParams) then
276 CplObj.OnParams(lParam,PChar(@NewCPLInfo),i);
277 Result := Integer(i);
278 end;
280 CPL_DBLCLK:
281 if Assigned(CplObj.OnExecute) then
282 CplObj.OnExecute(lParam,Longint(@NewCPLInfo));
285 CPL_SELECT:
286 if Assigned(CplObj.OnSelect) then
287 CplObj.OnSelect(lParam,Longint(@NewCPlInfo));
289 CPL_STOP:
290 if Assigned(CplObj.OnStop) then
291 CplObj.OnStop(lParam,Longint(@NewCPlInfo));
294 CPL_EXIT:
295 begin
296 if Assigned(CplObj.OnExit) then CplObj.OnExit;
297 Applet.Free;
298 end;
301 end;
302 end;
305 end.