From 98caf0bcecdeb62245fe39366022431578a7de72 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Tue, 27 Sep 2016 03:32:16 +0000 Subject: [PATCH] richmemo: win32 - restoring the context menu functioning, based on the patch by Andrey Korol git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5219 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/richmemo/win32/win32richmemo.pas | 103 +++++++++++++++++- .../richmemo/win32/win32richmemoole.pas | 87 +-------------- 2 files changed, 103 insertions(+), 87 deletions(-) diff --git a/components/richmemo/win32/win32richmemo.pas b/components/richmemo/win32/win32richmemo.pas index 7bd6e1a43..016d16595 100644 --- a/components/richmemo/win32/win32richmemo.pas +++ b/components/richmemo/win32/win32richmemo.pas @@ -30,7 +30,7 @@ uses // RTL headers Classes, SysUtils, // LCL headers - LCLType, LCLIntf, LCLProc, WSLCLClasses, + LCLType, LCLIntf, LCLProc, WSLCLClasses, LMessages, LCLMessageGlue, Graphics, Controls, StdCtrls, Printers, Themes, // Win32WidgetSet Win32WSControls, Win32Int, Win32WSStdCtrls, win32proc, @@ -1474,11 +1474,112 @@ begin SendMessage(Ahandle, EM_GETOLEINTERFACE, 0, LPARAM(@Result)); end; +type + { TRichEditCallback } + + TRichEditCallback = class(TInterfacedObject, IRichEditOleCallback) + public + fOwner: TWinControl; + function GetNewStorage(out stg: IStorage): HRESULT; stdcall; + function GetInPlaceContext(out Frame: IOleInPlaceFrame; + out Doc: IOleInPlaceUIWindow; + lpFrameInfo: POleInPlaceFrameInfo): HRESULT; stdcall; + function ShowContainerUI(fShow: BOOL): HRESULT; stdcall; + function QueryInsertObject(const clsid: TCLSID; const stg: IStorage; + cp: LongInt): HRESULT; stdcall; + function DeleteObject(const oleobj: IOleObject): HRESULT; stdcall; + function QueryAcceptData(const dataobj: IDataObject; + var cfFormat: TClipFormat; reco: DWORD; fReally: BOOL; + hMetaPict: HGLOBAL): HRESULT; stdcall; + function ContextSensitiveHelp(fEnterMode: BOOL): HRESULT; stdcall; + function GetClipboardData(const chrg: RichEdit.TCharRange; reco: DWORD; + out dataobj: IDataObject): HRESULT; stdcall; + function GetDragDropEffect(fDrag: BOOL; grfKeyState: DWORD; + var dwEffect: DWORD): HRESULT; stdcall; + function GetContextMenu(seltype: Word; oleobj: IOleObject; + const chrg: TCharRange; var menu: HMENU): HRESULT; stdcall; + end; + +{ TRichEditCallback } + +function TRichEditCallback.GetNewStorage(out stg: IStorage): HRESULT; stdcall; +begin + StgCreateDocfile(nil, STGM_READWRITE or STGM_SHARE_EXCLUSIVE, 0,stg); + Result := S_OK; +end; + +function TRichEditCallback.GetInPlaceContext(out Frame: IOleInPlaceFrame; out + Doc: IOleInPlaceUIWindow; lpFrameInfo: POleInPlaceFrameInfo): HRESULT; + stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.ShowContainerUI(fShow: BOOL): HRESULT; stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.QueryInsertObject(const clsid: TCLSID; + const stg: IStorage; cp: LongInt): HRESULT; stdcall; +begin + Result := S_OK; +end; + +function TRichEditCallback.DeleteObject(const oleobj: IOleObject): HRESULT; stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.QueryAcceptData(const dataobj: IDataObject; + var cfFormat: TClipFormat; reco: DWORD; fReally: BOOL; hMetaPict: HGLOBAL + ): HRESULT; stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.ContextSensitiveHelp(fEnterMode: BOOL): HRESULT; stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.GetClipboardData(const chrg: TCharRange; reco: DWORD; out + dataobj: IDataObject): HRESULT; stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.GetDragDropEffect(fDrag: BOOL; grfKeyState: DWORD; + var dwEffect: DWORD): HRESULT; stdcall; +begin + Result := E_NOTIMPL; +end; + +function TRichEditCallback.GetContextMenu(seltype: Word; oleobj: IOleObject; + const chrg: TCharRange; var menu: HMENU): HRESULT; stdcall; +var + msg : TLMContextMenu; +begin + FillChar(msg, sizeof(msg), 0); + msg.Msg:=LM_CONTEXTMENU; + msg.XPos:=Mouse.CursorPos.x; + msg.YPos:=Mouse.CursorPos.y; + msg.hWnd:=fOwner.Handle; + DeliverMessage(fOwner, msg); + + // do not give hmenu back to RichEdit, it will destory it! + menu:=0; + Result:=S_OK; +end; + + + procedure DefAllocOleObject(ARichMemo: TCustomRichMemo; AHandle: Windows.THandle; out OleCallback: IRichEditOleCallback); var cb : TRichEditCallback; begin cb:=TRichEditCallback.Create; + cb.fOwner:=ARichMemo; OleCallBack:=cb; end; diff --git a/components/richmemo/win32/win32richmemoole.pas b/components/richmemo/win32/win32richmemoole.pas index e34307da7..d28b4b480 100644 --- a/components/richmemo/win32/win32richmemoole.pas +++ b/components/richmemo/win32/win32richmemoole.pas @@ -21,7 +21,7 @@ unit Win32RichMemoOle; interface uses - Windows, ActiveX, ComObj, Win32RichMemoProc, RichEdit; + Windows, ActiveX, ComObj, Win32RichMemoProc; {.$define oledebug} @@ -80,93 +80,8 @@ type function Getadvise(paspects:pdword;padvf:pdword;out ppadvsink: IADviseSink):HRESULT;stdcall; end; - { TRichEditCallback } - - TRichEditCallback = class(TInterfacedObject, IRichEditOleCallback) - function GetNewStorage(out stg: IStorage): HRESULT; stdcall; - function GetInPlaceContext(out Frame: IOleInPlaceFrame; - out Doc: IOleInPlaceUIWindow; - lpFrameInfo: POleInPlaceFrameInfo): HRESULT; stdcall; - function ShowContainerUI(fShow: BOOL): HRESULT; stdcall; - function QueryInsertObject(const clsid: TCLSID; const stg: IStorage; - cp: LongInt): HRESULT; stdcall; - function DeleteObject(const oleobj: IOleObject): HRESULT; stdcall; - function QueryAcceptData(const dataobj: IDataObject; - var cfFormat: TClipFormat; reco: DWORD; fReally: BOOL; - hMetaPict: HGLOBAL): HRESULT; stdcall; - function ContextSensitiveHelp(fEnterMode: BOOL): HRESULT; stdcall; - function GetClipboardData(const chrg: RichEdit.TCharRange; reco: DWORD; - out dataobj: IDataObject): HRESULT; stdcall; - function GetDragDropEffect(fDrag: BOOL; grfKeyState: DWORD; - var dwEffect: DWORD): HRESULT; stdcall; - function GetContextMenu(seltype: Word; oleobj: IOleObject; - const chrg: TCharRange; var menu: HMENU): HRESULT; stdcall; - end; - - implementation -{ TRichEditCallback } - -function TRichEditCallback.GetNewStorage(out stg: IStorage): HRESULT; stdcall; -begin - StgCreateDocfile(nil, STGM_READWRITE or STGM_SHARE_EXCLUSIVE, 0,stg); - Result := S_OK; -end; - -function TRichEditCallback.GetInPlaceContext(out Frame: IOleInPlaceFrame; out - Doc: IOleInPlaceUIWindow; lpFrameInfo: POleInPlaceFrameInfo): HRESULT; - stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.ShowContainerUI(fShow: BOOL): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.QueryInsertObject(const clsid: TCLSID; - const stg: IStorage; cp: LongInt): HRESULT; stdcall; -begin - Result := S_OK; -end; - -function TRichEditCallback.DeleteObject(const oleobj: IOleObject): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.QueryAcceptData(const dataobj: IDataObject; - var cfFormat: TClipFormat; reco: DWORD; fReally: BOOL; hMetaPict: HGLOBAL - ): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.ContextSensitiveHelp(fEnterMode: BOOL): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.GetClipboardData(const chrg: TCharRange; reco: DWORD; out - dataobj: IDataObject): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.GetDragDropEffect(fDrag: BOOL; grfKeyState: DWORD; - var dwEffect: DWORD): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - -function TRichEditCallback.GetContextMenu(seltype: Word; oleobj: IOleObject; - const chrg: TCharRange; var menu: HMENU): HRESULT; stdcall; -begin - Result := E_NOTIMPL; -end; - { TCustomObject } function TCustomObject.SetClientSite(const clientSite: IOleClientSite