]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/logg.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/generic/logg.cpp 
   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 licence 
  11 ///////////////////////////////////////////////////////////////////////////// 
  13 // ============================================================================ 
  15 // ============================================================================ 
  17 // ---------------------------------------------------------------------------- 
  19 // ---------------------------------------------------------------------------- 
  21 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  22     #pragma implementation "logg.h" 
  25 // For compilers that support precompilation, includes "wx.h". 
  26 #include "wx/wxprec.h" 
  34     #include "wx/button.h" 
  39     #include "wx/filedlg.h" 
  40     #include "wx/msgdlg.h" 
  41     #include "wx/textctrl.h" 
  43     #include "wx/statbmp.h" 
  44     #include "wx/button.h" 
  45     #include "wx/settings.h" 
  48 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW 
  51 #include "wx/textfile.h" 
  52 #include "wx/statline.h" 
  53 #include "wx/artprov.h" 
  56   // for OutputDebugString() 
  57   #include  "wx/msw/private.h" 
  65     #include "wx/listctrl.h" 
  66     #include "wx/imaglist.h" 
  68 #else // !wxUSE_LOG_DIALOG 
  69     #include "wx/msgdlg.h" 
  70 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG 
  72 #if defined(__MWERKS__) && wxUSE_UNICODE 
  76 // the suffix we add to the button to show that the dialog can be expanded 
  77 #define EXPAND_SUFFIX _T(" >>") 
  79 // ---------------------------------------------------------------------------- 
  81 // ---------------------------------------------------------------------------- 
  85 // this function is a wrapper around strftime(3) 
  86 // allows to exclude the usage of wxDateTime 
  87 static wxString 
TimeStamp(const wxChar 
*format
, time_t t
) 
  94     if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) ) 
  96         // buffer is too small? 
  97         wxFAIL_MSG(_T("strftime() failed")); 
 104 class wxLogDialog 
: public wxDialog
 
 107     wxLogDialog(wxWindow 
*parent
, 
 108                 const wxArrayString
& messages
, 
 109                 const wxArrayInt
& severity
, 
 110                 const wxArrayLong
& timess
, 
 111                 const wxString
& caption
, 
 113     virtual ~wxLogDialog(); 
 116     void OnOk(wxCommandEvent
& event
); 
 117     void OnDetails(wxCommandEvent
& event
); 
 119     void OnSave(wxCommandEvent
& event
); 
 121     void OnListSelect(wxListEvent
& event
); 
 124     // create controls needed for the details display 
 125     void CreateDetailsControls(); 
 127     // the data for the listctrl 
 128     wxArrayString m_messages
; 
 129     wxArrayInt m_severity
; 
 132     // the "toggle" button and its state 
 133     wxButton 
*m_btnDetails
; 
 134     bool      m_showingDetails
; 
 136     // the controls which are not shown initially (but only when details 
 137     // button is pressed) 
 138     wxListCtrl 
*m_listctrl
; 
 140     wxStaticLine 
*m_statline
; 
 141 #endif // wxUSE_STATLINE 
 146     // the translated "Details" string 
 147     static wxString ms_details
; 
 149     DECLARE_EVENT_TABLE() 
 150     DECLARE_NO_COPY_CLASS(wxLogDialog
) 
 153 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
) 
 154     EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
) 
 155     EVT_BUTTON(wxID_MORE
,   wxLogDialog::OnDetails
) 
 157     EVT_BUTTON(wxID_SAVE
,   wxLogDialog::OnSave
) 
 159     EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
) 
 162 #endif // wxUSE_LOG_DIALOG 
 164 // ---------------------------------------------------------------------------- 
 166 // ---------------------------------------------------------------------------- 
 168 #if wxUSE_FILE && wxUSE_FILEDLG 
 170 // pass an uninitialized file object, the function will ask the user for the 
 171 // filename and try to open it, returns TRUE on success (file was opened), 
 172 // FALSE if file couldn't be opened/created and -1 if the file selection 
 173 // dialog was cancelled 
 174 static int OpenLogFile(wxFile
& file
, wxString 
*filename 
= NULL
, wxWindow 
*parent 
= NULL
); 
 178 // ---------------------------------------------------------------------------- 
 180 // ---------------------------------------------------------------------------- 
 182 // we use a global variable to store the frame pointer for wxLogStatus - bad, 
 183 // but it's the easiest way 
 184 static wxFrame 
