~ampelbein/+junk/fix-1201213

« back to all changes in this revision

Viewing changes to src/screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-10-08 19:37:25 UTC
  • mto: (3.1.3 squeeze) (1.1.7 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20091008193725-m04qzt6mv82hb7ho
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
# include <langinfo.h>
42
42
#endif
43
43
 
44
 
#ifdef HAVE_ASPELL_H
 
44
#ifdef WITH_ENCHANT
 
45
# include <enchant.h>
 
46
#endif
 
47
 
 
48
#ifdef WITH_ASPELL
45
49
# include <aspell.h>
46
50
#endif
47
51
 
73
77
static void scr_insert_text(const char*);
74
78
static void scr_handle_tab(void);
75
79
 
76
 
#ifdef HAVE_ASPELL_H
 
80
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
77
81
static void spellcheck(char *, char *);
78
82
#endif
79
83
 
120
124
static time_t LastActivity;
121
125
 
122
126
static char       inputLine[INPUTLINE_LENGTH+1];
123
 
#ifdef HAVE_ASPELL_H
 
127
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
124
128
static char       maskLine[INPUTLINE_LENGTH+1];
125
129
#endif
126
130
static char      *ptr_inputline;
155
159
                       unsigned int prefix_flags, int force_show,
156
160
                       unsigned mucnicklen);
157
161
 
 
162
inline void scr_WriteMessage(const char *bjid, const char *text,
 
163
                             time_t timestamp, guint prefix_flags,
 
164
                             unsigned mucnicklen);
158
165
inline void scr_UpdateBuddyWindow(void);
159
166
inline void scr_set_chatmode(int enable);
160
167
 
161
 
#ifdef HAVE_ASPELL_H
162
 
#define ASPELLBADCHAR 5
 
168
#define SPELLBADCHAR 5
 
169
 
 
170
#ifdef WITH_ENCHANT
 
171
EnchantBroker *spell_broker;
 
172
EnchantDict *spell_checker;
 
173
#endif
 
174
 
 
175
#ifdef WITH_ASPELL
163
176
AspellConfig *spell_config;
164
177
AspellSpeller *spell_checker;
165
178
#endif
730
743
  intrflush(stdscr, FALSE);
731
744
  start_color();
732
745
  use_default_colors();
 
746
#ifdef NCURSES_MOUSE_VERSION
 
747
  if (settings_opt_get_int("use_mouse"))
 
748
    mousemask(ALL_MOUSE_EVENTS, NULL);
 
749
#endif
733
750
 
734
751
  if (settings_opt_get("escdelay")) {
735
752
#ifdef HAVE_ESCDELAY
1952
1969
        foreach_group_member(BUDDATA(buddy), increment_if_buddy_not_filtered,
1953
1970
                             &group_count);
1954
1971
        snprintf(rline, 4*Roster_Width, " %c+++ %s (%i)", pending, name,
1955
 
               group_count);
 
1972
                 group_count);
 
1973
        /* Do not display the item count if there isn't enough space */
 
1974
        if (g_utf8_strlen(rline, 4*Roster_Width) >= Roster_Width)
 
1975
          snprintf(rline, 4*Roster_Width, " %c--- %s", pending, name);
1956
1976
      }
1957
1977
      else
1958
1978
        snprintf(rline, 4*Roster_Width, " %c--- %s", pending, name);
2028
2048
}
2029
2049
#endif
2030
2050
 
2031
 
inline void scr_WriteMessage(const char *bjid, const char *text,
2032
 
                             time_t timestamp, guint prefix_flags,
2033
 
                             unsigned mucnicklen)
 
2051
void scr_WriteMessage(const char *bjid, const char *text,
 
2052
                      time_t timestamp, guint prefix_flags,
 
2053
                      unsigned mucnicklen)
2034
2054
{
2035
2055
  char *xtext;
2036
2056
 
2153
2173
}
2154
2174
 
2155
2175
#if defined JEP0022 || defined JEP0085
2156
 
inline long int scr_GetChatStatesTimeout(time_t now)
 
2176
long int scr_GetChatStatesTimeout(time_t now)
2157
2177
{
2158
2178
  // Check if we're currently composing...
2159
2179
  if (chatstate != 1 || !chatstate_timestamp)
2246
2266
    scr_ShowBuddyWindow();
2247
2267
}
2248
2268
 
2249
 
//  scr_RosterUp()
2250
 
// Go to the previous buddy in the buddylist
2251
 
void scr_RosterUp(void)
 
2269
//  scr_RosterUpDown(updown, n)
 
2270
// Go to the nth next buddy in the buddylist
 
2271
// (up if updown == -1, down if updown == 1)
 
