~sil2100/nux/revert_640

« back to all changes in this revision

Viewing changes to Nux/Area.cpp

  • Committer: Jay Taoko
  • Date: 2011-10-09 22:18:34 UTC
  • Revision ID: jay.taoko@canonical.com-20111009221834-9y890qzzj8rlp2r6
* Removing non-core UI views from Nux
* Refactoring in Layout
* Added LinearLayout.h/.cpp as a sub-class for HLayout and VLayout

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
  Area::Area (NUX_FILE_LINE_DECL)
38
38
    :   InitiallyUnownedObject (NUX_FILE_LINE_PARAM)
39
 
    ,   _is_focused (0)
40
39
    ,   geometry_ (0, 0, DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT)
41
 
    ,   _min_size (AREA_MIN_WIDTH, AREA_MIN_HEIGHT)
42
 
    ,   _max_size (AREA_MAX_WIDTH, AREA_MAX_HEIGHT)
 
40
    ,   min_size_ (AREA_MIN_WIDTH, AREA_MIN_HEIGHT)
 
41
    ,   max_size_ (AREA_MAX_WIDTH, AREA_MAX_HEIGHT)
43
42
  {
44
 
    _parent_area = NULL;
45
 
    next_object_to_key_focus_area_ = NULL;
46
 
    has_key_focus_ = false;
47
 
 
48
 
    _stretch_factor = 1;
49
 
    _layout_properties = NULL;
50
43
    visible_ = true;
 
44
    view_enabled_ = true;
 
45
    parent_area_ = NULL;
 
46
 
 
47
    next_object_to_key_focus_area_ = NULL;
 
48
    has_key_focus_ = false;
 
49
 
 
50
    scale_factor_ = 1;
51
51
    sensitive_ = true;
52
52
 
53
53
    on_geometry_change_reconfigure_parent_layout_ = true;
62
62
 
63
63
  Area::~Area()
64
64
  {
65
 
    if (_layout_properties)
66
 
      delete _layout_properties;
67
65
  }
68
66
 
69
67
  const NString &Area::GetBaseString() const
78
76
 
79
77
  void Area::CheckMinSize()
80
78
  {
81
 
    int w = _min_size.width;
 
79
    int w = min_size_.width;
82
80
    w = Max<int>(AREA_MIN_WIDTH, w);
83
 
    int h = _min_size.height;
 
81
    int h = min_size_.height;
84
82
    h = Max<int>(AREA_MIN_HEIGHT, h);
85
83
 
86
 
    _min_size = Size(w, h);
87
 
 
88
 
    if (_min_size.width > _max_size.width)
89
 
    {
90
 
      _max_size.width = _min_size.width;
91
 
    }
92
 
 
93
 
    if (_min_size.height > _max_size.height)
94
 
    {
95
 
      _max_size.height = _min_size.height;
96
 
    }
97
 
 
98
 
    if (geometry_.width < _min_size.width)
99
 
    {
100
 
      geometry_.width = _min_size.width;
101
 
    }
102
 
 
103
 
    if (geometry_.height < _min_size.height )
104
 
    {
105
 
      geometry_.height = _min_size.height;
 
84
    min_size_ = Size(w, h);
 
85
 
 
86
    if (min_size_.width > max_size_.width)
 
87
    {
 
88
      max_size_.width = min_size_.width;
 
89
    }
 
90
 
 
91
    if (min_size_.height > max_size_.height)
 
92
    {
 
93
      max_size_.height = min_size_.height;
 
94
    }
 
95
 
 
96
    if (geometry_.width < min_size_.width)
 
97
    {
 
98
      geometry_.width = min_size_.width;
 
99
    }
 
100
 
 
101
    if (geometry_.height < min_size_.height )
 
102
    {
 
103
      geometry_.height = min_size_.height;
106
104
    }
107
105
  }
108
106
 
109
107
  void Area::CheckMaxSize()
110
108
  {
111
 
    int w = _max_size.width;
 
109
    int w = max_size_.width;
112
110
    w = Min<int>(AREA_MAX_WIDTH, w);
113
 
    int h = _max_size.height;
 
111
    int h = max_size_.height;
114
112
    h = Min<int>(AREA_MAX_HEIGHT, h);
115
113
 
116
 
    _max_size = Size(w, h);
117
 
 
118
 
    if (_min_size.width > _max_size.width)
119
 
    {
120
 
      _min_size.width = _max_size.width;
121
 
    }
122
 
 
123
 
    if (_min_size.height > _max_size.height)
124
 
    {
125
 
      _min_size.height = _max_size.height;
126
 
    }
127
 
 
128
 
    if (geometry_.width > _max_size.width)
129
 
    {
130
 
      geometry_.width = _max_size.width;
131
 
    }
132
 
 
133
 
    if (geometry_.height > _max_size.height)
134
 
    {
135
 
      geometry_.height = _max_size.height;
 
114
    max_size_ = Size(w, h);
 
115
 
 
116
    if (min_size_.width > max_size_.width)
 
117
    {
 
118
      min_size_.width = max_size_.width;
 
119
    }
 
120
 
 
121
    if (min_size_.height > max_size_.height)
 
122
    {
 
123
      min_size_.height = max_size_.height;
 
124
    }
 
125
 
 
126
    if (geometry_.width > max_size_.width)
 
127
    {
 
128
      geometry_.width = max_size_.width;
 
129
    }
 
130
 
 
131
    if (geometry_.height > max_size_.height)
 
132
    {
 
133
      geometry_.height = max_size_.height;
136
134
    }
137
135
  }
138
136
 
140
138
  {
141
139
    nuxAssert (w >= 0);
142
140
    nuxAssert (h >= 0);
143
 
    _min_size = Size(w, h);
 
141
    min_size_ = Size(w, h);
144
142
 
145
143
    CheckMinSize();
146
144
 
151
149
  {
152
150
    nuxAssert (w >= 0);
153
151
    nuxAssert (h >= 0);
154
 
    _max_size = Size(w, h);
 
152
    max_size_ = Size(w, h);
155
153
 
156
154
    CheckMaxSize();
157
155
 
170
168
 
171
169
  void Area::ApplyMinWidth()
172
170
  {
173
 
    geometry_.width = _min_size.width;
 
171
    geometry_.width = min_size_.width;
174
172
 
175
173
    ReconfigureParentLayout();
176
174
  }
177
175
 
178
176
  void Area::ApplyMinHeight()
179
177
  {
180
 
    geometry_.height = _min_size.height;
 
178
    geometry_.height = min_size_.height;
181
179
 
182
180
    ReconfigureParentLayout();
183
181
  }
184
182
 
185
183
  void Area::ApplyMaxWidth()
186
184
  {
187
 
    geometry_.width = _max_size.width;
 
185
    geometry_.width = max_size_.width;
188
186
 
189
187
    ReconfigureParentLayout();
190
188
  }
191
189
 
192
190
  void Area::ApplyMaxHeight()
193
191
  {
194
 
    geometry_.height = _max_size.height;
 
192
    geometry_.height = max_size_.height;
195
193
 
196
194
    ReconfigureParentLayout();
197
195
  }
198
196
 
199
197
  Size Area::GetMinimumSize() const
200
198
  {
201
 
    return _min_size;
 
199
    return min_size_;
202
200
  }
203
201
 
204
202
  Size Area::GetMaximumSize() const
205
203
  {
206
 
    return _max_size;
 
204
    return max_size_;
207
205
  }
208
206
 
209
207
  void Area::SetMinimumWidth (int w)
210
208
  {
211
209
    nuxAssert (w >= 0);
212
 
    _min_size.width = w;
 
210
    min_size_.width = w;
213
211
    CheckMinSize();
214
212
    ReconfigureParentLayout();
215
213
  }
217
215
  void Area::SetMaximumWidth (int w)
218
216
  {
219
217
    nuxAssert (w >= 0);
220
 
    _max_size.width = w;
 
218
    max_size_.width = w;
221
219
    CheckMaxSize();
222
220
    ReconfigureParentLayout();
223
221
  }
225
223
  void Area::SetMinimumHeight (int h)
226
224
  {
227
225
    nuxAssert (h >= 0);
228
 
    _min_size.height = h;
 
226
    min_size_.height = h;
229
227
    CheckMinSize();
230
228
    ReconfigureParentLayout();
231
229
  }
233
231
  void Area::SetMaximumHeight (int h)
234
232
  {
235
233
    nuxAssert (h >= 0);
236
 
    _max_size.height = h;
 
234
    max_size_.height = h;
237
235
    CheckMaxSize();
238
236
    ReconfigureParentLayout();
239
237
  }
240
238
 
241
239
  int Area::GetMinimumWidth() const
242
240
  {
243
 
    return _min_size.width;
 
241
    return min_size_.width;
244
242
  }
245
243
 
246
244
  int Area::GetMaximumWidth() const
247
245
  {
248
 
    return _max_size.width;
 
246
    return max_size_.width;
249
247
  }
250
248
 
251
249
  int Area::GetMinimumHeight() const
252
250
  {
253
 
    return _min_size.height;
 
251
    return min_size_.height;
254
252
  }
255
253
 
256
254
  int Area::GetMaximumHeight() const
257
255
  {
258
 
    return _max_size.height;
 
256
    return max_size_.height;
259
257
  }
260
258
 
261
259
  unsigned int Area::GetStretchFactor()
262
260
  {
263
 
    return _stretch_factor;
 
261
    return scale_factor_;
264
262
  }
265
263
 
266
264
  void Area::SetStretchFactor (unsigned int sf)
267
265
  {
268
266
    // re implemented by Layout
269
 
    _stretch_factor = sf;
 
267
    scale_factor_ = sf;
270
268
  }
271
269
 
272
270
  bool Area::SetParentObject (Area *parent)
277
275
      return false;
278
276
    }
279
277
 
280
 
    if (_parent_area && (_parent_area != parent))
 
278
    if (parent_area_ && (parent_area_ != parent))
281
279
    {
282
 
      nuxAssertMsg (0, TEXT ("[Area::SetParentObject] Object already has a parent. You must UnParent the object before you can parenting again.") );
 
280
      nuxAssertMsg (0, "[Area::SetParentObject] Object already has a parent. You must UnParent the object before you can parenting again." );
283
281
      return false;
284
282
    }
285
283
 
286
 
    if (_parent_area)
 
284
    if (parent_area_)
287
285
    {
288
286
      // Already parented to the same area. Return.
289
287
      return true;
290
288
    }
291
289
 
292
 
    _parent_area = parent;
 
290
    parent_area_ = parent;
293
291
    Reference();
294
292
 
295
293
    return true;
297
295
 
298
296
  void Area::UnParentObject()
299
297
  {
300
 
    if (_parent_area)
 
298
    if (parent_area_)
301
299
    {
302
 
      _parent_area = 0;
 
300
      parent_area_ = 0;
303
301
      UnReference();
304
302
    }
305
303
  }
306
304
 
307
305
  Area *Area::GetParentObject() const
308
306
  {
309
 
    return _parent_area;
 
307
    return parent_area_;
310
308
  }
311
309
 
312
310
  int Area::GetBaseX     () const
331
329
 
332
330
  void Area::SetGeometry(int x, int y, int w, int h)
333
331
  {
334
 
    h = nux::Clamp<int> (h, _min_size.height, _max_size.height);
335
 
    w = nux::Clamp<int> (w, _min_size.width, _max_size.width);
 
332
    h = nux::Clamp<int> (h, min_size_.height, max_size_.height);
 
333
    w = nux::Clamp<int> (w, min_size_.width, max_size_.width);
336
334
 
337
335
    nux::Geometry geometry(x, y, w, h);
338
336
    if (geometry_ == geometry)
450
448
          GetWindowThread ()->QueueObjectLayout (ic);
451
449
        }
452
450
      }
453
 
      else if (ic->_parent_area)
454
 
        ic->_parent_area->ReconfigureParentLayout (this);
 
451
      else if (ic->parent_area_)
 
452
        ic->parent_area_->ReconfigureParentLayout (this);
455
453
      else
456
454
      {
457
455
        GetWindowThread ()->QueueObjectLayout (ic);
468
466
 
469
467
      Layout *layout = static_cast<Layout *>(this);
470
468
 
471
 
      if (layout->_parent_area)
 
469
      if (layout->parent_area_)
472
470
      {
473
 
        if (layout->_parent_area->Type().IsDerivedFromType (View::StaticObjectType) )
 
471
        if (layout->parent_area_->Type().IsDerivedFromType (View::StaticObjectType) )
474
472
        {
475
 
          View *ic = (View *) (layout->_parent_area);
 
473
          View *ic = (View *) (layout->parent_area_);
476
474
 
477
475
          if (ic->CanBreakLayout() )
478
476
          {
491
489
          else
492
490
          {
493
491
            // The parent object of an object of type View is a Layout object type.
494
 
            layout->_parent_area->ReconfigureParentLayout (this);
 
492
            layout->parent_area_->ReconfigureParentLayout (this);
495
493
          }
496
494
        }
497
495
        else
498
496
        {
499
 
          layout->_parent_area->ReconfigureParentLayout (this);
 
497
          layout->parent_area_->ReconfigureParentLayout (this);
500
498
        }
501
499
      }
502
500
      else
508
506
    else
509
507
    {
510
508
      // The object that is being resized is a InputArea object.
511
 
      if (this->_parent_area)
 
509
      if (this->parent_area_)
512
510
      {
513
511
        // The object that is being resized is a View object and it has a parent.
514
512
        if (this->OwnsTheReference() == false && this->GetParentObject())
518
516
        }
519
517
 
520
518
        // The parent object of an object of type InputArea is a Layout object type.
521
 
        this->_parent_area->ReconfigureParentLayout (this);
 
519
        this->parent_area_->ReconfigureParentLayout (this);
522
520
      }
523
521
    }
524
522
  }
525
523
 
526
524
  void Area::RequestBottomUpLayoutComputation (Area *bo_initiator)
527
525
  {
528
 
    if (_parent_area && _parent_area->IsLayout() )
 
526
    if (parent_area_ && parent_area_->IsLayout() )
529
527
    {
530
 
      _parent_area->RequestBottomUpLayoutComputation (bo_initiator);
 
528
      parent_area_->RequestBottomUpLayoutComputation (bo_initiator);
531
529
    }
532
530
  }
533
531
 
534
 
  void Area::SetLayoutProperties (LayoutProperties *properties)
535
 
  {
536
 
    if (_layout_properties)
537
 
      delete _layout_properties;
538
 
 
539
 
    _layout_properties = properties;
540
 
  }
541
 
 
542
 
  Area::LayoutProperties * Area::GetLayoutProperties ()
543
 
  {
544
 
    return _layout_properties;
545
 
  }
546
 
 
547
532
  void Area::SetVisible (bool visible)
548
533
  {
549
534
    if (visible_ == visible)
559
544
    return visible_;
560
545
  }
561
546
 
562
 
  void Area::SetSensitive (bool sensitive)
 
547
  void Area::SetSensitive(bool sensitive)
 
548
  {
 
549
    SetInputEventSensitivity(sensitive);
 
550
  }
 
551
 
 
552
  void Area::SetInputEventSensitivity(bool sensitive)
563
553
  {
564
554
    if (sensitive_ == sensitive)
565
555
      return;
566
556
 
567
557
    sensitive_ = sensitive;
568
558
 
569
 
    OnSensitiveChanged.emit (this, sensitive_);
570
 
  }
571
 
 
572
 
  bool Area::IsSensitive ()
 
559
    OnSensitiveChanged.emit(this, sensitive_);
 
560
  }
 
561
 
 
562
  bool Area::IsSensitive() const
 
563
  {
 
564
    return GetInputEventSensitivity();
 
565
  }
 
566
 
 
567
  bool Area::GetInputEventSensitivity() const
573
568
  {
574
569
    return sensitive_;
575
570
  }
576
571
 
577
572
  MinorDimensionPosition Area::GetPositioning()
578
573
  {
579
 
    return _positioning;
 
574
    return minor_axis_position_;
580
575
  }
581
576
 
582
577
  void Area::SetPositioning (MinorDimensionPosition p)
583
578
  {
584
 
    _positioning = p;
 
579
    minor_axis_position_ = p;
585
580
  }
586
581
 
587
582
  MinorDimensionSize Area::GetExtend()
588
583
  {
589
 
    return _extend;
 
584
    return minor_axis_size_;
590
585
  }
591
586
 
592
587
  void Area::SetExtend (MinorDimensionSize ext)
593
588
  {
594
 
    _extend = ext;
 
589
    minor_axis_size_ = ext;
595
590
  }
596
591
 
597
592
  float Area::GetPercentage()
598
593
  {
599
 
    return _percentage;
 
594
    return minor_axis_size_scale_;
600
595
  }
601
596
 
602
597
  void Area::SetPercentage (float p)
603
598
  {
604
 
    _percentage = p;
 
599
    minor_axis_size_scale_ = p;
605
600
  }
606
601
 
607
602
  bool Area::IsLayoutDone()
608
603
  {
609
 
    return _layout_done;
 
604
    return layout_done_;
610
605
  }
611
606
 
612
607
  void Area::SetLayoutDone (bool b)
613
608
  {
614
 
    _layout_done = b;
 
609
    layout_done_ = b;
615
610
  }
616
611
 
617
612
  bool Area::IsArea () const
830
825
    if (this == parent)
831
826
      return true;
832
827
 
833
 
    if (!parent || !_parent_area)
 
828
    if (!parent || !parent_area_)
834
829
      return false;
835
830
 
836
 
    return _parent_area->IsChildOf(parent);    
 
831
    return parent_area_->IsChildOf(parent);    
837
832
  }
838
833
 
839
834
  void Area::QueueRelayout ()
861
856
    return _accept_mouse_wheel_event;
862
857
  }
