richole.c 46.1 KB
Newer Older
1
/*
2
 * RichEdit GUIDs and OLE interface
3 4
 *
 * Copyright 2004 by Krzysztof Foltman
5
 * Copyright 2004 Aric Stewart
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21
 */

22
#include <stdarg.h>
23

24 25 26 27 28 29 30 31 32 33
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "ole2.h"
#include "richole.h"
34
#include "editor.h"
35
#include "tom.h"
36
#include "wine/debug.h"
37

38
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
39

40 41 42
/* there is no way to be consistent across different sets of headers - mingw, Wine, Win32 SDK*/

/* FIXME: the next 6 lines should be in textserv.h */
43
#include "initguid.h"
44
#define TEXTSERV_GUID(name, l, w1, w2, b1, b2) \
45
    DEFINE_GUID(name, l, w1, w2, b1, b2, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5)
46 47 48 49

TEXTSERV_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d);
TEXTSERV_GUID(IID_ITextHost, 0xc5bdd8d0, 0xd26e, 0x11ce, 0xa8, 0x9e);
TEXTSERV_GUID(IID_ITextHost2, 0xc5bdd8d0, 0xd26e, 0x11ce, 0xa8, 0x9e);
50
DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
51 52 53 54
DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);

typedef struct ITextSelectionImpl ITextSelectionImpl;
55
typedef struct IOleClientSiteImpl IOleClientSiteImpl;
56

57
typedef struct IRichEditOleImpl {
58 59
    const IRichEditOleVtbl *lpRichEditOleVtbl;
    const ITextDocumentVtbl *lpTextDocumentVtbl;
60 61 62
    LONG ref;

    ME_TextEditor *editor;
63
    ITextSelectionImpl *txtSel;
64
    IOleClientSiteImpl *clientSite;
65 66
} IRichEditOleImpl;

67 68 69 70 71 72 73
struct ITextSelectionImpl {
    const ITextSelectionVtbl *lpVtbl;
    LONG ref;

    IRichEditOleImpl *reOle;
};

74 75 76 77 78 79 80
struct IOleClientSiteImpl {
    const IOleClientSiteVtbl *lpVtbl;
    LONG ref;

    IRichEditOleImpl *reOle;
};

81 82 83 84 85 86 87 88 89 90
static inline IRichEditOleImpl *impl_from_IRichEditOle(IRichEditOle *iface)
{
    return (IRichEditOleImpl *)((BYTE*)iface - FIELD_OFFSET(IRichEditOleImpl, lpRichEditOleVtbl));
}

static inline IRichEditOleImpl *impl_from_ITextDocument(ITextDocument *iface)
{
    return (IRichEditOleImpl *)((BYTE*)iface - FIELD_OFFSET(IRichEditOleImpl, lpTextDocumentVtbl));
}

91 92 93
static HRESULT WINAPI
IRichEditOle_fnQueryInterface(IRichEditOle *me, REFIID riid, LPVOID *ppvObj)
{
94
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
95 96 97

    TRACE("%p %s\n", This, debugstr_guid(riid) );

98
    *ppvObj = NULL;
99 100
    if (IsEqualGUID(riid, &IID_IUnknown) ||
        IsEqualGUID(riid, &IID_IRichEditOle))
101 102 103 104
        *ppvObj = &This->lpRichEditOleVtbl;
    else if (IsEqualGUID(riid, &IID_ITextDocument))
        *ppvObj = &This->lpTextDocumentVtbl;
    if (*ppvObj)
105 106 107 108
    {
        IRichEditOle_AddRef(me);
        return S_OK;
    }
109
    FIXME("%p: unhandled interface %s\n", This, debugstr_guid(riid) );
110 111 112 113 114 115 116
 
    return E_NOINTERFACE;   
}

static ULONG WINAPI
IRichEditOle_fnAddRef(IRichEditOle *me)
{
117
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
118 119
    ULONG ref = InterlockedIncrement( &This->ref );

120
    TRACE("%p ref = %u\n", This, ref);
121 122 123 124 125 126 127

    return ref;
}

static ULONG WINAPI
IRichEditOle_fnRelease(IRichEditOle *me)
{
128
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
129 130
    ULONG ref = InterlockedDecrement(&This->ref);

131
    TRACE ("%p ref=%u\n", This, ref);
132 133 134 135

    if (!ref)
    {
        TRACE ("Destroying %p\n", This);
136 137
        This->txtSel->reOle = NULL;
        ITextSelection_Release((ITextSelection *) This->txtSel);
138
        IOleClientSite_Release((IOleClientSite *) This->clientSite);
139
        heap_free(This);
140 141 142 143 144 145 146
    }
    return ref;
}

