nux-1.14.0
|
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 "AbstractComboBox.h" 00025 #include "HLayout.h" 00026 #include "StaticText.h" 00027 00028 namespace nux 00029 { 00030 00031 Color AbstractComboBox::m_sCOMBO_COLOR = Color (0x009F9F00); 00032 Color AbstractComboBox::m_sCOMBO_BUTTON_COLOR = Color (0x00FFFFFF); 00033 Color AbstractComboBox::m_sCOMBO_MOUSEOVER_COLOR = Color (0x55FFFFFF); 00034 00035 AbstractComboBox::AbstractComboBox (NUX_FILE_LINE_DECL) 00036 : View (NUX_FILE_LINE_PARAM) 00037 , m_MenuIsActive (false) 00038 { 00039 m_hlayout = new HLayout(NUX_TRACKER_LOCATION); 00040 _combo_box_area = new InputArea(NUX_TRACKER_LOCATION); 00041 _combo_box_opening_area = new InputArea(NUX_TRACKER_LOCATION); 00042 00043 m_hlayout->AddView (_combo_box_area, 1); 00044 m_hlayout->AddView (_combo_box_opening_area, 0); 00045 m_hlayout->SetHorizontalExternalMargin (0); 00046 m_hlayout->SetVerticalExternalMargin (0); 00047 SetLayout (m_hlayout); 00048 00049 _combo_box_area->mouse_enter.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseEnter) ); 00050 _combo_box_area->mouse_leave.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseLeave) ); 00051 00052 _combo_box_opening_area->mouse_enter.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseEnter) ); 00053 _combo_box_opening_area->mouse_leave.connect (sigc::mem_fun (this, &AbstractComboBox::RecvMouseLeave) ); 00054 00055 SetTextColor (color::Black); 00056 00057 _pango_static_text = new StaticText (TEXT(""), NUX_TRACKER_LOCATION); 00058 } 00059 00060 AbstractComboBox::~AbstractComboBox() 00061 { 00062 if (_pango_static_text) 00063 _pango_static_text->Dispose (); 00064 _pango_static_text = 0; 00065 } 00066 00067 void AbstractComboBox::Draw (GraphicsEngine &GfxContext, bool force_draw) 00068 { 00069 Geometry base = GetGeometry(); 00070 00071 GfxContext.PushClippingRectangle (base); 00072 GetPainter().PaintBackground (GfxContext, base); 00073 GetPainter().PaintShape (GfxContext, base, m_sCOMBO_COLOR, eSHAPE_CORNER_ROUND4); 00074 00075 { 00076 //GetPainter().PaintTextLineStatic (GfxContext, GetFont (), _combo_box_area->GetGeometry(), _combo_box_area->GetBaseString().GetTCharPtr(), GetTextColor(), eAlignTextLeft); 00077 _pango_static_text->SetGeometry (_combo_box_area->GetGeometry ()); 00078 _pango_static_text->ProcessDraw (GfxContext, true); 00079 } 00080 00081 Geometry button_geo = _combo_box_opening_area->GetGeometry(); 00082 button_geo.OffsetSize (-5, -2); 00083 button_geo.OffsetPosition (+4, +1); 00084 00085 if (_combo_box_area->IsMouseInside() || _combo_box_opening_area->IsMouseInside() || GetFocused ()) 00086 GetPainter().PaintShape (GfxContext, button_geo, m_sCOMBO_MOUSEOVER_COLOR, eSHAPE_CORNER_ROUND4); 00087 else 00088 GetPainter().PaintShape (GfxContext, button_geo, m_sCOMBO_BUTTON_COLOR, eSHAPE_CORNER_ROUND4); 00089 00090 GeometryPositioning gp (eHACenter, eVACenter); 00091 Geometry GeoPo = ComputeGeometryPositioning (button_geo, GetTheme().GetImageGeometry (eCOMBOBOX_OPEN_BUTTON), gp); 00092 GetPainter().PaintShape (GfxContext, GeoPo, Color (0xFFFFFFFF), eCOMBOBOX_OPEN_BUTTON); 00093 00094 Geometry popup_geometry; 00095 popup_geometry.SetX (_combo_box_area->GetBaseX() ); 00096 popup_geometry.SetY (_combo_box_area->GetBaseY() + _combo_box_area->GetBaseHeight() ); 00097 popup_geometry.SetWidth (_combo_box_area->GetBaseWidth() ); 00098 popup_geometry.SetHeight (_combo_box_area->GetBaseHeight() ); 00099 00100 GfxContext.PopClippingRectangle (); 00101 } 00102 00103 void AbstractComboBox::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00104 { 00105 00106 } 00107 00108 void AbstractComboBox::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00109 { 00110 00111 } 00112 00113 void AbstractComboBox::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags) 00114 { 00115 QueueDraw(); 00116 } 00117 00118 void AbstractComboBox::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags) 00119 { 00120 QueueDraw(); 00121 } 00122 00123 00124 00125 }