2272
void scr_RosterUpDown(int updown, unsigned int n)
2252
2273
{
2253
 
  set_current_buddy(g_list_previous(current_buddy));
2254
 
  if (chatmode)
2255
 
    scr_ShowBuddyWindow();
2256
 
}
 
2274
  unsigned int i;
2257
2275
 
2258
 
//  scr_RosterDown()
2259
 
// Go to the next buddy in the buddylist
2260
 
void scr_RosterDown(void)
2261
 
{
2262
 
  set_current_buddy(g_list_next(current_buddy));
 
2276
  if (updown < 0) {
 
2277
    for (i = 0; i < n; i++)
 
2278
      set_current_buddy(g_list_previous(current_buddy));
 
2279
  } else {
 
2280
    for (i = 0; i < n; i++)
 
2281
      set_current_buddy(g_list_next(current_buddy));
 
2282
  }
2263
2283
  if (chatmode)
2264
2284
    scr_ShowBuddyWindow();
2265
2285
}
2932
2952
 
2933
2953
//  scr_cmdhisto_addline()
2934
2954
// Add a line to the inputLine history
2935
 
inline void scr_cmdhisto_addline(char *line)
 
2955
static inline void scr_cmdhisto_addline(char *line)
2936
2956
{
2937
2957
  int max_histo_lines;
2938
2958
 
3570
3590
  inputline_offset = c - inputLine;
3571
3591
}
3572
3592
 
3573
 
#ifdef HAVE_ASPELL_H
 
