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