fixed some bugs
[wmaker-crm.git] / WPrefs.app / imagebrowser.c
blob62112c7ad89ba72a995aeb1ea084881dd9b5b2d9
1 /* imagebrowser.c- image browser widget
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2000-2003 Alfredo K. Kojima
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.
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.
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.
23 #define FOR_WPREFS
25 #ifdef FOR_WPREFS
26 # include "WPrefs.h" /* only for _() */
27 #else
28 # define _(a) a
29 #endif
31 #include <WINGs/WINGs.h>
32 #include <WINGs/WINGsP.h>
33 #include <assert.h>
34 #include <ctype.h>
35 #include <stdlib.h>
37 #include "imagebrowser.h"
41 struct _ImageBrowser {
42 WMWindow *win;
44 WMPopUpButton *pathP;
46 WMScrollView *sview;
47 WMFrame *frame;
50 WMWidget *auxWidget;
53 WMButton *viewBtn;
54 WMButton *okBtn;
55 WMButton *cancelBtn;
57 WMSize maxPreviewSize;
59 ImageBrowserDelegate *delegate;
61 WMArray *previews;
68 #define DEFAULT_WIDTH 300
69 #define DEFAULT_HEIGHT 200
72 ImageBrowser*
73 CreateImageBrowser(WMScreen *scr, char *title, char **paths, int pathN,
74 WMSize *maxSize, WMWidget *auxWidget)
76 ImageBrowser *br;
77 int i;
78 int h;
80 br = wmalloc(sizeof(ImageBrowser));
82 br->win = WMCreateWindow(scr, "imageBrowser");
83 WMResizeWidget(br->win, DEFAULT_WIDTH, DEFAULT_HEIGHT);
85 br->pathP = WMCreatePopUpButton(br->win);
86 WMMoveWidget(br->pathP, (DEFAULT_WIDTH - 80)/2, 10);
87 WMResizeWidget(br->pathP, DEFAULT_WIDTH - 80, 20);
89 for (i = 0; i < pathN; i++) {
90 WMAddPopUpButtonItem(br->pathP, paths[i]);
94 br->viewBtn = WMCreateCommandButton(br->win);
95 WMSetButtonText(br->viewBtn, _("View"));
96 WMResizeWidget(br->viewBtn, 80, 24);
97 WMMoveWidget(br->viewBtn, 10, DEFAULT_HEIGHT - 29);
99 br->cancelBtn = WMCreateCommandButton(br->win);
100 WMSetButtonText(br->cancelBtn, _("Cancel"));
101 WMResizeWidget(br->cancelBtn, 80, 24);
102 WMMoveWidget(br->cancelBtn, DEFAULT_WIDTH - 10 - 80, DEFAULT_HEIGHT - 29);
104 br->okBtn = WMCreateCommandButton(br->win);
105 WMSetButtonText(br->okBtn, _("OK"));
106 WMResizeWidget(br->okBtn, 80, 24);
107 WMMoveWidget(br->okBtn, DEFAULT_WIDTH - 10 - 160 - 5, DEFAULT_HEIGHT - 29);
111 br->auxWidget = auxWidget;
114 h = DEFAULT_HEIGHT
115 - 20 /* top and bottom spacing */
116 - 25 /* popup menu and spacing */
117 - 29; /* button row and spacing */
119 if (auxWidget != NULL) {
120 h -= WMWidgetHeight(auxWidget) + 5;
122 W_ReparentView(WMWidgetView(auxWidget),
123 WMWidgetView(br->win),
124 10, 10 + 25 + h + 5);
127 br->sview = WMCreateScrollView(br->win);
128 WMResizeWidget(br->sview, DEFAULT_WIDTH-20, h);
129 WMMoveWidget(br->sview, 10, 5 + 20 + 5);
133 WMMapSubwidgets(br->win);
135 return br;
139 void
140 ShowImageBrowser(ImageBrowser *browser)
142 WMMapWidget(browser->win);
145 void
146 CloseImageBrowser(ImageBrowser *browser)
148 WMUnmapWidget(browser->win);
152 void
153 SetImageBrowserPathList(ImageBrowser *browser, char **paths, int pathN)
158 void
159 SetImageBrowserDelegate(ImageBrowser *browser,
160 ImageBrowserDelegate *delegate)
169 void
170 DestroyImageBrowser(ImageBrowser *browser)
172 WMDestroyWidget(browser->win);
174 /**/
176 wfree(browser);