Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgspinnerbox.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:16:04 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgspinnerbox.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pgspinnerbox.h"
00030 #include "pgmaskedit.h"
00031 #include "pglineedit.h"
00032 #include "pgbutton.h"
00033 
00038 PG_SpinnerBox::PG_SpinnerBox(PG_Widget *parent, const PG_Rect& r, const std::string& style) : PG_ThemeWidget( parent, r, style ) {
00039         PG_Rect box_rect = r;
00040         PG_Rect up_rect, down_rect;
00041         box_rect.my_width -= (my_height/2);
00042         if( box_rect.my_width < my_height ) {
00043                 box_rect.my_width = my_height;
00044         }
00045         SizeWidget( box_rect.my_width+(my_height/2), my_height );
00046 
00047         m_pParent = parent;
00048 
00049         box_rect.my_xpos = box_rect.my_ypos = 0;
00050         up_rect.SetRect( box_rect.my_width, 0, (my_height/2), (my_height/2));
00051         down_rect.SetRect( box_rect.my_width, my_height - (my_height/2), (my_height/2), (my_height/2));
00052 
00053         m_pEditBox = new PG_MaskEdit(this, box_rect, style);
00054         m_pEditBox->sigEditEnd.connect(slot(*this, &PG_SpinnerBox::handleEditEnd));
00055 
00056         m_pButtonUp = new PG_Button(this, up_rect);
00057         m_pButtonUp->SetID(IDSPINNERBOX_UP);
00058         m_pButtonUp->sigClick.connect(slot(*this, &PG_SpinnerBox::handleButtonClick));
00059         m_pButtonUp->LoadThemeStyle(style, "ButtonUp");
00060 
00061         m_pButtonDown = new PG_Button( this, down_rect);
00062         m_pButtonDown->SetID(IDSPINNERBOX_DOWN);
00063         m_pButtonDown->sigClick.connect(slot(*this, &PG_SpinnerBox::handleButtonClick));
00064         m_pButtonDown->LoadThemeStyle(style, "ButtonDown");
00065 
00066         m_iMinValue = 0;
00067         m_iMaxValue = 99;
00068         m_iValue = 0;
00069         SetMask( "##" );
00070         m_pEditBox->SetText( "0" );
00071         m_pEditBox->SetValidKeys("-0123456789");
00072 }
00073 
00074 bool PG_SpinnerBox::handleButtonClick(PG_Button* button) {
00075 
00076         switch(button->GetID()) {
00077 
00078                 case IDSPINNERBOX_UP: // Up
00079                         if( m_iValue < m_iMaxValue ) {
00080                                 m_iValue++;
00081                                 SetTextValue();
00082                                 return true;
00083                         }
00084                         return false;
00085 
00086                 case IDSPINNERBOX_DOWN: // Down
00087                         if( m_iValue > m_iMinValue ) {
00088                                 m_iValue--;
00089                                 SetTextValue();
00090                                 return true;
00091                         }
00092                         return false;
00093         }
00094 
00095         return false;
00096 }
00097 
00098 void PG_SpinnerBox::SetTextValue() {
00099         m_pEditBox->SetTextFormat("%u", m_iValue );
00100         m_pEditBox->Update();
00101         sigChange(this, m_iValue);
00102 }
00103 
00104 void PG_SpinnerBox::AdjustSize() {
00105         Uint16 x, y;
00106 
00107         PG_FontEngine::GetTextSize(m_sMask, GetFont(), &x, &y);
00108         x += 3;
00109         y = m_pEditBox->my_height;
00110 
00111         Hide();
00112 
00113         SizeWidget( x+ (y >> 1), y );
00114         m_pEditBox->SizeWidget( x, y );
00115         m_pButtonUp->MoveWidget( x, 0 );
00116         m_pButtonDown->MoveWidget( x, y - (y >> 1) );
00117 
00118         Show();
00119 }
00120 
00121 bool PG_SpinnerBox::handleEditEnd(PG_LineEdit* edit) {
00122         const std::string& text = m_pEditBox->GetText();
00123         m_iValue = (!text.empty()) ? atoi(text.c_str()) : 0;
00124 
00125         // AMC Dec.4/2001
00126         if (m_iValue>m_iMaxValue) {
00127                 m_iValue=m_iMaxValue;
00128         }
00129 
00130         if (m_iValue<m_iMinValue) {
00131                 m_iValue=m_iMinValue;
00132         }
00133 
00134         SetTextValue();
00135         return true;
00136 }
00137 
00138 void PG_SpinnerBox::SetMask(const std::string& value) {
00139         m_sMask = value;
00140         m_pEditBox->SetMask( m_sMask );
00141         AdjustSize();
00142 }

Generated on Tue Jun 24 01:27:49 2008 for Advanced Strategic Command by  doxygen 1.4.2