PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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