~ubuntu-branches/ubuntu/hardy/uim/hardy

« back to all changes in this revision

Viewing changes to fep/callbacks.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2005-12-04 13:10:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051204131042-ktzc8b17zi7a3cw8
Tags: 1:0.4.9.1-1
* New upstream release
* libuim0-nox, libuim-nox-dev, and libuim0-dbg-nox is now obsolete.
  Because libuim0 does not depends on X11. They now become dummy package,
  therefore you can safely remove them.
* Add --enable-debug in configure again.
* debian/patches/08_fix_privilage_escalation_CVE_2005_3149: disabled.
* Fix Error on purge because update-uim-config is not found.
  (closes: Bug#339345)
* uim-qt: New package for Qt utilities for uim. qt-immodule does not
  contained yet because of Debian's Qt3 does not support immodule and
  because uim does not recognize libqt4-dev's headers properly. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
 
3
  Copyright (c) 2003-2005 uim Project http://uim.freedesktop.org/
4
4
 
5
5
  All rights reserved.
6
6
 
17
17
     may be used to endorse or promote products derived from this software
18
18
     without specific prior written permission.
19
19
 
20
 
  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
20
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
21
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
22
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 
  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
23
  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
24
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
25
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
26
  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34
34
/*
35
35
 * uim�Υ�����Хå��ؿ�
36
36
 */
37
 
#if HAVE_CONFIG_H
 
37
#ifdef HAVE_CONFIG_H
38
38
#include "config.h"
39
39
#endif
40
40
#ifndef DEBUG
41
41
#define NDEBUG
42
42
#endif
43
 
#if HAVE_STDLIB_H
 
43
#ifdef HAVE_STDLIB_H
44
44
#include <stdlib.h>
45
45
#endif
46
 
#if HAVE_STRING_H
 
46
#ifdef HAVE_STRING_H
47
47
#include <string.h>
48
48
#endif
49
 
#if HAVE_ASSERT_H
 
49
#ifdef HAVE_ASSERT_H
50
50
#include <assert.h>
51
51
#endif
 
52
#include <uim/uim-util.h>
52
53
#include "uim-fep.h"
53
54
#include "str.h"
54
55
#include "callbacks.h"
55
56
 
56
57
static uim_context s_context;
57
 
/* TRUE�ʤ饫��������֤�ȿž���ʤ� */
58
 
static int s_cursor_no_reverse;
59
 
/* ���ơ������饤����� */
60
 
static int s_statusline_width;
61
 
 
 
58
/* ���ơ������饤��κ����� */
 
59
static int s_max_width;
62
60
static char *s_commit_str;
63
61
static char *s_statusline_str;
64
62
static char *s_candidate_str;
66
64
static char *s_index_str;
67
65
static struct preedit_tag *s_preedit;
68
66
static int s_mode;
 
67
static char *s_nokori_str;
69
68
 
70
69
static void start_callbacks(void);
71
70
static void end_callbacks(void);
77
76
static void pushback_cb(void *ptr, int attr, const char *str);
78
77
static void update_cb(void *ptr);
79
78
static void mode_update_cb(void *ptr, int mode);
80
 
static void property_update_cb(void *ptr, const char *str);
81
 
static void property_list_update_cb(void *ptr, const char *str);
82
79
static struct preedit_tag *dup_preedit(struct preedit_tag *p);
83
80
static void make_page_strs(void);
84
81
static int numwidth(int n);
122
119
/*
123
120
 * �����
124
121
 */
125
 
void init_callbacks(uim_context context, int status_type, int cursor_no_reverse, int statusline_width)
 
122
void init_callbacks(uim_context context)
126
123
{
127
124
  s_context = context;
128
 
  s_cursor_no_reverse = cursor_no_reverse;
129
 
  s_statusline_width = statusline_width;
 
125
  s_max_width = g_win->ws_col;
 
126
  if (g_opt.statusline_width != UNDEFINED && g_opt.statusline_width <= s_max_width) {
 
127
    s_max_width = g_opt.statusline_width;
 
128
  }
130
129
  s_commit_str = strdup("");
131
130
  s_candidate_str = strdup("");
132
131
  s_statusline_str = strdup("");
136
135
  s_preedit = create_preedit();
137
136
  uim_set_preedit_cb(s_context, clear_cb, pushback_cb, update_cb);
138
137
  uim_set_mode_cb(s_context, mode_update_cb);
139
 
  uim_set_prop_label_update_cb(s_context, property_update_cb);
140
 
  uim_set_prop_list_update_cb(s_context, property_list_update_cb);
141
 
  if (status_type != NONE) {
 
138
  if (g_opt.status_type != NONE) {
142
139
    uim_set_candidate_selector_cb(s_context, activate_cb, select_cb, shift_page_cb, deactivate_cb);
143
140
  }
 
141
 
 
142
  if (g_opt.ddskk) {
 
143
    void *cd;
 
144
    const char *nokori_str = "�Ĥ�";
 
145
    const char *enc;
 
146
 
 
147
    if (uim_iconv->is_convertible(enc = get_enc(), "EUC-JP")) {
 
148
      cd = uim_iconv->create(enc, "EUC-JP");
 
149
      s_nokori_str = uim_iconv->convert(cd, nokori_str);
 
150
      if (cd) {
 
151
        uim_iconv->release(cd);
 
152
      }
 
153
    } else {
 
154
      perror("error in iconv_open");
 
155
      puts("-d option is not available");
 
156
      done(EXIT_FAILURE);
 
157
    }
 
158
  }
144
159
}
145
160
 
146
161
int press_key(int key, int key_state)
147
162
{
148
163
  int raw;
149
 
#if DEBUG > 2
 
164
#if defined DEBUG && DEBUG > 2
150
165
  if (32 <= key && key <= 127) {
151
166
    debug2(("press key = %c key_state = %d\n", key, key_state));
152
167
  } else {
281
296
  return s_mode;
282
297
}
283
298
 
 
299
char *get_mode_str(void)
 
300
{
 
301
  char *mode_str = strdup(uim_get_mode_name(s_context, s_mode));
 
302
  strhead(mode_str, s_max_width);
 
303
  return mode_str;
 
304
}
 
305
 
284
306
/*
285
307
 * ���������ɽ������Ȥ��˸ƤФ�롣
286
308
 * s_candidate.nr = nr(��������)
385
407
  /* ��ʸ�����̵�� */
386
408
  if (width > 0) {
387
409
    /* ����������֤�ʸ����ȿž�����ʤ� */
388
 
    if (s_cursor_no_reverse && cursor && attr & UPreeditAttr_Reverse && s_preedit->cursor != UNDEFINED) {
 
410
    if (g_opt.cursor_no_reverse && cursor && attr & UPreeditAttr_Reverse && s_preedit->cursor != UNDEFINED) {
389
411
      int *rval = width2byte2(str, 1);
390
412
      int first_char_byte = rval[0];
391
413
      int first_char_width = rval[1];
434
456
  s_mode = mode;
435
457
}
436
458
 
437
 
static void property_update_cb(void *ptr, const char *str)
438
 
{
439
 
  debug2(("prop(\"%s\")", str));
440
 
}
441
 
static void property_list_update_cb(void *ptr, const char *str)
442
 
{
443
 
  debug2(("proplist(\"%s\")", str));
444
 
}
445
 
 
446
459
/*
447
460
 * �������ץꥨ�ǥ��åȤ��ꡤ�ݥ��󥿤��֤�
448
461
 */
492
505
 
493
506
/*
494
507
 * s_candidate.page_strs = �ڡ���ʸ���������
495
 
 * ʸ���������max_width��ۤ����Ȥ��ϡ��Ϥ߽Ф�����򼡤Υڡ����˰ܤ���
 
508
 * ʸ���������s_max_width��ۤ����Ȥ��ϡ��Ϥ߽Ф�����򼡤Υڡ����˰ܤ���
496
509
 * 1�Ĥ������䤬�ʤ��ƤϤ߽Ф��Ȥ��ϡ��ܤ��ʤ���
497
 
 * max_width��ü�����������ץ����ǻ��ꤵ�줿��
 
510
 * s_max_width��ü�����������ץ����ǻ��ꤵ�줿��
498
511
 * s_candidate.page2index = �ڡ����κǽ�θ����index
499
512
 * s_candidate.cand_col = ����ΰ���
500
513
 * s_candidate.nr_pages = �ڡ���������
510
523
 
511
524
  int index;
512
525
 
513
 
  int max_width = g_win->ws_col;
514
 
 
515
 
  if (s_statusline_width != UNDEFINED && s_statusline_width <= max_width) {
516
 
    max_width = s_statusline_width;
517
 
  }
518
 
 
519
526
  assert(s_candidate.nr != UNDEFINED);
520
527
  assert(s_candidate.limit != UNDEFINED);
521
528
  assert(s_candidate.cand_col != NULL);
523
530
  s_candidate.nr_pages = 0;
524
531
 
525
532
  for (index = 0; index < s_candidate.nr; index++) {
 
533
    /* A:��  S:��  D:��  F:��  J:��  K:��  L:��  [�Ĥ� 227] */
526
534
    int next = FALSE;
527
535
    /* "[10/20]" ���� */
528
 
    int index_width = 3 + numwidth(index + 1) + numwidth(s_candidate.nr);
529
 
 
 
536
    int index_width;
530
537
    uim_candidate cand = uim_get_candidate(s_context, index, index_in_page);
531
538
    const char *cand_str_label = uim_candidate_get_heading_label(cand);
532
 
    const char *cand_str_cand = uim_candidate_get_cand_str(cand);
 
539
    char *cand_str_cand = tab2space(uim_candidate_get_cand_str(cand));
533
540
    int cand_label_width = strwidth(cand_str_label);
534
 
    int cand_width = cand_label_width + 1 + strwidth(cand_str_cand) + 1;
535
 
    int cand_byte = strlen(cand_str_label) + 1 + strlen(cand_str_cand) + 1;
 
541
    int cand_width = cand_label_width + strlen(":") + strwidth(cand_str_cand) + strlen(" ");
 
542
    int cand_byte = strlen(cand_str_label) + strlen(":") + strlen(cand_str_cand) + strlen(" ");
536
543
    char *cand_str = malloc(cand_byte + 1);
 
544
 
 
545
    if (g_opt.ddskk) {
 
546
      index_width = strlen("[xxxx ]") + numwidth(s_candidate.nr - index - 1);
 
547
    } else {
 
548
      index_width = strlen("[/]") + numwidth(index + 1) + numwidth(s_candidate.nr);
 
549
    }
 
550
 
537
551
    sprintf(cand_str, "%s:%s ", cand_str_label, cand_str_cand);
538
552
    uim_candidate_free(cand);
 
553
    free(cand_str_cand);
539
554
 
540
555
    if (index_in_page == 0) {
541
556
      s_candidate.page2index = realloc(s_candidate.page2index, (s_candidate.nr_pages + 1) * sizeof(int));
543
558
      s_candidate.index_col = realloc(s_candidate.index_col, (s_candidate.nr_pages + 1) * sizeof(int));
544
559
    }
545
560
 
546
 
    if (page_width + cand_width + index_width > max_width && index_in_page != 0) {
 
561
    if (page_width + cand_width + index_width > s_max_width && index_in_page != 0) {
547
562
      /* �Ϥ߽Ф��ΤǼ��Υڡ����˰ܤ� */
548
563
      index--;
549
 
      index_width = 3 + numwidth(index + 1) + numwidth(s_candidate.nr);
 
564
      if (g_opt.ddskk) {
 
565
        index_width = strlen("[xxxx ]") + numwidth(s_candidate.nr - index - 1);
 
566
      } else {
 
567
        index_width = strlen("[/]") + numwidth(index + 1) + numwidth(s_candidate.nr);
 
568
      }
550
569
      next = TRUE;
551
570
    } else {
552
 
      if (cand_width + index_width > max_width && index_in_page == 0) {
 
571
 
 
572
      s_candidate.cand_col[index] = page_width + cand_label_width + strlen(":");
 
573
 
 
574
      if (cand_width + index_width > s_max_width && index_in_page == 0) {
 
575
        /* �Ϥ߽Ф��������˰ܤ��ʤ� */
553
576
        assert(page_width == 0);
554
 
        /* �Ϥ߽Ф��������˰ܤ��ʤ� */      /* ���ڡ���������1 */
555
 
        cand_width = max_width - index_width - 1;
556
 
        cand_width = strhead(cand_str, cand_width);
557
 
        if (cand_label_width > cand_width) {
558
 
          cand_label_width = cand_width;
 
577
        next = TRUE;
 
578
                                                  /* ����1ʸ������ */
 
579
        if (s_max_width >= cand_label_width + strlen(":") + 2 + strlen(" ") + index_width) {
 
580
          /* ���� + ����ǥå��� */
 
581
 
 
582
          cand_width = s_max_width - index_width - strlen(" ");
 
583
          cand_width = strhead(cand_str, cand_width);
 
584
          assert(cand_width > cand_label_width);
 
585
          cand_width += strwidth(" ");
 
586
          cand_byte = strlen(cand_str);
 
587
          cand_str[cand_byte++] = ' ';
 
588
          cand_str[cand_byte] = '\0';
 
589
        } else {
 
590
          /* ����ǥå����Ϥʤ� */
 
591
 
 
592
          index_width = UNDEFINED;
 
593
          if (cand_width > s_max_width) {
 
594
            cand_width = s_max_width;
 
595
          }
 
596
          cand_width -= strlen(" ");
 
597
          cand_width = strhead(cand_str, cand_width);
 
598
          if (cand_width <= cand_label_width + strlen(":")) {
 
599
            cand_width = 1;
 
600
            strcpy(cand_str, " ");
 
601
            s_candidate.cand_col[index] = UNDEFINED;
 
602
          } else {
 
603
            cand_byte = strlen(cand_str);
 
604
            cand_str[cand_byte++] = ' ';
 
605
            cand_str[cand_byte] = '\0';
 
606
          }
559
607
        }
560
 
        cand_width++;
561
 
        cand_byte = strlen(cand_str);
562
 
        cand_str[cand_byte++] = ' ';
563
 
        cand_str[cand_byte] = '\0';
564
 
        next = TRUE;
565
608
      }
566
 
                                                             /* ':' */
567
 
      s_candidate.cand_col[index] = page_width + cand_label_width + 1;
 
609
 
568
610
      page_width += cand_width;
569
611
      page_byte += cand_byte;
570
612
      page_str = realloc(page_str, page_byte + 1);
577
619
    }
578
620
 
579
621
    if (next) {
580
 
      int index_byte = index_width;
581
 
      char *index_str = malloc(index_byte + 1);
582
 
      int i;
583
 
      sprintf(index_str, "[%d/%d]", index + 1, s_candidate.nr);
584
 
      for (i = 0; i < numwidth(index + 1); i++) {
585
 
        index_str[1 + i] = ' ';
586
 
      }
587
 
      index_str[i] = '-';
588
 
      /* ��ۤ�ü�������������ʤ�������Ϥ߽Фʤ� */
589
 
      if (page_width + index_width > max_width) {
590
 
        index_width = max_width - page_width;
591
 
        index_width = strhead(index_str, index_width);
592
 
        index_byte = strlen(index_str);
593
 
      }
594
 
      s_candidate.index_col[s_candidate.nr_pages] = page_width + 1;
595
 
      page_byte += index_byte;
596
 
      page_str = realloc(page_str, page_byte + 1);
597
 
      strcat(page_str, index_str);
598
 
      s_candidate.page_strs = realloc(s_candidate.page_strs, (s_candidate.nr_pages + 1)* sizeof(char *));
 
622
      if (index_width == UNDEFINED) {
 
623
        s_candidate.index_col[s_candidate.nr_pages] = UNDEFINED;
 
624
      } else {
 
625
        int index_byte = index_width + 2/* utf-8 */;
 
626
        char *index_str = malloc(index_byte + 1);
 
627
        int i;
 
628
        if (g_opt.ddskk) {
 
629
          sprintf(index_str, "[%s %d]", s_nokori_str, s_candidate.nr - index - 1);
 
630
        } else {
 
631
          sprintf(index_str, "[%d/%d]", index + 1, s_candidate.nr);
 
632
          for (i = 0; i < numwidth(index + 1); i++) {
 
633
            index_str[1 + i] = ' ';
 
634
          }
 
635
          index_str[i] = '-';
 
636
        }
 
637
        assert(page_width + index_width <= s_max_width);
 
638
        s_candidate.index_col[s_candidate.nr_pages] = page_width + strlen("[");
 
639
        page_byte += index_byte;
 
640
        page_str = realloc(page_str, page_byte + 1);
 
641
        strcat(page_str, index_str);
 
642
        free(index_str);
 
643
      }
 
644
      s_candidate.page_strs = realloc(s_candidate.page_strs, (s_candidate.nr_pages + 1) * sizeof(char *));
599
645
      s_candidate.page_strs[s_candidate.nr_pages] = strdup(page_str);
600
646
      s_candidate.nr_pages++; 
601
647
 
602
648
      page_byte = 0;
603
649
      page_width = 0;
604
650
      index_in_page = 0;
605
 
      free(index_str);
606
651
      free(page_str);
607
652
      page_str = strdup("");
608
653
    }
682
727
  int cand_width;
683
728
  /* "[10/20]"���� */
684
729
  int index_width;
685
 
  int max_width = g_win->ws_col;
686
 
  /* ��ü�θ���Υ���ǥå��� */
687
 
  int right_edge_cand_index = s_candidate.page + 1 == s_candidate.nr_pages ? s_candidate.nr : s_candidate.page2index[s_candidate.page + 1];
688
 
  /* ��ü�θ���Υ���ǥå������� */
689
 
  int right_edge_cand_index_width = numwidth(right_edge_cand_index + 1);
690
 
  /* ���ߤθ���Υ���ǥå������� */
691
 
  int cand_index_width = numwidth(s_candidate.index + 1);
692
 
  int i;
693
 
  s_index_str = malloc(right_edge_cand_index_width + 1);
694
 
  for (i = 0; i < right_edge_cand_index_width - cand_index_width; i++) {
695
 
    s_index_str[i] = ' ';
696
 
  }
697
 
  s_index_str[i] = '\0';
698
 
  sprintf(s_index_str, "%s%d", s_index_str, s_candidate.index + 1);
699
 
 
700
 
  if (s_statusline_width != UNDEFINED && s_statusline_width <= max_width) {
701
 
    max_width = s_statusline_width;
702
 
  }
 
730
 
 
731
  if (s_candidate.index_col[s_candidate.page] == UNDEFINED) {
 
732
    s_index_str = strdup("");
 
733
    index_width = 0;
 
734
  } else {
 
735
    /* ��ü�θ���Υ���ǥå��� */
 
736
    int right_edge_cand_index = s_candidate.page + 1 == s_candidate.nr_pages ? s_candidate.nr - 1 : s_candidate.page2index[s_candidate.page + 1] - 1;
 
737
    /* ��ü�θ���Υ���ǥå������� */
 
738
    int right_edge_cand_index_width = numwidth(right_edge_cand_index + 1);
 
739
    /* ���ߤθ���Υ���ǥå������� */
 
740
    int cand_index_width = numwidth(s_candidate.index + 1);
 
741
    int i;
 
742
    s_index_str = malloc(right_edge_cand_index_width + 1);
 
743
    for (i = 0; i < right_edge_cand_index_width - cand_index_width; i++) {
 
744
      s_index_str[i] = ' ';
 
745
    }
 
746
    s_index_str[i] = '\0';
 
747
    sprintf(s_index_str, "%s%d", s_index_str, s_candidate.index + 1);
 
748
    if (g_opt.ddskk) {
 
749
      index_width = strlen("[xxxx ]") + numwidth(s_candidate.nr - s_candidate.index - 1);
 
750
    } else {
 
751
      index_width = strlen("[/]") + numwidth(s_candidate.index + 1) + numwidth(s_candidate.nr);
 
752
    }
 
753
  }
 
754
 
703
755
 
704
756
  s_candidate_col = s_candidate.cand_col[s_candidate.index];
 
757
  if (s_candidate_col == UNDEFINED) {
 
758
    s_candidate_str = strdup("");
 
759
    return;
 
760
  }
705
761
  cand = uim_get_candidate(s_context, s_candidate.index, 0);
706
762
  if (uim_candidate_get_cand_str(cand) == NULL) {
707
763
    s_candidate_str = strdup("");
709
765
    uim_candidate_free(cand);
710
766
    return;
711
767
  }
712
 
  s_candidate_str = strdup(uim_candidate_get_cand_str(cand));
 
768
  s_candidate_str = tab2space(uim_candidate_get_cand_str(cand));
713
769
  cand_width = strwidth(s_candidate_str);
714
 
  index_width = 3 + numwidth(s_candidate.index + 1) + numwidth(s_candidate.nr);
715
 
  /* ��ۤ�ü�������������ʤ�������Ϥ߽Фʤ� */
716
 
  if (s_candidate_col + cand_width + index_width > max_width) {
717
 
    strhead(s_candidate_str, max_width - s_candidate_col - index_width - 1);
 
770
  if (s_candidate_col + cand_width + strlen(" ") + index_width > s_max_width) {
 
771
    strhead(s_candidate_str, s_max_width - s_candidate_col - strlen(" ") - index_width);
718
772
  }
719
773
  uim_candidate_free(cand);
720
774
}
721
775
 
722
776
void callbacks_winch(void)
723
777
{
 
778
  s_max_width = g_win->ws_col;
 
779
  if (g_opt.statusline_width != UNDEFINED && g_opt.statusline_width <= s_max_width) {
 
780
    s_max_width = g_opt.statusline_width;
 
781
  }
724
782
  if (s_candidate.nr != UNDEFINED) {
725
783
    if (s_candidate.page_strs != NULL) {
726
784
      int i;