module Metasm::Gui::TextWidget

Attributes

caret_x[RW]
caret_y[RW]
font_height[RW]
font_width[RW]
hl_word[RW]
hl_word_re[RW]

Public Instance Methods

clipboard_copy(buf) click to toggle source
# File metasm/gui/win32.rb, line 1753
def clipboard_copy(buf)
        Win32Gui.openclipboard(@hwnd)
        Win32Gui.emptyclipboard
        if buf and not buf.empty?
                h = Win32Gui.globalalloc(Win32Gui::GMEM_MOVEABLE, buf.length+1)
                ptr = Win32Gui.globallock(h)
                Win32Gui.memory_write(ptr, buf)
                Win32Gui.globalunlock(h)
                Win32Gui.setclipboarddata(Win32Gui::CF_TEXT, h)
                # on(WM_DESTROYCLIPBOARD) { Win32Gui.globalfree(h) }
        end
        Win32Gui.closeclipboard
end
clipboard_paste() click to toggle source
# File metasm/gui/win32.rb, line 1767
def clipboard_paste
        Win32Gui.openclipboard(@hwnd)
        h = Win32Gui.getclipboarddata(Win32Gui::CF_TEXT)
        if h and h != 0 and h != Win32Gui::GMEM_INVALID_HANDLE
                sz = Win32Gui.globalsize(h)
                ptr = Win32Gui.globallock(h)
                buf = Win32Gui.memory_read(ptr, sz)
                Win32Gui.globalunlock(h)
                Win32Gui.closeclipboard
                buf.chomp(0.chr)
        end
end
initialize_text() click to toggle source
# File metasm/gui/win32.rb, line 1719
def initialize_text
        @caret_x = @caret_y = 0               # text cursor position
        @oldcaret_x = @oldcaret_y = 1
        @font_width = @font_height = 1
        @hl_word = nil
end
invalidate_caret(cx, cy, x=0, y=0) click to toggle source
# File metasm/gui/win32.rb, line 1749
def invalidate_caret(cx, cy, x=0, y=0)
        invalidate(x + cx*@font_width, y + cy*@font_height, 2, @font_height)
end
set_caret_from_click(x, y) click to toggle source
# File metasm/gui/win32.rb, line 1743
def set_caret_from_click(x, y)
        @caret_x = (x-1).to_i / @font_width
        @caret_y = y.to_i / @font_height
        update_caret
end
set_font(todo) click to toggle source
# File metasm/gui/win32.rb, line 1780
def set_font(todo)
        hdc = Win32Gui.getdc(@hwnd)
        # selectobject(hdc, hfont)
        sz = Win32Gui.alloc_c_struct('POINT')
        Win32Gui.gettextextentpoint32a(hdc, 'x', 1, sz)
        @font_width = sz[:x]
        @font_height = sz[:y]
        Win32Gui.releasedc(@hwnd, hdc)
end
update_hl_word(line, offset, mode=:asm) click to toggle source
# File metasm/gui/win32.rb, line 1726
def update_hl_word(line, offset, mode=:asm)
        return if not line
        word = line[0...offset].to_s[/\w*$/] << line[offset..-1].to_s[/^\w*/]
        word = nil if word == ''
        if @hl_word != word
                if word
                        if mode == :asm and defined?(@dasm) and @dasm
                                re = @dasm.gui_hilight_word_regexp(word)
                        else
                                re = Regexp.escape(word)
                        end
                        @hl_word_re = /^(.*?)(\b(?:#{re})\b)/
                end
                @hl_word = word
        end
end