PageRenderTime 19ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/AppKit/GTMUILocalizerAndLayoutTweaker.h

http://macfuse.googlecode.com/
C++ Header | 126 lines | 35 code | 13 blank | 78 comment | 0 complexity | 81a2d948c3485e264587d162b1ca462b MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  1. //
  2. // GTMUILocalizerAndLayoutTweaker.h
  3. //
  4. // Copyright 2009 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Cocoa/Cocoa.h>
  19. #import "GTMDefines.h"
  20. @class GTMUILocalizer;
  21. // In addition to the information here, please see the project's documentation
  22. // (http://code.google.com/p/google-toolbox-for-mac/wiki/UILocalization) for
  23. // more information and examples.
  24. // This object will run a GTMUILocalizer on the given object, and then run
  25. // through the object's view heirarchy triggering any Tweakers to do their work.
  26. // (This "double duty" is needed so the work can be done in order during
  27. // awakeFromNib, if it was two objects, the order couldn't be guaranteed.)
  28. @interface GTMUILocalizerAndLayoutTweaker : NSObject {
  29. @private
  30. IBOutlet id uiObject_; // The window or view to process on awakeFromNib
  31. IBOutlet GTMUILocalizer *localizer_; // If nil, one will be created
  32. IBOutlet id localizerOwner_; // Set if you want the default GTMUILocalizer
  33. }
  34. // Localize the the UI and then tweak the layout in the given object.
  35. - (void)applyLocalizer:(GTMUILocalizer *)localizer
  36. tweakingUI:(id)uiObject;
  37. // Don't do any localization, just runs the tweaks, useful if you just need
  38. // layout adjusted based on content from elsewhere. |uiObject| should be
  39. // a NSWindow or NSView (or subclass).
  40. - (void)tweakUI:(id)uiObject;
  41. // This checks to see if |view| implements @selector(sizeToFit) and calls it.
  42. // It then checks the class of |view| and does some fixup for known issues
  43. // where sizeToFit doesn't produce a view that meets UI guidelines.
  44. // Returns the amount the view changed in size.
  45. + (NSSize)sizeToFitView:(NSView *)view;
  46. // If you call sizeToFit on a NSTextField it will try not to word wrap, so it
  47. // can get really wide. This method will keep the width fixed, but figure out
  48. // how tall the textfield needs to be to fit its text.
  49. // Returns the amount the field changed height.
  50. + (CGFloat)sizeToFitFixedWidthTextField:(NSTextField *)textField;
  51. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  52. // If you call sizeToFit on a NSTextField it will try not to word wrap, so it
  53. // can get really wide. This method will keep the height fixed, but figure out
  54. // how wide the textfield needs to be to fit its text.
  55. // Returns the amount the field changed width.
  56. + (CGFloat)sizeToFitFixedHeightTextField:(NSTextField *)textField;
  57. + (CGFloat)sizeToFitFixedHeightTextField:(NSTextField *)textField
  58. minWidth:(NSUInteger)minWidth;
  59. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  60. // Insert newlines into the title of the button (radio or checkbox) or all cells
  61. // in the radio group (NSMatrix) so they will word wrap to the item's current
  62. // width. Then +sizeToFitView can be called to then resize to the exact width
  63. // and height needed. Note: any existing Opt-Return forced wraps are removed
  64. // from the existing titles.
  65. + (void)wrapButtonTitleForWidth:(NSButton *)button;
  66. + (void)wrapRadioGroupForWidth:(NSMatrix *)radioGroup;
  67. // Resizes |window| or |view| by |delta| without letting the subviews get
  68. // resized. Useful when you've done manual tweaking by things like
  69. // +sizeToFitFixedWidthTextField. The origin is not adjusted. For windows,
  70. // passes |NO| to for -setFrame:display:'s |displayViews| flag on the
  71. // assumptions the caller is doing all the invals/updates needed.
  72. // NOTE: For windows, |delta| is assumed to be in content coordinates, and
  73. // Resolution Independence transforms on the window's frame are done.
  74. + (void)resizeWindowWithoutAutoResizingSubViews:(NSWindow*)window
  75. delta:(NSSize)delta;
  76. + (void)resizeViewWithoutAutoResizingSubViews:(NSView*)view
  77. delta:(NSSize)delta;
  78. @end
  79. // This is a Tweaker that will call sizeToFit on everything within it (that
  80. // supports it).
  81. //
  82. // If the items were all left aligned, they will stay as such and the box will
  83. // resize based on the largest change of any item within it. If they aren't
  84. // left aligned, they are assumed to be in a row, and it will slide everything
  85. // along as it lays them out to make sure they end up still spaced out and will
  86. // resize itself by the total change to the row.
  87. //
  88. // This Tweaker makes no attempt to deal with changes in an object height.
  89. //
  90. // This Tweaker makes no attempt to deal with its parent's width.
  91. @interface GTMWidthBasedTweaker : NSView {
  92. @private
  93. // This outlet is the view that should move by the same amount as this box
  94. // grows and change its size by the inverse. i.e.-if a box of NSTextFields,
  95. // they will stay next to the box of labels and resize so the two boxes
  96. // continue to use the same total space.
  97. IBOutlet NSView *viewToSlideAndResize_;
  98. // This outlet is just like viewToSlideAndResize_ except the view is only
  99. // slid (ie-its width is not adjusted). i.e.-lets something move along next
  100. // to this box.
  101. IBOutlet NSView *viewToSlide_;
  102. // This outlet is just like viewToSlideAndResize_ except the view is only
  103. // resized (ie-its position is not adjusted). i.e.-lets something above/below
  104. // this box stay the same width. You can set this to be the window, in
  105. // which case it is resized, but you need to make sure everything is setup
  106. // to handle that, and using two Tweakers pointed at the window isn't likely
  107. // to give the results you want.
  108. IBOutlet id viewToResize_;
  109. CGFloat widthChange_;
  110. }
  111. // Return the amount we changed our width by on last tweak.
  112. - (CGFloat)changedWidth;
  113. @end