tercio@5: --[[ $Id: AceGUIWidget-DropDown.lua 1116 2014-10-12 08:15:46Z nevcairiel $ ]]-- tercio@0: local AceGUI = LibStub("AceGUI-3.0") tercio@0: tercio@0: -- Lua APIs tercio@0: local min, max, floor = math.min, math.max, math.floor tercio@0: local select, pairs, ipairs, type = select, pairs, ipairs, type tercio@0: local tsort = table.sort tercio@0: tercio@0: -- WoW APIs tercio@0: local PlaySound = PlaySound tercio@0: local UIParent, CreateFrame = UIParent, CreateFrame tercio@0: local _G = _G tercio@0: tercio@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded tercio@0: -- List them here for Mikk's FindGlobals script tercio@0: -- GLOBALS: CLOSE tercio@0: tercio@0: local function fixlevels(parent,...) tercio@0: local i = 1 tercio@0: local child = select(i, ...) tercio@0: while child do tercio@0: child:SetFrameLevel(parent:GetFrameLevel()+1) tercio@0: fixlevels(child, child:GetChildren()) tercio@0: i = i + 1 tercio@0: child = select(i, ...) tercio@0: end tercio@0: end tercio@0: tercio@0: local function fixstrata(strata, parent, ...) tercio@0: local i = 1 tercio@0: local child = select(i, ...) tercio@0: parent:SetFrameStrata(strata) tercio@0: while child do tercio@0: fixstrata(strata, child, child:GetChildren()) tercio@0: i = i + 1 tercio@0: child = select(i, ...) tercio@0: end tercio@0: end tercio@0: tercio@0: do tercio@0: local widgetType = "Dropdown-Pullout" tercio@0: local widgetVersion = 3 tercio@0: tercio@0: --[[ Static data ]]-- tercio@0: tercio@0: local backdrop = { tercio@0: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", tercio@0: edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", tercio@0: edgeSize = 32, tercio@0: tileSize = 32, tercio@0: tile = true, tercio@0: insets = { left = 11, right = 12, top = 12, bottom = 11 }, tercio@0: } tercio@0: local sliderBackdrop = { tercio@0: bgFile = "Interface\\Buttons\\UI-SliderBar-Background", tercio@0: edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", tercio@0: tile = true, tileSize = 8, edgeSize = 8, tercio@0: insets = { left = 3, right = 3, top = 3, bottom = 3 } tercio@0: } tercio@0: tercio@0: local defaultWidth = 200 tercio@0: local defaultMaxHeight = 600 tercio@0: tercio@0: --[[ UI Event Handlers ]]-- tercio@0: tercio@0: -- HACK: This should be no part of the pullout, but there tercio@0: -- is no other 'clean' way to response to any item-OnEnter tercio@0: -- Used to close Submenus when an other item is entered tercio@0: local function OnEnter(item) tercio@0: local self = item.pullout tercio@0: for k, v in ipairs(self.items) do tercio@0: if v.CloseMenu and v ~= item then tercio@0: v:CloseMenu() tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: -- See the note in Constructor() for each scroll related function tercio@0: local function OnMouseWheel(this, value) tercio@0: this.obj:MoveScroll(value) tercio@0: end tercio@0: tercio@0: local function OnScrollValueChanged(this, value) tercio@0: this.obj:SetScroll(value) tercio@0: end tercio@0: tercio@0: local function OnSizeChanged(this) tercio@0: this.obj:FixScroll() tercio@0: end tercio@0: tercio@0: --[[ Exported methods ]]-- tercio@0: tercio@0: -- exported tercio@0: local function SetScroll(self, value) tercio@0: local status = self.scrollStatus tercio@0: local frame, child = self.scrollFrame, self.itemFrame tercio@0: local height, viewheight = frame:GetHeight(), child:GetHeight() tercio@0: tercio@0: local offset tercio@0: if height > viewheight then tercio@0: offset = 0 tercio@0: else tercio@0: offset = floor((viewheight - height) / 1000 * value) tercio@0: end tercio@0: child:ClearAllPoints() tercio@0: child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset) tercio@0: child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", self.slider:IsShown() and -12 or 0, offset) tercio@0: status.offset = offset tercio@0: status.scrollvalue = value tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function MoveScroll(self, value) tercio@0: local status = self.scrollStatus tercio@0: local frame, child = self.scrollFrame, self.itemFrame tercio@0: local height, viewheight = frame:GetHeight(), child:GetHeight() tercio@0: tercio@0: if height > viewheight then tercio@0: self.slider:Hide() tercio@0: else tercio@0: self.slider:Show() tercio@0: local diff = height - viewheight tercio@0: local delta = 1 tercio@0: if value < 0 then tercio@0: delta = -1 tercio@0: end tercio@0: self.slider:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000)) tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function FixScroll(self) tercio@0: local status = self.scrollStatus tercio@0: local frame, child = self.scrollFrame, self.itemFrame tercio@0: local height, viewheight = frame:GetHeight(), child:GetHeight() tercio@0: local offset = status.offset or 0 tercio@0: tercio@0: if viewheight < height then tercio@0: self.slider:Hide() tercio@0: child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, offset) tercio@0: self.slider:SetValue(0) tercio@0: else tercio@0: self.slider:Show() tercio@0: local value = (offset / (viewheight - height) * 1000) tercio@0: if value > 1000 then value = 1000 end tercio@0: self.slider:SetValue(value) tercio@0: self:SetScroll(value) tercio@0: if value < 1000 then tercio@0: child:ClearAllPoints() tercio@0: child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset) tercio@0: child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -12, offset) tercio@0: status.offset = offset tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported, AceGUI callback tercio@0: local function OnAcquire(self) tercio@0: self.frame:SetParent(UIParent) tercio@0: --self.itemFrame:SetToplevel(true) tercio@0: end tercio@0: tercio@0: -- exported, AceGUI callback tercio@0: local function OnRelease(self) tercio@0: self:Clear() tercio@0: self.frame:ClearAllPoints() tercio@0: self.frame:Hide() tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function AddItem(self, item) tercio@0: self.items[#self.items + 1] = item tercio@0: tercio@0: local h = #self.items * 16 tercio@0: self.itemFrame:SetHeight(h) tercio@0: self.frame:SetHeight(min(h + 34, self.maxHeight)) -- +34: 20 for scrollFrame placement (10 offset) and +14 for item placement tercio@0: tercio@0: item.frame:SetPoint("LEFT", self.itemFrame, "LEFT") tercio@0: item.frame:SetPoint("RIGHT", self.itemFrame, "RIGHT") tercio@0: tercio@0: item:SetPullout(self) tercio@0: item:SetOnEnter(OnEnter) tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function Open(self, point, relFrame, relPoint, x, y) tercio@0: local items = self.items tercio@0: local frame = self.frame tercio@0: local itemFrame = self.itemFrame tercio@0: tercio@0: frame:SetPoint(point, relFrame, relPoint, x, y) tercio@0: tercio@0: tercio@0: local height = 8 tercio@0: for i, item in pairs(items) do tercio@0: if i == 1 then tercio@0: item:SetPoint("TOP", itemFrame, "TOP", 0, -2) tercio@0: else tercio@0: item:SetPoint("TOP", items[i-1].frame, "BOTTOM", 0, 1) tercio@0: end tercio@0: tercio@0: item:Show() tercio@0: tercio@0: height = height + 16 tercio@0: end tercio@0: itemFrame:SetHeight(height) tercio@0: fixstrata("TOOLTIP", frame, frame:GetChildren()) tercio@0: frame:Show() tercio@0: self:Fire("OnOpen") tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function Close(self) tercio@0: self.frame:Hide() tercio@0: self:Fire("OnClose") tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function Clear(self) tercio@0: local items = self.items tercio@0: for i, item in pairs(items) do tercio@0: AceGUI:Release(item) tercio@0: items[i] = nil tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function IterateItems(self) tercio@0: return ipairs(self.items) tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetHideOnLeave(self, val) tercio@0: self.hideOnLeave = val tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetMaxHeight(self, height) tercio@0: self.maxHeight = height or defaultMaxHeight tercio@0: if self.frame:GetHeight() > height then tercio@0: self.frame:SetHeight(height) tercio@0: elseif (self.itemFrame:GetHeight() + 34) < height then tercio@0: self.frame:SetHeight(self.itemFrame:GetHeight() + 34) -- see :AddItem tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function GetRightBorderWidth(self) tercio@0: return 6 + (self.slider:IsShown() and 12 or 0) tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function GetLeftBorderWidth(self) tercio@0: return 6 tercio@0: end tercio@0: tercio@0: --[[ Constructor ]]-- tercio@0: tercio@0: local function Constructor() tercio@0: local count = AceGUI:GetNextWidgetNum(widgetType) tercio@0: local frame = CreateFrame("Frame", "AceGUI30Pullout"..count, UIParent) tercio@0: local self = {} tercio@0: self.count = count tercio@0: self.type = widgetType tercio@0: self.frame = frame tercio@0: frame.obj = self tercio@0: tercio@0: self.OnAcquire = OnAcquire tercio@0: self.OnRelease = OnRelease tercio@0: tercio@0: self.AddItem = AddItem tercio@0: self.Open = Open tercio@0: self.Close = Close tercio@0: self.Clear = Clear tercio@0: self.IterateItems = IterateItems tercio@0: self.SetHideOnLeave = SetHideOnLeave tercio@0: tercio@0: self.SetScroll = SetScroll tercio@0: self.MoveScroll = MoveScroll tercio@0: self.FixScroll = FixScroll tercio@0: tercio@0: self.SetMaxHeight = SetMaxHeight tercio@0: self.GetRightBorderWidth = GetRightBorderWidth tercio@0: self.GetLeftBorderWidth = GetLeftBorderWidth tercio@0: tercio@0: self.items = {} tercio@0: tercio@0: self.scrollStatus = { tercio@0: scrollvalue = 0, tercio@0: } tercio@0: tercio@0: self.maxHeight = defaultMaxHeight tercio@0: tercio@0: frame:SetBackdrop(backdrop) tercio@0: frame:SetBackdropColor(0, 0, 0) tercio@0: frame:SetFrameStrata("FULLSCREEN_DIALOG") tercio@0: frame:SetClampedToScreen(true) tercio@0: frame:SetWidth(defaultWidth) tercio@0: frame:SetHeight(self.maxHeight) tercio@0: --frame:SetToplevel(true) tercio@0: tercio@0: -- NOTE: The whole scroll frame code is copied from the AceGUI-3.0 widget ScrollFrame tercio@0: local scrollFrame = CreateFrame("ScrollFrame", nil, frame) tercio@0: local itemFrame = CreateFrame("Frame", nil, scrollFrame) tercio@0: tercio@0: self.scrollFrame = scrollFrame tercio@0: self.itemFrame = itemFrame tercio@0: tercio@0: scrollFrame.obj = self tercio@0: itemFrame.obj = self tercio@0: tercio@0: local slider = CreateFrame("Slider", "AceGUI30PulloutScrollbar"..count, scrollFrame) tercio@0: slider:SetOrientation("VERTICAL") tercio@0: slider:SetHitRectInsets(0, 0, -10, 0) tercio@0: slider:SetBackdrop(sliderBackdrop) tercio@0: slider:SetWidth(8) tercio@0: slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Vertical") tercio@0: slider:SetFrameStrata("FULLSCREEN_DIALOG") tercio@0: self.slider = slider tercio@0: slider.obj = self tercio@0: tercio@0: scrollFrame:SetScrollChild(itemFrame) tercio@0: scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -12) tercio@0: scrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -6, 12) tercio@0: scrollFrame:EnableMouseWheel(true) tercio@0: scrollFrame:SetScript("OnMouseWheel", OnMouseWheel) tercio@0: scrollFrame:SetScript("OnSizeChanged", OnSizeChanged) tercio@0: scrollFrame:SetToplevel(true) tercio@0: scrollFrame:SetFrameStrata("FULLSCREEN_DIALOG") tercio@0: tercio@0: itemFrame:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, 0) tercio@0: itemFrame:SetPoint("TOPRIGHT", scrollFrame, "TOPRIGHT", -12, 0) tercio@0: itemFrame:SetHeight(400) tercio@0: itemFrame:SetToplevel(true) tercio@0: itemFrame:SetFrameStrata("FULLSCREEN_DIALOG") tercio@0: tercio@0: slider:SetPoint("TOPLEFT", scrollFrame, "TOPRIGHT", -16, 0) tercio@0: slider:SetPoint("BOTTOMLEFT", scrollFrame, "BOTTOMRIGHT", -16, 0) tercio@0: slider:SetScript("OnValueChanged", OnScrollValueChanged) tercio@0: slider:SetMinMaxValues(0, 1000) tercio@0: slider:SetValueStep(1) tercio@0: slider:SetValue(0) tercio@0: tercio@0: scrollFrame:Show() tercio@0: itemFrame:Show() tercio@0: slider:Hide() tercio@0: tercio@0: self:FixScroll() tercio@0: tercio@0: AceGUI:RegisterAsWidget(self) tercio@0: return self tercio@0: end tercio@0: tercio@0: AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) tercio@0: end tercio@0: tercio@0: do tercio@0: local widgetType = "Dropdown" tercio@5: local widgetVersion = 30 tercio@0: tercio@0: --[[ Static data ]]-- tercio@0: tercio@0: --[[ UI event handler ]]-- tercio@0: tercio@0: local function Control_OnEnter(this) tercio@0: this.obj.button:LockHighlight() tercio@0: this.obj:Fire("OnEnter") tercio@0: end tercio@0: tercio@0: local function Control_OnLeave(this) tercio@0: this.obj.button:UnlockHighlight() tercio@0: this.obj:Fire("OnLeave") tercio@0: end tercio@0: tercio@0: local function Dropdown_OnHide(this) tercio@0: local self = this.obj tercio@0: if self.open then tercio@0: self.pullout:Close() tercio@0: end tercio@0: end tercio@0: tercio@0: local function Dropdown_TogglePullout(this) tercio@0: local self = this.obj tercio@0: PlaySound("igMainMenuOptionCheckBoxOn") -- missleading name, but the Blizzard code uses this sound tercio@0: if self.open then tercio@0: self.open = nil tercio@0: self.pullout:Close() tercio@0: AceGUI:ClearFocus() tercio@0: else tercio@0: self.open = true tercio@0: self.pullout:SetWidth(self.pulloutWidth or self.frame:GetWidth()) tercio@0: self.pullout:Open("TOPLEFT", self.frame, "BOTTOMLEFT", 0, self.label:IsShown() and -2 or 0) tercio@0: AceGUI:SetFocus(self) tercio@0: end tercio@0: end tercio@0: tercio@0: local function OnPulloutOpen(this) tercio@0: local self = this.userdata.obj tercio@0: local value = self.value tercio@0: tercio@0: if not self.multiselect then tercio@0: for i, item in this:IterateItems() do tercio@0: item:SetValue(item.userdata.value == value) tercio@0: end tercio@0: end tercio@0: tercio@0: self.open = true tercio@0: self:Fire("OnOpened") tercio@0: end tercio@0: tercio@0: local function OnPulloutClose(this) tercio@0: local self = this.userdata.obj tercio@0: self.open = nil tercio@0: self:Fire("OnClosed") tercio@0: end tercio@0: tercio@0: local function ShowMultiText(self) tercio@0: local text tercio@0: for i, widget in self.pullout:IterateItems() do tercio@0: if widget.type == "Dropdown-Item-Toggle" then tercio@0: if widget:GetValue() then tercio@0: if text then tercio@0: text = text..", "..widget:GetText() tercio@0: else tercio@0: text = widget:GetText() tercio@0: end tercio@0: end tercio@0: end tercio@0: end tercio@0: self:SetText(text) tercio@0: end tercio@0: tercio@0: local function OnItemValueChanged(this, event, checked) tercio@0: local self = this.userdata.obj tercio@0: tercio@0: if self.multiselect then tercio@0: self:Fire("OnValueChanged", this.userdata.value, checked) tercio@0: ShowMultiText(self) tercio@0: else tercio@0: if checked then tercio@0: self:SetValue(this.userdata.value) tercio@0: self:Fire("OnValueChanged", this.userdata.value) tercio@0: else tercio@0: this:SetValue(true) tercio@0: end tercio@0: if self.open then tercio@0: self.pullout:Close() tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: --[[ Exported methods ]]-- tercio@0: tercio@0: -- exported, AceGUI callback tercio@0: local function OnAcquire(self) tercio@0: local pullout = AceGUI:Create("Dropdown-Pullout") tercio@0: self.pullout = pullout tercio@0: pullout.userdata.obj = self tercio@0: pullout:SetCallback("OnClose", OnPulloutClose) tercio@0: pullout:SetCallback("OnOpen", OnPulloutOpen) tercio@0: self.pullout.frame:SetFrameLevel(self.frame:GetFrameLevel() + 1) tercio@0: fixlevels(self.pullout.frame, self.pullout.frame:GetChildren()) tercio@0: tercio@0: self:SetHeight(44) tercio@0: self:SetWidth(200) tercio@0: self:SetLabel() tercio@0: self:SetPulloutWidth(nil) tercio@0: end tercio@0: tercio@0: -- exported, AceGUI callback tercio@0: local function OnRelease(self) tercio@0: if self.open then tercio@0: self.pullout:Close() tercio@0: end tercio@0: AceGUI:Release(self.pullout) tercio@0: self.pullout = nil tercio@0: tercio@0: self:SetText("") tercio@0: self:SetDisabled(false) tercio@0: self:SetMultiselect(false) tercio@0: tercio@0: self.value = nil tercio@0: self.list = nil tercio@0: self.open = nil tercio@0: self.hasClose = nil tercio@0: tercio@0: self.frame:ClearAllPoints() tercio@0: self.frame:Hide() tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetDisabled(self, disabled) tercio@0: self.disabled = disabled tercio@0: if disabled then tercio@0: self.text:SetTextColor(0.5,0.5,0.5) tercio@0: self.button:Disable() tercio@5: self.button_cover:Disable() tercio@0: self.label:SetTextColor(0.5,0.5,0.5) tercio@0: else tercio@0: self.button:Enable() tercio@5: self.button_cover:Enable() tercio@0: self.label:SetTextColor(1,.82,0) tercio@0: self.text:SetTextColor(1,1,1) tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function ClearFocus(self) tercio@0: if self.open then tercio@0: self.pullout:Close() tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetText(self, text) tercio@0: self.text:SetText(text or "") tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetLabel(self, text) tercio@0: if text and text ~= "" then tercio@0: self.label:SetText(text) tercio@0: self.label:Show() tercio@0: self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,-14) tercio@0: self:SetHeight(40) tercio@0: self.alignoffset = 26 tercio@0: else tercio@0: self.label:SetText("") tercio@0: self.label:Hide() tercio@0: self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,0) tercio@0: self:SetHeight(26) tercio@0: self.alignoffset = 12 tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetValue(self, value) tercio@0: if self.list then tercio@0: self:SetText(self.list[value] or "") tercio@0: end tercio@0: self.value = value tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function GetValue(self) tercio@0: return self.value tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetItemValue(self, item, value) tercio@0: if not self.multiselect then return end tercio@0: for i, widget in self.pullout:IterateItems() do tercio@0: if widget.userdata.value == item then tercio@0: if widget.SetValue then tercio@0: widget:SetValue(value) tercio@0: end tercio@0: end tercio@0: end tercio@0: ShowMultiText(self) tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetItemDisabled(self, item, disabled) tercio@0: for i, widget in self.pullout:IterateItems() do tercio@0: if widget.userdata.value == item then tercio@0: widget:SetDisabled(disabled) tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: local function AddListItem(self, value, text, itemType) tercio@0: if not itemType then itemType = "Dropdown-Item-Toggle" end tercio@0: local exists = AceGUI:GetWidgetVersion(itemType) tercio@0: if not exists then error(("The given item type, %q, does not exist within AceGUI-3.0"):format(tostring(itemType)), 2) end tercio@0: tercio@0: local item = AceGUI:Create(itemType) tercio@0: item:SetText(text) tercio@0: item.userdata.obj = self tercio@0: item.userdata.value = value tercio@0: item:SetCallback("OnValueChanged", OnItemValueChanged) tercio@0: self.pullout:AddItem(item) tercio@0: end tercio@0: tercio@0: local function AddCloseButton(self) tercio@0: if not self.hasClose then tercio@0: local close = AceGUI:Create("Dropdown-Item-Execute") tercio@0: close:SetText(CLOSE) tercio@0: self.pullout:AddItem(close) tercio@0: self.hasClose = true tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local sortlist = {} tercio@0: local function SetList(self, list, order, itemType) tercio@0: self.list = list tercio@0: self.pullout:Clear() tercio@0: self.hasClose = nil tercio@0: if not list then return end tercio@0: tercio@0: if type(order) ~= "table" then tercio@0: for v in pairs(list) do tercio@0: sortlist[#sortlist + 1] = v tercio@0: end tercio@0: tsort(sortlist) tercio@0: tercio@0: for i, key in ipairs(sortlist) do tercio@0: AddListItem(self, key, list[key], itemType) tercio@0: sortlist[i] = nil tercio@0: end tercio@0: else tercio@0: for i, key in ipairs(order) do tercio@0: AddListItem(self, key, list[key], itemType) tercio@0: end tercio@0: end tercio@0: if self.multiselect then tercio@0: ShowMultiText(self) tercio@0: AddCloseButton(self) tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function AddItem(self, value, text, itemType) tercio@0: if self.list then tercio@0: self.list[value] = text tercio@0: AddListItem(self, value, text, itemType) tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function SetMultiselect(self, multi) tercio@0: self.multiselect = multi tercio@0: if multi then tercio@0: ShowMultiText(self) tercio@0: AddCloseButton(self) tercio@0: end tercio@0: end tercio@0: tercio@0: -- exported tercio@0: local function GetMultiselect(self) tercio@0: return self.multiselect tercio@0: end tercio@0: tercio@0: local function SetPulloutWidth(self, width) tercio@0: self.pulloutWidth = width tercio@0: end tercio@0: tercio@0: --[[ Constructor ]]-- tercio@0: tercio@0: local function Constructor() tercio@0: local count = AceGUI:GetNextWidgetNum(widgetType) tercio@0: local frame = CreateFrame("Frame", nil, UIParent) tercio@0: local dropdown = CreateFrame("Frame", "AceGUI30DropDown"..count, frame, "UIDropDownMenuTemplate") tercio@0: tercio@0: local self = {} tercio@0: self.type = widgetType tercio@0: self.frame = frame tercio@0: self.dropdown = dropdown tercio@0: self.count = count tercio@0: frame.obj = self tercio@0: dropdown.obj = self tercio@0: tercio@0: self.OnRelease = OnRelease tercio@0: self.OnAcquire = OnAcquire tercio@0: tercio@0: self.ClearFocus = ClearFocus tercio@0: tercio@0: self.SetText = SetText tercio@0: self.SetValue = SetValue tercio@0: self.GetValue = GetValue tercio@0: self.SetList = SetList tercio@0: self.SetLabel = SetLabel tercio@0: self.SetDisabled = SetDisabled tercio@0: self.AddItem = AddItem tercio@0: self.SetMultiselect = SetMultiselect tercio@0: self.GetMultiselect = GetMultiselect tercio@0: self.SetItemValue = SetItemValue tercio@0: self.SetItemDisabled = SetItemDisabled tercio@0: self.SetPulloutWidth = SetPulloutWidth tercio@0: tercio@0: self.alignoffset = 26 tercio@0: tercio@0: frame:SetScript("OnHide",Dropdown_OnHide) tercio@0: tercio@0: dropdown:ClearAllPoints() tercio@0: dropdown:SetPoint("TOPLEFT",frame,"TOPLEFT",-15,0) tercio@0: dropdown:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",17,0) tercio@0: dropdown:SetScript("OnHide", nil) tercio@0: tercio@0: local left = _G[dropdown:GetName() .. "Left"] tercio@0: local middle = _G[dropdown:GetName() .. "Middle"] tercio@0: local right = _G[dropdown:GetName() .. "Right"] tercio@0: tercio@0: middle:ClearAllPoints() tercio@0: right:ClearAllPoints() tercio@0: tercio@0: middle:SetPoint("LEFT", left, "RIGHT", 0, 0) tercio@0: middle:SetPoint("RIGHT", right, "LEFT", 0, 0) tercio@0: right:SetPoint("TOPRIGHT", dropdown, "TOPRIGHT", 0, 17) tercio@0: tercio@0: local button = _G[dropdown:GetName() .. "Button"] tercio@0: self.button = button tercio@0: button.obj = self tercio@0: button:SetScript("OnEnter",Control_OnEnter) tercio@0: button:SetScript("OnLeave",Control_OnLeave) tercio@0: button:SetScript("OnClick",Dropdown_TogglePullout) tercio@0: tercio@0: local button_cover = CreateFrame("BUTTON",nil,self.frame) tercio@5: self.button_cover = button_cover tercio@0: button_cover.obj = self tercio@0: button_cover:SetPoint("TOPLEFT",self.frame,"BOTTOMLEFT",0,25) tercio@0: button_cover:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT") tercio@0: button_cover:SetScript("OnEnter",Control_OnEnter) tercio@0: button_cover:SetScript("OnLeave",Control_OnLeave) tercio@0: button_cover:SetScript("OnClick",Dropdown_TogglePullout) tercio@0: tercio@0: local text = _G[dropdown:GetName() .. "Text"] tercio@0: self.text = text tercio@0: text.obj = self tercio@0: text:ClearAllPoints() tercio@0: text:SetPoint("RIGHT", right, "RIGHT" ,-43, 2) tercio@0: text:SetPoint("LEFT", left, "LEFT", 25, 2) tercio@0: tercio@0: local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall") tercio@0: label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) tercio@0: label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0) tercio@0: label:SetJustifyH("LEFT") tercio@0: label:SetHeight(18) tercio@0: label:Hide() tercio@0: self.label = label tercio@0: tercio@0: AceGUI:RegisterAsWidget(self) tercio@0: return self tercio@0: end tercio@0: tercio@0: AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion) tercio@0: end