Quantcast WoWInterface: SVN - HealMeNow - Blame - Rev 3 - /trunk/Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua

WoWInterface SVN HealMeNow

[/] [trunk/] [Libs/] [AceGUI-3.0/] [widgets/] [AceGUIWidget-DropDown.lua] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 SeiferTim-84726
--[[ $Id: AceGUIWidget-DropDown.lua 76326 2008-06-09 09:29:17Z nevcairiel $ ]]--
2 SeiferTim-84726
local min, max, floor = math.min, math.max, math.floor
3 SeiferTim-84726
 
4 SeiferTim-84726
local AceGUI = LibStub("AceGUI-3.0")
5 SeiferTim-84726
 
6 SeiferTim-84726
local function fixlevels(parent,...)
7 SeiferTim-84726
        local i = 1
8 SeiferTim-84726
        local child = select(i, ...)
9 SeiferTim-84726
        while child do
10 SeiferTim-84726
                child:SetFrameLevel(parent:GetFrameLevel()+1)
11 SeiferTim-84726
                fixlevels(child, child:GetChildren())
12 SeiferTim-84726
                i = i + 1
13 SeiferTim-84726
                child = select(i, ...)
14 SeiferTim-84726
        end
15 SeiferTim-84726
end
16 SeiferTim-84726
 
17 SeiferTim-84726
local function fixstrata(strata, parent, ...)
18 SeiferTim-84726
        local i = 1
19 SeiferTim-84726
        local child = select(i, ...)
20 SeiferTim-84726
        parent:SetFrameStrata(strata)
21 SeiferTim-84726
        while child do
22 SeiferTim-84726
                fixstrata(strata, child, child:GetChildren())
23 SeiferTim-84726
                i = i + 1
24 SeiferTim-84726
                child = select(i, ...)
25 SeiferTim-84726
        end
26 SeiferTim-84726
end
27 SeiferTim-84726
 
28 SeiferTim-84726
do
29 SeiferTim-84726
        local widgetType = "Dropdown-Pullout"
30 SeiferTim-84726
        local widgetVersion = 2
31 SeiferTim-84726
 
32 SeiferTim-84726
        --[[ Static data ]]--
33 SeiferTim-84726
 
34 SeiferTim-84726
        local backdrop = {
35 SeiferTim-84726
                bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
36 SeiferTim-84726
                edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
37 SeiferTim-84726
                edgeSize = 32,
38 SeiferTim-84726
                tileSize = 32,
39 SeiferTim-84726
                tile = true,
40 SeiferTim-84726
                insets = { left = 11, right = 12, top = 12, bottom = 11 },
41 SeiferTim-84726
        }
42 SeiferTim-84726
        local sliderBackdrop  = {
43 SeiferTim-84726
                bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
44 SeiferTim-84726
                edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
45 SeiferTim-84726
                tile = true, tileSize = 8, edgeSize = 8,
46 SeiferTim-84726
                insets = { left = 3, right = 3, top = 3, bottom = 3 }
47 SeiferTim-84726
        }
48 SeiferTim-84726
 
49 SeiferTim-84726
        local defaultWidth = 200
50 SeiferTim-84726
        local defaultMaxHeight = 600
51 SeiferTim-84726
 
52 SeiferTim-84726
        --[[ UI Event Handlers ]]--
53 SeiferTim-84726
 
54 SeiferTim-84726
        -- HACK: This should be no part of the pullout, but there
55 SeiferTim-84726
        --       is no other 'clean' way to response to any item-OnEnter
56 SeiferTim-84726
        --       Used to close Submenus when an other item is entered
57 SeiferTim-84726
        local function OnEnter(item)
58 SeiferTim-84726
                local self = item.pullout
59 SeiferTim-84726
                for k, v in ipairs(self.items) do
60 SeiferTim-84726
                        if v.CloseMenu and v ~= item then
61 SeiferTim-84726
                                v:CloseMenu()
62 SeiferTim-84726
                        end
63 SeiferTim-84726
                end
64 SeiferTim-84726
        end
65 SeiferTim-84726
 
66 SeiferTim-84726
        -- See the note in Constructor() for each scroll related function
67 SeiferTim-84726
        local function OnMouseWheel(this, value)
68 SeiferTim-84726
                this.obj:MoveScroll(value)
69 SeiferTim-84726
        end
70 SeiferTim-84726
 
71 SeiferTim-84726
        local function OnScrollValueChanged(this, value)
72 SeiferTim-84726
                this.obj:SetScroll(value)
73 SeiferTim-84726
        end
74 SeiferTim-84726
 
75 SeiferTim-84726
        local function OnSizeChanged(this)
76 SeiferTim-84726
                this.obj:FixScroll()
77 SeiferTim-84726
        end
78 SeiferTim-84726
 
79 SeiferTim-84726
        --[[ Exported methods ]]--
80 SeiferTim-84726
 
81 SeiferTim-84726
        -- exported
82 SeiferTim-84726
        local function SetScroll(self, value)
83 SeiferTim-84726
                local status = self.scrollStatus
