399888dc8f389e546c29253ce380531c65945d96
[dana/openbox.git] / obrender / button.c
1 #include "render.h"
2 #include "button.h"
3 #include "instance.h"
4
5 #include <X11/Xlib.h>
6 #include <X11/Xutil.h>
7 #include <string.h>
8
9 RrButton *RrButtonNew (const RrInstance *inst)
10 {
11     RrButton *out = NULL;
12
13     out = g_new(RrButton, 1);
14     out->inst = inst;
15
16     /* no need to alloc colors, set them null (for freeing later) */
17     out->focused_unpressed_color = NULL;
18     out->unfocused_unpressed_color = NULL;
19     out->focused_pressed_color = NULL;
20     out->unfocused_pressed_color = NULL;
21     out->disabled_focused_color = NULL;
22     out->disabled_unfocused_color = NULL;
23     out->hover_focused_color = NULL;
24     out->hover_unfocused_color = NULL;
25     out->toggled_hover_focused_color = NULL;
26     out->toggled_hover_unfocused_color = NULL;
27     out->toggled_focused_pressed_color = NULL;
28     out->toggled_unfocused_pressed_color = NULL;
29     out->toggled_focused_unpressed_color = NULL;
30     out->toggled_unfocused_unpressed_color = NULL;
31
32     /* same with masks */
33     out->mask = NULL;
34     out->pressed_mask = NULL;
35     out->disabled_mask = NULL;
36     out->hover_mask = NULL;
37     out->toggled_mask = NULL;
38     out->toggled_hover_mask = NULL;
39     out->toggled_pressed_mask = NULL;
40
41     /* allocate appearances */
42     out->a_focused_unpressed = RrAppearanceNew(inst, 1);
43     out->a_unfocused_unpressed = RrAppearanceNew(inst, 1);
44     out->a_focused_pressed = RrAppearanceNew(inst, 1);
45     out->a_unfocused_pressed = RrAppearanceNew(inst, 1);
46     out->a_disabled_focused = RrAppearanceNew(inst, 1);
47     out->a_disabled_unfocused = RrAppearanceNew(inst, 1);
48     out->a_hover_focused = RrAppearanceNew(inst, 1);
49     out->a_hover_unfocused = RrAppearanceNew(inst, 1);
50     out->a_toggled_focused_unpressed = RrAppearanceNew(inst, 1);
51     out->a_toggled_unfocused_unpressed = RrAppearanceNew(inst, 1);
52     out->a_toggled_focused_pressed = RrAppearanceNew(inst, 1);
53     out->a_toggled_unfocused_pressed = RrAppearanceNew(inst, 1);
54     out->a_toggled_hover_focused = RrAppearanceNew(inst, 1);
55     out->a_toggled_hover_unfocused = RrAppearanceNew(inst, 1);
56
57     return out;
58 }
59
60 void RrButtonFree(RrButton* b)
61 {
62     /* colors */
63     if (b->focused_unpressed_color) 
64         RrColorFree(b->focused_unpressed_color);
65     if (b->unfocused_unpressed_color) 
66         RrColorFree(b->unfocused_unpressed_color);
67     if (b->focused_pressed_color) 
68         RrColorFree(b->focused_pressed_color);
69     if (b->unfocused_pressed_color) 
70         RrColorFree(b->unfocused_pressed_color);
71     if (b->disabled_focused_color) 
72         RrColorFree(b->disabled_focused_color);
73     if (b->disabled_unfocused_color) 
74         RrColorFree(b->disabled_unfocused_color);
75     if (b->hover_focused_color) 
76         RrColorFree(b->hover_focused_color);
77     if (b->hover_unfocused_color) 
78         RrColorFree(b->hover_unfocused_color);
79     if (b->toggled_hover_focused_color) 
80         RrColorFree(b->toggled_hover_focused_color);
81     if (b->toggled_hover_unfocused_color) 
82         RrColorFree(b->toggled_hover_unfocused_color);
83     if (b->toggled_focused_pressed_color) 
84         RrColorFree(b->toggled_focused_pressed_color);
85     if (b->toggled_unfocused_pressed_color) 
86         RrColorFree(b->toggled_unfocused_pressed_color);
87     if (b->toggled_focused_unpressed_color) 
88         RrColorFree(b->toggled_focused_unpressed_color);
89     if (b->toggled_unfocused_unpressed_color) 
90         RrColorFree(b->toggled_unfocused_unpressed_color);
91
92     /* masks */
93     if (mask) RrPixmapMaskFree(mask);
94     if (pressed_mask) RrPixmapMaskFree(pressed_mask);
95     if (disabled_mask) RrPixmapMaskFree(disabled_mask);
96     if (hover_mask) RrPixmapMaskFree(hover_mask);
97     if (toggled_mask) RrPixmapMaskFree(toggled_mask);
98     if (toggled_hover_mask) RrPixmapMaskFree(toggled_hover_mask);
99     if (toggled_pressed_mask) RrPixmapMaskFree(toggled_pressed_mask);
100
101     /* appearances */
102     RrAppearanceFree(a_focused_unpressed);
103     RrAppearanceFree(a_unfocused_unpressed);
104     RrAppearanceFree(a_focused_pressed);
105     RrAppearanceFree(a_unfocused_pressed);
106     RrAppearanceFree(a_disabled_focused);
107     RrAppearanceFree(a_disabled_unfocused);
108     RrAppearanceFree(a_hover_focused);
109     RrAppearanceFree(a_hover_unfocused);
110     RrAppearanceFree(a_toggled_focused_unpressed);
111     RrAppearanceFree(a_toggled_unfocused_unpressed);
112     RrAppearanceFree(a_toggled_focused_pressed);
113     RrAppearanceFree(a_toggled_unfocused_pressed);
114     RrAppearanceFree(a_toggled_hover_focused);
115     RrAppearanceFree(a_toggled_hover_unfocused);
116 }