wxUSE_LOG fixes and sizer adjustements related to positioning with/without LOG output.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28349 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2004-07-21 10:29:21 +00:00
parent 48112931db
commit b29903d485
8 changed files with 194 additions and 13 deletions

View File

@@ -220,7 +220,9 @@ public:
void OnDragMoveAllow(wxCommandEvent& event);
void OnNewFrame(wxCommandEvent& event);
void OnHelp (wxCommandEvent& event);
#if wxUSE_LOG
void OnLogClear(wxCommandEvent& event);
#endif // wxUSE_LOG
void OnCopy(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event);
@@ -248,10 +250,13 @@ private:
// GUI controls
wxListBox *m_ctrlFile,
*m_ctrlText;
#if wxUSE_LOG
wxTextCtrl *m_ctrlLog;
wxLog *m_pLog,
*m_pLogPrev;
#endif // wxUSE_LOG
// move the text by default (or copy)?
bool m_moveByDefault;
@@ -821,7 +826,9 @@ BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
EVT_MENU(Menu_DragMoveAllow,DnDFrame::OnDragMoveAllow)
EVT_MENU(Menu_NewFrame, DnDFrame::OnNewFrame)
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
#if wxUSE_LOG
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
#endif // wxUSE_LOG
EVT_MENU(Menu_Copy, DnDFrame::OnCopy)
EVT_MENU(Menu_Paste, DnDFrame::OnPaste)
EVT_MENU(Menu_CopyBitmap, DnDFrame::OnCopyBitmap)
@@ -887,11 +894,13 @@ bool DnDApp::OnInit()
{
#if wxUSE_DRAG_AND_DROP || wxUSE_CLIPBOARD
// switch on trace messages
#if wxUSE_LOG
#if defined(__WXGTK__)
wxLog::AddTraceMask(_T("clipboard"));
#elif defined(__WXMSW__)
wxLog::AddTraceMask(wxTRACE_OleCalls);
#endif
#endif // wxUSE_LOG
#if wxUSE_LIBPNG
wxImage::AddHandler( new wxPNGHandler );
@@ -942,8 +951,10 @@ DnDFrame::DnDFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h)
file_menu->AppendSeparator();
file_menu->Append(Menu_Quit, _T("E&xit\tCtrl-Q"));
#if wxUSE_LOG
wxMenu *log_menu = new wxMenu;
log_menu->Append(Menu_Clear, _T("Clear\tCtrl-L"));
#endif // wxUSE_LOG
wxMenu *help_menu = new wxMenu;
help_menu->Append(Menu_Help, _T("&Help..."));
@@ -965,7 +976,9 @@ DnDFrame::DnDFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h)
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, _T("&File"));
#if wxUSE_LOG
menu_bar->Append(log_menu, _T("&Log"));
#endif // wxUSE_LOG
menu_bar->Append(clip_menu, _T("&Clipboard"));
menu_bar->Append(help_menu, _T("&Help"));
@@ -979,6 +992,7 @@ DnDFrame::DnDFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h)
m_ctrlText = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 1, &strText,
wxLB_HSCROLL | wxLB_ALWAYS_SB );
#if wxUSE_LOG
m_ctrlLog = new wxTextCtrl(this, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_READONLY |
wxSUNKEN_BORDER );
@@ -986,12 +1000,15 @@ DnDFrame::DnDFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h)
// redirect log messages to the text window
m_pLog = new wxLogTextCtrl(m_ctrlLog);
m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
#endif // wxUSE_LOG
#if wxUSE_DRAG_AND_DROP
// associate drop targets with the controls
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
#if wxUSE_LOG
m_ctrlLog->SetDropTarget(new URLDropTarget);
#endif // wxUSE_LOG
#endif // wxUSE_DRAG_AND_DROP
wxBoxSizer *m_sizer_top = new wxBoxSizer( wxHORIZONTAL );
@@ -1000,7 +1017,10 @@ DnDFrame::DnDFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h)
wxBoxSizer *m_sizer = new wxBoxSizer( wxVERTICAL );
m_sizer->Add(m_sizer_top, 1, wxEXPAND );
m_sizer->Add(m_ctrlLog, 1, wxEXPAND | wxBOTTOM, 50);
#if wxUSE_LOG
m_sizer->Add(m_ctrlLog, 1, wxEXPAND);
#endif // wxUSE_LOG
m_sizer->Add(0,50);
SetSizer( m_sizer );
m_sizer->SetSizeHints( this );
@@ -1136,12 +1156,14 @@ void DnDFrame::OnHelp(wxCommandEvent& /* event */)
dialog.ShowModal();
}
#if wxUSE_LOG
void DnDFrame::OnLogClear(wxCommandEvent& /* event */ )
{
m_ctrlLog->Clear();
m_ctrlText->Clear();
m_ctrlFile->Clear();
}
#endif // wxUSE_LOG
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{
@@ -1201,10 +1223,12 @@ void DnDFrame::OnRightDown(wxMouseEvent &event )
DnDFrame::~DnDFrame()
{
#if wxUSE_LOG
if ( m_pLog != NULL ) {
if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog )
delete m_pLog;
}
#endif // wxUSE_LOG
}
// ---------------------------------------------------------------------------
@@ -1639,8 +1663,7 @@ void DnDShapeDialog::OnColour(wxCommandEvent& WXUNUSED(event))
DnDShapeFrame *DnDShapeFrame::ms_lastDropTarget = NULL;
DnDShapeFrame::DnDShapeFrame(wxFrame *parent)
: wxFrame(parent, wxID_ANY, _T("Shape Frame"),
wxDefaultPosition, wxSize(250, 150))
: wxFrame(parent, wxID_ANY, _T("Shape Frame"))
{
#if wxUSE_STATUSBAR
CreateStatusBar();

View File

@@ -30,6 +30,10 @@
#include "wx/wx.h"
#endif
#if !wxUSE_LOG
# error You must set wxUSE_LOG to 1 in setup.h
#endif
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------

View File

@@ -74,7 +74,9 @@ enum
LboxTest_AddSeveral,
LboxTest_AddMany,
LboxTest_Clear,
#if wxUSE_LOG
LboxTest_ClearLog,
#endif // wxUSE_LOG
LboxTest_Change,
LboxTest_ChangeText,
LboxTest_Delete,
@@ -117,7 +119,9 @@ protected:
void OnButtonDelete(wxCommandEvent& event);
void OnButtonDeleteSel(wxCommandEvent& event);
void OnButtonClear(wxCommandEvent& event);
#if wxUSE_LOG
void OnButtonClearLog(wxCommandEvent& event);
#endif // wxUSE_LOG
void OnButtonAdd(wxCommandEvent& event);
void OnButtonAddSeveral(wxCommandEvent& event);
void OnButtonAddMany(wxCommandEvent& event);
@@ -176,8 +180,10 @@ protected:
wxListBox *m_lbox;
wxSizer *m_sizerLbox;
#if wxUSE_LOG
// the listbox for logging messages
wxListBox *m_lboxLog;
#endif // wxUSE_LOG
// the text entries for "Add/change string" and "Delete" buttons
wxTextCtrl *m_textAdd,
@@ -185,13 +191,16 @@ protected:
*m_textDelete;
private:
#if wxUSE_LOG
// the log target we use to redirect messages to the listbox
wxLog *m_logTarget;
#endif // wxUSE_LOG
// any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE()
};
#if wxUSE_LOG
// A log target which just redirects the messages to a listbox
class LboxLogger : public wxLog
{
@@ -251,6 +260,7 @@ private:
// the old log target
wxLog *m_logOld;
};
#endif // wxUSE_LOG
// ----------------------------------------------------------------------------
// misc macros
@@ -269,7 +279,9 @@ BEGIN_EVENT_TABLE(LboxTestFrame, wxFrame)
EVT_BUTTON(LboxTest_Delete, LboxTestFrame::OnButtonDelete)
EVT_BUTTON(LboxTest_DeleteSel, LboxTestFrame::OnButtonDeleteSel)
EVT_BUTTON(LboxTest_Clear, LboxTestFrame::OnButtonClear)
#if wxUSE_LOG
EVT_BUTTON(LboxTest_ClearLog, LboxTestFrame::OnButtonClearLog)
#endif // wxUSE_LOG
EVT_BUTTON(LboxTest_Add, LboxTestFrame::OnButtonAdd)
EVT_BUTTON(LboxTest_AddSeveral, LboxTestFrame::OnButtonAddSeveral)
EVT_BUTTON(LboxTest_AddMany, LboxTestFrame::OnButtonAddMany)
@@ -308,8 +320,10 @@ bool LboxTestApp::OnInit()
wxFrame *frame = new LboxTestFrame(_T("wxListBox sample"));
frame->Show();
#if wxUSE_LOG
//wxLog::AddTraceMask(_T("listbox"));
wxLog::AddTraceMask(_T("scrollbar"));
#endif // wxUSE_LOG
return true;
}
@@ -329,11 +343,15 @@ LboxTestFrame::LboxTestFrame(const wxString& title)
m_chkHScroll =
m_chkSort = (wxCheckBox *)NULL;
m_lbox =
m_lbox = (wxListBox *)NULL;
#if wxUSE_LOG
m_lboxLog = (wxListBox *)NULL;
#endif // wxUSE_LOG
m_sizerLbox = (wxSizer *)NULL;
#if wxUSE_LOG
m_logTarget = (wxLog *)NULL;
#endif // wxUSE_LOG
wxPanel *panel = new wxPanel(this, wxID_ANY);
@@ -433,6 +451,7 @@ LboxTestFrame::LboxTestFrame(const wxString& title)
sizerUp->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
// the lower one only has the log listbox and a button to clear it
#if wxUSE_LOG
wxSizer *sizerDown = new wxStaticBoxSizer
(
new wxStaticBox(panel, wxID_ANY, _T("&Log window")),
@@ -440,10 +459,15 @@ LboxTestFrame::LboxTestFrame(const wxString& title)
);
m_lboxLog = new wxListBox(panel, wxID_ANY);
sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
#else
wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL);
#endif // wxUSE_LOG
wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
#if wxUSE_LOG
btn = new wxButton(panel, LboxTest_ClearLog, _T("Clear &log"));
sizerBtns->Add(btn);
sizerBtns->Add(10, 0); // spacer
#endif // wxUSE_LOG
btn = new wxButton(panel, LboxTest_Quit, _T("E&xit"));
sizerBtns->Add(btn);
sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
@@ -462,15 +486,19 @@ LboxTestFrame::LboxTestFrame(const wxString& title)
sizerTop->Fit(this);
sizerTop->SetSizeHints(this);
#if wxUSE_LOG
// now that everything is created we can redirect the log messages to the
// listbox
m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
wxLog::SetActiveTarget(m_logTarget);
#endif // wxUSE_LOG
}
LboxTestFrame::~LboxTestFrame()
{
#if wxUSE_LOG
delete m_logTarget;
#endif // wxUSE_LOG
}
// ----------------------------------------------------------------------------
@@ -597,10 +625,12 @@ void LboxTestFrame::OnButtonClear(wxCommandEvent& WXUNUSED(event))
m_lbox->Clear();
}
#if wxUSE_LOG
void LboxTestFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
{
m_lboxLog->Clear();
}
#endif // wxUSE_LOG
void LboxTestFrame::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
{

View File

@@ -115,7 +115,9 @@ public:
void OnFullScreen( wxCommandEvent &event );
wxScrolledWindow *m_scrolled;
#if wxUSE_LOG
wxTextCtrl *m_log;
#endif // wxUSE_LOG
private:
DECLARE_DYNAMIC_CLASS(MyFrame)
@@ -400,13 +402,17 @@ MyFrame::MyFrame()
m_scrolled = new MyScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxSize(100,100) );
m_scrolled->SetScrollbars( 10, 10, 50, 50 );
#if wxUSE_LOG
m_log = new wxTextCtrl( this, wxID_ANY, _T("This is the log window.\n"), wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
delete old_log;
#endif // wxUSE_LOG
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( m_scrolled, 1, wxEXPAND );
#if wxUSE_LOG
topsizer->Add( m_log, 0, wxEXPAND );
#endif // wxUSE_LOG
SetAutoLayout( true );
SetSizer( topsizer );

View File

@@ -97,7 +97,12 @@ class MyPanel: public wxPanel
{
public:
MyPanel(wxFrame *frame, int x, int y, int w, int h);
virtual ~MyPanel() { delete wxLog::SetActiveTarget(m_logOld); }
virtual ~MyPanel()
{
#if wxUSE_LOG
delete wxLog::SetActiveTarget(m_logOld);
#endif // wxUSE_LOG
}
#if wxUSE_CLIPBOARD
void DoPasteFromClipboard();
@@ -124,9 +129,10 @@ public:
MyTextCtrl *m_textrich;
#if wxUSE_LOG
wxTextCtrl *m_log;
wxLog *m_logOld;
#endif // wxUSE_LOG
private:
// get the currently focused text control or return the default one is no
@@ -195,7 +201,9 @@ public:
wxLogMessage(_T("Already at the top"));
}
#if wxUSE_LOG
void OnLogClear(wxCommandEvent& event);
#endif // wxUSE_LOG
void OnFileSave(wxCommandEvent& event);
void OnFileLoad(wxCommandEvent& event);
void OnRichTextTest(wxCommandEvent& event);
@@ -405,6 +413,7 @@ bool MyApp::OnInit()
menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page up"));
menu_bar->Append(menuText, _T("Te&xt"));
#if wxUSE_LOG
wxMenu *menuLog = new wxMenu;
menuLog->AppendCheckItem(TEXT_LOG_KEY, _T("Log &key events"));
menuLog->AppendCheckItem(TEXT_LOG_CHAR, _T("Log &char events"));
@@ -423,7 +432,9 @@ bool MyApp::OnInit()
MyTextCtrl::ms_logKey =
MyTextCtrl::ms_logChar =
MyTextCtrl::ms_logText = true;
menu_bar->Append(menuLog, _T("&Log"));
#endif // wxUSE_LOG
frame->SetMenuBar(menu_bar);
@@ -840,16 +851,18 @@ END_EVENT_TABLE()
MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
: wxPanel( frame, wxID_ANY, wxPoint(x, y), wxSize(w, h) )
{
#if wxUSE_LOG
m_log = new wxTextCtrl( this, wxID_ANY, _T("This is the log window.\n"),
wxPoint(5,260), wxSize(630,100),
wxTE_MULTILINE | wxTE_READONLY /* | wxTE_RICH */);
m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
#endif // wxUSE_LOG
// single line text controls
m_text = new MyTextCtrl( this, wxID_ANY, _T("Single line."),
wxPoint(10,10), wxSize(140,wxDefaultCoord),
wxDefaultPosition, wxDefaultSize,
wxTE_PROCESS_ENTER);
m_text->SetForegroundColour(*wxBLUE);
m_text->SetBackgroundColour(*wxLIGHT_GREY);
@@ -949,13 +962,47 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_textrich->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE));
m_textrich->AppendText(_T("And this should be in blue and the text you ")
_T("type should be in blue as well"));
wxBoxSizer *column1 = new wxBoxSizer(wxVERTICAL);
column1->Add( m_text, 0, wxALL, 10 );
column1->Add( m_password, 0, wxALL, 10 );
column1->Add( m_readonly, 0, wxALL, 10 );
column1->Add( m_limited, 0, wxALL, 10 );
column1->Add( m_horizontal, 1, wxALL | wxEXPAND, 10 );
wxBoxSizer *column2 = new wxBoxSizer(wxVERTICAL);
column2->Add( m_multitext, 1, wxALL | wxEXPAND, 10 );
column2->Add( m_tab, 1, wxALL | wxEXPAND, 10 );
column2->Add( m_enter, 1, wxALL | wxEXPAND, 10 );
wxBoxSizer *column3 = new wxBoxSizer(wxVERTICAL);
column3->Add( m_textrich, 1, wxALL | wxEXPAND, 10 );
wxBoxSizer *row1 = new wxBoxSizer(wxHORIZONTAL);
row1->Add( column1, 0, wxALL | wxEXPAND, 10 );
row1->Add( column2, 1, wxALL | wxEXPAND, 10 );
row1->Add( column3, 1, wxALL | wxEXPAND, 10 );
wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add( row1, 2, wxALL | wxEXPAND, 10 );
#if wxUSE_LOG
wxBoxSizer *row2 = new wxBoxSizer(wxHORIZONTAL);
row2->Add( m_log, 1, wxALL | wxEXPAND, 10 );
topSizer->Add( row2, 1, wxALL | wxEXPAND, 10 );
#endif
SetAutoLayout( true );
SetSizer(topSizer);
}
void MyPanel::OnSize( wxSizeEvent &event )
{
#if wxUSE_LOG
wxSize client_area( GetClientSize() );
if (m_log)
m_log->SetSize( 0, 260, client_area.x, client_area.y - 260 );
#endif // wxUSE_LOG
event.Skip();
}
@@ -977,38 +1024,52 @@ void MyPanel::DoPasteFromClipboard()
if (!wxTheClipboard->Open())
{
#if wxUSE_LOG
*m_log << _T("Error opening the clipboard.\n");
#endif // wxUSE_LOG
return;
}
else
{
#if wxUSE_LOG
*m_log << _T("Successfully opened the clipboard.\n");
#endif // wxUSE_LOG
}
wxTextDataObject data;
if (wxTheClipboard->IsSupported( data.GetFormat() ))
{
#if wxUSE_LOG
*m_log << _T("Clipboard supports requested format.\n");
#endif // wxUSE_LOG
if (wxTheClipboard->GetData( data ))
{
#if wxUSE_LOG
*m_log << _T("Successfully retrieved data from the clipboard.\n");
#endif // wxUSE_LOG
*m_multitext << data.GetText() << _T("\n");
}
else
{
#if wxUSE_LOG
*m_log << _T("Error getting data from the clipboard.\n");
#endif // wxUSE_LOG
}
}
else
{
#if wxUSE_LOG
*m_log << _T("Clipboard doesn't support requested format.\n");
#endif // wxUSE_LOG
}
wxTheClipboard->Close();
#if wxUSE_LOG
*m_log << _T("Closed the clipboard.\n");
#endif // wxUSE_LOG
}
void MyPanel::DoCopyToClipboard()
@@ -1022,36 +1083,48 @@ void MyPanel::DoCopyToClipboard()
if (text.IsEmpty())
{
#if wxUSE_LOG
*m_log << _T("No text to copy.\n");
#endif // wxUSE_LOG
return;
}
if (!wxTheClipboard->Open())
{
#if wxUSE_LOG
*m_log << _T("Error opening the clipboard.\n");
#endif // wxUSE_LOG
return;
}
else
{
#if wxUSE_LOG
*m_log << _T("Successfully opened the clipboard.\n");
#endif // wxUSE_LOG
}
wxTextDataObject *data = new wxTextDataObject( text );
if (!wxTheClipboard->SetData( data ))
{
#if wxUSE_LOG
*m_log << _T("Error while copying to the clipboard.\n");
#endif // wxUSE_LOG
}
else
{
#if wxUSE_LOG
*m_log << _T("Successfully copied data to the clipboard.\n");
#endif // wxUSE_LOG
}
wxTheClipboard->Close();
#if wxUSE_LOG
*m_log << _T("Closed the clipboard.\n");
#endif // wxUSE_LOG
}
#endif // wxUSE_CLIPBOARD
@@ -1099,7 +1172,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(TEXT_LOG_MOUSE,MyFrame::OnLogMouse)
EVT_MENU(TEXT_LOG_TEXT, MyFrame::OnLogText)
EVT_MENU(TEXT_LOG_FOCUS,MyFrame::OnLogFocus)
#if wxUSE_LOG
EVT_MENU(TEXT_CLEAR, MyFrame::OnLogClear)
#endif // wxUSE_LOG
#if wxUSE_TOOLTIPS
EVT_MENU(TEXT_TOOLTIPS_SETDELAY, MyFrame::OnSetTooltipDelay)
@@ -1200,10 +1275,12 @@ void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
}
#endif // tooltips
#if wxUSE_LOG
void MyFrame::OnLogClear(wxCommandEvent& WXUNUSED(event))
{
m_panel->m_log->Clear();
}
#endif // wxUSE_LOG
void MyFrame::OnSetEditable(wxCommandEvent& WXUNUSED(event))
{

View File

@@ -165,7 +165,10 @@ bool MyApp::OnInit()
// My frame constructor
MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
: wxFrame((wxFrame *)NULL, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
m_treeCtrl(NULL), m_textCtrl(NULL)
m_treeCtrl(NULL)
#if wxUSE_LOG
, m_textCtrl(NULL)
#endif // wxUSE_LOG
{
// This reduces flicker effects - even better would be to define
// OnEraseBackground to do nothing. When the tree control's scrollbars are
@@ -255,10 +258,12 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
SetMenuBar(menu_bar);
#endif // wxUSE_MENUS
#if wxUSE_LOG
// create the controls
m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxT(""),
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxSUNKEN_BORDER);
#endif // wxUSE_LOG
CreateTreeWithDefStyle();
@@ -269,6 +274,7 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
CreateStatusBar(2);
#endif // wxUSE_STATUSBAR
#if wxUSE_LOG
#ifdef __WXMOTIF__
// For some reason, we get a memcpy crash in wxLogStream::DoLogStream
// on gcc/wxMotif, if we use wxLogTextCtl. Maybe it's just gcc?
@@ -278,11 +284,14 @@ MyFrame::MyFrame(const wxString& title, int x, int y, int w, int h)
wxLogTextCtrl *logWindow = new wxLogTextCtrl(m_textCtrl);
delete wxLog::SetActiveTarget(logWindow);
#endif
#endif // wxUSE_LOG
}
MyFrame::~MyFrame()
{
#if wxUSE_LOG
delete wxLog::SetActiveTarget(NULL);
#endif // wxUSE_LOG
}
void MyFrame::CreateTreeWithDefStyle()
@@ -354,7 +363,11 @@ void MyFrame::OnIdle(wxIdleEvent& event)
void MyFrame::OnSize(wxSizeEvent& event)
{
if ( m_treeCtrl && m_textCtrl )
if ( m_treeCtrl
#if wxUSE_LOG
&& m_textCtrl
#endif // wxUSE_LOG
)
{
Resize();
}
@@ -365,8 +378,13 @@ void MyFrame::OnSize(wxSizeEvent& event)
void MyFrame::Resize()
{
wxSize size = GetClientSize();
m_treeCtrl->SetSize(0, 0, size.x, 2*size.y/3);
m_treeCtrl->SetSize(0, 0, size.x, size.y
#if !wxUSE_LOG
);
#else
*2/3);
m_textCtrl->SetSize(0, 2*size.y/3, size.x, size.y/3);
#endif
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))