84 SeiferTim-84726
                local frame, child = self.scrollFrame, self.itemFrame
85 SeiferTim-84726
                local height, viewheight = frame:GetHeight(), child:GetHeight()
86 SeiferTim-84726
 
87 SeiferTim-84726
                local offset
88 SeiferTim-84726
                if height > viewheight then
89 SeiferTim-84726
                        offset = 0
90 SeiferTim-84726
                else
91 SeiferTim-84726
                        offset = floor((viewheight - height) / 1000 * value)
92 SeiferTim-84726
                end
93 SeiferTim-84726
                child:ClearAllPoints()
94 SeiferTim-84726
                child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset)
95 SeiferTim-84726
                child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", self.slider:IsShown() and -12 or 0, offset)
96 SeiferTim-84726
                status.offset = offset
97 SeiferTim-84726
                status.scrollvalue = value
98 SeiferTim-84726
        end
99 SeiferTim-84726
 
100 SeiferTim-84726
        -- exported
101 SeiferTim-84726
        local function MoveScroll(self, value)
102 SeiferTim-84726
                local status = self.scrollStatus
103 SeiferTim-84726
                local frame, child = self.scrollFrame, self.itemFrame
104 SeiferTim-84726
                local height, viewheight = frame:GetHeight(), child:GetHeight()
105 SeiferTim-84726
 
106 SeiferTim-84726
                if height > viewheight then
107 SeiferTim-84726
                        self.slider:Hide()
108 SeiferTim-84726
                else
109 SeiferTim-84726
                        self.slider:Show()
110 SeiferTim-84726
                        local diff = height - viewheight
111 SeiferTim-84726
                        local delta = 1
112 SeiferTim-84726
                        if value < 0 then
113 SeiferTim-84726
                                delta = -1
114 SeiferTim-84726
                        end
115 SeiferTim-84726
                        self.slider:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000))
116 SeiferTim-84726
                end
117 SeiferTim-84726
        end
118 SeiferTim-84726
 
119 SeiferTim-84726
        -- exported
120 SeiferTim-84726
        local function FixScroll(self)
121 SeiferTim-84726
                local status = self.scrollStatus
122 SeiferTim-84726
                local frame, child = self.scrollFrame, self.itemFrame
123 SeiferTim-84726
                local height, viewheight = frame:GetHeight(), child:GetHeight()
124 SeiferTim-84726
                local offset = status.offset or 0
125 SeiferTim-84726
 
126 SeiferTim-84726
                if viewheight < height then
127 SeiferTim-84726
                        self.slider:Hide()
128 SeiferTim-84726
                        child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, offset)
129 SeiferTim-84726
                        self.slider:SetValue(0)
130 SeiferTim-84726
                else
131 SeiferTim-84726
                        self.slider:Show()
132 SeiferTim-84726
                        local value = (offset / (viewheight - height) * 1000)
133 SeiferTim-84726
                        if value > 1000 then value = 1000 end
134 SeiferTim-84726
                        self.slider:SetValue(value)
135 SeiferTim-84726
                        self:SetScroll(value)
136 SeiferTim-84726
                        if value < 1000 then
137 SeiferTim-84726
                                child:ClearAllPoints()
138 SeiferTim-84726
                                child:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, offset)
139 SeiferTim-84726
                                child:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -12, offset)
140 SeiferTim-84726
                                status.offset = offset
141 SeiferTim-84726
                        end
142 SeiferTim-84726
                end
143 SeiferTim-84726
        end
144 SeiferTim-84726
 
145 SeiferTim-84726
        -- exported, AceGUI callback
146 SeiferTim-84726
        local function OnAcquire(self)
147 SeiferTim-84726
                self.frame:SetParent(UIParent)
148 SeiferTim-84726
                --self.itemFrame:SetToplevel(true)
149 SeiferTim-84726
        end
150 SeiferTim-84726
 
151 SeiferTim-84726
        -- exported, AceGUI callback
152 SeiferTim-84726
        local function OnRelease(self)
153 SeiferTim-84726
                self:Clear()
154 SeiferTim-84726
                self.frame:ClearAllPoints()
155 SeiferTim-84726
                self.frame:Hide()
156 SeiferTim-84726
        end
157 SeiferTim-84726
 
158 SeiferTim-84726
        -- exported
159 SeiferTim-84726
        local function AddItem(self, item)
