Convert the text window to Xft
This commit is contained in:
committed by
Pasi Kallinen
parent
cfe67ecc62
commit
31f5ca334d
+29
-75
@@ -17,7 +17,8 @@
|
|||||||
#include <X11/Shell.h>
|
#include <X11/Shell.h>
|
||||||
#include <X11/Xos.h>
|
#include <X11/Xos.h>
|
||||||
#include <X11/Xaw/Form.h>
|
#include <X11/Xaw/Form.h>
|
||||||
#include <X11/Xaw/AsciiText.h>
|
#include <X11/Xaw/Label.h>
|
||||||
|
#include <X11/Xaw/Viewport.h>
|
||||||
#include <X11/Xaw/Cardinals.h>
|
#include <X11/Xaw/Cardinals.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
@@ -43,12 +44,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static const char text_translations[] = "#override\n\
|
static const char text_translations[] = "#override\n\
|
||||||
<BtnDown>: dismiss_text()\n\
|
<Btn1Down>: dismiss_text()\n\
|
||||||
|
<Btn4Down>: scroll(8)\n\
|
||||||
|
<Btn5Down>: scroll(2)\n\
|
||||||
<Key>: key_dismiss_text()";
|
<Key>: key_dismiss_text()";
|
||||||
|
|
||||||
#ifdef GRAPHIC_TOMBSTONE
|
#ifdef GRAPHIC_TOMBSTONE
|
||||||
static const char rip_translations[] = "#override\n\
|
static const char rip_translations[] = "#override\n\
|
||||||
<BtnDown>: rip_dismiss_text()\n\
|
<Btn1Down>: rip_dismiss_text()\n\
|
||||||
|
<Btn4Down>: scroll(8)\n\
|
||||||
|
<Btn5Down>: scroll(2)\n\
|
||||||
<Key>: rip_dismiss_text()";
|
<Key>: rip_dismiss_text()";
|
||||||
|
|
||||||
static Widget create_ripout_widget(Widget);
|
static Widget create_ripout_widget(Widget);
|
||||||
@@ -147,42 +152,13 @@ display_text_window(struct xwindow *wp, boolean blocking)
|
|||||||
struct text_info_t *text_info;
|
struct text_info_t *text_info;
|
||||||
Arg args[8];
|
Arg args[8];
|
||||||
Cardinal num_args;
|
Cardinal num_args;
|
||||||
Dimension width, height, font_height;
|
|
||||||
int nlines;
|
|
||||||
|
|
||||||
text_info = wp->text_information;
|
text_info = wp->text_information;
|
||||||
width = text_info->max_width + text_info->extra_width;
|
|
||||||
text_info->blocked = blocking;
|
text_info->blocked = blocking;
|
||||||
text_info->destroy_on_ack = FALSE;
|
text_info->destroy_on_ack = FALSE;
|
||||||
font_height = nhFontHeight(wp->w, NHW_TEXT);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate the number of lines to use. First, find the number of
|
|
||||||
* lines that would fit on the screen. Next, remove four of these
|
|
||||||
* lines to give room for a possible window manager titlebar (some
|
|
||||||
* wm's put a titlebar on transient windows). Make sure we have
|
|
||||||
* _some_ lines. Finally, use the number of lines in the text if
|
|
||||||
* there are fewer than the max.
|
|
||||||
*/
|
|
||||||
nlines = (XtScreen(wp->w)->height - text_info->extra_height) / font_height;
|
|
||||||
nlines -= 4;
|
|
||||||
|
|
||||||
if (nlines > text_info->text.num_lines)
|
|
||||||
nlines = text_info->text.num_lines;
|
|
||||||
if (nlines <= 0)
|
|
||||||
nlines = 1;
|
|
||||||
|
|
||||||
height = nlines * font_height + text_info->extra_height;
|
|
||||||
|
|
||||||
num_args = 0;
|
num_args = 0;
|
||||||
|
|
||||||
if (nlines < text_info->text.num_lines) {
|
|
||||||
/* add on width of scrollbar. Really should look this up,
|
|
||||||
* but can't until the window is realized. Chicken-and-egg problem.
|
|
||||||
*/
|
|
||||||
width += 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef GRAPHIC_TOMBSTONE
|
#ifdef GRAPHIC_TOMBSTONE
|
||||||
if (text_info->is_rip) {
|
if (text_info->is_rip) {
|
||||||
Widget rip = create_ripout_widget(XtParent(wp->w));
|
Widget rip = create_ripout_widget(XtParent(wp->w));
|
||||||
@@ -195,18 +171,10 @@ display_text_window(struct xwindow *wp, boolean blocking)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (width > (Dimension) XtScreen(wp->w)->width) { /* too wide for screen */
|
XtSetArg(args[num_args], XtNlabel, text_info->text.text);
|
||||||
/* Back off some amount - we really need to back off the scrollbar */
|
|
||||||
/* width plus some extra. */
|
|
||||||
width = XtScreen(wp->w)->width - 20;
|
|
||||||
}
|
|
||||||
XtSetArg(args[num_args], XtNstring, text_info->text.text);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], XtNwidth, width);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], XtNheight, height);
|
|
||||||
num_args++;
|
num_args++;
|
||||||
XtSetValues(wp->w, args, num_args);
|
XtSetValues(wp->w, args, num_args);
|
||||||
|
X11_update_label_if_Xft(wp->w);
|
||||||
|
|
||||||
#ifdef TRANSIENT_TEXT
|
#ifdef TRANSIENT_TEXT
|
||||||
XtRealizeWidget(wp->popup);
|
XtRealizeWidget(wp->popup);
|
||||||
@@ -217,22 +185,6 @@ display_text_window(struct xwindow *wp, boolean blocking)
|
|||||||
|
|
||||||
nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w);
|
nh_XtPopup(wp->popup, (int) XtGrabNone, wp->w);
|
||||||
|
|
||||||
/* Kludge alert. Scrollbars are not sized correctly by the Text widget */
|
|
||||||
/* if added before the window is displayed, so do it afterward. */
|
|
||||||
num_args = 0;
|
|
||||||
if (nlines < text_info->text.num_lines) { /* add vert scrollbar */
|
|
||||||
XtSetArg(args[num_args], nhStr(XtNscrollVertical),
|
|
||||||
XawtextScrollAlways);
|
|
||||||
num_args++;
|
|
||||||
}
|
|
||||||
if (width >= (Dimension)(XtScreen(wp->w)->width - 20)) { /* too wide */
|
|
||||||
XtSetArg(args[num_args], nhStr(XtNscrollHorizontal),
|
|
||||||
XawtextScrollAlways);
|
|
||||||
num_args++;
|
|
||||||
}
|
|
||||||
if (num_args)
|
|
||||||
XtSetValues(wp->w, args, num_args);
|
|
||||||
|
|
||||||
/* We want the user to acknowledge. */
|
/* We want the user to acknowledge. */
|
||||||
if (blocking) {
|
if (blocking) {
|
||||||
(void) x_event(EXIT_ON_EXIT);
|
(void) x_event(EXIT_ON_EXIT);
|
||||||
@@ -246,7 +198,6 @@ create_text_window(struct xwindow *wp)
|
|||||||
struct text_info_t *text_info;
|
struct text_info_t *text_info;
|
||||||
Arg args[8];
|
Arg args[8];
|
||||||
Cardinal num_args;
|
Cardinal num_args;
|
||||||
Position top_margin, bottom_margin, left_margin, right_margin;
|
|
||||||
Widget form;
|
Widget form;
|
||||||
|
|
||||||
wp->type = NHW_TEXT;
|
wp->type = NHW_TEXT;
|
||||||
@@ -280,46 +231,49 @@ create_text_window(struct xwindow *wp)
|
|||||||
wp->popup,
|
wp->popup,
|
||||||
XtParseTranslationTable("<Message>WM_PROTOCOLS: delete_text()"));
|
XtParseTranslationTable("<Message>WM_PROTOCOLS: delete_text()"));
|
||||||
|
|
||||||
|
/* Create the viewport */
|
||||||
|
num_args = 0;
|
||||||
|
XtSetArg(args[num_args], XtNallowVert, True);
|
||||||
|
num_args++;
|
||||||
|
XtSetArg(args[num_args], XtNallowHoriz, True);
|
||||||
|
num_args++;
|
||||||
|
Widget viewport = XtCreateManagedWidget(
|
||||||
|
"text_viewport", /* name */
|
||||||
|
viewportWidgetClass, /* widget class from Window.h */
|
||||||
|
wp->popup, /* parent widget */
|
||||||
|
args, /* set some values */
|
||||||
|
num_args); /* number of values to set */
|
||||||
|
|
||||||
num_args = 0;
|
num_args = 0;
|
||||||
XtSetArg(args[num_args], XtNallowShellResize, True), num_args++;
|
XtSetArg(args[num_args], XtNallowShellResize, True), num_args++;
|
||||||
XtSetArg(args[num_args], XtNtranslations,
|
XtSetArg(args[num_args], XtNtranslations,
|
||||||
XtParseTranslationTable(text_translations)), num_args++;
|
XtParseTranslationTable(text_translations)), num_args++;
|
||||||
form = XtCreateManagedWidget("form", formWidgetClass, wp->popup, args,
|
form = XtCreateManagedWidget("form", formWidgetClass, viewport, args,
|
||||||
num_args);
|
num_args);
|
||||||
|
|
||||||
num_args = 0;
|
num_args = 0;
|
||||||
XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], XtNresize, XawtextResizeBoth);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], XtNtranslations,
|
XtSetArg(args[num_args], XtNtranslations,
|
||||||
XtParseTranslationTable(text_translations));
|
XtParseTranslationTable(text_translations));
|
||||||
num_args++;
|
num_args++;
|
||||||
|
XtSetArg(args[num_args], XtNjustify, XtJustifyLeft); num_args++;
|
||||||
|
|
||||||
wp->w = XtCreateManagedWidget(svk.killer.name[0] && WIN_MAP == WIN_ERR
|
wp->w = XtCreateManagedWidget(svk.killer.name[0] && WIN_MAP == WIN_ERR
|
||||||
? "tombstone"
|
? "tombstone"
|
||||||
: "text_text", /* name */
|
: "text_text", /* name */
|
||||||
asciiTextWidgetClass,
|
labelWidgetClass,
|
||||||
form, /* parent widget */
|
form, /* parent widget */
|
||||||
args, /* set some values */
|
args, /* set some values */
|
||||||
num_args); /* number of values to set */
|
num_args); /* number of values to set */
|
||||||
|
X11_wrap_widget_if_Xft(wp->w, NHW_TEXT);
|
||||||
|
|
||||||
/* Get the font and margin information. */
|
/* Get the font and margin information. */
|
||||||
num_args = 0;
|
num_args = 0;
|
||||||
XtSetArg(args[num_args], XtNfont, &text_info->fs);
|
XtSetArg(args[num_args], XtNfont, &text_info->fs);
|
||||||
num_args++;
|
num_args++;
|
||||||
XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], nhStr(XtNbottomMargin), &bottom_margin);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin);
|
|
||||||
num_args++;
|
|
||||||
XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin);
|
|
||||||
num_args++;
|
|
||||||
XtGetValues(wp->w, args, num_args);
|
XtGetValues(wp->w, args, num_args);
|
||||||
|
|
||||||
text_info->extra_width = left_margin + right_margin;
|
text_info->extra_width = 0;
|
||||||
text_info->extra_height = top_margin + bottom_margin;
|
text_info->extra_height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user