summaryrefslogtreecommitdiff
path: root/libs/gtkmm2/gtk/gtkmm/spinbutton.h
blob: d6790544256cd81e23b10ef3c4f94c7d46550ea7 (plain)
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
// -*- c++ -*-
// Generated by gtkmmproc -- DO NOT MODIFY!
#ifndef _GTKMM_SPINBUTTON_H
#define _GTKMM_SPINBUTTON_H

#include <glibmm.h>

/* $Id$ */

/* Copyright (C) 1998-2002 The gtkmm Development Team
 *
 * 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.
 */

#include <gtkmm/entry.h>
#include <gtkmm/editable.h>


#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GtkSpinButton GtkSpinButton;
typedef struct _GtkSpinButtonClass GtkSpinButtonClass;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */


namespace Gtk
{ class SpinButton_Class; } // namespace Gtk
namespace Gtk
{


/** @addtogroup gtkmmEnums Enums and Flags */

/**
 * @ingroup gtkmmEnums
 */
enum SpinButtonUpdatePolicy
{
  UPDATE_ALWAYS,
  UPDATE_IF_VALID
};

} // namespace Gtk


#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Glib
{

template <>
class Value<Gtk::SpinButtonUpdatePolicy> : public Glib::Value_Enum<Gtk::SpinButtonUpdatePolicy>
{
public:
  static GType value_type() G_GNUC_CONST;
};

} // namespace Glib
#endif /* DOXYGEN_SHOULD_SKIP_THIS */


namespace Gtk
{

/**
 * @ingroup gtkmmEnums
 */
enum SpinType
{
  SPIN_STEP_FORWARD,
  SPIN_STEP_BACKWARD,
  SPIN_PAGE_FORWARD,
  SPIN_PAGE_BACKWARD,
  SPIN_HOME,
  SPIN_END,
  SPIN_USER_DEFINED
};

} // namespace Gtk


#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Glib
{

template <>
class Value<Gtk::SpinType> : public Glib::Value_Enum<Gtk::SpinType>
{
public:
  static GType value_type() G_GNUC_CONST;
};

} // namespace Glib
#endif /* DOXYGEN_SHOULD_SKIP_THIS */


namespace Gtk
{


/** @ingroup gtkmmEnums */
enum { INPUT_ERROR = -1 };

class Adjustment;

/** numeric Entry with up/down buttons
 * Slightly misnamed, this should be called a SpinEntry.
 *
 * @ingroup Widgets
 */

class SpinButton : public Entry
{
  public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
  typedef SpinButton CppObjectType;
  typedef SpinButton_Class CppClassType;
  typedef GtkSpinButton BaseObjectType;
  typedef GtkSpinButtonClass BaseClassType;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

  virtual ~SpinButton();

#ifndef DOXYGEN_SHOULD_SKIP_THIS

private:
  friend class SpinButton_Class;
  static CppClassType spinbutton_class_;

  // noncopyable
  SpinButton(const SpinButton&);
  SpinButton& operator=(const SpinButton&);

protected:
  explicit SpinButton(const Glib::ConstructParams& construct_params);
  explicit SpinButton(GtkSpinButton* castitem);

#endif /* DOXYGEN_SHOULD_SKIP_THIS */

public:
#ifndef DOXYGEN_SHOULD_SKIP_THIS
  static GType get_type()      G_GNUC_CONST;
  static GType get_base_type() G_GNUC_CONST;
#endif

  ///Provides access to the underlying C GtkObject.
  GtkSpinButton*       gobj()       { return reinterpret_cast<GtkSpinButton*>(gobject_); }

  ///Provides access to the underlying C GtkObject.
  const GtkSpinButton* gobj() const { return reinterpret_cast<GtkSpinButton*>(gobject_); }


public:
  //C++ methods used to invoke GTK+ virtual functions:

protected:
  //GTK+ Virtual Functions (override these to change behaviour):

