]>
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 #include "wx/datetime.h"
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 #ifndef __SMARTPHONE__
131 wxButton
*m_btnDetails
;
133 bool m_showingDetails
;
135 // the controls which are not shown initially (but only when details
136 // button is pressed)
137 wxListCtrl
*m_listctrl
;
138 #ifndef __SMARTPHONE__
140 wxStaticLine
*m_statline
;
141 #endif // wxUSE_STATLINE
145 #endif // __SMARTPHONE__
147 // the translated "Details" string
148 static wxString ms_details
;
150 DECLARE_EVENT_TABLE()
151 DECLARE_NO_COPY_CLASS(wxLogDialog
)
154 BEGIN_EVENT_TABLE(wxLogDialog
, wxDialog
)
155 EVT_BUTTON(wxID_OK
, wxLogDialog::OnOk
)
156 EVT_BUTTON(wxID_MORE
, wxLogDialog::OnDetails
)
158 EVT_BUTTON(wxID_SAVE
, wxLogDialog::OnSave
)
160 EVT_LIST_ITEM_SELECTED(wxID_ANY
, wxLogDialog::OnListSelect
)
163 #endif // wxUSE_LOG_DIALOG
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 #if wxUSE_FILE && wxUSE_FILEDLG
171 // pass an uninitialized file object, the function will ask the user for the
172 // filename and try to open it, returns true on success (file was opened),
173 // false if file couldn't be opened/created and -1 if the file selection
174 // dialog was cancelled
175 static int OpenLogFile(wxFile
& file
, wxString
*filename
= NULL
, wxWindow
*parent
= NULL
);
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 // we use a global variable to store the frame pointer for wxLogStatus - bad,
184 // but it's the easiest way
185 static wxFrame
*gs_pFrame
= NULL
; // FIXME MT-unsafe
187 // ============================================================================
189 // ============================================================================
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 // accepts an additional argument which tells to which frame the output should
197 void wxVLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, va_list argptr
)
201 wxLog
*pLog
= wxLog::GetActiveTarget();
202 if ( pLog
!= NULL
) {
203 msg
.PrintfV(szFormat
, argptr
);
205 wxASSERT( gs_pFrame
== NULL
); // should be reset!
208 wxLog::OnLog(wxLOG_Status
, msg
, 0);
210 wxLog::OnLog(wxLOG_Status
, msg
, time(NULL
));
212 gs_pFrame
= (wxFrame
*) NULL
;
216 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
219 va_start(argptr
, szFormat
);
220 wxVLogStatus(pFrame
, szFormat
, argptr
);
224 // ----------------------------------------------------------------------------
225 // wxLogGui implementation (FIXME MT-unsafe)
226 // ----------------------------------------------------------------------------
235 void wxLogGui::Clear()
239 m_bHasMessages
= false;
246 void wxLogGui::Flush()
248 if ( !m_bHasMessages
)
251 // do it right now to block any new calls to Flush() while we're here
252 m_bHasMessages
= false;
254 wxString appName
= wxTheApp
->GetAppName();
255 if ( !appName
.empty() )
256 appName
[0u] = (wxChar
)wxToupper(appName
[0u]);
259 wxString titleFormat
;
261 titleFormat
= _("%s Error");
264 else if ( m_bWarnings
) {
265 titleFormat
= _("%s Warning");
266 style
= wxICON_EXCLAMATION
;
269 titleFormat
= _("%s Information");
270 style
= wxICON_INFORMATION
;
274 title
.Printf(titleFormat
, appName
.c_str());
276 size_t nMsgCount
= m_aMessages
.Count();
278 // avoid showing other log dialogs until we're done with the dialog we're
279 // showing right now: nested modal dialogs make for really bad UI!
283 if ( nMsgCount
== 1 )
285 str
= m_aMessages
[0];
287 else // more than one message
291 wxLogDialog
dlg(NULL
,
292 m_aMessages
, m_aSeverity
, m_aTimes
,
295 // clear the message list before showing the dialog because while it's
296 // shown some new messages may appear
299 (void)dlg
.ShowModal();
300 #else // !wxUSE_LOG_DIALOG
301 // concatenate all strings (but not too many to not overfill the msg box)
304 // start from the most recent message
305 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
306 // for Windows strings longer than this value are wrapped (NT 4.0)
307 const size_t nMsgLineWidth
= 156;
309 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
311 if ( nLines
> 25 ) // don't put too many lines in message box
314 str
<< m_aMessages
[n
- 1] << wxT("\n");
316 #endif // wxUSE_LOG_DIALOG/!wxUSE_LOG_DIALOG
319 // this catches both cases of 1 message with wxUSE_LOG_DIALOG and any
320 // situation without it
323 wxMessageBox(str
, title
, wxOK
| style
);
325 // no undisplayed messages whatsoever
329 // allow flushing the logs again
333 // log all kinds of messages
334 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
341 m_aMessages
.Add(szString
);
342 m_aSeverity
.Add(wxLOG_Message
);
343 m_aTimes
.Add((long)t
);
344 m_bHasMessages
= true;
351 // find the top window and set it's status text if it has any
352 wxFrame
*pFrame
= gs_pFrame
;
353 if ( pFrame
== NULL
) {
354 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
355 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
356 pFrame
= (wxFrame
*)pWin
;
360 if ( pFrame
&& pFrame
->GetStatusBar() )
361 pFrame
->SetStatusText(szString
);
363 #endif // wxUSE_STATUSBAR
374 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
375 // don't prepend debug/trace here: it goes to the
376 // debug window anyhow
378 OutputDebugString(str
);
380 // send them to stderr
381 wxFprintf(stderr
, wxT("[%s] %s\n"),
382 level
== wxLOG_Trace
? wxT("Trace")
388 #endif // __WXDEBUG__
392 case wxLOG_FatalError
:
393 // show this one immediately
394 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
400 #if !wxUSE_LOG_DIALOG
401 // discard earlier informational messages if this is the 1st
402 // error because they might not make sense any more and showing
403 // them in a message box might be confusing
407 #endif // wxUSE_LOG_DIALOG
414 // for the warning we don't discard the info messages
418 m_aMessages
.Add(szString
);
419 m_aSeverity
.Add((int)level
);
420 m_aTimes
.Add((long)t
);
421 m_bHasMessages
= true;
426 #endif // wxUSE_LOGGUI
428 // ----------------------------------------------------------------------------
429 // wxLogWindow and wxLogFrame implementation
430 // ----------------------------------------------------------------------------
436 class wxLogFrame
: public wxFrame
440 wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
441 virtual ~wxLogFrame();
444 void OnClose(wxCommandEvent
& event
);
445 void OnCloseWindow(wxCloseEvent
& event
);
447 void OnSave (wxCommandEvent
& event
);
449 void OnClear(wxCommandEvent
& event
);
452 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
455 // use standard ids for our commands!
458 Menu_Close
= wxID_CLOSE
,
459 Menu_Save
= wxID_SAVE
,
460 Menu_Clear
= wxID_CLEAR
463 // common part of OnClose() and OnCloseWindow()
466 wxTextCtrl
*m_pTextCtrl
;
469 DECLARE_EVENT_TABLE()
470 DECLARE_NO_COPY_CLASS(wxLogFrame
)
473 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
474 // wxLogWindow menu events
475 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
477 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
479 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
481 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
484 wxLogFrame::wxLogFrame(wxWindow
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
485 : wxFrame(pParent
, wxID_ANY
, szTitle
)
489 m_pTextCtrl
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
493 // needed for Win32 to avoid 65Kb limit but it doesn't work well
494 // when using RichEdit 2.0 which we always do in the Unicode build
497 #endif // !wxUSE_UNICODE
502 wxMenuBar
*pMenuBar
= new wxMenuBar
;
503 wxMenu
*pMenu
= new wxMenu
;
505 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
507 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
508 pMenu
->AppendSeparator();
509 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
510 pMenuBar
->Append(pMenu
, _("&Log"));
511 SetMenuBar(pMenuBar
);
512 #endif // wxUSE_MENUS
515 // status bar for menu prompts
517 #endif // wxUSE_STATUSBAR
519 m_log
->OnFrameCreate(this);
522 void wxLogFrame::DoClose()
524 if ( m_log
->OnFrameClose(this) )
526 // instead of closing just hide the window to be able to Show() it
532 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
537 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
543 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
548 int rc
= OpenLogFile(file
, &filename
, this);
557 // retrieve text and save it
558 // -------------------------
559 int nLines
= m_pTextCtrl
->GetNumberOfLines();
560 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
561 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
562 wxTextFile::GetEOL());
569 wxLogError(_("Can't save log contents to file."));
572 wxLogStatus(this, _("Log saved to the file '%s'."), filename
.c_str());
578 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
580 m_pTextCtrl
->Clear();
583 wxLogFrame::~wxLogFrame()
585 m_log
->OnFrameDelete(this);
591 wxLogWindow::wxLogWindow(wxWindow
*pParent
,
592 const wxChar
*szTitle
,
596 PassMessages(bDoPass
);
598 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
604 void wxLogWindow::Show(bool bShow
)
606 m_pLogFrame
->Show(bShow
);
609 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
611 // first let the previous logger show it
612 wxLogPassThrough::DoLog(level
, szString
, t
);
617 // by default, these messages are ignored by wxLog, so process
619 if ( !wxIsEmpty(szString
) )
622 str
<< _("Status: ") << szString
;
627 // don't put trace messages in the text window for 2 reasons:
628 // 1) there are too many of them
629 // 2) they may provoke other trace messages thus sending a program
630 // into an infinite loop
635 // and this will format it nicely and call our DoLogString()
636 wxLog::DoLog(level
, szString
, t
);
641 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
643 // put the text into our window
644 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
646 // remove selection (WriteText is in fact ReplaceSelection)
648 wxTextPos nLen
= pText
->GetLastPosition();
649 pText
->SetSelection(nLen
, nLen
);
654 msg
<< szString
<< wxT('\n');
656 pText
->AppendText(msg
);
658 // TODO ensure that the line can be seen
661 wxFrame
*wxLogWindow::GetFrame() const
666 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
670 bool wxLogWindow::OnFrameClose(wxFrame
* WXUNUSED(frame
))
676 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
678 m_pLogFrame
= (wxLogFrame
*)NULL
;
681 wxLogWindow::~wxLogWindow()
683 // may be NULL if log frame already auto destroyed itself
687 #endif // wxUSE_LOGWINDOW
689 // ----------------------------------------------------------------------------
691 // ----------------------------------------------------------------------------
695 #ifndef __SMARTPHONE__
696 static const size_t MARGIN
= 10;
698 static const size_t MARGIN
= 0;
701 wxString
wxLogDialog::ms_details
;
703 wxLogDialog::wxLogDialog(wxWindow
*parent
,
704 const wxArrayString
& messages
,
705 const wxArrayInt
& severity
,
706 const wxArrayLong
& times
,
707 const wxString
& caption
,
709 : wxDialog(parent
, wxID_ANY
, caption
,
710 wxDefaultPosition
, wxDefaultSize
,
711 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
713 if ( ms_details
.empty() )
715 // ensure that we won't loop here if wxGetTranslation()
716 // happens to pop up a Log message while translating this :-)
717 ms_details
= wxTRANSLATE("&Details");
718 ms_details
= wxGetTranslation(ms_details
);
719 #ifdef __SMARTPHONE__
720 ms_details
= wxStripMenuCodes(ms_details
);
724 size_t count
= messages
.GetCount();
725 m_messages
.Alloc(count
);
726 m_severity
.Alloc(count
);
727 m_times
.Alloc(count
);
729 for ( size_t n
= 0; n
< count
; n
++ )
731 wxString msg
= messages
[n
];
732 msg
.Replace(wxT("\n"), wxT(" "));
734 m_severity
.Add(severity
[n
]);
735 m_times
.Add(times
[n
]);
738 m_showingDetails
= false; // not initially
739 m_listctrl
= (wxListCtrl
*)NULL
;
741 #ifndef __SMARTPHONE__
744 m_statline
= (wxStaticLine
*)NULL
;
745 #endif // wxUSE_STATLINE
748 m_btnSave
= (wxButton
*)NULL
;
751 #endif // __SMARTPHONE__
753 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
755 // create the controls which are always shown and layout them: we use
756 // sizers even though our window is not resizeable to calculate the size of
757 // the dialog properly
758 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
759 #ifndef __SMARTPHONE__
760 wxBoxSizer
*sizerButtons
= new wxBoxSizer(isPda
? wxHORIZONTAL
: wxVERTICAL
);
762 wxBoxSizer
*sizerAll
= new wxBoxSizer(isPda
? wxVERTICAL
: wxHORIZONTAL
);
764 #ifdef __SMARTPHONE__
765 SetLeftMenu(wxID_OK
);
766 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
768 wxButton
*btnOk
= new wxButton(this, wxID_OK
);
769 sizerButtons
->Add(btnOk
, 0, isPda
? wxCENTRE
: wxCENTRE
|wxBOTTOM
, MARGIN
/2);
770 m_btnDetails
= new wxButton(this, wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
771 sizerButtons
->Add(m_btnDetails
, 0, isPda
? wxCENTRE
|wxLEFT
: wxCENTRE
| wxTOP
, MARGIN
/2 - 1);
775 switch ( style
& wxICON_MASK
)
778 bitmap
= wxArtProvider::GetBitmap(wxART_ERROR
, wxART_MESSAGE_BOX
);
780 bitmap
.SetId(wxICON_SMALL_ERROR
);
784 case wxICON_INFORMATION
:
785 bitmap
= wxArtProvider::GetBitmap(wxART_INFORMATION
, wxART_MESSAGE_BOX
);
787 bitmap
.SetId(wxICON_SMALL_INFO
);
792 bitmap
= wxArtProvider::GetBitmap(wxART_WARNING
, wxART_MESSAGE_BOX
);
794 bitmap
.SetId(wxICON_SMALL_WARNING
);
799 wxFAIL_MSG(_T("incorrect log style"));
803 sizerAll
->Add(new wxStaticBitmap(this, wxID_ANY
, bitmap
), 0,
804 wxALIGN_CENTRE_VERTICAL
);
806 const wxString
& message
= messages
.Last();
807 sizerAll
->Add(CreateTextSizer(message
), 1,
808 wxALIGN_CENTRE_VERTICAL
| wxLEFT
| wxRIGHT
, MARGIN
);
809 #ifndef __SMARTPHONE__
810 sizerAll
->Add(sizerButtons
, 0, isPda
? wxCENTRE
|wxTOP
|wxBOTTOM
: (wxALIGN_RIGHT
| wxLEFT
), MARGIN
);
813 sizerTop
->Add(sizerAll
, 0, wxALL
| wxEXPAND
, MARGIN
);
817 // see comments in OnDetails()
819 // Note: Doing this, this way, triggered a nasty bug in
820 // wxTopLevelWindowGTK::GtkOnSize which took -1 literally once
821 // either of maxWidth or maxHeight was set. This symptom has been
822 // fixed there, but it is a problem that remains as long as we allow
823 // unchecked access to the internal size members. We really need to
824 // encapuslate window sizes more cleanly and make it clear when -1 will
825 // be substituted and when it will not.
827 wxSize size
= sizerTop
->Fit(this);
828 m_maxHeight
= size
.y
;
829 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
831 #ifndef __SMARTPHONE__
839 // Move up the screen so that when we expand the dialog,
840 // there's enough space.
841 Move(wxPoint(GetPosition().x
, GetPosition().y
/ 2));
845 void wxLogDialog::CreateDetailsControls()
847 #ifndef __SMARTPHONE__
848 // create the save button and separator line if possible
850 m_btnSave
= new wxButton(this, wxID_SAVE
);
854 m_statline
= new wxStaticLine(this, wxID_ANY
);
855 #endif // wxUSE_STATLINE
857 #endif // __SMARTPHONE__
859 // create the list ctrl now
860 m_listctrl
= new wxListCtrl(this, wxID_ANY
,
861 wxDefaultPosition
, wxDefaultSize
,
867 // This maks a big aesthetic difference on WinCE but I
868 // don't want to risk problems on other platforms
872 // no need to translate these strings as they're not shown to the
873 // user anyhow (we use wxLC_NO_HEADER style)
874 m_listctrl
->InsertColumn(0, _T("Message"));
875 m_listctrl
->InsertColumn(1, _T("Time"));
877 // prepare the imagelist
878 static const int ICON_SIZE
= 16;
879 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
881 // order should be the same as in the switch below!
882 static const wxChar
* icons
[] =
889 bool loadedIcons
= true;
891 for ( size_t icon
= 0; icon
< WXSIZEOF(icons
); icon
++ )
893 wxBitmap bmp
= wxArtProvider::GetBitmap(icons
[icon
], wxART_MESSAGE_BOX
,
894 wxSize(ICON_SIZE
, ICON_SIZE
));
896 // This may very well fail if there are insufficient colours available.
897 // Degrade gracefully.
908 m_listctrl
->SetImageList(imageList
, wxIMAGE_LIST_SMALL
);
911 wxString fmt
= wxLog::GetTimestamp();
918 size_t count
= m_messages
.GetCount();
919 for ( size_t n
= 0; n
< count
; n
++ )
925 switch ( m_severity
[n
] )
939 else // failed to load images
944 m_listctrl
->InsertItem(n
, m_messages
[n
], image
);
945 m_listctrl
->SetItem(n
, 1, TimeStamp(fmt
, (time_t)m_times
[n
]));
948 // let the columns size themselves
949 m_listctrl
->SetColumnWidth(0, wxLIST_AUTOSIZE
);
950 m_listctrl
->SetColumnWidth(1, wxLIST_AUTOSIZE
);
952 // calculate an approximately nice height for the listctrl
953 int height
= GetCharHeight()*(count
+ 4);
955 // but check that the dialog won't fall fown from the screen
957 // we use GetMinHeight() to get the height of the dialog part without the
958 // details and we consider that the "Save" button below and the separator
959 // line (and the margins around it) take about as much, hence double it
960 int heightMax
= wxGetDisplaySize().y
- GetPosition().y
- 2*GetMinHeight();
962 // we should leave a margin
966 m_listctrl
->SetSize(wxDefaultCoord
, wxMin(height
, heightMax
));
969 void wxLogDialog::OnListSelect(wxListEvent
& event
)
971 // we can't just disable the control because this looks ugly under Windows
972 // (wrong bg colour, no scrolling...), but we still want to disable
973 // selecting items - it makes no sense here
974 m_listctrl
->SetItemState(event
.GetIndex(), 0, wxLIST_STATE_SELECTED
);
977 void wxLogDialog::OnOk(wxCommandEvent
& WXUNUSED(event
))
984 void wxLogDialog::OnSave(wxCommandEvent
& WXUNUSED(event
))
988 int rc
= OpenLogFile(file
, NULL
, this);
997 wxString fmt
= wxLog::GetTimestamp();
1004 size_t count
= m_messages
.GetCount();
1005 for ( size_t n
= 0; ok
&& (n
< count
); n
++ )
1008 line
<< TimeStamp(fmt
, (time_t)m_times
[n
])
1011 << wxTextFile::GetEOL();
1013 ok
= file
.Write(line
);
1020 wxLogError(_("Can't save log contents to file."));
1021 #endif // wxUSE_FILEDLG
1024 #endif // wxUSE_FILE
1026 void wxLogDialog::OnDetails(wxCommandEvent
& WXUNUSED(event
))
1028 wxSizer
*sizer
= GetSizer();
1030 if ( m_showingDetails
)
1032 #ifdef __SMARTPHONE__
1033 SetRightMenu(wxID_MORE
, ms_details
+ EXPAND_SUFFIX
);
1035 m_btnDetails
->SetLabel(ms_details
+ EXPAND_SUFFIX
);
1038 sizer
->Detach( m_listctrl
);
1040 #ifndef __SMARTPHONE__
1043 sizer
->Detach( m_statline
);
1044 #endif // wxUSE_STATLINE
1047 sizer
->Detach( m_btnSave
);
1048 #endif // wxUSE_FILE
1050 #endif // __SMARTPHONE__
1052 else // show details now
1054 #ifdef __SMARTPHONE__
1055 SetRightMenu(wxID_MORE
, wxString(_T("<< ")) + ms_details
);
1057 m_btnDetails
->SetLabel(wxString(_T("<< ")) + ms_details
);
1062 CreateDetailsControls();
1065 #if wxUSE_STATLINE && !defined(__SMARTPHONE__)
1066 bool isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
1068 sizer
->Add(m_statline
, 0, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1069 #endif // wxUSE_STATLINE
1071 sizer
->Add(m_listctrl
, 1, wxEXPAND
| (wxALL
& ~wxTOP
), MARGIN
);
1073 // VZ: this doesn't work as this becomes the initial (and not only
1074 // minimal) listctrl height as well - why?
1076 // allow the user to make the dialog shorter than its initial height -
1077 // without this it wouldn't work as the list ctrl would have been
1079 sizer
->SetItemMinSize(m_listctrl
, 100, 3*GetCharHeight());
1082 #if wxUSE_FILE && !defined(__SMARTPHONE__)
1083 sizer
->Add(m_btnSave
, 0, wxALIGN_RIGHT
| (wxALL
& ~wxTOP
), MARGIN
);
1084 #endif // wxUSE_FILE
1087 m_showingDetails
= !m_showingDetails
;
1089 // in any case, our size changed - relayout everything and set new hints
1090 // ---------------------------------------------------------------------
1092 // we have to reset min size constraints or Fit() would never reduce the
1093 // dialog size when collapsing it and we have to reset max constraint
1094 // because it wouldn't expand it otherwise
1099 // wxSizer::FitSize() is private, otherwise we might use it directly...
1100 wxSize sizeTotal
= GetSize(),
1101 sizeClient
= GetClientSize();
1103 wxSize size
= sizer
->GetMinSize();
1104 size
.x
+= sizeTotal
.x
- sizeClient
.x
;
1105 size
.y
+= sizeTotal
.y
- sizeClient
.y
;
1107 // we don't want to allow expanding the dialog in vertical direction as
1108 // this would show the "hidden" details but we can resize the dialog
1109 // vertically while the details are shown
1110 if ( !m_showingDetails
)
1111 m_maxHeight
= size
.y
;
1113 SetSizeHints(size
.x
, size
.y
, m_maxWidth
, m_maxHeight
);
1116 if (m_showingDetails
)
1120 // don't change the width when expanding/collapsing
1121 SetSize(wxDefaultCoord
, size
.y
);
1124 // VS: this is necessary in order to force frame redraw under
1125 // WindowMaker or fvwm2 (and probably other broken WMs).
1126 // Otherwise, detailed list wouldn't be displayed.
1131 wxLogDialog::~wxLogDialog()
1135 delete m_listctrl
->GetImageList(wxIMAGE_LIST_SMALL
);
1139 #endif // wxUSE_LOG_DIALOG
1141 #if wxUSE_FILE && wxUSE_FILEDLG
1143 // pass an uninitialized file object, the function will ask the user for the
1144 // filename and try to open it, returns true on success (file was opened),
1145 // false if file couldn't be opened/created and -1 if the file selection
1146 // dialog was cancelled
1147 static int OpenLogFile(wxFile
& file
, wxString
*pFilename
, wxWindow
*parent
)
1149 // get the file name
1150 // -----------------
1151 wxString filename
= wxSaveFileSelector(wxT("log"), wxT("txt"), wxT("log.txt"), parent
);
1159 bool bOk
wxDUMMY_INITIALIZE(false);
1160 if ( wxFile::Exists(filename
) ) {
1161 bool bAppend
= false;
1163 strMsg
.Printf(_("Append log to file '%s' (choosing [No] will overwrite it)?"),
1165 switch ( wxMessageBox(strMsg
, _("Question"),
1166 wxICON_QUESTION
| wxYES_NO
| wxCANCEL
) ) {
1179 wxFAIL_MSG(_("invalid message box return value"));
1183 bOk
= file
.Open(filename
, wxFile::write_append
);
1186 bOk
= file
.Create(filename
, true /* overwrite */);
1190 bOk
= file
.Create(filename
);
1194 *pFilename
= filename
;
1199 #endif // wxUSE_FILE
1201 #endif // !(wxUSE_LOGGUI || wxUSE_LOGWINDOW)
1203 #if wxUSE_LOG && wxUSE_TEXTCTRL
1205 // ----------------------------------------------------------------------------
1206 // wxLogTextCtrl implementation
1207 // ----------------------------------------------------------------------------
1209 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
1211 m_pTextCtrl
= pTextCtrl
;
1214 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
1219 msg
<< szString
<< wxT('\n');
1220 m_pTextCtrl
->AppendText(msg
);
1223 #endif // wxUSE_LOG && wxUSE_TEXTCTRL