*gs_pFrame 
= NULL
; // FIXME MT-unsafe 
 186 // ============================================================================ 
 188 // ============================================================================ 
 190 // ---------------------------------------------------------------------------- 
 192 // ---------------------------------------------------------------------------- 
 194 // accepts an additional argument which tells to which frame the output should 
 196 void wxVLogStatus(wxFrame 
*pFrame
, const wxChar 
*szFormat
, va_list argptr
) 
 200   wxLog 
*pLog 
= wxLog::GetActiveTarget(); 
 201   if ( pLog 
!= NULL 
) { 
 202     msg
.PrintfV(szFormat
, argptr
); 
 204     wxASSERT( gs_pFrame 
== NULL 
); // should be reset! 
 207     wxLog::OnLog(wxLOG_Status
, msg
, 0); 
 209     wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
)); 
 211     gs_pFrame 
= (wxFrame 
*) NULL
; 
 215 void wxLogStatus(wxFrame 
*pFrame
, const wxChar 
*szFormat
, ...) 
 218     va_start(argptr
, szFormat
); 
 219     wxVLogStatus(pFrame
, szFormat
, argptr
); 
 223 // ---------------------------------------------------------------------------- 
 224 // wxLogGui implementation (FIXME MT-unsafe) 
 225 // ---------------------------------------------------------------------------- 
 234 void wxLogGui::Clear() 
 238     m_bHasMessages 
= FALSE
; 
 245 void wxLogGui::Flush() 
 247     if ( !m_bHasMessages 
) 
 250     // do it right now to block any new calls to Flush() while we're here 
 251     m_bHasMessages 
= FALSE
; 
 253     wxString appName 
= wxTheApp
->GetAppName(); 
 255         appName
[0u] = wxToupper(appName
[0u]); 
 258     wxString titleFormat
; 
 260         titleFormat 
