|
|
1.1 root 1: /*
2: * dialog.c - Handles the Windows 3.1 common dialogs.
3: *
4: * Created by Microsoft Corporation.
5: * (c) Copyright Microsoft Corp. 1990 - 1992 All Rights Reserved
6: */
7:
8: //*** INCLUDES ****
9:
10: #include <windows.h> //* WINDOWS
11: #include <ole.h> //* OLE
12:
1.1.1.3 ! root 13: #include "global.h" //* global
! 14: #include "demorc.h" //* String table constants
1.1 root 15: #include "register.h" //* Class registration library
16: #include "utility.h"
17: #include "dialog.h"
18: #include "object.h"
19:
20: //*** GLOBALS ***
21: //* strings used with commdlg
22: CHAR szDefExtension[CBMESSAGEMAX];
23: CHAR szFilterSpec[CBFILTERMAX];
24: CHAR szInsertFilter[CBFILTERMAX];
25: CHAR szLastDir[CBPATHMAX];
26: OPENFILENAME OFN;
27: HWND hwndProp = NULL;
28: HWND hRetry;
29:
30: /***************************************************************************
1.1.1.3 ! root 31: * OfnInit()
1.1 root 32: * Initializes the standard file dialog OFN structure.
33: **************************************************************************/
34:
35: VOID FAR OfnInit( //* ENTRY:
36: HANDLE hInst //* instance handle
37: ){ //* LOCAL:
38: LPSTR lpstr; //* string pointer
39:
40: LoadString(hInst, IDS_FILTER, szFilterSpec, CBMESSAGEMAX);
41: LoadString(hInst, IDS_EXTENSION, szDefExtension, CBMESSAGEMAX);
42:
43: OFN.lStructSize = sizeof(OPENFILENAME);
44: OFN.hInstance = hInst;
45: OFN.nMaxCustFilter = CBFILTERMAX;
46: OFN.nMaxFile = CBPATHMAX;
1.1.1.3 ! root 47: OFN.lCustData = 0;
1.1 root 48: OFN.lpfnHook = NULL;
49: OFN.lpTemplateName = NULL;
50: OFN.lpstrFileTitle = NULL;
1.1.1.3 ! root 51: //* Construct the filter string
! 52: //* for the Open and Save dialogs
1.1 root 53: lpstr = (LPSTR)szFilterSpec;
54: lstrcat(lpstr, " (*.");
55: lstrcat(lpstr, szDefExtension);
56: lstrcat(lpstr, ")");
57: lpstr += lstrlen(lpstr) + 1;
58:
59: lstrcpy(lpstr, "*.");
60: lstrcat(lpstr, szDefExtension);
61: lpstr += lstrlen(lpstr) + 1;
62: *lpstr = 0;
63:
64: RegMakeFilterSpec(NULL, NULL, (LPSTR)szInsertFilter);
65:
66: }
67:
68: /***************************************************************************
1.1.1.3 ! root 69: * OfnGetName()
1.1 root 70: *
71: * Calls the standard file dialogs to get a file name
72: **************************************************************************/
73:
74: BOOL FAR OfnGetName( //* ENTRY:
75: HWND hwnd, //* parent window handle
76: LPSTR szFileName, //* File name
77: WORD msg //* operation
78: ){ //* LOCAL:
79: BOOL frc; //* return flag
80: CHAR szCaption[CBMESSAGEMAX];//* dialog caption
81:
82: OFN.hwndOwner = hwnd; //* window
83: OFN.nFilterIndex = 1;
84: OFN.lpstrInitialDir = (LPSTR)szLastDir;
85: OFN.Flags = OFN_HIDEREADONLY;
86:
87: switch (msg) //* message
1.1.1.3 ! root 88: {
1.1 root 89: case IDM_OPEN: //* open file
90: Normalize(szFileName);
91: OFN.lpstrDefExt = (LPSTR)szDefExtension;
92: OFN.lpstrFile = (LPSTR)szFileName;
93: OFN.lpstrFilter = (LPSTR)szFilterSpec;
94: LoadString(hInst, IDS_OPENFILE, szCaption, CBMESSAGEMAX);
95: OFN.lpstrTitle = (LPSTR)szCaption;
96: OFN.Flags |= OFN_FILEMUSTEXIST;
97: return GetOpenFileName((LPOPENFILENAME)&OFN);
98: break;
99:
100: case IDM_SAVEAS: //* save as file
101: Normalize(szFileName);
102: OFN.lpstrDefExt = (LPSTR)szDefExtension;
103: OFN.lpstrFile = (LPSTR)szFileName;
104: OFN.lpstrFilter = (LPSTR)szFilterSpec;
105: LoadString(hInst, IDS_SAVEFILE, szCaption, CBMESSAGEMAX);
106: OFN.lpstrTitle = (LPSTR)szCaption;
107: OFN.Flags |= OFN_PATHMUSTEXIST;
108: return GetSaveFileName((LPOPENFILENAME)&OFN);
109: break;
1.1.1.3 ! root 110:
1.1 root 111: case IDM_INSERTFILE: //* insert file
112: OFN.lpstrDefExt = NULL;
113: OFN.lpstrFile = (LPSTR)szFileName;
114: OFN.lpstrFilter = (LPSTR)szInsertFilter;
115: LoadString(hInst, IDS_INSERTFILE, szCaption, CBMESSAGEMAX);
116: OFN.lpstrTitle = (LPSTR)szCaption;
117: OFN.Flags |= OFN_FILEMUSTEXIST;
118: frc = GetOpenFileName((LPOPENFILENAME)&OFN);
119: AddExtension(&OFN);
120: return frc;
121: break;
122:
123: default: //* default
124: break;
125: }
126:
127: }
128:
129: /***************************************************************************
130: * OfnGetNewLinkName() - Sets up the "Change Link..." dialog box
131: *
1.1.1.3 ! root 132: * returns LPSTR - fully qualified filename
1.1 root 133: **************************************************************************/
134:
135: LPSTR FAR OfnGetNewLinkName( //* ENTRY:
136: HWND hwnd, //* calling window or dialog
137: LPSTR lpstrData //* link data
138: ){ //* LOCAL:
139: LPSTR lpReturn = NULL; //* return string
1.1.1.3 ! root 140: LPSTR lpstrFile = NULL; //* non-qualified file name
1.1 root 141: LPSTR lpstrPath = NULL; //* pathname
142: LPSTR lpstrTemp = NULL; //* work string
143: CHAR szDocFile[CBPATHMAX];//* document name
144: CHAR szDocPath[CBPATHMAX];//* document path name
1.1.1.3 ! root 145: CHAR szServerFilter[CBPATHMAX];
1.1 root 146: CHAR szCaption[CBMESSAGEMAX];
147:
1.1.1.3 ! root 148: //* Figure out the link's path
! 149: //* name and file name
1.1 root 150: lpstrTemp = lpstrData;
151: while (*lpstrTemp++);
152: lpstrPath = lpstrFile = lpstrTemp;
153:
154: while (*(lpstrTemp = AnsiNext(lpstrTemp)))
155: if (*lpstrTemp == '\\')
156: lpstrFile = lpstrTemp + 1;
157: //* Copy the document name
158: lstrcpy(szDocFile, lpstrFile);
159: *(lpstrFile - 1) = 0;
1.1.1.3 ! root 160: //* Copy the path name
1.1 root 161: lstrcpy(szDocPath, ((lpstrPath != lpstrFile) ? lpstrPath : ""));
162: if (lpstrPath != lpstrFile) //* Restore the backslash
163: *(lpstrFile - 1) = '\\';
1.1.1.3 ! root 164: while (*lpstrFile != '.' && *lpstrFile)//* Get the extension
1.1 root 165: lpstrFile++;
1.1.1.3 ! root 166: //* Make a filter that respects
! 167: //* the link's class name
1.1 root 168: OFN.hwndOwner = hwnd;
169: OFN.nFilterIndex = RegMakeFilterSpec(lpstrData, lpstrFile, szServerFilter);
170: OFN.lpstrDefExt = NULL;
171: OFN.lpstrFile = (LPSTR)szDocFile;
172: OFN.lpstrFilter = (LPSTR)szServerFilter;
173: OFN.lpstrInitialDir = (LPSTR)szDocPath;
174: LoadString(hInst, IDS_CHANGELINK, szCaption, CBMESSAGEMAX);
175: OFN.lpstrTitle = (LPSTR)szCaption;
176: OFN.lpstrCustomFilter = NULL;
177: OFN.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
178:
179: //* If we get a file... */
1.1.1.3 ! root 180: if (GetOpenFileName((LPOPENFILENAME)&OFN))
1.1 root 181: {
182: if (!(lpReturn = GlobalLock(GlobalAlloc(LHND, CBPATHMAX))))
183: goto Error;
184:
185: AddExtension(&OFN);
186: lstrcpy(lpReturn, szDocFile);
187:
188: OFN.lpstrInitialDir = (LPSTR)szLastDir;
189: }
190:
191: return lpReturn; //* SUCCESS return
192:
193: Error: //* ERROR Tag
194:
195: return NULL; //* ERROR return
1.1.1.3 ! root 196:
1.1 root 197: }
198:
199: /***************************************************************************
1.1.1.3 ! root 200: * Normalize()
1.1 root 201: * Removes the path specification from the file name.
202: *
203: * Note: It isn't possible to get "<drive>:<filename>" as input because
204: * the path received will always be fully qualified.
205: **************************************************************************/
206:
207: VOID Normalize( //* ENTRY:
208: LPSTR lpstrFile //* file name
209: ){ //* LOCAL:
210: LPSTR lpstrBackslash = NULL;//* back slash
211: LPSTR lpstrTemp = lpstrFile;//* file name
212:
1.1.1.3 ! root 213: while (*lpstrTemp)
1.1 root 214: {
215: if (*lpstrTemp == '\\')
216: lpstrBackslash = lpstrTemp;
217:
218: lpstrTemp = AnsiNext(lpstrTemp);
219: }
220: if (lpstrBackslash)
221: lstrcpy(lpstrFile, lpstrBackslash + 1);
222:
223: }
224:
225: /***************************************************************************
1.1.1.3 ! root 226: * AddExtension()
1.1 root 227: *
228: * Adds the extension corresponding to the filter dropdown.
229: **************************************************************************/
230:
231: VOID AddExtension( //* ENTRY:
232: LPOPENFILENAME lpOFN //* open file structure
233: ){
234:
1.1.1.3 ! root 235: if (lpOFN->nFileExtension == (WORD)lstrlen(lpOFN->lpstrFile)
! 236: && lpOFN->nFilterIndex)
1.1 root 237: {
238: LPSTR lpstrFilter = (LPSTR)lpOFN->lpstrFilter;
239:
1.1.1.3 ! root 240: while (*lpstrFilter && --lpOFN->nFilterIndex)
1.1 root 241: {
242: while (*lpstrFilter++) ;
243: while (*lpstrFilter++) ;
244: }
1.1.1.3 ! root 245: //* If we got to the filter,
! 246: if (*lpstrFilter) //* retrieve the extension
1.1 root 247: {
248: while (*lpstrFilter++) ;
249: lpstrFilter++;
1.1.1.3 ! root 250: //* Copy the extension
1.1 root 251: if (lpstrFilter[1] != '*')
252: lstrcat(lpOFN->lpstrFile, lpstrFilter);
253: }
254: }
255:
256: }
257: /****************************************************************************
258: * fnInsertNew()
259: *
260: * Dialog procedure for the Insert New dialog.
261: *
262: * Returns int - TRUE if message processed, FALSE otherwise
263: ***************************************************************************/
264:
265: BOOL APIENTRY fnInsertNew( //* ENTRY:
266: HWND hDlg, //* standard dialog box paramters
1.1.1.3 ! root 267: UINT msg,
! 268: WPARAM wParam,
1.1.1.2 root 269: LPARAM lParam //* (LPSTR) class name
1.1 root 270: ){ //* LOCAL:
1.1.1.3 ! root 271: HWND hwndList; //* handle to listbox
1.1 root 272: static LPSTR lpClassName; //* classname for return value
1.1.1.3 ! root 273:
1.1 root 274: hwndList = GetDlgItem(hDlg, IDD_LISTBOX);
275:
1.1.1.3 ! root 276: switch (msg)
1.1 root 277: {
278: case WM_INITDIALOG:
279: if (!RegGetClassNames(hwndList))
280: EndDialog(hDlg, IDCANCEL);
281:
282: lpClassName = (LPSTR)lParam;
283: SetFocus(hwndList);
284: SendMessage(hwndList, LB_SETCURSEL, 0, 0L);
285: return (FALSE);
286:
287: case WM_COMMAND:
288: {
289: WORD wID = LOWORD(wParam);
290: WORD wCmd = HIWORD(wParam);
291:
1.1.1.3 ! root 292: switch (wID)
1.1 root 293: {
294: case IDD_LISTBOX:
295: if (wCmd != LBN_DBLCLK)
296: break;
297:
298: case IDOK:
299: if (!RegCopyClassName(hwndList, lpClassName))
300: wParam = IDCANCEL;
301:
302: case IDCANCEL:
303: EndDialog(hDlg, wParam);
304: break;
305: }
306: break;
307: }
308: }
1.1.1.3 ! root 309: return FALSE;
1.1 root 310:
311: }
312:
313: /***************************************************************************
314: * LinkProperties();
315: *
316: * Manage the link properties dialog box.
317: **************************************************************************/
318:
1.1.1.3 ! root 319: VOID FAR LinkProperties()
1.1 root 320: { //* LOCAL
321:
322: DialogBox (
1.1.1.3 ! root 323: hInst,
! 324: MAKEINTRESOURCE(DTPROP),
! 325: hwndFrame,
! 326: (DLGPROC)fnProperties
1.1 root 327: );
328:
329: }
330:
331: /***************************************************************************
332: * fnProperties()
333: *
334: * Dialog procedure for link properties. The Links dialog allows the user to
1.1.1.3 ! root 335: * change the link options, edit/play the object, cancel the link as
1.1 root 336: * well change links.
337: *
338: * returns BOOL - TRUE if processed, FALSE otherwise
339: **************************************************************************/
340:
341: BOOL APIENTRY fnProperties( //* ENTRY:
342: HWND hDlg, //* standard dialog box parameters
1.1.1.3 ! root 343: UINT msg,
! 344: WPARAM wParam,
1.1.1.2 root 345: LPARAM lParam //* (HWND) child window with focus
1.1 root 346: ){ //* LOCAL:
347: static APPITEMPTR *pLinks; //* pointer to links (associated windows)
348: static INT nLinks; //* number of links
1.1.1.3 ! root 349: static HWND hwndList; //* handle to listbox window
1.1 root 350: static BOOL fTry;
351:
1.1.1.3 ! root 352: switch (msg)
1.1 root 353: {
1.1.1.3 ! root 354: case WM_INITDIALOG:
1.1 root 355: hwndProp = hDlg;
356: hwndList = GetDlgItem(hDlg, IDD_LINKNAME);
357: if (!(InitLinkDlg(hDlg, &nLinks, hwndList, &pLinks)))
358: EndDialog(hDlg, TRUE);
359: UpdateLinkButtons(hDlg,nLinks,hwndList,pLinks);
360: break;
361:
1.1.1.3 ! root 362: case WM_COMMAND:
1.1 root 363: {
364: WORD wID = LOWORD(wParam);
365:
1.1.1.3 ! root 366: switch (wID)
1.1 root 367: {
368: case IDD_CHANGE: //* change links
369: BLOCK_BUSY(fTry);
370: if (ChangeLinks(hDlg,nLinks,hwndList,pLinks))
371: DisplayUpdate(nLinks,hwndList,pLinks, FALSE);
372: return TRUE;
373:
374: case IDD_FREEZE: //* cancel links
375: BLOCK_BUSY(fTry);
376: CancelLinks(hDlg,nLinks,hwndList,pLinks);
377: UpdateLinkButtons(hDlg,nLinks,hwndList,pLinks);
378: return TRUE;
379:
380: case IDD_UPDATE: //* update links
381: BLOCK_BUSY(fTry);
382: DisplayUpdate(nLinks,hwndList,pLinks,TRUE);
383: UpdateLinkButtons(hDlg,nLinks,hwndList,pLinks);
384: return TRUE;
385:
386: case IDD_AUTO:
387: case IDD_MANUAL: //* change link update options
388: BLOCK_BUSY(fTry);
389: if (!SendMessage(GetDlgItem(hDlg,wParam),BM_GETCHECK, 0, 0L))
390: {
391: CheckRadioButton(hDlg, IDD_AUTO ,IDD_MANUAL ,wParam);
1.1.1.3 ! root 392: ChangeUpdateOptions(hDlg,nLinks,hwndList,pLinks,
1.1 root 393: (wParam == IDD_AUTO ? oleupdate_always : oleupdate_oncall));
394: UpdateLinkButtons(hDlg,nLinks,hwndList,pLinks);
395: }
396: return TRUE;
397:
1.1.1.3 ! root 398: case IDD_LINKNAME:
1.1.1.2 root 399: if (HIWORD(wParam) == LBN_SELCHANGE)
1.1 root 400: UpdateLinkButtons(hDlg,nLinks,hwndList,pLinks);
401: return TRUE;
402:
403: case IDCANCEL:
404: BLOCK_BUSY(fTry);
405: UndoObjects();
406: END_PROP_DLG(hDlg,pLinks);
1.1.1.3 ! root 407: return TRUE;
1.1 root 408:
409: case IDOK:
410: BLOCK_BUSY(fTry);
411: DelUndoObjects(FALSE);
412: END_PROP_DLG(hDlg,pLinks);
1.1.1.3 ! root 413: return TRUE;
! 414: }
1.1 root 415: }
1.1.1.3 ! root 416: }
1.1 root 417: return FALSE;
418: }
419:
420:
421: /****************************************************************************
422: * InitLinkDlg();
423: *
424: * Initialize the list box of links.
425: ***************************************************************************/
426:
427: static BOOL InitLinkDlg ( //* ENTRY:
428: HWND hDlg, //* dialog box handle
429: INT *nLinks, //* pointer to number of links
430: HWND hwndList, //* listbox handle
1.1.1.3 ! root 431: APPITEMPTR **pLinks //* list of window handles of links
1.1 root 432: ){ //* LOCAL
433: APPITEMPTR pItem; //* application item pointer
434: LPSTR lpstrData = NULL; //* pointer to link data
435: CHAR szFull[CBMESSAGEMAX * 4];//* list box entry string
436: CHAR pLinkData[OBJECT_LINK_MAX];//* holder of link data
437: BOOL fSelect = FALSE; //* item selected flag
438: HANDLE hWork; //* working memory handle
439: APPITEMPTR pTop; //* pointer to the top object
440:
441: if (!(*pLinks = (APPITEMPTR *)LocalLock(LocalAlloc(LHND,sizeof(APPITEMPTR)*10))))
1.1.1.3 ! root 442: {
! 443: ErrorMessage(E_FAILED_TO_ALLOC);
! 444: return 0;
! 445: }
1.1 root 446: *nLinks = 0;
447: //* set tabs
448: SendMessage(hwndList,WM_SETREDRAW,FALSE,0L);
449: //* enumerate child windows
450: for (pTop = pItem = GetTopItem(); pItem; pItem = GetNextItem(pItem))
451: {
1.1.1.3 ! root 452: if (pItem->otObject == OT_LINK && pItem->fVisible)
1.1 root 453: {
1.1.1.3 ! root 454: *(*pLinks + *nLinks) = pItem;
1.1 root 455: if (!((*nLinks += 1)%10))
456: { //* add blocks of ten
457: hWork = LocalHandle((LPSTR)(*pLinks));
458: LocalUnlock(hWork);
1.1.1.3 ! root 459: if (!(hWork = LocalReAlloc(hWork,(*nLinks+10)*sizeof(APPITEMPTR),0)))
1.1 root 460: {
461: ErrorMessage(E_FAILED_TO_ALLOC);
462: return FALSE; //* ERROR return
463: }
464: *pLinks = (APPITEMPTR *)LocalLock(hWork);
465: }
466:
467: if (pTop == pItem)
468: fSelect = TRUE;
469:
470: if (!ObjGetData(pItem, pLinkData))
471: continue;
472: //* make listbox entry
473: MakeListBoxString(pLinkData, szFull, pItem->uoObject);
474: //* add listbox entry
475: SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPSTR)szFull);
476: }
477: }
478:
479: if (fSelect)
480: SendMessage(hwndList, LB_SETSEL, 1, 0L);
1.1.1.3 ! root 481:
1.1 root 482: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
1.1.1.3 ! root 483: UpdateWindow(hwndList);
1.1 root 484:
485: return TRUE; //* SUCCESS return
1.1.1.3 ! root 486:
1.1 root 487: }
488:
489: /****************************************************************************
490: * MakeListBoxString()
491: *
492: * build an listbox entry string
493: ***************************************************************************/
494:
495: static VOID MakeListBoxString( //* ENTRY:
496: LPSTR lpLinkData, //* pointer to link data
497: LPSTR lpBoxData, //* return string
498: OLEOPT_UPDATE oleopt_update //* OLE update option
499: ){ //* LOCAL:
500: CHAR szType[CBMESSAGEMAX];//* holds update option string
501: LPSTR lpTemp; //* working string pointer
502: INT i; //* index
1.1.1.3 ! root 503:
1.1 root 504: //* get classname
505: RegGetClassId(lpBoxData, lpLinkData);
506: lstrcat(lpBoxData, " - "); //* ads tab
1.1.1.3 ! root 507:
1.1 root 508: while (*lpLinkData++); //* skip to document name
509:
510: lpTemp = lpLinkData;
511: while (*lpTemp) //* copy document name;
512: { //* strip drive an directory
513: if (*lpTemp == '\\' || *lpTemp == ':')
514: lpLinkData = lpTemp + 1;
515: lpTemp = AnsiNext(lpTemp);
516: }
517: lstrcat(lpBoxData, lpLinkData);
518: lstrcat(lpBoxData, " - ");
1.1.1.3 ! root 519:
1.1 root 520: while (*lpLinkData++); //* copy item data
521: lstrcat(lpBoxData, lpLinkData);
522: lstrcat(lpBoxData, " - ");
523: //* add update option string
524: switch (oleopt_update)
525: {
526: case oleupdate_always: i = SZAUTO; break;
527: case oleupdate_oncall: i = SZMANUAL; break;
528: default: i = SZFROZEN;
529: }
530: LoadString(hInst, i, szType, CBMESSAGEMAX);
531: lstrcat(lpBoxData, szType);
532:
533: } //* SUCCESS return
534:
535: /***************************************************************************
536: * UpdateLinkButtons()
537: *
538: * Keep link buttons active as appropriate. This routine is called after
539: * a selection is made so the buttons reflect the selected items.
540: **************************************************************************/
541:
542: static VOID UpdateLinkButtons( //* ENTRY:
543: HWND hDlg, //* dialog box handle
544: INT nLinks, //* number of links
545: HWND hwndList, //* listbox handle
546: APPITEMPTR *pLinks //* pointer to link's window handles
547: ){ //* LOCAL:
548: ATOM aCurName=0; //* atom of current doc
549: BOOL fChangeLink = TRUE; //* enable/disable changelink button
550: INT iAuto,iManual,i; //* count of manual and auto links
551: APPITEMPTR pItem; //* application item pointer
552: INT iStatic;
553:
554: iStatic = iAuto = iManual = 0;
555:
1.1.1.3 ! root 556: for (i = 0; i < nLinks; i++) //* enum selected links
1.1 root 557: {
558: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
559: {
560: pItem = *(pLinks+i);
561: if (pItem->otObject == OT_STATIC)
562: iStatic++;
563: else
564: {
1.1.1.3 ! root 565: switch(pItem->uoObject)
! 566: { //* count number of manual and
1.1 root 567: case oleupdate_always: //* automatic links selected
568: iAuto++;
569: break;
570: case oleupdate_oncall:
571: iManual++;
572: break;
573: }
574: //* check if all selected links are
575: if (!aCurName) //* linked to same file
576: aCurName = pItem->aLinkName;
577: else if (aCurName != pItem->aLinkName)
578: fChangeLink = FALSE;
579: }
580: }
581: }
582:
583: if (!(iAuto || iManual || iStatic) //* if no links disable all buttons
584: || (!iAuto && !iManual && iStatic))
585: {
586: EnableWindow(GetDlgItem(hDlg, IDD_FREEZE), FALSE );
587: EnableWindow(GetDlgItem(hDlg, IDD_CHANGE), FALSE );
588: EnableWindow(GetDlgItem(hDlg, IDD_UPDATE), FALSE );
589: CheckDlgButton(hDlg, IDD_AUTO, FALSE);
590: EnableWindow(GetDlgItem(hDlg, IDD_AUTO),FALSE);
591: CheckDlgButton(hDlg, IDD_MANUAL, FALSE);
592: EnableWindow(GetDlgItem(hDlg, IDD_MANUAL),FALSE);
593: }
594: else
1.1.1.3 ! root 595: {
1.1 root 596: EnableWindow(GetDlgItem(hDlg, IDD_UPDATE), TRUE );
597: EnableWindow(GetDlgItem(hDlg, IDD_FREEZE), TRUE );
598:
599: if (iAuto && iManual || !(iAuto || iManual))
1.1.1.3 ! root 600: { //* Set update buttons
1.1 root 601: CheckDlgButton(hDlg, IDD_AUTO, FALSE);
602: EnableWindow(GetDlgItem(hDlg, IDD_AUTO),FALSE);
603: CheckDlgButton(hDlg, IDD_MANUAL, FALSE);
604: EnableWindow(GetDlgItem(hDlg, IDD_MANUAL),FALSE);
605: }
1.1.1.3 ! root 606: else
1.1 root 607: {
608: EnableWindow(GetDlgItem(hDlg, IDD_MANUAL), TRUE);
609: EnableWindow(GetDlgItem(hDlg, IDD_AUTO), TRUE);
610: if (iAuto)
1.1.1.3 ! root 611: {
1.1 root 612: CheckDlgButton(hDlg, IDD_AUTO, TRUE);
613: CheckDlgButton(hDlg, IDD_MANUAL, FALSE);
614: }
615: else
616: {
617: CheckDlgButton(hDlg, IDD_AUTO, FALSE);
618: CheckDlgButton(hDlg, IDD_MANUAL, TRUE);
619: }
620: }
1.1.1.3 ! root 621: }
1.1 root 622:
623: EnableWindow(GetDlgItem(hDlg, IDD_CHANGE),fChangeLink && aCurName);
624:
625: }
626:
627: /****************************************************************************
628: * ChangeLinks()
629: *
630: * This routine changes the linked data if the user chooses a new file to
631: * replace the old document data portion of the linked date. The routine
632: * does nothing if the user cancels.
633: *
634: * returns TRUE - if data changed FALSE if user cancel or err.
635: ***************************************************************************/
636:
637: static BOOL ChangeLinks( //* ENTRY:
638: HWND hDlg, //* dialog handle
639: INT nLinks, //* number of links in listbox
640: HWND hwndList, //* listbox
641: APPITEMPTR *pLinks //* list of application link handles
642: ){ //* LOCAL
643: INT i; //* general index
644: HANDLE hWork; //* work
645: APPITEMPTR pItem; //* application item
646: LPSTR lpNewDoc = NULL; //* new document
647: ATOM aOldDoc; //* atom of old doc. name
1.1.1.3 ! root 648: ATOM aCurDoc = 0; //* atom of change-to doc. name
1.1 root 649: BOOL fMessage = FALSE; //* error message flag
650: LPSTR lpLinkData; //* pointer to link data
1.1.1.3 ! root 651:
1.1 root 652: lpLinkData = NULL;
653: //* This loop finds all selected links
654: for (i = 0; i < nLinks; i++) //* and updates them
655: {
656: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
657: {
658: pItem = *(pLinks+i);
659: CHECK_IF_STATIC(pItem);
660:
661: pItem->lpLinkData = lpLinkData;
662: if (!ObjGetData(pItem,NULL))
663: continue;
664:
665: if (!lpNewDoc)
666: {
667: if (!(lpNewDoc = OfnGetNewLinkName(hDlg, pItem->lpLinkData)))
668: return FALSE; //* ERROR jump
669: aOldDoc = pItem->aLinkName;
670: aCurDoc = AddAtom(lpNewDoc);
671: SendMessage(hwndList,WM_SETREDRAW,FALSE,0L);
672: }
673:
1.1.1.3 ! root 674: ObjSaveUndo(pItem);
1.1 root 675: ObjChangeLinkData(pItem,lpNewDoc);
676: pItem->aLinkName = aCurDoc;
677: lpLinkData = pItem->lpLinkData;
678:
679: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pItem->lpLinkData);
680:
681: pItem->lpLinkData = NULL;
682: }
1.1.1.3 ! root 683: }
1.1 root 684:
685: /*************************************************************************
686: * now deal with non-selected links and look for a match...
687: *************************************************************************/
688:
689: //* this loop finds non-selected links
690: for (i = 0; i < nLinks; i++) //* and asks the user to update these?
691: {
692: if (!SendMessage(hwndList, LB_GETSEL, i, 0L))
693: {
694: pItem = *(pLinks+i);
695: if (pItem->otObject == OT_STATIC)
696: continue;
1.1.1.3 ! root 697:
1.1 root 698: if (!ObjGetData(pItem,NULL))
699: continue;
700:
701: if (pItem->aLinkName == aOldDoc)
702: {
703: if (!fMessage)
704: {
705: CHAR szMessage[2*CBMESSAGEMAX+3*CBPATHMAX];
706: CHAR szRename[2*CBMESSAGEMAX];
707: CHAR szOldDoc[CBMESSAGEMAX];
708: LPSTR pOldDoc;
1.1.1.3 ! root 709:
1.1 root 710: GetAtomName(aOldDoc,szOldDoc,CBMESSAGEMAX);
1.1.1.3 ! root 711: pOldDoc =(LPSTR)UnqualifyPath(szOldDoc);
1.1 root 712: LoadString(hInst, IDS_RENAME, szRename, 2*CBMESSAGEMAX);
713: wsprintf(
714: szMessage,
715: szRename,
716: pOldDoc,
717: (LPSTR)UnqualifyPath(szFileName),
718: pOldDoc
719: );
720:
1.1.1.3 ! root 721: if (MessageBox(hDlg, szMessage,
! 722: szAppName, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
1.1 root 723: break;
724: fMessage = TRUE;
725: }
726:
1.1.1.3 ! root 727: ObjSaveUndo(pItem);
1.1 root 728: ObjChangeLinkData(pItem,lpNewDoc);
729: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pItem->lpLinkData);
1.1.1.3 ! root 730:
1.1 root 731: pItem->aLinkName = aCurDoc;
732: }
733: }
1.1.1.3 ! root 734: }
1.1 root 735:
736: if(lpNewDoc)
737: {
738: hWork = GlobalHandle(lpNewDoc);
739: GlobalUnlock(hWork);
740: GlobalFree(hWork);
741: }
742:
1.1.1.3 ! root 743: #if 0
! 744: // This is bogus -- this memory is owned by OLECLI32.DLL, not this app,
! 745: // so it should not be freed here.
1.1 root 746: if (lpLinkData)
747: FreeLinkData(lpLinkData);
1.1.1.3 ! root 748: #endif
1.1 root 749:
750: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
751: InvalidateRect(hwndList,NULL,TRUE);
752: UpdateWindow(hwndList);
753:
754: WaitForAllObjects();
755:
756: if (aCurDoc)
757: DeleteAtom(aCurDoc);
758:
759: return(TRUE);
760: }
761:
762: /****************************************************************************
763: * DisplayUpdate()
764: *
1.1.1.3 ! root 765: * Get the most up to date rendering information and show it.
1.1 root 766: ***************************************************************************/
767:
768: static VOID DisplayUpdate( //* ENTRY:
769: INT nLinks, //* number of links in listbox
770: HWND hwndList, //* listbox
771: APPITEMPTR *pLinks, //* list of application link handles
772: BOOL fSaveUndo //* save undo objects
773: ){ //* LOCAL:
774: INT i; //* index
775: APPITEMPTR pItem; //* temporary item pointer
776:
1.1.1.3 ! root 777:
! 778: for (i = 0; i < nLinks; i++)
1.1 root 779: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
780: {
781: pItem = *(pLinks+i);
782: CHECK_IF_STATIC(pItem);
783: if (fSaveUndo)
784: ObjSaveUndo(pItem);
785: Error(OleUpdate(pItem->lpObject));
786: }
787:
788: WaitForAllObjects();
789:
790: }
791:
792: /****************************************************************************
793: * UndoObjects()
794: *
795: * Bring objects back to their original state.
796: ***************************************************************************/
797:
798: static VOID UndoObjects()
1.1.1.3 ! root 799: {
1.1 root 800: APPITEMPTR pItem; //* application item pointer
801: //* enum objects
802: for (pItem = GetTopItem(); pItem; pItem = GetNextItem(pItem))
1.1.1.3 ! root 803: if (pItem->lpObjectUndo)
1.1 root 804: ObjUndo(pItem);
1.1.1.3 ! root 805:
1.1 root 806: WaitForAllObjects();
807:
808: }
809:
810:
811: /****************************************************************************
812: * DelUndoObjects()
813: *
814: * remove all objects created for undo operation.
815: ***************************************************************************/
816:
817: static VOID DelUndoObjects( //* ENTRY:
818: BOOL fPrompt //* prompt user?
819: ){ //* LOCAL:
820: APPITEMPTR pItem; //* application item pointer
821: BOOL fPrompted = FALSE; //* prompted user?
1.1.1.3 ! root 822:
1.1 root 823: for (pItem = GetTopItem(); pItem; pItem = GetNextItem(pItem))
824: {
1.1.1.3 ! root 825: if (pItem->lpObjectUndo)
1.1 root 826: {
827: if (fPrompt && !fPrompted) //* prompt user in activation case
828: {
829: CHAR szPrompt[CBMESSAGEMAX];
830:
831: LoadString(hInst, IDS_SAVE_CHANGES, szPrompt, CBMESSAGEMAX);
832:
1.1.1.3 ! root 833: if (MessageBox(hwndFrame, szPrompt,
1.1 root 834: szAppName, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
835: {
1.1.1.3 ! root 836: UndoObjects();
1.1 root 837: return; //* user canceled operation
838: }
839: fPrompted = TRUE;
840: }
841: ObjDelUndo(pItem); //* delete udo object
842: }
843: }
844:
845: WaitForAllObjects();
846:
847: } //* SUCCESS return
848:
849: /****************************************************************************
850: * CancelLinks()
851: ***************************************************************************/
852:
853: static VOID CancelLinks( //* ENTRY:
854: HWND hDlg, //* calling dialog
855: INT nLinks, //* number of links in listbox
856: HWND hwndList, //* listbox
857: APPITEMPTR *pLinks //* list of application link handles
858: ){ //* LOCAL:
859: APPITEMPTR pItem; //* application item pointer
860: INT i; //* index
861: CHAR pLinkData[OBJECT_LINK_MAX];//* holder of link data
862:
863: SendMessage(hwndList,WM_SETREDRAW,FALSE,0L);
1.1.1.3 ! root 864: for (i = 0; i < nLinks; i++)
1.1 root 865: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
866: {
867: pItem = *(pLinks+i);
868: CHECK_IF_STATIC(pItem);
869: ObjGetData(pItem,pLinkData);
870: ObjSaveUndo(pItem);
871: ObjFreeze(pItem);
872:
873: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pLinkData);
874: }
875:
876: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
877: InvalidateRect(hwndList,NULL,TRUE);
878: UpdateWindow(hwndList);
879:
880: }
1.1.1.3 ! root 881:
1.1 root 882:
883: /****************************************************************************
884: * ChangeUpdateOptions()
885: *
886: * Change the update options for all selected objects.
887: ***************************************************************************/
888:
889: static VOID ChangeUpdateOptions( //* ENTRY:
890: HWND hDlg, //* calling dialog
891: INT nLinks, //* number of links in listbox
892: HWND hwndList, //* listbox
893: APPITEMPTR *pLinks, //* list of application link handles
894: OLEOPT_UPDATE lUpdate //* update option
895: ){ //* LOCAL:
896: APPITEMPTR pItem; //* application item
897: INT i; //* index
898: CHAR pLinkData[OBJECT_LINK_MAX];
899:
900: SendMessage(hwndList,WM_SETREDRAW,FALSE,0L);
1.1.1.3 ! root 901:
1.1 root 902: for (i = 0; i < nLinks; i++) //* enum selected objects
903: {
904: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
905: {
906: pItem = *(pLinks+i);
907: CHECK_IF_STATIC(pItem);
908: ObjGetData(pItem,pLinkData);
909: ObjSaveUndo(pItem);
910: if (Error(OleSetLinkUpdateOptions(pItem->lpObject,lUpdate)))
911: continue;
912: pItem->uoObject = lUpdate;
913:
914: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pLinkData);
915: }
916: }
917:
918: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
919: InvalidateRect(hwndList,NULL,TRUE);
920: UpdateWindow(hwndList);
921: WaitForAllObjects();
922:
923: }
924: /****************************************************************************
925: * InvalidLink()
926: *
927: * Deal with letting the user know that the program has inadvertently come
928: * across an invalid link.
1.1.1.3 ! root 929: *
! 930: * Global fPropBoxActive - flag to determine whether or not the link dialog
1.1 root 931: * box is active. If it is not active we give the
932: * user an opportunity to enter the links property
933: * dialog directly from here.
934: ***************************************************************************/
935:
936: VOID FAR InvalidLink()
1.1.1.3 ! root 937: {
1.1 root 938:
939: if (!hwndProp)
940: DialogBox(hInst, "InvalidLink", hwndFrame, (DLGPROC)fnInvalidLink);
941: else
942: ErrorMessage(E_FAILED_TO_CONNECT);
943:
944: }
945:
946: /****************************************************************************
947: * fnABout()
948: *
949: * About box dialog box procedure.
950: ***************************************************************************/
951:
1.1.1.3 ! root 952: BOOL APIENTRY fnInvalidLink( //* ENTRY:
1.1 root 953: HWND hDlg, //* standard windows dialog box
1.1.1.3 ! root 954: UINT message,
! 955: WPARAM wParam,
! 956: LPARAM lParam
1.1 root 957: ){
958:
1.1.1.3 ! root 959: switch (message)
1.1 root 960: {
961: case WM_INITDIALOG:
962: return (TRUE);
963:
964: case WM_COMMAND:
965: if (LOWORD(wParam) == IDD_CHANGE)
1.1.1.3 ! root 966: LinkProperties();
1.1 root 967: EndDialog(hDlg, TRUE);
968: return (TRUE);
969: }
970: return (FALSE);
971:
972: }
973:
974: /****************************************************************************
975: * AboutBox()
976: *
977: * Show the About Box dialog.
978: ***************************************************************************/
979:
1.1.1.3 ! root 980: VOID FAR AboutBox()
! 981: {
1.1 root 982:
983: DialogBox(hInst, "AboutBox", hwndFrame, (DLGPROC)fnAbout);
984:
985: }
986:
987: /****************************************************************************
988: * fnABout()
989: *
990: * About box dialog box procedure.
991: ***************************************************************************/
992:
1.1.1.3 ! root 993: BOOL APIENTRY fnAbout( //* ENTRY:
1.1 root 994: HWND hDlg, //* standard windows dialog box
1.1.1.3 ! root 995: UINT message,
! 996: WPARAM wParam,
! 997: LPARAM lParam
1.1 root 998: ){
999:
1.1.1.3 ! root 1000: switch (message)
1.1 root 1001: {
1002: case WM_INITDIALOG:
1003: return (TRUE);
1004:
1005: case WM_COMMAND:
1006: {
1007: WORD wID = LOWORD(wParam);
1.1.1.3 ! root 1008:
! 1009: if (wID == IDOK || wID == IDCANCEL)
1.1 root 1010: {
1011: EndDialog(hDlg, TRUE);
1012: return (TRUE);
1013: }
1014: break;
1015: }
1016: }
1017: return (FALSE);
1018:
1019: }
1020:
1021:
1.1.1.3 ! root 1022:
1.1 root 1023: /***************************************************************************
1024: * RetryMessage()
1025: *
1026: * give the user the chance to abort when a server is in retry case.
1027: *
1028: * Returns BOOL - TRUE if user chooses to cancel
1029: **************************************************************************/
1030:
1031: VOID FAR RetryMessage ( //* ENTRY:
1032: APPITEMPTR paItem, //* application item pointer
1033: LONG lParam
1.1.1.3 ! root 1034: ){
1.1 root 1035: RETRYPTR pRetry;
1036: LONG objectType;
1037: HANDLE hData;
1038: static CHAR szServerName[KEYNAMESIZE];
1039: HWND hwnd; //* window handle
1040:
1041: if (IsWindow(hwndProp))
1042: hwnd = hwndProp;
1043: else if (IsWindow(hwndFrame))
1.1.1.3 ! root 1044: hwnd = hwndFrame;
1.1 root 1045: else
1046: return; //* should not happen
1047: //* get the busy servers name
1048: lstrcpy(szServerName, "server application");
1049:
1050: if (paItem)
1051: {
1052: if (!paItem->aServer)
1053: {
1054: OleQueryType(paItem->lpObject, &objectType );
1055: if (OLE_OK == OleGetData(paItem->lpObject, (OLECLIPFORMAT) (objectType == OT_LINK ? vcfLink : vcfOwnerLink), &hData ))
1056: {
1057: RegGetClassId(szServerName, GlobalLock(hData));
1058: paItem->aServer = AddAtom(szServerName);
1059: GlobalUnlock( hData );
1.1.1.3 ! root 1060: }
1.1 root 1061: }
1062: else
1063: GetAtomName(paItem->aServer,szServerName,KEYNAMESIZE);
1.1.1.3 ! root 1064:
1.1 root 1065: }
1066:
1067: hData = LocalAlloc(LHND,sizeof(RETRYSTRUCT));
1068: if(!(pRetry = (RETRYPTR)LocalLock(hData)))
1069: return;
1070:
1071: pRetry->lpserver = (LPSTR)szServerName;
1072: pRetry->bCancel = (BOOL)(lParam & RD_CANCEL);
1073: pRetry->paItem = paItem;
1074:
1075: DialogBoxParam(hInst, "RetryBox", hwnd, (DLGPROC)fnRetry, (LONG)pRetry );
1076:
1077: LocalUnlock(hData);
1078: LocalFree(hData);
1079:
1080: hRetry = NULL;
1081:
1082: }
1083:
1084: /****************************************************************************
1085: * fnRetry()
1086: *
1.1.1.3 ! root 1087: * Retry message box nothing to tricky; however, when a server becomes
1.1 root 1088: * unbusy a message is posted to automatically get rid of this dialog.
1089: * I send a no.
1090: ***************************************************************************/
1091:
1092: BOOL APIENTRY fnRetry( //* ENTRY
1093: HWND hDlg, //* standard dialog entry
1.1.1.3 ! root 1094: UINT message,
! 1095: WPARAM wParam,
1.1.1.2 root 1096: LPARAM lParam
1.1 root 1097: ){
1098: static RETRYPTR pRetry;
1099:
1.1.1.3 ! root 1100: switch (message)
1.1 root 1101: {
1102: case WM_COMMAND:
1103: {
1104: WORD wID = LOWORD(wParam);
1105:
1.1.1.3 ! root 1106: switch (wParam)
1.1 root 1107: {
1108: case IDD_SWITCH:
1.1.1.3 ! root 1109: DefWindowProc( hDlg, WM_SYSCOMMAND, SC_TASKLIST, 0);
1.1 root 1110: break;
1111:
1112: case IDCANCEL:
1113: if (pRetry->paItem)
1114: pRetry->paItem->fRetry = FALSE;
1115: EndDialog(hDlg, TRUE);
1116: return TRUE;
1117:
1118: default:
1119: break;
1120: }
1121: break;
1122: }
1123:
1124: case WM_INITDIALOG:
1125: {
1126: CHAR szBuffer[CBMESSAGEMAX];
1127: CHAR szText[2*CBMESSAGEMAX];
1.1.1.3 ! root 1128:
1.1 root 1129: pRetry = (RETRYPTR)lParam;
1130: hRetry = hDlg;
1.1.1.3 ! root 1131:
1.1 root 1132: LoadString(hInst, IDS_RETRY_TEXT1, szBuffer, CBMESSAGEMAX);
1133: wsprintf(szText, szBuffer, pRetry->lpserver);
1134: SetWindowText (GetDlgItem(hDlg, IDD_RETRY_TEXT1), szText);
1135:
1136: LoadString(hInst, IDS_RETRY_TEXT2, szBuffer, CBMESSAGEMAX);
1137: wsprintf(szText, szBuffer, pRetry->lpserver);
1138: SetWindowText (GetDlgItem(hDlg, IDD_RETRY_TEXT2), szText);
1.1.1.3 ! root 1139:
1.1 root 1140: EnableWindow (GetDlgItem(hDlg, IDCANCEL), pRetry->bCancel);
1141:
1.1.1.3 ! root 1142: return TRUE;
1.1 root 1143: }
1.1.1.3 ! root 1144:
1.1 root 1145: default:
1146: break;
1147: }
1148:
1149: return FALSE;
1150: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.