static HRESULT WINAPI
IRichEditOle_fnActivateAs(IRichEditOle *me, REFCLSID rclsid, REFCLSID rclsidAs)
{
147
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
148 149 150 151 152 153 154
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnContextSensitiveHelp(IRichEditOle *me, BOOL fEnterMode)
{
155
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
156 157 158 159 160 161 162 163
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnConvertObject(IRichEditOle *me, LONG iob,
               REFCLSID rclsidNew, LPCSTR lpstrUserTypeNew)
{
164
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
165 166 167 168
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
static HRESULT WINAPI
IOleClientSite_fnQueryInterface(IOleClientSite *me, REFIID riid, LPVOID *ppvObj)
{
    TRACE("%p %s\n", me, debugstr_guid(riid) );

    *ppvObj = NULL;
    if (IsEqualGUID(riid, &IID_IUnknown) ||
        IsEqualGUID(riid, &IID_IOleClientSite))
        *ppvObj = me;
    if (*ppvObj)
    {
        IOleClientSite_AddRef(me);
        return S_OK;
    }
    FIXME("%p: unhandled interface %s\n", me, debugstr_guid(riid) );

    return E_NOINTERFACE;
}

static ULONG WINAPI
IOleClientSite_fnAddRef(IOleClientSite *me)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI
IOleClientSite_fnRelease(IOleClientSite *me)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    ULONG ref = InterlockedDecrement(&This->ref);
    if (ref == 0)
        heap_free(This);
    return ref;
}

static HRESULT WINAPI
IOleClientSite_fnSaveObject(IOleClientSite *me)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("stub %p\n",me);
    return E_NOTIMPL;
}


static HRESULT WINAPI
IOleClientSite_fnGetMoniker(IOleClientSite *me, DWORD dwAssign, DWORD dwWhichMoniker,
    IMoniker **ppmk)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("stub %p\n",me);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IOleClientSite_fnGetContainer(IOleClientSite *me, IOleContainer **ppContainer)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("stub %p\n",me);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IOleClientSite_fnShowObject(IOleClientSite *me)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("stub %p\n",me);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IOleClientSite_fnOnShowWindow(IOleClientSite *me, BOOL fShow)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("stub %p\n",me);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IOleClientSite_fnRequestNewObjectLayout(IOleClientSite *me)
{
    IOleClientSiteImpl *This = (IOleClientSiteImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("stub %p\n",me);
    return E_NOTIMPL;
}

static const IOleClientSiteVtbl ocst = {
    IOleClientSite_fnQueryInterface,
    IOleClientSite_fnAddRef,
    IOleClientSite_fnRelease,
    IOleClientSite_fnSaveObject,
    IOleClientSite_fnGetMoniker,
    IOleClientSite_fnGetContainer,
    IOleClientSite_fnShowObject,
    IOleClientSite_fnOnShowWindow,
    IOleClientSite_fnRequestNewObjectLayout
};

static IOleClientSiteImpl *
CreateOleClientSite(IRichEditOleImpl *reOle)
{
    IOleClientSiteImpl *clientSite = heap_alloc(sizeof *clientSite);
    if (!clientSite)
        return NULL;

    clientSite->lpVtbl = &ocst;
    clientSite->ref = 1;
    clientSite->reOle = reOle;
    return clientSite;
}

298 299 300 301
static HRESULT WINAPI
IRichEditOle_fnGetClientSite(IRichEditOle *me,
               LPOLECLIENTSITE *lplpolesite)
{
302
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
303 304 305 306 307 308 309 310

    TRACE("%p,%p\n",This, lplpolesite);

    if(!lplpolesite)
        return E_INVALIDARG;
    *lplpolesite = (IOleClientSite *) This->clientSite;
    IOleClientSite_fnAddRef(*lplpolesite);
    return S_OK;
311 312 313 314 315 316
}

static HRESULT WINAPI
IRichEditOle_fnGetClipboardData(IRichEditOle *me, CHARRANGE *lpchrg,
               DWORD reco, LPDATAOBJECT *lplpdataobj)
{
317
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
318 319
    ME_Cursor start;
    int nChars;
320

321
    TRACE("(%p,%p,%d)\n",This, lpchrg, reco);
322 323 324
    if(!lplpdataobj)
        return E_INVALIDARG;
    if(!lpchrg) {
325 326 327 328 329 330
        int nFrom, nTo, nStartCur = ME_GetSelectionOfs(This->editor, &nFrom, &nTo);
        start = This->editor->pCursors[nStartCur];
        nChars = nTo - nFrom;
    } else {
        ME_CursorFromCharOfs(This->editor, lpchrg->cpMin, &start);
        nChars = lpchrg->cpMax - lpchrg->cpMin;
331
    }
332
    return ME_GetDataObject(This->editor, &start, nChars, lplpdataobj);
333 334 335 336
}

static LONG WINAPI IRichEditOle_fnGetLinkCount(IRichEditOle *me)
{
337
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
338 339 340 341 342 343 344 345
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnGetObject(IRichEditOle *me, LONG iob,
               REOBJECT *lpreobject, DWORD dwFlags)
{
346
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
347 348 349 350 351 352 353
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static LONG WINAPI
IRichEditOle_fnGetObjectCount(IRichEditOle *me)
{
354
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
355
    FIXME("stub %p\n",This);
356
    return 0;
357 358 359 360 361
}

static HRESULT WINAPI
IRichEditOle_fnHandsOffStorage(IRichEditOle *me, LONG iob)
{
362
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
363 364 365 366 367 368 369 370
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnImportDataObject(IRichEditOle *me, LPDATAOBJECT lpdataobj,
               CLIPFORMAT cf, HGLOBAL hMetaPict)
{
371
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
372 373 374 375 376 377 378
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnInPlaceDeactivate(IRichEditOle *me)
{
379
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
380 381 382 383 384
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
385
IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
386
{
387
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
388 389 390 391 392
    TRACE("(%p,%p)\n", This, reo);

    if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;

    ME_InsertOLEFromCursor(This->editor, reo, 0);
393 394
    ME_CommitUndo(This->editor);
    ME_UpdateRepaint(This->editor);
395
    return S_OK;
396 397 398 399 400
}

static HRESULT WINAPI IRichEditOle_fnSaveCompleted(IRichEditOle *me, LONG iob,
               LPSTORAGE lpstg)
{
401
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
402 403 404 405 406 407 408
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnSetDvaspect(IRichEditOle *me, LONG iob, DWORD dvaspect)
{
409
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
410 411 412 413 414 415 416
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI IRichEditOle_fnSetHostNames(IRichEditOle *me,
               LPCSTR lpstrContainerApp, LPCSTR lpstrContainerObj)
{
417
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
418
    FIXME("stub %p %s %s\n",This, lpstrContainerApp, lpstrContainerObj);
419 420 421 422 423 424
    return E_NOTIMPL;
}

static HRESULT WINAPI
IRichEditOle_fnSetLinkAvailable(IRichEditOle *me, LONG iob, BOOL fAvailable)
{
425
    IRichEditOleImpl *This = impl_from_IRichEditOle(me);
426 427 428 429
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

430
static const IRichEditOleVtbl revt = {
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    IRichEditOle_fnQueryInterface,
    IRichEditOle_fnAddRef,
    IRichEditOle_fnRelease,
    IRichEditOle_fnGetClientSite,
    IRichEditOle_fnGetObjectCount,
    IRichEditOle_fnGetLinkCount,
    IRichEditOle_fnGetObject,
    IRichEditOle_fnInsertObject,
    IRichEditOle_fnConvertObject,
    IRichEditOle_fnActivateAs,
    IRichEditOle_fnSetHostNames,
    IRichEditOle_fnSetLinkAvailable,
    IRichEditOle_fnSetDvaspect,
    IRichEditOle_fnHandsOffStorage,
    IRichEditOle_fnSaveCompleted,
    IRichEditOle_fnInPlaceDeactivate,
    IRichEditOle_fnContextSensitiveHelp,
    IRichEditOle_fnGetClipboardData,
    IRichEditOle_fnImportDataObject
};

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
static HRESULT WINAPI
ITextDocument_fnQueryInterface(ITextDocument* me, REFIID riid,
    void** ppvObject)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    return IRichEditOle_fnQueryInterface((IRichEditOle*)&This->lpRichEditOleVtbl,
            riid, ppvObject);
}

static ULONG WINAPI
ITextDocument_fnAddRef(ITextDocument* me)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    return IRichEditOle_fnAddRef((IRichEditOle*)&This->lpRichEditOleVtbl);
}

static ULONG WINAPI
ITextDocument_fnRelease(ITextDocument* me)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    return IRichEditOle_fnRelease((IRichEditOle*)&This->lpRichEditOleVtbl);
}

static HRESULT WINAPI
ITextDocument_fnGetTypeInfoCount(ITextDocument* me,
    UINT* pctinfo)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnGetTypeInfo(ITextDocument* me, UINT iTInfo, LCID lcid,
    ITypeInfo** ppTInfo)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnGetIDsOfNames(ITextDocument* me, REFIID riid,
    LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnInvoke(ITextDocument* me, DISPID dispIdMember,
    REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
    VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnGetName(ITextDocument* me, BSTR* pName)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnGetSelection(ITextDocument* me, ITextSelection** ppSel)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
524 525 526 527
    TRACE("(%p)\n", me);
    *ppSel = (ITextSelection *) This->txtSel;
    ITextSelection_AddRef(*ppSel);
    return S_OK;
528 529 530
}

static HRESULT WINAPI
531
ITextDocument_fnGetStoryCount(ITextDocument* me, LONG* pCount)
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnGetStoryRanges(ITextDocument* me,
    ITextStoryRanges** ppStories)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
548
ITextDocument_fnGetSaved(ITextDocument* me, LONG* pValue)
549 550 551 552 553 554 555
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
556
ITextDocument_fnSetSaved(ITextDocument* me, LONG Value)
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnGetDefaultTabStop(ITextDocument* me, float* pValue)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnSetDefaultTabStop(ITextDocument* me, float Value)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnNew(ITextDocument* me)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
588 589
ITextDocument_fnOpen(ITextDocument* me, VARIANT* pVar, LONG Flags,
    LONG CodePage)
590 591 592 593 594 595 596
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
597 598
ITextDocument_fnSave(ITextDocument* me, VARIANT* pVar, LONG Flags,
    LONG CodePage)
599 600 601 602 603 604 605
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
606
ITextDocument_fnFreeze(ITextDocument* me, LONG* pCount)
607 608 609 610 611 612 613
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
614
ITextDocument_fnUnfreeze(ITextDocument* me, LONG* pCount)
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnBeginEditCollection(ITextDocument* me)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
ITextDocument_fnEndEditCollection(ITextDocument* me)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
638
ITextDocument_fnUndo(ITextDocument* me, LONG Count, LONG* prop)
639 640 641 642 643 644 645
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
646
ITextDocument_fnRedo(ITextDocument* me, LONG Count, LONG* prop)
647 648 649 650 651 652 653
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
654
ITextDocument_fnRange(ITextDocument* me, LONG cp1, LONG cp2,
655 656 657 658 659 660 661 662
    ITextRange** ppRange)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static HRESULT WINAPI
663
ITextDocument_fnRangeFromPoint(ITextDocument* me, LONG x, LONG y,
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
    ITextRange** ppRange)
{
    IRichEditOleImpl *This = impl_from_ITextDocument(me);
    FIXME("stub %p\n",This);
    return E_NOTIMPL;
}

static const ITextDocumentVtbl tdvt = {
    ITextDocument_fnQueryInterface,
    ITextDocument_fnAddRef,
    ITextDocument_fnRelease,
    ITextDocument_fnGetTypeInfoCount,
    ITextDocument_fnGetTypeInfo,
    ITextDocument_fnGetIDsOfNames,
    ITextDocument_fnInvoke,
    ITextDocument_fnGetName,
    ITextDocument_fnGetSelection,
    ITextDocument_fnGetStoryCount,
    ITextDocument_fnGetStoryRanges,
    ITextDocument_fnGetSaved,
    ITextDocument_fnSetSaved,
    ITextDocument_fnGetDefaultTabStop,
    ITextDocument_fnSetDefaultTabStop,
    ITextDocument_fnNew,
    ITextDocument_fnOpen,
    ITextDocument_fnSave,
    ITextDocument_fnFreeze,
    ITextDocument_fnUnfreeze,
    ITextDocument_fnBeginEditCollection,
    ITextDocument_fnEndEditCollection,
    ITextDocument_fnUndo,
    ITextDocument_fnRedo,
    ITextDocument_fnRange,
    ITextDocument_fnRangeFromPoint
};

700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
static HRESULT WINAPI ITextSelection_fnQueryInterface(
    ITextSelection *me,
    REFIID riid,
    void **ppvObj)
{
    *ppvObj = NULL;
    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDispatch)
        || IsEqualGUID(riid, &IID_ITextRange)
        || IsEqualGUID(riid, &IID_ITextSelection))
    {
        *ppvObj = me;
        ITextSelection_AddRef(me);
        return S_OK;
    }

    return E_NOINTERFACE;
}

static ULONG WINAPI ITextSelection_fnAddRef(
    ITextSelection *me)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI ITextSelection_fnRelease(
    ITextSelection *me)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    ULONG ref = InterlockedDecrement(&This->ref);
    if (ref == 0)
        heap_free(This);
    return ref;
}

static HRESULT WINAPI ITextSelection_fnGetTypeInfoCount(
    ITextSelection *me,
    UINT *pctinfo)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetTypeInfo(
    ITextSelection *me,
    UINT iTInfo,
    LCID lcid,
    ITypeInfo **ppTInfo)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetIDsOfNames(
    ITextSelection *me,
    REFIID riid,
    LPOLESTR *rgszNames,
    UINT cNames,
    LCID lcid,
    DISPID *rgDispId)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnInvoke(
    ITextSelection *me,
    DISPID dispIdMember,
    REFIID riid,
    LCID lcid,
    WORD wFlags,
    DISPPARAMS *pDispParams,
    VARIANT *pVarResult,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr)
{
    FIXME("not implemented\n");
    return E_NOTIMPL;
}

/*** ITextRange methods ***/
static HRESULT WINAPI ITextSelection_fnGetText(
    ITextSelection *me,
    BSTR *pbstr)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetText(
    ITextSelection *me,
    BSTR bstr)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetChar(
    ITextSelection *me,
820
    LONG *pch)
821 822 823 824 825 826 827 828 829 830 831
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetChar(
    ITextSelection *me,
832
    LONG ch)
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetDuplicate(
    ITextSelection *me,
    ITextRange **ppRange)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetFormattedText(
    ITextSelection *me,
    ITextRange **ppRange)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetFormattedText(
    ITextSelection *me,
    ITextRange *pRange)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetStart(
    ITextSelection *me,
880
    LONG *pcpFirst)
881 882 883 884 885 886 887 888 889 890 891
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetStart(
    ITextSelection *me,
892
    LONG cpFirst)
893 894 895 896 897 898 899 900 901 902 903
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetEnd(
    ITextSelection *me,
904
    LONG *pcpLim)
905 906 907 908 909 910 911 912 913 914 915
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetEnd(
    ITextSelection *me,
916
    LONG cpLim)
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetFont(
    ITextSelection *me,
    ITextFont **pFont)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetFont(
    ITextSelection *me,
    ITextFont *pFont)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetPara(
    ITextSelection *me,
    ITextPara **ppPara)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetPara(
    ITextSelection *me,
    ITextPara *pPara)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetStoryLength(
    ITextSelection *me,
976
    LONG *pcch)
977 978 979 980 981 982 983 984 985 986 987
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetStoryType(
    ITextSelection *me,
988
    LONG *pValue)
989 990 991 992 993 994 995 996 997 998 999
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnCollapse(
    ITextSelection *me,
1000
    LONG bStart)
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnExpand(
    ITextSelection *me,
1012 1013
    LONG Unit,
    LONG *pDelta)
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetIndex(
    ITextSelection *me,
1025 1026
    LONG Unit,
    LONG *pIndex)
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetIndex(
    ITextSelection *me,
1038 1039 1040
    LONG Unit,
    LONG Index,
    LONG Extend)
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetRange(
    ITextSelection *me,
1052 1053
    LONG cpActive,
    LONG cpOther)
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnInRange(
    ITextSelection *me,
    ITextRange *pRange,
1066
    LONG *pb)
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnInStory(
    ITextSelection *me,
    ITextRange *pRange,
1079
    LONG *pb)
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnIsEqual(
    ITextSelection *me,
    ITextRange *pRange,
1092
    LONG *pb)
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSelect(
    ITextSelection *me)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnStartOf(
    ITextSelection *me,
1115 1116 1117
    LONG Unit,
    LONG Extend,
    LONG *pDelta)
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnEndOf(
    ITextSelection *me,
1129 1130 1131
    LONG Unit,
    LONG Extend,
    LONG *pDelta)
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMove(
    ITextSelection *me,
1143 1144 1145
    LONG Unit,
    LONG Count,
    LONG *pDelta)
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveStart(
    ITextSelection *me,
1157 1158 1159
    LONG Unit,
    LONG Count,
    LONG *pDelta)
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveEnd(
    ITextSelection *me,
1171 1172 1173
    LONG Unit,
    LONG Count,
    LONG *pDelta)
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveWhile(
    ITextSelection *me,
    VARIANT *Cset,
1186 1187
    LONG Count,
    LONG *pDelta)
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveStartWhile(
    ITextSelection *me,
    VARIANT *Cset,
1200 1201
    LONG Count,
    LONG *pDelta)
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveEndWhile(
    ITextSelection *me,
    VARIANT *Cset,
1214 1215
    LONG Count,
    LONG *pDelta)
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveUntil(
    ITextSelection *me,
    VARIANT *Cset,
1228 1229
    LONG Count,
    LONG *pDelta)
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveStartUntil(
    ITextSelection *me,
    VARIANT *Cset,
1242 1243
    LONG Count,
    LONG *pDelta)
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveEndUntil(
    ITextSelection *me,
    VARIANT *Cset,
1256 1257
    LONG Count,
    LONG *pDelta)
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnFindText(
    ITextSelection *me,
    BSTR bstr,
1270 1271 1272
    LONG cch,
    LONG Flags,
    LONG *pLength)
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnFindTextStart(
    ITextSelection *me,
    BSTR bstr,
1285 1286 1287
    LONG cch,
    LONG Flags,
    LONG *pLength)
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnFindTextEnd(
    ITextSelection *me,
    BSTR bstr,
1300 1301 1302
    LONG cch,
    LONG Flags,
    LONG *pLength)
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnDelete(
    ITextSelection *me,
1314 1315 1316
    LONG Unit,
    LONG Count,
    LONG *pDelta)
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnCut(
    ITextSelection *me,
    VARIANT *pVar)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnCopy(
    ITextSelection *me,
    VARIANT *pVar)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnPaste(
    ITextSelection *me,
    VARIANT *pVar,
1353
    LONG Format)
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnCanPaste(
    ITextSelection *me,
    VARIANT *pVar,
1366 1367
    LONG Format,
    LONG *pb)
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnCanEdit(
    ITextSelection *me,
1379
    LONG *pb)
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnChangeCase(
    ITextSelection *me,
1391
    LONG Type)
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetPoint(
    ITextSelection *me,
1403 1404 1405
    LONG Type,
    LONG *cx,
    LONG *cy)
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetPoint(
    ITextSelection *me,
1417 1418 1419 1420
    LONG x,
    LONG y,
    LONG Type,
    LONG Extend)
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnScrollIntoView(
    ITextSelection *me,
1432
    LONG Value)
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetEmbeddedObject(
    ITextSelection *me,
    IUnknown **ppv)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

/*** ITextSelection methods ***/
static HRESULT WINAPI ITextSelection_fnGetFlags(
    ITextSelection *me,
1457
    LONG *pFlags)
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnSetFlags(
    ITextSelection *me,
1469
    LONG Flags)
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnGetType(
    ITextSelection *me,
1481
    LONG *pType)
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveLeft(
    ITextSelection *me,
1493 1494 1495 1496
    LONG Unit,
    LONG Count,
    LONG Extend,
    LONG *pDelta)
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveRight(
    ITextSelection *me,
1508 1509 1510 1511
    LONG Unit,
    LONG Count,
    LONG Extend,
    LONG *pDelta)
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveUp(
    ITextSelection *me,
1523 1524 1525 1526
    LONG Unit,
    LONG Count,
    LONG Extend,
    LONG *pDelta)
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnMoveDown(
    ITextSelection *me,
1538 1539 1540 1541
    LONG Unit,
    LONG Count,
    LONG Extend,
    LONG *pDelta)
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnHomeKey(
    ITextSelection *me,
1553 1554 1555
    LONG Unit,
    LONG Extend,
    LONG *pDelta)
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnEndKey(
    ITextSelection *me,
1567 1568 1569
    LONG Unit,
    LONG Extend,
    LONG *pDelta)
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ITextSelection_fnTypeText(
    ITextSelection *me,
    BSTR bstr)
{
    ITextSelectionImpl *This = (ITextSelectionImpl *) me;
    if (!This->reOle)
        return CO_E_RELEASED;

    FIXME("not implemented\n");
    return E_NOTIMPL;
}

static const ITextSelectionVtbl tsvt = {
    ITextSelection_fnQueryInterface,
    ITextSelection_fnAddRef,
    ITextSelection_fnRelease,
    ITextSelection_fnGetTypeInfoCount,
    ITextSelection_fnGetTypeInfo,
    ITextSelection_fnGetIDsOfNames,
    ITextSelection_fnInvoke,
    ITextSelection_fnGetText,
    ITextSelection_fnSetText,
    ITextSelection_fnGetChar,
    ITextSelection_fnSetChar,
    ITextSelection_fnGetDuplicate,
    ITextSelection_fnGetFormattedText,
    ITextSelection_fnSetFormattedText,
    ITextSelection_fnGetStart,
    ITextSelection_fnSetStart,
    ITextSelection_fnGetEnd,
    ITextSelection_fnSetEnd,
    ITextSelection_fnGetFont,
    ITextSelection_fnSetFont,
    ITextSelection_fnGetPara,
    ITextSelection_fnSetPara,
    ITextSelection_fnGetStoryLength,
    ITextSelection_fnGetStoryType,
    ITextSelection_fnCollapse,
    ITextSelection_fnExpand,
    ITextSelection_fnGetIndex,
    ITextSelection_fnSetIndex,
    ITextSelection_fnSetRange,
    ITextSelection_fnInRange,
    ITextSelection_fnInStory,
    ITextSelection_fnIsEqual,
    ITextSelection_fnSelect,
    ITextSelection_fnStartOf,
    ITextSelection_fnEndOf,
    ITextSelection_fnMove,
    ITextSelection_fnMoveStart,
    ITextSelection_fnMoveEnd,
    ITextSelection_fnMoveWhile,
    ITextSelection_fnMoveStartWhile,
    ITextSelection_fnMoveEndWhile,
    ITextSelection_fnMoveUntil,
    ITextSelection_fnMoveStartUntil,
    ITextSelection_fnMoveEndUntil,
    ITextSelection_fnFindText,
    ITextSelection_fnFindTextStart,
    ITextSelection_fnFindTextEnd,
    ITextSelection_fnDelete,
    ITextSelection_fnCut,
    ITextSelection_fnCopy,
    ITextSelection_fnPaste,
    ITextSelection_fnCanPaste,
    ITextSelection_fnCanEdit,
    ITextSelection_fnChangeCase,
    ITextSelection_fnGetPoint,
    ITextSelection_fnSetPoint,
    ITextSelection_fnScrollIntoView,
    ITextSelection_fnGetEmbeddedObject,
    ITextSelection_fnGetFlags,
    ITextSelection_fnSetFlags,
    ITextSelection_fnGetType,
    ITextSelection_fnMoveLeft,
    ITextSelection_fnMoveRight,
    ITextSelection_fnMoveUp,
    ITextSelection_fnMoveDown,
    ITextSelection_fnHomeKey,
    ITextSelection_fnEndKey,
    ITextSelection_fnTypeText
};

static ITextSelectionImpl *
CreateTextSelection(IRichEditOleImpl *reOle)
{
    ITextSelectionImpl *txtSel = heap_alloc(sizeof *txtSel);
    if (!txtSel)
        return NULL;

    txtSel->lpVtbl = &tsvt;
    txtSel->ref = 1;
    txtSel->reOle = reOle;
    return txtSel;
}

1675
LRESULT CreateIRichEditOle(ME_TextEditor *editor, LPVOID *ppObj)
1676 1677 1678
{
    IRichEditOleImpl *reo;

1679
    reo = heap_alloc(sizeof(IRichEditOleImpl));
1680 1681 1682
    if (!reo)
        return 0;

1683 1684
    reo->lpRichEditOleVtbl = &revt;
    reo->lpTextDocumentVtbl = &tdvt;
1685
    reo->ref = 1;
1686
    reo->editor = editor;
1687 1688 1689 1690 1691 1692
    reo->txtSel = CreateTextSelection(reo);
    if (!reo->txtSel)
    {
        heap_free(reo);
        return 0;
    }
1693 1694 1695 1696 1697 1698 1699
    reo->clientSite = CreateOleClientSite(reo);
    if (!reo->txtSel)
    {
        ITextSelection_Release((ITextSelection *) reo->txtSel);
        heap_free(reo);
        return 0;
    }
1700
    TRACE("Created %p\n",reo);
1701
    *ppObj = reo;
1702 1703 1704

    return 1;
}
1705

1706 1707 1708 1709 1710 1711 1712
static void convert_sizel(ME_Context *c, const SIZEL* szl, SIZE* sz)
{
  /* sizel is in .01 millimeters, sz in pixels */
  sz->cx = MulDiv(szl->cx, c->dpi.cx, 2540);
  sz->cy = MulDiv(szl->cy, c->dpi.cy, 2540);
}

1713 1714 1715 1716 1717
/******************************************************************************
 * ME_GetOLEObjectSize
 *
 * Sets run extent for OLE objects.
 */
1718
void ME_GetOLEObjectSize(ME_Context *c, ME_Run *run, SIZE *pSize)
1719 1720 1721 1722 1723 1724 1725 1726 1727
{
  IDataObject*  ido;
  FORMATETC     fmt;
  STGMEDIUM     stgm;
  DIBSECTION    dibsect;
  ENHMETAHEADER emh;

  assert(run->nFlags & MERF_GRAPHICS);
  assert(run->ole_obj);
1728 1729 1730 1731

  if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
  {
    convert_sizel(c, &run->ole_obj->sizel, pSize);
1732 1733 1734 1735 1736
    if (c->editor->nZoomNumerator != 0)
    {
      pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
      pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
    }
1737 1738 1739
    return;
  }

1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
  IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido);
  fmt.cfFormat = CF_BITMAP;
  fmt.ptd = NULL;
  fmt.dwAspect = DVASPECT_CONTENT;
  fmt.lindex = -1;
  fmt.tymed = TYMED_GDI;
  if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
  {
    fmt.cfFormat = CF_ENHMETAFILE;
    fmt.tymed = TYMED_ENHMF;
    if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
    {
      FIXME("unsupported format\n");
      pSize->cx = pSize->cy = 0;
      IDataObject_Release(ido);
      return;
    }
  }

  switch (stgm.tymed)
  {
  case TYMED_GDI:
    GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
    pSize->cx = dibsect.dsBm.bmWidth;
    pSize->cy = dibsect.dsBm.bmHeight;
    if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
    break;
  case TYMED_ENHMF:
    GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
    pSize->cx = emh.rclBounds.right - emh.rclBounds.left;
    pSize->cy = emh.rclBounds.bottom - emh.rclBounds.top;
    if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
    break;
  default:
    FIXME("Unsupported tymed %d\n", stgm.tymed);
    break;
  }
  IDataObject_Release(ido);
1778
  if (c->editor->nZoomNumerator != 0)
1779
  {
1780 1781
    pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
    pSize->cy = MulDiv(pSize->cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1782
  }
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
}

void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run,
                ME_Paragraph *para, BOOL selected)
{
  IDataObject*  ido;
  FORMATETC     fmt;
  STGMEDIUM     stgm;
  DIBSECTION    dibsect;
  ENHMETAHEADER emh;
  HDC           hMemDC;
1794
  SIZE          sz;
1795
  BOOL          has_size;
1796 1797 1798 1799 1800 1801 1802 1803

  assert(run->nFlags & MERF_GRAPHICS);
  assert(run->ole_obj);
  if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
  {
    FIXME("Couldn't get interface\n");
    return;
  }
1804
  has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
  fmt.cfFormat = CF_BITMAP;
  fmt.ptd = NULL;
  fmt.dwAspect = DVASPECT_CONTENT;
  fmt.lindex = -1;
  fmt.tymed = TYMED_GDI;
  if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
  {
    fmt.cfFormat = CF_ENHMETAFILE;
    fmt.tymed = TYMED_ENHMF;
    if (IDataObject_GetData(ido, &fmt, &stgm) != S_OK)
    {
      FIXME("Couldn't get storage medium\n");
      IDataObject_Release(ido);
      return;
    }
  }
  switch (stgm.tymed)
  {
  case TYMED_GDI:
    GetObjectW(stgm.u.hBitmap, sizeof(dibsect), &dibsect);
    hMemDC = CreateCompatibleDC(c->hDC);
    SelectObject(hMemDC, stgm.u.hBitmap);
1827
    if (has_size)
1828
    {
1829 1830 1831 1832 1833 1834 1835 1836 1837
      convert_sizel(c, &run->ole_obj->sizel, &sz);
    } else {
      sz.cx = MulDiv(dibsect.dsBm.bmWidth, c->dpi.cx, 96);
      sz.cy = MulDiv(dibsect.dsBm.bmHeight, c->dpi.cy, 96);
    }
    if (c->editor->nZoomNumerator != 0)
    {
      sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
      sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1838
    }
1839
    if (sz.cx == dibsect.dsBm.bmWidth && sz.cy == dibsect.dsBm.bmHeight)
1840
    {
1841 1842 1843 1844
      BitBlt(c->hDC, x, y - sz.cy,
             dibsect.dsBm.bmWidth, dibsect.dsBm.bmHeight,
             hMemDC, 0, 0, SRCCOPY);
    } else {
1845
      StretchBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy,
1846 1847
                 hMemDC, 0, 0, dibsect.dsBm.bmWidth,
                 dibsect.dsBm.bmHeight, SRCCOPY);
1848
    }
1849 1850 1851 1852
    if (!stgm.pUnkForRelease) DeleteObject(stgm.u.hBitmap);
    break;
  case TYMED_ENHMF:
    GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
1853
    if (has_size)
1854
    {
1855 1856 1857 1858
      convert_sizel(c, &run->ole_obj->sizel, &sz);
    } else {
      sz.cy = MulDiv(emh.rclBounds.bottom - emh.rclBounds.top, c->dpi.cx, 96);
      sz.cx = MulDiv(emh.rclBounds.right - emh.rclBounds.left, c->dpi.cy, 96);
1859
    }
1860
    if (c->editor->nZoomNumerator != 0)
1861
    {
1862 1863
      sz.cx = MulDiv(sz.cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
      sz.cy = MulDiv(sz.cy, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
1864
    }
1865

1866 1867 1868 1869 1870 1871 1872 1873
    {
      RECT    rc;

      rc.left = x;
      rc.top = y - sz.cy;
      rc.right = x + sz.cx;
      rc.bottom = y;
      PlayEnhMetaFile(c->hDC, stgm.u.hEnhMetaFile, &rc);
1874
    }
1875 1876 1877 1878
    if (!stgm.pUnkForRelease) DeleteEnhMetaFile(stgm.u.hEnhMetaFile);
    break;
  default:
    FIXME("Unsupported tymed %d\n", stgm.tymed);
1879
    selected = FALSE;
1880 1881
    break;
  }
1882 1883
  if (selected && !c->editor->bHideSelection)
    PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902
  IDataObject_Release(ido);
}

void ME_DeleteReObject(REOBJECT* reo)
{
    if (reo->poleobj)   IOleObject_Release(reo->poleobj);
    if (reo->pstg)      IStorage_Release(reo->pstg);
    if (reo->polesite)  IOleClientSite_Release(reo->polesite);
    FREE_OBJ(reo);
}

void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
{
    *dst = *src;

    if (dst->poleobj)   IOleObject_AddRef(dst->poleobj);
    if (dst->pstg)      IStorage_AddRef(dst->pstg);
    if (dst->polesite)  IOleClientSite_AddRef(dst->polesite);
}