require 'rouge/rougetk'

module Rouge
	class Builder
		include RougeTK

		def initialize preferred='fox'
			_rouge_setup(preferred)
		end

		def window(title)
			widget = @toolkit.window(title)
			yield if block_given?
			@toolkit.exit_widget
			widget
		end

		def button( label, image=nil, align=nil, &block )
			widget = @toolkit.button( label, image, align, &block )
			@toolkit.exit_widget
			widget
		end

		def box( layout=:vertical )
			widget = @toolkit.box(layout)
			yield if block_given?
			@toolkit.exit_widget
			widget
		end

		def text( label )
			widget = @toolkit.text( label )
			@toolkit.exit_widget
			widget
		end

		def textbox width=10
			widget = @toolkit.textbox( width )
			@toolkit.exit_widget
			widget
		end

		def radiogroup groupname
			widget = @toolkit.radiogroup( groupname )
			@toolkit.exit_widget
			widget
		end

		def radio( label, groupname )
			widget = @toolkit.radio( label, groupname )
			@toolkit.exit_widget
			widget
		end

		def checkbox( label )
			widget = @toolkit.checkbox( label )
			@toolkit.exit_widget
			widget
		end

		def separator
			widget = @toolkit.separator
			@toolkit.exit_widget
			widget
		end

		def progessmeter
			widget = @toolkit.progressmeter
			@toolkit.exit_widget
			widget
		end

		def start
			@toolkit.start
		end
	end

	# Implement this module
	# All of the widget methods must return at least the widget that
	# was created.  They may optionally return an array, the first
	# item of which must be the widget, and the second item of which
	# must be a Proc which will be called when the widget is done
	# being created.  This allows containers to perform post 
	# processing.
	module RougeToolkit
		# Called after all widgets are done being instantiated.  Allows
		# the toolkit to enter an event handling loop.
		def run
		end

		# Methods to extend
		def window title, orient=:vertical
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def button( label, image=nil, align=nil, &block )
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def text label
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def textbox width
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def box( layout=:vertical )
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def radiogroup( groupname )
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def radio( label, groupname )
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def checkbox( label )
			puts "IMPLEMENT ME"
			StubWidget.new
		end

		def start
			puts "IMPLEMENT ME"
		end
	end
end
