1 /*
2  * Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
3  *
4  * Framebuffer windowing toolkit window widget.
5  *
6  * This file is part of NetSurf, http://www.netsurf-browser.org/
7  *
8  * NetSurf is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * NetSurf is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <stdbool.h>
22 #include <stdlib.h>
23 
24 #include <libnsfb.h>
25 #include <libnsfb_plot.h>
26 
27 #include "netsurf/browser_window.h"
28 
29 #include "framebuffer/gui.h"
30 #include "framebuffer/fbtk.h"
31 
32 #include "widget.h"
33 
34 /** Window redraw callback.
35  *
36  * Called when a window requires redrawing.
37  *
38  * @param widget The widget to be redrawn.
39  * @param cbi The callback parameters.
40  * @return The callback result.
41  */
42 static int
fb_redraw_window(fbtk_widget_t * widget,fbtk_callback_info * cbi)43 fb_redraw_window(fbtk_widget_t *widget, fbtk_callback_info *cbi)
44 {
45 	nsfb_bbox_t bbox;
46 	nsfb_t *nsfb;
47 
48 	if ((widget->bg & 0xFF000000) == 0)
49 		return 0;
50 
51 	nsfb = fbtk_get_nsfb(widget);
52 
53 	fbtk_get_bbox(widget, &bbox);
54 
55 	nsfb_claim(nsfb, &bbox);
56 
57 	nsfb_plot_rectangle_fill(nsfb, &bbox, widget->bg);
58 
59 	nsfb_update(nsfb, &bbox);
60 
61 	return 0;
62 }
63 
64 /* exported function documented in fbtk.h */
65 fbtk_widget_t *
fbtk_create_window(fbtk_widget_t * parent,int x,int y,int width,int height,colour bg)66 fbtk_create_window(fbtk_widget_t *parent,
67 		   int x,
68 		   int y,
69 		   int width,
70 		   int height,
71 		   colour bg)
72 {
73 	fbtk_widget_t *neww;
74 
75 	if (parent == NULL)
76 		return NULL;
77 
78 	neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_WINDOW, x, y, width, height);
79 
80 	neww->bg = bg;
81 
82 	fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_window, NULL);
83 
84 	return neww;
85 }
86 
87 /*
88  * Local Variables:
89  * c-basic-offset:8
90  * End:
91  */
92