Back to index

nux  3.0.0
Panel.cpp
Go to the documentation of this file.
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   void Panel::Draw(GraphicsEngine &graphics_engine, bool force_draw)
00049   {
00050 
00051   }
00052 
00053   void Panel::DrawContent(GraphicsEngine &graphics_engine, bool force_draw)
00054   {
00055     graphics_engine.PushClippingRectangle(GetGeometry());
00056 
00057     graphics_engine.PushClippingRectangle(Rect(m_ViewX, m_ViewY, m_ViewWidth, m_ViewHeight));
00058 
00059     if (m_layout)
00060     {
00061       graphics_engine.PushClippingRectangle(m_layout->GetGeometry());
00062       m_layout->ProcessDraw(graphics_engine, force_draw);
00063       graphics_engine.PopClippingRectangle();
00064     }
00065 
00066     graphics_engine.PopClippingRectangle();
00067 
00068     if (m_vertical_scrollbar_enable)
00069     {
00070       _vscrollbar->ProcessDraw(graphics_engine, force_draw);
00071     }
00072 
00073     if (m_horizontal_scrollbar_enable)
00074     {
00075       _hscrollbar->ProcessDraw(graphics_engine, force_draw);
00076     }
00077 
00078     graphics_engine.PopClippingRectangle();
00079   }
00080 
00081   void Panel::AddWidget(View *ic, int stretchfactor)
00082   {
00083     if (ic && m_layout)
00084     {
00085       m_layout->AddView(ic, stretchfactor);
00086       // if (stretchfactor ==0): the WidgetLayout geometry will be set to SetGeometry(0,0,1,1);
00087       // and the children will take their natural size by expending WidgetLayout.
00088       // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout.
00089 
00090       ComputeContentSize();
00091     }
00092   }
00093 
00094   void Panel::AddWidget(std::list<View *> *ViewList)
00095   {
00096     std::list<View *>::iterator it;
00097 
00098     for (it = ViewList->begin(); it != ViewList->end(); it++)
00099     {
00100       AddWidget((*it));
00101     }
00102   }
00103 
00104   bool Panel::SetLayout(Layout *layout)
00105   {
00106     if (View::SetLayout(layout) == false)
00107     {
00108       return false;
00109     }
00110 
00111     m_layout = view_layout_;
00112     
00113     FormatContent();
00114 
00115     return true;
00116   }
00117 
00118   void Panel::clearContent()
00119   {
00120     m_layout->Clear();
00121   }
00122 
00123 // Get a change to do any work on an element.
00124 // Here we need to position the header by hand because it is not under the control of vlayout.
00125   void Panel::PreLayoutManagement()
00126   {
00127     ScrollView::PreLayoutManagement();
00128   }
00129 
00130 // Get a change to do any work on an element.
00131 // Here we need to position the header by hand because it is not under the control of vlayout.
00132   long Panel::PostLayoutManagement(long LayoutResult)
00133   {
00134     long result = ScrollView::PostLayoutManagement(LayoutResult);
00135     return result;
00136   }
00137 
00138 // Get a change to do any work on an element.
00139 // Here we need to position the header by hand because it is not under the control of vlayout.
00140   void Panel::ComputeContentPosition(float offsetX, float offsetY)
00141   {
00142     ScrollView::ComputeContentPosition(offsetX, offsetY);
00143   }
00144 
00145   void Panel::ScrollLeft(float stepx, int mousedx)
00146   {
00147     ScrollView::ScrollLeft(stepx, mousedx);
00148     ComputeContentSize();
00149     QueueDraw();
00150   }
00151 
00152   void Panel::ScrollRight(float stepx, int mousedx)
00153   {
00154     ScrollView::ScrollRight(stepx, mousedx);
00155     ComputeContentSize();
00156     QueueDraw();
00157   }
00158 
00159   void Panel::ScrollUp(float stepy, int mousedy)
00160   {
00161     ScrollView::ScrollUp(stepy, mousedy);
00162     ComputeContentSize();
00163     QueueDraw();
00164   }
00165 
00166   void Panel::ScrollDown(float stepy, int mousedy)
00167   {
00168     ScrollView::ScrollDown(stepy, mousedy);
00169     ComputeContentSize();
00170     QueueDraw();
00171   }
00172 
00173   bool Panel::AcceptKeyNavFocus()
00174   {
00175     return false;
00176   }
00177 }