]>
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 // For compilers that support precompilation, includes "wx.h". 
  22 #include "wx/wxprec.h" 
  30     #include "wx/button.h" 
  35     #include "wx/filedlg.h" 
  36     #include "wx/msgdlg.h" 
  37     #include "wx/textctrl.h" 
  39     #include "wx/statbmp.h" 
  40     #include "wx/button.h" 
  41     #include "wx/settings.h" 
  44 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW 
  47 #include "wx/textfile.h" 
  48 #include "wx/statline.h" 
  49 #include "wx/artprov.h" 
  52   // for OutputDebugString() 
  53   #include  "wx/msw/private.h" 
  61     #include "wx/listctrl.h" 
  62     #include "wx/imaglist.h" 
  64 #else // !wxUSE_LOG_DIALOG 
  65     #include "wx/msgdlg.h" 
  66 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG 
  68 #if defined(__MWERKS__) && wxUSE_UNICODE 
  72 #include "wx/datetime.h" 
  74 // the suffix we add to the button to show that the dialog can be expanded 
  75 #define EXPAND_SUFFIX _T(" >>") 
  77 // ---------------------------------------------------------------------------- 
  79 // ---------------------------------------------------------------------------- 
  83 // this function is a wrapper around strftime(3) 
  84 // allows to exclude the usage of wxDateTime 
  85 static wxString 
TimeStamp(const wxChar 
*format
, time_t t
) 
  88     if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) ) 
  90         // buffer is too small? 
  91         wxFAIL_MSG(_T("strftime() failed")); 
  97 class wxLogDialog 
: public wxDialog
 
 100     wxLogDialog(wxWindow 
*parent
, 
 101                 const wxArrayString
& messages
, 
 102                 const wxArrayInt
& severity
, 
 103                 const wxArrayLong
& timess
, 
 104                 const wxString
& caption
, 
 106     virtual ~wxLogDialog(); 
 109     void OnOk(wxCommandEvent
& event
); 
 110     void OnDetails(wxCommandEvent
& event
); 
 112     void OnSave(wxCommandEvent
& event
); 
 114     void OnListSelect(wxListEvent
& event
); 
 117     // create controls needed for the details display 
 118     void CreateDetailsControls(); 
 120     // the data for the listctrl 
 121     wxArrayString m_messages
; 
 122     wxArrayInt m_severity
; 
 125     // the "toggle" button and its state 
 126 #ifndef __SMARTPHONE__ 
 127     wxButton 
*m_btnDetails
; 
 129     bool      m_showingDetails
; 
 131     // the controls which are not shown initially (but only when details 
 132     // button is pressed) 
 133     wxListCtrl 
*m_listctrl
; 
 134 #ifndef __SMARTPHONE__ 
 136     wxStaticLine 
*m_statline
; 
 137 #endif // wxUSE_STATLINE 
 141 #endif // __SMARTPHONE__ 
 143     // the translated "Details" string 
 144     static wxString ms_details
; 
 146     DECLARE_EVENT_TABLE() 
 147     DECLARE_NO_COPY_CLASS(wxLogDialog
) 
 150 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
) 
 151     EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
) 
 152     EVT_BUTTON(wxID_MORE
,   wxLogDialog::OnDetails
) 
 154     EVT_BUTTON(wxID_SAVE
,   wxLogDialog::OnSave
) 
 156     EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
) 
 159 #endif // wxUSE_LOG_DIALOG 
 161 // ---------------------------------------------------------------------------- 
 163 // ---------------------------------------------------------------------------- 
 165 #if wxUSE_FILE && wxUSE_FILEDLG 
 167 // pass an uninitialized file object, the function will ask the user for the 
 168 // filename and try to open it, returns true on success (file was opened), 
 169 // false if file couldn't be opened/created and -1 if the file selection 
 170 // dialog was cancelled 
 171 static int OpenLogFile(wxFile
& file
, wxString 
*filename 
= NULL
, wxWindow 
*parent 
= NULL
); 
 175 // ---------------------------------------------------------------------------- 
 177 // ---------------------------------------------------------------------------- 
 179 // we use a global variable to store the frame pointer for wxLogStatus - bad, 
 180 // but it's the easiest way 
 181 static wxFrame 
