]>
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 wxButton
*m_btnDetails
;
136 bool m_showingDetails
;
138 // the controls which are not shown initially (but only when details
139 // button is pressed)
140 wxListCtrl
*m_listctrl
;
142 wxStaticLine
*m_statline
;
143 #endif // wxUSE_STATLINE
148 // the translated "Details" string
149 static wxString ms_details
;
151 DECLARE_EVENT_TABLE()
152 DECLARE_NO_COPY_CLASS(wxLogDialog
)
155 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
156 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
157 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
159 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
161 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
164 #endif // wxUSE_LOG_DIALOG
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 #if wxUSE_FILE && wxUSE_FILEDLG
172 // pass an uninitialized file object, the function will ask the user for the
173 // filename and try to open it, returns true on success (file was opened),
174 // false if file couldn't be opened/created and -1 if the file selection
175 // dialog was cancelled
176 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 // we use a global variable to store the frame pointer for wxLogStatus - bad,
185 // but it's the easiest way
186 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
188 // ============================================================================
190 // ============================================================================
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 // accepts an additional argument which tells to which frame the output should
198 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
202 wxLog
*pLog
= wxLog::GetActiveTarget();
203 if ( pLog
!= NULL
) {
204 msg
.PrintfV(szFormat
, argptr
);
206 wxASSERT( gs_pFrame
== NULL
); // should be reset!
209 wxLog::OnLog(wxLOG_Status
, msg
, 0);
211 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
213 gs_pFrame
= (wxFrame
*) NULL
;
217 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
220 va_start(argptr
, szFormat
);
221 wxVLogStatus(pFrame
, szFormat
, argptr
);
225 // ----------------------------------------------------------------------------
226 // wxLogGui implementation (FIXME MT-unsafe)
227 // ----------------------------------------------------------------------------
236 void wxLogGui::Clear()
240 m_bHasMessages
= false;
247 void wxLogGui::Flush()
249 if ( !m_bHasMessages
)
252 // do it right now to block any new calls to Flush() while we're here
253 m_bHasMessages
= false;
255 wxString appName
= wxTheApp
->GetAppName();
256 if ( !appName
.empty() )
257 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
260 wxString titleFormat
;
262 titleFormat
= _("%s Error");
265 else if ( m_bWarnings
) {
266 titleFormat
= _("%s Warning");
267 style
= wxICON_EXCLAMATION
;
270 titleFormat
= _("%s Information");
271 style
= wxICON_INFORMATION
;
275 title
.Printf(titleFormat
, appName
.c_str());
277 size_t nMsgCount
= m_aMessages
.Count();
279 // avoid showing other log dialogs until we're done with the dialog we're
280 // showing right now: nested modal dialogs make for really bad UI!
284 if ( nMsgCount
== 1 )
286 str
= m_aMessages
[0];
288 else // more than one message
292 wxLogDialog
dlg(NULL
,
293 m_aMessages
, m_aSeverity
, m_aTimes
,
296 // clear the message list before showing the dialog because while it's
297 // shown some new messages may appear
300 (void)dlg
.ShowModal();
301 #else // !wxUSE_LOG_DIALOG
302 // concatenate all strings (but not too many to not overfill the msg box)
305 // start from the most recent message
306 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
307 // for Windows strings longer than this value are wrapped (NT 4.0)
308 const size_t nMsgLineWidth
= 156;
310 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
312 if ( nLines
> 25 ) // don't put too many lines in message box
315 str
<< m_aMessages
[n
- 1] << wxT("\n");
317 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
320 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
321 // situation without it
324 wxMessageBox(str
, title
, wxOK
| style
);
326 // no undisplayed messages whatsoever
330 // allow flushing the logs again
334 // log all kinds of messages
335 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
342 m_aMessages
.Add(szString
);
343 m_aSeverity
.Add(wxLOG_Message
);
344 m_aTimes
.Add((long)t
);
345 m_bHasMessages
= true;
352 // find the top window and set it's status text if it has any
353 wxFrame
*pFrame
= gs_pFrame
;
354 if ( pFrame
== NULL
) {
355 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
356 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
357 pFrame
= (wxFrame
*)pWin
;
361 if ( pFrame
&& pFrame
->GetStatusBar() )
362 pFrame
->SetStatusText(szString
);
364 #endif // wxUSE_STATUSBAR
375 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
376 // don't prepend debug/trace here: it goes to the
377 // debug window anyhow
379 OutputDebugString(str
);
381 // send them to stderr
382 wxFprintf(stderr
, wxT("[%s] %s\n"),
383 level
== wxLOG_Trace
? wxT("Trace")
389 #endif // __WXDEBUG__
393 case wxLOG_FatalError
:
394 // show this one immediately
395 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
401 #if !wxUSE_LOG_DIALOG
402 // discard earlier informational messages if this is the 1st
403 // error because they might not make sense any more and showing
404 // them in a message box might be confusing
408 #endif // wxUSE_LOG_DIALOG
415 // for the warning we don't discard the info messages
419 m_aMessages
.Add(szString
);
420 m_aSeverity
.Add((int)level
);
421 m_aTimes
.Add((long)t
);
422 m_bHasMessages
= true;
427 #endif // wxUSE_LOGGUI
429 // ----------------------------------------------------------------------------
430 // wxLogWindow and wxLogFrame implementation
431 // ----------------------------------------------------------------------------
435 class wxLogFrame
: public wxFrame
439 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
440 virtual ~wxLogFrame();
443 void OnClose(wxCommandEvent
& event
);
444 void OnCloseWindow(wxCloseEvent
& event
);
446 void OnSave (wxCommandEvent
& event
);
448 void OnClear(wxCommandEvent
& event
);
451 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
454 // use standard ids for our commands!
457 Menu_Close
= wxID_CLOSE
,
458 Menu_Save
= wxID_SAVE
,
459 Menu_Clear
= wxID_CLEAR
462 // common part of OnClose() and OnCloseWindow()
465 wxTextCtrl
*m_pTextCtrl
;
468 DECLARE_EVENT_TABLE()
469 DECLARE_NO_COPY_CLASS(wxLogFrame
)
472 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
473 // wxLogWindow menu events
474 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
476 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
478 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
480 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
483 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
484 : wxFrame(pParent
, wxID_ANY
, szTitle
)
488 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
492 // needed for Win32 to avoid 65Kb limit but it doesn't work well
493 // when using RichEdit 2.0 which we always do in the Unicode build
496 #endif // !wxUSE_UNICODE
501 wxMenuBar
*pMenuBar
= new wxMenuBar
;
502 wxMenu
*pMenu
= new wxMenu
;
504 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
506 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
507 pMenu
->AppendSeparator();
508 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
509 pMenuBar
->Append(pMenu
, _("&Log"));
510 SetMenuBar(pMenuBar
);
511 #endif // wxUSE_MENUS
514 // status bar for menu prompts
516 #endif // wxUSE_STATUSBAR
518 m_log
->OnFrameCreate(this);
521 void wxLogFrame::DoClose()
523 if ( m_log
->OnFrameClose(this) )
525 // instead of closing just hide the window to be able to Show() it
531 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
536 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
542 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
547 int rc
= OpenLogFile(file
, &filename
, this);
556 // retrieve text and save it
557 // -------------------------
558 int nLines
= m_pTextCtrl
->GetNumberOfLines();
559 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
560 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
561 wxTextFile::GetEOL());
568 wxLogError(_("Can't save log contents to file."));
571 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
577 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
579 m_pTextCtrl
->Clear();
582 wxLogFrame::~wxLogFrame()
584 m_log
->OnFrameDelete(this);
590 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
591 const wxChar
*szTitle
,
595 PassMessages(bDoPass
);
597 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
603 void wxLogWindow::Show(bool bShow
)
605 m_pLogFrame
->Show(bShow
);
608 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
610 // first let the previous logger show it
611 wxLogPassThrough::DoLog(level
, szString
, t
);
616 // by default, these messages are ignored by wxLog, so process
618 if ( !wxIsEmpty(szString
) )
621 str
<< _("Status: ") << szString
;
626 // don't put trace messages in the text window for 2 reasons:
627 // 1) there are too many of them
628 // 2) they may provoke other trace messages thus sending a program
629 // into an infinite loop
634 // and this will format it nicely and call our DoLogString()
635 wxLog::DoLog(level
, szString
, t
);
640 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
642 // put the text into our window
643 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
645 // remove selection (WriteText is in fact ReplaceSelection)
647 wxTextPos nLen
= pText
->GetLastPosition();
648 pText
->SetSelection(nLen
, nLen
);
653 msg
<< szString
<< wxT('\n');
655 pText
->AppendText(msg
);
657 // TODO ensure that the line can be seen
660 wxFrame
*wxLogWindow::GetFrame() const
665 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
669 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
675 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
677 m_pLogFrame
= (wxLogFrame
*)NULL
;
680 wxLogWindow::~wxLogWindow()
682 // may be NULL if log frame already auto destroyed itself
686 // ----------------------------------------------------------------------------
688 // ----------------------------------------------------------------------------
692 static const size_t MARGIN
= 10;
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
);
714 size_t count
= messages
.GetCount();
715 m_messages
.Alloc(count
);
716 m_severity
.Alloc(count
);
717 m_times
.Alloc(count
);
719 for ( size_t n
= 0; n
< count
; n
++ )
721 wxString msg
= messages
[n
];
722 msg
.Replace(wxT("\n"), wxT(" "));
724 m_severity
.Add(severity
[n
]);
725 m_times
.Add(times
[n
]);
728 m_showingDetails
= false; // not initially
729 m_listctrl
= (wxListCtrl
*)NULL
;
732 m_statline
= (wxStaticLine
*)NULL
;
733 #endif // wxUSE_STATLINE
736 m_btnSave
= (wxButton
*)NULL
;
739 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
741 // create the controls which are always shown and layout them: we use
742 // sizers even though our window is not resizeable to calculate the size of
743 // the dialog properly
744 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
745 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
746 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
748 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
749 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
750 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
751 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
754 switch ( style
& wxICON_MASK
)
757 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
759 bitmap
.SetId(wxICON_SMALL_ERROR
);
763 case wxICON_INFORMATION
:
764 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
766 bitmap
.SetId(wxICON_SMALL_INFO
);
771 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
773 bitmap
.SetId(wxICON_SMALL_WARNING
);
778 wxFAIL_MSG(_T("incorrect log style"));
782 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
783 wxALIGN_CENTRE_VERTICAL
);
785 const wxString
& message
= messages
.Last();
786 sizerAll
->Add(CreateTextSizer(message
), 1,
787 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
788 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
790 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
794 // see comments in OnDetails()
796 // Note: Doing this, this way, triggered a nasty bug in
797 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
798 // either of maxWidth or maxHeight was set. This symptom has been
799 // fixed there, but it is a problem that remains as long as we allow
800 // unchecked access to the internal size members. We really need to
801 // encapuslate window sizes more cleanly and make it clear when -1 will
802 // be substituted and when it will not.
804 wxSize size
= sizerTop
->Fit(this);
805 m_maxHeight
= size
.y
;
806 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
814 // Move up the screen so that when we expand the dialog,
815 // there's enough space.
816 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
820 void wxLogDialog::CreateDetailsControls()
822 // create the save button and separator line if possible
824 m_btnSave
= new wxButton(this, wxID_SAVE
);
828 m_statline
= new wxStaticLine(this, wxID_ANY
);
829 #endif // wxUSE_STATLINE
831 // create the list ctrl now
832 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
833 wxDefaultPosition
, wxDefaultSize
,
839 // This maks a big aesthetic difference on WinCE but I
840 // don't want to risk problems on other platforms
844 // no need to translate these strings as they're not shown to the
845 // user anyhow (we use wxLC_NO_HEADER style)
846 m_listctrl
->InsertColumn(0, _T("Message"));
847 m_listctrl
->InsertColumn(1, _T("Time"));
849 // prepare the imagelist
850 static const int ICON_SIZE
= 16;
851 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
853 // order should be the same as in the switch below!
854 static const wxChar
* icons
[] =
861 bool loadedIcons
= true;
863 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
865 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
866 wxSize(ICON_SIZE
, ICON_SIZE
));
868 // This may very well fail if there are insufficient colours available.
869 // Degrade gracefully.
880 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
883 wxString fmt
= wxLog::GetTimestamp();
887 fmt
= wxDefaultDateTimeFormat
;
890 size_t count
= m_messages
.GetCount();
891 for ( size_t n
= 0; n
< count
; n
++ )
897 switch ( m_severity
[n
] )
911 else // failed to load images
916 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
917 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
920 // let the columns size themselves
921 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
922 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
924 // calculate an approximately nice height for the listctrl
925 int height
= GetCharHeight()*(count
+ 4);
927 // but check that the dialog won't fall fown from the screen
929 // we use GetMinHeight() to get the height of the dialog part without the
930 // details and we consider that the "Save" button below and the separator
931 // line (and the margins around it) take about as much, hence double it
932 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
934 // we should leave a margin
938 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
941 void wxLogDialog::OnListSelect(wxListEvent
& event
)
943 // we can't just disable the control because this looks ugly under Windows
944 // (wrong bg colour, no scrolling...), but we still want to disable
945 // selecting items - it makes no sense here
946 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
949 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
956 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
960 int rc
= OpenLogFile(file
, NULL
, this);
969 wxString fmt
= wxLog::GetTimestamp();
973 fmt
= wxDefaultDateTimeFormat
;
976 size_t count
= m_messages
.GetCount();
977 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
980 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
983 << wxTextFile::GetEOL();
985 ok
= file
.Write(line
);
992 wxLogError(_("Can't save log contents to file."));
993 #endif // wxUSE_FILEDLG
998 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1000 wxSizer
*sizer
= GetSizer();
1002 if ( m_showingDetails
)
1004 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1006 sizer
->Detach( m_listctrl
);
1009 sizer
->Detach( m_statline
);
1010 #endif // wxUSE_STATLINE
1013 sizer
->Detach( m_btnSave
);
1014 #endif // wxUSE_FILE
1016 else // show details now
1018 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1022 CreateDetailsControls();
1026 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1028 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1029 #endif // wxUSE_STATLINE
1031 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1033 // VZ: this doesn't work as this becomes the initial (and not only
1034 // minimal) listctrl height as well - why?
1036 // allow the user to make the dialog shorter than its initial height -
1037 // without this it wouldn't work as the list ctrl would have been
1039 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1043 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1044 #endif // wxUSE_FILE
1047 m_showingDetails
= !m_showingDetails
;
1049 // in any case, our size changed - relayout everything and set new hints
1050 // ---------------------------------------------------------------------
1052 // we have to reset min size constraints or Fit() would never reduce the
1053 // dialog size when collapsing it and we have to reset max constraint
1054 // because it wouldn't expand it otherwise
1059 // wxSizer::FitSize() is private, otherwise we might use it directly...
1060 wxSize sizeTotal
= GetSize(),
1061 sizeClient
= GetClientSize();
1063 wxSize size
= sizer
->GetMinSize();
1064 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1065 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1067 // we don't want to allow expanding the dialog in vertical direction as
1068 // this would show the "hidden" details but we can resize the dialog
1069 // vertically while the details are shown
1070 if ( !m_showingDetails
)
1071 m_maxHeight
= size
.y
;
1073 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1076 if (m_showingDetails
)
1080 // don't change the width when expanding/collapsing
1081 SetSize(wxDefaultCoord
, size
.y
);
1084 // VS: this is neccessary in order to force frame redraw under
1085 // WindowMaker or fvwm2 (and probably other broken WMs).
1086 // Otherwise, detailed list wouldn't be displayed.
1091 wxLogDialog::~wxLogDialog()
1095 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1099 #endif // wxUSE_LOG_DIALOG
1101 #if wxUSE_FILE && wxUSE_FILEDLG
1103 // pass an uninitialized file object, the function will ask the user for the
1104 // filename and try to open it, returns true on success (file was opened),
1105 // false if file couldn't be opened/created and -1 if the file selection
1106 // dialog was cancelled
1107 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1109 // get the file name
1110 // -----------------
1111 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1120 if ( wxFile::Exists(filename
) ) {
1121 bool bAppend
= false;
1123 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1125 switch ( wxMessageBox(strMsg
, _("Question"),
1126 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1139 wxFAIL_MSG(_("invalid message box return value"));
1143 bOk
= file
.Open(filename
, wxFile::write_append
);
1146 bOk
= file
.Create(filename
, true /* overwrite */);
1150 bOk
= file
.Create(filename
);
1154 *pFilename
= filename
;
1159 #endif // wxUSE_FILE
1161 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1163 #if wxUSE_LOG && wxUSE_TEXTCTRL
1165 // ----------------------------------------------------------------------------
1166 // wxLogTextCtrl implementation
1167 // ----------------------------------------------------------------------------
1169 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1171 m_pTextCtrl
= pTextCtrl
;
1174 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1179 msg
<< szString
<< wxT('\n');
1180 m_pTextCtrl
->AppendText(msg
);
1183 #endif // wxUSE_LOG && wxUSE_TEXTCTRL