source: trunk/third/gnome-panel/gnome-panel/edge-widget.c @ 18631

Revision 18631, 6.2 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18630, which included commits to RCS files with non-trunk default branches.
Line 
1/* Gnome panel: edge (snapped) widget
2 * (C) 1999 the Free Software Foundation
3 *
4 * Authors:  Jacob Berkman
5 *           George Lebl
6 */
7
8#include "config.h"
9#include "edge-widget.h"
10#include "panel-config-global.h"
11#include "foobar-widget.h"
12#include "multiscreen-stuff.h"
13
14extern GlobalConfig global_config;
15extern int pw_minimized_size;
16
17static void edge_pos_class_init (EdgePosClass *klass);
18static void edge_pos_instance_init (EdgePos *pos);
19
20static void edge_pos_set_pos (BasePWidget *basep,
21                              int x, int y,
22                              int w, int h,
23                              gboolean force);
24static void edge_pos_get_pos (BasePWidget *basep,
25                              int *x, int *y,
26                              int w, int h);
27
28static void edge_pos_get_size (BasePWidget *basep,
29                               int *w, int *h);
30
31static void edge_pos_pre_convert_hook (BasePWidget *basep);
32
33static BorderPosClass *edge_pos_parent_class;
34
35GType
36edge_pos_get_type (void)
37{
38        static GType object_type = 0;
39
40        if (object_type == 0) {
41                static const GTypeInfo object_info = {
42                    sizeof (EdgePosClass),
43                    (GBaseInitFunc)         NULL,
44                    (GBaseFinalizeFunc)     NULL,
45                    (GClassInitFunc)        edge_pos_class_init,
46                    NULL,                   /* class_finalize */
47                    NULL,                   /* class_data */
48                    sizeof (EdgePos),
49                    0,                      /* n_preallocs */
50                    (GInstanceInitFunc)     edge_pos_instance_init
51                };
52
53                object_type = g_type_register_static (BORDER_TYPE_POS, "EdgePos", &object_info, 0);
54                edge_pos_parent_class = g_type_class_ref (BORDER_TYPE_POS);
55        }
56                               
57        return object_type;
58}
59
60static void
61edge_pos_class_init (EdgePosClass *klass)
62{
63        BasePPosClass *pos_class = BASEP_POS_CLASS(klass);
64
65        pos_class->set_pos = edge_pos_set_pos;
66        pos_class->get_pos = edge_pos_get_pos;
67        pos_class->get_size = edge_pos_get_size;
68        pos_class->pre_convert_hook = edge_pos_pre_convert_hook;
69}
70
71static void
72edge_pos_instance_init (EdgePos *pos) { }
73
74static void
75edge_pos_set_pos (BasePWidget *basep,
76                  int x, int y,
77                  int w, int h,
78                  gboolean force)
79{
80        BorderEdge newloc;
81        int innerx, innery;
82        int screen_width, screen_height;
83       
84        if ( ! force) {
85                int minx, miny, maxx, maxy;
86
87                gdk_window_get_geometry (GTK_WIDGET (basep)->window,
88                                         &minx, &miny, &maxx, &maxy, NULL);
89                gdk_window_get_origin (GTK_WIDGET (basep)->window,
90                                       &minx, &miny);
91
92                newloc = BORDER_POS(basep->pos)->edge;
93
94                maxx += minx;
95                maxy += miny;
96
97                if (x >= minx &&
98                    x <= maxx &&
99                    y >= miny &&
100                    y <= maxy)
101                        return;
102        }
103       
104        innerx = x - multiscreen_x (basep->screen, basep->monitor);
105        innery = y - multiscreen_y (basep->screen, basep->monitor);
106        screen_width = multiscreen_width (basep->screen, basep->monitor);
107        screen_height = multiscreen_height (basep->screen, basep->monitor);
108
109        if ( innerx > (screen_width / 3) &&
110             innerx < (2*screen_width / 3) &&
111             innery > (screen_height / 3) &&
112             innery < (2*screen_height / 3))
113                return;
114
115        if (innerx * screen_height > innery * screen_width) {
116                if (screen_height * (screen_width - innerx) >
117                    innery * screen_width)
118                        newloc = BORDER_TOP;
119                else
120                        newloc = BORDER_RIGHT;
121        } else {
122                if (screen_height * (screen_width - innerx) >
123                    innery * screen_width)
124                        newloc = BORDER_LEFT;
125                else
126                        newloc = BORDER_BOTTOM;
127        }
128        if (newloc != BORDER_POS (basep->pos)->edge)
129                border_widget_change_edge (BORDER_WIDGET (basep), newloc);
130}
131
132static void
133edge_pos_get_pos (BasePWidget *basep,
134                  int         *x,
135                  int         *y,
136                  int          w,
137                  int          h)
138{
139        BorderEdge edge;
140
141        *x = *y = 0;
142
143        edge = BORDER_POS (basep->pos)->edge;
144
145        switch (edge) {
146        case BORDER_RIGHT:
147                basep_border_get (basep, BORDER_TOP, NULL, NULL, y);
148                *y += foobar_widget_get_height (basep->screen, basep->monitor);
149                *x = multiscreen_width (basep->screen, basep->monitor) - w;
150                break;
151        case BORDER_LEFT:
152                basep_border_get (basep, BORDER_TOP, y, NULL, NULL);
153                *y += foobar_widget_get_height (basep->screen, basep->monitor);
154                break;
155        case BORDER_TOP:
156                *y = foobar_widget_get_height (basep->screen, basep->monitor);
157                break;
158        case BORDER_BOTTOM:
159                *y = multiscreen_height (basep->screen, basep->monitor) - h;
160                break;
161        }
162
163        *x += multiscreen_x (basep->screen, basep->monitor);
164        *y += multiscreen_y (basep->screen, basep->monitor);
165
166        basep_border_queue_recalc (basep->screen, basep->monitor);
167}
168
169static void
170edge_pos_get_size (BasePWidget *basep, int *w, int *h)
171{
172        BorderEdge edge = BORDER_POS (basep->pos)->edge;
173        int        a, b;
174
175        switch (edge) {
176        case BORDER_RIGHT:
177                basep_border_get (basep, BORDER_TOP, NULL, NULL, &a);
178                basep_border_get (basep, BORDER_BOTTOM, NULL, NULL, &b);
179                *h = multiscreen_height (basep->screen, basep->monitor) -
180                     foobar_widget_get_height (basep->screen, basep->monitor) - a - b;
181                break;
182        case BORDER_LEFT:
183                basep_border_get (basep, BORDER_TOP, &a, NULL, NULL);
184                basep_border_get (basep, BORDER_BOTTOM, &b, NULL, NULL);
185                *h = multiscreen_height (basep->screen, basep->monitor) -
186                     foobar_widget_get_height (basep->screen, basep->monitor) - a - b;
187                break;
188        case BORDER_TOP:
189        case BORDER_BOTTOM:
190                *w = multiscreen_width (basep->screen, basep->monitor);
191                break;
192        }
193}
194
195static void
196edge_pos_pre_convert_hook (BasePWidget *basep)
197{
198        basep->keep_in_screen = TRUE;
199        PANEL_WIDGET (basep->panel)->packed = FALSE;
200}
201
202GtkWidget *
203edge_widget_new (const char *panel_id,
204                 int screen,
205                 int monitor,
206                 BorderEdge edge,
207                 BasePMode mode,
208                 BasePState state,
209                 int sz,
210                 gboolean hidebuttons_enabled,
211                 gboolean hidebutton_pixmaps_enabled,
212                 PanelBackgroundType back_type,
213                 const char *back_pixmap,
214                 gboolean fit_pixmap_bg,
215                 gboolean stretch_pixmap_bg,
216                 gboolean rotate_pixmap_bg,
217                 PanelColor *back_color)
218{
219        EdgeWidget  *edgew;
220        BasePWidget *basep;
221
222        edgew = g_object_new (EDGE_TYPE_WIDGET, NULL);
223        basep = BASEP_WIDGET (edgew);
224
225        basep->pos = g_object_new (EDGE_TYPE_POS, NULL);
226
227        border_widget_construct (panel_id,
228                                 BORDER_WIDGET (basep),
229                                 screen,
230                                 monitor,
231                                 edge,
232                                 FALSE, FALSE,
233                                 sz, mode, state,
234                                 hidebuttons_enabled,
235                                 hidebutton_pixmaps_enabled,
236                                 back_type, back_pixmap,
237                                 fit_pixmap_bg, stretch_pixmap_bg,
238                                 rotate_pixmap_bg,
239                                 back_color);
240
241        PANEL_WIDGET (basep->panel)->packed = FALSE;
242       
243        return GTK_WIDGET (edgew);
244}
Note: See TracBrowser for help on using the repository browser.