xref: /trunk/main/sd/source/ui/notes/TextLogger.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "TextLogger.hxx"
28 
29 #include "EditWindow.hxx"
30 #include <vos/mutex.hxx>
31 #include <vcl/svapp.hxx>
32 
33 namespace sd { namespace notes {
34 
35 TextLogger* TextLogger::spInstance = NULL;
36 
Instance(void)37 TextLogger& TextLogger::Instance (void)
38 {
39     if (spInstance == NULL)
40     {
41         ::vos::OGuard aGuard (::Application::GetSolarMutex());
42         if (spInstance == NULL)
43             spInstance = new TextLogger ();
44     }
45     return *spInstance;
46 }
47 
48 
49 
50 
TextLogger(void)51 TextLogger::TextLogger (void)
52     : mpEditWindow (NULL)
53 {
54 }
55 
56 
57 
58 
AppendText(const char * sText)59 void TextLogger::AppendText (const char* sText)
60 {
61     OSL_TRACE (sText);
62     if (mpEditWindow != NULL)
63         mpEditWindow->InsertText (UniString::CreateFromAscii(sText));
64 }
65 
66 
67 
68 
AppendText(const String & sText)69 void TextLogger::AppendText (const String& sText)
70 {
71     ByteString s(sText, RTL_TEXTENCODING_ISO_8859_1);
72     OSL_TRACE (s.GetBuffer());
73     if (mpEditWindow != NULL)
74         mpEditWindow->InsertText (sText);
75 }
76 
77 
78 
79 
AppendNumber(long int nValue)80 void TextLogger::AppendNumber (long int nValue)
81 {
82     AppendText (String::CreateFromInt32(nValue));
83 }
84 
85 
86 
87 
ConnectToEditWindow(EditWindow * pEditWindow)88 void TextLogger::ConnectToEditWindow (EditWindow* pEditWindow)
89 {
90     if (mpEditWindow != pEditWindow)
91     {
92         if (pEditWindow != NULL)
93             pEditWindow->AddEventListener(
94                 LINK(this, TextLogger, WindowEventHandler));
95         else
96             mpEditWindow->RemoveEventListener(
97                 LINK(this, TextLogger, WindowEventHandler));
98 
99         mpEditWindow = pEditWindow;
100     }
101 }
102 
103 
104 
105 
IMPL_LINK(TextLogger,WindowEventHandler,VclWindowEvent *,pEvent)106 IMPL_LINK(TextLogger, WindowEventHandler, VclWindowEvent*, pEvent)
107 {
108     if (pEvent != NULL)
109     {
110         DBG_ASSERT(static_cast<VclWindowEvent*>(pEvent)->GetWindow()
111             == mpEditWindow,
112             "TextLogger: received event from unknown window");
113         switch (pEvent->GetId())
114         {
115             case VCLEVENT_WINDOW_CLOSE:
116             case VCLEVENT_OBJECT_DYING:
117                 mpEditWindow = NULL;
118                 break;
119         }
120     }
121     return sal_True;
122 }
123 
124 
125 } } // end of namespace ::sd::notes
126