hotcocoa 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/History.txt +4 -0
  2. data/bin/hotcocoa +31 -0
  3. data/lib/hotcocoa/application_builder.rb +320 -0
  4. data/lib/hotcocoa/attributed_string.rb +143 -0
  5. data/lib/hotcocoa/behaviors.rb +7 -0
  6. data/lib/hotcocoa/data_sources/combo_box_data_source.rb +44 -0
  7. data/lib/hotcocoa/data_sources/table_data_source.rb +18 -0
  8. data/lib/hotcocoa/delegate_builder.rb +85 -0
  9. data/lib/hotcocoa/graphics/canvas.rb +836 -0
  10. data/lib/hotcocoa/graphics/color.rb +781 -0
  11. data/lib/hotcocoa/graphics/elements/particle.rb +75 -0
  12. data/lib/hotcocoa/graphics/elements/rope.rb +99 -0
  13. data/lib/hotcocoa/graphics/elements/sandpainter.rb +71 -0
  14. data/lib/hotcocoa/graphics/gradient.rb +63 -0
  15. data/lib/hotcocoa/graphics/image.rb +488 -0
  16. data/lib/hotcocoa/graphics/path.rb +325 -0
  17. data/lib/hotcocoa/graphics/pdf.rb +71 -0
  18. data/lib/hotcocoa/graphics.rb +161 -0
  19. data/lib/hotcocoa/kernel_ext.rb +14 -0
  20. data/lib/hotcocoa/kvo_accessors.rb +48 -0
  21. data/lib/hotcocoa/layout_view.rb +448 -0
  22. data/lib/hotcocoa/mapper.rb +227 -0
  23. data/lib/hotcocoa/mapping_methods.rb +40 -0
  24. data/lib/hotcocoa/mappings/alert.rb +25 -0
  25. data/lib/hotcocoa/mappings/application.rb +112 -0
  26. data/lib/hotcocoa/mappings/array_controller.rb +87 -0
  27. data/lib/hotcocoa/mappings/box.rb +39 -0
  28. data/lib/hotcocoa/mappings/button.rb +92 -0
  29. data/lib/hotcocoa/mappings/collection_view.rb +44 -0
  30. data/lib/hotcocoa/mappings/color.rb +28 -0
  31. data/lib/hotcocoa/mappings/column.rb +21 -0
  32. data/lib/hotcocoa/mappings/combo_box.rb +24 -0
  33. data/lib/hotcocoa/mappings/control.rb +33 -0
  34. data/lib/hotcocoa/mappings/font.rb +44 -0
  35. data/lib/hotcocoa/mappings/gradient.rb +15 -0
  36. data/lib/hotcocoa/mappings/image.rb +15 -0
  37. data/lib/hotcocoa/mappings/image_view.rb +43 -0
  38. data/lib/hotcocoa/mappings/label.rb +25 -0
  39. data/lib/hotcocoa/mappings/layout_view.rb +9 -0
  40. data/lib/hotcocoa/mappings/menu.rb +71 -0
  41. data/lib/hotcocoa/mappings/menu_item.rb +47 -0
  42. data/lib/hotcocoa/mappings/movie.rb +13 -0
  43. data/lib/hotcocoa/mappings/movie_view.rb +27 -0
  44. data/lib/hotcocoa/mappings/notification.rb +17 -0
  45. data/lib/hotcocoa/mappings/popup.rb +110 -0
  46. data/lib/hotcocoa/mappings/progress_indicator.rb +68 -0
  47. data/lib/hotcocoa/mappings/scroll_view.rb +29 -0
  48. data/lib/hotcocoa/mappings/search_field.rb +9 -0
  49. data/lib/hotcocoa/mappings/secure_text_field.rb +17 -0
  50. data/lib/hotcocoa/mappings/segmented_control.rb +97 -0
  51. data/lib/hotcocoa/mappings/slider.rb +25 -0
  52. data/lib/hotcocoa/mappings/sort_descriptor.rb +13 -0
  53. data/lib/hotcocoa/mappings/sound.rb +9 -0
  54. data/lib/hotcocoa/mappings/speech_synthesizer.rb +25 -0
  55. data/lib/hotcocoa/mappings/split_view.rb +21 -0
  56. data/lib/hotcocoa/mappings/status_bar.rb +7 -0
  57. data/lib/hotcocoa/mappings/status_item.rb +9 -0
  58. data/lib/hotcocoa/mappings/table_view.rb +110 -0
  59. data/lib/hotcocoa/mappings/text_field.rb +41 -0
  60. data/lib/hotcocoa/mappings/text_view.rb +13 -0
  61. data/lib/hotcocoa/mappings/timer.rb +25 -0
  62. data/lib/hotcocoa/mappings/toolbar.rb +97 -0
  63. data/lib/hotcocoa/mappings/toolbar_item.rb +36 -0
  64. data/lib/hotcocoa/mappings/view.rb +67 -0
  65. data/lib/hotcocoa/mappings/web_view.rb +22 -0
  66. data/lib/hotcocoa/mappings/window.rb +118 -0
  67. data/lib/hotcocoa/mappings/xml_parser.rb +41 -0
  68. data/lib/hotcocoa/mappings.rb +109 -0
  69. data/lib/hotcocoa/mvc.rb +175 -0
  70. data/lib/hotcocoa/notification_listener.rb +62 -0
  71. data/lib/hotcocoa/object_ext.rb +22 -0
  72. data/lib/hotcocoa/plist.rb +45 -0
  73. data/lib/hotcocoa/standard_rake_tasks.rb +17 -0
  74. data/lib/hotcocoa/template.rb +27 -0
  75. data/lib/hotcocoa/virtual_file_system.rb +172 -0
  76. data/lib/hotcocoa.rb +26 -0
  77. data/template/Rakefile +5 -0
  78. data/template/config/build.yml +8 -0
  79. data/template/lib/application.rb +45 -0
  80. data/template/lib/menu.rb +32 -0
  81. data/template/resources/HotCocoa.icns +0 -0
  82. data/test/test_helper.rb +3 -0
  83. data/test/test_hotcocoa.rb +11 -0
  84. metadata +137 -0