View File

@@ -227,7 +227,9 @@ private:
void CreateTree(long style);
MyTreeCtrl *m_treeCtrl;
#if wxUSE_LOG
wxTextCtrl *m_textCtrl;
#endif // wxUSE_LOG
void DoSetBold(bool bold = true);

View File

@@ -80,7 +80,9 @@ public:
protected:
// event handlers
#if wxUSE_LOG
void OnButtonClearLog(wxCommandEvent& event);
#endif // wxUSE_LOG
void OnButtonQuit(wxCommandEvent& event);
// initialize the notebook: add all pages to it
@@ -90,11 +92,13 @@ private:
// the panel containing everything
wxPanel *m_panel;
#if wxUSE_LOG
// the listbox for logging messages
wxListBox *m_lboxLog;
// the log target we use to redirect messages to the listbox
wxLog *m_logTarget;
#endif // wxUSE_LOG
// the notebook containing the test pages
wxNotebook *m_notebook;
@@ -106,6 +110,7 @@ private:
DECLARE_EVENT_TABLE()
};
#if wxUSE_LOG
// A log target which just redirects the messages to a listbox
class LboxLogger : public wxLog
{
@@ -162,6 +167,7 @@ private:
// the old log target
wxLog *m_logOld;
};
#endif // wxUSE_LOG
// array of pages
WX_DEFINE_ARRAY_PTR(WidgetsPage *, ArrayWidgetsPage);
@@ -177,7 +183,9 @@ IMPLEMENT_APP(WidgetsApp)
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
#if wxUSE_LOG
EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog)
#endif // wxUSE_LOG
EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnButtonQuit)
END_EVENT_TABLE()
@@ -236,8 +244,10 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
wxTAB_TRAVERSAL)
{
// init everything
#if wxUSE_LOG
m_lboxLog = (wxListBox *)NULL;
m_logTarget = (wxLog *)NULL;
#endif // wxUSE_LOG
m_notebook = (wxNotebook *)NULL;
m_imaglist = (wxImageList *)NULL;
@@ -255,6 +265,7 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
InitNotebook();
// the lower one only has the log listbox and a button to clear it
#if wxUSE_LOG
wxSizer *sizerDown = new wxStaticBoxSizer(
new wxStaticBox( m_panel, wxID_ANY, _T("&Log window") ),
wxVERTICAL);
@@ -262,11 +273,17 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
m_lboxLog = new wxListBox(m_panel, wxID_ANY);
sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
sizerDown->SetMinSize(100, 150);
#else
wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL);
#endif // wxUSE_LOG
wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
wxButton *btn = new wxButton(m_panel, Widgets_ClearLog, _T("Clear &log"));
wxButton *btn;
#if wxUSE_LOG
btn = new wxButton(m_panel, Widgets_ClearLog, _T("Clear &log"));
sizerBtns->Add(btn);
sizerBtns->Add(10, 0); // spacer
#endif // wxUSE_LOG
btn = new wxButton(m_panel, Widgets_Quit, _T("E&xit"));
sizerBtns->Add(btn);
sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
@@ -281,8 +298,8 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
sizerTop->Fit(this);
sizerTop->SetSizeHints(this);
#if wxUSE_LOG && !defined(__WXCOCOA__)
// wxCocoa's listbox is too flakey to use for logging right now
#if !defined(__WXCOCOA__)
// now that everything is created we can redirect the log messages to the
// listbox
m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
@@ -327,7 +344,9 @@ void WidgetsFrame::InitNotebook()
WidgetsFrame::~WidgetsFrame()
{
#if wxUSE_LOG
delete m_logTarget;
#endif // wxUSE_LOG
delete m_imaglist;
}
@@ -340,10 +359,12 @@ void WidgetsFrame::OnButtonQuit(wxCommandEvent& WXUNUSED(event))
Close();
}
#if wxUSE_LOG
void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
{
m_lboxLog->Clear();
}
#endif // wxUSE_LOG
// ----------------------------------------------------------------------------
// WidgetsPageInfo