= _("%s Error"); 
 263     else if ( m_bWarnings 
) { 
 264         titleFormat 
= _("%s Warning"); 
 265         style 
= wxICON_EXCLAMATION
; 
 268         titleFormat 
= _("%s Information"); 
 269         style 
= wxICON_INFORMATION
; 
 273     title
.Printf(titleFormat
, appName
.c_str()); 
 275     size_t nMsgCount 
= m_aMessages
.Count(); 
 277     // avoid showing other log dialogs until we're done with the dialog we're 
 278     // showing right now: nested modal dialogs make for really bad UI! 
 282     if ( nMsgCount 
== 1 ) 
 284         str 
= m_aMessages
[0]; 
 286     else // more than one message 
 290         wxLogDialog 
dlg(NULL
, 
 291                         m_aMessages
, m_aSeverity
, m_aTimes
, 
 294         // clear the message list before showing the dialog because while it's 
 295         // shown some new messages may appear 
 298         (void)dlg
.ShowModal(); 
 299 #else // !wxUSE_LOG_DIALOG 
 300         // concatenate all strings (but not too many to not overfill the msg box) 
 303         // start from the most recent message 
 304         for ( size_t n 
= nMsgCount
; n 
> 0; n
-- ) { 
 305             // for Windows strings longer than this value are wrapped (NT 4.0) 
 306             const size_t nMsgLineWidth 
= 156; 
 308             nLines 
+= (m_aMessages
[n 
- 1].Len() + nMsgLineWidth 
- 1) / nMsgLineWidth
; 
 310             if ( nLines 
> 25 )  // don't put too many lines in message box 
 313             str 
<< m_aMessages
[n 
- 1] << wxT("\n"); 
 315 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG 
 318     // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any 
 319     // situation without it 
 322         wxMessageBox(str
, title
, wxOK 
| style
); 
 324         // no undisplayed messages whatsoever 
 328     // allow flushing the logs again 
 332 // log all kinds of messages 
 333 void wxLogGui::DoLog(wxLogLevel level
, const wxChar 
*szString
, time_t t
) 
 340                 m_aMessages
.Add(szString
); 
 341                 m_aSeverity
.Add(wxLOG_Message
); 
 342                 m_aTimes
.Add((long)t
); 
 343                 m_bHasMessages 
= TRUE
; 
 350                 // find the top window and set it's status text if it has any 
 351                 wxFrame 
*pFrame 
= gs_pFrame
; 
 352                 if ( pFrame 
== NULL 
) { 
 353                     wxWindow 
*pWin 
= wxTheApp
->GetTopWindow(); 
 354                     if ( pWin 
!= NULL 
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) { 
 355                         pFrame 
= (wxFrame 
*)pWin
; 
 359                 if ( pFrame 
&& pFrame
->GetStatusBar() ) 
 360                     pFrame
->SetStatusText(szString
); 
 362 #endif // wxUSE_STATUSBAR 
 373                 #if defined(__WXMSW__) && !defined(__WXMICROWIN__) 
 374                     // don't prepend debug/trace here: it goes to the 
 375                     // debug window anyhow 
 377                     OutputDebugString(str
); 
 379                     // send them to stderr 
 380                     wxFprintf(stderr
, wxT("[%s] %s\n"), 
 381                               level 
== wxLOG_Trace 
? wxT("Trace") 
 387             #endif // __WXDEBUG__ 
 391         case wxLOG_FatalError
: 
 392             // show this one immediately 
 393             wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
); 
 399 #if !wxUSE_LOG_DIALOG 
 400                 // discard earlier informational messages if this is the 1st 
 401                 // error because they might not make sense any more and showing 
 402                 // them in a message box might be confusing 
 406 #endif // wxUSE_LOG_DIALOG 
 413                 // for the warning we don't discard the info messages 
 417             m_aMessages
.Add(szString
); 
 418             m_aSeverity
.Add((int)level
); 
 419             m_aTimes
.Add((long)t
); 
 420             m_bHasMessages 
= TRUE
; 
 425 #endif   // wxUSE_LOGGUI 
 427 // ---------------------------------------------------------------------------- 
 428 // wxLogWindow and wxLogFrame implementation 
 429 // ---------------------------------------------------------------------------- 
 433 class wxLogFrame 
: public wxFrame
 
 437     wxLogFrame(wxFrame 
*pParent
, wxLogWindow 
*log
, const wxChar 
*szTitle
); 
 438     virtual ~wxLogFrame(); 
 441     void OnClose(wxCommandEvent
& event
); 
 442     void OnCloseWindow(wxCloseEvent
& event
); 
 444     void OnSave (wxCommandEvent
& event
); 
 446     void OnClear(wxCommandEvent
& event
); 
 449     wxTextCtrl 
*TextCtrl() const { return m_pTextCtrl
; } 
 452     // use standard ids for our commands! 
 455         Menu_Close 
= wxID_CLOSE
, 
 456         Menu_Save  
= wxID_SAVE
, 
 457         Menu_Clear 
= wxID_CLEAR
 
 460     // common part of OnClose() and OnCloseWindow() 
 463     wxTextCtrl  
*m_pTextCtrl
; 
 466     DECLARE_EVENT_TABLE() 
 467     DECLARE_NO_COPY_CLASS(wxLogFrame
) 
 470 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
) 
 471     // wxLogWindow menu events 
 472     EVT_MENU(Menu_Close
, wxLogFrame::OnClose
) 
 474     EVT_MENU(Menu_Save
,  wxLogFrame::OnSave
) 
 476     EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
) 
 478     EVT_CLOSE(wxLogFrame::OnCloseWindow
) 
 481 wxLogFrame::wxLogFrame(wxFrame 
*pParent
, wxLogWindow 
*log
, const wxChar 
*szTitle
) 
 482           : wxFrame(pParent
, -1, szTitle
) 
 486     m_pTextCtrl 
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
, 
 490             // needed for Win32 to avoid 65Kb limit but it doesn't work well 
 491             // when using RichEdit 2.0 which we always do in the Unicode build 
 494 #endif // !wxUSE_UNICODE 
 499     wxMenuBar 
*pMenuBar 
= new wxMenuBar
; 
 500     wxMenu 
*pMenu 
= new wxMenu
; 
 502     pMenu
->Append(Menu_Save
,  _("&Save..."), _("Save log contents to file")); 
 504     pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents")); 
 505     pMenu
->AppendSeparator(); 
 506     pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window")); 
 507     pMenuBar
->Append(pMenu
, _("&Log")); 
 508     SetMenuBar(pMenuBar
); 
 509 #endif // wxUSE_MENUS 
 512     // status bar for menu prompts 
 514 #endif // wxUSE_STATUSBAR 
 516     m_log
->OnFrameCreate(this); 
 519 void wxLogFrame::DoClose() 
 521     if ( m_log
->OnFrameClose(this) ) 
 523         // instead of closing just hide the window to be able to Show() it 
 529 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
)) 
 534 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 540 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
)) 
 545     int rc 