*gs_pFrame 
= NULL
; // FIXME MT-unsafe 
 183 // ============================================================================ 
 185 // ============================================================================ 
 187 // ---------------------------------------------------------------------------- 
 189 // ---------------------------------------------------------------------------- 
 191 // accepts an additional argument which tells to which frame the output should 
 193 void wxVLogStatus(wxFrame 
*pFrame
, const wxChar 
*szFormat
, va_list argptr
) 
 197   wxLog 
*pLog 
= wxLog::GetActiveTarget(); 
 198   if ( pLog 
!= NULL 
) { 
 199     msg
.PrintfV(szFormat
, argptr
); 
 201     wxASSERT( gs_pFrame 
== NULL 
); // should be reset! 
 204     wxLog::OnLog(wxLOG_Status
, msg
, 0); 
 206     wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
)); 
 208     gs_pFrame 
= (wxFrame 
*) NULL
; 
 212 void wxLogStatus(wxFrame 
*pFrame
, const wxChar 
*szFormat
, ...) 
 215     va_start(argptr
, szFormat
); 
 216     wxVLogStatus(pFrame
, szFormat
, argptr
); 
 220 // ---------------------------------------------------------------------------- 
 221 // wxLogGui implementation (FIXME MT-unsafe) 
 222 // ---------------------------------------------------------------------------- 
 231 void wxLogGui::Clear() 
 235     m_bHasMessages 
= false; 
 242 void wxLogGui::Flush() 
 244     if ( !m_bHasMessages 
) 
 247     // do it right now to block any new calls to Flush() while we're here 
 248     m_bHasMessages 
= false; 
 250     wxString appName 
= wxTheApp
->GetAppName(); 
 251     if ( !appName
.empty() ) 
 252         appName
[0u] = (wxChar
)wxToupper(appName
[0u]); 
 255     wxString titleFormat
; 
 257         titleFormat 
