summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2020-11-21 10:09:12 +0100
committerDamiano Galassi <[email protected]>2020-11-21 10:09:12 +0100
commit652c636656fd51b15042244fa1d54ebf0f61d08d (patch)
tree20c9838593c73894a5e6c48a900dda0195acd3a7 /macosx
parente73d9e45d93b3de3509b6e6865a4bdc3e0d6f89e (diff)
MacGui: add maxHeight/maxWidth validation.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/Base.lproj/HBPictureViewController.xib16
-rw-r--r--macosx/HBPicture.m46
2 files changed, 56 insertions, 6 deletions
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 @@
<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17506" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17700" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17506"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17700"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -502,7 +502,11 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
- <binding destination="-2" name="value" keyPath="self.picture.maxWidth" id="BIc-fq-9qJ"/>
+ <binding destination="-2" name="value" keyPath="self.picture.maxWidth" id="VMN-Ha-9Wu">
+ <dictionary key="options">
+ <bool key="NSValidatesImmediately" value="YES"/>
+ </dictionary>
+ </binding>
</connections>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="YES" preferredMaxLayoutWidth="20" translatesAutoresizingMaskIntoConstraints="NO" id="who-FI-Crq">
@@ -525,7 +529,11 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
- <binding destination="-2" name="value" keyPath="self.picture.maxHeight" id="TWm-Sy-xoq"/>
+ <binding destination="-2" name="value" keyPath="self.picture.maxHeight" id="guG-f0-XBM">
+ <dictionary key="options">
+ <bool key="NSValidatesImmediately" value="YES"/>
+ </dictionary>
+ </binding>
</connections>
</textField>
</subviews>
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);