logg.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/logg.h
  3. // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 29/01/98
  7. // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_LOGG_H_
  11. #define _WX_LOGG_H_
  12. #if wxUSE_GUI
  13. class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
  14. class WXDLLIMPEXP_FWD_CORE wxLogFrame;
  15. class WXDLLIMPEXP_FWD_CORE wxWindow;
  16. // ----------------------------------------------------------------------------
  17. // the following log targets are only compiled in if the we're compiling the
  18. // GUI part (andnot just the base one) of the library, they're implemented in
  19. // src/generic/logg.cpp *and not src/common/log.cpp unlike all the rest)
  20. // ----------------------------------------------------------------------------
  21. #if wxUSE_TEXTCTRL
  22. // log everything to a text window (GUI only of course)
  23. class WXDLLIMPEXP_CORE wxLogTextCtrl : public wxLog
  24. {
  25. public:
  26. wxLogTextCtrl(wxTextCtrl *pTextCtrl);
  27. protected:
  28. // implement sink function
  29. virtual void DoLogText(const wxString& msg);
  30. private:
  31. // the control we use
  32. wxTextCtrl *m_pTextCtrl;
  33. wxDECLARE_NO_COPY_CLASS(wxLogTextCtrl);
  34. };
  35. #endif // wxUSE_TEXTCTRL
  36. // ----------------------------------------------------------------------------
  37. // GUI log target, the default one for wxWidgets programs
  38. // ----------------------------------------------------------------------------
  39. #if wxUSE_LOGGUI
  40. class WXDLLIMPEXP_CORE wxLogGui : public wxLog
  41. {
  42. public:
  43. // ctor
  44. wxLogGui();
  45. // show all messages that were logged since the last Flush()
  46. virtual void Flush();
  47. protected:
  48. virtual void DoLogRecord(wxLogLevel level,
  49. const wxString& msg,
  50. const wxLogRecordInfo& info);
  51. // return the title to be used for the log dialog, depending on m_bErrors
  52. // and m_bWarnings values
  53. wxString GetTitle() const;
  54. // return the icon (one of wxICON_XXX constants) to be used for the dialog
  55. // depending on m_bErrors/m_bWarnings
  56. int GetSeverityIcon() const;
  57. // empty everything
  58. void Clear();
  59. wxArrayString m_aMessages; // the log message texts
  60. wxArrayInt m_aSeverity; // one of wxLOG_XXX values
  61. wxArrayLong m_aTimes; // the time of each message
  62. bool m_bErrors, // do we have any errors?
  63. m_bWarnings, // any warnings?
  64. m_bHasMessages; // any messages at all?
  65. private:
  66. // this method is called to show a single log message, it uses
  67. // wxMessageBox() by default
  68. virtual void DoShowSingleLogMessage(const wxString& message,
  69. const wxString& title,
  70. int style);
  71. // this method is called to show multiple log messages, it uses wxLogDialog
  72. virtual void DoShowMultipleLogMessages(const wxArrayString& messages,
  73. const wxArrayInt& severities,
  74. const wxArrayLong& times,
  75. const wxString& title,
  76. int style);
  77. };
  78. #endif // wxUSE_LOGGUI
  79. // ----------------------------------------------------------------------------
  80. // (background) log window: this class forwards all log messages to the log
  81. // target which was active when it was instantiated, but also collects them
  82. // to the log window. This window has its own menu which allows the user to
  83. // close it, clear the log contents or save it to the file.
  84. // ----------------------------------------------------------------------------
  85. #if wxUSE_LOGWINDOW
  86. class WXDLLIMPEXP_CORE wxLogWindow : public wxLogPassThrough
  87. {
  88. public:
  89. wxLogWindow(wxWindow *pParent, // the parent frame (can be NULL)
  90. const wxString& szTitle, // the title of the frame
  91. bool bShow = true, // show window immediately?
  92. bool bPassToOld = true); // pass messages to the old target?
  93. virtual ~wxLogWindow();
  94. // window operations
  95. // show/hide the log window
  96. void Show(bool bShow = true);
  97. // retrieve the pointer to the frame
  98. wxFrame *GetFrame() const;
  99. // overridables
  100. // called if the user closes the window interactively, will not be
  101. // called if it is destroyed for another reason (such as when program
  102. // exits) - return true from here to allow the frame to close, false
  103. // to prevent this from happening
  104. virtual bool OnFrameClose(wxFrame *frame);
  105. // called right before the log frame is going to be deleted: will
  106. // always be called unlike OnFrameClose()
  107. virtual void OnFrameDelete(wxFrame *frame);
  108. protected:
  109. virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg);
  110. private:
  111. wxLogFrame *m_pLogFrame; // the log frame
  112. wxDECLARE_NO_COPY_CLASS(wxLogWindow);
  113. };
  114. #endif // wxUSE_LOGWINDOW
  115. #endif // wxUSE_GUI
  116. #endif // _WX_LOGG_H_