]>
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" 
  50 #include "wx/textfile.h" 
  51 #include "wx/statline.h" 
  54   // for OutputDebugString() 
  55   #include  "wx/msw/private.h" 
  58 // may be defined to 0 for old behavior (using wxMessageBox) - shouldn't be 
  59 // changed normally (that's why it's here and not in setup.h) 
  60 #define wxUSE_LOG_DIALOG 1 
  63     #include "wx/datetime.h" 
  64     #include "wx/listctrl.h" 
  65     #include "wx/imaglist.h" 
  67 #else // !wxUSE_TEXTFILE 
  68     #include "wx/msgdlg.h" 
  69 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG 
  71 // ---------------------------------------------------------------------------- 
  73 // ---------------------------------------------------------------------------- 
  77 class wxLogDialog 
: public wxDialog
 
  80     wxLogDialog(wxWindow 
*parent
, 
  81                 const wxArrayString
& messages
, 
  82                 const wxArrayInt
& severity
, 
  83                 const wxArrayLong
& timess
, 
  84                 const wxString
& caption
, 
  86     virtual ~wxLogDialog(); 
  89     void OnOk(wxCommandEvent
& event
); 
  90     void OnDetails(wxCommandEvent
& event
); 
  92     void OnSave(wxCommandEvent
& event
); 
  94     void OnListSelect(wxListEvent
& event
); 
  97     // create controls needed for the details display 
  98     void CreateDetailsControls(); 
 100     // the data for the listctrl 
 101     wxArrayString m_messages
; 
 102     wxArrayInt m_severity
; 
 105     // the "toggle" button and its state 
 106     wxButton 
*m_btnDetails
; 
 107     bool      m_showingDetails
; 
 109     // the controls which are not shown initially (but only when details 
 110     // button is pressed) 
 111     wxListCtrl 
*m_listctrl
; 
 113     wxStaticLine 
*m_statline
; 
 114 #endif // wxUSE_STATLINE 
 119     // the translated "Details" string 
 120     static wxString ms_details
; 
 122     DECLARE_EVENT_TABLE() 
 125 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
) 
 126     EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
) 
 127     EVT_BUTTON(wxID_MORE
,   wxLogDialog::OnDetails
) 
 129     EVT_BUTTON(wxID_SAVE
,   wxLogDialog::OnSave
) 
 131     EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
) 
 134 #endif // wxUSE_LOG_DIALOG 
 136 // ---------------------------------------------------------------------------- 
 138 // ---------------------------------------------------------------------------- 
 142 // pass an uninitialized file object, the function will ask the user for the 
 143 // filename and try to open it, returns TRUE on success (file was opened), 
 144 // FALSE if file couldn't be opened/created and -1 if the file selection 
 145 // dialog was cancelled 
 146 static int OpenLogFile(wxFile
& file
, wxString 
*filename 
= NULL
); 
 150 // ---------------------------------------------------------------------------- 
 152 // ---------------------------------------------------------------------------- 
 154 // we use a global variable to store the frame pointer for wxLogStatus - bad, 
 155 // but it's he easiest way 
 156 static wxFrame 
*gs_pFrame
; // FIXME MT-unsafe 
 158 // ============================================================================ 
 160 // ============================================================================ 
 162 // ---------------------------------------------------------------------------- 
 164 // ---------------------------------------------------------------------------- 
 166 // accepts an additional argument which tells to which frame the output should 
 168 void wxLogStatus(wxFrame 
*pFrame
, const wxChar 
*szFormat
, ...) 
 172   wxLog 
*pLog 
= wxLog::GetActiveTarget(); 
 173   if ( pLog 
!= NULL 
) { 
 175     va_start(argptr
, szFormat
); 
 176     msg
.PrintfV(szFormat
, argptr
); 
 179     wxASSERT( gs_pFrame 
== NULL 
); // should be reset! 
 181     wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
)); 
 182     gs_pFrame 
= (wxFrame 
*) NULL
; 
 186 // ---------------------------------------------------------------------------- 
 187 // wxLogTextCtrl implementation 
 188 // ---------------------------------------------------------------------------- 
 190 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl 
*pTextCtrl
) 
 192     m_pTextCtrl 
= pTextCtrl
; 
 195 void wxLogTextCtrl::DoLogString(const wxChar 
*szString
, time_t WXUNUSED(t
)) 
 199     msg 
<< szString 
<< wxT('\n'); 
 201     m_pTextCtrl
->AppendText(msg
); 
 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 
 267         wxLogDialog 