= _("%s Error"); 
 260     else if ( m_bWarnings 
) { 
 261         titleFormat 
= _("%s Warning"); 
 262         style 
= wxICON_EXCLAMATION
; 
 265         titleFormat 
= _("%s Information"); 
 266         style 
= wxICON_INFORMATION
; 
 270     title
.Printf(titleFormat
, appName
.c_str()); 
 272     size_t nMsgCount 
= m_aMessages
.Count(); 
 274     // avoid showing other log dialogs until we're done with the dialog we're 
 275     // showing right now: nested modal dialogs make for really bad UI! 
 279     if ( nMsgCount 
== 1 ) 
 281         str 
= m_aMessages
[0]; 
 283     else // more than one message 
 287         wxLogDialog 
dlg(NULL
, 
 288                         m_aMessages
, m_aSeverity
, m_aTimes
, 
 291         // clear the message list before showing the dialog because while it's 
 292         // shown some new messages may appear 
 295         (void)dlg
.ShowModal(); 
 296 #else // !wxUSE_LOG_DIALOG 
 297         // concatenate all strings (but not too many to not overfill the msg box) 
 300         // start from the most recent message 
 301         for ( size_t n 
= nMsgCount
; n 
> 0; n
-- ) { 
 302             // for Windows strings longer than this value are wrapped (NT 4.0) 
 303             const size_t nMsgLineWidth 
= 156; 
 305             nLines 
+= (m_aMessages
[n 
- 1].Len() + nMsgLineWidth 
- 1) / nMsgLineWidth
; 
 307             if ( nLines 
> 25 )  // don't put too many lines in message box 
 310             str 
<< m_aMessages
[n 
- 1] << wxT("\n"); 
 312 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG 
 315     // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any 
 316     // situation without it 
 319         wxMessageBox(str
, title
, wxOK 
| style
); 
 321         // no undisplayed messages whatsoever 
 325     // allow flushing the logs again 
 329 // log all kinds of messages 
 330 void wxLogGui::DoLog(wxLogLevel level
, const wxChar 
*szString
, time_t t
) 
 337                 m_aMessages
.Add(szString
); 
 338                 m_aSeverity
.Add(wxLOG_Message
); 
 339                 m_aTimes
.Add((long)t
); 
 340                 m_bHasMessages 
= true; 
 347                 // find the top window and set it's status text if it has any 
 348                 wxFrame 
*pFrame 
= gs_pFrame
; 
 349                 if ( pFrame 
== NULL 
) { 
 350                     wxWindow 
*pWin 
= wxTheApp
->GetTopWindow(); 
 351                     if ( pWin 
!= NULL 
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) { 
 352                         pFrame 
= (wxFrame 
*)pWin
; 
 356                 if ( pFrame 
&& pFrame
->GetStatusBar() ) 
 357                     pFrame
->SetStatusText(szString
); 
 359 #endif // wxUSE_STATUSBAR 
 370                 #if defined(__WXMSW__) && !defined(__WXMICROWIN__) 
 371                     // don't prepend debug/trace here: it goes to the 
 372                     // debug window anyhow 
 374                     OutputDebugString(str
); 
 376                     // send them to stderr 
 377                     wxFprintf(stderr
, wxT("[%s] %s\n"), 
 378                               level 
== wxLOG_Trace 
? wxT("Trace") 
 384             #endif // __WXDEBUG__ 
 388         case wxLOG_FatalError
: 
 389             // show this one immediately 
 390             wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
); 
 396 #if !wxUSE_LOG_DIALOG 
 397                 // discard earlier informational messages if this is the 1st 
 398                 // error because they might not make sense any more and showing 
 399                 // them in a message box might be confusing 
 403 #endif // wxUSE_LOG_DIALOG 
 410                 // for the warning we don't discard the info messages 
 414             m_aMessages
.Add(szString
); 
 415             m_aSeverity
.Add((int)level
); 
 416             m_aTimes
.Add((long)t
); 
 417             m_bHasMessages 
= true; 
 422 #endif   // wxUSE_LOGGUI 
 424 // ---------------------------------------------------------------------------- 
 425 // wxLogWindow and wxLogFrame implementation 
 426 // ---------------------------------------------------------------------------- 
 432 class wxLogFrame 
: public wxFrame
 
 436     wxLogFrame(wxWindow 
*pParent
, wxLogWindow 
*log
, const wxChar 
*szTitle
); 
 437     virtual ~wxLogFrame(); 
 440     void OnClose(wxCommandEvent
& event
); 
 441     void OnCloseWindow(wxCloseEvent
& event
); 
 443     void OnSave (wxCommandEvent
& event
); 
 445     void OnClear(wxCommandEvent
& event
); 
 448     wxTextCtrl 
*TextCtrl() const { return m_pTextCtrl
; } 
 451     // use standard ids for our commands! 
 454         Menu_Close 
= wxID_CLOSE
, 
 455         Menu_Save  
= wxID_SAVE
, 
 456         Menu_Clear 
= wxID_CLEAR
 
 459     // common part of OnClose() and OnCloseWindow() 
 462     wxTextCtrl  
*m_pTextCtrl
; 
 465     DECLARE_EVENT_TABLE() 
 466     DECLARE_NO_COPY_CLASS(wxLogFrame
) 
 469 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
) 
 470     // wxLogWindow menu events 
 471     EVT_MENU(Menu_Close
, wxLogFrame::OnClose
) 
 473     EVT_MENU(Menu_Save
,  wxLogFrame::OnSave
) 
 475     EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
) 
 477     EVT_CLOSE(wxLogFrame::OnCloseWindow
) 
 480 wxLogFrame::wxLogFrame(wxWindow 
*pParent
, wxLogWindow 
*log
, const wxChar 
*szTitle
) 
 481           : wxFrame(pParent
, wxID_ANY
, szTitle
) 
 485     m_pTextCtrl 
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, 
 489             // needed for Win32 to avoid 65Kb limit but it doesn't work well 
 490             // when using RichEdit 2.0 which we always do in the Unicode build 
 493 #endif // !wxUSE_UNICODE 
 498     wxMenuBar 
*pMenuBar 
= new wxMenuBar
; 
 499     wxMenu 
*pMenu 
= new wxMenu
; 
 501     pMenu
->Append(Menu_Save
,  _("&Save..."), _("Save log contents to file")); 
 503     pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents")); 
 504     pMenu
->AppendSeparator(); 
 505     pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window")); 
 506     pMenuBar
->Append(pMenu
, _("&Log")); 
 507     SetMenuBar(pMenuBar
); 
 508 #endif // wxUSE_MENUS 
 511     // status bar for menu prompts 
 513 #endif // wxUSE_STATUSBAR 
 515     m_log
->OnFrameCreate(this); 
 518 void wxLogFrame::DoClose() 
 520     if ( m_log
->OnFrameClose(this) ) 
 522         // instead of closing just hide the window to be able to Show() it 
 528 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
)) 
 533 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 539 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
)) 
 544     int rc 
