Mercurial > dwindows
changeset 2002:a2931caa3422
Fix setting/getting dates in dw_calendar under macos. Only tested on Mojave. Sorry about the white space changes.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 04 Nov 2019 01:15:03 +0000 |
parents | f7acca46f795 |
children | dee122916f3c |
files | dwtest.c mac/dw.m |
diffstat | 2 files changed, 37 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/dwtest.c Thu Oct 31 21:28:32 2019 +0000 +++ b/dwtest.c Mon Nov 04 01:15:03 2019 +0000 @@ -1226,7 +1226,7 @@ for(z=0;z<3;z++) { char names[100]; - + sprintf(names, "We can now allocate from the stack: Item: %d", z); size = z*100; sprintf(buffer, "Filename %d",z+1); @@ -1313,9 +1313,9 @@ dw_box_pack_start(notebookbox5, calbox, 500, 200, TRUE, TRUE, 1); cal = dw_calendar_new(100); dw_box_pack_start(calbox, cal, 180, 120, TRUE, TRUE, 0); - /* - dw_calendar_set_date(cal, 2001, 1, 1); - */ + + dw_calendar_set_date(cal, 2019, 4, 30); + /* * Create our file toolbar boxes... */
--- a/mac/dw.m Thu Oct 31 21:28:32 2019 +0000 +++ b/mac/dw.m Mon Nov 04 01:15:03 2019 +0000 @@ -419,7 +419,7 @@ { #ifdef BUILDING_FOR_MOJAVE NSAppearance *appearance = [object effectiveAppearance]; - + if(@available(macOS 10.14, *)) { NSAppearanceName basicAppearance = [appearance bestMatchFromAppearancesWithNames:@[ @@ -1185,7 +1185,7 @@ if(DWThread == (DWTID)-1 || DWThread == curr) { DWIMP imp = (DWIMP)[self methodForSelector:sel]; - + if(imp) imp(self, sel, param); } @@ -1199,12 +1199,12 @@ DWBitBlt *bltinfo = (DWBitBlt *)[bi pointerValue]; id bltdest = bltinfo->dest; id bltsrc = bltinfo->src; - + #ifdef BUILDING_FOR_MOJAVE if([bltdest isMemberOfClass:[DWRender class]]) { DWRender *render = bltdest; - + bltdest = [render cachedDrawingRep]; } #endif @@ -1231,7 +1231,7 @@ NSImage *image = [NSImage alloc]; SEL siwc = NSSelectorFromString(@"initWithCGImage"); NSCompositingOperation op = DWCompositingOperationSourceOver; - + if([image respondsToSelector:siwc]) { DWIMP iiwc = (DWIMP)[image methodForSelector:siwc]; @@ -1274,7 +1274,7 @@ #ifdef BUILDING_FOR_MOJAVE NSEnumerator *enumerator = [_DWDirtyDrawables objectEnumerator]; DWRender *rend; - + while (rend = [enumerator nextObject]) rend.needsDisplay = YES; [_DWDirtyDrawables removeAllObjects]; @@ -1293,7 +1293,7 @@ NSValue *v = (NSValue *)param; void **params = (void **)[v pointerValue]; void (* windowfunc)(void *); - + if(params) { windowfunc = params[0]; @@ -3246,13 +3246,13 @@ */ #ifndef BUILDING_FOR_MOJAVE NSWindow *window = [render window]; - + if([window preferredBackingLocation] != NSWindowBackingLocationVideoMemory) { [window setPreferredBackingLocation:NSWindowBackingLocationVideoMemory]; } #endif - + /* Eliminate duplicate configure requests */ if(oldsize.width != newsize.width || oldsize.height != newsize.height) { @@ -3894,7 +3894,7 @@ mstyle = DWAlertStyleCritical; else if(flags & DW_MB_INFORMATION) mstyle = DWAlertStyleInformational; - + params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; [DWObj safeCall:@selector(messageBox:) withObject:params]; iResponse = [[params lastObject] integerValue]; @@ -6337,7 +6337,7 @@ return [NSGraphicsContext graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]; #endif } - + /* Draw a point on a window (preferably a render window). * Parameters: * handle: Handle to the window. @@ -6355,7 +6355,7 @@ id image = handle; NSBitmapImageRep *bi = nil; bool bCanDraw = YES; - + if(pixmap) bi = image = (id)pixmap->image; else @@ -6364,7 +6364,7 @@ if([image isMemberOfClass:[DWRender class]]) { DWRender *render = image; - + bi = [render cachedDrawingRep]; } #else @@ -6425,7 +6425,7 @@ if([image isMemberOfClass:[DWRender class]]) { DWRender *render = image; - + bi = [render cachedDrawingRep]; } #else @@ -6480,7 +6480,7 @@ NSFont *font = nil; DWRender *render; bool bCanDraw = YES; - + if(pixmap) { bi = image = (id)pixmap->image; @@ -6619,7 +6619,7 @@ NSBitmapImageRep *bi = nil; bool bCanDraw = YES; int z; - + if(pixmap) bi = image = (id)pixmap->image; else @@ -6628,7 +6628,7 @@ if([image isMemberOfClass:[DWRender class]]) { DWRender *render = image; - + bi = [render cachedDrawingRep]; } #else @@ -6664,7 +6664,7 @@ } [aPath stroke]; } - + if(bi) [NSGraphicsContext restoreGraphicsState]; #ifndef BUILDING_FOR_MOJAVE @@ -6695,7 +6695,7 @@ id image = handle; NSBitmapImageRep *bi = nil; bool bCanDraw = YES; - + if(pixmap) bi = image = (id)pixmap->image; else @@ -6704,7 +6704,7 @@ if([image isMemberOfClass:[DWRender class]]) { DWRender *render = image; - + bi = [render cachedDrawingRep]; } #else @@ -6721,7 +6721,7 @@ [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:gc]; } - + if(bCanDraw == YES) { NSColor *color = pthread_getspecific(_dw_fg_color_key); @@ -6732,7 +6732,7 @@ else [NSBezierPath strokeRect:NSMakeRect(x, y, width, height)]; } - + if(bi) [NSGraphicsContext restoreGraphicsState]; #ifndef BUILDING_FOR_MOJAVE @@ -6766,7 +6766,7 @@ id image = handle; NSBitmapImageRep *bi = nil; bool bCanDraw = YES; - + if(pixmap) bi = image = (id)pixmap->image; else @@ -6775,7 +6775,7 @@ if([image isMemberOfClass:[DWRender class]]) { DWRender *render = image; - + bi = [render cachedDrawingRep]; } #else @@ -6792,7 +6792,7 @@ [NSGraphicsContext saveGraphicsState]; [NSGraphicsContext setCurrentContext:gc]; } - + if(bCanDraw) { NSBezierPath* aPath = [NSBezierPath bezierPath]; @@ -6828,7 +6828,7 @@ /* Actually do the drawing */ [aPath stroke]; } - + if(bi) [NSGraphicsContext restoreGraphicsState]; #ifndef BUILDING_FOR_MOJAVE @@ -8615,7 +8615,7 @@ snprintf(buffer, 100, "%04d-%02d-%02d", year, month, day); NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; - dateFormatter.dateFormat = @"yyyy-mm-dd"; + dateFormatter.dateFormat = @"yyyy-MM-dd"; date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]]; [calendar setDateValue:date]; @@ -8632,20 +8632,13 @@ { DWCalendar *calendar = handle; DW_LOCAL_POOL_IN; + NSCalendar *mycalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDate *date = [calendar dateValue]; - NSDateFormatter *df = [[NSDateFormatter alloc] init]; - [df setDateStyle:NSDateFormatterShortStyle]; - NSString *nstr = [df stringFromDate:date]; - sscanf([ nstr UTF8String ], "%d/%d/%d", month, day, year); - if(*year < 70) - { - *year += 2000; - } - else if(*year < 100) - { - *year += 1900; - } - [df release]; + NSDateComponents* components = [mycalendar components:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear fromDate:date]; + *day = [components day]; + *month = [components month]; + *year = [components year]; + [mycalendar release]; DW_LOCAL_POOL_OUT; }