-
Notifications
You must be signed in to change notification settings - Fork 0
/
G16UIWin.c
385 lines (301 loc) · 8.63 KB
/
G16UIWin.c
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
//-------------------------------------------------------------------------------
//
// G16 BMP File Format plugin for Photoshop 5.0+
// Copyright © 2004 neai.o2.pl
//
//-------------------------------------------------------------------------------
//
// File: G16UIWin.c
//
// Copyright © 1993-1997, Adobe Systems Incorporated.
// All rights reserved.
//
// C source file for MS-Windows specific code for G16 Plug-In
//
//-------------------------------------------------------------------------------
#include "G16.h"
#include "WinDialogUtils.h"
/*****************************************************************************/
char* its( int32 i )
{
static char s[33];
ltoa(i, s, 10);
return s;
}
int32 sti( char* s )
{
return atoi(s);
}
/*****************************************************************************/
void DoAbout (AboutRecordPtr about)
{
ShowAbout(about, hDllInstance, AboutID);
}
/*****************************************************************************/
/* Initialization and termination code for window's dlls. */
#ifdef WIN32
BOOL APIENTRY DLLInit(HANDLE hInstance, DWORD fdwReason, LPVOID lpReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
hDllInstance = hInstance;
return TRUE; // Indicate that the DLL was initialized successfully.
}
#else
// Code from Borland's window's dll example code.
#if defined(__BORLANDC__)
// Turn off warning: Parameter '' is never used; effects next function only
#pragma argsused
#endif
// Every DLL has an entry point LibMain and an exit point WEP.
int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
WORD wHeapSize, LPSTR lpszCmdLine )
{
// Required when using Zortech; causes blink to include startup code
extern __acrtused_dll;
// The startup code for the DLL initializes the local heap (if there is one)
// with a call to LocalInit which locks the data segment.
if ( wHeapSize != 0 )
UnlockData( 0 );
hDllInstance = hInstance;
return 1; // Indicate that the DLL was initialized successfully.
}
int FAR PASCAL WEP(int nParam)
{
switch (nParam) {
case WEP_SYSTEM_EXIT: // System shutdown in progress
case WEP_FREE_DLL : // DLL use count is 0
default : // Undefined; ignore
return 1;
}
}
#endif //ifdef WIN32
/*****************************************************************************/
#ifdef USE_DIALOG
#include "commctrl.h"
#define STATE_IDLE 0
#define STATE_AGAIN 1
#define STATE_CANCEL -1
short state = STATE_IDLE;
/*****************************************************************************/
void SetItemIdx ( LV_ITEM Item, int ItemIdx, int SubItemIdx )
{
Item.iItem = ItemIdx; //
Item.iSubItem = SubItemIdx; //
}
#define ListView_InsertItemText(hwnd, pitem, ItemIdx, SubItemIdx, ItemTxt) \
(pitem).iItem = (ItemIdx);\
(pitem).iSubItem = (SubItemIdx);\
(pitem).pszText = (ItemTxt);\
ListView_InsertItem((hwnd),&(pitem))
#define ListView_SetPair(hwnd, pitem, ItemIdx, ItemTxt, SubItemTxt) \
(pitem).iItem = (ItemIdx);\
(pitem).iSubItem = 0;\
(pitem).pszText = (ItemTxt);\
ListView_InsertItem((hwnd),&(pitem));\
ListView_SetItemText((hwnd), (ItemIdx),1,(SubItemTxt))
int32 ListView_ReadInt( HWND hwnd, int iItem, int iSubItem )
{
Str255 buf;
ListView_GetItemText(hwnd,iItem,iSubItem,buf,255);
return sti(buf);
}
/*****************************************************************************/
BOOL WINAPI LVProc(HWND hList, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
switch (wMsg)
{
case WM_CHAR:
{
// pass on keyboard input to the parent
SendMessage(GetParent(hList), wMsg, wParam, lParam);
break;
}
case WM_LBUTTONDOWN:
{
// single-click editing
LV_HITTESTINFO hti;
memset(&hti, 0, sizeof(hti));
hti.pt.x = LOWORD(lParam);
hti.pt.y = HIWORD(lParam);
if( ListView_HitTest(hList,&hti) != -1 )
{
SetFocus(hList);
ListView_EditLabel(hList,hti.iItem);
}
return 0;
}
case WM_LBUTTONDBLCLK:
{
// treat the double-click as another single click
SendMessage(hList, WM_LBUTTONDOWN, wParam, lParam);
return 0;
}
}
// pass the message on to the original window procedure
return CallWindowProc(LVProcPrev, hList, wMsg, wParam, lParam);
}
/*****************************************************************************/
BOOL WINAPI UIProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
static GPtr globals = NULL; // need to be static
switch (wMsg)
{
case WM_INITDIALOG:
{
LV_ITEM LvItem;
LV_COLUMN LstColVal, LstColProp;
int i;
CenterDialog(hDlg);
// set up globals
globals = (GPtr) lParam;
gList = GetDlgItem(hDlg,1011); // get the ID of the ListView
LVProcPrev = (WNDPROC)SetWindowLong(gList, GWL_WNDPROC, (DWORD)LVProc);
// Here we put the info on the Column headers
// this is not data, only name of each header we like
memset(&LstColVal,0,sizeof(LstColVal)); // Reset Column
LstColVal.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_ORDER; // Type of mask
LstColVal.cx = 0x64; // width between each coloum
LstColVal.pszText = "Value"; //
LstColVal.iOrder = 1; // put editable field on right side
LstColProp = LstColVal;
LstColProp.pszText = "Property";
LstColProp.iOrder = 0;
// Inserting Columns as much as we want
ListView_InsertColumn(gList, 0, &LstColVal);
ListView_InsertColumn(gList, 1, &LstColProp);
// Setting common properties Of Items:
memset(&LvItem,0,sizeof(LvItem)); // Reset Item Struct
LvItem.mask = LVIF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; // Text Style
LvItem.cchTextMax = 256; // Max size of test
// allocate mem for items
ListView_SetItemCount(gList, PI_MAX);
// insert items
for(i=0; i<PI_MAX; i++)
{
ListView_SetPair(gList, LvItem, i,its(gIntProps[i].value), gIntProps[i].name );
}
ShowWindow(hDlg,SW_NORMAL);
UpdateWindow(hDlg);
return FALSE;
}
case WM_NOTIFY:
{
switch( ((LPNMHDR)lParam)->code )
{
case LVN_BEGINLABELEDIT:
{
break;
}
case LVN_ENDLABELEDIT:
{
int iIndex;
char tempstr[255]="";
HWND hEdit;
iIndex = ListView_GetNextItem(gList,-1,LVNI_FOCUSED);
if( iIndex != - 1 )
{
//save to list
hEdit = ListView_GetEditControl(gList);
GetWindowText(hEdit, tempstr, sizeof(tempstr));
ListView_SetItemText(gList, iIndex,0,tempstr);
//save to globals
gIntProps[iIndex].value = ListView_ReadInt(gList, iIndex, 0);
}
break;
}
}
break;
}
case WM_COMMAND:
{
int item;
int cmd;
item = COMMANDID (wParam); // WIN32 Change
cmd = HIWORD(wParam);
switch (item)
{
case ok:
if (cmd == BN_CLICKED)
state = STATE_AGAIN;
break;
case cancel:
if (cmd == BN_CLICKED)
state = STATE_CANCEL;
break;
}
return FALSE;
}
}
return FALSE;
}
/*****************************************************************************/
/* Setup the parameters dialog. Returns TRUE if it succeeds. */
Boolean DialogOpen( GPtr globals )
{
PlatformData *platform;
state = STATE_IDLE;
if (gDialog != NULL)
{
SetActiveWindow (gDialog); // set the dialog window the active window
return TRUE;
}
else
{
// dialog not created yet. Do it.
platform = ((FormatRecordPtr)gStuff)->platformData;
gDialog = CreateDialogParam(hDllInstance,
(LPSTR)"TESTDIALOG",
(HWND)platform->hwnd,
(DLGPROC)UIProc, // FARPROC
(LPARAM)globals);
if (gDialog)
{
// got it. Show it.
ShowWindow(gDialog, SW_NORMAL);
UpdateWindow(gDialog);
return TRUE;
}
else // lost it.
return FALSE; // Couldnt put up the dialog box
}
}
/*****************************************************************************/
// Run the parameters dialog. Returns TRUE if it succeeds.
Boolean DialogRun (GPtr globals)
{
MSG msg;
// We are basically waiting for user to press "OK" or "Cancel" from the dialog
while (GetMessage((LPMSG)&msg, NULL, 0, 0))
{
if (!IsDialogMessage((HWND)gDialog, &msg))
{
// wasn't for our dialog. Send it on its way.
TranslateMessage((LPMSG)&msg);
DispatchMessage ((LPMSG)&msg);
}
// state is set in UIProc based on the user response
// The only way this function would return is by the user responding with
// either pressing the "OK" or the "Cancel" button
if (state == STATE_AGAIN)
{
return TRUE;
}
else if (state == STATE_CANCEL)
{
return FALSE;
}
}
return FALSE;
}
/*****************************************************************************/
/* Close the parameters dialog. */
void DialogClose (GPtr globals)
{
if (gDialog != NULL)
{
DestroyWindow(gDialog);
gDialog = NULL;
}
}
#endif //ifdef USE_DIALOG
/*****************************************************************************/