160 SeiferTim-84726
                self.items[#self.items + 1] = item
161 SeiferTim-84726
 
162 SeiferTim-84726
                local h = #self.items * 16
163 SeiferTim-84726
                self.itemFrame:SetHeight(h)
164 SeiferTim-84726
                self.frame:SetHeight(min(h + 34, self.maxHeight)) -- +34: 20 for scrollFrame placement (10 offset) and +14 for item placement
165 SeiferTim-84726
 
166 SeiferTim-84726
                item.frame:SetPoint("LEFT", self.itemFrame, "LEFT")
167 SeiferTim-84726
                item.frame:SetPoint("RIGHT", self.itemFrame, "RIGHT")
168 SeiferTim-84726
 
169 SeiferTim-84726
                item:SetPullout(self)
170 SeiferTim-84726
                item:SetOnEnter(OnEnter)
171 SeiferTim-84726
        end
172 SeiferTim-84726
 
173 SeiferTim-84726
        -- exported
174 SeiferTim-84726
        local function Open(self, point, relFrame, relPoint, x, y)
175 SeiferTim-84726
                local items = self.items
176 SeiferTim-84726
                local frame = self.frame
177 SeiferTim-84726
                local itemFrame = self.itemFrame
178 SeiferTim-84726
 
179 SeiferTim-84726
                frame:SetPoint(point, relFrame, relPoint, x, y)
180 SeiferTim-84726
 
181 SeiferTim-84726
 
182 SeiferTim-84726
                local height = 8
183 SeiferTim-84726
                for i, item in pairs(items) do
184 SeiferTim-84726
                        if i == 1 then
185 SeiferTim-84726
                                item:SetPoint("TOP", itemFrame, "TOP", 0, -2)
186 SeiferTim-84726
                        else
187 SeiferTim-84726
                                item:SetPoint("TOP", items[i-1].frame, "BOTTOM", 0, 1)
188 SeiferTim-84726
                        end
189 SeiferTim-84726
 
190 SeiferTim-84726
                        item:Show()
191 SeiferTim-84726
 
192 SeiferTim-84726
                        height = height + 16
193 SeiferTim-84726
                end
194 SeiferTim-84726
                itemFrame:SetHeight(height)
195 SeiferTim-84726
                fixstrata("TOOLTIP", frame, frame:GetChildren())
196 SeiferTim-84726
                frame:Show()
197 SeiferTim-84726
                self:Fire("OnOpen")
198 SeiferTim-84726
        end
199 SeiferTim-84726
 
200 SeiferTim-84726
        -- exported
201 SeiferTim-84726
        local function Close(self)
202 SeiferTim-84726
                self.frame:Hide()
203 SeiferTim-84726
                self:Fire("OnClose")
204 SeiferTim-84726
        end
205 SeiferTim-84726
 
206 SeiferTim-84726
        -- exported
207 SeiferTim-84726
        local function Clear(self)
208 SeiferTim-84726
                local items = self.items
209 SeiferTim-84726
                for i, item in pairs(items) do
210 SeiferTim-84726
                        AceGUI:Release(item)
211 SeiferTim-84726
                        items[i] = nil
212 SeiferTim-84726
                end
213 SeiferTim-84726
        end
214 SeiferTim-84726
 
215 SeiferTim-84726
        -- exported
216 SeiferTim-84726
        local function IterateItems(self)
217 SeiferTim-84726
                return ipairs(self.items)
218 SeiferTim-84726
        end
219 SeiferTim-84726
 
220 SeiferTim-84726
        -- exported
221 SeiferTim-84726
        local function SetHideOnLeave(self, val)
222 SeiferTim-84726
                self.hideOnLeave = val
223 SeiferTim-84726
        end
224 SeiferTim-84726
 
225 SeiferTim-84726
        -- exported
226 SeiferTim-84726
        local function SetMaxHeight(self, height)
227 SeiferTim-84726
                self.maxHeight = height or defaultMaxHeight
228 SeiferTim-84726
                if self.frame:GetHeight() > height then
229 SeiferTim-84726
                        self.frame:SetHeight(height)
230 SeiferTim-84726
                elseif (self.itemFrame:GetHeight() + 34) < height then
231 SeiferTim-84726
                        self.frame:SetHeight(self.itemFrame:GetHeight() + 34) -- see :AddItem
232 SeiferTim-84726
                end
233 SeiferTim-84726
        end
234 SeiferTim-84726
 
235 SeiferTim-84726
        -- exported
236 SeiferTim-84726
        local function GetRightBorderWidth(self)
237 SeiferTim-84726
                return 6 + (self.slider:IsShown() and 12 or 0)
238 SeiferTim-84726
        end
239 SeiferTim-84726
 
240 SeiferTim-84726
        -- exported
241 SeiferTim-84726
        local function GetLeftBorderWidth(self)
242 SeiferTim-84726
                return 6
243 SeiferTim-84726
        end
244 SeiferTim-84726
 
245 SeiferTim-84726
        --[[ Constructor ]]--
246 SeiferTim-84726
 
247 SeiferTim-84726
        local function Constructor()
248 SeiferTim-84726
                local count = AceGUI:GetNextWidgetNum(widgetType)
249 SeiferTim-84726
                local frame = CreateFrame("Frame", "AceGUI30Pullout"..count, UIParent)
250 SeiferTim-84726
                local self = {}
251 SeiferTim-84726
                self.count = count
252 SeiferTim-84726
                self.type = widgetType
253 SeiferTim-84726
                self.frame = frame
254 SeiferTim-84726
                frame.obj = self
255 SeiferTim-84726
 
256 SeiferTim-84726
                self.OnAcquire = OnAcquire
257 SeiferTim-84726
                self.OnRelease = OnRelease
258 SeiferTim-84726
 
259 SeiferTim-84726
                self.AddItem = AddItem
260 SeiferTim-84726
                self.Open    = Open
261 SeiferTim-84726
                self.Close   = Close
262 SeiferTim-84726
                self.Clear   = Clear
263 SeiferTim-84726
                self.IterateItems = IterateItems
264 SeiferTim-84726
                self.SetHideOnLeave = SetHideOnLeave
265 SeiferTim-84726
 
266 SeiferTim-84726
                self.SetScroll  = SetScroll
267 SeiferTim-84726
                self.MoveScroll = MoveScroll
268 SeiferTim-84726
                self.FixScroll  = FixScroll
269 SeiferTim-84726
 
270 SeiferTim-84726
                self.SetMaxHeight = SetMaxHeight
271 SeiferTim-84726
                self.GetRightBorderWidth = GetRightBorderWidth
272 SeiferTim-84726
                self.GetLeftBorderWidth = GetLeftBorderWidth
273 SeiferTim-84726
 
274 SeiferTim-84726
                self.items = {}
275 SeiferTim-84726
 
276 SeiferTim-84726
                self.scrollStatus = {
277 SeiferTim-84726
                        scrollvalue = 0,
278 SeiferTim-84726
                }
279 SeiferTim-84726
 
280 SeiferTim-84726
                self.maxHeight = defaultMaxHeight
281 SeiferTim-84726
 
282 SeiferTim-84726
                frame:SetBackdrop(backdrop)
283 SeiferTim-84726
                frame:SetBackdropColor(0, 0, 0)
284 SeiferTim-84726
                frame:SetFrameStrata("FULLSCREEN_DIALOG")
285 SeiferTim-84726
                frame:SetClampedToScreen(true)
286 SeiferTim-84726
                frame:SetWidth(defaultWidth)
287 SeiferTim-84726
                frame:SetHeight(self.maxHeight)
288 SeiferTim-84726
                --frame:SetToplevel(true)
289 SeiferTim-84726
 
290 SeiferTim-84726
                -- NOTE: The whole scroll frame code is copied from the AceGUI-3.0 widget ScrollFrame
291 SeiferTim-84726
                local scrollFrame = CreateFrame("ScrollFrame", nil, frame)
292 SeiferTim-84726
                local itemFrame = CreateFrame("Frame", nil, scrollFrame)
293 SeiferTim-84726
 
294 SeiferTim-84726
                self.scrollFrame = scrollFrame
295 SeiferTim-84726
                self.itemFrame = itemFrame
296 SeiferTim-84726
 
297 SeiferTim-84726
                scrollFrame.obj = self
298 SeiferTim-84726
                itemFrame.obj = self
299 SeiferTim-84726
 
300 SeiferTim-84726
                local slider = CreateFrame("Slider", "AceGUI30PulloutScrollbar"..count, scrollFrame)
301 SeiferTim-84726
                slider:SetOrientation("VERTICAL")
302 SeiferTim-84726
                slider:SetHitRectInsets(0, 0, -10, 0)
303 SeiferTim-84726
                slider:SetBackdrop(sliderBackdrop)
304 SeiferTim-84726
                slider:SetWidth(8)
305 SeiferTim-84726
                slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Vertical")
306 SeiferTim-84726
                slider:SetFrameStrata("FULLSCREEN_DIALOG")
307 SeiferTim-84726
                self.slider = slider
308 SeiferTim-84726
                slider.obj = self
309 SeiferTim-84726
 
310 SeiferTim-84726
                scrollFrame:SetScrollChild(itemFrame)
311 SeiferTim-84726
                scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -12)
