NetSurf
statusbar.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 Ole Loots <ole@monochrom.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <fcntl.h>
22#include <limits.h>
23#include <unistd.h>
24#include <string.h>
25#include <stdlib.h>
26#include <stdbool.h>
27#include <assert.h>
28#include <math.h>
29
30#include "utils/log.h"
31#include "netsurf/mouse.h"
32#include "netsurf/plotters.h"
33
34#include "atari/gui.h"
35#include "atari/statusbar.h"
36#include "atari/rootwin.h"
37#include "atari/misc.h"
38#include "atari/res/netsurf.rsh"
39#include "atari/plot/plot.h"
40#include "atari/osspec.h"
41
42#ifdef WITH_CUSTOM_STATUSBAR
43extern int atari_plot_vdi_handle;
44
45static
46void __CDECL evnt_sb_redraw( COMPONENT *c, long buff[8] )
47{
48 struct gui_window * gw = (struct gui_window *)mt_CompDataSearch(&app, c, CDT_OWNER);
49 assert(gw != NULL);
51 assert( sb != NULL );
52 if( sb == NULL )
53 return;
54
55 if( sb->attached == false )
56 return;
57
58 LGRECT work, lclip;
59 short pxy[8], d, pxyclip[4];
60
61 mt_CompGetLGrect(&app, sb->comp, WF_WORKXYWH, &work);
62 lclip = work;
63 if ( !rc_lintersect( (LGRECT*)&buff[4], &lclip ) ) {
64 return;
65 }
66 vsf_interior(atari_plot_vdi_handle, FIS_SOLID );
67 vsl_color(atari_plot_vdi_handle, BLACK );
68 vsl_type(atari_plot_vdi_handle, 1);
69 vsl_width(atari_plot_vdi_handle, 1 );
70 vst_color(atari_plot_vdi_handle, BLACK);
71
72 vst_height(atari_plot_vdi_handle, atari_sysinfo.medium_sfont_pxh, &pxy[0], &pxy[1], &pxy[2], &pxy[3] );
73 vst_alignment(atari_plot_vdi_handle, 0, 5, &d, &d );
74 vst_effects(atari_plot_vdi_handle, 0 );
75 pxyclip[0] = lclip.g_x;
76 pxyclip[1] = lclip.g_y;
77 pxyclip[2] = lclip.g_x + lclip.g_w-1;
78 pxyclip[3] = lclip.g_y + lclip.g_h-1;
79
80 vs_clip(atari_plot_vdi_handle, 1, (short*)&pxyclip );
81 vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
82
83 if( lclip.g_y <= work.g_y ) {
84 pxy[0] = work.g_x;
85 pxy[1] = work.g_y;
86 pxy[2] = MIN( work.g_x + work.g_w, lclip.g_x + lclip.g_w );
87 pxy[3] = work.g_y;
88 v_pline(atari_plot_vdi_handle, 2, (short*)&pxy );
89 }
90
91 if(app.nplanes > 2) {
92 vsf_color(atari_plot_vdi_handle, LWHITE);
93 } else {
94 vsf_color(atari_plot_vdi_handle, WHITE );
95 }
96
97 pxy[0] = work.g_x;
98 pxy[1] = work.g_y+1;
99 pxy[2] = work.g_x + work.g_w-1;
100 pxy[3] = work.g_y + work.g_h-1;
101 v_bar(atari_plot_vdi_handle, pxy );
102
103
104 if( sb->textlen > 0 ) {
105 size_t i;
106 short curx;
107 short vqw[4];
108 char t[2];
109 short cw = 8;
110 t[1]=0;
112 t[0]='A';
113 int r = vqt_width(atari_plot_vdi_handle, t[0], &vqw[0], &vqw[1], &vqw[2] );
114 cw = vqw[0];
115 }
116 vswr_mode(atari_plot_vdi_handle, MD_TRANS );
117 for( curx = work.g_x + 2, i=0 ; (curx+cw < work.g_x+work.g_w ) && i < sb->textlen; i++ ){
118 t[0] = sb->text[i];
120 vqt_width(atari_plot_vdi_handle, t[0], &vqw[0], &vqw[1], &vqw[2] );
121 cw = vqw[0];
122 }
123 if( curx >= lclip.g_x - cw ) {
124 v_gtext(atari_plot_vdi_handle, curx, work.g_y + 5, (char*)&t );
125 }
126 curx += cw;
127 if( curx >= lclip.g_x + lclip.g_w )
128 break;
129 }
130 }
131 vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
132 pxy[0] = work.g_x + work.g_w;
133 pxy[1] = work.g_y + work.g_h;
134 pxy[2] = work.g_x + work.g_w;
135 pxy[3] = work.g_y + work.g_h-work.g_h;
136 v_pline(atari_plot_vdi_handle, 2, (short*)&pxy );
137
138 vs_clip(atari_plot_vdi_handle, 0, (short*)&pxyclip );
139 return;
140}
141
142static void __CDECL evnt_sb_click( COMPONENT *c, long buff[8] )
143{
144 static bool prevstate;
145 LGRECT work;
146 mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work);
147 if( evnt.mx >= work.g_x + (work.g_w) && evnt.mx <= work.g_x + work.g_w &&
148 evnt.my >= work.g_y + (work.g_h) && evnt.my <= work.g_y + work.g_h ) {
149 // click within sb button
150 }
151}
152
154{
155 CMP_STATUSBAR s = malloc( sizeof(struct s_statusbar) );
156 s->attached = false;
157 s->comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, STATUSBAR_HEIGHT, 0);
158 s->comp->rect.g_h = STATUSBAR_HEIGHT;
159 s->comp->bounds.max_height = STATUSBAR_HEIGHT;
160 mt_CompDataAttach( &app, s->comp, CDT_OWNER, gw );
161 mt_CompEvntAttach( &app, s->comp, WM_REDRAW, evnt_sb_redraw );
162 mt_CompEvntAttach( &app, s->comp, WM_XBUTTON, evnt_sb_click );
163 sb_set_text( s, (char*)"" );
164 return( s );
165}
166
168{
169 NSLOG(netsurf, INFO, "%s\n", __FUNCTION__);
170 if( s ) {
171 if( s->comp ){
172 mt_CompDelete( &app, s->comp );
173 }
174 free( s );
175 }
176}
177
178void sb_set_text(CMP_STATUSBAR sb , const char * text)
179{
180
181 LGRECT work;
182 assert( sb != NULL );
183 assert( sb->comp != NULL );
184 strncpy( (char*)&sb->text, text, STATUSBAR_MAX_SLEN );
186 sb->textlen = strlen( (char*)&sb->text );
187 if( sb->attached ){
188 struct gui_window * gw = (struct gui_window *)mt_CompDataSearch(&app, sb->comp, CDT_OWNER);
189 if( gw != NULL ){
190 mt_CompGetLGrect(&app, sb->comp, WF_WORKXYWH, &work);
191 ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle,
192 work.g_x, work.g_y, work.g_w, work.g_h );
193 }
194 }
195}
196
197#else
198
200{
201 CMP_STATUSBAR s = malloc( sizeof(struct s_statusbar) );
202 s->attached = false;
203 sb_set_text( s, (char*)"" );
204 return( s );
205}
206
208{
209 NSLOG(netsurf, INFO, "%s\n", __FUNCTION__);
210 if( s ) {
211 free( s );
212 }
213}
214
215void sb_attach(CMP_STATUSBAR sb, struct gui_window * gw)
216{
217 sb->aes_win = gemtk_wm_get_handle(gw->root->win);
218 sb->attached = true;
219}
220
221void sb_set_text(CMP_STATUSBAR sb, const char * text )
222{
223 assert( sb != NULL );
224 strncpy(sb->text, text, STATUSBAR_MAX_SLEN);
226 sb->textlen = strlen(sb->text);
227 if(sb->attached){
228 wind_set_str(sb->aes_win, WF_INFO, sb->text);
229 }
230}
231
232#endif
#define CDT_OWNER
Definition: gui.h:96
int atari_plot_vdi_handle
Definition: plot.c:208
Core mouse and pointer states.
Target independent plotting interface.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
#define MIN(a, b)
Definition: os3support.h:51
NS_ATARI_SYSINFO atari_sysinfo
Definition: osspec.c:38
void sb_set_text(CMP_STATUSBAR sb, const char *text)
Definition: statusbar.c:221
CMP_STATUSBAR sb_create(struct gui_window *gw)
Definition: statusbar.c:199
void sb_attach(CMP_STATUSBAR sb, struct gui_window *gw)
Definition: statusbar.c:215
void sb_destroy(CMP_STATUSBAR s)
Definition: statusbar.c:207
#define STATUSBAR_MAX_SLEN
Definition: statusbar.h:23
#define STATUSBAR_HEIGHT
Definition: statusbar.h:22
Interface to utility string handling.
unsigned short medium_sfont_pxh
Definition: osspec.h:32
bool sfont_monospaced
Definition: osspec.h:34
first entry in window list
Definition: gui.c:296
struct s_gui_win_root * root
Definition: gui.h:148
GUIWIN * win
Definition: gui.h:121
CMP_STATUSBAR statusbar
Definition: gui.h:123
short aes_win
Definition: statusbar.h:32
size_t textlen
Definition: statusbar.h:30
char text[STATUSBAR_MAX_SLEN+1]
Definition: statusbar.h:29
bool attached
Definition: statusbar.h:31
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978