1 |
/* |
2 |
* textarea_gtk.c -- text area, GTK |
3 |
*/ |
4 |
|
5 |
#include "gui.h" |
6 |
|
7 |
|
8 |
/* |
9 |
* gui_ta_text_width -- return width of text in specified style |
10 |
*/ |
11 |
|
12 |
unsigned long gui_ta_text_width(struct gui_ta *doc, const wchar_t *text, |
13 |
unsigned long s) |
14 |
{ |
15 |
struct gui_ta_style *style; |
16 |
int width; |
17 |
|
18 |
style = (*doc->style)[s]; |
19 |
|
20 |
width = gdk_text_width_wc(style->handle, text, wcslen(text)); |
21 |
|
22 |
return width * 2; |
23 |
} |
24 |
|
25 |
|
26 |
/* |
27 |
* gui_ta_render_text -- render a word to the window |
28 |
*/ |
29 |
|
30 |
void gui_ta_render_text(struct gui_ta *doc, wchar_t *text, unsigned long s, |
31 |
unsigned long x, unsigned long y, unsigned long box_x0, |
32 |
unsigned long box_y0, unsigned long box_x1, unsigned long box_y1, |
33 |
bool sel) |
34 |
{ |
35 |
struct gui_ta_style *style; |
36 |
GdkGC *gc; |
37 |
GdkColor fg, bg; |
38 |
|
39 |
style = (*doc->style)[s]; |
40 |
|
41 |
BGR_TO_GDK(sel ? style->bcolour : style->fcolour, fg); |
42 |
BGR_TO_GDK(sel ? style->fcolour : style->bcolour, bg); |
43 |
|
44 |
gc = gdk_gc_new(gui_redraw_widget->window); |
45 |
|
46 |
gdk_colormap_alloc_color(gdk_window_get_colormap(gui_redraw_widget->window), &bg, FALSE, TRUE); |
47 |
// gdk_gc_set_foreground(gui_redraw_widget->style->fg_gc[gui_redraw_widget->state], &bg); |
48 |
gdk_gc_set_foreground(gc, &bg); |
49 |
gdk_draw_rectangle(gui_redraw_widget->window, gc, |
50 |
TRUE, box_x0 / 2, box_y0 / 2, (box_x1-box_x0) / 2 + 1, (box_y1-box_y0) / 2 + 1); |
51 |
|
52 |
gdk_colormap_alloc_color(gdk_window_get_colormap(gui_redraw_widget->window), &fg, FALSE, TRUE); |
53 |
// gdk_gc_set_foreground(gui_redraw_widget->style->fg_gc[gui_redraw_widget->state], &fg); |
54 |
gdk_gc_set_foreground(gc, &fg); |
55 |
gdk_draw_text_wc(gui_redraw_widget->window, style->handle, gc, |
56 |
x / 2, y / 2, text, wcslen(text)); |
57 |
} |
58 |
|
59 |
|
60 |
/* |
61 |
* gui_ta_position_x -- get offset within string of x offset |
62 |
*/ |
63 |
|
64 |
unsigned long gui_ta_position_x(struct gui_ta *doc, wchar_t *text, unsigned long s, |
65 |
signed long *x) |
66 |
{ |
67 |
struct gui_ta_style *style; |
68 |
unsigned int caret; |
69 |
|
70 |
style = (*doc->style)[s]; |
71 |
|
72 |
return 0; |
73 |
} |
74 |
|
75 |
|
76 |
/* |
77 |
* gui_ta_position_o -- get x offset within string of character offset |
78 |
*/ |
79 |
|
80 |
unsigned long gui_ta_position_o(struct gui_ta *doc, wchar_t *text, unsigned long s, |
81 |
unsigned long offset) |
82 |
{ |
83 |
unsigned int x; |
84 |
struct gui_ta_style *style; |
85 |
|
86 |
style = (*doc->style)[s]; |
87 |
|
88 |
return 0; |
89 |
} |
90 |
|
91 |
|
92 |
/* |
93 |
* gui_ta_caret -- place the wimp caret at the specified position |
94 |
*/ |
95 |
|
96 |
void gui_ta_caret(gui_window_id window_id, struct gui_ta *doc, |
97 |
struct gui_ta_position *pos, unsigned long x, unsigned long y) |
98 |
{ |
99 |
assert(window_id < gui_window_list_items && gui_window_list[window_id].used); |
100 |
|
101 |
#ifdef DEBUG |
102 |
printf("gui_ta_caret: window_id = 0x%x\n", window_id); |
103 |
fflush(stdout); |
104 |
#endif |
105 |
|
106 |
} |
107 |
|
108 |
|
109 |
/* |
110 |
* gui_ta_fill_style -- allocate platform dependent style resources |
111 |
*/ |
112 |
|
113 |
void gui_ta_fill_style(struct gui_ta_style *style) |
114 |
{ |
115 |
char xlfd[200]; |
116 |
|
117 |
/* sprintf(xlfd, "-*-helvetica-regular-r-normal-*-*-%i-*-*-*-*-iso8859-1", style->font, style->xsize / 16 * 10); */ |
118 |
style->handle = gdk_font_load("-urw-nimbus sans l-regular-r-normal--16-154-75-75-p-87-iso8859-1"); |
119 |
} |
120 |
|
121 |
|
122 |
/* |
123 |
* gui_ta_empty_style -- free platform dependent style resources |
124 |
*/ |
125 |
|
126 |
void gui_ta_empty_style(struct gui_ta_style *style) |
127 |
{ |
128 |
gdk_font_unref(style->font); |
129 |
} |