312 SeiferTim-84726
                scrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -6, 12)
313 SeiferTim-84726
                scrollFrame:EnableMouseWheel(true)
314 SeiferTim-84726
                scrollFrame:SetScript("OnMouseWheel", OnMouseWheel)
315 SeiferTim-84726
                scrollFrame:SetScript("OnSizeChanged", OnSizeChanged)
316 SeiferTim-84726
                scrollFrame:SetToplevel(true)
317 SeiferTim-84726
                scrollFrame:SetFrameStrata("FULLSCREEN_DIALOG")
318 SeiferTim-84726
 
319 SeiferTim-84726
                itemFrame:SetPoint("TOPLEFT", scrollFrame, "TOPLEFT", 0, 0)
320 SeiferTim-84726
                itemFrame:SetPoint("TOPRIGHT", scrollFrame, "TOPRIGHT", -12, 0)
321 SeiferTim-84726
                itemFrame:SetHeight(400)
322 SeiferTim-84726
                itemFrame:SetToplevel(true)
323 SeiferTim-84726
                itemFrame:SetFrameStrata("FULLSCREEN_DIALOG")
324 SeiferTim-84726
 
325 SeiferTim-84726
                slider:SetPoint("TOPLEFT", scrollFrame, "TOPRIGHT", -16, 0)
326 SeiferTim-84726
                slider:SetPoint("BOTTOMLEFT", scrollFrame, "BOTTOMRIGHT", -16, 0)
