2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
2014-02-05 05:29:38 +01:00
|
|
|
local print,ipairs = print,ipairs
|
2013-07-08 00:18:55 +02:00
|
|
|
local scroll = require( "radical.widgets.scroll" )
|
|
|
|
local filter = require( "radical.widgets.filter" )
|
|
|
|
local wibox = require( "wibox" )
|
2014-02-06 04:48:26 +01:00
|
|
|
local cairo = require( "lgi" ).cairo
|
|
|
|
local base = nil
|
2014-02-23 05:59:03 +01:00
|
|
|
local horizontal_item_layout= require( "radical.item.layout.horizontal" )
|
2013-05-11 21:02:42 +02:00
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
local function left(data)
|
|
|
|
if data._current_item._tmp_menu then
|
|
|
|
data = data._current_item._tmp_menu
|
2014-03-22 22:35:43 +01:00
|
|
|
data.items[1].selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
return true,data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function right(data)
|
2013-07-18 06:03:19 +02:00
|
|
|
if data.parent_geometry and data.parent_geometry.is_menu then
|
2013-05-11 21:02:42 +02:00
|
|
|
for k,v in ipairs(data.items) do
|
2014-03-22 22:35:43 +01:00
|
|
|
if v._tmp_menu == data or v.sub_menu_m == data then
|
|
|
|
v.selected = true
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
data.visible = false
|
|
|
|
data = data.parent_geometry
|
|
|
|
return true,data
|
2014-03-23 05:14:25 +01:00
|
|
|
else
|
|
|
|
return false
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function up(data)
|
|
|
|
data.previous_item.selected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function down(data)
|
|
|
|
data.next_item.selected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function module:setup_key_hooks(data)
|
|
|
|
data:add_key_hook({}, "Up" , "press", up )
|
2014-01-05 23:35:23 +01:00
|
|
|
data:add_key_hook({}, "&" , "press", up ) -- Xephyr bug
|
2013-05-11 21:02:42 +02:00
|
|
|
data:add_key_hook({}, "Down" , "press", down )
|
2014-01-05 23:35:23 +01:00
|
|
|
data:add_key_hook({}, "KP_Enter", "press", down ) -- Xephyr bug
|
2014-03-23 05:14:25 +01:00
|
|
|
data:add_key_hook({}, "Left" , "press", right )
|
|
|
|
data:add_key_hook({}, "\"" , "press", right ) -- Xephyr bug
|
|
|
|
data:add_key_hook({}, "Right" , "press", left )
|
|
|
|
data:add_key_hook({}, "#" , "press", left ) -- Xephyr bug
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--Get preferred item geometry
|
2016-01-09 10:25:46 +01:00
|
|
|
local function item_fit(data,item,self,context, width,height)
|
2014-07-28 01:20:04 +02:00
|
|
|
local w, h = 0,0--item._internal.cache_w or 1,item._internal.cache_h or 1
|
2014-02-05 05:29:38 +01:00
|
|
|
if data.visible then
|
2016-01-09 10:25:46 +01:00
|
|
|
w, h = item._private_data._fit({},self,context,width,height)
|
2013-07-04 19:19:01 +02:00
|
|
|
item._internal.pix_cache = {} --Clear the pimap cache
|
2013-07-04 07:51:01 +02:00
|
|
|
end
|
2014-07-28 01:20:04 +02:00
|
|
|
|
|
|
|
return w, item.height or h
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
2014-02-05 05:29:38 +01:00
|
|
|
function module:setup_text(item,data,text_w)
|
|
|
|
local text_w = item._internal.text_w
|
2014-01-05 07:04:40 +01:00
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
text_w.draw = function(self,context, cr, width, height)
|
2014-01-05 07:04:40 +01:00
|
|
|
if item.underlay then
|
2014-02-05 05:29:38 +01:00
|
|
|
horizontal_item_layout.paint_underlay(data,item,cr,width,height)
|
2014-01-05 07:04:40 +01:00
|
|
|
end
|
2015-12-29 11:19:23 +01:00
|
|
|
wibox.widget.textbox.draw(self, context, cr, width, height)
|
2014-01-05 07:04:40 +01:00
|
|
|
end
|
2015-12-29 11:19:23 +01:00
|
|
|
text_w.fit = function(self,context,width,height) return width,height end
|
2014-01-05 07:04:40 +01:00
|
|
|
|
2014-03-05 06:12:48 +01:00
|
|
|
item.set_text = function (_,value)
|
2014-01-05 07:04:40 +01:00
|
|
|
if data.disable_markup then
|
|
|
|
text_w:set_text(value)
|
|
|
|
else
|
|
|
|
text_w:set_markup(value)
|
|
|
|
end
|
2014-02-09 09:04:02 +01:00
|
|
|
item._private_data.text = value
|
2014-01-05 07:04:40 +01:00
|
|
|
end
|
2014-03-05 06:12:48 +01:00
|
|
|
item:set_text(item._private_data.text)
|
2014-01-05 07:04:40 +01:00
|
|
|
return text_w
|
|
|
|
end
|
2013-07-04 19:19:01 +02:00
|
|
|
|
2013-05-27 02:49:51 +02:00
|
|
|
function module:setup_item(data,item,args)
|
2014-02-12 03:38:05 +01:00
|
|
|
if not base then
|
|
|
|
base = require( "radical.base" )
|
|
|
|
end
|
2013-07-04 19:19:01 +02:00
|
|
|
--Create the background
|
2014-04-09 05:38:31 +02:00
|
|
|
local item_layout = item.layout or data.item_layout or horizontal_item_layout
|
2016-01-09 10:25:46 +01:00
|
|
|
item.widget = item_layout(item,data,args)
|
2014-01-04 06:49:20 +01:00
|
|
|
|
2013-05-27 02:49:51 +02:00
|
|
|
--Event handling
|
2014-02-06 04:48:26 +01:00
|
|
|
if data.select_on == base.event.HOVER then
|
2014-03-22 05:11:03 +01:00
|
|
|
item.widget:connect_signal("mouse::enter", function(_,geo)
|
|
|
|
item.y = geo.y
|
|
|
|
item.selected = true
|
|
|
|
end)
|
|
|
|
item.widget:connect_signal("mouse::leave", function()
|
|
|
|
item.selected = false
|
|
|
|
end)
|
2014-02-09 06:54:59 +01:00
|
|
|
else
|
2014-03-22 05:11:03 +01:00
|
|
|
item.widget:connect_signal("mouse::enter", function(_,geo)
|
|
|
|
item.y = geo.y
|
|
|
|
item.hover = true
|
|
|
|
end)
|
|
|
|
item.widget:connect_signal("mouse::leave", function()
|
|
|
|
item.hover = false
|
|
|
|
end)
|
2014-02-06 04:48:26 +01:00
|
|
|
end
|
2013-05-27 02:49:51 +02:00
|
|
|
data._internal.layout:add(item)
|
|
|
|
|
|
|
|
--Be sure to always hide sub menus, even when data.visible is set manually
|
|
|
|
data:connect_signal("visible::changed",function(_,vis)
|
|
|
|
if data._tmp_menu and data.visible == false then
|
|
|
|
data._tmp_menu.visible = false
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
data:connect_signal("parent_geometry::changed",function(_,vis)
|
|
|
|
local fit_w,fit_h = data._internal.layout:fit()
|
|
|
|
data.height = fit_h
|
|
|
|
data.style(data)
|
|
|
|
end)
|
|
|
|
|
|
|
|
item._private_data._fit = wibox.widget.background.fit
|
2014-03-26 21:18:59 +01:00
|
|
|
if item._internal.margin_w then
|
|
|
|
item._internal.margin_w.fit = function(...)
|
|
|
|
if (item.visible == false or item._filter_out == true or item._hidden == true) then
|
|
|
|
return 0,0
|
|
|
|
end
|
|
|
|
return data._internal.layout.item_fit(data,item,...)
|
2013-07-04 07:51:01 +02:00
|
|
|
end
|
2013-05-27 02:49:51 +02:00
|
|
|
end
|
|
|
|
|
2014-02-05 05:29:38 +01:00
|
|
|
-- Text need to take as much space as possible, override default
|
|
|
|
module:setup_text(item,data)
|
2014-01-05 07:04:40 +01:00
|
|
|
|
2014-02-06 03:43:06 +01:00
|
|
|
-- Necessary for :set_position()
|
|
|
|
local fit_w,fit_h = data._internal.layout:fit()
|
2014-03-26 21:18:59 +01:00
|
|
|
|
2014-02-06 03:43:06 +01:00
|
|
|
data.width = fit_w
|
|
|
|
data.height = fit_h
|
2014-01-04 22:51:50 +01:00
|
|
|
|
2014-01-05 07:04:40 +01:00
|
|
|
-- Enable scrollbar if necessary
|
2013-08-09 08:34:49 +02:00
|
|
|
if data._internal.scroll_w and data.rowcount > data.max_items then
|
|
|
|
data._internal.scroll_w.visible = true
|
|
|
|
data._internal.scroll_w["up"]:emit_signal("widget::updated")
|
|
|
|
data._internal.scroll_w["down"]:emit_signal("widget::updated")
|
|
|
|
end
|
2014-01-04 22:51:50 +01:00
|
|
|
|
|
|
|
-- Setup tooltip
|
|
|
|
item.widget:set_tooltip(item.tooltip)
|
2014-02-03 05:01:31 +01:00
|
|
|
|
|
|
|
-- Apply item style
|
|
|
|
local item_style = item.item_style or data.item_style
|
2014-03-02 22:28:30 +01:00
|
|
|
item_style(item,{})
|
2014-02-05 05:29:38 +01:00
|
|
|
|
2014-03-24 05:00:01 +01:00
|
|
|
-- Compute the minimum width
|
2014-03-26 21:18:59 +01:00
|
|
|
if data.auto_resize and item._internal.margin_w then
|
2015-12-29 11:19:23 +01:00
|
|
|
local fit_w = wibox.layout.margin.fit(item._internal.margin_w,{},9999,9999)
|
2014-03-24 05:00:01 +01:00
|
|
|
local is_largest = item == data._internal.largest_item_w
|
|
|
|
if fit_w < 1000 and (not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w) then
|
|
|
|
data._internal.largest_item_w = item
|
|
|
|
data._internal.largest_item_w_v = fit_w
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-05 05:29:38 +01:00
|
|
|
item.widget:emit_signal("widget::updated")
|
2013-05-27 02:49:51 +02:00
|
|
|
end
|
|
|
|
|
2014-10-06 00:01:54 +02:00
|
|
|
local function compute_geo(data,width,height,force_values)
|
2013-07-04 07:20:46 +02:00
|
|
|
local w = data.default_width
|
|
|
|
if data.auto_resize and data._internal.largest_item_w then
|
2014-03-24 05:00:01 +01:00
|
|
|
w = data._internal.largest_item_w_v > data.default_width and data._internal.largest_item_w_v or data.default_width
|
2013-07-04 07:20:46 +02:00
|
|
|
end
|
2015-12-29 12:21:13 +01:00
|
|
|
|
2014-10-06 00:01:54 +02:00
|
|
|
local visblerow = data.visible_row_count
|
2015-12-29 12:21:13 +01:00
|
|
|
|
|
|
|
local sw,sh = data._internal.suf_l:get_preferred_size()
|
|
|
|
local pw,ph = data._internal.pref_l:get_preferred_size()
|
2013-07-04 07:20:46 +02:00
|
|
|
if not data._internal.has_widget then
|
2014-03-12 01:49:49 +01:00
|
|
|
return w,(total and total > 0 and total or visblerow*data.item_height) + ph + sh
|
2013-07-04 07:20:46 +02:00
|
|
|
else
|
2014-10-06 00:01:54 +02:00
|
|
|
local sumh = data.widget_fit_height_sum
|
|
|
|
local h = (visblerow-#data._internal.widgets)*data.item_height + sumh
|
2013-07-04 07:20:46 +02:00
|
|
|
return w,h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-11 21:02:42 +02:00
|
|
|
local function new(data)
|
2016-02-11 08:51:14 +01:00
|
|
|
base = base or require( "radical.base" )
|
|
|
|
|
|
|
|
local function real_fit(self,context,o_w,o_h,force_values)
|
|
|
|
if not data.visible then return 1,1 end
|
|
|
|
local w,h = compute_geo(data,o_w,o_h,force_values)
|
|
|
|
data:emit_signal("layout_size",w,h)
|
|
|
|
return w,h
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
2016-02-11 08:51:14 +01:00
|
|
|
|
|
|
|
local function real_add(self, item)
|
|
|
|
return wibox.layout.fixed.add(data._internal.content_layout, item.widget)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create the scroll widgets
|
2013-07-07 06:39:17 +02:00
|
|
|
if data.max_items then
|
2016-02-11 08:51:14 +01:00
|
|
|
data._internal.scroll_w = scroll(data)
|
2013-07-07 06:39:17 +02:00
|
|
|
end
|
2016-02-11 08:51:14 +01:00
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
-- Define the item layout
|
|
|
|
local real_l = wibox.widget.base.make_widget_declarative {
|
2016-02-11 08:51:14 +01:00
|
|
|
-- Widgets
|
|
|
|
{
|
|
|
|
-- The prefix section, used for the scroll widgets and custom prefixes
|
|
|
|
|
|
|
|
-- Widgets
|
|
|
|
data._internal.scroll_w and data._internal.scroll_w["up"] or nil,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "prefix_layout",
|
|
|
|
layout = wibox.layout.fixed.vertical
|
|
|
|
},
|
|
|
|
{
|
|
|
|
-- The main layout (where items are added)
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "content_layout",
|
|
|
|
spacing = data.spacing and data.spacing or 0,
|
|
|
|
layout = wibox.layout.fixed.vertical ,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
-- The suffix section, used for the scroll widgets and custom suffixes
|
|
|
|
|
|
|
|
-- Widgets
|
|
|
|
data._internal.scroll_w and data._internal.scroll_w["down"] or nil,
|
|
|
|
data.show_filter and {
|
|
|
|
id = "filter_widget",
|
|
|
|
widget = filter(data) --FIXME for some reason it doesn't show up
|
|
|
|
} or nil,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
id = "suffix_layout" ,
|
|
|
|
layout = wibox.layout.fixed.vertical,
|
|
|
|
},
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
layout = wibox.layout.fixed.vertical,
|
|
|
|
|
|
|
|
-- Methods
|
|
|
|
item_fit = item_fit ,
|
|
|
|
setup_key_hooks = module.setup_key_hooks,
|
|
|
|
setup_item = module.setup_item ,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Set the important widgets
|
|
|
|
data._internal.content_layout = real_l:get_children_by_id( "content_layout" )[1]
|
|
|
|
data._internal.suf_l = real_l:get_children_by_id( "suffix_layout" )[1]
|
|
|
|
data._internal.pref_l = real_l:get_children_by_id( "prefix_layout" )[1]
|
|
|
|
data._internal.filter_tb = real_l:get_children_by_id( "filter_widget" )[1]
|
|
|
|
|
|
|
|
-- Set the overloaded methods
|
2016-02-11 10:21:10 +01:00
|
|
|
real_l.fit = real_fit
|
|
|
|
real_l.add = real_add
|
2016-02-11 08:51:14 +01:00
|
|
|
|
|
|
|
local l = data._internal.content_layout
|
|
|
|
|
|
|
|
--SWAP / MOVE / REMOVE
|
|
|
|
data:connect_signal("item::swapped",function(_,item1,item2,index1,index2)
|
|
|
|
l:swap(index1, index2)
|
|
|
|
end)
|
|
|
|
|
|
|
|
data:connect_signal("item::moved",function(_,item,new_idx,old_idx)
|
|
|
|
local w = l:get_children()[old_idx]
|
|
|
|
l:remove(old_idx)
|
|
|
|
l:insert(new_idx, w)
|
|
|
|
end)
|
|
|
|
|
|
|
|
data:connect_signal("item::removed",function(_,item,old_idx)
|
|
|
|
l:remove(old_idx)
|
|
|
|
end)
|
|
|
|
|
|
|
|
data:connect_signal("item::appended",function(_,item)
|
|
|
|
l:add(item.widget)
|
|
|
|
end)
|
|
|
|
|
|
|
|
data:connect_signal("widget::added",function(_,item,widget)
|
|
|
|
wibox.layout.fixed.add(l,item.widget)
|
|
|
|
l:emit_signal("widget::updated")
|
|
|
|
end)
|
|
|
|
|
|
|
|
data:connect_signal("prefix_widget::added",function(_,widget,args)
|
|
|
|
data._internal.pref_l:insert(1,widget)
|
|
|
|
end)
|
|
|
|
|
|
|
|
data:connect_signal("suffix_widget::added",function(_,widget,args)
|
|
|
|
data._internal.suf_l:add(widget)
|
|
|
|
end)
|
|
|
|
|
|
|
|
data._internal.text_fit = function(self, context, width, height)
|
|
|
|
return width,height
|
|
|
|
end
|
|
|
|
|
2016-02-11 10:21:10 +01:00
|
|
|
return real_l
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
2016-02-11 08:51:14 +01:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|