1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
/*
* $Id: prefsautoscroll.c,v 1.5 2003/07/05 20:46:37 prussar Exp $
*
* Viewer - a part of Plucker, the free off-line HTML viewer for PalmOS
* Copyright (c) 1998-2002, Mark Ian Lillywhite and Michael Nordstrom
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "control.h"
#include "prefsdata.h"
#include "util.h"
#include "prefsautoscroll.h"
/***********************************************************************
*
* Local functions
*
***********************************************************************/
static UInt16 HandleSpinner( UInt16 direction, UInt16 variable,
UInt16 minValue, UInt16 maxValue, UInt16 controlID,
UInt16 increment, UInt16 fineTransition, UInt16 fineIncrement )
PREFSFORM_SECTION;
/***********************************************************************
*
* Private variables
*
***********************************************************************/
static Boolean showFirst;
static AutoscrollModeType autoscrollMode;
static AutoscrollDirType autoscrollDir;
static UInt16 autoscrollInterval;
static UInt16 autoscrollJump;
/* Handle the Autoscroll preferences */
Boolean PrefsAutoscrollPreferenceEvent
(
ActionType action
)
{
Boolean handled;
ControlType* ctl;
static Char jumpLabel[ maxStrIToALen ];
static Char intervalLabel[ maxStrIToALen ];
handled = false;
switch ( action ) {
case AVAILABLE:
/* Always available */
handled = true;
break;
case SHOWFIRST:
handled = showFirst;
showFirst = false;
break;
case LOAD:
ctl = GetObjectPtr( frmPrefsAutoscrollJumpButton );
autoscrollJump = Prefs()->autoscrollJump;
StrIToA( jumpLabel, autoscrollJump );
CtlSetLabel( ctl, jumpLabel );
autoscrollMode = Prefs()->autoscrollMode; SetListToSelection(
frmPrefsAutoscrollModeList, frmPrefsAutoscrollModePopup,
autoscrollMode );
autoscrollDir = Prefs()->autoscrollDir;
SetListToSelection( frmPrefsAutoscrollDirList,
frmPrefsAutoscrollDirPopup, autoscrollDir ^ 1 );
ctl = GetObjectPtr( frmPrefsAutoscrollIntervalButton );
autoscrollInterval = TICKS_TO_MILLISECONDS(
Prefs()->autoscrollInterval );
StrIToA( intervalLabel, autoscrollInterval );
CtlSetLabel( ctl, intervalLabel );
CtlSetValue( GetObjectPtr( frmPrefsAutoscrollStayOn ),
Prefs()->autoscrollStayOn );
handled = true;
break;
case SAVE:
Prefs()->autoscrollJump = autoscrollJump;
Prefs()->autoscrollMode = autoscrollMode;
Prefs()->autoscrollDir = autoscrollDir;
/* pref in ticks, label in milliseconds */
Prefs()->autoscrollInterval = MILLISECONDS_TO_TICKS(
autoscrollInterval );
Prefs()->autoscrollStayOn = CtlGetValue(
GetObjectPtr( frmPrefsAutoscrollStayOn ) );
handled = true;
break;
default:
handled = false;
break;
}
return handled;
}
/* Handles behaviour of spinners for the Autoscroll section */
static UInt16 HandleSpinner
(
UInt16 direction, /* whether variable should increase or decrease */
UInt16 variable, /* variable to modify with the spinner input */
UInt16 minValue, /* minimum value allowed */
UInt16 maxValue, /* maximum value allowed */
UInt16 controlID, /* resourceID of the control to show the variable's
current value */
UInt16 increment, /* how much to increase by */
UInt16 fineTransition, /* from 0 to this, use the fineIncrement instead */
UInt16 fineIncrement /* use this from 0 to fineTransition */
)
{
ControlType* ctl;
static Char spinnerLabel[ maxStrIToALen ];
ctl = GetObjectPtr( controlID );
if ( direction == AUTOSCROLL_UP && ( variable + increment ) <= maxValue )
{
if ( variable < fineTransition )
variable += fineIncrement;
else
variable += increment;
}
else if ( direction == AUTOSCROLL_DOWN && minValue < variable )
{
if ( variable <= fineTransition )
variable -= fineIncrement;
else
variable -= increment;
}
else
SndPlaySystemSound( sndWarning );
StrIToA( spinnerLabel, variable );
CtlSetLabel( ctl, spinnerLabel );
return variable;
}
/* Nominate the Autoscroll section to be shown first when the prefsform loads */
void PrefsAutoscrollShowFirst( void )
{
showFirst = true;
}
/* Event handler for the Autoscroll preference */
Boolean PrefsAutoscrollPalmEvent
(
EventType* event /* pointer to an EventType structure */
)
{
Boolean handled;
handled = false;
switch ( event->eType ) {
case ctlSelectEvent:
switch ( event->data.ctlEnter.controlID ) {
case frmPrefsAutoscrollStayOn:
if ( CtlGetValue( GetObjectPtr(
frmPrefsAutoscrollStayOn ) ) )
FrmAlert( warnStayOn );
handled = true;
break;
default:
break;
}
break;
case ctlRepeatEvent:
switch ( event->data.ctlRepeat.controlID ) {
/* leave unhandled so the buttons can repeat */
case frmPrefsAutoscrollJumpUpButton:
autoscrollJump = HandleSpinner( AUTOSCROLL_UP,
autoscrollJump, AUTOSCROLL_MIN_JUMP_VALUE,
AUTOSCROLL_MAX_JUMP_VALUE,
frmPrefsAutoscrollJumpButton,
AUTOSCROLL_INCR_JUMP_VALUE, 0, 0 );
break;
case frmPrefsAutoscrollJumpDownButton:
autoscrollJump = HandleSpinner( AUTOSCROLL_DOWN,
autoscrollJump, AUTOSCROLL_MIN_JUMP_VALUE,
AUTOSCROLL_MAX_JUMP_VALUE,
frmPrefsAutoscrollJumpButton,
AUTOSCROLL_INCR_JUMP_VALUE, 0, 0 );
break;
case frmPrefsAutoscrollIntervalUpButton:
autoscrollInterval = HandleSpinner( AUTOSCROLL_UP,
autoscrollInterval, AUTOSCROLL_MIN_INTERVAL_VALUE,
AUTOSCROLL_MAX_INTERVAL_VALUE,
frmPrefsAutoscrollIntervalButton,
AUTOSCROLL_INCR_INTERVAL_VALUE,
AUTOSCROLL_FINE_TRANSITION,
AUTOSCROLL_FINE_INCR_INTERVAL_VALUE );
break;
case frmPrefsAutoscrollIntervalDownButton:
autoscrollInterval = HandleSpinner( AUTOSCROLL_DOWN,
autoscrollInterval, AUTOSCROLL_MIN_INTERVAL_VALUE,
AUTOSCROLL_MAX_INTERVAL_VALUE,
frmPrefsAutoscrollIntervalButton,
AUTOSCROLL_INCR_INTERVAL_VALUE,
AUTOSCROLL_FINE_TRANSITION,
AUTOSCROLL_FINE_INCR_INTERVAL_VALUE );
break;
default:
break;
}
break;
case popSelectEvent:
{
Int16 selection;
selection = event->data.popSelect.selection;
if ( selection != noListSelection ) {
ControlType* ctl;
ListType* list;
Char* label;
UInt16 controlID;
list = event->data.popSelect.listP;
controlID = event->data.popSelect.controlID;
ctl = GetObjectPtr( controlID );
label = LstGetSelectionText( list, selection );
CtlSetLabel( ctl, label );
LstSetSelection( list, selection );
switch ( controlID ) {
case frmPrefsAutoscrollModePopup:
autoscrollMode = (AutoscrollModeType) selection;
handled = true;
break;
case frmPrefsAutoscrollDirPopup:
autoscrollDir = (AutoscrollDirType) selection ^ 1;
handled = true;
break;
default:
break;
}
}
break;
}
default:
handled = false;
}
return handled;
}
|