]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/logg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/logg.cpp
3 // Purpose: wxLog-derived classes which need GUI support (the rest is in
5 // Author: Vadim Zeitlin
7 // Created: 20.09.99 (extracted from src/common/log.cpp)
9 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
22 #pragma implementation "logg.h"
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
34 #include "wx/button.h"
39 #include "wx/filedlg.h"
40 #include "wx/msgdlg.h"
41 #include "wx/textctrl.h"
43 #include "wx/statbmp.h"
44 #include "wx/button.h"
45 #include "wx/settings.h"
48 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW
51 #include "wx/textfile.h"
52 #include "wx/statline.h"
53 #include "wx/artprov.h"
56 // for OutputDebugString()
57 #include "wx/msw/private.h"
65 #include "wx/listctrl.h"
66 #include "wx/imaglist.h"
68 #else // !wxUSE_LOG_DIALOG
69 #include "wx/msgdlg.h"
70 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
72 #if defined(__MWERKS__) && wxUSE_UNICODE
76 #include "wx/datetime.h"
78 // the suffix we add to the button to show that the dialog can be expanded
79 #define EXPAND_SUFFIX _T(" >>")
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
87 // this function is a wrapper around strftime(3)
88 // allows to exclude the usage of wxDateTime
89 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
96 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
98 // buffer is too small?
99 wxFAIL_MSG(_T("strftime() failed"));
101 return wxString(buf
);
106 class wxLogDialog
: public wxDialog
109 wxLogDialog(wxWindow
*parent
,
110 const wxArrayString
& messages
,
111 const wxArrayInt
& severity
,
112 const wxArrayLong
& timess
,
113 const wxString
& caption
,
115 virtual ~wxLogDialog();
118 void OnOk(wxCommandEvent
& event
);
119 void OnDetails(wxCommandEvent
& event
);
121 void OnSave(wxCommandEvent
& event
);
123 void OnListSelect(wxListEvent
& event
);
126 // create controls needed for the details display
127 void CreateDetailsControls();
129 // the data for the listctrl
130 wxArrayString m_messages
;
131 wxArrayInt m_severity
;
134 // the "toggle" button and its state
135 #ifndef __SMARTPHONE__
136 wxButton
*m_btnDetails
;
138 bool m_showingDetails
;
140 // the controls which are not shown initially (but only when details
141 // button is pressed)
142 wxListCtrl
*m_listctrl
;
143 #ifndef __SMARTPHONE__
145 wxStaticLine
*m_statline
;
146 #endif // wxUSE_STATLINE
150 #endif // __SMARTPHONE__
152 // the translated "Details" string
153 static wxString ms_details
;
155 DECLARE_EVENT_TABLE()
156 DECLARE_NO_COPY_CLASS(wxLogDialog
)
159 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
160 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
161 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
163 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
165 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
168 #endif // wxUSE_LOG_DIALOG
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 #if wxUSE_FILE && wxUSE_FILEDLG
176 // pass an uninitialized file object, the function will ask the user for the
177 // filename and try to open it, returns true on success (file was opened),
178 // false if file couldn't be opened/created and -1 if the file selection
179 // dialog was cancelled
180 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 // we use a global variable to store the frame pointer for wxLogStatus - bad,
189 // but it's the easiest way
190 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
192 // ============================================================================
194 // ============================================================================
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 // accepts an additional argument which tells to which frame the output should
202 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
206 wxLog
*pLog
= wxLog::GetActiveTarget();
207 if ( pLog
!= NULL
) {
208 msg
.PrintfV(szFormat
, argptr
);
210 wxASSERT( gs_pFrame
== NULL
); // should be reset!
213 wxLog::OnLog(wxLOG_Status
, msg
, 0);
215 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
217 gs_pFrame
= (wxFrame
*) NULL
;
221 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
224 va_start(argptr
, szFormat
);
225 wxVLogStatus(pFrame
, szFormat
, argptr
);
229 // ----------------------------------------------------------------------------
230 // wxLogGui implementation (FIXME MT-unsafe)
231 // ----------------------------------------------------------------------------
240 void wxLogGui::Clear()
244 m_bHasMessages
= false;
251 void wxLogGui::Flush()
253 if ( !m_bHasMessages
)
256 // do it right now to block any new calls to Flush() while we're here
257 m_bHasMessages
= false;
259 wxString appName
= wxTheApp
->GetAppName();
260 if ( !appName
.empty() )
261 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
264 wxString titleFormat
;
266 titleFormat
= _("%s Error");
269 else if ( m_bWarnings
) {
270 titleFormat
= _("%s Warning");
271 style
= wxICON_EXCLAMATION
;
274 titleFormat
= _("%s Information");
275 style
= wxICON_INFORMATION
;
279 title
.Printf(titleFormat
, appName
.c_str());
281 size_t nMsgCount
= m_aMessages
.Count();
283 // avoid showing other log dialogs until we're done with the dialog we're
284 // showing right now: nested modal dialogs make for really bad UI!
288 if ( nMsgCount
== 1 )
290 str
= m_aMessages
[0];
292 else // more than one message
296 wxLogDialog
dlg(NULL
,
297 m_aMessages
, m_aSeverity
, m_aTimes
,
300 // clear the message list before showing the dialog because while it's
301 // shown some new messages may appear
304 (void)dlg
.ShowModal();
305 #else // !wxUSE_LOG_DIALOG
306 // concatenate all strings (but not too many to not overfill the msg box)
309 // start from the most recent message
310 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
311 // for Windows strings longer than this value are wrapped (NT 4.0)
312 const size_t nMsgLineWidth
= 156;
314 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
316 if ( nLines
> 25 ) // don't put too many lines in message box
319 str
<< m_aMessages
[n
- 1] << wxT("\n");
321 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
324 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
325 // situation without it
328 wxMessageBox(str
, title
, wxOK
| style
);
330 // no undisplayed messages whatsoever
334 // allow flushing the logs again
338 // log all kinds of messages
339 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
346 m_aMessages
.Add(szString
);
347 m_aSeverity
.Add(wxLOG_Message
);
348 m_aTimes
.Add((long)t
);
349 m_bHasMessages
= true;
356 // find the top window and set it's status text if it has any
357 wxFrame
*pFrame
= gs_pFrame
;
358 if ( pFrame
== NULL
) {
359 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
360 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
361 pFrame
= (wxFrame
*)pWin
;
365 if ( pFrame
&& pFrame
->GetStatusBar() )
366 pFrame
->SetStatusText(szString
);
368 #endif // wxUSE_STATUSBAR
379 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
380 // don't prepend debug/trace here: it goes to the
381 // debug window anyhow
383 OutputDebugString(str
);
385 // send them to stderr
386 wxFprintf(stderr
, wxT("[%s] %s\n"),
387 level
== wxLOG_Trace
? wxT("Trace")
393 #endif // __WXDEBUG__
397 case wxLOG_FatalError
:
398 // show this one immediately
399 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
405 #if !wxUSE_LOG_DIALOG
406 // discard earlier informational messages if this is the 1st
407 // error because they might not make sense any more and showing
408 // them in a message box might be confusing
412 #endif // wxUSE_LOG_DIALOG
419 // for the warning we don't discard the info messages
423 m_aMessages
.Add(szString
);
424 m_aSeverity
.Add((int)level
);
425 m_aTimes
.Add((long)t
);
426 m_bHasMessages
= true;
431 #endif // wxUSE_LOGGUI
433 // ----------------------------------------------------------------------------
434 // wxLogWindow and wxLogFrame implementation
435 // ----------------------------------------------------------------------------
439 class wxLogFrame
: public wxFrame
443 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
444 virtual ~wxLogFrame();
447 void OnClose(wxCommandEvent
& event
);
448 void OnCloseWindow(wxCloseEvent
& event
);
450 void OnSave (wxCommandEvent
& event
);
452 void OnClear(wxCommandEvent
& event
);
455 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
458 // use standard ids for our commands!
461 Menu_Close
= wxID_CLOSE
,
462 Menu_Save
= wxID_SAVE
,
463 Menu_Clear
= wxID_CLEAR
466 // common part of OnClose() and OnCloseWindow()
469 wxTextCtrl
*m_pTextCtrl
;
472 DECLARE_EVENT_TABLE()
473 DECLARE_NO_COPY_CLASS(wxLogFrame
)
476 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
477 // wxLogWindow menu events
478 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
480 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
482 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
484 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
487 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
488 : wxFrame(pParent
, wxID_ANY
, szTitle
)
492 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
496 // needed for Win32 to avoid 65Kb limit but it doesn't work well
497 // when using RichEdit 2.0 which we always do in the Unicode build
500 #endif // !wxUSE_UNICODE
505 wxMenuBar
*pMenuBar
= new wxMenuBar
;
506 wxMenu
*pMenu
= new wxMenu
;
508 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
510 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
511 pMenu
->AppendSeparator();
512 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
513 pMenuBar
->Append(pMenu
, _("&Log"));
514 SetMenuBar(pMenuBar
);
515 #endif // wxUSE_MENUS
518 // status bar for menu prompts
520 #endif // wxUSE_STATUSBAR
522 m_log
->OnFrameCreate(this);
525 void wxLogFrame::DoClose()
527 if ( m_log
->OnFrameClose(this) )
529 // instead of closing just hide the window to be able to Show() it
535 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
540 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
546 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
551 int rc
= OpenLogFile(file
, &filename
, this);
560 // retrieve text and save it
561 // -------------------------
562 int nLines
= m_pTextCtrl
->GetNumberOfLines();
563 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
564 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
565 wxTextFile::GetEOL());
572 wxLogError(_("Can't save log contents to file."));
575 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
581 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
583 m_pTextCtrl
->Clear();
586 wxLogFrame::~wxLogFrame()
588 m_log
->OnFrameDelete(this);
594 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
595 const wxChar
*szTitle
,
599 PassMessages(bDoPass
);
601 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
607 void wxLogWindow::Show(bool bShow
)
609 m_pLogFrame
->Show(bShow
);
612 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
614 // first let the previous logger show it
615 wxLogPassThrough::DoLog(level
, szString
, t
);
620 // by default, these messages are ignored by wxLog, so process
622 if ( !wxIsEmpty(szString
) )
625 str
<< _("Status: ") << szString
;
630 // don't put trace messages in the text window for 2 reasons:
631 // 1) there are too many of them
632 // 2) they may provoke other trace messages thus sending a program
633 // into an infinite loop
638 // and this will format it nicely and call our DoLogString()
639 wxLog::DoLog(level
, szString
, t
);
644 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
646 // put the text into our window
647 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
649 // remove selection (WriteText is in fact ReplaceSelection)
651 wxTextPos nLen
= pText
->GetLastPosition();
652 pText
->SetSelection(nLen
, nLen
);
657 msg
<< szString
<< wxT('\n');
659 pText
->AppendText(msg
);
661 // TODO ensure that the line can be seen
664 wxFrame
*wxLogWindow::GetFrame() const
669 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
673 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
679 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
681 m_pLogFrame
= (wxLogFrame
*)NULL
;
684 wxLogWindow::~wxLogWindow()
686 // may be NULL if log frame already auto destroyed itself
690 // ----------------------------------------------------------------------------
692 // ----------------------------------------------------------------------------
696 #ifndef __SMARTPHONE__
697 static const size_t MARGIN
= 10;
699 static const size_t MARGIN
= 0;
702 wxString
wxLogDialog::ms_details
;
704 wxLogDialog::wxLogDialog(wxWindow
*parent
,
705 const wxArrayString
& messages
,
706 const wxArrayInt
& severity
,
707 const wxArrayLong
& times
,
708 const wxString
& caption
,
710 : wxDialog(parent
, wxID_ANY
, caption
,
711 wxDefaultPosition
, wxDefaultSize
,
712 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
714 if ( ms_details
.empty() )
716 // ensure that we won't loop here if wxGetTranslation()
717 // happens to pop up a Log message while translating this :-)
718 ms_details
= wxTRANSLATE("&Details");
719 ms_details
= wxGetTranslation(ms_details
);
720 #ifdef __SMARTPHONE__
721 ms_details
= wxStripMenuCodes(ms_details
);
725 size_t count
= messages
.GetCount();
726 m_messages
.Alloc(count
);
727 m_severity
.Alloc(count
);
728 m_times
.Alloc(count
);
730 for ( size_t n
= 0; n
< count
; n
++ )
732 wxString msg
= messages
[n
];
733 msg
.Replace(wxT("\n"), wxT(" "));
735 m_severity
.Add(severity
[n
]);
736 m_times
.Add(times
[n
]);
739 m_showingDetails
= false; // not initially
740 m_listctrl
= (wxListCtrl
*)NULL
;
742 #ifndef __SMARTPHONE__
745 m_statline
= (wxStaticLine
*)NULL
;
746 #endif // wxUSE_STATLINE
749 m_btnSave
= (wxButton
*)NULL
;
752 #endif // __SMARTPHONE__
754 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
756 // create the controls which are always shown and layout them: we use
757 // sizers even though our window is not resizeable to calculate the size of
758 // the dialog properly
759 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
760 #ifndef __SMARTPHONE__
761 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
763 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
765 #ifdef __SMARTPHONE__
766 SetLeftMenu(wxID_OK
);
767 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
769 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
770 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
771 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
772 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
776 switch ( style
& wxICON_MASK
)
779 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
781 bitmap
.SetId(wxICON_SMALL_ERROR
);
785 case wxICON_INFORMATION
:
786 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
788 bitmap
.SetId(wxICON_SMALL_INFO
);
793 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
795 bitmap
.SetId(wxICON_SMALL_WARNING
);
800 wxFAIL_MSG(_T("incorrect log style"));
804 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
805 wxALIGN_CENTRE_VERTICAL
);
807 const wxString
& message
= messages
.Last();
808 sizerAll
->Add(CreateTextSizer(message
), 1,
809 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
810 #ifndef __SMARTPHONE__
811 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
814 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
818 // see comments in OnDetails()
820 // Note: Doing this, this way, triggered a nasty bug in
821 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
822 // either of maxWidth or maxHeight was set. This symptom has been
823 // fixed there, but it is a problem that remains as long as we allow
824 // unchecked access to the internal size members. We really need to
825 // encapuslate window sizes more cleanly and make it clear when -1 will
826 // be substituted and when it will not.
828 wxSize size
= sizerTop
->Fit(this);
829 m_maxHeight
= size
.y
;
830 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
832 #ifndef __SMARTPHONE__
840 // Move up the screen so that when we expand the dialog,
841 // there's enough space.
842 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
846 void wxLogDialog::CreateDetailsControls()
848 #ifndef __SMARTPHONE__
849 // create the save button and separator line if possible
851 m_btnSave
= new wxButton(this, wxID_SAVE
);
855 m_statline
= new wxStaticLine(this, wxID_ANY
);
856 #endif // wxUSE_STATLINE
858 #endif // __SMARTPHONE__
860 // create the list ctrl now
861 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
862 wxDefaultPosition
, wxDefaultSize
,
868 // This maks a big aesthetic difference on WinCE but I
869 // don't want to risk problems on other platforms
873 // no need to translate these strings as they're not shown to the
874 // user anyhow (we use wxLC_NO_HEADER style)
875 m_listctrl
->InsertColumn(0, _T("Message"));
876 m_listctrl
->InsertColumn(1, _T("Time"));
878 // prepare the imagelist
879 static const int ICON_SIZE
= 16;
880 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
882 // order should be the same as in the switch below!
883 static const wxChar
* icons
[] =
890 bool loadedIcons
= true;
892 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
894 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
895 wxSize(ICON_SIZE
, ICON_SIZE
));
897 // This may very well fail if there are insufficient colours available.
898 // Degrade gracefully.
909 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
912 wxString fmt
= wxLog::GetTimestamp();
916 fmt
= wxDefaultDateTimeFormat
;
919 size_t count
= m_messages
.GetCount();
920 for ( size_t n
= 0; n
< count
; n
++ )
926 switch ( m_severity
[n
] )
940 else // failed to load images
945 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
946 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
949 // let the columns size themselves
950 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
951 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
953 // calculate an approximately nice height for the listctrl
954 int height
= GetCharHeight()*(count
+ 4);
956 // but check that the dialog won't fall fown from the screen
958 // we use GetMinHeight() to get the height of the dialog part without the
959 // details and we consider that the "Save" button below and the separator
960 // line (and the margins around it) take about as much, hence double it
961 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
963 // we should leave a margin
967 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
970 void wxLogDialog::OnListSelect(wxListEvent
& event
)
972 // we can't just disable the control because this looks ugly under Windows
973 // (wrong bg colour, no scrolling...), but we still want to disable
974 // selecting items - it makes no sense here
975 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
978 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
985 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
989 int rc
= OpenLogFile(file
, NULL
, this);
998 wxString fmt
= wxLog::GetTimestamp();
1002 fmt
= wxDefaultDateTimeFormat
;
1005 size_t count
= m_messages
.GetCount();
1006 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
1009 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
1012 << wxTextFile::GetEOL();
1014 ok
= file
.Write(line
);
1021 wxLogError(_("Can't save log contents to file."));
1022 #endif // wxUSE_FILEDLG
1025 #endif // wxUSE_FILE
1027 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1029 wxSizer
*sizer
= GetSizer();
1031 if ( m_showingDetails
)
1033 #ifdef __SMARTPHONE__
1034 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
1036 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1039 sizer
->Detach( m_listctrl
);
1041 #ifndef __SMARTPHONE__
1044 sizer
->Detach( m_statline
);
1045 #endif // wxUSE_STATLINE
1048 sizer
->Detach( m_btnSave
);
1049 #endif // wxUSE_FILE
1051 #endif // __SMARTPHONE__
1053 else // show details now
1055 #ifdef __SMARTPHONE__
1056 SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
);
1058 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1063 CreateDetailsControls();
1066 #if wxUSE_STATLINE && !defined(__SMARTPHONE__)
1067 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1069 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1070 #endif // wxUSE_STATLINE
1072 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1074 // VZ: this doesn't work as this becomes the initial (and not only
1075 // minimal) listctrl height as well - why?
1077 // allow the user to make the dialog shorter than its initial height -
1078 // without this it wouldn't work as the list ctrl would have been
1080 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1083 #if wxUSE_FILE && !defined(__SMARTPHONE__)
1084 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1085 #endif // wxUSE_FILE
1088 m_showingDetails
= !m_showingDetails
;
1090 // in any case, our size changed - relayout everything and set new hints
1091 // ---------------------------------------------------------------------
1093 // we have to reset min size constraints or Fit() would never reduce the
1094 // dialog size when collapsing it and we have to reset max constraint
1095 // because it wouldn't expand it otherwise
1100 // wxSizer::FitSize() is private, otherwise we might use it directly...
1101 wxSize sizeTotal
= GetSize(),
1102 sizeClient
= GetClientSize();
1104 wxSize size
= sizer
->GetMinSize();
1105 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1106 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1108 // we don't want to allow expanding the dialog in vertical direction as
1109 // this would show the "hidden" details but we can resize the dialog
1110 // vertically while the details are shown
1111 if ( !m_showingDetails
)
1112 m_maxHeight
= size
.y
;
1114 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1117 if (m_showingDetails
)
1121 // don't change the width when expanding/collapsing
1122 SetSize(wxDefaultCoord
, size
.y
);
1125 // VS: this is neccessary in order to force frame redraw under
1126 // WindowMaker or fvwm2 (and probably other broken WMs).
1127 // Otherwise, detailed list wouldn't be displayed.
1132 wxLogDialog::~wxLogDialog()
1136 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1140 #endif // wxUSE_LOG_DIALOG
1142 #if wxUSE_FILE && wxUSE_FILEDLG
1144 // pass an uninitialized file object, the function will ask the user for the
1145 // filename and try to open it, returns true on success (file was opened),
1146 // false if file couldn't be opened/created and -1 if the file selection
1147 // dialog was cancelled
1148 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1150 // get the file name
1151 // -----------------
1152 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1160 bool bOk
wxDUMMY_INITIALIZE(false);
1161 if ( wxFile::Exists(filename
) ) {
1162 bool bAppend
= false;
1164 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1166 switch ( wxMessageBox(strMsg
, _("Question"),
1167 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1180 wxFAIL_MSG(_("invalid message box return value"));
1184 bOk
= file
.Open(filename
, wxFile::write_append
);
1187 bOk
= file
.Create(filename
, true /* overwrite */);
1191 bOk
= file
.Create(filename
);
1195 *pFilename
= filename
;
1200 #endif // wxUSE_FILE
1202 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1204 #if wxUSE_LOG && wxUSE_TEXTCTRL
1206 // ----------------------------------------------------------------------------
1207 // wxLogTextCtrl implementation
1208 // ----------------------------------------------------------------------------
1210 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1212 m_pTextCtrl
= pTextCtrl
;
1215 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1220 msg
<< szString
<< wxT('\n');
1221 m_pTextCtrl
->AppendText(msg
);
1224 #endif // wxUSE_LOG && wxUSE_TEXTCTRL