diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:56:41 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:59:33 -0800 |
commit | d577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch) | |
tree | 590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/iup_progressbar.c |
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/iup_progressbar.c')
-rwxr-xr-x | iup/src/iup_progressbar.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/iup/src/iup_progressbar.c b/iup/src/iup_progressbar.c new file mode 100755 index 0000000..76fdefc --- /dev/null +++ b/iup/src/iup_progressbar.c @@ -0,0 +1,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"); +} |