If I use -[NSView dataWithPDFInsideRect:] to create a PDF from an NSTextView, I get a single-page PDF with stuff past the bottom cut off. What do I need to do to get pagination to happen? Would embedding the NSTextView in an NSScrollView help?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have an overloaded function, one version with a BOOL parameter and one with a bool parameter. It gives me a redefinition error when compiling for Apple Silicon but not when compiling for Intel.
I have a view (custom subclass of NSView) that overrides mouseDown: and mouseUp:. If I double-click the view, I expect to see a sequence of events:
mouseDown with clickCount == 1
mouseUp with clickCount == 1
mouseDown with clickCount == 2
mouseUp with clickCount == 2
Usually, that's what happens. But occasionally, the second or both mouse up events don't arrive. That's a problem, because it's my understanding that if you want to handle a double-click, you should be looking for the second mouse up. I am certain that the mouse location is always within the bounds of the view. What could cause this? (Testing on macOS 13.6.4.)
Added: I use a subclass of NSApplication, and override nextEventMatchingMask:untilDate:inMode:dequeue: and sendEvent:. The overrides usually just call through to the superclass method. Logging mouse events from these methods, I see that in the problematic cases, the mouse up events are received from the queue, but never sent.
Recently, when I open a document in my app, it just adds a blank line to the Open Recent submenu. Attempting to select that line produces an error alert saying "The document “(null)” could not be opened. The file doesn’t exist." However, the document does appear in the global Recent Items menu. I tried rebooting. I'm not subclassing NSDocumentController or doing anything weird about opening files. Ideas?
P.S. I tried logging in to a different account, and tried changing the bundle ID. Neither helped.
I have a repeating timer installed like this:
_cmdTimer = [NSTimer timerWithTimeInterval: 0.5
target: self
selector: @selector(timedTask:)
userInfo: nil
repeats: YES];
[NSRunLoop.mainRunLoop addTimer: _cmdTimer
forMode: NSModalPanelRunLoopMode];
[NSRunLoop.mainRunLoop addTimer: _cmdTimer
forMode: NSDefaultRunLoopMode];
The first time the timer fires, it opens a modal dialog. But then the timer does not fire again until the dialog is closed. I don't get that, since I scheduled the timer in NSModalPanelRunLoopMode. To verify that the dialog was running in that mode, just before opening the dialog I said
[self performSelector: @selector(testMe)
withObject: nil
afterDelay: 0.7
inModes: @[NSModalPanelRunLoopMode] ];
and the testMe method did get executed while the dialog was open.
When making a disk image for software distribution, it used to be possible to make a Finder window automatically open when the disk image is mounted, using a command like
sudo bless --folder dirPath --openfolder dirPath
on a read-write disk image.
However, as of Ventura, attempting to do so produces an error message
bless: The 'openfolder' option is deprecated
and the command fails to do what I want.
Disk images that were set up this way in years past continue to work. I suppose I could duplicate a working writable disk image, remove the old contents and put in new contents, but that seems a little hacky. Is there an alternative?
Topic:
Developer Tools & Services
SubTopic:
General
I would like to install the beta of macOS 15 on an empty volume, rather than on top of an existing version of macOS. Is it possible? I see that I can download an .ipsw file, but I don't understand what can be done with it.
I'm trying to do a piecemeal conversion of a big macOS Objective-C++ code base to use Automatic Reference Counting (ARC), and started with a fairly complex modal dialog. I converted all the classes involved to use ARC. When the dialog closes, the window itself, and some of the controller objects, get deallocated as they should, but some do not. When I look at the memory debugging graph in Xcode, I see a bunch of things of the form NSKVONotifying_MyClassName. Here's an example:
It does not look as though any of my objects have strong references to GRMorphController, so what am I to make of this?
I have a Mac app with a background-only helper app that needs to have Accessibility permission in order to use an event tap that can modify events. This has worked OK through Sonoma, but in the Sequoia beta it is failing to create the tap. C code to test the ability to create the event tap:
static CGEventRef _Nullable DummyTap(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *userInfo)
{
return NULL;
}
static bool CanFilterEvents( void )
{
CFMachPortRef thePort = CGEventTapCreate(
kCGSessionEventTap,
kCGTailAppendEventTap,
kCGEventTapOptionDefault, // active filter, not passive listener
CGEventMaskBit(kCGEventKeyDown),
DummyTap,
NULL );
bool madeTap = (thePort != NULL);
if (madeTap)
{
CFMachPortInvalidate( thePort );
CFRelease( thePort );
}
return madeTap;
}
So, on Sequoia, CanFilterEvents returns false in spite of Accessibility permission being granted in System Settings. CGPreflightPostEventAccess also returns false, but AXIsProcessTrusted returns true.
I tried making a non-background-only test app, and when that has Accessibility permission, CanFilterEvents, CGPreflightPostEventAccess, and AXIsProcessTrusted all return true. Suggestions on what to try next?
I'm getting a runtime assertion failure like this:
"<FFRender3DView 0x616000271580> has reached dealloc but still has a super view. Super views strongly reference their children, so this is being over-released, or has been over-released in the past."
Looking at the code, I can't see any strong reference to the view except by its superview, so I can't see how it could be released other than by removal from its superview. My first instinct was to override release and set a breakpoint there, but that's not possible in ARC code.
I'm looking at a case where a handler for NSWindowDidBecomeMain gets the NSWindow* from the notification object and verifies that window.isVisible == YES, window.windowNumber > 0 and window.screen != nil. However, window.windowNumber is missing from the array [NSWindow windowNumbersWithOptions: NSWindowNumberListAllSpaces] and from CGWindowListCopyWindowInfo( kCGWindowListOptionOnScreenOnly, kCGNullWindowID ), how can that be?
The window number is in the array returned by CGWindowListCopyWindowInfo( kCGWindowListOptionAll, kCGNullWindowID ).
I'm seeing this issue in macOS 15, maybe 14, but not 13.
If I create a bitmap image and then try to get ready to draw into it, like so:
NSBitmapImageRep* newRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: nullptr
pixelsWide: 128
pixelsHigh: 128
bitsPerSample: 8
samplesPerPixel: 4
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSDeviceRGBColorSpace
bitmapFormat: NSBitmapFormatAlphaNonpremultiplied |
NSBitmapFormatThirtyTwoBitBigEndian
bytesPerRow: 4 * 128
bitsPerPixel: 32];
[NSGraphicsContext setCurrentContext:
[NSGraphicsContext graphicsContextWithBitmapImageRep: newRep]];
then the log shows this error:
CGBitmapContextCreate: unsupported parameter combination:
RGB
8 bits/component, integer
512 bytes/row
kCGImageAlphaLast
kCGImageByteOrderDefault
kCGImagePixelFormatPacked
Valid parameters for RGB color space model are:
16 bits per pixel, 5 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipLast
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedLast
32 bits per pixel, 10 bits per component, kCGImageAlphaNone|kCGImagePixelFormatRGBCIF10|kCGImageByteOrder16Little
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents|kCGImageByteOrder16Little
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents|kCGImageByteOrder16Little
128 bits per pixel, 32 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents
128 bits per pixel, 32 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents
See Quartz 2D Programming Guide (available online) for more information.
If I don't use NSBitmapFormatAlphaNonpremultiplied as part of the format, I don't get the error message. My question is, why does the constant NSBitmapFormatAlphaNonpremultiplied exist if you can't use it like this?
If you're wondering why I wanted to do this: I want to extract the RGBA pixel data from an image, which might have non-premultiplied alpha. And elsewhere online, I saw advice that if you want to look at the pixels of an image, draw it into a bitmap whose format you know and look at those pixels. And I don't want the process of drawing to premultiply my alpha.
I'm building an open-source framework called OgreNextMain on macOS, and it statically links to an open-source library called FreeImage. When I run the nm -gU command on the binary within the resulting framework, I see lots of the symbols from FreeImage, but a couple that I wanted to use are missing. I thought, maybe they get stripped if they are not called by OgreNextMain, so I looked into stripping options. The "strip style" in the Xcode build settings for OgreNextMain is set to "debugging symbols". I tried setting the "additional strip flags" build setting to have the "-s" option and the path to a file containing the names of the symbols I want, but that didn't have any effect.
When I try to make a unit test target for my macOS app that uses Objective-C, running tests fails, and the debugging log shows a message "Creating more than one Application". If, on the other hand, when I create the unit test target, I select "None" as the target to be tested, and then add all my sources to that target, my tests work. So, I can get my testing done, but I think I must be doing something wrong.
By the way, along with the error message, there is a stack crawl:
0 CoreFoundation 0x00007ff8140410aa __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff813b660b7 objc_exception_throw + 48
2 Foundation 0x00007ff814f19bd8 -[NSCalendarDate initWithCoder:] + 0
3 AppKit 0x00007ff817030062 -[NSApplication init] + 1718
4 XCTestCore 0x000000010774b0df -[XCTestDriver _createTestBundlePrincipalClassInstance] + 82
5 XCTestCore 0x0000000107749338 -[XCTestDriver _runTests] + 111
6 XCTestCore 0x000000010770f194 _XCTestMain + 126
7 libXCTestBundleInject.dylib 0x0000000106e8982d __copy_helper_block_e8_32s + 0
8 CoreFoundation 0x00007ff813fc9a91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
9 CoreFoundation 0x00007ff813fc99ca __CFRunLoopDoBlocks + 398
10 CoreFoundation 0x00007ff813fc883d __CFRunLoopRun + 898
11 CoreFoundation 0x00007ff813fc7e51 CFRunLoopRunSpecific + 560
12 HIToolbox 0x00007ff81da52f3d RunCurrentEventLoopInMode + 292
13 HIToolbox 0x00007ff81da52b84 ReceiveNextEventCommon + 199
14 HIToolbox 0x00007ff81da52aa8 _BlockUntilNextEventMatchingListInModeWithFilter + 64
15 AppKit 0x00007ff8170689d8 _DPSNextEvent + 858
16 AppKit 0x00007ff817067882 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1214
17 AppKit 0x00007ff817059ef7 -[NSApplication run] + 586
18 AppKit 0x00007ff81702e111 NSApplicationMain + 817
19 PlainCalc 0x00000001057d0a91 main + 65
20 dyld 0x00007ff813b93418 start + 1896
I have a document-based macOS app written in Objective-C, and each document window contains a scrollable NSTextView. I know that printing can get complicated if you want to do nice pagination, but is there a quick and dirty way to get basic printing working? As it is, the print panel shows up, but its preview area is totally blank. Here's the current printing part of my NSDocument subclass.
- (NSPrintInfo *)printInfo
{
NSPrintInfo *printInfo = [super printInfo];
[printInfo setHorizontalPagination: NSPrintingPaginationModeFit];
[printInfo setHorizontallyCentered: NO];
[printInfo setVerticallyCentered: NO];
[printInfo setLeftMargin: 72.0];
[printInfo setRightMargin: 72.0];
[printInfo setTopMargin: 72.0];
[printInfo setBottomMargin: 72.0];
return printInfo;
}
- (void)printDocumentWithSettings:(NSDictionary<NSPrintInfoAttributeKey, id> *)printSettings
showPrintPanel:(BOOL)showPrintPanel
delegate:(id)delegate
didPrintSelector:(SEL)didPrintSelector
contextInfo:(void *)contextInfo
{
NSPrintInfo* thePrintInfo = [self printInfo];
[thePrintInfo setVerticallyCentered: NO ];
NSPrintOperation *op = [NSPrintOperation
printOperationWithView: _textView
printInfo: thePrintInfo ];
[op runOperationModalForWindow: _docWindow
delegate: delegate
didRunSelector: didPrintSelector
contextInfo: contextInfo];
}