Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
bw.c
Go to the documentation of this file.
1/*
2 * File: bw.c
3 *
4 * Copyright (C) 2006-2007 Jorge Arellano Cid <jcid@dillo.org>
5 * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
18#include "bw.h"
19#include "msg.h"
20#include "list.h"
21#include "capi.h"
22#include "uicmd.hh"
23
24
25/*
26 * Local Data
27 */
28/* A list of working browser windows */
30static int num_bws, num_bws_max;
31
32
36void a_Bw_init(void)
37{
38 num_bws = 0;
39 num_bws_max = 16;
40 bws = NULL;
41}
42
48{
49 BrowserWindow *bw;
50
51 /* We use dNew0() to zero the memory */
52 bw = dNew0(BrowserWindow, 1);
54 bws[num_bws++] = bw;
55
56 /* Initialize nav_stack */
57 bw->nav_stack = dList_new(8);
58 bw->nav_stack_ptr = -1;
59
60 /* Init expect */
61 bw->nav_expect_url = NULL;
62
63 bw->redirect_level = 0;
64 bw->meta_refresh_status = 0;
65 bw->meta_refresh_url = NULL;
66
67 bw->RootClients = dList_new(8);
68 bw->ImageClients = dList_new(8);
69 bw->NumImages = 0;
70 bw->NumImagesGot = 0;
72 bw->PageUrls = dList_new(8);
73 bw->Docs = dList_new(8);
74
75 bw->num_page_bugs = 0;
76 bw->page_bugs = dStr_new("");
77
78 bw->zoom = 1.0;
79
80 /* now that the bw is made, let's customize it.. */
81 //Interface_browser_window_customize(bw);
82
83 return bw;
84}
85
90{
91 int i, j;
92
93 for (i = 0; i < num_bws; i++) {
94 if (bws[i] == bw) {
96
99 dList_free(bw->Docs);
100
102 for (j = 0; j < dList_length(bw->PageUrls); ++j)
104 dList_free(bw->PageUrls);
105
106 for (j = 0; j < dList_length(bw->nav_stack); ++j)
109
111
112 dStr_free(bw->page_bugs, 1);
113 dFree(bw);
114 break;
115 }
116 }
117}
118
119/*- Clients ----------------------------------------------------------------*/
128void a_Bw_add_client(BrowserWindow *bw, int Key, int Root)
129{
130 dReturn_if_fail ( bw != NULL );
131
132 if (Root) {
134 } else {
136 bw->NumImages++;
137 /* --Images progress-bar stuff-- */
139 }
142}
143
149int a_Bw_remove_client(BrowserWindow *bw, int ClientKey)
150{
151 void *data;
152
153 if ((data = dList_find(bw->RootClients, INT2VOIDP(ClientKey)))) {
155 } else if ((data = dList_find(bw->ImageClients, INT2VOIDP(ClientKey)))) {
157 ++bw->NumImagesGot;
158 }
159 return data ? 0 : 1;
160}
161
167void a_Bw_close_client(BrowserWindow *bw, int ClientKey)
168{
169 if (a_Bw_remove_client(bw, ClientKey) == 0) {
171 if (bw->NumImagesGot == bw->NumImages)
172 a_UIcmd_set_img_prog(bw, 0, 0, 0);
173 if (dList_length(bw->RootClients) == 0)
175 }
176}
177
183{
184 void *data;
185
186 if (flags & BW_Root) {
187 /* Remove root clients */
188 while ((data = dList_nth_data(bw->RootClients, 0))) {
189 a_Capi_stop_client(VOIDP2INT(data), (flags & BW_Force));
191 }
192 }
193
194 if (flags & BW_Img) {
195 /* Remove image clients */
196 while ((data = dList_nth_data(bw->ImageClients, 0))) {
197 a_Capi_stop_client(VOIDP2INT(data), (flags & BW_Force));
199 }
200 }
201}
202
203/*- Page -------------------------------------------------------------------*/
210{
211 dReturn_if_fail ( bw != NULL && Url != NULL );
212
215 }
216}
217
221void a_Bw_add_doc(BrowserWindow *bw, void *vdoc)
222{
223 dReturn_if_fail ( bw != NULL && vdoc != NULL);
224
225 dList_append(bw->Docs, vdoc);
226}
227
232{
233 void *doc = NULL;
234 int len = dList_length(bw->Docs);
235
236 if (len == 1)
237 doc = dList_nth_data(bw->Docs, 0);
238 else if (len > 1)
239 MSG("a_Bw_get_current_doc() multiple docs not implemented\n");
240
241 return doc;
242}
243
251{
252 void *doc = NULL;
253
254 if (url && dList_find_custom(bw->PageUrls, url, (dCompareFunc)a_Url_cmp)) {
255 doc = a_Bw_get_current_doc(bw);
256 }
257 return doc;
258}
259
263void a_Bw_remove_doc(BrowserWindow *bw, void *vdoc)
264{
265 void *data;
266
267 if ((data = dList_find(bw->Docs, vdoc))) {
268 dList_remove_fast(bw->Docs, data);
269 }
270}
271
272/*- Cleanup ----------------------------------------------------------------*/
278{
279 void *data;
280
281 /* Remove root clients */
282 while ((data = dList_nth_data(bw->RootClients, 0))) {
284 }
285 /* Remove image clients */
286 while ((data = dList_nth_data(bw->ImageClients, 0))) {
288 }
289 /* Remove PageUrls */
290 while ((data = dList_nth_data(bw->PageUrls, 0))) {
291 a_Url_free(data);
292 dList_remove_fast(bw->PageUrls, data);
293 }
294
295 /* Zero image-progress data */
296 bw->NumImages = 0;
297 bw->NumImagesGot = 0;
298
299 /* Zero stylesheet counter */
300 bw->NumPendingStyleSheets = 0;
301}
302
303/*--------------------------------------------------------------------------*/
304
305int a_Bw_num(void)
306{
307 return num_bws;
308}
309
314{
315 if (i >= 0 && i < num_bws)
316 return bws[i];
317 return NULL;
318}
319
320/* expect API ------------------------------------------------------------- */
321
322void a_Bw_expect(BrowserWindow *bw, const DilloUrl *url)
323{
325 bw->nav_expect_url = a_Url_dup(url);
326}
327
329{
331 bw->nav_expect_url = NULL;
332}
333
335{
336 return (bw->nav_expect_url != NULL);
337}
338
340{
341 return bw->nav_expect_url;
342}
343
#define MSG(...)
Definition bookmarks.c:46
bool_t a_Bw_expecting(BrowserWindow *bw)
Definition bw.c:334
int a_Bw_remove_client(BrowserWindow *bw, int ClientKey)
Remove the cache-client from the bw's list (client can be a image or a html page) Return: 0 if found,...
Definition bw.c:149
void a_Bw_expect(BrowserWindow *bw, const DilloUrl *url)
Definition bw.c:322
void a_Bw_free(BrowserWindow *bw)
Free resources associated to a bw.
Definition bw.c:89
void a_Bw_close_client(BrowserWindow *bw, int ClientKey)
Close a cache-client upon successful retrieval.
Definition bw.c:167
void * a_Bw_get_url_doc(BrowserWindow *bw, const DilloUrl *url)
Get document by URL.
Definition bw.c:250
static BrowserWindow ** bws
Definition bw.c:29
void a_Bw_add_url(BrowserWindow *bw, const DilloUrl *Url)
Add an URL to the browser window's list.
Definition bw.c:209
static int num_bws
Definition bw.c:30
BrowserWindow * a_Bw_get(int i)
Return a bw by index.
Definition bw.c:313
void a_Bw_stop_clients(BrowserWindow *bw, int flags)
Stop the active clients of this bw's top page.
Definition bw.c:182
void * a_Bw_get_current_doc(BrowserWindow *bw)
Get current document.
Definition bw.c:231
void a_Bw_add_client(BrowserWindow *bw, int Key, int Root)
Add a reference to a cache-client.
Definition bw.c:128
static int num_bws_max
Definition bw.c:30
void a_Bw_init(void)
Initialize global data.
Definition bw.c:36
void a_Bw_cleanup(BrowserWindow *bw)
Empty RootClients, ImageClients and PageUrls lists and reset progress bar data.
Definition bw.c:277
void a_Bw_cancel_expect(BrowserWindow *bw)
Definition bw.c:328
const DilloUrl * a_Bw_expected_url(BrowserWindow *bw)
Definition bw.c:339
int a_Bw_num(void)
Definition bw.c:305
BrowserWindow * a_Bw_new(void)
Create a new browser window and return it.
Definition bw.c:47
void a_Bw_remove_doc(BrowserWindow *bw, void *vdoc)
Remove a document from the bw's list.
Definition bw.c:263
void a_Bw_add_doc(BrowserWindow *bw, void *vdoc)
Add a document to the browser window's list.
Definition bw.c:221
#define BW_Img
Definition bw.h:22
#define BW_Force
Definition bw.h:23
#define BW_Root
Definition bw.h:21
void a_Capi_stop_client(int Key, int force)
Remove a client from the cache client queue.
Definition capi.c:621
unsigned char bool_t
Definition d_size.h:21
void dFree(void *mem)
Definition dlib.c:68
Dlist * dList_new(int size)
Create a new empty list.
Definition dlib.c:548
int dList_length(Dlist *lp)
For completing the ADT.
Definition dlib.c:613
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
Definition dlib.c:662
void dList_remove_fast(Dlist *lp, const void *data)
Remove a data item without preserving order.
Definition dlib.c:623
void dStr_free(Dstr *ds, int all)
Free a dillo string.
Definition dlib.c:337
Dstr * dStr_new(const char *s)
Create a new string.
Definition dlib.c:325
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
Definition dlib.c:597
void dList_free(Dlist *lp)
Free a list (not its elements)
Definition dlib.c:564
void * dList_find_custom(Dlist *lp, const void *data, dCompareFunc func)
Search a data item using a custom function.
Definition dlib.c:704
void * dList_find(Dlist *lp, const void *data)
Return the found data item, or NULL if not present.
Definition dlib.c:672
#define dReturn_if_fail(expr)
Definition dlib.h:72
int(* dCompareFunc)(const void *a, const void *b)
Definition dlib.h:144
#define dNew0(type, count)
Definition dlib.h:51
#define VOIDP2INT(p)
Definition dlib.h:43
#define INT2VOIDP(i)
Definition dlib.h:44
#define a_List_add(list, num_items, alloc_step)
Definition cookies.c:68
Fast list methods.
#define a_List_remove(list, item, num_items)
Quickly remove an item from the list ==> We preserve relative position, but not the element index <==...
Definition list.h:38
Contains the specific data for a single window.
Definition bw.h:27
Dlist * ImageClients
Image Keys for all active connections in the window.
Definition bw.h:42
int NumImagesGot
Number of images already loaded.
Definition bw.h:46
int redirect_level
Counter for the number of hops on a redirection.
Definition bw.h:63
int meta_refresh_status
Url for zero-delay redirections in the META element.
Definition bw.h:66
Dstr * page_bugs
Definition bw.h:71
Dlist * RootClients
A list of active cache clients in the window (The primary Key)
Definition bw.h:40
Dlist * Docs
Root document(s).
Definition bw.h:37
float zoom
Definition bw.h:74
Dlist * nav_stack
The navigation stack (holds indexes to history list)
Definition bw.h:53
int NumImages
Number of images in the page.
Definition bw.h:44
int nav_stack_ptr
'nav_stack_ptr' refers to what's being displayed
Definition bw.h:55
DilloUrl * meta_refresh_url
Definition bw.h:67
Dlist * PageUrls
List of all Urls requested by this page (and its types)
Definition bw.h:50
int num_page_bugs
HTML-bugs detected at parse time.
Definition bw.h:70
DilloUrl * nav_expect_url
When the user clicks a link, the URL isn't pushed directly to history; nav_expect_url holds it until ...
Definition bw.h:59
int NumPendingStyleSheets
Number of not yet arrived style sheets.
Definition bw.h:48
Definition url.h:88
void a_UIcmd_set_buttons_sens(BrowserWindow *bw)
Definition uicmd.cc:1527
void a_UIcmd_set_img_prog(BrowserWindow *bw, int n_img, int t_img, int cmd)
Definition uicmd.cc:1469
int a_Url_cmp(const DilloUrl *A, const DilloUrl *B)
Compare two Url's to check if they're the same, or which one is bigger.
Definition url.c:506
void a_Url_free(DilloUrl *url)
Free a DilloUrl.
Definition url.c:208
DilloUrl * a_Url_dup(const DilloUrl *ori)
Duplicate a Url structure.
Definition url.c:477