|
|
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:
13: #include "global.h" //* global
14: #include "demorc.h" //* String table constants
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: /***************************************************************************
31: * OfnInit()
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;
47: OFN.lCustData = NULL;
48: OFN.lpfnHook = NULL;
49: OFN.lpTemplateName = NULL;
50: OFN.lpstrFileTitle = NULL;
51: //* Construct the filter string
52: //* for the Open and Save dialogs
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: /***************************************************************************
69: * OfnGetName()
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
88: {
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;
110:
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: *
132: * returns LPSTR - fully qualified filename
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
140: LPSTR lpstrFile = NULL; //* non-qualified file name
141: LPSTR lpstrPath = NULL; //* pathname
142: LPSTR lpstrTemp = NULL; //* work string
143: CHAR szDocFile[CBPATHMAX];//* document name
144: CHAR szDocPath[CBPATHMAX];//* document path name
145: CHAR szServerFilter[CBPATHMAX];
146: CHAR szCaption[CBMESSAGEMAX];
147:
148: //* Figure out the link's path
149: //* name and file name
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;
160: //* Copy the path name
161: lstrcpy(szDocPath, ((lpstrPath != lpstrFile) ? lpstrPath : ""));
162: if (lpstrPath != lpstrFile) //* Restore the backslash
163: *(lpstrFile - 1) = '\\';
164: while (*lpstrFile != '.' && *lpstrFile)//* Get the extension
165: lpstrFile++;
166: //* Make a filter that respects
167: //* the link's class name
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... */
180: if (GetOpenFileName((LPOPENFILENAME)&OFN))
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
196:
197: }
198:
199: /***************************************************************************
200: * Normalize()
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:
213: while (*lpstrTemp)
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: /***************************************************************************
226: * AddExtension()
227: *
228: * Adds the extension corresponding to the filter dropdown.
229: **************************************************************************/
230:
231: VOID AddExtension( //* ENTRY:
232: LPOPENFILENAME lpOFN //* open file structure
233: ){
234:
235: if (lpOFN->nFileExtension == (WORD)lstrlen(lpOFN->lpstrFile)
236: && lpOFN->nFilterIndex)
237: {
238: LPSTR lpstrFilter = (LPSTR)lpOFN->lpstrFilter;
239:
240: while (*lpstrFilter && --lpOFN->nFilterIndex)
241: {
242: while (*lpstrFilter++) ;
243: while (*lpstrFilter++) ;
244: }
245: //* If we got to the filter,
246: if (*lpstrFilter) //* retrieve the extension
247: {
248: while (*lpstrFilter++) ;
249: lpstrFilter++;
250: //* Copy the extension
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
267: UINT msg,
1.1.1.2 ! root 268: WPARAM wParam,
! 269: LPARAM lParam //* (LPSTR) class name
1.1 root 270: ){ //* LOCAL:
271: HWND hwndList; //* handle to listbox
272: static LPSTR lpClassName; //* classname for return value
273:
274: hwndList = GetDlgItem(hDlg, IDD_LISTBOX);
275:
276: switch (msg)
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:
292: switch (wID)
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: }
309: return FALSE;
310:
311: }
312:
313: /***************************************************************************
314: * LinkProperties();
315: *
316: * Manage the link properties dialog box.
317: **************************************************************************/
318:
319: VOID FAR LinkProperties()
320: { //* LOCAL
321:
322: DialogBox (
323: hInst,
324: MAKEINTRESOURCE(DTPROP),
325: hwndFrame,
1.1.1.2 ! root 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
335: * change the link options, edit/play the object, cancel the link as
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
343: UINT msg,
1.1.1.2 ! root 344: WPARAM wParam,
! 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
349: static HWND hwndList; //* handle to listbox window
350: static BOOL fTry;
351:
352: switch (msg)
353: {
354: case WM_INITDIALOG:
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:
362: case WM_COMMAND:
363: {
364: WORD wID = LOWORD(wParam);
365:
366: switch (wID)
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);
392: ChangeUpdateOptions(hDlg,nLinks,hwndList,pLinks,
393: (wParam == IDD_AUTO ? oleupdate_always : oleupdate_oncall));
394: UpdateLinkButtons(hDlg,nLinks,hwndList,pLinks);
395: }
396: return TRUE;
397:
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);
407: return TRUE;
408:
409: case IDOK:
410: BLOCK_BUSY(fTry);
411: DelUndoObjects(FALSE);
412: END_PROP_DLG(hDlg,pLinks);
413: return TRUE;
414: }
415: }
416: }
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
431: APPITEMPTR **pLinks //* list of window handles of links
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))))
442: {
443: ErrorMessage(E_FAILED_TO_ALLOC);
444: return NULL;
445: }
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: {
452: if (pItem->otObject == OT_LINK && pItem->fVisible)
453: {
454: *(*pLinks + *nLinks) = pItem;
455: if (!((*nLinks += 1)%10))
456: { //* add blocks of ten
457: hWork = LocalHandle((LPSTR)(*pLinks));
458: LocalUnlock(hWork);
459: if (!(hWork = LocalReAlloc(hWork,(*nLinks+10)*sizeof(APPITEMPTR),NULL)))
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);
481:
482: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
483: UpdateWindow(hwndList);
484:
485: return TRUE; //* SUCCESS return
486:
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
503:
504: //* get classname
505: RegGetClassId(lpBoxData, lpLinkData);
506: lstrcat(lpBoxData, " - "); //* ads tab
507:
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, " - ");
519:
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:
556: for (i = 0; i < nLinks; i++) //* enum selected links
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: {
565: switch(pItem->uoObject)
566: { //* count number of manual and
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
595: {
596: EnableWindow(GetDlgItem(hDlg, IDD_UPDATE), TRUE );
597: EnableWindow(GetDlgItem(hDlg, IDD_FREEZE), TRUE );
598:
599: if (iAuto && iManual || !(iAuto || iManual))
600: { //* Set update buttons
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: }
606: else
607: {
608: EnableWindow(GetDlgItem(hDlg, IDD_MANUAL), TRUE);
609: EnableWindow(GetDlgItem(hDlg, IDD_AUTO), TRUE);
610: if (iAuto)
611: {
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: }
621: }
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
648: ATOM aCurDoc = NULL; //* atom of change-to doc. name
649: BOOL fMessage = FALSE; //* error message flag
650: LPSTR lpLinkData; //* pointer to link data
651:
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:
674: ObjSaveUndo(pItem);
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: }
683: }
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;
697:
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;
709:
710: GetAtomName(aOldDoc,szOldDoc,CBMESSAGEMAX);
711: pOldDoc =(LPSTR)UnqualifyPath(szOldDoc);
712: LoadString(hInst, IDS_RENAME, szRename, 2*CBMESSAGEMAX);
713: wsprintf(
714: szMessage,
715: szRename,
716: pOldDoc,
717: (LPSTR)UnqualifyPath(szFileName),
718: pOldDoc
719: );
720:
721: if (MessageBox(hDlg, szMessage,
722: szAppName, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
723: break;
724: fMessage = TRUE;
725: }
726:
727: ObjSaveUndo(pItem);
728: ObjChangeLinkData(pItem,lpNewDoc);
729: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pItem->lpLinkData);
730:
731: pItem->aLinkName = aCurDoc;
732: }
733: }
734: }
735:
736: if(lpNewDoc)
737: {
738: hWork = GlobalHandle(lpNewDoc);
739: GlobalUnlock(hWork);
740: GlobalFree(hWork);
741: }
742:
743: if (lpLinkData)
744: FreeLinkData(lpLinkData);
745:
746: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
747: InvalidateRect(hwndList,NULL,TRUE);
748: UpdateWindow(hwndList);
749:
750: WaitForAllObjects();
751:
752: if (aCurDoc)
753: DeleteAtom(aCurDoc);
754:
755: return(TRUE);
756: }
757:
758: /****************************************************************************
759: * DisplayUpdate()
760: *
761: * Get the most up to date rendering information and show it.
762: ***************************************************************************/
763:
764: static VOID DisplayUpdate( //* ENTRY:
765: INT nLinks, //* number of links in listbox
766: HWND hwndList, //* listbox
767: APPITEMPTR *pLinks, //* list of application link handles
768: BOOL fSaveUndo //* save undo objects
769: ){ //* LOCAL:
770: INT i; //* index
771: APPITEMPTR pItem; //* temporary item pointer
772:
773:
774: for (i = 0; i < nLinks; i++)
775: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
776: {
777: pItem = *(pLinks+i);
778: CHECK_IF_STATIC(pItem);
779: if (fSaveUndo)
780: ObjSaveUndo(pItem);
781: Error(OleUpdate(pItem->lpObject));
782: }
783:
784: WaitForAllObjects();
785:
786: }
787:
788: /****************************************************************************
789: * UndoObjects()
790: *
791: * Bring objects back to their original state.
792: ***************************************************************************/
793:
794: static VOID UndoObjects()
795: {
796: APPITEMPTR pItem; //* application item pointer
797: //* enum objects
798: for (pItem = GetTopItem(); pItem; pItem = GetNextItem(pItem))
799: if (pItem->lpObjectUndo)
800: ObjUndo(pItem);
801:
802: WaitForAllObjects();
803:
804: }
805:
806:
807: /****************************************************************************
808: * DelUndoObjects()
809: *
810: * remove all objects created for undo operation.
811: ***************************************************************************/
812:
813: static VOID DelUndoObjects( //* ENTRY:
814: BOOL fPrompt //* prompt user?
815: ){ //* LOCAL:
816: APPITEMPTR pItem; //* application item pointer
817: BOOL fPrompted = FALSE; //* prompted user?
818:
819: for (pItem = GetTopItem(); pItem; pItem = GetNextItem(pItem))
820: {
821: if (pItem->lpObjectUndo)
822: {
823: if (fPrompt && !fPrompted) //* prompt user in activation case
824: {
825: CHAR szPrompt[CBMESSAGEMAX];
826:
827: LoadString(hInst, IDS_SAVE_CHANGES, szPrompt, CBMESSAGEMAX);
828:
829: if (MessageBox(hwndFrame, szPrompt,
830: szAppName, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
831: {
832: UndoObjects();
833: return; //* user canceled operation
834: }
835: fPrompted = TRUE;
836: }
837: ObjDelUndo(pItem); //* delete udo object
838: }
839: }
840:
841: WaitForAllObjects();
842:
843: } //* SUCCESS return
844:
845: /****************************************************************************
846: * CancelLinks()
847: ***************************************************************************/
848:
849: static VOID CancelLinks( //* ENTRY:
850: HWND hDlg, //* calling dialog
851: INT nLinks, //* number of links in listbox
852: HWND hwndList, //* listbox
853: APPITEMPTR *pLinks //* list of application link handles
854: ){ //* LOCAL:
855: APPITEMPTR pItem; //* application item pointer
856: INT i; //* index
857: CHAR pLinkData[OBJECT_LINK_MAX];//* holder of link data
858:
859: SendMessage(hwndList,WM_SETREDRAW,FALSE,0L);
860: for (i = 0; i < nLinks; i++)
861: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
862: {
863: pItem = *(pLinks+i);
864: CHECK_IF_STATIC(pItem);
865: ObjGetData(pItem,pLinkData);
866: ObjSaveUndo(pItem);
867: ObjFreeze(pItem);
868:
869: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pLinkData);
870: }
871:
872: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
873: InvalidateRect(hwndList,NULL,TRUE);
874: UpdateWindow(hwndList);
875:
876: }
877:
878:
879: /****************************************************************************
880: * ChangeUpdateOptions()
881: *
882: * Change the update options for all selected objects.
883: ***************************************************************************/
884:
885: static VOID ChangeUpdateOptions( //* ENTRY:
886: HWND hDlg, //* calling dialog
887: INT nLinks, //* number of links in listbox
888: HWND hwndList, //* listbox
889: APPITEMPTR *pLinks, //* list of application link handles
890: OLEOPT_UPDATE lUpdate //* update option
891: ){ //* LOCAL:
892: APPITEMPTR pItem; //* application item
893: INT i; //* index
894: CHAR pLinkData[OBJECT_LINK_MAX];
895:
896: SendMessage(hwndList,WM_SETREDRAW,FALSE,0L);
897:
898: for (i = 0; i < nLinks; i++) //* enum selected objects
899: {
900: if (SendMessage(hwndList, LB_GETSEL, i, 0L))
901: {
902: pItem = *(pLinks+i);
903: CHECK_IF_STATIC(pItem);
904: ObjGetData(pItem,pLinkData);
905: ObjSaveUndo(pItem);
906: if (Error(OleSetLinkUpdateOptions(pItem->lpObject,lUpdate)))
907: continue;
908: pItem->uoObject = lUpdate;
909:
910: CHANGE_LISTBOX_STRING(hwndList, i, pItem, pLinkData);
911: }
912: }
913:
914: SendMessage(hwndList,WM_SETREDRAW,TRUE,0L);
915: InvalidateRect(hwndList,NULL,TRUE);
916: UpdateWindow(hwndList);
917: WaitForAllObjects();
918:
919: }
920: /****************************************************************************
921: * InvalidLink()
922: *
923: * Deal with letting the user know that the program has inadvertently come
924: * across an invalid link.
925: *
926: * Global fPropBoxActive - flag to determine whether or not the link dialog
927: * box is active. If it is not active we give the
928: * user an opportunity to enter the links property
929: * dialog directly from here.
930: ***************************************************************************/
931:
932: VOID FAR InvalidLink()
933: {
934:
935: if (!hwndProp)
936: DialogBox(hInst, "InvalidLink", hwndFrame, (DLGPROC)fnInvalidLink);
937: else
938: ErrorMessage(E_FAILED_TO_CONNECT);
939:
940: }
941:
942: /****************************************************************************
943: * fnABout()
944: *
945: * About box dialog box procedure.
946: ***************************************************************************/
947:
948: BOOL APIENTRY fnInvalidLink( //* ENTRY:
949: HWND hDlg, //* standard windows dialog box
950: UINT message,
1.1.1.2 ! root 951: WPARAM wParam,
! 952: LPARAM lParam
1.1 root 953: ){
954:
955: switch (message)
956: {
957: case WM_INITDIALOG:
958: return (TRUE);
959:
960: case WM_COMMAND:
961: if (LOWORD(wParam) == IDD_CHANGE)
962: LinkProperties();
963: EndDialog(hDlg, TRUE);
964: return (TRUE);
965: }
966: return (FALSE);
967:
968: }
969:
970: /****************************************************************************
971: * AboutBox()
972: *
973: * Show the About Box dialog.
974: ***************************************************************************/
975:
976: VOID FAR AboutBox()
977: {
978:
979: DialogBox(hInst, "AboutBox", hwndFrame, (DLGPROC)fnAbout);
980:
981: }
982:
983: /****************************************************************************
984: * fnABout()
985: *
986: * About box dialog box procedure.
987: ***************************************************************************/
988:
989: BOOL APIENTRY fnAbout( //* ENTRY:
990: HWND hDlg, //* standard windows dialog box
991: UINT message,
1.1.1.2 ! root 992: WPARAM wParam,
! 993: LPARAM lParam
1.1 root 994: ){
995:
996: switch (message)
997: {
998: case WM_INITDIALOG:
999: return (TRUE);
1000:
1001: case WM_COMMAND:
1002: {
1003: WORD wID = LOWORD(wParam);
1004:
1005: if (wID == IDOK || wID == IDCANCEL)
1006: {
1007: EndDialog(hDlg, TRUE);
1008: return (TRUE);
1009: }
1010: break;
1011: }
1012: }
1013: return (FALSE);
1014:
1015: }
1016:
1017:
1018:
1019: /***************************************************************************
1020: * RetryMessage()
1021: *
1022: * give the user the chance to abort when a server is in retry case.
1023: *
1024: * Returns BOOL - TRUE if user chooses to cancel
1025: **************************************************************************/
1026:
1027: VOID FAR RetryMessage ( //* ENTRY:
1028: APPITEMPTR paItem, //* application item pointer
1029: LONG lParam
1030: ){
1031: RETRYPTR pRetry;
1032: LONG objectType;
1033: HANDLE hData;
1034: static CHAR szServerName[KEYNAMESIZE];
1035: HWND hwnd; //* window handle
1036:
1037: if (IsWindow(hwndProp))
1038: hwnd = hwndProp;
1039: else if (IsWindow(hwndFrame))
1040: hwnd = hwndFrame;
1041: else
1042: return; //* should not happen
1043: //* get the busy servers name
1044: lstrcpy(szServerName, "server application");
1045:
1046: if (paItem)
1047: {
1048: if (!paItem->aServer)
1049: {
1050: OleQueryType(paItem->lpObject, &objectType );
1051: if (OLE_OK == OleGetData(paItem->lpObject, (OLECLIPFORMAT) (objectType == OT_LINK ? vcfLink : vcfOwnerLink), &hData ))
1052: {
1053: RegGetClassId(szServerName, GlobalLock(hData));
1054: paItem->aServer = AddAtom(szServerName);
1055: GlobalUnlock( hData );
1056: }
1057: }
1058: else
1059: GetAtomName(paItem->aServer,szServerName,KEYNAMESIZE);
1060:
1061: }
1062:
1063: hData = LocalAlloc(LHND,sizeof(RETRYSTRUCT));
1064: if(!(pRetry = (RETRYPTR)LocalLock(hData)))
1065: return;
1066:
1067: pRetry->lpserver = (LPSTR)szServerName;
1068: pRetry->bCancel = (BOOL)(lParam & RD_CANCEL);
1069: pRetry->paItem = paItem;
1070:
1071: DialogBoxParam(hInst, "RetryBox", hwnd, (DLGPROC)fnRetry, (LONG)pRetry );
1072:
1073: LocalUnlock(hData);
1074: LocalFree(hData);
1075:
1076: hRetry = NULL;
1077:
1078: }
1079:
1080: /****************************************************************************
1081: * fnRetry()
1082: *
1083: * Retry message box nothing to tricky; however, when a server becomes
1084: * unbusy a message is posted to automatically get rid of this dialog.
1085: * I send a no.
1086: ***************************************************************************/
1087:
1088: BOOL APIENTRY fnRetry( //* ENTRY
1089: HWND hDlg, //* standard dialog entry
1090: UINT message,
1.1.1.2 ! root 1091: WPARAM wParam,
! 1092: LPARAM lParam
1.1 root 1093: ){
1094: static RETRYPTR pRetry;
1095:
1096: switch (message)
1097: {
1098: case WM_COMMAND:
1099: {
1100: WORD wID = LOWORD(wParam);
1101:
1102: switch (wParam)
1103: {
1104: case IDD_SWITCH:
1105: DefWindowProc( hDlg, WM_SYSCOMMAND, SC_TASKLIST, NULL);
1106: break;
1107:
1108: case IDCANCEL:
1109: if (pRetry->paItem)
1110: pRetry->paItem->fRetry = FALSE;
1111: EndDialog(hDlg, TRUE);
1112: return TRUE;
1113:
1114: default:
1115: break;
1116: }
1117: break;
1118: }
1119:
1120: case WM_INITDIALOG:
1121: {
1122: CHAR szBuffer[CBMESSAGEMAX];
1123: CHAR szText[2*CBMESSAGEMAX];
1124:
1125: pRetry = (RETRYPTR)lParam;
1126: hRetry = hDlg;
1127:
1128: LoadString(hInst, IDS_RETRY_TEXT1, szBuffer, CBMESSAGEMAX);
1129: wsprintf(szText, szBuffer, pRetry->lpserver);
1130: SetWindowText (GetDlgItem(hDlg, IDD_RETRY_TEXT1), szText);
1131:
1132: LoadString(hInst, IDS_RETRY_TEXT2, szBuffer, CBMESSAGEMAX);
1133: wsprintf(szText, szBuffer, pRetry->lpserver);
1134: SetWindowText (GetDlgItem(hDlg, IDD_RETRY_TEXT2), szText);
1135:
1136: EnableWindow (GetDlgItem(hDlg, IDCANCEL), pRetry->bCancel);
1137:
1138: return TRUE;
1139: }
1140:
1141: default:
1142: break;
1143: }
1144:
1145: return FALSE;
1146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.