]>
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 // 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"
67 #include "wx/listctrl.h"
68 #include "wx/imaglist.h"
70 #else // !wxUSE_LOG_DIALOG
71 #include "wx/msgdlg.h"
72 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
74 // the suffix we add to the button to show that the dialog can be expanded
75 #define EXPAND_SUFFIX _T(" >>")
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
83 // this function is a wrapper around strftime(3)
84 // allows to exclude the usage of wxDateTime
85 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
88 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
90 // buffer is too small?
91 wxFAIL_MSG(_T("strftime() failed"));
97 class wxLogDialog
: public wxDialog
100 wxLogDialog(wxWindow
*parent
,
101 const wxArrayString
& messages
,
102 const wxArrayInt
& severity
,
103 const wxArrayLong
& timess
,
104 const wxString
& caption
,
106 virtual ~wxLogDialog();
109 void OnOk(wxCommandEvent
& event
);
110 void OnDetails(wxCommandEvent
& event
);
112 void OnSave(wxCommandEvent
& event
);
114 void OnListSelect(wxListEvent
& event
);
117 // create controls needed for the details display
118 void CreateDetailsControls();
120 // the data for the listctrl
121 wxArrayString m_messages
;
122 wxArrayInt m_severity
;
125 // the "toggle" button and its state
126 wxButton
*m_btnDetails
;
127 bool m_showingDetails
;
129 // the controls which are not shown initially (but only when details
130 // button is pressed)
131 wxListCtrl
*m_listctrl
;
133 wxStaticLine
*m_statline
;
134 #endif // wxUSE_STATLINE
139 // the translated "Details" string
140 static wxString ms_details
;
142 DECLARE_EVENT_TABLE()
143 DECLARE_NO_COPY_CLASS(wxLogDialog
)
146 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
147 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
148 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
150 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
152 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
155 #endif // wxUSE_LOG_DIALOG
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 #if wxUSE_FILE && wxUSE_FILEDLG
163 // pass an uninitialized file object, the function will ask the user for the
164 // filename and try to open it, returns TRUE on success (file was opened),
165 // FALSE if file couldn't be opened/created and -1 if the file selection
166 // dialog was cancelled
167 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 // we use a global variable to store the frame pointer for wxLogStatus - bad,
176 // but it's the easiest way
177 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
179 // ============================================================================
181 // ============================================================================
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 // accepts an additional argument which tells to which frame the output should
189 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
193 wxLog
*pLog
= wxLog::GetActiveTarget();
194 if ( pLog
!= NULL
) {
195 msg
.PrintfV(szFormat
, argptr
);
197 wxASSERT( gs_pFrame
== NULL
); // should be reset!
199 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
200 gs_pFrame
= (wxFrame
*) NULL
;
204 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
207 va_start(argptr
, szFormat
);
208 wxVLogStatus(pFrame
, szFormat
, argptr
);
212 // ----------------------------------------------------------------------------
213 // wxLogGui implementation (FIXME MT-unsafe)
214 // ----------------------------------------------------------------------------
221 void wxLogGui::Clear()
225 m_bHasMessages
= FALSE
;
232 void wxLogGui::Flush()
234 if ( !m_bHasMessages
)
237 // do it right now to block any new calls to Flush() while we're here
238 m_bHasMessages
= FALSE
;
240 wxString appName
= wxTheApp
->GetAppName();
242 appName
[0u] = wxToupper(appName
[0u]);
245 wxString titleFormat
;
247 titleFormat
= _("%s Error");
250 else if ( m_bWarnings
) {
251 titleFormat
= _("%s Warning");
252 style
= wxICON_EXCLAMATION
;
255 titleFormat
= _("%s Information");
256 style
= wxICON_INFORMATION
;
260 title
.Printf(titleFormat
, appName
.c_str());
262 size_t nMsgCount
= m_aMessages
.Count();
264 // avoid showing other log dialogs until we're done with the dialog we're
265 // showing right now: nested modal dialogs make for really bad UI!
269 if ( nMsgCount
== 1 )
271 str
= m_aMessages
[0];
273 else // more than one message
277 wxLogDialog
dlg(NULL
,
278 m_aMessages
, m_aSeverity
, m_aTimes
,
281 // clear the message list before showing the dialog because while it's
282 // shown some new messages may appear
285 (void)dlg
.ShowModal();
286 #else // !wxUSE_LOG_DIALOG
287 // concatenate all strings (but not too many to not overfill the msg box)
290 // start from the most recent message
291 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
292 // for Windows strings longer than this value are wrapped (NT 4.0)
293 const size_t nMsgLineWidth
= 156;
295 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
297 if ( nLines
> 25 ) // don't put too many lines in message box
300 str
<< m_aMessages
[n
- 1] << wxT("\n");
302 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
305 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
306 // situation without it
309 wxMessageBox(str
, title
, wxOK
| style
);
311 // no undisplayed messages whatsoever
315 // allow flushing the logs again
319 // log all kinds of messages
320 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
327 m_aMessages
.Add(szString
);
328 m_aSeverity
.Add(wxLOG_Message
);
329 m_aTimes
.Add((long)t
);
330 m_bHasMessages
= TRUE
;
337 // find the top window and set it's status text if it has any
338 wxFrame
*pFrame
= gs_pFrame
;
339 if ( pFrame
== NULL
) {
340 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
341 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
342 pFrame
= (wxFrame
*)pWin
;
346 if ( pFrame
&& pFrame
->GetStatusBar() )
347 pFrame
->SetStatusText(szString
);
349 #endif // wxUSE_STATUSBAR
360 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
361 // don't prepend debug/trace here: it goes to the
362 // debug window anyhow
364 OutputDebugString(str
);
366 // send them to stderr
367 wxFprintf(stderr
, wxT("[%s] %s\n"),
368 level
== wxLOG_Trace
? wxT("Trace")
374 #endif // __WXDEBUG__
378 case wxLOG_FatalError
:
379 // show this one immediately
380 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
386 #if !wxUSE_LOG_DIALOG
387 // discard earlier informational messages if this is the 1st
388 // error because they might not make sense any more and showing
389 // them in a message box might be confusing
393 #endif // wxUSE_LOG_DIALOG
400 // for the warning we don't discard the info messages
404 m_aMessages
.Add(szString
);
405 m_aSeverity
.Add((int)level
);
406 m_aTimes
.Add((long)t
);
407 m_bHasMessages
= TRUE
;
412 // ----------------------------------------------------------------------------
413 // wxLogWindow and wxLogFrame implementation
414 // ----------------------------------------------------------------------------
418 class wxLogFrame
: public wxFrame
422 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
423 virtual ~wxLogFrame();
426 void OnClose(wxCommandEvent
& event
);
427 void OnCloseWindow(wxCloseEvent
& event
);
429 void OnSave (wxCommandEvent
& event
);
431 void OnClear(wxCommandEvent
& event
);
433 void OnIdle(wxIdleEvent
&);
436 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
439 // use standard ids for our commands!
442 Menu_Close
= wxID_CLOSE
,
443 Menu_Save
= wxID_SAVE
,
444 Menu_Clear
= wxID_CLEAR
447 // common part of OnClose() and OnCloseWindow()
450 wxTextCtrl
*m_pTextCtrl
;
453 DECLARE_EVENT_TABLE()
454 DECLARE_NO_COPY_CLASS(wxLogFrame
)
457 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
458 // wxLogWindow menu events
459 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
461 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
463 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
465 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
468 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
469 : wxFrame(pParent
, -1, szTitle
)
473 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
477 // needed for Win32 to avoid 65Kb limit but it doesn't work well
478 // when using RichEdit 2.0 which we always do in the Unicode build
481 #endif // !wxUSE_UNICODE
486 wxMenuBar
*pMenuBar
= new wxMenuBar
;
487 wxMenu
*pMenu
= new wxMenu
;
489 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
491 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
492 pMenu
->AppendSeparator();
493 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
494 pMenuBar
->Append(pMenu
, _("&Log"));
495 SetMenuBar(pMenuBar
);
496 #endif // wxUSE_MENUS
499 // status bar for menu prompts
501 #endif // wxUSE_STATUSBAR
503 m_log
->OnFrameCreate(this);
506 void wxLogFrame::DoClose()
508 if ( m_log
->OnFrameClose(this) )
510 // instead of closing just hide the window to be able to Show() it
516 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
521 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
527 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
532 int rc
= OpenLogFile(file
, &filename
);
541 // retrieve text and save it
542 // -------------------------
543 int nLines
= m_pTextCtrl
->GetNumberOfLines();
544 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
545 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
546 wxTextFile::GetEOL());
553 wxLogError(_("Can't save log contents to file."));
556 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
562 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
564 m_pTextCtrl
->Clear();
567 wxLogFrame::~wxLogFrame()
569 m_log
->OnFrameDelete(this);
575 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
576 const wxChar
*szTitle
,
580 PassMessages(bDoPass
);
582 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
585 m_pLogFrame
->Show(TRUE
);
588 void wxLogWindow::Show(bool bShow
)
590 m_pLogFrame
->Show(bShow
);
593 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
595 // first let the previous logger show it
596 wxLogPassThrough::DoLog(level
, szString
, t
);
601 // by default, these messages are ignored by wxLog, so process
603 if ( !wxIsEmpty(szString
) )
606 str
<< _("Status: ") << szString
;
611 // don't put trace messages in the text window for 2 reasons:
612 // 1) there are too many of them
613 // 2) they may provoke other trace messages thus sending a program
614 // into an infinite loop
619 // and this will format it nicely and call our DoLogString()
620 wxLog::DoLog(level
, szString
, t
);
625 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
627 // put the text into our window
628 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
630 // remove selection (WriteText is in fact ReplaceSelection)
632 long nLen
= pText
->GetLastPosition();
633 pText
->SetSelection(nLen
, nLen
);
638 msg
<< szString
<< wxT('\n');
640 pText
->AppendText(msg
);
642 // TODO ensure that the line can be seen
645 wxFrame
*wxLogWindow::GetFrame() const
650 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
654 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
660 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
662 m_pLogFrame
= (wxLogFrame
*)NULL
;
665 wxLogWindow::~wxLogWindow()
667 // may be NULL if log frame already auto destroyed itself
671 // ----------------------------------------------------------------------------
673 // ----------------------------------------------------------------------------
677 static const size_t MARGIN
= 10;
679 wxString
wxLogDialog::ms_details
;
681 wxLogDialog::wxLogDialog(wxWindow
*parent
,
682 const wxArrayString
& messages
,
683 const wxArrayInt
& severity
,
684 const wxArrayLong
& times
,
685 const wxString
& caption
,
687 : wxDialog(parent
, -1, caption
,
688 wxDefaultPosition
, wxDefaultSize
,
689 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
691 if ( ms_details
.IsEmpty() )
693 // ensure that we won't loop here if wxGetTranslation()
694 // happens to pop up a Log message while translating this :-)
695 ms_details
= wxTRANSLATE("&Details");
696 ms_details
= wxGetTranslation(ms_details
);
699 size_t count
= messages
.GetCount();
700 m_messages
.Alloc(count
);
701 m_severity
.Alloc(count
);
702 m_times
.Alloc(count
);
704 for ( size_t n
= 0; n
< count
; n
++ )
706 wxString msg
= messages
[n
];
709 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
710 msg
= msg
.AfterFirst(_T('\n'));
712 m_severity
.Add(severity
[n
]);
713 m_times
.Add(times
[n
]);
718 m_showingDetails
= FALSE
; // not initially
719 m_listctrl
= (wxListCtrl
*)NULL
;
722 m_statline
= (wxStaticLine
*)NULL
;
723 #endif // wxUSE_STATLINE
726 m_btnSave
= (wxButton
*)NULL
;
729 // create the controls which are always shown and layout them: we use
730 // sizers even though our window is not resizeable to calculate the size of
731 // the dialog properly
732 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
733 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
734 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
736 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
737 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
738 // translates into click on cancel button)
739 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
740 sizerButtons
->Add(btnOk
, 0, wxCENTRE
| wxBOTTOM
, MARGIN
/2);
741 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
742 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
746 switch ( style
& wxICON_MASK
)
749 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
751 bitmap
.SetId(wxICON_SMALL_ERROR
);
755 case wxICON_INFORMATION
:
756 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
758 bitmap
.SetId(wxICON_SMALL_INFO
);
763 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
765 bitmap
.SetId(wxICON_SMALL_WARNING
);
770 wxFAIL_MSG(_T("incorrect log style"));
772 sizerAll
->Add(new wxStaticBitmap(this, -1, bitmap
), 0);
775 const wxString
& message
= messages
.Last();
776 sizerAll
->Add(CreateTextSizer(message
), 1,
777 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
778 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
| wxLEFT
, MARGIN
);
780 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
785 // see comments in OnDetails()
787 // Note: Doing this, this way, triggered a nasty bug in
788 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
789 // either of maxWidth or maxHeight was set. This symptom has been
790 // fixed there, but it is a problem that remains as long as we allow
791 // unchecked access to the internal size members. We really need to
792 // encapuslate window sizes more cleanly and make it clear when -1 will
793 // be substituted and when it will not.
795 wxSize size
= sizerTop
->Fit(this);
796 m_maxHeight
= size
.y
;
797 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
801 // this can't happen any more as we don't use this dialog in this case
805 // no details... it's easier to disable a button than to change the
806 // dialog layout depending on whether we have details or not
807 m_btnDetails
->Disable();
814 void wxLogDialog::CreateDetailsControls()
816 // create the save button and separator line if possible
818 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
822 m_statline
= new wxStaticLine(this, -1);
823 #endif // wxUSE_STATLINE
825 // create the list ctrl now
826 m_listctrl
= new wxListCtrl(this, -1,
827 wxDefaultPosition
, wxDefaultSize
,
833 // no need to translate these strings as they're not shown to the
834 // user anyhow (we use wxLC_NO_HEADER style)
835 m_listctrl
->InsertColumn(0, _T("Message"));
836 m_listctrl
->InsertColumn(1, _T("Time"));
838 // prepare the imagelist
839 static const int ICON_SIZE
= 16;
840 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
842 // order should be the same as in the switch below!
843 static const wxChar
* icons
[] =
850 bool loadedIcons
= TRUE
;
853 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
855 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
856 wxSize(ICON_SIZE
, ICON_SIZE
));
858 // This may very well fail if there are insufficient colours available.
859 // Degrade gracefully.
870 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
874 wxString fmt
= wxLog::GetTimestamp();
881 size_t count
= m_messages
.GetCount();
882 for ( size_t n
= 0; n
< count
; n
++ )
889 switch ( m_severity
[n
] )
903 else // failed to load images
909 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
910 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
913 // let the columns size themselves
914 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
915 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
917 // calculate an approximately nice height for the listctrl
918 int height
= GetCharHeight()*(count
+ 4);
920 // but check that the dialog won't fall fown from the screen
922 // we use GetMinHeight() to get the height of the dialog part without the
923 // details and we consider that the "Save" button below and the separator
924 // line (and the margins around it) take about as much, hence double it
925 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
927 // we should leave a margin
931 m_listctrl
->SetSize(-1, wxMin(height
, heightMax
));
934 void wxLogDialog::OnListSelect(wxListEvent
& event
)
936 // we can't just disable the control because this looks ugly under Windows
937 // (wrong bg colour, no scrolling...), but we still want to disable
938 // selecting items - it makes no sense here
939 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
942 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
949 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
953 int rc
= OpenLogFile(file
);
962 wxString fmt
= wxLog::GetTimestamp();
969 size_t count
= m_messages
.GetCount();
970 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
973 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
976 << wxTextFile::GetEOL();
978 ok
= file
.Write(line
);
985 wxLogError(_("Can't save log contents to file."));
986 #endif // wxUSE_FILEDLG
991 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
993 wxSizer
*sizer
= GetSizer();
995 if ( m_showingDetails
)
997 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
999 sizer
->Detach( m_listctrl
);
1002 sizer
->Detach( m_statline
);
1003 #endif // wxUSE_STATLINE
1006 sizer
->Detach( m_btnSave
);
1007 #endif // wxUSE_FILE
1009 else // show details now
1011 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1015 CreateDetailsControls();
1019 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1020 #endif // wxUSE_STATLINE
1022 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1024 // VZ: this doesn't work as this becomes the initial (and not only
1025 // minimal) listctrl height as well - why?
1027 // allow the user to make the dialog shorter than its initial height -
1028 // without this it wouldn't work as the list ctrl would have been
1030 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1034 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1035 #endif // wxUSE_FILE
1038 m_showingDetails
= !m_showingDetails
;
1040 // in any case, our size changed - relayout everything and set new hints
1041 // ---------------------------------------------------------------------
1043 // we have to reset min size constraints or Fit() would never reduce the
1044 // dialog size when collapsing it and we have to reset max constraint
1045 // because it wouldn't expand it otherwise
1050 // wxSizer::FitSize() is private, otherwise we might use it directly...
1051 wxSize sizeTotal
= GetSize(),
1052 sizeClient
= GetClientSize();
1054 wxSize size
= sizer
->GetMinSize();
1055 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1056 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1058 // we don't want to allow expanding the dialog in vertical direction as
1059 // this would show the "hidden" details but we can resize the dialog
1060 // vertically while the details are shown
1061 if ( !m_showingDetails
)
1062 m_maxHeight
= size
.y
;
1064 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1066 // don't change the width when expanding/collapsing
1067 SetSize(-1, size
.y
);
1070 // VS: this is neccessary in order to force frame redraw under
1071 // WindowMaker or fvwm2 (and probably other broken WMs).
1072 // Otherwise, detailed list wouldn't be displayed.
1077 wxLogDialog::~wxLogDialog()
1081 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1085 #endif // wxUSE_LOG_DIALOG
1087 #if wxUSE_FILE && wxUSE_FILEDLG
1089 // pass an uninitialized file object, the function will ask the user for the
1090 // filename and try to open it, returns TRUE on success (file was opened),
1091 // FALSE if file couldn't be opened/created and -1 if the file selection
1092 // dialog was cancelled
1093 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1095 // get the file name
1096 // -----------------
1097 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1106 if ( wxFile::Exists(filename
) ) {
1107 bool bAppend
= FALSE
;
1109 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1111 switch ( wxMessageBox(strMsg
, _("Question"),
1112 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1125 wxFAIL_MSG(_("invalid message box return value"));
1129 bOk
= file
.Open(filename
, wxFile::write_append
);
1132 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1136 bOk
= file
.Create(filename
);
1140 *pFilename
= filename
;
1145 #endif // wxUSE_FILE
1147 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1149 #if wxUSE_LOG && wxUSE_GUI && wxUSE_TEXTCTRL
1151 // ----------------------------------------------------------------------------
1152 // wxLogTextCtrl implementation
1153 // ----------------------------------------------------------------------------
1155 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1157 m_pTextCtrl
= pTextCtrl
;
1160 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1165 #if defined(__WXMAC__)
1166 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1167 // translation must be done in wxTextCtrl, not here! (FIXME)
1168 msg
<< szString
<< wxT('\r');
1170 msg
<< szString
<< wxT('\n');
1173 m_pTextCtrl
->AppendText(msg
);
1176 #endif // wxUSE_LOG && wxUSE_GUI && wxUSE_TEXTCTRL