nux-1.16.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 "Layout.h" 00025 #include "HLayout.h" 00026 #include "VLayout.h" 00027 #include "Validator.h" 00028 #include "StaticTextBox.h" 00029 00030 namespace nux 00031 { 00032 NUX_IMPLEMENT_OBJECT_TYPE (StaticTextBox); 00033 00034 StaticTextBox::StaticTextBox (const TCHAR *Caption, NUX_FILE_LINE_DECL) 00035 : View (NUX_FILE_LINE_PARAM) 00036 , m_TextAlignment (eAlignTextLeft) 00037 , m_bMinimumWidthMatchText (true) 00038 , m_bDrawBackground (false) 00039 , m_WriteAlpha (true) 00040 { 00041 m_BackgroundColor = Color (0xFF343434); 00042 m_TextColor = Color (1.0f, 1.0f, 1.0f, 1.0f); 00043 // First, set the default minimum size. 00044 SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT); 00045 00046 // The width size of the text is computed in SetText and set as the minimum for the widget. 00047 // If the text is null or empty, then the default minimum widtth set above remains. 00048 SetText (Caption); 00049 00050 SetGeometry (Geometry (0, 0, 3 * DEFAULT_WIDGET_WIDTH, DEFAULT_WIDGET_HEIGHT) ); 00051 00052 // This widget does not use a layout! 00053 m_Background = 0; 00054 } 00055 00056 StaticTextBox::~StaticTextBox() 00057 { 00058 delete m_Background; 00059 } 00060 00061 long StaticTextBox::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00062 { 00063 long ret = TraverseInfo; 00064 00065 ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo); 00066 return ret; 00067 } 00068 00069 void StaticTextBox::Draw (GraphicsEngine &GfxContext, bool force_draw) 00070 { 00071 Geometry base = GetGeometry(); 00072 { 00073 GfxContext.PushClippingRectangle (base); 00074 00075 if (m_bDrawBackground) 00076 { 00077 GetPainter().PushDrawLayer (GfxContext, base, m_Background); 00078 GetPainter().PaintTextLineStatic (GfxContext, GetFont (), GetGeometry(), m_Text.GetTCharPtr(), m_TextColor, m_WriteAlpha, m_TextAlignment); 00079 GetPainter().PopBackground(); 00080 } 00081 else 00082 { 00083 //GetPainter().PaintBackground(GfxContext, base); 00084 GetPainter().PaintTextLineStatic (GfxContext, GetFont (), GetGeometry(), m_Text.GetTCharPtr(), m_TextColor, m_WriteAlpha, m_TextAlignment); 00085 } 00086 00087 GfxContext.PopClippingRectangle(); 00088 } 00089 } 00090 00091 void StaticTextBox::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00092 { 00093 00094 } 00095 00096 void StaticTextBox::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00097 { 00098 00099 } 00100 00101 void StaticTextBox::SetText (const TCHAR &Caption) 00102 { 00103 NString s (Caption); 00104 SetText (s); 00105 } 00106 00107 void StaticTextBox::SetText (const TCHAR *Caption) 00108 { 00109 NString s (Caption); 00110 SetText (s); 00111 } 00112 00113 void StaticTextBox::SetText (const tstring &Caption) 00114 { 00115 NString s (Caption); 00116 SetText (s); 00117 } 00118 00119 void StaticTextBox::SetText (const NString &Caption) 00120 { 00121 m_Text = Caption; 00122 00123 if (GetMinWidthMatchText() ) 00124 AdjustMinWidthToMatchText(); 00125 00126 QueueDraw(); 00127 } 00128 00129 void StaticTextBox::SetMinWidthMatchText (bool b) 00130 { 00131 m_bMinimumWidthMatchText = b; 00132 00133 if (m_bMinimumWidthMatchText) 00134 AdjustMinWidthToMatchText(); 00135 } 00136 00137 bool StaticTextBox::GetMinWidthMatchText() const 00138 { 00139 return m_bMinimumWidthMatchText; 00140 } 00141 00142 void StaticTextBox::AdjustMinWidthToMatchText() 00143 { 00144 if (m_Text.Size() == 0) 00145 return; 00146 00147 SetMinimumWidth (/*4 + */GetFont ()->GetStringWidth (m_Text.GetTStringRef() ) ); 00148 } 00149 00150 void StaticTextBox::SetFont (ObjectPtr<FontTexture> Font) 00151 { 00152 View::SetFont (Font); 00153 00154 if (GetMinWidthMatchText() ) 00155 AdjustMinWidthToMatchText(); 00156 } 00157 00158 void StaticTextBox::SetBackground (AbstractPaintLayer *layer) 00159 { 00160 delete m_Background; 00161 m_Background = layer->Clone(); 00162 } 00163 00164 bool StaticTextBox::AcceptKeyNavFocus() 00165 { 00166 return false; 00167 } 00168 }