Some more wxMotif improvements: DrawIcon fixed; generic notebook
implementation used. wxGTK's DrawIcon has 2 args added for wxMSW compatibility. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1259 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
926c550dc5
commit
793f619f7f
@ -38,6 +38,13 @@ public:
|
||||
wxIcon();
|
||||
wxIcon( const wxIcon& icon);
|
||||
wxIcon( const char **bits, int width=-1, int height=-1 );
|
||||
|
||||
// For compatibility with wxMSW where desired size is sometimes required to
|
||||
// distinguish between multiple icons in a resource.
|
||||
wxIcon( const wxString& filename, int type = wxBITMAP_TYPE_XPM, int WXUNUSED(desiredWidth)=-1, int WXUNUSED(desiredHeight)=-1 ):
|
||||
wxBitmap(filename, type)
|
||||
{
|
||||
}
|
||||
wxIcon( char **bits, int width=-1, int height=-1 );
|
||||
|
||||
wxIcon& operator = (const wxIcon& icon);
|
||||
|
@ -38,6 +38,13 @@ public:
|
||||
wxIcon();
|
||||
wxIcon( const wxIcon& icon);
|
||||
wxIcon( const char **bits, int width=-1, int height=-1 );
|
||||
|
||||
// For compatibility with wxMSW where desired size is sometimes required to
|
||||
// distinguish between multiple icons in a resource.
|
||||
wxIcon( const wxString& filename, int type = wxBITMAP_TYPE_XPM, int WXUNUSED(desiredWidth)=-1, int WXUNUSED(desiredHeight)=-1 ):
|
||||
wxBitmap(filename, type)
|
||||
{
|
||||
}
|
||||
wxIcon( char **bits, int width=-1, int height=-1 );
|
||||
|
||||
wxIcon& operator = (const wxIcon& icon);
|
||||
|
@ -142,7 +142,7 @@ class WXDLLEXPORT wxDC: public wxObject
|
||||
|
||||
virtual bool CanDrawBitmap(void) const = 0;
|
||||
|
||||
virtual void DrawIcon( const wxIcon &icon, long x, long y, bool useMask=FALSE );
|
||||
virtual void DrawIcon( const wxIcon &icon, long x, long y);
|
||||
inline void DrawIcon(const wxIcon& icon, const wxPoint& pt)
|
||||
{
|
||||
DrawIcon(icon, pt.x, pt.y);
|
||||
|
@ -64,7 +64,7 @@ class WXDLLEXPORT wxWindowDC: public wxDC
|
||||
virtual void DrawEllipse( long x, long y, long width, long height );
|
||||
|
||||
virtual bool CanDrawBitmap(void) const;
|
||||
virtual void DrawIcon( const wxIcon &icon, long x, long y, bool useMask=FALSE );
|
||||
virtual void DrawIcon( const wxIcon &icon, long x, long y);
|
||||
virtual bool Blit( long xdest, long ydest, long width, long height,
|
||||
wxDC *source, long xsrc, long ysrc, int logical_func = wxCOPY, bool useMask=FALSE );
|
||||
|
||||
|
@ -1,250 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: notebook.h
|
||||
// Purpose: wxNotebook class (a.k.a. property sheet, tabbed dialog)
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_NOTEBOOK_H_
|
||||
#define _WX_NOTEBOOK_H_
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "notebook.h"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/event.h"
|
||||
#include "wx/control.h"
|
||||
#include "wx/generic/tabg.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// fwd declarations
|
||||
class WXDLLEXPORT wxImageList;
|
||||
class WXDLLEXPORT wxWindow;
|
||||
|
||||
// array of notebook pages
|
||||
typedef wxWindow wxNotebookPage; // so far, any window can be a page
|
||||
WX_DEFINE_ARRAY(wxNotebookPage *, wxArrayPages);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// notebook events
|
||||
// ----------------------------------------------------------------------------
|
||||
class WXDLLEXPORT wxNotebookEvent : public wxCommandEvent
|
||||
{
|
||||
public:
|
||||
wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
|
||||
int nSel = -1, int nOldSel = -1)
|
||||
: wxCommandEvent(commandType, id) { m_nSel = nSel; m_nOldSel = nOldSel; }
|
||||
|
||||
// accessors
|
||||
int GetSelection() const { return m_nSel; }
|
||||
int GetOldSelection() const { return m_nOldSel; }
|
||||
|
||||
void SetSelection(int sel) { m_nSel = sel; }
|
||||
void SetOldSelection(int oldSel) { m_nOldSel = oldSel; }
|
||||
|
||||
private:
|
||||
int m_nSel, // currently selected page
|
||||
m_nOldSel; // previously selected page
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxNotebook;
|
||||
|
||||
// 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);
|
||||
|
||||
protected:
|
||||
wxNotebook* m_notebook;
|
||||
};
|
||||
|
||||
class wxNotebook : public wxControl
|
||||
{
|
||||
public:
|
||||
// ctors
|
||||
// -----
|
||||
// default for dynamic class
|
||||
wxNotebook();
|
||||
// the same arguments as for wxControl (@@@ any special styles?)
|
||||
wxNotebook(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = 0,
|
||||
const wxString& name = "notebook");
|
||||
// Create() function
|
||||
bool Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = 0,
|
||||
const wxString& name = "notebook");
|
||||
// dtor
|
||||
~wxNotebook();
|
||||
|
||||
// accessors
|
||||
// ---------
|
||||
// get number of pages in the dialog
|
||||
int GetPageCount() const;
|
||||
|
||||
// Find the position of the wxNotebookPage, -1 if not found.
|
||||
int FindPagePosition(wxNotebookPage* page) const;
|
||||
|
||||
// set the currently selected page, return the index of the previously
|
||||
// selected one (or -1 on error)
|
||||
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
|
||||
int SetSelection(int nPage);
|
||||
// cycle thru the tabs
|
||||
void AdvanceSelection(bool bForward = TRUE);
|
||||
// get the currently selected page
|
||||
int GetSelection() const { return m_nSelection; }
|
||||
|
||||
// set/get the title of a page
|
||||
bool SetPageText(int nPage, const wxString& strText);
|
||||
wxString GetPageText(int nPage) const;
|
||||
|
||||
// image list stuff: each page may have an image associated with it. All
|
||||
// the images belong to an image list, so you have to
|
||||
// 1) create an image list
|
||||
// 2) associate it with the notebook
|
||||
// 3) set for each page it's image
|
||||
// associate image list with a control
|
||||
void SetImageList(wxImageList* imageList);
|
||||
// get pointer (may be NULL) to the associated image list
|
||||
wxImageList* GetImageList() const { return m_pImageList; }
|
||||
|
||||
// sets/returns item's image index in the current image list
|
||||
int GetPageImage(int nPage) const;
|
||||
bool SetPageImage(int nPage, int nImage);
|
||||
|
||||
// currently it's always 1 because wxGTK doesn't support multi-row
|
||||
// tab controls
|
||||
int GetRowCount() const;
|
||||
|
||||
// control the appearance of the notebook pages
|
||||
// set the size (the same for all pages)
|
||||
void SetPageSize(const wxSize& size);
|
||||
// set the padding between tabs (in pixels)
|
||||
void SetPadding(const wxSize& padding);
|
||||
|
||||
// operations
|
||||
// ----------
|
||||
// remove one page from the notebook, and delete the page.
|
||||
bool DeletePage(int nPage);
|
||||
bool DeletePage(wxNotebookPage* page);
|
||||
// remove one page from the notebook, without deleting the page.
|
||||
bool RemovePage(int nPage);
|
||||
bool RemovePage(wxNotebookPage* page);
|
||||
// remove all pages
|
||||
bool DeleteAllPages();
|
||||
// adds a new page to the notebook (it will be deleted ny the notebook,
|
||||
// don't delete it yourself). If bSelect, this page becomes active.
|
||||
bool AddPage(wxNotebookPage *pPage,
|
||||
const wxString& strText,
|
||||
bool bSelect = FALSE,
|
||||
int imageId = -1);
|
||||
// the same as AddPage(), but adds it at the specified position
|
||||
bool InsertPage(int nPage,
|
||||
wxNotebookPage *pPage,
|
||||
const wxString& strText,
|
||||
bool bSelect = FALSE,
|
||||
int imageId = -1);
|
||||
// get the panel which represents the given page
|
||||
wxNotebookPage *GetPage(int nPage) { return m_aPages[nPage]; }
|
||||
|
||||
// callbacks
|
||||
// ---------
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnIdle(wxIdleEvent& event);
|
||||
void OnSelChange(wxNotebookEvent& event);
|
||||
void OnSetFocus(wxFocusEvent& event);
|
||||
void OnNavigationKey(wxNavigationKeyEvent& event);
|
||||
|
||||
// base class virtuals
|
||||
// -------------------
|
||||
virtual void Command(wxCommandEvent& event);
|
||||
virtual void SetConstraintSizes(bool recurse = TRUE);
|
||||
virtual bool DoPhase(int nPhase);
|
||||
|
||||
// Implementation
|
||||
|
||||
// wxNotebook on Motif uses a generic wxTabView to implement itself.
|
||||
inline wxTabView *GetTabView() const { return m_tabView; }
|
||||
inline void SetTabView(wxTabView *v) { m_tabView = v; }
|
||||
|
||||
void OnMouseEvent(wxMouseEvent& event);
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
|
||||
virtual void ChangeFont(bool keepOriginalSize = TRUE);
|
||||
virtual void ChangeBackgroundColour();
|
||||
virtual void ChangeForegroundColour();
|
||||
virtual wxRect GetAvailableClientSize();
|
||||
|
||||
// Implementation: calculate the layout of the view rect
|
||||
// and resize the children if required
|
||||
bool RefreshLayout(bool force = TRUE);
|
||||
|
||||
protected:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
// helper functions
|
||||
void ChangePage(int nOldSel, int nSel); // change pages
|
||||
|
||||
wxImageList *m_pImageList; // we can have an associated image list
|
||||
wxArrayPages m_aPages; // array of pages
|
||||
|
||||
int m_nSelection; // the current selection (-1 if none)
|
||||
|
||||
wxTabView* m_tabView;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxNotebook)
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event macros
|
||||
// ----------------------------------------------------------------------------
|
||||
typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
|
||||
|
||||
#define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
|
||||
{ \
|
||||
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
|
||||
id, \
|
||||
-1, \
|
||||
(wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
|
||||
NULL \
|
||||
},
|
||||
|
||||
#define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
|
||||
{ \
|
||||
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
|
||||
id, \
|
||||
-1, \
|
||||
(wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
|
||||
NULL \
|
||||
},
|
||||
|
||||
#endif // _WX_NOTEBOOK_H_
|
@ -8,7 +8,7 @@
|
||||
#include "wx/msw/notebook.h"
|
||||
#endif
|
||||
#elif defined(__WXMOTIF__)
|
||||
#include "wx/motif/notebook.h"
|
||||
#include "wx/generic/notebook.h"
|
||||
#elif defined(__WXGTK__)
|
||||
#include "wx/gtk/notebook.h"
|
||||
#elif defined(__WXQT__)
|
||||
|
@ -29,7 +29,8 @@
|
||||
|
||||
#include <wx/string.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/imaglist.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/generic/imaglist.h>
|
||||
#include <wx/generic/notebook.h>
|
||||
#include <wx/dcclient.h>
|
||||
|
||||
|
@ -91,7 +91,7 @@ wxDC::~wxDC(void)
|
||||
{
|
||||
};
|
||||
|
||||
void wxDC::DrawIcon( const wxIcon &WXUNUSED(icon), long WXUNUSED(x), long WXUNUSED(y), bool WXUNUSED(useMask) )
|
||||
void wxDC::DrawIcon( const wxIcon &WXUNUSED(icon), long WXUNUSED(x), long WXUNUSED(y))
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -849,12 +849,15 @@ static void XCopyRemote(Display *src_display, Display *dest_display,
|
||||
XDestroyImage(image);
|
||||
}
|
||||
|
||||
void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
|
||||
void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y)
|
||||
{
|
||||
if (!Ok()) return;
|
||||
|
||||
if (!icon.Ok()) return;
|
||||
|
||||
DrawBitmap(icon, x, y, TRUE);
|
||||
|
||||
#if 0
|
||||
// FreeGetPixelCache();
|
||||
|
||||
// Be sure that foreground pixels (1) of
|
||||
@ -909,7 +912,7 @@ void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask )
|
||||
(int) XLOG2DEV (x), (int) YLOG2DEV (y), FALSE, &cache);
|
||||
}
|
||||
CalcBoundingBox (x, y);
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
bool wxWindowDC::Blit( long xdest, long ydest, long width, long height,
|
||||
|
@ -475,7 +475,7 @@ int wxDialog::ShowModal()
|
||||
wxModalShowingStack.Insert((wxObject *)TRUE);
|
||||
|
||||
m_modalShowing = TRUE;
|
||||
// XtAddGrab((Widget) m_mainWidget, TRUE, FALSE);
|
||||
XtAddGrab((Widget) m_mainWidget, TRUE, FALSE);
|
||||
|
||||
XEvent event;
|
||||
|
||||
|
@ -109,7 +109,6 @@ LIB_CPP_SRC=\
|
||||
metafile.cpp \
|
||||
minifram.cpp \
|
||||
msgdlg.cpp \
|
||||
notebook.cpp \
|
||||
palette.cpp \
|
||||
pen.cpp \
|
||||
print.cpp \
|
||||
@ -143,6 +142,7 @@ LIB_CPP_SRC=\
|
||||
../generic/listctrl.cpp \
|
||||
../generic/laywin.cpp \
|
||||
../generic/msgdlgg.cpp \
|
||||
../generic/notebook.cpp \
|
||||
../generic/panelg.cpp \
|
||||
../generic/printps.cpp \
|
||||
../generic/prntdlgg.cpp \
|
||||
|
@ -1,653 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: notebook.cpp
|
||||
// Purpose: implementation of wxNotebook
|
||||
// Author: Julian Smart
|
||||
// Modified by:
|
||||
// Created: 17/09/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "notebook.h"
|
||||
#endif
|
||||
|
||||
#include <wx/string.h>
|
||||
#include <wx/log.h>
|
||||
#include <wx/imaglist.h>
|
||||
#include <wx/notebook.h>
|
||||
#include <wx/dcclient.h>
|
||||
|
||||
#include <Xm/Xm.h>
|
||||
#include <wx/motif/private.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// check that the page index is valid
|
||||
#define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount()))
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// event table
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if !USE_SHARED_LIBRARIES
|
||||
BEGIN_EVENT_TABLE(wxNotebook, wxControl)
|
||||
EVT_NOTEBOOK_PAGE_CHANGED(-1, 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)
|
||||
EVT_IDLE(wxNotebook::OnIdle)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
|
||||
#endif
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook construction
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// common part of all ctors
|
||||
void wxNotebook::Init()
|
||||
{
|
||||
m_tabView = (wxNotebookTabView*) NULL;
|
||||
m_pImageList = 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 == -1 ? NewControlId() : id;
|
||||
|
||||
// It's like a normal window...
|
||||
if (!wxWindow::Create(parent, id, pos, size, style, name))
|
||||
return FALSE;
|
||||
|
||||
SetTabView(new wxNotebookTabView(this));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// dtor
|
||||
wxNotebook::~wxNotebook()
|
||||
{
|
||||
delete m_tabView;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook accessors
|
||||
// ----------------------------------------------------------------------------
|
||||
int wxNotebook::GetPageCount() const
|
||||
{
|
||||
return m_aPages.Count();
|
||||
}
|
||||
|
||||
int wxNotebook::GetRowCount() const
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wxNotebook::SetSelection(int nPage)
|
||||
{
|
||||
if (nPage == -1)
|
||||
return 0;
|
||||
|
||||
wxASSERT( IS_VALID_PAGE(nPage) );
|
||||
|
||||
wxNotebookPage* pPage = GetPage(nPage);
|
||||
|
||||
m_tabView->SetTabSelection((int) (long) pPage);
|
||||
|
||||
// TODO
|
||||
return 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);
|
||||
}
|
||||
|
||||
bool wxNotebook::SetPageText(int 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(int 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(int nPage) const
|
||||
{
|
||||
wxASSERT( IS_VALID_PAGE(nPage) );
|
||||
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wxNotebook::SetPageImage(int nPage, int nImage)
|
||||
{
|
||||
wxASSERT( IS_VALID_PAGE(nPage) );
|
||||
|
||||
// TODO
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxNotebook::SetImageList(wxImageList* imageList)
|
||||
{
|
||||
m_pImageList = imageList;
|
||||
// TODO
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook operations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// remove one page from the notebook and delete it
|
||||
bool wxNotebook::DeletePage(int nPage)
|
||||
{
|
||||
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
|
||||
|
||||
if (m_nSelection != -1)
|
||||
{
|
||||
m_aPages[m_nSelection]->Show(FALSE);
|
||||
m_aPages[m_nSelection]->Lower();
|
||||
}
|
||||
|
||||
wxNotebookPage* pPage = GetPage(nPage);
|
||||
m_tabView->RemoveTab((int) (long) pPage);
|
||||
|
||||
delete m_aPages[nPage];
|
||||
m_aPages.Remove(nPage);
|
||||
|
||||
if (m_aPages.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;
|
||||
}
|
||||
|
||||
// remove one page from the notebook
|
||||
bool wxNotebook::RemovePage(int nPage)
|
||||
{
|
||||
wxCHECK( IS_VALID_PAGE(nPage), FALSE );
|
||||
|
||||
m_aPages[nPage]->Show(FALSE);
|
||||
// m_aPages[nPage]->Lower();
|
||||
|
||||
wxNotebookPage* pPage = GetPage(nPage);
|
||||
m_tabView->RemoveTab((int) (long) pPage);
|
||||
|
||||
m_aPages.Remove(nPage);
|
||||
|
||||
if (m_aPages.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 == m_nSelection)
|
||||
{
|
||||
m_nSelection = -1;
|
||||
// Select the first tab. Generates a ChangePage.
|
||||
m_tabView->SetTabSelection((int) (long) GetPage(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 (m_nSelection > nPage)
|
||||
m_nSelection -- ;
|
||||
}
|
||||
}
|
||||
|
||||
RefreshLayout(FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
int nPageCount = GetPageCount();
|
||||
int nPage;
|
||||
for ( nPage = 0; nPage < nPageCount; nPage++ )
|
||||
if (m_aPages[nPage] == page)
|
||||
return nPage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// remove all pages
|
||||
bool wxNotebook::DeleteAllPages()
|
||||
{
|
||||
m_tabView->ClearTabs(TRUE);
|
||||
|
||||
int nPageCount = GetPageCount();
|
||||
int nPage;
|
||||
for ( nPage = 0; nPage < nPageCount; nPage++ )
|
||||
delete m_aPages[nPage];
|
||||
|
||||
m_aPages.Clear();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// add a page to the notebook
|
||||
bool wxNotebook::AddPage(wxNotebookPage *pPage,
|
||||
const wxString& strText,
|
||||
bool bSelect,
|
||||
int imageId)
|
||||
{
|
||||
return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
|
||||
}
|
||||
|
||||
// same as AddPage() but does it at given position
|
||||
bool wxNotebook::InsertPage(int nPage,
|
||||
wxNotebookPage *pPage,
|
||||
const wxString& strText,
|
||||
bool bSelect,
|
||||
int imageId)
|
||||
{
|
||||
wxASSERT( pPage != NULL );
|
||||
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
|
||||
|
||||
m_tabView->AddTab((int) (long) pPage, strText);
|
||||
if (!bSelect)
|
||||
pPage->Show(FALSE);
|
||||
|
||||
// save the pointer to the page
|
||||
m_aPages.Insert(pPage, nPage);
|
||||
|
||||
if (bSelect)
|
||||
{
|
||||
// This will cause ChangePage to be called, via OnSelPage
|
||||
m_tabView->SetTabSelection((int) (long) pPage, TRUE);
|
||||
}
|
||||
|
||||
// some page must be selected: either this one or the first one if there is
|
||||
// still no selection
|
||||
if ( m_nSelection == -1 )
|
||||
ChangePage(-1, 0);
|
||||
|
||||
RefreshLayout(FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook callbacks
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// @@@ OnSize() is used for setting the font when it's called for the first
|
||||
// time because doing it in ::Create() doesn't work (for unknown reasons)
|
||||
void wxNotebook::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
static bool s_bFirstTime = TRUE;
|
||||
if ( s_bFirstTime ) {
|
||||
// TODO: any first-time-size processing.
|
||||
s_bFirstTime = FALSE;
|
||||
}
|
||||
|
||||
RefreshLayout();
|
||||
|
||||
// Processing continues to next OnSize
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
// This was supposed to cure the non-display of the notebook
|
||||
// until the user resizes the window.
|
||||
// What's going on?
|
||||
void wxNotebook::OnIdle(wxIdleEvent& event)
|
||||
{
|
||||
static bool s_bFirstTime = TRUE;
|
||||
if ( s_bFirstTime ) {
|
||||
/*
|
||||
wxSize sz(GetSize());
|
||||
sz.x ++;
|
||||
SetSize(sz);
|
||||
sz.x --;
|
||||
SetSize(sz);
|
||||
*/
|
||||
|
||||
/*
|
||||
wxSize sz(GetSize());
|
||||
wxSizeEvent sizeEvent(sz, GetId());
|
||||
sizeEvent.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(sizeEvent);
|
||||
Refresh();
|
||||
*/
|
||||
s_bFirstTime = FALSE;
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
// Implementation: calculate the layout of the view rect
|
||||
// and resize the children if required
|
||||
bool wxNotebook::RefreshLayout(bool force)
|
||||
{
|
||||
if (m_tabView)
|
||||
{
|
||||
wxRect oldRect = m_tabView->GetViewRect();
|
||||
|
||||
int cw, ch;
|
||||
GetClientSize(& cw, & ch);
|
||||
|
||||
int tabHeight = m_tabView->GetTotalTabHeight();
|
||||
wxRect rect;
|
||||
rect.x = 4;
|
||||
rect.y = tabHeight + 4;
|
||||
rect.width = cw - 8;
|
||||
rect.height = ch - 4 - rect.y ;
|
||||
|
||||
m_tabView->SetViewRect(rect);
|
||||
|
||||
m_tabView->Layout();
|
||||
|
||||
// Need to do it a 2nd time to get the tab height with
|
||||
// the new view width, since changing the view width changes the
|
||||
// tab layout.
|
||||
tabHeight = m_tabView->GetTotalTabHeight();
|
||||
rect.x = 4;
|
||||
rect.y = tabHeight + 4;
|
||||
rect.width = cw - 8;
|
||||
rect.height = ch - 4 - rect.y ;
|
||||
|
||||
m_tabView->SetViewRect(rect);
|
||||
|
||||
m_tabView->Layout();
|
||||
|
||||
if (!force && (rect == oldRect))
|
||||
return FALSE;
|
||||
|
||||
// fit the notebook page to the tab control's display area
|
||||
|
||||
unsigned int nCount = m_aPages.Count();
|
||||
for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
|
||||
wxNotebookPage *pPage = m_aPages[nPage];
|
||||
if (pPage->IsShown())
|
||||
{
|
||||
wxRect clientRect = GetAvailableClientSize();
|
||||
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
|
||||
if ( pPage->GetAutoLayout() )
|
||||
pPage->Layout();
|
||||
}
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxNotebook::OnSelChange(wxNotebookEvent& event)
|
||||
{
|
||||
// is it our tab control?
|
||||
if ( event.GetEventObject() == this )
|
||||
{
|
||||
if (event.GetSelection() != m_nSelection)
|
||||
ChangePage(event.GetOldSelection(), event.GetSelection());
|
||||
}
|
||||
|
||||
// we want to give others a chance to process this message as well
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void wxNotebook::OnSetFocus(wxFocusEvent& event)
|
||||
{
|
||||
// set focus to the currently selected page if any
|
||||
if ( m_nSelection != -1 )
|
||||
m_aPages[m_nSelection]->SetFocus();
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
|
||||
{
|
||||
if ( event.IsWindowChange() ) {
|
||||
// change pages
|
||||
AdvanceSelection(event.GetDirection());
|
||||
}
|
||||
else {
|
||||
// pass to the parent
|
||||
if ( GetParent() ) {
|
||||
event.SetCurrentFocus(this);
|
||||
GetParent()->ProcessEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook base class virtuals
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// override these 2 functions to do nothing: everything is done in OnSize
|
||||
|
||||
void wxNotebook::SetConstraintSizes(bool /* recurse */)
|
||||
{
|
||||
// don't set the sizes of the pages - their correct size is not yet known
|
||||
wxControl::SetConstraintSizes(FALSE);
|
||||
}
|
||||
|
||||
bool wxNotebook::DoPhase(int /* nPhase */)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxNotebook::Command(wxCommandEvent& event)
|
||||
{
|
||||
wxFAIL_MSG("wxNotebook::Command not implemented");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxNotebook helper functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// hide the currently active panel and show the new one
|
||||
void wxNotebook::ChangePage(int nOldSel, int nSel)
|
||||
{
|
||||
// cout << "ChangePage: " << nOldSel << ", " << nSel << "\n";
|
||||
wxASSERT( nOldSel != nSel ); // impossible
|
||||
|
||||
if ( nOldSel != -1 ) {
|
||||
m_aPages[nOldSel]->Show(FALSE);
|
||||
m_aPages[nOldSel]->Lower();
|
||||
}
|
||||
|
||||
wxNotebookPage *pPage = m_aPages[nSel];
|
||||
|
||||
wxRect clientRect = GetAvailableClientSize();
|
||||
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
|
||||
|
||||
pPage->Show(TRUE);
|
||||
pPage->Raise();
|
||||
pPage->SetFocus();
|
||||
|
||||
Refresh();
|
||||
|
||||
m_nSelection = nSel;
|
||||
}
|
||||
|
||||
void wxNotebook::ChangeFont(bool keepOriginalSize)
|
||||
{
|
||||
wxWindow::ChangeFont(keepOriginalSize);
|
||||
}
|
||||
|
||||
void wxNotebook::ChangeBackgroundColour()
|
||||
{
|
||||
wxWindow::ChangeBackgroundColour();
|
||||
}
|
||||
|
||||
void wxNotebook::ChangeForegroundColour()
|
||||
{
|
||||
wxWindow::ChangeForegroundColour();
|
||||
}
|
||||
|
||||
void wxNotebook::OnMouseEvent(wxMouseEvent& event)
|
||||
{
|
||||
if (m_tabView)
|
||||
m_tabView->OnEvent(event);
|
||||
}
|
||||
|
||||
void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
if (m_tabView)
|
||||
m_tabView->Draw(dc);
|
||||
}
|
||||
|
||||
wxRect wxNotebook::GetAvailableClientSize()
|
||||
{
|
||||
int cw, ch;
|
||||
GetClientSize(& cw, & ch);
|
||||
|
||||
int tabHeight = m_tabView->GetTotalTabHeight();
|
||||
|
||||
// TODO: these margins should be configurable.
|
||||
wxRect rect;
|
||||
rect.x = 6;
|
||||
rect.y = tabHeight + 6;
|
||||
rect.width = cw - 12;
|
||||
rect.height = ch - 4 - rect.y ;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
/*
|
||||
* wxNotebookTabView
|
||||
*/
|
||||
|
||||
IMPLEMENT_CLASS(wxNotebookTabView, wxTabView)
|
||||
|
||||
wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabView(style)
|
||||
{
|
||||
m_notebook = notebook;
|
||||
|
||||
m_notebook->SetTabView(this);
|
||||
|
||||
SetWindow(m_notebook);
|
||||
}
|
||||
|
||||
wxNotebookTabView::~wxNotebookTabView(void)
|
||||
{
|
||||
}
|
||||
|
||||
// Called when a tab is activated
|
||||
void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
|
||||
{
|
||||
if (!m_notebook)
|
||||
return;
|
||||
|
||||
wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
|
||||
|
||||
// Translate from wxTabView's ids (which aren't position-dependent)
|
||||
// to wxNotebook's (which are).
|
||||
wxNotebookPage* pActive = (wxNotebookPage*) activateId;
|
||||
wxNotebookPage* pDeactive = (wxNotebookPage*) deactivateId;
|
||||
|
||||
int activatePos = m_notebook->FindPagePosition(pActive);
|
||||
int deactivatePos = m_notebook->FindPagePosition(pDeactive);
|
||||
|
||||
event.SetEventObject(m_notebook);
|
||||
event.SetSelection(activatePos);
|
||||
event.SetOldSelection(deactivatePos);
|
||||
m_notebook->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user