~ubuntu-branches/ubuntu/oneiric/irssi/oneiric

« back to all changes in this revision

Viewing changes to src/fe-text/gui-entry.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Bjälevik
  • Date: 2007-04-28 02:52:01 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070428025201-2c4swxnpn4wr7fpg
Tags: 0.8.11-0ubuntu1
* New upstream release:
  - http://www.irssi.org/news/ChangeLog
* debian/{control,compat}:
  - Bump Standards.
* debian/patches/00list:
  - Disable 05upgrade-check-binary.patch, applied upstream.
  - Disable 08doublefree.patch, applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
        return len;
98
98
}
99
99
 
 
100
void unichars_to_big5_with_pos(const unichar *str, int spos, char *out, int *opos)
 
101
{
 
102
        const unichar *sstart = str;
 
103
        char *ostart = out;
 
104
 
 
105
        *opos = 0;
 
106
        while(*str != '\0')
 
107
        {
 
108
                if(*str > 0xff)
 
109
                        *out ++ = (*str >> 8) & 0xff;
 
110
                *out ++ = *str & 0xff;
 
111
                str ++;
 
112
                if(str - sstart == spos)
 
113
                        *opos = out - ostart;
 
114
        }
 
115
        *out = '\0';
 
116
}
 
117
 
100
118
void big5_to_unichars(const char *str, unichar *out)
101
119
{
102
120
        const unsigned char *p = (const unsigned char *) str;
214
232
 
215
233
                if (entry->hidden)
216
234
                        term_addch(root_window, ' ');
217
 
                else if (*p >= 32 && (entry->utf8 || (*p & 127) >= 32))
 
235
                else if (*p >= 32 && (*p < 0x7F || *p > 0x9F))
218
236
                        term_add_unichar(root_window, *p);
219
237
                else {
220
238
                        term_set_color(root_window, ATTR_RESET|ATTR_REVERSE);
221
 
                        term_addch(root_window, *p+'A'-1);
 
239
                        term_addch(root_window, (*p & 127)+'A'-1);
222
240
                        term_set_color(root_window, ATTR_RESET);
223
241
                }
224
242
        }
225
243
 
226
244
        /* clear the rest of the input line */
227
 
        if (end_xpos == term_width)
228
 
                term_clrtoeol(root_window);
229
 
        else {
230
 
                while (xpos < end_xpos) {
231
 
                        term_addch(root_window, ' ');
232
 
                        xpos++;
 
245
        if (xpos < end_xpos) {
 
246
                if (end_xpos == term_width)
 
247
                        term_clrtoeol(root_window);
 
248
                else {
 
249
                        while (xpos < end_xpos) {
 
250
                                term_addch(root_window, ' ');
 
251
                                xpos++;
 
252
                        }
233
253
                }
234
254
        }
235
255
}
371
391
        return buf;
372
392
}
373
393
 
 
394
char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos)
 
395
{
 
396
        char *buf;
 
397
        int i;
 
398
 
 
399
        g_return_val_if_fail(entry != NULL, NULL);
 
400
 
 
401
        buf = g_malloc(entry->text_len*6 + 1);
 
402
        if (entry->utf8)
 
403
                utf16_to_utf8_with_pos(entry->text, entry->pos, buf, pos);
 
404
        else {
 
405
                if(term_type==TERM_TYPE_BIG5)
 
406
                        unichars_to_big5_with_pos(entry->text, entry->pos, buf, pos);
 
407
                else
 
408
                {
 
409
                        for (i = 0; i <= entry->text_len; i++)
 
410
                                buf[i] = entry->text[i];
 
411
                        *pos = entry->pos;
 
412
                }
 
413
        }
 
414
        return buf;
 
415
}
 
416
 
374
417
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str)
375
418
{
376
419
        unichar chr;
466
509
        gui_entry_erase(entry, size, update_cutbuffer);
467
510
}
468
511
 
 
512
static size_t cell_width(unichar *buf, int len)
 
513
{
 
514
        unichar *str = buf;
 
515
 
 
516
        while (len-- && utf8_width(*str--) == 0);
 
517
        return buf - str;
 
518
}
 
519
 
469
520
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
470
521
{
 
522
        size_t w = 0;
 
523
 
471
524
        g_return_if_fail(entry != NULL);
472
525
 
473
526
        if (entry->pos < size)
491
544
                return;
492
545
        }
493
546
 
 
547
        if (entry->utf8)
 
548
                w = cell_width(entry->text + entry->pos - size, entry->pos - size + 1)-1;
 
549
 
494
550
        g_memmove(entry->text + entry->pos - size, entry->text + entry->pos,
495
551
                  (entry->text_len-entry->pos+1) * sizeof(unichar));
496
552
 
497
553
        entry->pos -= size;
498
554
        entry->text_len -= size;
499
555
 
500
 
        gui_entry_redraw_from(entry, entry->pos);
 
556
        gui_entry_redraw_from(entry, entry->pos-w);
501
557
        gui_entry_fix_cursor(entry);
502
558
        gui_entry_draw(entry);
503
559
}