Commit 0154b59c authored by Jactry Zeng's avatar Jactry Zeng Committed by Alexandre Julliard

riched20: Save reobj in linked list.

parent ea718634
......@@ -471,12 +471,26 @@ ME_InternalInsertTextFromCursor(ME_TextEditor *editor, int nCursor,
return ME_InsertRunAtCursor(editor, p, style, str, len, flags);
}
static struct re_object* create_re_object(const REOBJECT *reo)
{
struct re_object *reobj = heap_alloc(sizeof(*reobj));
if (!reobj)
{
WARN("Fail to allocate re_object.\n");
return NULL;
}
ME_CopyReObject(&reobj->obj, reo);
return reobj;
}
void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor)
{
ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
ME_DisplayItem *di;
WCHAR space = ' ';
ME_DisplayItem *di_prev = NULL;
struct re_object *reobj_prev = NULL;
/* FIXME no no no */
if (ME_IsSelection(editor))
......@@ -484,8 +498,22 @@ void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCur
di = ME_InternalInsertTextFromCursor(editor, nCursor, &space, 1, pStyle,
MERF_GRAPHICS);
di->member.run.ole_obj = heap_alloc(sizeof(*reo));
ME_CopyReObject(di->member.run.ole_obj, reo);
di->member.run.reobj = create_re_object(reo);
di_prev = di;
while (ME_PrevRun(NULL, &di_prev, TRUE))
{
if (di_prev->member.run.reobj)
{
reobj_prev = di_prev->member.run.reobj;
break;
}
}
if (reobj_prev)
list_add_after(&reobj_prev->entry, &di->member.run.reobj->entry);
else
list_add_head(&editor->reobj_list, &di->member.run.reobj->entry);
ME_ReleaseStyle(pStyle);
}
......
......@@ -3113,6 +3113,7 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->wheel_remain = 0;
list_init( &ed->style_list );
list_init( &ed->reobj_list );
OleInitialize(NULL);
return ed;
......
......@@ -232,7 +232,7 @@ LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *p
void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run* run, BOOL selected) DECLSPEC_HIDDEN;
void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize) DECLSPEC_HIDDEN;
void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src) DECLSPEC_HIDDEN;
void ME_DeleteReObject(REOBJECT* reo) DECLSPEC_HIDDEN;
void ME_DeleteReObject(struct re_object *re_object) DECLSPEC_HIDDEN;
void ME_GetITextDocumentInterface(IRichEditOle *iface, LPVOID *ppvObj) DECLSPEC_HIDDEN;
/* editor.c */
......
......@@ -153,6 +153,12 @@ typedef enum {
struct tagME_DisplayItem;
struct re_object
{
struct list entry;
REOBJECT obj;
};
typedef struct tagME_Run
{
ME_Style *style;
......@@ -163,7 +169,7 @@ typedef struct tagME_Run
int nFlags;
int nAscent, nDescent; /* pixels above/below baseline */
POINT pt; /* relative to para's position */
REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
struct re_object *reobj; /* FIXME: should be a union with strText (at least) */
SCRIPT_ANALYSIS script_analysis;
int num_glyphs, max_glyphs;
......@@ -436,6 +442,7 @@ typedef struct tagME_TextEditor
BOOL bMouseCaptured;
int wheel_remain;
struct list style_list;
struct list reobj_list;
} ME_TextEditor;
typedef struct tagME_Context
......
......@@ -169,7 +169,11 @@ void ME_DestroyDisplayItem(ME_DisplayItem *item)
if (item->type==diRun)
{
if (item->member.run.ole_obj) ME_DeleteReObject(item->member.run.ole_obj);
if (item->member.run.reobj)
{
list_remove(&item->member.run.reobj->entry);
ME_DeleteReObject(item->member.run.reobj);
}
heap_free( item->member.run.glyphs );
heap_free( item->member.run.clusters );
ME_ReleaseStyle(item->member.run.style);
......
......@@ -5284,11 +5284,11 @@ void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
ENHMETAHEADER emh;
assert(run->nFlags & MERF_GRAPHICS);
assert(run->ole_obj);
assert(run->reobj);
if (run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0)
if (run->reobj->obj.sizel.cx != 0 || run->reobj->obj.sizel.cy != 0)
{
convert_sizel(c, &run->ole_obj->sizel, pSize);
convert_sizel(c, &run->reobj->obj.sizel, pSize);
if (c->editor->nZoomNumerator != 0)
{
pSize->cx = MulDiv(pSize->cx, c->editor->nZoomNumerator, c->editor->nZoomDenominator);
......@@ -5297,13 +5297,13 @@ void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize)
return;
}
if (!run->ole_obj->poleobj)
if (!run->reobj->obj.poleobj)
{
pSize->cx = pSize->cy = 0;
return;
}
if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
if (IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
{
FIXME("Query Interface IID_IDataObject failed!\n");
pSize->cx = pSize->cy = 0;
......@@ -5366,13 +5366,13 @@ void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run, BOOL selected)
RECT rc;
assert(run->nFlags & MERF_GRAPHICS);
assert(run->ole_obj);
if (IOleObject_QueryInterface(run->ole_obj->poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
assert(run->reobj);
if (IOleObject_QueryInterface(run->reobj->obj.poleobj, &IID_IDataObject, (void**)&ido) != S_OK)
{
FIXME("Couldn't get interface\n");
return;
}
has_size = run->ole_obj->sizel.cx != 0 || run->ole_obj->sizel.cy != 0;
has_size = run->reobj->obj.sizel.cx != 0 || run->reobj->obj.sizel.cy != 0;
fmt.cfFormat = CF_BITMAP;
fmt.ptd = NULL;
fmt.dwAspect = DVASPECT_CONTENT;
......@@ -5399,7 +5399,7 @@ void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run, BOOL selected)
old_bm = SelectObject(hMemDC, stgm.u.hBitmap);
if (has_size)
{
convert_sizel(c, &run->ole_obj->sizel, &sz);
convert_sizel(c, &run->reobj->obj.sizel, &sz);
} else {
sz.cx = dibsect.dsBm.bmWidth;
sz.cy = dibsect.dsBm.bmHeight;
......@@ -5419,7 +5419,7 @@ void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run, BOOL selected)
GetEnhMetaFileHeader(stgm.u.hEnhMetaFile, sizeof(emh), &emh);
if (has_size)
{
convert_sizel(c, &run->ole_obj->sizel, &sz);
convert_sizel(c, &run->reobj->obj.sizel, &sz);
} else {
sz.cx = emh.rclBounds.right - emh.rclBounds.left;
sz.cy = emh.rclBounds.bottom - emh.rclBounds.top;
......@@ -5447,12 +5447,12 @@ void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run *run, BOOL selected)
PatBlt(c->hDC, x, y - sz.cy, sz.cx, sz.cy, DSTINVERT);
}
void ME_DeleteReObject(REOBJECT* reo)
void ME_DeleteReObject(struct re_object *reobj)
{
if (reo->poleobj) IOleObject_Release(reo->poleobj);
if (reo->pstg) IStorage_Release(reo->pstg);
if (reo->polesite) IOleClientSite_Release(reo->polesite);
heap_free(reo);
if (reobj->obj.poleobj) IOleObject_Release(reobj->obj.poleobj);
if (reobj->obj.pstg) IStorage_Release(reobj->obj.pstg);
if (reobj->obj.polesite) IOleClientSite_Release(reobj->obj.polesite);
heap_free(reobj);
}
void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
......
......@@ -290,7 +290,7 @@ ME_DisplayItem *ME_MakeRun(ME_Style *s, int nFlags)
{
ME_DisplayItem *item = ME_MakeDI(diRun);
item->member.run.style = s;
item->member.run.ole_obj = NULL;
item->member.run.reobj = NULL;
item->member.run.nFlags = nFlags;
item->member.run.nCharOfs = -1;
item->member.run.len = 0;
......
......@@ -947,7 +947,7 @@ static BOOL stream_out_graphics( ME_TextEditor *editor, ME_OutStream *stream,
SIZE goal, pic;
ME_Context c;
hr = IOleObject_QueryInterface( run->ole_obj->poleobj, &IID_IDataObject, (void **)&data );
hr = IOleObject_QueryInterface( run->reobj->obj.poleobj, &IID_IDataObject, (void **)&data );
if (FAILED(hr)) return FALSE;
ME_InitContext( &c, editor, ITextHost_TxGetDC( editor->texthost ) );
......@@ -975,8 +975,8 @@ static BOOL stream_out_graphics( ME_TextEditor *editor, ME_OutStream *stream,
emf_bits->szlMillimeters.cy * c.dpi.cy * 10 );
/* convert goal size to twips */
goal.cx = MulDiv( run->ole_obj->sizel.cx, 144, 254 );
goal.cy = MulDiv( run->ole_obj->sizel.cy, 144, 254 );
goal.cx = MulDiv( run->reobj->obj.sizel.cx, 144, 254 );
goal.cy = MulDiv( run->reobj->obj.sizel.cy, 144, 254 );
if (!ME_StreamOutPrint( stream, "{\\*\\shppict{\\pict\\emfblip\\picw%d\\pich%d\\picwgoal%d\\pichgoal%d\n",
pic.cx, pic.cy, goal.cx, goal.cy ))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment