Implemented the uiSlider and uiProgressBar functions and events. More TODOs. Some build warnings fixed.

This commit is contained in:
Pietro Gagliardi 2015-08-17 15:16:54 -04:00
parent 478f5d2504
commit 6544e76d5f
3 changed files with 68 additions and 8 deletions

View File

@ -23,7 +23,7 @@ void initAlloc(void)
void uninitAlloc(void)
{
if ([allocations count] == 0) {
NSInteger i;
NSUInteger i;
for (i = 0; i < [delegates count]; i++)
[[delegates objectAtIndex:i] release];

View File

@ -1,6 +1,10 @@
// 14 august 2015
#import "uipriv_darwin.h"
// TODOs:
// - 10.8: left/right side of progress bar clipped
// - 10.8: increasing value animates just like with Aero
struct uiProgressBar {
uiDarwinControl c;
NSProgressIndicator *pi;
@ -16,7 +20,7 @@ void uiProgressBarSetValue(uiProgressBar *p, int value)
{
if (value < 0 || value > 100)
complain("value %d out of range in progressbarSetValue()", value);
// TODO
[p->pi setDoubleValue:((double) value)];
}
uiProgressBar *uiNewProgressBar(void)

View File

@ -1,8 +1,6 @@
// 14 august 2015
#import "uipriv_darwin.h"
// TODO events
struct uiSlider {
uiDarwinControl c;
NSSlider *slider;
@ -10,20 +8,73 @@ struct uiSlider {
void *onChangedData;
};
uiDarwinDefineControl(
@interface sliderDelegateClass : NSObject {
NSMapTable *sliders;
}
- (IBAction)onChanged:(id)sender;
- (void)registerSlider:(uiSlider *)b;
- (void)unregisterSlider:(uiSlider *)b;
@end
@implementation sliderDelegateClass
- (id)init
{
self = [super init];
if (self)
self->sliders = newMap();
return self;
}
- (void)dealloc
{
if ([self->sliders count] != 0)
complain("attempt to destroy shared slider delegate but sliders are still registered to it");
[self->sliders release];
[super dealloc];
}
- (IBAction)onChanged:(id)sender
{
uiSlider *s;
s = (uiSlider *) mapGet(self->sliders, sender);
(*(s->onChanged))(s, s->onChangedData);
}
- (void)registerSlider:(uiSlider *)s
{
mapSet(self->sliders, s->slider, s);
[s->slider setTarget:self];
[s->slider setAction:@selector(onChanged:)];
}
- (void)unregisterSlider:(uiSlider *)s
{
[s->slider setTarget:nil];
[self->sliders removeObjectForKey:s->slider];
}
@end
static sliderDelegateClass *sliderDelegate = nil;
uiDarwinDefineControlWithOnDestroy(
uiSlider, // type name
uiSliderType, // type function
slider // handle
slider, // handle
[sliderDelegate unregisterSlider:this]; // on destroy
)
intmax_t uiSliderValue(uiSlider *s)
{
return PUT_CODE_HERE;
// NSInteger is the most similar to intmax_t
return [s->slider integerValue];
}
void uiSliderSetValue(uiSlider *s, intmax_t value)
{
// TODO
[s->slider setIntegerValue:value];
}
void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data)
@ -55,6 +106,11 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max)
cell = (NSSliderCell *) [s->slider cell];
[cell setSliderType:NSLinearSlider];
if (sliderDelegate == nil) {
sliderDelegate = [sliderDelegateClass new];
[delegates addObject:sliderDelegate];
}
[sliderDelegate registerSlider:s];
uiSliderOnChanged(s, defaultOnChanged, NULL);
uiDarwinFinishNewControl(s, uiSlider);