863
858
 
864
 
  bool Area::TestMousePointerInclusion(const Point& mouse_position, NuxEventType event_type)
865
 
  {
866
 
    if (IsSensitive() == false)
867
 
      return false;
868
 
 
869
 
    bool mouse_pointer_inside_area = false;
870
 
 
871
 
    if (Type().IsDerivedFromType(MenuPage::StaticObjectType))
872
 
    {
873
 
      // A MenuPage geometry is already in absolute coordinates.
874
 
      mouse_pointer_inside_area = geometry_.IsInside(mouse_position);
875
 
    }
876
 
    else
877
 
    {
878
 
      mouse_pointer_inside_area = GetAbsoluteGeometry().IsInside(mouse_position);
879
 
    }
880
 
 
881
 
    if ((event_type == NUX_MOUSE_WHEEL) && mouse_pointer_inside_area)
882
 
    {
883
 
      if (_accept_mouse_wheel_event == false)
884
 
        return NULL;
885
 
    }
886
 
 
887
 
    return mouse_pointer_inside_area;
888
 
  }
889
 
 
890
 
  bool Area::TestMousePointerInclusionFilterMouseWheel(const Point& mouse_position, NuxEventType event_type)
891
 
  {
892
 
    if (IsSensitive() == false)
893
 
      return false;
894
 
 
895
 
    bool mouse_pointer_inside_area = false;
896
 
 
897
 
    if (Type().IsDerivedFromType(MenuPage::StaticObjectType))
898
 
    {
899
 
      // A MenuPage geometry is already in absolute coordinates.
900
 
      mouse_pointer_inside_area = geometry_.IsInside(mouse_position);
901
 
    }
902
 
    else
903
 
    {
904
 
      mouse_pointer_inside_area = GetAbsoluteGeometry().IsInside(mouse_position);
905
 
    }
906
 
 
907
 
    return mouse_pointer_inside_area;
908
 
  }
 
