2 #include "MessageList.h"
10 #include <X11/Xutil.h> /* needed for Region on solaris? */
17 extern Display
*display
;
24 static XSizeHints mysizehints
;
25 extern Pixel back_pix
, fore_pix
;
28 extern Pixel
GetColor(const char *name
);
30 static XFontStruct
*fn
;
31 static int fontHeight
;
32 extern const char *foreground
;
33 extern const char *background
;
37 static int loadFont(const char *fontname
)
39 if (display
!= NULL
) {
40 fn
= XLoadQueryFont(display
, fontname
);
42 XSetFont(display
, localGC
, fn
->fid
);
44 fn
->max_bounds
.ascent
+ fn
->max_bounds
.descent
+ 2;
47 printf("couldn't set font! (%s)\n", fontname
);
54 static int flush_expose(Window w
)
59 while (XCheckTypedWindowEvent(display
, w
, Expose
, &dummy
))
65 struct msglst
*Headers
;
66 void msglst_show(Pop3 pc
, int x
, int y
)
74 Active_pc
= pc
; /* hold so we can release later. */
77 gcm
= GCForeground
| GCBackground
| GCGraphicsExposures
;
78 gcv
.foreground
= GetColor(foreground
);
79 gcv
.background
= GetColor(background
);
80 gcv
.graphics_exposures
= 0;
81 localGC
= XCreateGC(display
, Root
, gcm
, &gcv
);
84 /* loadFont? or use a proportional instead? mmm. */
85 if (loadFont("-*-fixed-*-r-*-*-10-*-*-*-*-*-*-*") < 0) {
89 if (pc
->getHeaders
== NULL
) {
90 DM(pc
, DEBUG_INFO
, "no getHeaders callback\n");
93 Headers
= pc
->getHeaders(pc
);
94 if (Headers
== NULL
) {
95 #define NO_MSG "no new messages"
96 mysizehints
.height
= 5 + fontHeight
;
97 mysizehints
.width
= XTextWidth(fn
, NO_MSG
, strlen(NO_MSG
));
98 DM(pc
, DEBUG_INFO
, "no new messages\n");
101 mysizehints
.height
= 5;
102 for (h
= Headers
; h
!= NULL
&& limit
> 0; h
= h
->next
, limit
--) {
107 if ((c
= index(h
->from
, '\r')) != NULL
) {
108 *c
= '\0'; /* chomp newlines */
110 if ((c
= index(h
->subj
, '\r')) != NULL
) {
111 *c
= '\0'; /* chomp newlines */
114 if ((c
= index(h
->from
, '<')) != NULL
) {
115 *c
= '\0'; /* chomp <foo@bar */
117 if (h
->from
[0] == '"') { /* remove "'s */
118 for (c
= &h
->from
[1]; *c
&& *c
!= '"'; c
++) {
125 subjlen
= XTextWidth(fn
, h
->subj
, strlen(h
->subj
));
126 frmlen
= XTextWidth(fn
, h
->from
, strlen(h
->from
));
127 if (frmlen
> maxfrm
) {
130 if (subjlen
> maxsubj
) {
133 mysizehints
.height
+= fontHeight
;
136 maxfrm
+ maxsubj
+ LEFT_MAR
+ RIGHT_MAR
+ COL_SEP
;
139 /* Create a window to hold the stuff */
140 mysizehints
.flags
= USSize
| USPosition
;
141 mysizehints
.x
= max(x
- mysizehints
.width
, 0);
142 mysizehints
.y
= max(y
- mysizehints
.height
, 0);
145 XCreateSimpleWindow(display
, Root
, mysizehints
.x
, mysizehints
.y
,
146 mysizehints
.width
, mysizehints
.height
, 2,
147 gcv
.foreground
, gcv
.background
);
148 XSetWMNormalHints(display
, newwin
, &mysizehints
);
149 XStoreName(display
, newwin
, pc
->label
);
150 XSelectInput(display
, newwin
, ExposureMask
);
152 { /* I confess I don't know what this does or whether it matters */
153 XSetWindowAttributes xswa
;
154 xswa
.backing_store
= Always
;
155 xswa
.bit_gravity
= CenterGravity
;
156 XChangeWindowAttributes(display
, newwin
,
157 CWBackingStore
| CWBitGravity
, &xswa
);
160 XMapWindow(display
, newwin
);
163 /* may be called without the window open */
164 void msglst_hide(void)
167 flush_expose(newwin
); /* swallow the messages */
168 XDestroyWindow(display
, newwin
);
170 // no window fprintf(stderr, "unexpected error destroying msglist window\n");
171 if (Active_pc
->releaseHeaders
!= NULL
&& Headers
!= NULL
) {
172 Active_pc
->releaseHeaders(Active_pc
, Headers
);
178 void msglst_redraw(void)
181 unsigned int width
, height
;
190 while (XCheckTypedWindowEvent(display
, newwin
, Expose
, &dummy
));
191 XGetGeometry(display
, newwin
, &r
, &x
, &y
, &width
, &height
, &bw
, &d
);
193 XSetForeground(display
, localGC
, GetColor(background
));
194 XFillRectangle(display
, newwin
, localGC
, 0, 0, width
, height
);
196 XSetForeground(display
, localGC
, GetColor(foreground
));
197 XSetBackground(display
, localGC
, GetColor(background
));
199 if (Headers
== NULL
) {
200 XDrawString(display
, newwin
, localGC
, 0, fontHeight
,
201 NO_MSG
, strlen(NO_MSG
));
202 flush_expose(newwin
);
209 /* draw the from lines */
210 for (h
= Headers
, linenum
= 0; h
!= NULL
&& linenum
< limit
;
211 h
= h
->next
, linenum
++) {
212 int frm
= XTextWidth(fn
, h
->from
, strlen(h
->from
));
216 XDrawString(display
, newwin
, localGC
, LEFT_MAR
,
217 (linenum
+ 1) * fontHeight
, h
->from
,
221 /* draw the subject lines */
222 for (h
= Headers
, linenum
= 0; h
!= NULL
&& linenum
< limit
;
223 h
= h
->next
, linenum
++) {
224 XDrawString(display
, newwin
, localGC
,
225 LEFT_MAR
+ maxfrm
+ COL_SEP
,
226 (linenum
+ 1) * fontHeight
, h
->subj
,