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