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 * Gordon Allott <gord.allott@canonical.com> 00020 * 00021 */ 00022 00023 #include "Nux.h" 00024 #include "AbstractButton.h" 00025 #include "HLayout.h" 00026 00027 namespace nux 00028 { 00029 NUX_IMPLEMENT_OBJECT_TYPE(AbstractButton); 00030 00031 AbstractButton::AbstractButton(NUX_FILE_LINE_DECL) 00032 : View(NUX_FILE_LINE_PARAM) 00033 , state(NUX_STATE_NORMAL) 00034 { 00035 active = false; 00036 togglable_ = false; 00037 Init(); 00038 } 00039 00040 AbstractButton::~AbstractButton() 00041 { 00042 00043 } 00044 00045 void AbstractButton::Init() 00046 { 00047 mouse_click.connect(sigc::mem_fun(this, &AbstractButton::RecvClick)); 00048 mouse_down.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseDown)); 00049 mouse_double_click.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseDown)); 00050 mouse_up.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseUp)); 00051 mouse_move.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseMove)); 00052 mouse_enter.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseEnter)); 00053 mouse_leave.connect(sigc::mem_fun(this, &AbstractButton::RecvMouseLeave)); 00054 } 00055 00056 long AbstractButton::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo) 00057 { 00058 return PostProcessEvent2 (ievent, TraverseInfo, ProcessEventInfo); 00059 } 00060 00061 void AbstractButton::RecvClick(int x, int y, unsigned long button_flags, unsigned long key_flags) 00062 { 00063 if (!IsViewActive()) 00064 return; 00065 00066 if(togglable_) 00067 { 00068 active = !active; 00069 } 00070 else 00071 { 00072 active = true; 00073 } 00074 00075 if(togglable_ == false) 00076 { 00077 active = false; 00078 } 00079 00080 activated.emit(this); 00081 QueueDraw(); 00082 } 00083 00084 void AbstractButton::RecvMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) 00085 { 00086 if (!IsViewActive()) 00087 return; 00088 00089 state = NUX_STATE_PRELIGHT; 00090 //state = 1; 00091 QueueDraw(); 00092 } 00093 00094 void AbstractButton::RecvMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags) 00095 { 00096 if (!IsViewActive()) 00097 return; 00098 00099 state = NUX_STATE_ACTIVE; 00100 QueueDraw(); 00101 } 00102 00103 void AbstractButton::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) 00104 { 00105 00106 } 00107 00108 void AbstractButton::RecvMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) 00109 { 00110 state = NUX_STATE_PRELIGHT; 00111 QueueDraw(); 00112 } 00113 00114 void AbstractButton::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) 00115 { 00116 state = NUX_STATE_NORMAL; 00117 QueueDraw(); 00118 } 00119 }