Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / imagebrowser.c
1 /* imagebrowser.c- image browser widget
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 2000-2003 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
21 */
22
23 #define FOR_WPREFS
24
25 #ifdef FOR_WPREFS
26 # include "WPrefs.h" /* only for _() */
27 #else
28 # define _(a) a
29 #endif
30
31 #include <WINGs/WINGs.h>
32 #include <WINGs/WINGsP.h>
33 #include <assert.h>
34 #include <ctype.h>
35 #include <stdlib.h>
36
37 #include "imagebrowser.h"
38
39 struct _ImageBrowser {
40 WMWindow *win;
41
42 WMPopUpButton *pathP;
43
44 WMScrollView *sview;
45 WMFrame *frame;
46
47 WMWidget *auxWidget;
48
49 WMButton *viewBtn;
50 WMButton *okBtn;
51 WMButton *cancelBtn;
52
53 WMSize maxPreviewSize;
54
55 ImageBrowserDelegate *delegate;
56
57 WMArray *previews;
58 };
59
60 #define DEFAULT_WIDTH 300
61 #define DEFAULT_HEIGHT 200
62
63 ImageBrowser *CreateImageBrowser(WMScreen * scr, char *title, char **paths, int pathN,
64 WMSize * maxSize, WMWidget * auxWidget)
65 {
66 ImageBrowser *br;
67 int i;
68 int h;
69
70 br = wmalloc(sizeof(ImageBrowser));
71
72 br->win = WMCreateWindow(scr, "imageBrowser");
73 WMResizeWidget(br->win, DEFAULT_WIDTH, DEFAULT_HEIGHT);
74
75 br->pathP = WMCreatePopUpButton(br->win);
76 WMMoveWidget(br->pathP, (DEFAULT_WIDTH - 80) / 2, 10);
77 WMResizeWidget(br->pathP, DEFAULT_WIDTH - 80, 20);
78
79 for (i = 0; i < pathN; i++) {
80 WMAddPopUpButtonItem(br->pathP, paths[i]);
81 }
82
83 br->viewBtn = WMCreateCommandButton(br->win);
84 WMSetButtonText(br->viewBtn, _("View"));
85 WMResizeWidget(br->viewBtn, 80, 24);
86 WMMoveWidget(br->viewBtn, 10, DEFAULT_HEIGHT - 29);
87
88 br->cancelBtn = WMCreateCommandButton(br->win);
89 WMSetButtonText(br->cancelBtn, _("Cancel"));
90 WMResizeWidget(br->cancelBtn, 80, 24);
91 WMMoveWidget(br->cancelBtn, DEFAULT_WIDTH - 10 - 80, DEFAULT_HEIGHT - 29);
92
93 br->okBtn = WMCreateCommandButton(br->win);
94 WMSetButtonText(br->okBtn, _("OK"));
95 WMResizeWidget(br->okBtn, 80, 24);
96 WMMoveWidget(br->okBtn, DEFAULT_WIDTH - 10 - 160 - 5, DEFAULT_HEIGHT - 29);
97
98 br->auxWidget = auxWidget;
99
100 h = DEFAULT_HEIGHT - 20 /* top and bottom spacing */
101 - 25 /* popup menu and spacing */
102 - 29; /* button row and spacing */
103
104 if (auxWidget != NULL) {
105 h -= WMWidgetHeight(auxWidget) + 5;
106
107 W_ReparentView(WMWidgetView(auxWidget), WMWidgetView(br->win), 10, 10 + 25 + h + 5);
108 }
109
110 br->sview = WMCreateScrollView(br->win);
111 WMResizeWidget(br->sview, DEFAULT_WIDTH - 20, h);
112 WMMoveWidget(br->sview, 10, 5 + 20 + 5);
113
114 WMMapSubwidgets(br->win);
115
116 return br;
117 }
118
119 void ShowImageBrowser(ImageBrowser * browser)
120 {
121 WMMapWidget(browser->win);
122 }
123
124 void CloseImageBrowser(ImageBrowser * browser)
125 {
126 WMUnmapWidget(browser->win);
127 }
128
129 void SetImageBrowserPathList(ImageBrowser * browser, char **paths, int pathN)
130 {
131 }
132
133 void SetImageBrowserDelegate(ImageBrowser * browser, ImageBrowserDelegate * delegate)
134 {
135
136 }
137
138 void DestroyImageBrowser(ImageBrowser * browser)
139 {
140 WMDestroyWidget(browser->win);
141
142 /**/ wfree(browser);
143 }