Class: Fzeet::UIRibbon
- Inherits:
-
Object
- Object
- Fzeet::UIRibbon
- Defined in:
- lib/fzeet/windows/uiribbon.rb
Defined Under Namespace
Modules: Color Classes: Command, GalleryItem
Instance Attribute Summary collapse
-
#hdll ⇒ Object
readonly
Returns the value of attribute hdll.
-
#uia ⇒ Object
readonly
Returns the value of attribute uia.
-
#uich ⇒ Object
readonly
Returns the value of attribute uich.
-
#uif ⇒ Object
readonly
Returns the value of attribute uif.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #background ⇒ Object
- #background=(hsb) ⇒ Object
- #color ⇒ Object
- #color=(hsb) ⇒ Object
- #contextualUI(id, x, y) ⇒ Object
- #execute(commandId, verb, key, value, props) ⇒ Object
- #fontPropsChanged(args) ⇒ Object
- #fontPropsUpdate(args) ⇒ Object
- #height ⇒ Object
- #highlight ⇒ Object
- #highlight=(hsb) ⇒ Object
-
#initialize(_window, opts = {}) ⇒ UIRibbon
constructor
A new instance of UIRibbon.
- #invalidate(commandId, flags = Windows::UI_INVALIDATIONS_ALLPROPERTIES, key = nil) ⇒ Object
- #on(*args, &block) ⇒ Object
- #update(commandId, key, value, newValue) ⇒ Object
Constructor Details
#initialize(_window, opts = {}) ⇒ UIRibbon
Returns a new instance of UIRibbon.
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# 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. %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 |
Instance Attribute Details
#hdll ⇒ Object (readonly)
Returns the value of attribute hdll.
697 698 699 |
# File 'lib/fzeet/windows/uiribbon.rb', line 697 def hdll @hdll end |
#uia ⇒ Object (readonly)
Returns the value of attribute uia.
697 698 699 |
# File 'lib/fzeet/windows/uiribbon.rb', line 697 def uia @uia end |
#uich ⇒ Object (readonly)
Returns the value of attribute uich.
697 698 699 |
# File 'lib/fzeet/windows/uiribbon.rb', line 697 def uich @uich end |
#uif ⇒ Object (readonly)
Returns the value of attribute uif.
697 698 699 |
# File 'lib/fzeet/windows/uiribbon.rb', line 697 def uif @uif end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
697 698 699 |
# File 'lib/fzeet/windows/uiribbon.rb', line 697 def window @window end |
Instance Method Details
#[](id) ⇒ Object
470 |
# File 'lib/fzeet/windows/uiribbon.rb', line 470 def [](id) Command.new(self, id) end |
#background ⇒ Object
495 496 497 498 499 500 501 502 503 |
# 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) ⇒ Object
505 506 507 508 509 |
# 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 ⇒ Object
511 512 513 514 515 516 517 518 519 |
# 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) ⇒ Object
521 522 523 524 525 |
# 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) ⇒ Object
815 816 817 818 819 820 821 |
# 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) ⇒ Object
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
# 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. %Q{#{$!}\n\n#{$!.backtrace.join("\n")}}, icon: :error self end |
#fontPropsChanged(args) ⇒ Object
803 804 805 806 807 808 809 810 811 812 813 |
# 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) ⇒ Object
789 790 791 792 793 794 795 796 797 798 799 800 801 |
# 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 ⇒ Object
699 |
# File 'lib/fzeet/windows/uiribbon.rb', line 699 def height; uia.uir.height end |
#highlight ⇒ Object
527 528 529 530 531 532 533 534 535 |
# 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) ⇒ Object
537 538 539 540 541 |
# 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) ⇒ Object
759 760 761 762 763 |
# 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) ⇒ Object
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
# 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) ⇒ Object
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 |
# 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. %Q{#{$!}\n\n#{$!.backtrace.join("\n")}}, icon: :error self end |