@@ -0,0 +1,110 @@
1
+ HotCocoa::Mappings.map :table_view => :NSTableView do
2
+
3
+ defaults :column_resize => :uniform, :frame => DefaultEmptyRect, :layout => {}
4
+
5
+ constant :column_resize, {
6
+ :none => NSTableViewNoColumnAutoresizing,
7
+ :uniform => NSTableViewUniformColumnAutoresizingStyle,
8
+ :sequential => NSTableViewSequentialColumnAutoresizingStyle,
9
+ :reverse_sequential => NSTableViewReverseSequentialColumnAutoresizingStyle,
10
+ :last_column_only => NSTableViewLastColumnOnlyAutoresizingStyle,
11
+ :first_column_only => NSTableViewFirstColumnOnlyAutoresizingStyle
12
+ }
13
+
14
+ constant :grid_style, {
15
+ :none => NSTableViewGridNone,
16
+ :vertical => NSTableViewSolidVerticalGridLineMask,
17
+ :horizontal => NSTableViewSolidHorizontalGridLineMask,
18
+ :both => NSTableViewSolidVerticalGridLineMask | NSTableViewSolidHorizontalGridLineMask
19
+ }
20
+
21
+ constant :selection_style, {
22
+ :regular => NSTableViewSelectionHighlightStyleRegular,
23
+ :source_list => NSTableViewSelectionHighlightStyleSourceList
24
+ }
25
+
26
+ def init_with_options(table_view, options)
27
+ table_view.initWithFrame(options.delete(:frame))
28
+ end
29
+
30
+ custom_methods do
31
+
32
+ def data=(data_source)
33
+ data_source = HotCocoa::TableDataSource.new(data_source) if data_source.kind_of?(Array)
34
+ setDataSource(data_source)
35
+ end
36
+
37
+ def columns=(columns)
38
+ columns.each do |column|
39
+ addTableColumn(column)
40
+ end
41
+ end
42
+
43
+ def column=(column)
44
+ addTableColumn(column)
45
+ end
46
+
47
+ def auto_size
48
+ setAutoresizingMask(NSViewHeightSizable|NSViewWidthSizable)
49
+ end
50
+
51
+ def column_resize=(style)
52
+ setColumnAutoresizingStyle(style)
53
+ end
54
+
55
+ def reload
56
+ reloadData
57
+ end
58
+
59
+ def grid_style=(value)
60
+ setGridStyleMask(value)
61
+ end
62
+
63
+ def on_double_action=(behavior)
64
+ if target && (
65
+ target.instance_variable_get("@action_behavior") ||
66
+ target.instance_variable_get("@double_action_behavior"))
67
+ object.instance_variable_set("@double_action_behavior", behavior)
68
+ object = target
69
+ else
70
+ object = Object.new
71
+ object.instance_variable_set("@double_action_behavior", behavior)
72
+ setTarget(object)
73
+ end
74
+ def object.perform_double_action(sender)
75
+ @double_action_behavior.call(sender)
76
+ end
77
+ setDoubleAction("perform_double_action:")
78
+ end
79
+
80
+ def on_double_action(&behavior)
81
+ self.on_double_action = behavior
82
+ self
83
+ end
84
+
85
+ end
86
+
87
+ delegating "tableView:willDisplayCell:forTableColumn:row:", :to => :will_display_cell, :parameters => [:willDisplayCell, :forTableColumn, :row]
88
+ delegating "tableView:dataCellForTableColumn:row:", :to => :data_cell, :parameters => [:dataCellForTableColumn, :row]
89
+ delegating "tableView:shouldShowCellExpansionForTableColumn:row:", :to => :expand_cell?, :parameters => [:shouldShowCellExpansionForTableColumn, :row]
90
+ delegating "tableView:isGroupRow:", :to => :is_group_row?, :parameters => [:isGroupRow]
91
+ delegating "tableView:shouldEditTableColumn:row:", :to => :edit_table_column?, :parameters => [:shouldEditTableColumn, :row]
92
+ delegating "tableView:heightOfRow:", :to => :height_of_row, :parameters => [:heightOfRow]
93
+ delegating "selectionShouldChangeInTableView:", :to => :change_selection?
94
+ delegating "tableView:shouldSelectRow:", :to => :select_row?, :parameters => [:shouldSelectRow]
95
+ delegating "tableView:selectionIndexesForProposedSelection:", :to => :indexes_for_selection, :parameters => [:selectIndexesForProposedSelection]
96
+ delegating "tableView:shouldSelectTableColumn:", :to => :select_column?, :parameters => [:shouldSelectTableColumn]
97
+ delegating "tableViewSelectionIsChanging:", :to => :selection_changing, :parameters => [:tableViewSelectionIsChanging]
98
+ delegating "tableViewSelectionDidChange:", :to => :selection_changed, :parameters => [:tableViewSelectionDidChange]
99
+ delegating "tableView:shouldTypeSelectForEvent:withCurrentSearchString:", :to => :type_select_for_event?, :parameters => [:shouldTypeSelectForEvent, :withCurrentSearchString]
100
+ delegating "tableView:typeSelectStringForTableColumn:row:", :to => :type_select_string, :parameters => [:typeSelectStringForTableColumn, :row]
101
+ delegating "tableView:nextTypeSelectMatchFromRow:toRow:forString:", :to => :find_in_range, :parameters => [:nextTypeSelectMatchFromRow, :toRow, :forString]
102
+ delegating "tableView:didDragTableColumn:", :to => :dragged_column, :parameters => [:didDragTableColumn]
103
+ delegating "tableViewColumnDidMove:", :to => :column_moved, :parameters => [:tableViewColumnDidMove]
104
+ delegating "tableViewColumnDidResize:", :to => :column_resized, :parameters => [:tableViewColumnDidResize]
105
+ delegating "tableView:didClickTableColumn:", :to => :clicked_column, :parameters => [:didClickTableColumn]
106
+ delegating "tableView:mouseDownInHeaderOfTableColumn:", :to => :header_clicked, :parameters => [:mouseDownInHeaderOfTableColumn]
107
+ delegating "tableView:shouldTrackCell:forTableColumn:row:", :to => :track_cell?, :parameters => [:shouldTrackCell, :forTableColumn, :row]
108
+ delegating "tableView:toolTipForCell:rect:tableColumn:row:mouseLocation:",:to => :tooltip_for_cell, :parameters => [:toolTipForCell, :rect, :tableColumn, :row, :mouseLocation]
109
+
110
+ end
@@ -0,0 +1,41 @@
1
+ # NSTextField mappings
2
+ #
3
+ # Usage example:
4
+ # @field = text_field(:text => "your text here", :layout => {:start => false}, :frame => [0, 0, 300, 300])
5
+ # @field.text = "New text"
6
+
7
+ # Cocoa Documentation:
8
+ # http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextField_Class/Reference/Reference.html
9
+ #
10
+ #
11
+
12
+ HotCocoa::Mappings.map :text_field => :NSTextField do
13
+
14
+ constant :text_align, {
15
+ :right => NSRightTextAlignment,
16
+ :left => NSLeftTextAlignment,
17
+ :center => NSCenterTextAlignment
18
+ }
19
+
20
+ defaults :selectable => true, :editable => true, :layout => {}, :frame => DefaultEmptyRect
21
+
22
+ def init_with_options(text_field, options)
23
+ text_field.initWithFrame options.delete(:frame)
24
+ end
25
+
26
+ custom_methods do
27
+
28
+ def text_align=(value)
29
+ setAlignment(value)
30
+ end
31
+
32
+ end
33
+
34
+ delegating "control:textShouldBeginEditing:", :to => :should_begin_editing?, :parameters => [:textShouldBeginEditing]
35
+ delegating "control:textShouldEndEditing:", :to => :should_end_editing?, :parameters => [:textShouldEndEditing]
36
+ delegating "controlTextDidBeginEditing:", :to => :did_begin_editing, :parameters => ["controlTextDidBeginEditing.userInfo['NSFieldEditor']"]
37
+ delegating "controlTextDidEndEditing:", :to => :did_end_editing, :parameters => ["controlTextDidEndEditing.userInfo['NSFieldEditor']"]
38
+ delegating "controlTextDidChange:", :to => :did_change, :parameters => ["controlTextDidChange.userInfo['NSFieldEditor']"]
39
+
40
+
41
+ end
@@ -0,0 +1,13 @@
1
+ HotCocoa::Mappings.map :text_view => :NSTextView do
2
+
3
+ defaults :layout => {}, :frame => DefaultEmptyRect
4
+
5
+ def init_with_options(text_view, options)
6
+ if options[:container]
7
+ text_view.initWithFrame options.delete(:frame), :textContainer => options.delete(:container)
8
+ else
9
+ text_view.initWithFrame options.delete(:frame)
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,25 @@
1
+ HotCocoa::Mappings.map :timer => :NSTimer do
2
+
3
+ defaults :scheduled => true, :repeats => false
4
+
5
+ def alloc_with_options(options)
6
+ raise ArgumentError, "timer requires :interval" unless options.has_key?(:interval)
7
+ target = options.delete(:target)
8
+ selector = options.delete(:selector)
9
+ if !target || !selector
10
+ raise ArgumentError, "timer requires either :target and :selector or :on_action" unless options.has_key?(:on_action)
11
+ target = Object.new
12
+ target.instance_variable_set(:@block, options.delete(:on_action))
13
+ def target.fire(timer)
14
+ @block.call(timer)
15
+ end
16
+ selector = "fire:"
17
+ end
18
+ if options.delete(:scheduled)
19
+ NSTimer.scheduledTimerWithTimeInterval(options.delete(:interval), target:target, selector:selector, userInfo:options.delete(:info), repeats:options.delete(:repeats))
20
+ else
21
+ NSTimer.timerWithTimeInterval(options.delete(:interval), target:target, selector:selector, userInfo:options.delete(:info), repeats:options.delete(:repeats))
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,97 @@
1
+ HotCocoa::Mappings.map :toolbar => :NSToolbar do
2
+
3
+ constant :size, {
4
+ :default => NSToolbarSizeModeDefault,
5
+ :regular => NSToolbarSizeModeRegular,
6
+ :small => NSToolbarSizeModeSmall
7
+ }
8
+
9
+ constant :display, {
10
+ :default => NSToolbarDisplayModeDefault,
11
+ :icon_and_label => NSToolbarDisplayModeIconAndLabel,
12
+ :icon => NSToolbarDisplayModeIconOnly,
13
+ :label => NSToolbarDisplayModeLabelOnly
14
+ }
15
+
16
+ defaults :identifier => 'DefaultToolbarIdentifier',
17
+ :allowed => [:separator, :space, :flexible_space, :show_colors,
18
+ :show_fonts, :customize, :print],
19
+ :default => [],
20
+ :allow_customization => true,
21
+ :size => :default
22
+
23
+ def init_with_options(toolbar, options)
24
+ toolbar = toolbar.initWithIdentifier options.delete(:identifier)
25
+ toolbar.allowsUserCustomization = options.delete(:allow_customization)
26
+ toolbar
27
+ end
28
+
29
+ custom_methods do
30
+
31
+ def size=(mode)
32
+ setSizeMode(mode)
33
+ end
34
+
35
+ def display=(mode)
36
+ setDisplayMode(mode)
37
+ end
38
+
39
+ def default=(list)
40
+ @default = list.dup
41
+ build_custom_items
42
+ end
43
+
44
+ def allowed=(list)
45
+ @allowed = list.dup
46
+ build_custom_items
47
+ end
48
+
49
+ private
50
+
51
+ def build_custom_items
52
+ if @allowed && @default
53
+ ary = @default.select { |x| x.is_a?(NSToolbarItem) }
54
+ @default -= ary
55
+ @custom_items = {}
56
+ ary.each { |x| @custom_items[x.itemIdentifier] = x }
57
+ @allowed.concat(@custom_items.keys)
58
+ @default.concat(@custom_items.keys)
59
+
60
+ [@allowed, @default].each do |a|
61
+ a.map! do |i|
62
+ case i
63
+ when :separator
64
+ NSToolbarSeparatorItemIdentifier
65
+ when :space
66
+ NSToolbarSpaceItemIdentifier
67
+ when :flexible_space
68
+ NSToolbarFlexibleSpaceItemIdentifier
69
+ when :show_colors
70
+ NSToolbarShowColorsItemIdentifier
71
+ when :show_fonts
72
+ NSToolbarShowFontsItemIdentifier
73
+ when :customize
74
+ NSToolbarCustomizeToolbarItemIdentifier
75
+ when :print
76
+ NSToolbarPrintItemIdentifier
77
+ else
78
+ i
79
+ end
80
+ end
81
+ end
82
+ allowed_items { @allowed }
83
+ default_items { @default }
84
+ item_for_identifier { |identifier, will_be_inserted| @custom_items[identifier] }
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ delegating "toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:", :to => :item_for_identifier, :parameters => [:itemForItemIdentifier, :willBeInsertedIntoToolbar], :required => true
91
+ delegating "toolbarAllowedItemIdentifiers:", :to => :allowed_items, :required => true
92
+ delegating "toolbarDefaultItemIdentifiers:", :to => :default_items, :required => true
93
+ delegating "toolbarSelectableItemIdentifiers:", :to => :selectable_items
94
+ delegating "toolbarDidRemoveItem:", :to => :did_remove_item, :parameters => ["toolbarDidRemoveItem.userInfo['item']"]
95
+ delegating "toolbarWillAddItem:", :to => :will_add_item, :parameters => ["toolbarWillAddItem.userInfo['item']"]
96
+
97
+ end
@@ -0,0 +1,36 @@
1
+ HotCocoa::Mappings.map :toolbar_item => :NSToolbarItem do
2
+
3
+ defaults :priority => :standard
4
+
5
+ constant :priority, {
6
+ :standard => NSToolbarItemVisibilityPriorityStandard,
7
+ :low => NSToolbarItemVisibilityPriorityLow,
8
+ :high => NSToolbarItemVisibilityPriorityHigh,
9
+ :user => NSToolbarItemVisibilityPriorityUser
10
+ }
11
+
12
+ def init_with_options(toolbar_item, options)
13
+ if !options.has_key?(:label) && !options.has_key?(:identifier)
14
+ raise ArgumentError, ":identifier or :label required"
15
+ end
16
+ label = options[:label]
17
+ toolbar_item.initWithItemIdentifier(options.delete(:identifier) || label.tr(' ', '_'))
18
+ toolbar_item.paletteLabel = label if label
19
+ toolbar_item
20
+ end
21
+
22
+ custom_methods do
23
+
24
+ include HotCocoa::Mappings::TargetActionConvenience
25
+
26
+ def priority=(value)
27
+ setVisibilityPriority(value)
28
+ end
29
+
30
+ def priority
31
+ visibilityPriority
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,67 @@
1
+
2
+ HotCocoa::Mappings.map :view => :NSView do
3
+
4
+ defaults :frame => DefaultEmptyRect,
5
+ :layout => {}
6
+
7
+ constant :auto_resize, {
8
+ :none => NSViewNotSizable,
9
+ :width => NSViewWidthSizable,
10
+ :height => NSViewHeightSizable,
11
+ :min_x => NSViewMinXMargin,
12
+ :min_y => NSViewMinYMargin,
13
+ :max_x => NSViewMaxXMargin,
14
+ :max_y => NSViewMaxYMargin
15
+ }
16
+
17
+ constant :border, {
18
+ :none => NSNoBorder,
19
+ :line => NSLineBorder,
20
+ :bezel => NSBezelBorder,
21
+ :groove => NSGrooveBorder
22
+ }
23
+
24
+ def init_with_options(view, options)
25
+ view.initWithFrame options.delete(:frame)
26
+ end
27
+
28
+ custom_methods do
29
+
30
+ def auto_resize=(value)
31
+ setAutoresizingMask(value)
32
+ end
33
+
34
+ def <<(view)
35
+ addSubview(view)
36
+ end
37
+
38
+ def layout=(options)
39
+ @layout = HotCocoa::LayoutOptions.new(self, options)
40
+ @layout.update_layout_views!
41
+ end
42
+
43
+ def layout
44
+ @layout
45
+ end
46
+
47
+ def on_notification(options={}, &block)
48
+ options[:sent_by] = self
49
+ NotificationListener.new(options, &block)
50
+ end
51
+
52
+ def remove(subview, options = {})
53
+ raise ArgumentError, "#{subview} is not a subview of #{self} and cannot be removed." unless subview.superview == self
54
+ options[:needs_display] == false ? subview.removeFromSuperviewWithoutNeedingDisplay : subview.removeFromSuperview
55
+ end
56
+
57
+ def enter_full_screen(options={})
58
+ enterFullScreenMode((options.delete(:screen) || NSScreen.mainScreen), withOptions:options)
59
+ end
60
+
61
+ def leave_full_screen(options={})
62
+ exitFullScreenModeWithOptions(options)
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,22 @@
1
+ HotCocoa::Mappings.map :web_view => :WebView , :framework => :WebKit do
2
+
3
+ defaults :layout => {}, :frame => DefaultEmptyRect
4
+
5
+ def init_with_options(web_view, options)
6
+ web_view.initWithFrame(options.delete(:frame))
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def url=(url)
12
+ url = url.kind_of?(String) ? NSURL.alloc.initWithString(url) : url
13
+ mainFrame.loadRequest(NSURLRequest.requestWithURL(url))
14
+ end
15
+
16
+ def auto_size
17
+ setAutoresizingMask(NSViewHeightSizable|NSViewWidthSizable)
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,118 @@
1
+ # Cocoa Reference: NSWindow
2
+ #
3
+ # Usage example:
4
+ # ==============
5
+ #
6
+ # window :frame => [100, 100, 604, 500], :title => "My app", :style => [:titled, :closable, :miniaturizable, :resizable] do |win|
7
+ # win.contentView.margin = 0
8
+ # win.background_color = color(:name => 'white')
9
+ # win.will_close { exit }
10
+ # end
11
+ #
12
+ # Apple Developer Connection url: http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html
13
+ #
14
+
15
+ HotCocoa::Mappings.map :window => :NSWindow do
16
+
17
+ defaults :style => [:titled, :closable, :miniaturizable, :resizable],
18
+ :backing => :buffered,
19
+ :defer => true,
20
+ :show => true,
21
+ :view => :layout,
22
+ :default_layout => {}
23
+
24
+ constant :backing, :buffered => NSBackingStoreBuffered
25
+
26
+ constant :style, {
27
+ :borderless => NSBorderlessWindowMask,
28
+ :titled => NSTitledWindowMask,
29
+ :closable => NSClosableWindowMask,
30
+ :miniaturizable => NSMiniaturizableWindowMask,
31
+ :resizable => NSResizableWindowMask,
32
+ :textured => NSTexturedBackgroundWindowMask
33
+ }
34
+
35
+ def init_with_options(window, options)
36
+ unless options[:frame]
37
+ size = (options.delete(:size) || [400,400])
38
+ width, height = size
39
+ screen_frame = NSScreen.screens[0].visibleFrame
40
+ center = options.delete(:center)
41
+ x = screen_frame.origin.x + (center ? (screen_frame.size.width - width)/2 : 30)
42
+ y = screen_frame.origin.y + (center ? (screen_frame.size.height - height)/2 : (screen_frame.size.height - height - 30))
43
+ options[:frame] = [x, y, width, height]
44
+ end
45
+ window = window.initWithContentRect options.delete(:frame),
46
+ styleMask:options.delete(:style),
47
+ backing:options.delete(:backing),
48
+ defer:options.delete(:defer)
49
+ default_layout = options.delete(:default_layout)
50
+ if options[:view] == :layout
51
+ options.delete(:view)
52
+ window.setContentView(HotCocoa::LayoutView.alloc.initWithFrame([0,0,window.contentView.frameSize.width, window.contentView.frameSize.height]))
53
+ window.contentView.default_layout = default_layout
54
+ elsif options[:view] == :nolayout
55
+ options.delete(:view)
56
+ end
57
+ window
58
+ end
59
+
60
+ custom_methods do
61
+
62
+ def <<(control)
63
+ contentView.addSubview control
64
+ end
65
+
66
+ def view
67
+ contentView
68
+ end
69
+
70
+ def view=(view)
71
+ setContentView(view)
72
+ end
73
+
74
+ def on_notification(options={}, &block)
75
+ options[:sent_by] = self
76
+ NotificationListener.new(options, &block)
77
+ end
78
+
79
+ def show
80
+ display
81
+ makeKeyAndOrderFront(nil)
82
+ orderFrontRegardless
83
+ end
84
+
85
+ def has_shadow?
86
+ hasShadow
87
+ end
88
+
89
+ end
90
+
91
+ delegating "window:shouldDragDocumentWithEvent:from:withPasteboard:", :to => :should_drag_document?, :parameters => [:shouldDragDocumentWithEvent, :from, :withPasteboard]
92
+ delegating "window:shouldPopUpDocumentPathMenu:", :to => :should_popup_path_menu?, :parameters => [:shouldPopUpDocumentPathMenu]
93
+ delegating "window:willPositionSheet:usingRect:", :to => :will_position_sheet, :parameters => [:willPositionSheet, :usingRect]
94
+ delegating "windowDidBecomeKey:", :to => :did_become_key
95
+ delegating "windowDidBecomeMain:", :to => :did_become_main
96
+ delegating "windowDidChangeScreen:", :to => :did_change_screen
97
+ delegating "windowDidChangeScreenProfile:", :to => :did_change_screen_profile
98
+ delegating "windowDidDeminiaturize:", :to => :did_deminiturize
99
+ delegating "windowDidEndSheet:", :to => :did_end_sheet
100
+ delegating "windowDidExpose:", :to => :did_expose, :parameters => ["windowDidExpose.userInfo['NSExposedRect']"]
101
+ delegating "windowDidMiniaturize:", :to => :did_miniaturize
102
+ delegating "windowDidMove:", :to => :did_move
103
+ delegating "windowDidResignKey:", :to => :did_resign_key
104
+ delegating "windowDidResignMain:", :to => :did_resign_main
105
+ delegating "windowDidResize:", :to => :did_resize
106
+ delegating "windowDidUpdate:", :to => :did_update
107
+ delegating "windowShouldClose:", :to => :should_close?
108
+ delegating "windowShouldZoom:toFrame:", :to => :should_zoom?, :parameters => [:toFrame]
109
+ delegating "windowWillBeginSheet:", :to => :will_begin_sheet
110
+ delegating "windowWillClose:", :to => :will_close
111
+ delegating "windowWillMiniaturize:", :to => :will_miniaturize
112
+ delegating "windowWillMove:", :to => :will_move
113
+ delegating "windowWillResize:toSize:", :to => :will_resize, :parameters => [:toSize]
114
+ delegating "windowWillReturnFieldEditor:toObject:", :to => :returning_field_editor, :parameters => [:toObject]
115
+ delegating "windowWillReturnUndoManager:", :to => :returning_undo_manager
116
+ delegating "windowWillUseStandardFrame:defaultFrame:", :to => :will_use_standard_frame, :parameters => [:defaultFrame]
117
+
118
+ end
@@ -0,0 +1,41 @@
1
+ HotCocoa::Mappings.map :xml_parser => :NSXMLParser do
2
+
3
+ def alloc_with_options(options)
4
+ if options[:url]
5
+ url = options.delete(:url)
6
+ url = NSURL.alloc.initWithString(url) if url.is_a?(String)
7
+ NSXMLParser.alloc.initWithContentsOfURL(url)
8
+ elsif options[:file]
9
+ NSXMLParser.alloc.initWithData(NSData.alloc.initWithContentsOfFile(options.delete(:file)))
10
+ elsif options[:data]
11
+ NSXMLParser.alloc.initWithData(options.delete(:data))
12
+ else
13
+ raise "Must provide either :url or :data when constructing an NSXMLParser"
14
+ end
15
+ end
16
+
17
+ delegating "parserDidStartDocument:", :to => :on_start_document
18
+ delegating "parserDidEndDocument:", :to => :on_end_document
19
+ delegating "parser:didStartElement:namespaceURI:qualifiedName:attributes:", :to => :on_start_element, :parameters => [:didStartElement, :namespaceURI, :qualifiedName, :attributes]
20
+ delegating "parser:didEndElement:namespaceURI:qualifiedName:", :to => :on_end_element, :parameters => [:didEndElement, :namespaceURI, :qualifiedName]
21
+ delegating "parser:didStartMappingPrefix:toURI:", :to => :on_start_mapping_prefix, :parameters => [:didStartMappingPrefix, :toURI]
22
+ delegating "parser:didEndMappingPrefix:", :to => :on_end_mapping_prefix, :parameters => [:didEndMappingPrefix]
23
+
24
+ delegating "parser:foundAttributeDeclarationWithName:forElement:type:defaultValue:", :to => :on_attribute_declaration, :parameters => [:foundAttributeDeclarationWithName, :forElement, :type, :defaultValue]
25
+ delegating "parser:foundCDATA:", :to => :on_cdata, :parameters => [:foundCDATA]
26
+ delegating "parser:foundCharacters:", :to => :on_characters, :parameters => [:foundCharacters]
27
+ delegating "parser:foundComment:", :to => :on_comment, :parameters => [:foundComment]
28
+ delegating "parser:foundElementDeclarationWithName:model:", :to => :on_element_declaration, :parameters => [:foundElementDeclarationWithName, :model]
29
+ delegating "parser:foundExternalEntityDeclarationWithName:publicID:systemID:", :to => :on_external_entity_declaration, :parameters => [:foundExternalEntityDeclarationWithName, :publicID, :systemID]
30
+ delegating "parser:foundIgnorableWhitespace:", :to => :on_ignorable_whitespace, :parameters => [:foundIgnorableWhitespace]
31
+ delegating "parser:foundInternalEntityDeclarationWithName:value:", :to => :on_internal_entity_declaration, :parameters => [:foundInternalEntityDeclarationWithName, :value]
32
+ delegating "parser:foundNotationDeclarationWithName:publicID:systemID:", :to => :on_notation_declaration, :parameters => [:foundNotationDeclarationWithName, :data]
33
+ delegating "parser:foundProcessingInstructionWithTarget:data:", :to => :on_processing_instruction, :parameters => [:foundProcessingInstructionWithTarget, :data]
34
+ delegating "parser:foundUnparsedEntityDeclarationWithName:publicID:systemID:notationName:", :to => :on_unparsed_entity_declaration, :parameters => [:foundUnparsedEntityDeclarationWithName, :publicID, :systemID, :notationName]
35
+
36
+ delegating "parser:resolveExternalEntityName:systemID:", :to => :resolve_external_entity_name, :parameters => [:resolveExternalEntityName, :systemID]
37
+
38
+ delegating "parser:parseErrorOccurred:", :to => :on_parse_error, :parameters => [:parseErrorOccurred]
39
+ delegating "parser:validationErrorOccurred:", :to => :on_validation_error, :parameters => [:validationErrorOccurred]
40
+
41
+ end