File: csspinbx.h

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (149 lines) | stat: -rw-r--r-- 3,822 bytes parent folder | download
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
/*
    Crystal Space Windowing System: spin box class
    Copyright (C) 1998,1999 by Andrew Zabolotny <bit@eltech.ru>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __CSSPINBX_H__
#define __CSSPINBX_H__

#include "cscomp.h"
#include "cstimer.h"
#include "csiline.h"
#include "csutil/csstrvec.h"

/// Spin box item structure
struct csSpinBoxItem
{
  /// Item value
  char *Value;
  /// Item position (ordinal of element before which item will be inserted)
  int Position;
};

/// Spin box item placement values
/// Insert item before all other items
#define CSSB_ITEM_BEFOREALL	0
/// Insert item after all other items
#define CSSB_ITEM_AFTERALL	999999

struct csSpinBoxLimits
{
  int MinValue,MaxValue;
  char *ValueFormat;
};

enum
{
  /**
   * Query value of spin box
   * <pre>
   * OUT: (int)Value
   * </pre>
   */
  cscmdSpinBoxQueryValue = 0x00000A00,
  /**
   * Set spin box value
   * <pre>
   * IN: (int)Value
   * </pre>
   */
  cscmdSpinBoxSetValue,
  /**
   * Insert a string into list of spin box's values
   * <pre>
   * IN: (csSpinBoxItem *)Item
   * OUT: (int)Ordinal
   * </pre>
   */
  cscmdSpinBoxInsertItem,
  /**
   * Set spinbox type to numerical and set its limits
   * <pre>
   * IN: (csSpinBoxLimits *)Limits
   * </pre>
   */
  cscmdSpinBoxSetLimits,
  /**
   * Passed to parent control as spinbox value changes
   * <pre>
   * IN: (csSpinBox *)Source
   * </pre>
   */
  cscmdSpinBoxValueChanged
};

/**
 * The spinbox class is a combination of an input line and a bi-directional
 * arrow button which can be used to switch input line contents back and
 * forth between a set of predefined values.
 */
class csSpinBox : public csInputLine
{
  // Current spin box value
  int Value;
  // The list of allowed values; if list is empty, spin box is numerical
  csStrVector Values;
  // Alternative value limits for numerical content
  csSpinBoxLimits NumLimits;
  // Spin box state
  int SpinState;
  // Spin timer
  csTimer *SpinTimer;
  // spin box size in pixels
  int SpinBoxSize;
  // Number of autorepeats since spin beginning
  int AutoRepeats;

public:
  /// Create spin box object
  csSpinBox (csComponent *iParent,
    csInputLineFrameStyle iFrameStyle = csifsThickRect);

  /// Destructor
  virtual ~csSpinBox ();

  /// Draw the spin box
  virtual void Draw ();

  /// Handle external events
  virtual bool HandleEvent (iEvent &Event);

  /// Set spin box type to numerical and set spin limits
  void SetLimits (int iMin, int iMax, char *iFormat = "%d");

  /**
   * Set spin box content.<p>
   * If spin box type is numerical, the iValue parameter is the number
   * that will be set in entry field (after it will be clipped to Min..Max),
   * if spin box type is enumerated, iValue is the ordinal of value to be set.
   */
  void SetValue (int iValue);

  /// Insert a item into spinbox (same as csSpinBoxInsertItem message)
  int InsertItem (char *iValue, int iPosition);

  /// Set spinbox text
  virtual void SetText (const char *iText);

private:
  // Spin to other value
  void Spin (int iDelta);
  // Spin value depending on spin box state
  void Spin ();
};

#endif // __CSSPINBX_H__