~ubuntu-branches/ubuntu/oneiric/nux/oneiric-updates

« back to all changes in this revision

Viewing changes to Nux/ScrollView.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-08-25 13:42:45 UTC
  • mfrom: (1.1.27 upstream)
  • Revision ID: james.westby@ubuntu.com-20110825134245-edi1g8cm2iqibae7
Tags: 1.4.0-0ubuntu1
* New upstream version:
  - "scrolling down in a lens brings it back to the top automatically" 
    (lp: #821534)
* debian/rules: updated shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1
2
/*
2
 
 * Copyright 2010 Inalogic® Inc.
 
3
 * Copyright 2010-2011 Inalogic® Inc.
3
4
 *
4
5
 * This program is free software: you can redistribute it and/or modify it
5
6
 * under the terms of the GNU Lesser General Public License, as
31
32
{
32
33
  NUX_IMPLEMENT_OBJECT_TYPE(ScrollView);
33
34
 
34
 
  ScrollView::ScrollView (NUX_FILE_LINE_DECL)
35
 
    :   View (NUX_FILE_LINE_PARAM)
 
35
  ScrollView::ScrollView(NUX_FILE_LINE_DECL)
 
36
    : View(NUX_FILE_LINE_PARAM)
 
37
    , m_MouseWheelScrollSize(32)
 
38
      // TODO: these should really be Rects.
 
39
    , m_ViewContentX(0)
 
40
    , m_ViewContentY(0)
 
41
    , m_ViewContentWidth(0)
 
42
    , m_ViewContentHeight(0)
 
43
    , m_ViewX(0)
 
44
    , m_ViewY(0)
 
45
    , m_ViewWidth(0)
 
46
    , m_ViewHeight(0)
 
47
    , m_TextureIndex(0)
 
48
    , m_ReformatTexture(true)
 
49
    , m_horizontal_scrollbar_enable(true)
 
50
    , m_vertical_scrollbar_enable(true)
 
51
    , m_top_border(4)
 
52
    , m_border(4)
 
53
    , _delta_x(0)
 
54
    , _delta_y(0)
 
55
    , m_bSizeMatchContent(false)
 
56
    , m_ViewContentLeftMargin(0)
 
57
    , m_ViewContentRightMargin(0)
 
58
    , m_ViewContentTopMargin(0)
 
59
    , m_ViewContentBottomMargin(0)
36
60
  {
37
 
    m_vertical_scrollbar_enable     = true;
38
 
    m_horizontal_scrollbar_enable   = true;
39
 
    m_bSizeMatchContent             = false;
40
 
    m_TextureIndex                  = 0;
41
 
    m_ReformatTexture               = true;
42
 
 
43
 
    _delta_x                        = 0;
44
 
    _delta_y                        = 0;
45
61
 
46
62
    //GetPainter().CreateBackgroundTexture(m_BackgroundTexture);
47
63
    _hscrollbar = new HScrollBar (NUX_TRACKER_LOCATION);
66
82
    mouse_wheel.connect(sigc::mem_fun(this, &ScrollView::RecvMouseWheel));
67
83
    _vscrollbar->mouse_wheel.connect(sigc::mem_fun(this, &ScrollView::RecvMouseWheel));
68
84
 
69
 
    setTopBorder (4);
70
 
    setBorder (4);
71
 
 
72
 
    m_MouseWheelScrollSize = 32;
73
 
 
74
 
    m_ViewContentLeftMargin      = 0;
75
 
    m_ViewContentRightMargin     = 0;
76
 
    m_ViewContentTopMargin       = 0;
77
 
    m_ViewContentBottomMargin    = 0;
78
85
    FormatContent();
79
 
  
 
86
 
80
87
    //FIXME disabling until we have better API for this
81
88
    //ChildFocusChanged.connect (sigc::mem_fun (this, &ScrollView::OnChildFocusChanged));
82
89
 
128
135
    }
129
136
    if (child->IsLayout ())
130
137
      return;
131
 
    
 
138
 
132
139
    int child_y = child->GetGeometry ().y - GetGeometry ().y;
133
140
    int child_y_diff = child_y - abs (_delta_y);
134
141
 
135
 
    
 
142
 
136
143
    if (child_y_diff + child->GetGeometry ().height < GetGeometry ().height && child_y_diff >= 0)
137
144
    {
138
145
      return;
139
146
    }
140
 
    
 
147
 
141
148
    if (child_y_diff < 0)
142
149
    {
143
150
      ScrollUp (1, abs (child_y_diff));
148
155
 
149
156
      // always keeps the top of a view on the screen
150
157
      size += (child->GetGeometry ().height, GetGeometry ().height) ? child->GetGeometry ().height : GetGeometry ().height;
151
 
      
 
158
 
152
159
      ScrollDown (1, size);
153
160
    }
154
161
 
217
224
  {
218
225
    // Test if the mouse is inside the ScrollView.
219
226
    // The last parameter of TestMousePointerInclusion is a boolean used to test if the case
220
 
    // of mouse wheel events. If that boolean value is true, then TestMousePointerInclusion 
 
227
    // of mouse wheel events. If that boolean value is true, then TestMousePointerInclusion
221
228
    // returns true only if the mouse pointer is over this area and the the area accepts
222
229
    // mouse wheel events (see Area::SetAcceptMouseWheelEvent)
223
230
    bool mouse_inside = TestMousePointerInclusionFilterMouseWheel(mouse_position, event_type);
339
346
///////////////////////
340
347
// Internal function //
341
348
///////////////////////
342
 
  void ScrollView::setBorder (int border)
343
 
  {
344
 
    m_border = border;
345
 
  }
346
 
 
347
 
  void ScrollView::setTopBorder (int top_border)
348
 
  {
349
 
    m_top_border = top_border;
350
 
  }
351
 
 
352
 
  int ScrollView::getBorder() const
353
 
  {
354
 
    return m_border;
355
 
  }
356
 
 
357
 
  int ScrollView::getTopBorder() const
358
 
  {
359
 
    return m_top_border;
360
 
  }
361
349
 
362
350
  void ScrollView::SetGeometry (const Geometry &geo)
363
351
  {
375
363
 
376
364
  void ScrollView::PreLayoutManagement()
377
365
  {
378
 
    // Reset the client view to the top left corner of the container.
379
 
    _delta_x = _delta_y = 0;
380
366
    // Give the managed layout the same size and position as the Control.
381
367
 
382
368
    Geometry geo = GetGeometry();
737
723
    w = _vscrollbar->GetBaseWidth();
738
724
    h = _hscrollbar->GetBaseHeight();
739
725
 
740
 
//    m_ViewX = GetX() + m_border;
741
 
//    m_ViewY = GetY() + m_top_border;
742
 
//
743
 
//    if(m_vertical_scrollbar_enable == false)
744
 
//        m_ViewWidth = GetWidth() - 2*m_border - m_ViewContentRightMargin;
745
 
//    else
746
 
//        m_ViewWidth = GetWidth() - w - 2*m_border - m_ViewContentRightMargin;
747
 
//
748
 
//    if(m_horizontal_scrollbar_enable == false)
749
 
//        m_ViewHeight = GetBaseHeight() - m_top_border - m_border - m_ViewContentBottomMargin;
750
 
//    else
751
 
//        m_ViewHeight = GetBaseHeight() - h - m_top_border - m_border - m_ViewContentBottomMargin;
752
 
 
753
726
    m_ViewX = GetBaseX() + m_border + m_ViewContentLeftMargin;
754
727
    m_ViewY = GetBaseY() + m_top_border + m_ViewContentTopMargin;
755
728