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.

281 lines
6.7 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* clipdisp.c -- Clipboard display routines */
  5. /* This module only gets called in when the clipboard view window is up */
  6. #define NOVIRTUALKEYCODES
  7. #define NOWINSTYLES
  8. #define NOGDICAPMASKS
  9. #define NOSYSMETRICS
  10. #define NOMENUS
  11. #define NOCTLMGR
  12. #include "windows.h"
  13. #include "mw.h"
  14. #include "docdefs.h"
  15. #include "cmddefs.h"
  16. #include "str.h"
  17. #include "propdefs.h"
  18. #include "editdefs.h"
  19. #include "winddefs.h"
  20. #include "dispdefs.h"
  21. #include "wwdefs.h"
  22. #if defined(OLE)
  23. #include "obj.h"
  24. #endif
  25. #define SCRIBBLE
  26. #include "debug.h"
  27. extern int docCur; /* Document in current ww */
  28. extern int docScrap;
  29. extern struct WWD rgwwd [];
  30. int NEAR FGetClipboardDC( void );
  31. int NEAR SetupClipboardDC( void );
  32. int NEAR ReleaseClipboardDC( void );
  33. MdocPaintClipboard( hWnd, hPS )
  34. HWND hWnd;
  35. HANDLE hPS;
  36. { /* Paint portion of clipboard window indicated by hPS */
  37. LPPAINTSTRUCT lpps;
  38. if (wwClipboard == wwNil)
  39. return;
  40. /* Must set the scroll bar range each time we get a PAINT message;
  41. CLIPBRD.EXE resets it when it gets WM_DRAWCLIPBOARD */
  42. SetScrollRange( wwdClipboard.wwptr, SB_VERT, 0, drMax-1, FALSE );
  43. SetScrollRange( wwdClipboard.wwptr, SB_HORZ, 0, xpRightLim, FALSE );
  44. if ( (lpps = (LPPAINTSTRUCT)GlobalLock( hPS )) != NULL )
  45. { /* Paint the clipboard */
  46. wwdClipboard.hDC = lpps->hdc;
  47. SetupClipboardDC();
  48. NewCurWw( wwClipboard, TRUE );
  49. InvalBand( &wwdClipboard, lpps->rcPaint.top, lpps->rcPaint.bottom - 1 );
  50. UpdateWw( wwClipboard, FALSE );
  51. NewCurWw( wwDocument, TRUE );
  52. GlobalUnlock( hPS );
  53. }
  54. /* Since the DC is no longer good, we'll set it to NULL */
  55. wwdClipboard.hDC = NULL;
  56. #if 0
  57. #if defined(OLE)
  58. /* gotta delete objects loaded from scrap document */
  59. ObjEnumInDoc(docScrap,ObjDeleteObjectInDoc);
  60. #endif
  61. #endif
  62. }
  63. MdocSizeClipboard( hWnd, hRC )
  64. HWND hWnd;
  65. HANDLE hRC;
  66. { /* Set clipboard window to be the rect in hRC */
  67. /* If rectangle is 0 units high or wide, this means we're losing the
  68. necessity for display until the next size message */
  69. LPRECT lprc;
  70. int dypRect;
  71. if ( (lprc = (LPRECT)GlobalLock( hRC )) == NULL )
  72. return;
  73. if ( (dypRect = lprc->bottom - lprc->top) <= 0 )
  74. { /* NULL rect, means lose display until we get a nonnull size */
  75. if (wwClipboard != wwNil)
  76. FreeWw( wwClipboard );
  77. }
  78. else if ( (wwClipboard != wwNil) ||
  79. ((wwClipboard=WwAlloc( hWnd, docScrap )) != wwNil))
  80. { /* Have WWD entry for clipboard, set its size */
  81. wwdClipboard.wwptr = hWnd; /* Just in case clipboard
  82. was closed, then re-opened */
  83. wwdClipboard.xpMin = lprc->left;
  84. wwdClipboard.xpMac = lprc->right;
  85. wwdClipboard.ypMin = lprc->top;
  86. wwdClipboard.ypMac = lprc->bottom;
  87. #ifdef WIN30
  88. SetScrollPos(hWnd, SB_HORZ, 0, TRUE); /* suggested by sankar */
  89. #endif
  90. }
  91. GlobalUnlock( hRC );
  92. }
  93. MdocVScrollClipboard( hWnd, sbMessage, wNewThumb )
  94. HWND hWnd;
  95. int sbMessage;
  96. int wNewThumb;
  97. {
  98. if ( hWnd != wwdClipboard.wwptr || wwClipboard == wwNil)
  99. {
  100. Assert( FALSE );
  101. return;
  102. }
  103. if (!FGetClipboardDC())
  104. /* Unable to create clipboard device context */
  105. return;
  106. NewCurWw( wwClipboard, TRUE );
  107. switch ( sbMessage )
  108. {
  109. case SB_THUMBPOSITION:
  110. {
  111. extern typeCP cpMacCur;
  112. DirtyCache( wwdClipboard.cpFirst = (cpMacCur - wwdClipboard.cpMin) *
  113. wNewThumb / (drMax - 1) + wwdClipboard.cpMin);
  114. wwdClipboard.ichCpFirst = 0;
  115. wwdClipboard.fCpBad = TRUE;
  116. TrashWw( wwClipboard );
  117. break;
  118. }
  119. case SB_LINEUP:
  120. ScrollUpCtr( 1 );
  121. break;
  122. case SB_LINEDOWN:
  123. ScrollDownCtr( 1 );
  124. break;
  125. case SB_PAGEUP:
  126. ScrollUpDypWw();
  127. break;
  128. case SB_PAGEDOWN:
  129. ScrollDownCtr( 100 ); /* 100 > tr's in a page */
  130. break;
  131. }
  132. UpdateWw( wwClipboard, FALSE );
  133. NewCurWw( wwDocument, TRUE ); /* Frees the memory DC */
  134. ReleaseClipboardDC();
  135. }
  136. MdocHScrollClipboard( hWnd, sbMessage, wNewThumb )
  137. HWND hWnd;
  138. int sbMessage;
  139. int wNewThumb;
  140. {
  141. if ( hWnd != wwdClipboard.wwptr || wwClipboard == wwNil)
  142. {
  143. Assert( FALSE );
  144. return;
  145. }
  146. if (!FGetClipboardDC())
  147. /* Unable to create clipboard device context */
  148. return;
  149. NewCurWw( wwClipboard, TRUE );
  150. switch (sbMessage)
  151. {
  152. case SB_LINEUP: /* line left */
  153. ScrollRight(xpMinScroll);
  154. break;
  155. case SB_LINEDOWN: /* line right */
  156. ScrollLeft(xpMinScroll);
  157. break;
  158. case SB_PAGEUP: /* page left */
  159. ScrollRight(wwdClipboard.xpMac - xpSelBar);
  160. break;
  161. case SB_PAGEDOWN: /* page right */
  162. ScrollLeft(wwdClipboard.xpMac - xpSelBar);
  163. break;
  164. case SB_THUMBPOSITION:
  165. /* position to posNew */
  166. AdjWwHoriz( wNewThumb - wwdClipboard.xpMin );
  167. break;
  168. }
  169. UpdateWw( wwClipboard, FALSE );
  170. NewCurWw( wwDocument, TRUE ); /* Frees the memory DC */
  171. ReleaseClipboardDC();
  172. }
  173. MdocAskCBFormatName( lpchName, cchNameMax )
  174. LPCH lpchName;
  175. int cchNameMax;
  176. { /* Copy the format name for the current contents of the clipboard
  177. (of which we are the owner) to lpchName, copying no more than
  178. cchNameMax characters */
  179. extern int vfOwnClipboard;
  180. extern int vfScrapIsPic;
  181. extern CHAR szWRITEText[];
  182. int cchCopy;
  183. Assert( vfOwnClipboard );
  184. /* Don't give a format name for pictures; the name is covered by the
  185. standard types */
  186. if (!vfScrapIsPic)
  187. {
  188. if ( (cchCopy=CchSz( szWRITEText )) > cchNameMax )
  189. {
  190. lpchName[ cchCopy = cchNameMax - 1 ] = '\0';
  191. }
  192. bltbx( (LPSTR)szWRITEText, (LPSTR)lpchName, cchCopy );
  193. }
  194. }
  195. int NEAR FGetClipboardDC()
  196. { /* Get a DC for the clipboard window. Leave it in rgwwd [wwClipboard].
  197. Call SetupClipboardDC to set up proper colors */
  198. if ((wwdClipboard.hDC = GetDC( wwdClipboard.wwptr )) == NULL )
  199. return FALSE;
  200. SetupClipboardDC();
  201. return TRUE;
  202. }
  203. int NEAR SetupClipboardDC()
  204. { /* Select in the background brush for appropriate color behavior. */
  205. extern long rgbBkgrnd;
  206. extern long rgbText;
  207. extern HBRUSH hbrBkgrnd;
  208. SelectObject( wwdClipboard.hDC, hbrBkgrnd );
  209. SetBkColor( wwdClipboard.hDC, rgbBkgrnd );
  210. SetTextColor( wwdClipboard.hDC, rgbText );
  211. }
  212. int NEAR ReleaseClipboardDC()
  213. {
  214. ReleaseDC( wwdClipboard.wwptr, wwdClipboard.hDC );
  215. wwdClipboard.hDC = NULL; /* Mark clipboard DC as invalid */
  216. }
  217.