= OpenLogFile(file
, &filename
, this); 
 553     // retrieve text and save it 
 554     // ------------------------- 
 555     int nLines 
= m_pTextCtrl
->GetNumberOfLines(); 
 556     for ( int nLine 
= 0; bOk 
&& nLine 
< nLines
; nLine
++ ) { 
 557         bOk 
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) + 
 558                          wxTextFile::GetEOL()); 
 565         wxLogError(_("Can't save log contents to file.")); 
 568         wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str()); 
 574 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
)) 
 576     m_pTextCtrl
->Clear(); 
 579 wxLogFrame::~wxLogFrame() 
 581     m_log
->OnFrameDelete(this); 
 587 wxLogWindow::wxLogWindow(wxWindow 
*pParent
, 
 588                          const wxChar 
*szTitle
, 
 592     PassMessages(bDoPass
); 
 594     m_pLogFrame 
= new wxLogFrame(pParent
, this, szTitle
); 
 600 void wxLogWindow::Show(bool bShow
) 
 602     m_pLogFrame
->Show(bShow
); 
 605 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar 
*szString
, time_t t
) 
 607     // first let the previous logger show it 
 608     wxLogPassThrough::DoLog(level
, szString
, t
); 
 613                 // by default, these messages are ignored by wxLog, so process 
 615                 if ( !wxIsEmpty(szString
) ) 
 618                     str 
<< _("Status: ") << szString
; 
 623                 // don't put trace messages in the text window for 2 reasons: 
 624                 // 1) there are too many of them 
 625                 // 2) they may provoke other trace messages thus sending a program 
 626                 //    into an infinite loop 
 631                 // and this will format it nicely and call our DoLogString() 
 632                 wxLog::DoLog(level
, szString
, t
); 
 637 void wxLogWindow::DoLogString(const wxChar 
*szString
, time_t WXUNUSED(t
)) 
 639     // put the text into our window 
 640     wxTextCtrl 
*pText 
= m_pLogFrame
->TextCtrl(); 
 642     // remove selection (WriteText is in fact ReplaceSelection) 
 644     wxTextPos nLen 
= pText
->GetLastPosition(); 
 645     pText
->SetSelection(nLen
, nLen
); 
 650     msg 
<< szString 
<< wxT('\n'); 
 652     pText
->AppendText(msg
); 
 654     // TODO ensure that the line can be seen 
 657 wxFrame 
