]>
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
)
85 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
87 // buffer is too small?
88 wxFAIL_MSG(_T("strftime() failed"));
94 class wxLogDialog
: public wxDialog
97 wxLogDialog(wxWindow
*parent
,
98 const wxArrayString
& messages
,
99 const wxArrayInt
& severity
,
100 const wxArrayLong
& timess
,
101 const wxString
& caption
,
103 virtual ~wxLogDialog();
106 void OnOk(wxCommandEvent
& event
);
107 void OnDetails(wxCommandEvent
& event
);
109 void OnSave(wxCommandEvent
& event
);
111 void OnListSelect(wxListEvent
& event
);
114 // create controls needed for the details display
115 void CreateDetailsControls();
117 // the data for the listctrl
118 wxArrayString m_messages
;
119 wxArrayInt m_severity
;
122 // the "toggle" button and its state
123 #ifndef __SMARTPHONE__
124 wxButton
*m_btnDetails
;
126 bool m_showingDetails
;
128 // the controls which are not shown initially (but only when details
129 // button is pressed)
130 wxListCtrl
*m_listctrl
;
131 #ifndef __SMARTPHONE__
133 wxStaticLine
*m_statline
;
134 #endif // wxUSE_STATLINE
138 #endif // __SMARTPHONE__
140 // the translated "Details" string
141 static wxString ms_details
;
143 DECLARE_EVENT_TABLE()
144 DECLARE_NO_COPY_CLASS(wxLogDialog
)
147 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
148 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
149 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
151 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
153 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
156 #endif // wxUSE_LOG_DIALOG
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 #if wxUSE_FILE && wxUSE_FILEDLG
164 // pass an uninitialized file object, the function will ask the user for the
165 // filename and try to open it, returns true on success (file was opened),
166 // false if file couldn't be opened/created and -1 if the file selection
167 // dialog was cancelled
168 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 // we use a global variable to store the frame pointer for wxLogStatus - bad,
177 // but it's the easiest way
178 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
180 // ============================================================================
182 // ============================================================================
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 // accepts an additional argument which tells to which frame the output should
190 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
194 wxLog
*pLog
= wxLog::GetActiveTarget();
195 if ( pLog
!= NULL
) {
196 msg
.PrintfV(szFormat
, argptr
);
198 wxASSERT( gs_pFrame
== NULL
); // should be reset!
201 wxLog::OnLog(wxLOG_Status
, msg
, 0);
203 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
205 gs_pFrame
= (wxFrame
*) NULL
;
209 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
212 va_start(argptr
, szFormat
);
213 wxVLogStatus(pFrame
, szFormat
, argptr
);
217 // ----------------------------------------------------------------------------
218 // wxLogGui implementation (FIXME MT-unsafe)
219 // ----------------------------------------------------------------------------
228 void wxLogGui::Clear()
232 m_bHasMessages
= false;
239 void wxLogGui::Flush()
241 if ( !m_bHasMessages
)
244 // do it right now to block any new calls to Flush() while we're here
245 m_bHasMessages
= false;
247 wxString appName
= wxTheApp
->GetAppName();
248 if ( !appName
.empty() )
249 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
252 wxString titleFormat
;
254 titleFormat
= _("%s Error");
257 else if ( m_bWarnings
) {
258 titleFormat
= _("%s Warning");
259 style
= wxICON_EXCLAMATION
;
262 titleFormat
= _("%s Information");
263 style
= wxICON_INFORMATION
;
267 title
.Printf(titleFormat
, appName
.c_str());
269 size_t nMsgCount
= m_aMessages
.Count();
271 // avoid showing other log dialogs until we're done with the dialog we're
272 // showing right now: nested modal dialogs make for really bad UI!
276 if ( nMsgCount
== 1 )
278 str
= m_aMessages
[0];
280 else // more than one message
284 wxLogDialog
dlg(NULL
,
285 m_aMessages
, m_aSeverity
, m_aTimes
,
288 // clear the message list before showing the dialog because while it's
289 // shown some new messages may appear
292 (void)dlg
.ShowModal();
293 #else // !wxUSE_LOG_DIALOG
294 // concatenate all strings (but not too many to not overfill the msg box)
297 // start from the most recent message
298 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
299 // for Windows strings longer than this value are wrapped (NT 4.0)
300 const size_t nMsgLineWidth
= 156;
302 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
304 if ( nLines
> 25 ) // don't put too many lines in message box
307 str
<< m_aMessages
[n
- 1] << wxT("\n");
309 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
312 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
313 // situation without it
316 wxMessageBox(str
, title
, wxOK
| style
);
318 // no undisplayed messages whatsoever
322 // allow flushing the logs again
326 // log all kinds of messages
327 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
334 m_aMessages
.Add(szString
);
335 m_aSeverity
.Add(wxLOG_Message
);
336 m_aTimes
.Add((long)t
);
337 m_bHasMessages
= true;
344 // find the top window and set it's status text if it has any
345 wxFrame
*pFrame
= gs_pFrame
;
346 if ( pFrame
== NULL
) {
347 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
348 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
349 pFrame
= (wxFrame
*)pWin
;
353 if ( pFrame
&& pFrame
->GetStatusBar() )
354 pFrame
->SetStatusText(szString
);
356 #endif // wxUSE_STATUSBAR
367 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
368 // don't prepend debug/trace here: it goes to the
369 // debug window anyhow
371 OutputDebugString(str
);
373 // send them to stderr
374 wxFprintf(stderr
, wxT("[%s] %s\n"),
375 level
== wxLOG_Trace
? wxT("Trace")
381 #endif // __WXDEBUG__
385 case wxLOG_FatalError
:
386 // show this one immediately
387 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
393 #if !wxUSE_LOG_DIALOG
394 // discard earlier informational messages if this is the 1st
395 // error because they might not make sense any more and showing
396 // them in a message box might be confusing
400 #endif // wxUSE_LOG_DIALOG
407 // for the warning we don't discard the info messages
411 m_aMessages
.Add(szString
);
412 m_aSeverity
.Add((int)level
);
413 m_aTimes
.Add((long)t
);
414 m_bHasMessages
= true;
419 #endif // wxUSE_LOGGUI
421 // ----------------------------------------------------------------------------
422 // wxLogWindow and wxLogFrame implementation
423 // ----------------------------------------------------------------------------
429 class wxLogFrame
: public wxFrame
433 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
434 virtual ~wxLogFrame();
437 void OnClose(wxCommandEvent
& event
);
438 void OnCloseWindow(wxCloseEvent
& event
);
440 void OnSave (wxCommandEvent
& event
);
442 void OnClear(wxCommandEvent
& event
);
445 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
448 // use standard ids for our commands!
451 Menu_Close
= wxID_CLOSE
,
452 Menu_Save
= wxID_SAVE
,
453 Menu_Clear
= wxID_CLEAR
456 // common part of OnClose() and OnCloseWindow()
459 wxTextCtrl
*m_pTextCtrl
;
462 DECLARE_EVENT_TABLE()
463 DECLARE_NO_COPY_CLASS(wxLogFrame
)
466 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
467 // wxLogWindow menu events
468 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
470 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
472 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
474 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
477 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
478 : wxFrame(pParent
, wxID_ANY
, szTitle
)
482 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
486 // needed for Win32 to avoid 65Kb limit but it doesn't work well
487 // when using RichEdit 2.0 which we always do in the Unicode build
490 #endif // !wxUSE_UNICODE
495 wxMenuBar
*pMenuBar
= new wxMenuBar
;
496 wxMenu
*pMenu
= new wxMenu
;
498 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
500 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
501 pMenu
->AppendSeparator();
502 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
503 pMenuBar
->Append(pMenu
, _("&Log"));
504 SetMenuBar(pMenuBar
);
505 #endif // wxUSE_MENUS
508 // status bar for menu prompts
510 #endif // wxUSE_STATUSBAR
512 m_log
->OnFrameCreate(this);
515 void wxLogFrame::DoClose()
517 if ( m_log
->OnFrameClose(this) )
519 // instead of closing just hide the window to be able to Show() it
525 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
530 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
536 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
541 int rc
= OpenLogFile(file
, &filename
, this);
550 // retrieve text and save it
551 // -------------------------
552 int nLines
= m_pTextCtrl
->GetNumberOfLines();
553 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
554 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
555 wxTextFile::GetEOL());
562 wxLogError(_("Can't save log contents to file."));
565 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
571 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
573 m_pTextCtrl
->Clear();
576 wxLogFrame::~wxLogFrame()
578 m_log
->OnFrameDelete(this);
584 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
585 const wxChar
*szTitle
,
589 PassMessages(bDoPass
);
591 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
597 void wxLogWindow::Show(bool bShow
)
599 m_pLogFrame
->Show(bShow
);
602 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
604 // first let the previous logger show it
605 wxLogPassThrough::DoLog(level
, szString
, t
);
610 // by default, these messages are ignored by wxLog, so process
612 if ( !wxIsEmpty(szString
) )
615 str
<< _("Status: ") << szString
;
620 // don't put trace messages in the text window for 2 reasons:
621 // 1) there are too many of them
622 // 2) they may provoke other trace messages thus sending a program
623 // into an infinite loop
628 // and this will format it nicely and call our DoLogString()
629 wxLog::DoLog(level
, szString
, t
);
634 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
636 // put the text into our window
637 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
639 // remove selection (WriteText is in fact ReplaceSelection)
641 wxTextPos nLen
= pText
->GetLastPosition();
642 pText
->SetSelection(nLen
, nLen
);
647 msg
<< szString
<< wxT('\n');
649 pText
->AppendText(msg
);
651 // TODO ensure that the line can be seen
654 wxFrame
*wxLogWindow::GetFrame() const
659 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
663 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
669 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
671 m_pLogFrame
= (wxLogFrame
*)NULL
;
674 wxLogWindow::~wxLogWindow()
676 // may be NULL if log frame already auto destroyed itself
680 #endif // wxUSE_LOGWINDOW
682 // ----------------------------------------------------------------------------
684 // ----------------------------------------------------------------------------
688 #ifndef __SMARTPHONE__
689 static const size_t MARGIN
= 10;
691 static const size_t MARGIN
= 0;
694 wxString
wxLogDialog::ms_details
;
696 wxLogDialog::wxLogDialog(wxWindow
*parent
,
697 const wxArrayString
& messages
,
698 const wxArrayInt
& severity
,
699 const wxArrayLong
& times
,
700 const wxString
& caption
,
702 : wxDialog(parent
, wxID_ANY
, caption
,
703 wxDefaultPosition
, wxDefaultSize
,
704 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
706 if ( ms_details
.empty() )
708 // ensure that we won't loop here if wxGetTranslation()
709 // happens to pop up a Log message while translating this :-)
710 ms_details
= wxTRANSLATE("&Details");
711 ms_details
= wxGetTranslation(ms_details
);
712 #ifdef __SMARTPHONE__
713 ms_details
= wxStripMenuCodes(ms_details
);
717 size_t count
= messages
.GetCount();
718 m_messages
.Alloc(count
);
719 m_severity
.Alloc(count
);
720 m_times
.Alloc(count
);
722 for ( size_t n
= 0; n
< count
; n
++ )
724 wxString msg
= messages
[n
];
725 msg
.Replace(wxT("\n"), wxT(" "));
727 m_severity
.Add(severity
[n
]);
728 m_times
.Add(times
[n
]);
731 m_showingDetails
= false; // not initially
732 m_listctrl
= (wxListCtrl
*)NULL
;
734 #ifndef __SMARTPHONE__
737 m_statline
= (wxStaticLine
*)NULL
;
738 #endif // wxUSE_STATLINE
741 m_btnSave
= (wxButton
*)NULL
;
744 #endif // __SMARTPHONE__
746 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
748 // create the controls which are always shown and layout them: we use
749 // sizers even though our window is not resizeable to calculate the size of
750 // the dialog properly
751 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
752 #ifndef __SMARTPHONE__
753 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
755 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
757 #ifdef __SMARTPHONE__
758 SetLeftMenu(wxID_OK
);
759 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
761 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
762 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
763 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
764 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
768 switch ( style
& wxICON_MASK
)
771 bitmap
= wxArtProvider::GetBitmap(wxART_ERROR
, wxART_MESSAGE_BOX
);
773 bitmap
.SetId(wxICON_SMALL_ERROR
);
777 case wxICON_INFORMATION
:
778 bitmap
= wxArtProvider::GetBitmap(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
780 bitmap
.SetId(wxICON_SMALL_INFO
);
785 bitmap
= wxArtProvider::GetBitmap(wxART_WARNING
, wxART_MESSAGE_BOX
);
787 bitmap
.SetId(wxICON_SMALL_WARNING
);
792 wxFAIL_MSG(_T("incorrect log style"));
796 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
797 wxALIGN_CENTRE_VERTICAL
);
799 const wxString
& message
= messages
.Last();
800 sizerAll
->Add(CreateTextSizer(message
), 1,
801 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
802 #ifndef __SMARTPHONE__
803 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
806 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
810 // see comments in OnDetails()
812 // Note: Doing this, this way, triggered a nasty bug in
813 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
814 // either of maxWidth or maxHeight was set. This symptom has been
815 // fixed there, but it is a problem that remains as long as we allow
816 // unchecked access to the internal size members. We really need to
817 // encapuslate window sizes more cleanly and make it clear when -1 will
818 // be substituted and when it will not.
820 wxSize size
= sizerTop
->Fit(this);
821 m_maxHeight
= size
.y
;
822 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
824 #ifndef __SMARTPHONE__
832 // Move up the screen so that when we expand the dialog,
833 // there's enough space.
834 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
838 void wxLogDialog::CreateDetailsControls()
840 #ifndef __SMARTPHONE__
841 // create the save button and separator line if possible
843 m_btnSave
= new wxButton(this, wxID_SAVE
);
847 m_statline
= new wxStaticLine(this, wxID_ANY
);
848 #endif // wxUSE_STATLINE
850 #endif // __SMARTPHONE__
852 // create the list ctrl now
853 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
854 wxDefaultPosition
, wxDefaultSize
,
860 // This maks a big aesthetic difference on WinCE but I
861 // don't want to risk problems on other platforms
865 // no need to translate these strings as they're not shown to the
866 // user anyhow (we use wxLC_NO_HEADER style)
867 m_listctrl
->InsertColumn(0, _T("Message"));
868 m_listctrl
->InsertColumn(1, _T("Time"));
870 // prepare the imagelist
871 static const int ICON_SIZE
= 16;
872 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
874 // order should be the same as in the switch below!
875 static const wxChar
* icons
[] =
882 bool loadedIcons
= true;
884 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
886 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
887 wxSize(ICON_SIZE
, ICON_SIZE
));
889 // This may very well fail if there are insufficient colours available.
890 // Degrade gracefully.
901 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
904 wxString fmt
= wxLog::GetTimestamp();
911 size_t count
= m_messages
.GetCount();
912 for ( size_t n
= 0; n
< count
; n
++ )
918 switch ( m_severity
[n
] )
932 else // failed to load images
937 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
938 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
941 // let the columns size themselves
942 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
943 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
945 // calculate an approximately nice height for the listctrl
946 int height
= GetCharHeight()*(count
+ 4);
948 // but check that the dialog won't fall fown from the screen
950 // we use GetMinHeight() to get the height of the dialog part without the
951 // details and we consider that the "Save" button below and the separator
952 // line (and the margins around it) take about as much, hence double it
953 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
955 // we should leave a margin
959 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
962 void wxLogDialog::OnListSelect(wxListEvent
& event
)
964 // we can't just disable the control because this looks ugly under Windows
965 // (wrong bg colour, no scrolling...), but we still want to disable
966 // selecting items - it makes no sense here
967 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
970 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
977 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
981 int rc
= OpenLogFile(file
, NULL
, this);
990 wxString fmt
= wxLog::GetTimestamp();
997 size_t count
= m_messages
.GetCount();
998 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
1001 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
1004 << wxTextFile::GetEOL();
1006 ok
= file
.Write(line
);
1013 wxLogError(_("Can't save log contents to file."));
1014 #endif // wxUSE_FILEDLG
1017 #endif // wxUSE_FILE
1019 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1021 wxSizer
*sizer
= GetSizer();
1023 if ( m_showingDetails
)
1025 #ifdef __SMARTPHONE__
1026 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
1028 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1031 sizer
->Detach( m_listctrl
);
1033 #ifndef __SMARTPHONE__
1036 sizer
->Detach( m_statline
);
1037 #endif // wxUSE_STATLINE
1040 sizer
->Detach( m_btnSave
);
1041 #endif // wxUSE_FILE
1043 #endif // __SMARTPHONE__
1045 else // show details now
1047 #ifdef __SMARTPHONE__
1048 SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
);
1050 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1055 CreateDetailsControls();
1058 #if wxUSE_STATLINE && !defined(__SMARTPHONE__)
1059 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1061 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1062 #endif // wxUSE_STATLINE
1064 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1066 // VZ: this doesn't work as this becomes the initial (and not only
1067 // minimal) listctrl height as well - why?
1069 // allow the user to make the dialog shorter than its initial height -
1070 // without this it wouldn't work as the list ctrl would have been
1072 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1075 #if wxUSE_FILE && !defined(__SMARTPHONE__)
1076 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1077 #endif // wxUSE_FILE
1080 m_showingDetails
= !m_showingDetails
;
1082 // in any case, our size changed - relayout everything and set new hints
1083 // ---------------------------------------------------------------------
1085 // we have to reset min size constraints or Fit() would never reduce the
1086 // dialog size when collapsing it and we have to reset max constraint
1087 // because it wouldn't expand it otherwise
1092 // wxSizer::FitSize() is private, otherwise we might use it directly...
1093 wxSize sizeTotal
= GetSize(),
1094 sizeClient
= GetClientSize();
1096 wxSize size
= sizer
->GetMinSize();
1097 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1098 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1100 // we don't want to allow expanding the dialog in vertical direction as
1101 // this would show the "hidden" details but we can resize the dialog
1102 // vertically while the details are shown
1103 if ( !m_showingDetails
)
1104 m_maxHeight
= size
.y
;
1106 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1109 if (m_showingDetails
)
1113 // don't change the width when expanding/collapsing
1114 SetSize(wxDefaultCoord
, size
.y
);
1117 // VS: this is necessary in order to force frame redraw under
1118 // WindowMaker or fvwm2 (and probably other broken WMs).
1119 // Otherwise, detailed list wouldn't be displayed.
1124 wxLogDialog::~wxLogDialog()
1128 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1132 #endif // wxUSE_LOG_DIALOG
1134 #if wxUSE_FILE && wxUSE_FILEDLG
1136 // pass an uninitialized file object, the function will ask the user for the
1137 // filename and try to open it, returns true on success (file was opened),
1138 // false if file couldn't be opened/created and -1 if the file selection
1139 // dialog was cancelled
1140 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1142 // get the file name
1143 // -----------------
1144 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1152 bool bOk
wxDUMMY_INITIALIZE(false);
1153 if ( wxFile::Exists(filename
) ) {
1154 bool bAppend
= false;
1156 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1158 switch ( wxMessageBox(strMsg
, _("Question"),
1159 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1172 wxFAIL_MSG(_("invalid message box return value"));
1176 bOk
= file
.Open(filename
, wxFile::write_append
);
1179 bOk
= file
.Create(filename
, true /* overwrite */);
1183 bOk
= file
.Create(filename
);
1187 *pFilename
= filename
;
1192 #endif // wxUSE_FILE
1194 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1196 #if wxUSE_LOG && wxUSE_TEXTCTRL
1198 // ----------------------------------------------------------------------------
1199 // wxLogTextCtrl implementation
1200 // ----------------------------------------------------------------------------
1202 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1204 m_pTextCtrl
= pTextCtrl
;
1207 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1212 msg
<< szString
<< wxT('\n');
1213 m_pTextCtrl
->AppendText(msg
);
1216 #endif // wxUSE_LOG && wxUSE_TEXTCTRL