nux-1.16.0
Panel.cpp
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "Nux.h"
00024 #include "Layout.h"
00025 #include "WindowCompositor.h"
00026 #include "VScrollBar.h"
00027 #include "HScrollBar.h"
00028 #include "Panel.h"
00029 
00030 namespace nux
00031 {
00032 
00033   Panel::Panel (NUX_FILE_LINE_DECL)
00034     :   ScrollView (NUX_FILE_LINE_PARAM)
00035     ,   m_layout (0)
00036   {
00037     m_top_border = 0;
00038     m_border = 0;
00039   }
00040 
00041   Panel::~Panel()
00042   {
00043     // Delete all the interface object: This is a problem... The widget should be destroy by there associated parameters
00044     //delete vlayout;
00045     m_layout = NULL;
00046   }
00047 
00048   long Panel::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
00049   {
00050     long ret = TraverseInfo;
00051     long ProcEvInfo = 0;
00052 
00053     if (ievent.e_event == NUX_MOUSE_PRESSED)
00054     {
00055       if (!GetGeometry().IsPointInside (ievent.e_x - ievent.e_x_root, ievent.e_y - ievent.e_y_root) )
00056       {
00057         ProcEvInfo = eDoNotProcess;
00058         //return TraverseInfo;
00059       }
00060     }
00061 
00062     if (m_vertical_scrollbar_enable)
00063       ret = _vscrollbar->ProcessEvent (ievent, ret, ProcEvInfo);
00064 
00065     if (m_horizontal_scrollbar_enable)
00066       ret = _hscrollbar->ProcessEvent (ievent, ret, ProcEvInfo);
00067 
00068     // The child layout get the Mouse down button only if the MouseDown happened inside the client view Area
00069     Geometry viewGeometry = Geometry (m_ViewX, m_ViewY, m_ViewWidth, m_ViewHeight);
00070 
00071     if (ievent.e_event == NUX_MOUSE_PRESSED)
00072     {
00073       if (!viewGeometry.IsPointInside (ievent.e_x - ievent.e_x_root, ievent.e_y - ievent.e_y_root) )
00074       {
00075         ProcEvInfo = eDoNotProcess;
00076       }
00077     }
00078 
00079     if (m_layout)
00080       ret = m_layout->ProcessEvent (ievent, ret, ProcEvInfo);
00081 
00082     ret = PostProcessEvent2 (ievent, ret, 0);
00083     return ret;
00084   }
00085 
00086   void Panel::Draw (GraphicsEngine &GfxContext, bool force_draw)
00087   {
00088     GfxContext.PushClippingRectangle (GetGeometry() );
00089 
00090     Geometry base = GetGeometry();
00091 
00092     if (m_layout)
00093       m_layout->QueueDraw();
00094 
00095     GetPainter().PaintBackground (GfxContext, base);
00096 
00097     if (m_vertical_scrollbar_enable)
00098     {
00099       _vscrollbar->QueueDraw();
00100     }
00101 
00102     if (m_horizontal_scrollbar_enable)
00103     {
00104       _hscrollbar->QueueDraw();
00105     }
00106 
00107     GfxContext.PopClippingRectangle();
00108   }
00109 
00110   void Panel::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
00111   {
00112     GfxContext.PushClippingRectangle (GetGeometry() );
00113 
00114     GfxContext.PushClippingRectangle (Rect (m_ViewX, m_ViewY, m_ViewWidth, m_ViewHeight) );
00115 
00116     if (m_layout)
00117     {
00118       GfxContext.PushClippingRectangle (m_layout->GetGeometry() );
00119       m_layout->ProcessDraw (GfxContext, force_draw);
00120       GfxContext.PopClippingRectangle();
00121     }
00122 
00123     GfxContext.PopClippingRectangle();
00124 
00125     if (m_vertical_scrollbar_enable)
00126     {
00127       _vscrollbar->ProcessDraw (GfxContext, force_draw);
00128     }
00129 
00130     if (m_horizontal_scrollbar_enable)
00131     {
00132       _hscrollbar->ProcessDraw (GfxContext, force_draw);
00133     }
00134 
00135     GfxContext.PopClippingRectangle();
00136   }
00137 
00138   void Panel::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
00139   {
00140 
00141   }
00142 
00143   void Panel::AddWidget (View *ic, int stretchfactor)
00144   {
00145     if (ic && m_layout)
00146     {
00147       m_layout->AddView (ic, stretchfactor);
00148       // if(stretchfactor ==0): the WidgetLayout geometry will be set to SetGeometry(0,0,1,1);
00149       // and the children will take their natural size by expending WidgetLayout.
00150       // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout.
00151 
00152       ComputeChildLayout();
00153     }
00154   }
00155 
00156   void Panel::AddWidget (std::list<View *> *ViewList)
00157   {
00158     std::list<View *>::iterator it;
00159 
00160     for (it = ViewList->begin(); it != ViewList->end(); it++)
00161     {
00162       AddWidget ( (*it) );
00163     }
00164   }
00165 
00166   bool Panel::SetLayout (Layout *layout)
00167   {
00168     if(View::SetLayout(layout) == false)
00169     {
00170       return false;
00171     }
00172 
00173     m_layout = m_CompositionLayout;
00174     
00175     FormatContent();
00176 
00177     return true;
00178   }
00179 
00180   void Panel::clearContent()
00181   {
00182     m_layout->Clear();
00183   }
00184 
00185 // Get a change to do any work on an element.
00186 // Here we need to position the header by hand because it is not under the control of vlayout.
00187   void Panel::PreLayoutManagement()
00188   {
00189     ScrollView::PreLayoutManagement();
00190   }
00191 
00192 // Get a change to do any work on an element.
00193 // Here we need to position the header by hand because it is not under the control of vlayout.
00194   long Panel::PostLayoutManagement (long LayoutResult)
00195   {
00196     long result = ScrollView::PostLayoutManagement (LayoutResult);
00197     return result;
00198   }
00199 
00200 // Get a change to do any work on an element.
00201 // Here we need to position the header by hand because it is not under the control of vlayout.
00202   void Panel::PositionChildLayout (float offsetX, float offsetY)
00203   {
00204     ScrollView::PositionChildLayout (offsetX, offsetY);
00205   }
00206 
00207   void Panel::ScrollLeft (float stepx, int mousedx)
00208   {
00209     ScrollView::ScrollLeft (stepx, mousedx);
00210     ComputeChildLayout();
00211     QueueDraw();
00212   }
00213 
00214   void Panel::ScrollRight (float stepx, int mousedx)
00215   {
00216     ScrollView::ScrollRight (stepx, mousedx);
00217     ComputeChildLayout();
00218     QueueDraw();
00219   }
00220 
00221   void Panel::ScrollUp (float stepy, int mousedy)
00222   {
00223     ScrollView::ScrollUp (stepy, mousedy);
00224     ComputeChildLayout();
00225     QueueDraw();
00226   }
00227 
00228   void Panel::ScrollDown (float stepy, int mousedy)
00229   {
00230     ScrollView::ScrollDown (stepy, mousedy);
00231     ComputeChildLayout();
00232     QueueDraw();
00233   }
00234 
00235   bool Panel::AcceptKeyNavFocus()
00236   {
00237     return false;
00238   }
00239 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends