xref: /aoo42x/main/sd/source/ui/notes/TextLogger.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "TextLogger.hxx"
32 
33 #include "EditWindow.hxx"
34 #include <vos/mutex.hxx>
35 #include <vcl/svapp.hxx>
36 
37 namespace sd { namespace notes {
38 
39 TextLogger* TextLogger::spInstance = NULL;
40 
41 TextLogger& TextLogger::Instance (void)
42 {
43     if (spInstance == NULL)
44     {
45         ::vos::OGuard aGuard (::Application::GetSolarMutex());
46         if (spInstance == NULL)
47             spInstance = new TextLogger ();
48     }
49     return *spInstance;
50 }
51 
52 
53 
54 
55 TextLogger::TextLogger (void)
56     : mpEditWindow (NULL)
57 {
58 }
59 
60 
61 
62 
63 void TextLogger::AppendText (const char* sText)
64 {
65     OSL_TRACE (sText);
66     if (mpEditWindow != NULL)
67         mpEditWindow->InsertText (UniString::CreateFromAscii(sText));
68 }
69 
70 
71 
72 
73 void TextLogger::AppendText (const String& sText)
74 {
75     ByteString s(sText, RTL_TEXTENCODING_ISO_8859_1);
76     OSL_TRACE (s.GetBuffer());
77     if (mpEditWindow != NULL)
78         mpEditWindow->InsertText (sText);
79 }
80 
81 
82 
83 
84 void TextLogger::AppendNumber (long int nValue)
85 {
86     AppendText (String::CreateFromInt32(nValue));
87 }
88 
89 
90 
91 
92 void TextLogger::ConnectToEditWindow (EditWindow* pEditWindow)
93 {
94     if (mpEditWindow != pEditWindow)
95     {
96         if (pEditWindow != NULL)
97             pEditWindow->AddEventListener(
98                 LINK(this, TextLogger, WindowEventHandler));
99         else
100             mpEditWindow->RemoveEventListener(
101                 LINK(this, TextLogger, WindowEventHandler));
102 
103         mpEditWindow = pEditWindow;
104     }
105 }
106 
107 
108 
109 
110 IMPL_LINK(TextLogger, WindowEventHandler, VclWindowEvent*, pEvent)
111 {
112     if (pEvent != NULL)
113     {
114         DBG_ASSERT(static_cast<VclWindowEvent*>(pEvent)->GetWindow()
115             == mpEditWindow,
116             "TextLogger: received event from unknown window");
117         switch (pEvent->GetId())
118         {
119             case VCLEVENT_WINDOW_CLOSE:
120             case VCLEVENT_OBJECT_DYING:
121                 mpEditWindow = NULL;
122                 break;
123         }
124     }
125     return sal_True;
126 }
127 
128 
129 } } // end of namespace ::sd::notes
130