Patch from Andrea. Adds focus rectangle on the tabs, and provides
best size. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
# Python Code By:
|
# Python Code By:
|
||||||
#
|
#
|
||||||
# Andrea Gavana, @ 02 Oct 2006
|
# Andrea Gavana, @ 02 Oct 2006
|
||||||
# Latest Revision: 16 Apr 2007, 11.00 GMT
|
# Latest Revision: 26 Jun 2007, 21.00 GMT
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
|
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
|
||||||
@@ -58,9 +58,9 @@ License And Version:
|
|||||||
|
|
||||||
FlatNotebook Is Freeware And Distributed Under The wxPython License.
|
FlatNotebook Is Freeware And Distributed Under The wxPython License.
|
||||||
|
|
||||||
Latest Revision: Andrea Gavana @ 16 Apr 2007, 11.00 GMT
|
Latest Revision: Andrea Gavana @ 26 Jun 2007, 21.00 GMT
|
||||||
|
|
||||||
Version 2.0.
|
Version 2.1.
|
||||||
|
|
||||||
@undocumented: FNB_HEIGHT_SPACER, VERTICAL_BORDER_PADDING, VC8_SHAPE_LEN,
|
@undocumented: FNB_HEIGHT_SPACER, VERTICAL_BORDER_PADDING, VC8_SHAPE_LEN,
|
||||||
wxEVT*, left_arrow_*, right_arrow*, x_button*, down_arrow*,
|
wxEVT*, left_arrow_*, right_arrow*, x_button*, down_arrow*,
|
||||||
@@ -892,6 +892,7 @@ class PageInfo:
|
|||||||
self._region = wx.Region()
|
self._region = wx.Region()
|
||||||
self._xRect = wx.Rect()
|
self._xRect = wx.Rect()
|
||||||
self._color = None
|
self._color = None
|
||||||
|
self._hasFocus = False
|
||||||
|
|
||||||
|
|
||||||
def SetCaption(self, value):
|
def SetCaption(self, value):
|
||||||
@@ -960,7 +961,7 @@ class PageInfo:
|
|||||||
return self._bEnabled
|
return self._bEnabled
|
||||||
|
|
||||||
|
|
||||||
def Enable(self, enabled):
|
def EnableTab(self, enabled):
|
||||||
""" Sets the tab enabled or disabled. """
|
""" Sets the tab enabled or disabled. """
|
||||||
|
|
||||||
self._bEnabled = enabled
|
self._bEnabled = enabled
|
||||||
@@ -1283,6 +1284,13 @@ class FNBRenderer:
|
|||||||
self._rightBgBmp = wx.EmptyBitmap(16, 14)
|
self._rightBgBmp = wx.EmptyBitmap(16, 14)
|
||||||
self._tabHeight = None
|
self._tabHeight = None
|
||||||
|
|
||||||
|
if wx.Platform == "__WXMAC__":
|
||||||
|
self._focusPen = wx.Pen(wx.BLACK, 1, wx.SOLID)
|
||||||
|
else:
|
||||||
|
self._focusPen = wx.Pen(wx.BLACK, 1, wx.USER_DASH)
|
||||||
|
self._focusPen.SetDashes([1, 1])
|
||||||
|
self._focusPen.SetCap(wx.CAP_BUTT)
|
||||||
|
|
||||||
|
|
||||||
def GetLeftButtonPos(self, pageContainer):
|
def GetLeftButtonPos(self, pageContainer):
|
||||||
""" Returns the left button position in the navigation area. """
|
""" Returns the left button position in the navigation area. """
|
||||||
@@ -1872,6 +1880,8 @@ class FNBRenderer:
|
|||||||
|
|
||||||
pc._pagesInfoVec[i].SetPosition(wx.Point(posx, posy))
|
pc._pagesInfoVec[i].SetPosition(wx.Point(posx, posy))
|
||||||
pc._pagesInfoVec[i].SetSize(wx.Size(tabWidth, tabHeight))
|
pc._pagesInfoVec[i].SetSize(wx.Size(tabWidth, tabHeight))
|
||||||
|
self.DrawFocusRectangle(dc, pc, pc._pagesInfoVec[i])
|
||||||
|
|
||||||
posx += tabWidth
|
posx += tabWidth
|
||||||
|
|
||||||
# Update all tabs that can not fit into the screen as non-visible
|
# Update all tabs that can not fit into the screen as non-visible
|
||||||
@@ -1890,6 +1900,25 @@ class FNBRenderer:
|
|||||||
self.DrawTabsLine(pc, dc, x1, x2)
|
self.DrawTabsLine(pc, dc, x1, x2)
|
||||||
|
|
||||||
|
|
||||||
|
def DrawFocusRectangle(self, dc, pageContainer, page):
|
||||||
|
""" Draws a focus rectangle like the native Notebooks. """
|
||||||
|
|
||||||
|
if not page._hasFocus:
|
||||||
|
return
|
||||||
|
|
||||||
|
tabPos = page.GetPosition()
|
||||||
|
if pageContainer.GetParent().GetWindowStyleFlag() & FNB_VC8:
|
||||||
|
vc8ShapeLen = self.CalcTabHeight(pageContainer) - VERTICAL_BORDER_PADDING - 2
|
||||||
|
tabPos.x += vc8ShapeLen
|
||||||
|
|
||||||
|
rect = wx.RectPS(tabPos, page.GetSize())
|
||||||
|
rect = wx.Rect(rect.x+2, rect.y+2, rect.width-4, rect.height-8)
|
||||||
|
|
||||||
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||||
|
dc.SetPen(self._focusPen)
|
||||||
|
dc.DrawRoundedRectangleRect(rect, 2)
|
||||||
|
|
||||||
|
|
||||||
def DrawDragHint(self, pc, tabIdx):
|
def DrawDragHint(self, pc, tabIdx):
|
||||||
"""
|
"""
|
||||||
Draws tab drag hint, the default implementation is to do nothing.
|
Draws tab drag hint, the default implementation is to do nothing.
|
||||||
@@ -2736,6 +2765,8 @@ class FNBRendererVC8(FNBRenderer):
|
|||||||
# Draw the tab
|
# Draw the tab
|
||||||
self.DrawTabX(pc, dc, x_rect, tabIdx, btnStatus)
|
self.DrawTabX(pc, dc, x_rect, tabIdx, btnStatus)
|
||||||
|
|
||||||
|
self.DrawFocusRectangle(dc, pc, pc._pagesInfoVec[tabIdx])
|
||||||
|
|
||||||
|
|
||||||
def FillVC8GradientColour(self, pageContainer, dc, tabPoints, bSelectedTab, tabIdx):
|
def FillVC8GradientColour(self, pageContainer, dc, tabPoints, bSelectedTab, tabIdx):
|
||||||
""" Fills a tab with a gradient shading. """
|
""" Fills a tab with a gradient shading. """
|
||||||
@@ -2975,7 +3006,7 @@ class FNBRendererVC8(FNBRenderer):
|
|||||||
# Class FlatNotebook
|
# Class FlatNotebook
|
||||||
# ---------------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------------- #
|
||||||
|
|
||||||
class FlatNotebook(wx.Panel):
|
class FlatNotebook(wx.PyPanel):
|
||||||
"""
|
"""
|
||||||
Display one or more windows in a notebook.
|
Display one or more windows in a notebook.
|
||||||
|
|
||||||
@@ -3011,7 +3042,7 @@ class FlatNotebook(wx.Panel):
|
|||||||
self._windows = []
|
self._windows = []
|
||||||
self._popupWin = None
|
self._popupWin = None
|
||||||
|
|
||||||
wx.Panel.__init__(self, parent, id, pos, size, style)
|
wx.PyPanel.__init__(self, parent, id, pos, size, style)
|
||||||
|
|
||||||
self._pages = PageContainer(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, style)
|
self._pages = PageContainer(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, style)
|
||||||
|
|
||||||
@@ -3059,6 +3090,24 @@ class FlatNotebook(wx.Panel):
|
|||||||
self.SetDropTarget(self._pDropTarget)
|
self.SetDropTarget(self._pDropTarget)
|
||||||
|
|
||||||
|
|
||||||
|
def DoGetBestSize(self):
|
||||||
|
""" Overrides DoGetBestSize to handle sizers nicely. """
|
||||||
|
|
||||||
|
if not self._windows:
|
||||||
|
# Something is better than nothing... no pages!
|
||||||
|
return wx.Size(20, 20)
|
||||||
|
|
||||||
|
maxWidth = maxHeight = 0
|
||||||
|
tabHeight = self.GetPageBestSize().height
|
||||||
|
|
||||||
|
for win in self._windows:
|
||||||
|
# Loop over all the windows to get their best size
|
||||||
|
width, height = win.GetBestSize()
|
||||||
|
maxWidth, maxHeight = max(maxWidth, width), max(maxHeight, height)
|
||||||
|
|
||||||
|
return wx.Size(maxWidth, maxHeight+tabHeight)
|
||||||
|
|
||||||
|
|
||||||
def SetActiveTabTextColour(self, textColour):
|
def SetActiveTabTextColour(self, textColour):
|
||||||
""" Sets the text colour for the active tab. """
|
""" Sets the text colour for the active tab. """
|
||||||
|
|
||||||
@@ -3452,10 +3501,7 @@ class FlatNotebook(wx.Panel):
|
|||||||
# change pages
|
# change pages
|
||||||
self.AdvanceSelection(event.GetDirection())
|
self.AdvanceSelection(event.GetDirection())
|
||||||
else:
|
else:
|
||||||
# pass to the parent
|
event.Skip()
|
||||||
if self.GetParent():
|
|
||||||
event.SetCurrentFocus(self)
|
|
||||||
self.GetParent().ProcessEvent(event)
|
|
||||||
|
|
||||||
|
|
||||||
def GetPageShapeAngle(self, page_index):
|
def GetPageShapeAngle(self, page_index):
|
||||||
@@ -3531,7 +3577,7 @@ class FlatNotebook(wx.Panel):
|
|||||||
def SetWindowStyleFlag(self, style):
|
def SetWindowStyleFlag(self, style):
|
||||||
""" Sets the L{FlatNotebook} window style flags. """
|
""" Sets the L{FlatNotebook} window style flags. """
|
||||||
|
|
||||||
wx.Panel.SetWindowStyleFlag(self, style)
|
wx.PyPanel.SetWindowStyleFlag(self, style)
|
||||||
renderer = self._pages._mgr.GetRenderer(self.GetWindowStyleFlag())
|
renderer = self._pages._mgr.GetRenderer(self.GetWindowStyleFlag())
|
||||||
renderer._tabHeight = None
|
renderer._tabHeight = None
|
||||||
|
|
||||||
@@ -3673,14 +3719,14 @@ class FlatNotebook(wx.Panel):
|
|||||||
return self._pages.GetEnabled(page)
|
return self._pages.GetEnabled(page)
|
||||||
|
|
||||||
|
|
||||||
def Enable(self, page, enabled=True):
|
def EnableTab(self, page, enabled=True):
|
||||||
""" Enables or disables a tab. """
|
""" Enables or disables a tab. """
|
||||||
|
|
||||||
if page >= len(self._windows):
|
if page >= len(self._windows):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._windows[page].Enable(enabled)
|
self._windows[page].Enable(enabled)
|
||||||
self._pages.Enable(page, enabled)
|
self._pages.EnableTab(page, enabled)
|
||||||
|
|
||||||
|
|
||||||
def GetNonActiveTabTextColour(self):
|
def GetNonActiveTabTextColour(self):
|
||||||
@@ -3789,6 +3835,8 @@ class PageContainer(wx.Panel):
|
|||||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
|
||||||
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnterWindow)
|
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnterWindow)
|
||||||
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
|
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
|
||||||
|
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||||
|
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
||||||
|
|
||||||
|
|
||||||
def OnEraseBackground(self, event):
|
def OnEraseBackground(self, event):
|
||||||
@@ -4356,7 +4404,7 @@ class PageContainer(wx.Panel):
|
|||||||
dc = wx.ClientDC(self)
|
dc = wx.ClientDC(self)
|
||||||
|
|
||||||
if bRedrawX:
|
if bRedrawX:
|
||||||
|
|
||||||
render.DrawX(self, dc)
|
render.DrawX(self, dc)
|
||||||
|
|
||||||
if bRedrawLeft:
|
if bRedrawLeft:
|
||||||
@@ -4369,7 +4417,7 @@ class PageContainer(wx.Panel):
|
|||||||
|
|
||||||
if bRedrawTabX:
|
if bRedrawTabX:
|
||||||
|
|
||||||
render.DrawTabX(self, dc, self._pagesInfoVec[tabIdx].GetXRect(), tabIdx, self._nTabXButtonStatus)
|
self.Refresh()
|
||||||
|
|
||||||
if bRedrawDropArrow:
|
if bRedrawDropArrow:
|
||||||
|
|
||||||
@@ -4663,13 +4711,13 @@ class PageContainer(wx.Panel):
|
|||||||
return self._pagesInfoVec[page].GetEnabled()
|
return self._pagesInfoVec[page].GetEnabled()
|
||||||
|
|
||||||
|
|
||||||
def Enable(self, page, enabled=True):
|
def EnableTab(self, page, enabled=True):
|
||||||
""" Enables or disables a tab. """
|
""" Enables or disables a tab. """
|
||||||
|
|
||||||
if page >= len(self._pagesInfoVec):
|
if page >= len(self._pagesInfoVec):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._pagesInfoVec[page].Enable(enabled)
|
self._pagesInfoVec[page].EnableTab(enabled)
|
||||||
|
|
||||||
|
|
||||||
def GetSingleLineBorderColour(self):
|
def GetSingleLineBorderColour(self):
|
||||||
@@ -4727,6 +4775,37 @@ class PageContainer(wx.Panel):
|
|||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
|
|
||||||
|
def OnSetFocus(self, event):
|
||||||
|
""" Handles the wx.EVT_SET_FOCUS event for L{PageContainer}. """
|
||||||
|
|
||||||
|
if self._iActivePage < 0:
|
||||||
|
event.Skip()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.SetFocusedPage(self._iActivePage)
|
||||||
|
|
||||||
|
|
||||||
|
def OnKillFocus(self, event):
|
||||||
|
""" Handles the wx.EVT_KILL_FOCUS event for L{PageContainer}. """
|
||||||
|
|
||||||
|
self.SetFocusedPage()
|
||||||
|
|
||||||
|
|
||||||
|
def SetFocusedPage(self, pageIndex=-1):
|
||||||
|
"""
|
||||||
|
Sets/Unsets the focus on the appropriate page.
|
||||||
|
If pageIndex is defaulted, we have lost focus and no focus indicator is drawn.
|
||||||
|
"""
|
||||||
|
|
||||||
|
for indx, page in enumerate(self._pagesInfoVec):
|
||||||
|
if indx == pageIndex:
|
||||||
|
page._hasFocus = True
|
||||||
|
else:
|
||||||
|
page._hasFocus = False
|
||||||
|
|
||||||
|
self.Refresh()
|
||||||
|
|
||||||
|
|
||||||
def PopupTabsMenu(self):
|
def PopupTabsMenu(self):
|
||||||
""" Pops up the menu activated with the drop down arrow in the navigation area. """
|
""" Pops up the menu activated with the drop down arrow in the navigation area. """
|
||||||
|
|
||||||
@@ -4743,7 +4822,7 @@ class PageContainer(wx.Panel):
|
|||||||
item.SetBitmap(self.GetImageList().GetBitmap(pi.GetImageIndex()))
|
item.SetBitmap(self.GetImageList().GetBitmap(pi.GetImageIndex()))
|
||||||
|
|
||||||
popupMenu.AppendItem(item)
|
popupMenu.AppendItem(item)
|
||||||
item.Enable(pi.GetEnabled())
|
item.EnableTab(pi.GetEnabled())
|
||||||
|
|
||||||
self.PopupMenu(popupMenu)
|
self.PopupMenu(popupMenu)
|
||||||
|
|
||||||
@@ -4781,6 +4860,7 @@ class PageContainer(wx.Panel):
|
|||||||
event.SetEventType(wxEVT_FLATNOTEBOOK_PAGE_CHANGED)
|
event.SetEventType(wxEVT_FLATNOTEBOOK_PAGE_CHANGED)
|
||||||
event.SetOldSelection(oldSelection)
|
event.SetOldSelection(oldSelection)
|
||||||
self.GetParent().GetEventHandler().ProcessEvent(event)
|
self.GetParent().GetEventHandler().ProcessEvent(event)
|
||||||
|
self.SetFocus()
|
||||||
|
|
||||||
|
|
||||||
def SetImageList(self, imglist):
|
def SetImageList(self, imglist):
|
||||||
|
Reference in New Issue
Block a user