dlg(parent
, 
 268                         m_aMessages
, m_aSeverity
, m_aTimes
, 
 271         // clear the message list before showing the dialog because while it's 
 272         // shown some new messages may appear 
 275         (void)dlg
.ShowModal(); 
 276 #else // !wxUSE_LOG_DIALOG 
 277         // concatenate all strings (but not too many to not overfill the msg box) 
 280         // start from the most recent message 
 281         for ( size_t n 
= nMsgCount
; n 
> 0; n
-- ) { 
 282             // for Windows strings longer than this value are wrapped (NT 4.0) 
 283             const size_t nMsgLineWidth 
= 156; 
 285             nLines 
+= (m_aMessages
[n 
- 1].Len() + nMsgLineWidth 
- 1) / nMsgLineWidth
; 
 287             if ( nLines 
> 25 )  // don't put too many lines in message box 
 290             str 
<< m_aMessages
[n 
- 1] << wxT("\n"); 
 292 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG 
 295     // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any 
 296     // situation without it 
 299         wxMessageBox(str
, title
, wxOK 
| style
, parent
); 
 301         // no undisplayed messages whatsoever 
 306 // log all kinds of messages 
 307 void wxLogGui::DoLog(wxLogLevel level
, const wxChar 
*szString
, time_t t
) 
 315                     m_aMessages
.Add(szString
); 
 316                     m_aSeverity
.Add(wxLOG_Message
); 
 317                     m_aTimes
.Add((long)t
); 
 318                     m_bHasMessages 
= TRUE
; 
 326                 // find the top window and set it's status text if it has any 
 327                 wxFrame 
*pFrame 
= gs_pFrame
; 
 328                 if ( pFrame 
== NULL 
) { 
 329                     wxWindow 
*pWin 
= wxTheApp
->GetTopWindow(); 
 330                     if ( pWin 
!= NULL 
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) { 
 331                         pFrame 
= (wxFrame 
*)pWin
; 
 335                 if ( pFrame 
&& pFrame
->GetStatusBar() ) 
 336                     pFrame
->SetStatusText(szString
); 
 338 #endif // wxUSE_STATUSBAR 
 346                     // don't prepend debug/trace here: it goes to the 
 347                     // debug window anyhow, but do put a timestamp 
 350                     str 
<< szString 
<< wxT("\n\r"); 
 351                     OutputDebugString(str
); 
 353                     // send them to stderr 
 354                     wxFprintf(stderr
, wxT("%s: %s\n"), 
 355                               level 
== wxLOG_Trace 
? wxT("Trace") 
 361             #endif // __WXDEBUG__ 
 365         case wxLOG_FatalError
: 
 366             // show this one immediately 
 367             wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
); 
 373 #if !wxUSE_LOG_DIALOG 
 374                 // discard earlier informational messages if this is the 1st 
 375                 // error because they might not make sense any more and showing 
 376                 // them in a message box might be confusing 
 380 #endif // wxUSE_LOG_DIALOG 
 387                 // for the warning we don't discard the info messages 
 391             m_aMessages
.Add(szString
); 
 392             m_aSeverity
.Add((int)level
); 
 393             m_aTimes
.Add((long)t
); 
 394             m_bHasMessages 
= TRUE
; 
 399 // ---------------------------------------------------------------------------- 
 400 // wxLogWindow and wxLogFrame implementation 
 401 // ---------------------------------------------------------------------------- 
 405 class wxLogFrame 
: public wxFrame
 
 409     wxLogFrame(wxFrame 
*pParent
, wxLogWindow 
*log
, const wxChar 
*szTitle
); 
 410     virtual ~wxLogFrame(); 
 413     void OnClose(wxCommandEvent
& event
); 
 414     void OnCloseWindow(wxCloseEvent
& event
); 
 416     void OnSave (wxCommandEvent
& event
); 
 418     void OnClear(wxCommandEvent
& event
); 
 420     void OnIdle(wxIdleEvent
&); 
 423     wxTextCtrl 
*TextCtrl() const { return m_pTextCtrl
; } 
 426     // use standard ids for our commands! 
 429         Menu_Close 
= wxID_CLOSE
, 
 430         Menu_Save  
= wxID_SAVE
, 
 431         Menu_Clear 
= wxID_CLEAR
 
 434     // common part of OnClose() and OnCloseWindow() 
 437     wxTextCtrl  
*m_pTextCtrl
; 
 440     DECLARE_EVENT_TABLE() 
 443 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
) 
 444     // wxLogWindow menu events 
 445     EVT_MENU(Menu_Close
, wxLogFrame::OnClose
) 
 447     EVT_MENU(Menu_Save
,  wxLogFrame::OnSave
) 
 449     EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
) 
 451     EVT_CLOSE(wxLogFrame::OnCloseWindow
) 
 454 wxLogFrame::wxLogFrame(wxFrame 
*pParent
, wxLogWindow 
*log
, const wxChar 
*szTitle
) 
 455           : wxFrame(pParent
, -1, szTitle
) 
 459     m_pTextCtrl 
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
, 
 466     wxMenuBar 
*pMenuBar 
= new wxMenuBar
; 
 467     wxMenu 
*pMenu 
= new wxMenu
; 
 469     pMenu
->Append(Menu_Save
,  _("&Save..."), _("Save log contents to file")); 
 471     pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents")); 
 472     pMenu
->AppendSeparator(); 
 473     pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window")); 
 474     pMenuBar
->Append(pMenu
, _("&Log")); 
 475     SetMenuBar(pMenuBar
); 
 478     // status bar for menu prompts 
 480 #endif // wxUSE_STATUSBAR 
 482     m_log
->OnFrameCreate(this); 
 485 void wxLogFrame::DoClose() 
 487     if ( m_log
->OnFrameClose(this) ) 
 489         // instead of closing just hide the window to be able to Show() it 
 495 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
)) 
 500 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 506 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
)) 
 510     int rc 
