b7760651303471868a21c852a5956704096ebf73
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/settings.h"
43 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW
46 #include "wx/textfile.h"
47 #include "wx/statline.h"
48 #include "wx/artprov.h"
51 // for OutputDebugString()
52 #include "wx/msw/private.h"
60 #include "wx/listctrl.h"
61 #include "wx/imaglist.h"
63 #else // !wxUSE_LOG_DIALOG
64 #include "wx/msgdlg.h"
65 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
67 #if defined(__MWERKS__) && wxUSE_UNICODE
71 #include "wx/datetime.h"
73 // the suffix we add to the button to show that the dialog can be expanded
74 #define EXPAND_SUFFIX _T(" >>")
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
82 // this function is a wrapper around strftime(3)
83 // allows to exclude the usage of wxDateTime
84 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
87 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
89 // buffer is too small?
90 wxFAIL_MSG(_T("strftime() failed"));
96 class wxLogDialog
: public wxDialog
99 wxLogDialog(wxWindow
*parent
,
100 const wxArrayString
& messages
,
101 const wxArrayInt
& severity
,
102 const wxArrayLong
& timess
,
103 const wxString
& caption
,
105 virtual ~wxLogDialog();
108 void OnOk(wxCommandEvent
& event
);
109 void OnDetails(wxCommandEvent
& event
);
111 void OnSave(wxCommandEvent
& event
);
113 void OnListSelect(wxListEvent
& event
);
116 // create controls needed for the details display
117 void CreateDetailsControls();
119 // the data for the listctrl
120 wxArrayString m_messages
;
121 wxArrayInt m_severity
;
124 // the "toggle" button and its state
125 #ifndef __SMARTPHONE__
126 wxButton
*m_btnDetails
;
128 bool m_showingDetails
;
130 // the controls which are not shown initially (but only when details
131 // button is pressed)
132 wxListCtrl
*m_listctrl
;
133 #ifndef __SMARTPHONE__
135 wxStaticLine
*m_statline
;
136 #endif // wxUSE_STATLINE
140 #endif // __SMARTPHONE__
142 // the translated "Details" string
143 static wxString ms_details
;
145 DECLARE_EVENT_TABLE()
146 DECLARE_NO_COPY_CLASS(wxLogDialog
)
149 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
150 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
151 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
153 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
155 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
158 #endif // wxUSE_LOG_DIALOG
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 #if wxUSE_FILE && wxUSE_FILEDLG
166 // pass an uninitialized file object, the function will ask the user for the
167 // filename and try to open it, returns true on success (file was opened),
168 // false if file couldn't be opened/created and -1 if the file selection
169 // dialog was cancelled
170 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 // we use a global variable to store the frame pointer for wxLogStatus - bad,
179 // but it's the easiest way
180 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
182 // ============================================================================
184 // ============================================================================
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 // accepts an additional argument which tells to which frame the output should
192 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
196 wxLog
*pLog
= wxLog::GetActiveTarget();
197 if ( pLog
!= NULL
) {
198 msg
.PrintfV(szFormat
, argptr
);
200 wxASSERT( gs_pFrame
== NULL
); // should be reset!
203 wxLog::OnLog(wxLOG_Status
, msg
, 0);
205 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
207 gs_pFrame
= (wxFrame
*) NULL
;
211 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
214 va_start(argptr
, szFormat
);
215 wxVLogStatus(pFrame
, szFormat
, argptr
);
219 // ----------------------------------------------------------------------------
220 // wxLogGui implementation (FIXME MT-unsafe)
221 // ----------------------------------------------------------------------------
230 void wxLogGui::Clear()
234 m_bHasMessages
= false;
241 void wxLogGui::Flush()
243 if ( !m_bHasMessages
)
246 // do it right now to block any new calls to Flush() while we're here
247 m_bHasMessages
= false;
249 wxString appName
= wxTheApp
->GetAppName();
250 if ( !appName
.empty() )
251 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
254 wxString titleFormat
;
256 titleFormat
= _("%s Error");
259 else if ( m_bWarnings
) {
260 titleFormat
= _("%s Warning");
261 style
= wxICON_EXCLAMATION
;
264 titleFormat
= _("%s Information");
265 style
= wxICON_INFORMATION
;
269 title
.Printf(titleFormat
, appName
.c_str());
271 size_t nMsgCount
= m_aMessages
.Count();
273 // avoid showing other log dialogs until we're done with the dialog we're
274 // showing right now: nested modal dialogs make for really bad UI!
278 if ( nMsgCount
== 1 )
280 str
= m_aMessages
[0];
282 else // more than one message
286 wxLogDialog
dlg(NULL
,
287 m_aMessages
, m_aSeverity
, m_aTimes
,
290 // clear the message list before showing the dialog because while it's
291 // shown some new messages may appear
294 (void)dlg
.ShowModal();
295 #else // !wxUSE_LOG_DIALOG
296 // concatenate all strings (but not too many to not overfill the msg box)
299 // start from the most recent message
300 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
301 // for Windows strings longer than this value are wrapped (NT 4.0)
302 const size_t nMsgLineWidth
= 156;
304 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
306 if ( nLines
> 25 ) // don't put too many lines in message box
309 str
<< m_aMessages
[n
- 1] << wxT("\n");
311 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
314 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
315 // situation without it
318 wxMessageBox(str
, title
, wxOK
| style
);
320 // no undisplayed messages whatsoever
324 // allow flushing the logs again
328 // log all kinds of messages
329 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
336 m_aMessages
.Add(szString
);
337 m_aSeverity
.Add(wxLOG_Message
);
338 m_aTimes
.Add((long)t
);
339 m_bHasMessages
= true;
346 // find the top window and set it's status text if it has any
347 wxFrame
*pFrame
= gs_pFrame
;
348 if ( pFrame
== NULL
) {
349 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
350 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
351 pFrame
= (wxFrame
*)pWin
;
355 if ( pFrame
&& pFrame
->GetStatusBar() )
356 pFrame
->SetStatusText(szString
);
358 #endif // wxUSE_STATUSBAR
369 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
370 // don't prepend debug/trace here: it goes to the
371 // debug window anyhow
373 OutputDebugString(str
);
375 // send them to stderr
376 wxFprintf(stderr
, wxT("[%s] %s\n"),
377 level
== wxLOG_Trace
? wxT("Trace")
383 #endif // __WXDEBUG__
387 case wxLOG_FatalError
:
388 // show this one immediately
389 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
395 #if !wxUSE_LOG_DIALOG
396 // discard earlier informational messages if this is the 1st
397 // error because they might not make sense any more and showing
398 // them in a message box might be confusing
402 #endif // wxUSE_LOG_DIALOG
409 // for the warning we don't discard the info messages
413 m_aMessages
.Add(szString
);
414 m_aSeverity
.Add((int)level
);
415 m_aTimes
.Add((long)t
);
416 m_bHasMessages
= true;
421 #endif // wxUSE_LOGGUI
423 // ----------------------------------------------------------------------------
424 // wxLogWindow and wxLogFrame implementation
425 // ----------------------------------------------------------------------------
431 class wxLogFrame
: public wxFrame
435 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
436 virtual ~wxLogFrame();
439 void OnClose(wxCommandEvent
& event
);
440 void OnCloseWindow(wxCloseEvent
& event
);
442 void OnSave (wxCommandEvent
& event
);
444 void OnClear(wxCommandEvent
& event
);
447 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
450 // use standard ids for our commands!
453 Menu_Close
= wxID_CLOSE
,
454 Menu_Save
= wxID_SAVE
,
455 Menu_Clear
= wxID_CLEAR
458 // common part of OnClose() and OnCloseWindow()
461 wxTextCtrl
*m_pTextCtrl
;
464 DECLARE_EVENT_TABLE()
465 DECLARE_NO_COPY_CLASS(wxLogFrame
)
468 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
469 // wxLogWindow menu events
470 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
472 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
474 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
476 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
479 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
480 : wxFrame(pParent
, wxID_ANY
, szTitle
)
484 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
488 // needed for Win32 to avoid 65Kb limit but it doesn't work well
489 // when using RichEdit 2.0 which we always do in the Unicode build
492 #endif // !wxUSE_UNICODE
497 wxMenuBar
*pMenuBar
= new wxMenuBar
;
498 wxMenu
*pMenu
= new wxMenu
;
500 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
502 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
503 pMenu
->AppendSeparator();
504 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
505 pMenuBar
->Append(pMenu
, _("&Log"));
506 SetMenuBar(pMenuBar
);
507 #endif // wxUSE_MENUS
510 // status bar for menu prompts
512 #endif // wxUSE_STATUSBAR
514 m_log
->OnFrameCreate(this);
517 void wxLogFrame::DoClose()
519 if ( m_log
->OnFrameClose(this) )
521 // instead of closing just hide the window to be able to Show() it
527 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
532 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
538 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
543 int rc
= OpenLogFile(file
, &filename
, this);
552 // retrieve text and save it
553 // -------------------------
554 int nLines
= m_pTextCtrl
->GetNumberOfLines();
555 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
556 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
557 wxTextFile::GetEOL());
564 wxLogError(_("Can't save log contents to file."));
567 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
573 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
575 m_pTextCtrl
->Clear();
578 wxLogFrame::~wxLogFrame()
580 m_log
->OnFrameDelete(this);
586 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
587 const wxChar
*szTitle
,
591 PassMessages(bDoPass
);
593 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
599 void wxLogWindow::Show(bool bShow
)
601 m_pLogFrame
->Show(bShow
);
604 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
606 // first let the previous logger show it
607 wxLogPassThrough::DoLog(level
, szString
, t
);
612 // by default, these messages are ignored by wxLog, so process
614 if ( !wxIsEmpty(szString
) )
617 str
<< _("Status: ") << szString
;
622 // don't put trace messages in the text window for 2 reasons:
623 // 1) there are too many of them
624 // 2) they may provoke other trace messages thus sending a program
625 // into an infinite loop
630 // and this will format it nicely and call our DoLogString()
631 wxLog::DoLog(level
, szString
, t
);
636 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
638 // put the text into our window
639 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
641 // remove selection (WriteText is in fact ReplaceSelection)
643 wxTextPos nLen
= pText
->GetLastPosition();
644 pText
->SetSelection(nLen
, nLen
);
649 msg
<< szString
<< wxT('\n');
651 pText
->AppendText(msg
);
653 // TODO ensure that the line can be seen
656 wxFrame
*wxLogWindow::GetFrame() const
661 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
665 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
671 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
673 m_pLogFrame
= (wxLogFrame
*)NULL
;
676 wxLogWindow::~wxLogWindow()
678 // may be NULL if log frame already auto destroyed itself
682 #endif // wxUSE_LOGWINDOW
684 // ----------------------------------------------------------------------------
686 // ----------------------------------------------------------------------------
690 #ifndef __SMARTPHONE__
691 static const size_t MARGIN
= 10;
693 static const size_t MARGIN
= 0;
696 wxString
wxLogDialog::ms_details
;
698 wxLogDialog::wxLogDialog(wxWindow
*parent
,
699 const wxArrayString
& messages
,
700 const wxArrayInt
& severity
,
701 const wxArrayLong
& times
,
702 const wxString
& caption
,
704 : wxDialog(parent
, wxID_ANY
, caption
,
705 wxDefaultPosition
, wxDefaultSize
,
706 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
708 if ( ms_details
.empty() )
710 // ensure that we won't loop here if wxGetTranslation()
711 // happens to pop up a Log message while translating this :-)
712 ms_details
= wxTRANSLATE("&Details");
713 ms_details
= wxGetTranslation(ms_details
);
714 #ifdef __SMARTPHONE__
715 ms_details
= wxStripMenuCodes(ms_details
);
719 size_t count
= messages
.GetCount();
720 m_messages
.Alloc(count
);
721 m_severity
.Alloc(count
);
722 m_times
.Alloc(count
);
724 for ( size_t n
= 0; n
< count
; n
++ )
726 wxString msg
= messages
[n
];
727 msg
.Replace(wxT("\n"), wxT(" "));
729 m_severity
.Add(severity
[n
]);
730 m_times
.Add(times
[n
]);
733 m_showingDetails
= false; // not initially
734 m_listctrl
= (wxListCtrl
*)NULL
;
736 #ifndef __SMARTPHONE__
739 m_statline
= (wxStaticLine
*)NULL
;
740 #endif // wxUSE_STATLINE
743 m_btnSave
= (wxButton
*)NULL
;
746 #endif // __SMARTPHONE__
748 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
750 // create the controls which are always shown and layout them: we use
751 // sizers even though our window is not resizeable to calculate the size of
752 // the dialog properly
753 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
754 #ifndef __SMARTPHONE__
755 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
757 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
759 #ifdef __SMARTPHONE__
760 SetLeftMenu(wxID_OK
);
761 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
763 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
764 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
765 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
766 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
770 switch ( style
& wxICON_MASK
)
773 bitmap
= wxArtProvider::GetBitmap(wxART_ERROR
, wxART_MESSAGE_BOX
);
775 bitmap
.SetId(wxICON_SMALL_ERROR
);
779 case wxICON_INFORMATION
:
780 bitmap
= wxArtProvider::GetBitmap(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
782 bitmap
.SetId(wxICON_SMALL_INFO
);
787 bitmap
= wxArtProvider::GetBitmap(wxART_WARNING
, wxART_MESSAGE_BOX
);
789 bitmap
.SetId(wxICON_SMALL_WARNING
);
794 wxFAIL_MSG(_T("incorrect log style"));
798 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
799 wxALIGN_CENTRE_VERTICAL
);
801 const wxString
& message
= messages
.Last();
802 sizerAll
->Add(CreateTextSizer(message
), 1,
803 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
804 #ifndef __SMARTPHONE__
805 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
808 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
812 // see comments in OnDetails()
814 // Note: Doing this, this way, triggered a nasty bug in
815 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
816 // either of maxWidth or maxHeight was set. This symptom has been
817 // fixed there, but it is a problem that remains as long as we allow
818 // unchecked access to the internal size members. We really need to
819 // encapuslate window sizes more cleanly and make it clear when -1 will
820 // be substituted and when it will not.
822 wxSize size
= sizerTop
->Fit(this);
823 m_maxHeight
= size
.y
;
824 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
826 #ifndef __SMARTPHONE__
834 // Move up the screen so that when we expand the dialog,
835 // there's enough space.
836 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
840 void wxLogDialog::CreateDetailsControls()
842 #ifndef __SMARTPHONE__
843 // create the save button and separator line if possible
845 m_btnSave
= new wxButton(this, wxID_SAVE
);
849 m_statline
= new wxStaticLine(this, wxID_ANY
);
850 #endif // wxUSE_STATLINE
852 #endif // __SMARTPHONE__
854 // create the list ctrl now
855 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
856 wxDefaultPosition
, wxDefaultSize
,
862 // This maks a big aesthetic difference on WinCE but I
863 // don't want to risk problems on other platforms
867 // no need to translate these strings as they're not shown to the
868 // user anyhow (we use wxLC_NO_HEADER style)
869 m_listctrl
->InsertColumn(0, _T("Message"));
870 m_listctrl
->InsertColumn(1, _T("Time"));
872 // prepare the imagelist
873 static const int ICON_SIZE
= 16;
874 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
876 // order should be the same as in the switch below!
877 static const wxChar
* icons
[] =
884 bool loadedIcons
= true;
886 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
888 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
889 wxSize(ICON_SIZE
, ICON_SIZE
));
891 // This may very well fail if there are insufficient colours available.
892 // Degrade gracefully.
903 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
906 wxString fmt
= wxLog::GetTimestamp();
913 size_t count
= m_messages
.GetCount();
914 for ( size_t n
= 0; n
< count
; n
++ )
920 switch ( m_severity
[n
] )
934 else // failed to load images
939 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
940 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
943 // let the columns size themselves
944 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
945 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
947 // calculate an approximately nice height for the listctrl
948 int height
= GetCharHeight()*(count
+ 4);
950 // but check that the dialog won't fall fown from the screen
952 // we use GetMinHeight() to get the height of the dialog part without the
953 // details and we consider that the "Save" button below and the separator
954 // line (and the margins around it) take about as much, hence double it
955 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
957 // we should leave a margin
961 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
964 void wxLogDialog::OnListSelect(wxListEvent
& event
)
966 // we can't just disable the control because this looks ugly under Windows
967 // (wrong bg colour, no scrolling...), but we still want to disable
968 // selecting items - it makes no sense here
969 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
972 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
979 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
983 int rc
= OpenLogFile(file
, NULL
, this);
992 wxString fmt
= wxLog::GetTimestamp();
999 size_t count
= m_messages
.GetCount();
1000 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
1003 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
1006 << wxTextFile::GetEOL();
1008 ok
= file
.Write(line
);
1015 wxLogError(_("Can't save log contents to file."));
1016 #endif // wxUSE_FILEDLG
1019 #endif // wxUSE_FILE
1021 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1023 wxSizer
*sizer
= GetSizer();
1025 if ( m_showingDetails
)
1027 #ifdef __SMARTPHONE__
1028 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
1030 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1033 sizer
->Detach( m_listctrl
);
1035 #ifndef __SMARTPHONE__
1038 sizer
->Detach( m_statline
);
1039 #endif // wxUSE_STATLINE
1042 sizer
->Detach( m_btnSave
);
1043 #endif // wxUSE_FILE
1045 #endif // __SMARTPHONE__
1047 else // show details now
1049 #ifdef __SMARTPHONE__
1050 SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
);
1052 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1057 CreateDetailsControls();
1060 #if wxUSE_STATLINE && !defined(__SMARTPHONE__)
1061 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1063 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1064 #endif // wxUSE_STATLINE
1066 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1068 // VZ: this doesn't work as this becomes the initial (and not only
1069 // minimal) listctrl height as well - why?
1071 // allow the user to make the dialog shorter than its initial height -
1072 // without this it wouldn't work as the list ctrl would have been
1074 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1077 #if wxUSE_FILE && !defined(__SMARTPHONE__)
1078 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1079 #endif // wxUSE_FILE
1082 m_showingDetails
= !m_showingDetails
;
1084 // in any case, our size changed - relayout everything and set new hints
1085 // ---------------------------------------------------------------------
1087 // we have to reset min size constraints or Fit() would never reduce the
1088 // dialog size when collapsing it and we have to reset max constraint
1089 // because it wouldn't expand it otherwise
1094 // wxSizer::FitSize() is private, otherwise we might use it directly...
1095 wxSize sizeTotal
= GetSize(),
1096 sizeClient
= GetClientSize();
1098 wxSize size
= sizer
->GetMinSize();
1099 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1100 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1102 // we don't want to allow expanding the dialog in vertical direction as
1103 // this would show the "hidden" details but we can resize the dialog
1104 // vertically while the details are shown
1105 if ( !m_showingDetails
)
1106 m_maxHeight
= size
.y
;
1108 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1111 if (m_showingDetails
)
1115 // don't change the width when expanding/collapsing
1116 SetSize(wxDefaultCoord
, size
.y
);
1119 // VS: this is necessary in order to force frame redraw under
1120 // WindowMaker or fvwm2 (and probably other broken WMs).
1121 // Otherwise, detailed list wouldn't be displayed.
1126 wxLogDialog::~wxLogDialog()
1130 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1134 #endif // wxUSE_LOG_DIALOG
1136 #if wxUSE_FILE && wxUSE_FILEDLG
1138 // pass an uninitialized file object, the function will ask the user for the
1139 // filename and try to open it, returns true on success (file was opened),
1140 // false if file couldn't be opened/created and -1 if the file selection
1141 // dialog was cancelled
1142 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1144 // get the file name
1145 // -----------------
1146 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1154 bool bOk
wxDUMMY_INITIALIZE(false);
1155 if ( wxFile::Exists(filename
) ) {
1156 bool bAppend
= false;
1158 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1160 switch ( wxMessageBox(strMsg
, _("Question"),
1161 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1174 wxFAIL_MSG(_("invalid message box return value"));
1178 bOk
= file
.Open(filename
, wxFile::write_append
);
1181 bOk
= file
.Create(filename
, true /* overwrite */);
1185 bOk
= file
.Create(filename
);
1189 *pFilename
= filename
;
1194 #endif // wxUSE_FILE
1196 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1198 #if wxUSE_LOG && wxUSE_TEXTCTRL
1200 // ----------------------------------------------------------------------------
1201 // wxLogTextCtrl implementation
1202 // ----------------------------------------------------------------------------
1204 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1206 m_pTextCtrl
= pTextCtrl
;
1209 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1214 msg
<< szString
<< wxT('\n');
1215 m_pTextCtrl
->AppendText(msg
);
1218 #endif // wxUSE_LOG && wxUSE_TEXTCTRL