G33kDude / RichCode.ahk

A wrapper around a RichEdit control to provide code editing features.
MIT License
16 stars 8 forks source link

The Contextmenu Doesn't Work Properly. #8

Open nperovic opened 1 year ago

nperovic commented 1 year ago

https://github.com/G33kDude/RichCode.ahk/blob/9a54252d193dbafeccb86b9e751cb36c8c8f5548/RichCode.ahk#L207-L241

I apologise for not being able to point out exactly where the problem is, but this is what I have done so far to fix it. I'm sure you'll understand as soon as you see it.

; Create the right click menu
this.menu := Menu()
for Index, Entry in RichCode.MenuItems
    this.menu.Add(Entry?, IsSet(Entry) ? RightClickMenu : unset)

; Get the ITextDocument object
bufpIRichEditOle := Buffer(A_PtrSize, 0)
this.SendMsg(0x43C, 0, bufpIRichEditOle) ; EM_GETOLEINTERFACE
this.pIRichEditOle := NumGet(bufpIRichEditOle, "UPtr")
this.IRichEditOle := ComValue(9, this.pIRichEditOle, 1)
; ObjAddRef(this.pIRichEditOle)
this.pITextDocument := ComObjQuery(this.IRichEditOle, RichCode.IID_ITextDocument)
this.ITextDocument := ComValue(9, this.pITextDocument, 1)
; ObjAddRef(this.pITextDocument)

RightClickMenu(ItemName, ItemPos, MenuName)
{
    Switch ItemName {
    case "Cut"       : A_Clipboard := this.SelectedText, this.SelectedText := ""
    case "Copy"      : A_Clipboard := this.SelectedText
    case "Paste"     : this.SelectedText := A_Clipboard
    case "Delete"    : this.SelectedText := ""
    case "Select All": this.Selection    := [0, -1]
    case "UPPERCASE" : this.SelectedText := Format("{:U}", this.SelectedText)
    case "lowercase" : this.SelectedText := Format("{:L}", this.SelectedText)
    case "TitleCase" : this.SelectedText := Format("{:T}", this.SelectedText)
    }
}