= OpenLogFile(file
, &filename
); 
 519     // retrieve text and save it 
 520     // ------------------------- 
 521     int nLines 
= m_pTextCtrl
->GetNumberOfLines(); 
 522     for ( int nLine 
= 0; bOk 
&& nLine 
< nLines
; nLine
++ ) { 
 523         bOk 
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) + 
 524                          wxTextFile::GetEOL()); 
 531         wxLogError(_("Can't save log contents to file.")); 
 534         wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str()); 
 539 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
)) 
 541     m_pTextCtrl
->Clear(); 
 544 wxLogFrame::~wxLogFrame() 
 546     m_log
->OnFrameDelete(this); 
 551 wxLogWindow::wxLogWindow(wxFrame 
*pParent
, 
 552                          const wxChar 
*szTitle
, 
 556     m_bPassMessages 
= bDoPass
; 
 558     m_pLogFrame 
= new wxLogFrame(pParent
, this, szTitle
); 
 559     m_pOldLog 
= wxLog::SetActiveTarget(this); 
 562         m_pLogFrame
->Show(TRUE
); 
 565 void wxLogWindow::Show(bool bShow
) 
 567     m_pLogFrame
->Show(bShow
); 
 570 void wxLogWindow::Flush() 
 572     if ( m_pOldLog 
!= NULL 
) 
 575     m_bHasMessages 
= FALSE
; 
 578 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar 
*szString
, time_t t
) 
 580     // first let the previous logger show it 
 581     if ( m_pOldLog 
!= NULL 
&& m_bPassMessages 
) { 
 582         // bogus cast just to access protected DoLog 
 583         ((wxLogWindow 
*)m_pOldLog
)->DoLog(level
, szString
, t
); 
 589                 // by default, these messages are ignored by wxLog, so process 
 591                 if ( !wxIsEmpty(szString
) ) 
 594                     str 
<< _("Status: ") << szString
; 
 599                 // don't put trace messages in the text window for 2 reasons: 
 600                 // 1) there are too many of them 
 601                 // 2) they may provoke other trace messages thus sending a program 
 602                 //    into an infinite loop 
 607                 // and this will format it nicely and call our DoLogString() 
 608                 wxLog::DoLog(level
, szString
, t
); 
 612     m_bHasMessages 
= TRUE
; 
 615 void wxLogWindow::DoLogString(const wxChar 
*szString
, time_t WXUNUSED(t
)) 
 617     // put the text into our window 
 618     wxTextCtrl 
*pText 
= m_pLogFrame
->TextCtrl(); 
 620     // remove selection (WriteText is in fact ReplaceSelection) 
 622     long nLen 
= pText
->GetLastPosition(); 
 623     pText
->SetSelection(nLen
, nLen
); 
 628     msg 
<< szString 
<< wxT('\n'); 
 630     pText
->AppendText(msg
); 
 632     // TODO ensure that the line can be seen 
 635 wxFrame 
*wxLogWindow::GetFrame() const 
 640 void wxLogWindow::OnFrameCreate(wxFrame 
* WXUNUSED(frame
)) 
 644 bool wxLogWindow::OnFrameClose(wxFrame 
* WXUNUSED(frame
)) 
 650 void wxLogWindow::OnFrameDelete(wxFrame 
* WXUNUSED(frame
)) 
 652     m_pLogFrame 
= (wxLogFrame 
*)NULL
; 
 655 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
) 
 681     if ( ms_details
.IsEmpty() ) 
 683         // ensure that we won't loop here if wxGetTranslation() 
 684         // happens to pop up a Log message while translating this :-) 
 685         ms_details 
= wxTRANSLATE("&Details"); 
 686         ms_details 
= wxGetTranslation(ms_details
); 
 689     size_t count 
= messages
.GetCount(); 
 690     m_messages
.Alloc(count
); 
 691     m_severity
.Alloc(count
); 
 692     m_times
.Alloc(count
); 
 694     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 696         wxString msg 
= messages
[n
]; 
 699             m_messages
.Add(msg
.BeforeFirst(_T('\n'))); 
 700             msg 
= msg
.AfterFirst(_T('\n')); 
 702             m_severity
.Add(severity
[n
]); 
 703             m_times
.Add(times
[n
]); 
 708     m_showingDetails 
= FALSE
; // not initially 
 709     m_listctrl 
= (wxListCtrl 
*)NULL
; 
 712     m_statline 
= (wxStaticLine 
*)NULL
; 
 713 #endif // wxUSE_STATLINE 
 716     m_btnSave 
= (wxButton 
*)NULL
; 
 719     // create the controls which are always shown and layout them: we use 
 720     // sizers even though our window is not resizeable to calculate the size of 
 721     // the dialog properly 
 722     wxBoxSizer 
*sizerTop 
= new wxBoxSizer(wxVERTICAL
); 
 723     wxBoxSizer 
*sizerButtons 
= new wxBoxSizer(wxVERTICAL
); 
 724     wxBoxSizer 
*sizerAll 
= new wxBoxSizer(wxHORIZONTAL
); 
 726     // this "Ok" button has wxID_CANCEL id - not very logical, but this allows 
 727     // to close the log dialog with <Esc> which wouldn't work otherwise (as it 
 728     // translates into click on cancel button) 
 729     wxButton 
*btnOk 
= new wxButton(this, wxID_CANCEL
, _("OK")); 
 730     sizerButtons
->Add(btnOk
, 0, wxCENTRE
|wxBOTTOM
, MARGIN
/2); 
 731     m_btnDetails 
= new wxButton(this, wxID_MORE
, ms_details 
+ _T(" >>")); 
 732     sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
|wxTOP
, MARGIN
/2 - 1); 
 735     wxIcon icon 
= wxTheApp
->GetStdIcon((int)(style 
& wxICON_MASK
)); 
 736     sizerAll
->Add(new wxStaticBitmap(this, -1, icon
), 0, wxCENTRE
); 
 739     const wxString
& message 
= messages
.Last(); 
 740     sizerAll
->Add(CreateTextSizer(message
), 0, wxCENTRE
|wxLEFT
|wxRIGHT
, MARGIN
); 
 741     sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
|wxLEFT
, MARGIN
); 
 743     sizerTop
->Add(sizerAll
, 0, wxCENTRE
|wxALL
, MARGIN
); 
 748     sizerTop
->SetSizeHints(this); 
 753     // this can't happen any more as we don't use this dialog in this case 
 757         // no details... it's easier to disable a button than to change the 
 758         // dialog layout depending on whether we have details or not 
 759         m_btnDetails
->Disable(); 
 766 void wxLogDialog::CreateDetailsControls() 
 768     // create the save button and separator line if possible 
 770     m_btnSave 
= new wxButton(this, wxID_SAVE
, _("&Save...")); 
 774     m_statline 
= new wxStaticLine(this, -1); 
 775 #endif // wxUSE_STATLINE 
 777     // create the list ctrl now 
 778     m_listctrl 
= new wxListCtrl(this, -1, 
 779                                 wxDefaultPosition
, wxDefaultSize
, 
 785     // no need to translate these strings as they're not shown to the 
 786     // user anyhow (we use wxLC_NO_HEADER style) 
 787     m_listctrl
->InsertColumn(0, _T("Message")); 
 788     m_listctrl
->InsertColumn(1, _T("Time")); 
 790     // prepare the imagelist 
 791     static const int ICON_SIZE 
= 16; 
 792     wxImageList 
*imageList 
= new wxImageList(ICON_SIZE
, ICON_SIZE
); 
 794     // order should be the same as in the switch below! 
 795     static const int icons
[] = 
 802     bool loadedIcons 
= TRUE
; 
 805     for ( size_t icon 
= 0; icon 
< WXSIZEOF(icons
); icon
++ ) 
 807         wxBitmap bmp 
= wxTheApp
->GetStdIcon(icons
[icon
]); 
 809         // This may very well fail if there are insufficient 
 810         // colours available. Degrade gracefully. 
 815             imageList
->Add(wxImage(bmp
). 
 816                         Rescale(ICON_SIZE
, ICON_SIZE
). 
 820     m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
); 
 824     wxString fmt 
= wxLog::GetTimestamp(); 
 831     size_t count 
= m_messages
.GetCount(); 
 832     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 836         switch ( m_severity
[n
] ) 
 855             m_listctrl
->InsertItem(n
, m_messages
[n
], image
); 
 857             m_listctrl
->InsertItem(n
, m_messages
[n
]); 
 859         m_listctrl
->SetItem(n
, 1, 
 860                             wxDateTime((time_t)m_times
[n
]).Format(fmt
)); 
 863     // let the columns size themselves 
 864     m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
); 
 865     m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
); 
 867     // get the approx height of the listctrl 
 868     wxFont font 
