]>
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 // the suffix we add to the button to show that the dialog can be expanded
77 #define EXPAND_SUFFIX _T(" >>")
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
85 // this function is a wrapper around strftime(3)
86 // allows to exclude the usage of wxDateTime
87 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
94 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
96 // buffer is too small?
97 wxFAIL_MSG(_T("strftime() failed"));
104 class wxLogDialog
: public wxDialog
107 wxLogDialog(wxWindow
*parent
,
108 const wxArrayString
& messages
,
109 const wxArrayInt
& severity
,
110 const wxArrayLong
& timess
,
111 const wxString
& caption
,
113 virtual ~wxLogDialog();
116 void OnOk(wxCommandEvent
& event
);
117 void OnDetails(wxCommandEvent
& event
);
119 void OnSave(wxCommandEvent
& event
);
121 void OnListSelect(wxListEvent
& event
);
124 // create controls needed for the details display
125 void CreateDetailsControls();
127 // the data for the listctrl
128 wxArrayString m_messages
;
129 wxArrayInt m_severity
;
132 // the "toggle" button and its state
133 wxButton
*m_btnDetails
;
134 bool m_showingDetails
;
136 // the controls which are not shown initially (but only when details
137 // button is pressed)
138 wxListCtrl
*m_listctrl
;
140 wxStaticLine
*m_statline
;
141 #endif // wxUSE_STATLINE
146 // the translated "Details" string
147 static wxString ms_details
;
149 DECLARE_EVENT_TABLE()
150 DECLARE_NO_COPY_CLASS(wxLogDialog
)
153 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
154 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
155 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
157 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
159 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
162 #endif // wxUSE_LOG_DIALOG
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 #if wxUSE_FILE && wxUSE_FILEDLG
170 // pass an uninitialized file object, the function will ask the user for the
171 // filename and try to open it, returns TRUE on success (file was opened),
172 // FALSE if file couldn't be opened/created and -1 if the file selection
173 // dialog was cancelled
174 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 // we use a global variable to store the frame pointer for wxLogStatus - bad,
183 // but it's the easiest way
184 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
186 // ============================================================================
188 // ============================================================================
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 // accepts an additional argument which tells to which frame the output should
196 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
200 wxLog
*pLog
= wxLog::GetActiveTarget();
201 if ( pLog
!= NULL
) {
202 msg
.PrintfV(szFormat
, argptr
);
204 wxASSERT( gs_pFrame
== NULL
); // should be reset!
207 wxLog::OnLog(wxLOG_Status
, msg
, 0);
209 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
211 gs_pFrame
= (wxFrame
*) NULL
;
215 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
218 va_start(argptr
, szFormat
);
219 wxVLogStatus(pFrame
, szFormat
, argptr
);
223 // ----------------------------------------------------------------------------
224 // wxLogGui implementation (FIXME MT-unsafe)
225 // ----------------------------------------------------------------------------
232 void wxLogGui::Clear()
236 m_bHasMessages
= FALSE
;
243 void wxLogGui::Flush()
245 if ( !m_bHasMessages
)
248 // do it right now to block any new calls to Flush() while we're here
249 m_bHasMessages
= FALSE
;
251 wxString appName
= wxTheApp
->GetAppName();
253 appName
[0u] = wxToupper(appName
[0u]);
256 wxString titleFormat
;
258 titleFormat
= _("%s Error");
261 else if ( m_bWarnings
) {
262 titleFormat
= _("%s Warning");
263 style
= wxICON_EXCLAMATION
;
266 titleFormat
= _("%s Information");
267 style
= wxICON_INFORMATION
;
271 title
.Printf(titleFormat
, appName
.c_str());
273 size_t nMsgCount
= m_aMessages
.Count();
275 // avoid showing other log dialogs until we're done with the dialog we're
276 // showing right now: nested modal dialogs make for really bad UI!
280 if ( nMsgCount
== 1 )
282 str
= m_aMessages
[0];
284 else // more than one message
288 wxLogDialog
dlg(NULL
,
289 m_aMessages
, m_aSeverity
, m_aTimes
,
292 // clear the message list before showing the dialog because while it's
293 // shown some new messages may appear
296 (void)dlg
.ShowModal();
297 #else // !wxUSE_LOG_DIALOG
298 // concatenate all strings (but not too many to not overfill the msg box)
301 // start from the most recent message
302 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
303 // for Windows strings longer than this value are wrapped (NT 4.0)
304 const size_t nMsgLineWidth
= 156;
306 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
308 if ( nLines
> 25 ) // don't put too many lines in message box
311 str
<< m_aMessages
[n
- 1] << wxT("\n");
313 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
316 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
317 // situation without it
320 wxMessageBox(str
, title
, wxOK
| style
);
322 // no undisplayed messages whatsoever
326 // allow flushing the logs again
330 // log all kinds of messages
331 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
338 m_aMessages
.Add(szString
);
339 m_aSeverity
.Add(wxLOG_Message
);
340 m_aTimes
.Add((long)t
);
341 m_bHasMessages
= TRUE
;
348 // find the top window and set it's status text if it has any
349 wxFrame
*pFrame
= gs_pFrame
;
350 if ( pFrame
== NULL
) {
351 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
352 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
353 pFrame
= (wxFrame
*)pWin
;
357 if ( pFrame
&& pFrame
->GetStatusBar() )
358 pFrame
->SetStatusText(szString
);
360 #endif // wxUSE_STATUSBAR
371 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
372 // don't prepend debug/trace here: it goes to the
373 // debug window anyhow
375 OutputDebugString(str
);
377 // send them to stderr
378 wxFprintf(stderr
, wxT("[%s] %s\n"),
379 level
== wxLOG_Trace
? wxT("Trace")
385 #endif // __WXDEBUG__
389 case wxLOG_FatalError
:
390 // show this one immediately
391 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
397 #if !wxUSE_LOG_DIALOG
398 // discard earlier informational messages if this is the 1st
399 // error because they might not make sense any more and showing
400 // them in a message box might be confusing
404 #endif // wxUSE_LOG_DIALOG
411 // for the warning we don't discard the info messages
415 m_aMessages
.Add(szString
);
416 m_aSeverity
.Add((int)level
);
417 m_aTimes
.Add((long)t
);
418 m_bHasMessages
= TRUE
;
423 // ----------------------------------------------------------------------------
424 // wxLogWindow and wxLogFrame implementation
425 // ----------------------------------------------------------------------------
429 class wxLogFrame
: public wxFrame
433 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
434 virtual ~wxLogFrame();
437 void OnClose(wxCommandEvent
& event
);
438 void OnCloseWindow(wxCloseEvent
& event
);
440 void OnSave (wxCommandEvent
& event
);
442 void OnClear(wxCommandEvent
& event
);
445 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
448 // use standard ids for our commands!
451 Menu_Close
= wxID_CLOSE
,
452 Menu_Save
= wxID_SAVE
,
453 Menu_Clear
= wxID_CLEAR
456 // common part of OnClose() and OnCloseWindow()
459 wxTextCtrl
*m_pTextCtrl
;
462 DECLARE_EVENT_TABLE()
463 DECLARE_NO_COPY_CLASS(wxLogFrame
)
466 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
467 // wxLogWindow menu events
468 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
470 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
472 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
474 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
477 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
478 : wxFrame(pParent
, -1, szTitle
)
482 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
486 // needed for Win32 to avoid 65Kb limit but it doesn't work well
487 // when using RichEdit 2.0 which we always do in the Unicode build
490 #endif // !wxUSE_UNICODE
495 wxMenuBar
*pMenuBar
= new wxMenuBar
;
496 wxMenu
*pMenu
= new wxMenu
;
498 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
500 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
501 pMenu
->AppendSeparator();
502 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
503 pMenuBar
->Append(pMenu
, _("&Log"));
504 SetMenuBar(pMenuBar
);
505 #endif // wxUSE_MENUS
508 // status bar for menu prompts
510 #endif // wxUSE_STATUSBAR
512 m_log
->OnFrameCreate(this);
515 void wxLogFrame::DoClose()
517 if ( m_log
->OnFrameClose(this) )
519 // instead of closing just hide the window to be able to Show() it
525 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
530 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
536 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
541 int rc
= OpenLogFile(file
, &filename
);
550 // retrieve text and save it
551 // -------------------------
552 int nLines
= m_pTextCtrl
->GetNumberOfLines();
553 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
554 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
555 wxTextFile::GetEOL());
562 wxLogError(_("Can't save log contents to file."));
565 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
571 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
573 m_pTextCtrl
->Clear();
576 wxLogFrame::~wxLogFrame()
578 m_log
->OnFrameDelete(this);
584 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
585 const wxChar
*szTitle
,
589 PassMessages(bDoPass
);
591 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
594 m_pLogFrame
->Show(TRUE
);
597 void wxLogWindow::Show(bool bShow
)
599 m_pLogFrame
->Show(bShow
);
602 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
604 // first let the previous logger show it
605 wxLogPassThrough::DoLog(level
, szString
, t
);
610 // by default, these messages are ignored by wxLog, so process
612 if ( !wxIsEmpty(szString
) )
615 str
<< _("Status: ") << szString
;
620 // don't put trace messages in the text window for 2 reasons:
621 // 1) there are too many of them
622 // 2) they may provoke other trace messages thus sending a program
623 // into an infinite loop
628 // and this will format it nicely and call our DoLogString()
629 wxLog::DoLog(level
, szString
, t
);
634 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
636 // put the text into our window
637 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
639 // remove selection (WriteText is in fact ReplaceSelection)
641 long nLen
= pText
->GetLastPosition();
642 pText
->SetSelection(nLen
, nLen
);
647 msg
<< szString
<< wxT('\n');
649 pText
->AppendText(msg
);
651 // TODO ensure that the line can be seen
654 wxFrame
*wxLogWindow::GetFrame() const
659 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
663 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
669 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
671 m_pLogFrame
= (wxLogFrame
*)NULL
;
674 wxLogWindow::~wxLogWindow()
676 // may be NULL if log frame already auto destroyed itself
680 // ----------------------------------------------------------------------------
682 // ----------------------------------------------------------------------------
686 static const size_t MARGIN
= 10;
688 wxString
wxLogDialog::ms_details
;
690 wxLogDialog::wxLogDialog(wxWindow
*parent
,
691 const wxArrayString
& messages
,
692 const wxArrayInt
& severity
,
693 const wxArrayLong
& times
,
694 const wxString
& caption
,
696 : wxDialog(parent
, -1, caption
,
697 wxDefaultPosition
, wxDefaultSize
,
698 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
700 if ( ms_details
.IsEmpty() )
702 // ensure that we won't loop here if wxGetTranslation()
703 // happens to pop up a Log message while translating this :-)
704 ms_details
= wxTRANSLATE("&Details");
705 ms_details
= wxGetTranslation(ms_details
);
708 size_t count
= messages
.GetCount();
709 m_messages
.Alloc(count
);
710 m_severity
.Alloc(count
);
711 m_times
.Alloc(count
);
713 for ( size_t n
= 0; n
< count
; n
++ )
715 wxString msg
= messages
[n
];
718 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
719 msg
= msg
.AfterFirst(_T('\n'));
721 m_severity
.Add(severity
[n
]);
722 m_times
.Add(times
[n
]);
727 m_showingDetails
= FALSE
; // not initially
728 m_listctrl
= (wxListCtrl
*)NULL
;
731 m_statline
= (wxStaticLine
*)NULL
;
732 #endif // wxUSE_STATLINE
735 m_btnSave
= (wxButton
*)NULL
;
738 // create the controls which are always shown and layout them: we use
739 // sizers even though our window is not resizeable to calculate the size of
740 // the dialog properly
741 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
742 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
743 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
745 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
746 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
747 // translates into click on cancel button)
748 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
749 sizerButtons
->Add(btnOk
, 0, wxCENTRE
| wxBOTTOM
, MARGIN
/2);
750 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
751 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
755 switch ( style
& wxICON_MASK
)
758 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
760 bitmap
.SetId(wxICON_SMALL_ERROR
);
764 case wxICON_INFORMATION
:
765 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
767 bitmap
.SetId(wxICON_SMALL_INFO
);
772 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
774 bitmap
.SetId(wxICON_SMALL_WARNING
);
779 wxFAIL_MSG(_T("incorrect log style"));
781 sizerAll
->Add(new wxStaticBitmap(this, -1, bitmap
), 0);
784 const wxString
& message
= messages
.Last();
785 sizerAll
->Add(CreateTextSizer(message
), 1,
786 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
787 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
| wxLEFT
, MARGIN
);
789 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
);
810 // this can't happen any more as we don't use this dialog in this case
814 // no details... it's easier to disable a button than to change the
815 // dialog layout depending on whether we have details or not
816 m_btnDetails
->Disable();
823 void wxLogDialog::CreateDetailsControls()
825 // create the save button and separator line if possible
827 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
831 m_statline
= new wxStaticLine(this, -1);
832 #endif // wxUSE_STATLINE
834 // create the list ctrl now
835 m_listctrl
= new wxListCtrl(this, -1,
836 wxDefaultPosition
, wxDefaultSize
,
842 // no need to translate these strings as they're not shown to the
843 // user anyhow (we use wxLC_NO_HEADER style)
844 m_listctrl
->InsertColumn(0, _T("Message"));
845 m_listctrl
->InsertColumn(1, _T("Time"));
847 // prepare the imagelist
848 static const int ICON_SIZE
= 16;
849 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
851 // order should be the same as in the switch below!
852 static const wxChar
* icons
[] =
859 bool loadedIcons
= TRUE
;
862 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
864 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
865 wxSize(ICON_SIZE
, ICON_SIZE
));
867 // This may very well fail if there are insufficient colours available.
868 // Degrade gracefully.
879 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
883 wxString fmt
= wxLog::GetTimestamp();
890 size_t count
= m_messages
.GetCount();
891 for ( size_t n
= 0; n
< count
; n
++ )
898 switch ( m_severity
[n
] )
912 else // failed to load images
918 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
919 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
922 // let the columns size themselves
923 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
924 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
926 // calculate an approximately nice height for the listctrl
927 int height
= GetCharHeight()*(count
+ 4);
929 // but check that the dialog won't fall fown from the screen
931 // we use GetMinHeight() to get the height of the dialog part without the
932 // details and we consider that the "Save" button below and the separator
933 // line (and the margins around it) take about as much, hence double it
934 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
936 // we should leave a margin
940 m_listctrl
->SetSize(-1, wxMin(height
, heightMax
));
943 void wxLogDialog::OnListSelect(wxListEvent
& event
)
945 // we can't just disable the control because this looks ugly under Windows
946 // (wrong bg colour, no scrolling...), but we still want to disable
947 // selecting items - it makes no sense here
948 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
951 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
958 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
962 int rc
= OpenLogFile(file
);
971 wxString fmt
= wxLog::GetTimestamp();
978 size_t count
= m_messages
.GetCount();
979 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
982 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
985 << wxTextFile::GetEOL();
987 ok
= file
.Write(line
);
994 wxLogError(_("Can't save log contents to file."));
995 #endif // wxUSE_FILEDLG
1000 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1002 wxSizer
*sizer
= GetSizer();
1004 if ( m_showingDetails
)
1006 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1008 sizer
->Detach( m_listctrl
);
1011 sizer
->Detach( m_statline
);
1012 #endif // wxUSE_STATLINE
1015 sizer
->Detach( m_btnSave
);
1016 #endif // wxUSE_FILE
1018 else // show details now
1020 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1024 CreateDetailsControls();
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
);
1075 // don't change the width when expanding/collapsing
1076 SetSize(-1, size
.y
);
1079 // VS: this is neccessary in order to force frame redraw under
1080 // WindowMaker or fvwm2 (and probably other broken WMs).
1081 // Otherwise, detailed list wouldn't be displayed.
1086 wxLogDialog::~wxLogDialog()
1090 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1094 #endif // wxUSE_LOG_DIALOG
1096 #if wxUSE_FILE && wxUSE_FILEDLG
1098 // pass an uninitialized file object, the function will ask the user for the
1099 // filename and try to open it, returns TRUE on success (file was opened),
1100 // FALSE if file couldn't be opened/created and -1 if the file selection
1101 // dialog was cancelled
1102 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1104 // get the file name
1105 // -----------------
1106 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1115 if ( wxFile::Exists(filename
) ) {
1116 bool bAppend
= FALSE
;
1118 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1120 switch ( wxMessageBox(strMsg
, _("Question"),
1121 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1134 wxFAIL_MSG(_("invalid message box return value"));
1138 bOk
= file
.Open(filename
, wxFile::write_append
);
1141 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1145 bOk
= file
.Create(filename
);
1149 *pFilename
= filename
;
1154 #endif // wxUSE_FILE
1156 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1158 #if wxUSE_LOG && wxUSE_TEXTCTRL
1160 // ----------------------------------------------------------------------------
1161 // wxLogTextCtrl implementation
1162 // ----------------------------------------------------------------------------
1164 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1166 m_pTextCtrl
= pTextCtrl
;
1169 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1174 #if defined(__WXMAC__)
1175 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1176 // translation must be done in wxTextCtrl, not here! (FIXME)
1177 msg
<< szString
<< wxT('\r');
1179 msg
<< szString
<< wxT('\n');
1182 m_pTextCtrl
->AppendText(msg
);
1185 #endif // wxUSE_LOG && wxUSE_TEXTCTRL