Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
11 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #include "windows.h"
  5. #include "mw.h"
  6. #include "winddefs.h"
  7. #include "obj.h"
  8. #include "objreg.h"
  9. #include "str.h"
  10. static BOOL GetClipObjectInfo(LPSTR szClass, LPSTR szItem);
  11. BOOL QueryPasteFromClip(OLEOPT_RENDER lpRender, OLECLIPFORMAT lpFormat);
  12. BOOL QueryLinkFromClip(OLEOPT_RENDER lpRender, OLECLIPFORMAT lpFormat);
  13. static int FillListFormat(HWND hwndList, BOOL bObjAvail);
  14. static WORD GetFormatClip(int i);
  15. static BOOL IsFormatAvailable(WORD cfFormat);
  16. WORD cfObjPasteSpecial;
  17. BOOL vObjPasteLinkSpecial;
  18. WORD rgchFormats[5];
  19. int irgchFormats = 0;
  20. void fnObjPasteSpecial(void)
  21. {
  22. if (OurDialogBox(hINSTANCE, "PasteSpecial", hMAINWINDOW, lpfnPasteSpecial))
  23. fnPasteEdit();
  24. cfObjPasteSpecial = 0; // clear it for next time
  25. vbObjLinkOnly = vObjPasteLinkSpecial = FALSE;
  26. }
  27. int FAR PASCAL fnPasteSpecial(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  28. {
  29. extern HWND vhWndMsgBoxParent;
  30. static BOOL bLinkAvail,bObjAvail;
  31. extern BOOL ferror;
  32. switch (message)
  33. {
  34. case WM_INITDIALOG:
  35. {
  36. char szClassName[KEYNAMESIZE];
  37. char szItemName[CBPATHMAX];
  38. int nWhichToSelect;
  39. HWND hwndList = GetDlgItem(hDlg,IDD_LISTBOX);
  40. szClassName[0] = szItemName[0] = '\0';
  41. irgchFormats = 0; //always start with 0
  42. vObjPasteLinkSpecial = vbObjLinkOnly = FALSE;
  43. bObjAvail = OleQueryCreateFromClip(PROTOCOL, olerender_draw, 0) == OLE_OK;
  44. bLinkAvail = OleQueryLinkFromClip(PROTOCOL, olerender_draw, 0) == OLE_OK;
  45. if (bObjAvail || bLinkAvail)
  46. {
  47. GetClipObjectInfo(szClassName, szItemName);
  48. SetWindowText(GetDlgItem(hDlg,IDD_CLIPOWNER), szClassName);
  49. SetWindowText(GetDlgItem(hDlg,IDD_ITEM), szItemName);
  50. }
  51. else
  52. ShowWindow(GetDlgItem(hDlg,IDD_SOURCE), SW_HIDE);
  53. if (bObjAvail || bLinkAvail)
  54. /* then there's an object on clipboard */
  55. {
  56. char szListItem[CBMESSAGEMAX]; // hope this is big enough!
  57. char szTmp[CBMESSAGEMAX];
  58. LoadString(hINSTANCE, IDSTRObject, szTmp, sizeof(szTmp));
  59. wsprintf(szListItem,"%s %s",(LPSTR)szClassName,(LPSTR)szTmp);
  60. SendMessage(hwndList, LB_INSERTSTRING, irgchFormats, (DWORD)(LPSTR)szListItem);
  61. if (bObjAvail)
  62. rgchFormats[irgchFormats++] = vcfOwnerLink;
  63. else
  64. rgchFormats[irgchFormats++] = vcfLink;
  65. }
  66. nWhichToSelect = FillListFormat(hwndList,bObjAvail || bLinkAvail);
  67. /* select what Write would normally take */
  68. SendMessage(hwndList, LB_SETCURSEL, nWhichToSelect, 0L);
  69. EnableWindow(GetDlgItem(hDlg, IDD_PASTELINK), bLinkAvail &&
  70. rgchFormats[nWhichToSelect] != CF_TEXT);
  71. if (!bObjAvail && bLinkAvail)
  72. /* then we've got the object format in the list box, but don't want to
  73. enable paste if its selected */
  74. EnableWindow(GetDlgItem(hDlg, IDD_PASTE), nWhichToSelect != 0);
  75. return TRUE;
  76. }
  77. case WM_ACTIVATE:
  78. if (wParam)
  79. vhWndMsgBoxParent = hDlg;
  80. break;
  81. case WM_SYSCOMMAND:
  82. switch(wParam & 0xFFF0)
  83. {
  84. case SC_CLOSE:
  85. OurEndDialog(hDlg, FALSE);
  86. break;
  87. }
  88. break;
  89. case WM_COMMAND:
  90. switch (wParam)
  91. {
  92. case IDD_LISTBOX:
  93. switch (HIWORD(lParam))
  94. {
  95. case LBN_DBLCLK:
  96. SendMessage(hDlg,WM_COMMAND,IDD_PASTE,0L);
  97. return TRUE;
  98. case LBN_SELCHANGE:
  99. if (!bObjAvail && bLinkAvail)
  100. /* then we've got the object format in the list box, but don't want to
  101. enable paste if its selected */
  102. EnableWindow(GetDlgItem(hDlg, IDD_PASTE),
  103. SendMessage(LOWORD(lParam), LB_GETCURSEL, 0, 0L) != 0);
  104. EnableWindow(GetDlgItem(hDlg, IDD_PASTELINK),
  105. bLinkAvail &&
  106. (GetFormatClip(SendMessage(LOWORD(lParam), LB_GETCURSEL, 0, 0L)) != CF_TEXT));
  107. return TRUE;
  108. }
  109. break;
  110. case IDD_PASTE:
  111. case IDD_PASTELINK:
  112. {
  113. int i;
  114. if (LB_ERR == (i = (WORD)SendMessage(GetDlgItem(hDlg, IDD_LISTBOX), LB_GETCURSEL, 0, 0L)))
  115. break;
  116. cfObjPasteSpecial = GetFormatClip(i);
  117. if (!IsFormatAvailable(cfObjPasteSpecial))
  118. /* somebody changed clip contents while in dialog */
  119. {
  120. Error(IDPMTFormat);
  121. ferror=FALSE; // reenable error messages
  122. SendMessage(GetDlgItem(hDlg,IDD_LISTBOX), LB_RESETCONTENT, 0, 0L);
  123. SendMessage(hDlg, WM_INITDIALOG, 0, 0L);
  124. break;
  125. }
  126. if (wParam == IDD_PASTELINK)
  127. if (i > 0)
  128. vObjPasteLinkSpecial = TRUE;
  129. else
  130. vbObjLinkOnly = TRUE;
  131. OurEndDialog(hDlg, TRUE);
  132. }
  133. break;
  134. case IDCANCEL:
  135. OurEndDialog(hDlg, FALSE);
  136. break;
  137. }
  138. break;
  139. }
  140. return FALSE;
  141. }
  142. static int FillListFormat(HWND hwndList, BOOL bObjAvail)
  143. /* fill hwndList with all the formats available on clipboard */
  144. /* return index of which format Write would normally take */
  145. {
  146. WORD cfFormat = NULL;
  147. int nDefFormat= -1;
  148. char szFormat[cchMaxSz];
  149. BOOL bFoundDefault = FALSE;
  150. OpenClipboard(hDOCWINDOW);
  151. /** priority order:
  152. if (bObjAvail)
  153. If text comes before native, then text is default.
  154. else object is default
  155. else no object available
  156. if text is there it is the default,
  157. else default is first come first server of bitmap, metafile or DIB
  158. **/
  159. while (cfFormat = EnumClipboardFormats(cfFormat))
  160. switch(cfFormat)
  161. {
  162. case CF_BITMAP:
  163. LoadString(hINSTANCE, IDSTRBitmap, szFormat, sizeof(szFormat));
  164. SendMessage(hwndList, LB_INSERTSTRING, irgchFormats, (DWORD)(LPSTR)szFormat);
  165. if (!bObjAvail)
  166. if (!bFoundDefault)
  167. {
  168. nDefFormat = irgchFormats;
  169. bFoundDefault = TRUE;
  170. }
  171. rgchFormats[irgchFormats++] = cfFormat;
  172. break;
  173. case CF_METAFILEPICT:
  174. LoadString(hINSTANCE, IDSTRPicture, szFormat, sizeof(szFormat));
  175. SendMessage(hwndList, LB_INSERTSTRING, irgchFormats, (DWORD)(LPSTR)szFormat);
  176. if (!bObjAvail)
  177. if (!bFoundDefault)
  178. {
  179. nDefFormat = irgchFormats;
  180. bFoundDefault = TRUE;
  181. }
  182. rgchFormats[irgchFormats++] = cfFormat;
  183. break;
  184. case CF_DIB:
  185. LoadString(hINSTANCE, IDSTRDIB, szFormat, sizeof(szFormat));
  186. SendMessage(hwndList, LB_INSERTSTRING, irgchFormats, (DWORD)(LPSTR)szFormat);
  187. if (!bObjAvail)
  188. if (!bFoundDefault)
  189. {
  190. nDefFormat = irgchFormats;
  191. bFoundDefault = TRUE;
  192. }
  193. rgchFormats[irgchFormats++] = cfFormat;
  194. break;
  195. case CF_TEXT:
  196. LoadString(hINSTANCE, IDSTRText, szFormat, sizeof(szFormat));
  197. SendMessage(hwndList, LB_INSERTSTRING, irgchFormats, (DWORD)(LPSTR)szFormat);
  198. if (bObjAvail)
  199. {
  200. if (!bFoundDefault)
  201. /* then found text before native */
  202. nDefFormat = irgchFormats;
  203. }
  204. else
  205. nDefFormat = irgchFormats;
  206. rgchFormats[irgchFormats++] = cfFormat;
  207. bFoundDefault = TRUE;
  208. break;
  209. default:
  210. if (!bFoundDefault && (cfFormat == vcfNative))
  211. {
  212. bFoundDefault = TRUE;
  213. nDefFormat = 0;
  214. }
  215. break;
  216. } //end switch
  217. CloseClipboard();
  218. if (nDefFormat == -1)
  219. nDefFormat = 0;
  220. return nDefFormat;
  221. }
  222. static WORD GetFormatClip(int i)
  223. {
  224. return rgchFormats[i];
  225. }
  226. static BOOL GetClipObjectInfo(LPSTR szClass, LPSTR szItem)
  227. /* get the classname, item name for the owner of the clipboard */
  228. /* return TRUE if error */
  229. /* only gets ownerlink class, assumes its available */
  230. {
  231. HANDLE hData=NULL;
  232. LPSTR lpData=NULL;
  233. BOOL bRetval = TRUE;
  234. char szFullItem[CBPATHMAX],*pch;
  235. OpenClipboard( hDOCWINDOW );
  236. if ((hData = GetClipboardData(vcfOwnerLink)) == NULL)
  237. if ((hData = GetClipboardData(vcfLink)) == NULL)
  238. {
  239. bRetval = TRUE;
  240. goto end;
  241. }
  242. if ((lpData = GlobalLock(hData)) == NULL)
  243. goto end;
  244. /**** get szClass ****/
  245. RegGetClassId(szClass,lpData);
  246. /**** get szName ****/
  247. while(*lpData++); // skip class key
  248. pch = szFullItem;
  249. /* first doc name */
  250. do
  251. *pch++ = *lpData;
  252. while(*lpData++);
  253. /* second item name (if there) */
  254. if (*lpData)
  255. {
  256. *(pch-1) = ' ';
  257. do
  258. *pch++ = *lpData;
  259. while(*lpData++);
  260. }
  261. /* get rid of path. pch now points to \0 */
  262. #ifdef DBCS //T-HIROYN 1992.07.13
  263. pch = AnsiPrev(szFullItem,pch); //02/26/93 T-HIROYN
  264. while (pch != szFullItem) {
  265. if ((*(pch) == '\\') || (*(pch) == ':')) {
  266. pch++;
  267. break;
  268. }
  269. else
  270. pch = AnsiPrev(szFullItem,pch);
  271. }
  272. if ((*(pch) == '\\') || (*(pch) == ':')) //02/26/93 T-HIROYN
  273. pch++;
  274. #else
  275. --pch;
  276. while (pch != szFullItem)
  277. if ((*(pch-1) == '\\') || (*(pch-1) == ':'))
  278. break;
  279. else
  280. --pch;
  281. #endif
  282. lstrcpy(szItem,(LPSTR)pch);
  283. bRetval = FALSE;
  284. end:
  285. if (lpData)
  286. GlobalUnlock(hData);
  287. CloseClipboard();
  288. return bRetval;
  289. }
  290. static BOOL IsFormatAvailable(WORD cfFormat)
  291. {
  292. BOOL bRetval;
  293. OpenClipboard(hDOCWINDOW);
  294. bRetval = IsClipboardFormatAvailable(cfFormat);
  295. CloseClipboard();
  296. return bRetval;
  297. }
  298.