Class: Fzeet::FindReplaceDialog

Inherits:
CommonDialog show all
Defined in:
lib/fzeet/windows/comdlg/FindReplaceDialog.rb

Direct Known Subclasses

FindDialog, ReplaceDialog

Constant Summary collapse

DialogStruct =
Windows::FINDREPLACE
HookProc =
-> *args { CommonDialog::HookProc.(*args.unshift(DialogStruct)) }
Message =
Windows.DetonateLastError(0, :RegisterWindowMessage, Windows::FINDMSGSTRING)

Constants included from WindowMethods

WindowMethods::EnumChildProc

Instance Attribute Summary

Attributes inherited from CommonDialog

#struct

Instance Method Summary collapse

Methods inherited from CommonDialog

crackMessage, #hookProc, #on

Methods included from WindowMethods

#[], #capture=, #capture?, #dialog=, #dialog?, #dlgmsg?, #drawMenuBar, #eachChild, #enabled=, #enabled?, #focus=, #focus?, #invalidate, #location, #location=, #long, #menu, #menu=, #message, #paint, #position, #position=, #postmsg, #question, #rect, #reframe, #sendmsg, #show, #size, #size=, #style, #style?, #text, #text=, #textlen, #topmost=, #topmost?, #update, #visible=, #visible?, #xstyle, #xstyle?

Methods included from Toggle

#toggle

Constructor Details

#initialize(opts = {}) ⇒ FindReplaceDialog



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fzeet/windows/comdlg/FindReplaceDialog.rb', line 77

def initialize(opts = {})
  _opts = {

  }
  badopts = opts.keys - _opts.keys; raise "Bad option(s): #{badopts.join(', ')}." unless badopts.empty?
  _opts.merge!(opts)

  @frNotifies = {}

  @struct = DialogStruct.new

  @struct[:lStructSize] = @struct.size
  @struct[:hInstance] = Windows.GetModuleHandle(nil)
  @struct[:Flags] = Fzeet.flags(:enablehook, :fr_)
  @struct[:lpstrFindWhat] = @findbuf = FFI::MemoryPointer.new(:char, 4096)
  @struct[:lpstrReplaceWith] = @replacebuf = FFI::MemoryPointer.new(:char, 4096)
  @struct[:wFindWhatLen] = @findbuf.size
  @struct[:wReplaceWithLen] = @replacebuf.size
  @struct[:lCustData] = object_id
  @struct[:lpfnHook] = HookProc

  super()
end

Instance Method Details

#disposeObject



101
# File 'lib/fzeet/windows/comdlg/FindReplaceDialog.rb', line 101

def dispose; [@findbuf, @replacebuf].each(&:free) end

#findWhatObject



103
# File 'lib/fzeet/windows/comdlg/FindReplaceDialog.rb', line 103

def findWhat; @findbuf.read_string end

#frProc(args) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fzeet/windows/comdlg/FindReplaceDialog.rb', line 106

def frProc(args)
  return unless args[:lParam] == @struct.pointer.address

  (handlers = @frNotifies[:all]) and handlers.each { |handler|
    (handler.arity == 0) ? handler.call : handler.call(args)
  }

  if @struct[:Flags] & Windows::FR_DIALOGTERM != 0
    (handlers = @frNotifies[Windows::FR_DIALOGTERM]) and handlers.each { |handler|
      (handler.arity == 0) ? handler.call : handler.call(args)
    }

    self.dialog = false

    dispose
  elsif @struct[:Flags] & Windows::FR_FINDNEXT != 0
    (handlers = @frNotifies[Windows::FR_FINDNEXT]) and handlers.each { |handler|
      (handler.arity == 0) ? handler.call : handler.call(args)
    }
  elsif @struct[:Flags] & Windows::FR_REPLACE != 0
    (handlers = @frNotifies[Windows::FR_REPLACE]) and handlers.each { |handler|
      (handler.arity == 0) ? handler.call : handler.call(args)
    }
  elsif @struct[:Flags] & Windows::FR_REPLACEALL != 0
    (handlers = @frNotifies[Windows::FR_REPLACEALL]) and handlers.each { |handler|
      (handler.arity == 0) ? handler.call : handler.call(args)
    }
  end
end

#onNotify(notification, &block) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/fzeet/windows/comdlg/FindReplaceDialog.rb', line 136

def onNotify(notification, &block)
  notification = Fzeet.constant(notification, :fr_) unless
    notification.kind_of?(Integer) || notification == :all

  (@frNotifies[notification] ||= []) << block

  self
end

#replaceWithObject



104
# File 'lib/fzeet/windows/comdlg/FindReplaceDialog.rb', line 104

def replaceWith; @replacebuf.read_string end