OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
oclink.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectComponents
3// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of TOcLinkView Class
7//----------------------------------------------------------------------------
8#include <ocf/pch.h>
9
10#include <ocf/oclink.h>
11#include <ocf/ocapp.h>
12#include <ocf/ocremvie.h>
13
14namespace ocf {
15
16using namespace owl;
17
18//
19//
20//
21TOcLinkView::TOcLinkView(TOcView* ocView, TRegList* regList, IUnknown* outer)
22:
23 BSiteI(0), OcView(ocView),
24 Origin(0,0),
25 Extent(0,0)
26{
27 PRECONDITION(OcView);
28 SetOuter(outer);
29 AddRef(); // TUnknown defaults to 0, we need 1
30
31 // Create a site for this remote view
32 //
33 if (SUCCEEDED(OcView->OcApp.BOleComponentCreate(&BSite, (IUnknown*)(IBPart*)this,
34 OcView->OcApp.IsOptionSet(amExeModule)? cidBOleSite : cidBOleInProcSite))) {
35
36 if (SUCCEEDED(BSite->QueryInterface(IID_IBSite, (LPVOID *)&BSiteI)))
37 Release();
38
39 // Connect the part and the site
40 //
41 if (BSiteI) {
42 const _TCHAR* progid = regList->Lookup(OcView->OcApp.IsOptionSet(amDebug) ?
43 "debugprogid" : "progid");
44 BSiteI->Init(this, this, OleStr(progid), true);
45 }
46
47 if (SUCCEEDED(BSite->QueryInterface(IID_IBApplication, (LPVOID *)&BAppI)))
48 BAppI->Release(); // avoid deadlock
49 }
50}
51
52//
53//
54//
55TOcLinkView::~TOcLinkView()
56{
57 // Detach the link view
58 //
59 //Detach();
60 if (BSite) {
61 BSite->Release();
62 }
63}
64
65//
66/// Remove this link view from the document
67//
68int
70{
71 return OcView->OcDocument.GetViews().Detach(this);
72}
73
74//
75//
76//
77HRESULT
78TOcLinkView::QueryObject(const IID & iid, void * * iface)
79{
80 PRECONDITION(iface);
81 HRESULT hr;
82
83 static_cast<void>
84 (
85 // interfaces
86 //
87 SUCCEEDED(hr = IBPart_QueryInterface(this, iid, iface))
88 || SUCCEEDED(hr = IBDataProvider_QueryInterface(this, iid, iface))
89
90 // helpers
91 //
92 || (BSite && SUCCEEDED(hr = BSite->QueryInterface(iid, iface)))
93 );
94
95 return hr;
96}
97
98//----------------------------------------------------------------------------
99// IBSite pass-thrus
100
101//
102/// Invalidate the site corresponding to this view
103//
104void
106{
107 if (BSiteI)
108 BSiteI->Invalidate(invalid);
109}
110
111//
112/// Disconnect from the client site
113//
114void
116{
117 if (BSiteI)
118 BSiteI->Disconnect();
119}
120
121//
122/// Remember the name of the moniker
123//
124void
126{
127 Moniker = const_cast<LPTSTR>(name); // force TString to copy
128}
129
130
131//----------------------------------------------------------------------------
132// IDataNegotiator implementation -- delegate to our owning OcView
133
134//
135//
136//
139{
140 return OcView->CountFormats();
141}
142
143//
144//
145//
146HRESULT _IFUNC
148{
149 PRECONDITION(fmt);
150
151 return OcView->GetFormat(index, fmt);
152}
153
154//----------------------------------------------------------------------------
155// IBDataNegotiator implementation
156
157//
158/// Request native data for pasting into client application.
159/// This is only called at paste time (not at copy time).
160//
161HANDLE _IFUNC
163{
164 PRECONDITION(fmt);
165
166 TOcFormat* format = OcView->FormatList.Find(fmt->Id);
167 if (format) {
168 TOcFormatData formatData(*format);
169 if (OcView->ServerHost->EvOcViewClipData(formatData))
170 return formatData.Handle;
171 }
172
173 return 0;
174}
175
176//
177/// Get the initial size and position from the host app into our members
178//
179void
181{
182 TOcPartSize ps(true, &Moniker);
183
184 // Ask the app for initial server extent
185 //
186 if (!OcView->ServerHost->EvOcViewPartSize(ps)) {
187 // An empty rect as default means that the container
188 // decides the size for this server
189 //
190 ps.PartRect.SetNull();
191 }
192
193 Extent = ps.PartRect.Size();
194 Origin = ps.PartRect.TopLeft();
195}
196
197//
198/// Render the view in the DC provided. Should be a MetaFile
199/// Packup all the args & forward message to real view to paint
200//
201HRESULT _IFUNC
202TOcLinkView::Draw(HDC dc, const RECTL * pos, const RECTL * clip,
203 TOcAspect aspect, TOcDraw bd)
204{
205 PRECONDITION(dc);
206
207 // Rely on the bolero shading
208 //
209 if (bd == drShadingOnly)
210 return HR_NOERROR;
211
212 TRect p((int)pos->left, (int)pos->top, (int)pos->right, (int)pos->bottom);
213 TRect c((int)clip->left, (int)clip->top, (int)clip->right, (int)clip->bottom);
214
215 p.SetEmpty();
216 ::SetMapMode(dc, MM_ANISOTROPIC);
217
218 ::SetWindowExtEx(dc, Extent.cx, Extent.cy, 0);
219 ::SetWindowOrgEx(dc, 0, 0, 0);
220
221 p.Normalize();
222 c.Normalize();
223
224 // Find out where the TOleLinkView is
225 //
226 GetLinkRect();
227 *(TPoint*)&p = Origin;
228
229 TOcViewPaint vp = { dc, &p, &c, (TOcAspect)aspect, false, &Moniker, 0 };
230
231 return HRFailIfZero(OcView->ServerHost->EvOcViewPaint(vp));
232}
233
234//
235/// Return the 'size' of the document that this view in on
236//
237HRESULT _IFUNC
239{
240 *size = Extent;
241 return HR_NOERROR;
242}
243
244//
245/// Save the document that we are a view on
246//
247HRESULT _IFUNC
248TOcLinkView::Save(IStorage* storage, BOOL sameAsLoad, BOOL remember)
249{
250 PRECONDITION(storage);
251
252 TOcSaveLoad ocSave(storage, ToBool(sameAsLoad), ToBool(remember));
253
254 return HRFailIfZero(OcView->ServerHost->EvOcViewSavePart(ocSave));
255}
256
257#if 0
258//
259//
260//
261HRESULT _IFUNC
262TOcLinkView::SetFormatData(TOcFormatInfo * /*fmt*/, HANDLE /*data*/, BOOL /*release*/)
263{
264 return HR_NOTIMPL;
265}
266#endif
267
268//----------------------------------------------------------------------------
269// IBPart implementation
270
271//
272/// Load the associated document and activate the remote view
273//
274HRESULT _IFUNC
276{
277 return HR_NOERROR;
278}
279
280//
281/// Close the remote view window, & if canShutDown is true, try to close the server
282/// app too
283//
284HRESULT _IFUNC
286{
287 OcView->ServerHost->EvOcViewBreakLink(*this); // !CQ check return?
288 return HR_NOERROR;
289}
290
291//
292/// Query to determine if this view can open in place
293//
294HRESULT _IFUNC
296{
297 return HR_FAIL; // Links never open in place
298}
299
300//
301/// Set a new position for our document within its container
302//
303HRESULT _IFUNC
305{
306 Origin = *(POINT*)&r->left;
307 return HR_NOERROR;
308}
309
310//
311//
312//
313HRESULT _IFUNC
315{
316 Extent = *size;
317 return HR_NOERROR;
318}
319
320//
321/// Activate this view
322//
323HRESULT _IFUNC
324TOcLinkView::Activate(BOOL /*activate*/)
325{
326 return HR_NOERROR;
327}
328
329//
330/// Show/Hide the server view window
331//
332HRESULT _IFUNC
333TOcLinkView::Show(BOOL /*show*/)
334{
335 return HR_NOERROR;
336}
337
338//
339/// Start or end open editing
340/// Work with the window Z-order and parenting
341//
342HRESULT _IFUNC
344{
345 if (open) {
346 TOcRemView* ocRemView = TYPESAFE_DOWNCAST(OcView, TOcRemView);
347 if (ocRemView)
348 ocRemView->SetOpenEditing();
349
350 OcView->ServerHost->EvOcViewAttachWindow(true);
351 OcView->BringToFront();
352 }
353
354 return HR_NOERROR;
355}
356
357//
358/// Enumerate the verbs for our document
359//
360HRESULT _IFUNC
362{
363 return HR_FAIL; // Not called on BOle parts
364}
365
366//
367/// Perform a verb on our document
368//
369HRESULT _IFUNC
371{
372 return HR_FAIL; // Assume that links don't need to do verbs
373}
374
375//
376/// Open or close this view as an in-place edit session. If hWndParent is 0, then
377/// in-place is closing
378//
379HWND _IFUNC
380TOcLinkView::OpenInPlace(HWND /*hWndParent*/)
381{
382 return 0;
383}
384
385//
386/// Insert the server's menus into the shared menubar
387//
388HRESULT _IFUNC
389TOcLinkView::InsertMenus(HMENU /*hMenu*/, TOcMenuWidths * /*omw*/)
390{
391 return HR_NOERROR;
392}
393
394//
395/// Show or hide the tool windows used by our view
396//
397HRESULT _IFUNC
399{
400 return HR_NOERROR;
401}
402
403//
404/// A container window has resized. Perform any necessary adjustment of our
405/// tools.
406//
407void _IFUNC
408TOcLinkView::FrameResized(const TRect * /*contFrameR*/, BOOL /*isMainFrame*/)
409{
410}
411
412//
413/// Let the server provide drag feedback
414//
415HRESULT _IFUNC
416TOcLinkView::DragFeedback(TPoint * where, BOOL /*nearScroll*/)
417{
418 TPoint awhere(*where);
419 TOcDragDrop dd = { 0, &awhere, 0 };
420 return HRFailIfZero(OcView->ServerHost->EvOcViewDrag(dd));
421}
422
423//
424/// Optional palette query for
425//
426HRESULT _IFUNC
427TOcLinkView::GetPalette(LOGPALETTE * * palette)
428{
429 PRECONDITION(palette);
430
431 return HRFailIfZero(OcView->ServerHost->EvOcViewGetPalette(palette));
432}
433
434//
435//
436//
437HRESULT _IFUNC
439{
440 return HR_FAIL; // Not called on BOle parts.
441}
442
443//
444//
445//
446HRESULT _IFUNC
447TOcLinkView::DoQueryInterface(const IID & iid, void * * iface)
448{
449 PRECONDITION(iface);
450
451 return OcView->QueryInterface(iid, iface); // Unused on server side
452}
453
454//
455//
456//
457LPOLESTR _IFUNC
459{
460 return 0; // Not called on BOle parts.
461}
462
463
464//----------------------------------------------------------------------------
465// TOcLinkCollection
466//
467
468//
469//
470//
474
475//
476//
477//
482
483//
484/// Release Views in the collection
485//
486void
488{
489 for (int i = Count() - 1; i >= 0; i--) {
490 TOcLinkView* view = (TOcLinkView*)(*this)[i];
491 view->Release();
492 Base::Detach(i); ///DR why do we want to keep data after a clear? Remove it.
493 }
494}
495
496//
497//
498//
499int
501{
502 int ret = Base::Detach(Find(view));
503 if (ret && del)
504 const_cast<TOcLinkView*>(view)->Release();
505 return ret;
506}
507
508//
509//
510//
513{
514 for (TOcViewCollectionIter j((TOcViewCollection&)*this); j; j++) {
515 TOcLinkView* view = (TOcLinkView*)j.Current();
516 if (view && strcmp(view->GetMoniker(), moniker) == 0) {
517 return view;
518 }
519 }
520
521 return 0;
522}
523
524} // OCF namespace
525
526//==============================================================================
527
#define PRECONDITION(condition)
Definition checks.h:227
IBContainer – Supported by container app's document window.
Definition ocbocole.h:403
IBPart – Supported by server objects.
Definition ocbocole.h:246
IBSite – Supported by container apps for each linked/embedded object.
Definition ocbocole.h:442
Used to obtain the native clipboard format data.
Definition ocview.h:416
HANDLE Handle
clipboard data in handle
Definition ocview.h:427
Clipboard format wrapper.
Definition ocview.h:55
Used to obtain the size of the rectangle that encloses the selection.
Definition ocview.h:364
owl::TRect PartRect
rect enclosing the whole/part of the embedded object
Definition ocview.h:394
Remote Viewer object for a server document.
Definition ocremvie.h:26
void SetOpenEditing()
Definition ocremvie.h:74
Use when doing parts save and load.
Definition ocview.h:326
The TOcView partner is a container (viewer) of a given (server/client) document.
Definition ocview.h:136
IUnknown * SetOuter(IUnknown *outer=0)
Definition oleutil.h:298
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
void SetEmpty()
Empties this rectangle by setting left, top, right, and bottom to 0.
Definition geometry.h:898
const TPoint & TopLeft() const
Returns the upperleft point.
Definition geometry.h:983
void SetNull()
Sets the left, top, right, and bottom of the rectangle to 0.
Definition geometry.h:1075
TSize Size() const
Returns the size of rectangle.
Definition geometry.h:1057
TRect & Normalize()
Normalizes this rectangle by switching the left and right data member values if left > right,...
Definition geometry.cpp:99
A registration parameter table, composed of a list of TRegItems.
Definition registry.h:531
LPCTSTR Lookup(LPCSTR key, TLangId lang=TLocaleString::UserDefaultLangId)
Performs the lookup of the TRegItems using a key (an item name such as progid) and returns the value ...
Definition regheap.cpp:58
The tagSIZE struct is defined as.
Definition geometry.h:234
Reference to reference counted string object TUString Lightweight reference object consisting of a po...
Definition string.h:67
bool Detach(int loc)
Definition template.h:1573
Include for OC, gets common headers when precompiled headers are enabled.
Object Component Framework (COM encapsulation).
Definition appdesc.h:22
TOcAspect
Definition ocobject.h:64
const BCID cidBOleInProcSite
Definition ocbocole.h:119
HRESULT HRFailIfZero(int bexpr)
Definition defs.h:126
const BCID cidBOleSite
Definition ocbocole.h:118
TOcLinkCollection TOcViewCollection
Definition oclink.h:142
TOcLinkCollectionIter TOcViewCollectionIter
Iterator for view collection.
Definition oclink.h:153
TOcInvalidate
Definition ocobject.h:59
const GUID & iid
Definition appdesc.h:328
@ amExeModule
set for EXE components, 0 if DLL inproc server
Definition ocreg.h:87
@ amDebug
user requested launching for debugging
Definition ocreg.h:85
TOcPartName
Definition ocobject.h:87
TOcDraw
Definition ocobject.h:81
@ drShadingOnly
Definition ocobject.h:83
bool ToBool(const T &t)
Definition defs.h:291
unsigned int uint
Definition number.h:25
Definition of TOcApp application connection class.
interface _ICLASS IStorage
Definition ocdoc.h:25
#define HR_NOTIMPL
Definition defs.h:76
#define HR_NOERROR
Definition defs.h:73
#define HR_FAIL
Definition defs.h:83
Definition of TOcRemView Class.
#define _IFUNC
Definition oleutil.h:28
#define TYPESAFE_DOWNCAST(object, toClass)
Definition defs.h:269
#define OleStr(s)
Definition string.h:128
For viewdrop & viewdrag.
Definition ocview.h:303
For part adornment painting over part, & painting views.
Definition ocview.h:312