859
   bool Area::TestMousePointerInclusion(const Point& mouse_position, NuxEventType event_type)
 
860
   {
 
861
     if ((IsLayout() == false) && ((GetInputEventSensitivity() == false) || (view_enabled_ == false)))
 
862
     {
 
863
       // If this area is not a view and:
 
864
       //    - it is insensitive to input event
 
865
       //    - it is not enabled
 
866
       //    - it is not visible
 
867
       // then return false.
 
868
       return false;
 
869
     }
 
870
 
 
871
     bool mouse_pointer_inside_area = false;
 
872
 
 
873
     if (Type().IsDerivedFromType(MenuPage::StaticObjectType))
 
874
     {
 
875
       // A MenuPage geometry is already in absolute coordinates.
 
876
       mouse_pointer_inside_area = geometry_.IsInside(mouse_position);
 
877
     }
 
878
     else
 
879
     {
 
880
       mouse_pointer_inside_area = GetAbsoluteGeometry().IsInside(mouse_position);
 
881
     }
 
882
 
 
883
     if ((event_type == NUX_MOUSE_WHEEL) && mouse_pointer_inside_area)
 
884
     {
 
885
       if (_accept_mouse_wheel_event == false)
 
886
         return NULL;
 
887
     }
 
888
 
 
889
     return mouse_pointer_inside_area;
 
890
   }
 
