My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
Changes to /trunk/AppKit/GTMUILocalizerAndLayoutTweaker.h
r253 vs. r302 Compare: vs.  Format:
Revision r302
Go to: 
Project members, sign in to write a code review
/trunk/AppKit/GTMUILocalizerAndLayoutTweaker.h   r253 /trunk/AppKit/GTMUILocalizerAndLayoutTweaker.h   r302
1 // 1 //
2 // GTMUILocalizerAndLayoutTweaker.h 2 // GTMUILocalizerAndLayoutTweaker.h
3 // 3 //
4 // Copyright 2009 Google Inc. 4 // Copyright 2009 Google Inc.
5 // 5 //
6 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 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 7 // use this file except in compliance with the License. You may obtain a copy
8 // of the License at 8 // of the License at
9 // 9 //
10 // http://www.apache.org/licenses/LICENSE-2.0 10 // http://www.apache.org/licenses/LICENSE-2.0
11 // 11 //
12 // Unless required by applicable law or agreed to in writing, software 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 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 14 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 // License for the specific language governing permissions and limitations under 15 // License for the specific language governing permissions and limitations under
16 // the License. 16 // the License.
17 // 17 //
18 18
19 #import <Cocoa/Cocoa.h> 19 #import <Cocoa/Cocoa.h>
20 #import "GTMDefines.h" 20 #import "GTMDefines.h"
21 21
22 @class GTMUILocalizer; 22 @class GTMUILocalizer;
23 23
24 // In addition to the information here, please see the project's documentation 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 25 // (http://code.google.com/p/google-toolbox-for-mac/wiki/UILocalization) for
26 // more information and examples. 26 // more information and examples.
27 27
28 // This object will run a GTMUILocalizer on the given object, and then run 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. 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 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.) 31 // awakeFromNib, if it was two objects, the order couldn't be guaranteed.)
32 @interface GTMUILocalizerAndLayoutTweaker : NSObject { 32 @interface GTMUILocalizerAndLayoutTweaker : NSObject {
33 @private 33 @private
34 IBOutlet id uiObject_; // The window or view to process on awakeFromNib 34 IBOutlet id uiObject_; // The window or view to process on awakeFromNib
35 IBOutlet GTMUILocalizer *localizer_; // If nil, one will be created 35 IBOutlet GTMUILocalizer *localizer_; // If nil, one will be created
36 IBOutlet id localizerOwner_; // Set if you want the default GTMUILocalizer 36 IBOutlet id localizerOwner_; // Set if you want the default GTMUILocalizer
37 } 37 }
38 // Localize the the UI and then tweak the layout in the given object. 38 // Localize the the UI and then tweak the layout in the given object.
39 - (void)applyLocalizer:(GTMUILocalizer *)localizer 39 - (void)applyLocalizer:(GTMUILocalizer *)localizer
40 tweakingUI:(id)uiObject; 40 tweakingUI:(id)uiObject;
41 41
42 // Don't do any localization, just runs the tweaks, useful if you just need 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 43 // layout adjusted based on content from elsewhere. |uiObject| should be
44 // a NSWindow or NSView (or subclass). 44 // a NSWindow or NSView (or subclass).
45 - (void)tweakUI:(id)uiObject; 45 - (void)tweakUI:(id)uiObject;
46 46
47 // This checks to see if |view| implements @selector(sizeToFit) and calls it. 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 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. 49 // where sizeToFit doesn't produce a view that meets UI guidelines.
50 // Returns the amount the view changed in size. 50 // Returns the amount the view changed in size.
51 + (NSSize)sizeToFitView:(NSView *)view; 51 + (NSSize)sizeToFitView:(NSView *)view;
52 52
53 // If you call sizeToFit on a NSTextField it will try not to word wrap, so it 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 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. 55 // how tall the textfield needs to be to fit its text.
56 // Returns the amount the field changed height. 56 // Returns the amount the field changed height.
57 + (CGFloat)sizeToFitFixedWidthTextField:(NSTextField *)textField; 57 + (CGFloat)sizeToFitFixedWidthTextField:(NSTextField *)textField;
58 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
59 // Insert newlines into the title of the button (radio or checkbox) or all cells 69 // Insert newlines into the title of the button (radio or checkbox) or all cells
60 // in the radio group (NSMatrix) so they will word wrap to the item's current 70 // in the radio group (NSMatrix) so they will word wrap to the item's current
61 // width. Then +sizeToFitView can be called to have then resize to the exact 71 // width. Then +sizeToFitView can be called to then resize to the exact width
62 // width and height needed. Note: any existing Opt-Return forced wraps are 72 // and height needed. Note: any existing Opt-Return forced wraps are removed
63 // removed from the existing titles. 73 // from the existing titles.
64 + (void)wrapButtonTitleForWidth:(NSButton *)button; 74 + (void)wrapButtonTitleForWidth:(NSButton *)button;
65 + (void)wrapRadioGroupForWidth:(NSMatrix *)radioGroup; 75 + (void)wrapRadioGroupForWidth:(NSMatrix *)radioGroup;
66 76
67 // Resizes |window| or |view| by |delta| without letting the subviews get 77 // Resizes |window| or |view| by |delta| without letting the subviews get
68 // resized. Useful when you've done manual tweaking by things like 78 // resized. Useful when you've done manual tweaking by things like
69 // +sizeToFitFixedWidthTextField. The origin is not adjusted. For windows, 79 // +sizeToFitFixedWidthTextField. The origin is not adjusted. For windows,
70 // passes |NO| to for -setFrame:display:'s |displayViews| flag on the 80 // passes |NO| to for -setFrame:display:'s |displayViews| flag on the
71 // assumptions the caller is doing all the invals/updates needed. 81 // assumptions the caller is doing all the invals/updates needed.
72 + (void)resizeWindowWithoutAutoResizingSubViews:(NSWindow*)window 82 + (void)resizeWindowWithoutAutoResizingSubViews:(NSWindow*)window
73 delta:(NSSize)delta; 83 delta:(NSSize)delta;
74 + (void)resizeViewWithoutAutoResizingSubViews:(NSView*)view 84 + (void)resizeViewWithoutAutoResizingSubViews:(NSView*)view
75 delta:(NSSize)delta; 85 delta:(NSSize)delta;
76 86
77 @end 87 @end
78 88
79 // This is a Tweaker that will call sizeToFit on everything within it (that 89 // This is a Tweaker that will call sizeToFit on everything within it (that
80 // supports it). 90 // supports it).
81 // 91 //
82 // If the items were all left aligned, they will stay as such and the box will 92 // 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 93 // 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 94 // 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 95 // 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. 96 // resize itself by the total change to the row.
87 // 97 //
88 // This Tweaker makes no attempt to deal with changes in an object height. 98 // This Tweaker makes no attempt to deal with changes in an object height.
89 // 99 //
90 // This Tweaker makes no attempt to deal with its parent's width. 100 // This Tweaker makes no attempt to deal with its parent's width.
91 @interface GTMWidthBasedTweaker : NSView { 101 @interface GTMWidthBasedTweaker : NSView {
92 @private 102 @private
93 // This outlet is the view that should move by the same amount as this box 103 // 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, 104 // 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 105 // they will stay next to the box of labels and resize so the two boxes
96 // continue to use the same total space. 106 // continue to use the same total space.
97 IBOutlet NSView *viewToSlideAndResize_; 107 IBOutlet NSView *viewToSlideAndResize_;
98 // This outlet is just like viewToSlideAndResize_ except the view is only 108 // 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 109 // slid (ie-its width is not adjusted). i.e.-lets something move along next
100 // to this box. 110 // to this box.
101 IBOutlet NSView *viewToSlide_; 111 IBOutlet NSView *viewToSlide_;
102 // This outlet is just like viewToSlideAndResize_ except the view is only 112 // 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 113 // 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 114 // 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 115 // 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 116 // to handle that, and using two Tweakers pointed at the window isn't likely
107 // to give the results you want. 117 // to give the results you want.
108 IBOutlet id viewToResize_; 118 IBOutlet id viewToResize_;
109 119
110 CGFloat widthChange_; 120 CGFloat widthChange_;
111 } 121 }
112 // Return the amount we changed our width by on last tweak. 122 // Return the amount we changed our width by on last tweak.
113 - (CGFloat)changedWidth; 123 - (CGFloat)changedWidth;
114 @end 124 @end
Powered by Google Project Hosting