[wx] Enable wxWebKit to run using the wxGC Cairo backend on platforms other than...
[WebKit-https.git] / Source / WebCore / platform / wx / RenderThemeWx.cpp
index a34e2d4..faf2f7c 100644 (file)
@@ -30,6 +30,7 @@
 #include "FrameView.h"
 #include "GraphicsContext.h"
 #include "HostWindow.h"
+#include "LocalDC.h"
 #include "NotImplemented.h"
 #include "PaintInfo.h"
 #include "RenderView.h"
@@ -249,6 +250,7 @@ bool RenderThemeWx::supportsFocus(ControlPart part) const
         case PushButtonPart:
         case ButtonPart:
         case TextFieldPart:
+        case MenulistPart:
             return true;
         default: // No for all others...
             return false;
@@ -264,24 +266,11 @@ bool RenderThemeWx::paintButton(RenderObject* o, const PaintInfo& i, const IntRe
 {
     wxWindow* window = nativeWindowForRenderObject(o);
     wxDC* dc = static_cast<wxDC*>(i.context->platformContext());
+    LocalDC localDC(dc, r);
+
     int flags = 0;
     
-    IntRect rect = r; 
-
-// On Mac, wxGraphicsContext and wxDC share the same native implementation,
-// and so transformations are available.
-// On Win and Linux, however, this is not true and transforms are lost,
-// so we need to restore them here.
-#if USE(WXGC) && !defined(__WXMAC__)
-    double xtrans = 0;
-    double ytrans = 0;
-    
-    wxGCDC* gcdc = static_cast<wxGCDC*>(dc);
-    wxGraphicsContext* gc = gcdc->GetGraphicsContext();
-    gc->GetTransform().TransformPoint(&xtrans, &ytrans);
-    rect.setX(r.x() + (int)xtrans);
-    rect.setY(r.y() + (int)ytrans);
-#endif
+    IntRect rect = r;
 
     if (!isEnabled(o))
         flags |= wxCONTROL_DISABLED;
@@ -294,39 +283,48 @@ bool RenderThemeWx::paintButton(RenderObject* o, const PaintInfo& i, const IntRe
         flags |= wxCONTROL_PRESSED;
     
     if (part == PushButtonPart || part == ButtonPart)
-        wxRendererNative::Get().DrawPushButton(window, *dc, rect, flags);
+        wxRendererNative::Get().DrawPushButton(window, *localDC.context(), rect, flags);
     else if(part == RadioPart) {
         if (isChecked(o))
             flags |= wxCONTROL_CHECKED;
 #if wxCHECK_VERSION(2,9,1)
-        wxRendererNative::Get().DrawRadioBitmap(window, *dc, rect, flags);
+        wxRendererNative::Get().DrawRadioBitmap(window, *localDC.context(), rect, flags);
 #elif wxCHECK_VERSION(2,9,0)
-        wxRendererNative::Get().DrawRadioButton(window, *dc, rect, flags);
+        wxRendererNative::Get().DrawRadioButton(window, *localDC.context(), rect, flags);
 #else
-        wxRenderer_DrawRadioButton(window, *dc, rect, flags);
+        wxRenderer_DrawRadioButton(window, *localDC.context(), rect, flags);
 #endif
     }
     else if(part == CheckboxPart) {
         if (isChecked(o))
             flags |= wxCONTROL_CHECKED;
-        wxRendererNative::Get().DrawCheckBox(window, *dc, rect, flags);
+        wxRendererNative::Get().DrawCheckBox(window, *localDC.context(), rect, flags);
     }
     return false;
 }
 
 void RenderThemeWx::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
 {
-    
+
 }
 
 bool RenderThemeWx::paintTextField(RenderObject* o, const PaintInfo& i, const IntRect& r)
 {
     wxWindow* window = nativeWindowForRenderObject(o);
     wxDC* dc = static_cast<wxDC*>(i.context->platformContext());
+    LocalDC localDC(dc, r);
+    int flags = 0;
+    
+    IntRect rect = r;
+
+    ControlPart part = o->style()->appearance();
+    if (supportsFocus(part) && isFocused(o))
+        flags |= wxCONTROL_FOCUSED;
+
 #if wxCHECK_VERSION(2,9,0)
-    wxRendererNative::Get().DrawTextCtrl(window, *dc, r, 0);
+    wxRendererNative::Get().DrawTextCtrl(window, *localDC.context(), rect, flags);
 #else
-    wxRenderer_DrawTextCtrl(window, *dc, r, 0);
+    wxRenderer_DrawTextCtrl(window, *localDC.context(), r, 0);
 #endif
 
     return false;
@@ -339,13 +337,23 @@ int RenderThemeWx::minimumMenuListSize(RenderStyle*) const
 
 void RenderThemeWx::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
 {
+     style->resetBorder();
+
+    // Height is locked to auto.
+    style->setHeight(Length(Auto));
+    
+    style->setPaddingTop(Length(2, Fixed));
+    style->setPaddingBottom(Length(2, Fixed));
 }
     
 bool RenderThemeWx::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& r)
 {
     wxWindow* window = nativeWindowForRenderObject(o);
     wxDC* dc = static_cast<wxDC*>(i.context->platformContext());
-    
+
+    LocalDC localDC(dc, r);
+    IntRect rect = r;
+
     int flags = 0;      
     if (!isEnabled(o))
         flags |= wxCONTROL_DISABLED;
@@ -357,9 +365,9 @@ bool RenderThemeWx::paintMenuList(RenderObject* o, const PaintInfo& i, const Int
         flags |= wxCONTROL_PRESSED;
 
 #if wxCHECK_VERSION(2,9,0)
-    wxRendererNative::Get().DrawChoice(window, *dc, r, flags);
+    wxRendererNative::Get().DrawChoice(window, *localDC.context(), rect, flags);
 #else
-    wxRenderer_DrawChoice(window, *dc, r, flags);
+    wxRenderer_DrawChoice(window, *localDC.context(), rect, flags);
 #endif
 
     return false;
@@ -374,7 +382,9 @@ bool RenderThemeWx::paintMenuListButton(RenderObject* o, const PaintInfo& i, con
 {
     wxWindow* window = nativeWindowForRenderObject(o);
     wxDC* dc = static_cast<wxDC*>(i.context->platformContext());
-    
+    LocalDC localDC(dc, r);
+    IntRect rect = r;
+
     int flags = 0;      
     if (!isEnabled(o))
         flags |= wxCONTROL_DISABLED;
@@ -385,7 +395,7 @@ bool RenderThemeWx::paintMenuListButton(RenderObject* o, const PaintInfo& i, con
     if (isPressed(o))
         flags |= wxCONTROL_PRESSED;
 
-    wxRendererNative::Get().DrawComboBoxDropButton(window, *dc, r, flags);
+    wxRendererNative::Get().DrawComboBoxDropButton(window, *localDC.context(), rect, flags);
             
     return false;
 }