Hello.

I have a window in my application for which I have set resize
increments. When I click the zoom button in the window's title
bar, sometimes it obeys the resize increments, i.e. the window
fills the screen as much as possible without violating the resize
increments. But sometimes the window resizes in such a way that
it does violate the resize increments.

I have not yet figured out what conditions exactly cause this.
I suspect it has something to do with the initial size of the
window, but I am not sure.

I have created a minium working example. It is a standard Xcode-
created Cocoa application, but I used a custom view for the
content view of the main window. The custom view draws a grid
and the window resize increments are the grid cell's dimensions.
Here is the implementation of the custom view:

=== CODE BEGIN ===

#import "CustomView.h"

#define CELL_WIDTH  100
#define CELL_HEIGHT 100

@implementation CustomView

- (void)awakeFromNib
{

  NSWindow *window = [self window];

  // Set the size of the window content's height and width to a
  // multiple of the cell height and the cell width, respectively.
  NSRect frame = [window frame];
  frame.size = NSMakeSize(5 * CELL_WIDTH, 5 * CELL_HEIGHT);;
  frame = [NSWindow frameRectForContentRect:frame
      styleMask:NSTitledWindowMask];
  [window setFrame:frame display:TRUE];

  // Set the window's resize increments to the cell dimensions.
  [window setResizeIncrements:NSMakeSize(CELL_WIDTH, CELL_HEIGHT)];

}

- (void)drawRect:(NSRect)dirtyRect
{

  NSRect bounds = [self bounds];

  // Draw background color.
  [[NSColor whiteColor] set];
  NSRectFill(bounds);

  // Draw a grid.
  [[NSColor gridColor] set];
  CGFloat x = 0, y = 0;
  while (x < bounds.size.width)
    NSFrameRect(NSMakeRect(x += CELL_WIDTH, 0, 1, bounds.size.height));
  while (y < bounds.size.height)
    NSFrameRect(NSMakeRect(0, y += CELL_HEIGHT, bounds.size.width, 1));

}

@end

=== CODE END ===

When I played around with the values of CELL_WIDTH and CELL_HEIGHT,
I noticed that the problem occurs for some values and for some it
does not. For example, it does not occur when I use 100 and 100, but
it does occur when I use 47 and 47.

Am I doing something wrong or is this a bug?
If I am doing something wrong, how can I do it right?
If it is a bug, how can I work around it?

Thanks in advance.
Best regards,

Jacob
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to