]> git.saurik.com Git - wxWidgets.git/commitdiff
Themed backgrounds for flat generic buttons
authorRobin Dunn <robin@alldunn.com>
Tue, 17 May 2005 00:41:02 +0000 (00:41 +0000)
committerRobin Dunn <robin@alldunn.com>
Tue, 17 May 2005 00:41:02 +0000 (00:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34088 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/demo/GenericButtons.py
wxPython/docs/CHANGES.txt
wxPython/wx/lib/buttons.py

index 7bbe9d57042f2fc43f3282edec41f6642828f0d6..f99c65e3e67b5a643ba8fbbd75cfbedcd7d3e58f 100644 (file)
@@ -114,6 +114,22 @@ class TestPanel(wx.Panel):
         b.SetBestSize()
         sizer.Add(b)
 
+
+        # a flat text button
+        b = buttons.GenButton(self, -1, 'Flat buttons too!', style=wx.BORDER_NONE)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b, flag=wx.ALIGN_CENTER_VERTICAL)
+
+        # A flat image button
+        bmp = images.getTest2Bitmap()
+        bmp.SetMaskColour("blue")
+        b = buttons.GenBitmapButton(self, -1, bmp, style=wx.BORDER_NONE)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+        ##b.SetBackgroundColour("sky blue")
+        ##b.SetBackgroundColour("pink")
+
+
         border = wx.BoxSizer(wx.VERTICAL)
         border.Add(sizer, 0, wx.ALL, 25)
         self.SetSizer(border)
index 604b9846f1ac89f8c9ecd63edaa8674b4c2a0122..bf5d3817d16ec5a66282a73c86ec17a9c65f7148 100644 (file)
@@ -69,6 +69,9 @@ parameter, like this::
         wxversion.select("2.6-unicode", True)
         import wx
 
+Tweaked wx.lib.buttons such that flat buttons (e.g. have no bevel and
+a wx.BORDER_NONE style flag) paint themed backgrounds if there are
+transparent areas and the parent is displaying a theme.
 
 
 
index adeb59e1333a1076aaf9ad00b7128fa21549546a..7f198175472734a279226436b5dd1c4d8435ed89 100644 (file)
@@ -62,12 +62,13 @@ class GenButton(wx.PyControl):
                  name = "genbutton"):
         cstyle = style
         if cstyle == 0:
-            cstyle = wx.NO_BORDER
+            cstyle = wx.BORDER_NONE
         wx.PyControl.__init__(self, parent, ID, pos, size, cstyle, validator, name)
 
         self.up = True
         self.hasFocus = False
-        if style & wx.NO_BORDER:
+        self.style = style
+        if style & wx.BORDER_NONE:
             self.bezelWidth = 0
             self.useFocusInd = False
         else:
@@ -88,7 +89,6 @@ class GenButton(wx.PyControl):
         self.Bind(wx.EVT_KILL_FOCUS,       self.OnLoseFocus)
         self.Bind(wx.EVT_KEY_DOWN,         self.OnKeyDown)
         self.Bind(wx.EVT_KEY_UP,           self.OnKeyUp)
-        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
         self.Bind(wx.EVT_PAINT,            self.OnPaint)
 
 
@@ -261,22 +261,39 @@ class GenButton(wx.PyControl):
         x1 = y1 = 0
         x2 = width-1
         y2 = height-1
+        
         dc = wx.BufferedPaintDC(self)
+        brush = None
+        
         if self.up:
-            dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
+            colBg = self.GetBackgroundColour()
+            brush = wx.Brush(colBg, wx.SOLID)
+            if self.style & wx.BORDER_NONE:
+                myAttr = self.GetDefaultAttributes()
+                parAttr = self.GetParent().GetDefaultAttributes()
+                myDef = colBg == myAttr.colBg
+                parDef = self.GetParent().GetBackgroundColour() == parAttr.colBg
+                if myDef and parDef:
+                    if wx.Platform == "__WXMAC__":
+                        brush.MacSetTheme(1) # 1 == kThemeBrushDialogBackgroundActive
+                    elif wx.Platform == "__WXMSW__":
+                        if self.DoEraseBackground(dc):
+                            brush = None
+                elif myDef and not parDef:
+                    colBg = self.GetParent().GetBackgroundColour()
+                    brush = wx.Brush(colBg, wx.SOLID)
         else:
-            dc.SetBackground(wx.Brush(self.faceDnClr, wx.SOLID))
-        dc.Clear()
+            brush = wx.Brush(self.faceDnClr, wx.SOLID)
+        if brush is not None:
+            dc.SetBackground(brush)
+            dc.Clear()
+                    
         self.DrawBezel(dc, x1, y1, x2, y2)
         self.DrawLabel(dc, width, height)
         if self.hasFocus and self.useFocusInd:
             self.DrawFocusIndicator(dc, width, height)
 
 
-    def OnEraseBackground(self, event):
-        pass
-
-
     def OnLeftDown(self, event):
         if not self.IsEnabled():
             return