= GetFont(); 
 870         font 
= *wxSWISS_FONT
; 
 873     GetTextExtent(_T("H"), (int*)NULL
, &y
, (int*)NULL
, (int*)NULL
, &font
); 
 874     int height 
= wxMax(y
*(count 
+ 3), 100); 
 875     m_listctrl
->SetSize(-1, height
); 
 878 void wxLogDialog::OnListSelect(wxListEvent
& event
) 
 880     // we can't just disable the control because this looks ugly under Windows 
 881     // (wrong bg colour, no scrolling...), but we still want to disable 
 882     // selecting items - it makes no sense here 
 883     m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
); 
 886 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
)) 
 893 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
)) 
 896     int rc 
= OpenLogFile(file
); 
 905     wxString fmt 
= wxLog::GetTimestamp(); 
 912     size_t count 
= m_messages
.GetCount(); 
 913     for ( size_t n 
= 0; ok 
&& (n 
< count
); n
++ ) 
 916         line 
<< wxDateTime((time_t)m_times
[n
]).Format(fmt
) 
 919              << wxTextFile::GetEOL(); 
 921         ok 
= file
.Write(line
); 
 928         wxLogError(_("Can't save log contents to file.")); 
 933 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
)) 
 935     wxSizer 
*sizer 
= GetSizer(); 
 937     if ( m_showingDetails 
) 
 939         m_btnDetails
->SetLabel(ms_details 
+ _T(">>")); 
 941         sizer
->Remove(m_listctrl
); 
 944         sizer
->Remove(m_statline
); 
 945 #endif // wxUSE_STATLINE 
 948         sizer
->Remove(m_btnSave
); 
 951     else // show details now 
 953         m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
); 
 957             CreateDetailsControls(); 
 961         sizer
->Add(m_statline
, 0, wxEXPAND 
| (wxALL 
& ~wxTOP
), MARGIN
); 
 962 #endif // wxUSE_STATLINE 
 964         sizer
->Add(m_listctrl
, 1, wxEXPAND 
| (wxALL 
& ~wxTOP
), MARGIN
); 
 967         sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT 
| (wxALL 
& ~wxTOP
), MARGIN
); 
 971     m_showingDetails 
= !m_showingDetails
; 
 973     // in any case, our size changed - update 
 974     sizer
->SetSizeHints(this); 
 978     // VS: this is neccessary in order to force frame redraw under 
 979     // WindowMaker or fvwm2 (and probably other broken WMs). 
 980     // Otherwise, detailed list wouldn't be displayed. 
 985 wxLogDialog::~wxLogDialog() 
 989         delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
); 
 993 #endif // wxUSE_LOG_DIALOG 
 997 // pass an uninitialized file object, the function will ask the user for the 
 998 // filename and try to open it, returns TRUE on success (file was opened), 
 999 // FALSE if file couldn't be opened/created and -1 if the file selection 
1000 // dialog was cancelled 
1001 static int OpenLogFile(wxFile
& file
, wxString 
*pFilename
) 
1003     // get the file name 
1004     // ----------------- 
1005     wxString filename 
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt")); 
1014     if ( wxFile::Exists(filename
) ) { 
1015         bool bAppend 
= FALSE
; 
1017         strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"), 
1019         switch ( wxMessageBox(strMsg
, _("Question"), 
1020                               wxICON_QUESTION 
| wxYES_NO 
| wxCANCEL
) ) { 
1033                 wxFAIL_MSG(_("invalid message box return value")); 
1037             bOk 
= file
.Open(filename
, wxFile::write_append
); 
1040             bOk 
= file
.Create(filename
, TRUE 
/* overwrite */); 
1044         bOk 
= file
.Create(filename
); 
1048         *pFilename 
= filename
; 
1053 #endif // wxUSE_FILE