1 /* Copyright (C) 2016-2017 Shengyu Zhang <i@silverrainz.me>
2  *
3  * This file is part of Srain.
4  *
5  * Srain is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __SUI_BUFFER_H
20 #define __SUI_BUFFER_H
21 
22 #include <gtk/gtk.h>
23 
24 #include "sui_message.h"
25 #include "sui_message_list.h"
26 #include "sui_completion.h"
27 
28 #define SUI_TYPE_BUFFER (sui_buffer_get_type())
29 #define SUI_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SUI_TYPE_BUFFER, SuiBuffer))
30 #define SUI_IS_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SUI_TYPE_BUFFER))
31 #define SUI_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SUI_TYPE_BUFFER, SuiBufferClass))
32 #define SUI_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SUI_TYPE_BUFFER, SuiBufferClass))
33 
34 typedef struct _SuiBuffer SuiBuffer;
35 typedef struct _SuiBufferClass SuiBufferClass;
36 
37 struct _SuiBuffer {
38     GtkBox parent;
39 
40     SrnChat *ctx;
41     SuiBufferEvents *events;
42     SuiBufferConfig *cfg;
43 
44     /* Menus */
45     GtkMenu *menu;
46     GtkCheckMenuItem *topic_menu_item;
47 
48     /* Topic */
49     GtkRevealer *topic_revealer;
50     GtkLabel *topic_label;
51 
52     /* User list */
53     // FIXME: this is part of SuiChatBuffer
54     GtkRevealer *user_list_revealer;
55 
56     /* Message list */
57     GtkBox *msg_list_box;
58     SuiMessageList *msg_list;
59 
60     GtkTextBuffer *input_text_buffer;
61     SuiCompletion *completion;
62     GList *input_history;
63     GList *input_history_iter;
64     GList *input_stage;
65 };
66 
67 struct _SuiBufferClass {
68     GtkBoxClass parent_class;
69 
70     // SuiBuffer and its child class should implement this functions for input
71     // completing.
72     GtkListStore* (*completion_func)(SuiBuffer *self, const char *context);
73 };
74 
75 GType sui_buffer_get_type(void);
76 
77 void sui_buffer_insert_text(SuiBuffer *self, const char *text, int line, int offset);
78 void sui_buffer_show_topic(SuiBuffer *self, bool show);
79 void sui_buffer_complete(SuiBuffer *self);
80 GtkTreeModel* sui_buffer_completion_func(const char *context, void *user_data);
81 bool sui_buffer_send_input(SuiBuffer *self);
82 void sui_buffer_browse_prev_input(SuiBuffer *self);
83 void sui_buffer_browse_next_input(SuiBuffer *self);
84 
85 void* sui_buffer_get_ctx(SuiBuffer *self);
86 SuiBufferEvents* sui_buffer_get_events(SuiBuffer *self);
87 void sui_buffer_set_config(SuiBuffer *self, SuiBufferConfig *cfg);
88 SuiBufferConfig* sui_buffer_get_config(SuiBuffer *self);
89 const char* sui_buffer_get_name(SuiBuffer *self);
90 const char* sui_buffer_get_remark(SuiBuffer *self);
91 void sui_buffer_set_topic(SuiBuffer *self, const char *topic);
92 void sui_buffer_set_topic_setter(SuiBuffer *self, const char *setter);
93 GtkMenu* sui_buffer_get_menu(SuiBuffer *self);
94 SuiMessageList* sui_buffer_get_message_list(SuiBuffer *self);
95 GtkTextBuffer* sui_buffer_get_input_text_buffer(SuiBuffer *self);
96 
97 #endif /* __SUI_BUFFER_H */
98