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 00025 #include "HToolBar.h" 00026 #include "HLayout.h" 00027 #include "ToolButton.h" 00028 #include "ActionItem.h" 00029 #include "AbstractSeparator.h" 00030 #include "VSeparator.h" 00031 #include "EditTextBox.h" 00032 #include "StaticTextBox.h" 00033 00034 namespace nux 00035 { 00036 00037 HToolBar::HToolBar (NUX_FILE_LINE_DECL) 00038 : View (NUX_FILE_LINE_PARAM) 00039 , m_hlayout (0) 00040 { 00041 m_hlayout = new HLayout (NUX_TRACKER_LOCATION); 00042 00043 m_hlayout->SetHorizontalInternalMargin (2); 00044 m_hlayout->SetHorizontalExternalMargin (0); 00045 m_hlayout->SetVerticalExternalMargin (0); 00046 m_hlayout->SetContentDistribution (eStackLeft); 00047 SetMinimumSize (200, 32); 00048 SetMaximumHeight (32); 00049 SetGeometry (Geometry (0, 0, 200, 20) ); 00050 SetCompositionLayout (m_hlayout); 00051 } 00052 00053 HToolBar::~HToolBar() 00054 { 00055 } 00056 00057 long HToolBar::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00058 { 00059 long ret = TraverseInfo; 00060 00061 ret = m_hlayout->ProcessEvent (ievent, TraverseInfo, ProcessEventInfo); 00062 00063 // PostProcessEvent2 must always have its last parameter set to 0 00064 // because the m_BackgroundArea is the real physical limit of the window. 00065 // So the previous test about IsPointInside do not prevail over m_BackgroundArea 00066 // testing the event by itself. 00067 ret = PostProcessEvent2 (ievent, ret, 0); 00068 return ret; 00069 } 00070 00071 void HToolBar::Draw (GraphicsEngine &GfxContext, bool force_draw) 00072 { 00073 Geometry base = GetGeometry(); 00074 GfxContext.PushClippingRectangle (base); 00075 00076 GfxContext.QRP_Color (base.x, base.y, base.GetWidth(), base.GetHeight(), COLOR_BACKGROUND_PRIMARY); 00077 00078 GfxContext.PopClippingRectangle(); 00079 } 00080 00081 void HToolBar::DrawContent (GraphicsEngine &GfxContext, bool force_draw) 00082 { 00083 Geometry base = GetGeometry(); 00084 GfxContext.PushClippingRectangle (base); 00085 GetPainter().PushColorLayer (GfxContext, base, COLOR_BACKGROUND_PRIMARY); 00086 m_hlayout->ProcessDraw (GfxContext, force_draw); 00087 GetPainter().PopBackground(); 00088 GfxContext.PopClippingRectangle(); 00089 } 00090 00091 void HToolBar::PostDraw (GraphicsEngine &GfxContext, bool force_draw) 00092 { 00093 00094 } 00095 00096 void HToolBar::AddToolButton (ToolButton *toolbutton) 00097 { 00098 nuxAssert (toolbutton); 00099 00100 if (toolbutton == 0) 00101 return; 00102 00103 m_hlayout->AddView (toolbutton, 0, eCenter, eFix); 00104 // 0: the WidgetLayout geometry will be set to SetGeometry(0,0,1,1); 00105 // and the children will take their natural size by expending WidgetLayout. 00106 // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout. 00107 ComputeChildLayout(); 00108 } 00109 00110 void HToolBar::AddAction (ActionItem *action) 00111 { 00112 // nuxAssert(action); 00113 // if(action == 0) 00114 // return; 00115 00116 ToolButton *tool_button (new ToolButton); 00117 tool_button->SetAction (action); 00118 00119 m_hlayout->AddView (tool_button, 0, eCenter, eFix); 00120 // 0: the WidgetLayout geometry will be set to SetGeometry(0,0,1,1); 00121 // and the children will take their natural size by expending WidgetLayout. 00122 // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout. 00123 ComputeChildLayout(); 00124 } 00125 00126 void HToolBar::AddSpace (int size) 00127 { 00128 SpaceLayout *layout (new SpaceLayout() ); 00129 layout->SetMaximumWidth (size); 00130 layout->SetMinimumWidth (size); 00131 m_hlayout->AddLayout (layout); 00132 ComputeChildLayout(); 00133 } 00134 00135 void HToolBar::AddSeparator() 00136 { 00137 VSeparator *separator (new VSeparator() ); 00138 m_hlayout->AddView (separator, 0); 00139 ComputeChildLayout(); 00140 } 00141 00142 void HToolBar::AddEditTextLine (EditTextBox *edittextline) 00143 { 00144 nuxAssert (edittextline); 00145 00146 if (edittextline == 0) 00147 return; 00148 00149 m_hlayout->AddView (edittextline, 0, eCenter, eFix); 00150 // 0: the WidgetLayout geometry will be set to SetGeometry(0,0,1,1); 00151 // and the children will take their natural size by expending WidgetLayout. 00152 // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout. 00153 ComputeChildLayout(); 00154 } 00155 00156 void HToolBar::AddStaticTextLine (StaticTextBox *statictextline) 00157 { 00158 nuxAssert (statictextline); 00159 00160 if (statictextline == 0) 00161 return; 00162 00163 m_hlayout->AddView (statictextline, 0, eCenter, eFix); 00164 // 0: the WidgetLayout geometry will be set to SetGeometry(0,0,1,1); 00165 // and the children will take their natural size by expending WidgetLayout. 00166 // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout. 00167 ComputeChildLayout(); 00168 } 00169 00170 void HToolBar::ClearWidget() 00171 { 00172 m_CompositionLayout->Clear(); 00173 } 00174 00175 void HToolBar::RecvMouseDownOnIcon (int x, int y, unsigned long button_flags, unsigned long key_flags) 00176 { 00177 QueueDraw(); 00178 } 00179 00180 void HToolBar::RecvMouseUpOnIcon (int x, int y, unsigned long button_flags, unsigned long key_flags) 00181 { 00182 QueueDraw(); 00183 } 00184 00185 void HToolBar::RecvMouseMoveOnIcon (int x, int y, unsigned long button_flags, unsigned long key_flags) 00186 { 00187 QueueDraw(); 00188 } 00189 00190 void HToolBar::RecvMouseDragOnIcon (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 00191 { 00192 QueueDraw(); 00193 } 00194 00195 void HToolBar::RecvMouseEnterIcon (int x, int y, unsigned long button_flags, unsigned long key_flags) 00196 { 00197 QueueDraw(); 00198 } 00199 00200 void HToolBar::RecvMouseLeaveIcon (int x, int y, unsigned long button_flags, unsigned long key_flags) 00201 { 00202 QueueDraw(); 00203 } 00204 }