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