Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / imagebrowser.c
Commit [+]AuthorDateLineData
d4c23fba kojima2000-05-23 21:18:49 +00001/* imagebrowser.c- image browser widget
6830b057 dan2004-10-12 21:28:27 +00002 *
d4c23fba kojima2000-05-23 21:18:49 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 2000-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
d4c23fba kojima2000-05-23 21:18:49 +00007 * 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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
d4c23fba kojima2000-05-23 21:18:49 +000020 * USA.
21 */
22
23#define FOR_WPREFS
24
25#ifdef FOR_WPREFS
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020026# include "WPrefs.h" /* only for _() */
d4c23fba kojima2000-05-23 21:18:49 +000027#else
28# define _(a) a
29#endif
30
a20aebde dan2001-01-18 19:21:56 +000031#include <WINGs/WINGs.h>
32#include <WINGs/WINGsP.h>
d4c23fba kojima2000-05-23 21:18:49 +000033#include <assert.h>
34#include <ctype.h>
35#include <stdlib.h>
36
37#include "imagebrowser.h"
38
d4c23fba kojima2000-05-23 21:18:49 +000039struct _ImageBrowser {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020040 WMWindow *win;
d4c23fba kojima2000-05-23 21:18:49 +000041
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020042 WMPopUpButton *pathP;
6830b057 dan2004-10-12 21:28:27 +000043
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020044 WMScrollView *sview;
45 WMFrame *frame;
6830b057 dan2004-10-12 21:28:27 +000046
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020047 WMWidget *auxWidget;
6830b057 dan2004-10-12 21:28:27 +000048
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020049 WMButton *viewBtn;
50 WMButton *okBtn;
51 WMButton *cancelBtn;
d4c23fba kojima2000-05-23 21:18:49 +000052
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020053 WMSize maxPreviewSize;
6830b057 dan2004-10-12 21:28:27 +000054
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020055 ImageBrowserDelegate *delegate;
6830b057 dan2004-10-12 21:28:27 +000056
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020057 WMArray *previews;
d4c23fba kojima2000-05-23 21:18:49 +000058};
59
d4c23fba kojima2000-05-23 21:18:49 +000060#define DEFAULT_WIDTH 300
61#define DEFAULT_HEIGHT 200
62
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020063ImageBrowser *CreateImageBrowser(WMScreen * scr, char *title, char **paths, int pathN,
64 WMSize * maxSize, WMWidget * auxWidget)
d4c23fba kojima2000-05-23 21:18:49 +000065{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020066 ImageBrowser *br;
67 int i;
68 int h;
d4c23fba kojima2000-05-23 21:18:49 +000069
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020070 br = wmalloc(sizeof(ImageBrowser));
6830b057 dan2004-10-12 21:28:27 +000071
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020072 br->win = WMCreateWindow(scr, "imageBrowser");
73 WMResizeWidget(br->win, DEFAULT_WIDTH, DEFAULT_HEIGHT);
d4c23fba kojima2000-05-23 21:18:49 +000074
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020075 br->pathP = WMCreatePopUpButton(br->win);
76 WMMoveWidget(br->pathP, (DEFAULT_WIDTH - 80) / 2, 10);
77 WMResizeWidget(br->pathP, DEFAULT_WIDTH - 80, 20);
d4c23fba kojima2000-05-23 21:18:49 +000078
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020079 for (i = 0; i < pathN; i++) {
80 WMAddPopUpButtonItem(br->pathP, paths[i]);
81 }
d4c23fba kojima2000-05-23 21:18:49 +000082
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020083 br->viewBtn = WMCreateCommandButton(br->win);
84 WMSetButtonText(br->viewBtn, _("View"));
85 WMResizeWidget(br->viewBtn, 80, 24);
86 WMMoveWidget(br->viewBtn, 10, DEFAULT_HEIGHT - 29);
6830b057 dan2004-10-12 21:28:27 +000087
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020088 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);
6830b057 dan2004-10-12 21:28:27 +000092
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020093 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);
6830b057 dan2004-10-12 21:28:27 +000097
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020098 br->auxWidget = auxWidget;
6830b057 dan2004-10-12 21:28:27 +000099
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200100 h = DEFAULT_HEIGHT - 20 /* top and bottom spacing */
101 - 25 /* popup menu and spacing */
102 - 29; /* button row and spacing */
6830b057 dan2004-10-12 21:28:27 +0000103
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200104 if (auxWidget != NULL) {
105 h -= WMWidgetHeight(auxWidget) + 5;
6830b057 dan2004-10-12 21:28:27 +0000106
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200107 W_ReparentView(WMWidgetView(auxWidget), WMWidgetView(br->win), 10, 10 + 25 + h + 5);
108 }
d4c23fba kojima2000-05-23 21:18:49 +0000109
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200110 br->sview = WMCreateScrollView(br->win);
111 WMResizeWidget(br->sview, DEFAULT_WIDTH - 20, h);
112 WMMoveWidget(br->sview, 10, 5 + 20 + 5);
6830b057 dan2004-10-12 21:28:27 +0000113
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200114 WMMapSubwidgets(br->win);
6830b057 dan2004-10-12 21:28:27 +0000115
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200116 return br;
d4c23fba kojima2000-05-23 21:18:49 +0000117}
118
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200119void ShowImageBrowser(ImageBrowser * browser)
d4c23fba kojima2000-05-23 21:18:49 +0000120{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200121 WMMapWidget(browser->win);
d4c23fba kojima2000-05-23 21:18:49 +0000122}
123
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200124void CloseImageBrowser(ImageBrowser * browser)
d4c23fba kojima2000-05-23 21:18:49 +0000125{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200126 WMUnmapWidget(browser->win);
d4c23fba kojima2000-05-23 21:18:49 +0000127}
128
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200129void SetImageBrowserPathList(ImageBrowser * browser, char **paths, int pathN)
d4c23fba kojima2000-05-23 21:18:49 +0000130{
131}
132
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200133void SetImageBrowserDelegate(ImageBrowser * browser, ImageBrowserDelegate * delegate)
d4c23fba kojima2000-05-23 21:18:49 +0000134{
6830b057 dan2004-10-12 21:28:27 +0000135
d4c23fba kojima2000-05-23 21:18:49 +0000136}
137
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200138void DestroyImageBrowser(ImageBrowser * browser)
d4c23fba kojima2000-05-23 21:18:49 +0000139{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200140 WMDestroyWidget(browser->win);
6830b057 dan2004-10-12 21:28:27 +0000141
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200142 /**/ wfree(browser);
d4c23fba kojima2000-05-23 21:18:49 +0000143}