nux-1.14.0
GroupBox.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 "GroupBox.h"
00026 
00027 namespace nux
00028 {
00029 
00030   GroupBox::GroupBox (const TCHAR *Caption, NUX_FILE_LINE_DECL)
00031     :   View (NUX_FILE_LINE_PARAM)
00032     ,   bCaptionAvailable (false)
00033     ,   m_layout (0)
00034   {
00035     m_CaptionArea.SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00036     m_CaptionArea.SetBaseSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00037 
00038     SetMinimumSize (DEFAULT_WIDGET_WIDTH + 5, PRACTICAL_WIDGET_HEIGHT + 5);
00039     SetBaseSize (DEFAULT_WIDGET_WIDTH + 5, 2 * PRACTICAL_WIDGET_HEIGHT);
00040     SetCaption (TEXT ("") );
00041   }
00042 
00043   GroupBox::~GroupBox()
00044   {
00045 
00046   }
00047 
00048   long GroupBox::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_y) )
00056       {
00057         ProcEvInfo = eDoNotProcess;
00058       }
00059     }
00060 
00061     if (m_layout != 0)
00062     {
00063       ret = m_layout->ProcessEvent (ievent, ret, ProcEvInfo);
00064     }
00065 
00066     ret = PostProcessEvent2 (ievent, ret, 0);
00067     return ret;
00068   }
00069 
00070 
00071   void GroupBox::Draw (GraphicsEngine &GfxContext, bool force_draw)
00072   {
00073     GfxContext.PushClippingRectangle (GetGeometry() );
00074 
00075     Geometry wireborder_geo = GetGeometry();
00076 
00077     //if(bCaptionAvailable)
00078     {
00079       wireborder_geo.OffsetPosition (0, 10);
00080       wireborder_geo.OffsetSize (0, -10);
00081     }
00082 //    else
00083 //    {
00084 //        wireborder_geo.OffsetPosition(0, 0);
00085 //        wireborder_geo.OffsetSize(0, 0);
00086 //    }
00087 
00088     //if(bCaptionAvailable)
00089     {
00090       //GetPainter().Paint2DQuadColor(m_CaptionArea.GetGeometry(), COLOR_BACKGROUND_PRIMARY);
00091       //GetPainter().PaintTextLineStatic(m_CaptionArea.GetGeometry(), m_CaptionArea.GetCaptionString(), eAlignTextCenter);
00092       GetPainter().PaintTextLineStatic (GfxContext, GetSysBoldFont(), m_CaptionArea.GetGeometry(), m_CaptionArea.GetBaseString().GetTCharPtr(), GetTextColor(),
00093                                     true, eAlignTextCenter);
00094     }
00095 
00096     if (m_layout != 0)
00097     {
00098       m_layout->QueueDraw();
00099     }
00100 
00101     GfxContext.PopClippingRectangle();
00102   }
00103 
00104   void GroupBox::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
00105   {
00106     GfxContext.PushClippingRectangle (GetGeometry() );
00107 
00108     if (m_layout)
00109     {
00110       GfxContext.PushClippingRectangle (m_layout->GetGeometry() );
00111       m_layout->ProcessDraw (GfxContext, force_draw);
00112       GfxContext.PopClippingRectangle();
00113     }
00114 
00115     GfxContext.PopClippingRectangle();
00116   }
00117 
00118   void GroupBox::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
00119   {
00120 
00121   }
00122 
00123   bool GroupBox::SetLayout (Layout *layout)
00124   {
00125     if(View::SetLayout(layout) == false)
00126     {
00127       return false;
00128     }
00129 
00130     m_layout = layout;
00131 
00132     return true;
00133 
00134 //    Geometry geo = GetGeometry();
00135 //    Geometry layout_geo = Geometry(geo.x + m_border, geo.y + m_top_border,
00136 //        geo.GetWidth() - 2*m_border, geo.GetHeight() - m_border - m_top_border);
00137 //    m_layout->SetGeometry(layout_geo);
00138   }
00139 
00140   void GroupBox::PreLayoutManagement()
00141   {
00142     // Give the managed layout appropriate size and position..
00143     if (m_CompositionLayout)
00144     {
00145       Geometry layout_geo = GetGeometry();
00146       //if(bCaptionAvailable)
00147       {
00148         layout_geo.OffsetPosition (2, 20);
00149         layout_geo.OffsetSize (-4, -22);
00150       }
00151 //        else
00152 //        {
00153 //            layout_geo.OffsetPosition(2, 2);
00154 //            layout_geo.OffsetSize(-4, -4);
00155 //        }
00156       m_CompositionLayout->SetGeometry (layout_geo);
00157     }
00158   }
00159 
00160   long GroupBox::PostLayoutManagement (long LayoutResult)
00161   {
00162     // A Group box must tightly group its children.
00163     // So it must embrace the size that was compute for the composition layout.
00164     // Only the size is change is important here of the GroupBox is important here.
00165 
00166     long ret = 0;
00167     Geometry old_geo = Area::GetGeometry();
00168 
00169     if (m_CompositionLayout)
00170     {
00171       Geometry base = m_CompositionLayout->GetGeometry();
00172       //if(bCaptionAvailable)
00173       {
00174         base.OffsetPosition (-2, -20);
00175         base.OffsetSize (4, 22);
00176       }
00177 //        else
00178 //        {
00179 //            base.OffsetPosition(-2, -2);
00180 //            base.OffsetSize(4, 4);
00181 //        }
00182       Area::SetGeometry (base);
00183     }
00184 
00185     Geometry base = GetGeometry();
00186     m_CaptionArea.SetBaseXY (base.x + 6, base.y);
00187 
00188     if (old_geo.GetWidth() > base.GetWidth() )
00189       ret |= eLargerWidth;
00190     else if (old_geo.GetWidth() < base.GetWidth() )
00191       ret |= eSmallerWidth;
00192     else
00193       ret |= eCompliantWidth;
00194 
00195     if (old_geo.GetHeight() > base.GetHeight() )
00196       ret |= eLargerHeight;
00197     else if (old_geo.GetHeight() < base.GetHeight() )
00198       ret |= eSmallerHeight;
00199     else
00200       ret |= eCompliantHeight;
00201 
00202     return ret;
00203   }
00204 
00205   void GroupBox::PositionChildLayout (float offsetX, float offsetY)
00206   {
00207     if (m_CompositionLayout)
00208     {
00209       //if(bCaptionAvailable)
00210       {
00211         m_CompositionLayout->SetBaseX (GetBaseX() + 2);
00212         m_CompositionLayout->SetBaseY (GetBaseY() + 20);
00213       }
00214 //        else
00215 //        {
00216 //            m_CompositionLayout->SetX(GetX() + 2);
00217 //            m_CompositionLayout->SetY(GetY() + 2);
00218 //        }
00219       m_CompositionLayout->ComputePosition2 (offsetX, offsetY);
00220     }
00221 
00222     Geometry base = GetGeometry();
00223     m_CaptionArea.SetBaseXY (base.x + 6, base.y);
00224   }
00225 
00226   void GroupBox::SetCaption (const char *name)
00227   {
00228     if ( (name == 0) || strlen (name) == 0)
00229     {
00230       //bCaptionAvailable = false;
00231       m_CaptionArea.SetBaseString (TEXT ("") );
00232       m_CaptionArea.SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00233       m_CaptionArea.SetBaseSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
00234     }
00235     else
00236     {
00237       //bCaptionAvailable = true;
00238       m_CaptionArea.SetBaseString (name);
00239       m_CaptionArea.SetMinimumSize (4 + GetSysBoldFont()->GetStringWidth (name), PRACTICAL_WIDGET_HEIGHT);
00240       m_CaptionArea.SetBaseSize (4 + GetSysBoldFont()->GetStringWidth (name), PRACTICAL_WIDGET_HEIGHT);
00241     }
00242   }
00243 
00244   bool GroupBox::AcceptKeyNavFocus()
00245   {
00246     return false;
00247   }
00248 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends