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 = 9
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 self.dropdown:SetPoint("TOPLEFT", self.frame, "BOTTOMLEFT")
151 for k, v in pairs(self.list) do
152 sortedlist[#sortedlist+1] = k
154 table.sort(sortedlist, textSort)
155 for i, k in ipairs(sortedlist) do
156 local f = GetContentLine()
159 if k == self.value then
163 f.dropdown = self.dropdown
164 self.dropdown:AddFrame(f)
170 local function ClearFocus(self)
171 if self.dropdown then
172 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
176 local function OnHide(this)
177 local self = this.obj
178 if self.dropdown then
179 self.dropdown = AGSMW:ReturnDropDownFrame(self.dropdown)
183 local function Drop_OnEnter(this)
184 this.obj:Fire("OnEnter")
187 local function Drop_OnLeave(this)
188 this.obj:Fire("OnLeave")
191 local function Constructor()
192 local frame = AGSMW:GetBaseFrameWithWindow()
195 self.type = widgetType
198 frame.dropButton.obj = self
199 frame.dropButton:SetScript("OnEnter", Drop_OnEnter)
200 frame.dropButton:SetScript("OnLeave", Drop_OnLeave)
201 frame.dropButton:SetScript("OnClick",ToggleDrop)
202 frame:SetScript("OnHide", OnHide)
204 self.alignoffset = 31
206 self.OnRelease = OnRelease
207 self.OnAcquire = OnAcquire
208 self.ClearFocus = ClearFocus
209 self.SetText = SetText
210 self.SetValue = SetValue
211 self.GetValue = GetValue
212 self.SetList = SetList
213 self.SetLabel = SetLabel
214 self.SetDisabled = SetDisabled
215 self.AddItem = AddItem
216 self.SetMultiselect = SetMultiselect
217 self.GetMultiselect = GetMultiselect
218 self.SetItemValue = SetItemValue
219 self.SetItemDisabled = SetItemDisabled
220 self.ToggleDrop = ToggleDrop
222 AceGUI:RegisterAsWidget(self)
226 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)