Update lua versions
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / webbrowser.lua
blobfdb36c76c6aa136d14f0dbe0d2cf12539a5f3ce2
2 -- global
3 WebBrowser = {
4 template = "webig_browser",
5 apps = {}
8 function WebBrowser:addWindow(id, title, ui)
9 local found_app = nil
10 for k,app in pairs(self.apps) do
11 if app.id == id then
12 found_app = app
13 app.title = title
14 app.uiWindow = ui
15 app.winw = ui.w
16 app.winh = ui.h
17 end
18 end
19 if found_app == nil then
20 local app = {}
21 app.id = id
22 app.title = ""
23 app.url = ""
24 app.uiWindow = ui
25 app.winid = "ui:interface:" .. id
26 app.winw = ui.w
27 app.winh = ui.h
28 app.minimized = true
29 app.activeUrl = ""
30 app.closedw = 150
31 app.closedh = 0
32 table.insert(self.apps, app)
33 end
34 return ui
35 end
38 function WebBrowser:openWindow(id, url)
39 -- default value if url is not set
40 url = url or "http://app.ryzom.com/"
42 local newWindow = false
43 local app = self:findAppById(id)
45 if not app then
46 app = {}
47 app.id = id
48 app.title = ""
49 app.url = url
50 -- getUI() object
51 app.uiWindow = nil
52 app.winid = "ui:interface:" .. id
53 app.winw = 780
54 app.winh = 500
55 app.closedw = 150
56 app.closedh = 0
57 app.minimized = true
58 app.activeUrl = ""
60 table.insert(self.apps, app)
61 end
63 if not app.uiWindow then
64 -- if there is window present (eg, 'webig'), then reuse it
65 app.uiWindow = getUI(app.winid, false)
66 if not app.uiWindow then
67 app.uiWindow = createRootGroupInstance(self.template, app.id, {
68 x = 0, y = 0, w = app.winw, h = app.winh, home = app.url,
69 browse_redo = "ui:interface:" .. app.id .. ":browser:header_opened:browse_redo",
70 browse_undo = "ui:interface:" .. app.id .. ":browser:header_opened:browse_undo",
71 browse_refresh = "ui:interface:" .. app.id .. ":browser:header_opened:browse_refresh"
73 if not app.uiWindow then
74 return
75 end
76 app.uiWindow:center()
77 end
79 newWindow = true
80 end
82 app.activeUrl = url
84 -- trigger on_open event
85 if not app.uiWindow.opened then
86 app.uiWindow.opened = true
87 end
89 -- trigger on_active event
90 if not app.uiWindow.active then
91 app.uiWindow.active = true
92 end
94 local html = app.uiWindow:find("html")
95 html:browse(url)
97 setTopWindow(app.uiWindow)
98 end
100 function WebBrowser:findAppById(id)
101 for k,app in pairs(self.apps) do
102 if app.id == id then
103 return app
106 return nil
109 function WebBrowser:findAppFromUiCaller()
110 -- id = app123
111 local id = getUICaller().id:match("ui:interface:([^:]*):?")
112 local app = self:findAppById(id)
113 if app then
114 return app
118 function WebBrowser:onActive()
119 if app then
120 self:restoreWindow(app)
124 function WebBrowser:onClickHeaderClose()
125 local app = self:findAppFromUiCaller()
126 if app then
127 self:saveWindow(app)
131 function WebBrowser:onClickHeaderOpen()
132 local app = self:findAppFromUiCaller()
133 if app then
134 self:restoreWindow(app)
138 -- save current window dimension and minimize window
139 function WebBrowser:saveWindow(app)
140 app.minimized = true
141 app.winw = app.uiWindow.w
142 app.winh = app.uiWindow.h
143 -- minimize
144 app.uiWindow.w = app.closedw
145 app.uiWindow.h = app.closedh
148 function WebBrowser:restoreWindow(app)
149 if app.minimized then
150 app.uiWindow.w = app.winw
151 app.uiWindow.h = app.winh
152 app.minimized = false
157 ------------------------------------------------------------------------------------------------------------
159 function WebBrowser:saveWindowPop(app)
160 if app == nil then
161 app = self:findAppFromUiCaller()
164 if app then
165 app.minimized = true
166 -- save size
167 app.winw = app.uiWindow.w
168 app.winh = app.uiWindow.h
169 app.pop_min_h = app.uiWindow.pop_min_h
170 app.pop_max_h = app.uiWindow.pop_max_h
171 app.pop_min_w = app.uiWindow.pop_min_w
172 -- minimize
173 app.uiWindow.w = app.closedw
174 app.uiWindow.h = app.closedh
175 app.uiWindow.pop_min_h = 32
176 app.uiWindow.pop_min_w = app.closedw
180 ------------------------------------------------------------------------------------------------------------
182 function WebBrowser:restoreWindowPop(app)
183 if app == nil then
184 app = self:findAppFromUiCaller()
187 if app and app.minimized then
188 app.uiWindow.w = app.winw
189 app.uiWindow.h = app.winh
190 if app.pop_min_h ~= nil then
191 app.uiWindow.pop_min_h = app.pop_min_h
194 if app.pop_max_h ~= nil then
195 app.uiWindow.pop_max_h = app.pop_max_h
198 if app.pop_min_w ~= nil then
199 app.uiWindow.pop_min_w = app.pop_min_w
201 app.minimized = false
208 function WebBrowser:onClickRedo()
209 -- caller is :header_opened:browse_redo
210 local uiWindow = getUICaller().parent.parent
211 local html = uiWindow:find("html")
212 if html ~= nil then
213 runAH(nil, "browse_redo", "name=" .. html.id)
217 function WebBrowser:onClickUndo()
218 -- caller is :header_opened:browse_undo
219 local uiWindow = getUICaller().parent.parent
221 local html = uiWindow:find("html")
222 if html ~= nil then
223 runAH(nil, "browse_undo", "name=" .. html.id)
227 function WebBrowser:onClickRefresh()
228 -- caller is :header_opened:browse_refresh
229 local uiWindow = getUICaller().parent.parent
231 local html = uiWindow:find("html")
232 if html ~= nil then
233 html:refresh()
237 function WebBrowser:onClickHome()
238 -- caller is :header_opened:browse_home
239 local uiWindow = getUICaller().parent.parent
241 local html = uiWindow:find("html")
242 if html ~= nil then
243 html:browse("home")
247 -- VERSION --
248 RYZOM_WEBBROWSER_VERSION = 10469