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. // ipframe.cpp : implementation of the CInPlaceFrame class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "wordpad.h"
  14. #include "formatba.h"
  15. #include "ruler.h"
  16. #include "ipframe.h"
  17. #include "wordpdoc.h"
  18. #include "wordpvw.h"
  19. #include "colorlis.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CInPlaceFrame
  26. IMPLEMENT_DYNCREATE(CInPlaceFrame, COleIPFrameWnd)
  27. BEGIN_MESSAGE_MAP(CInPlaceFrame, COleIPFrameWnd)
  28. //{{AFX_MSG_MAP(CInPlaceFrame)
  29. ON_WM_CREATE()
  30. ON_WM_DESTROY()
  31. ON_COMMAND(ID_HELP, OnHelpFinder)
  32. ON_COMMAND(ID_CHAR_COLOR, OnCharColor)
  33. ON_COMMAND(ID_HELP_INDEX, OnHelpFinder)
  34. ON_COMMAND(ID_PEN_TOGGLE, OnPenToggle)
  35. //}}AFX_MSG_MAP
  36. ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLBAR, OnUpdateControlBarMenu)
  37. ON_COMMAND_EX(ID_VIEW_TOOLBAR, OnBarCheck)
  38. ON_UPDATE_COMMAND_UI(ID_VIEW_FORMATBAR, OnUpdateControlBarMenu)
  39. ON_COMMAND_EX(ID_VIEW_FORMATBAR, OnBarCheck)
  40. ON_UPDATE_COMMAND_UI(ID_VIEW_RULER, OnUpdateControlBarMenu)
  41. ON_COMMAND_EX(ID_VIEW_RULER, OnBarCheck)
  42. ON_MESSAGE(WM_SIZECHILD, OnResizeChild)
  43. ON_MESSAGE(WPM_BARSTATE, OnBarState)
  44. ON_COMMAND(ID_DEFAULT_HELP, OnHelpFinder)
  45. // ON_COMMAND(ID_CONTEXT_HELP, COleIPFrameWnd::OnContextHelp)
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // arrays of IDs used to initialize control bars
  49. static UINT BASED_CODE toolButtons[] =
  50. {
  51. // same order as in the bitmap 'itoolbar.bmp'
  52. ID_EDIT_CUT,
  53. ID_EDIT_COPY,
  54. ID_EDIT_PASTE,
  55. ID_SEPARATOR,
  56. ID_PEN_TOGGLE,
  57. ID_PEN_PERIOD,
  58. ID_PEN_SPACE,
  59. ID_PEN_BACKSPACE,
  60. ID_PEN_NEWLINE,
  61. ID_PEN_LENS
  62. };
  63. #define NUM_PEN_ITEMS 7
  64. #define NUM_PEN_TOGGLE 5
  65. static UINT BASED_CODE format[] =
  66. {
  67. // same order as in the bitmap 'format.bmp'
  68. ID_SEPARATOR, // font name combo box
  69. ID_SEPARATOR,
  70. ID_SEPARATOR, // font size combo box
  71. ID_SEPARATOR,
  72. ID_SEPARATOR, // font script combo box
  73. ID_SEPARATOR,
  74. ID_CHAR_BOLD,
  75. ID_CHAR_ITALIC,
  76. ID_CHAR_UNDERLINE,
  77. ID_CHAR_COLOR,
  78. ID_SEPARATOR,
  79. ID_PARA_LEFT,
  80. ID_PARA_CENTER,
  81. ID_PARA_RIGHT,
  82. ID_SEPARATOR,
  83. ID_INSERT_BULLET,
  84. };
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CInPlaceFrame construction/destruction
  87. int CInPlaceFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  88. {
  89. if (COleIPFrameWnd::OnCreate(lpCreateStruct) == -1)
  90. return -1;
  91. // CResizeBar implements in-place resizing.
  92. if (!m_wndResizeBar.Create(this))
  93. {
  94. TRACE0("Failed to create resize bar\n");
  95. return -1; // fail to create
  96. }
  97. if (!CreateRulerBar(this))
  98. return FALSE;
  99. // By default, it is a good idea to register a drop-target that does
  100. // nothing with your frame window. This prevents drops from
  101. // "falling through" to a container that supports drag-drop.
  102. m_dropTarget.Register(this);
  103. return 0;
  104. }
  105. // OnCreateControlBars is called by the framework to create control bars on the
  106. // container application's windows. pWndFrame is the top level frame window of
  107. // the container and is always non-NULL. pWndDoc is the doc level frame window
  108. // and will be NULL when the container is an SDI application. A server
  109. // application can place MFC control bars on either window.
  110. BOOL CInPlaceFrame::OnCreateControlBars(CFrameWnd* pWndFrame, CFrameWnd* /*pWndDoc*/)
  111. {
  112. if (!CreateToolBar(pWndFrame))
  113. return FALSE;
  114. if (!CreateFormatBar(pWndFrame))
  115. return FALSE;
  116. // set owner to this window, so messages are delivered to correct app
  117. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  118. m_wndFormatBar.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM);
  119. pWndFrame->EnableDocking(CBRS_ALIGN_ANY);
  120. pWndFrame->DockControlBar(&m_wndToolBar);
  121. pWndFrame->DockControlBar(&m_wndFormatBar);
  122. m_wndToolBar.SetOwner(this);
  123. m_wndFormatBar.SetOwner(this);
  124. m_wndRulerBar.SetOwner(this);
  125. OnBarState(1, RD_EMBEDDED); //load bar state
  126. return TRUE;
  127. }
  128. BOOL CInPlaceFrame::CreateToolBar(CWnd* pWndFrame)
  129. {
  130. // Create toolbar on client's frame window
  131. ASSERT(m_wndToolBar.m_hWnd == NULL);
  132. int nPen = GetSystemMetrics(SM_PENWINDOWS) ? NUM_PEN_TOGGLE :
  133. NUM_PEN_ITEMS;
  134. UINT nID = theApp.m_bLargeIcons ?
  135. IDR_SRVR_INPLACE_BIG : IDR_SRVR_INPLACE;
  136. if (!m_wndToolBar.Create(pWndFrame, WS_CHILD|WS_VISIBLE|CBRS_TOP|
  137. CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)||
  138. !m_wndToolBar.LoadBitmap(nID) ||
  139. !m_wndToolBar.SetButtons(toolButtons,
  140. sizeof(toolButtons)/sizeof(UINT) - nPen))
  141. {
  142. TRACE0("Failed to create toolbar\n");
  143. return FALSE; // fail to create
  144. }
  145. if (theApp.m_bLargeIcons)
  146. m_wndToolBar.SetSizes(CSize(31,30), CSize(24,24));
  147. else
  148. m_wndToolBar.SetSizes(CSize(23,22), CSize(16,16));
  149. CString str;
  150. str.LoadString(IDS_TITLE_TOOLBAR);
  151. m_wndToolBar.SetWindowText(str);
  152. return TRUE;
  153. }
  154. BOOL CInPlaceFrame::CreateFormatBar(CWnd* pWndFrame)
  155. {
  156. ASSERT(m_wndFormatBar.m_hWnd == NULL);
  157. m_wndFormatBar.m_hWndOwner = m_hWnd;
  158. UINT nID = theApp.m_bLargeIcons ? IDB_FORMATBAR_BIG : IDB_FORMATBAR;
  159. if (!m_wndFormatBar.Create(pWndFrame, WS_CHILD|WS_VISIBLE|CBRS_TOP|
  160. CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_HIDE_INPLACE|CBRS_SIZE_DYNAMIC, ID_VIEW_FORMATBAR) ||
  161. !m_wndFormatBar.LoadBitmap(nID) ||
  162. !m_wndFormatBar.SetButtons(format,
  163. sizeof(format)/sizeof(UINT)))
  164. {
  165. TRACE0("Failed to create FormatBar\n");
  166. return FALSE; // fail to create
  167. }
  168. if (theApp.m_bLargeIcons)
  169. m_wndFormatBar.SetSizes(CSize(31,30), CSize(24,24));
  170. else
  171. m_wndFormatBar.SetSizes(CSize(23,22), CSize(16,16));
  172. CString str;
  173. str.LoadString(IDS_TITLE_FORMATBAR);
  174. m_wndFormatBar.SetWindowText(str);
  175. m_wndFormatBar.PositionCombos();
  176. return TRUE;
  177. }
  178. CInPlaceFrame::CreateRulerBar(CWnd* pWndFrame)
  179. {
  180. if (!m_wndRulerBar.Create(pWndFrame,
  181. WS_CHILD|WS_VISIBLE|CBRS_ALIGN_TOP|CBRS_HIDE_INPLACE, ID_VIEW_RULER))
  182. {
  183. TRACE0("Failed to create ruler\n");
  184. return FALSE; // fail to create
  185. }
  186. return TRUE;
  187. }
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CInPlaceFrame Operations
  190. /////////////////////////////////////////////////////////////////////////////
  191. // CInPlaceFrame diagnostics
  192. #ifdef _DEBUG
  193. void CInPlaceFrame::AssertValid() const
  194. {
  195. COleIPFrameWnd::AssertValid();
  196. }
  197. void CInPlaceFrame::Dump(CDumpContext& dc) const
  198. {
  199. COleIPFrameWnd::Dump(dc);
  200. }
  201. #endif //_DEBUG
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CInPlaceFrame commands
  204. void CInPlaceFrame::OnDestroy()
  205. {
  206. m_wndToolBar.DestroyWindow();
  207. m_wndFormatBar.DestroyWindow();
  208. COleIPFrameWnd::OnDestroy();
  209. }
  210. void CInPlaceFrame::RepositionFrame(LPCRECT lpPosRect, LPCRECT lpClipRect)
  211. {
  212. CRect rectNew = lpPosRect;
  213. rectNew.left -= HORZ_TEXTOFFSET;
  214. rectNew.top -= VERT_TEXTOFFSET;
  215. m_wndResizeBar.BringWindowToTop();
  216. COleIPFrameWnd::RepositionFrame(&rectNew, lpClipRect);
  217. CWnd* pWnd = GetActiveView();
  218. if (pWnd != NULL)
  219. pWnd->BringWindowToTop();
  220. m_wndRulerBar.BringWindowToTop();
  221. }
  222. void CInPlaceFrame::RecalcLayout(BOOL bNotify)
  223. {
  224. if (m_wndResizeBar.m_hWnd != NULL)
  225. m_wndResizeBar.BringWindowToTop();
  226. COleIPFrameWnd::RecalcLayout(bNotify);
  227. CWnd* pWnd = GetActiveView();
  228. if (pWnd != NULL)
  229. pWnd->BringWindowToTop();
  230. if (m_wndRulerBar.m_hWnd != NULL)
  231. m_wndRulerBar.BringWindowToTop();
  232. // at least 12 pt region plus ruler if it exists
  233. CDisplayIC dc;
  234. CSize size;
  235. size.cy = MulDiv(12, dc.GetDeviceCaps(LOGPIXELSY), 72)+1;
  236. size.cx = dc.GetDeviceCaps(LOGPIXELSX)/4; // 1/4"
  237. size.cx += HORZ_TEXTOFFSET; //adjust for offset
  238. size.cy += VERT_TEXTOFFSET;
  239. if (m_wndRulerBar.m_hWnd != NULL && m_wndRulerBar.IsVisible())
  240. {
  241. CRect rect;
  242. m_wndRulerBar.GetWindowRect(&rect);
  243. size.cy += rect.Height();
  244. }
  245. m_wndResizeBar.SetMinSize(size);
  246. }
  247. void CInPlaceFrame::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
  248. {
  249. COleIPFrameWnd::CalcWindowRect(lpClientRect, nAdjustType);
  250. }
  251. LRESULT CInPlaceFrame::OnResizeChild(WPARAM /*wParam*/, LPARAM lParam)
  252. {
  253. // notify the container that the rectangle has changed!
  254. CWordPadDoc* pDoc = (CWordPadDoc*)GetActiveDocument();
  255. if (pDoc == NULL)
  256. return 0;
  257. ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CWordPadDoc)));
  258. // get new rect and parent
  259. CRect rectNew;
  260. rectNew.CopyRect((LPCRECT)lParam);
  261. CWnd* pParentWnd = GetParent();
  262. ASSERT_VALID(pParentWnd);
  263. // convert rectNew relative to pParentWnd
  264. ClientToScreen(&rectNew);
  265. pParentWnd->ScreenToClient(&rectNew);
  266. if (m_wndRulerBar.GetStyle()&WS_VISIBLE)
  267. {
  268. CRect rect;
  269. m_wndRulerBar.GetWindowRect(&rect);
  270. rectNew.top += rect.Height();
  271. }
  272. rectNew.left += HORZ_TEXTOFFSET;
  273. rectNew.top += VERT_TEXTOFFSET;
  274. // adjust the new rectangle for the current control bars
  275. CWnd* pLeftOver = GetDlgItem(AFX_IDW_PANE_FIRST);
  276. ASSERT(pLeftOver != NULL);
  277. CRect rectCur = m_rectPos;
  278. pLeftOver->CalcWindowRect(&rectCur, CWnd::adjustOutside);
  279. rectNew.left += m_rectPos.left - rectCur.left;
  280. rectNew.top += m_rectPos.top - rectCur.top;
  281. rectNew.right -= rectCur.right - m_rectPos.right;
  282. rectNew.bottom -= rectCur.bottom - m_rectPos.bottom;
  283. OnRequestPositionChange(rectNew);
  284. return 0;
  285. }
  286. LONG CInPlaceFrame::OnBarState(UINT wParam, LONG lParam)
  287. {
  288. if (lParam == -1)
  289. return 0L;
  290. if (wParam == 0)
  291. {
  292. GetDockState(theApp.GetDockState(RD_EMBEDDED));
  293. ASSERT(m_pMainFrame != NULL);
  294. m_pMainFrame->GetDockState(theApp.GetDockState(RD_EMBEDDED, FALSE));
  295. }
  296. else
  297. {
  298. SetDockState(theApp.GetDockState(RD_EMBEDDED));
  299. m_pMainFrame->SetDockState(theApp.GetDockState(RD_EMBEDDED, FALSE));
  300. }
  301. return 0L;
  302. }
  303. void CInPlaceFrame::OnHelpFinder()
  304. {
  305. ::HtmlHelpA( ::GetDesktopWindow(), "wordpad.chm", HH_DISPLAY_TOPIC, 0L );
  306. }
  307. void CInPlaceFrame::OnCharColor()
  308. {
  309. CColorMenu colorMenu;
  310. CRect rc;
  311. int index = m_wndFormatBar.CommandToIndex(ID_CHAR_COLOR);
  312. m_wndFormatBar.GetItemRect(index, &rc);
  313. m_wndFormatBar.ClientToScreen(rc);
  314. colorMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,rc.left,rc.bottom, this);
  315. }
  316. void CInPlaceFrame::OnPenToggle()
  317. {
  318. static int nPen = 0;
  319. m_wndToolBar.SetButtons(toolButtons, sizeof(toolButtons)/sizeof(UINT) - nPen);
  320. nPen = (nPen == 0) ? NUM_PEN_TOGGLE : 0;
  321. m_wndToolBar.Invalidate();
  322. m_wndToolBar.GetParentFrame()->RecalcLayout();
  323. }