/AppKit/CPWindow/_CPHUDWindowView.j

http://github.com/cacaodev/cappuccino · Unknown · 193 lines · 151 code · 42 blank · 0 comment · 0 complexity · 06687f364b2e422c35101f052985ae88 MD5 · raw file

  1. /*
  2. * _CPHUDWindowView.j
  3. * AppKit
  4. *
  5. * Created by Francisco Tolmasky.
  6. * Copyright 2008, 280 North, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. @import "CPButton.j"
  23. @import "CPTextField.j"
  24. @import "_CPTitleableWindowView.j"
  25. @implementation _CPHUDWindowView : _CPTitleableWindowView
  26. {
  27. CPView _toolbarView;
  28. CPButton _closeButton;
  29. }
  30. + (CPString)defaultThemeClass
  31. {
  32. return @"hud-window-view";
  33. }
  34. + (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
  35. {
  36. /*
  37. This window view class draws a frame.
  38. So we have to inset the content rect to be inside the frame.
  39. The top coordinate has already been adjusted by _CPTitleableWindowView.
  40. */
  41. var contentRect = [super contentRectForFrameRect:aFrameRect];
  42. contentRect.origin.x += 1;
  43. contentRect.size.width -= 2;
  44. contentRect.size.height -= 1;
  45. return contentRect;
  46. }
  47. - (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
  48. {
  49. var contentRect = [[self class] contentRectForFrameRect:aFrameRect];
  50. if ([[[self window] toolbar] isVisible])
  51. {
  52. var toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
  53. contentRect.origin.y += toolbarHeight;
  54. contentRect.size.height -= toolbarHeight;
  55. }
  56. return contentRect;
  57. }
  58. - (CGRect)frameRectForContentRect:(CGRect)aContentRect
  59. {
  60. var frameRect = [[self class] frameRectForContentRect:aContentRect];
  61. if ([[[self window] toolbar] isVisible])
  62. {
  63. var toolbarHeight = CGRectGetHeight([[self toolbarView] frame]);
  64. frameRect.origin.y -= toolbarHeight;
  65. frameRect.size.height += toolbarHeight;
  66. }
  67. return frameRect;
  68. }
  69. - (id)initWithFrame:(CGRect)aFrame styleMask:(unsigned)aStyleMask
  70. {
  71. self = [super initWithFrame:aFrame styleMask:aStyleMask];
  72. if (self)
  73. {
  74. if (_styleMask & CPClosableWindowMask)
  75. {
  76. _closeButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
  77. [_closeButton setBordered:NO];
  78. [_closeButton setButtonType:CPMomentaryChangeButton];
  79. [self addSubview:_closeButton];
  80. }
  81. [self setResizeIndicatorOffset:CGSizeMake(5.0, 5.0)];
  82. [self tile];
  83. }
  84. return self;
  85. }
  86. - (void)viewDidMoveToWindow
  87. {
  88. [_closeButton setTarget:[self window]];
  89. [_closeButton setAction:@selector(performClose:)];
  90. }
  91. - (_CPToolbarView)toolbarView
  92. {
  93. return _toolbarView;
  94. }
  95. - (CPColor)toolbarLabelColor
  96. {
  97. return [CPColor whiteColor];
  98. }
  99. - (CPColor)toolbarLabelShadowColor
  100. {
  101. return [CPColor blackColor];
  102. }
  103. - (CGSize)toolbarOffset
  104. {
  105. return CGSizeMake(0.0, [[self class] titleBarHeight]);
  106. }
  107. - (void)tile
  108. {
  109. [super tile];
  110. var theWindow = [self window],
  111. bounds = [self bounds],
  112. width = CGRectGetWidth(bounds);
  113. [_titleField setFrame:CGRectMake(20.0, 0, width - 40.0, [self toolbarOffset].height)];
  114. var maxY = [self toolbarMaxY];
  115. if ([_titleField isHidden])
  116. maxY -= ([self toolbarOffset]).height;
  117. var contentRect = CGRectMake(0.0, maxY, width, CGRectGetHeight(bounds) - maxY);
  118. [[theWindow contentView] setFrame:contentRect];
  119. }
  120. - (void)_enableSheet:(BOOL)enable inWindow:(CPWindow)parentWindow
  121. {
  122. // No need to call super, it just deals with the shadow view, which we don't want
  123. [_closeButton setHidden:enable];
  124. [_titleField setHidden:enable];
  125. // resize the window
  126. var theWindow = [self window],
  127. frame = [theWindow frame],
  128. dy = ([self toolbarOffset]).height;
  129. if (enable)
  130. dy = -dy;
  131. var newHeight = CGRectGetMaxY(frame) + dy,
  132. newWidth = CGRectGetMaxX(frame);
  133. frame.size.height += dy;
  134. [self setFrameSize:CGSizeMake(newWidth, newHeight)];
  135. [self tile];
  136. [theWindow setFrame:frame display:NO animate:NO];
  137. [theWindow setMovableByWindowBackground:!enable];
  138. [self setNeedsLayout];
  139. }
  140. - (void)layoutSubviews
  141. {
  142. [super layoutSubviews];
  143. if (_styleMask & CPClosableWindowMask)
  144. {
  145. [_closeButton setFrameOrigin:[self valueForThemeAttribute:@"close-image-origin"]];
  146. [_closeButton setFrameSize:[self valueForThemeAttribute:@"close-image-size"]]
  147. [_closeButton setImage:[self valueForThemeAttribute:@"close-image"]];
  148. [_closeButton setAlternateImage:[self valueForThemeAttribute:@"close-active-image"]];
  149. }
  150. }
  151. @end