]>
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"
47 #include "wx/settings.h"
50 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW
53 #include "wx/textfile.h"
54 #include "wx/statline.h"
57 // for OutputDebugString()
58 #include "wx/msw/private.h"
62 #include "wx/listctrl.h"
63 #include "wx/imaglist.h"
65 #else // !wxUSE_LOG_DIALOG
66 #include "wx/msgdlg.h"
67 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
75 // this function is a wrapper around strftime(3)
76 // allows to exclude the usage of wxDateTime
77 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
80 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
82 // buffer is too small?
83 wxFAIL_MSG(_T("strftime() failed"));
89 class wxLogDialog
: public wxDialog
92 wxLogDialog(wxWindow
*parent
,
93 const wxArrayString
& messages
,
94 const wxArrayInt
& severity
,
95 const wxArrayLong
& timess
,
96 const wxString
& caption
,
98 virtual ~wxLogDialog();
101 void OnOk(wxCommandEvent
& event
);
102 void OnDetails(wxCommandEvent
& event
);
104 void OnSave(wxCommandEvent
& event
);
106 void OnListSelect(wxListEvent
& event
);
109 // create controls needed for the details display
110 void CreateDetailsControls();
112 // the data for the listctrl
113 wxArrayString m_messages
;
114 wxArrayInt m_severity
;
117 // the "toggle" button and its state
118 wxButton
*m_btnDetails
;
119 bool m_showingDetails
;
121 // the controls which are not shown initially (but only when details
122 // button is pressed)
123 wxListCtrl
*m_listctrl
;
125 wxStaticLine
*m_statline
;
126 #endif // wxUSE_STATLINE
131 // the translated "Details" string
132 static wxString ms_details
;
134 DECLARE_EVENT_TABLE()
137 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
138 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
139 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
141 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
143 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
146 #endif // wxUSE_LOG_DIALOG
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 #if wxUSE_FILE && wxUSE_FILEDLG
154 // pass an uninitialized file object, the function will ask the user for the
155 // filename and try to open it, returns TRUE on success (file was opened),
156 // FALSE if file couldn't be opened/created and -1 if the file selection
157 // dialog was cancelled
158 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 // we use a global variable to store the frame pointer for wxLogStatus - bad,
167 // but it's the easiest way
168 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
170 // ============================================================================
172 // ============================================================================
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 // accepts an additional argument which tells to which frame the output should
180 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
184 wxLog
*pLog
= wxLog::GetActiveTarget();
185 if ( pLog
!= NULL
) {
186 msg
.PrintfV(szFormat
, argptr
);
188 wxASSERT( gs_pFrame
== NULL
); // should be reset!
190 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
191 gs_pFrame
= (wxFrame
*) NULL
;
195 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
198 va_start(argptr
, szFormat
);
199 wxVLogStatus(pFrame
, szFormat
, argptr
);
203 // ----------------------------------------------------------------------------
204 // wxLogGui implementation (FIXME MT-unsafe)
205 // ----------------------------------------------------------------------------
212 void wxLogGui::Clear()
216 m_bHasMessages
= FALSE
;
223 void wxLogGui::Flush()
225 if ( !m_bHasMessages
)
228 // do it right now to block any new calls to Flush() while we're here
229 m_bHasMessages
= FALSE
;
231 wxString appName
= wxTheApp
->GetAppName();
233 appName
[0u] = wxToupper(appName
[0u]);
236 wxString titleFormat
;
238 titleFormat
= _("%s Error");
241 else if ( m_bWarnings
) {
242 titleFormat
= _("%s Warning");
243 style
= wxICON_EXCLAMATION
;
246 titleFormat
= _("%s Information");
247 style
= wxICON_INFORMATION
;
251 title
.Printf(titleFormat
, appName
.c_str());
253 size_t nMsgCount
= m_aMessages
.Count();
255 // avoid showing other log dialogs until we're done with the dialog we're
256 // showing right now: nested modal dialogs make for really bad UI!
260 if ( nMsgCount
== 1 )
262 str
= m_aMessages
[0];
264 else // more than one message
268 wxLogDialog
dlg(NULL
,
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
);
302 // no undisplayed messages whatsoever
306 // allow flushing the logs again
310 // log all kinds of messages
311 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
318 m_aMessages
.Add(szString
);
319 m_aSeverity
.Add(wxLOG_Message
);
320 m_aTimes
.Add((long)t
);
321 m_bHasMessages
= TRUE
;
328 // find the top window and set it's status text if it has any
329 wxFrame
*pFrame
= gs_pFrame
;
330 if ( pFrame
== NULL
) {
331 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
332 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
333 pFrame
= (wxFrame
*)pWin
;
337 if ( pFrame
&& pFrame
->GetStatusBar() )
338 pFrame
->SetStatusText(szString
);
340 #endif // wxUSE_STATUSBAR
351 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
352 // don't prepend debug/trace here: it goes to the
353 // debug window anyhow
355 OutputDebugString(str
);
357 // send them to stderr
358 wxFprintf(stderr
, wxT("[%s] %s\n"),
359 level
== wxLOG_Trace
? wxT("Trace")
365 #endif // __WXDEBUG__
369 case wxLOG_FatalError
:
370 // show this one immediately
371 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
377 #if !wxUSE_LOG_DIALOG
378 // discard earlier informational messages if this is the 1st
379 // error because they might not make sense any more and showing
380 // them in a message box might be confusing
384 #endif // wxUSE_LOG_DIALOG
391 // for the warning we don't discard the info messages
395 m_aMessages
.Add(szString
);
396 m_aSeverity
.Add((int)level
);
397 m_aTimes
.Add((long)t
);
398 m_bHasMessages
= TRUE
;
403 // ----------------------------------------------------------------------------
404 // wxLogWindow and wxLogFrame implementation
405 // ----------------------------------------------------------------------------
409 class wxLogFrame
: public wxFrame
413 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
414 virtual ~wxLogFrame();
417 void OnClose(wxCommandEvent
& event
);
418 void OnCloseWindow(wxCloseEvent
& event
);
420 void OnSave (wxCommandEvent
& event
);
422 void OnClear(wxCommandEvent
& event
);
424 void OnIdle(wxIdleEvent
&);
427 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
430 // use standard ids for our commands!
433 Menu_Close
= wxID_CLOSE
,
434 Menu_Save
= wxID_SAVE
,
435 Menu_Clear
= wxID_CLEAR
438 // common part of OnClose() and OnCloseWindow()
441 wxTextCtrl
*m_pTextCtrl
;
444 DECLARE_EVENT_TABLE()
447 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
448 // wxLogWindow menu events
449 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
451 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
453 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
455 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
458 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
459 : wxFrame(pParent
, -1, szTitle
)
463 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
467 // needed for Win32 to avoid 65Kb limit but it doesn't work well
468 // when using RichEdit 2.0 which we always do in the Unicode build
471 #endif // !wxUSE_UNICODE
476 wxMenuBar
*pMenuBar
= new wxMenuBar
;
477 wxMenu
*pMenu
= new wxMenu
;
479 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
481 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
482 pMenu
->AppendSeparator();
483 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
484 pMenuBar
->Append(pMenu
, _("&Log"));
485 SetMenuBar(pMenuBar
);
486 #endif // wxUSE_MENUS
489 // status bar for menu prompts
491 #endif // wxUSE_STATUSBAR
493 m_log
->OnFrameCreate(this);
496 void wxLogFrame::DoClose()
498 if ( m_log
->OnFrameClose(this) )
500 // instead of closing just hide the window to be able to Show() it
506 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
511 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
517 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
522 int rc
= OpenLogFile(file
, &filename
);
531 // retrieve text and save it
532 // -------------------------
533 int nLines
= m_pTextCtrl
->GetNumberOfLines();
534 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
535 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
536 wxTextFile::GetEOL());
543 wxLogError(_("Can't save log contents to file."));
546 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
552 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
554 m_pTextCtrl
->Clear();
557 wxLogFrame::~wxLogFrame()
559 m_log
->OnFrameDelete(this);
565 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
566 const wxChar
*szTitle
,
570 PassMessages(bDoPass
);
572 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
575 m_pLogFrame
->Show(TRUE
);
578 void wxLogWindow::Show(bool bShow
)
580 m_pLogFrame
->Show(bShow
);
583 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
585 // first let the previous logger show it
586 wxLogPassThrough::DoLog(level
, szString
, t
);
591 // by default, these messages are ignored by wxLog, so process
593 if ( !wxIsEmpty(szString
) )
596 str
<< _("Status: ") << szString
;
601 // don't put trace messages in the text window for 2 reasons:
602 // 1) there are too many of them
603 // 2) they may provoke other trace messages thus sending a program
604 // into an infinite loop
609 // and this will format it nicely and call our DoLogString()
610 wxLog::DoLog(level
, szString
, t
);
614 m_bHasMessages
= TRUE
;
617 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
619 // put the text into our window
620 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
622 // remove selection (WriteText is in fact ReplaceSelection)
624 long nLen
= pText
->GetLastPosition();
625 pText
->SetSelection(nLen
, nLen
);
630 msg
<< szString
<< wxT('\n');
632 pText
->AppendText(msg
);
634 // TODO ensure that the line can be seen
637 wxFrame
*wxLogWindow::GetFrame() const
642 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
646 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
652 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
654 m_pLogFrame
= (wxLogFrame
*)NULL
;
657 wxLogWindow::~wxLogWindow()
659 // may be NULL if log frame already auto destroyed itself
663 // ----------------------------------------------------------------------------
665 // ----------------------------------------------------------------------------
669 static const size_t MARGIN
= 10;
671 wxString
wxLogDialog::ms_details
;
673 wxLogDialog::wxLogDialog(wxWindow
*parent
,
674 const wxArrayString
& messages
,
675 const wxArrayInt
& severity
,
676 const wxArrayLong
& times
,
677 const wxString
& caption
,
679 : wxDialog(parent
, -1, caption
,
680 wxDefaultPosition
, wxDefaultSize
,
681 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
683 if ( ms_details
.IsEmpty() )
685 // ensure that we won't loop here if wxGetTranslation()
686 // happens to pop up a Log message while translating this :-)
687 ms_details
= wxTRANSLATE("&Details");
688 ms_details
= wxGetTranslation(ms_details
);
691 size_t count
= messages
.GetCount();
692 m_messages
.Alloc(count
);
693 m_severity
.Alloc(count
);
694 m_times
.Alloc(count
);
696 for ( size_t n
= 0; n
< count
; n
++ )
698 wxString msg
= messages
[n
];
701 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
702 msg
= msg
.AfterFirst(_T('\n'));
704 m_severity
.Add(severity
[n
]);
705 m_times
.Add(times
[n
]);
710 m_showingDetails
= FALSE
; // not initially
711 m_listctrl
= (wxListCtrl
*)NULL
;
714 m_statline
= (wxStaticLine
*)NULL
;
715 #endif // wxUSE_STATLINE
718 m_btnSave
= (wxButton
*)NULL
;
721 // create the controls which are always shown and layout them: we use
722 // sizers even though our window is not resizeable to calculate the size of
723 // the dialog properly
724 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
725 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
726 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
728 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
729 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
730 // translates into click on cancel button)
731 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
732 sizerButtons
->Add(btnOk
, 0, wxCENTRE
| wxBOTTOM
, MARGIN
/2);
733 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ _T(" >>"));
734 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
737 wxIcon icon
= wxTheApp
->GetStdIcon((int)(style
& wxICON_MASK
));
738 sizerAll
->Add(new wxStaticBitmap(this, -1, icon
), 0);
741 const wxString
& message
= messages
.Last();
742 sizerAll
->Add(CreateTextSizer(message
), 1,
743 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
744 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
| wxLEFT
, MARGIN
);
746 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
751 sizerTop
->SetSizeHints(this);
756 // this can't happen any more as we don't use this dialog in this case
760 // no details... it's easier to disable a button than to change the
761 // dialog layout depending on whether we have details or not
762 m_btnDetails
->Disable();
769 void wxLogDialog::CreateDetailsControls()
771 // create the save button and separator line if possible
773 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
777 m_statline
= new wxStaticLine(this, -1);
778 #endif // wxUSE_STATLINE
780 // create the list ctrl now
781 m_listctrl
= new wxListCtrl(this, -1,
782 wxDefaultPosition
, wxDefaultSize
,
788 // no need to translate these strings as they're not shown to the
789 // user anyhow (we use wxLC_NO_HEADER style)
790 m_listctrl
->InsertColumn(0, _T("Message"));
791 m_listctrl
->InsertColumn(1, _T("Time"));
793 // prepare the imagelist
794 static const int ICON_SIZE
= 16;
795 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
797 // order should be the same as in the switch below!
798 static const int icons
[] =
805 bool loadedIcons
= TRUE
;
808 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
810 wxBitmap bmp
= wxTheApp
->GetStdIcon(icons
[icon
]);
812 // This may very well fail if there are insufficient
813 // colours available. Degrade gracefully.
818 imageList
->Add(wxImage(bmp
).
819 Rescale(ICON_SIZE
, ICON_SIZE
).
823 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
827 wxString fmt
= wxLog::GetTimestamp();
834 size_t count
= m_messages
.GetCount();
835 for ( size_t n
= 0; n
< count
; n
++ )
839 switch ( m_severity
[n
] )
858 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
860 m_listctrl
->InsertItem(n
, m_messages
[n
]);
862 m_listctrl
->SetItem(n
, 1,
863 TimeStamp(fmt
, (time_t)m_times
[n
]));
866 // let the columns size themselves
867 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
868 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
870 // get the approx height of the listctrl
871 wxFont font
= GetFont();
873 font
= *wxSWISS_FONT
;
876 GetTextExtent(_T("H"), (int*)NULL
, &y
, (int*)NULL
, (int*)NULL
, &font
);
877 int height
= wxMax(y
*(count
+ 3), 100);
879 // if the height as computed from list items exceeds, together with the
880 // actual message & controls, the screen, make it smaller
882 (3*wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
))/5 - GetSize().y
;
884 m_listctrl
->SetSize(-1, wxMin(height
, heightMax
));
887 void wxLogDialog::OnListSelect(wxListEvent
& event
)
889 // we can't just disable the control because this looks ugly under Windows
890 // (wrong bg colour, no scrolling...), but we still want to disable
891 // selecting items - it makes no sense here
892 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
895 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
902 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
906 int rc
= OpenLogFile(file
);
915 wxString fmt
= wxLog::GetTimestamp();
922 size_t count
= m_messages
.GetCount();
923 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
926 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
929 << wxTextFile::GetEOL();
931 ok
= file
.Write(line
);
938 wxLogError(_("Can't save log contents to file."));
944 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
946 wxSizer
*sizer
= GetSizer();
948 if ( m_showingDetails
)
950 m_btnDetails
->SetLabel(ms_details
+ _T(">>"));
952 sizer
->Remove(m_listctrl
);
955 sizer
->Remove(m_statline
);
956 #endif // wxUSE_STATLINE
959 sizer
->Remove(m_btnSave
);
962 else // show details now
964 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
968 CreateDetailsControls();
972 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
973 #endif // wxUSE_STATLINE
975 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
978 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
982 m_showingDetails
= !m_showingDetails
;
984 // in any case, our size changed - update
985 sizer
->SetSizeHints(this);
989 // VS: this is neccessary in order to force frame redraw under
990 // WindowMaker or fvwm2 (and probably other broken WMs).
991 // Otherwise, detailed list wouldn't be displayed.
996 wxLogDialog::~wxLogDialog()
1000 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1004 #endif // wxUSE_LOG_DIALOG
1006 #if wxUSE_FILE && wxUSE_FILEDLG
1008 // pass an uninitialized file object, the function will ask the user for the
1009 // filename and try to open it, returns TRUE on success (file was opened),
1010 // FALSE if file couldn't be opened/created and -1 if the file selection
1011 // dialog was cancelled
1012 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1014 // get the file name
1015 // -----------------
1016 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1025 if ( wxFile::Exists(filename
) ) {
1026 bool bAppend
= FALSE
;
1028 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1030 switch ( wxMessageBox(strMsg
, _("Question"),
1031 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1044 wxFAIL_MSG(_("invalid message box return value"));
1048 bOk
= file
.Open(filename
, wxFile::write_append
);
1051 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1055 bOk
= file
.Create(filename
);
1059 *pFilename
= filename
;
1064 #endif // wxUSE_FILE
1066 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1070 // ----------------------------------------------------------------------------
1071 // wxLogTextCtrl implementation
1072 // ----------------------------------------------------------------------------
1074 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1076 m_pTextCtrl
= pTextCtrl
;
1079 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1084 #if defined(__WXMAC__) && !defined(__DARWIN__)
1085 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1086 // translation must be done in wxTextCtrl, not here! (FIXME)
1087 msg
<< szString
<< wxT('\r');
1089 msg
<< szString
<< wxT('\n');
1092 m_pTextCtrl
->AppendText(msg
);
1095 #endif // wxUSE_TEXTCTRL