*wxLogWindow::GetFrame() const 
 662 void wxLogWindow::OnFrameCreate(wxFrame 
* WXUNUSED(frame
)) 
 666 bool wxLogWindow::OnFrameClose(wxFrame 
* WXUNUSED(frame
)) 
 672 void wxLogWindow::OnFrameDelete(wxFrame 
* WXUNUSED(frame
)) 
 674     m_pLogFrame 
= (wxLogFrame 
*)NULL
; 
 677 wxLogWindow::~wxLogWindow() 
 679     // may be NULL if log frame already auto destroyed itself 
 683 #endif // wxUSE_LOGWINDOW 
 685 // ---------------------------------------------------------------------------- 
 687 // ---------------------------------------------------------------------------- 
 691 #ifndef __SMARTPHONE__ 
 692 static const size_t MARGIN 
= 10; 
 694 static const size_t MARGIN 
= 0; 
 697 wxString 
wxLogDialog::ms_details
; 
 699 wxLogDialog::wxLogDialog(wxWindow 
*parent
, 
 700                          const wxArrayString
& messages
, 
 701                          const wxArrayInt
& severity
, 
 702                          const wxArrayLong
& times
, 
 703                          const wxString
& caption
, 
 705            : wxDialog(parent
, wxID_ANY
, caption
, 
 706                       wxDefaultPosition
, wxDefaultSize
, 
 707                       wxDEFAULT_DIALOG_STYLE 
| wxRESIZE_BORDER
) 
 709     if ( ms_details
.empty() ) 
 711         // ensure that we won't loop here if wxGetTranslation() 
 712         // happens to pop up a Log message while translating this :-) 
 713         ms_details 
= wxTRANSLATE("&Details"); 
 714         ms_details 
= wxGetTranslation(ms_details
); 
 715 #ifdef __SMARTPHONE__ 
 716         ms_details 
= wxStripMenuCodes(ms_details
); 
 720     size_t count 
= messages
.GetCount(); 
 721     m_messages
.Alloc(count
); 
 722     m_severity
.Alloc(count
); 
 723     m_times
.Alloc(count
); 
 725     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 727         wxString msg 
= messages
[n
]; 
 728         msg
.Replace(wxT("\n"), wxT(" ")); 
 730         m_severity
.Add(severity
[n
]); 
 731         m_times
.Add(times
[n
]); 
 734     m_showingDetails 
= false; // not initially 
 735     m_listctrl 
= (wxListCtrl 
*)NULL
; 
 737 #ifndef __SMARTPHONE__ 
 740     m_statline 
= (wxStaticLine 
*)NULL
; 
 741 #endif // wxUSE_STATLINE 
 744     m_btnSave 
= (wxButton 
*)NULL
; 
 747 #endif // __SMARTPHONE__ 
 749     bool isPda 
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
); 
 751     // create the controls which are always shown and layout them: we use 
 752     // sizers even though our window is not resizeable to calculate the size of 
 753     // the dialog properly 
 754     wxBoxSizer 
*sizerTop 
= new wxBoxSizer(wxVERTICAL
); 
 755 #ifndef __SMARTPHONE__ 
 756     wxBoxSizer 
*sizerButtons 
= new wxBoxSizer(isPda 
? wxHORIZONTAL 
: wxVERTICAL
); 
 758     wxBoxSizer 
*sizerAll 
= new wxBoxSizer(isPda 
? wxVERTICAL 
: wxHORIZONTAL
); 
 760 #ifdef __SMARTPHONE__ 
 761     SetLeftMenu(wxID_OK
); 
 762     SetRightMenu(wxID_MORE
, ms_details 
+ EXPAND_SUFFIX
); 
 764     wxButton 
*btnOk 
= new wxButton(this, wxID_OK
); 
 765     sizerButtons
->Add(btnOk
, 0, isPda 
? wxCENTRE 
: wxCENTRE
|wxBOTTOM
, MARGIN
/2); 
 766     m_btnDetails 
= new wxButton(this, wxID_MORE
, ms_details 
+ EXPAND_SUFFIX
); 
 767     sizerButtons
->Add(m_btnDetails
, 0, isPda 
? wxCENTRE
|wxLEFT 
: wxCENTRE 
| wxTOP
, MARGIN
/2 - 1); 
 771     switch ( style 
& wxICON_MASK 
) 
 774             bitmap 
= wxArtProvider::GetBitmap(wxART_ERROR
, wxART_MESSAGE_BOX
); 
 776             bitmap
.SetId(wxICON_SMALL_ERROR
); 
 780         case wxICON_INFORMATION
: 
 781             bitmap 
= wxArtProvider::GetBitmap(wxART_INFORMATION
, wxART_MESSAGE_BOX
); 
 783             bitmap
.SetId(wxICON_SMALL_INFO
); 
 788             bitmap 
= wxArtProvider::GetBitmap(wxART_WARNING
, wxART_MESSAGE_BOX
); 
 790             bitmap
.SetId(wxICON_SMALL_WARNING
); 
 795             wxFAIL_MSG(_T("incorrect log style")); 
 799         sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0, 
 800                   wxALIGN_CENTRE_VERTICAL
); 
 802     const wxString
& message 
= messages
.Last(); 
 803     sizerAll
->Add(CreateTextSizer(message
), 1, 
 804                   wxALIGN_CENTRE_VERTICAL 
| wxLEFT 
| wxRIGHT
, MARGIN
); 
 805 #ifndef __SMARTPHONE__ 
 806     sizerAll
->Add(sizerButtons
, 0, isPda 
? wxCENTRE
|wxTOP
|wxBOTTOM 
: (wxALIGN_RIGHT 
| wxLEFT
), MARGIN
); 
 809     sizerTop
->Add(sizerAll
, 0, wxALL 
| wxEXPAND
, MARGIN
); 
 813     // see comments in OnDetails() 
 815     // Note: Doing this, this way, triggered a nasty bug in 
 816     //       wxTopLevelWindowGTK::GtkOnSize which took -1 literally once 
 817     //       either of maxWidth or maxHeight was set.  This symptom has been 
 818     //       fixed there, but it is a problem that remains as long as we allow 
 819     //       unchecked access to the internal size members.  We really need to 
 820     //       encapuslate window sizes more cleanly and make it clear when -1 will 
 821     //       be substituted and when it will not. 
 823     wxSize size 
= sizerTop
->Fit(this); 
 824     m_maxHeight 
= size
.y
; 
 825     SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
); 
 827 #ifndef __SMARTPHONE__ 
 835         // Move up the screen so that when we expand the dialog, 
 836         // there's enough space. 
 837         Move(wxPoint(GetPosition().x
, GetPosition().y 
/ 2)); 
 841 void wxLogDialog::CreateDetailsControls() 
 843 #ifndef __SMARTPHONE__ 
 844     // create the save button and separator line if possible 
 846     m_btnSave 
= new wxButton(this, wxID_SAVE
); 
 850     m_statline 
= new wxStaticLine(this, wxID_ANY
); 
 851 #endif // wxUSE_STATLINE 
 853 #endif // __SMARTPHONE__ 
 855     // create the list ctrl now 
 856     m_listctrl 
= new wxListCtrl(this, wxID_ANY
, 
 857                                 wxDefaultPosition
, wxDefaultSize
, 
 863     // This maks a big aesthetic difference on WinCE but I 
 864     // don't want to risk problems on other platforms 
 868     // no need to translate these strings as they're not shown to the 
 869     // user anyhow (we use wxLC_NO_HEADER style) 
 870     m_listctrl
->InsertColumn(0, _T("Message")); 
 871     m_listctrl
->InsertColumn(1, _T("Time")); 
 873     // prepare the imagelist 
 874     static const int ICON_SIZE 
= 16; 
 875     wxImageList 
*imageList 
= new wxImageList(ICON_SIZE
, ICON_SIZE
); 
 877     // order should be the same as in the switch below! 
 878     static const wxChar
* icons
[] = 
 885     bool loadedIcons 
= true; 
 887     for ( size_t icon 
= 0; icon 
< WXSIZEOF(icons
); icon
++ ) 
 889         wxBitmap bmp 
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
, 
 890                                                 wxSize(ICON_SIZE
, ICON_SIZE
)); 
 892         // This may very well fail if there are insufficient colours available. 
 893         // Degrade gracefully. 
 904     m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
); 
 907     wxString fmt 
= wxLog::GetTimestamp(); 
 914     size_t count 
= m_messages
.GetCount(); 
 915     for ( size_t n 
= 0; n 
< count
; n
++ ) 
 921             switch ( m_severity
[n
] ) 
 935         else // failed to load images 
 940         m_listctrl
->InsertItem(n
, m_messages
[n
], image
); 
 941         m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
])); 
 944     // let the columns size themselves 
 945     m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
); 
 946     m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
); 
 948     // calculate an approximately nice height for the listctrl 
 949     int height 
= GetCharHeight()*(count 
+ 4); 
 951     // but check that the dialog won't fall fown from the screen 
 953     // we use GetMinHeight() to get the height of the dialog part without the 
 954     // details and we consider that the "Save" button below and the separator 
 955     // line (and the margins around it) take about as much, hence double it 
 956     int heightMax 
= wxGetDisplaySize().y 
- GetPosition().y 
- 2*GetMinHeight(); 
 958     // we should leave a margin 
 962     m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
)); 
 965 void wxLogDialog::OnListSelect(wxListEvent
& event
) 
 967     // we can't just disable the control because this looks ugly under Windows 
 968     // (wrong bg colour, no scrolling...), but we still want to disable 
 969     // selecting items - it makes no sense here 
 970     m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
); 
 973 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
)) 
 980 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
)) 
 984     int rc 
= OpenLogFile(file
, NULL
, this); 
 993     wxString fmt 
