summaryrefslogtreecommitdiff
path: root/toolkit/source/awt/scrollabledialog.cxx
blob: dc3d3ab2dba2c362bbd6fb7f850e261d7c95cffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <toolkit/awt/scrollabledialog.hxx>
namespace toolkit
{

ScrollableDialog::ScrollableDialog( Window* pParent, WinBits nStyle ) : Dialog( pParent, nStyle | ~( WB_HSCROLL | WB_VSCROLL ) ), maHScrollBar( this, WB_HSCROLL | WB_DRAG), maVScrollBar( this, WB_VSCROLL | WB_DRAG ), mbHasHoriBar( false ), mbHasVertBar( false ), maScrollVis( None )
{
    Link aLink( LINK( this, ScrollableDialog, ScrollBarHdl ) );
    maVScrollBar.SetScrollHdl( aLink );
    maHScrollBar.SetScrollHdl( aLink );

    Size aOutSz = GetOutputSizePixel();
    ScrollBarVisibility aVis = None;

    if ( nStyle & ( WB_HSCROLL | WB_VSCROLL ) )
    {
        if ( nStyle & WB_HSCROLL )
            aVis = Hori;
        if ( nStyle &  WB_VSCROLL )
        {
            if ( aVis == Hori )
                aVis = Both;
            else
                aVis = Vert;
        }
    }
    setScrollVisibility( aVis );
    mnScrWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
}

void ScrollableDialog::setScrollVisibility( ScrollBarVisibility rVisState )
{
    maScrollVis = rVisState;
    if (  maScrollVis == Hori || maScrollVis == Both )
        mbHasHoriBar = true;
    if ( maScrollVis == Vert || maScrollVis == Both )
        mbHasVertBar = true;
    if ( mbHasVertBar )
        maVScrollBar.Show();
    if ( mbHasHoriBar )
        maHScrollBar.Show();
    if ( mbHasHoriBar || mbHasVertBar )
        SetStyle( GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
}

ScrollableDialog::~ScrollableDialog()
{
}

Window* ScrollableDialog::getContentWindow()
{
    return this;
}

void ScrollableDialog::lcl_Scroll( long nX, long nY )
{
    long nXScroll = mnScrollPos.X() - nX;
    long nYScroll = mnScrollPos.Y() - nY;
    printf( "ScrollableDialog::lcl_Scroll %d, %d nXScroll %d, nYScroll %d\n", nX, nY, nXScroll, nYScroll );
    mnScrollPos = Point( nX, nY );

    Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
    Window::Scroll(nXScroll, nYScroll, aScrollableArea );

    // Manually scroll all children ( except the scrollbars )
    for ( int index = 0; index < GetChildCount(); ++index )
    {
        Window* pChild = GetChild( index );
        if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
        {
            Point aPos = pChild->GetPosPixel();
            aPos += Point( nXScroll, nYScroll );
            pChild->SetPosPixel( aPos );
        }
    }
}

IMPL_LINK( ScrollableDialog, ScrollBarHdl, ScrollBar*, pSB )
{
    sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
    if( pSB == &maVScrollBar )
        lcl_Scroll(mnScrollPos.X(), nPos );
    else if( pSB == &maHScrollBar )
        lcl_Scroll(nPos, mnScrollPos.Y() );
    return 1;
}

void ScrollableDialog::SetScrollTop( long nTop )
{
    printf("ScrollableDialog::SetScrollTop(%d)\n", nTop );
}
void ScrollableDialog::SetScrollLeft( long nLeft )
{
    printf("ScrollableDialog::SetScrollLeft(%d)\n", nLeft );
}
void ScrollableDialog::SetScrollWidth( long nWidth )
{
    printf("ScrollableDialog::SetScrollWidth(%d)\n", nWidth );
    maScrollArea.Width() = nWidth;
}

void ScrollableDialog::SetScrollHeight( long nHeight )
{
    printf("ScrollableDialog::SetScrollHeight(%d)\n", nHeight );
    maScrollArea.Height() = nHeight;
}

void  ScrollableDialog::Paint( const Rectangle& rRect )
{
//    printf("ScrollableDialog::Paint( %d, %d, %d, %d width %d height %d\n", rRect.Top(), rRect.Left(), rRect.Right(), rRect.Bottom(),GetSizePixel().Width(),  GetSizePixel().Height() );
    Dialog::Paint( rRect );
}

void ScrollableDialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
{
//    printf("ScrollableDialog::Draw( ( %d, %d ) h %d, w %d \n", rPos.X(), rPos.Y(), rSize.Height(), rSize.Width() );
    Dialog::Draw( pDev, rPos, rSize, nFlags );
}

void ScrollableDialog::Resize()
{
    Size aOutSz = GetOutputSizePixel();
    printf("ScrollableDialog::Resize() - size is width %d height %d\n", GetSizePixel().Width(),  GetSizePixel().Height() );
    // find the output area for the window
    long nMaxX = GetSizePixel().Width();
    long nMaxY = GetSizePixel().Height();
    for ( int index = 0, count = GetChildCount(); index < count; ++index )
    {
        Window* pChild = GetChild( index );
        if ( pChild )
        {
            Point aPos = pChild->GetPosPixel();
            Size aSize = pChild->GetSizePixel();
            long nX = aPos.X() + aSize.Width();
            long nY = aPos.Y() + aSize.Height();
            if ( nX > nMaxX )
                nMaxX = nX;
            if ( nY > nMaxY )
                nMaxY = nY;
            printf("%s child[%d] pos (%d,%d)  height %d, width %d\n", rtl::OUStringToOString( pChild->GetText(), RTL_TEXTENCODING_UTF8 ).getStr(), index, aPos.X(),  aPos.Y(), aSize.Height(), aSize.Width() );
        }
    }

#if 1
    // assume for the moment that we have both hori & vert scroll bars
    Size aContentsSize( aOutSz );
    if ( mbHasVertBar )
    {
        aContentsSize.Width() -= mnScrWidth;
        nMaxX += mnScrWidth;
    }
    if ( mbHasHoriBar )
    {
        aContentsSize.Height() -= mnScrWidth;
        nMaxY += mnScrWidth;
    }
    maScrollArea = aContentsSize;
#endif

    Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
    Point aHPos( 0, aOutSz.Height() - mnScrWidth );

    maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth,  GetSizePixel().Height() - mnScrWidth ) );
    maHScrollBar.SetPosSizePixel( aHPos, Size(  GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );

    printf("nMaxX is %d nMaxY is %d, scrollarea height %d, width %d\n", nMaxX, nMaxY, maScrollArea.Height(),  maScrollArea.Width() );
    printf("Width %d Height %d outsize width %d height %d\n", GetSizePixel().Width(),  GetSizePixel().Height(), aOutSz.Width(), aOutSz.Height() );
    maHScrollBar.SetRangeMax( nMaxX  );
    maHScrollBar.SetVisibleSize( GetSizePixel().Width() );
//    maHScrollBar.SetPageSize( maScrollArea.Height() );

    maVScrollBar.SetRangeMax( nMaxY );
    maVScrollBar.SetVisibleSize( GetSizePixel().Height() );
//    maVScrollBar.SetPageSize( maScrollArea.Width() );
}

} // toolkit
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */