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.
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 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 |
# File 'lib/fzeet/windows/uiribbon.rb', line 557 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.
678 679 680 |
# File 'lib/fzeet/windows/uiribbon.rb', line 678 def hdll @hdll end |
#uia ⇒ Object (readonly)
Returns the value of attribute uia.
678 679 680 |
# File 'lib/fzeet/windows/uiribbon.rb', line 678 def uia @uia end |
#uich ⇒ Object (readonly)
Returns the value of attribute uich.
678 679 680 |
# File 'lib/fzeet/windows/uiribbon.rb', line 678 def uich @uich end |
#uif ⇒ Object (readonly)
Returns the value of attribute uif.
678 679 680 |
# File 'lib/fzeet/windows/uiribbon.rb', line 678 def uif @uif end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
678 679 680 |
# File 'lib/fzeet/windows/uiribbon.rb', line 678 def window @window end |
Instance Method Details
#[](id) ⇒ Object
451 |
# File 'lib/fzeet/windows/uiribbon.rb', line 451 def [](id) Command.new(self, id) end |
#background ⇒ Object
476 477 478 479 480 481 482 483 484 |
# File 'lib/fzeet/windows/uiribbon.rb', line 476 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
486 487 488 489 490 |
# File 'lib/fzeet/windows/uiribbon.rb', line 486 def background=(hsb) uif.QueryInstance(Windows::PropertyStore) { |ps| ps.uiprop(:GlobalBackgroundColor, Windows::PROPVARIANT[:uint, Windows::UI_HSB(*hsb)]).commit } end |
#color ⇒ Object
492 493 494 495 496 497 498 499 500 |
# File 'lib/fzeet/windows/uiribbon.rb', line 492 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
502 503 504 505 506 |
# File 'lib/fzeet/windows/uiribbon.rb', line 502 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
796 797 798 799 800 801 802 |
# File 'lib/fzeet/windows/uiribbon.rb', line 796 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
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/fzeet/windows/uiribbon.rb', line 682 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
784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/fzeet/windows/uiribbon.rb', line 784 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
770 771 772 773 774 775 776 777 778 779 780 781 782 |
# File 'lib/fzeet/windows/uiribbon.rb', line 770 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
680 |
# File 'lib/fzeet/windows/uiribbon.rb', line 680 def height; uia.uir.height end |
#highlight ⇒ Object
508 509 510 511 512 513 514 515 516 |
# File 'lib/fzeet/windows/uiribbon.rb', line 508 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
518 519 520 521 522 |
# File 'lib/fzeet/windows/uiribbon.rb', line 518 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
740 741 742 743 744 |
# File 'lib/fzeet/windows/uiribbon.rb', line 740 def invalidate(commandId, flags = Windows::UI_INVALIDATIONS_ALLPROPERTIES, key = nil) @uif.InvalidateUICommand(commandId, flags, key) self end |
#on(*args, &block) ⇒ Object
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'lib/fzeet/windows/uiribbon.rb', line 746 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
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/fzeet/windows/uiribbon.rb', line 719 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 |