]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/logg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxLog-derived classes which need GUI support (the rest is in
5 // Author: Vadim Zeitlin
7 // Created: 20.09.99 (extracted from src/common/log.cpp)
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 // no #pragma implementation "log.h" because it's already in src/common/log.cpp
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
31 #error "This file can't be compiled without GUI!"
36 #include "wx/button.h"
41 #include "wx/filedlg.h"
42 #include "wx/msgdlg.h"
43 #include "wx/textctrl.h"
45 #include "wx/statbmp.h"
46 #include "wx/button.h"
49 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW
52 #include "wx/textfile.h"
53 #include "wx/statline.h"
56 // for OutputDebugString()
57 #include "wx/msw/private.h"
60 // may be defined to 0 for old behavior (using wxMessageBox) - shouldn't be
61 // changed normally (that's why it's here and not in setup.h).
62 // Actually it now is in setup.h.
63 #ifndef wxUSE_LOG_DIALOG
64 #define wxUSE_LOG_DIALOG 1
68 #include "wx/listctrl.h"
69 #include "wx/imaglist.h"
71 #else // !wxUSE_TEXTFILE
72 #include "wx/msgdlg.h"
73 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
81 // this function is a wrapper around strftime(3)
82 // allows to exclude the usage of wxDateTime
83 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
86 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
88 // buffer is too small?
89 wxFAIL_MSG(_T("strftime() failed"));
95 class wxLogDialog
: public wxDialog
98 wxLogDialog(wxWindow
*parent
,
99 const wxArrayString
& messages
,
100 const wxArrayInt
& severity
,
101 const wxArrayLong
& timess
,
102 const wxString
& caption
,
104 virtual ~wxLogDialog();
107 void OnOk(wxCommandEvent
& event
);
108 void OnDetails(wxCommandEvent
& event
);
110 void OnSave(wxCommandEvent
& event
);
112 void OnListSelect(wxListEvent
& event
);
115 // create controls needed for the details display
116 void CreateDetailsControls();
118 // the data for the listctrl
119 wxArrayString m_messages
;
120 wxArrayInt m_severity
;
123 // the "toggle" button and its state
124 wxButton
*m_btnDetails
;
125 bool m_showingDetails
;
127 // the controls which are not shown initially (but only when details
128 // button is pressed)
129 wxListCtrl
*m_listctrl
;
131 wxStaticLine
*m_statline
;
132 #endif // wxUSE_STATLINE
137 // the translated "Details" string
138 static wxString ms_details
;
140 DECLARE_EVENT_TABLE()
143 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
144 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
145 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
147 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
149 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
152 #endif // wxUSE_LOG_DIALOG
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 #if wxUSE_FILE && wxUSE_FILEDLG
160 // pass an uninitialized file object, the function will ask the user for the
161 // filename and try to open it, returns TRUE on success (file was opened),
162 // FALSE if file couldn't be opened/created and -1 if the file selection
163 // dialog was cancelled
164 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 // we use a global variable to store the frame pointer for wxLogStatus - bad,
173 // but it's the easiest way
174 static wxFrame
*gs_pFrame
; // FIXME MT-unsafe
176 // ============================================================================
178 // ============================================================================
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 // accepts an additional argument which tells to which frame the output should
186 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
190 wxLog
*pLog
= wxLog::GetActiveTarget();
191 if ( pLog
!= NULL
) {
193 va_start(argptr
, szFormat
);
194 msg
.PrintfV(szFormat
, argptr
);
197 wxASSERT( gs_pFrame
== NULL
); // should be reset!
199 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
200 gs_pFrame
= (wxFrame
*) NULL
;
204 // ----------------------------------------------------------------------------
205 // wxLogGui implementation (FIXME MT-unsafe)
206 // ----------------------------------------------------------------------------
213 void wxLogGui::Clear()
217 m_bHasMessages
= FALSE
;
224 void wxLogGui::Flush()
226 if ( !m_bHasMessages
)
229 // do it right now to block any new calls to Flush() while we're here
230 m_bHasMessages
= FALSE
;
232 wxString appName
= wxTheApp
->GetAppName();
234 appName
[0u] = wxToupper(appName
[0u]);
237 wxString titleFormat
;
239 titleFormat
= _("%s Error");
242 else if ( m_bWarnings
) {
243 titleFormat
= _("%s Warning");
244 style
= wxICON_EXCLAMATION
;
247 titleFormat
= _("%s Information");
248 style
= wxICON_INFORMATION
;
252 title
.Printf(titleFormat
, appName
.c_str());
254 // this is the best we can do here
255 wxWindow
*parent
= wxTheApp
->GetTopWindow();
257 size_t nMsgCount
= m_aMessages
.Count();
260 if ( nMsgCount
== 1 )
262 str
= m_aMessages
[0];
264 else // more than one message
268 wxLogDialog
dlg(parent
,
269 m_aMessages
, m_aSeverity
, m_aTimes
,
272 // clear the message list before showing the dialog because while it's
273 // shown some new messages may appear
276 (void)dlg
.ShowModal();
277 #else // !wxUSE_LOG_DIALOG
278 // concatenate all strings (but not too many to not overfill the msg box)
281 // start from the most recent message
282 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
283 // for Windows strings longer than this value are wrapped (NT 4.0)
284 const size_t nMsgLineWidth
= 156;
286 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
288 if ( nLines
> 25 ) // don't put too many lines in message box
291 str
<< m_aMessages
[n
- 1] << wxT("\n");
293 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
296 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
297 // situation without it
300 wxMessageBox(str
, title
, wxOK
| style
, parent
);
302 // no undisplayed messages whatsoever
307 // log all kinds of messages
308 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
316 m_aMessages
.Add(szString
);
317 m_aSeverity
.Add(wxLOG_Message
);
318 m_aTimes
.Add((long)t
);
319 m_bHasMessages
= TRUE
;
327 // find the top window and set it's status text if it has any
328 wxFrame
*pFrame
= gs_pFrame
;
329 if ( pFrame
== NULL
) {
330 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
331 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
332 pFrame
= (wxFrame
*)pWin
;
336 if ( pFrame
&& pFrame
->GetStatusBar() )
337 pFrame
->SetStatusText(szString
);
339 #endif // wxUSE_STATUSBAR
346 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
347 // don't prepend debug/trace here: it goes to the
348 // debug window anyhow, but do put a timestamp
351 str
<< szString
<< wxT("\r\n");
352 OutputDebugString(str
);
354 // send them to stderr
355 wxFprintf(stderr
, wxT("%s: %s\n"),
356 level
== wxLOG_Trace
? wxT("Trace")
362 #endif // __WXDEBUG__
366 case wxLOG_FatalError
:
367 // show this one immediately
368 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
374 #if !wxUSE_LOG_DIALOG
375 // discard earlier informational messages if this is the 1st
376 // error because they might not make sense any more and showing
377 // them in a message box might be confusing
381 #endif // wxUSE_LOG_DIALOG
388 // for the warning we don't discard the info messages
392 m_aMessages
.Add(szString
);
393 m_aSeverity
.Add((int)level
);
394 m_aTimes
.Add((long)t
);
395 m_bHasMessages
= TRUE
;
400 // ----------------------------------------------------------------------------
401 // wxLogWindow and wxLogFrame implementation
402 // ----------------------------------------------------------------------------
406 class wxLogFrame
: public wxFrame
410 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
411 virtual ~wxLogFrame();
414 void OnClose(wxCommandEvent
& event
);
415 void OnCloseWindow(wxCloseEvent
& event
);
417 void OnSave (wxCommandEvent
& event
);
419 void OnClear(wxCommandEvent
& event
);
421 void OnIdle(wxIdleEvent
&);
424 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
427 // use standard ids for our commands!
430 Menu_Close
= wxID_CLOSE
,
431 Menu_Save
= wxID_SAVE
,
432 Menu_Clear
= wxID_CLEAR
435 // common part of OnClose() and OnCloseWindow()
438 wxTextCtrl
*m_pTextCtrl
;
441 DECLARE_EVENT_TABLE()
444 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
445 // wxLogWindow menu events
446 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
448 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
450 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
452 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
455 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
456 : wxFrame(pParent
, -1, szTitle
)
460 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
468 wxMenuBar
*pMenuBar
= new wxMenuBar
;
469 wxMenu
*pMenu
= new wxMenu
;
471 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
473 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
474 pMenu
->AppendSeparator();
475 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
476 pMenuBar
->Append(pMenu
, _("&Log"));
477 SetMenuBar(pMenuBar
);
478 #endif // wxUSE_MENUS
481 // status bar for menu prompts
483 #endif // wxUSE_STATUSBAR
485 m_log
->OnFrameCreate(this);
488 void wxLogFrame::DoClose()
490 if ( m_log
->OnFrameClose(this) )
492 // instead of closing just hide the window to be able to Show() it
498 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
503 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
509 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
514 int rc
= OpenLogFile(file
, &filename
);
523 // retrieve text and save it
524 // -------------------------
525 int nLines
= m_pTextCtrl
->GetNumberOfLines();
526 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
527 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
528 wxTextFile::GetEOL());
535 wxLogError(_("Can't save log contents to file."));
538 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
544 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
546 m_pTextCtrl
->Clear();
549 wxLogFrame::~wxLogFrame()
551 m_log
->OnFrameDelete(this);
556 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
557 const wxChar
*szTitle
,
561 m_bPassMessages
= bDoPass
;
563 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
564 m_pOldLog
= wxLog::SetActiveTarget(this);
567 m_pLogFrame
->Show(TRUE
);
570 void wxLogWindow::Show(bool bShow
)
572 m_pLogFrame
->Show(bShow
);
575 void wxLogWindow::Flush()
577 if ( m_pOldLog
!= NULL
)
580 m_bHasMessages
= FALSE
;
583 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
585 // first let the previous logger show it
586 if ( m_pOldLog
!= NULL
&& m_bPassMessages
) {
587 // bogus cast just to access protected DoLog
588 ((wxLogWindow
*)m_pOldLog
)->DoLog(level
, szString
, t
);
594 // by default, these messages are ignored by wxLog, so process
596 if ( !wxIsEmpty(szString
) )
599 str
<< _("Status: ") << szString
;
604 // don't put trace messages in the text window for 2 reasons:
605 // 1) there are too many of them
606 // 2) they may provoke other trace messages thus sending a program
607 // into an infinite loop
612 // and this will format it nicely and call our DoLogString()
613 wxLog::DoLog(level
, szString
, t
);
617 m_bHasMessages
= TRUE
;
620 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
622 // put the text into our window
623 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
625 // remove selection (WriteText is in fact ReplaceSelection)
627 long nLen
= pText
->GetLastPosition();
628 pText
->SetSelection(nLen
, nLen
);
633 msg
<< szString
<< wxT('\n');
635 pText
->AppendText(msg
);
637 // TODO ensure that the line can be seen
640 wxFrame
*wxLogWindow::GetFrame() const
645 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
649 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
655 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
657 m_pLogFrame
= (wxLogFrame
*)NULL
;
660 wxLogWindow::~wxLogWindow()
664 // may be NULL if log frame already auto destroyed itself
668 // ----------------------------------------------------------------------------
670 // ----------------------------------------------------------------------------
674 static const size_t MARGIN
= 10;
676 wxString
wxLogDialog::ms_details
;
678 wxLogDialog::wxLogDialog(wxWindow
*parent
,
679 const wxArrayString
& messages
,
680 const wxArrayInt
& severity
,
681 const wxArrayLong
& times
,
682 const wxString
& caption
,
684 : wxDialog(parent
, -1, caption
)
686 if ( ms_details
.IsEmpty() )
688 // ensure that we won't loop here if wxGetTranslation()
689 // happens to pop up a Log message while translating this :-)
690 ms_details
= wxTRANSLATE("&Details");
691 ms_details
= wxGetTranslation(ms_details
);
694 size_t count
= messages
.GetCount();
695 m_messages
.Alloc(count
);
696 m_severity
.Alloc(count
);
697 m_times
.Alloc(count
);
699 for ( size_t n
= 0; n
< count
; n
++ )
701 wxString msg
= messages
[n
];
704 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
705 msg
= msg
.AfterFirst(_T('\n'));
707 m_severity
.Add(severity
[n
]);
708 m_times
.Add(times
[n
]);
713 m_showingDetails
= FALSE
; // not initially
714 m_listctrl
= (wxListCtrl
*)NULL
;
717 m_statline
= (wxStaticLine
*)NULL
;
718 #endif // wxUSE_STATLINE
721 m_btnSave
= (wxButton
*)NULL
;
724 // create the controls which are always shown and layout them: we use
725 // sizers even though our window is not resizeable to calculate the size of
726 // the dialog properly
727 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
728 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
729 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
731 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
732 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
733 // translates into click on cancel button)
734 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
735 sizerButtons
->Add(btnOk
, 0, wxCENTRE
|wxBOTTOM
, MARGIN
/2);
736 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ _T(" >>"));
737 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
|wxTOP
, MARGIN
/2 - 1);
740 wxIcon icon
= wxTheApp
->GetStdIcon((int)(style
& wxICON_MASK
));
741 sizerAll
->Add(new wxStaticBitmap(this, -1, icon
), 0, wxCENTRE
);
744 const wxString
& message
= messages
.Last();
745 sizerAll
->Add(CreateTextSizer(message
), 0, wxCENTRE
|wxLEFT
|wxRIGHT
, MARGIN
);
746 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
|wxLEFT
, MARGIN
);
748 sizerTop
->Add(sizerAll
, 0, wxCENTRE
|wxALL
, MARGIN
);
753 sizerTop
->SetSizeHints(this);
758 // this can't happen any more as we don't use this dialog in this case
762 // no details... it's easier to disable a button than to change the
763 // dialog layout depending on whether we have details or not
764 m_btnDetails
->Disable();
771 void wxLogDialog::CreateDetailsControls()
773 // create the save button and separator line if possible
775 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
779 m_statline
= new wxStaticLine(this, -1);
780 #endif // wxUSE_STATLINE
782 // create the list ctrl now
783 m_listctrl
= new wxListCtrl(this, -1,
784 wxDefaultPosition
, wxDefaultSize
,
790 // no need to translate these strings as they're not shown to the
791 // user anyhow (we use wxLC_NO_HEADER style)
792 m_listctrl
->InsertColumn(0, _T("Message"));
793 m_listctrl
->InsertColumn(1, _T("Time"));
795 // prepare the imagelist
796 static const int ICON_SIZE
= 16;
797 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
799 // order should be the same as in the switch below!
800 static const int icons
[] =
807 bool loadedIcons
= TRUE
;
810 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
812 wxBitmap bmp
= wxTheApp
->GetStdIcon(icons
[icon
]);
814 // This may very well fail if there are insufficient
815 // colours available. Degrade gracefully.
820 imageList
->Add(wxImage(bmp
).
821 Rescale(ICON_SIZE
, ICON_SIZE
).
825 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
829 wxString fmt
= wxLog::GetTimestamp();
836 size_t count
= m_messages
.GetCount();
837 for ( size_t n
= 0; n
< count
; n
++ )
841 switch ( m_severity
[n
] )
860 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
862 m_listctrl
->InsertItem(n
, m_messages
[n
]);
864 m_listctrl
->SetItem(n
, 1,
865 TimeStamp(fmt
, (time_t)m_times
[n
]));
868 // let the columns size themselves
869 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
870 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
872 // get the approx height of the listctrl
873 wxFont font
= GetFont();
875 font
= *wxSWISS_FONT
;
878 GetTextExtent(_T("H"), (int*)NULL
, &y
, (int*)NULL
, (int*)NULL
, &font
);
879 int height
= wxMax(y
*(count
+ 3), 100);
880 m_listctrl
->SetSize(-1, height
);
883 void wxLogDialog::OnListSelect(wxListEvent
& event
)
885 // we can't just disable the control because this looks ugly under Windows
886 // (wrong bg colour, no scrolling...), but we still want to disable
887 // selecting items - it makes no sense here
888 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
891 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
898 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
902 int rc
= OpenLogFile(file
);
911 wxString fmt
= wxLog::GetTimestamp();
918 size_t count
= m_messages
.GetCount();
919 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
922 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
925 << wxTextFile::GetEOL();
927 ok
= file
.Write(line
);
934 wxLogError(_("Can't save log contents to file."));
940 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
942 wxSizer
*sizer
= GetSizer();
944 if ( m_showingDetails
)
946 m_btnDetails
->SetLabel(ms_details
+ _T(">>"));
948 sizer
->Remove(m_listctrl
);
951 sizer
->Remove(m_statline
);
952 #endif // wxUSE_STATLINE
955 sizer
->Remove(m_btnSave
);
958 else // show details now
960 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
964 CreateDetailsControls();
968 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
969 #endif // wxUSE_STATLINE
971 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
974 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
978 m_showingDetails
= !m_showingDetails
;
980 // in any case, our size changed - update
981 sizer
->SetSizeHints(this);
985 // VS: this is neccessary in order to force frame redraw under
986 // WindowMaker or fvwm2 (and probably other broken WMs).
987 // Otherwise, detailed list wouldn't be displayed.
992 wxLogDialog::~wxLogDialog()
996 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1000 #endif // wxUSE_LOG_DIALOG
1002 #if wxUSE_FILE && wxUSE_FILEDLG
1004 // pass an uninitialized file object, the function will ask the user for the
1005 // filename and try to open it, returns TRUE on success (file was opened),
1006 // FALSE if file couldn't be opened/created and -1 if the file selection
1007 // dialog was cancelled
1008 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1010 // get the file name
1011 // -----------------
1012 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1021 if ( wxFile::Exists(filename
) ) {
1022 bool bAppend
= FALSE
;
1024 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1026 switch ( wxMessageBox(strMsg
, _("Question"),
1027 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1040 wxFAIL_MSG(_("invalid message box return value"));
1044 bOk
= file
.Open(filename
, wxFile::write_append
);
1047 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1051 bOk
= file
.Create(filename
);
1055 *pFilename
= filename
;
1060 #endif // wxUSE_FILE
1062 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1066 // ----------------------------------------------------------------------------
1067 // wxLogTextCtrl implementation
1068 // ----------------------------------------------------------------------------
1070 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1072 m_pTextCtrl
= pTextCtrl
;
1075 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1081 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1082 // translation must be done in wxTextCtrl, not here! (FIXME)
1083 msg
<< szString
<< wxT('\r');
1085 msg
<< szString
<< wxT('\n');
1088 m_pTextCtrl
->AppendText(msg
);
1091 #endif // wxUSE_TEXTCTRL