annotate console/libgnt/gntutils.c @ 14454:22cb019456bd

[gaim-migrate @ 17168] Use NSIS' built-in language registry key stuff. This fixes the installer forgetting which language you've selected. Fill the installer file versioning information - Unfortunately, there doesn't appear to be a way to manipulate the value to use for the ProductVersion inside the NSIS script, so the Makefile needs to massage the data. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 05 Sep 2006 15:40:24 +0000
parents c374f45f4c94
children ca36763497d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gntutils.h"
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
3 #include <stdlib.h>
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
4 #include <string.h>
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
5
14417
64e28f46c695 [gaim-migrate @ 17125]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14366
diff changeset
6 #include "config.h"
64e28f46c695 [gaim-migrate @ 17125]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14366
diff changeset
7
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8 void gnt_util_get_text_bound(const char *text, int *width, int *height)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 {
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 const char *s = text, *last;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
11 int count = 1, max = 0;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 int len;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
13
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 /* XXX: ew ... everyone look away */
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
15 last = s;
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
16 if (s)
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
17 {
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
18 while (*s)
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
19 {
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
20 if (*s == '\n' || *s == '\r')
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
21 {
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
22 count++;
14420
c4a32405af68 [gaim-migrate @ 17128]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14419
diff changeset
23 len = gnt_util_onscreen_width(last, s);
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
24 if (max < len)
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
25 max = len;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
26 last = s + 1;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
27 }
14420
c4a32405af68 [gaim-migrate @ 17128]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14419
diff changeset
28 s = g_utf8_next_char(s);
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 }
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
30
14420
c4a32405af68 [gaim-migrate @ 17128]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14419
diff changeset
31 len = gnt_util_onscreen_width(last, s);
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
32 if (max < len)
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
33 max = len;
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 }
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36 if (height)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
37 *height = count;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
38 if (width)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
39 *width = max + (count > 1);
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
40 }
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
41
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
42 int gnt_util_onscreen_width(const char *start, const char *end)
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
43 {
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
44 int width = 0;
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
45
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
46 while (start < end) {
14419
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
47 width += g_unichar_iswide(g_utf8_get_char(start)) ? 2 : 1;
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
48 start = g_utf8_next_char(start);
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
49 }
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
50 return width;
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
51 }
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
52
14420
c4a32405af68 [gaim-migrate @ 17128]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14419
diff changeset
53 const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w)
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
54 {
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
55 int size;
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
56 int width = 0;
14420
c4a32405af68 [gaim-migrate @ 17128]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14419
diff changeset
57 const char *str = string;
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
58
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
59 while (width < len && *str) {
14419
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
60 size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1;
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
61 if (width + size > len)
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
62 break;
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
63 str = g_utf8_next_char(str);
b50aa149e09d [gaim-migrate @ 17127]
Ethan Blanton <elb@pidgin.im>
parents: 14418
diff changeset
64 width += size;
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
65 }
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
66 if (w)
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
67 *w = width;
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
68 return str;
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
69 }
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14060
diff changeset
70
14423
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
71 char *gnt_util_onscreen_fit_string(const char *string, int maxw)
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
72 {
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
73 const char *start, *end;
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
74 GString *str;
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
75
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
76 if (maxw <= 0)
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
77 maxw = getmaxx(stdscr) - 4;
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
78
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
79 start = string;
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
80 str = g_string_new(NULL);
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
81
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
82 while (*start) {
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
83 if ((end = strchr(start, '\n')) != NULL ||
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
84 (end = strchr(start, '\r')) != NULL) {
14424
c374f45f4c94 [gaim-migrate @ 17132]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14423
diff changeset
85 if (gnt_util_onscreen_width(start, end) > maxw)
14423
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
86 end = NULL;
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
87 }
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
88 if (end == NULL)
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
89 end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL);
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
90 str = g_string_append_len(str, start, end - start);
14424
c374f45f4c94 [gaim-migrate @ 17132]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14423
diff changeset
91 if (*end) {
c374f45f4c94 [gaim-migrate @ 17132]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14423
diff changeset
92 str = g_string_append_c(str, '\n');
c374f45f4c94 [gaim-migrate @ 17132]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14423
diff changeset
93 if (*end == '\n' || *end == '\r')
c374f45f4c94 [gaim-migrate @ 17132]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14423
diff changeset
94 end++;
c374f45f4c94 [gaim-migrate @ 17132]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14423
diff changeset
95 }
14423
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
96 start = end;
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
97 }
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
98 return g_string_free(str, FALSE);
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
99 }
cfd5bcc06a7e [gaim-migrate @ 17131]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14420
diff changeset
100