]>
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
)
87 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, wxLocaltime_r(&t
, &tm
)) )
89 // buffer is too small?
90 wxFAIL_MSG(_T("strftime() failed"));
93 #else // !wxUSE_DATETIME
95 #endif // wxUSE_DATETIME/!wxUSE_DATETIME
99 class wxLogDialog
: public wxDialog
102 wxLogDialog(wxWindow
*parent
,
103 const wxArrayString
& messages
,
104 const wxArrayInt
& severity
,
105 const wxArrayLong
& timess
,
106 const wxString
& caption
,
108 virtual ~wxLogDialog();
111 void OnOk(wxCommandEvent
& event
);
112 void OnDetails(wxCommandEvent
& event
);
114 void OnSave(wxCommandEvent
& event
);
116 void OnListSelect(wxListEvent
& event
);
119 // create controls needed for the details display
120 void CreateDetailsControls();
122 // the data for the listctrl
123 wxArrayString m_messages
;
124 wxArrayInt m_severity
;
127 // the "toggle" button and its state
128 #ifndef __SMARTPHONE__
129 wxButton
*m_btnDetails
;
131 bool m_showingDetails
;
133 // the controls which are not shown initially (but only when details
134 // button is pressed)
135 wxListCtrl
*m_listctrl
;
136 #ifndef __SMARTPHONE__
138 wxStaticLine
*m_statline
;
139 #endif // wxUSE_STATLINE
143 #endif // __SMARTPHONE__
145 // the translated "Details" string
146 static wxString ms_details
;
148 DECLARE_EVENT_TABLE()
149 DECLARE_NO_COPY_CLASS(wxLogDialog
)
152 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
153 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
154 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
156 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
158 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
161 #endif // wxUSE_LOG_DIALOG
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 #if wxUSE_FILE && wxUSE_FILEDLG
169 // pass an uninitialized file object, the function will ask the user for the
170 // filename and try to open it, returns true on success (file was opened),
171 // false if file couldn't be opened/created and -1 if the file selection
172 // dialog was cancelled
173 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 // we use a global variable to store the frame pointer for wxLogStatus - bad,
182 // but it's the easiest way
183 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
185 // ============================================================================
187 // ============================================================================
189 // ----------------------------------------------------------------------------
191 // ----------------------------------------------------------------------------
193 // accepts an additional argument which tells to which frame the output should
195 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
199 wxLog
*pLog
= wxLog::GetActiveTarget();
200 if ( pLog
!= NULL
) {
201 msg
.PrintfV(szFormat
, argptr
);
203 wxASSERT( gs_pFrame
== NULL
); // should be reset!
206 wxLog::OnLog(wxLOG_Status
, msg
, 0);
208 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
210 gs_pFrame
= (wxFrame
*) NULL
;
214 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
217 va_start(argptr
, szFormat
);
218 wxVLogStatus(pFrame
, szFormat
, argptr
);
222 // ----------------------------------------------------------------------------
223 // wxLogGui implementation (FIXME MT-unsafe)
224 // ----------------------------------------------------------------------------
233 void wxLogGui::Clear()
237 m_bHasMessages
= false;
244 void wxLogGui::Flush()
246 if ( !m_bHasMessages
)
249 // do it right now to block any new calls to Flush() while we're here
250 m_bHasMessages
= false;
252 unsigned repeatCount
= 0;
253 if ( wxLog::GetRepetitionCounting() )
255 repeatCount
= wxLog::DoLogNumberOfRepeats();
258 wxString appName
= wxTheApp
->GetAppName();
259 if ( !appName
.empty() )
260 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
263 wxString titleFormat
;
265 titleFormat
= _("%s Error");
268 else if ( m_bWarnings
) {
269 titleFormat
= _("%s Warning");
270 style
= wxICON_EXCLAMATION
;
273 titleFormat
= _("%s Information");
274 style
= wxICON_INFORMATION
;
278 title
.Printf(titleFormat
, appName
.c_str());
280 size_t nMsgCount
= m_aMessages
.Count();
282 // avoid showing other log dialogs until we're done with the dialog we're
283 // showing right now: nested modal dialogs make for really bad UI!
287 if ( nMsgCount
== 1 )
289 str
= m_aMessages
[0];
291 else // more than one message
295 if ( repeatCount
> 0 )
296 m_aMessages
[nMsgCount
-1] += wxString::Format(wxT(" (%s)"), m_aMessages
[nMsgCount
-2].c_str());
297 wxLogDialog
dlg(NULL
,
298 m_aMessages
, m_aSeverity
, m_aTimes
,
301 // clear the message list before showing the dialog because while it's
302 // shown some new messages may appear
305 (void)dlg
.ShowModal();
306 #else // !wxUSE_LOG_DIALOG
307 // concatenate all strings (but not too many to not overfill the msg box)
310 // start from the most recent message
311 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
312 // for Windows strings longer than this value are wrapped (NT 4.0)
313 const size_t nMsgLineWidth
= 156;
315 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
317 if ( nLines
> 25 ) // don't put too many lines in message box
320 str
<< m_aMessages
[n
- 1] << wxT("\n");
322 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
325 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
326 // situation without it
329 wxMessageBox(str
, title
, wxOK
| style
);
331 // no undisplayed messages whatsoever
335 // allow flushing the logs again
339 // log all kinds of messages
340 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
347 m_aMessages
.Add(szString
);
348 m_aSeverity
.Add(wxLOG_Message
);
349 m_aTimes
.Add((long)t
);
350 m_bHasMessages
= true;
357 // find the top window and set it's status text if it has any
358 wxFrame
*pFrame
= gs_pFrame
;
359 if ( pFrame
== NULL
) {
360 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
361 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
362 pFrame
= (wxFrame
*)pWin
;
366 if ( pFrame
&& pFrame
->GetStatusBar() )
367 pFrame
->SetStatusText(szString
);
369 #endif // wxUSE_STATUSBAR
380 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
381 // don't prepend debug/trace here: it goes to the
382 // debug window anyhow
384 OutputDebugString(str
);
386 // send them to stderr
387 wxFprintf(stderr
, wxT("[%s] %s\n"),
388 level
== wxLOG_Trace
? wxT("Trace")
394 #endif // __WXDEBUG__
398 case wxLOG_FatalError
:
399 // show this one immediately
400 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
406 #if !wxUSE_LOG_DIALOG
407 // discard earlier informational messages if this is the 1st
408 // error because they might not make sense any more and showing
409 // them in a message box might be confusing
413 #endif // wxUSE_LOG_DIALOG
420 // for the warning we don't discard the info messages
424 m_aMessages
.Add(szString
);
425 m_aSeverity
.Add((int)level
);
426 m_aTimes
.Add((long)t
);
427 m_bHasMessages
= true;
432 #endif // wxUSE_LOGGUI
434 // ----------------------------------------------------------------------------
435 // wxLogWindow and wxLogFrame implementation
436 // ----------------------------------------------------------------------------
442 class wxLogFrame
: public wxFrame
446 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
447 virtual ~wxLogFrame();
450 void OnClose(wxCommandEvent
& event
);
451 void OnCloseWindow(wxCloseEvent
& event
);
453 void OnSave (wxCommandEvent
& event
);
455 void OnClear(wxCommandEvent
& event
);
458 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
461 // use standard ids for our commands!
464 Menu_Close
= wxID_CLOSE
,
465 Menu_Save
= wxID_SAVE
,
466 Menu_Clear
= wxID_CLEAR
469 // common part of OnClose() and OnCloseWindow()
472 wxTextCtrl
*m_pTextCtrl
;
475 DECLARE_EVENT_TABLE()
476 DECLARE_NO_COPY_CLASS(wxLogFrame
)
479 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
480 // wxLogWindow menu events
481 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
483 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
485 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
487 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
490 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
491 : wxFrame(pParent
, wxID_ANY
, szTitle
)
495 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
499 // needed for Win32 to avoid 65Kb limit but it doesn't work well
500 // when using RichEdit 2.0 which we always do in the Unicode build
503 #endif // !wxUSE_UNICODE
508 wxMenuBar
*pMenuBar
= new wxMenuBar
;
509 wxMenu
*pMenu
= new wxMenu
;
511 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
513 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
514 pMenu
->AppendSeparator();
515 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
516 pMenuBar
->Append(pMenu
, _("&Log"));
517 SetMenuBar(pMenuBar
);
518 #endif // wxUSE_MENUS
521 // status bar for menu prompts
523 #endif // wxUSE_STATUSBAR
525 m_log
->OnFrameCreate(this);
528 void wxLogFrame::DoClose()
530 if ( m_log
->OnFrameClose(this) )
532 // instead of closing just hide the window to be able to Show() it
538 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
543 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
549 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
554 int rc
= OpenLogFile(file
, &filename
, this);
563 // retrieve text and save it
564 // -------------------------
565 int nLines
= m_pTextCtrl
->GetNumberOfLines();
566 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
567 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
568 wxTextFile::GetEOL());
575 wxLogError(_("Can't save log contents to file."));
578 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
584 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
586 m_pTextCtrl
->Clear();
589 wxLogFrame::~wxLogFrame()
591 m_log
->OnFrameDelete(this);
597 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
598 const wxChar
*szTitle
,
602 PassMessages(bDoPass
);
604 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
610 void wxLogWindow::Show(bool bShow
)
612 m_pLogFrame
->Show(bShow
);
615 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
617 // first let the previous logger show it
618 wxLogPassThrough::DoLog(level
, szString
, t
);
623 // by default, these messages are ignored by wxLog, so process
625 if ( !wxIsEmpty(szString
) )
628 str
<< _("Status: ") << szString
;
633 // don't put trace messages in the text window for 2 reasons:
634 // 1) there are too many of them
635 // 2) they may provoke other trace messages thus sending a program
636 // into an infinite loop
641 // and this will format it nicely and call our DoLogString()
642 wxLog::DoLog(level
, szString
, t
);
647 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
649 // put the text into our window
650 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
652 // remove selection (WriteText is in fact ReplaceSelection)
654 wxTextPos nLen
= pText
->GetLastPosition();
655 pText
->SetSelection(nLen
, nLen
);
660 msg
<< szString
<< wxT('\n');
662 pText
->AppendText(msg
);
664 // TODO ensure that the line can be seen
667 wxFrame
*wxLogWindow::GetFrame() const
672 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
676 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
682 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
684 m_pLogFrame
= (wxLogFrame
*)NULL
;
687 wxLogWindow::~wxLogWindow()
689 // may be NULL if log frame already auto destroyed itself
693 #endif // wxUSE_LOGWINDOW
695 // ----------------------------------------------------------------------------
697 // ----------------------------------------------------------------------------
701 #ifndef __SMARTPHONE__
702 static const size_t MARGIN
= 10;
704 static const size_t MARGIN
= 0;
707 wxString
wxLogDialog::ms_details
;
709 wxLogDialog::wxLogDialog(wxWindow
*parent
,
710 const wxArrayString
& messages
,
711 const wxArrayInt
& severity
,
712 const wxArrayLong
& times
,
713 const wxString
& caption
,
715 : wxDialog(parent
, wxID_ANY
, caption
,
716 wxDefaultPosition
, wxDefaultSize
,
717 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
719 if ( ms_details
.empty() )
721 // ensure that we won't loop here if wxGetTranslation()
722 // happens to pop up a Log message while translating this :-)
723 ms_details
= wxTRANSLATE("&Details");
724 ms_details
= wxGetTranslation(ms_details
);
725 #ifdef __SMARTPHONE__
726 ms_details
= wxStripMenuCodes(ms_details
);
730 size_t count
= messages
.GetCount();
731 m_messages
.Alloc(count
);
732 m_severity
.Alloc(count
);
733 m_times
.Alloc(count
);
735 for ( size_t n
= 0; n
< count
; n
++ )
737 wxString msg
= messages
[n
];
738 msg
.Replace(wxT("\n"), wxT(" "));
740 m_severity
.Add(severity
[n
]);
741 m_times
.Add(times
[n
]);
744 m_showingDetails
= false; // not initially
745 m_listctrl
= (wxListCtrl
*)NULL
;
747 #ifndef __SMARTPHONE__
750 m_statline
= (wxStaticLine
*)NULL
;
751 #endif // wxUSE_STATLINE
754 m_btnSave
= (wxButton
*)NULL
;
757 #endif // __SMARTPHONE__
759 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
761 // create the controls which are always shown and layout them: we use
762 // sizers even though our window is not resizeable to calculate the size of
763 // the dialog properly
764 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
765 #ifndef __SMARTPHONE__
766 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
768 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
770 #ifdef __SMARTPHONE__
771 SetLeftMenu(wxID_OK
);
772 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
774 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
775 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
776 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
777 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
781 switch ( style
& wxICON_MASK
)
784 bitmap
= wxArtProvider::GetBitmap(wxART_ERROR
, wxART_MESSAGE_BOX
);
786 bitmap
.SetId(wxICON_SMALL_ERROR
);
790 case wxICON_INFORMATION
:
791 bitmap
= wxArtProvider::GetBitmap(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
793 bitmap
.SetId(wxICON_SMALL_INFO
);
798 bitmap
= wxArtProvider::GetBitmap(wxART_WARNING
, wxART_MESSAGE_BOX
);
800 bitmap
.SetId(wxICON_SMALL_WARNING
);
805 wxFAIL_MSG(_T("incorrect log style"));
809 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
810 wxALIGN_CENTRE_VERTICAL
);
812 const wxString
& message
= messages
.Last();
813 sizerAll
->Add(CreateTextSizer(message
), 1,
814 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
815 #ifndef __SMARTPHONE__
816 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
819 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
823 // see comments in OnDetails()
825 // Note: Doing this, this way, triggered a nasty bug in
826 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
827 // either of maxWidth or maxHeight was set. This symptom has been
828 // fixed there, but it is a problem that remains as long as we allow
829 // unchecked access to the internal size members. We really need to
830 // encapuslate window sizes more cleanly and make it clear when -1 will
831 // be substituted and when it will not.
833 wxSize size
= sizerTop
->Fit(this);
834 m_maxHeight
= size
.y
;
835 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
837 #ifndef __SMARTPHONE__
845 // Move up the screen so that when we expand the dialog,
846 // there's enough space.
847 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
851 void wxLogDialog::CreateDetailsControls()
853 #ifndef __SMARTPHONE__
854 // create the save button and separator line if possible
856 m_btnSave
= new wxButton(this, wxID_SAVE
);
860 m_statline
= new wxStaticLine(this, wxID_ANY
);
861 #endif // wxUSE_STATLINE
863 #endif // __SMARTPHONE__
865 // create the list ctrl now
866 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
867 wxDefaultPosition
, wxDefaultSize
,
873 // This maks a big aesthetic difference on WinCE but I
874 // don't want to risk problems on other platforms
878 // no need to translate these strings as they're not shown to the
879 // user anyhow (we use wxLC_NO_HEADER style)
880 m_listctrl
->InsertColumn(0, _T("Message"));
881 m_listctrl
->InsertColumn(1, _T("Time"));
883 // prepare the imagelist
884 static const int ICON_SIZE
= 16;
885 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
887 // order should be the same as in the switch below!
888 static const wxChar
* icons
[] =
895 bool loadedIcons
= true;
897 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
899 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
900 wxSize(ICON_SIZE
, ICON_SIZE
));
902 // This may very well fail if there are insufficient colours available.
903 // Degrade gracefully.
914 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
917 wxString fmt
= wxLog::GetTimestamp();
924 size_t count
= m_messages
.GetCount();
925 for ( size_t n
= 0; n
< count
; n
++ )
931 switch ( m_severity
[n
] )
945 else // failed to load images
950 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
951 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
954 // let the columns size themselves
955 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
956 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
958 // calculate an approximately nice height for the listctrl
959 int height
= GetCharHeight()*(count
+ 4);
961 // but check that the dialog won't fall fown from the screen
963 // we use GetMinHeight() to get the height of the dialog part without the
964 // details and we consider that the "Save" button below and the separator
965 // line (and the margins around it) take about as much, hence double it
966 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
968 // we should leave a margin
972 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
975 void wxLogDialog::OnListSelect(wxListEvent
& event
)
977 // we can't just disable the control because this looks ugly under Windows
978 // (wrong bg colour, no scrolling...), but we still want to disable
979 // selecting items - it makes no sense here
980 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
983 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
990 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
994 int rc
= OpenLogFile(file
, NULL
, this);
1003 wxString fmt
= wxLog::GetTimestamp();
1010 size_t count
= m_messages
.GetCount();
1011 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
1014 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
1017 << wxTextFile::GetEOL();
1019 ok
= file
.Write(line
);
1026 wxLogError(_("Can't save log contents to file."));
1027 #endif // wxUSE_FILEDLG
1030 #endif // wxUSE_FILE
1032 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1034 wxSizer
*sizer
= GetSizer();
1036 if ( m_showingDetails
)
1038 #ifdef __SMARTPHONE__
1039 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
1041 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1044 sizer
->Detach( m_listctrl
);
1046 #ifndef __SMARTPHONE__
1049 sizer
->Detach( m_statline
);
1050 #endif // wxUSE_STATLINE
1053 sizer
->Detach( m_btnSave
);
1054 #endif // wxUSE_FILE
1056 #endif // __SMARTPHONE__
1058 else // show details now
1060 #ifdef __SMARTPHONE__
1061 SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
);
1063 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1068 CreateDetailsControls();
1071 #if wxUSE_STATLINE && !defined(__SMARTPHONE__)
1072 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1074 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1075 #endif // wxUSE_STATLINE
1077 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1079 // VZ: this doesn't work as this becomes the initial (and not only
1080 // minimal) listctrl height as well - why?
1082 // allow the user to make the dialog shorter than its initial height -
1083 // without this it wouldn't work as the list ctrl would have been
1085 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1088 #if wxUSE_FILE && !defined(__SMARTPHONE__)
1089 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1090 #endif // wxUSE_FILE
1093 m_showingDetails
= !m_showingDetails
;
1095 // in any case, our size changed - relayout everything and set new hints
1096 // ---------------------------------------------------------------------
1098 // we have to reset min size constraints or Fit() would never reduce the
1099 // dialog size when collapsing it and we have to reset max constraint
1100 // because it wouldn't expand it otherwise
1105 // wxSizer::FitSize() is private, otherwise we might use it directly...
1106 wxSize sizeTotal
= GetSize(),
1107 sizeClient
= GetClientSize();
1109 wxSize size
= sizer
->GetMinSize();
1110 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1111 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1113 // we don't want to allow expanding the dialog in vertical direction as
1114 // this would show the "hidden" details but we can resize the dialog
1115 // vertically while the details are shown
1116 if ( !m_showingDetails
)
1117 m_maxHeight
= size
.y
;
1119 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1122 if (m_showingDetails
)
1126 // don't change the width when expanding/collapsing
1127 SetSize(wxDefaultCoord
, size
.y
);
1130 // VS: this is necessary in order to force frame redraw under
1131 // WindowMaker or fvwm2 (and probably other broken WMs).
1132 // Otherwise, detailed list wouldn't be displayed.
1137 wxLogDialog::~wxLogDialog()
1141 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1145 #endif // wxUSE_LOG_DIALOG
1147 #if wxUSE_FILE && wxUSE_FILEDLG
1149 // pass an uninitialized file object, the function will ask the user for the
1150 // filename and try to open it, returns true on success (file was opened),
1151 // false if file couldn't be opened/created and -1 if the file selection
1152 // dialog was cancelled
1153 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1155 // get the file name
1156 // -----------------
1157 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1165 bool bOk
wxDUMMY_INITIALIZE(false);
1166 if ( wxFile::Exists(filename
) ) {
1167 bool bAppend
= false;
1169 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1171 switch ( wxMessageBox(strMsg
, _("Question"),
1172 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1185 wxFAIL_MSG(_("invalid message box return value"));
1189 bOk
= file
.Open(filename
, wxFile::write_append
);
1192 bOk
= file
.Create(filename
, true /* overwrite */);
1196 bOk
= file
.Create(filename
);
1200 *pFilename
= filename
;
1205 #endif // wxUSE_FILE
1207 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1209 #if wxUSE_LOG && wxUSE_TEXTCTRL
1211 // ----------------------------------------------------------------------------
1212 // wxLogTextCtrl implementation
1213 // ----------------------------------------------------------------------------
1215 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1217 m_pTextCtrl
= pTextCtrl
;
1220 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1225 msg
<< szString
<< wxT('\n');
1226 m_pTextCtrl
->AppendText(msg
);
1229 #endif // wxUSE_LOG && wxUSE_TEXTCTRL