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.

357 lines
10 KiB

  1. /*****************************************************************************
  2. C L I P B O O K I N I T
  3. Name: cvinit.c
  4. Date: 21-Jan-1994
  5. Creator: Unknown
  6. *****************************************************************************/
  7. #define OEMRESOURCE
  8. #include <windows.h>
  9. #include <commctrl.h>
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include "common.h"
  13. #include "clipbook.h"
  14. #include "clipbrd.h"
  15. #include "clipdsp.h"
  16. #include "cvinit.h"
  17. #include "debugout.h"
  18. static int SSplit[] = { 200, 500 };
  19. static int SBorders[3] = { 20, 0, 0 };
  20. HWND hwndToolbar = NULL;
  21. HWND hwndStatus = NULL;
  22. HBITMAP hbmStatus = NULL;
  23. TCHAR szWindows[] = TEXT("Windows");
  24. DWORD nIDs[] =
  25. {
  26. MH_BASE ,MH_POPUPBASE, 0, 0 /* This list must be NULL terminated */
  27. };
  28. TBBUTTON tbButtons[] = {
  29. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  30. {0, IDM_CONNECT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  31. {1, IDM_DISCONNECT,TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  32. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  33. {2, IDM_SHARE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  34. {3, IDM_UNSHARE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  35. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  36. {5, IDM_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  37. {6, IDM_KEEP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  38. {7, IDM_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  39. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  40. {8, IDM_LISTVIEW, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP,0},
  41. {9, IDM_PREVIEWS, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP,0},
  42. {10, IDM_PAGEVIEW, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP,0}
  43. };
  44. VOID LoadIntlStrings (void)
  45. {
  46. LoadString (hInst, IDS_HELV, szHelv, SMLRCBUF);
  47. LoadString (hInst, IDS_APPNAME, szAppName, SMLRCBUF);
  48. LoadString (hInst, IDS_LOCALCLIP, szLocalClpBk, SMLRCBUF);
  49. LoadString (hInst, IDS_CLIPBOARD, szSysClpBrd, SMLRCBUF);
  50. LoadString (hInst, IDS_DATAUNAVAIL, szDataUnavail, BIGRCBUF);
  51. LoadString (hInst, IDS_READINGITEM, szReadingItem, BIGRCBUF);
  52. LoadString (hInst, IDS_VIEWHELPFMT, szViewHelpFmt, BIGRCBUF);
  53. LoadString (hInst, IDS_ACTIVATEFMT, szActivateFmt, BIGRCBUF);
  54. LoadString (hInst, IDS_RENDERING, szRendering, BIGRCBUF);
  55. LoadString (hInst, IDS_DEFFORMAT, szDefaultFormat, BIGRCBUF);
  56. LoadString (hInst, IDS_GETTINGDATA, szGettingData, BIGRCBUF);
  57. LoadString (hInst, IDS_ESTABLISHING, szEstablishingConn, BIGRCBUF);
  58. LoadString (hInst, IDS_CLIPBOOKONFMT, szClipBookOnFmt, BIGRCBUF);
  59. LoadString (hInst, IDS_PAGEFMT, szPageFmt, SMLRCBUF);
  60. LoadString (hInst, IDS_PAGEFMTPL, szPageFmtPl, SMLRCBUF);
  61. LoadString (hInst, IDS_PAGEOFPAGEFMT, szPageOfPageFmt, SMLRCBUF);
  62. LoadString (hInst, IDS_DELETE, szDelete, SMLRCBUF);
  63. LoadString (hInst, IDS_DELETECONFIRMFMT, szDeleteConfirmFmt, SMLRCBUF);
  64. LoadString (hInst, IDS_FILEFILTER, szFileFilter, BIGRCBUF);
  65. }
  66. VOID SaveWindowPlacement (
  67. PWINDOWPLACEMENT pwp )
  68. {
  69. WINDOWPLACEMENT wp;
  70. int dir_num = 0;
  71. HWND hwnd;
  72. // save main window placement
  73. if (hkeyRoot != NULL)
  74. {
  75. pwp->length = sizeof(WINDOWPLACEMENT);
  76. lstrcat(lstrcpy(szBuf2, szWindows), szAppName);
  77. RegSetValueEx(hkeyRoot,
  78. szBuf2,
  79. 0L,
  80. REG_BINARY,
  81. (LPBYTE)pwp,
  82. sizeof(WINDOWPLACEMENT));
  83. // write out dir window strings in reverse order
  84. // so that when we read them back in we get the same Z order
  85. wp.length = sizeof (WINDOWPLACEMENT);
  86. wp.flags = 0;
  87. for (hwnd = GetWindow(hwndMDIClient, GW_CHILD); hwnd;
  88. hwnd = GetWindow(hwnd, GW_HWNDNEXT))
  89. {
  90. // don't save MDI icon title windows or search windows,
  91. // or any dir window which is currently recursing
  92. if (GetWindow(hwnd, GW_OWNER) == NULL &&
  93. GetWindowPlacement(hwnd, &wp) )
  94. {
  95. wp.length = sizeof(WINDOWPLACEMENT);
  96. wp.flags = (wp.showCmd == SW_SHOWMINIMIZED)
  97. ? WPF_SETMINPOSITION : 0;
  98. if (GETMDIINFO(hwnd))
  99. lstrcat(lstrcpy(szBuf2, szWindows), GETMDIINFO(hwnd)->szBaseName);
  100. RegSetValueEx(hkeyRoot,
  101. szBuf2,
  102. 0L,
  103. REG_BINARY,
  104. (LPBYTE)&wp,
  105. sizeof(wp));
  106. }
  107. }
  108. }
  109. }
  110. BOOL ReadWindowPlacement(
  111. LPTSTR szKey,
  112. PWINDOWPLACEMENT pwp)
  113. {
  114. // AnsiToOem ( szKey, szBuf2 );
  115. if (hkeyRoot != NULL)
  116. {
  117. DWORD dwBufSize = sizeof(WINDOWPLACEMENT);
  118. lstrcat(lstrcpy(szBuf2, szWindows), szKey);
  119. RegQueryValueEx(hkeyRoot, szBuf2, NULL, NULL, (LPBYTE)pwp, &dwBufSize);
  120. if (pwp->length == sizeof(WINDOWPLACEMENT))
  121. {
  122. return TRUE;
  123. }
  124. else
  125. {
  126. PINFO(TEXT("ReadWindowPlacement: QueryValue failed\n\r"));
  127. }
  128. return FALSE;
  129. }
  130. PINFO(TEXT("ReadWindowPlacement: no entry\n\r"));
  131. return FALSE;
  132. }
  133. BOOL CreateTools(
  134. HWND hwnd)
  135. {
  136. HDC hdc;
  137. TEXTMETRIC tm;
  138. int dyBorder;
  139. int cx,cy;
  140. HFONT hTmpFont;
  141. SIZE size;
  142. if ( !(hbrBackground = CreateSolidBrush ( GetSysColor(COLOR_WINDOW) )))
  143. return FALSE;
  144. if ( !(hbmStatus = CreateMappedBitmap(hInst, IDSTATUS, FALSE, NULL, 0)))
  145. return FALSE;
  146. // create toolbar and status bar windows
  147. // has all buttons initially...
  148. if ( !(hwndToolbar = CreateToolbarEx (hwnd,
  149. (fToolBar?WS_VISIBLE:0)|WS_BORDER|TBSTYLE_TOOLTIPS,
  150. IDC_TOOLBAR,
  151. 11,
  152. hInst,
  153. IDBITMAP,
  154. tbButtons,
  155. sizeof(tbButtons)/sizeof(TBBUTTON),
  156. 0,0,0,0,sizeof(TBBUTTON))))
  157. return FALSE;
  158. // get rid of share buttons?
  159. if (!fShareEnabled)
  160. {
  161. SendMessage (hwndToolbar, TB_DELETEBUTTON, 3, 0L);
  162. SendMessage (hwndToolbar, TB_DELETEBUTTON, 3, 0L);
  163. SendMessage (hwndToolbar, TB_DELETEBUTTON, 3, 0L);
  164. }
  165. // get rid of connect/disonnect buttons?
  166. if (!fNetDDEActive)
  167. {
  168. SendMessage (hwndToolbar, TB_DELETEBUTTON, 0, 0L);
  169. SendMessage (hwndToolbar, TB_DELETEBUTTON, 0, 0L);
  170. SendMessage (hwndToolbar, TB_DELETEBUTTON, 0, 0L);
  171. }
  172. if ( fToolBar )
  173. ShowWindow ( hwndToolbar, SW_SHOW );
  174. // create status bar
  175. if ( !(hwndStatus = CreateStatusWindow ((fStatus?WS_VISIBLE:0)|WS_BORDER|WS_CHILD|WS_CLIPSIBLINGS,
  176. szNull,
  177. hwnd,
  178. IDSTATUS )))
  179. return FALSE;
  180. // now build the parameters based on the font we will be using
  181. dyBorder = GetSystemMetrics(SM_CYBORDER);
  182. cx = GetSystemMetrics (SM_CXVSCROLL);
  183. cy = GetSystemMetrics (SM_CYHSCROLL);
  184. if ( hdc= GetDC(NULL) )
  185. {
  186. CHARSETINFO csi;
  187. DWORD dw = GetACP();
  188. LOGFONT lfDef;
  189. GetObject( GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lfDef );
  190. if (!TranslateCharsetInfo((DWORD*)(DWORD_PTR)dw, &csi, TCI_SRCCODEPAGE))
  191. csi.ciCharset = ANSI_CHARSET;
  192. hPreviewBmp = CreateBitmap ( 64, 64, 1, 1, NULL );
  193. hBtnDC = CreateCompatibleDC ( hdc );
  194. hPgUpBmp = LoadBitmap ( hInst, MAKEINTRESOURCE(IBM_UPARROW) );
  195. hPgDnBmp = LoadBitmap ( hInst, MAKEINTRESOURCE(IBM_DNARROW) );
  196. hPgUpDBmp = LoadBitmap ( hInst, MAKEINTRESOURCE(IBM_UPARROWD) );
  197. hPgDnDBmp = LoadBitmap ( hInst, MAKEINTRESOURCE(IBM_DNARROWD) );
  198. hFontPreview = CreateFont (lfDef.lfHeight,
  199. 0,
  200. 0,
  201. 0,
  202. 400,
  203. 0,
  204. 0,
  205. 0,
  206. csi.ciCharset,
  207. OUT_DEFAULT_PRECIS,
  208. CLIP_DEFAULT_PRECIS,
  209. DEFAULT_QUALITY,
  210. VARIABLE_PITCH | FF_SWISS,
  211. szHelv);
  212. hOldFont = SelectObject(hdc, hFontPreview);
  213. GetTextMetrics(hdc, &tm);
  214. dyPrevFont = tm.tmHeight + tm.tmExternalLeading;
  215. if (hOldFont)
  216. SelectObject(hdc, hOldFont);
  217. // figure out where to put the first status bar splitpoint
  218. SendMessage ( hwndStatus, SB_GETBORDERS, 0, (LPARAM)(LPBYTE)&SBorders );
  219. if ( hTmpFont = (HFONT)SendMessage(hwndStatus, WM_GETFONT, 0, 0L ))
  220. {
  221. if ( hOldFont = SelectObject ( hdc, hTmpFont ))
  222. {
  223. wsprintf ( szBuf, szPageOfPageFmt, 888, 888 );
  224. GetTextExtentPoint(hdc, szBuf, lstrlen(szBuf),&size);
  225. SSplit[0] = size.cx + 2 * GetSystemMetrics(SM_CXBORDER)
  226. + 2 * SBorders[0];
  227. if ( hOldFont )
  228. SelectObject( hdc, hOldFont );
  229. }
  230. }
  231. ReleaseDC(NULL, hdc);
  232. if ( !hTmpFont || !hPgUpBmp || !hPgDnBmp || !hPgUpDBmp ||
  233. !hFontPreview || !hPreviewBmp || !hBtnDC )
  234. return FALSE;
  235. }
  236. else
  237. return FALSE;
  238. //second split point is fixed for now.
  239. SendMessage ( hwndStatus, SB_SETPARTS, 2, (LPARAM)(LPBYTE)&SSplit );
  240. return TRUE;
  241. }
  242. VOID DeleteTools (
  243. HWND hwnd)
  244. {
  245. DeleteDC ( hBtnDC );
  246. DeleteObject ( hPreviewBmp );
  247. DeleteObject ( hbmStatus );
  248. DeleteObject ( hFontPreview );
  249. DeleteObject ( hbrBackground );
  250. DeleteObject ( hPgUpBmp );
  251. DeleteObject ( hPgDnBmp );
  252. DeleteObject ( hPgUpDBmp );
  253. DeleteObject ( hPgDnDBmp );
  254. DestroyWindow(hwndToolbar);
  255. DestroyWindow(hwndStatus);
  256. }