1 | /*
|
---|
2 | * Copyright (C) 1997-2001 Andrei Los.
|
---|
3 | * Based on a sample XWorkplace widget by Ulrich Mller
|
---|
4 | * This file is part of the lSwitcher source package.
|
---|
5 | * lSwitcher is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published
|
---|
7 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
8 | * "COPYING" file of the lSwitcher main distribution.
|
---|
9 | * This program is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | /*
|
---|
16 | * Any XCenter widget plugin DLL must export the
|
---|
17 | * following procedures by ordinal:
|
---|
18 | *
|
---|
19 | * -- Ordinal 1 (WgtInitModule): this must
|
---|
20 | * return the widgets which this DLL provides.
|
---|
21 | *
|
---|
22 | * -- Ordinal 2 (WgtUnInitModule): this must
|
---|
23 | * clean up global DLL data.
|
---|
24 | *
|
---|
25 | * Unless you start your own threads in your widget,
|
---|
26 | * you can safely compile the widget with the VAC
|
---|
27 | * subsystem libraries to reduce the DLL's size.
|
---|
28 | * You can also import functions from XFLDR.DLL
|
---|
29 | * to avoid code duplication.
|
---|
30 | *
|
---|
31 | * This is all new with V0.9.7.
|
---|
32 | *
|
---|
33 | *@@added V0.9.7 (2000-12-31) [umoeller]
|
---|
34 | *@@header "shared\center.h"
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <string.h>
|
---|
38 | #include <stdlib.h>
|
---|
39 |
|
---|
40 | #include "lswitch.h"
|
---|
41 | #include "common.h"
|
---|
42 | #include "taskbar.h"
|
---|
43 | #include "settings.h"
|
---|
44 | #include "prmdlg.h"
|
---|
45 |
|
---|
46 | // XWorkplace implementation headers
|
---|
47 | #include "center.h" // public XCenter interfaces
|
---|
48 |
|
---|
49 |
|
---|
50 | #define WNDCLASS_WIDGET_SAMPLE "XWPCenterlSwitcherWidget"
|
---|
51 |
|
---|
52 | VOID EXPENTRY lswShowSettings(PWIDGETSETTINGSDLGDATA pData);
|
---|
53 |
|
---|
54 | static XCENTERWIDGETCLASS G_WidgetClasses[] = {
|
---|
55 | LSWTASKBARCLASS, // PM window class name
|
---|
56 | 0, // additional flag, not used here
|
---|
57 | "lswWidget", // internal widget class name
|
---|
58 | "lSwitcher", // widget class name displayed to user
|
---|
59 | WGTF_UNIQUEPERXCENTER, // widget class flags
|
---|
60 | NULL//lswShowSettings // no settings dialog
|
---|
61 | };
|
---|
62 |
|
---|
63 |
|
---|
64 | //global variable used by lSwitcher code
|
---|
65 | //to be used during the popup window initialization
|
---|
66 | PXCENTERWIDGET pWidget;
|
---|
67 | //the widget DLL module handle
|
---|
68 | HMODULE hmodWidgetDll;
|
---|
69 |
|
---|
70 |
|
---|
71 | /* ******************************************************************
|
---|
72 | *
|
---|
73 | * Callbacks stored in XCENTERWIDGETCLASS
|
---|
74 | *
|
---|
75 | ********************************************************************/
|
---|
76 |
|
---|
77 | /*
|
---|
78 | *@@ WwgtShowSettingsDlg:
|
---|
79 | * this displays the winlist widget's settings
|
---|
80 | * dialog.
|
---|
81 | *
|
---|
82 | * This procedure's address is stored in
|
---|
83 | * XCENTERWIDGET so that the XCenter knows that
|
---|
84 | * we can do this.
|
---|
85 | *
|
---|
86 | * When calling this function, the XCenter expects
|
---|
87 | * it to display a modal dialog and not return
|
---|
88 | * until the dialog is destroyed. While the dialog
|
---|
89 | * is displaying, it would be nice to have the
|
---|
90 | * widget dynamically update itself.
|
---|
91 | */
|
---|
92 |
|
---|
93 | VOID EXPENTRY lswShowSettings(PWIDGETSETTINGSDLGDATA pData)
|
---|
94 | {
|
---|
95 | /* HWND hwnd = WinLoadDlg(HWND_DESKTOP, // parent
|
---|
96 | pData->hwndOwner,
|
---|
97 | fnwpSettingsDlg,
|
---|
98 | pcmnQueryNLSModuleHandle(FALSE),
|
---|
99 | ID_CRD_WINLISTWGT_SETTINGS,
|
---|
100 | // pass original setup string with WM_INITDLG
|
---|
101 | (PVOID)pData);
|
---|
102 | if (hwnd) {
|
---|
103 | pcmnSetControlsFont(hwnd,1, 10000);
|
---|
104 | WinProcessDlg(hwnd);
|
---|
105 | WinDestroyWindow(hwnd);
|
---|
106 | }*/
|
---|
107 | WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, ParmDlgProc,
|
---|
108 | hmodWidgetDll, DLG_PARAMS, (PLSWDATA)pWidget->pUser);
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* ******************************************************************
|
---|
112 | *
|
---|
113 | * Exported procedures
|
---|
114 | *
|
---|
115 | ********************************************************************/
|
---|
116 |
|
---|
117 | /*
|
---|
118 | *@@ WgtInitModule:
|
---|
119 | * required export with ordinal 1, which must tell
|
---|
120 | * the XCenter how many widgets this DLL provides,
|
---|
121 | * and give the XCenter an array of XCENTERWIDGETCLASS
|
---|
122 | * structures describing the widgets.
|
---|
123 | *
|
---|
124 | * With this call, you are given the module handle of
|
---|
125 | * XFLDR.DLL. For convenience, you may resolve imports
|
---|
126 | * for some useful functions which are exported thru
|
---|
127 | * src\shared\xwp.def. See the code below.
|
---|
128 | *
|
---|
129 | * This function must also register the PM window classes
|
---|
130 | * which are specified in the XCENTERWIDGETCLASS array
|
---|
131 | * entries. For this, you are given a HAB which you
|
---|
132 | * should pass to WinRegisterClass. For the window
|
---|
133 | * class style (4th param to WinRegisterClass),
|
---|
134 | * you should specify
|
---|
135 | *
|
---|
136 | + CS_PARENTCLIP | CS_SIZEREDRAW | CS_SYNCPAINT
|
---|
137 | *
|
---|
138 | * Your widget window _will_ be resized, even if you're
|
---|
139 | * not planning it to be.
|
---|
140 | *
|
---|
141 | * This function only gets called _once_ when the widget
|
---|
142 | * DLL has been successfully loaded by the XCenter. If
|
---|
143 | * there are several instances of a widget running (in
|
---|
144 | * the same or in several XCenters), this function does
|
---|
145 | * not get called again. However, since the XCenter unloads
|
---|
146 | * the widget DLLs again if they are no longer referenced
|
---|
147 | * by any XCenter, this might get called again when the
|
---|
148 | * DLL is re-loaded.
|
---|
149 | *
|
---|
150 | * There will ever be only one load occurence of the DLL.
|
---|
151 | * The XCenter manages sharing the DLL between several
|
---|
152 | * XCenters. As a result, it doesn't matter if the DLL
|
---|
153 | * has INITINSTANCE etc. set or not.
|
---|
154 | *
|
---|
155 | * If this returns 0, this is considered an error, and the
|
---|
156 | * DLL will be unloaded again immediately.
|
---|
157 | *
|
---|
158 | * If this returns any value > 0, *ppaClasses must be
|
---|
159 | * set to a static array (best placed in the DLL's
|
---|
160 | * global data) of XCENTERWIDGETCLASS structures,
|
---|
161 | * which must have as many entries as the return value.
|
---|
162 | */
|
---|
163 |
|
---|
164 | ULONG EXPENTRY WgtInitModule(HAB hab, // XCenter's anchor block
|
---|
165 | HMODULE hmodPlugin, // module handle of the widget DLL
|
---|
166 | HMODULE hmodXFLDR, // XFLDR.DLL module handle
|
---|
167 | PXCENTERWIDGETCLASS *ppaClasses,
|
---|
168 | PSZ pszErrorMsg) // if 0 is returned, 500 bytes of error msg
|
---|
169 | { PVOID pData;
|
---|
170 | PXCENTERWIDGET pWidget;
|
---|
171 | LONG lrc;
|
---|
172 |
|
---|
173 | if (queryAppInstance()) {
|
---|
174 | strcpy(pszErrorMsg, "lSwitcher is already loaded.");
|
---|
175 | return 0;
|
---|
176 | }
|
---|
177 |
|
---|
178 | hmodWidgetDll = hmodPlugin;
|
---|
179 |
|
---|
180 | pWidget = malloc(sizeof(XCENTERWIDGET));
|
---|
181 | if (pWidget == NULL) {
|
---|
182 | strcpy(pszErrorMsg,"Memory allocation error");
|
---|
183 | return 0;
|
---|
184 | }
|
---|
185 |
|
---|
186 | pWidget->pGlobals = NULL;
|
---|
187 |
|
---|
188 | pData = (PXCENTERWIDGET)pWidget;
|
---|
189 | lrc = SwitcherInit(hab, 0, pszErrorMsg, 500, &pData);
|
---|
190 | if (pData != NULL) SwitcherTerm((PLSWDATA)pData);
|
---|
191 | free(pWidget);
|
---|
192 |
|
---|
193 | if (lrc > 0) return 0;
|
---|
194 |
|
---|
195 | if (!WinRegisterClass(hab,LSWTASKBARCLASS,TaskBarWndProc,
|
---|
196 | CS_PARENTCLIP | CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPCHILDREN,sizeof(PXCENTERWIDGET))) {
|
---|
197 | strcpy(pszErrorMsg,"WinRegisterClass(lswTaskBarClass)");
|
---|
198 | return 0;
|
---|
199 | }
|
---|
200 |
|
---|
201 | *ppaClasses = G_WidgetClasses;
|
---|
202 | // return no. of classes in this DLL (one here):
|
---|
203 | return sizeof(G_WidgetClasses) / sizeof(G_WidgetClasses[0]);
|
---|
204 | }
|
---|
205 |
|
---|
206 | /*
|
---|
207 | *@@ WgtUnInitModule:
|
---|
208 | * optional export with ordinal 2, which can clean
|
---|
209 | * up global widget class data.
|
---|
210 | *
|
---|
211 | * This gets called by the XCenter right before
|
---|
212 | * a widget DLL gets unloaded. Note that this
|
---|
213 | * gets called even if the "init module" export
|
---|
214 | * returned 0 (meaning an error) and the DLL
|
---|
215 | * gets unloaded right away.
|
---|
216 | */
|
---|
217 |
|
---|
218 | VOID EXPENTRY WgtUnInitModule(VOID)
|
---|
219 | {
|
---|
220 | }
|
---|
221 |
|
---|
222 | /*
|
---|
223 | *@@ WgtQueryVersion:
|
---|
224 | * this new export with ordinal 3 can return the
|
---|
225 | * XWorkplace version number which is required
|
---|
226 | * for this widget to run. For example, if this
|
---|
227 | * returns 0.9.10, this widget will not run on
|
---|
228 | * earlier XWorkplace versions.
|
---|
229 | *
|
---|
230 | * NOTE: This export was mainly added because the
|
---|
231 | * prototype for the "Init" export was changed
|
---|
232 | * with V0.9.9. If this returns 0.9.9, it is
|
---|
233 | * assumed that the INIT export understands
|
---|
234 | * the new FNWGTINITMODULE_099 format (see center.h).
|
---|
235 | *
|
---|
236 | *@@added V0.9.9 (2001-02-06) [umoeller]
|
---|
237 | */
|
---|
238 |
|
---|
239 | VOID EXPENTRY WgtQueryVersion(PULONG pulMajor,
|
---|
240 | PULONG pulMinor,
|
---|
241 | PULONG pulRevision)
|
---|
242 | {
|
---|
243 | *pulMajor = 0;
|
---|
244 | *pulMinor = 9;
|
---|
245 | *pulRevision = 11;
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 |
|
---|