nux-1.14.0
Valuator.cpp
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 "TimerProc.h"
00025 #include "EditTextBox.h"
00026 #include "Valuator.h"
00027 
00028 namespace nux
00029 {
00030 
00031   Valuator::Valuator (NUX_FILE_LINE_DECL)
00032     :   View (NUX_FILE_LINE_PARAM)
00033     ,   m_Mouse (0)
00034   {
00035     m_MouseControlledButton = new InputArea (NUX_TRACKER_LOCATION);
00036     //m_MouseControlledButton->Reference();
00037     m_EditLine              = new EditTextBox (TEXT (""), NUX_TRACKER_LOCATION);
00038     //m_EditLine->Reference();
00039     // Set Original State
00040     m_EditLine->SetSuffix (TEXT ("") );
00041     m_EditLine->SetPrefix (TEXT ("") );
00042 
00043     // Set Signals
00044     m_MouseControlledButton->mouse_down.connect (sigc::mem_fun (this, &Valuator::RecvMouseDown) );
00045     m_MouseControlledButton->mouse_double_click.connect (sigc::mem_fun (this, &Valuator::RecvMouseDown) );
00046     m_MouseControlledButton->mouse_up.connect (sigc::mem_fun (this, &Valuator::RecvMouseUp) );
00047     m_MouseControlledButton->mouse_drag.connect (sigc::mem_fun (this, &Valuator::RecvMouseDrag) );
00048     m_MouseControlledButton->mouse_enter.connect (sigc::mem_fun (this, &Valuator::RecvMouseEnter) );
00049     m_MouseControlledButton->mouse_leave.connect (sigc::mem_fun (this, &Valuator::RecvMouseLeave) );
00050 
00051     m_EditLine->sigValidateEntry.connect (sigc::mem_fun (this, &Valuator::RecvValidateEntry) );
00052     m_EditLine->sigStartKeyboardFocus.connect (sigc::mem_fun (this, &Valuator::RecvStartKeyboardFocus) );
00053     m_EditLine->sigEndKeyboardFocus.connect (sigc::mem_fun (this, &Valuator::RecvEndKeyboardFocus) );
00054     m_EditLine->sigEscapeKeyboardFocus.connect (sigc::mem_fun (this, &Valuator::RecvEscapeKeyboardFocus) );
00055     m_EditLine->sigEditChange.connect (sigc::mem_fun (this, &Valuator::RecvEditChange) );
00056     m_EditLine->mouse_enter.connect (sigc::mem_fun (this, &Valuator::RecvMouseEnter) );
00057     m_EditLine->mouse_leave.connect (sigc::mem_fun (this, &Valuator::RecvMouseLeave) );
00058 
00059   }
00060 
00061   Valuator::~Valuator()
00062   {
00063 //     if (m_EditLine)
00064 //     {
00065 //       if (m_EditLine->OwnsTheReference())
00066 //         m_EditLine->UnReference();
00067 //       else
00068 //         m_EditLine->Dispose();
00069 //     }
00070 // 
00071 //     if (m_MouseControlledButton)
00072 //     {
00073 //       if (m_MouseControlledButton->OwnsTheReference())
00074 //         m_MouseControlledButton->UnReference();
00075 //       else
00076 //         m_MouseControlledButton->Dispose();
00077 //     }
00078   }
00079 
00080   void Valuator::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
00081   {
00082     if (button_flags & NUX_EVENT_BUTTON1)
00083       m_Mouse = 1;
00084     else if (button_flags & NUX_EVENT_BUTTON3)
00085       m_Mouse = 3;
00086 
00087     QueueDraw();
00088   }
00089 
00090   void Valuator::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
00091   {
00092     if ( (m_Mouse == 1) && (button_flags & NUX_EVENT_BUTTON1) )
00093       m_Mouse = 0;
00094     else if ( (m_Mouse == 3) && (button_flags & NUX_EVENT_BUTTON3) )
00095       m_Mouse = 0;
00096 
00097     QueueDraw();
00098   }
00099 
00100   void Valuator::RecvDecrement (int x, int y, unsigned long button_flags, unsigned long key_flags)
00101   {
00102     TimerSpinDownBtn (0);
00103   }
00104 
00105   void Valuator::TimerSpinUpBtn (void *v)
00106   {
00107     ImplementIncrementBtn();
00108   }
00109 
00110   void Valuator::TimerSpinDownBtn (void *v)
00111   {
00112     ImplementDecrementBtn();
00113   }
00114 
00115   void Valuator::RecvStartKeyboardFocus (EditTextBox *textbox)
00116   {
00117     QueueDraw();
00118   }
00119 
00120   void Valuator::RecvEndKeyboardFocus (EditTextBox *textbox)
00121   {
00122     QueueDraw();
00123   }
00124 
00125   void Valuator::RecvEscapeKeyboardFocus (EditTextBox *textbox)
00126   {
00127     QueueDraw();
00128   }
00129 
00130   void Valuator::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
00131   {
00132     QueueDraw();
00133   }
00134 
00135   void Valuator::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
00136   {
00137     QueueDraw();
00138   }
00139 
00140   void Valuator::RecvMouseMove (int x, int y, unsigned long button_flags, unsigned long key_flags)
00141   {
00142     QueueDraw();
00143   }
00144 
00145   void Valuator::RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
00146   {
00147     if (m_Mouse == 1)
00148     {
00149       if (dx > 0)
00150         TimerSpinUpBtn (0);
00151 
00152       if (dx < 0)
00153         TimerSpinDownBtn (0);
00154     }
00155 
00156     if (m_Mouse == 3)
00157     {
00158       if (dy > 0)
00159         TimerSpinDownBtn (0);
00160 
00161       if (dy < 0)
00162         TimerSpinUpBtn (0);
00163     }
00164 
00165     QueueDraw();
00166   }
00167 
00168   void Valuator::RecvEditChange (EditTextBox *textbox)
00169   {
00170     QueueDraw();
00171   }
00172 
00173   void Valuator::RecvValidateEntry (EditTextBox *textbox)
00174   {
00175     ImplementValidateEntry();
00176 
00177 //    int ret = 0;
00178 //    if(inlCharToInteger(m_EditLine->GetCleanCaption().GetTChar(), ret))
00179 //    {
00180 //        m_iValue = ret;
00181 //        if(m_iValue < m_IntValidator.GetMinimum())
00182 //        {
00183 //            m_iValue = m_IntValidator.GetMinimum();
00184 //            m_EditLine->setCaption(NString::Printf("%d", m_iValue));
00185 //        }
00186 //        if(m_iValue > m_IntValidator.GetMaximum())
00187 //        {
00188 //            m_iValue = m_IntValidator.GetMaximum();
00189 //            m_EditLine->setCaption(NString::Printf("%d", m_iValue));
00190 //        }
00191 //    }
00192 //    else
00193 //    {
00194 //        m_EditLine->setCaption(NString::Printf("%d", m_iValue));
00195 //    }
00196   }
00197 
00198 
00199 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends