]>
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/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 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
65 #if defined(__MWERKS__) && wxUSE_UNICODE
69 #include "wx/datetime.h"
71 // the suffix we add to the button to show that the dialog can be expanded
72 #define EXPAND_SUFFIX _T(" >>")
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
80 // this function is a wrapper around strftime(3)
81 // allows to exclude the usage of wxDateTime
82 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
86 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, wxLocaltime_r(&t
, &tm
)) )
88 // buffer is too small?
89 wxFAIL_MSG(_T("strftime() failed"));
95 class wxLogDialog
: public wxDialog
98 wxLogDialog(wxWindow
*parent
,
99 const wxArrayString
& messages
,
100 const wxArrayInt
& severity
,
101 const wxArrayLong
& timess
,
102 const wxString
& caption
,
104 virtual ~wxLogDialog();
107 void OnOk(wxCommandEvent
& event
);
108 void OnDetails(wxCommandEvent
& event
);
110 void OnSave(wxCommandEvent
& event
);
112 void OnListSelect(wxListEvent
& event
);
115 // create controls needed for the details display
116 void CreateDetailsControls();
118 // the data for the listctrl
119 wxArrayString m_messages
;
120 wxArrayInt m_severity
;
123 // the "toggle" button and its state
124 #ifndef __SMARTPHONE__
125 wxButton
*m_btnDetails
;
127 bool m_showingDetails
;
129 // the controls which are not shown initially (but only when details
130 // button is pressed)
131 wxListCtrl
*m_listctrl
;
132 #ifndef __SMARTPHONE__
134 wxStaticLine
*m_statline
;
135 #endif // wxUSE_STATLINE
139 #endif // __SMARTPHONE__
141 // the translated "Details" string
142 static wxString ms_details
;
144 DECLARE_EVENT_TABLE()
145 DECLARE_NO_COPY_CLASS(wxLogDialog
)
148 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
149 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
150 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
152 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
154 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
157 #endif // wxUSE_LOG_DIALOG
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 #if wxUSE_FILE && wxUSE_FILEDLG
165 // pass an uninitialized file object, the function will ask the user for the
166 // filename and try to open it, returns true on success (file was opened),
167 // false if file couldn't be opened/created and -1 if the file selection
168 // dialog was cancelled
169 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 // we use a global variable to store the frame pointer for wxLogStatus - bad,
178 // but it's the easiest way
179 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
181 // ============================================================================
183 // ============================================================================
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 // accepts an additional argument which tells to which frame the output should
191 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
195 wxLog
*pLog
= wxLog::GetActiveTarget();
196 if ( pLog
!= NULL
) {
197 msg
.PrintfV(szFormat
, argptr
);
199 wxASSERT( gs_pFrame
== NULL
); // should be reset!
202 wxLog::OnLog(wxLOG_Status
, msg
, 0);
204 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
206 gs_pFrame
= (wxFrame
*) NULL
;
210 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
213 va_start(argptr
, szFormat
);
214 wxVLogStatus(pFrame
, szFormat
, argptr
);
218 // ----------------------------------------------------------------------------
219 // wxLogGui implementation (FIXME MT-unsafe)
220 // ----------------------------------------------------------------------------
229 void wxLogGui::Clear()
233 m_bHasMessages
= false;
240 void wxLogGui::Flush()
242 if ( !m_bHasMessages
)
245 // do it right now to block any new calls to Flush() while we're here
246 m_bHasMessages
= false;
248 unsigned repeatCount
= 0;
249 if ( wxLog::GetRepetitionCounting() )
251 repeatCount
= wxLog::DoLogNumberOfRepeats();
254 wxString appName
= wxTheApp
->GetAppName();
255 if ( !appName
.empty() )
256 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
259 wxString titleFormat
;
261 titleFormat
= _("%s Error");
264 else if ( m_bWarnings
) {
265 titleFormat
= _("%s Warning");
266 style
= wxICON_EXCLAMATION
;
269 titleFormat
= _("%s Information");
270 style
= wxICON_INFORMATION
;
274 title
.Printf(titleFormat
, appName
.c_str());
276 size_t nMsgCount
= m_aMessages
.Count();
278 // avoid showing other log dialogs until we're done with the dialog we're
279 // showing right now: nested modal dialogs make for really bad UI!
283 if ( nMsgCount
== 1 )
285 str
= m_aMessages
[0];
287 else // more than one message
291 if ( repeatCount
> 0 )
292 m_aMessages
[nMsgCount
-1] += wxString::Format(wxT(" (%s)"), m_aMessages
[nMsgCount
-2].c_str());
293 wxLogDialog
dlg(NULL
,
294 m_aMessages
, m_aSeverity
, m_aTimes
,
297 // clear the message list before showing the dialog because while it's
298 // shown some new messages may appear
301 (void)dlg
.ShowModal();
302 #else // !wxUSE_LOG_DIALOG
303 // concatenate all strings (but not too many to not overfill the msg box)
306 // start from the most recent message
307 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
308 // for Windows strings longer than this value are wrapped (NT 4.0)
309 const size_t nMsgLineWidth
= 156;
311 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
313 if ( nLines
> 25 ) // don't put too many lines in message box
316 str
<< m_aMessages
[n
- 1] << wxT("\n");
318 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
321 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
322 // situation without it
325 wxMessageBox(str
, title
, wxOK
| style
);
327 // no undisplayed messages whatsoever
331 // allow flushing the logs again
335 // log all kinds of messages
336 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
343 m_aMessages
.Add(szString
);
344 m_aSeverity
.Add(wxLOG_Message
);
345 m_aTimes
.Add((long)t
);
346 m_bHasMessages
= true;
353 // find the top window and set it's status text if it has any
354 wxFrame
*pFrame
= gs_pFrame
;
355 if ( pFrame
== NULL
) {
356 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
357 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
358 pFrame
= (wxFrame
*)pWin
;
362 if ( pFrame
&& pFrame
->GetStatusBar() )
363 pFrame
->SetStatusText(szString
);
365 #endif // wxUSE_STATUSBAR
376 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
377 // don't prepend debug/trace here: it goes to the
378 // debug window anyhow
380 OutputDebugString(str
);
382 // send them to stderr
383 wxFprintf(stderr
, wxT("[%s] %s\n"),
384 level
== wxLOG_Trace
? wxT("Trace")
390 #endif // __WXDEBUG__
394 case wxLOG_FatalError
:
395 // show this one immediately
396 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
402 #if !wxUSE_LOG_DIALOG
403 // discard earlier informational messages if this is the 1st
404 // error because they might not make sense any more and showing
405 // them in a message box might be confusing
409 #endif // wxUSE_LOG_DIALOG
416 // for the warning we don't discard the info messages
420 m_aMessages
.Add(szString
);
421 m_aSeverity
.Add((int)level
);
422 m_aTimes
.Add((long)t
);
423 m_bHasMessages
= true;
428 #endif // wxUSE_LOGGUI
430 // ----------------------------------------------------------------------------
431 // wxLogWindow and wxLogFrame implementation
432 // ----------------------------------------------------------------------------
438 class wxLogFrame
: public wxFrame
442 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
443 virtual ~wxLogFrame();
446 void OnClose(wxCommandEvent
& event
);
447 void OnCloseWindow(wxCloseEvent
& event
);
449 void OnSave (wxCommandEvent
& event
);
451 void OnClear(wxCommandEvent
& event
);
454 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
457 // use standard ids for our commands!
460 Menu_Close
= wxID_CLOSE
,
461 Menu_Save
= wxID_SAVE
,
462 Menu_Clear
= wxID_CLEAR
465 // common part of OnClose() and OnCloseWindow()
468 wxTextCtrl
*m_pTextCtrl
;
471 DECLARE_EVENT_TABLE()
472 DECLARE_NO_COPY_CLASS(wxLogFrame
)
475 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
476 // wxLogWindow menu events
477 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
479 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
481 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
483 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
486 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
487 : wxFrame(pParent
, wxID_ANY
, szTitle
)
491 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
495 // needed for Win32 to avoid 65Kb limit but it doesn't work well
496 // when using RichEdit 2.0 which we always do in the Unicode build
499 #endif // !wxUSE_UNICODE
504 wxMenuBar
*pMenuBar
= new wxMenuBar
;
505 wxMenu
*pMenu
= new wxMenu
;
507 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
509 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
510 pMenu
->AppendSeparator();
511 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
512 pMenuBar
->Append(pMenu
, _("&Log"));
513 SetMenuBar(pMenuBar
);
514 #endif // wxUSE_MENUS
517 // status bar for menu prompts
519 #endif // wxUSE_STATUSBAR
521 m_log
->OnFrameCreate(this);
524 void wxLogFrame::DoClose()
526 if ( m_log
->OnFrameClose(this) )
528 // instead of closing just hide the window to be able to Show() it
534 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
539 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
545 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
550 int rc
= OpenLogFile(file
, &filename
, this);
559 // retrieve text and save it
560 // -------------------------
561 int nLines
= m_pTextCtrl
->GetNumberOfLines();
562 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
563 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
564 wxTextFile::GetEOL());
571 wxLogError(_("Can't save log contents to file."));
574 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
580 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
582 m_pTextCtrl
->Clear();
585 wxLogFrame::~wxLogFrame()
587 m_log
->OnFrameDelete(this);
593 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
594 const wxChar
*szTitle
,
598 PassMessages(bDoPass
);
600 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
606 void wxLogWindow::Show(bool bShow
)
608 m_pLogFrame
->Show(bShow
);
611 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
613 // first let the previous logger show it
614 wxLogPassThrough::DoLog(level
, szString
, t
);
619 // by default, these messages are ignored by wxLog, so process
621 if ( !wxIsEmpty(szString
) )
624 str
<< _("Status: ") << szString
;
629 // don't put trace messages in the text window for 2 reasons:
630 // 1) there are too many of them
631 // 2) they may provoke other trace messages thus sending a program
632 // into an infinite loop
637 // and this will format it nicely and call our DoLogString()
638 wxLog::DoLog(level
, szString
, t
);
643 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
645 // put the text into our window
646 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
648 // remove selection (WriteText is in fact ReplaceSelection)
650 wxTextPos nLen
= pText
->GetLastPosition();
651 pText
->SetSelection(nLen
, nLen
);
656 msg
<< szString
<< wxT('\n');
658 pText
->AppendText(msg
);
660 // TODO ensure that the line can be seen
663 wxFrame
*wxLogWindow::GetFrame() const
668 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
672 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
678 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
680 m_pLogFrame
= (wxLogFrame
*)NULL
;
683 wxLogWindow::~wxLogWindow()
685 // may be NULL if log frame already auto destroyed itself
689 #endif // wxUSE_LOGWINDOW
691 // ----------------------------------------------------------------------------
693 // ----------------------------------------------------------------------------
697 #ifndef __SMARTPHONE__
698 static const size_t MARGIN
= 10;
700 static const size_t MARGIN
= 0;
703 wxString
wxLogDialog::ms_details
;
705 wxLogDialog::wxLogDialog(wxWindow
*parent
,
706 const wxArrayString
& messages
,
707 const wxArrayInt
& severity
,
708 const wxArrayLong
& times
,
709 const wxString
& caption
,
711 : wxDialog(parent
, wxID_ANY
, caption
,
712 wxDefaultPosition
, wxDefaultSize
,
713 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
715 if ( ms_details
.empty() )
717 // ensure that we won't loop here if wxGetTranslation()
718 // happens to pop up a Log message while translating this :-)
719 ms_details
= wxTRANSLATE("&Details");
720 ms_details
= wxGetTranslation(ms_details
);
721 #ifdef __SMARTPHONE__
722 ms_details
= wxStripMenuCodes(ms_details
);
726 size_t count
= messages
.GetCount();
727 m_messages
.Alloc(count
);
728 m_severity
.Alloc(count
);
729 m_times
.Alloc(count
);
731 for ( size_t n
= 0; n
< count
; n
++ )
733 wxString msg
= messages
[n
];
734 msg
.Replace(wxT("\n"), wxT(" "));
736 m_severity
.Add(severity
[n
]);
737 m_times
.Add(times
[n
]);
740 m_showingDetails
= false; // not initially
741 m_listctrl
= (wxListCtrl
*)NULL
;
743 #ifndef __SMARTPHONE__
746 m_statline
= (wxStaticLine
*)NULL
;
747 #endif // wxUSE_STATLINE
750 m_btnSave
= (wxButton
*)NULL
;
753 #endif // __SMARTPHONE__
755 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
757 // create the controls which are always shown and layout them: we use
758 // sizers even though our window is not resizeable to calculate the size of
759 // the dialog properly
760 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
761 #ifndef __SMARTPHONE__
762 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
764 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
766 #ifdef __SMARTPHONE__
767 SetLeftMenu(wxID_OK
);
768 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
770 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
771 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
772 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
773 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
777 switch ( style
& wxICON_MASK
)
780 bitmap
= wxArtProvider::GetBitmap(wxART_ERROR
, wxART_MESSAGE_BOX
);
782 bitmap
.SetId(wxICON_SMALL_ERROR
);
786 case wxICON_INFORMATION
:
787 bitmap
= wxArtProvider::GetBitmap(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
789 bitmap
.SetId(wxICON_SMALL_INFO
);
794 bitmap
= wxArtProvider::GetBitmap(wxART_WARNING
, wxART_MESSAGE_BOX
);
796 bitmap
.SetId(wxICON_SMALL_WARNING
);
801 wxFAIL_MSG(_T("incorrect log style"));
805 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
806 wxALIGN_CENTRE_VERTICAL
);
808 const wxString
& message
= messages
.Last();
809 sizerAll
->Add(CreateTextSizer(message
), 1,
810 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
811 #ifndef __SMARTPHONE__
812 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
815 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
819 // see comments in OnDetails()
821 // Note: Doing this, this way, triggered a nasty bug in
822 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
823 // either of maxWidth or maxHeight was set. This symptom has been
824 // fixed there, but it is a problem that remains as long as we allow
825 // unchecked access to the internal size members. We really need to
826 // encapuslate window sizes more cleanly and make it clear when -1 will
827 // be substituted and when it will not.
829 wxSize size
= sizerTop
->Fit(this);
830 m_maxHeight
= size
.y
;
831 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
833 #ifndef __SMARTPHONE__
841 // Move up the screen so that when we expand the dialog,
842 // there's enough space.
843 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
847 void wxLogDialog::CreateDetailsControls()
849 #ifndef __SMARTPHONE__
850 // create the save button and separator line if possible
852 m_btnSave
= new wxButton(this, wxID_SAVE
);
856 m_statline
= new wxStaticLine(this, wxID_ANY
);
857 #endif // wxUSE_STATLINE
859 #endif // __SMARTPHONE__
861 // create the list ctrl now
862 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
863 wxDefaultPosition
, wxDefaultSize
,
869 // This maks a big aesthetic difference on WinCE but I
870 // don't want to risk problems on other platforms
874 // no need to translate these strings as they're not shown to the
875 // user anyhow (we use wxLC_NO_HEADER style)
876 m_listctrl
->InsertColumn(0, _T("Message"));
877 m_listctrl
->InsertColumn(1, _T("Time"));
879 // prepare the imagelist
880 static const int ICON_SIZE
= 16;
881 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
883 // order should be the same as in the switch below!
884 static const wxChar
* icons
[] =
891 bool loadedIcons
= true;
893 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
895 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
896 wxSize(ICON_SIZE
, ICON_SIZE
));
898 // This may very well fail if there are insufficient colours available.
899 // Degrade gracefully.
910 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
913 wxString fmt
= wxLog::GetTimestamp();
920 size_t count
= m_messages
.GetCount();
921 for ( size_t n
= 0; n
< count
; n
++ )
927 switch ( m_severity
[n
] )
941 else // failed to load images
946 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
947 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
950 // let the columns size themselves
951 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
952 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
954 // calculate an approximately nice height for the listctrl
955 int height
= GetCharHeight()*(count
+ 4);
957 // but check that the dialog won't fall fown from the screen
959 // we use GetMinHeight() to get the height of the dialog part without the
960 // details and we consider that the "Save" button below and the separator
961 // line (and the margins around it) take about as much, hence double it
962 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
964 // we should leave a margin
968 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
971 void wxLogDialog::OnListSelect(wxListEvent
& event
)
973 // we can't just disable the control because this looks ugly under Windows
974 // (wrong bg colour, no scrolling...), but we still want to disable
975 // selecting items - it makes no sense here
976 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
979 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
986 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
990 int rc
= OpenLogFile(file
, NULL
, this);
999 wxString fmt
= wxLog::GetTimestamp();
1006 size_t count
= m_messages
.GetCount();
1007 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
1010 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
1013 << wxTextFile::GetEOL();
1015 ok
= file
.Write(line
);
1022 wxLogError(_("Can't save log contents to file."));
1023 #endif // wxUSE_FILEDLG
1026 #endif // wxUSE_FILE
1028 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1030 wxSizer
*sizer
= GetSizer();
1032 if ( m_showingDetails
)
1034 #ifdef __SMARTPHONE__
1035 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
1037 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1040 sizer
->Detach( m_listctrl
);
1042 #ifndef __SMARTPHONE__
1045 sizer
->Detach( m_statline
);
1046 #endif // wxUSE_STATLINE
1049 sizer
->Detach( m_btnSave
);
1050 #endif // wxUSE_FILE
1052 #endif // __SMARTPHONE__
1054 else // show details now
1056 #ifdef __SMARTPHONE__
1057 SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
);
1059 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1064 CreateDetailsControls();
1067 #if wxUSE_STATLINE && !defined(__SMARTPHONE__)
1068 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1070 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1071 #endif // wxUSE_STATLINE
1073 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1075 // VZ: this doesn't work as this becomes the initial (and not only
1076 // minimal) listctrl height as well - why?
1078 // allow the user to make the dialog shorter than its initial height -
1079 // without this it wouldn't work as the list ctrl would have been
1081 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1084 #if wxUSE_FILE && !defined(__SMARTPHONE__)
1085 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1086 #endif // wxUSE_FILE
1089 m_showingDetails
= !m_showingDetails
;
1091 // in any case, our size changed - relayout everything and set new hints
1092 // ---------------------------------------------------------------------
1094 // we have to reset min size constraints or Fit() would never reduce the
1095 // dialog size when collapsing it and we have to reset max constraint
1096 // because it wouldn't expand it otherwise
1101 // wxSizer::FitSize() is private, otherwise we might use it directly...
1102 wxSize sizeTotal
= GetSize(),
1103 sizeClient
= GetClientSize();
1105 wxSize size
= sizer
->GetMinSize();
1106 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1107 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1109 // we don't want to allow expanding the dialog in vertical direction as
1110 // this would show the "hidden" details but we can resize the dialog
1111 // vertically while the details are shown
1112 if ( !m_showingDetails
)
1113 m_maxHeight
= size
.y
;
1115 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1118 if (m_showingDetails
)
1122 // don't change the width when expanding/collapsing
1123 SetSize(wxDefaultCoord
, size
.y
);
1126 // VS: this is necessary in order to force frame redraw under
1127 // WindowMaker or fvwm2 (and probably other broken WMs).
1128 // Otherwise, detailed list wouldn't be displayed.
1133 wxLogDialog::~wxLogDialog()
1137 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1141 #endif // wxUSE_LOG_DIALOG
1143 #if wxUSE_FILE && wxUSE_FILEDLG
1145 // pass an uninitialized file object, the function will ask the user for the
1146 // filename and try to open it, returns true on success (file was opened),
1147 // false if file couldn't be opened/created and -1 if the file selection
1148 // dialog was cancelled
1149 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1151 // get the file name
1152 // -----------------
1153 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1161 bool bOk
wxDUMMY_INITIALIZE(false);
1162 if ( wxFile::Exists(filename
) ) {
1163 bool bAppend
= false;
1165 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1167 switch ( wxMessageBox(strMsg
, _("Question"),
1168 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1181 wxFAIL_MSG(_("invalid message box return value"));
1185 bOk
= file
.Open(filename
, wxFile::write_append
);
1188 bOk
= file
.Create(filename
, true /* overwrite */);
1192 bOk
= file
.Create(filename
);
1196 *pFilename
= filename
;
1201 #endif // wxUSE_FILE
1203 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1205 #if wxUSE_LOG && wxUSE_TEXTCTRL
1207 // ----------------------------------------------------------------------------
1208 // wxLogTextCtrl implementation
1209 // ----------------------------------------------------------------------------
1211 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1213 m_pTextCtrl
= pTextCtrl
;
1216 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1221 msg
<< szString
<< wxT('\n');
1222 m_pTextCtrl
->AppendText(msg
);
1225 #endif // wxUSE_LOG && wxUSE_TEXTCTRL