]>
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 // ----------------------------------------------------------------------------
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
)
90 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
92 // buffer is too small?
93 wxFAIL_MSG(_T("strftime() failed"));
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 wxButton
*m_btnDetails
;
129 bool m_showingDetails
;
131 // the controls which are not shown initially (but only when details
132 // button is pressed)
133 wxListCtrl
*m_listctrl
;
135 wxStaticLine
*m_statline
;
136 #endif // wxUSE_STATLINE
141 // the translated "Details" string
142 static wxString ms_details
;
144 DECLARE_EVENT_TABLE()
145 DECLARE_NO_COPY_CLASS(wxLogDialog
)
148 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
149 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
150 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
152 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
154 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
157 #endif // wxUSE_LOG_DIALOG
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 #if wxUSE_FILE && wxUSE_FILEDLG
165 // pass an uninitialized file object, the function will ask the user for the
166 // filename and try to open it, returns TRUE on success (file was opened),
167 // FALSE if file couldn't be opened/created and -1 if the file selection
168 // dialog was cancelled
169 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 // we use a global variable to store the frame pointer for wxLogStatus - bad,
178 // but it's the easiest way
179 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
181 // ============================================================================
183 // ============================================================================
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 // accepts an additional argument which tells to which frame the output should
191 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
195 wxLog
*pLog
= wxLog::GetActiveTarget();
196 if ( pLog
!= NULL
) {
197 msg
.PrintfV(szFormat
, argptr
);
199 wxASSERT( gs_pFrame
== NULL
); // should be reset!
201 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
202 gs_pFrame
= (wxFrame
*) NULL
;
206 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
209 va_start(argptr
, szFormat
);
210 wxVLogStatus(pFrame
, szFormat
, argptr
);
214 // ----------------------------------------------------------------------------
215 // wxLogGui implementation (FIXME MT-unsafe)
216 // ----------------------------------------------------------------------------
223 void wxLogGui::Clear()
227 m_bHasMessages
= FALSE
;
234 void wxLogGui::Flush()
236 if ( !m_bHasMessages
)
239 // do it right now to block any new calls to Flush() while we're here
240 m_bHasMessages
= FALSE
;
242 wxString appName
= wxTheApp
->GetAppName();
244 appName
[0u] = wxToupper(appName
[0u]);
247 wxString titleFormat
;
249 titleFormat
= _("%s Error");
252 else if ( m_bWarnings
) {
253 titleFormat
= _("%s Warning");
254 style
= wxICON_EXCLAMATION
;
257 titleFormat
= _("%s Information");
258 style
= wxICON_INFORMATION
;
262 title
.Printf(titleFormat
, appName
.c_str());
264 size_t nMsgCount
= m_aMessages
.Count();
266 // avoid showing other log dialogs until we're done with the dialog we're
267 // showing right now: nested modal dialogs make for really bad UI!
271 if ( nMsgCount
== 1 )
273 str
= m_aMessages
[0];
275 else // more than one message
279 wxLogDialog
dlg(NULL
,
280 m_aMessages
, m_aSeverity
, m_aTimes
,
283 // clear the message list before showing the dialog because while it's
284 // shown some new messages may appear
287 (void)dlg
.ShowModal();
288 #else // !wxUSE_LOG_DIALOG
289 // concatenate all strings (but not too many to not overfill the msg box)
292 // start from the most recent message
293 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
294 // for Windows strings longer than this value are wrapped (NT 4.0)
295 const size_t nMsgLineWidth
= 156;
297 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
299 if ( nLines
> 25 ) // don't put too many lines in message box
302 str
<< m_aMessages
[n
- 1] << wxT("\n");
304 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
307 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
308 // situation without it
311 wxMessageBox(str
, title
, wxOK
| style
);
313 // no undisplayed messages whatsoever
317 // allow flushing the logs again
321 // log all kinds of messages
322 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
329 m_aMessages
.Add(szString
);
330 m_aSeverity
.Add(wxLOG_Message
);
331 m_aTimes
.Add((long)t
);
332 m_bHasMessages
= TRUE
;
339 // find the top window and set it's status text if it has any
340 wxFrame
*pFrame
= gs_pFrame
;
341 if ( pFrame
== NULL
) {
342 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
343 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
344 pFrame
= (wxFrame
*)pWin
;
348 if ( pFrame
&& pFrame
->GetStatusBar() )
349 pFrame
->SetStatusText(szString
);
351 #endif // wxUSE_STATUSBAR
362 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
363 // don't prepend debug/trace here: it goes to the
364 // debug window anyhow
366 OutputDebugString(str
);
368 // send them to stderr
369 wxFprintf(stderr
, wxT("[%s] %s\n"),
370 level
== wxLOG_Trace
? wxT("Trace")
376 #endif // __WXDEBUG__
380 case wxLOG_FatalError
:
381 // show this one immediately
382 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
388 #if !wxUSE_LOG_DIALOG
389 // discard earlier informational messages if this is the 1st
390 // error because they might not make sense any more and showing
391 // them in a message box might be confusing
395 #endif // wxUSE_LOG_DIALOG
402 // for the warning we don't discard the info messages
406 m_aMessages
.Add(szString
);
407 m_aSeverity
.Add((int)level
);
408 m_aTimes
.Add((long)t
);
409 m_bHasMessages
= TRUE
;
414 // ----------------------------------------------------------------------------
415 // wxLogWindow and wxLogFrame implementation
416 // ----------------------------------------------------------------------------
420 class wxLogFrame
: public wxFrame
424 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
425 virtual ~wxLogFrame();
428 void OnClose(wxCommandEvent
& event
);
429 void OnCloseWindow(wxCloseEvent
& event
);
431 void OnSave (wxCommandEvent
& event
);
433 void OnClear(wxCommandEvent
& event
);
435 void OnIdle(wxIdleEvent
&);
438 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
441 // use standard ids for our commands!
444 Menu_Close
= wxID_CLOSE
,
445 Menu_Save
= wxID_SAVE
,
446 Menu_Clear
= wxID_CLEAR
449 // common part of OnClose() and OnCloseWindow()
452 wxTextCtrl
*m_pTextCtrl
;
455 DECLARE_EVENT_TABLE()
456 DECLARE_NO_COPY_CLASS(wxLogFrame
)
459 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
460 // wxLogWindow menu events
461 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
463 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
465 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
467 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
470 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
471 : wxFrame(pParent
, -1, szTitle
)
475 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
479 // needed for Win32 to avoid 65Kb limit but it doesn't work well
480 // when using RichEdit 2.0 which we always do in the Unicode build
483 #endif // !wxUSE_UNICODE
488 wxMenuBar
*pMenuBar
= new wxMenuBar
;
489 wxMenu
*pMenu
= new wxMenu
;
491 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
493 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
494 pMenu
->AppendSeparator();
495 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
496 pMenuBar
->Append(pMenu
, _("&Log"));
497 SetMenuBar(pMenuBar
);
498 #endif // wxUSE_MENUS
501 // status bar for menu prompts
503 #endif // wxUSE_STATUSBAR
505 m_log
->OnFrameCreate(this);
508 void wxLogFrame::DoClose()
510 if ( m_log
->OnFrameClose(this) )
512 // instead of closing just hide the window to be able to Show() it
518 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
523 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
529 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
534 int rc
= OpenLogFile(file
, &filename
);
543 // retrieve text and save it
544 // -------------------------
545 int nLines
= m_pTextCtrl
->GetNumberOfLines();
546 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
547 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
548 wxTextFile::GetEOL());
555 wxLogError(_("Can't save log contents to file."));
558 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
564 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
566 m_pTextCtrl
->Clear();
569 wxLogFrame::~wxLogFrame()
571 m_log
->OnFrameDelete(this);
577 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
578 const wxChar
*szTitle
,
582 PassMessages(bDoPass
);
584 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
587 m_pLogFrame
->Show(TRUE
);
590 void wxLogWindow::Show(bool bShow
)
592 m_pLogFrame
->Show(bShow
);
595 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
597 // first let the previous logger show it
598 wxLogPassThrough::DoLog(level
, szString
, t
);
603 // by default, these messages are ignored by wxLog, so process
605 if ( !wxIsEmpty(szString
) )
608 str
<< _("Status: ") << szString
;
613 // don't put trace messages in the text window for 2 reasons:
614 // 1) there are too many of them
615 // 2) they may provoke other trace messages thus sending a program
616 // into an infinite loop
621 // and this will format it nicely and call our DoLogString()
622 wxLog::DoLog(level
, szString
, t
);
627 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
629 // put the text into our window
630 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
632 // remove selection (WriteText is in fact ReplaceSelection)
634 long nLen
= pText
->GetLastPosition();
635 pText
->SetSelection(nLen
, nLen
);
640 msg
<< szString
<< wxT('\n');
642 pText
->AppendText(msg
);
644 // TODO ensure that the line can be seen
647 wxFrame
*wxLogWindow::GetFrame() const
652 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
656 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
662 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
664 m_pLogFrame
= (wxLogFrame
*)NULL
;
667 wxLogWindow::~wxLogWindow()
669 // may be NULL if log frame already auto destroyed itself
673 // ----------------------------------------------------------------------------
675 // ----------------------------------------------------------------------------
679 static const size_t MARGIN
= 10;
681 wxString
wxLogDialog::ms_details
;
683 wxLogDialog::wxLogDialog(wxWindow
*parent
,
684 const wxArrayString
& messages
,
685 const wxArrayInt
& severity
,
686 const wxArrayLong
& times
,
687 const wxString
& caption
,
689 : wxDialog(parent
, -1, caption
,
690 wxDefaultPosition
, wxDefaultSize
,
691 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
693 if ( ms_details
.IsEmpty() )
695 // ensure that we won't loop here if wxGetTranslation()
696 // happens to pop up a Log message while translating this :-)
697 ms_details
= wxTRANSLATE("&Details");
698 ms_details
= wxGetTranslation(ms_details
);
701 size_t count
= messages
.GetCount();
702 m_messages
.Alloc(count
);
703 m_severity
.Alloc(count
);
704 m_times
.Alloc(count
);
706 for ( size_t n
= 0; n
< count
; n
++ )
708 wxString msg
= messages
[n
];
711 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
712 msg
= msg
.AfterFirst(_T('\n'));
714 m_severity
.Add(severity
[n
]);
715 m_times
.Add(times
[n
]);
720 m_showingDetails
= FALSE
; // not initially
721 m_listctrl
= (wxListCtrl
*)NULL
;
724 m_statline
= (wxStaticLine
*)NULL
;
725 #endif // wxUSE_STATLINE
728 m_btnSave
= (wxButton
*)NULL
;
731 // create the controls which are always shown and layout them: we use
732 // sizers even though our window is not resizeable to calculate the size of
733 // the dialog properly
734 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
735 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
736 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
738 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
739 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
740 // translates into click on cancel button)
741 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
742 sizerButtons
->Add(btnOk
, 0, wxCENTRE
| wxBOTTOM
, MARGIN
/2);
743 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
744 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
748 switch ( style
& wxICON_MASK
)
751 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
753 bitmap
.SetId(wxICON_SMALL_ERROR
);
757 case wxICON_INFORMATION
:
758 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
760 bitmap
.SetId(wxICON_SMALL_INFO
);
765 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
767 bitmap
.SetId(wxICON_SMALL_WARNING
);
772 wxFAIL_MSG(_T("incorrect log style"));
774 sizerAll
->Add(new wxStaticBitmap(this, -1, bitmap
), 0);
777 const wxString
& message
= messages
.Last();
778 sizerAll
->Add(CreateTextSizer(message
), 1,
779 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
780 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
| wxLEFT
, MARGIN
);
782 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
787 // see comments in OnDetails()
789 // Note: Doing this, this way, triggered a nasty bug in
790 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
791 // either of maxWidth or maxHeight was set. This symptom has been
792 // fixed there, but it is a problem that remains as long as we allow
793 // unchecked access to the internal size members. We really need to
794 // encapuslate window sizes more cleanly and make it clear when -1 will
795 // be substituted and when it will not.
797 wxSize size
= sizerTop
->Fit(this);
798 m_maxHeight
= size
.y
;
799 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
803 // this can't happen any more as we don't use this dialog in this case
807 // no details... it's easier to disable a button than to change the
808 // dialog layout depending on whether we have details or not
809 m_btnDetails
->Disable();
816 void wxLogDialog::CreateDetailsControls()
818 // create the save button and separator line if possible
820 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
824 m_statline
= new wxStaticLine(this, -1);
825 #endif // wxUSE_STATLINE
827 // create the list ctrl now
828 m_listctrl
= new wxListCtrl(this, -1,
829 wxDefaultPosition
, wxDefaultSize
,
835 // no need to translate these strings as they're not shown to the
836 // user anyhow (we use wxLC_NO_HEADER style)
837 m_listctrl
->InsertColumn(0, _T("Message"));
838 m_listctrl
->InsertColumn(1, _T("Time"));
840 // prepare the imagelist
841 static const int ICON_SIZE
= 16;
842 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
844 // order should be the same as in the switch below!
845 static const wxChar
* icons
[] =
852 bool loadedIcons
= TRUE
;
855 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
857 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
858 wxSize(ICON_SIZE
, ICON_SIZE
));
860 // This may very well fail if there are insufficient colours available.
861 // Degrade gracefully.
872 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
876 wxString fmt
= wxLog::GetTimestamp();
883 size_t count
= m_messages
.GetCount();
884 for ( size_t n
= 0; n
< count
; n
++ )
891 switch ( m_severity
[n
] )
905 else // failed to load images
911 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
912 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
915 // let the columns size themselves
916 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
917 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
919 // calculate an approximately nice height for the listctrl
920 int height
= GetCharHeight()*(count
+ 4);
922 // but check that the dialog won't fall fown from the screen
924 // we use GetMinHeight() to get the height of the dialog part without the
925 // details and we consider that the "Save" button below and the separator
926 // line (and the margins around it) take about as much, hence double it
927 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
929 // we should leave a margin
933 m_listctrl
->SetSize(-1, wxMin(height
, heightMax
));
936 void wxLogDialog::OnListSelect(wxListEvent
& event
)
938 // we can't just disable the control because this looks ugly under Windows
939 // (wrong bg colour, no scrolling...), but we still want to disable
940 // selecting items - it makes no sense here
941 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
944 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
951 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
955 int rc
= OpenLogFile(file
);
964 wxString fmt
= wxLog::GetTimestamp();
971 size_t count
= m_messages
.GetCount();
972 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
975 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
978 << wxTextFile::GetEOL();
980 ok
= file
.Write(line
);
987 wxLogError(_("Can't save log contents to file."));
988 #endif // wxUSE_FILEDLG
993 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
995 wxSizer
*sizer
= GetSizer();
997 if ( m_showingDetails
)
999 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1001 sizer
->Detach( m_listctrl
);
1004 sizer
->Detach( m_statline
);
1005 #endif // wxUSE_STATLINE
1008 sizer
->Detach( m_btnSave
);
1009 #endif // wxUSE_FILE
1011 else // show details now
1013 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1017 CreateDetailsControls();
1021 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1022 #endif // wxUSE_STATLINE
1024 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1026 // VZ: this doesn't work as this becomes the initial (and not only
1027 // minimal) listctrl height as well - why?
1029 // allow the user to make the dialog shorter than its initial height -
1030 // without this it wouldn't work as the list ctrl would have been
1032 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1036 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1037 #endif // wxUSE_FILE
1040 m_showingDetails
= !m_showingDetails
;
1042 // in any case, our size changed - relayout everything and set new hints
1043 // ---------------------------------------------------------------------
1045 // we have to reset min size constraints or Fit() would never reduce the
1046 // dialog size when collapsing it and we have to reset max constraint
1047 // because it wouldn't expand it otherwise
1052 // wxSizer::FitSize() is private, otherwise we might use it directly...
1053 wxSize sizeTotal
= GetSize(),
1054 sizeClient
= GetClientSize();
1056 wxSize size
= sizer
->GetMinSize();
1057 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1058 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1060 // we don't want to allow expanding the dialog in vertical direction as
1061 // this would show the "hidden" details but we can resize the dialog
1062 // vertically while the details are shown
1063 if ( !m_showingDetails
)
1064 m_maxHeight
= size
.y
;
1066 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1068 // don't change the width when expanding/collapsing
1069 SetSize(-1, size
.y
);
1072 // VS: this is neccessary in order to force frame redraw under
1073 // WindowMaker or fvwm2 (and probably other broken WMs).
1074 // Otherwise, detailed list wouldn't be displayed.
1079 wxLogDialog::~wxLogDialog()
1083 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1087 #endif // wxUSE_LOG_DIALOG
1089 #if wxUSE_FILE && wxUSE_FILEDLG
1091 // pass an uninitialized file object, the function will ask the user for the
1092 // filename and try to open it, returns TRUE on success (file was opened),
1093 // FALSE if file couldn't be opened/created and -1 if the file selection
1094 // dialog was cancelled
1095 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1097 // get the file name
1098 // -----------------
1099 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1108 if ( wxFile::Exists(filename
) ) {
1109 bool bAppend
= FALSE
;
1111 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1113 switch ( wxMessageBox(strMsg
, _("Question"),
1114 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1127 wxFAIL_MSG(_("invalid message box return value"));
1131 bOk
= file
.Open(filename
, wxFile::write_append
);
1134 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1138 bOk
= file
.Create(filename
);
1142 *pFilename
= filename
;
1147 #endif // wxUSE_FILE
1149 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1151 #if wxUSE_LOG && wxUSE_TEXTCTRL
1153 // ----------------------------------------------------------------------------
1154 // wxLogTextCtrl implementation
1155 // ----------------------------------------------------------------------------
1157 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1159 m_pTextCtrl
= pTextCtrl
;
1162 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1167 #if defined(__WXMAC__)
1168 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1169 // translation must be done in wxTextCtrl, not here! (FIXME)
1170 msg
<< szString
<< wxT('\r');
1172 msg
<< szString
<< wxT('\n');
1175 m_pTextCtrl
->AppendText(msg
);
1178 #endif // wxUSE_LOG && wxUSE_TEXTCTRL