Previously, when removing a view, Cappuccino didn't clean the notification center. The notification center kept in reference old views.
This PR fix this issue. When a CPView is added to a view, the methods _removeObservers and _addObservers are called. In these both methods we remove and add the observer to the notification center if needed. _removeObservers and _addObservers are called for the view and its subviews. These both methods are called through the method viewWillMoveToSuperview.
When a CPView is removed, we only call the method _removeObservers.
When a CPWindow is closed, we call the method _removeObservers on its contentView.
When a CPWindow is about to be opened, we call the method _removeObservers and _addObservers on its contentView.
Refs #1880
Refs #2024
Test app in Tests/Manual/AttachedSheet2/SheetWindowController.j
Previously, Cappuccino was using preprocessor macros internally for the CGPoint/Size/Rect/Inset/Affine functions, as well as for CPRange. These macros had the same name as the corresponding function, but began with _. The functions were actually defined using the macros.
The motivation behind using macros was to increase performance by reducing function calls. However, there were a number of problems with this approach:
- There was an artificial dichotomy between _CG macros and the corresponding CG functions. We never completely replaced CG function calls with _CG macros. In fact, they were often mixed up in the same file. There was an extra burden on the programmer to remember to use the macro instead of the function.
- If a method call was passed as an argument to a macro, performance could actually be significantly *worse* than a function call. For example, _CGGetRectMakeCopy([view frame]) would expand to `{ origin:{ x:[view frame].origin.x, y:[view frame].origin.y }, size:{ width:[view frame].size.width, height:[view frame].size.height } }`. So instead of a single objj_msgSend and a single simple function call, we ended up with 4 objj_msgSend calls, which are way more expensive than simple function calls.
- Because of this expansion problem, to use macros efficiently required us to remember to use variables for all macro parameters. This didn't happen, and shouldn't have to happen.
- Finally, with modern Javascript engines, function call overhead is so small that it really isn't worth using the macros.
This commit eliminates the _CGGeometry, CGAffineTransformation and CPRange macros and replaces them with function calls.
BREAKING CHANGE:
The macros are no longer available. They could only be used with compiled code, but if there is any user code that used them, they will have to be replaced with the corresponding functions.
- Changed from deprecated image scaling constants to new ones.
- Added support for CPImageScaleProportionallyUpOrDown (thanks BlairDuncan).
- Cleaned up image layout code.
- Fix recentAutosaveName decoding (setter was needed)
- Fix a bug where 2 search fields in the same app would receive the same recentSearches update when recentAutosaveName set.
- Update recentAutosaveName to use the new CPUserDefaults class instead of CPCookie.
- searchMenuTemplate nib2cib decoding. searchMenutemplate is just an outlet, it's automatically connected.
- Removed CPSearchFieldSeparatorItemTag
- Updated Test app with a nib2cibed search field. Ability to set some options for the regular search field.
- Style and white space.
All classes (excluding the ones prefixed with underscores) in Foundation
and AppKit can now be loaded individually except CPOpenPanel and
CPSavePanel. These two classes have some sort of dependency cycle
that seems impossible to resolve without forward declarations (which
we don't have).
- Added more documentation for -defaultSearchTemplate.
- Capitalized the text of the menu items in the default template.
- Adding a separator before no recents menu item if there are items before it.
- Updated the test app to use the default template and then modify it.
- Updated the test app to maintain the state of the custom items.
- No longer setting the search menu template to the default, but -defaultSearchMenuTemplate was made public.
- Action and target for clear recents item is always set to CPSearchField -_searchFieldClearRecents: since that is a built-in type.
- Action and target for recents item is always set to CPSearchField -_searchFieldSearch: since that is a built-in type.
- Template menu items are copied via CPMenuItem -copy (which is now implemented), so all state is maintained.
- Added the ability to specify a separator in the template by using the tag CPSearchFieldSeparatorMenuItemTag.
- _recentSearches was not being initialized by -initWithCoder, moved that code into -_init.
- -setSearchMenuTemplate was not being invoked. Since having a recents menu is the default behavior in Cocoa, it should probably be the default behavior in cappuccino. To turn it off, set _maximumRecents to >= 254.
- -searchTextRectForBounds was using the wrong rect for -searchButtonRectForBounds and -cancelButtonRectForBounds, resulting in a rect that was too narrow and did not fill the space.
- Tightened up the spacing between the magnifying glass and the text to exactly Cocoa distance.
- Overhauled -
updateSearchMenu to fix some logic bugs.
- Made sure the search field becomes first responder after closing the search menu.
- Cleared the search string when clearing recent searches, this is what Safari does.
- Removed redundant invoking of -setDelegate in -initWithCoder.
- -_init has to be called last in _initWithCoder.
- Replaced CG functions with inline _CG functions
- _canResignFirstResponder was not being initialized to YES
- -resignFirstResponder has to call super if _canResignFirstResponder == YES
- Do not override search button action, catch mouse events in mouseDown: instead.
- Do not resign first responder on searchfield when showing the context menu
- Give more space between search button and insertion point
- Do not add search string to recents searches when typing and sendsWholeString == NO, only on enter.
- Select all text when showing the menu or after selecting a recent search in the menu
- Support custom search/cancel buttons and custom layout
- Allow images in template menu items
- Updated Test App with custom buttons