1 /*****************************************************************
2 ViewKlass - C++ framework library for Motif
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 Copyright (C) 2001 John Lemcke
19 jostle@users.sourceforge.net
20 *****************************************************************/
21
22 /**
23 *
24 * VkFileSelectionDialog.C
25 *
26 * This file contains the class implementation for the
27 * VkFileSelectionDialog class.
28 *
29 * Chris Toshok
30 * Copyright (C) 1994
31 * The Hungry Programmers, Inc
32 *
33 **/
34
35 static const char* rcsid
36 #ifdef __GNUC__
37 __attribute__ ((unused))
38 #endif
39 = "$Id: VkFileSelectionDialog.C,v 1.11 2009/03/21 11:44:34 jostle Exp $";
40
41 #include <string>
42 #include <iostream>
43
44 using namespace std;
45
46 #include <Vk/VkFileSelectionDialog.h>
47 #include <Vk/VkApp.h>
48
VkFileSelectionDialog(const char * name)49 VkFileSelectionDialog::VkFileSelectionDialog(const char *name)
50 : VkDialogManager(name),
51 _directory(0),
52 _pattern(0),
53 _selection(0),
54 _filename(0),
55 _dialogBox(0)
56 {
57 _showOK = True;
58 _showCancel = True;
59 _showApply = True;
60
61 _dialogShellTitle = NULL;
62 }
63
64 Widget
createDialog(Widget parent)65 VkFileSelectionDialog::createDialog(Widget parent)
66 {
67 Arg args[5];
68 int n =0;
69 XmString dirXmstr = 0;
70 XmString patXmstr = 0;
71 XmString selXmstr = 0;
72
73 XtSetArg(args[n], XmNdefaultButton, XmDIALOG_APPLY_BUTTON); n++;
74 if (_directory) {
75 dirXmstr = XmStringCreateLocalized(_directory);
76 XtSetArg(args[n], XmNdirectory, dirXmstr); n++;
77 }
78 if (_pattern) {
79 patXmstr = XmStringCreateLocalized(_pattern);
80 XtSetArg(args[n], XmNpattern, patXmstr); n++;
81 }
82 if (_selection) {
83 selXmstr = XmStringCreateLocalized(_selection);
84 XtSetArg(args[n], XmNdirSpec, selXmstr); n++;
85 }
86
87 _dialogBox =
88 XmCreateFileSelectionDialog(parent, (char*)_name, args, n);
89
90 if (dirXmstr) XmStringFree(dirXmstr);
91 if (patXmstr) XmStringFree(patXmstr);
92 if (selXmstr) XmStringFree(selXmstr);
93
94 return _dialogBox;
95 }
96
97 void
setDirectory(const char * directory)98 VkFileSelectionDialog::setDirectory(const char *directory)
99 {
100 delete []_directory;
101 _directory = new char[strlen(directory) + 1];
102 strcpy(_directory, directory);
103
104 if (_dialogBox) {
105 XmString xmstr = XmStringCreateLocalized(_directory);
106 XtVaSetValues(_dialogBox, XmNdirectory, xmstr, NULL);
107 XmStringFree(xmstr);
108 }
109 }
110
111 void
setFilterPattern(const char * pattern)112 VkFileSelectionDialog::setFilterPattern(const char *pattern)
113 {
114 delete []_pattern;
115 _pattern = new char[strlen(pattern) + 1];
116 strcpy(_pattern, pattern);
117
118 if (_dialogBox) {
119 XmString xmstr = XmStringCreateLocalized(_pattern);
120 XtVaSetValues(_dialogBox, XmNpattern, xmstr, NULL);
121 XmFileSelectionDoSearch(_dialogBox, xmstr);
122 XmStringFree(xmstr);
123 }
124 }
125
126 void
setSelection(const char * selection)127 VkFileSelectionDialog::setSelection(const char *selection)
128 {
129 delete []_selection;
130 _selection = new char[strlen(selection) + 1];
131 strcpy(_selection, selection);
132
133 if (_dialogBox) {
134 XmString xmstr = XmStringCreateLocalized(_selection);
135 XtVaSetValues(_dialogBox, XmNdirSpec, xmstr, NULL);
136 XmStringFree(xmstr);
137 }
138 }
139
140 const char *
fileName()141 VkFileSelectionDialog::fileName()
142 {
143 return _filename;
144 }
145
146 void
ok(Widget w,XtPointer callData)147 VkFileSelectionDialog::ok(Widget w, XtPointer callData)
148 {
149 char *filename;
150
151 XmFileSelectionBoxCallbackStruct *cb
152 = (XmFileSelectionBoxCallbackStruct*)callData;
153
154 XmStringGetLtoR(cb->value, XmFONTLIST_DEFAULT_TAG, &filename);
155 delete []_filename;
156 _filename = new char[strlen(filename) + 1];
157 strcpy(_filename, filename);
158
159 XtFree(filename);
160
161 VkDialogManager::ok(w, callData);
162 }
163
theFileSelectionDialogInstance()164 VkFileSelectionDialog* theFileSelectionDialogInstance()
165 {
166 static VkFileSelectionDialog* instance = 0;
167 if (instance == 0) {
168 instance = new VkFileSelectionDialog("FileSelection");
169 }
170 return instance;
171 }
172