hotcocoa 0.5

Sign up to get free protection for your applications and to get access to all the features.
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,71 @@
1
+ HotCocoa::Mappings.map :menu => :NSMenu do
2
+
3
+ defaults :title => ""
4
+
5
+ def alloc_with_options(options)
6
+ NSMenu.alloc.initWithTitle(options.delete(:title))
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def submenu(symbol, options={}, &block)
12
+ item = addItemWithTitle((options[:title] || titleize(symbol)), :action => nil, :keyEquivalent => "")
13
+ submenu = builder.menu :title => (options[:title] || titleize(symbol))
14
+ case symbol
15
+ when :apple
16
+ app.setAppleMenu(submenu)
17
+ when :services
18
+ app.setServicesMenu(submenu)
19
+ when :window
20
+ app.setWindowsMenu(submenu)
21
+ end
22
+ item_map[symbol] = submenu
23
+ block.call(submenu) if block
24
+ setSubmenu submenu, :forItem => item
25
+ submenu
26
+ end
27
+
28
+ def item(symbol, options={})
29
+ options[:title] ||= titleize(symbol)
30
+ options[:action] ||= "on_#{symbol}:"
31
+ item = builder.menu_item(options)
32
+ item_map[symbol] = item
33
+ addItem item
34
+ item
35
+ end
36
+
37
+ def separator
38
+ addItem NSMenuItem.separatorItem
39
+ end
40
+
41
+ def [](*symbols)
42
+ symbol = symbols.shift
43
+ symbols.empty? ? item_map[symbol] : item_map[symbol][*symbols]
44
+ end
45
+
46
+ private
47
+
48
+ def builder
49
+ @builder || create_builder
50
+ end
51
+
52
+ def create_builder
53
+ @builder = Object.new
54
+ @builder.extend HotCocoa
55
+ @builder
56
+ end
57
+
58
+ def item_map
59
+ @item_map ||= {}
60
+ end
61
+
62
+ def titleize(symbol)
63
+ symbol.to_s.split("_").collect(&:capitalize).join(" ")
64
+ end
65
+
66
+ def app
67
+ @app ||= NSApplication.sharedApplication
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,47 @@
1
+ HotCocoa::Mappings.map :menu_item => :NSMenuItem do
2
+
3
+ defaults :title => "", :key => "", :action => nil
4
+
5
+ constant :modifiers, {
6
+ :control => NSControlKeyMask,
7
+ :alt => NSAlternateKeyMask,
8
+ :command => NSCommandKeyMask,
9
+ :shift => NSShiftKeyMask
10
+ }
11
+
12
+ def alloc_with_options(options)
13
+ NSMenuItem.alloc.initWithTitle options.delete(:title), :action => options.delete(:action), :keyEquivalent => options.delete(:key)
14
+ end
15
+
16
+ custom_methods do
17
+
18
+ def on_action=(behavior)
19
+ object = Object.new
20
+ object.instance_variable_set("@behavior", behavior)
21
+ def object.perform_action(sender)
22
+ @behavior.call(sender)
23
+ end
24
+ setTarget(object)
25
+ setAction("perform_action:")
26
+ end
27
+
28
+ def on_action(&behavior)
29
+ self.on_action = behavior
30
+ self
31
+ end
32
+
33
+ def key
34
+ keyEquivalent
35
+ end
36
+
37
+ def key=(value)
38
+ setKeyEquivalent(value)
39
+ end
40
+
41
+ def modifiers=(value)
42
+ setKeyEquivalentModifierMask(value)
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,13 @@
1
+ HotCocoa::Mappings.map :movie => :QTMovie, :framework => :QTKit do
2
+
3
+ def alloc_with_options(options)
4
+ if options.has_key?(:file)
5
+ QTMovie.movieWithFile(options.delete(:file), error:options.delete(:error))
6
+ elsif options.has_key?(:url)
7
+ QTMovie.movieWithURL(NSURL.alloc.initWithString(options.delete(:url)), error:options.delete(:error))
8
+ else
9
+ raise "Can only allocate a movie from a file or a url"
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,27 @@
1
+ HotCocoa::Mappings.map :movie_view => :QTMovieView, :framework => :QTKit do
2
+
3
+ defaults :layout => {}, :frame => DefaultEmptyRect
4
+
5
+ def init_with_options(movie_view, options)
6
+ movie_view.initWithFrame(options.delete(:frame))
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def controller_visible=(value)
12
+ setControllerVisible(value)
13
+ end
14
+
15
+ def controller_buttons=(buttons)
16
+ setBackButtonVisible(buttons.include?(:back))
17
+ setCustomButtonVisible(buttons.include?(:custom))
18
+ setHotSpotButtonVisible(buttons.include?(:hot_spot))
19
+ setStepButtonsVisible(buttons.include?(:step))
20
+ setTranslateButtonVisible(buttons.include?(:translate))
21
+ setVolumeButtonVisible(buttons.include?(:volume))
22
+ setZoomButtonsVisible(buttons.include?(:zoom))
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,17 @@
1
+ HotCocoa::Mappings.map :notification => :NSNotification do
2
+
3
+ defaults :post => true, :distributed => false
4
+
5
+ def alloc_with_options(options)
6
+ if options.delete(:post)
7
+ if options.delete(:distributed)
8
+ NSDistributedNotificationCenter.defaultCenter.postNotificationName options.delete(:name), object:options.delete(:object), userInfo:options.delete(:info), deliverImmediately:(options.delete(:immediately) == true)
9
+ else
10
+ NSNotificationCenter.defaultCenter.postNotificationName options.delete(:name), object:options.delete(:object), userInfo:options.delete(:info)
11
+ end
12
+ else
13
+ NSNotification.notificationName options.delete(:name), object:options.delete(:object), userInfo:options.delete(:info)
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,110 @@
1
+ module HotCocoa
2
+ class PopUpItemList
3
+
4
+ include Enumerable
5
+
6
+ attr_reader :control
7
+
8
+ def initialize(control)
9
+ @control = control
10
+ end
11
+
12
+ def <<(title)
13
+ control.addItemWithTitle(title)
14
+ end
15
+
16
+ def [](index)
17
+ control.itemTitleAtIndex(index)
18
+ end
19
+
20
+ def delete(title)
21
+ if title.kind_of?(Fixnum)
22
+ control.removeItemAtIndex(title)
23
+ else
24
+ control.removeItemWithTitle(title)
25
+ end
26
+ end
27
+
28
+ def insert(title, at:index)
29
+ control.insertItemWithTitle(title, atIndex:index)
30
+ end
31
+
32
+ def selected
33
+ control.titleOfSelectedItem
34
+ end
35
+
36
+ def selected=(title)
37
+ if title.kind_of?(Fixnum)
38
+ control.selectItemAtIndex(title)
39
+ else
40
+ control.selectItemWithTitle(title)
41
+ end
42
+ end
43
+
44
+ def selected_index
45
+ control.indexOfSelectedItem
46
+ end
47
+
48
+ def size
49
+ control.numberOfItems
50
+ end
51
+
52
+ def each(&block)
53
+ control.itemTitles.each(&block)
54
+ end
55
+
56
+ end
57
+
58
+ class PopUpMenuItemList < PopUpItemList
59
+ include Enumerable
60
+
61
+ def selected
62
+ control.selectedItem
63
+ end
64
+
65
+ def selected=(menu_item)
66
+ if menu_item.kind_of?(Fixnum)
67
+ control.selectItemAtIndex(menu_item)
68
+ else
69
+ control.selectItem(menu_item)
70
+ end
71
+ end
72
+
73
+ def [](index)
74
+ control.itemAtIndex(index)
75
+ end
76
+
77
+ def each(&block)
78
+ control.itemArray.each(&block)
79
+ end
80
+ end
81
+ end
82
+
83
+ HotCocoa::Mappings.map :popup => :NSPopUpButton do
84
+
85
+ defaults :pulls_down => false,
86
+ :frame => DefaultEmptyRect,
87
+ :layout => {}
88
+
89
+ def init_with_options(popup, options)
90
+ popup.initWithFrame(options.delete(:frame), pullsDown:options.delete(:pulls_down))
91
+ end
92
+
93
+ custom_methods do
94
+
95
+ def items=(values)
96
+ removeAllItems
97
+ addItemsWithTitles(values)
98
+ end
99
+
100
+ def items
101
+ @_item_list ||= HotCocoa::PopUpItemList.new(self)
102
+ end
103
+
104
+ def menu_items
105
+ @_menu_item_list ||= HotCocoa::PopUpMenuItemList.new(self)
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,68 @@
1
+ # Cocoa class: NSProgressIndicator
2
+ # ================================
3
+ #
4
+ # Apple Documentation: http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSProgressIndicator_Class/Reference/Reference.html
5
+ #
6
+ # Usage Example:
7
+ # --------------
8
+ #
9
+
10
+
11
+ HotCocoa::Mappings.map :progress_indicator => :NSProgressIndicator do
12
+
13
+ defaults :layout => {}, :frame => [0,0,250,20]
14
+
15
+ def init_with_options(progress_bar, options)
16
+ progress_bar.initWithFrame(options.delete(:frame))
17
+ end
18
+
19
+ custom_methods do
20
+
21
+ def to_f
22
+ doubleValue
23
+ end
24
+ alias :value :to_f
25
+
26
+ def value=(value)
27
+ setDoubleValue(value.to_f)
28
+ end
29
+
30
+ def start
31
+ startAnimation(nil)
32
+ end
33
+
34
+ def stop
35
+ stopAnimation(nil)
36
+ end
37
+
38
+ def show
39
+ setHidden(false)
40
+ end
41
+
42
+ def hide
43
+ setHidden(true)
44
+ end
45
+
46
+ def reset
47
+ setDoubleValue(0.0)
48
+ end
49
+
50
+ def style=(style_name)
51
+ if style_name == :spinning
52
+ setStyle(NSProgressIndicatorSpinningStyle)
53
+ else
54
+ setStyle(NSProgressIndicatorBarStyle)
55
+ end
56
+ end
57
+
58
+ def spinning_style
59
+ setStyle(NSProgressIndicatorSpinningStyle)
60
+ end
61
+
62
+ def bar_style
63
+ setStyle(NSProgressIndicatorBarStyle)
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,29 @@
1
+ HotCocoa::Mappings.map :scroll_view => :NSScrollView do
2
+
3
+ defaults :vertical_scroller => true, :horizontal_scroller => true, :autoresizes_subviews => true, :layout => {}, :frame => [0,0,0,0]
4
+
5
+ def init_with_options(scroll_view, options)
6
+ scroll_view.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def <<(view)
12
+ setDocumentView(view)
13
+ end
14
+
15
+ def background=(value)
16
+ setDrawsBackground(value)
17
+ end
18
+
19
+ def vertical_scroller=(value)
20
+ setHasVerticalScroller(value)
21
+ end
22
+
23
+ def horizontal_scroller=(value)
24
+ setHasHorizontalScroller(value)
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,9 @@
1
+ HotCocoa::Mappings.map :search_field => :NSSearchField do
2
+
3
+ defaults :layout => {}, :frame => DefaultEmptyRect
4
+
5
+ def init_with_options(search_field, options)
6
+ search_field.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ end
@@ -0,0 +1,17 @@
1
+ HotCocoa::Mappings.map :secure_text_field => :NSSecureTextField do
2
+
3
+ defaults :selectable => true, :editable => true, :echo => true, :layout => {}
4
+
5
+ def init_with_options(secure_text_field, options)
6
+ secure_text_field.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def echo=(value)
12
+ cell.setEchosBullets(value)
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,97 @@
1
+ module HotCocoa
2
+ class SegmentedControlSegment
3
+ attr_reader :number, :control
4
+ def initialize(control, number)
5
+ @number = number
6
+ @control = control
7
+ end
8
+
9
+ def width
10
+ control.widthForSegment(number)
11
+ end
12
+
13
+ def width=(width)
14
+ control.setWidth(width, forSegment:number)
15
+ end
16
+
17
+ def label
18
+ control.labelForSegment(number)
19
+ end
20
+
21
+ def label=(label)
22
+ control.setLabel(label, forSegment:number)
23
+ end
24
+
25
+ def image
26
+ control.imageForSegment(number)
27
+ end
28
+
29
+ def image=(image)
30
+ control.setImage(image, forSegment:number)
31
+ end
32
+
33
+ def menu
34
+ control.menuForSegment(number)
35
+ end
36
+
37
+ def menu=(menu)
38
+ control.setMenu(menu, forSegment:number)
39
+ end
40
+
41
+ def selected?
42
+ control.isSelectedForSegment(number)
43
+ end
44
+
45
+ def selected=(value)
46
+ control.setSelected(value, forSegment:number)
47
+ end
48
+
49
+ def enabled?
50
+ control.isEnabledForSegment(number)
51
+ end
52
+
53
+ def enabled=(value)
54
+ control.setEnabled(value, forSegment:number)
55
+ end
56
+ end
57
+ end
58
+
59
+ HotCocoa::Mappings.map :segmented_control => :NSSegmentedControl do
60
+
61
+ defaults :layout => {}, :frame => [0,0,0,0]
62
+
63
+ def init_with_options(segmented_control, options)
64
+ segmented_control.initWithFrame options.delete(:frame)
65
+ end
66
+
67
+ custom_methods do
68
+
69
+ def segments=(segments)
70
+ segments.each do |segment|
71
+ self << segment
72
+ end
73
+ end
74
+
75
+ def <<(data)
76
+ setSegmentCount(segmentCount+1)
77
+ segment = HotCocoa::SegmentedControlSegment.new(self, segmentCount-1)
78
+ data.each do |key, value|
79
+ segment.send("#{key}=", value)
80
+ end
81
+ end
82
+
83
+ def [](segment_number)
84
+ Segment.new(self, segment_number)
85
+ end
86
+
87
+ def select(segment_number)
88
+ setSelectedSegment(segment_number)
89
+ end
90
+
91
+ def selected_segment
92
+ HotCocoa::SegmentedControlSegment.new(self, selectedSegment)
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,25 @@
1
+ HotCocoa::Mappings.map :slider => :NSSlider do
2
+
3
+ defaults :frame => DefaultEmptyRect, :layout => {}
4
+
5
+ def init_with_options(button, options)
6
+ button.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def min=(value)
12
+ setMinValue(value)
13
+ end
14
+
15
+ def max=(value)
16
+ setMaxValue(value)
17
+ end
18
+
19
+ def tic_marks=(value)
20
+ setNumberOfTickMarks(value)
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,13 @@
1
+ HotCocoa::Mappings.map :sort_descriptor => :NSSortDescriptor do
2
+
3
+ defaults :ascending => true
4
+
5
+ def init_with_options(sort_descriptor, opts)
6
+ if opts.has_key?(:selector)
7
+ sort_descriptor.initWithKey(opts.delete(:key), ascending:opts.delete(:ascending))
8
+ else
9
+ sort_descriptor.initWithKey(opts.delete(:key), ascending:opts.delete(:ascending), selector:opts.delete(:selector))
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ HotCocoa::Mappings.map :sound => :NSSound do
2
+
3
+ defaults :by_reference => true
4
+
5
+ def init_with_options(sound, options)
6
+ sound.initWithContentsOfFile options.delete(:file), byReference:options.delete(:by_reference)
7
+ end
8
+
9
+ end
@@ -0,0 +1,25 @@
1
+ HotCocoa::Mappings.map :speech_synthesizer => :NSSpeechSynthesizer do
2
+
3
+ def init_with_options(obj, options)
4
+ if voice = options.delete(:voice)
5
+ obj.initWithVoice voice
6
+ else
7
+ obj.init
8
+ end
9
+ end
10
+
11
+ custom_methods do
12
+
13
+ def speak(what, to=nil)
14
+ if to
15
+ url = to.is_a?(String) ? NSURL.fileURLWithPath(to) : to
16
+ startSpeakingString(what, toURL:url)
17
+ else
18
+ startSpeakingString(what)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,21 @@
1
+ HotCocoa::Mappings.map :split_view => :NSSplitView do
2
+
3
+ defaults :layout => {}
4
+
5
+ def init_with_options(split_view, options)
6
+ split_view.initWithFrame options.delete(:frame)
7
+ end
8
+
9
+ custom_methods do
10
+
11
+ def horizontal=(value)
12
+ setVertical(!value)
13
+ end
14
+
15
+ def set_position(position, of_divider_at_index:index)
16
+ setPosition position, ofDividerAtIndex:index
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ HotCocoa::Mappings.map :status_bar => :NSStatusBar do
2
+
3
+ def alloc_with_options(options)
4
+ NSStatusBar.systemStatusBar
5
+ end
6
+
7
+ end
@@ -0,0 +1,9 @@
1
+ HotCocoa::Mappings.map :status_item => :NSStatusItem do
2
+
3
+ defaults :length => NSVariableStatusItemLength
4
+
5
+ def alloc_with_options(options)
6
+ HotCocoa.status_bar.statusItemWithLength options.delete(:length)
7
+ end
8
+
9
+ end