fixed many bugs, removed linked list
[wmaker-crm.git] / WINGs / wframe.c
blob8d2e17be043285faceba9f0d7e2204451707b07e
2 #include "WINGsP.h"
5 typedef struct W_Frame {
6 W_Class widgetClass;
7 W_View *view;
9 char *caption;
12 struct {
13 WMReliefType relief:4;
14 WMTitlePosition titlePosition:4;
15 } flags;
16 } Frame;
19 #define DEFAULT_RELIEF WRGroove
20 #define DEFAULT_TITLE_POSITION WTPAtTop
21 #define DEFAULT_WIDTH 40
22 #define DEFAULT_HEIGHT 40
25 static void destroyFrame(Frame *fPtr);
26 static void paintFrame(Frame *fPtr);
30 void
31 WMSetFrameTitlePosition(WMFrame *fPtr, WMTitlePosition position)
33 fPtr->flags.titlePosition = position;
35 if (fPtr->view->flags.realized) {
36 paintFrame(fPtr);
41 void
42 WMSetFrameRelief(WMFrame *fPtr, WMReliefType relief)
44 fPtr->flags.relief = relief;
46 if (fPtr->view->flags.realized) {
47 paintFrame(fPtr);
52 void
53 WMSetFrameTitle(WMFrame *fPtr, char *title)
55 if (fPtr->caption)
56 free(fPtr->caption);
57 if (title)
58 fPtr->caption = wstrdup(title);
59 else
60 fPtr->caption = NULL;
62 if (fPtr->view->flags.realized) {
63 paintFrame(fPtr);
68 static void
69 paintFrame(Frame *fPtr)
71 W_View *view = fPtr->view;
72 W_Screen *scrPtr = view->screen;
73 int tx, ty, tw, th;
74 int fy, fh;
76 if (fPtr->caption!=NULL)
77 th = WMFontHeight(scrPtr->normalFont);
78 else {
79 th = 0;
82 fh = view->size.height;
83 fy = 0;
85 switch (fPtr->flags.titlePosition) {
86 case WTPAboveTop:
87 ty = 0;
88 fy = th + 4;
89 fh = view->size.height - fy;
90 break;
92 case WTPAtTop:
93 ty = 0;
94 fy = th/2;
95 fh = view->size.height - fy;
96 break;
98 case WTPBelowTop:
99 ty = 4;
100 fy = 0;
101 fh = view->size.height;
102 break;
104 case WTPAboveBottom:
105 ty = view->size.height - th - 4;
106 fy = 0;
107 fh = view->size.height;
108 break;
110 case WTPAtBottom:
111 ty = view->size.height - th;
112 fy = 0;
113 fh = view->size.height - th/2;
114 break;
116 case WTPBelowBottom:
117 ty = view->size.height - th;
118 fy = 0;
119 fh = view->size.height - th - 4;
120 break;
122 default:
123 ty = 0;
124 fy = 0;
125 fh = view->size.height;
128 XClearArea(scrPtr->display, view->window, fy+2, 2, fh-4, view->size.width-4,
129 False);
131 XClearWindow(scrPtr->display, view->window);
133 W_DrawRelief(scrPtr, view->window, 0, fy, view->size.width, fh,
134 fPtr->flags.relief);
136 if (fPtr->caption!=NULL && fPtr->flags.titlePosition!=WTPNoTitle) {
139 tw = WMWidthOfString(scrPtr->normalFont, fPtr->caption,
140 strlen(fPtr->caption));
142 tx = (view->size.width - tw) / 2;
144 XFillRectangle(scrPtr->display, view->window, WMColorGC(scrPtr->gray),
145 tx, ty, tw, th);
147 WMDrawString(scrPtr, view->window, WMColorGC(scrPtr->black),
148 scrPtr->normalFont, tx, ty, fPtr->caption,
149 strlen(fPtr->caption));
157 static void
158 handleEvents(XEvent *event, void *data)
160 Frame *fPtr = (Frame*)data;
162 CHECK_CLASS(data, WC_Frame);
164 switch (event->type) {
165 case Expose:
166 if (event->xexpose.count!=0)
167 break;
168 paintFrame(fPtr);
169 break;
171 case DestroyNotify:
172 destroyFrame(fPtr);
173 break;
178 WMFrame*
179 WMCreateFrame(WMWidget *parent)
181 Frame *fPtr;
183 fPtr = wmalloc(sizeof(Frame));
184 memset(fPtr, 0, sizeof(Frame));
186 fPtr->widgetClass = WC_Frame;
188 fPtr->view = W_CreateView(W_VIEW(parent));
189 if (!fPtr->view) {
190 free(fPtr);
191 return NULL;
193 fPtr->view->self = fPtr;
195 WMCreateEventHandler(fPtr->view, ExposureMask|StructureNotifyMask,
196 handleEvents, fPtr);
199 fPtr->flags.relief = DEFAULT_RELIEF;
200 fPtr->flags.titlePosition = DEFAULT_TITLE_POSITION;
202 WMResizeWidget(fPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT);
204 return fPtr;
208 static void
209 destroyFrame(Frame *fPtr)
211 if (fPtr->caption)
212 free(fPtr->caption);
214 free(fPtr);