= OpenLogFile(file
, &filename
, this); 
 554     // retrieve text and save it 
 555     // ------------------------- 
 556     int nLines 
= m_pTextCtrl
->GetNumberOfLines(); 
 557     for ( int nLine 
= 0; bOk 
&& nLine 
< nLines
; nLine
++ ) { 
 558         bOk 
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) + 
 559                          wxTextFile::GetEOL()); 
 566         wxLogError(_("Can't save log contents to file.")); 
 569         wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str()); 
 575 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
)) 
 577     m_pTextCtrl
->Clear(); 
 580 wxLogFrame::~wxLogFrame() 
 582     m_log
->OnFrameDelete(this); 
 588 wxLogWindow::wxLogWindow(wxFrame 
*pParent
, 
 589                          const wxChar 
*szTitle
, 
 593     PassMessages(bDoPass
); 
 595     m_pLogFrame 
= new wxLogFrame(pParent
, this, szTitle
); 
 598         m_pLogFrame
->Show(TRUE
); 
 601 void wxLogWindow::Show(bool bShow
) 
 603     m_pLogFrame
->Show(bShow
); 
 606 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar 
*szString
, time_t t
) 
 608     // first let the previous logger show it 
 609     wxLogPassThrough::DoLog(level
, szString
, t
); 
 614                 // by default, these messages are ignored by wxLog, so process 
 616                 if ( !wxIsEmpty(szString
) ) 
 619                     str 
<< _("Status: ") << szString
; 
 624                 // don't put trace messages in the text window for 2 reasons: 
 625                 // 1) there are too many of them 
 626                 // 2) they may provoke other trace messages thus sending a program 
 627                 //    into an infinite loop 
 632                 // and this will format it nicely and call our DoLogString() 
 633                 wxLog::DoLog(level
, szString
, t
); 
 638 void wxLogWindow::DoLogString(const wxChar 
*szString
, time_t WXUNUSED(t
)) 
 640     // put the text into our window 
 641     wxTextCtrl 
*pText 
= m_pLogFrame
->TextCtrl(); 
 643     // remove selection (WriteText is in fact ReplaceSelection) 
 645     long nLen 
= pText
->GetLastPosition(); 
 646     pText
->SetSelection(nLen
, nLen
); 
 651     msg 
<< szString 
<< wxT('\n'); 
 653     pText
->AppendText(msg
); 
 655     // TODO ensure that the line can be seen 
 658 wxFrame 
*wxLogWindow::GetFrame() const 
 663 void wxLogWindow::OnFrameCreate(wxFrame 
* WXUNUSED(frame
)) 
 667 bool wxLogWindow::OnFrameClose(wxFrame 
* WXUNUSED(frame
)) 
 673 void wxLogWindow::OnFrameDelete(wxFrame 
* WXUNUSED(frame
)) 
 675     m_pLogFrame 
= (wxLogFrame 
*)NULL
; 
 678 wxLogWindow::~wxLogWindow() 
 680     // may be NULL if log frame already auto destroyed itself 
 684 // ---------------------------------------------------------------------------- 
 686 // ---------------------------------------------------------------------------- 
 690 static const size_t MARGIN 
= 10; 
 692 wxString 
