summaryrefslogtreecommitdiff
path: root/redo/basicctrls_darwin.m
diff options
context:
space:
mode:
Diffstat (limited to 'redo/basicctrls_darwin.m')
-rw-r--r--redo/basicctrls_darwin.m49
1 files changed, 49 insertions, 0 deletions
diff --git a/redo/basicctrls_darwin.m b/redo/basicctrls_darwin.m
index 8e16eb1..6f2769c 100644
--- a/redo/basicctrls_darwin.m
+++ b/redo/basicctrls_darwin.m
@@ -7,6 +7,7 @@
#define toNSButton(x) ((NSButton *) (x))
#define toNSTextField(x) ((NSTextField *) (x))
#define toNSView(x) ((NSView *) (x))
+#define toNSPopover(x) ((NSPopover *) (x))
#define toNSBox(x) ((NSBox *) (x))
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
@@ -162,6 +163,54 @@ void textFieldSetText(id t, char *text)
[toNSTextField(t) setStringValue:[NSString stringWithUTF8String:text]];
}
+id textfieldOpenInvalidPopover(id textfield, char *reason)
+{
+ // step 1: set up the display
+ NSTextField *label;
+ NSTextAttachmentCell *cell;
+ NSTextAttachment *attachment;
+ NSAttributedString *strImage;
+ NSAttributedString *strText;
+ NSFont *font;
+ NSMutableAttributedString *str;
+
+ // method thanks to Anne in http://stackoverflow.com/a/5303517/3408572
+ // TODO improve appearance
+ label = toNSTextField(newLabel());
+ cell = [[NSTextAttachmentCell alloc] initImageCell:[NSImage imageNamed:NSImageNameCaution]];
+ attachment = [NSTextAttachment new];
+ [attachment setAttachmentCell:cell];
+ strImage = [NSAttributedString attributedStringWithAttachment:attachment];
+ font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
+ strText = [[NSAttributedString alloc] initWithString:[NSString stringWithUTF8String:reason] attributes:[[font fontDescriptor] fontAttributes]];
+ str = [[NSMutableAttributedString alloc] initWithAttributedString:strImage];
+ [str appendAttributedString:strText];
+ [label setAttributedStringValue:str];
+
+ // step 2: set up the popover
+ NSPopover *popover;
+ NSViewController *vc;
+
+ vc = [NSViewController new];
+ [vc setView:label];
+ popover = [NSPopover new];
+ [popover setContentViewController:vc];
+ [label sizeToFit];
+ [popover setContentSize:[label frame].size];
+
+ // step 3: show the popover
+ // NSMaxYEdge is the bottom edge when looking (maximum edge in window coordinates)
+ [popover showRelativeToRect:NSZeroRect ofView:toNSView(textfield) preferredEdge:NSMaxYEdge];
+
+ return (id) popover;
+}
+
+void textfieldCloseInvalidPopover(id popover)
+{
+ [toNSPopover(popover) close];
+ [toNSPopover(popover) release];
+}
+
id newLabel(void)
{
NSTextField *l;