= wxLog::GetTimestamp(); 
1000     size_t count 
= m_messages
.GetCount(); 
1001     for ( size_t n 
= 0; ok 
&& (n 
< count
); n
++ ) 
1004         line 
<< TimeStamp(fmt
, (time_t)m_times
[n
]) 
1007              << wxTextFile::GetEOL(); 
1009         ok 
= file
.Write(line
); 
1016         wxLogError(_("Can't save log contents to file.")); 
1017 #endif // wxUSE_FILEDLG 
1020 #endif // wxUSE_FILE 
1022 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
)) 
1024     wxSizer 
*sizer 
= GetSizer(); 
1026     if ( m_showingDetails 
) 
1028 #ifdef __SMARTPHONE__ 
1029         SetRightMenu(wxID_MORE
, ms_details 
+ EXPAND_SUFFIX
); 
1031         m_btnDetails
->SetLabel(ms_details 
+ EXPAND_SUFFIX
); 
1034         sizer
->Detach( m_listctrl 
); 
1036 #ifndef __SMARTPHONE__ 
1039         sizer
->Detach( m_statline 
); 
1040 #endif // wxUSE_STATLINE 
1043         sizer
->Detach( m_btnSave 
); 
1044 #endif // wxUSE_FILE 
1046 #endif // __SMARTPHONE__ 
1048     else // show details now 
1050 #ifdef __SMARTPHONE__ 
1051         SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
); 
1053         m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
); 
1058             CreateDetailsControls(); 
1061 #if wxUSE_STATLINE && !defined(__SMARTPHONE__) 
1062         bool isPda 
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
); 
1064             sizer
->Add(m_statline
, 0, wxEXPAND 
| (wxALL 
& ~wxTOP
), MARGIN
); 
1065 #endif // wxUSE_STATLINE 
1067         sizer
->Add(m_listctrl
, 1, wxEXPAND 
| (wxALL 
& ~wxTOP
), MARGIN
); 
1069         // VZ: this doesn't work as this becomes the initial (and not only 
1070         //     minimal) listctrl height as well - why? 
1072         // allow the user to make the dialog shorter than its initial height - 
1073         // without this it wouldn't work as the list ctrl would have been 
1075         sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight()); 
1078 #if wxUSE_FILE && !defined(__SMARTPHONE__) 
1079         sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT 
| (wxALL 
& ~wxTOP
), MARGIN
); 
1080 #endif // wxUSE_FILE 
1083     m_showingDetails 
= !m_showingDetails
; 
1085     // in any case, our size changed - relayout everything and set new hints 
1086     // --------------------------------------------------------------------- 
1088     // we have to reset min size constraints or Fit() would never reduce the 
1089     // dialog size when collapsing it and we have to reset max constraint 
1090     // because it wouldn't expand it otherwise 
1095     // wxSizer::FitSize() is private, otherwise we might use it directly... 
1096     wxSize sizeTotal 
= GetSize(), 
1097            sizeClient 
= GetClientSize(); 
1099     wxSize size 
= sizer
->GetMinSize(); 
1100     size
.x 
+= sizeTotal
.x 
- sizeClient
.x
; 
1101     size
.y 
+= sizeTotal
.y 
- sizeClient
.y
; 
1103     // we don't want to allow expanding the dialog in vertical direction as 
1104     // this would show the "hidden" details but we can resize the dialog 
1105     // vertically while the details are shown 
1106     if ( !m_showingDetails 
) 
1107         m_maxHeight 
= size
.y
; 
1109     SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
); 
1112     if (m_showingDetails
) 
1116     // don't change the width when expanding/collapsing 
1117     SetSize(wxDefaultCoord
, size
.y
); 
1120     // VS: this is necessary in order to force frame redraw under 
1121     // WindowMaker or fvwm2 (and probably other broken WMs). 
1122     // Otherwise, detailed list wouldn't be displayed. 
1127 wxLogDialog::~wxLogDialog() 
1131         delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
); 
1135 #endif // wxUSE_LOG_DIALOG 
1137 #if wxUSE_FILE && wxUSE_FILEDLG 
1139 // pass an uninitialized file object, the function will ask the user for the 
1140 // filename and try to open it, returns true on success (file was opened), 
1141 // false if file couldn't be opened/created and -1 if the file selection 
1142 // dialog was cancelled 
1143 static int OpenLogFile(wxFile
& file
, wxString 
*pFilename
, wxWindow 
*parent
) 
1145     // get the file name 
1146     // ----------------- 
1147     wxString filename 
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
); 
1155     bool bOk 
wxDUMMY_INITIALIZE(false); 
1156     if ( wxFile::Exists(filename
) ) { 
1157         bool bAppend 
= false; 
1159         strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"), 
1161         switch ( wxMessageBox(strMsg
, _("Question"), 
1162                               wxICON_QUESTION 
| wxYES_NO 
| wxCANCEL
) ) { 
1175                 wxFAIL_MSG(_("invalid message box return value")); 
1179             bOk 
= file
.Open(filename
, wxFile::write_append
); 
1182             bOk 
= file
.Create(filename
, true /* overwrite */); 
1186         bOk 
= file
.Create(filename
); 
1190         *pFilename 
= filename
; 
1195 #endif // wxUSE_FILE 
1197 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW) 
1199 #if wxUSE_LOG && wxUSE_TEXTCTRL 
1201 // ---------------------------------------------------------------------------- 
1202 // wxLogTextCtrl implementation 
1203 // ---------------------------------------------------------------------------- 
1205 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl 
*pTextCtrl
) 
1207     m_pTextCtrl 
= pTextCtrl
; 
1210 void wxLogTextCtrl::DoLogString(const wxChar 
*szString
, time_t WXUNUSED(t
)) 
1215     msg 
<< szString 
<< wxT('\n'); 
1216     m_pTextCtrl
->AppendText(msg
); 
1219 #endif // wxUSE_LOG && wxUSE_TEXTCTRL