wxLogDialog::ms_details
; 
 694 wxLogDialog::wxLogDialog(wxWindow 
*parent
, 
 695                          const wxArrayString
& messages
, 
 696                          const wxArrayInt
& severity
, 
 697                          const wxArrayLong
& times
, 
 698                          const wxString
& caption
, 
 700            : wxDialog(parent
, -1, caption
, 
 701                       wxDefaultPosition
, wxDefaultSize
, 
 702                       wxDEFAULT_DIALOG_STYLE 
| wxRESIZE_BORDER
) 
 704     if ( ms_details
.IsEmpty() ) 
 706         // ensure that we won't loop here if wxGetTranslation() 
 707         // happens to pop up a Log message while translating this :-) 
 708         ms_details 
= wxTRANSLATE("&Details"); 
 709         ms_details 
= wxGetTranslation(ms_details
); 
 712     size_t count 
= messages
.GetCount(); 
 713     m_messages
.Alloc(count
); 
 714     m_severity
.Alloc(count
); 
 715     m_times
.Alloc(count
); 
 717     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 719         wxString msg 
= messages
[n
]; 
 722             m_messages
.Add(msg
.BeforeFirst(_T('\n'))); 
 723             msg 
= msg
.AfterFirst(_T('\n')); 
 725             m_severity
.Add(severity
[n
]); 
 726             m_times
.Add(times
[n
]); 
 731     m_showingDetails 
= FALSE
; // not initially 
 732     m_listctrl 
= (wxListCtrl 
*)NULL
; 
 735     m_statline 
= (wxStaticLine 
*)NULL
; 
 736 #endif // wxUSE_STATLINE 
 739     m_btnSave 
= (wxButton 
*)NULL
; 
 742     // create the controls which are always shown and layout them: we use 
 743     // sizers even though our window is not resizeable to calculate the size of 
 744     // the dialog properly 
 745     wxBoxSizer 
*sizerTop 
= new wxBoxSizer(wxVERTICAL
); 
 746     wxBoxSizer 
*sizerButtons 
= new wxBoxSizer(wxVERTICAL
); 
 747     wxBoxSizer 
*sizerAll 
= new wxBoxSizer(wxHORIZONTAL
); 
 749     // this "Ok" button has wxID_CANCEL id - not very logical, but this allows 
 750     // to close the log dialog with <Esc> which wouldn't work otherwise (as it 
 751     // translates into click on cancel button) 
 752     wxButton 
*btnOk 
= new wxButton(this, wxID_CANCEL
, _("OK")); 
 753     sizerButtons
->Add(btnOk
, 0, wxCENTRE 
| wxBOTTOM
, MARGIN
/2); 
 754     m_btnDetails 
= new wxButton(this, wxID_MORE
, ms_details 
+ EXPAND_SUFFIX
); 
 755     sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE 
| wxTOP
, MARGIN
/2 - 1); 
 759     switch ( style 
& wxICON_MASK 
) 
 762             bitmap 
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
); 
 764             bitmap
.SetId(wxICON_SMALL_ERROR
); 
 768         case wxICON_INFORMATION
: 
 769             bitmap 
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
); 
 771             bitmap
.SetId(wxICON_SMALL_INFO
); 
 776             bitmap 
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
); 
 778             bitmap
.SetId(wxICON_SMALL_WARNING
); 
 783             wxFAIL_MSG(_T("incorrect log style")); 
 785     sizerAll
->Add(new wxStaticBitmap(this, -1, bitmap
), 0); 
 788     const wxString
& message 
= messages
.Last(); 
 789     sizerAll
->Add(CreateTextSizer(message
), 1, 
 790                   wxALIGN_CENTRE_VERTICAL 
| wxLEFT 
| wxRIGHT
, MARGIN
); 
 791     sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT 
| wxLEFT
, MARGIN
); 
 793     sizerTop
->Add(sizerAll
, 0, wxALL 
| wxEXPAND
, MARGIN
); 
 798     // see comments in OnDetails() 
 800     // Note: Doing this, this way, triggered a nasty bug in 
 801     //       wxTopLevelWindowGTK::GtkOnSize which took -1 literally once 
 802     //       either of maxWidth or maxHeight was set.  This symptom has been 
 803     //       fixed there, but it is a problem that remains as long as we allow 
 804     //       unchecked access to the internal size members.  We really need to 
 805     //       encapuslate window sizes more cleanly and make it clear when -1 will 
 806     //       be substituted and when it will not. 
 808     wxSize size 
= sizerTop
->Fit(this); 
 809     m_maxHeight 
