#include "config.h"
#include "Document.h"
#include "RenderTheme.h"
#include "GraphicsContext.h"
#include "RenderView.h"
#include "FrameView.h"
#include <wx/defs.h>
#include <wx/renderer.h>
#include <wx/dcclient.h>
#include <wx/scrolwin.h>
#include <wx/settings.h>
namespace WebCore {
class RenderThemeWx : public RenderTheme
{
public:
RenderThemeWx() : RenderTheme() { }
virtual bool supportsHover(const RenderStyle*) const { return true; }
virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
return paintButton(o, i, r);
}
virtual void setCheckboxSize(RenderStyle*) const;
virtual bool paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
return paintButton(o, i, r);
}
virtual void setRadioSize(RenderStyle*) const;
virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
virtual bool paintButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;
virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);
virtual bool isControlStyled(const RenderStyle*, const BorderData&,
const BackgroundLayer&, const Color&) const;
virtual bool controlSupportsTints(const RenderObject*) const;
virtual void systemFont(int propId, FontDescription&) const;
virtual Color platformActiveSelectionBackgroundColor() const;
virtual Color platformInactiveSelectionBackgroundColor() const;
virtual Color platformActiveSelectionForegroundColor() const;
virtual Color platformInactiveSelectionForegroundColor() const;
private:
void addIntrinsicMargins(RenderStyle*) const;
void close();
bool supportsFocus(EAppearance) const;
};
RenderTheme* theme()
{
static RenderThemeWx rt;
return &rt;
}
bool RenderThemeWx::isControlStyled(const RenderStyle* style, const BorderData& border,
const BackgroundLayer& background, const Color& backgroundColor) const
{
if (style->appearance() == TextFieldAppearance || style->appearance() == TextAreaAppearance)
return style->border() != border;
return RenderTheme::isControlStyled(style, border, background, backgroundColor);
}
bool RenderThemeWx::controlSupportsTints(const RenderObject* o) const
{
if (!isEnabled(o))
return false;
if (o->style()->appearance() == CheckboxAppearance)
return isChecked(o);
return true;
}
void RenderThemeWx::systemFont(int propId, FontDescription& fontDescription) const
{
}
void RenderThemeWx::addIntrinsicMargins(RenderStyle* style) const
{
if (style->fontSize() < 11)
return;
const int m = 2;
if (style->width().isIntrinsicOrAuto()) {
if (style->marginLeft().quirk())
style->setMarginLeft(Length(m, Fixed));
if (style->marginRight().quirk())
style->setMarginRight(Length(m, Fixed));
}
if (style->height().isAuto()) {
if (style->marginTop().quirk())
style->setMarginTop(Length(m, Fixed));
if (style->marginBottom().quirk())
style->setMarginBottom(Length(m, Fixed));
}
}
void RenderThemeWx::setCheckboxSize(RenderStyle* style) const
{
if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())
return;
if (style->width().isIntrinsicOrAuto())
style->setWidth(Length(13, Fixed));
if (style->height().isAuto())
style->setHeight(Length(13, Fixed));
}
void RenderThemeWx::setRadioSize(RenderStyle* style) const
{
setCheckboxSize(style);
}
bool RenderThemeWx::supportsFocus(EAppearance appearance) const
{
switch (appearance) {
case PushButtonAppearance:
case ButtonAppearance:
case TextFieldAppearance:
return true;
default: return false;
}
}
void RenderThemeWx::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
addIntrinsicMargins(style);
}
bool RenderThemeWx::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
wxScrolledWindow* window = o->view()->frameView()->nativeWindow();
wxPaintDC dc((wxWindow*)window);
window->DoPrepareDC(dc);
int flags = 0;
if (!isEnabled(o))
flags |= wxCONTROL_DISABLED;
EAppearance appearance = o->style()->appearance();
if (supportsFocus(o->style()->appearance()) && isFocused(o))
flags |= wxCONTROL_FOCUSED;
if (isPressed(o))
flags |= wxCONTROL_PRESSED;
if(appearance == PushButtonAppearance || appearance == ButtonAppearance)
wxRendererNative::Get().DrawPushButton(window, dc, r, flags);
else if(appearance == CheckboxAppearance)
wxRendererNative::Get().DrawCheckBox(window, dc, r, flags);
return false;
}
void RenderThemeWx::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
addIntrinsicMargins(style);
}
bool RenderThemeWx::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
i.context->setStrokeThickness(1);
i.context->setStrokeColor(Color(0, 0, 0));
i.context->drawRect(r);
return false;
}
Color RenderThemeWx::platformActiveSelectionBackgroundColor() const
{
return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
}
Color RenderThemeWx::platformInactiveSelectionBackgroundColor() const
{
return wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
}
Color RenderThemeWx::platformActiveSelectionForegroundColor() const
{
#if __WXGTK__
return Color(255, 255, 255);
#else
return Color();
#endif
}
Color RenderThemeWx::platformInactiveSelectionForegroundColor() const
{
#if __WXGTK__
return Color(255, 255, 255);
#else
return Color();
#endif
}
}