Yet another try to get 0.51.2-pre2 in cvs
[wmaker-crm.git] / WINGs / wframe.c
blob1811c87cd27e6817027073758ad3a9a34925e9ed
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:3;
14 WMTitlePosition titlePosition:3;
15 } flags;
16 } Frame;
20 struct W_ViewProcedureTable _FrameViewProcedures = {
21 NULL,
22 NULL,
23 NULL
27 #define DEFAULT_RELIEF WRGroove
28 #define DEFAULT_TITLE_POSITION WTPAtTop
29 #define DEFAULT_WIDTH 40
30 #define DEFAULT_HEIGHT 40
33 static void destroyFrame(Frame *fPtr);
34 static void paintFrame(Frame *fPtr);
38 void
39 WMSetFrameTitlePosition(WMFrame *fPtr, WMTitlePosition position)
41 fPtr->flags.titlePosition = position;
43 if (fPtr->view->flags.realized) {
44 paintFrame(fPtr);
49 void
50 WMSetFrameRelief(WMFrame *fPtr, WMReliefType relief)
52 fPtr->flags.relief = relief;
54 if (fPtr->view->flags.realized) {
55 paintFrame(fPtr);
60 void
61 WMSetFrameTitle(WMFrame *fPtr, char *title)
63 if (fPtr->caption)
64 free(fPtr->caption);
65 if (title)
66 fPtr->caption = wstrdup(title);
67 else
68 fPtr->caption = NULL;
70 if (fPtr->view->flags.realized) {
71 paintFrame(fPtr);
76 static void
77 paintFrame(Frame *fPtr)
79 W_View *view = fPtr->view;
80 W_Screen *scrPtr = view->screen;
81 int tx, ty, tw, th;
82 int fy, fh;
84 if (fPtr->caption!=NULL)
85 th = WMFontHeight(scrPtr->normalFont);
86 else {
87 th = 0;
90 fh = view->size.height;
91 fy = 0;
93 switch (fPtr->flags.titlePosition) {
94 case WTPAboveTop:
95 ty = 0;
96 fy = th + 4;
97 fh = view->size.height - fy;
98 break;
100 case WTPAtTop:
101 ty = 0;
102 fy = th/2;
103 fh = view->size.height - fy;
104 break;
106 case WTPBelowTop:
107 ty = 4;
108 fy = 0;
109 fh = view->size.height;
110 break;
112 case WTPAboveBottom:
113 ty = view->size.height - th - 4;
114 fy = 0;
115 fh = view->size.height;
116 break;
118 case WTPAtBottom:
119 ty = view->size.height - th;
120 fy = 0;
121 fh = view->size.height - th/2;
122 break;
124 case WTPBelowBottom:
125 ty = view->size.height - th;
126 fy = 0;
127 fh = view->size.height - th - 4;
128 break;
130 default:
131 ty = 0;
132 fy = 0;
133 fh = view->size.height;
136 XClearArea(scrPtr->display, view->window, fy+2, 2, fh-4, view->size.width-4,
137 False);
139 XClearWindow(scrPtr->display, view->window);
141 W_DrawRelief(scrPtr, view->window, 0, fy, view->size.width, fh,
142 fPtr->flags.relief);
144 if (fPtr->caption!=NULL && fPtr->flags.titlePosition!=WTPNoTitle) {
147 tw = WMWidthOfString(scrPtr->normalFont, fPtr->caption,
148 strlen(fPtr->caption));
150 tx = (view->size.width - tw) / 2;
152 XFillRectangle(scrPtr->display, view->window, WMColorGC(scrPtr->gray),
153 tx, ty, tw, th);
155 WMDrawString(scrPtr, view->window, WMColorGC(scrPtr->black),
156 scrPtr->normalFont, tx, ty, fPtr->caption,
157 strlen(fPtr->caption));
165 static void
166 handleEvents(XEvent *event, void *data)
168 Frame *fPtr = (Frame*)data;
170 CHECK_CLASS(data, WC_Frame);
172 switch (event->type) {
173 case Expose:
174 if (event->xexpose.count!=0)
175 break;
176 paintFrame(fPtr);
177 break;
179 case DestroyNotify:
180 destroyFrame(fPtr);
181 break;
186 WMFrame*
187 WMCreateFrame(WMWidget *parent)
189 Frame *fPtr;
191 fPtr = wmalloc(sizeof(Frame));
192 memset(fPtr, 0, sizeof(Frame));
194 fPtr->widgetClass = WC_Frame;
196 fPtr->view = W_CreateView(W_VIEW(parent));
197 if (!fPtr->view) {
198 free(fPtr);
199 return NULL;
201 fPtr->view->self = fPtr;
203 WMCreateEventHandler(fPtr->view, ExposureMask|StructureNotifyMask,
204 handleEvents, fPtr);
207 fPtr->flags.relief = DEFAULT_RELIEF;
208 fPtr->flags.titlePosition = DEFAULT_TITLE_POSITION;
210 WMResizeWidget(fPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT);
212 return fPtr;
216 static void
217 destroyFrame(Frame *fPtr)
219 if (fPtr->caption)
220 free(fPtr->caption);
222 free(fPtr);