= size
.y
; 
 810     SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
); 
 814     // this can't happen any more as we don't use this dialog in this case 
 818         // no details... it's easier to disable a button than to change the 
 819         // dialog layout depending on whether we have details or not 
 820         m_btnDetails
->Disable(); 
 827 void wxLogDialog::CreateDetailsControls() 
 829     // create the save button and separator line if possible 
 831     m_btnSave 
= new wxButton(this, wxID_SAVE
, _("&Save...")); 
 835     m_statline 
= new wxStaticLine(this, -1); 
 836 #endif // wxUSE_STATLINE 
 838     // create the list ctrl now 
 839     m_listctrl 
= new wxListCtrl(this, -1, 
 840                                 wxDefaultPosition
, wxDefaultSize
, 
 846     // no need to translate these strings as they're not shown to the 
 847     // user anyhow (we use wxLC_NO_HEADER style) 
 848     m_listctrl
->InsertColumn(0, _T("Message")); 
 849     m_listctrl
->InsertColumn(1, _T("Time")); 
 851     // prepare the imagelist 
 852     static const int ICON_SIZE 
= 16; 
 853     wxImageList 
*imageList 
= new wxImageList(ICON_SIZE
, ICON_SIZE
); 
 855     // order should be the same as in the switch below! 
 856     static const wxChar
* icons
[] = 
 863     bool loadedIcons 
= TRUE
; 
 866     for ( size_t icon 
= 0; icon 
< WXSIZEOF(icons
); icon
++ ) 
 868         wxBitmap bmp 
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
, 
 869                                                 wxSize(ICON_SIZE
, ICON_SIZE
)); 
 871         // This may very well fail if there are insufficient colours available. 
 872         // Degrade gracefully. 
 883     m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
); 
 887     wxString fmt 
= wxLog::GetTimestamp(); 
 894     size_t count 
= m_messages
.GetCount(); 
 895     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 902             switch ( m_severity
[n
] ) 
 916         else // failed to load images 
 922         m_listctrl
->InsertItem(n
, m_messages
[n
], image
); 
 923         m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
])); 
 926     // let the columns size themselves 
 927     m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
); 
 928     m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
); 
 930     // calculate an approximately nice height for the listctrl 
 931     int height 
= GetCharHeight()*(count 
+ 4); 
 933     // but check that the dialog won't fall fown from the screen 
 935     // we use GetMinHeight() to get the height of the dialog part without the 
 936     // details and we consider that the "Save" button below and the separator 
 937     // line (and the margins around it) take about as much, hence double it 
 938     int heightMax 
= wxGetDisplaySize().y 
- GetPosition().y 
- 2*GetMinHeight(); 
 940     // we should leave a margin 
 944     m_listctrl
->SetSize(-1, wxMin(height
, heightMax
)); 
 947 void wxLogDialog::OnListSelect(wxListEvent
& event
) 
 949     // we can't just disable the control because this looks ugly under Windows 
 950     // (wrong bg colour, no scrolling...), but we still want to disable 
 951     // selecting items - it makes no sense here 
 952     m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
); 
 955 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
)) 
 962 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
)) 
 966     int rc 
= OpenLogFile(file
, NULL
, this); 
 975     wxString fmt 
= wxLog::GetTimestamp(); 
 982     size_t count 
= m_messages
.GetCount(); 
 983     for ( size_t n 
= 0; ok 
&& (n 
< count
); n
++ ) 
 986         line 
<< TimeStamp(fmt
, (time_t)m_times
[n
]) 
 989              << wxTextFile::GetEOL(); 
 991         ok 
= file
.Write(line
); 
 998         wxLogError(_("Can't save log contents to file.")); 
 999 #endif // wxUSE_FILEDLG 
