#include "config.h"
#include "ScrollView.h"
#include <algorithm>
#include "FloatRect.h"
#include "IntRect.h"
#include <stdio.h>
#include "NotImplemented.h"
#include <wx/defs.h>
#include <wx/scrolwin.h>
using namespace std;
namespace WebCore {
class ScrollView::ScrollViewPrivate {
public:
ScrollViewPrivate()
: hasStaticBackground(false)
, suppressScrollbars(false)
, vScrollbarMode(ScrollbarAuto)
, hScrollbarMode(ScrollbarAuto)
{
}
IntSize scrollOffset;
IntSize contentsSize;
bool hasStaticBackground;
bool suppressScrollbars;
ScrollbarMode vScrollbarMode;
ScrollbarMode hScrollbarMode;
};
ScrollView::ScrollView()
: m_data(new ScrollViewPrivate())
{
}
ScrollView::~ScrollView()
{
delete m_data;
}
void ScrollView::updateContents(const IntRect& updateRect, bool now)
{
wxRect contentsRect = updateRect;
contentsRect.Offset(-contentsX(), -contentsY());
wxScrolledWindow* win = nativeWindow();
if (win){
win->RefreshRect(contentsRect, true);
if (now)
win->Update();
}
}
void ScrollView::update()
{
wxScrolledWindow* win = nativeWindow();
if (win){
win->Update();
}
}
int ScrollView::visibleWidth() const
{
int width = 0;
wxScrolledWindow* win = nativeWindow();
if (win)
win->GetClientSize(&width, NULL);
return width;
}
int ScrollView::visibleHeight() const
{
int height = 0;
wxScrolledWindow* win = nativeWindow();
if (win)
win->GetClientSize(NULL, &height);
return height;
}
FloatRect ScrollView::visibleContentRect() const
{
return FloatRect(contentsX(),contentsY(),visibleWidth(),visibleHeight());
}
void ScrollView::setContentsPos(int newX, int newY)
{
int dx = newX - contentsX();
int dy = newY - contentsY();
scrollBy(dx, dy);
}
void ScrollView::resizeContents(int w,int h)
{
wxScrolledWindow* win = nativeWindow();
if (win)
{
win->SetVirtualSize(w, h);
win->SetScrollRate(20, 20);
}
}
int ScrollView::contentsX() const
{
int x = 0;
wxScrolledWindow* win = nativeWindow();
if (win)
{
int sUnitX = 1;
win->GetViewStart(&x, NULL);
win->GetScrollPixelsPerUnit(&sUnitX, NULL);
x *= sUnitX;
}
return x;
}
int ScrollView::contentsY() const
{
int y = 0;
wxScrolledWindow* win = nativeWindow();
if (win)
{
int sUnitY = 1;
win->GetViewStart(NULL, &y);
win->GetScrollPixelsPerUnit(&sUnitY, NULL);
y *= sUnitY;
}
return y;
}
int ScrollView::contentsWidth() const
{
int width = 0;
wxScrolledWindow* win = nativeWindow();
if (win)
win->GetVirtualSize(&width, NULL);
return width;
}
int ScrollView::contentsHeight() const
{
int height = 0;
wxScrolledWindow* win = nativeWindow();
if (win)
win->GetVirtualSize(NULL, &height);
return height;
}
FloatRect ScrollView::visibleContentRectConsideringExternalScrollers() const
{
return visibleContentRect();
}
IntSize ScrollView::scrollOffset() const
{
return IntSize(contentsX(), contentsY());
}
IntSize ScrollView::maximumScroll() const
{
notImplemented();
return IntSize(0, 0);
}
void ScrollView::scrollBy(int dx, int dy)
{
wxScrolledWindow* win = nativeWindow();
if (win)
win->Scroll(dx, dy);
}
WebCore::ScrollbarMode ScrollView::hScrollbarMode() const
{
return m_data->hScrollbarMode;
}
WebCore::ScrollbarMode ScrollView::vScrollbarMode() const
{
return m_data->vScrollbarMode;
}
void ScrollView::setHScrollbarMode(ScrollbarMode newMode)
{
notImplemented();
}
void ScrollView::setVScrollbarMode(ScrollbarMode newMode)
{
notImplemented();
}
void ScrollView::updateScrollBars()
{
wxScrolledWindow* win = nativeWindow();
if (win)
{
}
}
void ScrollView::setStaticBackground(bool flag)
{
m_data->hasStaticBackground = flag;
}
void ScrollView::suppressScrollbars(bool suppressed, bool repaintOnSuppress)
{
m_data->suppressScrollbars = suppressed;
}
void ScrollView::setScrollbarsMode(ScrollbarMode newMode)
{
m_data->hScrollbarMode = m_data->vScrollbarMode = newMode;
}
IntPoint ScrollView::contentsToWindow(const IntPoint& point) const
{
return point - scrollOffset();
}
IntPoint ScrollView::windowToContents(const IntPoint& point) const
{
return point + scrollOffset();
}
bool ScrollView::inWindow() const
{
return nativeWindow() != NULL;
}
void ScrollView::wheelEvent(PlatformWheelEvent&)
{
}
void ScrollView::addChild(Widget*)
{
}
void ScrollView::removeChild(Widget* widget)
{
if (nativeWindow() && widget->nativeWindow())
{
nativeWindow()->RemoveChild(widget->nativeWindow());
widget->nativeWindow()->Destroy();
}
}
void ScrollView::scrollRectIntoViewRecursively(const IntRect& rect)
{
setContentsPos(rect.x(), rect.y());
}
PlatformScrollbar* ScrollView::scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent)
{
return 0;
}
}