327 SeiferTim-84726
                slider:SetScript("OnValueChanged", OnScrollValueChanged)
328 SeiferTim-84726
                slider:SetMinMaxValues(0, 1000)
329 SeiferTim-84726
                slider:SetValueStep(1)
330 SeiferTim-84726
                slider:SetValue(0)
331 SeiferTim-84726
 
332 SeiferTim-84726
                scrollFrame:Show()
333 SeiferTim-84726
                itemFrame:Show()
334 SeiferTim-84726
                slider:Hide()
335 SeiferTim-84726
 
336 SeiferTim-84726
                self:FixScroll()
337 SeiferTim-84726
 
338 SeiferTim-84726
                AceGUI:RegisterAsWidget(self)
339 SeiferTim-84726
                return self
340 SeiferTim-84726
        end
341 SeiferTim-84726
 
342 SeiferTim-84726
        AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
343 SeiferTim-84726
end
344 SeiferTim-84726
 
345 SeiferTim-84726
do
346 SeiferTim-84726
        local widgetType = "Dropdown"
347 SeiferTim-84726
        local widgetVersion = 17
348 SeiferTim-84726
 
349 SeiferTim-84726
        --[[ Static data ]]--
350 SeiferTim-84726
 
351 SeiferTim-84726
        --[[ UI event handler ]]--
352 SeiferTim-84726
 
353 SeiferTim-84726
        local function Control_OnEnter(this)
354 SeiferTim-84726
                this.obj:Fire("OnEnter")
355 SeiferTim-84726
        end
356 SeiferTim-84726
 
357 SeiferTim-84726
        local function Control_OnLeave(this)
358 SeiferTim-84726
                this.obj:Fire("OnLeave")
359 SeiferTim-84726
        end
360 SeiferTim-84726
 
361 SeiferTim-84726
        local function Dropdown_OnHide(this)
362 SeiferTim-84726
                this.obj.pullout:Close()
363 SeiferTim-84726
        end
364 SeiferTim-84726
 
365 SeiferTim-84726
        local function Dropdown_TogglePullout(this)
366 SeiferTim-84726
                local self = this.obj
367 SeiferTim-84726
                if self.open then
368 SeiferTim-84726
                        self.open = nil
369 SeiferTim-84726
                        self.pullout:Close()
370 SeiferTim-84726
                        AceGUI:ClearFocus()
371 SeiferTim-84726
                else
372 SeiferTim-84726
                        self.open = true
373 SeiferTim-84726
                        self.pullout:SetWidth(self.frame:GetWidth())
374 SeiferTim-84726
                        self.pullout:Open("TOPLEFT", self.frame, "BOTTOMLEFT", 0, self.label:IsShown() and -2 or 0)
375 SeiferTim-84726
                        AceGUI:SetFocus(self)
376 SeiferTim-84726
                end
377 SeiferTim-84726
        end
378 SeiferTim-84726
 
379 SeiferTim-84726
        local function OnPulloutOpen(this)
380 SeiferTim-84726
                local self = this.userdata.obj
381 SeiferTim-84726
                local value = self.value
382 SeiferTim-84726
 
383 SeiferTim-84726
                if not self.multiselect then
384 SeiferTim-84726
                        for i, item in this:IterateItems() do
385 SeiferTim-84726
                                item:SetValue(item.userdata.value == value)
386 SeiferTim-84726
                        end
387 SeiferTim-84726
                end
388 SeiferTim-84726
 
389 SeiferTim-84726
                self.open = true
390 SeiferTim-84726
        end
391 SeiferTim-84726
 
392 SeiferTim-84726
        local function OnPulloutClose(this)
393 SeiferTim-84726
                local self = this.userdata.obj
394 SeiferTim-84726
                self.open = nil
395 SeiferTim-84726
                self:Fire("OnClosed")
396 SeiferTim-84726
        end
397 SeiferTim-84726
 
398 SeiferTim-84726
        local function ShowMultiText(self)
399 SeiferTim-84726
                local text
400 SeiferTim-84726
                for i, widget in self.pullout:IterateItems() do
401 SeiferTim-84726
                        if widget.type == "Dropdown-Item-Toggle" then
402 SeiferTim-84726
                                if widget:GetValue() then
403 SeiferTim-84726
                                        if text then
404 SeiferTim-84726
                                                text = text..", "..widget:GetText()
405 SeiferTim-84726
                                        else
406 SeiferTim-84726
                                                text = widget:GetText()
407 SeiferTim-84726
                                        end
408 SeiferTim-84726
                                end
409 SeiferTim-84726
                        end
410 SeiferTim-84726
                end
411 SeiferTim-84726
                self:SetText(text)
412 SeiferTim-84726
        end
413 SeiferTim-84726
 
414 SeiferTim-84726
        local function OnItemValueChanged(this, event, checked)
415 SeiferTim-84726
                local self = this.userdata.obj
416 SeiferTim-84726
 
417 SeiferTim-84726
                if self.multiselect then
