Back to index

plt-scheme  4.2.1
Gauge.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: gauge panel item
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifdef __GNUG__
00028 #pragma implementation "Gauge.h"
00029 #endif
00030 
00031 #define  Uses_XtIntrinsic
00032 #define  Uses_wxGauge
00033 #include "wx.h"
00034 #define  Uses_TraversingEnforcerWidget
00035 #define  Uses_SliderWidget
00036 #include "widgets.h"
00037 
00038 //-----------------------------------------------------------------------------
00039 // create and destroy gauge
00040 //-----------------------------------------------------------------------------
00041 
00042 wxGauge::wxGauge(wxPanel *panel, char *label, int _range,
00043                int x, int y, int width, int height, long style, 
00044                wxFont *_font, char *name) : wxItem(_font)
00045 {
00046     __type = wxTYPE_GAUGE;
00047 
00048     range = value = 0;
00049 
00050     Create(panel, label, _range, x, y, width, height, style, name);
00051 }
00052 
00053 #define wxDEFAULT_GAUGE_WIDTH             100
00054 #define wxDEFAULT_GAUGE_HEIGHT             24
00055 
00056 Bool wxGauge::Create(wxPanel *panel, char *label, int _range,
00057                    int x, int y, int width, int height, long style, char *name)
00058 {
00059     Widget wgt;
00060     wxWindow_Xintern *ph;
00061     Bool vert;
00062     double lw, lh, lvh, lhw;
00063 
00064     ChainToPanel(panel, style, name);
00065 
00066     if (style & wxVERTICAL_LABEL)
00067       vert = 1;
00068     else if (style & wxHORIZONTAL_LABEL)
00069       vert = 0;
00070     else
00071       vert = (panel->GetLabelPosition() == wxVERTICAL);
00072     range     = _range;
00073 
00074     label = wxGetCtlLabel(label);
00075 
00076     ph = parent->GetHandle();
00077 
00078     // create frame
00079     wgt = XtVaCreateWidget
00080        (name, xfwfTraversingEnforcerWidgetClass, ph->handle,
00081         XtNlabel,       label,
00082         XtNalignment,   vert ? XfwfTop : XfwfLeft,
00083         XtNbackground,  wxGREY_PIXEL,
00084         XtNforeground,  wxBLACK_PIXEL,
00085         XtNfont,        font->GetInternalFont(),
00086 #ifdef WX_USE_XFT
00087         XtNxfont,       font->GetInternalAAFont(),
00088 #endif
00089         XtNtraversalOn, FALSE,
00090         XtNframeType,   XfwfSunken,
00091         XtNframeWidth,  1,
00092         XtNhighlightThickness, 0, XtNtraversalOn, FALSE,
00093         NULL);
00094     if (!(style & wxINVISIBLE))
00095       XtManageChild(wgt);
00096     else
00097       XtRealizeWidget(wgt);
00098     X->frame = wgt;
00099     // create the slider widget
00100     wgt = XtVaCreateManagedWidget
00101        ("gauge", xfwfSlider2WidgetClass, X->frame,
00102         XtNbackground,    wxDARK_GREY_PIXEL,
00103         XtNforeground,    wxBLACK_PIXEL,
00104         XtNthumbColor,    wxCTL_HIGHLIGHT_PIXEL,
00105         XtNminsize,     0,
00106         XtNframeType,     XfwfRaised,
00107         XtNframeWidth,    0,
00108         XtNhighlightThickness, 0,
00109         NULL);
00110     X->handle = wgt;
00111     XtUninstallTranslations(X->handle);
00112     // set data declared in wxItem
00113     // panel positioning
00114 
00115     if (label)
00116       GetTextExtent(label, &lw, &lh, NULL, NULL, font);
00117     else
00118       lw = lh = 0;
00119     if (vert) {
00120       lhw = 0;
00121       lvh = lh;
00122     } else {
00123       lhw = lw;
00124       lvh = 0;
00125     }
00126 
00127     panel->PositionItem(this, x, y, 
00128                      (width  > -1 
00129                       ? (int)width  
00130                       : ((style & wxVERTICAL) 
00131                          ? (int)lhw + wxDEFAULT_GAUGE_HEIGHT
00132                          : (int)lhw + wxDEFAULT_GAUGE_WIDTH)),
00133                      (height > -1 
00134                       ? (int)height 
00135                       : ((style & wxVERTICAL) 
00136                          ? (int)lvh + wxDEFAULT_GAUGE_WIDTH
00137                          : (int)lvh + wxDEFAULT_GAUGE_HEIGHT)));
00138 
00139     SetValue(0);
00140 
00141     AddEventHandlers();
00142 
00143     if (style & wxINVISIBLE)
00144       Show(FALSE);
00145 
00146     return TRUE;
00147 }
00148 
00149 //-----------------------------------------------------------------------------
00150 // methods to access internal data
00151 //-----------------------------------------------------------------------------
00152 
00153 void wxGauge::SetRange(int new_range)
00154 {
00155     if (0 <= new_range) {
00156        range = new_range;
00157        SetValue(value);
00158     }
00159 }
00160 
00161 void wxGauge::SetValue(int new_value)
00162 {
00163   if (0 <= new_value && new_value <= range) {
00164     value = new_value;
00165     if (style & wxVERTICAL) {
00166       XfwfMoveThumb (X->handle, 0.0, 1.0);
00167       XfwfResizeThumb(X->handle, 1.0, ((double)value)/((double)range));
00168     } else {
00169       XfwfMoveThumb(X->handle, 0.0, 0.0);
00170       XfwfResizeThumb(X->handle, ((double)value)/((double)range), 1.0);
00171     }
00172   }
00173 }