<?xml version="1.0"?>
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ http://wowprogramming.com/FrameXML/UI.xsd">
    <!-- Ensure we always have access to Backdrops on both classic and retail -->
    <Frame name="Clique_BackdropTemplate" virtual="true">
        <Scripts>
            <OnLoad>
                if BackdropTemplateMixin then
                    Mixin(self, BackdropTemplateMixin);
                end
            </OnLoad>
            <OnSizeChanged>
                if self.OnBackdropSizeChanged then
                    self:OnBackdropSizeChanged();
                end
            </OnSizeChanged>
        </Scripts>
    </Frame>

    <Button name="CliqueRowTemplate" enableMouse="true" virtual="true">
        <Size x="298" y="30"/>
        <Layers>
            <Layer level="BORDER">
                <Texture name="$parentIcon" parentKey="icon" file="Interface\Icons\INV_Misc_QuestionMark">
                    <Size x="25" y="25"/>
                    <Anchors>
                        <Anchor point="LEFT">
                            <Offset>
                                <AbsDimension x="5" y="0"/>
                            </Offset>
                        </Anchor>
                    </Anchors>
                </Texture>
                <FontString name="$parentName" parentKey="name" inherits="GameFontHighlight" justifyH="LEFT" text="An error has occurred">
                    <Size>
                        <AbsDimension x="175" y="12"/>
                    </Size>
                    <Anchors>
                        <Anchor point="TOPLEFT" relativeTo="$parentIcon" relativePoint="TOPRIGHT">
                            <Offset>
                                <AbsDimension x="3" y="0"/>
                            </Offset>
                        </Anchor>
                    </Anchors>
                </FontString>
                <FontString name="$parentInfo" parentKey="info" inherits="GameFontNormalSmall" justifyH="LEFT" text="Spell">
                    <Size>
                        <AbsDimension x="175" y="12"/>
                    </Size>
                    <Anchors>
                        <Anchor point="TOPLEFT" relativeTo="$parentName" relativePoint="BOTTOMLEFT">
                            <Offset>
                                <AbsDimension x="0" y="-2"/>
                            </Offset>
                        </Anchor>
                    </Anchors>
                    <Color r="0.6" g="0.6" b="0.6"/>
                </FontString>
                <FontString name="$parentBind" parentKey="bind" inherits="GameFontHighlightSmall" justifyH="RIGHT" text="Alt-LeftClick">
                    <Size>
                        <AbsDimension x="106" y="12"/>
                    </Size>
                    <Anchors>
                        <Anchor point="TOPLEFT" relativeTo="$parentName" relativePoint="TOPRIGHT">
                            <Offset>
                                <AbsDimension x="0" y="0"/>
                            </Offset>
                        </Anchor>
                    </Anchors>
                </FontString>
            </Layer>
        </Layers>
        <Scripts>
            <OnLoad>
                self:RegisterForClicks("RightButtonDown")
            </OnLoad>
            <OnClick>
                CliqueConfig:Row_OnClick(self, button)
            </OnClick>
            <OnMouseWheel>
                local slider = CliqueConfig.page1.slider
                slider:SetValue(slider:GetValue() - delta)
            </OnMouseWheel>
        </Scripts>
        <HighlightTexture setAllPoints="true" file="Interface\QuestFrame\UI-QuestTitleHighlight" alphaMode="ADD">
            <Size x="315" y="28"/>
            <Anchors>
                <Anchor point="TOPLEFT">
                    <Offset x="1" y="0"/>
                </Anchor>
            </Anchors>
        </HighlightTexture>
    </Button>

    <Button name="CliqueColumnTemplate" inherits="WhoFrameColumnHeaderTemplate" virtual="true">
        <Scripts>
            <OnClick>
                PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
                CliqueConfig:Column_OnClick(self, button)
            </OnClick>
        </Scripts>
    </Button>

    <Button name="CliqueSpellbookButtonTemplate" setAllPoints="true" hidden="true" virtual="true">
        <Scripts>
            <OnEnter>
                local parent = self:GetParent()
                if not Clique:APIIsTrue(parent:IsEnabled()) then
                    self:GetHighlightTexture():Hide()
                end

                CliqueConfig:Spellbook_EnableKeyboard(self, motion)
            </OnEnter>
            <OnLeave>
                GameTooltip:Hide()
                CliqueConfig:Spellbook_DisableKeyboard(self, motion)
            </OnLeave>
            <OnClick>
                CliqueConfig:Spellbook_OnBinding(self, button)
            </OnClick>
            <OnKeyDown>
                CliqueConfig:Spellbook_OnBinding(self, key)
            </OnKeyDown>
            <OnMouseWheel>
                if time() ~= self.last_mousewheel then
                    local button = (delta &gt; 0) and "MOUSEWHEELUP" or "MOUSEWHEELDOWN"
                    CliqueConfig:Spellbook_OnBinding(self, button)
                    self.last_mousewheel = time()
                end
            </OnMouseWheel>
        </Scripts>
        <HighlightTexture file="Interface\BUTTONS\ButtonHilight-Square" alphaMode="ADD"/>
    </Button>

    <CheckButton name="CliqueSpellTab" inherits="SpellBookSkillLineTabTemplate" parent="SpellBookSkillLineTab1" hidden="false">
        <Scripts>
            <OnClick>
                CliqueConfig:SpellTab_OnClick()
            </OnClick>
            <OnShow>
                if CliqueConfig:IsVisible() then
                    self:SetChecked(true)
                end

                local num = GetNumSpellTabs()
                self:ClearAllPoints()
                local lastTab = _G["SpellBookSkillLineTab" .. num]
                self:SetPoint("TOPLEFT", lastTab, "BOTTOMLEFT", 0, -17)
            </OnShow>
        </Scripts>
        <NormalTexture file="Interface\AddOns\Clique\images\icon_square_64"/>
    </CheckButton>

    <Frame name="CliqueTabAlert" parentKey="alert" inherits="GlowBoxTemplate" parent="SpellBookFrame" enableMouse="true" hidden="true" frameStrata="DIALOG" framelevel="2">
        <Size x="220" y="100"/>
        <Anchors>
            <Anchor point="LEFT" relativeTo="CliqueSpellTab" relativePoint="RIGHT" x="20" y="0"/>
        </Anchors>
        <Layers>
            <Layer level="OVERLAY">
                <FontString name="$parentText" parentKey="text" inherits="GameFontHighlightLeft" justifyV="TOP" text="" >
                    <Size x="188" y="0"/>
                    <Anchors>
                        <Anchor point="TOPLEFT" x="16" y="-24"/>
                    </Anchors>
                </FontString>
            </Layer>
        </Layers>
        <Frames>
            <Button name="$parentClose" parentKey="close" inherits="UIPanelCloseButton">
                <Anchors>
                    <Anchor point="TOPRIGHT" x="6" y="6"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        Clique.settings.alerthidden = true
                        CliqueTabAlert:Hide();
                    </OnClick>
                </Scripts>
            </Button>
            <Frame name="$parentArrow" parentKey="arrow" inherits="GlowBoxArrowTemplate">
                <Anchors>
                    <Anchor point="RIGHT" relativePoint="LEFT" x="0" y="0"/>
                </Anchors>
            </Frame>
        </Frames>
        <Scripts>
            <OnLoad>
                self.arrow:SetSize(21, 53)
                self.arrow.arrow = _G[self.arrow:GetName() .. "Arrow"]
                self.arrow.glow = _G[self.arrow:GetName() .. "Glow"]
                self.arrow.arrow:SetAllPoints(true)
                self.arrow.glow:SetAllPoints(true)
                -- Rotate 90 degrees
                -- left, bottom, right, bottom, left, top, right, top
                self.arrow.arrow:SetTexCoord(0.78515625, 0.58789063, 0.99218750, 0.58789063, 0.78515625, 0.54687500, 0.99218750, 0.54687500)
                self.arrow.glow:SetTexCoord(0.40625000, 0.82812500, 0.66015625, 0.82812500, 0.40625000, 0.77343750, 0.66015625, 0.77343750)
                self.text:SetSpacing(4)

            </OnLoad>
            <OnShow>
                self:SetHeight(self.text:GetHeight() + 42)
            </OnShow>
        </Scripts>
    </Frame>

    <Frame name="CliqueDialog" toplevel="true" enableMouse="true" movable="true" inherits="BasicFrameTemplate" parent="UIParent" frameStrata="DIALOG" hidden="true">
        <Size x="350" y="160"/>
        <Layers>
            <Layer level="OVERLAY"> 
                <FontString name="$parentDesc" parentKey="desc" inherits="GameFontHighlightSmallLeftTop">
                    <Size x="340" y="60"/>
                    <Anchors>
                        <Anchor point="TOPLEFT" x="5" y="-25"/>
                    </Anchors>
                </FontString>
                <FontString name="$parentBindText" parentKey="bindText" JustifyH="CENTER" inherits="GameFontHighlightSmallLeftTop">
                    <Size x="200" y="12"/>
                    <Anchors>
                        <Anchor point="BOTTOM" x="0" y="35"/>
                    </Anchors>
                </FontString>
            </Layer>
        </Layers>
        <Frames>
            <Button name="$parentDragButton">
                <Size x="0" y="20"/>
                <Anchors>
                    <Anchor point="TOPLEFT"/>
                    <Anchor point="TOPRIGHT"/>
                </Anchors>
                <Scripts>
                    <OnLoad>
                        self:RegisterForClicks("LeftButton") 
                    </OnLoad>
                    <OnMouseDown>
                        CliqueDialog:SetUserPlaced(false)
                        CliqueDialog:StartMoving()
                    </OnMouseDown>
                    <OnMouseUp>
                        CliqueDialog:SetUserPlaced(false)
                        CliqueDialog:StopMovingOrSizing()
                    </OnMouseUp>
                    <OnHide>
                        CliqueDialog:SetUserPlaced(false)
                        CliqueDialog:StopMovingOrSizing()
                    </OnHide>
                </Scripts>
            </Button>
            <Button name="$parentButtonBinding" parentKey="button_binding" inherits="UIPanelButtonTemplate">
                <Size x="160" y="22"/>
                <Anchors>
                    <Anchor point="TOP" relativeTo="$parentDesc" relativePoint="BOTTOM" x="0" y="0"/>
                </Anchors>
                <Scripts>
                    <OnLoad>
                        self:RegisterForClicks("AnyUp")
                        self:EnableKeyboard(false)
                    </OnLoad>
                    <OnEnter>
                        if motion then
                            self:EnableKeyboard(true)
                        end
                    </OnEnter>
                    <OnLeave>
                        self:EnableKeyboard(false)
                    </OnLeave>
                    <OnClick>
                        CliqueConfig:BindingButton_OnClick(self, button)
                    </OnClick>
                    <OnKeyDown>
                        CliqueConfig:BindingButton_OnClick(self, key)
                    </OnKeyDown>
                    <OnMouseWheel>
                        local button = (delta > 0) and "MOUSEWHEELUP" or "MOUSEWHEELDOWN"
                        CliqueConfig:BindingButton_OnClick(self, button)
                    </OnMouseWheel>
                </Scripts>
            </Button>
            <Button name="$parentButtonAccept" parentKey="button_accept" inherits="UIPanelButtonTemplate">
                <Size x="80" y="22"/>
                <Anchors>
                    <Anchor point="BOTTOMRIGHT" x="-3" y="3"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        CliqueConfig:AcceptSetBinding()
                    </OnClick>
                </Scripts>
            </Button>
        </Frames>
        <Scripts>
            <OnLoad>
                table.insert(UISpecialFrames, "CliqueDialog")
            </OnLoad>
        </Scripts>
    </Frame>

    <!-- Main configuration frame -->
    <Frame name="CliqueConfig" inherits="ButtonFrameTemplate" parent="UIParent" hidden="true">
        <Size>
            <AbsDimension x="333" y="475"/>
        </Size>
        <Anchors>
            <Anchor point="CENTER" x="0" y="0"/>
        </Anchors>
        <Frames>
            <!-- Dropdown menu for utility -->
            <Frame name="$parentDropdown" parentKey="dropdown" inherits="UIDropDownMenuTemplate"/>

            <!-- Page definitions - Configuration List -->
            <Frame name="$parentPage1" parentKey="page1" hidden="true">
                <Frames>
                    <Button name="$parentColumn1" parentKey="column1" inherits="CliqueColumnTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT">
                                <Offset x="0" y="0"/>
                            </Anchor>
                        </Anchors>
                        <Scripts>
                            <OnLoad>
                                local width = 203
                                self:SetWidth(width);
                                _G[self:GetName().."Middle"]:SetWidth(width - 9);
                            </OnLoad>
                        </Scripts>
                    </Button>
                    <Button name="$parentColumn2" parentKey="column2" inherits="CliqueColumnTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativePoint="TOPRIGHT" relativeTo="$parentColumn1">
                                <Offset x="-2" y="0"/>
                            </Anchor>
                        </Anchors>
                        <Scripts>
                            <OnLoad>
                                local width = 120
                                self:SetWidth(width);
                                _G[self:GetName().."Middle"]:SetWidth(width - 9);
                            </OnLoad>
                        </Scripts>
                        <ButtonText>
                            <Anchors>
                                <Anchor point="RIGHT">
                                    <Offset>
                                        <AbsDimension x="-8" y="0"/>
                                    </Offset>
                                </Anchor>
                            </Anchors>
                        </ButtonText>
                    </Button>
                    <Slider name="$parent_VSlider" parentKey="slider" valueStep="1.0" hidden="true" orientation="VERTICAL" inherits="Clique_BackdropTemplate">
                        <Size x="18" y="0"/>
                        <Anchors>
                            <Anchor point="TOPRIGHT" x="0" y="-20"/>
                            <Anchor point="BOTTOMRIGHT"/>
                        </Anchors>
                        <Scripts>
                            <OnLoad inherit="prepend">
                                local backdropInfo = {
                                    bgFile   = "Interface\\Buttons\\UI-SliderBar-Background",
                                    edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
                                    tile     = true,
                                    tileEdge = true,
                                    tileSize = 8,
                                    edgeSize = 8,
                                    insets   = {left = 3, right = 3, top = 6, bottom = 6},
                                }
                                self:SetBackdrop(backdropInfo)
                            </OnLoad>
                            <OnValueChanged>
                                CliqueConfig:UpdateList()
                            </OnValueChanged>
                        </Scripts>
                        <ThumbTexture name="$parentThumbTexture" file="Interface\Buttons\UI-ScrollBar-Knob">
                            <Size x="24" y="24"/>
                        </ThumbTexture>
                    </Slider>
                    <Button name="$parentButtonSpell" parentKey="button_spell" inherits="MagicButtonTemplate">
                        <Size x="100" y="22"/>
                        <Anchors>
                            <Anchor point="BOTTOMLEFT" relativeTo="CliqueConfig"/>
                        </Anchors>
                        <Scripts>
                            <OnClick>
                                CliqueConfig:Button_OnClick(self)
                            </OnClick>
                        </Scripts>
                    </Button>
                    <Button name="$parentButtonOther" parentKey="button_other" inherits="MagicButtonTemplate">
                        <Size x="100" y="22"/>
                        <Anchors>
                            <Anchor point="TOPLEFT" relativeTo="$parentButtonSpell" relativePoint="TOPRIGHT"/>
                        </Anchors>
                        <Scripts>
                            <OnClick>
                                CliqueConfig:Button_OnClick(self)
                            </OnClick>
                        </Scripts>
                    </Button>
                    <Button name="$parentButtonOptions" parentKey="button_options" inherits="MagicButtonTemplate">
                        <Size x="80" y="22"/>
                        <Anchors>
                            <Anchor point="BOTTOMRIGHT" relativeTo="CliqueConfig"/>
                        </Anchors>
                        <Scripts>
                            <OnClick>
                                CliqueConfig:Button_OnClick(self)
                            </OnClick>
                        </Scripts>
                    </Button>
                </Frames>
                <Scripts>
                    <OnShow>
                        CliqueConfig:EnableSpellbookButtons()
                    </OnShow>
                    <OnHide>
                        CliqueConfig:EnableSpellbookButtons()
                    </OnHide>
                </Scripts>
            </Frame> <!-- Page 1 - Configuration List -->

             <!-- Page definitions - Edit Page -->
            <Frame name="$parentPage2" parentKey="page2" hidden="true">
                <Layers>
                    <Layer level="OVERLAY">
                        <FontString name="$parentDesc" parentKey="desc" inherits="GameFontHighlightSmallLeftTop">
                            <Size x="0" y="200"/>
                            <Anchors>
                                <Anchor point="TOPLEFT" x="5" y="-5"/>
                                <Anchor point="TOPRIGHT" x="-5" y="-5"/>
                            </Anchors>
                        </FontString>
                        <FontString name="$parentBindText" parentKey="bindText" JustifyH="CENTER" inherits="GameFontHighlightSmallLeftTop">
                            <Size x="200" y="12"/>
                            <Anchors>
                                <Anchor point="CENTER" relativeTo="$parent" x="0" y="-24"/>
                            </Anchors>
                        </FontString>
                    </Layer>
                </Layers>
                <Frames>
                    <Button name="$parentButtonBinding" parentKey="button_binding" inherits="UIPanelButtonTemplate">
                        <Size x="160" y="22"/>
                        <Anchors>
                            <Anchor point="CENTER" relativeTo="$parent" x="0" y="0"/>
                        </Anchors>
                        <Scripts>
                            <OnLoad>
                                self:RegisterForClicks("AnyUp")
                                self:EnableKeyboard(false)
                            </OnLoad>
                            <OnEnter>
                                if motion then
                                    self:EnableKeyboard(true)
                                end
                                if CliqueConfig.page2.editbox:HasFocus() then
                                    CliqueConfig.page2.editbox:ClearFocus()
                                end
                            </OnEnter>
                            <OnLeave>
                                self:EnableKeyboard(false)
                            </OnLeave>
                            <OnClick>
                                CliqueConfig:MacroBindingButton_OnClick(self, button)
                            </OnClick>
                            <OnKeyDown>
                                CliqueConfig:MacroBindingButton_OnClick(self, key)
                            </OnKeyDown>
                            <OnMouseWheel>
                                local button = (delta > 0) and "MOUSEWHEELUP" or "MOUSEWHEELDOWN"
                                CliqueConfig:MacroBindingButton_OnClick(self, button)
                            </OnMouseWheel>
                        </Scripts>
                    </Button>

                    <!-- Wrap the scroll frame in a frame that can capture clicks -->
                    <Button name="CliqueClickGrabber" parentKey="clickGrabber" inherits="Clique_BackdropTemplate">
                        <Size x="320" y="160"/>
                        <Anchors>
                            <Anchor point="BOTTOMLEFT" relativeTo="$parent" relativePoint="BOTTOMLEFT">
                                <Offset>
                                    <AbsDimension x="1" y="0"/>
                                </Offset>
                            </Anchor>
                        </Anchors>
                        <Scripts>
                            <OnLoad inherit="prepend">
                                local backdropInfo = {
                                    bgFile   = "Interface\\Tooltips\\UI-Tooltip-Background",
                                    edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
                                    tile     = true,
                                    tileEdge = true,
                                    tileSize = 16,
                                    edgeSize = 16,
                                    insets   = {left = 5, right = 5, top = 5, bottom = 5},
                                }
                                self:SetBackdrop(backdropInfo)
                                self:SetBackdropColor(0.3, 0.3, 0.3)
                                self:SetBackdropBorderColor(0.5, 0.5, 0.5)
                            </OnLoad>
                            <OnClick>
                                CliqueScrollFrameEditBox:SetFocus()
                            </OnClick>
                        </Scripts>
                        <Frames> 
                            <ScrollFrame name="CliqueScrollFrame" parentKey="scrollFrame" inherits="UIPanelScrollFrameTemplate">
                                <Size>
                                    <AbsDimension x="288" y="150"/>
                                </Size>
                                <Anchors>
                                    <Anchor point="TOPLEFT" relativeTo="$parent" relativePoint="TOPLEFT">
                                        <Offset>
                                            <AbsDimension x="5" y="-5"/>
                                        </Offset>
                                    </Anchor>
                                </Anchors>
                                <ScrollChild>
                                    <EditBox name="$parentEditBox" parentKey="editbox" multiLine="true" autoFocus="false" countInvisibleLetters="true">
                                        <Size>
                                            <AbsDimension x="288" y="85"/>
                                        </Size>
                                        <Scripts>
                                            <OnTextChanged>
                                                ScrollingEdit_OnTextChanged(self, self:GetParent());
                                            </OnTextChanged>
                                            <OnCursorChanged function="ScrollingEdit_OnCursorChanged"/>
                                            <OnUpdate>
                                                ScrollingEdit_OnUpdate(self, elapsed, self:GetParent());
                                            </OnUpdate>
                                            <OnEscapePressed function="EditBox_ClearFocus"/>
                                        </Scripts>
                                        <FontString inherits="GameFontHighlightSmall"/>
                                    </EditBox> 
                                </ScrollChild>
                            </ScrollFrame>
                        </Frames>
                    </Button>
                    <Button name="$parentButtonSave" parentKey="button_save" inherits="MagicButtonTemplate">
                        <Size x="80" y="22"/>
                        <Anchors>
                            <Anchor point="BOTTOMLEFT" relativeTo="CliqueConfig"/>
                        </Anchors>
                        <Scripts>
                            <OnClick>
                                CliqueConfig:Button_OnClick(self)
                            </OnClick>
                        </Scripts>
                    </Button>
                    <Button name="$parentButtonCancel" parentKey="button_cancel" inherits="MagicButtonTemplate">
                        <Size x="80" y="22"/>
                        <Anchors>
                            <Anchor point="BOTTOMRIGHT" relativeTo="CliqueConfig"/>
                        </Anchors>
                        <Scripts>
                            <OnClick>
                                CliqueConfig:Button_OnClick(self)
                            </OnClick>
                        </Scripts>
                    </Button>
                 </Frames>
            </Frame> <!-- Page 3 - Macro Edit Page -->

            <!-- Alert above the spellbook to show we're in binding mode -->
            <Frame name="CliqueConfigBindAlert" parentKey="bindAlert" inherits="GlowBoxTemplate" hidden="false" frameStrata="DIALOG" framelevel="2">
                <Size x="220" y="43"/>
                <Anchors>
                    <Anchor point="BOTTOMLEFT" relativeTo="SpellButton1" relativePoint="TOP" x="-40" y="25"/>
                </Anchors>
                <Layers>
                    <Layer level="OVERLAY">
                        <FontString name="$parentText" parentKey="text" inherits="GameFontHighlightLeft" justifyV="TOP" text="" >
                            <Size x="230" y="0"/>
                            <Anchors>
                                <Anchor point="TOPLEFT" x="16" y="-15"/>
                            </Anchors>
                        </FontString>
                    </Layer>
                </Layers>
                <Frames>
                    <Frame name="$parentArrow" parentKey="arrow" inherits="GlowBoxArrowTemplate">
                        <Anchors>
                            <Anchor point="TOP" relativePoint="BOTTOMLEFT" x="40" y="1"/>
                        </Anchors>
                    </Frame>
                </Frames>
                <Scripts>
                    <OnLoad>
                        self.text:SetSpacing(4)
                    </OnLoad>
                </Scripts>
            </Frame> <!-- End bindAlert -->
        </Frames>
        <Scripts>
            <OnLoad>
                CliqueConfigPortrait:SetTexture("Interface\\Addons\\Clique\\images\\icon_circle_128")
                CliqueConfig.page1:SetParent(CliqueConfig.Inset)
                CliqueConfig.page2:SetParent(CliqueConfig.Inset)
                CliqueConfig.page1:SetAllPoints(CliqueConfig.Inset)
                CliqueConfig.page2:SetAllPoints(CliqueConfig.Inset)
            </OnLoad>
            <OnShow>
                CliqueConfig:OnShow()
            </OnShow>
            <OnHide>
                CliqueConfig:OnHide()
            </OnHide>
        </Scripts>
    </Frame> <!-- CliqueConfig -->
</Ui>
