]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIOutputMessages.cxx
274b5e8324d5554f67258d2aba5f17514a445f50
[bbtk.git] / kernel / src / bbtkWxGUIOutputMessages.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIOutputMessages.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/12/09 08:46:20 $
6   Version:   $Revision: 1.4 $
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 /**
33  * \brief Short description in one line
34  * 
35  * Long description which 
36  * can span multiple lines
37  */
38 /**
39  * \file 
40  * \brief 
41  */
42 /**
43  * \class bbtk::
44  * \brief 
45  */
46
47
48 #ifdef _USE_WXWIDGETS_
49
50 #include "bbtkWxGUIOutputMessages.h"
51 #include "bbtkMessageManager.h"
52 #include "bbtkConfigurationFile.h"
53 #include "bbtkWxStreamRedirector.h"
54
55 namespace bbtk
56 {
57
58
59   WxGUIOutputMessages::WxGUIOutputMessages(wxWindow *parent, WxGUIOutputMessagesUser* user)
60     : wxPanel(parent,-1),
61       mUser(user)
62   {
63     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
64     mwxOutputText = 
65       new wxTextCtrl(this,
66                      -1, //ID_OutputText,
67                      _T(""),wxDefaultPosition,
68                      wxDefaultSize,
69                      wxTE_READONLY |
70                      wxTE_MULTILINE );
71  
72     mFixedFont = new wxFont(10,
73                                    wxFONTFAMILY_MODERN,
74                                    wxFONTSTYLE_NORMAL,
75                                    wxFONTWEIGHT_NORMAL,
76                                    false);
77
78    mwxOutputTextAttr = new wxTextAttr;
79    mwxOutputTextAttr->SetFont(*mFixedFont);
80    sizer->Add ( mwxOutputText, 1, wxGROW);
81    
82    // Redirection of std::cout to mwxTextHistory and printf
83     mRedirect_cout = 
84       new WxStreamRedirector(std::cout,mwxOutputText,*wxBLACK,true);
85     mRedirect_cerr = 
86       new WxStreamRedirector(std::cerr,mwxOutputText,*wxGREEN,true); 
87
88     SetSizer(sizer);
89     SetAutoLayout(true);
90     Layout();
91   }
92
93   WxGUIOutputMessages::~WxGUIOutputMessages()
94   {
95     delete mRedirect_cout;
96     delete mRedirect_cerr;
97    delete mwxOutputTextAttr;
98    delete mFixedFont;
99   } 
100
101   void WxGUIOutputMessages::Print(const std::string& message, 
102                                   const wxColor* col)
103   {
104     if (col != 0)
105       {
106         mwxOutputTextAttr->SetTextColour(*col);
107         mwxOutputText->SetDefaultStyle(*mwxOutputTextAttr);
108       }
109     mwxOutputText->AppendText(std2wx(message));
110     if (col != 0)
111       {
112         mwxOutputTextAttr->SetTextColour(*wxBLACK);
113         mwxOutputText->SetDefaultStyle(*mwxOutputTextAttr);
114       }
115   }
116
117
118 }
119
120 #endif