1002 #endif // wxUSE_FILE 
1004 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
)) 
1006     wxSizer 
*sizer 
= GetSizer(); 
1008     if ( m_showingDetails 
) 
1010         m_btnDetails
->SetLabel(ms_details 
+ EXPAND_SUFFIX
); 
1012         sizer
->Detach( m_listctrl 
); 
1015         sizer
->Detach( m_statline 
); 
1016 #endif // wxUSE_STATLINE 
1019         sizer
->Detach( m_btnSave 
); 
1020 #endif // wxUSE_FILE 
1022     else // show details now 
1024         m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
); 
1028             CreateDetailsControls(); 
1032         sizer
->Add(m_statline
, 0, wxEXPAND 
| (wxALL 
& ~wxTOP
), MARGIN
); 
1033 #endif // wxUSE_STATLINE 
1035         sizer
->Add(m_listctrl
, 1, wxEXPAND 
| (wxALL 
& ~wxTOP
), MARGIN
); 
1037         // VZ: this doesn't work as this becomes the initial (and not only 
1038         //     minimal) listctrl height as well - why? 
1040         // allow the user to make the dialog shorter than its initial height - 
1041         // without this it wouldn't work as the list ctrl would have been 
1043         sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight()); 
1047         sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT 
| (wxALL 
& ~wxTOP
), MARGIN
); 
1048 #endif // wxUSE_FILE 
1051     m_showingDetails 
= !m_showingDetails
; 
1053     // in any case, our size changed - relayout everything and set new hints 
1054     // --------------------------------------------------------------------- 
1056     // we have to reset min size constraints or Fit() would never reduce the 
1057     // dialog size when collapsing it and we have to reset max constraint 
1058     // because it wouldn't expand it otherwise 
1063     // wxSizer::FitSize() is private, otherwise we might use it directly... 
1064     wxSize sizeTotal 
= GetSize(), 
1065            sizeClient 
= GetClientSize(); 
1067     wxSize size 
= sizer
->GetMinSize(); 
1068     size
.x 
+= sizeTotal
.x 
- sizeClient
.x
; 
1069     size
.y 
+= sizeTotal
.y 
- sizeClient
.y
; 
1071     // we don't want to allow expanding the dialog in vertical direction as 
1072     // this would show the "hidden" details but we can resize the dialog 
1073     // vertically while the details are shown 
1074     if ( !m_showingDetails 
) 
1075         m_maxHeight 
= size
.y
; 
1077     SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
); 
1079     // don't change the width when expanding/collapsing 
1080     SetSize(-1, size
.y
); 
1083     // VS: this is neccessary in order to force frame redraw under 
1084     // WindowMaker or fvwm2 (and probably other broken WMs). 
1085     // Otherwise, detailed list wouldn't be displayed. 
1090 wxLogDialog::~wxLogDialog() 
1094         delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
); 
1098 #endif // wxUSE_LOG_DIALOG 
1100 #if wxUSE_FILE && wxUSE_FILEDLG 
1102 // pass an uninitialized file object, the function will ask the user for the 
1103 // filename and try to open it, returns TRUE on success (file was opened), 
1104 // FALSE if file couldn't be opened/created and -1 if the file selection 
1105 // dialog was cancelled 
1106 static int OpenLogFile(wxFile
& file
, wxString 
*pFilename
, wxWindow 
*parent
) 
1108     // get the file name 
1109     // ----------------- 
1110     wxString filename 
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
); 
1119     if ( wxFile::Exists(filename
) ) { 
1120         bool bAppend 
= FALSE
; 
1122         strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"), 
1124         switch ( wxMessageBox(strMsg
, _("Question"), 
1125                               wxICON_QUESTION 
| wxYES_NO 
| wxCANCEL
) ) { 
1138                 wxFAIL_MSG(_("invalid message box return value")); 
1142             bOk 
= file
.Open(filename
, wxFile::write_append
); 
1145             bOk 
= file
.Create(filename
, TRUE 
/* overwrite */); 
1149         bOk 
= file
.Create(filename
); 
1153         *pFilename 
= filename
; 
1158 #endif // wxUSE_FILE 
1160 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW) 
1162 #if wxUSE_LOG && wxUSE_TEXTCTRL 
1164 // ---------------------------------------------------------------------------- 
1165 // wxLogTextCtrl implementation 
1166 // ---------------------------------------------------------------------------- 
1168 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl 
*pTextCtrl
) 
1170     m_pTextCtrl 
= pTextCtrl
; 
1173 void wxLogTextCtrl::DoLogString(const wxChar 
*szString
, time_t WXUNUSED(t
)) 
1178     msg 
<< szString 
<< wxT('\n'); 
1179     m_pTextCtrl
->AppendText(msg
); 
1182 #endif // wxUSE_LOG && wxUSE_TEXTCTRL