summaryrefslogtreecommitdiff
path: root/src/gui/gui-panel.c
blob: 4fff4757ddb61b14c2ecba8eb6b9c8695513f00e (plain)
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
/*
 * Copyright (c) 2003-2007 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/* gui-panel.c: panel functions, used by all GUI */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <ctype.h>

#include "../common/weechat.h"
#include "gui.h"
#include "../common/log.h"


t_gui_panel *gui_panels = NULL;             /* pointer to first panel       */
t_gui_panel *last_gui_panel = NULL;         /* pointer to last panel        */


/*
 * gui_panel_global_get_size: get total panel size (global panels) for a position
 */

int
gui_panel_global_get_size (t_gui_panel *panel, int position)
{
    t_gui_panel *ptr_panel;
    int total_size;

    total_size = 0;
    for (ptr_panel = gui_panels; ptr_panel; ptr_panel = ptr_panel->next_panel)
    {
        if ((panel) && (ptr_panel == panel))
            return total_size;
        
        if (ptr_panel->position == position)
        {
            switch (position)
            {
                case GUI_PANEL_TOP:
                case GUI_PANEL_BOTTOM:
                    total_size += ptr_panel->size;
                    break;
                case GUI_PANEL_LEFT:
                case GUI_PANEL_RIGHT:
                    total_size += ptr_panel->size;
                    break;
            }
            if (ptr_panel->separator)
                total_size++;
        }
    }
    return total_size;
}

/*
 * gui_panel_new: create a new panel
 */

t_gui_panel *
gui_panel_new (char *name, int type, int position, int size, int separator)
{
    t_gui_panel *new_panel;
    t_gui_window *ptr_win;

    if (!name || !name[0])
        return NULL;
    
    if ((new_panel = (t_gui_panel *) malloc (sizeof (t_gui_panel))))
    {
        new_panel->number = (last_gui_panel) ? last_gui_panel->number + 1 : 1;
        new_panel->name = strdup (name);
        new_panel->position = position;
        new_panel->separator = separator;
        new_panel->size = size;
        if (type == GUI_PANEL_WINDOWS)
        {
            /* create panel window for all opened windows */
            for (ptr_win = gui_windows; ptr_win;
                 ptr_win = ptr_win->next_window)
                gui_panel_window_new (new_panel, ptr_win);
        }
        else
            /* create only one panel window (global) */
            gui_panel_window_new (new_panel, NULL);
        
        /* add panel to panels queue */
        new_panel->prev_panel = last_gui_panel;
        if (gui_panels)
            last_gui_panel->next_panel = new_panel;
        else
            gui_panels = new_panel;
        last_gui_panel = new_panel;
        new_panel->next_panel = NULL;
        
        return new_panel;
    }
    else
        return NULL;
}

/*
 * gui_panel_free: delete a panel
 */

void
gui_panel_free (t_gui_panel *panel)
{
    /* remove panel from panels list */
    if (panel->prev_panel)
        panel->prev_panel->next_panel = panel->next_panel;
    if (panel->next_panel)
        panel->next_panel->prev_panel = panel->prev_panel;
    if (gui_panels == panel)
        gui_panels = panel->next_panel;
    if (last_gui_panel == panel)
        last_gui_panel = panel->prev_panel;

    /* free data */
    if (panel->name)
        free (panel->name);
    if (panel->panel_window)
        gui_panel_window_free (panel->panel_window);
    
    free (panel);
}

/*
 * gui_panel_print_log: print panel infos in log (usually for crash dump)
 */

void
gui_panel_print_log ()
{
    t_gui_panel *ptr_panel;

    for (ptr_panel = gui_panels; ptr_panel; ptr_panel = ptr_panel->next_panel)
    {
        weechat_log_printf ("\n");
        weechat_log_printf ("[panel (addr:0x%X)]\n", ptr_panel);
        weechat_log_printf ("  position. . . . . . : %d\n",   ptr_panel->position);
        weechat_log_printf ("  name. . . . . . . . : '%s'\n", ptr_panel->name);
        weechat_log_printf ("  panel_window. . . . : 0x%X\n", ptr_panel->panel_window);
        weechat_log_printf ("  separator . . . . . : %d\n",   ptr_panel->separator);
        weechat_log_printf ("  size. . . . . . . . : %d\n",   ptr_panel->size);
        weechat_log_printf ("  prev_panel . .. . . : 0x%X\n", ptr_panel->prev_panel);
        weechat_log_printf ("  next_panel . .. . . : 0x%X\n", ptr_panel->next_panel);
    }
}