1 -- Widget is based on the AceGUIWidget-DropDown.lua supplied with AceGUI-3.0
2 -- Widget created by Yssaril
4 local AceGUI = LibStub("AceGUI-3.0")
5 local Media = LibStub("LibSharedMedia-3.0")
7 local AGSMW = LibStub("AceGUISharedMediaWidgets-1.0")
10 local widgetType = "LSM30_Border"
11 local widgetVersion = 10
13 local contentFrameCache = {}
14 local function ReturnSelf(self)
18 table.insert(contentFrameCache, self)
21 local function ContentOnClick(this, button)
23 self:Fire("OnValueChanged", this.text:GetText())
25 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
29 local function ContentOnEnter(this, button)
31 local text = this.text:GetText()
32 local border = self.list[text] ~= text and self.list[text] or Media:Fetch('border',text)
33 this.dropdown:SetBackdrop({edgeFile = border,
34 bgFile=[[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
35 tile = true, tileSize = 16, edgeSize = 16,
36 insets = { left = 4, right = 4, top = 4, bottom = 4 }})
39 local function GetContentLine()
41 if next(contentFrameCache) then
42 frame = table.remove(contentFrameCache)
44 frame = CreateFrame("Button", nil, UIParent)
47 frame:SetHighlightTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]], "ADD")
48 frame:SetScript("OnClick", ContentOnClick)
49 frame:SetScript("OnEnter", ContentOnEnter)
50 local check = frame:CreateTexture("OVERLAY")
53 check:SetPoint("LEFT",frame,"LEFT",1,-1)
54 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
57 local text = frame:CreateFontString(nil,"OVERLAY","GameFontWhite")
58 text:SetPoint("LEFT", check, "RIGHT", 1, 0)
59 text:SetPoint("RIGHT", frame, "RIGHT", -2, 0)
60 text:SetJustifyH("LEFT")
61 text:SetText("Test Test Test Test Test Test Test")
63 frame.ReturnSelf = ReturnSelf
69 local function OnAcquire(self)
74 local function OnRelease(self)
77 self:SetDisabled(false)
84 self.frame:ClearAllPoints()
88 local function SetValue(self, value) -- Set the value to an item in the List.
90 self:SetText(value or "")
95 local function GetValue(self)
99 local function SetList(self, list) -- Set the list of values for the dropdown (key => value pairs)
100 self.list = list or Media:HashTable("border")
104 local function SetText(self, text) -- Set the text displayed in the box.
105 self.frame.text:SetText(text or "")
106 local border = self.list[text] ~= text and self.list[text] or Media:Fetch('border',text)
108 self.frame.displayButton:SetBackdrop({edgeFile = border,
109 bgFile=[[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
110 tile = true, tileSize = 16, edgeSize = 16,
111 insets = { left = 4, right = 4, top = 4, bottom = 4 }})
114 local function SetLabel(self, text) -- Set the text for the label.
115 self.frame.label:SetText(text or "")
118 local function AddItem(self, key, value) -- Add an item to the list.
119 self.list = self.list or {}
120 self.list[key] = value
122 local SetItemValue = AddItem -- Set the value of a item in the list. <<same as adding a new item>>
124 local function SetMultiselect(self, flag) end -- Toggle multi-selecting. <<Dummy function to stay inline with the dropdown API>>
125 local function GetMultiselect() return false end-- Query the multi-select flag. <<Dummy function to stay inline with the dropdown API>>
126 local function SetItemDisabled(self, key) end-- Disable one item in the list. <<Dummy function to stay inline with the dropdown API>>
128 local function SetDisabled(self, disabled) -- Disable the widget.
129 self.disabled = disabled
137 local function textSort(a,b)
138 return string.upper(a) < string.upper(b)
141 local sortedlist = {}
142 local function ToggleDrop(this)
143 local self = this.obj
144 if self.dropdown then
145 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
148 AceGUI:SetFocus(self)
149 self.dropdown = AGSMW:GetDropDownFrame()
150 local width = self.frame:GetWidth()
151 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
152 self.dropdown:SetPoint("TOPRIGHT", self.frame, "BOTTOMRIGHT", width < 160 and (160 - width) or 0, 0)
153 for k, v in pairs(self.list) do
154 sortedlist[#sortedlist+1] = k
156 table.sort(sortedlist, textSort)
157 for i, k in ipairs(sortedlist) do
158 local f = GetContentLine()
161 if k == self.value then
165 f.dropdown = self.dropdown
166 self.dropdown:AddFrame(f)
172 local function ClearFocus(self)
173 if self.dropdown then
174 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
178 local function OnHide(this)
179 local self = this.obj
180 if self.dropdown then
181 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
185 local function Drop_OnEnter(this)
186 this.obj:Fire("OnEnter")
189 local function Drop_OnLeave(this)
190 this.obj:Fire("OnLeave")
193 local function Constructor()
194 local frame = AGSMW:GetBaseFrameWithWindow()
197 self.type = widgetType
200 frame.dropButton.obj = self
201 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
202 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
203 frame.dropButton:SetScript("OnClick",ToggleDrop)
204 frame:SetScript("OnHide", OnHide)
206 self.alignoffset = 31
208 self.OnRelease = OnRelease
209 self.OnAcquire = OnAcquire
210 self.ClearFocus = ClearFocus
211 self.SetText = SetText
212 self.SetValue = SetValue
213 self.GetValue = GetValue
214 self.SetList = SetList
215 self.SetLabel = SetLabel
216 self.SetDisabled = SetDisabled
217 self.AddItem = AddItem
218 self.SetMultiselect = SetMultiselect
219 self.GetMultiselect = GetMultiselect
220 self.SetItemValue = SetItemValue
221 self.SetItemDisabled = SetItemDisabled
222 self.ToggleDrop = ToggleDrop
224 AceGUI:RegisterAsWidget(self)
228 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)