/[james]/archive/guilib/textarea_riscos.c
ViewVC logotype

Contents of /archive/guilib/textarea_riscos.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations) (download) (as text)
Mon Feb 10 22:56:40 2003 UTC (21 years, 3 months ago) by james
File MIME type: text/x-csrc
File size: 4750 byte(s)
Initial import.

1 /*
2 * textarea_riscos.c -- text area, RISC OS
3 */
4
5 #include "gui.h"
6 #include "ufont.h"
7
8
9 /*
10 * gui_ta_text_width -- return width of text in specified style
11 */
12
13 unsigned long gui_ta_text_width(struct gui_ta *doc, const wchar_t *text,
14 unsigned long s)
15 {
16 struct gui_ta_style *style;
17 /* font_f font; */
18 int width;
19
20 style = (*doc->style)[s];
21
22 /* gui_error = xfont_find_font(style->font, style->xsize, style->ysize, 0, 0, &font, NULL, NULL); */
23 /* gui_check_error(); */
24 gui_error = xufont_scan_string(style->handle, text, font_GIVEN_FONT | font_KERN, 0x7fffffff, 0x7fffffff,
25 NULL, NULL, 0, NULL, &width, NULL, NULL);
26 gui_check_error();
27 /* gui_error = xfont_lose_font(font); */
28 /* gui_check_error(); */
29
30 return width / 400;
31 }
32
33
34 /*
35 * gui_ta_render_text -- render a word to the window
36 */
37
38 void gui_ta_render_text(struct gui_ta *doc, wchar_t *text, unsigned long s,
39 unsigned long x, unsigned long y, unsigned long box_x0,
40 unsigned long box_y0, unsigned long box_x1, unsigned long box_y1,
41 bool sel)
42 {
43 struct gui_ta_style *style;
44 /* font_f font; */
45 font_paint_block box;
46
47 style = (*doc->style)[s];
48
49 box.space.x = box.space.y = box.letter.x = box.letter.y = 0;
50 box.rubout.x0 = (gui_window_origin_x + box_x0) * 400;
51 box.rubout.y0 = (gui_window_origin_y - box_y1) * 400;
52 box.rubout.x1 = (gui_window_origin_x + box_x1) * 400;
53 box.rubout.y1 = (gui_window_origin_y - box_y0) * 400;
54
55 /* gui_error = xfont_find_font(style->font, style->xsize, style->ysize, 0, 0, &font, NULL, NULL); */
56 /* gui_check_error(); */
57
58 gui_error = xcolourtrans_set_font_colours(font_CURRENT, (sel ? style->fcolour : style->bcolour) << 8,
59 (sel ? style->bcolour : style->fcolour) << 8, 14, NULL, NULL, NULL);
60 gui_check_error();
61
62 gui_error = xufont_paint(style->handle, text, font_RUBOUT | font_GIVEN_BLOCK | font_GIVEN_FONT | font_KERN,
63 (signed int) ((x + gui_window_origin_x) * 400), (signed int) ((gui_window_origin_y - y) * 400), &box, NULL, 0);
64 gui_check_error();
65
66 /* gui_error = xfont_lose_font(font); */
67 /* gui_check_error(); */
68 }
69
70
71 /*
72 * gui_ta_position_x -- get offset within string of x offset
73 */
74
75 unsigned long gui_ta_position_x(struct gui_ta *doc, wchar_t *text, unsigned long s,
76 signed long *x)
77 {
78 struct gui_ta_style *style;
79 /* font_f font; */
80 unsigned int caret;
81
82 style = (*doc->style)[s];
83
84 /* gui_error = xfont_find_font(style->font, style->xsize, style->ysize, 0, 0, &font, NULL, NULL); */
85 /* gui_check_error(); */
86 gui_error = xufont_scan_string(style->handle, text,
87 font_GIVEN_FONT | font_KERN | font_RETURN_CARET_POS,
88 *x * 400, 0x7fffffff, NULL, NULL, 0, &caret, (int *) x, NULL, NULL);
89 gui_check_error();
90 /* gui_error = xfont_lose_font(font); */
91 /* gui_check_error(); */
92
93 *x /= 400;
94 return caret;
95 }
96
97
98 /*
99 * gui_ta_position_o -- get x offset within string of character offset
100 */
101
102 unsigned long gui_ta_position_o(struct gui_ta *doc, wchar_t *text, unsigned long s,
103 unsigned long offset)
104 {
105 unsigned int x;
106 struct gui_ta_style *style;
107 /* font_f font; */
108
109 style = (*doc->style)[s];
110
111 /* gui_error = xfont_find_font(style->font, style->xsize, style->ysize, 0, 0, &font, NULL, NULL); */
112 /* gui_check_error(); */
113 gui_error = xufont_scan_string(style->handle, text, font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN,
114 0x7fffffff, 0x7fffffff, NULL, NULL, (signed int) offset, NULL, &x, NULL, NULL);
115 gui_check_error();
116 /* gui_error = xfont_lose_font(font); */
117 /* gui_check_error(); */
118
119 return x / 400;
120 }
121
122
123 /*
124 * gui_ta_caret -- place the wimp caret at the specified position
125 */
126
127 void gui_ta_caret(gui_window_id window_id, struct gui_ta *doc,
128 struct gui_ta_position *pos, unsigned long x, unsigned long y)
129 {
130 assert(window_id < gui_window_list_items && gui_window_list[window_id].used);
131
132 #ifdef DEBUG
133 printf("gui_ta_caret: window_id = 0x%x\n", window_id);
134 fflush(stdout);
135 #endif
136
137 gui_error = xwimp_set_caret_position(gui_window_list[window_id].handle,
138 wimp_ICON_WINDOW, (signed int) (x + pos->x), -((signed int) (y + pos->y)),
139 (signed int) (*doc->content)[pos->content]->leading, 0);
140 gui_check_error();
141 }
142
143
144 /*
145 * gui_ta_fill_style -- allocate platform dependent style resources
146 */
147
148 void gui_ta_fill_style(struct gui_ta_style *style)
149 {
150 ufont_f font;
151
152 gui_error = xufont_find_font(style->font, (signed int) style->xsize, (signed int) style->ysize, 0, 0, &font, NULL, NULL);
153 gui_check_error();
154
155 style->handle = font;
156 }
157
158
159 /*
160 * gui_ta_empty_style -- free platform dependent style resources
161 */
162
163 void gui_ta_empty_style(struct gui_ta_style *style)
164 {
165 gui_error = xufont_lose_font(style->handle);
166 gui_check_error();
167 }

  ViewVC Help
Powered by ViewVC 1.1.26