Just for fun.

--
--  Shared Lists factory
--


local iup = require("iuplua")

local SHList = {}

function SHList:new(list)
    o = {}
    setmetatable(o, self)
    self.__index = self
    o.lists = {} -- holder for clones
    o.list = list -- source model
    return o
end

local function set_action_wrapper(obj, list)
    list._action = list.action
    list.action = function (this, text, item, state, ext)
        if ext then
            this.VALUE = item
        else
            for k,v in pairs(obj.lists) do
                if v ~= this then
                    --iup.CopyClassAttributes(this, v)
                    v:action(text, item, state, true)
                end
            end
        end
        this:_action(text, item, state)
    end
end

function SHList:clone()
    local list = iup.list{}
    iup.CopyClassAttributes(self.list, list)
    list.action = self.list.action
    set_action_wrapper(self, list)
    table.insert(self.lists, list)
    return list
end

function SHList:set_active(state)
    for k,v in pairs(self.lists) do
        v.ACTIVE = state and "YES" or "NO"
    end
end

return SHList
local iup = require("iuplua")
local SHList = require("SHList")

local shl = SHList:new(iup.list{
    "AAA", "BBB", "CCC",
    MINSIZE = "100x",
    DROPDOWN = "YES",
    action = function (this, text, item, state)
        print(this, text, item, state)
    end,
})

local dlg = iup.dialog {
    iup.frame{
        iup.vbox{
            NGAP = 8,
            NMARGIN = "8x8",
            NORMALIZESIZE = "HORIZONTAL",
            shl:clone(),
            shl:clone(),
            shl:clone(),
            iup.button{TITLE="Enable",  action=function(this) 
shl:set_active(true) end,},
            iup.button{TITLE="Disable", action=function(this) 
shl:set_active(false) end,},
        },
    },
}

dlg:showxy(iup.CENTER, iup.CENTER)

iup.MainLoop()
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to