/Frameworks/Debug/AppKit/browser.platform/_CPHUDWindowView.j

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 152 lines · 151 code · 1 blank · 0 comment · 0 complexity · 6161fe6a8cb0e1032cca6035556466e1 MD5 · raw file

  1. c;9230;var _CPHUDWindowViewBackgroundColor = nil,
  2. CPHUDCloseButtonImage = nil;
  3. var HUD_TITLEBAR_HEIGHT = 26.0;
  4. {var the_class = objj_allocateClassPair(_CPWindowView, "_CPHUDWindowView"),
  5. meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_toolbarView"), new objj_ivar("_titleField"), new objj_ivar("_closeButton")]);
  6. objj_registerClassPair(the_class);
  7. objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  8. class_addMethods(the_class, [new objj_method(sel_getUid("contentRectForFrameRect:"), function $_CPHUDWindowView__contentRectForFrameRect_(self, _cmd, aFrameRect)
  9. { with(self)
  10. {
  11. var contentRect = objj_msgSend(objj_msgSend(self, "class"), "contentRectForFrameRect:", aFrameRect);
  12. if (objj_msgSend(objj_msgSend(objj_msgSend(self, "window"), "toolbar"), "isVisible"))
  13. {
  14. toolbarHeight = CGRectGetHeight(objj_msgSend(objj_msgSend(self, "toolbarView"), "frame"));
  15. contentRect.origin.y += toolbarHeight;
  16. contentRect.size.height -= toolbarHeight;
  17. }
  18. return contentRect;
  19. }
  20. }), new objj_method(sel_getUid("frameRectForContentRect:"), function $_CPHUDWindowView__frameRectForContentRect_(self, _cmd, aContentRect)
  21. { with(self)
  22. {
  23. var frameRect = objj_msgSend(objj_msgSend(self, "class"), "frameRectForContentRect:", aContentRect);
  24. if (objj_msgSend(objj_msgSend(objj_msgSend(self, "window"), "toolbar"), "isVisible"))
  25. {
  26. toolbarHeight = CGRectGetHeight(objj_msgSend(objj_msgSend(self, "toolbarView"), "frame"));
  27. frameRect.origin.y -= toolbarHeight;
  28. frameRect.size.height += toolbarHeight;
  29. }
  30. return frameRect;
  31. }
  32. }), new objj_method(sel_getUid("initWithFrame:styleMask:"), function $_CPHUDWindowView__initWithFrame_styleMask_(self, _cmd, aFrame, aStyleMask)
  33. { with(self)
  34. {
  35. self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("_CPWindowView") }, "initWithFrame:styleMask:", aFrame, aStyleMask);
  36. if (self)
  37. {
  38. var bounds = objj_msgSend(self, "bounds");
  39. objj_msgSend(self, "setBackgroundColor:", _CPHUDWindowViewBackgroundColor);
  40. _titleField = objj_msgSend(objj_msgSend(CPTextField, "alloc"), "initWithFrame:", CGRectMakeZero());
  41. objj_msgSend(_titleField, "setHitTests:", NO);
  42. objj_msgSend(_titleField, "setFont:", objj_msgSend(CPFont, "systemFontOfSize:", 11.0));
  43. objj_msgSend(_titleField, "setTextColor:", objj_msgSend(CPColor, "whiteColor"));
  44. objj_msgSend(_titleField, "setTextShadowColor:", objj_msgSend(CPColor, "blackColor"));
  45. objj_msgSend(_titleField, "setTextShadowOffset:", CGSizeMake(0.0, 1.0));
  46. objj_msgSend(_titleField, "setAutoresizingMask:", CPViewWidthSizable);
  47. objj_msgSend(_titleField, "setLineBreakMode:", CPLineBreakByTruncatingTail);
  48. objj_msgSend(_titleField, "setAlignment:", CPCenterTextAlignment);
  49. objj_msgSend(_titleField, "setStringValue:", "Untitled");
  50. objj_msgSend(_titleField, "sizeToFit");
  51. objj_msgSend(_titleField, "setAutoresizingMask:", CPViewWidthSizable);
  52. objj_msgSend(_titleField, "setStringValue:", "");
  53. objj_msgSend(_titleField, "setFrame:", CGRectMake(20.0, 3.0, CGRectGetWidth(objj_msgSend(self, "bounds")) - 40.0, CGRectGetHeight(objj_msgSend(_titleField, "frame"))));
  54. objj_msgSend(self, "addSubview:", _titleField);
  55. if (_styleMask & CPClosableWindowMask)
  56. {
  57. var closeSize = objj_msgSend(_CPHUDWindowViewCloseImage, "size");
  58. _closeButton = objj_msgSend(objj_msgSend(CPButton, "alloc"), "initWithFrame:", CGRectMake(4.0, 4.0, closeSize.width, closeSize.height));
  59. objj_msgSend(_closeButton, "setBordered:", NO);
  60. objj_msgSend(_closeButton, "setImage:", _CPHUDWindowViewCloseImage);
  61. objj_msgSend(_closeButton, "setAlternateImage:", _CPHUDWindowViewCloseActiveImage);
  62. objj_msgSend(self, "addSubview:", _closeButton);
  63. }
  64. objj_msgSend(self, "setResizeIndicatorOffset:", CGSizeMake(5.0, 5.0));
  65. }
  66. return self;
  67. }
  68. }), new objj_method(sel_getUid("viewDidMoveToWindow"), function $_CPHUDWindowView__viewDidMoveToWindow(self, _cmd)
  69. { with(self)
  70. {
  71. objj_msgSend(_closeButton, "setTarget:", objj_msgSend(self, "window"));
  72. objj_msgSend(_closeButton, "setAction:", sel_getUid("performClose:"));
  73. }
  74. }), new objj_method(sel_getUid("setTitle:"), function $_CPHUDWindowView__setTitle_(self, _cmd, aTitle)
  75. { with(self)
  76. {
  77. objj_msgSend(_titleField, "setStringValue:", aTitle);
  78. }
  79. }), new objj_method(sel_getUid("toolbarView"), function $_CPHUDWindowView__toolbarView(self, _cmd)
  80. { with(self)
  81. {
  82. return _toolbarView;
  83. }
  84. }), new objj_method(sel_getUid("toolbarLabelColor"), function $_CPHUDWindowView__toolbarLabelColor(self, _cmd)
  85. { with(self)
  86. {
  87. return objj_msgSend(CPColor, "whiteColor");
  88. }
  89. }), new objj_method(sel_getUid("toolbarLabelShadowColor"), function $_CPHUDWindowView__toolbarLabelShadowColor(self, _cmd)
  90. { with(self)
  91. {
  92. return objj_msgSend(CPColor, "blackColor");
  93. }
  94. }), new objj_method(sel_getUid("toolbarOffset"), function $_CPHUDWindowView__toolbarOffset(self, _cmd)
  95. { with(self)
  96. {
  97. return CGSizeMake(0.0, HUD_TITLEBAR_HEIGHT);
  98. }
  99. }), new objj_method(sel_getUid("tile"), function $_CPHUDWindowView__tile(self, _cmd)
  100. { with(self)
  101. {
  102. objj_msgSendSuper({ receiver:self, super_class:objj_getClass("_CPWindowView") }, "tile");
  103. var theWindow = objj_msgSend(self, "window"),
  104. bounds = objj_msgSend(self, "bounds"),
  105. width = CGRectGetWidth(bounds);
  106. objj_msgSend(_titleField, "setFrame:", CGRectMake(20.0, 3.0, width - 40.0, CGRectGetHeight(objj_msgSend(_titleField, "frame"))));
  107. var maxY = objj_msgSend(self, "toolbarMaxY");
  108. objj_msgSend(objj_msgSend(theWindow, "contentView"), "setFrameOrigin:", CGPointMake(0.0, maxY, width, CGRectGetHeight(bounds) - maxY));
  109. }
  110. })]);
  111. class_addMethods(meta_class, [new objj_method(sel_getUid("initialize"), function $_CPHUDWindowView__initialize(self, _cmd)
  112. { with(self)
  113. {
  114. if (self != objj_msgSend(_CPHUDWindowView, "class"))
  115. return;
  116. var bundle = objj_msgSend(CPBundle, "bundleForClass:", self);
  117. _CPHUDWindowViewBackgroundColor = objj_msgSend(CPColor, "colorWithPatternImage:", objj_msgSend(objj_msgSend(CPNinePartImage, "alloc"), "initWithImageSlices:",
  118. [
  119. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground0.png"), CPSizeMake(6.0, 78.0)),
  120. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground1.png"), CPSizeMake(1.0, 78.0)),
  121. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground2.png"), CPSizeMake(6.0, 78.0)),
  122. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground3.png"), CPSizeMake(6.0, 1.0)),
  123. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground4.png"), CPSizeMake(1.0, 1.0)),
  124. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground5.png"), CPSizeMake(6.0, 1.0)),
  125. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground6.png"), CPSizeMake(6.0, 6.0)),
  126. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground7.png"), CPSizeMake(6.0, 6.0)),
  127. objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPWindow/HUD/CPWindowHUDBackground8.png"), CPSizeMake(6.0, 6.0))
  128. ]));
  129. _CPHUDWindowViewCloseImage = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "HUDTheme/WindowClose.png"), CPSizeMake(20.0, 20.0));
  130. _CPHUDWindowViewCloseActiveImage = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "HUDTheme/WindowCloseActive.png"), CPSizeMake(20.0, 20.0));
  131. }
  132. }), new objj_method(sel_getUid("contentRectForFrameRect:"), function $_CPHUDWindowView__contentRectForFrameRect_(self, _cmd, aFrameRect)
  133. { with(self)
  134. {
  135. var contentRect = CGRectMakeCopy(aFrameRect),
  136. titleBarHeight = HUD_TITLEBAR_HEIGHT;
  137. contentRect.origin.y += titleBarHeight;
  138. contentRect.size.height -= titleBarHeight;
  139. return contentRect;
  140. }
  141. }), new objj_method(sel_getUid("frameRectForContentRect:"), function $_CPHUDWindowView__frameRectForContentRect_(self, _cmd, aContentRect)
  142. { with(self)
  143. {
  144. var frameRect = CGRectMakeCopy(aContentRect),
  145. titleBarHeight = HUD_TITLEBAR_HEIGHT;
  146. frameRect.origin.y -= titleBarHeight;
  147. frameRect.size.height += titleBarHeight;
  148. return frameRect;
  149. }
  150. })]);
  151. }