3593
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
3574
3594
// prints inputLine with underlined words when misspelled
3575
3595
static inline void print_checked_line(void)
3576
3596
{
3577
3597
  char *wprint_char_fmt = "%c";
3578
3598
  int point;
 
3599
  int nrchar = maxX;
3579
3600
  char *ptrCur = inputLine + inputline_offset;
3580
3601
 
3581
3602
#ifdef UNICODE
3586
3607
 
3587
3608
  wmove(inputWnd, 0, 0); // problem with backspace
3588
3609
 
3589
 
  while (*ptrCur) {
 
3610
  while (*ptrCur && nrchar-- > 0) {
3590
3611
    point = ptrCur - inputLine;
3591
3612
    if (maskLine[point])
3592
3613
      wattrset(inputWnd, A_UNDERLINE);
3599
3620
 
3600
3621
static inline void refresh_inputline(void)
3601
3622
{
3602
 
#ifdef HAVE_ASPELL_H
3603
 
  if (settings_opt_get_int("aspell_enable")) {
 
3623
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
 
3624
  if (settings_opt_get_int("spell_enable")) {
3604
3625
    memset(maskLine, 0, INPUTLINE_LENGTH+1);
3605
3626
    spellcheck(inputLine, maskLine);
3606
3627
  }
3734
3755
  kcode->value = wgetch(inputWnd);
3735
3756
  if (utf8_mode) {
3736
3757
    bool ismeta = (kcode->value == 27);
 
3758
#ifdef NCURSES_MOUSE_VERSION
 
3759
    bool ismouse = (kcode->value == KEY_MOUSE);
3737
3760
 
 
3761
    if (ismouse) {
 
3762
      MEVENT mouse;
 
3763
      getmouse(&mouse);
 
3764
      kcode->value = mouse.bstate;
 
3765
      kcode->mcode = MKEY_MOUSE;
 
3766
      return;
 
3767
    } else if (ismeta)
 
3768
#else
3738
3769
    if (ismeta)
 
3770
#endif
3739
3771
      ks[0] = wgetch(inputWnd);
3740
3772
    else
3741
3773
      ks[0] = kcode->value;
3815
3847
    g_snprintf(asciikey, 15, "%s", asciicode);
3816
3848
  else if (kcode.mcode == MKEY_META)
3817
3849
    g_snprintf(asciikey, 15, "M%s", asciicode);
 
3850
  else if (kcode.mcode == MKEY_MOUSE)
 
3851
    g_snprintf(asciikey, 15, "p%s", asciicode);
3818
3852
  else
3819
3853
    g_snprintf(asciikey, 15, "MK%d", kcode.mcode);
3820
3854
 
3953
3987
  return;
3954
3988
}
3955
3989
 
3956
 
#ifdef HAVE_ASPELL_H
3957
 
// Aspell initialization
 
3990
#if defined(WITH_ENCHANT) || defined(WITH_ASPELL)
 
3991
// initialization
3958
3992
void spellcheck_init(void)
3959
3993
{
3960
 
  int aspell_enable           = settings_opt_get_int("aspell_enable");
3961
 
  const char *aspell_lang     = settings_opt_get("aspell_lang");
3962
 
  const char *aspell_encoding = settings_opt_get("aspell_encoding");
 
3994
  int spell_enable            = settings_opt_get_int("spell_enable");
 
3995
  const char *spell_lang     = settings_opt_get("spell_lang");
 
3996
#ifdef WITH_ASPELL
 
3997
  const char *spell_encoding = settings_opt_get("spell_encoding");
3963
3998
  AspellCanHaveError *possible_err;
 
3999
#endif
3964
4000
 
3965
 
  if (!aspell_enable)
 
4001
  if (!spell_enable)
3966
4002
    return;
3967
4003
 
 
4004
#ifdef WITH_ENCHANT
 
4005
  if (spell_checker) {
 
4006
     enchant_broker_free_dict(spell_broker, spell_checker);
 
4007
     enchant_broker_free(spell_broker);
 
4008
     spell_checker = NULL;
 
4009
     spell_broker = NULL;
 
4010
  }
 
4011
 
 
4012
  spell_broker = enchant_broker_init();
 
4013
  spell_checker = enchant_broker_request_dict(spell_broker, spell_lang);
 
4014
#endif
 
4015
#ifdef WITH_ASPELL
3968
4016
  if (spell_checker) {
3969
4017
    delete_aspell_speller(spell_checker);
3970
4018
    delete_aspell_config(spell_config);
3973
4021
  }
3974
4022
 
3975
4023
  spell_config = new_aspell_config();
3976
 
  aspell_config_replace(spell_config, "encoding", aspell_encoding);
3977
 
  aspell_config_replace(spell_config, "lang", aspell_lang);
 
4024
  aspell_config_replace(spell_config, "encoding", spell_encoding);
 
4025
  aspell_config_replace(spell_config, "lang", spell_lang);
3978
4026
  possible_err = new_aspell_speller(spell_config);
3979
4027
 
3980
4028
  if (aspell_error_number(possible_err) != 0) {
3984
4032
  } else {
3985
4033
    spell_checker = to_aspell_speller(possible_err);
3986
4034
  }
 
4035
#endif
3987
4036
}
3988
4037
 
3989
 
// Deinitialization of Aspell spellchecker
 
4038
// Deinitialization of spellchecker
3990
4039
void spellcheck_deinit(void)
3991
4040
{
3992
4041
  if (spell_checker) {
 
4042
#ifdef WITH_ENCHANT
 
4043
    enchant_broker_free_dict(spell_broker, spell_checker);
 
4044
#endif
 
4045
#ifdef WITH_ASPELL
3993
4046
    delete_aspell_speller(spell_checker);
 
4047
#endif
3994
4048
    spell_checker = NULL;
3995
4049
  }
3996
4050
 
 
4051
#ifdef WITH_ENCHANT
 
4052
  if (spell_broker) {
 
4053
    enchant_broker_free(spell_broker);
 
4054
    spell_broker = NULL;
 
4055
  }
 
4056
#endif
 
4057
#ifdef WITH_ASPELL
3997
4058
  if (spell_config) {
3998
4059
    delete_aspell_config(spell_config);
3999
4060
    spell_config = NULL;
4000
4061
  }
 
4062
#endif
4001
4063
}
4002
4064
 
4003
 
#define aspell_isalpha(c) (utf8_mode ? iswalpha(get_char(c)) : isalpha(*c))
 
4065
#define spell_isalpha(c) (utf8_mode ? iswalpha(get_char(c)) : isalpha(*c))
4004
4066
 
4005
4067
// Spell checking function
4006
4068
static void spellcheck(char *line, char *checked)
4014
4076
 
4015
4077
  while (*line) {
4016
4078
 
4017
 
    if (!aspell_isalpha(line)) {
 
4079
    if (!spell_isalpha(line)) {
4018
4080
      line = next_char(line);
4019
4081
      continue;
4020
4082
    }
4039
4101
 
4040
4102
    start = line;
4041
4103
 
4042
 
    while (aspell_isalpha(line))
 
4104
    while (spell_isalpha(line))
4043
4105
      line = next_char(line);
4044
4106
 
4045
4107
    if (spell_checker &&
4046
 
        aspell_speller_check(spell_checker, start, line - start) == 0)
4047
 
      memset(&checked[start - line_start], ASPELLBADCHAR, line - start);
 
4108
#ifdef WITH_ENCHANT
 
4109
        enchant_dict_check(spell_checker, start, line - start) != 0
 
4110
#endif
 
4111
#ifdef WITH_ASPELL
 
4112
        aspell_speller_check(spell_checker, start, line - start) == 0
 
4113
#endif
 
4114
    )
 
4115
      memset(&checked[start - line_start], SPELLBADCHAR, line - start);
4048
4116
  }
4049
4117
}
4050
4118
#endif