OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
ocdata.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 TOcDataProvider Class
7//----------------------------------------------------------------------------
8#include <ocf/pch.h>
9
10#include <ocf/ocapp.h>
11#include <ocf/ocdata.h>
12
13namespace ocf {
14
15using namespace owl;
16
17//
18//
19//
22:
23 OcView(ocView), BSite(0), BSiteI(0), BLSiteI(0),
24 UserData(userData), CBDelete(callBack),
25 Origin(0,0),
26 Extent(0,0)
27{
29 AddRef(); // TUnknown defaults to 0, we need 1
30
31 // Create a site for this data provider
32 //
33 if (SUCCEEDED(OcView.OcApp.BOleComponentCreate(&BSite, (IUnknown*)(IBDataProvider*)this,
34 cidBOleSite))) {
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 LPCTSTR progid = regList->Lookup(OcView.OcApp.IsOptionSet(amDebug) ?
43 "debugprogid" : "progid");
44 BSiteI->Init(this, 0, OleStr(progid), true);
45 }
46
47 if (SUCCEEDED(BSite->QueryInterface(IID_IBLinkable,(LPVOID *)&BLSiteI)))
48 BLSiteI->Release(); // avoid deadlock
49
50 // Remember the dataprovider in OcView
51 //
52 OcView.SetOcData(this);
53
54 // Set up monikers for selection
55 //
56 Rename();
57 }
58}
59
60//
61//
62//
63TOcDataProvider::~TOcDataProvider()
64{
65 // If the TOcDataProvider object is released by the clipboard
66 //
67 if (OcView.GetOcData() == this)
68 OcView.SetOcData(0);
69
70 // User data clean up
71 //
72 if (CBDelete)
73 CBDelete(UserData);
74
75 if(BSite)
76 BSite->Release();
77}
78
79//
80//
81//
83TOcDataProvider::QueryObject(const IID & iid, void * * iface)
84{
86 HRESULT hr;
87
88 static_cast<void>
89 (
90 // interfaces
91 //
93
94 // helpers
95 //
96 || (BSite && SUCCEEDED(hr = BSite->QueryInterface(iid, iface)))
97 );
98
99 return hr;
100}
101
102//
103/// Disconnect from the site
104//
105void
107{
108 if (BSiteI)
109 BSiteI->Disconnect();
110}
111
112//
113/// Update item moniker with new name
114//
115void
117{
118 PRECONDITION(BLSiteI);
119
120 OcView.Rename();
121
122 // Update the item's moniker
123 //
124 TOcItemName item(true);
125 if (OcView.ServerHost->EvOcViewGetItemName(item))
126 BLSiteI->OnRename(OcView.BLDocumentI, OleStr(item.Name));
127}
128
129//
130//
131//
134{
135 return OcView.CountFormats();
136}
137
138//
139//
140//
143{
145
146 return OcView.GetFormat(index, fmt);
147}
148
149//
150/// Request native data for pasting into client application.
151/// This is only called at paste time (not at copy time).
152//
155{
157
158 TOcFormat* format = OcView.FormatList.Find(fmt->Id);
159 if (format && *format->GetRegName()) {
160 TOcFormatData formatData(*format, UserData);
162 return formatData.Handle;
163 }
164
165 return 0;
166}
167
168//
169/// Render the data in the DC provided. May be a MetaFile
170/// Packup all the args & forward message to real view to paint
171//
175{
176 PRECONDITION(dc);
177 bool metafile = ::GetDeviceCaps(dc, TECHNOLOGY) == DT_METAFILE;
178
179 // Rely on the bolero shading
180 //
181 if (bd == drShadingOnly)
182 return HR_NOERROR;
183
184 TRect p((int)pos->left, (int)pos->top, (int)pos->right, (int)pos->bottom);
185 TRect c((int)clip->left, (int)clip->top, (int)clip->right, (int)clip->bottom);
186
187 if (metafile) {
188 p.SetNull();
189 ::SetMapMode(dc, MM_ANISOTROPIC);
190
191 ::SetWindowExtEx(dc, Extent.cx, Extent.cy, 0);
192 ::SetWindowOrgEx(dc, 0, 0, 0);
193 }
194
195 p.Normalize();
196 c.Normalize();
197 TOcViewPaint vp = { dc, &p, &c, (TOcAspect)aspect, true, 0, UserData };
198
199 return HRFailIfZero(OcView.ServerHost->EvOcViewPaint(vp));
200}
201
202//
203/// Return the 'size' of the document that this view is on
204//
207{
208 TOcPartSize ps(true, 0, UserData);
209
210 // Ask the app for initial server extent
211 //
212 if (!OcView.ServerHost->EvOcViewPartSize(ps)) {
213 // An empty rect as default means that the container
214 // decides the size for this server
215 //
216 ps.PartRect.SetNull();
217 }
218
219 Extent = ps.PartRect.Size();
220 Origin = ps.PartRect.TopLeft();
221
222 *size = Extent;
223 return HR_NOERROR;
224}
225
226//
227/// Save the selection that we are a view on
228//
239
240} // OCF namespace
241
242//==============================================================================
243
#define PRECONDITION(condition)
Definition checks.h:227
IBDataProvider – Supported by parts and/or sites which can be copied to the OLE2 clipboard.
Definition ocbocole.h:219
virtual HRESULT _IFUNC OnRename(IBLinkable *pContainer, LPCOLESTR name)=0
virtual void _IFUNC Disconnect()=0
HRESULT BOleComponentCreate(IUnknown **retIface, IUnknown *outer, owl::uint32 idClass)
Create a BOle helper for one of our OC objects in this app.
Definition ocapp.cpp:213
bool IsOptionSet(owl::uint32 option) const
Definition ocapp.h:302
HRESULT _IFUNC Save(IStorage *, BOOL sameAsLoad, BOOL remember)
Save the selection that we are a view on.
Definition ocdata.cpp:230
owl::ulong _IFUNC Release()
Definition ocdata.h:39
HRESULT _IFUNC GetPartSize(owl::TSize *size)
Return the 'size' of the document that this view is on.
Definition ocdata.cpp:206
HANDLE _IFUNC GetFormatData(TOcFormatInfo *fmt)
Request native data for pasting into client application.
Definition ocdata.cpp:154
void Rename()
Update item moniker with new name.
Definition ocdata.cpp:116
owl::TSize Extent
Definition ocdata.h:67
void Disconnect()
Disconnect from the site.
Definition ocdata.cpp:106
owl::ulong _IFUNC AddRef()
Definition ocdata.h:38
HRESULT _IFUNC Draw(HDC dc, const RECTL *pos, const RECTL *clip, TOcAspect aspect, TOcDraw bd)
Render the data in the DC provided.
Definition ocdata.cpp:173
HRESULT _IFUNC GetFormat(owl::uint index, TOcFormatInfo *fmt)
Definition ocdata.cpp:142
owl::TPoint Origin
Definition ocdata.h:66
TOcDataProvider(TOcView &ocView, owl::TRegList *regList, IUnknown *outer=0, void *userData=0, TDeleteUserData callBack=0)
Definition ocdata.cpp:20
UINT _IFUNC CountFormats()
Definition ocdata.cpp:133
Used to obtain the native clipboard format data.
Definition ocview.h:416
Clipboard format wrapper.
Definition ocview.h:55
int Find(const TOcFormat *format) const
Definition ocview.h:111
Used to obtain the item name for building monikers.
Definition ocview.h:403
owl::TString Name
Item moniker.
Definition ocview.h:409
Used to obtain the size of the rectangle that encloses the selection.
Definition ocview.h:364
Use when doing parts save and load.
Definition ocview.h:326
virtual bool EvOcViewGetItemName(TOcItemName &item)=0
virtual bool EvOcViewPartSize(TOcPartSize &size)=0
virtual bool EvOcViewPaint(TOcViewPaint &vp)=0
virtual bool EvOcViewClipData(TOcFormatData &format)=0
virtual bool EvOcViewSavePart(TOcSaveLoad &ocSave)=0
The TOcView partner is a container (viewer) of a given (server/client) document.
Definition ocview.h:136
void SetOcData(TOcDataProvider *ocData=0)
Definition ocview.h:160
TOcDataProvider * GetOcData()
Definition ocview.h:161
owl::uint _IFUNC CountFormats()
Format count.
Definition ocview.cpp:543
virtual void Rename()
Definition ocview.cpp:393
HRESULT _IFUNC GetFormat(owl::uint, TOcFormatInfo *)
Format retrieval.
Definition ocview.cpp:552
IBRootLinkable * BLDocumentI
RootLinkable interface on the container.
Definition ocview.h:265
TOcFormatList FormatList
Definition ocview.h:285
TOcApp & OcApp
Our OC application object.
Definition ocview.h:269
TOcServerHost * ServerHost
The hosting app's server object.
Definition ocview.h:273
IUnknown * SetOuter(IUnknown *outer=0)
Definition oleutil.h:298
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
void SetNull()
Sets the left, top, right, and bottom of the rectangle to 0.
Definition geometry.h:1075
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
The tagSIZE struct is defined as.
Definition geometry.h:234
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
HRESULT HRFailIfZero(int bexpr)
Definition defs.h:126
const BCID cidBOleSite
Definition ocbocole.h:113
const GUID & iid
Definition appdesc.h:328
@ amDebug
user requested launching for debugging
Definition ocreg.h:85
TOcDraw
Definition ocobject.h:81
@ drShadingOnly
Definition ocobject.h:83
void(* TDeleteUserData)(void *userData)
Definition ocdata.h:22
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
bool ToBool(const T &t)
Definition defs.h:291
unsigned int uint
Definition number.h:25
Definition of TOcApp application connection class.
Definition of TOcDataProvider Class.
interface _ICLASS IStorage
Definition ocdoc.h:25
#define HR_NOERROR
Definition defs.h:73
#define _IFUNC
Definition oleutil.h:28
#define OleStr(s)
Definition string.h:128
For part adornment painting over part, & painting views.
Definition ocview.h:312