418 SeiferTim-84726
                        self:Fire("OnValueChanged", this.userdata.value, checked)
419 SeiferTim-84726
                        ShowMultiText(self)
420 SeiferTim-84726
                else
421 SeiferTim-84726
                        if checked then
422 SeiferTim-84726
                                self:SetValue(this.userdata.value)
423 SeiferTim-84726
                                self:Fire("OnValueChanged", this.userdata.value)
424 SeiferTim-84726
                        else
425 SeiferTim-84726
                                this:SetValue(true)
426 SeiferTim-84726
                        end
427 SeiferTim-84726
                        self.pullout:Close()
428 SeiferTim-84726
                end
429 SeiferTim-84726
        end
430 SeiferTim-84726
 
431 SeiferTim-84726
        --[[ Exported methods ]]--
432 SeiferTim-84726
 
433 SeiferTim-84726
        -- exported, AceGUI callback
434 SeiferTim-84726
        local function OnAcquire(self)
435 SeiferTim-84726
                local pullout = AceGUI:Create("Dropdown-Pullout")
436 SeiferTim-84726
                self.pullout = pullout
437 SeiferTim-84726
                pullout.userdata.obj = self
438 SeiferTim-84726
                pullout:SetCallback("OnClose", OnPulloutClose)
439 SeiferTim-84726
                pullout:SetCallback("OnOpen", OnPulloutOpen)
440 SeiferTim-84726
                self.pullout.frame:SetFrameLevel(self.frame:GetFrameLevel() + 1)
441 SeiferTim-84726
                fixlevels(self.pullout.frame, self.pullout.frame:GetChildren())
442 SeiferTim-84726
        end
443 SeiferTim-84726
 
444 SeiferTim-84726
        -- exported, AceGUI callback
445 SeiferTim-84726
        local function OnRelease(self)
446 SeiferTim-84726
                self.pullout:Close()
447 SeiferTim-84726
                AceGUI:Release(self.pullout)
448 SeiferTim-84726
 
449 SeiferTim-84726
                self:SetText("")
450 SeiferTim-84726
                self:SetLabel("")
451 SeiferTim-84726
                self:SetDisabled(false)
452 SeiferTim-84726
                self:SetMultiselect(false)
453 SeiferTim-84726
 
454 SeiferTim-84726
                self.value = nil
455 SeiferTim-84726
                self.list = nil
456 SeiferTim-84726
                self.open = nil
457 SeiferTim-84726
                self.hasClose = nil
458 SeiferTim-84726
 
459 SeiferTim-84726
                self.frame:ClearAllPoints()
460 SeiferTim-84726
                self.frame:Hide()
461 SeiferTim-84726
        end
462 SeiferTim-84726
 
463 SeiferTim-84726
        -- exported
464 SeiferTim-84726
        local function SetDisabled(self, disabled)
465 SeiferTim-84726
                self.disabled = disabled
466 SeiferTim-84726
                if disabled then
467 SeiferTim-84726
                        self.text:SetTextColor(0.5,0.5,0.5)
468 SeiferTim-84726
                        self.button:Disable()
469 SeiferTim-84726
                        self.label:SetTextColor(0.5,0.5,0.5)
470 SeiferTim-84726
                else
471 SeiferTim-84726
                        self.button:Enable()
472 SeiferTim-84726
                        self.label:SetTextColor(1,.82,0)
473 SeiferTim-84726
                        self.text:SetTextColor(1,1,1)
474 SeiferTim-84726
                end
475 SeiferTim-84726
        end
476 SeiferTim-84726
 
477 SeiferTim-84726
        -- exported
478 SeiferTim-84726
        local function ClearFocus(self)
479 SeiferTim-84726
                self.pullout:Close()
480 SeiferTim-84726
        end
481 SeiferTim-84726
 
482 SeiferTim-84726
        -- exported
483 SeiferTim-84726
        local function SetText(self, text)
484 SeiferTim-84726
                self.text:SetText(text or "")
485 SeiferTim-84726
        end
486 SeiferTim-84726
 
487 SeiferTim-84726
        -- exported
488 SeiferTim-84726
        local function SetLabel(self, text)
489 SeiferTim-84726
                if text and text ~= "" then
490 SeiferTim-84726
                        self.label:SetText(text)
491 SeiferTim-84726
                        self.label:Show()
492 SeiferTim-84726
                        self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,-18)
493 SeiferTim-84726
                        self.frame:SetHeight(44)
494 SeiferTim-84726
                else
495 SeiferTim-84726
                        self.label:SetText("")
496 SeiferTim-84726
                        self.label:Hide()
497 SeiferTim-84726
                        self.dropdown:SetPoint("TOPLEFT",self.frame,"TOPLEFT",-15,0)
498 SeiferTim-84726
                        self.frame:SetHeight(26)
499 SeiferTim-84726
                end
500 SeiferTim-84726
        end
501 SeiferTim-84726
 
502 SeiferTim-84726
        -- exported
503 SeiferTim-84726
        local function SetValue(self, value)
504 SeiferTim-84726
                if self.list then
