class Fzeet::UIRibbon
Attributes
hdll[R]
uia[R]
uich[R]
uif[R]
window[R]
Public Class Methods
new(_window, opts = {})
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 576 def initialize(_window, opts = {}) handlers = {} opts.delete_if { |k, v| next false unless v.kind_of?(Proc) handlers[k] = v; true } _opts = { name: Application.name, resname: 'APPLICATION_RIBBON' } badopts = opts.keys - _opts.keys; raise "Bad option(s): #{badopts.join(', ')}." unless badopts.empty? _opts.merge!(opts) @creates = [] @destroys = [] @sizes = [] @executesAllVerbs = {} @executesExecute = {} @executesPreview = {} @executesCancelPreview = {} @updatesAllKeys = {} @window = _window window.instance_variable_set(:@ribbon, self) class << window attr_reader :ribbon end @uich = Windows::UICommandHandler.new uich.instance_variable_set(:@ribbon, self) class << uich attr_reader :ribbon def Execute(*args) ribbon.execute(*args); Windows::S_OK end def UpdateProperty(*args) ribbon.update(*args); Windows::S_OK end end @uia = Windows::UIApplication.new uia.instance_variable_set(:@uich, @uich) class << uia attr_reader :uich, :uir def OnViewChanged(viewId, typeId, view, verb, reason) return Windows::S_OK unless typeId == Windows::UI_VIEWTYPE_RIBBON args = { viewId: viewId, typeId: typeId, view: view, verb: verb, reason: reason, ribbon: self, sender: self } case verb when Windows::UI_VIEWVERB_CREATE @uir = Windows::Unknown.new(view).QueryInstance(Windows::UIRibbon) uir.instance_variable_set(:@height, 0) class << uir attr_accessor :height end uich.ribbon.instance_variable_get(:@creates).each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } when Windows::UI_VIEWVERB_DESTROY uich.ribbon.instance_variable_get(:@destroys).each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } uir.Release when Windows::UI_VIEWVERB_SIZE FFI::MemoryPointer.new(:uint) { |p| uir.GetHeight(p); uir.height = p.read_int } uich.ribbon.instance_variable_get(:@sizes).each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } end Windows::S_OK rescue Fzeet.message %Q{#{$!}\n\n#{$!.backtrace.join("\n")}}, icon: :error Windows::S_OK end def OnCreateUICommand(*args) uich.QueryInterface(uich.class::IID, args[-1]); Windows::S_OK end end @hdll = Windows.LoadRibbonDll(_opts[:name]) handlers.each { |k, v| k[1] = Object.const_get(k[1]) if k.length > 1 on(*k, &v) } @uif = Windows::UIFramework.new uif.Initialize(window.handle, uia) uif.LoadUI(@hdll, "#{_opts[:resname]}\0".encode('utf-16le')) window.on(:destroy) { raise unless uif.Destroy == Windows::S_OK; raise unless uif.Release == 0 raise unless uia.Release == 0 raise unless uich.Release == 0 } end
Public Instance Methods
[](id)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 470 def [](id) Command.new(self, id) end
background()
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 495 def background hsb = nil uif.QueryInstance(Windows::PropertyStore) { |ps| hsb = ps.uiprop(:GlobalBackgroundColor).uint } Color.enhance([Windows::UI_GetHValue(hsb), Windows::UI_GetSValue(hsb), Windows::UI_GetBValue(hsb)], self, __method__) end
background=(hsb)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 505 def background=(hsb) uif.QueryInstance(Windows::PropertyStore) { |ps| ps.uiprop(:GlobalBackgroundColor, Windows::PROPVARIANT[:uint, Windows::UI_HSB(*hsb)]).commit } end
color()
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 511 def color hsb = nil uif.QueryInstance(Windows::PropertyStore) { |ps| hsb = ps.uiprop(:GlobalTextColor).uint } Color.enhance([Windows::UI_GetHValue(hsb), Windows::UI_GetSValue(hsb), Windows::UI_GetBValue(hsb)], self, __method__) end
color=(hsb)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 521 def color=(hsb) uif.QueryInstance(Windows::PropertyStore) { |ps| ps.uiprop(:GlobalTextColor, Windows::PROPVARIANT[:uint, Windows::UI_HSB(*hsb)]).commit } end
contextualUI(id, x, y)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 815 def contextualUI(id, x, y) uif.UseInstance(Windows::UIContextualUI, :GetView, id) { |view| view.ShowAtLocation(x, y) } self end
execute(commandId, verb, key, value, props)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 701 def execute(commandId, verb, key, value, props) args = { commandId: commandId, verb: verb, key: (key.null?) ? nil : Windows::PROPERTYKEY.new(key), value: (value.null?) ? nil : Windows::PROPVARIANT.new(value), props: (props.null?) ? nil : Windows::UISimplePropertySet.new(props), ribbon: self, sender: Command.new(self, commandId) } (handlers = @executesAllVerbs[commandId]) and handlers.each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } case verb when Windows::UI_EXECUTIONVERB_EXECUTE (handlers = @executesExecute[commandId]) and handlers.each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } when Windows::UI_EXECUTIONVERB_PREVIEW (handlers = @executesPreview[commandId]) and handlers.each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } when Windows::UI_EXECUTIONVERB_CANCELPREVIEW (handlers = @executesCancelPreview[commandId]) and handlers.each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } end self rescue Fzeet.message %Q{#{$!}\n\n#{$!.backtrace.join("\n")}}, icon: :error self end
fontPropsChanged(args) { |ps| ... }
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 803 def fontPropsChanged(args) return self unless args[:key] == Windows::UI_PKEY_FontProperties args[:props].uiprop(:FontProperties_ChangedProperties).unknown { |changed| changed.QueryInstance(Windows::PropertyStore) { |ps| yield ps } } self end
fontPropsUpdate(args) { |ps| ... }
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 789 def fontPropsUpdate(args) return self unless args[:key] == Windows::UI_PKEY_FontProperties args[:value].unknown { |current| current.QueryInstance(Windows::PropertyStore) { |ps| yield ps args[:newValue].unknown = current } } self end
height()
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 699 def height; uia.uir.height end
highlight()
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 527 def highlight hsb = nil uif.QueryInstance(Windows::PropertyStore) { |ps| hsb = ps.uiprop(:GlobalHighlightColor).uint } Color.enhance([Windows::UI_GetHValue(hsb), Windows::UI_GetSValue(hsb), Windows::UI_GetBValue(hsb)], self, __method__) end
highlight=(hsb)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 537 def highlight=(hsb) uif.QueryInstance(Windows::PropertyStore) { |ps| ps.uiprop(:GlobalHighlightColor, Windows::PROPVARIANT[:uint, Windows::UI_HSB(*hsb)]).commit } end
invalidate(commandId, flags = Windows::UI_INVALIDATIONS_ALLPROPERTIES, key = nil)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 759 def invalidate(commandId, flags = Windows::UI_INVALIDATIONS_ALLPROPERTIES, key = nil) @uif.InvalidateUICommand(commandId, flags, key) self end
on(*args, &block)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 765 def on(*args, &block) case args.size when 1 case args[0] when /^create$/i; @creates << block when /^destroy$/i; @destroys << block when /^size$/i; @sizes << block when Integer; (@executesAllVerbs[args[0]] ||= []) << block else raise ArgumentError end when 2 case args[0] when /^execute$/i; (@executesExecute[args[1]] ||= []) << block when /^preview$/i; (@executesPreview[args[1]] ||= []) << block when /^cancelpreview$/i; (@executesCancelPreview[args[1]] ||= []) << block when /^update$/i; (@updatesAllKeys[args[1]] ||= []) << block else raise ArgumentError end else raise ArgumentError end self end
update(commandId, key, value, newValue)
click to toggle source
# File lib/fzeet/windows/uiribbon.rb, line 738 def update(commandId, key, value, newValue) args = { commandId: commandId, key: (key.null?) ? nil : Windows::PROPERTYKEY.new(key), value: (value.null?) ? nil : Windows::PROPVARIANT.new(value), newValue: (newValue.null?) ? nil : Windows::PROPVARIANT.new(newValue), ribbon: self, sender: Command.new(self, commandId) } (handlers = @updatesAllKeys[commandId]) and handlers.each { |handler| (handler.arity == 0) ? handler.call : handler.call(args) } self rescue Fzeet.message %Q{#{$!}\n\n#{$!.backtrace.join("\n")}}, icon: :error self end