1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
/*
* Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WEECHAT_GUI_H
#define __WEECHAT_GUI_H 1
#include "../common/completion.h"
#include "../common/history.h"
#define INPUT_BUFFER_BLOCK_SIZE 256
/* shift ncurses colors for compatibility with colors
in IRC messages (same as other IRC clients) */
#define WEECHAT_COLOR_BLACK COLOR_BLACK
#define WEECHAT_COLOR_RED COLOR_BLUE
#define WEECHAT_COLOR_GREEN COLOR_GREEN
#define WEECHAT_COLOR_YELLOW COLOR_CYAN
#define WEECHAT_COLOR_BLUE COLOR_RED
#define WEECHAT_COLOR_MAGENTA COLOR_MAGENTA
#define WEECHAT_COLOR_CYAN COLOR_YELLOW
#define WEECHAT_COLOR_WHITE COLOR_WHITE
#define COLOR_WIN_NICK_NUMBER 10
typedef enum t_weechat_color t_weechat_color;
enum t_weechat_color
{
COLOR_WIN_TITLE = 0,
COLOR_WIN_CHAT,
COLOR_WIN_CHAT_TIME,
COLOR_WIN_CHAT_TIME_SEP,
COLOR_WIN_CHAT_PREFIX1,
COLOR_WIN_CHAT_PREFIX2,
COLOR_WIN_CHAT_SERVER,
COLOR_WIN_CHAT_JOIN,
COLOR_WIN_CHAT_PART,
COLOR_WIN_CHAT_NICK,
COLOR_WIN_CHAT_HOST,
COLOR_WIN_CHAT_CHANNEL,
COLOR_WIN_CHAT_DARK,
COLOR_WIN_CHAT_HIGHLIGHT,
COLOR_WIN_STATUS,
COLOR_WIN_STATUS_DELIMITERS,
COLOR_WIN_STATUS_CHANNEL,
COLOR_WIN_STATUS_DATA_MSG,
COLOR_WIN_STATUS_DATA_PRIVATE,
COLOR_WIN_STATUS_DATA_HIGHLIGHT,
COLOR_WIN_STATUS_DATA_OTHER,
COLOR_WIN_STATUS_MORE,
COLOR_WIN_INFOBAR,
COLOR_WIN_INFOBAR_DELIMITERS,
COLOR_WIN_INFOBAR_HIGHLIGHT,
COLOR_WIN_INPUT,
COLOR_WIN_INPUT_CHANNEL,
COLOR_WIN_INPUT_NICK,
COLOR_WIN_INPUT_DELIMITERS,
COLOR_WIN_NICK,
COLOR_WIN_NICK_AWAY,
COLOR_WIN_NICK_CHANOWNER,
COLOR_WIN_NICK_CHANADMIN,
COLOR_WIN_NICK_OP,
COLOR_WIN_NICK_HALFOP,
COLOR_WIN_NICK_VOICE,
COLOR_WIN_NICK_MORE,
COLOR_WIN_NICK_SEP,
COLOR_WIN_NICK_SELF,
COLOR_WIN_NICK_PRIVATE,
COLOR_WIN_NICK_1,
COLOR_WIN_NICK_2,
COLOR_WIN_NICK_3,
COLOR_WIN_NICK_4,
COLOR_WIN_NICK_5,
COLOR_WIN_NICK_6,
COLOR_WIN_NICK_7,
COLOR_WIN_NICK_8,
COLOR_WIN_NICK_9,
COLOR_WIN_NICK_10,
COLOR_DCC_SELECTED,
COLOR_DCC_WAITING,
COLOR_DCC_CONNECTING,
COLOR_DCC_ACTIVE,
COLOR_DCC_DONE,
COLOR_DCC_FAILED,
COLOR_DCC_ABORTED,
NUM_COLORS
};
/* attributes in IRC messages for color & style (bold, ..) */
#define GUI_ATTR_BOLD_CHAR '\x02'
#define GUI_ATTR_BOLD_STR "\x02"
#define GUI_ATTR_COLOR_CHAR '\x03'
#define GUI_ATTR_COLOR_STR "\x03"
#define GUI_ATTR_RESET_CHAR '\x0F'
#define GUI_ATTR_RESET_STR "\x0F"
#define GUI_ATTR_FIXED_CHAR '\x11'
#define GUI_ATTR_FIXED_STR "\x11"
#define GUI_ATTR_REVERSE_CHAR '\x12'
#define GUI_ATTR_REVERSE_STR "\x12"
#define GUI_ATTR_REVERSE2_CHAR '\x16'
#define GUI_ATTR_REVERSE2_STR "\x16"
#define GUI_ATTR_ITALIC_CHAR '\x1D'
#define GUI_ATTR_ITALIC_STR "\x1D"
#define GUI_ATTR_UNDERLINE_CHAR '\x1F'
#define GUI_ATTR_UNDERLINE_STR "\x1F"
/* WeeChat internal attributes (should never be in IRC messages) */
#define GUI_ATTR_WEECHAT_COLOR_CHAR '\x19'
#define GUI_ATTR_WEECHAT_COLOR_STR "\x19"
#define GUI_ATTR_WEECHAT_SET_CHAR '\x1A'
#define GUI_ATTR_WEECHAT_SET_STR "\x1A"
#define GUI_ATTR_WEECHAT_REMOVE_CHAR '\x1B'
#define GUI_ATTR_WEECHAT_REMOVE_STR "\x1B"
#define GUI_COLOR(color) ((gui_color[color]) ? gui_color[color]->string : "")
#define GUI_NO_COLOR GUI_ATTR_RESET_STR
#define SERVER(buffer) ((t_irc_server *)(buffer->server))
#define CHANNEL(buffer) ((t_irc_channel *)(buffer->channel))
#define BUFFER_IS_SERVER(buffer) ((SERVER(buffer) || (buffer->all_servers)) && !CHANNEL(buffer))
#define BUFFER_IS_CHANNEL(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHAT_CHANNEL))
#define BUFFER_IS_PRIVATE(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHAT_PRIVATE))
#define BUFFER_HAS_NICKLIST(buffer) (BUFFER_IS_CHANNEL(buffer))
#define MSG_TYPE_TIME 1
#define MSG_TYPE_PREFIX 2
#define MSG_TYPE_NICK 4
#define MSG_TYPE_INFO 8
#define MSG_TYPE_MSG 16
#define MSG_TYPE_HIGHLIGHT 32
#define MSG_TYPE_NOLOG 64
#define gui_printf(buffer, fmt, argz...) \
gui_printf_internal(buffer, 1, MSG_TYPE_INFO, fmt, ##argz)
#define gui_printf_type(buffer, type, fmt, argz...) \
gui_printf_internal(buffer, 1, type, fmt, ##argz)
#define gui_printf_nolog(buffer, fmt, argz...) \
gui_printf_internal(buffer, 1, MSG_TYPE_INFO | MSG_TYPE_NOLOG, fmt, ##argz)
#define gui_printf_nolog_notime(buffer, fmt, argz...) \
gui_printf_internal(buffer, 0, MSG_TYPE_NOLOG, fmt, ##argz)
#define NOTIFY_LEVEL_MIN 0
#define NOTIFY_LEVEL_MAX 3
#define NOTIFY_LEVEL_DEFAULT NOTIFY_LEVEL_MAX
#define KEY_SHOW_MODE_DISPLAY 1
#define KEY_SHOW_MODE_BIND 2
typedef struct t_gui_color t_gui_color;
struct t_gui_color
{
int foreground; /* foreground color */
int background; /* background color */
int attributes; /* attributes (bold, ..) */
char *string; /* WeeChat color: "\x19??", ?? is #color*/
};
typedef struct t_gui_infobar t_gui_infobar;
struct t_gui_infobar
{
int color; /* text color */
char *text; /* infobar text */
int remaining_time; /* delay (sec) before erasing this text */
/* if < 0, text is never erased (except */
/* by user action to erase it) */
t_gui_infobar *next_infobar; /* next message for infobar */
};
typedef struct t_gui_line t_gui_line;
struct t_gui_line
{
int length; /* length of the line (in char) */
int length_align; /* alignment length (time or time/nick) */
int log_write; /* = 1 if line will be written to log */
int line_with_message; /* line contains a message from a user? */
int line_with_highlight; /* line contains highlight */
char *data; /* line content */
int ofs_after_date; /* offset to first char after date */
t_gui_line *prev_line; /* link to previous line */
t_gui_line *next_line; /* link to next line */
};
typedef struct t_gui_buffer t_gui_buffer;
struct t_gui_buffer
{
int num_displayed; /* number of windows displaying buffer */
int number; /* buffer number (for jump/switch) */
/* server/channel */
void *server; /* buffer's server */
int all_servers; /* =1 if all servers are displayed here */
void *channel; /* buffer's channel */
int dcc; /* buffer is dcc status */
/* chat content (lines, line is composed by many messages) */
t_gui_line *lines; /* lines of chat window */
t_gui_line *last_line; /* last line of chat window */
int num_lines; /* number of lines in the window */
int line_complete; /* current line complete ? (\n ending) */
/* notify level: when activity should be displayed? default: 3 (always) */
int notify_level; /* 0 = never */
/* 1 = highlight only */
/* 2 = highlight + message */
/* 3 = highlight + message + join/part */
/* file to save buffer content */
char *log_filename; /* filename for saving buffer content */
FILE *log_file; /* for logging buffer to file */
/* inupt buffer */
int has_input; /* = 1 if buffer has input (DCC has not)*/
char *input_buffer; /* input buffer */
int input_buffer_alloc; /* input buffer: allocated size in mem */
int input_buffer_size; /* buffer size in bytes */
int input_buffer_length; /* number of chars in buffer */
int input_buffer_pos; /* position into buffer */
int input_buffer_1st_display; /* first char displayed on screen */
/* completion */
t_completion completion; /* for cmds/nicks completion */
/* history */
t_history *history; /* commands history */
t_history *last_history; /* last command in history */
t_history *ptr_history; /* current command in history */
int num_history; /* number of commands in history */
/* link to previous/next buffer */
t_gui_buffer *prev_buffer; /* link to previous buffer */
t_gui_buffer *next_buffer; /* link to next buffer */
};
typedef struct t_gui_window t_gui_window;
struct t_gui_window
{
/* global position & size */
int win_x, win_y; /* position of window */
int win_width, win_height; /* window geometry */
/* chat window settings */
int win_chat_x, win_chat_y; /* chat window position */
int win_chat_width; /* width of chat window */
int win_chat_height; /* height of chat window */
int win_chat_cursor_x; /* position of cursor in chat window */
int win_chat_cursor_y; /* position of cursor in chat window */
/* nicklist window settings */
int win_nick_x, win_nick_y; /* nick window position */
int win_nick_width; /* width of nick window */
int win_nick_height; /* height of nick window */
int win_nick_start; /* # of 1st nick for display (scroll) */
/* input window settings */
int win_input_x; /* position of cursor in input window */
/* windows for Curses GUI */
void *win_title; /* title window */
void *win_chat; /* chat window (example: channel) */
void *win_nick; /* nick window */
void *win_status; /* status window */
void *win_infobar; /* info bar window */
void *win_input; /* input window */
void *win_separator; /* separation between 2 splited (V) win */
/* windows for Gtk GUI */
void *textview_chat; /* textview widget for chat */
void *textbuffer_chat; /* textbuffer widget for chat */
void *texttag_chat; /* texttag widget for chat */
void *textview_nicklist; /* textview widget for nicklist */
void *textbuffer_nicklist; /* textbuffer widget for nicklist */
/* windows for Qt GUI */
/* TODO: declare Qt window */
int current_style_fg;; /* current color used for foreground */
int current_style_bg;; /* current color used for background */
int current_style_attr; /* current attributes (bold, ..) */
int current_color_attr; /* attr sum of last color(s) displayed */
/* DCC */
void *dcc_first; /* first dcc displayed */
void *dcc_selected; /* selected dcc */
void *dcc_last_displayed; /* last dcc displayed (for scroll) */
t_gui_buffer *buffer; /* buffer currently displayed in window */
int first_line_displayed; /* = 1 if first line is displayed */
t_gui_line *start_line; /* pointer to line if scrolling */
int start_line_pos; /* position in first line displayed */
t_gui_window *prev_window; /* link to previous window */
t_gui_window *next_window; /* link to next window */
};
typedef struct t_gui_key t_gui_key;
struct t_gui_key
{
char *key; /* key combo (ex: a, ^W, ^W^C, meta-a) */
char *command; /* associated command (may be NULL) */
void (*function)(t_gui_window *);
/* associated function (if cmd is NULL) */
t_gui_key *prev_key; /* link to previous key */
t_gui_key *next_key; /* link to next key */
};
typedef struct t_gui_key_function t_gui_key_function;
struct t_gui_key_function
{
char *function_name; /* name of function */
void (*function)(); /* associated function */
char *description; /* description of function */
};
/* variables */
extern int gui_init_ok;
extern int gui_ok;
extern int gui_add_hotlist;
extern t_gui_window *gui_windows;
extern t_gui_window *last_gui_window;
extern t_gui_window *gui_current_window;
extern t_gui_buffer *gui_buffers;
extern t_gui_buffer *last_gui_buffer;
extern t_gui_buffer *buffer_before_dcc;
extern t_gui_infobar *gui_infobar;
extern t_gui_key *gui_keys;
extern t_gui_key *last_gui_key;
extern t_gui_key_function gui_key_functions[];
extern char gui_key_buffer[128];
extern int gui_key_grab;
extern int gui_key_grab_count;
extern char *gui_input_clipboard;
extern t_gui_color *gui_color[NUM_COLORS];
/* GUI independent functions: windows & buffers */
extern t_gui_window *gui_window_new (int, int, int, int);
extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int);
extern void gui_buffer_clear (t_gui_buffer *);
extern void gui_buffer_clear_all ();
extern void gui_infobar_printf (int, int, char *, ...);
extern void gui_window_free (t_gui_window *);
extern void gui_infobar_remove ();
extern void gui_buffer_free (t_gui_buffer *, int);
extern t_gui_line *gui_new_line (t_gui_buffer *);
extern int gui_word_strlen (t_gui_window *, char *);
extern int gui_word_real_pos (t_gui_window *, char *, int);
extern void gui_printf_internal (t_gui_buffer *, int, int, char *, ...);
extern void gui_optimize_input_buffer_size (t_gui_buffer *);
extern void gui_exec_action_dcc (t_gui_window *, char *);
extern int gui_insert_string_input (t_gui_window *, char *, int);
extern void gui_merge_servers (t_gui_window *);
extern void gui_split_server (t_gui_window *);
extern void gui_window_switch_server (t_gui_window *);
extern void gui_switch_to_previous_buffer (t_gui_window *);
extern void gui_switch_to_next_buffer (t_gui_window *);
extern void gui_switch_to_previous_window (t_gui_window *);
extern void gui_switch_to_next_window (t_gui_window *);
extern void gui_switch_to_window_by_buffer (t_gui_window *, int);
extern void gui_switch_to_dcc_buffer (t_gui_window *);
extern t_gui_buffer *gui_switch_to_buffer_by_number (t_gui_window *, int);
extern void gui_move_buffer_to_number (t_gui_window *, int);
extern void gui_window_print_log (t_gui_window *);
extern void gui_buffer_print_log (t_gui_buffer *);
/* GUI independent functions: actions */
extern void gui_action_clipboard_copy (char *, int);
extern void gui_action_clipboard_paste (t_gui_window *);
extern void gui_action_return (t_gui_window *);
extern void gui_action_tab (t_gui_window *);
extern void gui_action_backspace (t_gui_window *);
extern void gui_action_delete (t_gui_window *);
extern void gui_action_delete_previous_word (t_gui_window *);
extern void gui_action_delete_next_word (t_gui_window *);
extern void gui_action_delete_begin_of_line (t_gui_window *);
extern void gui_action_delete_end_of_line (t_gui_window *);
extern void gui_action_delete_line (t_gui_window *);
extern void gui_action_transpose_chars (t_gui_window *);
extern void gui_action_home (t_gui_window *);
extern void gui_action_end (t_gui_window *);
extern void gui_action_left (t_gui_window *);
extern void gui_action_previous_word (t_gui_window *);
extern void gui_action_right (t_gui_window *);
extern void gui_action_next_word (t_gui_window *);
extern void gui_action_up (t_gui_window *);
extern void gui_action_up_global (t_gui_window *);
extern void gui_action_down (t_gui_window *);
extern void gui_action_down_global (t_gui_window *);
extern void gui_action_page_up (t_gui_window *);
extern void gui_action_page_down (t_gui_window *);
extern void gui_action_nick_beginning (t_gui_window *);
extern void gui_action_nick_end (t_gui_window *);
extern void gui_action_nick_page_up (t_gui_window *);
extern void gui_action_nick_page_down (t_gui_window *);
extern void gui_action_jump_smart (t_gui_window *);
extern void gui_action_jump_dcc (t_gui_window *);
extern void gui_action_jump_last_buffer (t_gui_window *);
extern void gui_action_jump_server (t_gui_window *);
extern void gui_action_jump_next_server (t_gui_window *);
extern void gui_action_switch_server (t_gui_window *);
extern void gui_action_hotlist_clear (t_gui_window *);
extern void gui_action_infobar_clear (t_gui_window *);
extern void gui_action_refresh_screen ();
extern void gui_action_grab_key (t_gui_window *);
/* GUI independent functions: keys */
extern void gui_key_init ();
extern void gui_key_init_grab ();
extern char *gui_key_get_internal_code (char *);
extern char *gui_key_get_expanded_name (char *);
extern void *gui_key_function_search_by_name (char *);
extern char *gui_key_function_search_by_ptr (void *);
extern t_gui_key *gui_key_bind (char *, char *);
extern int gui_key_unbind (char *);
extern int gui_key_pressed (char *);
extern void gui_key_free (t_gui_key *);
extern void gui_key_free_all ();
/* GUI dependant functions: display */
extern int gui_assign_color (int *, char *);
extern char *gui_get_color_name (int);
extern unsigned char *gui_color_decode (unsigned char *, int);
extern unsigned char *gui_color_encode (unsigned char *);
extern int gui_buffer_has_nicklist (t_gui_buffer *);
extern void gui_calculate_pos_size (t_gui_window *);
extern void gui_draw_buffer_title (t_gui_buffer *, int);
extern char *gui_word_get_next_char (t_gui_window *, unsigned char *, int);
extern void gui_draw_buffer_chat (t_gui_buffer *, int);
extern void gui_draw_buffer_nick (t_gui_buffer *, int);
extern void gui_draw_buffer_status (t_gui_buffer *, int);
extern void gui_draw_buffer_infobar_time (t_gui_buffer *);
extern void gui_draw_buffer_infobar (t_gui_buffer *, int);
extern void gui_draw_buffer_input (t_gui_buffer *, int);
extern void gui_redraw_buffer (t_gui_buffer *);
extern void gui_switch_to_buffer (t_gui_window *, t_gui_buffer *);
extern t_gui_buffer *gui_get_dcc_buffer (t_gui_window *);
extern void gui_window_page_up (t_gui_window *);
extern void gui_window_page_down (t_gui_window *);
extern void gui_window_nick_beginning (t_gui_window *);
extern void gui_window_nick_end (t_gui_window *);
extern void gui_window_nick_page_up (t_gui_window *);
extern void gui_window_nick_page_down (t_gui_window *);
extern void gui_window_init_subwindows (t_gui_window *);
extern void gui_window_split_horiz (t_gui_window *);
extern void gui_window_split_vertic (t_gui_window *);
extern int gui_window_merge_up (t_gui_window *);
extern int gui_window_merge_down (t_gui_window *);
extern int gui_window_merge_left (t_gui_window *);
extern int gui_window_merge_right (t_gui_window *);
extern void gui_window_merge_auto (t_gui_window *);
extern void gui_window_merge_all (t_gui_window *);
extern void gui_refresh_screen ();
extern void gui_pre_init (int *, char **[]);
extern void gui_rebuild_weechat_colors ();
extern void gui_set_window_title ();
extern void gui_init ();
extern void gui_end ();
extern void gui_input_default_key_bindings ();
extern void gui_main_loop ();
#endif /* gui.h */
|