<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="AddonFactory_UIPanelScrollBarTemplate" 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="AddonFactory_UIPanelScrollFrameTemplate" virtual="true">
		<Frames>
			<Slider parentKey="ScrollBar" inherits="AddonFactory_UIPanelScrollBarTemplate">
				<Anchors>
					<Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="-20" y="-18" />
					<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="-20" y="17" />
				</Anchors>
			</Slider>
		</Frames>
		<ScrollChild>
			<Frame parentKey="ScrollChildFrame">
				<Size x="300" y="334" />
			</Frame>
		</ScrollChild>
		<KeyValues>
			<KeyValue key="rowPrefix" value="Entry" />
		</KeyValues>
		<Scripts>
			<OnLoad>
				LibStub("LibMVC-1.0"):BindViewToController(self, "AddonFactory.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 _, maximum = scrollBar:GetMinMaxValues()
				
				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>
			<OnScrollRangeChanged function=""/>
		</Scripts>
	</ScrollFrame>
	
	<!-- Used for data panels -->
	<ScrollFrame name="AddonFactory_BaseScrollFrameTemplate" inherits="AddonFactory_UIPanelScrollFrameTemplate" virtual="true">
		<Anchors>
			<Anchor point="TOPLEFT" />
			<Anchor point="BOTTOMRIGHT" />
		</Anchors>
		<Layers>
			<Layer level="BORDER">
				<Texture parentKey="scrollBorderTop" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="31" y="256" />
					<Anchors>
						<Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="-28" y="2" />
					</Anchors>
					<TexCoords left="0" right="0.484375" top="0" bottom="1.0"/>
				</Texture>
				<Texture parentKey="scrollBorderBottom" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="31" y="106" />
					<Anchors>
						<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="-28" y="-2" />
					</Anchors>
					<TexCoords left="0.515625" right="1.0" top="0" bottom="0.4140625"/>
				</Texture>
				<Texture parentKey="scrollBorderMiddle" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Anchors>
						<Anchor point="TOPLEFT" relativeKey="$parent.scrollBorderTop" relativePoint="BOTTOMLEFT"/>
						<Anchor point="BOTTOMRIGHT" relativeKey="$parent.scrollBorderBottom" relativePoint="TOPRIGHT"/>
					</Anchors>
					<TexCoords left="0" right="0.484375" top="0.1640625" bottom="1"/>
				</Texture>
			</Layer>
			<Layer level="BACKGROUND">
				<Texture parentKey="scrollFrameScrollBarBackground">
					<Anchors>
						<Anchor point="TOPLEFT" relativeKey="$parent.scrollBorderTop" relativePoint="TOPLEFT"/>
						<Anchor point="BOTTOMRIGHT" relativeKey="$parent.scrollBorderBottom" relativePoint="BOTTOMRIGHT"/>
					</Anchors>
					<Color r="0" g="0" b="0"/>
				</Texture>
			</Layer>
		</Layers>
	</ScrollFrame>
	
	<!-- Used for left-side menus -->
	<ScrollFrame name="AddonFactory_MenuScrollFrameTemplate" inherits="AddonFactory_UIPanelScrollFrameTemplate" virtual="true">
		<Size x="188" y="438" />
		<Anchors>
			<Anchor point="TOPRIGHT" relativePoint="TOPLEFT" x="188" y="0" />
		</Anchors>
		<Layers>
			<Layer level="BORDER">
				<Texture parentKey="scrollBorderTop" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="28" y="48"/>
					<Anchors>
						<Anchor point="TOPRIGHT" relativePoint="TOPRIGHT" x="0" y="2"/>
					</Anchors>
					<TexCoords left="0" right="0.484375" top="0" bottom="0.2"/>
				</Texture>
				<Texture parentKey="scrollBorderBottom" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Size x="28" y="67"/>
					<Anchors>
						<Anchor point="BOTTOMRIGHT" relativePoint="BOTTOMRIGHT" x="0" y="0"/>
					</Anchors>
					<TexCoords left="0.515625" right="1.0" top="0.1440625" bottom="0.4140625"/>
				</Texture>
				<Texture parentKey="scrollBorderMiddle" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
					<Anchors>
						<Anchor point="TOPLEFT" relativeKey="$parent.scrollBorderTop" relativePoint="BOTTOMLEFT"/>
						<Anchor point="BOTTOMRIGHT" relativeKey="$parent.scrollBorderBottom" relativePoint="TOPRIGHT"/>
					</Anchors>
					<TexCoords left="0" right="0.484375" top="0.1640625" bottom="1"/>
				</Texture>
			</Layer>
			<Layer level="BACKGROUND">
				<Texture parentKey="scrollFrameScrollBarBackground">
					<Anchors>
						<Anchor point="TOPLEFT" relativeKey="$parent.scrollBorderTop" relativePoint="TOPLEFT"/>
						<Anchor point="BOTTOMRIGHT" relativeKey="$parent.scrollBorderBottom" relativePoint="BOTTOMRIGHT"/>
					</Anchors>
					<Color r="0" g="0" b="0"/>
				</Texture>
			</Layer>
		</Layers>
	</ScrollFrame>
</Ui>
