]>
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 #if defined(__MWERKS__) && wxUSE_UNICODE
78 // the suffix we add to the button to show that the dialog can be expanded
79 #define EXPAND_SUFFIX _T(" >>")
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
87 // this function is a wrapper around strftime(3)
88 // allows to exclude the usage of wxDateTime
89 static wxString
TimeStamp(const wxChar
*format
, time_t t
)
92 if ( !wxStrftime(buf
, WXSIZEOF(buf
), format
, localtime(&t
)) )
94 // buffer is too small?
95 wxFAIL_MSG(_T("strftime() failed"));
101 class wxLogDialog
: public wxDialog
104 wxLogDialog(wxWindow
*parent
,
105 const wxArrayString
& messages
,
106 const wxArrayInt
& severity
,
107 const wxArrayLong
& timess
,
108 const wxString
& caption
,
110 virtual ~wxLogDialog();
113 void OnOk(wxCommandEvent
& event
);
114 void OnDetails(wxCommandEvent
& event
);
116 void OnSave(wxCommandEvent
& event
);
118 void OnListSelect(wxListEvent
& event
);
121 // create controls needed for the details display
122 void CreateDetailsControls();
124 // the data for the listctrl
125 wxArrayString m_messages
;
126 wxArrayInt m_severity
;
129 // the "toggle" button and its state
130 wxButton
*m_btnDetails
;
131 bool m_showingDetails
;
133 // the controls which are not shown initially (but only when details
134 // button is pressed)
135 wxListCtrl
*m_listctrl
;
137 wxStaticLine
*m_statline
;
138 #endif // wxUSE_STATLINE
143 // the translated "Details" string
144 static wxString ms_details
;
146 DECLARE_EVENT_TABLE()
147 DECLARE_NO_COPY_CLASS(wxLogDialog
)
150 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
151 EVT_BUTTON(wxID_CANCEL
, wxLogDialog::OnOk
)
152 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
154 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
156 EVT_LIST_ITEM_SELECTED(-1, wxLogDialog::OnListSelect
)
159 #endif // wxUSE_LOG_DIALOG
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 #if wxUSE_FILE && wxUSE_FILEDLG
167 // pass an uninitialized file object, the function will ask the user for the
168 // filename and try to open it, returns TRUE on success (file was opened),
169 // FALSE if file couldn't be opened/created and -1 if the file selection
170 // dialog was cancelled
171 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
);
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 // we use a global variable to store the frame pointer for wxLogStatus - bad,
180 // but it's the easiest way
181 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
183 // ============================================================================
185 // ============================================================================
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 // accepts an additional argument which tells to which frame the output should
193 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
197 wxLog
*pLog
= wxLog::GetActiveTarget();
198 if ( pLog
!= NULL
) {
199 msg
.PrintfV(szFormat
, argptr
);
201 wxASSERT( gs_pFrame
== NULL
); // should be reset!
203 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
204 gs_pFrame
= (wxFrame
*) NULL
;
208 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
211 va_start(argptr
, szFormat
);
212 wxVLogStatus(pFrame
, szFormat
, argptr
);
216 // ----------------------------------------------------------------------------
217 // wxLogGui implementation (FIXME MT-unsafe)
218 // ----------------------------------------------------------------------------
225 void wxLogGui::Clear()
229 m_bHasMessages
= FALSE
;
236 void wxLogGui::Flush()
238 if ( !m_bHasMessages
)
241 // do it right now to block any new calls to Flush() while we're here
242 m_bHasMessages
= FALSE
;
244 wxString appName
= wxTheApp
->GetAppName();
246 appName
[0u] = wxToupper(appName
[0u]);
249 wxString titleFormat
;
251 titleFormat
= _("%s Error");
254 else if ( m_bWarnings
) {
255 titleFormat
= _("%s Warning");
256 style
= wxICON_EXCLAMATION
;
259 titleFormat
= _("%s Information");
260 style
= wxICON_INFORMATION
;
264 title
.Printf(titleFormat
, appName
.c_str());
266 size_t nMsgCount
= m_aMessages
.Count();
268 // avoid showing other log dialogs until we're done with the dialog we're
269 // showing right now: nested modal dialogs make for really bad UI!
273 if ( nMsgCount
== 1 )
275 str
= m_aMessages
[0];
277 else // more than one message
281 wxLogDialog
dlg(NULL
,
282 m_aMessages
, m_aSeverity
, m_aTimes
,
285 // clear the message list before showing the dialog because while it's
286 // shown some new messages may appear
289 (void)dlg
.ShowModal();
290 #else // !wxUSE_LOG_DIALOG
291 // concatenate all strings (but not too many to not overfill the msg box)
294 // start from the most recent message
295 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
296 // for Windows strings longer than this value are wrapped (NT 4.0)
297 const size_t nMsgLineWidth
= 156;
299 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
301 if ( nLines
> 25 ) // don't put too many lines in message box
304 str
<< m_aMessages
[n
- 1] << wxT("\n");
306 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
309 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
310 // situation without it
313 wxMessageBox(str
, title
, wxOK
| style
);
315 // no undisplayed messages whatsoever
319 // allow flushing the logs again
323 // log all kinds of messages
324 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
331 m_aMessages
.Add(szString
);
332 m_aSeverity
.Add(wxLOG_Message
);
333 m_aTimes
.Add((long)t
);
334 m_bHasMessages
= TRUE
;
341 // find the top window and set it's status text if it has any
342 wxFrame
*pFrame
= gs_pFrame
;
343 if ( pFrame
== NULL
) {
344 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
345 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
346 pFrame
= (wxFrame
*)pWin
;
350 if ( pFrame
&& pFrame
->GetStatusBar() )
351 pFrame
->SetStatusText(szString
);
353 #endif // wxUSE_STATUSBAR
364 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
365 // don't prepend debug/trace here: it goes to the
366 // debug window anyhow
368 OutputDebugString(str
);
370 // send them to stderr
371 wxFprintf(stderr
, wxT("[%s] %s\n"),
372 level
== wxLOG_Trace
? wxT("Trace")
378 #endif // __WXDEBUG__
382 case wxLOG_FatalError
:
383 // show this one immediately
384 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
390 #if !wxUSE_LOG_DIALOG
391 // discard earlier informational messages if this is the 1st
392 // error because they might not make sense any more and showing
393 // them in a message box might be confusing
397 #endif // wxUSE_LOG_DIALOG
404 // for the warning we don't discard the info messages
408 m_aMessages
.Add(szString
);
409 m_aSeverity
.Add((int)level
);
410 m_aTimes
.Add((long)t
);
411 m_bHasMessages
= TRUE
;
416 // ----------------------------------------------------------------------------
417 // wxLogWindow and wxLogFrame implementation
418 // ----------------------------------------------------------------------------
422 class wxLogFrame
: public wxFrame
426 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
427 virtual ~wxLogFrame();
430 void OnClose(wxCommandEvent
& event
);
431 void OnCloseWindow(wxCloseEvent
& event
);
433 void OnSave (wxCommandEvent
& event
);
435 void OnClear(wxCommandEvent
& event
);
437 void OnIdle(wxIdleEvent
&);
440 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
443 // use standard ids for our commands!
446 Menu_Close
= wxID_CLOSE
,
447 Menu_Save
= wxID_SAVE
,
448 Menu_Clear
= wxID_CLEAR
451 // common part of OnClose() and OnCloseWindow()
454 wxTextCtrl
*m_pTextCtrl
;
457 DECLARE_EVENT_TABLE()
458 DECLARE_NO_COPY_CLASS(wxLogFrame
)
461 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
462 // wxLogWindow menu events
463 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
465 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
467 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
469 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
472 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
473 : wxFrame(pParent
, -1, szTitle
)
477 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
481 // needed for Win32 to avoid 65Kb limit but it doesn't work well
482 // when using RichEdit 2.0 which we always do in the Unicode build
485 #endif // !wxUSE_UNICODE
490 wxMenuBar
*pMenuBar
= new wxMenuBar
;
491 wxMenu
*pMenu
= new wxMenu
;
493 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
495 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
496 pMenu
->AppendSeparator();
497 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
498 pMenuBar
->Append(pMenu
, _("&Log"));
499 SetMenuBar(pMenuBar
);
500 #endif // wxUSE_MENUS
503 // status bar for menu prompts
505 #endif // wxUSE_STATUSBAR
507 m_log
->OnFrameCreate(this);
510 void wxLogFrame::DoClose()
512 if ( m_log
->OnFrameClose(this) )
514 // instead of closing just hide the window to be able to Show() it
520 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
525 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
531 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
536 int rc
= OpenLogFile(file
, &filename
);
545 // retrieve text and save it
546 // -------------------------
547 int nLines
= m_pTextCtrl
->GetNumberOfLines();
548 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
549 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
550 wxTextFile::GetEOL());
557 wxLogError(_("Can't save log contents to file."));
560 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
566 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
568 m_pTextCtrl
->Clear();
571 wxLogFrame::~wxLogFrame()
573 m_log
->OnFrameDelete(this);
579 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
580 const wxChar
*szTitle
,
584 PassMessages(bDoPass
);
586 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
589 m_pLogFrame
->Show(TRUE
);
592 void wxLogWindow::Show(bool bShow
)
594 m_pLogFrame
->Show(bShow
);
597 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
599 // first let the previous logger show it
600 wxLogPassThrough::DoLog(level
, szString
, t
);
605 // by default, these messages are ignored by wxLog, so process
607 if ( !wxIsEmpty(szString
) )
610 str
<< _("Status: ") << szString
;
615 // don't put trace messages in the text window for 2 reasons:
616 // 1) there are too many of them
617 // 2) they may provoke other trace messages thus sending a program
618 // into an infinite loop
623 // and this will format it nicely and call our DoLogString()
624 wxLog::DoLog(level
, szString
, t
);
629 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
631 // put the text into our window
632 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
634 // remove selection (WriteText is in fact ReplaceSelection)
636 long nLen
= pText
->GetLastPosition();
637 pText
->SetSelection(nLen
, nLen
);
642 msg
<< szString
<< wxT('\n');
644 pText
->AppendText(msg
);
646 // TODO ensure that the line can be seen
649 wxFrame
*wxLogWindow::GetFrame() const
654 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
658 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
664 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
666 m_pLogFrame
= (wxLogFrame
*)NULL
;
669 wxLogWindow::~wxLogWindow()
671 // may be NULL if log frame already auto destroyed itself
675 // ----------------------------------------------------------------------------
677 // ----------------------------------------------------------------------------
681 static const size_t MARGIN
= 10;
683 wxString
wxLogDialog::ms_details
;
685 wxLogDialog::wxLogDialog(wxWindow
*parent
,
686 const wxArrayString
& messages
,
687 const wxArrayInt
& severity
,
688 const wxArrayLong
& times
,
689 const wxString
& caption
,
691 : wxDialog(parent
, -1, caption
,
692 wxDefaultPosition
, wxDefaultSize
,
693 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
695 if ( ms_details
.IsEmpty() )
697 // ensure that we won't loop here if wxGetTranslation()
698 // happens to pop up a Log message while translating this :-)
699 ms_details
= wxTRANSLATE("&Details");
700 ms_details
= wxGetTranslation(ms_details
);
703 size_t count
= messages
.GetCount();
704 m_messages
.Alloc(count
);
705 m_severity
.Alloc(count
);
706 m_times
.Alloc(count
);
708 for ( size_t n
= 0; n
< count
; n
++ )
710 wxString msg
= messages
[n
];
713 m_messages
.Add(msg
.BeforeFirst(_T('\n')));
714 msg
= msg
.AfterFirst(_T('\n'));
716 m_severity
.Add(severity
[n
]);
717 m_times
.Add(times
[n
]);
722 m_showingDetails
= FALSE
; // not initially
723 m_listctrl
= (wxListCtrl
*)NULL
;
726 m_statline
= (wxStaticLine
*)NULL
;
727 #endif // wxUSE_STATLINE
730 m_btnSave
= (wxButton
*)NULL
;
733 // create the controls which are always shown and layout them: we use
734 // sizers even though our window is not resizeable to calculate the size of
735 // the dialog properly
736 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
737 wxBoxSizer
*sizerButtons
= new wxBoxSizer(wxVERTICAL
);
738 wxBoxSizer
*sizerAll
= new wxBoxSizer(wxHORIZONTAL
);
740 // this "Ok" button has wxID_CANCEL id - not very logical, but this allows
741 // to close the log dialog with <Esc> which wouldn't work otherwise (as it
742 // translates into click on cancel button)
743 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _("OK"));
744 sizerButtons
->Add(btnOk
, 0, wxCENTRE
| wxBOTTOM
, MARGIN
/2);
745 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
746 sizerButtons
->Add(m_btnDetails
, 0, wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
750 switch ( style
& wxICON_MASK
)
753 bitmap
= wxArtProvider::GetIcon(wxART_ERROR
, wxART_MESSAGE_BOX
);
755 bitmap
.SetId(wxICON_SMALL_ERROR
);
759 case wxICON_INFORMATION
:
760 bitmap
= wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
762 bitmap
.SetId(wxICON_SMALL_INFO
);
767 bitmap
= wxArtProvider::GetIcon(wxART_WARNING
, wxART_MESSAGE_BOX
);
769 bitmap
.SetId(wxICON_SMALL_WARNING
);
774 wxFAIL_MSG(_T("incorrect log style"));
776 sizerAll
->Add(new wxStaticBitmap(this, -1, bitmap
), 0);
779 const wxString
& message
= messages
.Last();
780 sizerAll
->Add(CreateTextSizer(message
), 1,
781 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
782 sizerAll
->Add(sizerButtons
, 0, wxALIGN_RIGHT
| wxLEFT
, MARGIN
);
784 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
789 // see comments in OnDetails()
791 // Note: Doing this, this way, triggered a nasty bug in
792 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
793 // either of maxWidth or maxHeight was set. This symptom has been
794 // fixed there, but it is a problem that remains as long as we allow
795 // unchecked access to the internal size members. We really need to
796 // encapuslate window sizes more cleanly and make it clear when -1 will
797 // be substituted and when it will not.
799 wxSize size
= sizerTop
->Fit(this);
800 m_maxHeight
= size
.y
;
801 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
805 // this can't happen any more as we don't use this dialog in this case
809 // no details... it's easier to disable a button than to change the
810 // dialog layout depending on whether we have details or not
811 m_btnDetails
->Disable();
818 void wxLogDialog::CreateDetailsControls()
820 // create the save button and separator line if possible
822 m_btnSave
= new wxButton(this, wxID_SAVE
, _("&Save..."));
826 m_statline
= new wxStaticLine(this, -1);
827 #endif // wxUSE_STATLINE
829 // create the list ctrl now
830 m_listctrl
= new wxListCtrl(this, -1,
831 wxDefaultPosition
, wxDefaultSize
,
837 // no need to translate these strings as they're not shown to the
838 // user anyhow (we use wxLC_NO_HEADER style)
839 m_listctrl
->InsertColumn(0, _T("Message"));
840 m_listctrl
->InsertColumn(1, _T("Time"));
842 // prepare the imagelist
843 static const int ICON_SIZE
= 16;
844 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
846 // order should be the same as in the switch below!
847 static const wxChar
* icons
[] =
854 bool loadedIcons
= TRUE
;
857 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
859 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
860 wxSize(ICON_SIZE
, ICON_SIZE
));
862 // This may very well fail if there are insufficient colours available.
863 // Degrade gracefully.
874 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
878 wxString fmt
= wxLog::GetTimestamp();
885 size_t count
= m_messages
.GetCount();
886 for ( size_t n
= 0; n
< count
; n
++ )
893 switch ( m_severity
[n
] )
907 else // failed to load images
913 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
914 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
917 // let the columns size themselves
918 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
919 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
921 // calculate an approximately nice height for the listctrl
922 int height
= GetCharHeight()*(count
+ 4);
924 // but check that the dialog won't fall fown from the screen
926 // we use GetMinHeight() to get the height of the dialog part without the
927 // details and we consider that the "Save" button below and the separator
928 // line (and the margins around it) take about as much, hence double it
929 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
931 // we should leave a margin
935 m_listctrl
->SetSize(-1, wxMin(height
, heightMax
));
938 void wxLogDialog::OnListSelect(wxListEvent
& event
)
940 // we can't just disable the control because this looks ugly under Windows
941 // (wrong bg colour, no scrolling...), but we still want to disable
942 // selecting items - it makes no sense here
943 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
946 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
953 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
957 int rc
= OpenLogFile(file
);
966 wxString fmt
= wxLog::GetTimestamp();
973 size_t count
= m_messages
.GetCount();
974 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
977 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
980 << wxTextFile::GetEOL();
982 ok
= file
.Write(line
);
989 wxLogError(_("Can't save log contents to file."));
990 #endif // wxUSE_FILEDLG
995 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
997 wxSizer
*sizer
= GetSizer();
999 if ( m_showingDetails
)
1001 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1003 sizer
->Detach( m_listctrl
);
1006 sizer
->Detach( m_statline
);
1007 #endif // wxUSE_STATLINE
1010 sizer
->Detach( m_btnSave
);
1011 #endif // wxUSE_FILE
1013 else // show details now
1015 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1019 CreateDetailsControls();
1023 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1024 #endif // wxUSE_STATLINE
1026 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1028 // VZ: this doesn't work as this becomes the initial (and not only
1029 // minimal) listctrl height as well - why?
1031 // allow the user to make the dialog shorter than its initial height -
1032 // without this it wouldn't work as the list ctrl would have been
1034 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1038 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1039 #endif // wxUSE_FILE
1042 m_showingDetails
= !m_showingDetails
;
1044 // in any case, our size changed - relayout everything and set new hints
1045 // ---------------------------------------------------------------------
1047 // we have to reset min size constraints or Fit() would never reduce the
1048 // dialog size when collapsing it and we have to reset max constraint
1049 // because it wouldn't expand it otherwise
1054 // wxSizer::FitSize() is private, otherwise we might use it directly...
1055 wxSize sizeTotal
= GetSize(),
1056 sizeClient
= GetClientSize();
1058 wxSize size
= sizer
->GetMinSize();
1059 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1060 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1062 // we don't want to allow expanding the dialog in vertical direction as
1063 // this would show the "hidden" details but we can resize the dialog
1064 // vertically while the details are shown
1065 if ( !m_showingDetails
)
1066 m_maxHeight
= size
.y
;
1068 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1070 // don't change the width when expanding/collapsing
1071 SetSize(-1, size
.y
);
1074 // VS: this is neccessary in order to force frame redraw under
1075 // WindowMaker or fvwm2 (and probably other broken WMs).
1076 // Otherwise, detailed list wouldn't be displayed.
1081 wxLogDialog::~wxLogDialog()
1085 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1089 #endif // wxUSE_LOG_DIALOG
1091 #if wxUSE_FILE && wxUSE_FILEDLG
1093 // pass an uninitialized file object, the function will ask the user for the
1094 // filename and try to open it, returns TRUE on success (file was opened),
1095 // FALSE if file couldn't be opened/created and -1 if the file selection
1096 // dialog was cancelled
1097 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
)
1099 // get the file name
1100 // -----------------
1101 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"));
1110 if ( wxFile::Exists(filename
) ) {
1111 bool bAppend
= FALSE
;
1113 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1115 switch ( wxMessageBox(strMsg
, _("Question"),
1116 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1129 wxFAIL_MSG(_("invalid message box return value"));
1133 bOk
= file
.Open(filename
, wxFile::write_append
);
1136 bOk
= file
.Create(filename
, TRUE
/* overwrite */);
1140 bOk
= file
.Create(filename
);
1144 *pFilename
= filename
;
1149 #endif // wxUSE_FILE
1151 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1153 #if wxUSE_LOG && wxUSE_GUI && wxUSE_TEXTCTRL
1155 // ----------------------------------------------------------------------------
1156 // wxLogTextCtrl implementation
1157 // ----------------------------------------------------------------------------
1159 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1161 m_pTextCtrl
= pTextCtrl
;
1164 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1169 #if defined(__WXMAC__)
1170 // VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
1171 // translation must be done in wxTextCtrl, not here! (FIXME)
1172 msg
<< szString
<< wxT('\r');
1174 msg
<< szString
<< wxT('\n');
1177 m_pTextCtrl
->AppendText(msg
);
1180 #endif // wxUSE_LOG && wxUSE_GUI && wxUSE_TEXTCTRL