2012-05-18 23:10:57 +00:00
|
|
|
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"
|
2013-01-01 02:22:45 +00:00
|
|
|
require "ui/reader/readerbookmark"
|
2012-06-12 09:42:02 +00:00
|
|
|
require "ui/reader/readerfont"
|
2013-01-17 22:12:50 +00:00
|
|
|
require "ui/reader/readertypeset"
|
2012-06-10 18:14:29 +00:00
|
|
|
require "ui/reader/readermenu"
|
2012-12-14 10:20:04 +00:00
|
|
|
require "ui/reader/readerconfig"
|
2013-02-02 20:42:59 +00:00
|
|
|
require "ui/reader/readercropping"
|
2013-02-19 11:16:42 +00:00
|
|
|
require "ui/reader/readerkopt"
|
2013-03-04 15:23:37 +00:00
|
|
|
require "ui/reader/readercopt"
|
2013-03-06 14:36:51 +00:00
|
|
|
require "ui/reader/readerscreenshot"
|
2013-03-12 12:28:01 +00:00
|
|
|
require "ui/reader/readerhinting"
|
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" },
|
|
|
|
},
|
2013-03-07 10:06:18 +00:00
|
|
|
active_widgets = {},
|
2012-05-18 22:50:26 +00:00
|
|
|
|
|
|
|
-- 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,
|
2013-01-13 02:22:33 +00:00
|
|
|
|
2013-01-13 03:24:42 +00:00
|
|
|
postInitCallback = nil,
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderUI:init()
|
2013-01-13 03:24:42 +00:00
|
|
|
self.postInitCallback = {}
|
2012-05-18 22:50:26 +00:00
|
|
|
-- 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
|
2012-06-26 09:05:09 +00:00
|
|
|
|
2013-01-01 02:22:45 +00:00
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events.Back = {
|
|
|
|
{ "Back" }, doc = "close document",
|
|
|
|
event = "Close" }
|
|
|
|
end
|
|
|
|
|
2012-06-26 09:05:09 +00:00
|
|
|
self.doc_settings = DocSettings:open(self.document.file)
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
-- 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-12-13 04:41:48 +00:00
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
-- 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-12-31 00:13:46 +00:00
|
|
|
-- reader menu controller
|
|
|
|
self[3] = ReaderMenu:new{
|
2012-05-27 11:47:22 +00:00
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2012-12-31 00:13:46 +00:00
|
|
|
self.menu = self[3] -- hold reference to menu widget
|
2013-01-01 19:38:29 +00:00
|
|
|
-- Table of content controller
|
2012-12-31 00:13:46 +00:00
|
|
|
self[4] = ReaderToc:new{
|
|
|
|
dialog = self.dialog,
|
2012-06-10 18:14:29 +00:00
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2013-01-01 19:38:29 +00:00
|
|
|
self.toc = self[4] -- hold reference to bm widget
|
|
|
|
-- bookmark controller
|
2013-01-01 02:22:45 +00:00
|
|
|
local reader_bm = ReaderBookmark:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, reader_bm)
|
2013-03-06 14:36:51 +00:00
|
|
|
-- screenshot controller
|
|
|
|
local reader_ss = ReaderScreenshot:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2013-03-07 10:06:18 +00:00
|
|
|
table.insert(self.active_widgets, reader_ss)
|
2012-12-15 01:30:48 +00:00
|
|
|
|
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
|
|
|
|
|
2012-12-04 07:19:50 +00:00
|
|
|
-- if needed, insert a paging container
|
|
|
|
local pager = ReaderPaging:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, pager)
|
2012-06-05 07:23:36 +00:00
|
|
|
-- 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)
|
2013-02-02 20:42:59 +00:00
|
|
|
-- cropping controller
|
|
|
|
local cropper = ReaderCropping:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
}
|
|
|
|
table.insert(self, cropper)
|
2013-03-12 12:28:01 +00:00
|
|
|
-- hinting controller
|
|
|
|
local hinter = ReaderHinting:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
}
|
|
|
|
table.insert(self, hinter)
|
2012-06-05 07:23:36 +00:00
|
|
|
else
|
2013-01-13 02:22:33 +00:00
|
|
|
-- make sure we load document first before calling any callback
|
|
|
|
table.insert(self.postInitCallback, function()
|
|
|
|
self.document:loadDocument()
|
|
|
|
end)
|
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-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)
|
2013-01-17 22:12:50 +00:00
|
|
|
-- typeset controller
|
|
|
|
local typeset = ReaderTypeset:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, typeset)
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
if self.document.info.configurable then
|
|
|
|
-- configurable controller
|
|
|
|
local config_dialog = ReaderConfig:new{
|
|
|
|
configurable = self.document.configurable,
|
|
|
|
options = self.document.options,
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, config_dialog)
|
2013-03-04 15:23:37 +00:00
|
|
|
-- kopt option controller
|
2013-02-20 03:50:36 +00:00
|
|
|
local koptlistener = ReaderKoptListener:new{
|
2013-02-19 11:16:42 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
}
|
2013-02-20 03:50:36 +00:00
|
|
|
table.insert(self, koptlistener)
|
2013-03-04 15:23:37 +00:00
|
|
|
-- cre option controller
|
|
|
|
local coptlistener = ReaderCoptListener:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
}
|
|
|
|
table.insert(self, coptlistener)
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
2012-06-26 16:59:22 +00:00
|
|
|
--DEBUG(self.doc_settings)
|
|
|
|
-- we only read settings after all the widgets are initialized
|
|
|
|
self:handleEvent(Event:new("ReadSettings", self.doc_settings))
|
2012-05-18 22:50:26 +00:00
|
|
|
-- notify childs of dimensions
|
|
|
|
self:handleEvent(Event:new("SetDimensions", self.dimen))
|
2013-01-13 02:22:33 +00:00
|
|
|
|
|
|
|
for _,v in ipairs(self.postInitCallback) do
|
|
|
|
v()
|
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
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-06-26 09:05:09 +00:00
|
|
|
self:handleEvent(Event:new("CloseDocument"))
|
|
|
|
self.doc_settings:flush()
|
2012-12-15 01:30:48 +00:00
|
|
|
if self.document ~= nil then
|
2012-05-18 22:50:26 +00:00
|
|
|
self.document:close()
|
2012-12-15 01:30:48 +00:00
|
|
|
self.document = nil
|
|
|
|
self.start_pos = nil
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
UIManager:close(self.dialog)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|