505 SeiferTim-84726
                        self:SetText(self.list[value] or "")
506 SeiferTim-84726
                end
507 SeiferTim-84726
                self.value = value
508 SeiferTim-84726
        end
509 SeiferTim-84726
 
510 SeiferTim-84726
        -- exported
511 SeiferTim-84726
        local function SetItemValue(self, item, value)
512 SeiferTim-84726
                if not self.multiselect then return end
513 SeiferTim-84726
                for i, widget in self.pullout:IterateItems() do
514 SeiferTim-84726
                        if widget.userdata.value == item then
515 SeiferTim-84726
                                if widget.SetValue then
516 SeiferTim-84726
                                        widget:SetValue(value)
517 SeiferTim-84726
                                end
518 SeiferTim-84726
                        end
519 SeiferTim-84726
                end
520 SeiferTim-84726
                ShowMultiText(self)
521 SeiferTim-84726
        end
522 SeiferTim-84726
 
523 SeiferTim-84726
        -- exported
524 SeiferTim-84726
        local function SetItemDisabled(self, item, disabled)
525 SeiferTim-84726
                for i, widget in self.pullout:IterateItems() do
526 SeiferTim-84726
                        if widget.userdata.value == item then
527 SeiferTim-84726
                                widget:SetDisabled(disabled)
528 SeiferTim-84726
                        end
529 SeiferTim-84726
                end
530 SeiferTim-84726
        end
531 SeiferTim-84726
 
532 SeiferTim-84726
        local function AddListItem(self, value, text)
533 SeiferTim-84726
                local item = AceGUI:Create("Dropdown-Item-Toggle")
534 SeiferTim-84726
                item:SetText(text)
535 SeiferTim-84726
                item.userdata.obj = self
536 SeiferTim-84726
                item.userdata.value = value
537 SeiferTim-84726
                item:SetCallback("OnValueChanged", OnItemValueChanged)
538 SeiferTim-84726
                self.pullout:AddItem(item)
539 SeiferTim-84726
        end
540 SeiferTim-84726
 
541 SeiferTim-84726
        local function AddCloseButton(self)
542 SeiferTim-84726
                if not self.hasClose then
543 SeiferTim-84726
                        local close = AceGUI:Create("Dropdown-Item-Execute")
544 SeiferTim-84726
                        close:SetText(CLOSE)
545 SeiferTim-84726
                        self.pullout:AddItem(close)
546 SeiferTim-84726
                        self.hasClose = true
547 SeiferTim-84726
                end
548 SeiferTim-84726
        end
549 SeiferTim-84726
 
550 SeiferTim-84726
        -- exported
551 SeiferTim-84726
        local sortlist = {}
552 SeiferTim-84726
        local function SetList(self, list)
553 SeiferTim-84726
                self.list = list
554 SeiferTim-84726
                self.pullout:Clear()
555 SeiferTim-84726
                self.hasClose = nil
556 SeiferTim-84726
 
557 SeiferTim-84726
                for v in pairs(list) do
