Class: Fzeet::FontDialog

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

Constant Summary collapse

DialogStruct =
Windows::CHOOSEFONT
HookProc =
-> *args { CommonDialog::HookProc.(*args.unshift(DialogStruct)) }

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, #size, #size=, #style, #style?, #text, #text=, #textlen, #topmost=, #topmost?, #update, #visible=, #visible?, #xstyle, #xstyle?

Methods included from Toggle

#toggle

Constructor Details

#initialize(opts = {}) ⇒ FontDialog

Returns a new instance of FontDialog.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fzeet/windows/comdlg/FontDialog.rb', line 103

def initialize(opts = {})
  _opts = {
    font: Control::Font,
    color: 0
  }
  badopts = opts.keys - _opts.keys; raise "Bad option(s): #{badopts.join(', ')}." unless badopts.empty?
  _opts.merge!(opts)

  @struct = DialogStruct.new

  @struct[:lStructSize] = @struct.size
  @struct[:hInstance] = Windows.GetModuleHandle(nil)
  @struct[:lpLogFont] = _opts[:font].logfont.pointer
  @struct[:Flags] = Fzeet.flags([:enablehook, :both, :inittologfontstruct, :effects], :cf_)
  @struct[:rgbColors] = _opts[:color]
  @struct[:lCustData] = object_id
  @struct[:lpfnHook] = HookProc

  super()
end

Instance Method Details

#colorObject



131
# File 'lib/fzeet/windows/comdlg/FontDialog.rb', line 131

def color; @struct[:rgbColors] end

#fontObject



130
# File 'lib/fzeet/windows/comdlg/FontDialog.rb', line 130

def font; IndirectFont.new(Windows::LOGFONT.new(@struct[:lpLogFont])) end

#show(window = Application.window) ⇒ Object



124
125
126
127
128
# File 'lib/fzeet/windows/comdlg/FontDialog.rb', line 124

def show(window = Application.window)
  @struct[:hwndOwner] = window.handle

  DialogResult.new((Windows.ChooseFont(@struct) == 0) ? Windows::IDCANCEL : Windows::IDOK)
end