notebook.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 723 行 · 第 1/2 页
CPP
723 行
///////////////////////////////////////////////////////////////////////////////
// Name: notebook.cpp
// Purpose: implementation of wxNotebook
// Author: Julian Smart
// Modified by:
// Created: 17/09/98
// RCS-ID: $Id: notebook.cpp,v 1.36 2005/09/17 21:00:47 VZ Exp $
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "notebook.h"
#endif
#ifdef __VMS
#pragma message disable unscomzer
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef __WXPALMOS__
#include "wx/string.h"
#include "wx/log.h"
#include "wx/settings.h"
#include "wx/generic/imaglist.h"
#include "wx/notebook.h"
#include "wx/dcclient.h"
#include "wx/generic/tabg.h"
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// check that the page index is valid
#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
EVT_SIZE(wxNotebook::OnSize)
EVT_PAINT(wxNotebook::OnPaint)
EVT_MOUSE_EVENTS(wxNotebook::OnMouseEvent)
EVT_SET_FOCUS(wxNotebook::OnSetFocus)
EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
// ============================================================================
// implementation
// ============================================================================
// ============================================================================
// Private class
// ============================================================================
// This reuses wxTabView to draw the tabs.
class WXDLLEXPORT wxNotebookTabView: public wxTabView
{
DECLARE_DYNAMIC_CLASS(wxNotebookTabView)
public:
wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
~wxNotebookTabView(void);
// Called when a tab is activated
virtual void OnTabActivate(int activateId, int deactivateId);
// Allows vetoing
virtual bool OnTabPreActivate(int activateId, int deactivateId);
protected:
wxNotebook* m_notebook;
};
// ----------------------------------------------------------------------------
// wxNotebook construction
// ----------------------------------------------------------------------------
// common part of all ctors
void wxNotebook::Init()
{
m_tabView = (wxNotebookTabView*) NULL;
m_nSelection = -1;
}
// default for dynamic class
wxNotebook::wxNotebook()
{
Init();
}
// the same arguments as for wxControl
wxNotebook::wxNotebook(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
Init();
Create(parent, id, pos, size, style, name);
}
// Create() function
bool wxNotebook::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
// base init
SetName(name);
m_windowId = id == wxID_ANY ? NewControlId() : id;
if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
return false;
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
SetTabView(new wxNotebookTabView(this));
return true;
}
// dtor
wxNotebook::~wxNotebook()
{
delete m_tabView;
}
// ----------------------------------------------------------------------------
// wxNotebook accessors
// ----------------------------------------------------------------------------
int wxNotebook::GetRowCount() const
{
// TODO
return 0;
}
int wxNotebook::SetSelection(size_t nPage)
{
wxASSERT( IS_VALID_PAGE(nPage) );
wxNotebookPage* pPage = GetPage(nPage);
m_tabView->SetTabSelection((int) (long) pPage);
// TODO
return 0;
}
#if 0
void wxNotebook::AdvanceSelection(bool bForward)
{
int nSel = GetSelection();
int nMax = GetPageCount() - 1;
if ( bForward )
SetSelection(nSel == nMax ? 0 : nSel + 1);
else
SetSelection(nSel == 0 ? nMax : nSel - 1);
}
#endif
bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
{
wxASSERT( IS_VALID_PAGE(nPage) );
wxNotebookPage* page = GetPage(nPage);
if (page)
{
m_tabView->SetTabText((int) (long) page, strText);
Refresh();
return true;
}
return false;
}
wxString wxNotebook::GetPageText(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage);
if (page)
return m_tabView->GetTabText((int) (long) page);
else
return wxEmptyString;
}
int wxNotebook::GetPageImage(size_t nPage) const
{
wxASSERT( IS_VALID_PAGE(nPage) );
// TODO
return 0;
}
bool wxNotebook::SetPageImage(size_t nPage, int nImage)
{
wxASSERT( IS_VALID_PAGE(nPage) );
// TODO
return false;
}
// set the size (the same for all pages)
void wxNotebook::SetPageSize(const wxSize& size)
{
// TODO
}
// set the padding between tabs (in pixels)
void wxNotebook::SetPadding(const wxSize& padding)
{
// TODO
}
// set the size of the tabs for wxNB_FIXEDWIDTH controls
void wxNotebook::SetTabSize(const wxSize& sz)
{
// TODO
}
// ----------------------------------------------------------------------------
// wxNotebook operations
// ----------------------------------------------------------------------------
// remove one page from the notebook and delete it
bool wxNotebook::DeletePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), false );
if (m_nSelection != -1)
{
m_pages[m_nSelection]->Show(false);
m_pages[m_nSelection]->Lower();
}
wxNotebookPage* pPage = GetPage(nPage);
m_tabView->RemoveTab((int) (long) pPage);
m_pages.Remove(pPage);
delete pPage;
if (m_pages.GetCount() == 0)
{
m_nSelection = -1;
m_tabView->SetTabSelection(-1, false);
}
else if (m_nSelection > -1)
{
m_nSelection = -1;
m_tabView->SetTabSelection((int) (long) GetPage(0), false);
if (m_nSelection != 0)
ChangePage(-1, 0);
}
RefreshLayout(false);
return true;
}
bool wxNotebook::DeletePage(wxNotebookPage* page)
{
int pagePos = FindPagePosition(page);
if (pagePos > -1)
return DeletePage(pagePos);
else
return false;
}
bool wxNotebook::RemovePage(size_t nPage)
{
return DoRemovePage(nPage) != NULL;
}
// remove one page from the notebook
wxWindow* wxNotebook::DoRemovePage(size_t nPage)
{
wxCHECK( IS_VALID_PAGE(nPage), NULL );
m_pages[nPage]->Show(false);
// m_pages[nPage]->Lower();
wxNotebookPage* pPage = GetPage(nPage);
m_tabView->RemoveTab((int) (long) pPage);
m_pages.Remove(pPage);
if (m_pages.GetCount() == 0)
{
m_nSelection = -1;
m_tabView->SetTabSelection(-1, true);
}
else if (m_nSelection > -1)
{
// Only change the selection if the page we
// deleted was the selection.
if (nPage == (size_t)m_nSelection)
{
m_nSelection = -1;
// Select the first tab. Generates a ChangePage.
m_tabView->SetTabSelection(0, true);
}
else
{
// We must adjust which tab we think is selected.
// If greater than the page we deleted, it must be moved down
// a notch.
if (size_t(m_nSelection) > nPage)
m_nSelection -- ;
}
}
RefreshLayout(false);
return pPage;
}
bool wxNotebook::RemovePage(wxNotebookPage* page)
{
int pagePos = FindPagePosition(page);
if (pagePos > -1)
return RemovePage(pagePos);
else
return false;
}
// Find the position of the wxNotebookPage, -1 if not found.
int wxNotebook::FindPagePosition(wxNotebookPage* page) const
{
size_t nPageCount = GetPageCount();
size_t nPage;
for ( nPage = 0; nPage < nPageCount; nPage++ )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?