  //Default Signal Handlers::
  virtual int on_input(double* new_value);
  virtual bool on_output();
  virtual void on_value_changed();


private:

  
public:

  //: create instance
  // adjustment: see Gtk::Adjustment
  // climb_rate:
  // digits: number of decimal digits (has to be < 6)
  SpinButton(double climb_rate = 0.0, guint digits = 0);
  explicit SpinButton(Adjustment& adjustment, double climb_rate = 0.0, guint digits = 0);


  void configure(Adjustment& adjustment, double climb_rate, guint digits);

  
  /** Replaces the Gtk::Adjustment associated with @a spin_button .
   * @param adjustment A Gtk::Adjustment to replace the existing adjustment.
   */
  void set_adjustment(Adjustment& adjustment);
  void unset_adjustment();
  
  /** Get the adjustment associated with a Gtk::SpinButton
   * @return The Gtk::Adjustment of @a spin_button .
   */
  Gtk::Adjustment* get_adjustment();
  
  /** Get the adjustment associated with a Gtk::SpinButton
   * @return The Gtk::Adjustment of @a spin_button .
   */
  const Gtk::Adjustment* get_adjustment() const;

  
  /** Set the precision to be displayed by @a spin_button . Up to 20 digit precision
   * is allowed.
   * @param digits The number of digits after the decimal point to be displayed for the spin button's value.
   */
  void set_digits(guint digits);
  
  /** Fetches the precision of @a spin_button . See set_digits().
   * @return The current precision.
   */
  guint get_digits() const;

  
  /** Sets the step and page increments for spin_button.  This affects how 
   * quickly the value changes when the spin button's arrows are activated.
   * @param step Increment applied for a button 1 press.
   * @param page Increment applied for a button 2 press.
   */
  void set_increments(double step, double page);
  
  /** Gets the current step and page the increments used by @a spin_button . See
   * set_increments().
   * @param step Location to store step increment, or <tt>0</tt>.
   * @param page Location to store page increment, or <tt>0</tt>.
   */
  void get_increments(double& step, double& page) const;

  
  /** Sets the minimum and maximum allowable values for @a spin_button 
   * @param min Minimum allowable value.
   * @param max Maximum allowable value.
   */
  void set_range(double min, double max);
  
  /** Gets the range allowed for @a spin_button . See
   * set_range().
   * @param min Location to store minimum allowed value, or <tt>0</tt>.
   * @param max Location to store maximum allowed value, or <tt>0</tt>.
   */
  void get_range(double& min, double& max) const;

  
  /** Get the value in the @a spin_button .
   * @return The value of @a spin_button .
   */
  double get_value() const;
  
  /** Get the value @a spin_button  represented as an integer.
   * @return The value of @a spin_button .
   */
  int get_value_as_int() const;
  
  /** Set the value of @a spin_button .
   * @param value The new value.
   */
  void set_value(double value);

  
  /** Sets the update behavior of a spin button. This determines whether the
   * spin button is always updated or only when a valid value is set.
   * @param policy A Gtk::SpinButtonUpdatePolicy value.
   */
  void set_update_policy(SpinButtonUpdatePolicy policy);
  
  /** Gets the update behavior of a spin button. See
   * set_update_policy().
   * @return The current update policy.
   */
  SpinButtonUpdatePolicy get_update_policy() const;

  
  /** Sets the flag that determines if non-numeric text can be typed into
   * the spin button.
   * @param numeric Flag indicating if only numeric entry is allowed.
   */
  void set_numeric(bool numeric = true);
  