891
 
 
892
   bool Area::TestMousePointerInclusionFilterMouseWheel(const Point& mouse_position, NuxEventType event_type)
 
893
   {
 
894
     if ((IsLayout() == false) && ((GetInputEventSensitivity() == false) || (view_enabled_ == false)))
 
895
     {
 
896
       // If this area is not a view and:
 
897
       //    - it is insensitive to input event
 
898
       //    - it is not enabled
 
899
       //    - it is not visible
 
900
       // then return false.
 
901
 
 
902
       return false;
 
903
     }
 
904
 
 
905
     bool mouse_pointer_inside_area = false;
 
906
 
 
907
     if (Type().IsDerivedFromType(MenuPage::StaticObjectType))
 
908
     {
 
909
       // A MenuPage geometry is already in absolute coordinates.
 
910
       mouse_pointer_inside_area = geometry_.IsInside(mouse_position);
 
911
     }
 
912
     else
 
913
     {
 
914
       mouse_pointer_inside_area = GetAbsoluteGeometry().IsInside(mouse_position);
 
915
     }
 
916
 
 
917
     return mouse_pointer_inside_area;
 
918
   }
909
919
 
910
920
  Area* Area::FindAreaUnderMouse(const Point& mouse_position, NuxEventType event_type)
911
921
  {
961
971
  void Area::ResetUpwardPathToKeyFocusArea()
962
972
  {
963
973
    has_key_focus_ = false;
964
 
    if (_parent_area)
 
974
    if (parent_area_)
965
975
    {
966
 
      _parent_area->ResetUpwardPathToKeyFocusArea();
 
976
      parent_area_->ResetUpwardPathToKeyFocusArea();
967
977
    }
968
978
    if(next_object_to_key_focus_area_)
969
979
      next_object_to_key_focus_area_->UnReference();
980
990
 
981
991
  bool Area::AcceptKeyNavFocus()
982
992
  {
983
 
    if (IsSensitive() == false)
 
993
    if (GetInputEventSensitivity() == false)
984
994
      return false;
985
995
 
986
996
    return true;