1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TextLogger.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "TextLogger.hxx"
36 #include "EditWindow.hxx"
37 #include <vos/mutex.hxx>
38 #include <vcl/svapp.hxx>
40 namespace sd
{ namespace notes
{
42 TextLogger
* TextLogger::spInstance
= NULL
;
44 TextLogger
& TextLogger::Instance (void)
46 if (spInstance
== NULL
)
48 ::vos::OGuard
aGuard (::Application::GetSolarMutex());
49 if (spInstance
== NULL
)
50 spInstance
= new TextLogger ();
58 TextLogger::TextLogger (void)
66 void TextLogger::AppendText (const char* sText
)
69 if (mpEditWindow
!= NULL
)
70 mpEditWindow
->InsertText (UniString::CreateFromAscii(sText
));
76 void TextLogger::AppendText (const String
& sText
)
78 ByteString
s(sText
, RTL_TEXTENCODING_ISO_8859_1
);
79 OSL_TRACE (s
.GetBuffer());
80 if (mpEditWindow
!= NULL
)
81 mpEditWindow
->InsertText (sText
);
87 void TextLogger::AppendNumber (long int nValue
)
89 AppendText (String::CreateFromInt32(nValue
));
95 void TextLogger::ConnectToEditWindow (EditWindow
* pEditWindow
)
97 if (mpEditWindow
!= pEditWindow
)
99 if (pEditWindow
!= NULL
)
100 pEditWindow
->AddEventListener(
101 LINK(this, TextLogger
, WindowEventHandler
));
103 mpEditWindow
->RemoveEventListener(
104 LINK(this, TextLogger
, WindowEventHandler
));
106 mpEditWindow
= pEditWindow
;
113 IMPL_LINK(TextLogger
, WindowEventHandler
, VclWindowEvent
*, pEvent
)
117 DBG_ASSERT(static_cast<VclWindowEvent
*>(pEvent
)->GetWindow()
119 "TextLogger: received event from unknown window");
120 switch (pEvent
->GetId())
122 case VCLEVENT_WINDOW_CLOSE
:
123 case VCLEVENT_OBJECT_DYING
:
132 } } // end of namespace ::sd::notes