1 --[[ $Id: AceGUIWidget-DropDown-Items.lua 996 2010-12-01 18:34:17Z nevcairiel $ ]]--
3 local AceGUI = LibStub("AceGUI-3.0")
6 local select, assert = select, assert
9 local PlaySound = PlaySound
10 local CreateFrame = CreateFrame
12 local function fixlevels(parent,...)
14 local child = select(i, ...)
16 child:SetFrameLevel(parent:GetFrameLevel()+1)
17 fixlevels(child, child:GetChildren())
19 child = select(i, ...)
23 local function fixstrata(strata, parent, ...)
25 local child = select(i, ...)
26 parent:SetFrameStrata(strata)
28 fixstrata(strata, child, child:GetChildren())
30 child = select(i, ...)
34 -- ItemBase is the base "class" for all dropdown items.
35 -- Each item has to use ItemBase.Create(widgetType) to
36 -- create an initial 'self' value.
37 -- ItemBase will add common functions and ui event handlers.
38 -- Be sure to keep basic usage when you override functions.
41 -- NOTE: The ItemBase version is added to each item's version number
42 -- to ensure proper updates on ItemBase changes.
43 -- Use at least 1000er steps.
48 function ItemBase.Frame_OnEnter(this)
51 if self.useHighlight then
56 if self.specialOnEnter then
57 self.specialOnEnter(self)
61 function ItemBase.Frame_OnLeave(this)
67 if self.specialOnLeave then
68 self.specialOnLeave(self)
72 -- exported, AceGUI callback
73 function ItemBase.OnAcquire(self)
74 self.frame:SetToplevel(true)
75 self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
78 -- exported, AceGUI callback
79 function ItemBase.OnRelease(self)
80 self:SetDisabled(false)
82 self.frame:SetParent(nil)
83 self.frame:ClearAllPoints()
88 -- NOTE: this is called by a Dropdown-Pullout.
89 -- Do not call this method directly
90 function ItemBase.SetPullout(self, pullout)
91 self.pullout = pullout
93 self.frame:SetParent(nil)
94 self.frame:SetParent(pullout.itemFrame)
95 self.parent = pullout.itemFrame
96 fixlevels(pullout.itemFrame, pullout.itemFrame:GetChildren())
100 function ItemBase.SetText(self, text)
101 self.text:SetText(text or "")
105 function ItemBase.GetText(self)
106 return self.text:GetText()
110 function ItemBase.SetPoint(self, ...)
111 self.frame:SetPoint(...)
115 function ItemBase.Show(self)
120 function ItemBase.Hide(self)
125 function ItemBase.SetDisabled(self, disabled)
126 self.disabled = disabled
128 self.useHighlight = false
129 self.text:SetTextColor(.5, .5, .5)
131 self.useHighlight = true
132 self.text:SetTextColor(1, 1, 1)
137 -- NOTE: this is called by a Dropdown-Pullout.
138 -- Do not call this method directly
139 function ItemBase.SetOnLeave(self, func)
140 self.specialOnLeave = func
144 -- NOTE: this is called by a Dropdown-Pullout.
145 -- Do not call this method directly
146 function ItemBase.SetOnEnter(self, func)
147 self.specialOnEnter = func
150 function ItemBase.Create(type)
151 -- NOTE: Most of the following code is copied from AceGUI-3.0/Dropdown widget
152 local count = AceGUI:GetNextWidgetNum(type)
153 local frame = CreateFrame("Button", "AceGUI30DropDownItem"..count)
159 self.useHighlight = true
162 frame:SetFrameStrata("FULLSCREEN_DIALOG")
164 local text = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
165 text:SetTextColor(1,1,1)
166 text:SetJustifyH("LEFT")
167 text:SetPoint("TOPLEFT",frame,"TOPLEFT",18,0)
168 text:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-8,0)
171 local highlight = frame:CreateTexture(nil, "OVERLAY")
172 highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
173 highlight:SetBlendMode("ADD")
174 highlight:SetHeight(14)
175 highlight:ClearAllPoints()
176 highlight:SetPoint("RIGHT",frame,"RIGHT",-3,0)
177 highlight:SetPoint("LEFT",frame,"LEFT",5,0)
179 self.highlight = highlight
181 local check = frame:CreateTexture("OVERLAY")
184 check:SetPoint("LEFT",frame,"LEFT",3,-1)
185 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
189 local sub = frame:CreateTexture("OVERLAY")
192 sub:SetPoint("RIGHT",frame,"RIGHT",-3,-1)
193 sub:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow")
197 frame:SetScript("OnEnter", ItemBase.Frame_OnEnter)
198 frame:SetScript("OnLeave", ItemBase.Frame_OnLeave)
200 self.OnAcquire = ItemBase.OnAcquire
201 self.OnRelease = ItemBase.OnRelease
203 self.SetPullout = ItemBase.SetPullout
204 self.GetText = ItemBase.GetText
205 self.SetText = ItemBase.SetText
206 self.SetDisabled = ItemBase.SetDisabled
208 self.SetPoint = ItemBase.SetPoint
209 self.Show = ItemBase.Show
210 self.Hide = ItemBase.Hide
212 self.SetOnLeave = ItemBase.SetOnLeave
213 self.SetOnEnter = ItemBase.SetOnEnter
218 -- Register a dummy LibStub library to retrieve the ItemBase, so other addons can use it.
219 local IBLib = LibStub:NewLibrary("AceGUI-3.0-DropDown-ItemBase", ItemBase.version)
221 IBLib.GetItemBase = function() return ItemBase end
230 local widgetType = "Dropdown-Item-"
231 local widgetVersion = 1
233 local function Constructor()
234 local self = ItemBase.Create(widgetType)
236 AceGUI:RegisterAsWidget(self)
240 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
245 -- A single text entry.
246 -- Special: Different text color and no highlight
248 local widgetType = "Dropdown-Item-Header"
249 local widgetVersion = 1
251 local function OnEnter(this)
252 local self = this.obj
255 if self.specialOnEnter then
256 self.specialOnEnter(self)
260 local function OnLeave(this)
261 local self = this.obj
264 if self.specialOnLeave then
265 self.specialOnLeave(self)
269 -- exported, override
270 local function SetDisabled(self, disabled)
271 ItemBase.SetDisabled(self, disabled)
273 self.text:SetTextColor(1, 1, 0)
277 local function Constructor()
278 local self = ItemBase.Create(widgetType)
280 self.SetDisabled = SetDisabled
282 self.frame:SetScript("OnEnter", OnEnter)
283 self.frame:SetScript("OnLeave", OnLeave)
285 self.text:SetTextColor(1, 1, 0)
287 AceGUI:RegisterAsWidget(self)
291 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
297 local widgetType = "Dropdown-Item-Execute"
298 local widgetVersion = 1
300 local function Frame_OnClick(this, button)
301 local self = this.obj
302 if self.disabled then return end
309 local function Constructor()
310 local self = ItemBase.Create(widgetType)
312 self.frame:SetScript("OnClick", Frame_OnClick)
314 AceGUI:RegisterAsWidget(self)
318 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
322 -- Some sort of checkbox for dropdown menus.
323 -- Does not close the pullout on click.
325 local widgetType = "Dropdown-Item-Toggle"
326 local widgetVersion = 3
328 local function UpdateToggle(self)
336 local function OnRelease(self)
337 ItemBase.OnRelease(self)
341 local function Frame_OnClick(this, button)
342 local self = this.obj
343 if self.disabled then return end
344 self.value = not self.value
346 PlaySound("igMainMenuOptionCheckBoxOn")
348 PlaySound("igMainMenuOptionCheckBoxOff")
351 self:Fire("OnValueChanged", self.value)
355 local function SetValue(self, value)
361 local function GetValue(self)
365 local function Constructor()
366 local self = ItemBase.Create(widgetType)
368 self.frame:SetScript("OnClick", Frame_OnClick)
370 self.SetValue = SetValue
371 self.GetValue = GetValue
372 self.OnRelease = OnRelease
374 AceGUI:RegisterAsWidget(self)
378 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
382 -- Shows a submenu on mouse over
383 -- Does not close the pullout on click
385 local widgetType = "Dropdown-Item-Menu"
386 local widgetVersion = 2
388 local function OnEnter(this)
389 local self = this.obj
392 if self.specialOnEnter then
393 self.specialOnEnter(self)
396 self.highlight:Show()
398 if not self.disabled and self.submenu then
399 self.submenu:Open("TOPLEFT", self.frame, "TOPRIGHT", self.pullout:GetRightBorderWidth(), 0, self.frame:GetFrameLevel() + 100)
403 local function OnHide(this)
404 local self = this.obj
411 local function SetMenu(self, menu)
412 assert(menu.type == "Dropdown-Pullout")
417 local function CloseMenu(self)
421 local function Constructor()
422 local self = ItemBase.Create(widgetType)
426 self.frame:SetScript("OnEnter", OnEnter)
427 self.frame:SetScript("OnHide", OnHide)
429 self.SetMenu = SetMenu
430 self.CloseMenu = CloseMenu
432 AceGUI:RegisterAsWidget(self)
436 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
440 -- A single line to separate items
442 local widgetType = "Dropdown-Item-Separator"
443 local widgetVersion = 1
445 -- exported, override
446 local function SetDisabled(self, disabled)
447 ItemBase.SetDisabled(self, disabled)
448 self.useHighlight = false
451 local function Constructor()
452 local self = ItemBase.Create(widgetType)
454 self.SetDisabled = SetDisabled
456 local line = self.frame:CreateTexture(nil, "OVERLAY")
458 line:SetTexture(.5, .5, .5)
459 line:SetPoint("LEFT", self.frame, "LEFT", 10, 0)
460 line:SetPoint("RIGHT", self.frame, "RIGHT", -10, 0)
464 self.useHighlight = false
466 AceGUI:RegisterAsWidget(self)
470 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)