]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxFileSelector.cxx
a36f85f545d4004fdd25b187a1102f9262351574
[bbtk.git] / packages / wx / src / bbwxFileSelector.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxFileSelector.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:32 $
6   Version:   $Revision: 1.5 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36
37 #ifdef _USE_WXWIDGETS_
38
39
40 #include "bbwxFileSelector.h"
41 #include "bbwxPackage.h"
42 #include "bbtkWx.h"
43
44 #include <wx/filedlg.h>
45
46
47 namespace bbwx
48 {
49
50   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,FileSelector);
51   
52
53   BBTK_BLACK_BOX_IMPLEMENTATION(FileSelector,bbtk::AtomicBlackBox);
54
55
56   void FileSelector::Process() 
57   { 
58     bbtkDebugMessageInc("Core",9,"FileSelector::Process() ["
59                         <<bbGetFullName()<<"]"<<std::endl);
60
61     long style;
62     if (bbGetInputOpenSave()=="Save") 
63       {
64         style = wxSAVE | wxOVERWRITE_PROMPT;
65       }
66     else 
67       {
68         style = wxOPEN | wxFILE_MUST_EXIST;
69       }
70     
71     std::string wc(bbGetInputWildcard());
72     if (wc=="") 
73       {
74         wc = "*.*";
75       }
76     
77     
78     wxFileDialog* FD = new wxFileDialog( 0, 
79                                          bbtk::std2wx(bbGetInputMessage()),
80                                          bbtk::std2wx(bbGetInputDefaultDir()),
81                                          bbtk::std2wx(bbGetInputDefaultFile()),
82                                          bbtk::std2wx(wc),
83                                          style,
84                                          wxDefaultPosition);
85 //EED
86
87     int result_FD = FD->ShowModal();
88
89         // This line is need it by windows //EED
90         FD->SetReturnCode( result_FD );
91
92     if (FD->GetReturnCode()==wxID_OK)
93       {
94         bbSetOutputOut( bbtk::wx2std (FD->GetPath()) );
95       }
96     else
97       { 
98         bbSetOutputOut("");
99       }
100     
101     bbtkDebugDecTab("Core",9); 
102   }
103   
104
105   void FileSelector::bbUserConstructor()
106   {
107           bbSetInputOpenSave("Open");
108   }
109         
110
111
112 }//namespace bbtk
113
114 #endif // _USE_WXWIDGETS_ 
115