Changeset 601 for trunk/Cocoa/Pester/Source/OACalendarView.m
- Timestamp:
- 12/21/09 22:12:29 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/OACalendarView.m
r600 r601 57 57 @implementation OACalendarView 58 58 59 const float OACalendarViewButtonWidth = 15.0 ;60 const float OACalendarViewButtonHeight = 15.0 ;61 const float OACalendarViewSpaceBetweenMonthYearAndGrid = 6.0 ;59 const float OACalendarViewButtonWidth = 15.0f; 60 const float OACalendarViewButtonHeight = 15.0f; 61 const float OACalendarViewSpaceBetweenMonthYearAndGrid = 6.0f; 62 62 const int OACalendarViewNumDaysPerWeek = 7; 63 63 const int OACalendarViewMaxNumWeeksIntersectedByMonth = 6; … … 106 106 dayOfMonthCell = [[NSTextFieldCell alloc] init]; 107 107 [dayOfMonthCell setAlignment:NSCenterTextAlignment]; 108 [dayOfMonthCell setFont:[NSFont controlContentFontOfSize:11.0 ]];108 [dayOfMonthCell setFont:[NSFont controlContentFontOfSize:11.0f]]; 109 109 110 110 buttons = [[NSMutableArray alloc] initWithCapacity:2]; 111 111 112 monthAndYearView = [[NSView alloc] initWithFrame:NSMakeRect(0.0 , 0.0, frameRect.size.width, OACalendarViewButtonHeight + 2)];112 monthAndYearView = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, frameRect.size.width, OACalendarViewButtonHeight + 2)]; 113 113 [monthAndYearView setAutoresizingMask:NSViewWidthSizable]; 114 114 115 115 // Add left/right buttons 116 116 117 buttonFrame = NSMakeRect(0.0 , 0.0, OACalendarViewButtonWidth, OACalendarViewButtonHeight);117 buttonFrame = NSMakeRect(0.0f, 0.0f, OACalendarViewButtonWidth, OACalendarViewButtonHeight); 118 118 button = [self _createButtonWithFrame:buttonFrame]; 119 119 [button setImage:[NSImage imageNamed:@"OALeftArrow" inBundle:thisBundle]]; … … 123 123 [monthAndYearView addSubview:button]; 124 124 125 buttonFrame = NSMakeRect(frameRect.size.width - OACalendarViewButtonWidth, 0.0 , OACalendarViewButtonWidth, OACalendarViewButtonHeight);125 buttonFrame = NSMakeRect(frameRect.size.width - OACalendarViewButtonWidth, 0.0f, OACalendarViewButtonWidth, OACalendarViewButtonHeight); 126 126 button = [self _createButtonWithFrame:buttonFrame]; 127 127 [button setImage:[NSImage imageNamed:@"OARightArrow" inBundle:thisBundle]]; … … 197 197 minimumSize.height = monthAndYearRect.size.height + gridHeaderRect.size.height + ((OACalendarViewMaxNumWeeksIntersectedByMonth * [self _minimumRowHeight])); 198 198 // This should really check the lengths of the months, and include space for the buttons. 199 minimumSize.width = ([self _minimumColumnWidth] * OACalendarViewNumDaysPerWeek) + 1.0 ;199 minimumSize.width = ([self _minimumColumnWidth] * OACalendarViewNumDaysPerWeek) + 1.0f; 200 200 201 201 [self setFrameSize:minimumSize]; … … 608 608 609 609 // get the grid cell width (subtract 1.0 from the bounds width to allow for the border) 610 columnWidth = floor ((viewBounds.size.width - 1.0) / OACalendarViewNumDaysPerWeek);611 viewBounds.size.width = (columnWidth * OACalendarViewNumDaysPerWeek) + 1.0 ;610 columnWidth = floorf((viewBounds.size.width - 1.0f) / OACalendarViewNumDaysPerWeek); 611 viewBounds.size.width = (columnWidth * OACalendarViewNumDaysPerWeek) + 1.0f; 612 612 613 613 // resize the month & year view to be the same width as the grid … … 616 616 // get the rect for the month and year text field cell 617 617 cellSize = [monthAndYearTextFieldCell cellSize]; 618 NSDivideRect(viewBounds, &topRect, &gridHeaderAndBodyRect, ceil (cellSize.height + OACalendarViewSpaceBetweenMonthYearAndGrid), NSMinYEdge);619 NSDivideRect(topRect, &discardRect, &monthAndYearRect, floor ((viewBounds.size.width - cellSize.width) / 2), NSMinXEdge);618 NSDivideRect(viewBounds, &topRect, &gridHeaderAndBodyRect, ceilf(cellSize.height + OACalendarViewSpaceBetweenMonthYearAndGrid), NSMinYEdge); 619 NSDivideRect(topRect, &discardRect, &monthAndYearRect, floorf((viewBounds.size.width - cellSize.width) / 2), NSMinXEdge); 620 620 monthAndYearRect.size.width = cellSize.width; 621 621 622 622 tempRect = gridHeaderAndBodyRect; 623 623 // leave space for a one-pixel border on each side 624 tempRect.size.width -= 2.0 ;625 tempRect.origin.x += 1.0 ;624 tempRect.size.width -= 2.0f; 625 tempRect.origin.x += 1.0f; 626 626 // leave space for a one-pixel border at the bottom (the top already looks fine) 627 tempRect.size.height -= 1.0 ;627 tempRect.size.height -= 1.0f; 628 628 629 629 // get the grid header rect 630 630 cellSize = [dayOfWeekCell[0] cellSize]; 631 NSDivideRect(tempRect, &gridHeaderRect, &gridBodyRect, ceil (cellSize.height), NSMinYEdge);631 NSDivideRect(tempRect, &gridHeaderRect, &gridBodyRect, ceilf(cellSize.height), NSMinYEdge); 632 632 633 633 // get the grid row height (add 1.0 to the body height because while we can't actually draw on that extra pixel, our bottom row doesn't have to draw a bottom grid line as there's a border right below us, so we need to account for that, which we do by pretending that next pixel actually does belong to us) 634 rowHeight = floor ((gridBodyRect.size.height + 1.0) / OACalendarViewMaxNumWeeksIntersectedByMonth);634 rowHeight = floorf((gridBodyRect.size.height + 1.0f) / OACalendarViewMaxNumWeeksIntersectedByMonth); 635 635 636 636 // get the grid body rect 637 gridBodyRect.size.height = (rowHeight * OACalendarViewMaxNumWeeksIntersectedByMonth) - 1.0 ;637 gridBodyRect.size.height = (rowHeight * OACalendarViewMaxNumWeeksIntersectedByMonth) - 1.0f; 638 638 639 639 // adjust the header and body rect to account for any adjustment made while calculating even row heights 640 gridHeaderAndBodyRect.size.height = NSMaxY(gridBodyRect) - NSMinY(gridHeaderAndBodyRect) + 1.0 ;640 gridHeaderAndBodyRect.size.height = NSMaxY(gridBodyRect) - NSMinY(gridHeaderAndBodyRect) + 1.0f; 641 641 } 642 642 … … 653 653 654 654 // the cell is actually one pixel shorter than the row height, because the row height includes the bottom grid line (or the top grid line, depending on which way you prefer to think of it) 655 cellFrame.size.height = rowHeight - 1.0 ;655 cellFrame.size.height = rowHeight - 1.0f; 656 656 // the cell would actually be one pixel narrower than the column width but we don't draw vertical grid lines. instead, we want to include the area that would be grid line (were we drawing it) in our cell, because that looks a bit better under the header, which _does_ draw column separators. actually, we want to include the grid line area on _both sides_ or it looks unbalanced, so we actually _add_ one pixel, to cover that. below, our x position as we draw will have to take that into account. note that this means that sunday and saturday overwrite the outside borders, but the outside border is drawn last, so it ends up ok. (if we ever start drawing vertical grid lines, change this to be - 1.0, and adjust the origin appropriately below.) 657 cellFrame.size.width = columnWidth + 1.0 ;657 cellFrame.size.width = columnWidth + 1.0f; 658 658 659 659 cellSize = [dayOfMonthCell cellSize]; … … 668 668 669 669 // subtract 1.0 from the origin because we're including the area where vertical grid lines would be were we drawing them 670 cellFrame.origin.x = rect.origin.x + (column * columnWidth) - 1.0 ;670 cellFrame.origin.x = rect.origin.x + (column * columnWidth) - 1.0f; 671 671 cellFrame.origin.y = rect.origin.y + (row * rowHeight); 672 672 … … 716 716 [dayOfMonthCell setTextColor:textColor]; 717 717 } 718 NSDivideRect(cellFrame, &discardRect, &dayOfMonthFrame, floor ((cellFrame.size.height - cellSize.height) / 2.0), NSMinYEdge);718 NSDivideRect(cellFrame, &discardRect, &dayOfMonthFrame, floorf((cellFrame.size.height - cellSize.height) / 2.0f), NSMinYEdge); 719 719 [dayOfMonthCell drawWithFrame:dayOfMonthFrame inView:self]; 720 720 } … … 738 738 // add 0.5 to move to the center of the pixel before drawing a line 1.0 pixels thick, centered around 0.0 (which would mean half a pixel above the starting point and half a pixel below - not what we want) 739 739 // we could just subtract 0.5, but I think this is clearer, and the compiler will optimize it to the appropriate value for us 740 pointA = NSMakePoint(NSMinX(rect), NSMinY(rect) - 1.0 + 0.5);741 pointB = NSMakePoint(NSMaxX(rect), NSMinY(rect) - 1.0 + 0.5);740 pointA = NSMakePoint(NSMinX(rect), NSMinY(rect) - 1.0f + 0.5f); 741 pointB = NSMakePoint(NSMaxX(rect), NSMinY(rect) - 1.0f + 0.5f); 742 742 743 743 [[NSColor controlHighlightColor] set]; … … 780 780 } 781 781 782 return ceil (maxWidth);782 return ceilf(maxWidth); 783 783 } 784 784 … … 814 814 815 815 dayOfWeekWidth = [self _maximumDayOfWeekWidth]; // we don't have to add 1.0 because the day of week cell whose width is returned here includes it's own border 816 dayOfMonthWidth = [self _maximumDayOfMonthSize].width + 1.0 ; // add 1.0 to allow for the grid. We don't actually draw the vertical grid, but we treat it as if there was one (don't respond to clicks "on" the grid, we have a vertical separator in the header, etc.)816 dayOfMonthWidth = [self _maximumDayOfMonthSize].width + 1.0f; // add 1.0 to allow for the grid. We don't actually draw the vertical grid, but we treat it as if there was one (don't respond to clicks "on" the grid, we have a vertical separator in the header, etc.) 817 817 return (dayOfMonthWidth > dayOfWeekWidth) ? dayOfMonthWidth : dayOfWeekWidth; 818 818 } … … 820 820 - (float)_minimumRowHeight; 821 821 { 822 return [self _maximumDayOfMonthSize].height + 1.0 ; // add 1.0 to allow for a bordering grid line822 return [self _maximumDayOfMonthSize].height + 1.0f; // add 1.0 to allow for a bordering grid line 823 823 } 824 824
Note:
See TracChangeset
for help on using the changeset viewer.