diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2003-10-12 14:13:48 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2003-10-12 14:13:48 +0000 |
commit | d92955a533a3d4cffaeed7fab95b53ff7d5261ca (patch) | |
tree | 5c85964c1b9686f10c5b2ce9f8f46d4247666c41 /src | |
parent | b12527cf9002da35e364c75389fdce4c480be833 (diff) | |
download | weechat-d92955a533a3d4cffaeed7fab95b53ff7d5261ca.zip |
Version 0.0.3-pre2; added Gtk core functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 7 | ||||
-rw-r--r-- | src/completion.c | 11 | ||||
-rw-r--r-- | src/completion.h | 1 | ||||
-rw-r--r-- | src/gui/Makefile | 23 | ||||
-rw-r--r-- | src/gui/curses/gui-display.c | 269 | ||||
-rw-r--r-- | src/gui/curses/gui-input.c | 156 | ||||
-rw-r--r-- | src/gui/gtk/Makefile | 9 | ||||
-rw-r--r-- | src/gui/gtk/gui-display.c | 657 | ||||
-rw-r--r-- | src/gui/gtk/gui-input.c | 59 | ||||
-rw-r--r-- | src/gui/gui.h | 23 | ||||
-rw-r--r-- | src/weechat.c | 5 | ||||
-rw-r--r-- | src/weechat.h | 2 |
12 files changed, 789 insertions, 433 deletions
diff --git a/src/Makefile b/src/Makefile index 5be70c9bb..367070e34 100644 --- a/src/Makefile +++ b/src/Makefile @@ -23,7 +23,7 @@ OUTPUT=weechat OBJS=weechat.o config.o command.o completion.o history.o OBJS_IRC=irc/irc.a -OBJS_GUI=gui/gui.a +OBJS_GUI=gui/gui.a gui/gui-common.o # WeeChat with Curses interface @@ -38,7 +38,8 @@ endif # WeeChat with Gtk+ interface ifeq ($(GUI), gtk) OBJS_GTK=gui-gtk.o -LIBS_GTK= +LIBS_GTK=`pkg-config --libs gtk+-2.0` +INCLUDES=`pkg-config --cflags gtk+-2.0` DEFINES=WEE_GTK gtk: $(OBJS) $(OBJS_IRC) $(OBJS_GUI) $(CC) $(OPTIONS) $(OBJS) $(OBJS_IRC) $(OBJS_GUI) -o $(OUTPUT) $(LIBS_GTK) @@ -61,7 +62,7 @@ $(OBJS): $(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES) irc/irc.a: - cd irc && make + cd irc && make GUI=$(GUI) gui/gui.a: cd gui && make $(GUI) GUI=$(GUI) diff --git a/src/completion.c b/src/completion.c index 6809d8100..7d7532253 100644 --- a/src/completion.c +++ b/src/completion.c @@ -44,6 +44,17 @@ completion_init (t_completion *completion) } /* + * completion_free: free completion + */ + +void +completion_free (t_completion *completion) +{ + if (completion->base_word) + free (completion->base_word); +} + +/* * completion_command: complete a command */ diff --git a/src/completion.h b/src/completion.h index f07d4a1f7..d1111dbaa 100644 --- a/src/completion.h +++ b/src/completion.h @@ -36,6 +36,7 @@ struct t_completion }; extern void completion_init (t_completion *); +extern void completion_free (t_completion *); extern void completion_search (t_completion *, void *, char *, int, int); #endif /* completion.h */ diff --git a/src/gui/Makefile b/src/gui/Makefile index 9c0970ee1..ea1b051ae 100644 --- a/src/gui/Makefile +++ b/src/gui/Makefile @@ -15,23 +15,34 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +CC=gcc + +OPTIONS=-Wall -W -pipe -O2 + +OUTPUT=../gui.a +OBJS=gui-common.o + # WeeChat with Curses interface ifeq ($(GUI), curses) -curses: curses/gui.a +DEFINES=WEE_CURSES +curses: curses/gui.a $(OBJS) curses/gui.a: cd curses && make endif # WeeChat with Gtk+ interface ifeq ($(GUI), gtk) -gtk: gtk/gui.a +INCLUDES=`pkg-config --cflags gtk+-2.0` +DEFINES=WEE_GTK +gtk: gtk/gui.a $(OBJS) gtk/gui.a: cd gtk && make endif # WeeChat with Qt interface ifeq ($(GUI), qt) -qt: qt/gui.a +DEFINES=WEE_QT +qt: qt/gui.a $(OBJS) qt/gui.a: cd qt && make endif @@ -40,8 +51,14 @@ endif all: make curses GUI=curses +$(OBJS): + $(CC) $(OPTIONS) -o $@ -c $< $(INCLUDES) -D$(DEFINES) + clean: rm -f *.o *.a *~ core cd curses && make clean cd gtk && make clean cd qt && make clean + +gui-common.o: gui-common.c ../weechat.h gui.h ../completion.h \ + ../history.h ../irc/irc.h ../gui/gui.h diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index ec70af0c0..c679faefc 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -37,12 +37,6 @@ #include "../../irc/irc.h" -int gui_ready; /* = 1 if GUI is initialized */ - -t_gui_window *gui_windows = NULL; /* pointer to first window */ -t_gui_window *last_gui_window = NULL; /* pointer to last window */ -t_gui_window *gui_current_window = NULL; /* pointer to current window */ - t_gui_color gui_colors[] = { { "default", -1 | A_NORMAL }, { "black", COLOR_BLACK | A_NORMAL }, @@ -594,7 +588,7 @@ gui_redraw_window_chat (t_gui_window *window) if (window != gui_current_window) return; - //gui_curses_window_clear (window->win_chat); + gui_curses_window_clear (window->win_chat); gui_draw_window_chat (window); } @@ -1036,55 +1030,6 @@ gui_redraw_window (t_gui_window *window) } /* - * gui_window_clear: clear window content - */ - -void -gui_window_clear (t_gui_window *window) -{ - t_gui_line *ptr_line; - t_gui_message *ptr_message; - - while (window->lines) - { - ptr_line = window->lines->next_line; - while (window->lines->messages) - { - ptr_message = window->lines->messages->next_message; - if (window->lines->messages->message) - free (window->lines->messages->message); - free (window->lines->messages); - window->lines->messages = ptr_message; - } - free (window->lines); - window->lines = ptr_line; - } - - window->lines = NULL; - window->last_line = NULL; - window->first_line_displayed = 1; - window->sub_lines = 0; - window->line_complete = 1; - window->unread_data = 0; - - if (window == gui_current_window) - gui_redraw_window_chat (window); -} - -/* - * gui_window_clear_all: clear all windows content - */ - -void -gui_window_clear_all () -{ - t_gui_window *ptr_win; - - for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) - gui_window_clear (ptr_win); -} - -/* * gui_switch_to_window: switch to another window */ @@ -1245,156 +1190,11 @@ gui_move_page_down () } /* - * gui_window_new: create a new window - * (TODO: add coordinates and size, for splited windows) - */ - -t_gui_window * -gui_window_new (void *server, void *channel - /*int x, int y, int width, int height*/) -{ - t_gui_window *new_window; - - if (gui_windows) - { - if (!SERVER(gui_windows)) - { - if (server) - ((t_irc_server *)(server))->window = gui_windows; - if (channel) - ((t_irc_channel *)(channel))->window = gui_windows; - SERVER(gui_windows) = server; - CHANNEL(gui_windows) = channel; - return gui_windows; - } - } - - if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) - { - /* assign server and channel to window */ - SERVER(new_window) = server; - CHANNEL(new_window) = channel; - /* assign window to server and channel */ - if (server && !channel) - SERVER(new_window)->window = new_window; - if (channel) - CHANNEL(new_window)->window = new_window; - - gui_calculate_pos_size (new_window); - - /* init windows */ - new_window->win_title = NULL; - new_window->win_chat = NULL; - new_window->win_nick = NULL; - new_window->win_status = NULL; - new_window->win_input = NULL; - - /* init lines */ - new_window->lines = NULL; - new_window->last_line = NULL; - new_window->first_line_displayed = 1; - new_window->sub_lines = 0; - new_window->line_complete = 1; - new_window->unread_data = 0; - - /* init input buffer */ - new_window->input_buffer_alloc = INPUT_BUFFER_BLOCK_SIZE; - new_window->input_buffer = (char *) malloc (INPUT_BUFFER_BLOCK_SIZE); - new_window->input_buffer[0] = '\0'; - new_window->input_buffer_size = 0; - new_window->input_buffer_pos = 0; - new_window->input_buffer_1st_display = 0; - - /* init completion */ - completion_init (&(new_window->completion)); - - /* init history */ - new_window->history = NULL; - new_window->ptr_history = NULL; - - /* switch to new window */ - gui_switch_to_window (new_window); - - /* add window to windows queue */ - new_window->prev_window = last_gui_window; - if (gui_windows) - last_gui_window->next_window = new_window; - else - gui_windows = new_window; - last_gui_window = new_window; - new_window->next_window = NULL; - - /* redraw whole screen */ - gui_redraw_window (new_window); - } - else - return NULL; - - return new_window; -} - -/* - * gui_window_free: delete a window - */ - -void -gui_window_free (t_gui_window *window) -{ - t_gui_line *ptr_line; - t_gui_message *ptr_message; - int create_new; - - create_new = (window->server || window->channel); - - /* TODO: manage splitted windows! */ - if ((window == gui_current_window) && - ((window->next_window) || (window->prev_window))) - gui_switch_to_previous_window (); - - /* free lines and messages */ - while (window->lines) - { - ptr_line = window->lines->next_line; - while (window->lines->messages) - { - ptr_message = window->lines->messages->next_message; - if (window->lines->messages->message) - free (window->lines->messages->message); - free (window->lines->messages); - window->lines->messages = ptr_message; - } - free (window->lines); - window->lines = ptr_line; - } - if (window->input_buffer) - free (window->input_buffer); - - /* TODO: free completion struct */ - /* there... */ - - /* remove window from windows list */ - if (window->prev_window) - window->prev_window->next_window = window->next_window; - if (window->next_window) - window->next_window->prev_window = window->prev_window; - if (gui_windows == window) - gui_windows = window->next_window; - if (last_gui_window == window) - last_gui_window = window->prev_window; - - free (window); - - /* always at least one window */ - if (!gui_windows && create_new) - gui_window_new (NULL, NULL); -} - -/* - * gui_resize_term_handler: called when term size is modified + * gui_curses_resize_handler: called when term size is modified */ void -gui_resize_term_handler () +gui_curses_resize_handler () { t_gui_window *ptr_win; int width, height; @@ -1552,7 +1352,7 @@ gui_init () /* create windows */ gui_current_window = gui_window_new (NULL, NULL /*0, 0, COLS, LINES*/); - signal (SIGWINCH, gui_resize_term_handler); + signal (SIGWINCH, gui_curses_resize_handler); #ifdef __linux__ /* set title for term window, not for console */ @@ -1594,67 +1394,6 @@ gui_end () } /* - * gui_new_line: create new line for a window - */ - -t_gui_line * -gui_new_line (t_gui_window *window) -{ - t_gui_line *new_line; - - if ((new_line = (t_gui_line *) malloc (sizeof (struct t_gui_line)))) - { - new_line->length = 0; - new_line->length_align = 0; - new_line->line_with_message = 0; - new_line->messages = NULL; - new_line->last_message = NULL; - if (!window->lines) - window->lines = new_line; - else - window->last_line->next_line = new_line; - new_line->prev_line = window->last_line; - new_line->next_line = NULL; - window->last_line = new_line; - } - else - { - wprintw (window->win_chat, - _("%s not enough memory for new line!\n"), - WEECHAT_ERROR); - return NULL; - } - return new_line; -} - -/* - * gui_new_message: create a new message for last line of window - */ - -t_gui_message * -gui_new_message (t_gui_window *window) -{ - t_gui_message *new_message; - - if ((new_message = (t_gui_message *) malloc (sizeof (struct t_gui_message)))) - { - if (!window->last_line->messages) - window->last_line->messages = new_message; - else - window->last_line->last_message->next_message = new_message; - new_message->prev_message = window->last_line->last_message; - new_message->next_message = NULL; - window->last_line->last_message = new_message; - } - else - { - log_printf (_("not enough memory!\n")); - return NULL; - } - return new_message; -} - -/* * gui_add_message: add a message to a window */ diff --git a/src/gui/curses/gui-input.c b/src/gui/curses/gui-input.c index 2717d3dab..21a28022b 100644 --- a/src/gui/curses/gui-input.c +++ b/src/gui/curses/gui-input.c @@ -40,162 +40,6 @@ /* - * gui_optimize_input_buffer_size: optimize input buffer size by adding - * or deleting data block (predefined size) - */ - -void -gui_optimize_input_buffer_size (t_gui_window *window) -{ - int optimal_size; - - optimal_size = ((window->input_buffer_size / INPUT_BUFFER_BLOCK_SIZE) * - INPUT_BUFFER_BLOCK_SIZE) + INPUT_BUFFER_BLOCK_SIZE; - if (window->input_buffer_alloc != optimal_size) - { - window->input_buffer_alloc = optimal_size; - window->input_buffer = realloc (window->input_buffer, optimal_size); - } -} - -/* - * gui_delete_previous_word: delete previous word - */ - -void -gui_delete_previous_word () -{ - int i, j, num_char_deleted, num_char_end; - - if (gui_current_window->input_buffer_pos > 0) - { - i = gui_current_window->input_buffer_pos - 1; - while ((i >= 0) && - (gui_current_window->input_buffer[i] == ' ')) - i--; - if (i >= 0) - { - while ((i >= 0) && - (gui_current_window->input_buffer[i] != ' ')) - i--; - if (i >= 0) - { - while ((i >= 0) && - (gui_current_window->input_buffer[i] == ' ')) - i--; - } - } - - if (i >= 0) - i++; - i++; - num_char_deleted = gui_current_window->input_buffer_pos - i; - num_char_end = gui_current_window->input_buffer_size - - gui_current_window->input_buffer_pos; - - for (j = 0; j < num_char_end; j++) - gui_current_window->input_buffer[i + j] = - gui_current_window->input_buffer[gui_current_window->input_buffer_pos + j]; - - gui_current_window->input_buffer_size -= num_char_deleted; - gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0'; - gui_current_window->input_buffer_pos = i; - gui_draw_window_input (gui_current_window); - gui_optimize_input_buffer_size (gui_current_window); - gui_current_window->completion.position = -1; - } -} - -/* - * gui_move_previous_word: move to beginning of previous word - */ - -void -gui_move_previous_word () -{ - int i; - - if (gui_current_window->input_buffer_pos > 0) - { - i = gui_current_window->input_buffer_pos - 1; - while ((i >= 0) && - (gui_current_window->input_buffer[i] == ' ')) - i--; - if (i < 0) - gui_current_window->input_buffer_pos = 0; - else - { - while ((i >= 0) && - (gui_current_window->input_buffer[i] != ' ')) - i--; - gui_current_window->input_buffer_pos = i + 1; - } - gui_draw_window_input (gui_current_window); - } -} - -/* - * gui_move_next_word: move to the end of next - */ - -void -gui_move_next_word () -{ - int i; - - if (gui_current_window->input_buffer_pos < - gui_current_window->input_buffer_size + 1) - { - i = gui_current_window->input_buffer_pos; - while ((i <= gui_current_window->input_buffer_size) && - (gui_current_window->input_buffer[i] == ' ')) - i++; - if (i > gui_current_window->input_buffer_size) - gui_current_window->input_buffer_pos = i - 1; - else - { - while ((i <= gui_current_window->input_buffer_size) && - (gui_current_window->input_buffer[i] != ' ')) - i++; - if (i > gui_current_window->input_buffer_size) - gui_current_window->input_buffer_pos = - gui_current_window->input_buffer_size; - else - gui_current_window->input_buffer_pos = i; - - } - gui_draw_window_input (gui_current_window); - } -} - -/* - * gui_buffer_insert_string: insert a string into the input buffer - */ - -void -gui_buffer_insert_string (char *string, int pos) -{ - int i, start, end, length; - - length = strlen (string); - - /* increase buffer size */ - gui_current_window->input_buffer_size += length; - gui_optimize_input_buffer_size (gui_current_window); - gui_current_window->input_buffer[gui_current_window->input_buffer_size] = '\0'; - - /* move end of string to the right */ - start = pos + length; - end = gui_current_window->input_buffer_size - 1; - for (i = end; i >= start; i--) - gui_current_window->input_buffer[i] = - gui_current_window->input_buffer[i - length]; - - /* insert new string */ - strncpy (gui_current_window->input_buffer + pos, string, length); -} - -/* * gui_read_keyb: read keyboard line */ diff --git a/src/gui/gtk/Makefile b/src/gui/gtk/Makefile index 6d2de6eba..0da1a6390 100644 --- a/src/gui/gtk/Makefile +++ b/src/gui/gtk/Makefile @@ -21,6 +21,7 @@ OPTIONS=-Wall -W -pipe -O2 OUTPUT=../gui.a OBJS=gui-display.o gui-input.o +INCLUDES=`pkg-config --cflags gtk+-2.0` DEFINES=WEE_GTK all: $(OBJS) @@ -32,6 +33,8 @@ $(OBJS): clean: rm -f *.o *.a *~ core -gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../config.h \ - ../../irc/irc.h ../../gui/gui.h -gui-input.o: gui-input.c ../../weechat.h ../gui.h +gui-display.o: gui-display.c ../../weechat.h ../gui.h ../../completion.h \ + ../../history.h ../../config.h ../../irc/irc.h ../../gui/gui.h +gui-input.o: gui-input.c ../../weechat.h ../gui.h ../../completion.h \ + ../../history.h ../../config.h ../../command.h ../../irc/irc.h \ + ../../gui/gui.h diff --git a/src/gui/gtk/gui-display.c b/src/gui/gtk/gui-display.c new file mode 100644 index 000000000..0d9563491 --- /dev/null +++ b/src/gui/gtk/gui-display.c @@ -0,0 +1,657 @@ +/* + * Copyright (c) 2003 by FlashCode <flashcode@flashtux.org> + * Bounga <bounga@altern.org> + * Xahlexx <xahlexx@tuxisland.org> + * See README for License detail. + * + * 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 + */ + + +/* gui-display.c: display functions for Gtk GUI */ + + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <signal.h> +#include <time.h> + +#include "../../weechat.h" +#include "../gui.h" +#include "../../config.h" +#include "../../irc/irc.h" + + +t_gui_color gui_colors[] = +{ { "default", 0 }, + { "black", 0 }, + { "red", 0 }, + { "lightred", 0 }, + { "green", 0 }, + { "lightgreen", 0 }, + { "brown", 0 }, + { "yellow", 0 }, + { "blue", 0 }, + { "lightblue", 0 }, + { "magenta", 0L }, + { "lightmagenta", 0 }, + { "cyan", 0 }, + { "lightcyan", 0 }, + { "gray", 0 }, + { "white", 0 }, + { NULL, 0 } +}; + +char *nicks_colors[COLOR_WIN_NICK_NUMBER] = +{ "cyan", "magenta", "green", "brown", "lightblue", "gray", + "lightcyan", "lightmagenta", "lightgreen", "blue" }; + +int color_attr[NUM_COLORS]; + +/* + * gui_assign_color: assign a color (read from config) + */ + +int +gui_assign_color (int *color, char *color_name) +{ + int i; + + /* look for Gtk colors in table */ + i = 0; + while (gui_colors[i].name) + { + if (strcasecmp (gui_colors[i].name, color_name) == 0) + { + *color = gui_colors[i].color; + return 1; + } + i++; + } + + /* color not found */ + return 0; +} + +/* + * gui_get_color_by_name: get color by name + */ + +int +gui_get_color_by_name (char *color_name) +{ + int i; + + /* look for Gtk in table */ + i = 0; + while (gui_colors[i].name) + { + if (strcasecmp (gui_colors[i].name, color_name) == 0) + return gui_colors[i].color; + i++; + } + + /* color not found */ + return -1; +} + +/* + * gui_get_color_by_value: get color name by value + */ + +char * +gui_get_color_by_value (int color_value) +{ + int i; + + /* look for Gtk colors in table */ + i = 0; + while (gui_colors[i].name) + { + if (gui_colors[i].color == color_value) + return gui_colors[i].name; + i++; + } + + /* color not found */ + return NULL; +} + +/* + * gui_calculate_pos_size: calculate position and size for a window & sub-win + */ + +void +gui_calculate_pos_size (t_gui_window *window) +{ + /* TODO: write gui_calculate_pos_size for Gtk GUI */ + (void) window; +} + +/* + * gui_draw_window_title: draw title window + */ + +void +gui_draw_window_title (t_gui_window *window) +{ + char format[32]; + + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + if (CHANNEL(window)) + { + sprintf (format, "%%-%ds", window->win_width); + /* TODO: display topic */ + } + else + { + /* TODO: display title for server window */ + } +} + +/* + * gui_redraw_window_title: redraw title window + */ + +void +gui_redraw_window_title (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: first delete window content */ + gui_draw_window_title (window); +} + +/* + * gui_get_line_num_splits: returns number of lines on window + * (depending on window width and type (server/channel) + * for alignment) + */ + +int +gui_get_line_num_splits (t_gui_window *window, t_gui_line *line) +{ + int length, width; + + /* TODO: modify arbitraty value for non aligning messages on time/nick? */ + if (line->length_align >= window->win_chat_width - 5) + { + length = line->length; + width = window->win_chat_width; + } + else + { + length = line->length - line->length_align; + width = window->win_chat_width - line->length_align; + } + + return (length % width == 0) ? (length / width) : ((length / width) + 1); +} + +/* + * gui_display_end_of_line: display end of a line in the chat window + */ + +void +gui_display_end_of_line (t_gui_window *window, t_gui_line *line, int count) +{ + /* TODO: display end of line! */ + (void) window; + (void) line; + (void) count; +} + +/* + * gui_display_line: display a line in the chat window + * if stop_at_end == 1, screen will not scroll and then we + * exit since chat window is full + * returns: 1 if stop_at_end == 0 or screen not full + * 0 if screen is full and if stop_at_end == 1 + */ + +int +gui_display_line (t_gui_window *window, t_gui_line *line, int stop_at_end) +{ + /* TODO: display line! */ + (void) window; + (void) line; + (void) stop_at_end; + return 1; +} + +/* + * gui_draw_window_chat: draw chat window + */ + +void +gui_draw_window_chat (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: draw chat window */ +} + +/* + * gui_redraw_window_chat: redraw chat window + */ + +void +gui_redraw_window_chat (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: first delete window content */ + gui_draw_window_chat (window); +} + +/* + * gui_draw_window_nick: draw nick window + */ + +void +gui_draw_window_nick (t_gui_window *window) +{ + int i, x, y, column, max_length; + char format[32]; + t_irc_nick *ptr_nick; + + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + if (CHANNEL(window) && CHANNEL(window)->nicks) + { + max_length = nick_get_max_length (CHANNEL(window)); + if ((window == gui_current_window) && + ((max_length + 2) != window->win_nick_width)) + { + /* TODO: auto resize nicklist and chat windows */ + } + sprintf (format, "%%-%ds", max_length); + + switch (cfg_look_nicklist_position) + { + case CFG_LOOK_NICKLIST_LEFT: + /* TODO: init nicklist (left) */ + break; + case CFG_LOOK_NICKLIST_RIGHT: + /* TODO: init nicklist (right) */ + break; + case CFG_LOOK_NICKLIST_TOP: + /* TODO: init nicklist (top) */ + break; + case CFG_LOOK_NICKLIST_BOTTOM: + /* TODO: init nicklist (bottom) */ + break; + } + /* TODO: draw nicklist! */ + (void) i; + (void) x; + (void) y; + (void) column; + (void) ptr_nick; + } +} + +/* + * gui_redraw_window_nick: redraw nick window + */ + +void +gui_redraw_window_nick (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: first delete window content */ + gui_draw_window_nick (window); +} + +/* + * gui_draw_window_status: draw status window + */ + +void +gui_draw_window_status (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: draw status window! */ +} + +/* + * gui_redraw_window_status: redraw status window + */ + +void +gui_redraw_window_status (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: first delete window content */ + gui_draw_window_status (window); +} + +/* + * gui_draw_window_input: draw input window + */ + +void +gui_draw_window_input (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: draw input window */ +} + +/* + * gui_redraw_window_input: redraw input window + */ + +void +gui_redraw_window_input (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + /* TODO: first delete window content */ + gui_draw_window_input (window); +} + +/* + * gui_redraw_window: redraw a window + */ + +void +gui_redraw_window (t_gui_window *window) +{ + /* TODO: manage splitted windows! */ + if (window != gui_current_window) + return; + + gui_redraw_window_title (window); + gui_redraw_window_chat (window); + if (window->win_nick) + gui_redraw_window_nick (window); + gui_redraw_window_status (window); + gui_redraw_window_input (window); +} + +/* + * gui_switch_to_window: switch to another window + */ + +void +gui_switch_to_window (t_gui_window *window) +{ + int another_window; + t_gui_window *ptr_win; + + another_window = 0; + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if (ptr_win->win_title) + { + /* TODO: manage splitted windows */ + another_window = 1; + window->win_title = ptr_win->win_title; + window->win_chat = ptr_win->win_chat; + window->win_nick = ptr_win->win_nick; + window->win_status = ptr_win->win_status; + window->win_input = ptr_win->win_input; + ptr_win->win_title = NULL; + ptr_win->win_chat = NULL; + ptr_win->win_nick = NULL; + ptr_win->win_status = NULL; + ptr_win->win_input = NULL; + break; + } + } + + gui_calculate_pos_size (window); + + /* first time creation for windows */ + if (!another_window) + { + /* create new windows */ + /* TODO: create title, chat, nick, status and input windows */ + } + else + { + /* create chat & nick windows */ + if (WIN_IS_CHANNEL(window)) + { + /* (re)create nicklist window */ + /* TODO: delete nick/chat windows and create them */ + } + if (!(WIN_IS_CHANNEL(window))) + { + /* remove nick list window */ + /* TODO: remove nicklist window and create full chat window */ + } + } + + /* change current window to the new window */ + gui_current_window = window; + + window->unread_data = 0; +} + +/* + * gui_switch_to_previous_window: switch to previous window + */ + +void +gui_switch_to_previous_window () +{ + /* if only one windows then return */ + if (gui_windows == last_gui_window) + return; + + if (gui_current_window->prev_window) + gui_switch_to_window (gui_current_window->prev_window); + else + gui_switch_to_window (last_gui_window); + gui_redraw_window (gui_current_window); +} + +/* + * gui_switch_to_next_window: switch to next window + */ + +void +gui_switch_to_next_window () +{ + /* if only one windows then return */ + if (gui_windows == last_gui_window) + return; + + if (gui_current_window->next_window) + gui_switch_to_window (gui_current_window->next_window); + else + gui_switch_to_window (gui_windows); + gui_redraw_window (gui_current_window); +} + +/* + * gui_move_page_up: display previous page on window + */ + +void +gui_move_page_up () +{ + if (!gui_current_window->first_line_displayed) + { + gui_current_window->sub_lines += gui_current_window->win_chat_height - 1; + gui_redraw_window_chat (gui_current_window); + gui_redraw_window_status (gui_current_window); + } +} + +/* + * gui_move_page_down: display next page on window + */ + +void +gui_move_page_down () +{ + if (gui_current_window->sub_lines > 0) + { + gui_current_window->sub_lines -= gui_current_window->win_chat_height - 1; + if (gui_current_window->sub_lines < 0) + gui_current_window->sub_lines = 0; + if (gui_current_window->sub_lines == 0) + gui_current_window->unread_data = 0; + gui_redraw_window_chat (gui_current_window); + gui_redraw_window_status (gui_current_window); + } +} + +/* + * gui_gtk_resize_handler: called when term size is modified + */ + +void +gui_gtk_resize_handler () +{ + /* TODO: write resize handler for Gtk */ +} + +/* + * gui_init_colors: init GUI colors + */ + +void +gui_init_colors () +{ + /* TODO: init colors for Gtk */ +} + +/* + * gui_init: init GUI + */ + +void +gui_init () +{ + /* TODO: initialize Gtk GUI */ + + gui_ready = 1; +} + +/* + * gui_end: GUI end + */ + +void +gui_end () +{ + t_gui_window *ptr_win; + + /* delete all windows */ + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + /* TODO: delete Gtk windows */ + /* TODO: free input buffer, lines, messages, completion */ + } +} + +/* + * gui_add_message: add a message to a window + */ + +void +gui_add_message (t_gui_window *window, int type, int color, char *message) +{ + char *pos; + int length; + + /* create new line if previous was ending by '\n' (or if 1st line) */ + if (window->line_complete) + { + window->line_complete = 0; + if (!gui_new_line (window)) + return; + } + if (!gui_new_message (window)) + return; + + window->last_line->last_message->type = type; + window->last_line->last_message->color = color; + pos = strchr (message, '\n'); + if (pos) + { + pos[0] = '\0'; + window->line_complete = 1; + } + window->last_line->last_message->message = strdup (message); + length = strlen (message); + window->last_line->length += length; + if (type == MSG_TYPE_MSG) + window->last_line->line_with_message = 1; + if ((type == MSG_TYPE_TIME) || (type == MSG_TYPE_NICK)) + window->last_line->length_align += length; + if (pos) + { + pos[0] = '\n'; + if ((window == gui_current_window) && (window->sub_lines == 0)) + { + if ((window->win_chat_cursor_y + + gui_get_line_num_splits (window, window->last_line)) > + (window->win_chat_height - 1)) + gui_draw_window_chat (window); + else + gui_display_line (window, window->last_line, 1); + } + if ((window != gui_current_window) || (window->sub_lines > 0)) + { + window->unread_data = 1 + window->last_line->line_with_message; + gui_redraw_window_status (gui_current_window); + } + } +} + +/* + * gui_printf_color_type: display a message in a window + */ + +void +gui_printf_color_type (t_gui_window *window, int type, int color, char *message, ...) +{ + /* TODO: write gui_printf_colot_type function for Gtk! */ + (void) window; + (void) type; + (void) color; + (void) message; +} diff --git a/src/gui/gtk/gui-input.c b/src/gui/gtk/gui-input.c new file mode 100644 index 000000000..ffeeadeda --- /dev/null +++ b/src/gui/gtk/gui-input.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2003 by FlashCode <flashcode@flashtux.org> + * Bounga <bounga@altern.org> + * Xahlexx <xahlexx@tuxisland.org> + * See README for License detail. + * + * 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 + */ + + +/* gui-input: user input functions for Gtk GUI */ + + +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <signal.h> +#include <time.h> +#include <sys/socket.h> + +#include "../../weechat.h" +#include "../gui.h" +#include "../../config.h" +#include "../../command.h" +#include "../../irc/irc.h" + + +/* + * gui_read_keyb: read keyboard line + */ + +void +gui_read_keyb () +{ + /* TODO: read keyboard for Gtk GUI */ +} + +/* + * gui_main_loop: main loop for WeeChat with Gtk GUI + */ + +void +gui_main_loop () +{ + /* TODO: main loop function for Gtk GUI */ +} diff --git a/src/gui/gui.h b/src/gui/gui.h index d8e3aca99..8a87031b4 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -26,6 +26,9 @@ #ifdef WEE_CURSES #include <curses.h> #endif +#ifdef WEE_GTK +#include <gtk/gtk.h> +#endif #include "../completion.h" #include "../history.h" @@ -149,7 +152,11 @@ struct t_gui_window WINDOW *win_input; /* input window */ #endif #ifdef WEE_GTK - /* TODO: declare Gtk+ window */ + GtkWidget *win_title; /* title window */ + GtkWidget *win_chat; /* chat window (exemple: channel) */ + GtkWidget *win_nick; /* nick window */ + GtkWidget *win_status; /* status window */ + GtkWidget *win_input; /* input window */ #endif #ifdef WEE_QT /* TODO: declare Qt window */ @@ -186,6 +193,7 @@ struct t_gui_window extern int gui_ready; extern t_gui_window *gui_windows; +extern t_gui_window *last_gui_window; extern t_gui_window *gui_current_window; /* prototypes */ @@ -194,6 +202,8 @@ extern int gui_assign_color (int *, char *); extern int gui_get_color_by_name (char *); extern char *gui_get_color_by_value (int); +extern void gui_calculate_pos_size (t_gui_window *); + extern void gui_draw_window_title (t_gui_window *); extern void gui_redraw_window_title (t_gui_window *); extern void gui_draw_window_chat (t_gui_window *); @@ -206,6 +216,7 @@ extern void gui_draw_window_input (t_gui_window *); extern void gui_redraw_window_input (t_gui_window *); extern void gui_redraw_window (t_gui_window *); +extern t_gui_window *gui_window_new (void *, void *); extern void gui_window_clear (t_gui_window *); extern void gui_window_clear_all (); @@ -221,8 +232,16 @@ extern void gui_init (); extern t_gui_window *gui_window_new (void *, void * /*int, int, int, int*/); extern void gui_window_free (t_gui_window *); extern void gui_end (); + +extern t_gui_line *gui_new_line (t_gui_window *); +extern t_gui_message *gui_new_message (t_gui_window *); extern void gui_printf_color_type (t_gui_window *, int, int, char *, ...); -extern void gui_display_nick (t_gui_window *, void *, int, int, int, int); + +extern void gui_optimize_input_buffer_size (t_gui_window *); +extern void gui_delete_previous_word (); +extern void gui_move_previous_word (); +extern void gui_move_next_word (); +extern void gui_buffer_insert_string (char *, int); extern void gui_main_loop (); diff --git a/src/weechat.c b/src/weechat.c index 8ced99156..0e22c1c4c 100644 --- a/src/weechat.c +++ b/src/weechat.c @@ -231,6 +231,11 @@ main (int argc, char *argv[]) bindtextdomain (PACKAGE, "/usr/share/locale"); textdomain (PACKAGE); + /* Gtk init */ + #ifdef WEE_GTK + gtk_init (&argc, &argv); + #endif + /* initialize variables */ wee_init_vars (); diff --git a/src/weechat.h b/src/weechat.h index ca3bde9b2..adc0bf04e 100644 --- a/src/weechat.h +++ b/src/weechat.h @@ -32,7 +32,7 @@ #define N_(string) (string) #define WEECHAT_NAME "WeeChat" -#define WEECHAT_VERSION "0.0.3-pre1" +#define WEECHAT_VERSION "0.0.3-pre2" #define WEECHAT_NAME_AND_VERSION WEECHAT_NAME " " WEECHAT_VERSION #define WEECHAT_COPYRIGHT WEECHAT_NAME " (c) 2003 by Wee Team" |