Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / wtabview.c
Commit [+]AuthorDateLineData
dd2d71fc kojima1999-05-15 17:38:05 +00001
2#include "WINGsP.h"
3
dd2d71fc kojima1999-05-15 17:38:05 +00004typedef struct W_TabView {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02005 W_Class widgetClass;
6 W_View *view;
dd2d71fc kojima1999-05-15 17:38:05 +00007
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02008 struct W_TabViewItem **items;
9 int itemCount;
10 int maxItems; /* size of items array, can be increased */
dd2d71fc kojima1999-05-15 17:38:05 +000011
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020012 int selectedItem;
13 int firstVisible;
6830b057 dan2004-10-12 21:28:27 +000014
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020015 int visibleTabs;
dd2d71fc kojima1999-05-15 17:38:05 +000016
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020017 WMFont *font;
dd2d71fc kojima1999-05-15 17:38:05 +000018
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020019 WMColor *lightGray;
20 WMColor *tabColor;
dd2d71fc kojima1999-05-15 17:38:05 +000021
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020022 WMTabViewDelegate *delegate;
aff89828 kojima1999-05-17 03:55:35 +000023
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020024 short tabHeight;
dd2d71fc kojima1999-05-15 17:38:05 +000025
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020026 struct {
27 WMReliefType relief:4;
28 WMTitlePosition titlePosition:4;
29 WMTabViewType type:2;
6830b057 dan2004-10-12 21:28:27 +000030
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020031 unsigned enabled:1;
32 unsigned tabbed:1;
33 unsigned dontFitAll:1;
34 unsigned bordered:1;
35 unsigned uniformTabs:1;
36 } flags;
dd2d71fc kojima1999-05-15 17:38:05 +000037} TabView;
38
65e65c4e dan2002-03-14 12:28:52 +000039typedef struct W_TabViewItem {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020040 WMTabView *tabView;
65e65c4e dan2002-03-14 12:28:52 +000041
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020042 W_View *view;
65e65c4e dan2002-03-14 12:28:52 +000043
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020044 char *label;
65e65c4e dan2002-03-14 12:28:52 +000045
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020046 short tabWidth;
47 int identifier;
65e65c4e dan2002-03-14 12:28:52 +000048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020049 struct {
50 unsigned visible:1;
51 unsigned enabled:1;
52 } flags;
65e65c4e dan2002-03-14 12:28:52 +000053} W_TabViewItem;
54
dd2d71fc kojima1999-05-15 17:38:05 +000055#define DEFAULT_WIDTH 40
56#define DEFAULT_HEIGHT 40
57
93941b2c kojima2000-03-04 00:18:13 +000058#define NORMAL_SIDE_OFFSET 8
e99511b0 kojima2001-01-02 14:17:26 +000059#define BUTTONED_SIDE_OFFSET 15
93941b2c kojima2000-03-04 00:18:13 +000060
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020061static void destroyTabView(TabView * tPtr);
62static void paintTabView(TabView * tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +000063
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020064static void W_SetTabViewItemParent(WMTabViewItem * item, WMTabView * parent);
dd2d71fc kojima1999-05-15 17:38:05 +000065
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020066static void W_DrawLabel(WMTabViewItem * item, Drawable d, WMRect rect, Bool enabled);
dd2d71fc kojima1999-05-15 17:38:05 +000067
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020068static void W_UnmapTabViewItem(WMTabViewItem * item);
dd2d71fc kojima1999-05-15 17:38:05 +000069
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020070static void W_MapTabViewItem(WMTabViewItem * item);
dd2d71fc kojima1999-05-15 17:38:05 +000071
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020072static WMView *W_TabViewItemView(WMTabViewItem * item);
dd2d71fc kojima1999-05-15 17:38:05 +000073
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020074static int W_TabViewItemTabWidth(WMTabViewItem * item);
e99511b0 kojima2001-01-02 14:17:26 +000075
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020076static void W_SetTabViewItemTabWidth(WMTabViewItem * item, int width);
dd2d71fc kojima1999-05-15 17:38:05 +000077
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020078static void recalcTabWidth(TabView * tPtr);
79static void rearrange(TabView * tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +000080
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020081static void didResize(struct W_ViewDelegate *, WMView *);
52308a0a kojima2000-11-11 18:08:10 +000082
83static W_ViewDelegate delegate = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020084 NULL,
85 NULL,
86 didResize,
87 NULL,
88 NULL
52308a0a kojima2000-11-11 18:08:10 +000089};
90
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020091static int positionOfTab(WMTabView * tabView, int tab)
e99511b0 kojima2001-01-02 14:17:26 +000092{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020093 int i;
94 int offs;
6830b057 dan2004-10-12 21:28:27 +000095
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020096 if (tab < tabView->firstVisible)
97 return -1;
6830b057 dan2004-10-12 21:28:27 +000098
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020099 if (tab > tabView->firstVisible + tabView->visibleTabs)
100 return -1;
e99511b0 kojima2001-01-02 14:17:26 +0000101
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200102 if (tabView->flags.dontFitAll)
103 offs = BUTTONED_SIDE_OFFSET;
104 else
105 offs = NORMAL_SIDE_OFFSET;
6830b057 dan2004-10-12 21:28:27 +0000106
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200107 for (i = tabView->firstVisible; i < tab; i++)
108 offs += W_TabViewItemTabWidth(tabView->items[i]) - 10;
6830b057 dan2004-10-12 21:28:27 +0000109
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200110 return offs;
e99511b0 kojima2001-01-02 14:17:26 +0000111}
112
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200113static int countVisibleTabs(TabView * tPtr, int first)
e99511b0 kojima2001-01-02 14:17:26 +0000114{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200115 int i;
116 int width;
e99511b0 kojima2001-01-02 14:17:26 +0000117
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200118 if (first < 0) {
119 width = W_VIEW_WIDTH(tPtr->view) - 2 * NORMAL_SIDE_OFFSET;
120 first = 0;
121 } else {
122 width = W_VIEW_WIDTH(tPtr->view) - 2 * BUTTONED_SIDE_OFFSET;
123 }
52308a0a kojima2000-11-11 18:08:10 +0000124
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200125 for (i = first; i < tPtr->itemCount; i++) {
126 width -= W_TabViewItemTabWidth(tPtr->items[i]) - 10;
127 if (width <= 0) {
128 return i - first;
129 }
130 }
131 return i - first;
132}
52308a0a kojima2000-11-11 18:08:10 +0000133
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200134static void handleEvents(XEvent * event, void *data)
dd2d71fc kojima1999-05-15 17:38:05 +0000135{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200136 TabView *tPtr = (TabView *) data;
137
138 CHECK_CLASS(data, WC_TabView);
139
140 switch (event->type) {
141 case Expose:
142 if (event->xexpose.count != 0)
143 break;
144 paintTabView(tPtr);
145 break;
146
147 case ButtonPress:
148 if (tPtr->flags.enabled) {
149 WMTabViewItem *item = WMTabViewItemAtPoint(tPtr,
150 event->xbutton.x,
151 event->xbutton.y);
152 /*if (item && !item->flags.enabled)
153 break; */
dd2d71fc kojima1999-05-15 17:38:05 +0000154
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200155 if (item && item->flags.enabled) {
156 WMSelectTabViewItem(tPtr, item);
157 } else if (tPtr->flags.dontFitAll) {
158 int redraw = 0;
159 int lastVisible = tPtr->firstVisible + tPtr->visibleTabs - 1;
dd2d71fc kojima1999-05-15 17:38:05 +0000160
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200161 if (event->xbutton.x < BUTTONED_SIDE_OFFSET) {
162 if (tPtr->firstVisible > 0) {
163 redraw = 1;
164 tPtr->firstVisible--;
165 }
166 } else if (event->xbutton.x > positionOfTab(tPtr, lastVisible)) {
dd2d71fc kojima1999-05-15 17:38:05 +0000167
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200168 if (lastVisible < tPtr->itemCount - 1) {
169 redraw = 1;
170 tPtr->firstVisible++;
171 }
172 }
173 tPtr->visibleTabs = countVisibleTabs(tPtr, tPtr->firstVisible);
174 if (redraw) {
175 paintTabView(tPtr);
176 }
177 }
178 }
179 break;
180
181 case DestroyNotify:
182 destroyTabView(tPtr);
183 break;
184 }
185}
186
187WMTabView *WMCreateTabView(WMWidget * parent)
dd2d71fc kojima1999-05-15 17:38:05 +0000188{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200189 TabView *tPtr;
190 WMScreen *scr = WMWidgetScreen(parent);
dd2d71fc kojima1999-05-15 17:38:05 +0000191
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200192 tPtr = wmalloc(sizeof(TabView));
193 memset(tPtr, 0, sizeof(TabView));
dd2d71fc kojima1999-05-15 17:38:05 +0000194
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200195 tPtr->widgetClass = WC_TabView;
dd2d71fc kojima1999-05-15 17:38:05 +0000196
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200197 tPtr->view = W_CreateView(W_VIEW(parent));
198 if (!tPtr->view) {
199 wfree(tPtr);
200 return NULL;
201 }
202 tPtr->view->self = tPtr;
203 tPtr->view->delegate = &delegate;
dd2d71fc kojima1999-05-15 17:38:05 +0000204
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200205 tPtr->lightGray = WMCreateRGBColor(scr, 0xd9d9, 0xd9d9, 0xd9d9, False);
206 tPtr->tabColor = WMCreateRGBColor(scr, 0x8420, 0x8420, 0x8420, False);
dd2d71fc kojima1999-05-15 17:38:05 +0000207
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200208 tPtr->font = WMRetainFont(scr->normalFont);
6830b057 dan2004-10-12 21:28:27 +0000209
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200210 tPtr->flags.type = WTTopTabsBevelBorder;
211 tPtr->flags.bordered = 1;
212 tPtr->flags.uniformTabs = 0;
213 tPtr->flags.enabled = 1;
dd2d71fc kojima1999-05-15 17:38:05 +0000214
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200215 WMCreateEventHandler(tPtr->view, ExposureMask | StructureNotifyMask | ButtonPressMask, handleEvents, tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000216
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200217 WMResizeWidget(tPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT);
dd2d71fc kojima1999-05-15 17:38:05 +0000218
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200219 tPtr->tabHeight = WMFontHeight(tPtr->font) + 3;
dd2d71fc kojima1999-05-15 17:38:05 +0000220
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200221 return tPtr;
dd2d71fc kojima1999-05-15 17:38:05 +0000222}
223
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200224void WMSetTabViewDelegate(WMTabView * tPtr, WMTabViewDelegate * delegate)
aff89828 kojima1999-05-17 03:55:35 +0000225{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200226 tPtr->delegate = delegate;
aff89828 kojima1999-05-17 03:55:35 +0000227}
228
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200229WMTabViewItem *WMAddTabViewItemWithView(WMTabView * tPtr, WMView * view, int identifier, char *label)
1863d60e kojima2000-11-09 14:07:48 +0000230{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200231 WMTabViewItem *item;
6830b057 dan2004-10-12 21:28:27 +0000232
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200233 item = WMCreateTabViewItemWithIdentifier(identifier);
234 WMSetTabViewItemView(item, view);
235 WMAddItemInTabView(tPtr, item);
236 WMSetTabViewItemLabel(item, label);
1863d60e kojima2000-11-09 14:07:48 +0000237
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200238 return item;
1863d60e kojima2000-11-09 14:07:48 +0000239}
240
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200241void WMAddItemInTabView(WMTabView * tPtr, WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000242{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200243 WMInsertItemInTabView(tPtr, tPtr->itemCount, item);
dd2d71fc kojima1999-05-15 17:38:05 +0000244}
245
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200246void WMSetTabViewEnabled(WMTabView * tPtr, Bool flag)
b6f543df kojima2001-01-10 21:10:39 +0000247{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200248 tPtr->flags.enabled = ((flag == 0) ? 0 : 1);
249 if (W_VIEW_REALIZED(tPtr->view))
250 paintTabView(tPtr);
b6f543df kojima2001-01-10 21:10:39 +0000251}
252
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200253void WMInsertItemInTabView(WMTabView * tPtr, int index, WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000254{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200255 wassertr(W_TabViewItemView(item) != NULL);
dd2d71fc kojima1999-05-15 17:38:05 +0000256
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200257 if (tPtr->maxItems == tPtr->itemCount) {
258 WMTabViewItem **items;
dd2d71fc kojima1999-05-15 17:38:05 +0000259
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200260 items = wrealloc(tPtr->items, sizeof(WMTabViewItem *) * (tPtr->maxItems + 10));
261 memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem *) * 10);
262 tPtr->items = items;
263 tPtr->maxItems += 10;
264 }
dd2d71fc kojima1999-05-15 17:38:05 +0000265
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200266 if (index > tPtr->itemCount)
267 index = tPtr->itemCount;
dd2d71fc kojima1999-05-15 17:38:05 +0000268
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200269 if (index == 0 && tPtr->items[0]) {
270 W_UnmapTabViewItem(tPtr->items[0]);
271 }
dd2d71fc kojima1999-05-15 17:38:05 +0000272
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200273 if (index < tPtr->itemCount) {
274 memmove(tPtr->items + index + 1, tPtr->items + index,
275 (tPtr->itemCount - index) * sizeof(WMTabViewItem *));
276 }
dd2d71fc kojima1999-05-15 17:38:05 +0000277
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200278 tPtr->items[index] = item;
dd2d71fc kojima1999-05-15 17:38:05 +0000279
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200280 tPtr->itemCount++;
dd2d71fc kojima1999-05-15 17:38:05 +0000281
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200282 recalcTabWidth(tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000283
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200284 W_SetTabViewItemParent(item, tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000285
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200286 W_UnmapTabViewItem(item);
dd2d71fc kojima1999-05-15 17:38:05 +0000287
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200288 if (tPtr->flags.bordered) {
289 W_ReparentView(W_TabViewItemView(item), tPtr->view, 1, tPtr->tabHeight + 1);
dd2d71fc kojima1999-05-15 17:38:05 +0000290
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200291 W_ResizeView(W_TabViewItemView(item), tPtr->view->size.width - 3,
292 tPtr->view->size.height - tPtr->tabHeight - 3);
293 } else {
294 W_ReparentView(W_TabViewItemView(item), tPtr->view, 0, tPtr->tabHeight);
e99511b0 kojima2001-01-02 14:17:26 +0000295
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200296 W_ResizeView(W_TabViewItemView(item), tPtr->view->size.width,
297 tPtr->view->size.height - tPtr->tabHeight);
298 }
dd2d71fc kojima1999-05-15 17:38:05 +0000299
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200300 if (index == 0) {
301 W_MapTabViewItem(item);
302 }
303 if (tPtr->delegate && tPtr->delegate->didChangeNumberOfItems)
304 (*tPtr->delegate->didChangeNumberOfItems) (tPtr->delegate, tPtr);
6830b057 dan2004-10-12 21:28:27 +0000305
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200306 if (W_VIEW_REALIZED(tPtr->view))
307 paintTabView(tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000308}
309
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200310void WMRemoveTabViewItem(WMTabView * tPtr, WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000311{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200312 int i;
dd2d71fc kojima1999-05-15 17:38:05 +0000313
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200314 for (i = 0; i < tPtr->itemCount; i++) {
315 if (tPtr->items[i] == item) {
316 if (i < tPtr->itemCount - 1)
317 memmove(&tPtr->items[i], &tPtr->items[i + 1], tPtr->itemCount - i - 1);
318 else
319 tPtr->items[i] = NULL;
dd2d71fc kojima1999-05-15 17:38:05 +0000320
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200321 W_SetTabViewItemParent(item, NULL);
dd2d71fc kojima1999-05-15 17:38:05 +0000322
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200323 tPtr->itemCount--;
324 break;
325 }
326 }
327 if (tPtr->delegate && tPtr->delegate->didChangeNumberOfItems)
328 (*tPtr->delegate->didChangeNumberOfItems) (tPtr->delegate, tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000329}
330
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200331static Bool isInside(int x, int y, int width, int height, int px, int py)
dd2d71fc kojima1999-05-15 17:38:05 +0000332{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200333 if (py >= y + height - 3 && py <= y + height && px >= x + py - (y + height - 3)
334 && px <= x + width - (py - (y + height - 3))) {
335
336 return True;
337 }
338 if (py >= y + 3 && py < y + height - 3
339 && px >= x + 3 + ((y + 3) - py) * 3 / 7 && px <= x + width - 3 - ((y + 3) - py) * 3 / 7) {
dd2d71fc kojima1999-05-15 17:38:05 +0000340
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200341 return True;
342 }
343 if (py >= y && py < y + 3 && px >= x + 7 + py - y && px <= x + width - 7 - (py - y)) {
344
345 return True;
346 }
347 return False;
348}
dd2d71fc kojima1999-05-15 17:38:05 +0000349
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200350WMTabViewItem *WMTabViewItemAtPoint(WMTabView * tPtr, int x, int y)
e4dbd1fe kojima2000-11-13 13:22:22 +0000351{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200352 int i;
353 int count = tPtr->visibleTabs;
354 int first = tPtr->firstVisible;
6830b057 dan2004-10-12 21:28:27 +0000355
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200356 if (tPtr->flags.dontFitAll) {
357 i = tPtr->selectedItem - tPtr->firstVisible;
358 if (i >= 0 && i < tPtr->visibleTabs
359 && isInside(positionOfTab(tPtr, tPtr->selectedItem), 0,
360 W_TabViewItemTabWidth(tPtr->items[tPtr->selectedItem]), tPtr->tabHeight, x, y)) {
361 return tPtr->items[tPtr->selectedItem];
362 }
363 } else {
364 i = tPtr->selectedItem;
365 if (isInside(positionOfTab(tPtr, i), 0,
366 W_TabViewItemTabWidth(tPtr->items[i]), tPtr->tabHeight, x, y)) {
367 return tPtr->items[i];
368 }
369 }
6830b057 dan2004-10-12 21:28:27 +0000370
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200371 for (i = first; i < first + count; i++) {
372 int pos;
6830b057 dan2004-10-12 21:28:27 +0000373
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200374 pos = positionOfTab(tPtr, i);
375 if (isInside(pos, 0, W_TabViewItemTabWidth(tPtr->items[i]), tPtr->tabHeight, x, y)) {
376 return tPtr->items[i];
377 }
378 }
379 return NULL;
e4dbd1fe kojima2000-11-13 13:22:22 +0000380}
381
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200382void WMSetTabViewType(WMTabView * tPtr, WMTabViewType type)
dd2d71fc kojima1999-05-15 17:38:05 +0000383{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200384 tPtr->flags.type = type;
dd2d71fc kojima1999-05-15 17:38:05 +0000385
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200386 if (type != WTTopTabsBevelBorder)
387 tPtr->tabHeight = 0;
388 else
389 tPtr->tabHeight = WMFontHeight(tPtr->font) + 3;
dd2d71fc kojima1999-05-15 17:38:05 +0000390
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200391 if (type == WTNoTabsNoBorder)
392 tPtr->flags.bordered = 0;
393 else
394 tPtr->flags.bordered = 1;
dd2d71fc kojima1999-05-15 17:38:05 +0000395
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200396 rearrange(tPtr);
397}
dd2d71fc kojima1999-05-15 17:38:05 +0000398
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200399void WMSelectFirstTabViewItem(WMTabView * tPtr)
dd2d71fc kojima1999-05-15 17:38:05 +0000400{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200401 WMSelectTabViewItemAtIndex(tPtr, 0);
dd2d71fc kojima1999-05-15 17:38:05 +0000402}
403
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200404void WMSelectLastTabViewItem(WMTabView * tPtr)
dd2d71fc kojima1999-05-15 17:38:05 +0000405{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200406 WMSelectTabViewItemAtIndex(tPtr, tPtr->itemCount);
dd2d71fc kojima1999-05-15 17:38:05 +0000407}
408
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200409void WMSelectNextTabViewItem(WMTabView * tPtr)
dd2d71fc kojima1999-05-15 17:38:05 +0000410{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200411 WMSelectTabViewItemAtIndex(tPtr, tPtr->selectedItem + 1);
dd2d71fc kojima1999-05-15 17:38:05 +0000412}
413
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200414void WMSelectPreviousTabViewItem(WMTabView * tPtr)
dd2d71fc kojima1999-05-15 17:38:05 +0000415{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200416 WMSelectTabViewItemAtIndex(tPtr, tPtr->selectedItem - 1);
dd2d71fc kojima1999-05-15 17:38:05 +0000417}
418
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200419WMTabViewItem *WMGetSelectedTabViewItem(WMTabView * tPtr)
420{
421 return tPtr->items[tPtr->selectedItem];
422}
dd2d71fc kojima1999-05-15 17:38:05 +0000423
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200424void WMSelectTabViewItem(WMTabView * tPtr, WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000425{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200426 int i;
dd2d71fc kojima1999-05-15 17:38:05 +0000427
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200428 for (i = 0; i < tPtr->itemCount; i++) {
429 if (tPtr->items[i] == item) {
430 WMSelectTabViewItemAtIndex(tPtr, i);
431 break;
432 }
433 }
434}
dd2d71fc kojima1999-05-15 17:38:05 +0000435
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200436void WMSelectTabViewItemAtIndex(WMTabView * tPtr, int index)
437{
438 WMTabViewItem *item;
dd2d71fc kojima1999-05-15 17:38:05 +0000439
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200440 if (index == tPtr->selectedItem) {
441 return;
442 }
dd2d71fc kojima1999-05-15 17:38:05 +0000443
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200444 if (index < 0)
445 index = 0;
446 else if (index >= tPtr->itemCount)
447 index = tPtr->itemCount - 1;
aff89828 kojima1999-05-17 03:55:35 +0000448
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200449 item = tPtr->items[tPtr->selectedItem];
aff89828 kojima1999-05-17 03:55:35 +0000450
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200451 if (tPtr->delegate && tPtr->delegate->shouldSelectItem)
452 if (!(*tPtr->delegate->shouldSelectItem) (tPtr->delegate, tPtr, tPtr->items[index]))
453 return;
dd2d71fc kojima1999-05-15 17:38:05 +0000454
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200455 if (tPtr->delegate && tPtr->delegate->willSelectItem)
456 (*tPtr->delegate->willSelectItem) (tPtr->delegate, tPtr, tPtr->items[index]);
dd2d71fc kojima1999-05-15 17:38:05 +0000457
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200458 W_UnmapTabViewItem(item);
dd2d71fc kojima1999-05-15 17:38:05 +0000459
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200460 item = tPtr->items[index];
dd2d71fc kojima1999-05-15 17:38:05 +0000461
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200462 W_MapTabViewItem(item);
aff89828 kojima1999-05-17 03:55:35 +0000463
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200464 tPtr->selectedItem = index;
6830b057 dan2004-10-12 21:28:27 +0000465
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200466 if (tPtr->delegate && tPtr->delegate->didSelectItem)
467 (*tPtr->delegate->didSelectItem) (tPtr->delegate, tPtr, tPtr->items[index]);
468
469 paintTabView(tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000470}
471
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200472static void recalcTabWidth(TabView * tPtr)
473{
474 int i;
475 /*int twidth = W_VIEW(tPtr)->size.width; */
476 int width;
dd2d71fc kojima1999-05-15 17:38:05 +0000477
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200478 if (tPtr->flags.uniformTabs) {
479 int tabWidth;
e99511b0 kojima2001-01-02 14:17:26 +0000480
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200481 tabWidth = 0;
dd2d71fc kojima1999-05-15 17:38:05 +0000482
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200483 for (i = 0; i < tPtr->itemCount; i++) {
484 char *str = WMGetTabViewItemLabel(tPtr->items[i]);
dd2d71fc kojima1999-05-15 17:38:05 +0000485
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200486 if (str) {
487 width = WMWidthOfString(tPtr->font, str, strlen(str));
488 if (width > tabWidth)
489 tabWidth = width;
490 }
491 }
492
493 tabWidth = tabWidth + 30;
dd2d71fc kojima1999-05-15 17:38:05 +0000494
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200495 for (i = 0; i < tPtr->itemCount; i++)
496 W_SetTabViewItemTabWidth(tPtr->items[i], tabWidth);
dd2d71fc kojima1999-05-15 17:38:05 +0000497
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200498 tPtr->firstVisible = 0;
499 tPtr->visibleTabs = countVisibleTabs(tPtr, -1);
500 if (tPtr->visibleTabs < tPtr->itemCount)
501 tPtr->flags.dontFitAll = 1;
502 else
503 tPtr->flags.dontFitAll = 0;
504 } else {
505 for (i = 0; i < tPtr->itemCount; i++) {
506 char *str = WMGetTabViewItemLabel(tPtr->items[i]);
507 if (!str)
508 continue;
dd2d71fc kojima1999-05-15 17:38:05 +0000509
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200510 width = WMWidthOfString(tPtr->font, str, strlen(str)) + 30;
511
512 W_SetTabViewItemTabWidth(tPtr->items[i], width);
513 }
514
515 if (countVisibleTabs(tPtr, -1) < tPtr->itemCount) {
516 tPtr->flags.dontFitAll = 1;
517 tPtr->firstVisible = 0;
518 tPtr->visibleTabs = countVisibleTabs(tPtr, tPtr->firstVisible);
519 } else {
520 tPtr->flags.dontFitAll = 0;
521 tPtr->firstVisible = 0;
522 tPtr->visibleTabs = tPtr->itemCount;
523 }
524 }
dd2d71fc kojima1999-05-15 17:38:05 +0000525}
526
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200527static void drawRelief(W_Screen * scr, Drawable d, int x, int y, unsigned int width, unsigned int height)
528{
529 Display *dpy = scr->display;
530 GC bgc = WMColorGC(scr->black);
531 GC wgc = WMColorGC(scr->white);
532 GC dgc = WMColorGC(scr->darkGray);
533
534 XDrawLine(dpy, d, wgc, x, y, x, y + height - 1);
535
536 XDrawLine(dpy, d, bgc, x, y + height - 1, x + width - 1, y + height - 1);
537 XDrawLine(dpy, d, dgc, x + 1, y + height - 2, x + width - 2, y + height - 2);
dd2d71fc kojima1999-05-15 17:38:05 +0000538
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200539 XDrawLine(dpy, d, bgc, x + width - 1, y, x + width - 1, y + height - 1);
540 XDrawLine(dpy, d, dgc, x + width - 2, y + 1, x + width - 2, y + height - 2);
541}
542
543static void drawTab(TabView * tPtr, Drawable d, int x, int y, unsigned width, unsigned height, Bool selected)
dd2d71fc kojima1999-05-15 17:38:05 +0000544{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200545 WMScreen *scr = W_VIEW(tPtr)->screen;
546 Display *dpy = scr->display;
547 GC white = WMColorGC(selected ? scr->white : tPtr->lightGray);
548 GC black = WMColorGC(scr->black);
549 GC dark = WMColorGC(scr->darkGray);
550 GC light = WMColorGC(scr->gray);
551 XPoint trap[8];
dd2d71fc kojima1999-05-15 17:38:05 +0000552
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200553 trap[0].x = x + (selected ? 0 : 1);
554 trap[0].y = y + height - (selected ? 0 : 1);
dd2d71fc kojima1999-05-15 17:38:05 +0000555
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200556 trap[1].x = x + 3;
557 trap[1].y = y + height - 3;
dd2d71fc kojima1999-05-15 17:38:05 +0000558
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200559 trap[2].x = x + 10 - 3;
560 trap[2].y = y + 3;
dd2d71fc kojima1999-05-15 17:38:05 +0000561
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200562 trap[3].x = x + 10;
563 trap[3].y = y;
dd2d71fc kojima1999-05-15 17:38:05 +0000564
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200565 trap[4].x = x + width - 10;
566 trap[4].y = y;
dd2d71fc kojima1999-05-15 17:38:05 +0000567
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200568 trap[5].x = x + width - 10 + 3;
569 trap[5].y = y + 3;
dd2d71fc kojima1999-05-15 17:38:05 +0000570
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200571 trap[6].x = x + width - 3;
572 trap[6].y = y + height - 3;
dd2d71fc kojima1999-05-15 17:38:05 +0000573
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200574 trap[7].x = x + width - (selected ? 0 : 1);
575 trap[7].y = y + height - (selected ? 0 : 1);
dd2d71fc kojima1999-05-15 17:38:05 +0000576
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200577 XFillPolygon(dpy, d, selected ? light : WMColorGC(tPtr->tabColor), trap, 8, Convex, CoordModeOrigin);
578
579 XDrawLine(dpy, d, white, trap[0].x, trap[0].y, trap[1].x, trap[1].y);
580 XDrawLine(dpy, d, white, trap[1].x, trap[1].y, trap[2].x, trap[2].y);
581 XDrawLine(dpy, d, white, trap[2].x, trap[2].y, trap[3].x, trap[3].y);
582 XDrawLine(dpy, d, white, trap[3].x, trap[3].y, trap[4].x, trap[4].y);
583 XDrawLine(dpy, d, dark, trap[4].x, trap[4].y, trap[5].x, trap[5].y);
584 XDrawLine(dpy, d, black, trap[5].x, trap[5].y, trap[6].x, trap[6].y);
585 XDrawLine(dpy, d, black, trap[6].x, trap[6].y, trap[7].x, trap[7].y);
586
587 XDrawLine(dpy, d, selected ? light : WMColorGC(scr->white), trap[0].x, trap[0].y, trap[7].x, trap[7].y);
588}
589
590static void paintDot(TabView * tPtr, Drawable d, int x, int y)
591{
592 WMScreen *scr = W_VIEW(tPtr)->screen;
593 Display *dpy = scr->display;
594 GC white = WMColorGC(scr->white);
595 GC black = WMColorGC(scr->black);
596
597 XFillRectangle(dpy, d, black, x, y, 2, 2);
598 XDrawPoint(dpy, d, white, x, y);
599}
600
601static void paintTabView(TabView * tPtr)
602{
603 Pixmap buffer;
604 WMScreen *scr = W_VIEW(tPtr)->screen;
605 Display *dpy = scr->display;
606 GC white = WMColorGC(scr->white);
607 int i;
608
609 if (tPtr->flags.type == WTTopTabsBevelBorder) {
610 int count = tPtr->visibleTabs;
611 int first = tPtr->firstVisible;
612 int moreAtLeft;
613 int moreAtRight;
614 int selectedIsVisible;
615 int ty;
616 int twidth, theight;
617
618 ty = 2;
619 theight = tPtr->tabHeight;
620
621 buffer = XCreatePixmap(dpy, W_VIEW(tPtr)->window,
622 W_VIEW(tPtr)->size.width, theight, W_VIEW(tPtr)->screen->depth);
dd2d71fc kojima1999-05-15 17:38:05 +0000623
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200624 XFillRectangle(dpy, buffer, WMColorGC(W_VIEW(tPtr)->backColor),
625 0, 0, W_VIEW(tPtr)->size.width, tPtr->tabHeight);
dd2d71fc kojima1999-05-15 17:38:05 +0000626
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200627 if (tPtr->flags.dontFitAll) {
628 moreAtLeft = first > 0;
629 moreAtRight = (first + count) < tPtr->itemCount;
630 if (tPtr->selectedItem >= first && tPtr->selectedItem < first + count)
631 selectedIsVisible = 1;
632 else
633 selectedIsVisible = 0;
634 } else {
635 moreAtLeft = 0;
636 moreAtRight = 0;
637 selectedIsVisible = 1;
638 }
639
640 if (moreAtRight) {
641 drawTab(tPtr, buffer, positionOfTab(tPtr, first + count), 0,
642 W_VIEW_WIDTH(tPtr->view), theight, False);
643 }
644 for (i = first + count - 1; i >= first; i--) {
645 if (!selectedIsVisible || i != tPtr->selectedItem) {
646 twidth = W_TabViewItemTabWidth(tPtr->items[i]);
dd2d71fc kojima1999-05-15 17:38:05 +0000647
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200648 drawTab(tPtr, buffer, positionOfTab(tPtr, i), 0, twidth, theight, False);
649 }
650 }
651 if (moreAtLeft) {
652 drawTab(tPtr, buffer, positionOfTab(tPtr, 0) - 2 * BUTTONED_SIDE_OFFSET,
653 0, BUTTONED_SIDE_OFFSET * 4, theight, False);
654 }
dd2d71fc kojima1999-05-15 17:38:05 +0000655
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200656 if (selectedIsVisible) {
657 int idx = tPtr->selectedItem;
93941b2c kojima2000-03-04 00:18:13 +0000658
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200659 drawTab(tPtr, buffer, positionOfTab(tPtr, idx),
660 0, W_TabViewItemTabWidth(tPtr->items[idx]), theight, True);
93941b2c kojima2000-03-04 00:18:13 +0000661
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200662 XDrawLine(dpy, buffer, white, 0, theight - 1, positionOfTab(tPtr, idx), theight - 1);
93941b2c kojima2000-03-04 00:18:13 +0000663
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200664 XDrawLine(dpy, buffer, white,
665 positionOfTab(tPtr, idx) + W_TabViewItemTabWidth(tPtr->items[idx]),
666 tPtr->tabHeight - 1, W_VIEW_WIDTH(tPtr->view) - 1, tPtr->tabHeight - 1);
667 } else {
668 XDrawLine(dpy, buffer, white, 0, theight - 1, W_VIEW_WIDTH(tPtr->view), theight - 1);
669 }
93941b2c kojima2000-03-04 00:18:13 +0000670
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200671 for (i = 0; i < count; i++) {
672 WMRect rect;
dd2d71fc kojima1999-05-15 17:38:05 +0000673
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200674 rect.pos.x = 15 + positionOfTab(tPtr, first + i);
675 rect.pos.y = ty;
676 rect.size.width = W_TabViewItemTabWidth(tPtr->items[first + i]);
677 rect.size.height = theight;
678 W_DrawLabel(tPtr->items[first + i], buffer, rect,
679 tPtr->flags.enabled && tPtr->items[first + i]->flags.enabled);
680 }
dd2d71fc kojima1999-05-15 17:38:05 +0000681
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200682 if (moreAtLeft) {
683 paintDot(tPtr, buffer, 4, 10);
684 paintDot(tPtr, buffer, 7, 10);
685 paintDot(tPtr, buffer, 10, 10);
686 }
687 if (moreAtRight) {
688 int x;
689
690 x = positionOfTab(tPtr, tPtr->firstVisible + tPtr->visibleTabs);
691
692 x = x + (W_VIEW_WIDTH(tPtr->view) - x) / 2;
693 paintDot(tPtr, buffer, x + 5, 10);
694 paintDot(tPtr, buffer, x + 8, 10);
695 paintDot(tPtr, buffer, x + 11, 10);
696 }
697
698 XCopyArea(dpy, buffer, W_VIEW(tPtr)->window, scr->copyGC, 0, 0,
699 W_VIEW_WIDTH(tPtr->view), theight, 0, 0);
700
701 XFreePixmap(dpy, buffer);
702 }
703 switch (tPtr->flags.type) {
704 case WTTopTabsBevelBorder:
705 drawRelief(scr, W_VIEW(tPtr)->window, 0, tPtr->tabHeight - 1,
706 W_VIEW(tPtr)->size.width, W_VIEW(tPtr)->size.height - tPtr->tabHeight + 1);
707 break;
708
709 case WTNoTabsBevelBorder:
710 W_DrawRelief(scr, W_VIEW(tPtr)->window, 0, 0, W_VIEW(tPtr)->size.width,
711 W_VIEW(tPtr)->size.height, WRRaised);
712 break;
713
714 case WTNoTabsLineBorder:
715 W_DrawRelief(scr, W_VIEW(tPtr)->window, 0, 0, W_VIEW(tPtr)->size.width,
716 W_VIEW(tPtr)->size.height, WRSimple);
717 break;
718
719 case WTNoTabsNoBorder:
720 break;
721 }
52308a0a kojima2000-11-11 18:08:10 +0000722}
723
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200724static void rearrange(TabView * tPtr)
725{
726 int i;
727 int width, height;
728 int bordered = tPtr->flags.bordered;
729
730 recalcTabWidth(tPtr);
52308a0a kojima2000-11-11 18:08:10 +0000731
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200732 width = tPtr->view->size.width - (bordered ? 3 : 0);
733 height = tPtr->view->size.height - tPtr->tabHeight - (bordered ? 3 : 0);
734
735 for (i = 0; i < tPtr->itemCount; i++) {
736 W_MoveView(W_TabViewItemView(tPtr->items[i]), 1 * bordered, tPtr->tabHeight + 1 * bordered);
737 W_ResizeView(W_TabViewItemView(tPtr->items[i]), width, height);
738 }
739 if (W_VIEW_MAPPED(tPtr->view) && W_VIEW_REALIZED(tPtr->view))
740 paintTabView(tPtr);
52308a0a kojima2000-11-11 18:08:10 +0000741}
742
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200743static void didResize(struct W_ViewDelegate *deleg, WMView * view)
744{
745 rearrange(view->self);
746}
52308a0a kojima2000-11-11 18:08:10 +0000747
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200748static void destroyTabView(TabView * tPtr)
dd2d71fc kojima1999-05-15 17:38:05 +0000749{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200750 int i;
dd2d71fc kojima1999-05-15 17:38:05 +0000751
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200752 for (i = 0; i < tPtr->itemCount; i++) {
753 WMSetTabViewItemView(tPtr->items[i], NULL);
754 WMDestroyTabViewItem(tPtr->items[i]);
755 }
756 wfree(tPtr->items);
dd2d71fc kojima1999-05-15 17:38:05 +0000757
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200758 WMReleaseColor(tPtr->lightGray);
759 WMReleaseColor(tPtr->tabColor);
760 WMReleaseFont(tPtr->font);
dd2d71fc kojima1999-05-15 17:38:05 +0000761
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200762 wfree(tPtr);
dd2d71fc kojima1999-05-15 17:38:05 +0000763}
764
765/******************************************************************/
766
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200767static void W_SetTabViewItemParent(WMTabViewItem * item, WMTabView * parent)
dd2d71fc kojima1999-05-15 17:38:05 +0000768{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200769 item->tabView = parent;
dd2d71fc kojima1999-05-15 17:38:05 +0000770}
771
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200772static void W_DrawLabel(WMTabViewItem * item, Drawable d, WMRect rect, Bool enabled)
dd2d71fc kojima1999-05-15 17:38:05 +0000773{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200774 WMScreen *scr = W_VIEW(item->tabView)->screen;
dd2d71fc kojima1999-05-15 17:38:05 +0000775
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200776 if (!item->label)
777 return;
dd2d71fc kojima1999-05-15 17:38:05 +0000778
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200779 WMDrawString(scr, d, enabled ? scr->black : scr->darkGray,
780 item->tabView->font, rect.pos.x, rect.pos.y, item->label, strlen(item->label));
dd2d71fc kojima1999-05-15 17:38:05 +0000781}
782
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200783static void W_UnmapTabViewItem(WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000784{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200785 wassertr(item->view);
dd2d71fc kojima1999-05-15 17:38:05 +0000786
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200787 W_UnmapView(item->view);
dd2d71fc kojima1999-05-15 17:38:05 +0000788
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200789 item->flags.visible = 0;
dd2d71fc kojima1999-05-15 17:38:05 +0000790}
791
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200792static void W_MapTabViewItem(WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000793{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200794 wassertr(item->view);
dd2d71fc kojima1999-05-15 17:38:05 +0000795
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200796 W_MapView(item->view);
797 W_RaiseView(item->view);
dd2d71fc kojima1999-05-15 17:38:05 +0000798
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200799 item->flags.visible = 1;
dd2d71fc kojima1999-05-15 17:38:05 +0000800}
801
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200802static WMView *W_TabViewItemView(WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000803{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200804 return item->view;
dd2d71fc kojima1999-05-15 17:38:05 +0000805}
806
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200807static int W_TabViewItemTabWidth(WMTabViewItem * item)
e99511b0 kojima2001-01-02 14:17:26 +0000808{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200809 return item->tabWidth;
e99511b0 kojima2001-01-02 14:17:26 +0000810}
811
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200812static void W_SetTabViewItemTabWidth(WMTabViewItem * item, int width)
e99511b0 kojima2001-01-02 14:17:26 +0000813{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200814 item->tabWidth = width;
e99511b0 kojima2001-01-02 14:17:26 +0000815}
816
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200817WMTabViewItem *WMCreateTabViewItemWithIdentifier(int identifier)
dd2d71fc kojima1999-05-15 17:38:05 +0000818{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200819 WMTabViewItem *item;
dd2d71fc kojima1999-05-15 17:38:05 +0000820
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200821 item = wmalloc(sizeof(WMTabViewItem));
822 memset(item, 0, sizeof(WMTabViewItem));
dd2d71fc kojima1999-05-15 17:38:05 +0000823
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200824 item->identifier = identifier;
dd2d71fc kojima1999-05-15 17:38:05 +0000825
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200826 item->flags.enabled = 1;
65e65c4e dan2002-03-14 12:28:52 +0000827
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200828 return item;
dd2d71fc kojima1999-05-15 17:38:05 +0000829}
830
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200831WMTabViewItem *WMCreateTabViewItem(int identifier, char *label)
e29fce43 kojima2000-07-10 22:37:39 +0000832{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200833 WMTabViewItem *item;
e29fce43 kojima2000-07-10 22:37:39 +0000834
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200835 item = wmalloc(sizeof(WMTabViewItem));
836 memset(item, 0, sizeof(WMTabViewItem));
e29fce43 kojima2000-07-10 22:37:39 +0000837
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200838 item->identifier = identifier;
65e65c4e dan2002-03-14 12:28:52 +0000839
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200840 item->flags.enabled = 1;
65e65c4e dan2002-03-14 12:28:52 +0000841
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200842 WMSetTabViewItemLabel(item, label);
e29fce43 kojima2000-07-10 22:37:39 +0000843
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200844 return item;
e29fce43 kojima2000-07-10 22:37:39 +0000845}
846
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200847void WMSetTabViewItemEnabled(WMTabViewItem * tPtr, Bool flag)
65e65c4e dan2002-03-14 12:28:52 +0000848{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200849 tPtr->flags.enabled = ((flag == 0) ? 0 : 1);
850 if (tPtr->tabView && W_VIEW_REALIZED(tPtr->tabView->view))
851 paintTabView(tPtr->tabView);
65e65c4e dan2002-03-14 12:28:52 +0000852}
853
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200854int WMGetTabViewItemIdentifier(WMTabViewItem * item)
aff89828 kojima1999-05-17 03:55:35 +0000855{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200856 return item->identifier;
aff89828 kojima1999-05-17 03:55:35 +0000857}
858
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200859void WMSetTabViewFont(WMTabView * tPtr, WMFont * font)
237fa3ce dan1999-05-16 15:11:13 +0000860{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200861 if (tPtr->font)
862 WMReleaseFont(tPtr->font);
237fa3ce dan1999-05-16 15:11:13 +0000863
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200864 tPtr->font = WMRetainFont(font);
865 tPtr->tabHeight = WMFontHeight(tPtr->font) + 3;
866 recalcTabWidth(tPtr);
237fa3ce dan1999-05-16 15:11:13 +0000867}
868
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200869void WMSetTabViewItemLabel(WMTabViewItem * item, char *label)
dd2d71fc kojima1999-05-15 17:38:05 +0000870{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200871 if (item->label)
872 wfree(item->label);
dd2d71fc kojima1999-05-15 17:38:05 +0000873
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200874 if (label)
875 item->label = wstrdup(label);
876 else
877 item->label = NULL;
dd2d71fc kojima1999-05-15 17:38:05 +0000878
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200879 if (item->tabView)
880 recalcTabWidth(item->tabView);
dd2d71fc kojima1999-05-15 17:38:05 +0000881}
882
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200883char *WMGetTabViewItemLabel(WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000884{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200885 return item->label;
dd2d71fc kojima1999-05-15 17:38:05 +0000886}
887
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200888void WMSetTabViewItemView(WMTabViewItem * item, WMView * view)
dd2d71fc kojima1999-05-15 17:38:05 +0000889{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200890 item->view = view;
dd2d71fc kojima1999-05-15 17:38:05 +0000891}
892
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200893WMView *WMGetTabViewItemView(WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000894{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200895 return item->view;
dd2d71fc kojima1999-05-15 17:38:05 +0000896}
897
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200898void WMDestroyTabViewItem(WMTabViewItem * item)
dd2d71fc kojima1999-05-15 17:38:05 +0000899{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200900 if (item->label)
901 wfree(item->label);
dd2d71fc kojima1999-05-15 17:38:05 +0000902
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200903 if (item->view)
904 W_DestroyView(item->view);
dd2d71fc kojima1999-05-15 17:38:05 +0000905
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200906 wfree(item);
dd2d71fc kojima1999-05-15 17:38:05 +0000907}