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
|
/** \file
* \brief ProgressBar control
*
* See Copyright Notice in "iup.h"
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "iup.h"
#include "iupcbs.h"
#include "iup_object.h"
#include "iup_attrib.h"
#include "iup_str.h"
#include "iup_drv.h"
#include "iup_drvfont.h"
#include "iup_stdcontrols.h"
#include "iup_layout.h"
#include "iup_progressbar.h"
void iProgressBarCropValue(Ihandle* ih)
{
if(ih->data->value > ih->data->vmax)
ih->data->value = ih->data->vmax;
else if(ih->data->value < ih->data->vmin)
ih->data->value = ih->data->vmin;
}
char* iProgressBarGetValueAttrib(Ihandle* ih)
{
char* value = iupStrGetMemory(30);
sprintf(value, "%g", ih->data->value);
return value;
}
char* iProgressBarGetDashedAttrib(Ihandle* ih)
{
if(ih->data->dashed)
return "YES";
else
return "NO";
}
static int iProgressBarSetMinAttrib(Ihandle* ih, const char* value)
{
ih->data->vmin = atof(value);
iProgressBarCropValue(ih);
return 1;
}
static int iProgressBarSetMaxAttrib(Ihandle* ih, const char* value)
{
ih->data->vmax = atof(value);
iProgressBarCropValue(ih);
return 1;
}
static int iProgressBarCreateMethod(Ihandle* ih, void **params)
{
(void)params;
ih->data = iupALLOCCTRLDATA();
/* default values */
ih->data->vmax = 1;
ih->data->dashed = 0;
/* progress bar natural size is 200x30 */
IupSetAttribute(ih, "RASTERSIZE", "200x30");
return IUP_NOERROR;
}
Iclass* iupProgressBarGetClass(void)
{
Iclass* ic = iupClassNew(NULL);
ic->name = "progressbar";
ic->format = NULL; /* no parameters */
ic->nativetype = IUP_TYPECONTROL;
ic->childtype = IUP_CHILDNONE;
ic->is_interactive = 0;
/* Class functions */
ic->Create = iProgressBarCreateMethod;
ic->LayoutUpdate = iupdrvBaseLayoutUpdateMethod;
ic->UnMap = iupdrvBaseUnMapMethod;
/* Common Callbacks */
iupClassRegisterCallback(ic, "MAP_CB", "");
iupClassRegisterCallback(ic, "UNMAP_CB", "");
/* Common */
iupBaseRegisterCommonAttrib(ic);
/* Visual */
iupBaseRegisterVisualAttrib(ic);
/* IupProgressBar only */
iupClassRegisterAttribute(ic, "MIN", NULL, iProgressBarSetMinAttrib, IUPAF_SAMEASSYSTEM, "0", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT);
iupClassRegisterAttribute(ic, "MAX", NULL, iProgressBarSetMaxAttrib, IUPAF_SAMEASSYSTEM, "1", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT);
iupClassRegisterAttribute(ic, "ORIENTATION", NULL, NULL, IUPAF_SAMEASSYSTEM, "HORIZONTAL", IUPAF_NOT_MAPPED);
iupdrvProgressBarInitClass(ic);
return ic;
}
Ihandle *IupProgressBar(void)
{
return IupCreate("progressbar");
}
|