]>
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 license
11 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 // no #pragma implementation "log.h" because it's already in src/common/log.cpp
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
31 #error "This file can't be compiled without GUI!"
36 #include "wx/button.h"
41 #include "wx/filedlg.h"
42 #include "wx/msgdlg.h"
43 #include "wx/textctrl.h"
45 #include "wx/statbmp.h"
46 #include "wx/button.h"
47 #include "wx/settings.h"
50 #if wxUSE_LOGGUI || wxUSE_LOGWINDOW
53 #include "wx/textfile.h"
54 #include "wx/statline.h"
55 #include "wx/artprov.h"
58 // for OutputDebugString()
59 #include "wx/msw/private.h"
63 #include "wx/listctrl.h"
64 #include "wx/imaglist.h"
66 #else // !wxUSE_LOG_DIALOG
67 #include "wx/msgdlg.h"
68 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
70 // the suffix we add to the button to show that the dialog can be expanded
71 #define EXPAND_SUFFIX _T(" >>")
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
79 // this function is a wrapper around strftime(3)
80 // allows to exclude the usage of wxDateTime
81 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
84 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
86 // buffer is too small?
87 wxFAIL_MSG(_T("strftime() failed"));
93 class wxLogDialog
: public wxDialog
96 wxLogDialog(wxWindow
*parent
,
97 const wxArrayString
& messages
,
98 const wxArrayInt
& severity
,
99 const wxArrayLong
& timess
,
100 const wxString
& caption
,
102 virtual ~wxLogDialog();
105 void OnOk(wxCommandEvent
& event
);
106 void OnDetails(wxCommandEvent
& event
);
108 void OnSave(wxCommandEvent
& event
);
110 void OnListSelect(wxListEvent
& event
);
113 // create controls needed for the details display
114 void CreateDetailsControls();
116 // the data for the listctrl
117 wxArrayString m_messages
;
118 wxArrayInt m_severity
;
121 // the "toggle" button and its state
122 wxButton
*m_btnDetails
;
123 bool m_showingDetails
;
125 // the controls which are not shown initially (but only when details
126 // button is pressed)
127 wxListCtrl
*m_listctrl
;
129 wxStaticLine
*m_statline
;
130 #endif // wxUSE_STATLINE
135 // the translated "Details" string
136 static wxString ms_details
;
138 DECLARE_EVENT_TABLE()
141 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
142 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
143 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
145 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
147 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
150 #endif // wxUSE_LOG_DIALOG
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 #if wxUSE_FILE && wxUSE_FILEDLG
158 // pass an uninitialized file object, the function will ask the user for the
159 // filename and try to open it, returns TRUE on success (file was opened),
160 // FALSE if file couldn't be opened/created and -1 if the file selection
161 // dialog was cancelled
162 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 // we use a global variable to store the frame pointer for wxLogStatus - bad,
171 // but it's the easiest way
172 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
174 // ============================================================================
176 // ============================================================================
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 // accepts an additional argument which tells to which frame the output should
184 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
188 wxLog
*pLog
= wxLog::GetActiveTarget();
189 if ( pLog
!= NULL
) {
190 msg
.PrintfV(szFormat
, argptr
);
192 wxASSERT( gs_pFrame
== NULL
); // should be reset!
194 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
195 gs_pFrame
= (wxFrame
*) NULL
;
199 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
202 va_start(argptr
, szFormat
);
203 wxVLogStatus(pFrame
, szFormat
, argptr
);
207 // ----------------------------------------------------------------------------
208 // wxLogGui implementation (FIXME MT-unsafe)
209 // ----------------------------------------------------------------------------
216 void wxLogGui::Clear()
220 m_bHasMessages
= FALSE
;
227 void wxLogGui::Flush()
229 if ( !m_bHasMessages
)
232 // do it right now to block any new calls to Flush() while we're here
233 m_bHasMessages
= FALSE
;
235 wxString appName
= wxTheApp
->GetAppName();
237 appName
[0u] = wxToupper(appName
[0u]);
240 wxString titleFormat
;
242 titleFormat
= _("%s Error");
245 else if ( m_bWarnings
) {
246 titleFormat
= _("%s Warning");
247 style
= wxICON_EXCLAMATION
;
250 titleFormat
= _("%s Information");
251 style
= wxICON_INFORMATION
;
255 title
.Printf(titleFormat
, appName
.c_str());
257 size_t nMsgCount
= m_aMessages
.Count();
259 // avoid showing other log dialogs until we're done with the dialog we're
260 // showing right now: nested modal dialogs make for really bad UI!
264 if ( nMsgCount
== 1 )
266 str
= m_aMessages
[0];
268 else // more than one message
272 wxLogDialog
dlg(NULL
,
273 m_aMessages
, m_aSeverity
, m_aTimes
,
276 // clear the message list before showing the dialog because while it's
277 // shown some new messages may appear
280 (void)dlg
.ShowModal();
281 #else // !wxUSE_LOG_DIALOG
282 // concatenate all strings (but not too many to not overfill the msg box)
285 // start from the most recent message
286 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
287 // for Windows strings longer than this value are wrapped (NT 4.0)
288 const size_t nMsgLineWidth
= 156;
290 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
292 if ( nLines
> 25 ) // don't put too many lines in message box
295 str
<< m_aMessages
[n
- 1] << wxT("\n");
297 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
300 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
301 // situation without it
304 wxMessageBox(str
, title
, wxOK
| style
);
306 // no undisplayed messages whatsoever
310 // allow flushing the logs again
314 // log all kinds of messages
315 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
322 m_aMessages
.Add(szString
);
323 m_aSeverity
.Add(wxLOG_Message
);
324 m_aTimes
.Add((long)t
);
325 m_bHasMessages
= TRUE
;
332 // find the top window and set it's status text if it has any
333 wxFrame
*pFrame
= gs_pFrame
;
334 if ( pFrame
== NULL
) {
335 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
336 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
337 pFrame
= (wxFrame
*)pWin
;
341 if ( pFrame
&& pFrame
->GetStatusBar() )
342 pFrame
->SetStatusText(szString
);
344 #endif // wxUSE_STATUSBAR
355 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
356 // don't prepend debug/trace here: it goes to the
357 // debug window anyhow
359 OutputDebugString(str
);
361 // send them to stderr
362 wxFprintf(stderr
, wxT("[%s] %s\n"),
363 level
== wxLOG_Trace
? wxT("Trace")
369 #endif // __WXDEBUG__
373 case wxLOG_FatalError
:
374 // show this one immediately
375 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
381 #if !wxUSE_LOG_DIALOG
382 // discard earlier informational messages if this is the 1st
383 // error because they might not make sense any more and showing
384 // them in a message box might be confusing
388 #endif // wxUSE_LOG_DIALOG
395 // for the warning we don't discard the info messages
399 m_aMessages
.Add(szString
);
400 m_aSeverity
.Add((int)level
);
401 m_aTimes
.Add((long)t
);
402 m_bHasMessages
= TRUE
;
407 // ----------------------------------------------------------------------------
408 // wxLogWindow and wxLogFrame implementation
409 // ----------------------------------------------------------------------------
413 class wxLogFrame
: public wxFrame
417 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
418 virtual ~wxLogFrame();
421 void OnClose(wxCommandEvent
& event
);
422 void OnCloseWindow(wxCloseEvent
& event
);
424 void OnSave (wxCommandEvent
& event
);
426 void OnClear(wxCommandEvent
& event
);
428 void OnIdle(wxIdleEvent
&);
431 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
434 // use standard ids for our commands!
437 Menu_Close
= wxID_CLOSE
,
438 Menu_Save
= wxID_SAVE
,
439 Menu_Clear
= wxID_CLEAR
442 // common part of OnClose() and OnCloseWindow()
445 wxTextCtrl
*m_pTextCtrl
;
448 DECLARE_EVENT_TABLE()
451 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
452 // wxLogWindow menu events
453 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
455 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
457 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
459 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
462 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
463 : wxFrame(pParent
, -1, szTitle
)
467 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
471 // needed for Win32 to avoid 65Kb limit but it doesn't work well
472 // when using RichEdit 2.0 which we always do in the Unicode build
475 #endif // !wxUSE_UNICODE
480 wxMenuBar
*pMenuBar
= new wxMenuBar
;
481 wxMenu
*pMenu
= new wxMenu
;
483 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
485 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
486 pMenu
->AppendSeparator();
487 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
488 pMenuBar
->Append(pMenu
, _("&Log"));
489 SetMenuBar(pMenuBar
);
490 #endif // wxUSE_MENUS
493 // status bar for menu prompts
495 #endif // wxUSE_STATUSBAR
497 m_log
->OnFrameCreate(this);
500 void wxLogFrame::DoClose()
502 if ( m_log
->OnFrameClose(this) )
504 // instead of closing just hide the window to be able to Show() it
510 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
515 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
521 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
526 int rc
= OpenLogFile(file
, &filename
);
535 // retrieve text and save it
536 // -------------------------
537 int nLines
= m_pTextCtrl
->GetNumberOfLines();
538 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
539 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
540 wxTextFile::GetEOL());
547 wxLogError(_("Can't save log contents to file."));
550 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
556 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
558 m_pTextCtrl
->Clear();
561 wxLogFrame::~wxLogFrame()
563 m_log
->OnFrameDelete(this);
569 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
570 const wxChar
*szTitle
,
574 PassMessages(bDoPass
);
576 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
579 m_pLogFrame
->Show(TRUE
);
582 void wxLogWindow::Show(bool bShow
)
584 m_pLogFrame
->Show(bShow
);
587 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
589 // first let the previous logger show it
590 wxLogPassThrough::DoLog(level
, szString
, t
);
595 // by default, these messages are ignored by wxLog, so process
597 if ( !wxIsEmpty(szString
) )
600 str
<< _("Status: ") << szString
;
605 // don't put trace messages in the text window for 2 reasons:
606 // 1) there are too many of them
607 // 2) they may provoke other trace messages thus sending a program
608 // into an infinite loop
613 // and this will format it nicely and call our DoLogString()
614 wxLog::DoLog(level
, szString
, t
);
618 m_bHasMessages
= TRUE
;
621 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
623 // put the text into our window
624 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
626 // remove selection (WriteText is in fact ReplaceSelection)
628 long nLen
= pText
->GetLastPosition();
629 pText
->SetSelection(nLen
, nLen
);
634 msg
<< szString
<< wxT('\n');
636 pText
->AppendText(msg
);
638 // TODO ensure that the line can be seen
641 wxFrame
*wxLogWindow::GetFrame() const
646 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
650 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
656 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
658 m_pLogFrame
= (wxLogFrame
*)NULL
;
661 wxLogWindow::~wxLogWindow()
663 // may be NULL if log frame already auto destroyed itself
667 // ----------------------------------------------------------------------------
669 // ----------------------------------------------------------------------------
673 static const size_t MARGIN
= 10;
675 wxString
wxLogDialog::ms_details
;
677 wxLogDialog::wxLogDialog(wxWindow
*parent
,
678 const wxArrayString
& messages
,
679 const wxArrayInt
& severity
,
680 const wxArrayLong
& times
,
681 const wxString
& caption
,
683 : wxDialog(parent
, -1, caption
,
684 wxDefaultPosition
, wxDefaultSize
,
685 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
687 if ( ms_details
.IsEmpty() )
689 // ensure that we won't loop here if wxGetTranslation()
690 // happens to pop up a Log message while translating this :-)
691 ms_details
= wxTRANSLATE("&Details");
692 ms_details
= wxGetTranslation(ms_details
);
695 size_t count
= messages
.GetCount();
696 m_messages
.Alloc(count
);
697 m_severity
.Alloc(count
);
698 m_times
.Alloc(count
);
700 for ( size_t n
= 0; n
< count
; n
++ )
702 wxString msg
= messages
[n
];
705 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
706 msg
= msg
.AfterFirst(_T('\n'));
708 m_severity
.Add(severity
[n
]);
709 m_times
.Add(times
[n
]);
714 m_showingDetails
= FALSE
; // not initially
715 m_listctrl
= (wxListCtrl
*)NULL
;
718 m_statline
= (wxStaticLine
*)NULL
;
719 #endif // wxUSE_STATLINE
722 m_btnSave
= (wxButton
*)NULL
;
725 // create the controls which are always shown and layout them: we use
726 // sizers even though our window is not resizeable to calculate the size of
727 // the dialog properly
728 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
729 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
730 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
732 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
733 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
734 // translates into click on cancel button)
735 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
736 sizerButtons
->Add(btnOk
, 0, wxCENTRE
| wxBOTTOM
, MARGIN
/2);
737 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
738 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
742 switch ( style
& wxICON_MASK
)
745 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
747 bitmap
.SetId(wxICON_SMALL_ERROR
);
751 case wxICON_INFORMATION
:
752 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
754 bitmap
.SetId(wxICON_SMALL_INFO
);
759 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
761 bitmap
.SetId(wxICON_SMALL_WARNING
);
766 wxFAIL_MSG(_T("incorrect log style"));
768 sizerAll
->Add(new wxStaticBitmap(this, -1, bitmap
), 0);
771 const wxString
& message
= messages
.Last();
772 sizerAll
->Add(CreateTextSizer(message
), 1,
773 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
774 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
| wxLEFT
, MARGIN
);
776 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
781 // see comments in OnDetails()
783 // Note: Doing this, this way, triggered a nasty bug in
784 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
785 // either of maxWidth or maxHeight was set. This symptom has been
786 // fixed there, but it is a problem that remains as long as we allow
787 // unchecked access to the internal size members. We really need to
788 // encapuslate window sizes more cleanly and make it clear when -1 will
789 // be substituted and when it will not.
791 wxSize size
= sizerTop
->Fit(this);
792 m_maxHeight
= size
.y
;
793 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
797 // this can't happen any more as we don't use this dialog in this case
801 // no details... it's easier to disable a button than to change the
802 // dialog layout depending on whether we have details or not
803 m_btnDetails
->Disable();
810 void wxLogDialog::CreateDetailsControls()
812 // create the save button and separator line if possible
814 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
818 m_statline
= new wxStaticLine(this, -1);
819 #endif // wxUSE_STATLINE
821 // create the list ctrl now
822 m_listctrl
= new wxListCtrl(this, -1,
823 wxDefaultPosition
, wxDefaultSize
,
829 // no need to translate these strings as they're not shown to the
830 // user anyhow (we use wxLC_NO_HEADER style)
831 m_listctrl
->InsertColumn(0, _T("Message"));
832 m_listctrl
->InsertColumn(1, _T("Time"));
834 // prepare the imagelist
835 static const int ICON_SIZE
= 16;
836 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
838 // order should be the same as in the switch below!
839 static const wxChar
* icons
[] =
846 bool loadedIcons
= TRUE
;
849 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
851 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
852 wxSize(ICON_SIZE
, ICON_SIZE
));
854 // This may very well fail if there are insufficient colours available.
855 // Degrade gracefully.
866 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
870 wxString fmt
= wxLog::GetTimestamp();
877 size_t count
= m_messages
.GetCount();
878 for ( size_t n
= 0; n
< count
; n
++ )
885 switch ( m_severity
[n
] )
899 else // failed to load images
905 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
906 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
909 // let the columns size themselves
910 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
911 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
913 // calculate an approximately nice height for the listctrl
914 int height
= GetCharHeight()*(count
+ 4);
916 // but check that the dialog won't fall fown from the screen
918 // we use GetMinHeight() to get the height of the dialog part without the
919 // details and we consider that the "Save" button below and the separator
920 // line (and the margins around it) take about as much, hence double it
921 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
923 // we should leave a margin
927 m_listctrl
->SetSize(-1, wxMin(height
, heightMax
));
930 void wxLogDialog::OnListSelect(wxListEvent
& event
)
932 // we can't just disable the control because this looks ugly under Windows
933 // (wrong bg colour, no scrolling...), but we still want to disable
934 // selecting items - it makes no sense here
935 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
938 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
945 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
949 int rc
= OpenLogFile(file
);
958 wxString fmt
= wxLog::GetTimestamp();
965 size_t count
= m_messages
.GetCount();
966 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
969 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
972 << wxTextFile::GetEOL();
974 ok
= file
.Write(line
);
981 wxLogError(_("Can't save log contents to file."));
982 #endif // wxUSE_FILEDLG
987 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
989 wxSizer
*sizer
= GetSizer();
991 if ( m_showingDetails
)
993 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
995 sizer
->Remove(m_listctrl
);
998 sizer
->Remove(m_statline
);
999 #endif // wxUSE_STATLINE
1002 sizer
->Remove(m_btnSave
);
1003 #endif // wxUSE_FILE
1005 else // show details now
1007 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1011 CreateDetailsControls();
1015 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1016 #endif // wxUSE_STATLINE
1018 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1020 // VZ: this doesn't work as this becomes the initial (and not only
1021 // minimal) listctrl height as well - why?
1023 // allow the user to make the dialog shorter than its initial height -
1024 // without this it wouldn't work as the list ctrl would have been
1026 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1030 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1031 #endif // wxUSE_FILE
1034 m_showingDetails
= !m_showingDetails
;
1036 // in any case, our size changed - relayout everything and set new hints
1037 // ---------------------------------------------------------------------
1039 // we have to reset min size constraints or Fit() would never reduce the
1040 // dialog size when collapsing it and we have to reset max constraint
1041 // because it wouldn't expand it otherwise
1046 // wxSizer::FitSize() is private, otherwise we might use it directly...
1047 wxSize sizeTotal
= GetSize(),
1048 sizeClient
= GetClientSize();
1050 wxSize size
= sizer
->GetMinSize();
1051 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1052 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1054 // we don't want to allow expanding the dialog in vertical direction as
1055 // this would show the "hidden" details but we can resize the dialog
1056 // vertically while the details are shown
1057 if ( !m_showingDetails
)
1058 m_maxHeight
= size
.y
;
1060 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1062 // don't change the width when expanding/collapsing
1063 SetSize(-1, size
.y
);
1066 // VS: this is neccessary in order to force frame redraw under
1067 // WindowMaker or fvwm2 (and probably other broken WMs).
1068 // Otherwise, detailed list wouldn't be displayed.
1073 wxLogDialog::~wxLogDialog()
1077 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1081 #endif // wxUSE_LOG_DIALOG
1083 #if wxUSE_FILE && wxUSE_FILEDLG
1085 // pass an uninitialized file object, the function will ask the user for the
1086 // filename and try to open it, returns TRUE on success (file was opened),
1087 // FALSE if file couldn't be opened/created and -1 if the file selection
1088 // dialog was cancelled
1089 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1091 // get the file name
1092 // -----------------
1093 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1102 if ( wxFile::Exists(filename
) ) {
1103 bool bAppend
= FALSE
;
1105 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1107 switch ( wxMessageBox(strMsg
, _("Question"),
1108 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1121 wxFAIL_MSG(_("invalid message box return value"));
1125 bOk
= file
.Open(filename
, wxFile::write_append
);
1128 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1132 bOk
= file
.Create(filename
);
1136 *pFilename
= filename
;
1141 #endif // wxUSE_FILE
1143 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1147 // ----------------------------------------------------------------------------
1148 // wxLogTextCtrl implementation
1149 // ----------------------------------------------------------------------------
1151 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1153 m_pTextCtrl
= pTextCtrl
;
1156 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1161 #if defined(__WXMAC__)
1162 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1163 // translation must be done in wxTextCtrl, not here! (FIXME)
1164 msg
<< szString
<< wxT('\r');
1166 msg
<< szString
<< wxT('\n');
1169 m_pTextCtrl
->AppendText(msg
);
1172 #endif // wxUSE_TEXTCTRL