olesvr1.cpp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include <shellapi.h>
  12. #ifdef AFX_OLE4_SEG
  13. #pragma code_seg(AFX_OLE4_SEG)
  14. #endif
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. #define new DEBUG_NEW
  20. //////////////////////////////////////////////////////////////////////////////
  21. // COleServerDoc implementation
  22. COleServerDoc::COleServerDoc()
  23. {
  24. m_lpClientSite = NULL; // will be non-NULL when document is embedding
  25. m_bCntrVisible = FALSE;
  26. m_pInPlaceFrame = NULL; // will be non-NULL when in-place active
  27. m_pOrigParent = NULL;
  28. m_dwOrigStyle = 0;
  29. m_dwOrigStyleEx = 0;
  30. m_bClosing = FALSE;
  31. m_pEmbeddedItem = NULL; // will be non-NULL if embedded item needed
  32. m_pDocObjectServer = NULL; // becomes non-NULL if DocObject support enabled
  33. }
  34. COleServerDoc::~COleServerDoc()
  35. {
  36. DeleteContents(); // Note: will not call derived class
  37. if (m_pEmbeddedItem != NULL)
  38. {
  39. m_pEmbeddedItem->ExternalRelease();
  40. m_pEmbeddedItem = NULL;
  41. }
  42. // disconnect (remove) all items from the document
  43. POSITION pos = GetStartPosition();
  44. COleServerItem* pItem;
  45. while ((pItem = GetNextServerItem(pos)) != NULL)
  46. RemoveItem(pItem);
  47. // release doc object manager, if any
  48. if (m_pDocObjectServer != NULL)
  49. {
  50. delete m_pDocObjectServer;
  51. m_pDocObjectServer = NULL;
  52. }
  53. // should not be in-place active when doc is destroyed!
  54. ASSERT(m_pInPlaceFrame == NULL);
  55. // Note: this must be done before the client site is released
  56. RELEASE(m_lpRootStg);
  57. // release client-site pointer
  58. RELEASE(m_lpClientSite);
  59. }
  60. void COleServerDoc::DeleteContents()
  61. {
  62. COleLinkingDoc::DeleteContents();
  63. // protect all server items with an extra reference count
  64. POSITION pos = GetStartPosition();
  65. COleServerItem* pItem;
  66. while ((pItem = GetNextServerItem(pos)) != NULL)
  67. pItem->InternalAddRef();
  68. // delete any autodelete server items
  69. pos = GetStartPosition();
  70. while ((pItem = GetNextServerItem(pos)) != NULL)
  71. {
  72. if (pItem->m_bAutoDelete)
  73. delete pItem;
  74. }
  75. // remove extra reference added above
  76. pos = GetStartPosition();
  77. while ((pItem = GetNextServerItem(pos)) != NULL)
  78. pItem->InternalRelease();
  79. }
  80. COleServerItem* COleServerDoc::GetEmbeddedItem()
  81. {
  82. // allocate embedded item if necessary
  83. if (m_pEmbeddedItem == NULL)
  84. {
  85. m_pEmbeddedItem = OnGetEmbeddedItem();
  86. m_pEmbeddedItem->ExternalAddRef();
  87. }
  88. ASSERT_VALID(m_pEmbeddedItem);
  89. return m_pEmbeddedItem;
  90. }
  91. CDocObjectServer* COleServerDoc::GetDocObjectServer(LPOLEDOCUMENTSITE pDocSite)
  92. {
  93. // by default, we're not DocObject enabled
  94. UNUSED_ALWAYS(pDocSite);
  95. return NULL;
  96. }
  97. HRESULT COleServerDoc::OnExecOleCmd(const GUID* pguidCmdGroup, DWORD nCmdID,
  98. DWORD nCmdExecOpt, VARIANTARG* pvarargIn, VARIANTARG* pvarargOut)
  99. {
  100. UNUSED_ALWAYS(pguidCmdGroup);
  101. UNUSED_ALWAYS(nCmdID);
  102. UNUSED_ALWAYS(nCmdExecOpt);
  103. UNUSED_ALWAYS(pvarargIn);
  104. UNUSED_ALWAYS(pvarargOut);
  105. return E_NOTIMPL;
  106. }
  107. LPUNKNOWN COleServerDoc::GetInterfaceHook(const void* piid)
  108. {
  109. LPUNKNOWN lpUnk = NULL;
  110. // are we Doc Object supporters?
  111. if (m_pDocObjectServer != NULL)
  112. {
  113. // don't be tricked into handing out a different IUnknown
  114. DWORD lData1 = ((IID*)piid)->Data1;
  115. BOOL bUnknown = ((DWORD*)&IID_IUnknown)[0] == lData1 &&
  116. ((DWORD*)piid)[1] == ((DWORD*)&IID_IUnknown)[1] &&
  117. ((DWORD*)piid)[2] == ((DWORD*)&IID_IUnknown)[2] &&
  118. ((DWORD*)piid)[3] == ((DWORD*)&IID_IUnknown)[3];
  119. if (bUnknown)
  120. return NULL;
  121. lpUnk = m_pDocObjectServer->GetInterface(piid);
  122. }
  123. // failing that, try the base class
  124. if (lpUnk == NULL)
  125. lpUnk = COleLinkingDoc::GetInterfaceHook(piid);
  126. return lpUnk;
  127. }
  128. void COleServerDoc::ActivateDocObject()
  129. {
  130. if (m_pDocObjectServer != NULL)
  131. m_pDocObjectServer->ActivateDocObject();
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // COleServerDoc client notifications
  135. void COleServerDoc::NotifyRename(LPCTSTR lpszNewName)
  136. {
  137. ASSERT_VALID(this);
  138. ASSERT(AfxIsValidString(lpszNewName));
  139. if (m_pFactory != NULL)
  140. {
  141. // update running object table with new moniker
  142. Revoke();
  143. Register(m_pFactory, lpszNewName);
  144. // notify all items of the new moniker
  145. POSITION pos = GetStartPosition();
  146. COleServerItem* pItem;
  147. while ((pItem = GetNextServerItem(pos)) != NULL)
  148. {
  149. // notify client directly
  150. LPMONIKER lpMoniker = pItem->GetMoniker(OLEGETMONIKER_ONLYIFTHERE);
  151. pItem->NotifyClient(OLE_RENAMED, (DWORD)lpMoniker);
  152. RELEASE(lpMoniker);
  153. }
  154. }
  155. }
  156. void COleServerDoc::NotifyAllItems(OLE_NOTIFICATION nCode, DWORD dwParam)
  157. {
  158. ASSERT_VALID(this);
  159. POSITION pos = GetStartPosition();
  160. COleServerItem* pItem;
  161. while ((pItem = GetNextServerItem(pos)) != NULL)
  162. {
  163. // notify client directly
  164. pItem->NotifyClient(nCode, dwParam);
  165. }
  166. }
  167. // UpdateAllItems is much like UpdateAllViews, but for server items
  168. void COleServerDoc::UpdateAllItems(COleServerItem* pSender,
  169. LPARAM lHint, CObject* pHint, DVASPECT nDrawAspect)
  170. {
  171. ASSERT_VALID(this);
  172. POSITION pos = GetStartPosition();
  173. COleServerItem* pItem;
  174. while ((pItem = GetNextServerItem(pos)) != NULL)
  175. {
  176. // notify client indirectly through OnUpdate
  177. if (pItem != pSender)
  178. pItem->OnUpdate(pSender, lHint, pHint, nDrawAspect);
  179. }
  180. }
  181. void COleServerItem::OnUpdate(COleServerItem* /*pSender*/,
  182. LPARAM /*lHint*/, CObject* /*pHint*/, DVASPECT nDrawAspect)
  183. {
  184. // the default implementation always notifies the container, regardless
  185. // of the specific hint or sender.
  186. NotifyChanged(nDrawAspect);
  187. }
  188. /////////////////////////////////////////////////////////////////////////////
  189. // COleServerDoc attributes
  190. BOOL COleServerDoc::GetZoomFactor(LPSIZE lpSizeNum, LPSIZE lpSizeDenom,
  191. LPCRECT lpPosRect) const
  192. {
  193. ASSERT_VALID(this);
  194. ASSERT(lpSizeNum == NULL || AfxIsValidAddress(lpSizeNum, sizeof(SIZE)));
  195. ASSERT(lpSizeDenom == NULL || AfxIsValidAddress(lpSizeDenom, sizeof(SIZE)));
  196. ASSERT(lpPosRect == NULL ||
  197. AfxIsValidAddress(lpPosRect, sizeof(RECT), FALSE));
  198. if (!IsInPlaceActive())
  199. {
  200. if (lpSizeNum != NULL)
  201. {
  202. ASSERT(lpSizeDenom != NULL);
  203. lpSizeNum->cx = 1;
  204. lpSizeNum->cy = 1;
  205. *lpSizeDenom = *lpSizeNum;
  206. }
  207. return FALSE;
  208. }
  209. ASSERT_VALID(m_pInPlaceFrame);
  210. // the zoom factor is (Size(position-rect) / m_sizeExtent)
  211. CSize sizeNum;
  212. if (lpPosRect == NULL)
  213. {
  214. // use current position rect
  215. sizeNum = m_pInPlaceFrame->m_rectPos.Size();
  216. }
  217. else
  218. {
  219. // use new position rect
  220. sizeNum.cx = lpPosRect->right - lpPosRect->left;
  221. sizeNum.cy = lpPosRect->bottom - lpPosRect->top;
  222. }
  223. // m_sizeExtent is in HIMETRIC units -- need to convert to pixels.
  224. CSize sizeDenom(0, 0);
  225. COleServerItem* pItem = ((COleServerDoc*)this)->GetEmbeddedItem();
  226. ASSERT_VALID(pItem);
  227. ASSERT_KINDOF(COleServerItem, pItem);
  228. // get zoom denominator, which is based on the current extent
  229. ((COleServerItem*)pItem)->OnGetExtent(DVASPECT_CONTENT, sizeDenom);
  230. if (sizeDenom.cx == 0 || sizeDenom.cy == 0)
  231. {
  232. // no extent from container available, so use natural extent instead
  233. pItem->OnGetExtent(DVASPECT_CONTENT, sizeDenom);
  234. }
  235. // convert extent to pixels first
  236. ((CDC*)NULL)->HIMETRICtoDP(&sizeDenom);
  237. // might be bad to have zoom denominator of zero!
  238. if (sizeDenom.cy == 0 || sizeDenom.cx == 0)
  239. {
  240. TRACE0("Warning: zero 'zoom denominator', using 100%% zoom instead.\n");
  241. sizeDenom = sizeNum;
  242. }
  243. // store the results
  244. if (lpSizeNum != NULL)
  245. {
  246. ASSERT(lpSizeDenom != NULL);
  247. *lpSizeNum = sizeNum;
  248. *lpSizeDenom = sizeDenom;
  249. }
  250. // if 100% scaling, return FALSE
  251. return sizeNum != sizeDenom;
  252. }
  253. void COleServerDoc::GetItemPosition(LPRECT lpPosRect) const
  254. {
  255. ASSERT_VALID(this);
  256. ASSERT(AfxIsValidAddress(lpPosRect, sizeof(RECT)));
  257. ASSERT(IsInPlaceActive());
  258. ASSERT_VALID(m_pInPlaceFrame);
  259. // copy the current rectangle
  260. *lpPosRect = m_pInPlaceFrame->m_rectPos;
  261. }
  262. void COleServerDoc::GetItemClipRect(LPRECT lpClipRect) const
  263. {
  264. ASSERT_VALID(this);
  265. ASSERT(AfxIsValidAddress(lpClipRect, sizeof(RECT)));
  266. ASSERT(IsInPlaceActive());
  267. ASSERT_VALID(m_pInPlaceFrame);
  268. // copy the current rectangle
  269. *lpClipRect = m_pInPlaceFrame->m_rectClip;
  270. }
  271. /////////////////////////////////////////////////////////////////////////////
  272. // COleServerDoc overrideables
  273. COleServerItem* COleServerDoc::OnGetLinkedItem(LPCTSTR lpszItemName)
  274. {
  275. ASSERT_VALID(this);
  276. ASSERT(AfxIsValidString(lpszItemName));
  277. // default implementation walks list of server items looking for
  278. // a case sensitive match
  279. POSITION pos = GetStartPosition();
  280. COleServerItem* pItem;
  281. while ((pItem = GetNextServerItem(pos)) != NULL)
  282. {
  283. // return item if name matches (case sensitive)
  284. if (lstrcmp(pItem->GetItemName(), lpszItemName) == 0)
  285. return pItem;
  286. }
  287. #ifdef _DEBUG
  288. if (afxTraceFlags & traceOle)
  289. {
  290. TRACE0("Warning: default COleServerDoc::OnGetLinkedItem implementation\n");
  291. TRACE1("\tfailed to find item '%s'.\n", lpszItemName);
  292. }
  293. #endif
  294. return NULL; // not found (no link found)
  295. }
  296. void COleServerDoc::OnClose(OLECLOSE dwCloseOption)
  297. {
  298. ASSERT_VALID(this);
  299. // do nothing if already in the process of closing the document
  300. if (m_bClosing)
  301. return;
  302. // OLECLOSE_PROMPTSAVE is handled like OLECLOSE_SAVEIFDIRTY if invisible
  303. CFrameWnd* pFrameWnd = GetFirstFrame();
  304. if (pFrameWnd != NULL && pFrameWnd->IsWindowVisible())
  305. dwCloseOption = OLECLOSE_SAVEIFDIRTY;
  306. // handle modified document and special dwCloseOption flags
  307. TRY
  308. {
  309. if (IsModified())
  310. {
  311. switch (dwCloseOption)
  312. {
  313. case OLECLOSE_PROMPTSAVE:
  314. if (!SaveModifiedPrompt())
  315. AfxThrowOleException(OLE_E_PROMPTSAVECANCELLED);
  316. break;
  317. case OLECLOSE_SAVEIFDIRTY:
  318. SaveEmbedding();
  319. break;
  320. }
  321. }
  322. }
  323. END_TRY
  324. // deactivate in-place session
  325. if (m_pInPlaceFrame != NULL)
  326. {
  327. OnDeactivate();
  328. ASSERT(m_pInPlaceFrame == NULL);
  329. }
  330. // close the document
  331. BOOL bAutoDelete = m_bAutoDelete;
  332. m_bAutoDelete = FALSE;
  333. OnCloseDocument();
  334. m_bAutoDelete = bAutoDelete;
  335. }
  336. BOOL COleServerDoc::SaveModifiedPrompt()
  337. {
  338. ASSERT_VALID(this);
  339. if (m_lpClientSite == NULL)
  340. return SaveModified();
  341. UpdateModifiedFlag(); // check for modified client items
  342. if (!IsModified())
  343. return TRUE; // ok to continue
  344. CString prompt;
  345. AfxFormatString1(prompt, AFX_IDP_ASK_TO_UPDATE, m_strTitle);
  346. switch (AfxMessageBox(prompt, MB_YESNOCANCEL, AFX_IDP_ASK_TO_UPDATE))
  347. {
  348. case IDCANCEL:
  349. return FALSE; // don't continue
  350. case IDYES:
  351. if (!OnUpdateDocument())
  352. {
  353. TRACE0("Warning: OnUpdateDocument failed to update.\n");
  354. // keep going, close will flush it
  355. }
  356. break;
  357. }
  358. return TRUE; // keep going
  359. }
  360. BOOL COleServerDoc::CanCloseFrame(CFrameWnd* pFrame)
  361. {
  362. m_bClosing = TRUE;
  363. if (!COleLinkingDoc::CanCloseFrame(pFrame))
  364. {
  365. m_bClosing = FALSE;
  366. return FALSE;
  367. }
  368. return TRUE;
  369. }
  370. BOOL COleServerDoc::GetFileTypeString(CString& rString)
  371. {
  372. ASSERT_VALID(this);
  373. CDocTemplate* pTemplate = GetDocTemplate();
  374. if (pTemplate == NULL)
  375. return FALSE;
  376. pTemplate->GetDocString(rString, CDocTemplate::fileNewName);
  377. return !rString.IsEmpty();
  378. }
  379. void COleServerDoc::OnSetHostNames(LPCTSTR lpszHost, LPCTSTR lpszHostObj)
  380. {
  381. ASSERT_VALID(this);
  382. ASSERT(lpszHost == NULL || AfxIsValidString(lpszHost));
  383. ASSERT(lpszHostObj == NULL || AfxIsValidString(lpszHostObj));
  384. UNUSED(lpszHost); // unused in release builds
  385. // only change the title for embedded documents
  386. if (m_lpClientSite != NULL)
  387. {
  388. // save name of document for File.Exit update
  389. if (lpszHostObj == NULL)
  390. m_strHostObj.LoadString(AFX_IDS_UNTITLED);
  391. else
  392. m_strHostObj = lpszHostObj;
  393. // attempt to get the document name from the document template
  394. CString strFileType;
  395. if (!GetFileTypeString(strFileType))
  396. return;
  397. // format the string into <server-name> in <docname>
  398. CString strTitle;
  399. AfxFormatString2(strTitle, AFX_IDS_APP_TITLE_EMBEDDING,
  400. strFileType, m_strHostObj);
  401. // change title of document to that for an embedded item
  402. // (this call will update all of the frames)
  403. SetTitle(strTitle);
  404. }
  405. }
  406. void COleServerDoc::SaveEmbedding()
  407. {
  408. ASSERT_VALID(this);
  409. // tell the client site to save the object
  410. if (m_lpClientSite != NULL && !::InSendMessage())
  411. {
  412. SCODE sc = m_lpClientSite->SaveObject();
  413. if (sc != S_OK)
  414. AfxThrowOleException(sc);
  415. }
  416. ASSERT_VALID(this);
  417. }
  418. BOOL COleServerDoc::OnUpdateDocument()
  419. {
  420. ASSERT_VALID(this);
  421. // don't save if already up-to-date
  422. if (!IsModified())
  423. return TRUE;
  424. // save a server document -> update
  425. TRY
  426. {
  427. SaveEmbedding();
  428. }
  429. CATCH_ALL(e)
  430. {
  431. AfxMessageBox(AFX_IDP_FAILED_TO_UPDATE);
  432. DELETE_EXCEPTION(e);
  433. return FALSE;
  434. }
  435. END_CATCH_ALL
  436. return TRUE;
  437. }
  438. LPMONIKER COleServerDoc::GetMoniker(OLEGETMONIKER nAssign)
  439. {
  440. ASSERT_VALID(this);
  441. if (m_lpClientSite != NULL)
  442. {
  443. // get moniker from client site instead of from document
  444. LPMONIKER lpMoniker = NULL;
  445. m_lpClientSite->GetMoniker(nAssign, OLEWHICHMK_OBJFULL, &lpMoniker);
  446. return lpMoniker;
  447. }
  448. return COleLinkingDoc::GetMoniker(nAssign);
  449. }
  450. /////////////////////////////////////////////////////////////////////////////
  451. // COleServerDoc document handling
  452. BOOL COleServerDoc::SaveModified()
  453. {
  454. ASSERT_VALID(this);
  455. if (m_lpClientSite != NULL)
  456. {
  457. if (m_pInPlaceFrame == NULL)
  458. {
  459. UpdateModifiedFlag(); // check for modified items
  460. OnUpdateDocument();
  461. }
  462. return TRUE;
  463. }
  464. return COleLinkingDoc::SaveModified();
  465. }
  466. HMENU COleServerDoc::GetDefaultMenu()
  467. {
  468. ASSERT_VALID(this);
  469. CDocTemplate* pTemplate = GetDocTemplate();
  470. if (pTemplate == NULL)
  471. return NULL; // no doc template -- use default
  472. ASSERT_VALID(pTemplate);
  473. if (m_pInPlaceFrame != NULL)
  474. return pTemplate->m_hMenuInPlaceServer; // return special in-place menu
  475. else if (m_lpClientSite != NULL)
  476. return pTemplate->m_hMenuEmbedding; // return special embedding menu
  477. return NULL; // no special mode, use default menu
  478. }
  479. HACCEL COleServerDoc::GetDefaultAccelerator()
  480. {
  481. ASSERT_VALID(this);
  482. CDocTemplate* pTemplate = GetDocTemplate();
  483. if (pTemplate == NULL)
  484. return NULL; // no doc template -- use default
  485. ASSERT_VALID(pTemplate);
  486. if (m_pInPlaceFrame != NULL)
  487. return pTemplate->m_hAccelInPlaceServer; // return special in-place accel
  488. else if (m_lpClientSite != NULL)
  489. return pTemplate->m_hAccelEmbedding;// return special embedding accel
  490. return NULL; // no special mode, use default menu
  491. }
  492. /////////////////////////////////////////////////////////////////////////////
  493. // COleServerDoc default command handling
  494. BEGIN_MESSAGE_MAP(COleServerDoc, COleLinkingDoc)
  495. //{{AFX_MSG_MAP(COleServerDoc)
  496. ON_COMMAND(ID_FILE_UPDATE, OnFileUpdate)
  497. ON_COMMAND(ID_FILE_SAVE_COPY_AS, OnFileSaveCopyAs)
  498. ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateFileExit)
  499. ON_UPDATE_COMMAND_UI(ID_FILE_UPDATE, OnUpdateFileUpdate)
  500. //}}AFX_MSG_MAP
  501. END_MESSAGE_MAP()
  502. void COleServerDoc::OnFileUpdate()
  503. {
  504. ASSERT_VALID(this);
  505. ASSERT(m_lpClientSite != NULL);
  506. UpdateModifiedFlag();
  507. OnUpdateDocument();
  508. }
  509. void COleServerDoc::OnFileSaveCopyAs()
  510. {
  511. ASSERT_VALID(this);
  512. ASSERT(m_bRemember);
  513. ASSERT(m_lpClientSite != NULL);
  514. LPSTORAGE lpOrigStg = m_lpRootStg;
  515. m_lpRootStg = NULL; // ignore embedded storage for now
  516. TRY
  517. {
  518. // call DoSave to perform Save Copy As...
  519. m_bRemember = FALSE;
  520. DoSave(NULL, FALSE);
  521. }
  522. END_TRY
  523. m_lpRootStg = lpOrigStg;
  524. m_bRemember = TRUE;
  525. }
  526. void COleServerDoc::UpdateUsingHostObj(UINT nIDS, CCmdUI* pCmdUI)
  527. {
  528. ASSERT_VALID(this);
  529. ASSERT(pCmdUI != NULL);
  530. if (m_lpClientSite == NULL)
  531. return;
  532. // update menu item using m_strHostObj
  533. CString str;
  534. AfxFormatString1(str, nIDS, m_strHostObj);
  535. if (!str.IsEmpty())
  536. pCmdUI->SetText(str);
  537. }
  538. void COleServerDoc::OnUpdateFileExit(CCmdUI* pCmdUI)
  539. {
  540. ASSERT_VALID(this);
  541. ASSERT(pCmdUI != NULL);
  542. UpdateUsingHostObj(AFX_IDS_EXIT_MENU, pCmdUI);
  543. }
  544. void COleServerDoc::OnUpdateFileUpdate(CCmdUI* pCmdUI)
  545. {
  546. ASSERT_VALID(this);
  547. ASSERT(pCmdUI != NULL);
  548. UpdateUsingHostObj(AFX_IDS_UPDATE_MENU, pCmdUI);
  549. }
  550. BOOL COleServerDoc::OnSaveDocument(LPCTSTR lpszPathName)
  551. {
  552. ASSERT_VALID(this);
  553. ASSERT(lpszPathName == NULL || AfxIsValidString(lpszPathName));
  554. BOOL bModified = IsModified();
  555. BOOL bRemember = m_bRemember;
  556. if (!COleLinkingDoc::OnSaveDocument(lpszPathName))
  557. return FALSE;
  558. if (!bRemember)
  559. SetModifiedFlag(bModified);
  560. if (lpszPathName != NULL && bRemember)
  561. {
  562. if (AfxComparePath(GetPathName(), lpszPathName))
  563. NotifySaved();
  564. }
  565. return TRUE;
  566. }
  567. void COleServerDoc::OnCloseDocument()
  568. {
  569. ASSERT_VALID(this);
  570. // don't allow in-place active documents to be closed without first
  571. // deactivating them!
  572. if (m_pInPlaceFrame != NULL)
  573. {
  574. if (GetFirstViewPosition() != NULL)
  575. return;
  576. // no views but currently in-place active indicates that
  577. // a WM_ENDSESSION is being processed.
  578. m_pInPlaceFrame = NULL;
  579. }
  580. InternalAddRef(); // keep document stable during shutdown
  581. // update lock count before sending notifications
  582. UpdateVisibleLock(FALSE, FALSE);
  583. // send some notifications to the container
  584. if (m_lpClientSite != NULL && m_bCntrVisible)
  585. {
  586. // allow the container to unshade the object appropriately
  587. m_lpClientSite->OnShowWindow(FALSE);
  588. m_bCntrVisible = FALSE;
  589. }
  590. // send close notification
  591. NotifyClosed();
  592. // finish closing the document (before m_lpClientSite->Release)
  593. BOOL bAutoDelete = m_bAutoDelete;
  594. m_bAutoDelete = FALSE;
  595. COleLinkingDoc::OnCloseDocument();
  596. ASSERT_VALID(this);
  597. // release client-site pointer
  598. RELEASE(m_lpClientSite);
  599. // disconnect the object
  600. LPUNKNOWN lpUnknown = (LPUNKNOWN)GetInterface(&IID_IUnknown);
  601. ASSERT(lpUnknown != NULL);
  602. CoDisconnectObject(lpUnknown, 0);
  603. // destroy the document if allowed
  604. InterlockedDecrement(&m_dwRef); // remove InternalAddRef above
  605. if (bAutoDelete)
  606. delete this;
  607. }
  608. /////////////////////////////////////////////////////////////////////////////
  609. // COleServerDoc show/hide
  610. void COleServerDoc::OnShowDocument(BOOL bShow)
  611. {
  612. ASSERT_VALID(this);
  613. CWinApp* pApp = AfxGetApp();
  614. if (bShow)
  615. {
  616. // deactivate in-place session if active
  617. if (m_pInPlaceFrame != NULL)
  618. {
  619. OnDeactivate();
  620. ASSERT(m_pInPlaceFrame == NULL);
  621. }
  622. // find the first view of this document
  623. CFrameWnd* pFrameWnd;
  624. if ((pFrameWnd = GetFirstFrame()) != NULL)
  625. {
  626. // allow container to show & scroll to the object
  627. if (!pFrameWnd->IsWindowVisible() && m_lpClientSite != NULL)
  628. m_lpClientSite->ShowObject();
  629. // activate frame holding view
  630. ASSERT_VALID(pFrameWnd);
  631. pFrameWnd->ActivateFrame();
  632. // activate application if necessary
  633. CFrameWnd* pAppFrame = pFrameWnd->GetParentFrame();
  634. if (pAppFrame != NULL)
  635. {
  636. pFrameWnd = pAppFrame;
  637. ASSERT_VALID(pFrameWnd);
  638. ASSERT_KINDOF(CFrameWnd, pFrameWnd);
  639. pFrameWnd->ActivateFrame();
  640. }
  641. pFrameWnd->GetLastActivePopup()->SetForegroundWindow();
  642. // update the menu and title as appropriate for this document
  643. pFrameWnd->OnUpdateFrameMenu(NULL);
  644. pFrameWnd->OnUpdateFrameTitle(TRUE);
  645. }
  646. else if (pApp->m_pMainWnd != NULL)
  647. {
  648. // otherwise, just show the main window (for simple servers)
  649. CWnd* pWnd = AfxGetMainWnd();
  650. // allow container to show & scroll to the object
  651. if (!pWnd->IsWindowVisible() && m_lpClientSite != NULL)
  652. m_lpClientSite->ShowObject();
  653. pWnd->ShowWindow(SW_SHOW);
  654. pWnd->SetActiveWindow();
  655. pWnd->SetForegroundWindow();
  656. }
  657. // for file based documents, showing the document puts user in control.
  658. if (!m_bEmbedded)
  659. AfxOleSetUserCtrl(TRUE);
  660. }
  661. else
  662. {
  663. if (m_pInPlaceFrame != NULL)
  664. {
  665. // hide has semantics of DeactivateUI if the item is active
  666. if (m_pInPlaceFrame->m_bUIActive)
  667. OnDeactivateUI(FALSE);
  668. // and then hide the frame itself
  669. if (m_pInPlaceFrame != NULL)
  670. m_pInPlaceFrame->ActivateFrame(SW_HIDE);
  671. return;
  672. }
  673. // find the first view of this document
  674. POSITION pos = GetFirstViewPosition();
  675. if (pos != NULL)
  676. {
  677. CFrameWnd* pDocFrame = GetFirstFrame();
  678. CFrameWnd* pActiveFrame = NULL;
  679. CFrameWnd* pMainFrame = NULL;
  680. CView* pView = GetNextView(pos);
  681. ASSERT_VALID(pView);
  682. // destroy or hide all the frames for this document
  683. // (the main for the document is hidden, where the alternate
  684. // frames are simply destroyed)
  685. do
  686. {
  687. // hide frame holding view
  688. CFrameWnd* pFrame = pView->GetParentFrame();
  689. ASSERT_VALID(pFrame);
  690. // determine next valid view before destroying the frame
  691. while ((pView = GetNextView(pos)) != NULL)
  692. {
  693. if (pView->GetParentFrame() != pFrame)
  694. break;
  695. }
  696. pMainFrame = pFrame->GetParentFrame();
  697. if (pMainFrame != NULL && pMainFrame->GetActiveFrame() == pFrame)
  698. {
  699. // don't destroy the active frame until later
  700. pActiveFrame = pFrame;
  701. }
  702. else
  703. {
  704. // not the active frame -- destroy/hide it now
  705. PreCloseFrame(pFrame);
  706. if (pDocFrame == pFrame)
  707. pFrame->ActivateFrame(SW_HIDE);
  708. else
  709. pFrame->DestroyWindow();
  710. }
  711. } while (pView != NULL);
  712. // hide the active frame last
  713. if (pActiveFrame != NULL)
  714. {
  715. PreCloseFrame(pActiveFrame);
  716. if (pDocFrame == pActiveFrame)
  717. pActiveFrame->ActivateFrame(SW_HIDE);
  718. else
  719. pActiveFrame->DestroyWindow();
  720. // should leave at least one frame
  721. ASSERT_VALID(this);
  722. ASSERT_VALID(GetFirstFrame());
  723. }
  724. }
  725. CFrameWnd* pMainFrame = (CFrameWnd*)pApp->m_pMainWnd;
  726. if (!AfxOleGetUserCtrl() && pMainFrame != NULL &&
  727. pMainFrame->IsWindowEnabled() && pMainFrame->IsFrameWnd() &&
  728. pMainFrame->GetActiveFrame() == pMainFrame)
  729. {
  730. // hide the entire application -- no visible documents left
  731. pApp->HideApplication();
  732. }
  733. }
  734. // send OnShowWindow notifications to the container
  735. if (m_lpClientSite != NULL && (bShow || m_bCntrVisible != bShow))
  736. {
  737. // allow the container to shade the object appropriately
  738. m_lpClientSite->OnShowWindow(bShow);
  739. m_bCntrVisible = bShow;
  740. }
  741. // force update visible lock
  742. if (bShow)
  743. UpdateVisibleLock(TRUE, FALSE);
  744. }
  745. /////////////////////////////////////////////////////////////////////////////
  746. // COleServerDoc storage implementation
  747. void COleServerDoc::OnNewEmbedding(LPSTORAGE lpStorage)
  748. {
  749. ASSERT_VALID(this);
  750. ASSERT(lpStorage != NULL);
  751. // save state
  752. BOOL bUserCtrl = AfxOleGetUserCtrl();
  753. TRY
  754. {
  755. // remember new storage
  756. DeleteContents();
  757. lpStorage->AddRef();
  758. RELEASE(m_lpRootStg);
  759. m_lpRootStg = lpStorage;
  760. m_strPathName.Empty();
  761. m_bEmbedded = TRUE;
  762. // do document initialization by calling OnNewDocument
  763. if (!OnNewDocument())
  764. AfxThrowMemoryException();
  765. }
  766. CATCH_ALL(e)
  767. {
  768. // restore state
  769. AfxOleSetUserCtrl(bUserCtrl);
  770. THROW_LAST();
  771. }
  772. END_CATCH_ALL
  773. // restore state
  774. AfxOleSetUserCtrl(bUserCtrl);
  775. SetModifiedFlag(); // new storage-based documents are dirty!
  776. SendInitialUpdate();
  777. }
  778. void COleServerDoc::OnOpenEmbedding(LPSTORAGE lpStorage)
  779. {
  780. ASSERT_VALID(this);
  781. ASSERT(lpStorage != NULL);
  782. // save state
  783. BOOL bUserCtrl = AfxOleGetUserCtrl();
  784. TRY
  785. {
  786. // abort changes to current document
  787. DeleteContents();
  788. lpStorage->AddRef();
  789. RELEASE(m_lpRootStg);
  790. m_lpRootStg = lpStorage;
  791. // open document from the sub-storage
  792. if (!OnOpenDocument(NULL))
  793. AfxThrowMemoryException();
  794. // now document is storage based
  795. m_strPathName.Empty();
  796. m_bEmbedded = TRUE;
  797. }
  798. CATCH_ALL(e)
  799. {
  800. // restore state
  801. AfxOleSetUserCtrl(bUserCtrl);
  802. THROW_LAST();
  803. }
  804. END_CATCH_ALL
  805. // restore state
  806. AfxOleSetUserCtrl(bUserCtrl);
  807. SetModifiedFlag(FALSE); // start off with unmodified
  808. SendInitialUpdate();
  809. }
  810. void COleServerDoc::OnSaveEmbedding(LPSTORAGE lpStorage)
  811. {
  812. ASSERT_VALID(this);
  813. ASSERT(lpStorage != NULL);
  814. // save state
  815. BOOL bUserCtrl = AfxOleGetUserCtrl();
  816. // check for save as
  817. LPSTORAGE lpOrigStg = m_lpRootStg;
  818. if (!m_bSameAsLoad)
  819. {
  820. // File Save[Copy] As (saving to different file)
  821. ASSERT(lpStorage != NULL);
  822. m_lpRootStg = lpStorage;
  823. }
  824. TRY
  825. {
  826. // save document to the sub-storage
  827. if (!OnSaveDocument(NULL))
  828. AfxThrowMemoryException();
  829. }
  830. CATCH_ALL(e)
  831. {
  832. // restore state
  833. AfxOleSetUserCtrl(bUserCtrl);
  834. // re-attach original storage
  835. m_lpRootStg = lpOrigStg;
  836. THROW_LAST();
  837. }
  838. END_CATCH_ALL
  839. // restore state
  840. AfxOleSetUserCtrl(bUserCtrl);
  841. // re-attach original storage
  842. m_lpRootStg = lpOrigStg;
  843. }
  844. /////////////////////////////////////////////////////////////////////////////
  845. // COleServerDoc in-place activation implementation
  846. AFX_STATIC HWND AFXAPI _AfxGetWindow32(HWND hWnd)
  847. {
  848. // don't bother if hWnd is already a 32-bit HWND
  849. if (HIWORD(hWnd) != 0)
  850. return hWnd;
  851. // otherwise convert by getting a DC...
  852. HDC hDC = ::GetDC(hWnd);
  853. if (hDC == NULL)
  854. return hWnd;
  855. // then, getting the HWND from the DC...
  856. HWND hWnd32 = ::WindowFromDC(hDC);
  857. if (hWnd32 == NULL)
  858. hWnd32 = hWnd;
  859. // then releasing the DC itself
  860. ::ReleaseDC(hWnd, hDC);
  861. return hWnd32; // return full 32-bit HWND
  862. }
  863. BOOL COleServerDoc::ActivateInPlace()
  864. {
  865. ASSERT_VALID(this);
  866. USES_CONVERSION;
  867. LPCOLESTR lpszTitle = NULL;
  868. if (m_lpClientSite == NULL)
  869. return FALSE; // no client-side (may be a link)
  870. // activate already in-place window if currently in-place active
  871. if (m_pInPlaceFrame != NULL)
  872. {
  873. if (m_pInPlaceFrame->m_bUIActive)
  874. {
  875. m_lpClientSite->ShowObject(); // object should get focus
  876. return TRUE;
  877. }
  878. // deactivate in-place session entirely before continuing
  879. OnDeactivate();
  880. }
  881. // fail if already fully open
  882. if (GetFirstFrame()->IsWindowVisible())
  883. return FALSE;
  884. // build object title/name (the container may use this in its caption)
  885. CString strFileType, strTitle;
  886. if (!GetFileTypeString(strFileType))
  887. return FALSE;
  888. AfxFormatString2(strTitle, AFX_IDS_OBJ_TITLE_INPLACE,
  889. AfxGetAppName(), strFileType);
  890. // attempt to get in-place client-site interface
  891. LPOLEINPLACESITE lpInPlaceSite =
  892. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  893. if (lpInPlaceSite == NULL)
  894. {
  895. // unable to get in-place client site interface
  896. return FALSE;
  897. }
  898. // see if the container wants to go in-place right now
  899. if (lpInPlaceSite->CanInPlaceActivate() != S_OK)
  900. goto ReleaseAndFail;
  901. // start activation sequence...
  902. if (lpInPlaceSite->OnInPlaceActivate() != S_OK)
  903. goto ReleaseAndFail;
  904. // we'll need the parent window to create the COleIPFrameWnd
  905. HWND hWnd;
  906. VERIFY(lpInPlaceSite->GetWindow(&hWnd) == S_OK);
  907. CWnd* pParentWnd;
  908. pParentWnd = CWnd::FromHandle(hWnd);
  909. // create the inplace frame window
  910. COleIPFrameWnd* pFrameWnd;
  911. pFrameWnd = CreateInPlaceFrame(pParentWnd);
  912. if (pFrameWnd == NULL)
  913. {
  914. ASSERT(lpInPlaceSite != NULL);
  915. lpInPlaceSite->OnInPlaceDeactivate();
  916. goto ReleaseAndFail;
  917. }
  918. ASSERT(pFrameWnd->GetParent() == pParentWnd);
  919. m_pInPlaceFrame = pFrameWnd;
  920. // send activate notification.
  921. if (lpInPlaceSite->OnUIActivate() != S_OK)
  922. goto DestroyFrameAndFail;
  923. // need to get frame & doc window interfaces as well as other info
  924. RECT rcPosRect, rcClipRect;
  925. if (lpInPlaceSite->GetWindowContext(
  926. &pFrameWnd->m_lpFrame, &pFrameWnd->m_lpDocFrame,
  927. &rcPosRect, &rcClipRect, &pFrameWnd->m_frameInfo) != S_OK)
  928. {
  929. goto DeactivateUIAndFail;
  930. }
  931. ASSERT(pFrameWnd->m_lpFrame != NULL);
  932. // setup the shared menu
  933. if (!pFrameWnd->BuildSharedMenu())
  934. goto DeactivateUIAndFail;
  935. // allow server to install frame controls in container
  936. VERIFY(pFrameWnd->m_lpFrame->GetWindow(&hWnd) == S_OK);
  937. // some containers (Works 4.0, for example) return only the lower
  938. // 16-bits of the HWND and that confuses us; to work around this
  939. // we convert the 16-bit HWND into the full 32-bit HWND.
  940. hWnd = _AfxGetWindow32(hWnd);
  941. pFrameWnd->m_pMainFrame = new COleCntrFrameWnd(pFrameWnd);
  942. pFrameWnd->m_pMainFrame->Attach(hWnd);
  943. if (pFrameWnd->m_lpDocFrame != NULL)
  944. {
  945. HWND hWndDocument;
  946. VERIFY(pFrameWnd->m_lpDocFrame->GetWindow(&hWndDocument) == S_OK);
  947. if (hWndDocument != hWnd)
  948. {
  949. pFrameWnd->m_pDocFrame = new COleCntrFrameWnd(pFrameWnd);
  950. pFrameWnd->m_pDocFrame->Attach(hWndDocument);
  951. }
  952. else
  953. {
  954. RELEASE(pFrameWnd->m_lpDocFrame);
  955. pFrameWnd->m_lpDocFrame = NULL;
  956. }
  957. }
  958. // update zoom factor information before creating control bars
  959. //WINBUG: some clients send an empty rectangle and expect the
  960. // server to use the ClipRect for the PosRect
  961. if (IsRectEmpty(&rcPosRect))
  962. pFrameWnd->m_rectPos.CopyRect(&rcClipRect);
  963. else
  964. pFrameWnd->m_rectPos.CopyRect(&rcPosRect);
  965. pFrameWnd->m_rectClip.CopyRect(&rcClipRect);
  966. if (!pFrameWnd->OnCreateControlBars(pFrameWnd->m_pMainFrame,
  967. pFrameWnd->m_pDocFrame))
  968. {
  969. goto DeactivateUIAndFail;
  970. }
  971. // resize the window to match the object
  972. //WINBUG: some clients send an empty rectangle and expect the
  973. // server to use the ClipRect for the PosRect
  974. if (IsRectEmpty(&rcPosRect))
  975. OnSetItemRects(&rcClipRect, &rcClipRect);
  976. else
  977. OnSetItemRects(&rcPosRect, &rcClipRect);
  978. // set the active object
  979. ASSERT(pFrameWnd->m_lpFrame != NULL);
  980. LPOLEINPLACEACTIVEOBJECT lpActiveObject;
  981. lpActiveObject = (LPOLEINPLACEACTIVEOBJECT)
  982. GetInterface(&IID_IOleInPlaceActiveObject);
  983. lpszTitle = T2COLE(strTitle);
  984. pFrameWnd->m_lpFrame->SetActiveObject(lpActiveObject, lpszTitle);
  985. if (pFrameWnd->m_lpDocFrame != NULL)
  986. pFrameWnd->m_lpDocFrame->SetActiveObject(lpActiveObject, lpszTitle);
  987. // add frame & document level frame controls
  988. ASSERT(m_pInPlaceFrame->m_lpFrame != NULL);
  989. OnShowControlBars(m_pInPlaceFrame->m_pMainFrame, TRUE);
  990. if (m_pInPlaceFrame->m_lpDocFrame != NULL)
  991. OnShowControlBars(m_pInPlaceFrame->m_pDocFrame, TRUE);
  992. // show any hidden modeless dialogs as well...
  993. m_pInPlaceFrame->ShowOwnedWindows(TRUE);
  994. // attempt toolbar negotiation
  995. OnResizeBorder(NULL, pFrameWnd->m_lpFrame, TRUE);
  996. if (pFrameWnd->m_lpDocFrame != NULL)
  997. OnResizeBorder(NULL, pFrameWnd->m_lpDocFrame, FALSE);
  998. // install the menu (also installs a hook which forwards messages from
  999. // the menu to the inplace frame window)
  1000. pFrameWnd->m_lpFrame->SetMenu(pFrameWnd->m_hSharedMenu,
  1001. pFrameWnd->m_hOleMenu, pFrameWnd->m_hWnd);
  1002. // make sure object is scrolled into view
  1003. m_lpClientSite->ShowObject(); // object should get focus
  1004. // finally -- show the inplace frame window and set focus
  1005. pFrameWnd->ShowWindow(SW_SHOW);
  1006. pFrameWnd->SetFocus();
  1007. pFrameWnd->UpdateWindow();
  1008. UpdateVisibleLock(TRUE, FALSE);
  1009. // allow the main window to be set
  1010. OnFrameWindowActivate(TRUE);
  1011. pFrameWnd->m_bUIActive = TRUE;
  1012. // cleanup and return
  1013. lpInPlaceSite->Release();
  1014. return TRUE;
  1015. DeactivateUIAndFail:
  1016. ASSERT(lpInPlaceSite != NULL);
  1017. lpInPlaceSite->OnUIDeactivate(FALSE);
  1018. DestroyFrameAndFail:
  1019. if (m_pInPlaceFrame != NULL)
  1020. {
  1021. ASSERT(pFrameWnd != NULL);
  1022. DestroyInPlaceFrame(pFrameWnd);
  1023. m_pInPlaceFrame = NULL;
  1024. // also need to send OnInPlaceDeactivate notification
  1025. ASSERT(lpInPlaceSite != NULL);
  1026. lpInPlaceSite->OnInPlaceDeactivate();
  1027. }
  1028. ReleaseAndFail:
  1029. ASSERT(lpInPlaceSite != NULL);
  1030. lpInPlaceSite->Release();
  1031. return FALSE;
  1032. }
  1033. COleIPFrameWnd* COleServerDoc::CreateInPlaceFrame(CWnd* pParentWnd)
  1034. {
  1035. ASSERT_VALID(this);
  1036. ASSERT_VALID(pParentWnd);
  1037. // get runtime class from the doc template
  1038. CDocTemplate* pTemplate = GetDocTemplate();
  1039. ASSERT_VALID(pTemplate);
  1040. // use existing view if possible
  1041. CWnd* pViewParent = NULL;
  1042. CView* pView = NULL;
  1043. CFrameWnd* pFrame = GetFirstFrame();
  1044. if (pFrame != NULL)
  1045. {
  1046. pView = (CView*)pFrame->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
  1047. if (pView != NULL)
  1048. {
  1049. ASSERT_KINDOF(CView, pView);
  1050. pViewParent = pView->GetParent();
  1051. m_dwOrigStyle = pView->GetStyle();
  1052. m_dwOrigStyleEx = pView->GetExStyle();
  1053. }
  1054. }
  1055. // create the frame from the template
  1056. COleIPFrameWnd* pFrameWnd = (COleIPFrameWnd*)
  1057. pTemplate->CreateOleFrame(pParentWnd, this, pView == NULL);
  1058. if (pFrameWnd == NULL)
  1059. return NULL;
  1060. // connect the view to the frame window, if necessary
  1061. if (pView != NULL)
  1062. {
  1063. ConnectView(pFrameWnd, pView);
  1064. pView->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
  1065. }
  1066. // remember original parent window for deactivate
  1067. m_pOrigParent = pViewParent;
  1068. // send OnInitialUpdate if new view was created
  1069. if (pView == NULL)
  1070. pTemplate->InitialUpdateFrame(pFrameWnd, this, FALSE);
  1071. // verify the type
  1072. ASSERT_VALID(pFrameWnd);
  1073. ASSERT_KINDOF(COleIPFrameWnd, pFrameWnd);
  1074. return pFrameWnd;
  1075. }
  1076. void COleServerDoc::DestroyInPlaceFrame(COleIPFrameWnd* pFrameWnd)
  1077. {
  1078. ASSERT_VALID(this);
  1079. ASSERT_VALID(pFrameWnd);
  1080. // connect view to original, if existing view was used
  1081. if (m_pOrigParent != NULL)
  1082. {
  1083. CView* pView = (CView*)pFrameWnd->GetDescendantWindow(
  1084. AFX_IDW_PANE_FIRST, TRUE);
  1085. ASSERT_VALID(pView);
  1086. // leaving the focus on an MDI child or one of its child windows
  1087. // causes Windows to get confused when the child window is
  1088. // destroyed, not to mention the fact that the focus will be
  1089. // out of sync with activation.
  1090. if (::GetFocus() == pView->m_hWnd)
  1091. {
  1092. // move focus to somewhere safe
  1093. HWND hWnd = ::GetParent(pFrameWnd->m_hWnd);
  1094. if (hWnd != NULL)
  1095. ::SetFocus(hWnd);
  1096. // check again
  1097. if (::GetFocus() == pView->m_hWnd)
  1098. SetFocus(NULL); // last ditch effort
  1099. }
  1100. ConnectView(m_pOrigParent, pView);
  1101. m_pOrigParent = NULL;
  1102. // remove any scrollbars added because of in-place activation
  1103. if ((m_dwOrigStyle & (WS_HSCROLL|WS_VSCROLL)) == 0 &&
  1104. (pView->GetStyle() & (WS_HSCROLL|WS_VSCROLL)) != 0)
  1105. {
  1106. ::SetScrollRange(pView->m_hWnd, SB_HORZ, 0, 0, TRUE);
  1107. ::SetScrollRange(pView->m_hWnd, SB_VERT, 0, 0, TRUE);
  1108. }
  1109. // restore old 3D style
  1110. pView->ModifyStyleEx(0, m_dwOrigStyleEx & WS_EX_CLIENTEDGE,
  1111. SWP_DRAWFRAME);
  1112. // force recalc layout on splitter window
  1113. CSplitterWnd* pSplitter = CView::GetParentSplitter(pView, TRUE);
  1114. if (pSplitter != NULL)
  1115. pSplitter->RecalcLayout();
  1116. }
  1117. // no active view or document during destroy
  1118. pFrameWnd->SetActiveView(NULL);
  1119. // destroy in-place frame window
  1120. pFrameWnd->DestroyWindow();
  1121. }
  1122. void COleServerDoc::ConnectView(CWnd* pParentWnd, CView* pView)
  1123. {
  1124. ASSERT_VALID(this);
  1125. ASSERT_VALID(pParentWnd);
  1126. ASSERT_VALID(pView);
  1127. // move the view to the new parent
  1128. pView->SetParent(pParentWnd);
  1129. // Note: The currently active view on the original frame window is
  1130. // kept active, because some controls, especially Windows controls,
  1131. // continue to send notification messages to the original parent
  1132. // window of the control. So, the original frame window is kept
  1133. // alive with the original active view pointer intact, such that
  1134. // these notification messages do not get lost.
  1135. // set the active view of the new frame to newly moved view
  1136. CFrameWnd* pFrameWnd = pParentWnd->IsFrameWnd() ?
  1137. (CFrameWnd*)pParentWnd : pParentWnd->GetParentFrame();
  1138. pFrameWnd->SetActiveView(pView, FALSE);
  1139. pFrameWnd->RecalcLayout();
  1140. }
  1141. void COleServerDoc::OnFrameWindowActivate(BOOL bActivate)
  1142. {
  1143. ASSERT_VALID(this);
  1144. CFrameWnd* pFrameWnd = m_pInPlaceFrame;
  1145. ASSERT_VALID(pFrameWnd);
  1146. CWinThread* pThread = AfxGetThread();
  1147. if (bActivate)
  1148. {
  1149. // activating -- so set the main window
  1150. pThread->m_pActiveWnd = pFrameWnd;
  1151. // send activation notification messages
  1152. pFrameWnd->SendMessage(WM_ACTIVATEAPP, (WPARAM)TRUE);
  1153. pFrameWnd->SendMessage(WM_ACTIVATE, WA_ACTIVE);
  1154. }
  1155. else if (pFrameWnd == pThread->m_pActiveWnd)
  1156. {
  1157. // send deactivation notification messages
  1158. pFrameWnd->SendMessage(WM_ACTIVATEAPP, (WPARAM)FALSE);
  1159. pFrameWnd->SendMessage(WM_ACTIVATE, WA_INACTIVE);
  1160. // simulate deactivation notification messages
  1161. CView* pActiveView = pFrameWnd->GetActiveView();
  1162. if (pActiveView != NULL)
  1163. pActiveView->OnActivateView(FALSE, pActiveView, pActiveView);
  1164. // deactivating and was previously active -- reset the main window
  1165. pThread->m_pActiveWnd = NULL;
  1166. }
  1167. }
  1168. void COleServerDoc::OnDocWindowActivate(BOOL bActivate)
  1169. {
  1170. ASSERT_VALID(this);
  1171. CWinThread* pThread = AfxGetApp();
  1172. COleIPFrameWnd* pFrameWnd = m_pInPlaceFrame;
  1173. if (bActivate)
  1174. {
  1175. // attach frame windows back in the permanent map
  1176. pFrameWnd->m_pMainFrame->Attach(pFrameWnd->m_pMainFrame->Detach());
  1177. if (pFrameWnd->m_pDocFrame != NULL)
  1178. pFrameWnd->m_pDocFrame->Attach(pFrameWnd->m_pDocFrame->Detach());
  1179. // set active main window
  1180. pThread->m_pActiveWnd = pFrameWnd;
  1181. // show frame level controls
  1182. OnShowControlBars(pFrameWnd->m_pMainFrame, TRUE);
  1183. pFrameWnd->ShowOwnedWindows(TRUE);
  1184. // attempt toolbar negotiation
  1185. OnResizeBorder(NULL, pFrameWnd->m_lpFrame, TRUE);
  1186. // install the menu (also installs a hook which forwards messages from
  1187. // the menu to the inplace frame window)
  1188. pFrameWnd->m_lpFrame->SetMenu(
  1189. pFrameWnd->m_hSharedMenu, pFrameWnd->m_hOleMenu,
  1190. pFrameWnd->m_hWnd);
  1191. // set focus to the frame (it will probably set focus to the view)
  1192. // (by simulating normal application activate messages)
  1193. pFrameWnd->SendMessage(WM_ACTIVATE, WA_ACTIVE);
  1194. }
  1195. else
  1196. {
  1197. // clear active window for app if this object is active
  1198. if (pThread->m_pActiveWnd == pFrameWnd)
  1199. pThread->m_pActiveWnd = NULL;
  1200. // hide frame level controls -- this does not destroy them
  1201. pFrameWnd->ShowOwnedWindows(FALSE);
  1202. OnShowControlBars(pFrameWnd->m_pMainFrame, FALSE);
  1203. // attempt toolbar negotiation
  1204. OnResizeBorder(NULL, pFrameWnd->m_lpFrame, TRUE);
  1205. // simulate deactivation notification messages
  1206. CView* pActiveView = pFrameWnd->GetActiveView();
  1207. if (pActiveView != NULL)
  1208. pActiveView->OnActivateView(FALSE, pActiveView, pActiveView);
  1209. pFrameWnd->SendMessage(WM_ACTIVATE, WA_INACTIVE);
  1210. // set the m_hWnd members, but remove them from the maps
  1211. pFrameWnd->m_pMainFrame->m_hWnd = pFrameWnd->m_pMainFrame->Detach();
  1212. if (pFrameWnd->m_pDocFrame != NULL)
  1213. pFrameWnd->m_pDocFrame->m_hWnd = pFrameWnd->m_pDocFrame->Detach();
  1214. }
  1215. }
  1216. void COleServerDoc::OnShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow)
  1217. {
  1218. ASSERT_VALID(this);
  1219. ASSERT(pFrameWnd == m_pInPlaceFrame->m_pMainFrame ||
  1220. pFrameWnd == m_pInPlaceFrame->m_pDocFrame);
  1221. ASSERT_VALID(pFrameWnd);
  1222. // show/hide all control bars
  1223. POSITION pos = pFrameWnd->m_listControlBars.GetHeadPosition();
  1224. while (pos != NULL)
  1225. {
  1226. // show/hide the next control bar
  1227. CControlBar* pBar =
  1228. (CControlBar*)pFrameWnd->m_listControlBars.GetNext(pos);
  1229. ASSERT_VALID(pBar);
  1230. if (bShow)
  1231. {
  1232. if (pBar->m_nStateFlags & CControlBar::tempHide)
  1233. {
  1234. pBar->m_nStateFlags &= ~CControlBar::tempHide;
  1235. pFrameWnd->ShowControlBar(pBar, bShow, TRUE);
  1236. }
  1237. }
  1238. else
  1239. {
  1240. if (pBar->IsVisible() && !pBar->IsFloating())
  1241. {
  1242. pBar->m_nStateFlags |= CControlBar::tempHide;
  1243. pFrameWnd->ShowControlBar(pBar, bShow, TRUE);
  1244. }
  1245. }
  1246. }
  1247. }
  1248. void COleServerDoc::OnResizeBorder(
  1249. LPCRECT lpRectBorder, LPOLEINPLACEUIWINDOW lpUIWindow, BOOL bFrame)
  1250. {
  1251. ASSERT_VALID(this);
  1252. ASSERT(lpRectBorder == NULL ||
  1253. AfxIsValidAddress(lpRectBorder, sizeof(RECT), FALSE));
  1254. ASSERT(lpUIWindow != NULL);
  1255. // use IOleInPlaceUIWindow::GetBorder if no border given
  1256. CRect rectBorder;
  1257. if (lpRectBorder != NULL)
  1258. {
  1259. // use border space passed in
  1260. rectBorder.CopyRect(lpRectBorder);
  1261. }
  1262. else
  1263. {
  1264. // GetBorderSpace may fail (WinWord6, for example)
  1265. if (lpUIWindow->GetBorder(&rectBorder) != S_OK)
  1266. {
  1267. // in that case, always call SetBorderSpace(NULL), but
  1268. // ignore the return value.
  1269. lpUIWindow->SetBorderSpace(NULL);
  1270. return;
  1271. }
  1272. }
  1273. // get CWnd* for the OLE window
  1274. CFrameWnd* pFrameWnd = bFrame ?
  1275. m_pInPlaceFrame->m_pMainFrame : m_pInPlaceFrame->m_pDocFrame;
  1276. // if this is the active document clear temphide bits from bars
  1277. if (AfxGetThread()->m_pActiveWnd == m_pInPlaceFrame)
  1278. OnShowControlBars(pFrameWnd, TRUE);
  1279. // see how much space we need by calling reposition bars
  1280. CRect rectNeeded = rectBorder;
  1281. pFrameWnd->RepositionBars(0, 0xFFFF, 0, CWnd::reposQuery, &rectNeeded,
  1282. &rectBorder);
  1283. // request the border space from the container
  1284. CRect rectRequest(
  1285. rectNeeded.left - rectBorder.left,
  1286. rectNeeded.top - rectBorder.top,
  1287. rectBorder.right - rectNeeded.right,
  1288. rectBorder.bottom - rectNeeded.bottom);
  1289. CRect rectTemp;
  1290. rectTemp = rectRequest;
  1291. // if no border space, just call SetBorderSpace
  1292. if ((!rectRequest.IsRectNull() ||
  1293. !pFrameWnd->m_listControlBars.IsEmpty()) &&
  1294. lpUIWindow->RequestBorderSpace(&rectTemp) == S_OK)
  1295. {
  1296. // set the border space -- now this object owns it
  1297. VERIFY(lpUIWindow->SetBorderSpace(&rectRequest) == S_OK);
  1298. // move the bars into position after committing the space
  1299. pFrameWnd->RepositionBars(0, 0xFFFF, 0, CWnd::reposDefault, NULL,
  1300. &rectBorder);
  1301. // redraw all control bars
  1302. POSITION pos = pFrameWnd->m_listControlBars.GetHeadPosition();
  1303. while (pos != NULL)
  1304. {
  1305. CControlBar* pBar =
  1306. (CControlBar*)pFrameWnd->m_listControlBars.GetNext(pos);
  1307. ASSERT_VALID(pBar);
  1308. if (!pBar->IsFloating())
  1309. pBar->UpdateWindow();
  1310. }
  1311. }
  1312. else
  1313. {
  1314. // hide any toolbars (since we couldn't get border space for any)
  1315. OnShowControlBars(pFrameWnd, FALSE);
  1316. // make sure border space is cleared
  1317. CRect rect(0,0,0,0);
  1318. lpUIWindow->SetBorderSpace(&rect);
  1319. }
  1320. }
  1321. void COleServerDoc::OnDeactivate()
  1322. {
  1323. ASSERT_VALID(this);
  1324. ASSERT(m_pInPlaceFrame != NULL);
  1325. // do UI deactivate first -- this hides everything
  1326. if (m_pInPlaceFrame->m_bUIActive)
  1327. {
  1328. OnDeactivateUI(FALSE);
  1329. // some containers call OnDeactivate during OnDeactivateUI
  1330. if (m_pInPlaceFrame == NULL)
  1331. return;
  1332. }
  1333. ASSERT(m_pInPlaceFrame != NULL);
  1334. ASSERT(!m_pInPlaceFrame->m_bUIActive);
  1335. // now safe to destroy the shared menu
  1336. m_pInPlaceFrame->DestroySharedMenu();
  1337. // no longer need doc & frame window interfaces
  1338. RELEASE(m_pInPlaceFrame->m_lpFrame);
  1339. RELEASE(m_pInPlaceFrame->m_lpDocFrame);
  1340. DestroyInPlaceFrame(m_pInPlaceFrame);
  1341. m_pInPlaceFrame = NULL;
  1342. // destructor for COleIPFrameWnd or derivative should cleanup any
  1343. // toolbars etc. created during in-place activation
  1344. // last of all, call IOleClientSite::InPlaceDeactivate
  1345. ASSERT(m_lpClientSite != NULL);
  1346. LPOLEINPLACESITE lpInPlaceSite =
  1347. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  1348. if (lpInPlaceSite != NULL)
  1349. {
  1350. lpInPlaceSite->OnInPlaceDeactivate();
  1351. lpInPlaceSite->Release();
  1352. }
  1353. }
  1354. void COleServerDoc::OnDeactivateUI(BOOL bUndoable)
  1355. {
  1356. ASSERT_VALID(this);
  1357. COleIPFrameWnd* pFrameWnd = m_pInPlaceFrame;
  1358. if (pFrameWnd == NULL || !pFrameWnd->m_bUIActive)
  1359. return;
  1360. // reset active object pointers
  1361. ASSERT(pFrameWnd->m_lpFrame != NULL);
  1362. pFrameWnd->m_lpFrame->SetActiveObject(NULL, NULL);
  1363. if (pFrameWnd->m_lpDocFrame != NULL)
  1364. pFrameWnd->m_lpDocFrame->SetActiveObject(NULL, NULL);
  1365. // remove frame & document level frame controls
  1366. ASSERT(pFrameWnd->m_lpFrame != NULL);
  1367. OnShowControlBars(pFrameWnd->m_pMainFrame, FALSE);
  1368. if (pFrameWnd->m_lpDocFrame != NULL)
  1369. OnShowControlBars(pFrameWnd->m_pDocFrame, FALSE);
  1370. if (m_pDocObjectServer == NULL)
  1371. {
  1372. // hide the frame and any popups owned by the frame
  1373. pFrameWnd->ShowOwnedWindows(FALSE);
  1374. pFrameWnd->ShowWindow(SW_HIDE);
  1375. pFrameWnd->m_nShowDelay = SW_HIDE;
  1376. pFrameWnd->m_pMainFrame->m_nShowDelay = SW_HIDE;
  1377. }
  1378. // set the m_hWnd members, but remove them from the maps
  1379. pFrameWnd->m_pMainFrame->m_hWnd = pFrameWnd->m_pMainFrame->Detach();
  1380. if (pFrameWnd->m_pDocFrame != NULL)
  1381. pFrameWnd->m_pDocFrame->m_hWnd = pFrameWnd->m_pDocFrame->Detach();
  1382. // no longer UI active...
  1383. pFrameWnd->m_bUIActive = FALSE;
  1384. CWinThread* pThread = AfxGetApp();
  1385. if (pThread->m_pActiveWnd == pFrameWnd)
  1386. pThread->m_pActiveWnd = NULL;
  1387. // call IOleClientSite::OnUIDeactivate
  1388. ASSERT(m_lpClientSite != NULL);
  1389. LPOLEINPLACESITE lpInPlaceSite =
  1390. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  1391. if (lpInPlaceSite != NULL)
  1392. {
  1393. lpInPlaceSite->OnUIDeactivate(bUndoable);
  1394. lpInPlaceSite->Release();
  1395. }
  1396. }
  1397. void COleServerDoc::OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect)
  1398. {
  1399. ASSERT_VALID(this);
  1400. ASSERT(AfxIsValidAddress(lpPosRect, sizeof(RECT), FALSE));
  1401. ASSERT(AfxIsValidAddress(lpClipRect, sizeof(RECT), FALSE));
  1402. if (m_pInPlaceFrame == NULL)
  1403. return;
  1404. ASSERT_VALID(m_pInPlaceFrame);
  1405. // tell the frame to position itself such that the view is at the given
  1406. // rectangle (relative to the frame's parent)
  1407. m_pInPlaceFrame->RepositionFrame(lpPosRect, lpClipRect);
  1408. }
  1409. BOOL COleServerDoc::OnReactivateAndUndo()
  1410. {
  1411. // default implementation doesn't support undo
  1412. return FALSE;
  1413. }
  1414. /////////////////////////////////////////////////////////////////////////////
  1415. // COleServerDoc special APIs for in-place editing
  1416. void COleServerDoc::RequestPositionChange(LPCRECT lpPosRect)
  1417. {
  1418. ASSERT_VALID(this);
  1419. ASSERT(AfxIsValidAddress(lpPosRect, sizeof(RECT), FALSE));
  1420. // get IOleInPlaceSite interface
  1421. ASSERT(m_lpClientSite != NULL);
  1422. LPOLEINPLACESITE lpInPlaceSite =
  1423. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  1424. if (lpInPlaceSite != NULL)
  1425. {
  1426. // call IOleInPlaceSite::OnPosRectChange
  1427. lpInPlaceSite->OnPosRectChange(lpPosRect);
  1428. lpInPlaceSite->Release();
  1429. }
  1430. }
  1431. BOOL COleServerDoc::ScrollContainerBy(CSize sizeScroll)
  1432. {
  1433. ASSERT_VALID(this);
  1434. // get IOleInPlaceSite interface
  1435. ASSERT(m_lpClientSite != NULL);
  1436. LPOLEINPLACESITE lpInPlaceSite =
  1437. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  1438. if (lpInPlaceSite == NULL)
  1439. return FALSE;
  1440. // call IOleInPlaceSite::Scroll
  1441. BOOL bResult = lpInPlaceSite->Scroll(sizeScroll) == S_OK;
  1442. lpInPlaceSite->Release();
  1443. return bResult;
  1444. }
  1445. BOOL COleServerDoc::DeactivateAndUndo()
  1446. {
  1447. ASSERT_VALID(this);
  1448. // get IOleInPlaceSite interface
  1449. ASSERT(m_lpClientSite != NULL);
  1450. LPOLEINPLACESITE lpInPlaceSite =
  1451. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  1452. if (lpInPlaceSite == NULL)
  1453. return FALSE;
  1454. // call IOleInPlaceSite::DeactivateAndUndo
  1455. BOOL bResult = lpInPlaceSite->DeactivateAndUndo() == S_OK;
  1456. lpInPlaceSite->Release();
  1457. return bResult;
  1458. }
  1459. BOOL COleServerDoc::DiscardUndoState()
  1460. {
  1461. ASSERT_VALID(this);
  1462. // get IOleInPlaceSite interface
  1463. ASSERT(m_lpClientSite != NULL);
  1464. LPOLEINPLACESITE lpInPlaceSite =
  1465. QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
  1466. if (lpInPlaceSite == NULL)
  1467. return FALSE;
  1468. // call IOleInPlaceSite::DiscardUndoState
  1469. BOOL bResult = lpInPlaceSite->DiscardUndoState() == S_OK;
  1470. lpInPlaceSite->Release();
  1471. return bResult;
  1472. }
  1473. /////////////////////////////////////////////////////////////////////////////
  1474. // COleServerDoc OLE interface implementation
  1475. BEGIN_INTERFACE_MAP(COleServerDoc, COleLinkingDoc)
  1476. INTERFACE_PART(COleServerDoc, IID_IPersistStorage, PersistStorage)
  1477. INTERFACE_PART(COleServerDoc, IID_IOleObject, OleObject)
  1478. INTERFACE_PART(COleServerDoc, IID_IDataObject, DataObject)
  1479. INTERFACE_PART(COleServerDoc, IID_IOleWindow, OleInPlaceObject)
  1480. INTERFACE_PART(COleServerDoc, IID_IOleInPlaceObject, OleInPlaceObject)
  1481. INTERFACE_PART(COleServerDoc, IID_IOleInPlaceActiveObject, OleInPlaceActiveObject)
  1482. END_INTERFACE_MAP()
  1483. /////////////////////////////////////////////////////////////////////////////
  1484. // COleServerDoc::CPersistStorage
  1485. STDMETHODIMP_(ULONG) COleServerDoc::XPersistStorage::AddRef()
  1486. {
  1487. METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
  1488. return pThis->ExternalAddRef();
  1489. }
  1490. STDMETHODIMP_(ULONG) COleServerDoc::XPersistStorage::Release()
  1491. {
  1492. METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
  1493. return pThis->ExternalRelease();
  1494. }
  1495. STDMETHODIMP COleServerDoc::XPersistStorage::QueryInterface(
  1496. REFIID iid, LPVOID* ppvObj)
  1497. {
  1498. METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
  1499. return pThis->ExternalQueryInterface(&iid, ppvObj);
  1500. }
  1501. STDMETHODIMP COleServerDoc::XPersistStorage::GetClassID(LPCLSID lpClassID)
  1502. {
  1503. METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
  1504. LPPERSISTFILE lpPersistFile = (LPPERSISTFILE)
  1505. pThis->GetInterface(&IID_IPersistFile);
  1506. return lpPersistFile->GetClassID(lpClassID);
  1507. }
  1508. STDMETHODIMP COleServerDoc::XPersistStorage::IsDirty()
  1509. {
  1510. METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
  1511. LPPERSISTFILE lpPersistFile = (LPPERSISTFILE)
  1512. pThis->GetInterface(&IID_IPersistFile);
  1513. return lpPersistFile->IsDirty();
  1514. }
  1515. STDMETHODIMP COleServerDoc::XPersistStorage::InitNew(LPSTORAGE pStg)
  1516. {
  1517. METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
  1518. ASSERT_VALID(pThis);
  1519. SCODE sc = S_OK;
  1520. TRY
  1521. {
  1522. // delegate to member function in the document
  1523. pThis->OnNewEmbedding(pStg);
  1524. }
  1525. CATCH_ALL(e)
  1526. {
  1527. sc = COleException::Process(e);
  1528. DELETE_EXCEPTION(e);
  1529. }
  1530. END_CATCH_ALL
  1531. ASSERT_VALID(pThis);
  1532. return sc;
  1533. }
  1534. STDMETHODIMP COleServerDoc::XPersistStorage::Load(LPSTORAGE pStg)
  1535. {
  1536. METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
  1537. ASSERT_VALID(pThis);
  1538. SCODE sc = S_OK;
  1539. pThis->BeginDeferErrors();
  1540. TRY
  1541. {
  1542. // delegate to member function in the document
  1543. pThis->OnOpenEmbedding(pStg);
  1544. }
  1545. CATCH_ALL(e)
  1546. {
  1547. sc = COleException::Process(e);
  1548. DELETE_EXCEPTION(e);
  1549. }
  1550. END_CATCH_ALL
  1551. sc = pThis->EndDeferErrors(sc);
  1552. ASSERT_VALID(pThis);
  1553. return sc;
  1554. }
  1555. STDMETHODIMP COleServerDoc::XPersistStorage::Save(
  1556. LPSTORAGE pStgSave, BOOL fSameAsLoad)
  1557. {
  1558. METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
  1559. ASSERT_VALID(pThis);
  1560. // don't bother saving if destination is up-to-date
  1561. if (fSameAsLoad && !pThis->IsModified())
  1562. return S_OK;
  1563. SCODE sc = S_OK;
  1564. pThis->BeginDeferErrors();
  1565. TRY
  1566. {
  1567. // delegate through the document
  1568. ASSERT(pThis->m_bRemember);
  1569. pThis->m_bRemember = FALSE;
  1570. pThis->m_bSameAsLoad = fSameAsLoad;
  1571. pThis->OnSaveEmbedding(pStgSave);
  1572. // clear dirty flag since save to same storage successful
  1573. if (fSameAsLoad)
  1574. {
  1575. pThis->SetModifiedFlag(FALSE);
  1576. // notify clients that object has been saved
  1577. pThis->NotifySaved();
  1578. }
  1579. }
  1580. CATCH_ALL(e)
  1581. {
  1582. sc = COleException::Process(e);
  1583. DELETE_EXCEPTION(e);
  1584. }
  1585. END_CATCH_ALL
  1586. sc = pThis->EndDeferErrors(sc);
  1587. // restore default state
  1588. pThis->m_bRemember = TRUE;
  1589. ASSERT_VALID(pThis);
  1590. return sc;
  1591. }
  1592. STDMETHODIMP COleServerDoc::XPersistStorage::SaveCompleted(LPSTORAGE pStgSaved)
  1593. {
  1594. METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
  1595. ASSERT_VALID(pThis);
  1596. // call SaveCompleted on any embedded items
  1597. pThis->CommitItems(pStgSaved != NULL);
  1598. // update state to reflect new storage
  1599. if (pStgSaved != NULL)
  1600. {
  1601. // attach new storage
  1602. pStgSaved->AddRef();
  1603. RELEASE(pThis->m_lpRootStg);
  1604. pThis->m_lpRootStg = pStgSaved;
  1605. // now this document is storage based
  1606. pThis->m_strPathName.Empty();
  1607. pThis->m_bEmbedded = TRUE;
  1608. pThis->SetModifiedFlag(FALSE);
  1609. // notify clients that object has been saved
  1610. pThis->NotifySaved();
  1611. }
  1612. ASSERT_VALID(pThis);
  1613. return S_OK;
  1614. }
  1615. STDMETHODIMP COleServerDoc::XPersistStorage::HandsOffStorage()
  1616. {
  1617. METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
  1618. if (pThis->m_lpRootStg != NULL)
  1619. {
  1620. // first call HandsOffStorage for all the embedded client items
  1621. POSITION pos = pThis->GetStartPosition();
  1622. COleClientItem* pItem;
  1623. while ((pItem = pThis->GetNextClientItem(pos)) != NULL)
  1624. {
  1625. ASSERT(pItem->m_lpObject != NULL);
  1626. LPPERSISTSTORAGE lpPersistStorage =
  1627. QUERYINTERFACE(pItem->m_lpObject, IPersistStorage);
  1628. ASSERT(lpPersistStorage != NULL);
  1629. lpPersistStorage->HandsOffStorage();
  1630. lpPersistStorage->Release();
  1631. }
  1632. // for now, can't access the storage
  1633. RELEASE(pThis->m_lpRootStg);
  1634. }
  1635. ASSERT_VALID(pThis);
  1636. return S_OK;
  1637. }
  1638. /////////////////////////////////////////////////////////////////////////////
  1639. // COleServerDoc::XOleObject
  1640. STDMETHODIMP_(ULONG) COleServerDoc::XOleObject::AddRef()
  1641. {
  1642. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1643. return pThis->ExternalAddRef();
  1644. }
  1645. STDMETHODIMP_(ULONG) COleServerDoc::XOleObject::Release()
  1646. {
  1647. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1648. return pThis->ExternalRelease();
  1649. }
  1650. STDMETHODIMP COleServerDoc::XOleObject::QueryInterface(
  1651. REFIID iid, LPVOID* ppvObj)
  1652. {
  1653. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1654. return pThis->ExternalQueryInterface(&iid, ppvObj);
  1655. }
  1656. STDMETHODIMP COleServerDoc::XOleObject::SetClientSite(
  1657. LPOLECLIENTSITE pClientSite)
  1658. {
  1659. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1660. // maintain reference counts
  1661. if (pClientSite != NULL)
  1662. pClientSite->AddRef();
  1663. RELEASE(pThis->m_lpClientSite);
  1664. pThis->m_lpClientSite = pClientSite;
  1665. // do we already have doc object support enabled?
  1666. if (pThis->m_pDocObjectServer != NULL)
  1667. {
  1668. // If we currently have a document site pointer,
  1669. // release it.
  1670. pThis->m_pDocObjectServer->ReleaseDocSite();
  1671. }
  1672. if (pClientSite != NULL)
  1673. {
  1674. LPOLEDOCUMENTSITE pDocSite;
  1675. if (SUCCEEDED(pClientSite->QueryInterface(IID_IOleDocumentSite,
  1676. (LPVOID*) &pDocSite)))
  1677. {
  1678. if (pThis->m_pDocObjectServer != NULL)
  1679. pThis->m_pDocObjectServer->SetDocSite(pDocSite);
  1680. else
  1681. {
  1682. pThis->m_pDocObjectServer =
  1683. pThis->GetDocObjectServer(pDocSite);
  1684. }
  1685. }
  1686. }
  1687. return S_OK;
  1688. }
  1689. STDMETHODIMP COleServerDoc::XOleObject::GetClientSite(
  1690. LPOLECLIENTSITE* ppClientSite)
  1691. {
  1692. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1693. if (pThis->m_lpClientSite == NULL)
  1694. {
  1695. *ppClientSite = NULL;
  1696. return E_FAIL;
  1697. }
  1698. *ppClientSite = pThis->m_lpClientSite;
  1699. pThis->m_lpClientSite->AddRef();
  1700. return S_OK;
  1701. }
  1702. STDMETHODIMP COleServerDoc::XOleObject::SetHostNames(
  1703. LPCOLESTR lpszContainerApp, LPCOLESTR lpszContainerObj)
  1704. {
  1705. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1706. ASSERT_VALID(pThis);
  1707. USES_CONVERSION;
  1708. TRY
  1709. {
  1710. pThis->OnSetHostNames(OLE2CT(lpszContainerApp),
  1711. OLE2CT(lpszContainerObj));
  1712. }
  1713. END_TRY
  1714. return S_OK;
  1715. }
  1716. STDMETHODIMP COleServerDoc::XOleObject::Close(DWORD dwSaveOption)
  1717. {
  1718. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1719. ASSERT_VALID(pThis);
  1720. pThis->InternalAddRef(); // protect this object
  1721. SCODE sc = S_OK;
  1722. TRY
  1723. {
  1724. // delegate through document for most of the work
  1725. pThis->OnClose((OLECLOSE)dwSaveOption);
  1726. }
  1727. CATCH_ALL(e)
  1728. {
  1729. sc = COleException::Process(e);
  1730. DELETE_EXCEPTION(e);
  1731. }
  1732. END_CATCH_ALL
  1733. pThis->InternalRelease(); // may 'delete this'
  1734. return sc;
  1735. }
  1736. STDMETHODIMP COleServerDoc::XOleObject::SetMoniker(
  1737. DWORD /*dwWhichMoniker*/, LPMONIKER /*pmk*/)
  1738. {
  1739. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1740. if (pThis->m_lpClientSite == NULL)
  1741. return E_FAIL;
  1742. // get current full moniker from client-site
  1743. LPMONIKER lpMoniker = NULL;
  1744. if (pThis->m_lpClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
  1745. OLEWHICHMK_OBJFULL, &lpMoniker) != S_OK)
  1746. {
  1747. // just to make sure -- always set moniker to NULL on failure
  1748. lpMoniker = NULL;
  1749. }
  1750. // update all embedded items with new moniker
  1751. POSITION pos = pThis->GetStartPosition();
  1752. COleClientItem* pItem;
  1753. while ((pItem = pThis->GetNextClientItem(pos)) != NULL)
  1754. {
  1755. if (pItem->m_bMoniker)
  1756. pItem->m_lpObject->SetMoniker(OLEWHICHMK_CONTAINER, lpMoniker);
  1757. }
  1758. // send Rename advises
  1759. pThis->NotifyAllItems(OLE_RENAMED, (DWORD)lpMoniker);
  1760. RELEASE(lpMoniker);
  1761. return S_OK;
  1762. }
  1763. STDMETHODIMP COleServerDoc::XOleObject::GetMoniker(
  1764. DWORD dwAssign, DWORD /*dwWhichMoniker*/, LPMONIKER* ppMoniker)
  1765. {
  1766. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1767. *ppMoniker = pThis->GetMoniker((OLEGETMONIKER)dwAssign);
  1768. return *ppMoniker == NULL ? E_FAIL : S_OK;
  1769. }
  1770. STDMETHODIMP COleServerDoc::XOleObject::InitFromData(
  1771. LPDATAOBJECT pDataObject, BOOL fCreation, DWORD /*dwReserved*/)
  1772. {
  1773. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1774. ASSERT_VALID(pThis);
  1775. COleServerItem* pItem;
  1776. SCODE sc;
  1777. TRY
  1778. {
  1779. // delegate through item
  1780. pItem = pThis->GetEmbeddedItem();
  1781. ASSERT_VALID(pItem);
  1782. ASSERT_KINDOF(COleServerItem, pItem);
  1783. COleDataObject dataObject;
  1784. dataObject.Attach(pDataObject, FALSE);
  1785. sc = pItem->OnInitFromData(&dataObject, fCreation) ? S_OK : S_FALSE;
  1786. }
  1787. CATCH_ALL(e)
  1788. {
  1789. sc = COleException::Process(e);
  1790. DELETE_EXCEPTION(e);
  1791. }
  1792. END_CATCH_ALL
  1793. return sc;
  1794. }
  1795. STDMETHODIMP COleServerDoc::XOleObject::GetClipboardData(
  1796. DWORD /*dwReserved*/, LPDATAOBJECT* ppDataObject)
  1797. {
  1798. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1799. ASSERT_VALID(pThis);
  1800. *ppDataObject = NULL;
  1801. COleServerItem* pItem;
  1802. SCODE sc = S_OK;
  1803. TRY
  1804. {
  1805. // delegate through item
  1806. pItem = pThis->GetEmbeddedItem();
  1807. ASSERT_VALID(pItem);
  1808. ASSERT_KINDOF(COleServerItem, pItem);
  1809. COleDataSource* pDataSource =
  1810. pItem->OnGetClipboardData(TRUE, NULL, NULL);
  1811. ASSERT(pDataSource != NULL);
  1812. *ppDataObject =
  1813. (LPDATAOBJECT)pDataSource->GetInterface(&IID_IDataObject);
  1814. ASSERT(*ppDataObject != NULL);
  1815. }
  1816. CATCH_ALL(e)
  1817. {
  1818. sc = COleException::Process(e);
  1819. DELETE_EXCEPTION(e);
  1820. }
  1821. END_CATCH_ALL
  1822. return sc;
  1823. }
  1824. STDMETHODIMP COleServerDoc::XOleObject::DoVerb(
  1825. LONG iVerb, LPMSG /*lpmsg*/, LPOLECLIENTSITE /*pActiveSite*/, LONG /*lindex*/,
  1826. HWND /*hwndParent*/, LPCRECT /*lpPosRect*/)
  1827. {
  1828. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1829. ASSERT_VALID(pThis);
  1830. pThis->InternalAddRef(); // protect this object
  1831. COleServerItem* pItem;
  1832. SCODE sc = S_OK;
  1833. TRY
  1834. {
  1835. // delegate through item
  1836. pItem = pThis->GetEmbeddedItem();
  1837. ASSERT_VALID(pItem);
  1838. ASSERT_KINDOF(COleServerItem, pItem);
  1839. pItem->OnDoVerb(iVerb);
  1840. }
  1841. CATCH_ALL(e)
  1842. {
  1843. sc = COleException::Process(e);
  1844. DELETE_EXCEPTION(e);
  1845. }
  1846. END_CATCH_ALL
  1847. pThis->InternalRelease(); // may 'delete this'
  1848. return sc;
  1849. }
  1850. STDMETHODIMP COleServerDoc::XOleObject::EnumVerbs(
  1851. IEnumOLEVERB** ppenumOleVerb)
  1852. {
  1853. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1854. *ppenumOleVerb = NULL;
  1855. LPOLEOBJECT lpObject = (LPOLEOBJECT)pThis->GetInterface(&IID_IOleObject);
  1856. ASSERT(lpObject != NULL);
  1857. CLSID clsid;
  1858. lpObject->GetUserClassID(&clsid);
  1859. return OleRegEnumVerbs(clsid, ppenumOleVerb);
  1860. }
  1861. STDMETHODIMP COleServerDoc::XOleObject::Update()
  1862. {
  1863. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1864. ASSERT_VALID(pThis);
  1865. COleServerItem* pItem;
  1866. SCODE sc = S_OK;
  1867. TRY
  1868. {
  1869. // delegate through item
  1870. pItem = pThis->GetEmbeddedItem();
  1871. ASSERT_VALID(pItem);
  1872. ASSERT_KINDOF(COleServerItem, pItem);
  1873. pItem->OnUpdateItems();
  1874. }
  1875. CATCH_ALL(e)
  1876. {
  1877. sc = COleException::Process(e);
  1878. DELETE_EXCEPTION(e);
  1879. }
  1880. END_CATCH_ALL
  1881. return sc;
  1882. }
  1883. STDMETHODIMP COleServerDoc::XOleObject::IsUpToDate()
  1884. {
  1885. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1886. ASSERT_VALID(pThis);
  1887. COleServerItem* pItem;
  1888. SCODE sc;
  1889. TRY
  1890. {
  1891. // delegate through item
  1892. pItem = pThis->GetEmbeddedItem();
  1893. ASSERT_VALID(pItem);
  1894. ASSERT_KINDOF(COleServerItem, pItem);
  1895. sc = pItem->OnQueryUpdateItems() ? S_FALSE : S_OK;
  1896. }
  1897. CATCH_ALL(e)
  1898. {
  1899. sc = COleException::Process(e);
  1900. DELETE_EXCEPTION(e);
  1901. }
  1902. END_CATCH_ALL
  1903. return sc;
  1904. }
  1905. STDMETHODIMP COleServerDoc::XOleObject::GetUserClassID(CLSID* lpClassID)
  1906. {
  1907. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1908. LPPERSISTFILE lpPersistFile = (LPPERSISTFILE)
  1909. pThis->GetInterface(&IID_IPersistFile);
  1910. return lpPersistFile->GetClassID(lpClassID);
  1911. }
  1912. STDMETHODIMP COleServerDoc::XOleObject::GetUserType(
  1913. DWORD dwFormOfType, LPOLESTR* ppszUserType)
  1914. {
  1915. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  1916. *ppszUserType = NULL;
  1917. LPOLEOBJECT lpObject = (LPOLEOBJECT)pThis->GetInterface(&IID_IOleObject);
  1918. ASSERT(lpObject != NULL);
  1919. CLSID clsid;
  1920. lpObject->GetUserClassID(&clsid);
  1921. return OleRegGetUserType(clsid, dwFormOfType, ppszUserType);
  1922. }
  1923. STDMETHODIMP COleServerDoc::XOleObject::SetExtent(
  1924. DWORD dwDrawAspect, LPSIZEL lpsizel)
  1925. {
  1926. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1927. ASSERT_VALID(pThis);
  1928. COleServerItem* pItem;
  1929. SCODE sc = E_FAIL;
  1930. TRY
  1931. {
  1932. // convert rectangle to a CSize and call item OnSetExtent
  1933. pItem = pThis->GetEmbeddedItem();
  1934. ASSERT_VALID(pItem);
  1935. ASSERT_KINDOF(COleServerItem, pItem);
  1936. CSize size((int)lpsizel->cx, (int)lpsizel->cy);
  1937. if (pItem->OnSetExtent((DVASPECT)dwDrawAspect, size))
  1938. sc = S_OK;
  1939. }
  1940. CATCH_ALL(e)
  1941. {
  1942. sc = COleException::Process(e);
  1943. DELETE_EXCEPTION(e);
  1944. }
  1945. END_CATCH_ALL
  1946. return sc;
  1947. }
  1948. STDMETHODIMP COleServerDoc::XOleObject::GetExtent(
  1949. DWORD dwDrawAspect, LPSIZEL lpsizel)
  1950. {
  1951. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1952. ASSERT_VALID(pThis);
  1953. COleServerItem* pItem;
  1954. SCODE sc = E_INVALIDARG;
  1955. TRY
  1956. {
  1957. pItem = pThis->GetEmbeddedItem();
  1958. ASSERT_VALID(pItem);
  1959. ASSERT_KINDOF(COleServerItem, pItem);
  1960. // call to get regular windows CSize
  1961. CSize size;
  1962. if (pItem->OnGetExtent((DVASPECT)dwDrawAspect, size))
  1963. {
  1964. if (size.cy < 0)
  1965. size.cy = -size.cy; // extents are always positive
  1966. lpsizel->cx = size.cx;
  1967. lpsizel->cy = size.cy;
  1968. sc = S_OK;
  1969. }
  1970. }
  1971. CATCH_ALL(e)
  1972. {
  1973. sc = COleException::Process(e);
  1974. DELETE_EXCEPTION(e);
  1975. }
  1976. END_CATCH_ALL
  1977. return sc;
  1978. }
  1979. STDMETHODIMP COleServerDoc::XOleObject::Advise(
  1980. IAdviseSink* pAdvSink, DWORD* pdwConnection)
  1981. {
  1982. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  1983. COleServerItem* pItem = NULL;
  1984. SCODE sc = E_OUTOFMEMORY;
  1985. TRY
  1986. {
  1987. pItem = pThis->GetEmbeddedItem();
  1988. ASSERT_VALID(pItem);
  1989. ASSERT_KINDOF(COleServerItem, pItem);
  1990. sc = S_OK;
  1991. }
  1992. END_TRY
  1993. if (sc != S_OK)
  1994. return sc;
  1995. return pItem->GetOleObject()->Advise(pAdvSink, pdwConnection);
  1996. }
  1997. STDMETHODIMP COleServerDoc::XOleObject::Unadvise(DWORD dwConnection)
  1998. {
  1999. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  2000. COleServerItem* pItem = NULL;
  2001. SCODE sc = E_OUTOFMEMORY;
  2002. TRY
  2003. {
  2004. pItem = pThis->GetEmbeddedItem();
  2005. ASSERT_VALID(pItem);
  2006. ASSERT_KINDOF(COleServerItem, pItem);
  2007. sc = S_OK;
  2008. }
  2009. END_TRY
  2010. if (sc != S_OK)
  2011. return sc;
  2012. return pItem->GetOleObject()->Unadvise(dwConnection);
  2013. }
  2014. STDMETHODIMP COleServerDoc::XOleObject::EnumAdvise(
  2015. LPENUMSTATDATA* ppenumAdvise)
  2016. {
  2017. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  2018. COleServerItem* pItem = NULL;
  2019. SCODE sc = E_OUTOFMEMORY;
  2020. TRY
  2021. {
  2022. pItem = pThis->GetEmbeddedItem();
  2023. ASSERT_VALID(pItem);
  2024. ASSERT_KINDOF(COleServerItem, pItem);
  2025. sc = S_OK;
  2026. }
  2027. END_TRY
  2028. if (sc != S_OK)
  2029. return sc;
  2030. return pItem->GetOleObject()->EnumAdvise(ppenumAdvise);
  2031. }
  2032. STDMETHODIMP COleServerDoc::XOleObject::GetMiscStatus(
  2033. DWORD dwAspect, DWORD* pdwStatus)
  2034. {
  2035. METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
  2036. *pdwStatus = 0;
  2037. LPOLEOBJECT lpObject = (LPOLEOBJECT)pThis->GetInterface(&IID_IOleObject);
  2038. ASSERT(lpObject != NULL);
  2039. CLSID clsid;
  2040. lpObject->GetUserClassID(&clsid);
  2041. return OleRegGetMiscStatus(clsid, dwAspect, pdwStatus);
  2042. }
  2043. STDMETHODIMP COleServerDoc::XOleObject::SetColorScheme(LPLOGPALETTE lpLogpal)
  2044. {
  2045. METHOD_PROLOGUE_EX(COleServerDoc, OleObject)
  2046. ASSERT_VALID(pThis);
  2047. COleServerItem* pItem;
  2048. SCODE sc = E_NOTIMPL;
  2049. TRY
  2050. {
  2051. pItem = pThis->GetEmbeddedItem();
  2052. ASSERT_VALID(pItem);
  2053. ASSERT_KINDOF(COleServerItem, pItem);
  2054. // delegate to embedded item
  2055. if (pItem->OnSetColorScheme(lpLogpal))
  2056. sc = S_OK;
  2057. }
  2058. END_TRY
  2059. return sc;
  2060. }
  2061. /////////////////////////////////////////////////////////////////////////////
  2062. // COleServerDoc::XDataObject
  2063. STDMETHODIMP_(ULONG) COleServerDoc::XDataObject::AddRef()
  2064. {
  2065. METHOD_PROLOGUE_EX_(COleServerDoc, DataObject)
  2066. return pThis->ExternalAddRef();
  2067. }
  2068. STDMETHODIMP_(ULONG) COleServerDoc::XDataObject::Release()
  2069. {
  2070. METHOD_PROLOGUE_EX_(COleServerDoc, DataObject)
  2071. return pThis->ExternalRelease();
  2072. }
  2073. STDMETHODIMP COleServerDoc::XDataObject::QueryInterface(
  2074. REFIID iid, LPVOID* ppvObj)
  2075. {
  2076. METHOD_PROLOGUE_EX_(COleServerDoc, DataObject)
  2077. return pThis->ExternalQueryInterface(&iid, ppvObj);
  2078. }
  2079. STDMETHODIMP COleServerDoc::XDataObject::GetData(
  2080. LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium)
  2081. {
  2082. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2083. COleServerItem* pItem = NULL;
  2084. SCODE sc = E_OUTOFMEMORY;
  2085. TRY
  2086. {
  2087. pItem = pThis->GetEmbeddedItem();
  2088. ASSERT_VALID(pItem);
  2089. ASSERT_KINDOF(COleServerItem, pItem);
  2090. sc = S_OK;
  2091. }
  2092. END_TRY
  2093. if (sc != S_OK)
  2094. return sc;
  2095. return pItem->GetDataObject()->GetData(lpFormatEtc, lpStgMedium);
  2096. }
  2097. STDMETHODIMP COleServerDoc::XDataObject::GetDataHere(
  2098. LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium)
  2099. {
  2100. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2101. COleServerItem* pItem = NULL;
  2102. SCODE sc = E_OUTOFMEMORY;
  2103. TRY
  2104. {
  2105. pItem = pThis->GetEmbeddedItem();
  2106. ASSERT_VALID(pItem);
  2107. ASSERT_KINDOF(COleServerItem, pItem);
  2108. sc = S_OK;
  2109. }
  2110. END_TRY
  2111. if (sc != S_OK)
  2112. return sc;
  2113. return pItem->GetDataObject()->GetDataHere(lpFormatEtc, lpStgMedium);
  2114. }
  2115. STDMETHODIMP COleServerDoc::XDataObject::QueryGetData(
  2116. LPFORMATETC lpFormatEtc)
  2117. {
  2118. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2119. COleServerItem* pItem = NULL;
  2120. SCODE sc = E_OUTOFMEMORY;
  2121. TRY
  2122. {
  2123. pItem = pThis->GetEmbeddedItem();
  2124. ASSERT_VALID(pItem);
  2125. ASSERT_KINDOF(COleServerItem, pItem);
  2126. sc = S_OK;
  2127. }
  2128. END_TRY
  2129. if (sc != S_OK)
  2130. return sc;
  2131. return pItem->GetDataObject()->QueryGetData(lpFormatEtc);
  2132. }
  2133. STDMETHODIMP COleServerDoc::XDataObject::GetCanonicalFormatEtc(
  2134. LPFORMATETC /*lpFormatEtcIn*/, LPFORMATETC /*lpFormatEtcOut*/)
  2135. {
  2136. // because we support the target-device (ptd) for server metafile format,
  2137. // all members of the FORMATETC are significant.
  2138. return DATA_S_SAMEFORMATETC;
  2139. }
  2140. STDMETHODIMP COleServerDoc::XDataObject::SetData(
  2141. LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium, BOOL bRelease)
  2142. {
  2143. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2144. COleServerItem* pItem = NULL;
  2145. SCODE sc = E_OUTOFMEMORY;
  2146. TRY
  2147. {
  2148. pItem = pThis->GetEmbeddedItem();
  2149. ASSERT_VALID(pItem);
  2150. ASSERT_KINDOF(COleServerItem, pItem);
  2151. sc = S_OK;
  2152. }
  2153. END_TRY
  2154. if (sc != S_OK)
  2155. return sc;
  2156. return pItem->GetDataObject()->SetData(lpFormatEtc, lpStgMedium, bRelease);
  2157. }
  2158. STDMETHODIMP COleServerDoc::XDataObject::EnumFormatEtc(
  2159. DWORD dwDirection, LPENUMFORMATETC* ppenumFormatEtc)
  2160. {
  2161. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2162. COleServerItem* pItem = NULL;
  2163. SCODE sc = E_OUTOFMEMORY;
  2164. TRY
  2165. {
  2166. pItem = pThis->GetEmbeddedItem();
  2167. ASSERT_VALID(pItem);
  2168. ASSERT_KINDOF(COleServerItem, pItem);
  2169. sc = S_OK;
  2170. }
  2171. END_TRY
  2172. if (sc != S_OK)
  2173. return sc;
  2174. return pItem->GetDataObject()->EnumFormatEtc(dwDirection, ppenumFormatEtc);
  2175. }
  2176. STDMETHODIMP COleServerDoc::XDataObject::DAdvise(
  2177. FORMATETC* pFormatetc, DWORD advf,
  2178. LPADVISESINK pAdvSink, DWORD* pdwConnection)
  2179. {
  2180. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2181. COleServerItem* pItem = NULL;
  2182. SCODE sc = E_OUTOFMEMORY;
  2183. TRY
  2184. {
  2185. pItem = pThis->GetEmbeddedItem();
  2186. ASSERT_VALID(pItem);
  2187. ASSERT_KINDOF(COleServerItem, pItem);
  2188. sc = S_OK;
  2189. }
  2190. END_TRY
  2191. if (sc != S_OK)
  2192. return sc;
  2193. return pItem->GetDataObject()->DAdvise(pFormatetc, advf, pAdvSink,
  2194. pdwConnection);
  2195. }
  2196. STDMETHODIMP COleServerDoc::XDataObject::DUnadvise(DWORD dwConnection)
  2197. {
  2198. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2199. COleServerItem* pItem = NULL;
  2200. SCODE sc = E_OUTOFMEMORY;
  2201. TRY
  2202. {
  2203. pItem = pThis->GetEmbeddedItem();
  2204. ASSERT_VALID(pItem);
  2205. ASSERT_KINDOF(COleServerItem, pItem);
  2206. sc = S_OK;
  2207. }
  2208. END_TRY
  2209. if (sc != S_OK)
  2210. return sc;
  2211. return pItem->GetDataObject()->DUnadvise(dwConnection);
  2212. }
  2213. STDMETHODIMP COleServerDoc::XDataObject::EnumDAdvise(
  2214. LPENUMSTATDATA* ppenumAdvise)
  2215. {
  2216. METHOD_PROLOGUE_EX(COleServerDoc, DataObject)
  2217. COleServerItem* pItem = NULL;
  2218. SCODE sc = E_OUTOFMEMORY;
  2219. TRY
  2220. {
  2221. pItem = pThis->GetEmbeddedItem();
  2222. ASSERT_VALID(pItem);
  2223. ASSERT_KINDOF(COleServerItem, pItem);
  2224. sc = S_OK;
  2225. }
  2226. END_TRY
  2227. if (sc != S_OK)
  2228. return sc;
  2229. return pItem->GetDataObject()->EnumDAdvise(ppenumAdvise);
  2230. }
  2231. /////////////////////////////////////////////////////////////////////////////
  2232. // COleServerDoc::COleInPlaceObject
  2233. STDMETHODIMP_(ULONG) COleServerDoc::XOleInPlaceObject::AddRef()
  2234. {
  2235. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceObject)
  2236. return pThis->ExternalAddRef();
  2237. }
  2238. STDMETHODIMP_(ULONG) COleServerDoc::XOleInPlaceObject::Release()
  2239. {
  2240. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceObject)
  2241. return pThis->ExternalRelease();
  2242. }
  2243. STDMETHODIMP COleServerDoc::XOleInPlaceObject::QueryInterface(
  2244. REFIID iid, LPVOID* ppvObj)
  2245. {
  2246. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceObject)
  2247. return pThis->ExternalQueryInterface(&iid, ppvObj);
  2248. }
  2249. STDMETHODIMP COleServerDoc::XOleInPlaceObject::GetWindow(HWND* lphwnd)
  2250. {
  2251. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceObject)
  2252. LPOLEINPLACEACTIVEOBJECT lpActiveObject = (LPOLEINPLACEACTIVEOBJECT)
  2253. pThis->GetInterface(&IID_IOleInPlaceActiveObject);
  2254. return lpActiveObject->GetWindow(lphwnd);
  2255. }
  2256. STDMETHODIMP COleServerDoc::XOleInPlaceObject::ContextSensitiveHelp(
  2257. BOOL fEnterMode)
  2258. {
  2259. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceObject)
  2260. LPOLEINPLACEACTIVEOBJECT lpActiveObject = (LPOLEINPLACEACTIVEOBJECT)
  2261. pThis->GetInterface(&IID_IOleInPlaceActiveObject);
  2262. return lpActiveObject->ContextSensitiveHelp(fEnterMode);
  2263. }
  2264. STDMETHODIMP COleServerDoc::XOleInPlaceObject::InPlaceDeactivate()
  2265. {
  2266. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceObject)
  2267. ASSERT_VALID(pThis);
  2268. pThis->InternalAddRef(); // protect this object
  2269. SCODE sc = E_UNEXPECTED;
  2270. TRY
  2271. {
  2272. // only call deactivate if necessary
  2273. if (pThis->m_pInPlaceFrame != NULL)
  2274. pThis->OnDeactivate();
  2275. // should be completely inactive
  2276. ASSERT(pThis->m_pInPlaceFrame == NULL);
  2277. sc = S_OK;
  2278. }
  2279. END_TRY
  2280. pThis->InternalRelease(); // may 'delete this'
  2281. return sc;
  2282. }
  2283. STDMETHODIMP COleServerDoc::XOleInPlaceObject::UIDeactivate()
  2284. {
  2285. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceObject)
  2286. ASSERT_VALID(pThis);
  2287. pThis->InternalAddRef(); // protect this object
  2288. SCODE sc = E_UNEXPECTED;
  2289. TRY
  2290. {
  2291. // only call OnUIDeactivate if necessary
  2292. if (pThis->m_pInPlaceFrame != NULL &&
  2293. pThis->m_pInPlaceFrame->m_bUIActive)
  2294. {
  2295. pThis->OnDeactivateUI(FALSE); // default to not undoable
  2296. }
  2297. // should not be ui active
  2298. ASSERT(pThis->m_pInPlaceFrame == NULL ||
  2299. !pThis->m_pInPlaceFrame->m_bUIActive);
  2300. sc = S_OK;
  2301. }
  2302. END_TRY
  2303. pThis->InternalRelease(); // may 'delete this'
  2304. return sc;
  2305. }
  2306. STDMETHODIMP COleServerDoc::XOleInPlaceObject::SetObjectRects(
  2307. LPCRECT lpPosRect, LPCRECT lpClipRect)
  2308. {
  2309. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceObject)
  2310. ASSERT_VALID(pThis);
  2311. SCODE sc = E_UNEXPECTED;
  2312. TRY
  2313. {
  2314. pThis->OnSetItemRects(lpPosRect, lpClipRect);
  2315. sc = S_OK;
  2316. }
  2317. END_TRY
  2318. return sc;
  2319. }
  2320. STDMETHODIMP COleServerDoc::XOleInPlaceObject::ReactivateAndUndo()
  2321. {
  2322. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceObject)
  2323. ASSERT_VALID(pThis);
  2324. SCODE sc = E_UNEXPECTED;
  2325. TRY
  2326. {
  2327. sc = pThis->OnReactivateAndUndo() ? S_OK : INPLACE_E_NOTUNDOABLE;
  2328. }
  2329. END_TRY
  2330. return sc;
  2331. }
  2332. /////////////////////////////////////////////////////////////////////////////
  2333. // COleServerDoc::XOleInPlaceActiveObject
  2334. STDMETHODIMP_(ULONG) COleServerDoc::XOleInPlaceActiveObject::AddRef()
  2335. {
  2336. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceActiveObject)
  2337. return pThis->ExternalAddRef();
  2338. }
  2339. STDMETHODIMP_(ULONG) COleServerDoc::XOleInPlaceActiveObject::Release()
  2340. {
  2341. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceActiveObject)
  2342. return pThis->ExternalRelease();
  2343. }
  2344. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::QueryInterface(
  2345. REFIID iid, LPVOID* ppvObj)
  2346. {
  2347. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceActiveObject)
  2348. return pThis->ExternalQueryInterface(&iid, ppvObj);
  2349. }
  2350. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::GetWindow(
  2351. HWND* lphwnd)
  2352. {
  2353. METHOD_PROLOGUE_EX_(COleServerDoc, OleInPlaceActiveObject)
  2354. *lphwnd = pThis->m_pInPlaceFrame->GetSafeHwnd();
  2355. return *lphwnd != NULL ? S_OK : E_FAIL;
  2356. }
  2357. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::ContextSensitiveHelp(
  2358. BOOL fEnterMode)
  2359. {
  2360. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceActiveObject)
  2361. ASSERT_VALID(pThis);
  2362. if (fEnterMode)
  2363. {
  2364. if (!pThis->m_pInPlaceFrame->m_bHelpMode)
  2365. {
  2366. // check if help mode probable
  2367. if (!pThis->m_pInPlaceFrame->CanEnterHelpMode())
  2368. return E_UNEXPECTED;
  2369. // attempt to enter context help
  2370. if (!pThis->m_pInPlaceFrame->PostMessage(WM_COMMAND, ID_CONTEXT_HELP))
  2371. return E_UNEXPECTED;
  2372. }
  2373. }
  2374. else
  2375. {
  2376. // just exit help mode
  2377. pThis->m_pInPlaceFrame->ExitHelpMode();
  2378. }
  2379. return S_OK;
  2380. }
  2381. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::TranslateAccelerator(
  2382. LPMSG lpmsg)
  2383. {
  2384. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceActiveObject)
  2385. ASSERT_VALID(pThis);
  2386. pThis->InternalAddRef(); // protect this object
  2387. SCODE sc = E_UNEXPECTED;
  2388. TRY
  2389. {
  2390. // get frame window for this document
  2391. CFrameWnd* pFrameWnd = pThis->m_pInPlaceFrame;
  2392. ASSERT_VALID(pFrameWnd);
  2393. // attempt translate accelerator
  2394. MSG msg = *lpmsg;
  2395. sc = pFrameWnd->PreTranslateMessage(&msg) ? S_OK : S_FALSE;
  2396. *lpmsg = msg;
  2397. }
  2398. END_TRY
  2399. pThis->InternalRelease(); // may 'delete this'
  2400. return sc;
  2401. }
  2402. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::OnFrameWindowActivate(
  2403. BOOL fActivate)
  2404. {
  2405. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceActiveObject)
  2406. ASSERT_VALID(pThis);
  2407. SCODE sc = E_UNEXPECTED;
  2408. TRY
  2409. {
  2410. pThis->OnFrameWindowActivate(fActivate);
  2411. sc = S_OK;
  2412. }
  2413. END_TRY
  2414. return sc;
  2415. }
  2416. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::OnDocWindowActivate(
  2417. BOOL fActivate)
  2418. {
  2419. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceActiveObject)
  2420. ASSERT_VALID(pThis);
  2421. SCODE sc = E_UNEXPECTED;
  2422. TRY
  2423. {
  2424. pThis->OnDocWindowActivate(fActivate);
  2425. sc = S_OK;
  2426. }
  2427. END_TRY
  2428. return sc;
  2429. }
  2430. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::ResizeBorder(
  2431. LPCRECT lprectBorder, LPOLEINPLACEUIWINDOW lpUIWindow, BOOL fFrameWindow)
  2432. {
  2433. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceActiveObject)
  2434. ASSERT_VALID(pThis);
  2435. SCODE sc = E_UNEXPECTED;
  2436. TRY
  2437. {
  2438. pThis->OnResizeBorder(lprectBorder, lpUIWindow, fFrameWindow);
  2439. sc = S_OK;
  2440. }
  2441. END_TRY
  2442. return sc;
  2443. }
  2444. STDMETHODIMP COleServerDoc::XOleInPlaceActiveObject::EnableModeless(
  2445. BOOL fEnable)
  2446. {
  2447. METHOD_PROLOGUE_EX(COleServerDoc, OleInPlaceActiveObject)
  2448. ASSERT_VALID(pThis);
  2449. SCODE sc = E_UNEXPECTED;
  2450. TRY
  2451. {
  2452. if (!fEnable)
  2453. {
  2454. // start modal state if not in modal state
  2455. if (!pThis->m_pInPlaceFrame->InModalState())
  2456. {
  2457. CWnd* pTemp = pThis->m_pInPlaceFrame->GetTopLevelParent();
  2458. BOOL bEnabled = pTemp->IsWindowEnabled();
  2459. pThis->m_pInPlaceFrame->BeginModalState();
  2460. pTemp->EnableWindow(bEnabled);
  2461. }
  2462. }
  2463. else
  2464. {
  2465. // end modal state if in modal state
  2466. if (pThis->m_pInPlaceFrame->InModalState())
  2467. pThis->m_pInPlaceFrame->EndModalState();
  2468. }
  2469. sc = S_OK;
  2470. }
  2471. END_TRY
  2472. return sc;
  2473. }
  2474. //////////////////////////////////////////////////////////////////////////////
  2475. // Diagnostics
  2476. #ifdef _DEBUG
  2477. void COleServerDoc::AssertValid() const
  2478. {
  2479. COleLinkingDoc::AssertValid();
  2480. if (m_pInPlaceFrame != NULL)
  2481. m_pInPlaceFrame->AssertValid();
  2482. if (m_pOrigParent != NULL)
  2483. m_pOrigParent->AssertValid();
  2484. }
  2485. void COleServerDoc::Dump(CDumpContext& dc) const
  2486. {
  2487. COleLinkingDoc::Dump(dc);
  2488. if (dc.GetDepth() != 0)
  2489. {
  2490. if (m_pInPlaceFrame != NULL)
  2491. dc << "\nwith in-place frame: " << m_pInPlaceFrame;
  2492. else
  2493. dc << "\nwith no in-place frame\n";
  2494. if (m_pOrigParent != NULL)
  2495. dc << "\nwith original parent: " << m_pOrigParent;
  2496. else
  2497. dc << "with no original parent\n";
  2498. }
  2499. dc << "m_lpClientSite = " << m_lpClientSite;
  2500. dc << "\nm_strHostObj = " << m_strHostObj;
  2501. dc << "\nm_bCntrVisible = " << m_bCntrVisible;
  2502. dc << "\nm_dwOrigStyle = " << m_dwOrigStyle;
  2503. dc << "\n";
  2504. }
  2505. #endif //_DEBUG
  2506. //////////////////////////////////////////////////////////////////////////////
  2507. // Inline function declarations expanded out-of-line
  2508. #ifndef _AFX_ENABLE_INLINES
  2509. // expand inlines for OLE server APIs
  2510. static char _szAfxOleInl[] = "afxole.inl";
  2511. #undef THIS_FILE
  2512. #define THIS_FILE _szAfxOleInl
  2513. #define _AFXOLESVR_INLINE
  2514. #include "afxole.inl"
  2515. #endif //!_AFX_ENABLE_INLINES
  2516. #ifdef AFX_INIT_SEG
  2517. #pragma code_seg(AFX_INIT_SEG)
  2518. #endif
  2519. IMPLEMENT_DYNAMIC(COleServerDoc, COleLinkingDoc)
  2520. /////////////////////////////////////////////////////////////////////////////