<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
	<Script file="ScrollFrames.lua"></Script>
	
	<!-- ScrollFrames - Based on Blizzard's own UI templates, removed names, using parent keys, easier to manage -->
	<Slider name="AltoUIPanelScrollBarTemplate" virtual="true">
		<Size x="16" y="0" />
		<Frames>
			<Button parentKey="ScrollUpButton" inherits="UIPanelScrollUpButtonTemplate">
				<Anchors>
					<Anchor point="BOTTOM" relativePoint="TOP"/>
				</Anchors>
				<Scripts>
					<OnClick>
						local parent = self:GetParent()
						local scrollStep = parent.scrollStep or (parent:GetHeight() / 2)
						parent:SetValue(parent:GetValue() - scrollStep)
						PlaySound(1115)
					</OnClick>
				</Scripts>
			</Button>
			<Button parentKey="ScrollDownButton" inherits="UIPanelScrollDownButtonTemplate">
				<Anchors>
					<Anchor point="TOP" relativePoint="BOTTOM"/>
				</Anchors>
				<Scripts>
					<OnClick>
						local parent = self:GetParent()
						local scrollStep = parent.scrollStep or (parent:GetHeight() / 2)
						parent:SetValue(parent:GetValue() + scrollStep)
						PlaySound(1115)
					</OnClick>
				</Scripts>
			</Button>
		</Frames>
		<Scripts>
			<OnValueChanged>
				self:GetParent():SetVerticalScroll(value)
			</OnValueChanged>
		</Scripts>
		<ThumbTexture parentKey="ThumbTexture" inherits="UIPanelScrollBarButton" file="Interface\Buttons\UI-ScrollBar-Knob">
			<Size x="18" y="24"/>
			<TexCoords left="0.20" right="0.80" top="0.125" bottom="0.875"/>
		</ThumbTexture>
	</Slider>

	<ScrollFrame name="AltoUIPanelScrollFrameTemplate" virtual="true">
		<Frames>
			<Slider parentKey="ScrollBar" inherits="AltoUIPanelScrollBarTemplate">
				<Anchors>
					<Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="6" y="-16" />
					<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="6" y="16" />
				</Anchors>
			</Slider>
		</Frames>
		<ScrollChild>
			<Frame parentKey="ScrollChildFrame">
				<Size x="300" y="334" />
			</Frame>
		</ScrollChild>
		<KeyValues>
			<KeyValue key="rowPrefix" value="Entry" />
		</KeyValues>
		<Scripts>
			<OnLoad>
				Altoholic:BindViewToController(self, "AltoholicUI.UIPanelScrollFrame")
			</OnLoad>
			<OnScrollRangeChanged>
				self:OnScrollRangeChanged(xrange, yrange)
			</OnScrollRangeChanged>
			<!--  The code to disable the ScrollDownButton is pretty hacked, but it works -->
			<OnVerticalScroll>
				-- this code is actually not executed since it's always overriden in derived frames
				local scrollBar = self.ScrollBar
				scrollBar:SetValue(offset)
				
				local minimum, maximum = scrollBar:GetMinMaxValues()
				--print(format("min: %d, max: %d", minimum, maximum))
				
				if (offset == 0) then
					scrollBar.ScrollUpButton:Disable()
				else
					scrollBar.ScrollUpButton:Enable()
				end
				if ((scrollBar:GetValue() - maximum) == 0) then
					scrollBar.ScrollDownButton:Disable()
				else
					scrollBar.ScrollDownButton:Enable()
				end
			</OnVerticalScroll>
			<OnMouseWheel>
				self:OnMouseWheel(delta)
			</OnMouseWheel>
		</Scripts>
	</ScrollFrame>
	
	<!-- Used for data panels -->
	<ScrollFrame name="AltoBaseScrollFrameTemplate" inherits="AltoUIPanelScrollFrameTemplate" virtual="true">
		<Anchors>
			<Anchor point="TOPLEFT" />
			<Anchor point="BOTTOMRIGHT" />
		</Anchors>
		<Layers>
			<Layer level="ARTWORK">
				<Texture file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="31" y="256" />
					<Anchors>
						<Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="-2" y="5" />
					</Anchors>
					<TexCoords left="0" right="0.484375" top="0" bottom="1.0"/>
				</Texture>
				<Texture file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="31" y="106" />
					<Anchors>
						<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="-2" y="0" />
					</Anchors>
					<TexCoords left="0.515625" right="1.0" top="0" bottom="0.4140625"/>
				</Texture>
			</Layer>
		</Layers>
	</ScrollFrame>
	
	<!-- Used for left-side menus -->
	<ScrollFrame name="AltoMenuScrollFrameTemplate" inherits="AltoUIPanelScrollFrameTemplate" virtual="true">
		<Size x="160" y="305" />
		<Anchors>
			<Anchor point="TOPRIGHT" relativePoint="TOPLEFT" x="158" y="-105" />
		</Anchors>
		<Layers>
			<Layer level="ARTWORK">
				<Texture file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="31" y="256" />
					<Anchors>
						<Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="-2" y="5" />
					</Anchors>
					<TexCoords left="0" right="0.484375" top="0" bottom="1.0"/>
				</Texture>
				<Texture file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="31" y="106" />
					<Anchors>
						<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="-2" y="-2" />
					</Anchors>
					<TexCoords left="0.515625" right="1.0" top="0" bottom="0.4140625"/>
				</Texture>
			</Layer>
		</Layers>
	</ScrollFrame>
</Ui>
