home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap24 / patron / patron.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  41KB  |  1,668 lines

  1. /*
  2.  * PATRON.CPP
  3.  * Patron Chapter 24
  4.  *
  5.  * WinMain which is all we need for the basic application.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #define INITGUIDS
  16. #include "patron.h"
  17.  
  18. ULONG       g_cObj=0;
  19. ULONG       g_cLock=0;
  20. HWND        g_hWnd=NULL;
  21. BOOL        g_fUser=TRUE;
  22.  
  23.  
  24. /*
  25.  * The in-place site needs to have access to the frame and its
  26.  * IOleInPlaceFrame interface.  A global, pardon me, is the simplest
  27.  * way to achieve this.
  28.  */
  29.  
  30. PCPatronFrame   g_pFR;
  31.  
  32.  
  33.  
  34. /*
  35.  * WinMain
  36.  *
  37.  * Purpose:
  38.  *  Main entry point of application.  Should register the app class
  39.  *  if a previous instance has not done so and do any other one-time
  40.  *  initializations.
  41.  */
  42.  
  43. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev
  44.     , LPSTR pszCmdLine, int nCmdShow)
  45.     {
  46.     PCPatronFrame   pFR;
  47.     FRAMEINIT       fi;
  48.     WPARAM          wRet=0;
  49.  
  50.     SETMESSAGEQUEUE;
  51.  
  52.     //Attempt to allocate and initialize the application
  53.     pFR=new CPatronFrame(hInst, hPrev, pszCmdLine, nCmdShow);
  54.  
  55.     if (NULL==pFR)
  56.         return -1;
  57.  
  58.     g_pFR=pFR;
  59.  
  60.     fi.idsMin=IDS_FRAMEMIN;
  61.     fi.idsMax=IDS_FRAMEMAX;
  62.     fi.idsStatMin=IDS_STATMESSAGEMIN;
  63.     fi.idsStatMax=IDS_STATMESSAGEMAX;
  64.     fi.idStatMenuMin=ID_MENUFILE;
  65.     fi.idStatMenuMax=ID_MENUHELP;
  66.     fi.iPosWindowMenu=WINDOW_MENU;
  67.     fi.cMenus=CMENUS;
  68.  
  69.     fi.x=CW_USEDEFAULT;
  70.     fi.y=CW_USEDEFAULT;
  71.     fi.cx=CW_USEDEFAULT;
  72.     fi.cy=CW_USEDEFAULT;
  73.  
  74.     //If we can initialize pFR, start chugging messages
  75.     if (pFR->Init(&fi))
  76.         wRet=pFR->MessageLoop();
  77.  
  78.     delete pFR;
  79.     return wRet;
  80.     }
  81.  
  82.  
  83.  
  84. /*
  85.  * ObjectDestroyed
  86.  *
  87.  * Purpose:
  88.  *  Function for the Patron Document object to call when it gets
  89.  *  destroyed.  We destroy the main window if the proper conditions
  90.  *  are met for shutdown.
  91.  */
  92.  
  93. void ObjectDestroyed(void)
  94.     {
  95.     g_cObj--;
  96.  
  97.     //No more objects, no locks, no user control, shut the app down.
  98.     if (0==g_cObj && 0==g_cLock && IsWindow(g_hWnd) && !g_fUser)
  99.         PostMessage(g_hWnd, WM_CLOSE, 0, 0L);
  100.  
  101.     return;
  102.     }
  103.  
  104.  
  105.  
  106.  
  107.  
  108. /*
  109.  * CPatronFrame::CPatronFrame
  110.  * CPatronFrame::~CPatronFrame
  111.  *
  112.  * Constructor Parameters:
  113.  *  hInst           HINSTANCE from WinMain
  114.  *  hInstPrev       HINSTANCE from WinMain
  115.  *  pszCmdLine      LPSTR from WinMain
  116.  *  nCmdShow        int from WInMain
  117.  */
  118.  
  119. CPatronFrame::CPatronFrame(HINSTANCE hInst, HINSTANCE hInstPrev
  120.     , LPSTR pszCmdLine, int nCmdShow)
  121.     : CFrame(hInst, hInstPrev, pszCmdLine, nCmdShow)
  122.     {
  123.     m_fInitialized=FALSE;
  124.     m_pIClassDataTran=NULL;
  125.  
  126.     m_pDocCreated=NULL;
  127.     m_fEmbedding=FALSE;
  128.  
  129.     m_dwRegCO=0;
  130.     m_pIClassFactory=NULL;
  131.  
  132.     m_cRef=0;
  133.     m_hAccelIP=NULL;
  134.     m_hWndObj=NULL;
  135.     m_hMenuOrg=NULL;
  136.     m_hMenuTop=NULL;
  137.     m_fOurToolsShowing=TRUE;
  138.     m_fInContextHelp=FALSE;
  139.     m_pIOleIPActiveObject=NULL;
  140.  
  141.     return;
  142.     }
  143.  
  144.  
  145. CPatronFrame::~CPatronFrame(void)
  146.     {
  147.     //Opposite of CoRegisterClassObject, takes class factory ref to 1
  148.     if (0L!=m_dwRegCO)
  149.         CoRevokeClassObject(m_dwRegCO);
  150.  
  151.     //This should be the last Release, which frees the class factory.
  152.     ReleaseInterface(m_pIClassFactory);
  153.  
  154.     if (NULL!=m_pIClassDataTran)
  155.         {
  156.         m_pIClassDataTran->LockServer(FALSE);
  157.         m_pIClassDataTran->Release();
  158.         }
  159.  
  160.     OleFlushClipboard();
  161.  
  162.     if (m_fInitialized)
  163.         OleUninitialize();
  164.  
  165.     return;
  166.     }
  167.  
  168.  
  169.  
  170.  
  171. /*
  172.  * CPatronFrame::Init
  173.  *
  174.  * Purpose:
  175.  *  Call OleInitialize then calling down into the base class
  176.  *  initialization.
  177.  *
  178.  * Parameters:
  179.  *  pFI             PFRAMEINIT containing initialization
  180.  *                  parameters.
  181.  *
  182.  * Return Value:
  183.  *  BOOL            TRUE if initialization succeeded,
  184.  *                  FALSE otherwise.
  185.  */
  186.  
  187. BOOL CPatronFrame::Init(PFRAMEINIT pFI)
  188.     {
  189.     HRESULT     hr;
  190.     BOOL        fRet;
  191.  
  192.     CHECKVER_OLE;
  193.  
  194.     if (FAILED(OleInitialize(NULL)))
  195.         return FALSE;
  196.  
  197.     m_fInitialized=TRUE;
  198.  
  199.     //Lock the data transfer object factory as an optimization.
  200.     hr=CoGetClassObject(CLSID_DataTransferObject
  201.         , CLSCTX_INPROC_SERVER, NULL, IID_IClassFactory
  202.         , (PPVOID)&m_pIClassDataTran);
  203.  
  204.     if (SUCCEEDED(hr))
  205.         m_pIClassDataTran->LockServer(TRUE);
  206.  
  207.     //Check for command line flags
  208.     ParseCommandLine();
  209.  
  210.     if (NULL!=m_ppszCmdArgs)
  211.         {
  212.         if(0==lstrcmpi(m_ppszCmdArgs[0], TEXT("-Embedding"))
  213.            || 0==lstrcmpi(m_ppszCmdArgs[0], TEXT("/Embedding")))
  214.             m_fEmbedding=TRUE;
  215.         }
  216.  
  217.     g_fUser=!m_fEmbedding;
  218.  
  219.     if (m_fEmbedding)
  220.         {
  221.         HRESULT     hr;
  222.  
  223.         m_pIClassFactory=new CLinkClassFactory(this);
  224.  
  225.         if (NULL==m_pIClassFactory)
  226.             return FALSE;
  227.  
  228.         //Since we hold on to this, we should AddRef it.
  229.         m_pIClassFactory->AddRef();
  230.  
  231.         hr=CoRegisterClassObject(CLSID_PatronPages, m_pIClassFactory
  232.             , CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &m_dwRegCO);
  233.  
  234.         if (FAILED(hr))
  235.             return FALSE;
  236.         }
  237.  
  238.     //Load in-place accelerators
  239.     m_hAccelIP=LoadAccelerators(m_hInst
  240.         , MAKEINTRESOURCE(IDR_INPLACEACCELERATORS));
  241.  
  242.     if (NULL==m_hAccelIP)
  243.         return FALSE;
  244.  
  245.     fRet=CFrame::Init(pFI);
  246.  
  247.     m_hMenuOrg=GetMenu(m_hWnd);
  248.     return fRet;
  249.     }
  250.  
  251.  
  252.  
  253.  
  254.  
  255. /*
  256.  * CPatronFrame::CreateCClient
  257.  *
  258.  * Purpose:
  259.  *  Constructs a new client specific to the application.
  260.  *
  261.  * Parameters:
  262.  *  None
  263.  *
  264.  * Return Value:
  265.  *  PCClient        Pointer to the new client object.
  266.  */
  267.  
  268. PCClient CPatronFrame::CreateCClient(void)
  269.     {
  270.     return (PCClient)(new CPatronClient(m_hInst, this));
  271.     }
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278. /*
  279.  * CPatronFrame::RegisterAllClasses
  280.  *
  281.  * Purpose:
  282.  *  Registers all classes used in this application.
  283.  *
  284.  * Parameters:
  285.  *  None
  286.  *
  287.  * Return Value:
  288.  *  BOOL            TRUE if registration succeeded, FALSE otherwise.
  289.  */
  290.  
  291. BOOL CPatronFrame::RegisterAllClasses(void)
  292.     {
  293.     WNDCLASS        wc;
  294.  
  295.     //First let the standard frame do its thing
  296.     if (!CFrame::RegisterAllClasses())
  297.         return FALSE;
  298.  
  299.     //We need double-clicks now and for object activation.
  300.     wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  301.     wc.hInstance     = m_hInst;
  302.     wc.cbClsExtra    = 0;
  303.     wc.lpfnWndProc   = PagesWndProc;
  304.     wc.cbWndExtra    = CBPAGESWNDEXTRA;
  305.     wc.hIcon         = NULL;
  306.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  307.     wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  308.     wc.lpszMenuName  = NULL;
  309.     wc.lpszClassName = SZCLASSPAGES;
  310.  
  311.     if (!RegisterClass(&wc))
  312.         return FALSE;
  313.  
  314.     return TRUE;
  315.     }
  316.  
  317.  
  318.  
  319.  
  320. /*
  321.  * CPatronFrame::PreShowInit
  322.  *
  323.  * Purpose:
  324.  *  Called from Init before intially showing the window.  We do
  325.  *  whatever else we want here, modifying m_nCmdShow as necessary
  326.  *  which affects ShowWindow in Init.
  327.  *
  328.  * Parameters:
  329.  *  None
  330.  *
  331.  * Return Value:
  332.  *  BOOL            TRUE if this successful, FALSE otherwise.
  333.  */
  334.  
  335. BOOL CPatronFrame::PreShowInit(void)
  336.     {
  337.     //Base class does nothing
  338.     CFrame::PreShowInit();
  339.  
  340.     //Save the window handle for shutdown if necessary.
  341.     g_hWnd=m_hWnd;
  342.  
  343.     //If we're -Embedding, don't show the window initially.
  344.     if (m_fEmbedding)
  345.         m_nCmdShow=SW_HIDE;
  346.  
  347.     return TRUE;
  348.     }
  349.  
  350.  
  351.  
  352.  
  353.  
  354. /*
  355.  * CPatronFrame::OnCommand
  356.  *
  357.  * Purpose:
  358.  *  WM_COMMAND handler for the Patron frame window that processes
  359.  *  extra File menu items as well as the Page menu.
  360.  *
  361.  * Parameters:
  362.  *  hWnd            HWND of the frame window.
  363.  *  wParam          WPARAM of the message.
  364.  *  lParam          LPARAM of the message.
  365.  *
  366.  * Return Value:
  367.  *  LRESULT         Return value for the message.
  368.  */
  369.  
  370. LRESULT CPatronFrame::OnCommand(HWND hWnd, WPARAM wParam
  371.     , LPARAM lParam)
  372.     {
  373.     PCPatronDoc     pDoc;
  374.     //CHAPTER24MOD
  375.     BOOL            fTemp;
  376.     //End CHAPTER24MOD
  377.  
  378.     COMMANDPARAMS(wID, wCode, hWndMsg);
  379.  
  380.     /*
  381.      * Don't bother with anything during first initialization,
  382.      * skipping many toolbar notifications.
  383.      */
  384.     if (m_fInit)
  385.         return 0L;
  386.  
  387.     pDoc=(PCPatronDoc)m_pCL->ActiveDocument();
  388.  
  389.     //Also check for the open command now too.
  390.     if (NULL!=pDoc && ((IDM_VERBMIN <= wID) && (IDM_VERBMAX >= wID)
  391.         || IDM_OPENOBJECT==wID))
  392.         {
  393.         MSG     msg;
  394.         DWORD   dw;
  395.         LONG    iVerb=(long)(wID-IDM_VERBMIN);
  396.  
  397.         //Include a message for in-place objects.
  398.         msg.hwnd=NULL;
  399.         msg.message=WM_COMMAND;
  400.         msg.wParam=wParam;
  401.         msg.lParam=lParam;
  402.         msg.time=GetMessageTime();
  403.  
  404.         dw=GetMessagePos();
  405.         SETPOINT(msg.pt, LOWORD(dw), HIWORD(dw));
  406.  
  407.         if (IDM_OPENOBJECT==wID)
  408.             iVerb=OLEIVERB_OPEN;
  409.  
  410.         pDoc->ActivateObject(iVerb, &msg);
  411.         return 0L;
  412.         }
  413.  
  414.  
  415.     switch (wID)
  416.         {
  417.         case IDM_FILEPRINT:
  418.             pDoc->Print(m_hWnd);
  419.             return 0L;
  420.  
  421.         case IDM_FILEPRINTERSETUP:
  422.             pDoc->PrinterSetup(m_hWnd, FALSE);
  423.             return 0L;
  424.  
  425.         case IDM_EDITPASTESPECIAL:
  426.             pDoc->PasteSpecial(m_hWnd);
  427.             return 0L;
  428.  
  429.         case IDM_EDITDELETEOBJECT:
  430.             pDoc->Delete();
  431.             return 0L;
  432.  
  433.         case IDM_EDITINSERTOBJECT:
  434.             pDoc->InsertObject(m_hWnd);
  435.             return 0L;
  436.  
  437.         case IDM_EDITCONVERT:
  438.             pDoc->ConvertObject(m_hWnd);
  439.             return 0L;
  440.  
  441.         case IDM_EDITLINKS:
  442.             pDoc->EditLinks(m_hWnd);
  443.             return 0L;
  444.  
  445.         //CHAPTER24MOD
  446.         case IDM_EDITOBJECTEVENTS:
  447.             pDoc->AssignEvents(m_hWnd);
  448.             break;
  449.         //End CHAPTER24MOD
  450.  
  451.         case IDM_PAGENEWPAGE:
  452.             pDoc->NewPage();
  453.             break;
  454.  
  455.         case IDM_PAGEDELETEPAGE:
  456.             pDoc->DeletePage();
  457.             break;
  458.  
  459.         case IDM_PAGENEXTPAGE:
  460.             pDoc->NextPage();
  461.             break;
  462.  
  463.         case IDM_PAGEPREVIOUSPAGE:
  464.             pDoc->PreviousPage();
  465.             break;
  466.  
  467.         case IDM_PAGEFIRSTPAGE:
  468.             pDoc->FirstPage();
  469.             break;
  470.  
  471.         case IDM_PAGELASTPAGE:
  472.             pDoc->LastPage();
  473.             break;
  474.  
  475.         case IDM_PAGESHOWOBJECTS:
  476.             {
  477.             BOOL    fTemp;
  478.  
  479.             //First get the current state, then toggle it.
  480.             fTemp=pDoc->ShowOrQueryObjectTypes(TRUE, FALSE);
  481.             pDoc->ShowOrQueryObjectTypes(FALSE, !fTemp);
  482.             }
  483.             break;
  484.  
  485.         //CHAPTER24MOD
  486.         case IDM_PAGEDESIGNMODE:
  487.             fTemp=pDoc->FToggleOrQueryDesignMode(TRUE, FALSE);
  488.             pDoc->FToggleOrQueryDesignMode(FALSE, !fTemp);
  489.             break;
  490.  
  491.         case IDM_PAGEUIDISABLED:
  492.             fTemp=pDoc->FToggleOrQueryUIDead(TRUE, FALSE);
  493.             pDoc->FToggleOrQueryUIDead(FALSE, !fTemp);
  494.             break;
  495.  
  496.          case IDM_PAGESHOWHATCHHANDLES:
  497.             fTemp=pDoc->FToggleOrQueryHatchHandles(TRUE, FALSE);
  498.             pDoc->FToggleOrQueryHatchHandles(FALSE, !fTemp);
  499.             break;
  500.         //End CHAPTER24MOD
  501.  
  502.         case IDM_ENTERCONTEXTHELP:
  503.         case IDM_ESCAPECONTEXTHELP:
  504.             //Notify the object on entry and exit.
  505.             ContextSensitiveHelp(IDM_ENTERCONTEXTHELP==wID);
  506.             break;
  507.  
  508.         default:
  509.            return CFrame::OnCommand(hWnd, wParam, lParam);
  510.         }
  511.  
  512.     return 0L;
  513.     }
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522. /*
  523.  * CPatronFrame::CreateToolbar
  524.  *
  525.  * Purpose:
  526.  *  Procedure to create all the necessary toolbar buttons.
  527.  *
  528.  * Parameters:
  529.  *  None
  530.  *
  531.  * Return Value:
  532.  *  UINT            Number of tools added to the bar.
  533.  */
  534.  
  535. UINT CPatronFrame::CreateToolbar(void)
  536.     {
  537.     UINT            iLast;
  538.     UINT            uState=GIZMO_NORMAL;
  539.     UINT            utCmd =GIZMOTYPE_BUTTONCOMMAND;
  540.  
  541.     //Insert the standard ones.
  542.     iLast=CFrame::CreateToolbar();
  543.  
  544.     //Remove Undo:  we don't use it.
  545.     m_pTB->Remove(IDM_EDITUNDO);
  546.  
  547.     /*
  548.      * Insert Print File Import in the 5th position and account
  549.      * for it in iLast.
  550.      */
  551.     m_pTB->Add(utCmd, 4, IDM_FILEPRINT, m_dxB, m_dyB
  552.         , NULL, NULL, 6, uState);
  553.  
  554.     iLast++;
  555.  
  556.     m_pTB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB
  557.         , NULL, NULL, 0, uState);
  558.  
  559.     //Add New Page, and Delete Page
  560.     m_pTB->Add(utCmd, iLast++, IDM_PAGENEWPAGE, m_dxB, m_dyB
  561.         , NULL, m_hBmp, 2, uState);
  562.     m_pTB->Add(utCmd, iLast++, IDM_PAGEDELETEPAGE, m_dxB, m_dyB
  563.         , NULL, m_hBmp, 3, uState);
  564.  
  565.     m_pTB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB
  566.         , NULL, NULL, 0, uState);
  567.  
  568.     //First, Prev, Next, Last pages.
  569.     m_pTB->Add(utCmd, iLast++, IDM_PAGEFIRSTPAGE, m_dxB, m_dyB
  570.         , NULL, m_hBmp, 4, uState);
  571.     m_pTB->Add(utCmd, iLast++, IDM_PAGEPREVIOUSPAGE, m_dxB, m_dyB
  572.         , NULL, m_hBmp, 5, uState);
  573.     m_pTB->Add(utCmd, iLast++, IDM_PAGENEXTPAGE, m_dxB, m_dyB
  574.         , NULL, m_hBmp, 6, uState);
  575.     m_pTB->Add(utCmd, iLast++, IDM_PAGELASTPAGE, m_dxB, m_dyB
  576.         , NULL, m_hBmp, 7, uState);
  577.  
  578.     return iLast;
  579.     }
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587. /*
  588.  * CPatronFrame::UpdateMenus
  589.  *
  590.  * Purpose:
  591.  *  Handles the WM_INITMENU message for the frame window.  Depending
  592.  *  on the existence of an active window, menu items are selectively
  593.  *  enabled and disabled.
  594.  *
  595.  * Parameters:
  596.  *  hMenu           HMENU of the menu to intialize
  597.  *  iMenu           UINT position of the menu.
  598.  *
  599.  * Return Value:
  600.  *  None
  601.  */
  602.  
  603. void CPatronFrame::UpdateMenus(HMENU hMenu, UINT iMenu)
  604.     {
  605.     PCPatronDoc     pDoc;
  606.     BOOL            fOK=FALSE;
  607.     BOOL            fCallDefault=TRUE;
  608.     UINT            uTemp;
  609.     UINT            uTempE;
  610.     UINT            uTempD;
  611.  
  612.     pDoc=(PCPatronDoc)m_pCL->ActiveDocument();
  613.  
  614.     uTempE=MF_ENABLED | MF_BYCOMMAND;
  615.     uTempD=MF_DISABLED | MF_GRAYED | MF_BYCOMMAND;
  616.     uTemp=((NULL!=pDoc) ? uTempE : uTempD);
  617.  
  618.     if (m_phMenu[0]==hMenu)
  619.         {
  620.         EnableMenuItem(hMenu, IDM_FILEPRINT, uTemp);
  621.  
  622.         if (NULL!=pDoc)
  623.             fOK=pDoc->FQueryPrinterSetup();
  624.  
  625.         EnableMenuItem(hMenu, IDM_FILEPRINTERSETUP
  626.             , (fOK) ? uTempE : uTempD);
  627.         }
  628.  
  629.     if (m_phMenu[1]==hMenu)
  630.         {
  631.         if (NULL!=pDoc)
  632.             fOK=pDoc->FQueryPaste();
  633.  
  634.         EnableMenuItem(hMenu, IDM_EDITPASTE
  635.             , (fOK) ? uTempE : uTempD);
  636.         EnableMenuItem(hMenu, IDM_EDITPASTESPECIAL
  637.             , (fOK) ? uTempE : uTempD);
  638.  
  639.         //Cut, Copy, Delete depends on there being a selection.
  640.         if (NULL!=pDoc)
  641.             fOK=pDoc->FQueryObjectSelected(hMenu);
  642.         else
  643.             fOK=FALSE;
  644.  
  645.         EnableMenuItem(hMenu, IDM_EDITCUT, (fOK) ? uTempE : uTempD);
  646.         EnableMenuItem(hMenu, IDM_EDITCOPY
  647.             , (fOK) ? uTempE : uTempD);
  648.         EnableMenuItem(hMenu, IDM_EDITDELETEOBJECT
  649.             , (fOK) ? uTempE : uTempD);
  650.  
  651.         EnableMenuItem(hMenu, IDM_EDITINSERTOBJECT, uTemp);
  652.  
  653.         if (NULL!=pDoc)
  654.             fOK=pDoc->FQueryEnableEditLinks();
  655.         else
  656.             fOK=FALSE;
  657.  
  658.         EnableMenuItem(hMenu, IDM_EDITLINKS
  659.             , (fOK) ? uTempE : uTempD);
  660.  
  661.         //CHAPTER24MOD
  662.         //Enable Events... if we have a control
  663.         fOK=FALSE;
  664.  
  665.         if (NULL!=pDoc)
  666.             fOK=pDoc->FQueryEnableEvents();
  667.  
  668.         EnableMenuItem(hMenu, IDM_EDITOBJECTEVENTS
  669.             , (fOK) ? uTempE : uTempD);
  670.         //End CHAPTER24MOD
  671.  
  672.         //We did the whole menu...
  673.         fCallDefault=FALSE;
  674.         }
  675.  
  676.     //Page menu
  677.     if (m_phMenu[2]==hMenu)
  678.         {
  679.         EnableMenuItem(hMenu, IDM_PAGENEWPAGE,      uTemp);
  680.         EnableMenuItem(hMenu, IDM_PAGEDELETEPAGE,   uTemp);
  681.         EnableMenuItem(hMenu, IDM_PAGENEXTPAGE,     uTemp);
  682.         EnableMenuItem(hMenu, IDM_PAGEPREVIOUSPAGE, uTemp);
  683.         EnableMenuItem(hMenu, IDM_PAGEFIRSTPAGE,    uTemp);
  684.         EnableMenuItem(hMenu, IDM_PAGELASTPAGE,     uTemp);
  685.  
  686.         //Check the Show Objects command or not.
  687.         if (NULL!=pDoc)
  688.             fOK=pDoc->ShowOrQueryObjectTypes(TRUE, FALSE);
  689.         else
  690.             fOK=FALSE;
  691.  
  692.         CheckMenuItem(hMenu, IDM_PAGESHOWOBJECTS, MF_BYCOMMAND
  693.             | ((fOK) ? MF_CHECKED : MF_UNCHECKED));
  694.         EnableMenuItem(hMenu, IDM_PAGESHOWOBJECTS, uTemp);
  695.  
  696.         //CHAPTER24MOD
  697.         //Check the Design Mode command or not.
  698.         if (NULL!=pDoc)
  699.             fOK=pDoc->FToggleOrQueryDesignMode(TRUE, FALSE);
  700.         else
  701.             fOK=FALSE;
  702.  
  703.         CheckMenuItem(hMenu, IDM_PAGEDESIGNMODE, MF_BYCOMMAND
  704.             | ((fOK) ? MF_CHECKED : MF_UNCHECKED));
  705.         EnableMenuItem(hMenu, IDM_PAGEDESIGNMODE, uTemp);
  706.  
  707.         //Check the UI Disabled command or not.
  708.         if (NULL!=pDoc)
  709.             fOK=pDoc->FToggleOrQueryUIDead(TRUE, FALSE);
  710.         else
  711.             fOK=FALSE;
  712.  
  713.         CheckMenuItem(hMenu, IDM_PAGEUIDISABLED, MF_BYCOMMAND
  714.             | ((fOK) ? MF_CHECKED : MF_UNCHECKED));
  715.         EnableMenuItem(hMenu, IDM_PAGEUIDISABLED, uTemp);
  716.  
  717.         //Check the Show Hatch and Handles command or not.
  718.         if (NULL!=pDoc)
  719.             fOK=pDoc->FToggleOrQueryHatchHandles(TRUE, FALSE);
  720.         else
  721.             fOK=FALSE;
  722.  
  723.         CheckMenuItem(hMenu, IDM_PAGESHOWHATCHHANDLES, MF_BYCOMMAND
  724.             | ((fOK) ? MF_CHECKED : MF_UNCHECKED));
  725.         EnableMenuItem(hMenu, IDM_PAGESHOWHATCHHANDLES, uTemp);
  726.         //End CHAPTER24MOD
  727.         }
  728.  
  729.     if (fCallDefault)
  730.         CFrame::UpdateMenus(hMenu, iMenu);
  731.  
  732.     return;
  733.     }
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740. /*
  741.  * CPatronFrame::UpdateToolbar
  742.  *
  743.  * Purpose:
  744.  *  Enables and disables tools depending on whether we have
  745.  *  a document or not.
  746.  *
  747.  * Parameters:
  748.  *  None
  749.  *
  750.  * Return Value:
  751.  *  None
  752.  */
  753.  
  754. void CPatronFrame::UpdateToolbar(void)
  755.     {
  756.     PCDocument  pDoc;
  757.     BOOL        fEnable;
  758.  
  759.     //Let the default hack on its tools.
  760.     CFrame::UpdateToolbar();
  761.  
  762.     pDoc=m_pCL->ActiveDocument();
  763.     fEnable=(NULL!=pDoc);
  764.  
  765.     //No document, disable just about everything
  766.     m_pTB->Enable(IDM_FILEPRINT,        fEnable);
  767.     m_pTB->Enable(IDM_FILEPRINTERSETUP, fEnable);
  768.  
  769.     m_pTB->Enable(IDM_PAGENEWPAGE,      fEnable);
  770.     m_pTB->Enable(IDM_PAGEDELETEPAGE,   fEnable);
  771.     m_pTB->Enable(IDM_PAGEFIRSTPAGE,    fEnable);
  772.     m_pTB->Enable(IDM_PAGEPREVIOUSPAGE, fEnable);
  773.     m_pTB->Enable(IDM_PAGENEXTPAGE,     fEnable);
  774.     m_pTB->Enable(IDM_PAGELASTPAGE,     fEnable);
  775.  
  776.     return;
  777.     }
  778.  
  779.  
  780.  
  781.  
  782.  
  783. /*
  784.  * CPatronFrame::MessageLoop
  785.  *
  786.  * Purpose:
  787.  *  Override of standard message loop function in CLASSLIB to use
  788.  *  in-place accelerators when necessary.
  789.  *
  790.  * Parameters:
  791.  *  None
  792.  *
  793.  * Return Value:
  794.  *  WPARAM          Contents of msg.wParam from WM_QUIT.
  795.  */
  796.  
  797. WPARAM CPatronFrame::MessageLoop(void)
  798.     {
  799.     MSG     msg;
  800.  
  801.     while (GetMessage(&msg, NULL, 0,0 ))
  802.         {
  803.         HACCEL      hAccel=m_hAccel;
  804.  
  805.         //Always give the object first crack at translation.
  806.         if (NULL!=m_pIOleIPActiveObject)
  807.             {
  808.             HRESULT     hr;
  809.  
  810.             hAccel=m_hAccelIP;
  811.             hr=m_pIOleIPActiveObject->TranslateAccelerator(&msg);
  812.  
  813.             //If the object translated the accelerator, we're done
  814.             if (NOERROR==hr)
  815.                 continue;
  816.             }
  817.  
  818.         if (!m_pCL->TranslateAccelerator(&msg))
  819.             {
  820.             //hAccel is either the normal ones or the in-place ones.
  821.  
  822.             if (!::TranslateAccelerator(m_hWnd, hAccel, &msg))
  823.                 {
  824.                 TranslateMessage(&msg);
  825.                 DispatchMessage(&msg);
  826.                 }
  827.             }
  828.         }
  829.  
  830.     return msg.wParam;
  831.     }
  832.  
  833.  
  834.  
  835.  
  836. /*
  837.  * CPatronFrame::FMessageHook
  838.  *
  839.  * Purpose:
  840.  *  Override of CFrame::FMessageHook so we can specifically trap
  841.  *  WM_MENUSELECT messages for the Object verb menu to provide some
  842.  *  meaningful information on the status strip.
  843.  *
  844.  * Parameters:
  845.  *  <WndProc Parameters>
  846.  *  pLRes           LRESULT * in which to store the return value
  847.  *                  for the message.
  848.  *
  849.  * Return Value:
  850.  *  BOOL            TRUE to prevent further processing,
  851.  *                  FALSE otherwise.
  852.  */
  853.  
  854. BOOL CPatronFrame::FMessageHook(HWND hWnd, UINT iMsg, WPARAM wParam
  855.     , LPARAM lParam, LRESULT *pLRes)
  856.     {
  857.     BOOL        fRet=FALSE;
  858.     int         dx, dy;
  859.     //CHAPTER24MOD
  860.     PCPatronDoc pDoc;
  861.     MSG         msg;
  862.     DWORD       dw;
  863.     //End CHAPTER24MOD
  864.  
  865.     MENUSELECTPARAMS(wItem, wMenuFlags, hMenu);
  866.  
  867.     *pLRes=0;
  868.  
  869.     /*
  870.      * We use a switch now because we previously only processed
  871.      * WM_MENUSELECT which did not use a case statement.
  872.      */
  873.  
  874.     switch (iMsg)
  875.         {
  876.         case WM_SIZE:
  877.             if (NULL!=m_pIOleIPActiveObject)
  878.                 {
  879.                 RECT        rc;
  880.  
  881.                 GetClientRect(m_hWnd, &rc);
  882.                 m_pIOleIPActiveObject->ResizeBorder(&rc
  883.                     , this, TRUE);
  884.                 }
  885.  
  886.             /*
  887.              * If we're not showing our tools, don't let CLASSLIB
  888.              * resize the client, instead doing it ourselves.
  889.              */
  890.             if (m_fOurToolsShowing)
  891.                 return FALSE;
  892.  
  893.             m_fSizing=TRUE;
  894.             dx=LOWORD(lParam);
  895.             dy=HIWORD(lParam);
  896.  
  897.             //Change the Toolbar and StatStrip widths to match
  898.             m_pTB->OnSize(hWnd);
  899.             m_pSL->OnSize(hWnd);
  900.  
  901.             //Adjust the client properly, remembering the StatStrip.
  902.             m_pCL->OnSize(m_cxLeft, m_cyTop, dx-m_cxLeft-m_cxRight
  903.                 , dy-m_cyTop-m_cyBottom-CYSTATSTRIP);
  904.  
  905.             m_fSizing=FALSE;
  906.             return TRUE;
  907.  
  908.         case WM_ACTIVATEAPP:
  909.             if (NULL!=m_pIOleIPActiveObject)
  910.                 {
  911.                 m_pIOleIPActiveObject->OnFrameWindowActivate
  912.                     ((BOOL)wParam);
  913.                 }
  914.  
  915.             return FALSE;
  916.  
  917.         case WM_SETFOCUS:
  918.             if (NULL!=m_pIOleIPActiveObject)
  919.                 {
  920.                 HWND    hWndObj;
  921.  
  922.                 m_pIOleIPActiveObject->GetWindow(&hWndObj);
  923.                 SetFocus(hWndObj);
  924.                 }
  925.  
  926.             return TRUE;
  927.  
  928.         case WM_CLOSE:
  929.             if (NULL!=m_pDocCreated)
  930.                 {
  931.                 if (m_pDocCreated->FDirtyGet())
  932.                     {
  933.                     CHourglass  wait;
  934.                     m_pDocCreated->Save(0, NULL);
  935.                     }
  936.                 }
  937.  
  938.             return FALSE;
  939.  
  940.         case WM_MENUSELECT:
  941.             break;      //Continue processing below.
  942.  
  943.         //CHAPTER24MOD
  944.         /*
  945.          * Keyboard mnemonics can be Control- or Alt-keys with
  946.          * any other modifier.  That means WM_KEYDOWN with
  947.          * Control on or WM_SYSKEYDOWN by itself.
  948.          */
  949.         case WM_KEYDOWN:
  950.             //Filter out things without Control
  951.             if (!(0x8000 & GetKeyState(VK_CONTROL)))
  952.                 return FALSE;
  953.  
  954.             //FALL-THROUGH
  955.  
  956.         case WM_SYSKEYDOWN:
  957.             pDoc=(PCPatronDoc)m_pCL->ActiveDocument();
  958.  
  959.             if (NULL==pDoc)
  960.                 return FALSE;
  961.  
  962.             msg.hwnd=hWnd;
  963.             msg.message=iMsg;
  964.             msg.wParam=wParam;
  965.             msg.lParam=lParam;
  966.             msg.time=GetMessageTime();
  967.             dw=GetMessagePos();
  968.             msg.pt.x=LOWORD(dw);
  969.             msg.pt.y=HIWORD(dw);
  970.             return pDoc->TryMnemonic(&msg);
  971.         //End CHAPTER24MOD
  972.  
  973.         default:
  974.             return FALSE;
  975.         }
  976.  
  977.     //This happens when there's no menu selection.
  978.     if (-1==wMenuFlags)
  979.         return FALSE;
  980.  
  981.     if (MF_POPUP & wMenuFlags)
  982.         {
  983.         /*
  984.          * If this is the cascade verb menu itself, display the same
  985.          * message.  m_phMenu[1] contains the current edit menu
  986.          * handle.
  987.          */
  988.         if (0!=wItem)
  989.             {
  990.             fRet=((HMENU)wItem==GetSubMenu(m_phMenu[1]
  991.                 , MENUPOS_OBJECT));
  992.             }
  993.         }
  994.     else
  995.         {
  996.         /*
  997.          * If the ID is in the verb range, use
  998.          * IDS_ITEMMESSAGEEDITOBJECT message
  999.          */
  1000.         fRet=(IDM_VERBMIN <= wItem && IDM_VERBMAX >= wItem);
  1001.         }
  1002.  
  1003.     if (fRet)
  1004.         m_pSL->MessageDisplay(IDM_EDITOBJECT);
  1005.  
  1006.     return fRet;
  1007.     }
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013. /*
  1014.  * CPatronFrame::ShowUIAndTools
  1015.  *
  1016.  * Purpose:
  1017.  *  Installs or removes the in-place user interface which includes
  1018.  *  the menus and the tools.  The tools may be affected outside of
  1019.  *  the menu.
  1020.  *
  1021.  * Parameters:
  1022.  *  fShow           BOOL indicating to show (TRUE) or hide (FALSE)
  1023.  *  fMenu           BOOl indicating if the menu is also affected.
  1024.  *
  1025.  * Return Value:
  1026.  *  None
  1027.  */
  1028.  
  1029. void CPatronFrame::ShowUIAndTools(BOOL fShow, BOOL fMenu)
  1030.     {
  1031.     HWND    hWndTB;
  1032.  
  1033.     //This is the only menu case...restore our original menu
  1034.     if (fMenu && fShow)
  1035.         SetMenu(NULL, NULL, NULL);
  1036.  
  1037.     /*
  1038.      * If we're trying to hide our tools but the object didn't
  1039.      * want any space, then just leave our tools up and active.
  1040.      */
  1041.  
  1042.     hWndTB=m_pTB->Window();
  1043.     ShowWindow(hWndTB, fShow ? SW_SHOW : SW_HIDE);
  1044.  
  1045.     if (fShow)
  1046.         {
  1047.         InvalidateRect(hWndTB, NULL, TRUE);
  1048.         UpdateWindow(hWndTB);
  1049.         }
  1050.  
  1051.     m_fOurToolsShowing=fShow;
  1052.     return;
  1053.     }
  1054.  
  1055.  
  1056.  
  1057.  
  1058. /*
  1059.  * CPatronFrame::ReinstateUI
  1060.  *
  1061.  * Purpose:
  1062.  *  Reinstalls the application's normal toolbar and menu and
  1063.  *  readjusts the position of the client window and the documents
  1064.  *  within it.
  1065.  *
  1066.  * Parameters:
  1067.  *  None
  1068.  *
  1069.  * Return Value:
  1070.  *  None
  1071.  */
  1072.  
  1073. void CPatronFrame::ReinstateUI(void)
  1074.     {
  1075.     BORDERWIDTHS    bw;
  1076.  
  1077.     ShowUIAndTools(TRUE, TRUE);
  1078.  
  1079.     SetRect((LPRECT)&bw, 0, m_cyBar, 0, 0);
  1080.     SetBorderSpace(&bw);
  1081.     return;
  1082.     }
  1083.  
  1084.  
  1085.  
  1086. /*
  1087.  * CPatronFrame::QueryInterface
  1088.  * CPatronFrame::AddRef
  1089.  * CPatronFrame::Release
  1090.  */
  1091.  
  1092. STDMETHODIMP CPatronFrame::QueryInterface(REFIID riid, PPVOID ppv)
  1093.     {
  1094.     //We only know IUnknown and IOleInPlaceFrame
  1095.     *ppv=NULL;
  1096.  
  1097.     if (IID_IUnknown==riid || IID_IOleInPlaceUIWindow==riid
  1098.         || IID_IOleWindow==riid || IID_IOleInPlaceFrame==riid)
  1099.         *ppv=(LPOLEINPLACEFRAME)this;
  1100.  
  1101.     if (NULL!=*ppv)
  1102.         {
  1103.         ((LPUNKNOWN)*ppv)->AddRef();
  1104.         return NOERROR;
  1105.         }
  1106.  
  1107.     return ResultFromScode(E_NOINTERFACE);
  1108.     }
  1109.  
  1110.  
  1111. STDMETHODIMP_(ULONG) CPatronFrame::AddRef(void)
  1112.     {
  1113.     return ++m_cRef;
  1114.     }
  1115.  
  1116. STDMETHODIMP_(ULONG) CPatronFrame::Release(void)
  1117.     {
  1118.     /*
  1119.      * We don't do anything with this since we're not controlled
  1120.      * by a reference count as far as in-place stuff is concerned.
  1121.      */
  1122.     return --m_cRef;
  1123.     }
  1124.  
  1125.  
  1126.  
  1127.  
  1128. /*
  1129.  * CPatronFrame::GetWindow
  1130.  *
  1131.  * Purpose:
  1132.  *  Retrieves the handle of the window associated with the object
  1133.  *  on which this interface is implemented.
  1134.  *
  1135.  * Parameters:
  1136.  *  phWnd           HWND * in which to store the window handle.
  1137.  *
  1138.  * Return Value:
  1139.  *  HRESULT         NOERROR if successful, E_FAIL if there is no
  1140.  *                  window.
  1141.  */
  1142.  
  1143. STDMETHODIMP CPatronFrame::GetWindow(HWND *phWnd)
  1144.     {
  1145.     *phWnd=m_hWnd;
  1146.     return NOERROR;
  1147.     }
  1148.  
  1149.  
  1150.  
  1151.  
  1152. /*
  1153.  * CPatronFrame::ContextSensitiveHelp
  1154.  *
  1155.  * Purpose:
  1156.  *  Instructs the object on which this interface is implemented to
  1157.  *  enter or leave a context-sensitive help mode.
  1158.  *
  1159.  * Parameters:
  1160.  *  fEnterMode      BOOL TRUE to enter the mode, FALSE otherwise.
  1161.  *
  1162.  * Return Value:
  1163.  *  HRESULT         NOERROR
  1164.  */
  1165.  
  1166. STDMETHODIMP CPatronFrame::ContextSensitiveHelp(BOOL fEnterMode)
  1167.     {
  1168.     /*
  1169.      * Don't bother if there is no active object since we don't do
  1170.      * context help on our own.
  1171.      */
  1172.     if (NULL==m_pIOleIPActiveObject)
  1173.         return NOERROR;
  1174.  
  1175.     /*
  1176.      * If the state changes, an MDI frame should call the same
  1177.      * function in all documents.  An SDI frame should just call
  1178.      * the active object, if it has one.
  1179.      */
  1180.  
  1181.     if (m_fInContextHelp!=fEnterMode)
  1182.         {
  1183.         m_fInContextHelp=fEnterMode;
  1184.  
  1185.        #ifdef MDI
  1186.         ((PCPatronClient)m_pCL)->CallContextHelpOnDocuments
  1187.            (fEnterMode);
  1188.        #else
  1189.         m_pIOleIPActiveObject->ContextSensitiveHelp(fEnterMode);
  1190.        #endif
  1191.         }
  1192.  
  1193.     return NOERROR;
  1194.     }
  1195.  
  1196.  
  1197.  
  1198.  
  1199. /*
  1200.  * CPatronFrame::GetBorder
  1201.  *
  1202.  * Purpose:
  1203.  *  Returns the rectangle in which the container is willing to
  1204.  *  negotiate about an object's adornments.
  1205.  *
  1206.  * Parameters:
  1207.  *  prcBorder       LPRECT in which to store the rectangle.
  1208.  *
  1209.  * Return Value:
  1210.  *  HRESULT         NOERROR if all is well, INPLACE_E_NOTOOLSPACE
  1211.  *                  if there is no negotiable space.
  1212.  */
  1213.  
  1214. STDMETHODIMP CPatronFrame::GetBorder(LPRECT prcBorder)
  1215.     {
  1216.     if (NULL==prcBorder)
  1217.         return ResultFromScode(E_INVALIDARG);
  1218.  
  1219.     /*
  1220.      * We return all the client area space sans the StatStrip,
  1221.      * which we control
  1222.      */
  1223.     GetClientRect(m_hWnd, prcBorder);
  1224.     prcBorder->bottom-=CYSTATSTRIP;
  1225.  
  1226.     return NOERROR;
  1227.     }
  1228.  
  1229.  
  1230.  
  1231.  
  1232. /*
  1233.  * CPatronFrame::RequestBorderSpace
  1234.  *
  1235.  * Purpose:
  1236.  *  Asks the container if it can surrender the amount of space
  1237.  *  in pBW that the object would like for it's adornments.  The
  1238.  *  container does nothing but validate the spaces on this call.
  1239.  *
  1240.  * Parameters:
  1241.  *  pBW             LPCBORDERWIDTHS containing the requested space.
  1242.  *                  The values are the amount of space requested
  1243.  *                  from each side of the relevant window.
  1244.  *
  1245.  * Return Value:
  1246.  *  HRESULT         NOERROR if we can give up space,
  1247.  *                  INPLACE_E_NOTOOLSPACE otherwise.
  1248.  */
  1249.  
  1250. STDMETHODIMP CPatronFrame::RequestBorderSpace(LPCBORDERWIDTHS pBW)
  1251.     {
  1252.     //Everything is fine with us, so always return an OK.
  1253.     return NOERROR;
  1254.     }
  1255.  
  1256.  
  1257.  
  1258.  
  1259. /*
  1260.  * CPatronFrame::SetBorderSpace
  1261.  *
  1262.  * Purpose:
  1263.  *  Called when the object now officially requests that the
  1264.  *  container surrender border space it previously allowed
  1265.  *  in RequestBorderSpace.  The container should resize windows
  1266.  *  appropriately to surrender this space.
  1267.  *
  1268.  * Parameters:
  1269.  *  pBW             LPCBORDERWIDTHS containing the amount of space
  1270.  *                  from each side of the relevant window that the
  1271.  *                  object is now reserving.
  1272.  *
  1273.  * Return Value:
  1274.  *  HRESULT         NOERROR
  1275.  */
  1276.  
  1277. STDMETHODIMP CPatronFrame::SetBorderSpace(LPCBORDERWIDTHS pBW)
  1278.     {
  1279.     RECT            rc;
  1280.     POINT           pt1, pt2;
  1281.     PCPatronDoc     pDoc;
  1282.  
  1283.     pDoc=(PCPatronDoc)m_pCL->ActiveDocument();
  1284.  
  1285.     /*
  1286.      * If pBW is NULL, the object is not interested in tools, so we
  1287.      * can just leave ours up if we want.
  1288.      */
  1289.  
  1290.     if (NULL==pBW)
  1291.         {
  1292.         if (NULL!=pDoc)
  1293.             {
  1294.             pDoc->NoObjectFrameTools(TRUE, TRUE);
  1295.  
  1296.             /*
  1297.              * In some cases IOleInPlaceSite::OnUIActivate might
  1298.              * have been called before SetBorderSpace, so we might
  1299.              * have already hidden our tools (OnUIActivate calls
  1300.              * pDoc->NoObjectFrameTools before we set it to TRUE
  1301.              * here).  So we have to insure they are visible now
  1302.              * by a call to ShowUIAndTools.
  1303.              */
  1304.             if (!m_fOurToolsShowing)
  1305.                 ShowUIAndTools(TRUE, FALSE);
  1306.             }
  1307.  
  1308.         return NOERROR;
  1309.         }
  1310.  
  1311.     if (NULL!=pDoc)
  1312.         pDoc->NoObjectFrameTools(FALSE, TRUE);
  1313.  
  1314.     /*
  1315.      * This tells CFrame::FMessageHook (WM_SIZE) how much space
  1316.      * to reserve off the sides when resizing the client when
  1317.      * the frame is resized.
  1318.      */
  1319.  
  1320.     m_cyTop   =pBW->top;
  1321.     m_cyBottom=pBW->bottom;
  1322.     m_cxLeft  =pBW->left;
  1323.     m_cxRight =pBW->right;
  1324.  
  1325.  
  1326.     //Get the current offset of the client
  1327.     GetWindowRect(m_pCL->Window(), &rc);
  1328.     SETPOINT(pt1, rc.left, rc.top);
  1329.     SETPOINT(pt2, rc.right, rc.bottom);
  1330.     ScreenToClient(m_hWnd, &pt1);
  1331.     ScreenToClient(m_hWnd, &pt2);
  1332.  
  1333.     /*
  1334.      * Now move the client, keeping documents steady. pBW->left-pt.x
  1335.      * and pBW->top-pt.y are the deltas for the documents.
  1336.      */
  1337.  
  1338.     GetClientRect(m_hWnd, &rc);
  1339.     rc.left+=pBW->left;
  1340.     rc.right-=pBW->right;
  1341.     rc.top+=pBW->top;
  1342.     rc.bottom-=pBW->bottom+CYSTATSTRIP; //Remember the status line
  1343.  
  1344.     //Only bother the client if necessary.
  1345.     if (!(pt1.x==rc.left && pt1.y==rc.top
  1346.         && pt2.x==rc.right && pt2.y==rc.bottom))
  1347.         {
  1348.         ((PCPatronClient)m_pCL)->MoveWithoutFamily(&rc
  1349.             , pBW->left-pt1.x, pBW->top-pt1.y);
  1350.         }
  1351.  
  1352.     return NOERROR;
  1353.     }
  1354.  
  1355.  
  1356.  
  1357.  
  1358. /*
  1359.  * CPatronFrame::SetActiveObject
  1360.  *
  1361.  * Purpose:
  1362.  *  Provides the container with the object's IOleInPlaceActiveObject
  1363.  *  pointer
  1364.  *
  1365.  * Parameters:
  1366.  *  pIIPActiveObj   LPOLEINPLACEACTIVEOBJECT of interest.
  1367.  *  pszObj          LPCOLESTR naming the object.  Not used.
  1368.  *
  1369.  * Return Value:
  1370.  *  HRESULT         NOERROR
  1371.  */
  1372.  
  1373. STDMETHODIMP CPatronFrame::SetActiveObject
  1374.     (LPOLEINPLACEACTIVEOBJECT pIIPActiveObj, LPCOLESTR pszObj)
  1375.     {
  1376.     if (NULL!=m_pIOleIPActiveObject)
  1377.         m_pIOleIPActiveObject->Release();
  1378.  
  1379.     //NULLs m_pIOleIPActiveObject if pIIPActiveObj is NULL
  1380.     m_pIOleIPActiveObject=pIIPActiveObj;
  1381.  
  1382.     if (NULL!=m_pIOleIPActiveObject)
  1383.         m_pIOleIPActiveObject->AddRef();
  1384.  
  1385.     return NOERROR;
  1386.     }
  1387.  
  1388.  
  1389.  
  1390.  
  1391. /*
  1392.  * CPatronFrame::InsertMenus
  1393.  *
  1394.  * Purpose:
  1395.  *  Instructs the container to place its in-place menu items where
  1396.  *  necessary in the given menu and to fill in elements 0, 2, and 4
  1397.  *  of the OLEMENUGROUPWIDTHS array to indicate how many top-level
  1398.  *  items are in each group.
  1399.  *
  1400.  * Parameters:
  1401.  *  hMenu           HMENU in which to add popups.
  1402.  *  pMGW            LPOLEMENUGROUPWIDTHS in which to store the
  1403.  *                  width of each container menu group.
  1404.  *
  1405.  * Return Value:
  1406.  *  HRESULT         NOERROR
  1407.  */
  1408.  
  1409. STDMETHODIMP CPatronFrame::InsertMenus(HMENU hMenu
  1410.     , LPOLEMENUGROUPWIDTHS pMGW)
  1411.     {
  1412.     /*
  1413.      * Here Patron needs to copy it's File, Page, and Window menu
  1414.      * items into the object-supplied menu, meaning that we have
  1415.      * three menu groups.  The actual handles of these popup menus
  1416.      * are already in CPatronFrame::m_phMenu where File is element
  1417.      * 0 and Page is element 2, and in m_hMenuWindow which is the
  1418.      * Window menu.  The latter we do only for MDI, of course.
  1419.      */
  1420.  
  1421.     InsertMenu(hMenu, 0, MF_BYPOSITION | MF_POPUP, (UINT)m_phMenu[0]
  1422.         , PSZ(IDS_FILEMENU));
  1423.     InsertMenu(hMenu, 1, MF_BYPOSITION | MF_POPUP, (UINT)m_phMenu[2]
  1424.         , PSZ(IDS_PAGEMENU));
  1425.  
  1426.     pMGW->width[0]=1;
  1427.     pMGW->width[2]=1;
  1428.  
  1429.    #ifdef MDI
  1430.     InsertMenu(hMenu, 2, MF_BYPOSITION | MF_POPUP
  1431.        , (UINT)m_hMenuWindow, PSZ(IDS_WINDOWMENU));
  1432.  
  1433.     pMGW->width[4]=1;
  1434.    #else
  1435.     pMGW->width[4]=0;
  1436.    #endif
  1437.  
  1438.     return NOERROR;
  1439.     }
  1440.  
  1441.  
  1442.  
  1443.  
  1444. /*
  1445.  * CPatronFrame::SetMenu
  1446.  *
  1447.  * Purpose:
  1448.  *  Instructs the container to replace whatever menu it's currently
  1449.  *  using with the given menu and to call OleSetMenuDescritor so OLE
  1450.  *  knows to whom to dispatch messages.
  1451.  *
  1452.  * Parameters:
  1453.  *  hMenu           HMENU to show.
  1454.  *  hOLEMenu        HOLEMENU to the menu descriptor.
  1455.  *  hWndObj         HWND of the active object to which messages are
  1456.  *                  dispatched.
  1457.  * Return Value:
  1458.  *  HRESULT         NOERROR
  1459.  */
  1460.  
  1461. STDMETHODIMP CPatronFrame::SetMenu(HMENU hMenu
  1462.     , HOLEMENU hOLEMenu, HWND hWndObj)
  1463.     {
  1464.     HRESULT         hr;
  1465.     PCPatronClient  pCL=(PCPatronClient)m_pCL;
  1466.  
  1467.     /*
  1468.      * Our responsibilities here are to put the menu on the frame
  1469.      * window and call OleSetMenuDescriptor.
  1470.      * CPatronClient::SetMenu which we call here takes care of
  1471.      * MDI/SDI differences.
  1472.      *
  1473.      * We also want to save the object's hWnd for use in WM_SETFOCUS
  1474.      * processing.
  1475.      */
  1476.  
  1477.     if (NULL==hMenu)
  1478.         {
  1479.         m_hWndObj=NULL;
  1480.  
  1481.         //Prevent redundant calls, or debug warnings on startup.
  1482.         if (NULL==m_hMenuTop)
  1483.             return NOERROR;
  1484.  
  1485.         hMenu=m_hMenuTop;
  1486.         m_hMenuTop=NULL;
  1487.         }
  1488.     else
  1489.         {
  1490.         m_hMenuTop=m_hMenuOrg;
  1491.         m_hWndObj=hWndObj;
  1492.         }
  1493.  
  1494.     pCL->SetMenu(m_hWnd, hMenu, m_hMenuWindow);
  1495.     hr=OleSetMenuDescriptor(hOLEMenu, m_hWnd, hWndObj, NULL, NULL);
  1496.     return hr;
  1497.     }
  1498.  
  1499.  
  1500.  
  1501.  
  1502. /*
  1503.  * CPatronFrame::RemoveMenus
  1504.  *
  1505.  * Purpose:
  1506.  *  Asks the container to remove any menus it put into hMenu in
  1507.  *  InsertMenus.
  1508.  *
  1509.  * Parameters:
  1510.  *  hMenu           HMENU from which to remove the container's
  1511.  *                  items.
  1512.  *
  1513.  * Return Value:
  1514.  *  HRESULT         NOERROR
  1515.  */
  1516.  
  1517. STDMETHODIMP CPatronFrame::RemoveMenus(HMENU hMenu)
  1518.     {
  1519.     int         cItems, i, j;
  1520.     HMENU       hMenuT;
  1521.  
  1522.     /*
  1523.      * To be defensive, loop through this menu removing anything
  1524.      * we recognize (that is, anything in m_phMenu) just in case
  1525.      * the server didn't clean it up right.  At least we can
  1526.      * give ourselves the prophylactic benefit.
  1527.      */
  1528.  
  1529.     if (NULL==hMenu)
  1530.         return NOERROR;
  1531.  
  1532.     cItems=GetMenuItemCount(hMenu);
  1533.  
  1534.     /*
  1535.      * Walk backwards down the menu.  For each popup, see if it
  1536.      * matches any other popup we know about, and if so, remove
  1537.      * it from the shared menu.
  1538.      */
  1539.     for (i=cItems; i >=0; i--)
  1540.         {
  1541.         hMenuT=GetSubMenu(hMenu, i);
  1542.  
  1543.         for (j=0; j <= CMENUS; j++)
  1544.             {
  1545.             if (hMenuT==m_phMenu[j])
  1546.                 RemoveMenu(hMenu, i, MF_BYPOSITION);
  1547.             }
  1548.         }
  1549.  
  1550.     //The menu should now be empty.
  1551.     return NOERROR;
  1552.     }
  1553.  
  1554.  
  1555.  
  1556.  
  1557. /*
  1558.  * CPatronFrame::SetStatusText
  1559.  *
  1560.  * Purpose:
  1561.  *  Asks the container to place some text in a status line, if one
  1562.  *  exists.  If the container does not have a status line it
  1563.  *  should return E_FAIL here in which case the object could
  1564.  *  display its own.
  1565.  *
  1566.  * Parameters:
  1567.  *  pszText         LPCOLESTR to display.
  1568.  *
  1569.  * Return Value:
  1570.  *  HRESULT         NOERROR if successful, S_TRUNCATED if not all
  1571.  *                  of the text could be displayed, or E_FAIL if
  1572.  *                  the container has no status line.
  1573.  */
  1574.  
  1575. STDMETHODIMP CPatronFrame::SetStatusText(LPCOLESTR pszText)
  1576.     {
  1577.     /*
  1578.      * Just send this to the StatStrip.  Unfortunately it won't tell
  1579.      * us about truncation.  Oh well, we'll just act like it worked.
  1580.      */
  1581.    #ifdef WIN32ANSI
  1582.     TCHAR       szTemp[256];
  1583.  
  1584.     WideCharToMultiByte(CP_ACP, 0, pszText, -1, szTemp, 256
  1585.         , NULL, NULL);
  1586.     m_pSL->MessageSet(szTemp);
  1587.    #else
  1588.     m_pSL->MessageSet((LPTSTR)pszText);
  1589.    #endif
  1590.  
  1591.     return NOERROR;
  1592.     }
  1593.  
  1594.  
  1595.  
  1596.  
  1597. /*
  1598.  * CPatronFrame::EnableModeless
  1599.  *
  1600.  * Purpose:
  1601.  *  Instructs the container to show or hide any modeless popup
  1602.  *  windows that it may be using.
  1603.  *
  1604.  * Parameters:
  1605.  *  fEnable         BOOL indicating to enable/show the windows
  1606.  *                  (TRUE) or to hide them (FALSE).
  1607.  *
  1608.  * Return Value:
  1609.  *  HRESULT         NOERROR
  1610.  */
  1611.  
  1612. STDMETHODIMP CPatronFrame::EnableModeless(BOOL fEnable)
  1613.     {
  1614.     return NOERROR;
  1615.     }
  1616.  
  1617.  
  1618.  
  1619.  
  1620. /*
  1621.  * CPatronFrame::TranslateAccelerator
  1622.  *
  1623.  * Purpose:
  1624.  *  When dealing with an in-place object from an EXE server, this
  1625.  *  is called to give the container a chance to process accelerators
  1626.  *  after the server has looked at the message.
  1627.  *
  1628.  * Parameters:
  1629.  *  pMSG            LPMSG for the container to examine.
  1630.  *  wID             WORD the identifier in the container's
  1631.  *                  accelerator table (from IOleInPlaceSite
  1632.  *                  ::GetWindowContext) for this message (OLE does
  1633.  *                  some translation before calling).
  1634.  *
  1635.  * Return Value:
  1636.  *  HRESULT         NOERROR if the keystroke was used,
  1637.  *                  S_FALSE otherwise.
  1638.  */
  1639.  
  1640. STDMETHODIMP CPatronFrame::TranslateAccelerator(LPMSG pMSG, WORD wID)
  1641.     {
  1642.     SCODE       sc;
  1643.  
  1644.     /*
  1645.      * wID already has anything translated from m_hAccelIP for us,
  1646.      * so we can just check for the commands we want and process
  1647.      * them instead of calling TranslateAccelerator which would be
  1648.      * redundant and which also has a possibility of dispatching to
  1649.      * the wrong window.
  1650.      */
  1651.     if ((IDM_PAGENEWPAGE <= wID && IDM_PAGELASTPAGE >= wID)
  1652.         || IDM_OPENOBJECT==wID || IDM_ENTERCONTEXTHELP==wID
  1653.         || IDM_ESCAPECONTEXTHELP==wID)
  1654.         {
  1655.         //wID properly expands to 32-bits
  1656.         OnCommand(m_hWnd, (WPARAM)wID, 0L);
  1657.         sc=S_OK;
  1658.         }
  1659.    #ifdef MDI
  1660.     else if (TranslateMDISysAccel(m_pCL->Window(), pMSG))
  1661.         sc=S_OK;
  1662.    #endif
  1663.     else
  1664.         sc=S_FALSE;
  1665.  
  1666.     return ResultFromScode(sc);
  1667.     }
  1668.