2012-05-18 23:10:57 +00:00
|
|
|
require "ui/ui"
|
|
|
|
require "ui/reader/readerview"
|
|
|
|
require "ui/reader/readerzooming"
|
|
|
|
require "ui/reader/readerpanning"
|
|
|
|
require "ui/reader/readerrotation"
|
|
|
|
require "ui/reader/readerpaging"
|
2012-06-05 07:23:36 +00:00
|
|
|
require "ui/reader/readerrolling"
|
2012-05-27 11:47:22 +00:00
|
|
|
require "ui/reader/readertoc"
|
2012-06-12 09:42:02 +00:00
|
|
|
require "ui/reader/readerfont"
|
2012-06-10 18:14:29 +00:00
|
|
|
require "ui/reader/readermenu"
|
2012-05-18 22:50:26 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
This is an abstraction for a reader interface
|
|
|
|
|
|
|
|
it works using data gathered from a document interface
|
|
|
|
]]--
|
|
|
|
|
|
|
|
ReaderUI = InputContainer:new{
|
|
|
|
key_events = {
|
|
|
|
Close = { {"Home"}, doc = "close document", event = "Close" },
|
|
|
|
Back = { {"Back"}, doc = "close document", event = "Close" },
|
|
|
|
},
|
|
|
|
|
|
|
|
-- our own size
|
|
|
|
dimen = Geom:new{ w = 400, h = 600 },
|
|
|
|
-- if we have a parent container, it must be referenced for now
|
|
|
|
dialog = nil,
|
|
|
|
|
|
|
|
-- the document interface
|
|
|
|
document = nil,
|
2012-06-11 16:35:13 +00:00
|
|
|
|
|
|
|
-- initial page or percent inside document on opening
|
|
|
|
start_pos = nil,
|
|
|
|
-- password for document unlock
|
|
|
|
password = nil,
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderUI:init()
|
|
|
|
-- if we are not the top level dialog ourselves, it must be given in the table
|
|
|
|
if not self.dialog then
|
|
|
|
self.dialog = self
|
|
|
|
end
|
|
|
|
-- a view container (so it must be child #1!)
|
|
|
|
self[1] = ReaderView:new{
|
|
|
|
dialog = self.dialog,
|
2012-06-12 16:14:23 +00:00
|
|
|
dimen = self.dimen,
|
2012-05-18 22:50:26 +00:00
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
-- rotation controller
|
2012-06-05 07:23:36 +00:00
|
|
|
self[2] = ReaderRotation:new{
|
2012-05-18 22:50:26 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2012-05-27 11:47:22 +00:00
|
|
|
-- Toc menu controller
|
2012-06-05 07:23:36 +00:00
|
|
|
self[3] = ReaderToc:new{
|
2012-05-27 11:47:22 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2012-06-10 18:14:29 +00:00
|
|
|
-- reader menu controller
|
|
|
|
self[4] = ReaderMenu:new{
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2012-05-18 22:50:26 +00:00
|
|
|
if self.document.info.has_pages then
|
2012-06-05 07:23:36 +00:00
|
|
|
-- for page specific controller
|
|
|
|
|
|
|
|
-- zooming controller
|
|
|
|
local zoomer = ReaderZooming:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, zoomer)
|
|
|
|
-- panning controller
|
|
|
|
local panner = ReaderPanning:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, panner)
|
|
|
|
-- if needed, insert a paging container
|
2012-05-18 22:50:26 +00:00
|
|
|
local pager = ReaderPaging:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, pager)
|
2012-06-11 16:35:13 +00:00
|
|
|
if not self.start_pos then
|
|
|
|
self.start_pos = 1
|
|
|
|
end
|
|
|
|
pager:gotoPage(self.start_pos)
|
2012-06-05 07:23:36 +00:00
|
|
|
else
|
2012-06-12 09:42:02 +00:00
|
|
|
-- rolling controller
|
2012-06-05 07:23:36 +00:00
|
|
|
local roller = ReaderRolling:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, roller)
|
2012-06-11 16:35:13 +00:00
|
|
|
if not self.start_pos then
|
|
|
|
self.start_pos = 0
|
|
|
|
end
|
|
|
|
roller:gotoPercent(self.start_pos)
|
2012-06-12 09:42:02 +00:00
|
|
|
-- font menu
|
|
|
|
local font_menu = ReaderFont:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, font_menu)
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
-- notify childs of dimensions
|
|
|
|
self:handleEvent(Event:new("SetDimensions", self.dimen))
|
|
|
|
end
|
|
|
|
|
2012-06-12 16:14:23 +00:00
|
|
|
function ReaderUI:onSetDimensions(dimen)
|
|
|
|
self.dimen = dimen
|
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderUI:onClose()
|
2012-05-28 16:59:16 +00:00
|
|
|
DEBUG("closing reader")
|
2012-05-18 22:50:26 +00:00
|
|
|
if self.document then
|
|
|
|
self.document:close()
|
|
|
|
self.document = false
|
|
|
|
end
|
|
|
|
UIManager:close(self.dialog)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|