558 SeiferTim-84726
                        sortlist[#sortlist + 1] = v
559 SeiferTim-84726
                end
560 SeiferTim-84726
                table.sort(sortlist)
561 SeiferTim-84726
 
562 SeiferTim-84726
                for i, value in pairs(sortlist) do
563 SeiferTim-84726
                        AddListItem(self, value, list[value])
564 SeiferTim-84726
                        sortlist[i] = nil
565 SeiferTim-84726
                end
566 SeiferTim-84726
                if self.multiselect then
567 SeiferTim-84726
                        ShowMultiText(self)
568 SeiferTim-84726
                        AddCloseButton(self)
569 SeiferTim-84726
                end
570 SeiferTim-84726
        end
571 SeiferTim-84726
 
572 SeiferTim-84726
        -- exported
573 SeiferTim-84726
        local function AddItem(self, value, text)
574 SeiferTim-84726
                if self.list then
575 SeiferTim-84726
                        self.list[value] = text
576 SeiferTim-84726
                        AddListItem(self, value, text)
577 SeiferTim-84726
                end
578 SeiferTim-84726
        end
579 SeiferTim-84726
 
580 SeiferTim-84726
        -- exported
581 SeiferTim-84726
        local function SetMultiselect(self, multi)
582 SeiferTim-84726
                self.multiselect = multi
583 SeiferTim-84726
                if multi then
584 SeiferTim-84726
                        ShowMultiText(self)
585 SeiferTim-84726
                        AddCloseButton(self)
586 SeiferTim-84726
                end
587 SeiferTim-84726
        end
588 SeiferTim-84726
 
589 SeiferTim-84726
        -- exported
590 SeiferTim-84726
        local function GetMultiselect(self)
591 SeiferTim-84726
                return self.multiselect
592 SeiferTim-84726
        end
593 SeiferTim-84726
 
594 SeiferTim-84726
        --[[ Constructor ]]--
595 SeiferTim-84726
 
596 SeiferTim-84726
        local function Constructor()
597 SeiferTim-84726
                local count = AceGUI:GetNextWidgetNum(widgetType)
598 SeiferTim-84726
                local frame = CreateFrame("Frame", nil, UIParent)
599 SeiferTim-84726
                local dropdown = CreateFrame("Frame", "AceGUI30DropDown"..count, frame, "UIDropDownMenuTemplate")
600 SeiferTim-84726
 
601 SeiferTim-84726
                local self = {}
602 SeiferTim-84726
                self.type = widgetType
603 SeiferTim-84726
                self.frame = frame
604 SeiferTim-84726
                self.dropdown = dropdown
605 SeiferTim-84726
                self.count = count
606 SeiferTim-84726
                frame.obj = self
607 SeiferTim-84726
                dropdown.obj = self
608 SeiferTim-84726
 
609 SeiferTim-84726
                self.OnRelease   = OnRelease
610 SeiferTim-84726
                self.OnAcquire   = OnAcquire
611 SeiferTim-84726
 
612 SeiferTim-84726
                self.ClearFocus  = ClearFocus
613 SeiferTim-84726
 
614 SeiferTim-84726
                self.SetText     = SetText
615 SeiferTim-84726
                self.SetValue    = SetValue
616 SeiferTim-84726
                self.SetList     = SetList
617 SeiferTim-84726
                self.SetLabel    = SetLabel
618 SeiferTim-84726
                self.SetDisabled = SetDisabled
619 SeiferTim-84726
                self.AddItem     = AddItem
620 SeiferTim-84726
                self.SetMultiselect = SetMultiselect
621 SeiferTim-84726
                self.GetMultiselect = GetMultiselect
622 SeiferTim-84726
                self.SetItemValue = SetItemValue
623 SeiferTim-84726
                self.SetItemDisabled = SetItemDisabled
624 SeiferTim-84726
 
625 SeiferTim-84726
                self.alignoffset = 31
626 SeiferTim-84726
 
627 SeiferTim-84726
                frame:SetHeight(44)
628 SeiferTim-84726
                frame:SetWidth(200)
629 SeiferTim-84726
                frame:SetScript("OnHide",Dropdown_OnHide)
630 SeiferTim-84726
 
631 SeiferTim-84726
                dropdown:ClearAllPoints()
632 SeiferTim-84726
                dropdown:SetPoint("TOPLEFT",frame,"TOPLEFT",-15,0)
633 SeiferTim-84726
                dropdown:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",17,0)
634 SeiferTim-84726
                dropdown:SetScript("OnHide", nil)
635 SeiferTim-84726
 
636 SeiferTim-84726
                local left = _G[dropdown:GetName() .. "Left"]
637 SeiferTim-84726
                local middle = _G[dropdown:GetName() .. "Middle"]
638 SeiferTim-84726
                local right = _G[dropdown:GetName() .. "Right"]
639 SeiferTim-84726
 
640 SeiferTim-84726
                middle:ClearAllPoints()
641 SeiferTim-84726
                right:ClearAllPoints()
642 SeiferTim-84726
 
643 SeiferTim-84726
                middle:SetPoint("LEFT", left, "RIGHT", 0, 0)
644 SeiferTim-84726
                middle:SetPoint("RIGHT", right, "LEFT", 0, 0)
645 SeiferTim-84726
                right:SetPoint("TOPRIGHT", dropdown, "TOPRIGHT", 0, 17)
646 SeiferTim-84726
 
647 SeiferTim-84726
                local button = _G[dropdown:GetName() .. "Button"]
648 SeiferTim-84726
                self.button = button
649 SeiferTim-84726
                button.obj = self
650 SeiferTim-84726
                button:SetScript("OnEnter",Control_OnEnter)
651 SeiferTim-84726
                button:SetScript("OnLeave",Control_OnLeave)
652 SeiferTim-84726
                button:SetScript("OnClick",Dropdown_TogglePullout)
653 SeiferTim-84726
 
654 SeiferTim-84726
                local text = _G[dropdown:GetName() .. "Text"]
655 SeiferTim-84726
                self.text = text
656 SeiferTim-84726
                text.obj = self
657 SeiferTim-84726
                text:ClearAllPoints()
658 SeiferTim-84726
                text:SetPoint("RIGHT", right, "RIGHT" ,-43, 2)
659 SeiferTim-84726
                text:SetPoint("LEFT", left, "LEFT", 25, 2)
660 SeiferTim-84726
 
661 SeiferTim-84726
                local label = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
662 SeiferTim-84726
                label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0)
663 SeiferTim-84726
                label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0)
664 SeiferTim-84726
                label:SetJustifyH("LEFT")
665 SeiferTim-84726
                label:SetHeight(18)
666 SeiferTim-84726
                label:Hide()
667 SeiferTim-84726
                self.label = label
668 SeiferTim-84726
 
669 SeiferTim-84726
                AceGUI:RegisterAsWidget(self)
670 SeiferTim-84726
                return self
671 SeiferTim-84726
        end
672 SeiferTim-84726
 
673 SeiferTim-84726
        AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion)
674 SeiferTim-84726
end