From 652c636656fd51b15042244fa1d54ebf0f61d08d Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 21 Nov 2020 10:09:12 +0100 Subject: MacGui: add maxHeight/maxWidth validation. --- macosx/Base.lproj/HBPictureViewController.xib | 16 +++++++--- macosx/HBPicture.m | 46 +++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) (limited to 'macosx') diff --git a/macosx/Base.lproj/HBPictureViewController.xib b/macosx/Base.lproj/HBPictureViewController.xib index e4aa474a0..ae357a403 100644 --- a/macosx/Base.lproj/HBPictureViewController.xib +++ b/macosx/Base.lproj/HBPictureViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -502,7 +502,11 @@ - + + + + + @@ -525,7 +529,11 @@ - + + + + + diff --git a/macosx/HBPicture.m b/macosx/HBPicture.m index ff0ef8f20..ac381c2a6 100644 --- a/macosx/HBPicture.m +++ b/macosx/HBPicture.m @@ -197,6 +197,27 @@ NSString * const HBPictureChangedNotification = @"HBPictureChangedNotification"; } } +- (BOOL)validateMaxWidth:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + int value = [*ioValue intValue]; + + if (value >= HB_MAX_WIDTH) + { + *ioValue = @(HB_MAX_WIDTH); + } + else if (value <= HB_MIN_WIDTH) + { + *ioValue = @(HB_MIN_WIDTH); + } + } + + return retval; +} + - (void)setMaxHeight:(int)maxHeight { if (maxHeight != _maxHeight) @@ -211,6 +232,27 @@ NSString * const HBPictureChangedNotification = @"HBPictureChangedNotification"; } } +- (BOOL)validateMaxHeight:(id *)ioValue error:(NSError * __autoreleasing *)outError +{ + BOOL retval = YES; + + if (nil != *ioValue) + { + int value = [*ioValue intValue]; + + if (value >= HB_MAX_HEIGHT) + { + *ioValue = @(HB_MAX_HEIGHT); + } + else if (value <= HB_MIN_HEIGHT) + { + *ioValue = @(HB_MIN_HEIGHT); + } + } + + return retval; +} + - (void)setAllowUpscaling:(BOOL)allowUpscaling { if (allowUpscaling != _allowUpscaling) @@ -1017,8 +1059,8 @@ fail: { preset[@"PictureRotate"] = [NSString stringWithFormat:@"angle=%d:hflip=%d", self.rotate, self.flip]; - preset[@"PictureWidth"] = @(self.maxWidth); - preset[@"PictureHeight"] = @(self.maxHeight); + preset[@"PictureWidth"] = @(self.maxWidth == HB_MAX_WIDTH ? 0 : self.maxWidth); + preset[@"PictureHeight"] = @(self.maxHeight == HB_MAX_HEIGHT ? 0 : self.maxHeight); preset[@"PictureAllowUpscaling"] = @(self.allowUpscaling); preset[@"PictureUseMaximumSize"] = @(self.useMaximumSize); -- cgit v1.2.3