  /** Returns whether non-numeric text can be typed into the spin button.
   * See set_numeric().
   * @return <tt>true</tt> if only numeric text can be entered.
   */
  bool get_numeric() const;

  
  /** Increment or decrement a spin button's value in a specified direction
   * by a specified amount.
   * @param direction A Gtk::SpinType indicating the direction to spin.
   * @param increment Step increment to apply in the specified direction.
   */
  void spin(SpinType direction, double increment);

  
  /** Sets the flag that determines if a spin button value wraps around to the
   * opposite limit when the upper or lower limit of the range is exceeded.
   * @param wrap A flag indicating if wrapping behavior is performed.
   */
  void set_wrap(bool wrap = true);
  
  /** Returns whether the spin button's value wraps around to the
   * opposite limit when the upper or lower limit of the range is
   * exceeded. See set_wrap().
   * @return <tt>true</tt> if the spin button wraps around.
   */
  bool get_wrap() const;

  
  /** Sets the policy as to whether values are corrected to the nearest step 
   * increment when a spin button is activated after providing an invalid value.
   * @param snap_to_ticks A flag indicating if invalid values should be corrected.
   */
  void set_snap_to_ticks(bool snap_to_ticks = true);
  
  /** Returns whether the values are corrected to the nearest step. See
   * set_snap_to_ticks().
   * @return <tt>true</tt> if values are snapped to the nearest step.
   */
  bool get_snap_to_ticks() const;

  
  /** Manually force an update of the spin button.
   */
  void update();

  /** Convert the Entry text to a number.
   * The computed number should be written to <tt>*new_value</tt>.
   * @return
   * @li <tt>false</tt>: No conversion done, continue with default handler.
   * @li <tt>true</tt>: Conversion successful, don't call default handler.
   * @li <tt>Gtk::INPUT_ERROR</tt>: Conversion failed, don't call default handler.
   */
  

  Glib::SignalProxy1< int,double* > signal_input();


  /** Convert the Adjustment position to text.
   * The computed text should be written via Gtk::Entry::set_text().
   * @return
   * @li <tt>false</tt>: No conversion done, continue with default handler.
   * @li <tt>true</tt>: Conversion successful, don't call default handler.
   */
  

  Glib::SignalProxy0< bool > signal_output();


  Glib::SignalProxy0< void > signal_value_changed();


  //Keybinding signals:
  

  /** The adjustment that holds the value of the spinbutton.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<Gtk::Adjustment*> property_adjustment() ;

/** The adjustment that holds the value of the spinbutton.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<Gtk::Adjustment*> property_adjustment() const;

  /** The acceleration rate when you hold down a button.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<double> property_climb_rate() ;

/** The acceleration rate when you hold down a button.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<double> property_climb_rate() const;

  /** The number of decimal places to display.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<guint> property_digits() ;

/** The number of decimal places to display.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<guint> property_digits() const;

  /** Whether erroneous values are automatically changed to a spin button's nearest step increment.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<bool> property_snap_to_ticks() ;

/** Whether erroneous values are automatically changed to a spin button's nearest step increment.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<bool> property_snap_to_ticks() const;

  /** Whether non-numeric characters should be ignored.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<bool> property_numeric() ;

/** Whether non-numeric characters should be ignored.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<bool> property_numeric() const;

  /** Whether a spin button should wrap upon reaching its limits.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<bool> property_wrap() ;

/** Whether a spin button should wrap upon reaching its limits.
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<bool> property_wrap() const;

  /** Whether the spin button should update always
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<SpinButtonUpdatePolicy> property_update_policy() ;

/** Whether the spin button should update always
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<SpinButtonUpdatePolicy> property_update_policy() const;

  /** Reads the current value
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy<double> property_value() ;

/** Reads the current value
   *
   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
   * the value of the property changes.
   */
  Glib::PropertyProxy_ReadOnly<double> property_value() const;


};

} // namespace Gtk


namespace Glib
{
  /** @relates Gtk::SpinButton
   * @param object The C instance
   * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
   * @result A C++ instance that wraps this C instance.
   */
  Gtk::SpinButton* wrap(GtkSpinButton* object, bool take_copy = false);
}
#endif /* _GTKMM_SPINBUTTON_H */