]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIOutputMessages.cxx
d7d13bc4102fa275275f3991f07ae690a5b3b5e7
[bbtk.git] / kernel / src / bbtkWxGUIOutputMessages.cxx
1  /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkWxGUIOutputMessages.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/03/20 15:27:57 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*//**
18  * \brief Short description in one line
19  * 
20  * Long description which 
21  * can span multiple lines
22  */
23 /**
24  * \file 
25  * \brief 
26  */
27 /**
28  * \class bbtk::
29  * \brief 
30  */
31
32
33 #ifdef _USE_WXWIDGETS_
34
35 #include "bbtkWxGUIOutputMessages.h"
36 #include "bbtkMessageManager.h"
37 #include "bbtkConfigurationFile.h"
38 #include "bbtkWxStreamRedirector.h"
39
40 namespace bbtk
41 {
42
43
44   WxGUIOutputMessages::WxGUIOutputMessages(wxWindow *parent, WxGUIOutputMessagesUser* user)
45     : wxPanel(parent,-1),
46       mUser(user)
47   {
48     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
49     mwxOutputText = 
50       new wxTextCtrl(this,
51                      -1, //ID_OutputText,
52                      _T(""),wxDefaultPosition,
53                      wxDefaultSize,
54                      wxTE_READONLY |
55                      wxTE_MULTILINE );
56  
57     wxFont* FixedFont = new wxFont(10,
58                                    wxFONTFAMILY_MODERN,
59                                    wxFONTSTYLE_NORMAL,
60                                    wxFONTWEIGHT_NORMAL,
61                                    false);
62
63    mwxOutputTextAttr = new wxTextAttr;
64    mwxOutputTextAttr->SetFont(*FixedFont);
65    sizer->Add ( mwxOutputText, 1, wxGROW);
66    
67    // Redirection of std::cout to mwxTextHistory and printf
68     mRedirect_cout = 
69       new WxStreamRedirector(std::cout,mwxOutputText,*wxBLACK,true);
70     mRedirect_cerr = 
71       new WxStreamRedirector(std::cerr,mwxOutputText,*wxGREEN,true); 
72
73     SetSizer(sizer);
74     SetAutoLayout(true);
75     Layout();
76   }
77
78   WxGUIOutputMessages::~WxGUIOutputMessages()
79   {
80     delete mRedirect_cout;
81     delete mRedirect_cerr;
82    
83   } 
84
85   void WxGUIOutputMessages::Print(const std::string& message, 
86                                   const wxColor* col)
87   {
88     if (col != 0)
89       {
90         mwxOutputTextAttr->SetTextColour(*col);
91         mwxOutputText->SetDefaultStyle(*mwxOutputTextAttr);
92       }
93     mwxOutputText->AppendText(std2wx(message));
94     if (col != 0)
95       {
96         mwxOutputTextAttr->SetTextColour(*wxBLACK);
97         mwxOutputText->SetDefaultStyle(*mwxOutputTextAttr);
98       }
99   }
100
101
102 }
103
104 #endif