1 /*
2 * ===========================
3 * VDK Visual Develeopment Kit
4 * Version 2.0.4
5 * March 2004
6 * ===========================
7 *
8 * Copyright (C) 1998 - 2004 Mario Motta
9 * Developed by Mario Motta <mmotta@guest.net>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 * 02111-1307, USA.
25 */
26
27 #include <vdk/vdkfilechooser.h>
28 static char * stock_open_16_xpm[] = {
29 "16 16 64 1",
30 " c None",
31 ". c #000000",
32 "+ c #E4E5DF",
33 "@ c #D5D6CB",
34 "# c #D6D7CA",
35 "$ c #A3A39D",
36 "% c #F5F6F0",
37 "& c #8D907B",
38 "* c #92957E",
39 "= c #90937D",
40 "- c #979B84",
41 "; c #6D705F",
42 "> c #EAECDB",
43 ", c #8A8C7D",
44 "' c #8E917B",
45 ") c #91947F",
46 "! c #8B8E7A",
47 "~ c #999B87",
48 "{ c #919480",
49 "] c #989B86",
50 "^ c #B1B4A2",
51 "/ c #A2A394",
52 "( c #F7F7F7",
53 "_ c #878A75",
54 ": c #666858",
55 "< c #4B4D3F",
56 "[ c #4D4F40",
57 "} c #404135",
58 "| c #424337",
59 "1 c #434437",
60 "2 c #404236",
61 "3 c #3C3D32",
62 "4 c #48493C",
63 "5 c #1A1A16",
64 "6 c #C6C6BE",
65 "7 c #848672",
66 "8 c #25261F",
67 "9 c #F1F2E9",
68 "0 c #DDE0C7",
69 "a c #D6DABB",
70 "b c #CDD2AC",
71 "c c #C7CCA7",
72 "d c #989C80",
73 "e c #C6C7BE",
74 "f c #5F6152",
75 "g c #888980",
76 "h c #A7AB8C",
77 "i c #878A70",
78 "j c #9FA19A",
79 "k c #EFF0E5",
80 "l c #9EA284",
81 "m c #80817B",
82 "n c #96968D",
83 "o c #E3E5D1",
84 "p c #83866D",
85 "q c #97998D",
86 "r c #EDEFE2",
87 "s c #A2A688",
88 "t c #767671",
89 "u c #E7E9DA",
90 "v c #D1D3BD",
91 "w c #BBBF9D",
92 "x c #989B80",
93 "y c #6E715C",
94 " ",
95 " ",
96 " .... ",
97 " .+@#$. ",
98 " .%&*=-;..... ",
99 " .>,')!~{]{^/. ",
100 " .(_:<[}||12345 ",
101 " .67890abbbbbcd.",
102 " .efg0bbbbbbbhi.",
103 " .j8kabbbbbbbl. ",
104 " .mnobbbbbbbbp. ",
105 " .qrbbbbbbbbs. ",
106 " .tuvwwwwwwxy. ",
107 " ........... ",
108 " ",
109 " "};
110
111 static char * stock_cancel_20_xpm[] = {
112 "20 20 8 1",
113 " c None",
114 ". c #000000",
115 "+ c #C46D74",
116 "@ c #9F3C44",
117 "# c #B5444E",
118 "$ c #BD5A62",
119 "% c #7B2D34",
120 "& c #8C343C",
121 " ",
122 " ",
123 " ",
124 " .. . ",
125 " .+@. .#. ",
126 " .##. .$#. ",
127 " .#@. .$#%. ",
128 " .##..$#&. ",
129 " .####@. ",
130 " .####. ",
131 " .$###. ",
132 " .$####. ",
133 " .$#&..#&. ",
134 " .+#&. .@#. ",
135 " .#&. .#@. ",
136 " .. .@#. ",
137 " .. ",
138 " ",
139 " ",
140 " "};
141
142 GtkWindowType VDKFileChooser::DisplayType = GTK_WINDOW_TOPLEVEL;
143 GtkWindowPosition VDKFileChooser::InitialPosition = GTK_WIN_POS_NONE;
144 /*
145 defining signal and events
146 dynamics tables
147 */
148 DEFINE_SIGNAL_LIST(VDKFileChooser,VDKForm);
149 DEFINE_EVENT_LIST(VDKFileChooser,VDKForm);
150 /*
151 defining signal static table
152 */
DEFINE_SIGNAL_MAP(VDKFileChooser,VDKForm)153 DEFINE_SIGNAL_MAP(VDKFileChooser,VDKForm)
154 ON_SIGNAL(okButton,clicked_signal,OnokButtonClick),
155 ON_SIGNAL(cancelButton,clicked_signal,OncancelButtonClick)
156 END_SIGNAL_MAP
157
158 // Vdkfc FORM CLASS
159 /*
160 form constructor
161 */
162 VDKFileChooser::VDKFileChooser(VDKForm* owner, FileStringArray* selections, char* title):
163 VDKForm(owner,title,v_box,DisplayType),selections(selections),
164 MultiSelection("MultiSelection",this,false,&VDKFileChooser::SetMultiSelection,&VDKFileChooser::GetMultiSelection),
165 Action("Action",this,GTK_FILE_CHOOSER_ACTION_OPEN,&VDKFileChooser::SetAction,&VDKFileChooser::GetAction)
166 {
167 VDKFileChooser::Setup();
168 }
169
170 /*
171 form destructor
172 */
~VDKFileChooser()173 VDKFileChooser::~VDKFileChooser()
174 {
175 }
176
177 /*
178 form setup
179 */
180 void
Setup(void)181 VDKFileChooser::Setup(void)
182 {
183 SetSize(438,326);
184 mainbox = new VDKBox(this,v_box);
185 Add(mainbox,0,1,1,0);
186 fcbox = new VDKBox(this,v_box);
187 mainbox->Add(fcbox,0,1,1,0);
188 fcbox->BorderWidth(0);
189 separator0 = new VDKSeparator(this,h_separator);
190 gtk_widget_set_name (GTK_WIDGET(separator0->WrappedWidget()), "separator0");
191 mainbox->Add(separator0,0,0,0,5);
192 buttonbox = new VDKBox(this,h_box);
193 mainbox->Add(buttonbox,0,0,0,2);
194 buttonbox->BorderWidth(0);
195 okButton = new VDKCustomButton(this,(const char**) stock_open_16_xpm," OK",16,(GtkPositionType) 1);
196 gtk_widget_set_name (GTK_WIDGET(okButton->WrappedWidget()), "okButton");
197 buttonbox->Add(okButton,0,1,0,0);
198 cancelButton = new VDKCustomButton(this,(const char**) stock_cancel_20_xpm," Cancel",16,(GtkPositionType) 1);
199 gtk_widget_set_name (GTK_WIDGET(cancelButton->WrappedWidget()), "cancelButton");
200 buttonbox->Add(cancelButton,0,1,0,0);
201 // makes GtkFileChooser
202 sigwid = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
203 // makes dummy
204 filechooser = new VDKObject(this,sigwid);
205 fcbox->Add(filechooser,l_justify,true,true,0);
206 g_signal_connect_data (sigwid, "file-activated",
207 G_CALLBACK (VDKFileChooser::file_activated), this,
208 NULL,(GConnectFlags) 0);
209 }
210
211 //signal response method
212 bool
OncancelButtonClick(VDKObject * sender)213 VDKFileChooser::OncancelButtonClick(VDKObject* sender)
214 {
215 Close();
216 return true;
217 }
218 //signal response method
219 bool
OnokButtonClick(VDKObject * sender)220 VDKFileChooser::OnokButtonClick(VDKObject* sender)
221 {
222 if(MultiSelection)
223 {
224 int t = 0;
225 GSList* listhead = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(sigwid));
226 GSList* list = listhead;
227 selections->resize(g_slist_length(list ? list : 0));
228 while(list)
229 {
230 VDKUString s((char*)list->data);
231 (*selections)[t] = s;
232 g_free(list->data);
233 t++;
234 list = list->next;
235 }
236 if(listhead)
237 g_slist_free(listhead);
238 }
239 else
240 {
241 char* sel;
242 sel = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(sigwid));
243 if(sel)
244 {
245 selections->resize(1);
246 VDKUString s(sel);
247 (*selections)[0] = s;
248 g_free(sel);
249 }
250
251 }
252 Close();
253 return true;
254 }
255 //
256 void
file_activated(GtkFileChooser * filechooser,gpointer user_data)257 VDKFileChooser::file_activated (GtkFileChooser *filechooser,
258 gpointer user_data)
259 {
260 VDKFileChooser* fc = reinterpret_cast<VDKFileChooser*>(user_data);
261 fc->OnokButtonClick(NULL);
262 }
263
264 //
265 void
AddFilterPattern(char * name,char * pattern)266 VDKFileChooser::AddFilterPattern(char* name, char* pattern)
267 {
268 GtkFileFilter *filter = gtk_file_filter_new ();
269 gtk_file_filter_set_name (filter, name);
270 gtk_file_filter_add_pattern (filter, pattern);
271 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (sigwid), filter);
272 }
273 //
274 void
AddMimeType(char * name,char * mime)275 VDKFileChooser::AddMimeType(char* name, char* mime)
276 {
277 GtkFileFilter *filter = gtk_file_filter_new ();
278 gtk_file_filter_set_name (filter, name);
279 gtk_file_filter_add_mime_type (filter, mime);
280 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (sigwid), filter);
281 }
282 //
SetDefaultFilter(char * name)283 void VDKFileChooser::SetDefaultFilter(char* name)
284 {
285 GSList* listhead = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (sigwid));
286 GSList* list = listhead;
287 while(list)
288 {
289 const gchar* fname = gtk_file_filter_get_name ((GtkFileFilter*) list->data);
290 if(!strcmp(fname,name))
291 {
292 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (sigwid),(GtkFileFilter*) list->data);
293 break;
294 }
295 list = list->next;
296 }
297 if(listhead)
298 g_slist_free(listhead);
299 }
300 //
RemoveFilter(char * name)301 void VDKFileChooser::RemoveFilter(char* name)
302 {
303 GSList* listhead = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (sigwid));
304 GSList* list = listhead;
305 while(list)
306 {
307 const gchar* fname = gtk_file_filter_get_name ((GtkFileFilter*) list->data);
308 if(!strcmp(fname,name))
309 {
310 gtk_file_chooser_remove_filter (GTK_FILE_CHOOSER (sigwid),(GtkFileFilter*) list->data);
311 break;
312 }
313 list = list->next;
314 }
315 if(listhead)
316 g_slist_free(listhead);
317 }
318
319
320 // end of file:vdkfc.cc
321