Transfer more fixes from branch 1.4 to branch 1.3

This commit is contained in:
ManoloFLTK
2020-05-27 17:38:11 +02:00
parent 8ae0ac92ad
commit 5972eeb750
4 changed files with 73 additions and 19 deletions
+43 -7
View File
@@ -473,9 +473,10 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
char *q = p+1;
while (*q != ' ' && *q != ')' && *q != 0) q++;
*q = 0;
NSString *ns = [NSString stringWithFormat:@"%@.%@",
[[dialog performSelector:@selector(nameFieldStringValue)] stringByDeletingPathExtension],
[NSString stringWithUTF8String:p]];
NSString *ns = [NSString stringWithFormat:@"%@.%@",
[[dialog performSelector:@selector(nameFieldStringValue)] stringByDeletingPathExtension],
[NSString stringWithUTF8String:p]];
if (fl_mac_os_version >= 100900) [dialog setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]];
free(s);
[dialog performSelector:@selector(setNameFieldStringValue:) withObject:ns];
}
@@ -541,12 +542,37 @@ int Fl_Native_File_Chooser::runmodal()
fname = [preset lastPathComponent];
}
if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
if (fl_mac_os_version >= 100600) {
if (dir) [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]];
if (fname) [(NSSavePanel*)_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname];
retval = [(NSSavePanel*)_panel runModal];
bool usepath = false;
NSString *path = nil;
if (dir && fname && [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]]) {
// STR #3406: If both dir + fname specified, combine and pass to setDirectoryURL
path = [[NSString alloc] initWithFormat:@"%@/%@", dir, fname]; // dir+fname -> path
// See if full path to file exists
// If dir exists but fname doesn't, avoid using setDirectoryURL,
// otherwise NSSavePanel falls back to showing user's Documents dir.
//
if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) usepath = true;
}
if (usepath) {
// Set only if full path exists
[(NSSavePanel*)_panel setDirectoryURL:[NSURL fileURLWithPath:path]];
} else { // didn't setDirectoryURL to full path? Set dir + fname separately..
if (dir) [(NSSavePanel*)_panel setDirectoryURL:[NSURL fileURLWithPath:dir]];
if (fname) [(NSSavePanel*)_panel setNameFieldStringValue:fname];
}
[path release];
__block NSInteger complete = -1;
[(NSSavePanel*)_panel beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSInteger returnCode) {
complete = returnCode; // this block runs after OK or Cancel was triggered in file dialog
}]; // this message returns immediately and begins the file dialog as a sheet
while (complete < 0) Fl::wait(100); // loop until end of file dialog
retval = complete;
}
else {
else
#endif
{
retval = [(id)_panel runModalForDirectory:dir file:fname];
}
[dir release];
@@ -635,8 +661,18 @@ int Fl_Native_File_Chooser::post() {
[popup setAction:@selector(changedPopup:)];
[popup setTarget:saveDelegate];
[saveDelegate panel:(NSSavePanel*)_panel];
if (fl_mac_os_version >= 100900) {
char *p = _filt_patt[_filt_value];
char *q = strchr(p, '.'); if(!q) q = p-1;
do q++; while (*q==' ' || *q=='{');
p = strdup(q);
q = strchr(p, ','); if (q) *q = 0;
[(NSSavePanel*)_panel setAllowedFileTypes:[NSArray arrayWithObject:[NSString stringWithUTF8String:p]]];
free(p);
}
}
[(NSSavePanel*)_panel setCanSelectHiddenExtension:YES];
[(NSSavePanel*)_panel setExtensionHidden:NO];
}
}
int retval = runmodal();
+1 -1
View File
@@ -91,7 +91,7 @@ int Fl_PostScript_File_Device::start_job (int pagecount, enum Fl_Paged_Device::P
Fl_Native_File_Chooser fnfc;
fnfc.title(Fl_PostScript_File_Device::file_chooser_title);
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM);
fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
fnfc.filter("PostScript\t*.ps\n");
// Show native chooser
if ( fnfc.show() ) return 1;
+26 -8
View File
@@ -54,6 +54,16 @@ Fl_System_Printer::~Fl_System_Printer(void) {
delete driver();
}
@interface print_panel_delegate : NSObject
- (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(NSInteger)returnCode contextInfo:(NSInteger *)contextInfo;
@end
@implementation print_panel_delegate
- (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(NSInteger)returnCode contextInfo:(NSInteger *)contextInfo
{
*contextInfo = returnCode;
}
@end
int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage)
//printing using a Quartz graphics context
//returns 0 iff OK
@@ -67,19 +77,27 @@ int Fl_System_Printer::start_job (int pagecount, int *frompage, int *topage)
NSPrintPanel *panel = [NSPrintPanel printPanel];
//from 10.5
[panel setOptions:NSPrintPanelShowsCopies | NSPrintPanelShowsPageRange | NSPrintPanelShowsPageSetupAccessory];
NSInteger retval = [panel runModalWithPrintInfo:info];//from 10.5
if(retval != NSOKButton) {
Fl_Window *w = Fl::first_window();
if (w) w->show();
return 1;
}
NSInteger retval = -1;
Fl_Window *top = Fl::first_window();
NSWindow *main = (top ? (NSWindow*)fl_xid(top->top_window()) : nil);
if (main) {
[panel beginSheetWithPrintInfo:info
modalForWindow:main
delegate:[[[print_panel_delegate alloc] init] autorelease]
didEndSelector:@selector(printPanelDidEnd:returnCode:contextInfo:)
contextInfo:&retval];
while (retval < 0) Fl::wait(100);
[main makeKeyAndOrderFront:nil];
} else
retval = [panel runModalWithPrintInfo:info]; //from 10.5
if (retval != NSOKButton) return 1;
printSession = (PMPrintSession)[info PMPrintSession];//from 10.5
pageFormat = (PMPageFormat)[info PMPageFormat];//from 10.5
printSettings = (PMPrintSettings)[info PMPrintSettings];//from 10.5
UInt32 from32, to32;
PMGetFirstPage(printSettings, &from32);
PMGetFirstPage(printSettings, &from32);
if (frompage) *frompage = (int)from32;
PMGetLastPage(printSettings, &to32);
PMGetLastPage(printSettings, &to32);
if (topage) {
*topage = (int)to32;
if (*topage > pagecount && pagecount > 0) *topage = pagecount;
+3 -3
View File
@@ -4735,12 +4735,12 @@ void Fl_X::draw_layer_to_context(void *layer, CGContextRef gc, int w, int h)
void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
{
if (!win->shown() || win->parent() || !win->border() || !win->visible()) {
int bx, by, bt, bpp;
bt = get_window_frame_sizes(win, &bx, &by);
if (!win->shown() || win->parent() || !win->border() || !win->visible() || !bt) {
this->print_widget(win, x_offset, y_offset);
return;
}
int bx, by, bt, bpp;
bt = get_window_frame_sizes(win, &bx, &by);
BOOL to_quartz = (this->driver()->class_name() == Fl_Quartz_Graphics_Driver::class_id);
void *layer = Fl_X::get_titlebar_layer(win);
if (layer) { // if title bar uses a layer