summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2003-10-13 21:51:34 +0000
committerSebastien Helleu <flashcode@flashtux.org>2003-10-13 21:51:34 +0000
commit13716a52288360cae787e41bfd353ca3cf4e3710 (patch)
tree447710ef39f475859fdd709dc20cecae06a61e9c /src/gui
parentecd92ae24d43bd9046295b17114c4cf97ff137f6 (diff)
downloadweechat-13716a52288360cae787e41bfd353ca3cf4e3710.zip
New gtk features
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-display.c29
-rw-r--r--src/gui/gtk/gui-display.c223
-rw-r--r--src/gui/gui-common.c106
-rw-r--r--src/gui/gui.h54
4 files changed, 191 insertions, 221 deletions
diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c
index 1fa821940..f4a88e859 100644
--- a/src/gui/curses/gui-display.c
+++ b/src/gui/curses/gui-display.c
@@ -1041,7 +1041,7 @@ gui_switch_to_window (t_gui_window *window)
another_window = 0;
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
- if (ptr_win->win_title)
+ if (ptr_win->is_displayed)
{
/* TODO: manage splitted windows */
another_window = 1;
@@ -1055,6 +1055,7 @@ gui_switch_to_window (t_gui_window *window)
ptr_win->win_nick = NULL;
ptr_win->win_status = NULL;
ptr_win->win_input = NULL;
+ ptr_win->is_displayed = 0;
break;
}
}
@@ -1115,6 +1116,7 @@ gui_switch_to_window (t_gui_window *window)
/* change current window to the new window */
gui_current_window = window;
+ window->is_displayed = 1;
window->unread_data = 0;
}
@@ -1230,6 +1232,20 @@ gui_curses_resize_handler ()
}
/*
+ * gui_window_init_subwindows: init subwindows for a WeeChat window
+ */
+
+void
+gui_window_init_subwindows (t_gui_window *window)
+{
+ window->win_title = NULL;
+ window->win_chat = NULL;
+ window->win_nick = NULL;
+ window->win_status = NULL;
+ window->win_input = NULL;
+}
+
+/*
* gui_init_colors: init GUI colors
*/
@@ -1348,7 +1364,7 @@ gui_init ()
gui_init_colors ();
- /* create windows */
+ /* create a new window */
gui_current_window = gui_window_new (NULL, NULL /*0, 0, COLS, LINES*/);
signal (SIGWINCH, gui_curses_resize_handler);
@@ -1507,11 +1523,10 @@ gui_printf_color_type (t_gui_window *window, int type, int color, char *message,
gui_add_message (window, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, timestamp);
gui_add_message (window, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, "] ");
}
- gui_add_message (window, type, color, pos+1);
- pos = strchr (pos+1, '\n');
- if (pos)
- if (pos[1] == '\0')
- pos = NULL;
+ gui_add_message (window, type, color, pos + 1);
+ pos = strchr (pos + 1, '\n');
+ if (pos && !pos[1])
+ pos = NULL;
}
wrefresh (window->win_chat);
diff --git a/src/gui/gtk/gui-display.c b/src/gui/gtk/gui-display.c
index 8b3b09266..673f414f3 100644
--- a/src/gui/gtk/gui-display.c
+++ b/src/gui/gtk/gui-display.c
@@ -63,6 +63,15 @@ char *nicks_colors[COLOR_WIN_NICK_NUMBER] =
int color_attr[NUM_COLORS];
GtkWidget *gtk_main_window;
+GtkWidget *vbox1;
+GtkWidget *entry_topic;
+GtkWidget *notebook1;
+GtkWidget *vbox2;
+GtkWidget *hbox1;
+GtkWidget *scrolledwindow_chat;
+GtkWidget *scrolledwindow_nick;
+GtkWidget *entry_input;
+GtkWidget *label1;
/*
@@ -277,46 +286,11 @@ gui_redraw_window_chat (t_gui_window *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;
- }
+ /* TODO: display nicklist for Gtk GUI */
}
/*
@@ -405,7 +379,7 @@ gui_redraw_window (t_gui_window *window)
gui_redraw_window_title (window);
gui_redraw_window_chat (window);
- if (window->win_nick)
+ if (WIN_HAS_NICKLIST(window))
gui_redraw_window_nick (window);
gui_redraw_window_status (window);
gui_redraw_window_input (window);
@@ -418,56 +392,54 @@ gui_redraw_window (t_gui_window *window)
void
gui_switch_to_window (t_gui_window *window)
{
- int another_window;
t_gui_window *ptr_win;
+ GtkTextIter start, end;
- another_window = 0;
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window)
{
- if (ptr_win->win_title)
+ if (ptr_win->is_displayed)
{
/* 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;
+ ptr_win->is_displayed = 0;
break;
}
}
gui_calculate_pos_size (window);
- /* first time creation for windows */
- if (!another_window)
+ if (!window->textview_chat)
{
- /* create new windows */
- /* TODO: create title, chat, nick, status and input windows */
+ window->textview_chat = gtk_text_view_new ();
+ gtk_widget_show (window->textview_chat);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow_chat), window->textview_chat);
+ gtk_widget_set_size_request (window->textview_chat, 300, -1);
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview_chat), FALSE);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview_chat), FALSE);
+
+ window->textbuffer_chat = gtk_text_buffer_new (NULL);
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->textview_chat), window->textbuffer_chat);
+
+ window->texttag_chat = gtk_text_buffer_create_tag(window->textbuffer_chat, "courier", "font_family", "lucida");
+ gtk_text_buffer_get_bounds (window->textbuffer_chat, &start, &end);
+ gtk_text_buffer_apply_tag (window->textbuffer_chat, window->texttag_chat, &start, &end);
}
- else
+ if (WIN_IS_CHANNEL (window) && !window->textbuffer_nicklist)
{
- /* 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 */
- }
+
+ window->textview_nicklist = gtk_text_view_new ();
+ gtk_widget_show (window->textview_nicklist);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow_nick), window->textview_nicklist);
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview_nicklist), FALSE);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview_nicklist), FALSE);
+
+ window->textbuffer_nicklist = gtk_text_buffer_new (NULL);
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (window->textview_nicklist), window->textbuffer_nicklist);
}
/* change current window to the new window */
gui_current_window = window;
+ window->is_displayed = 1;
window->unread_data = 0;
}
@@ -552,6 +524,20 @@ gui_gtk_resize_handler ()
}
/*
+ * gui_window_init_subwindows: init subwindows for a WeeChat window
+ */
+
+void
+gui_window_init_subwindows (t_gui_window *window)
+{
+ window->textview_chat = NULL;
+ window->textbuffer_chat = NULL;
+ window->texttag_chat = NULL;
+ window->textview_nicklist = NULL;
+ window->textbuffer_nicklist = NULL;
+}
+
+/*
* gui_init_colors: init GUI colors
*/
@@ -568,18 +554,6 @@ gui_init_colors ()
void
gui_init ()
{
- GtkWidget *vbox1;
- GtkWidget *entry_topic;
- GtkWidget *notebook1;
- GtkWidget *vbox2;
- GtkWidget *hbox1;
- GtkWidget *scrolledwindow_chat;
- GtkWidget *textview_chat;
- GtkWidget *scrolledwindow_nick;
- GtkWidget *textview_nick;
- GtkWidget *entry_input;
- GtkWidget *label1;
-
gtk_main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (gtk_main_window), WEECHAT_NAME_AND_VERSION);
@@ -609,24 +583,11 @@ gui_init ()
gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow_chat, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_chat), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
- textview_chat = gtk_text_view_new ();
- gtk_widget_show (textview_chat);
- gtk_container_add (GTK_CONTAINER (scrolledwindow_chat), textview_chat);
- gtk_widget_set_size_request (textview_chat, 300, -1);
- gtk_text_view_set_editable (GTK_TEXT_VIEW (textview_chat), FALSE);
- gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview_chat), FALSE);
-
scrolledwindow_nick = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow_nick);
gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow_nick, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_nick), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
- textview_nick = gtk_text_view_new ();
- gtk_widget_show (textview_nick);
- gtk_container_add (GTK_CONTAINER (scrolledwindow_nick), textview_nick);
- gtk_text_view_set_editable (GTK_TEXT_VIEW (textview_nick), FALSE);
- gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview_nick), FALSE);
-
entry_input = gtk_entry_new ();
gtk_widget_show (entry_input);
gtk_box_pack_start (GTK_BOX (vbox2), entry_input, FALSE, FALSE, 0);
@@ -638,8 +599,11 @@ gui_init ()
gtk_widget_show_all (gtk_main_window);
+ /* create a new window */
+ gui_current_window = gui_window_new (NULL, NULL /*0, 0, COLS, LINES*/);
+
/* TODO: set gui_ready to 1 when Gtk display functions will be ok */
- gui_ready = 0;
+ gui_ready = 1;
}
/*
@@ -668,50 +632,28 @@ gui_add_message (t_gui_window *window, int type, int color, char *message)
{
char *pos;
int length;
+ GtkTextIter start, end;
/* create new line if previous was ending by '\n' (or if 1st line) */
if (window->line_complete)
{
+ gtk_text_buffer_insert_at_cursor (window->textbuffer_chat, "\n", -1);
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;
+
+ gtk_text_buffer_insert_at_cursor (window->textbuffer_chat, message, -1);
+ gtk_text_buffer_get_bounds (window->textbuffer_chat, &start, &end);
+ gtk_text_buffer_apply_tag (window->textbuffer_chat, window->texttag_chat, &start, &end);
+
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);
- }
- }
}
/*
@@ -727,12 +669,26 @@ gui_printf_color_type (t_gui_window *window, int type, int color, char *message,
va_list argptr;
static time_t seconds;
struct tm *date_tmp;
-
- /* make gcc hapy */
- (void) window;
- (void) type;
- (void) color;
- (void) message;
+
+ if (gui_ready)
+ {
+ if (color == -1)
+ color = COLOR_WIN_CHAT;
+
+ if (window == NULL)
+ {
+ if (SERVER(gui_current_window))
+ window = SERVER(gui_current_window)->window;
+ else
+ window = gui_current_window;
+ }
+
+ if (window == NULL)
+ {
+ log_printf ("gui_printf without window! this is a bug, please send to developers - thanks\n");
+ return;
+ }
+ }
va_start (argptr, message);
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
@@ -747,7 +703,7 @@ gui_printf_color_type (t_gui_window *window, int type, int color, char *message,
while (pos)
{
/* TODO: read timestamp format from config! */
- if ((!window->last_line) || (window->line_complete))
+ if (window->line_complete)
{
gui_add_message (window, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, "[");
sprintf (timestamp, "%02d", date_tmp->tm_hour);
@@ -760,11 +716,10 @@ gui_printf_color_type (t_gui_window *window, int type, int color, char *message,
gui_add_message (window, MSG_TYPE_TIME, COLOR_WIN_CHAT_TIME, timestamp);
gui_add_message (window, MSG_TYPE_TIME, COLOR_WIN_CHAT_DARK, "] ");
}
- gui_add_message (window, type, color, pos+1);
- pos = strchr (pos+1, '\n');
- if (pos)
- if (pos[1] == '\0')
- pos = NULL;
+ gui_add_message (window, type, color, pos + 1);
+ pos = strchr (pos + 1, '\n');
+ if (pos && !pos[1])
+ pos = NULL;
}
}
else
diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c
index 330f1f642..b6e4c7b86 100644
--- a/src/gui/gui-common.c
+++ b/src/gui/gui-common.c
@@ -44,55 +44,6 @@ t_gui_window *gui_current_window = NULL; /* pointer to current 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_window_new: create a new window
* (TODO: add coordinates and size, for splited windows)
*/
@@ -120,6 +71,8 @@ gui_window_new (void *server, void *channel
if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window)))))
{
+ new_window->is_displayed = 0;
+
/* assign server and channel to window */
SERVER(new_window) = server;
CHANNEL(new_window) = channel;
@@ -132,11 +85,7 @@ gui_window_new (void *server, void *channel
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;
+ gui_window_init_subwindows(new_window);
/* init lines */
new_window->lines = NULL;
@@ -183,6 +132,55 @@ gui_window_new (void *server, void *channel
}
/*
+ * 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_window_free: delete a window
*/
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 8a87031b4..11f326926 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -76,6 +76,13 @@
#define WIN_IS_CHANNEL(window) (CHANNEL(window) && (CHANNEL(window)->type == CHAT_CHANNEL))
#define WIN_IS_PRIVATE(window) (CHANNEL(window) && (CHANNEL(window)->type == CHAT_PRIVATE))
+#ifdef WEE_CURSES
+ #define WIN_HAS_NICKLIST(window) (window->win_nick)
+#endif
+#ifdef WEE_GTK
+ #define WIN_HAS_NICKLIST(window) (window->textbuffer_nicklist)
+#endif
+
#define MSG_TYPE_TIME 0
#define MSG_TYPE_NICK 1
#define MSG_TYPE_INFO 2
@@ -123,6 +130,8 @@ typedef struct t_gui_window t_gui_window;
struct t_gui_window
{
+ int is_displayed; /* = 1 if window is displayed */
+
/* server/channel */
void *server; /* window's server */
void *channel; /* window's channel */
@@ -152,11 +161,11 @@ struct t_gui_window
WINDOW *win_input; /* input window */
#endif
#ifdef WEE_GTK
- 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 */
+ GtkWidget *textview_chat; /* textview widget for chat */
+ GtkTextBuffer *textbuffer_chat; /* textbuffer widget for chat */
+ GtkTextTag *texttag_chat; /* texttag widget for chat */
+ GtkWidget *textview_nicklist; /* textview widget for nicklist */
+ GtkTextBuffer *textbuffer_nicklist; /* textbuffer widget for nicklist */
#endif
#ifdef WEE_QT
/* TODO: declare Qt window */
@@ -198,12 +207,22 @@ extern t_gui_window *gui_current_window;
/* prototypes */
+/* GUI independent functions */
+extern t_gui_window *gui_window_new (void *, void * /*int, int, int, int*/); /* TODO: add coordinates and size */
+extern void gui_window_clear (t_gui_window *);
+extern void gui_window_clear_all ();
+extern t_gui_line *gui_new_line (t_gui_window *);
+extern t_gui_message *gui_new_message (t_gui_window *);
+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);
+/* GUI dependant functions */
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 *);
@@ -215,34 +234,17 @@ extern void gui_redraw_window_status (t_gui_window *);
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 ();
-
extern void gui_switch_to_window (t_gui_window *);
extern void gui_switch_to_previous_window ();
extern void gui_switch_to_next_window ();
-
extern void gui_move_page_up ();
extern void gui_move_page_down ();
-
+extern void gui_window_init_subwindows (t_gui_window *);
+extern void gui_init_colors ();
extern void gui_init ();
-/* TODO: add coordinates and size */
-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_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 ();
#endif /* gui.h */