Class: Fzeet::CommonDialog

Inherits:
Handle
  • Object
show all
Includes:
WindowMethods
Defined in:
lib/fzeet/windows/comdlg/Common.rb

Direct Known Subclasses

ColorDialog, FileDialog, FolderDialog, FontDialog

Constant Summary collapse

HookProc =
-> klass, hwnd, uMsg, wParam, lParam {
	begin
		if klass == Windows::BROWSEINFO
			if uMsg == Windows::BFFM_IUNKNOWN
				instance = ObjectSpace._id2ref(lParam)

				if @@instances.include?(hwnd.to_i)
					@@instances.delete(hwnd.to_i)
				else
					@@instances[hwnd.to_i] = instance

					@@instances[hwnd.to_i].instance_variable_set(:@handle, hwnd)
				end
			end
		else
			if uMsg == Windows::WM_INITDIALOG
				@@instances[hwnd.to_i] = ObjectSpace._id2ref(
					klass.new(FFI::Pointer.new(lParam))[:lCustData].to_i
				)

				@@instances[hwnd.to_i].instance_variable_set(:@handle, hwnd)
			end
		end

		result = @@instances[hwnd.to_i].hookProc(hwnd, uMsg, wParam, lParam) if @@instances[hwnd.to_i]
	rescue
		answer = Fzeet.message %Q{#{$!}\n\n#{$!.backtrace.join("\n")}}, buttons: [:abort, :retry, :ignore], icon: :error

		Application.quit if answer.abort?
	ensure
		if uMsg == Windows::WM_NCDESTROY
			@@instances.delete(hwnd.to_i)
		end
	end

	result || 0
}

Constants included from WindowMethods

WindowMethods::EnumChildProc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#initializeCommonDialog

Returns a new instance of CommonDialog.



104
105
106
# File 'lib/fzeet/windows/comdlg/Common.rb', line 104

def initialize
	@messages = {}
end

Instance Attribute Details

#structObject (readonly)

Returns the value of attribute struct.



108
109
110
# File 'lib/fzeet/windows/comdlg/Common.rb', line 108

def struct
  @struct
end

Class Method Details

.crackMessage(hwnd, uMsg, wParam, lParam) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fzeet/windows/comdlg/Common.rb', line 88

def self.crackMessage(hwnd, uMsg, wParam, lParam)
	window = @@instances[hwnd.to_i]

	args = {
		hwnd: hwnd,
		uMsg: uMsg,
		wParam: wParam,
		lParam: lParam,
		result: 0,
		window: window,
		sender: window
	}

	args
end

Instance Method Details

#hookProc(hwnd, uMsg, wParam, lParam) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fzeet/windows/comdlg/Common.rb', line 110

def hookProc(hwnd, uMsg, wParam, lParam)
	args, result = nil, nil

	if (handlers = @messages[uMsg])
		args ||= self.class.crackMessage(hwnd, uMsg, wParam, lParam)

		handlers.each { |handler|
			(handler.arity == 0) ? handler.call : handler.call(args)

			result = args[:result]
		}
	end

	result
end

#on(msg, &block) ⇒ Object



126
127
128
129
130
# File 'lib/fzeet/windows/comdlg/Common.rb', line 126

def on(msg, &block)
	(@messages[Fzeet.constant(msg, :wm_)] ||= []) << block

	self
end