Compare commits

..
1474 Commits
Author SHA1 Message Date
David Richardson 0f160f648e Merge branch 'main' into aristo3
# Conflicts:
#	AppKit/CPOutlineView.j
#	Tests/Manual/CPButtonTest/Resources/MainMenu.cib
#	Tests/Manual/CPButtonTest/Resources/MainMenu.xib
#	Tests/Manual/CPComboBoxTest/Resources/MainMenu.cib
#	Tests/Manual/CPComboBoxTest/Resources/MainMenu.xib
#	Tests/Manual/CPControlSize/Resources/MainMenu.cib
#	Tests/Manual/CPControlSizeTest/Resources/MainMenu.xib
#	Tests/Manual/CPDatePickerTest/Resources/MainMenu.cib
#	Tests/Manual/CPDatePickerTest/Resources/MainMenu.xib
#	Tests/Manual/CPPopUpButtonBindingsTest/CPPopUpButton.j
#	Tests/Manual/CPStepperBindings/Resources/MainMenu.xib
#	Tests/Manual/CPStepperNibTest/Resources/MainMenu.xib
2026-09-09 10:31:33 -06:00
David RichardsonandGitHub f56855010f Merge pull request #3310 from enquora/manual-tests-audit
Manual tests audit
2026-09-08 19:28:28 -06:00
David Richardson b80713c1e5 Remove temporary test suite migration tooling
Deletes the Python migration script and shell restoration utilities used to transition the Tests/Manual directory to the @objj/jake toolchain.

The subsidiary Jakefile migration is complete.

The scripts are removed from the active tree to prevent repository clutter, while their implementation details and exact transformation logic remain permanently verifiable in the git history.
2026-09-08 19:25:21 -06:00
David Richardson 93a1eea08b Add missing copyright and license headers 2026-09-08 19:22:50 -06:00
David Richardson 7393607a52 Add batch compile tasks to Jakefile 2026-09-08 19:21:58 -06:00
David Richardson 53784f0e10 Migrate subsidiary test Jakefiles to @objj/jake toolchain
Applies the transformation script across all applications in the Tests/Manual directory to eliminate Narwhal-era dependencies and establish compatibility with the modern Node-based runner.

* Removes explicit `require("jake")` calls in favor of the injected JAKE global.
* Replaces legacy `cappuccino/jake` application instantiation with the `CAPPUCCINO.Jake.applicationtask.app` hook.
* Substitutes archaic `system`, `file`, and `os` API calls with native Node `child_process`, `fs`, and `path` modules.
* Corrects package paths for nativehost deployment targets.
2026-09-08 19:08:43 -06:00
David Richardson 900448528a Add temporary automation scripts for test suite migration
Commit the Python migration script and the shell restoration loop used to batch-process the transition of legacy test Jakefiles to the modern Node toolchain.

These scripts provide an auditable record of the automated transformations applied to the test suite and will be removed in a subsequent commit - once the migration is complete.
2026-09-08 19:05:20 -06:00
David Richardson e04e3d9ba5 Normallize naming of ScalingTest2
All test names must use Test suffix.
2026-09-08 18:48:55 -06:00
David Richardson 5eaede0622 Refactor subsidiary Jakefile migration script for @objj/jake compatibility
Updates the transformation script to target the modern Node-based Cappuccino toolchain, removing Narwhal-era APIs from test configurations.

* Replaces legacy `require("jake")` with the implicitly injected `JAKE` global.
* Routes application task instantiation through the modern `CAPPUCCINO.Jake.applicationtask.app` hook.
* Substitutes archaic `OS`, `FILE`, and `system` module calls with native Node `fs`, `path`, and `child_process` equivalents.
* Corrects package pathing for `nativehost` references.
2026-09-08 18:45:44 -06:00
David Richardson 2c06bf566f Refactor Tests/Manual orchestration
Removes recursive JAKE.subjake calls from the root Jakefile, eliminating silent error masking and path evaluation failures during test suite compilation. Replace subjake with POSIX find.

* Replaces Node-based directory traversal with POSIX find and -execdir to guarantee correct working directory context and propagate standard output.
* Restricts the `clean` task strictly to the removal of build artifacts.
* Introduces a `clobber` task to remove Frameworks symlinks alongside build artifacts, restoring the test directories to a pristine state.
2026-09-08 18:02:47 -06:00
David Richardson 4784a1a102 Normalize application naming in ./Tests/Manual
Ensure:
* CamelCase, ending in Test
* No hyphens, spaces, underscores or other non-alpha characters

Updated application directory names.
Update Jakefiles.
2026-09-08 17:47:30 -06:00
David RichardsonandGitHub e3cb2cd6db Merge pull request #3309 from cappuccino/manual-tests-xib-cleanup
Update test application menu titles in MainMenu.xib
2026-09-03 16:41:23 -06:00
David Richardson dfe14a0f97 Update test application menu titles in MainMenu.xib
* Replace generic 'NewApplication' placeholder strings with specific product names.

* Extract target names from Jakefile and assert parity with Info.plist CPBundleName.

* Improve visual grounding during manual test suite auditing.
2026-09-03 16:31:50 -06:00
David RichardsonandGitHub aa6fce3297 Merge pull request #3308 from enquora/manual-tests-upgrade-xibs-and-cibs
Upgrade legacy XIB documents and regenerate CIB test assets
2026-09-03 14:26:59 -06:00
David Richardson 06da3164fc Upgrade legacy XIB documents and regenerate CIB test assets
* Execute batch structural upgrade of all XIB files within ./Tests/Manual to modern XML DOM format using ibtool (Xcode 26.3) to resolve imminent Xcode 27 parsing failures.

* Add regenerate-test-cibs.py script to recursively compile the modernized XIB documents into CIB artifacts within Tests/Manual/ using the local nib2cib toolchain.

* Commit the updated CIB artifacts to maintain CI and test execution parity.

*Include batch execution bash and Python scripts with LGPL-2 licensing to serve as reference migration templates for the community.
2026-09-03 14:16:53 -06:00
David RichardsonandGitHub 9cacb134c7 Merge pull request #3307 from enquora/manual-tests-navigation-viewer
Manual tests navigation viewer
2026-09-03 12:36:11 -06:00
David Richardson 17e5d32621 rename Jakefile migration script
prefix with wip- to indicate it is not yet stable.
2026-09-03 12:19:20 -06:00
David Richardson f5b305317f Improve colour scheme
Match navigation bar/masthead to https://cappuccino.dev
Highlight table row on hover
Increase visual distinction of test buttons using colour
2026-09-03 11:26:10 -06:00
David Richardson 9677609340 Improve index.html presentation
Add logotype as self-contained data URI
Improve fonts for legibility
Improve table styling
2026-09-03 10:47:29 -06:00
David Richardson ab8e47fd01 Scripts to generate and serve index HTML file for all tests
Node.js, requires no additional interpreter or dependencies.
Generates a single index.html file at root which displays launch links for all tests.
2026-09-03 09:45:37 -06:00
David Richardson a2181c88d7 Improve migrate-jakefiles.py script
Move to ./Tests/Manual
Hard-code root path to ./
Exclude sibling Jakefile
2026-09-03 09:24:53 -06:00
David Richardson 1a9ff9ffb7 Provision framework dependencies for manual integration tests
Previously, the Tests/Manual integration suite lacked an automated mechanism to provision the required Frameworks directories, leaving test applications unexecutable or reliant on stale, manually copied dependencies.

This commit introduces a Jake task to automatically provision a shared, symlinked Frameworks cache for all manual test applications, ensuring dependencies remain synchronized with the current framework build. Additionally, it adds documentation detailing the architecture and execution of the manual test suite.
2026-09-02 18:32:11 -06:00
David Richardson cc4b0e2540 Jakefile Narwhal => Node migration script, initial effort 2026-09-01 20:03:32 -06:00
David RichardsonandGitHub 87e0a6fe34 Merge pull request #3304 from cappuccino/ToolsTest-disable
Disable ToolsTest unit
2026-08-31 10:13:32 -06:00
David Richardson 45d9f10a89 Disable ToolsTest unit
Unable to modify test so that it is successful both locally and on GitHub.
Tests Node hosted tooling which is deprecated and will not receive further support.

Expedient solution is to simply disable the test.
2026-08-31 10:11:39 -06:00
David RichardsonandGitHub 93937e8b1b Merge pull request #3303 from enquora/Address-failing-array-tests
test: disable unasserted performance benchmarks in CPArray suites
2026-08-31 09:52:15 -06:00
David Richardson bdc2b7cd67 test: disable unasserted performance benchmarks in CPArray suites
Prefix unasserted performance tests with 'disabled_' in CPArrayControllerTest
and CPArrayPerformanceTest to eliminate wall-clock timing noise from standard
CI runs.

Add a dummy assertion to CPArrayPerformanceTest to maintain runner
compatibility without executing obsolete micro-benchmarks.
2026-08-31 09:49:44 -06:00
David RichardsonandGitHub b6ba250f82 Merge pull request #3301 from enquora/_CPAutocompleteMenu-fix-cold-build-warning
Fix undeclared _clientView instance variable in CPRulerView
2026-08-28 20:58:43 -06:00
David Richardson 4a5a25bb65 Fix undeclared _clientView instance variable in CPRulerView
Declare _clientView within the CPRulerView instance variable block.

This resolves a cold build compilation failure where the Objective-J parser flags assignments to the undeclared variable as illegal global variable creations.
2026-08-28 20:57:03 -06:00
David RichardsonandGitHub bc1889c7d4 Merge pull request #3300 from enquora/Update-GitHub-Actions
ci: Restrict Node.js test matrix to version 24.x
2026-08-28 20:39:02 -06:00
David Richardson 5471c38905 ci: Restrict Node.js test matrix to version 24.x
Modify GitHub Actions workflows to execute strictly against Node.js 24.x.
* Reduced the execution matrix in BuildAndTest.yml to remove deprecated and redundant runtimes (versions 20 through 23).
* Explicitly pinned the setup-node step in main-branch-publish-manual-tests.yaml to version 24.x.

This eliminates unnecessary CI resource consumption. Node 24 is the active LTS, and exhaustive version testing is no longer warranted for the legacy infrastructure given the transition to the native Go toolchain.
2026-08-28 20:36:45 -06:00
David RichardsonandGitHub 9866dd49bb Merge pull request #3299 from enquora/CPTimeZoneTest-fix
Fixes: CPTimeZoneTest, CPTimeZone, and CPDate
2026-08-28 20:01:10 -06:00
David Richardson a6969bc756 Fix CPDate string initialization to respect explicit time zone offsets
The initWithString: method previously initialized the underlying JavaScript Date object using the local-time constructor (new Date(year, month, day)).
This caused the resulting absolute time to be corrupted by the host engine's local time zone configuration, effectively ignoring the explicit time zone offset provided in the initialization string.

The implementation was a fundamental violation of the canonical contract, as established by NSDate and to be followed by CPDate.

This commit refactors the parsing logic to use Date.UTC(), guaranteeing that the parsed components are evaluated independently of the host environment.

Additionally, it eliminates a redundant RegExp allocation during pattern matching and updates the API documentation to explicitly state that offset resolution is decoupled from both CPTimeZone and the host's local time rules.
2026-08-28 19:59:11 -06:00
David Richardson 23dff002a4 Fix CPTimeZone initialization and bridge prototype exceptions
The object returned by the host engine's Intl.supportedValuesOf("timeZone") lacks standard JavaScript Array prototype methods (e.g., slice, indexOf) when crossing the runtime bridge.

This previously caused exceptions in testKnownTimeZoneNamesUsesIntlWhenAvailable.

This commit resolves the exceptions by utilizing primitive JavaScript property access and zero-indexed iteration to construct a local array. This architecture safely isolates the class from bridge prototype limitations and CPArray dependencies.

Additionally, it explicitly appends the legacy aliases "GMT" and "UTC" during the manual array construction. Engines adhering to canonical IANA identifiers omit these aliases, which caused localTimeZone initialization to abort in UTC-bound CI environments.

Guaranteeing their presence resolves the null evaluation failure in testSecondsFromGMTForDate.
2026-08-28 19:46:46 -06:00
David Richardson 03b875697e Fix CPTimeZone initialization failure in UTC environments
Intl.supportedValuesOf("timeZone") returns canonical IANA identifiers, omitting legacy aliases such as "GMT" and "UTC". This causes localTimeZone to evaluate to nil when the host engine operates in a UTC time zone, as abbreviationDictionary statically maps these aliases.

We explicitly append "GMT" and "UTC" to the dynamic knownTimeZoneNames array. This ensures invariant preservation for static dictionary lookups, guarantees successful object initialization across all UTC-bound environments, and resolves the evaluation in testSecondsFromGMTForDate on CI runners.
2026-08-28 19:22:56 -06:00
David Richardson d717e07d5c Add offset-based fallback for local-zone abbreviation resolution
* Fix a GitHub CI failure on a UTC-configured runner. Name-based resolution previously found no candidate, and abbreviationForDate returned no value.

* Add a fallback mechanism that uses the system's current UTC offset when a name match fails.

* Ensure correct abbreviation resolution, regardless of the zone name string that the runtime reports.
2026-08-28 19:07:32 -06:00
David Richardson c39f03823a Replace date-string parsing in CPTimeZone with Intl API
* Update abbreviationForDate and _abbreviationForNameAndDate to read the short time zone name directly from Intl.DateTimeFormat(...).formatToParts(). This replaces regular expression parsing of date strings.

 * Update knownTimeZoneNames to use Intl.supportedValuesOf('timeZone') to retrieve the complete IANA time zone set. The method falls back to the legacy 48-city list if Intl is unavailable.

* Replace duplicate regular expression logic in testInitWithNameRespectsDaylightSaving with a direct Intl call.

* Add pinning tests for the recently corrected offsets and the unchanged MSD value.

* Add a feature-detected test for the knownTimeZoneNames upgrade.

* Add two disabled tests to document unresolved gaps: non-English localizedName outputs and ambiguous reverse offset lookups.

* The full IANA-identity redesign as a separate task. Abbreviation-keyed lookups, colliding offsets, and English-only localizedName limitations remain unresolved in this interim fix.
2026-08-28 14:19:46 -06:00
David Richardson f3a04f23f8 Fix incorrect UTC offsets in CPTimeZone abbreviation table
* Correct timeDifferenceFromUTC values for MDT, WAT, NZDT, NZST, and WIT.

* Update MSK to the current constant UTC+3 offset. Russia abolished Daylight Saving Time in 2014.

* Leave MSD unchanged. Add an inline comment explaining that Moscow Summer Time no longer exists and assigning a new offset would fabricate data.

* Track future work to replace this static table with Intl-backed lookup from browsers’ internal values.

This future lookup will include a protocol seam for:
* runtimes without complete timezone data.
* developers who cannot tolerate non-current information from browser update latency or have other individual need.
2026-08-28 13:59:05 -06:00
David RichardsonandGitHub 0089785713 Merge pull request #3281 from enquora/CPTreeNode-improve-tests
Improve and extend CPTreeNode tests

Structural gaps still exist in CPTreeNode, covered as comments in CPTreeNodeTest.
Issue to be created for these.
2026-08-28 13:38:57 -06:00
David Richardson 3a140b07fe Fix child-node index arithmetic and expand CPTreeNode test coverage
CPTreeNode.j:
* Correct index calculations in insertObject:inChildNodesAtIndex: and replaceObjectInChildNodesAtIndex:withObject:. Nodes no longer misplace during same-parent or cross-parent moves.
 * Update _removeChildNode: to call removeObjectFromChildNodesAtIndex:. This ensures detaches notify childNodes observers on the original parent.

CPTreeNodeTest.j:
* Add test coverage for same-parent replacement, cycle rejection on replace-path, KVO during cross-parent moves, mutableChildNodes proxy operations, insertion bounds, non-recursive sorting, isLeaf, and descendantNodeAtIndexPath: edge cases.
* Disable same-parent childNodes KVO test. CPKeyValueObserving.j coalesces nested change notifications on the same key, which drops the inner removal event.
* Disable parentNode KVO test. No setParentNode: method exists to instrument.
* Add inline comments to both disabled tests explaining these mechanisms.
2026-08-28 13:35:27 -06:00
David Richardson 74039c799a Merge branch 'main' into CPTreeNode-improve-tests 2026-08-27 22:05:19 -06:00
David RichardsonandGitHub b3e2ed1071 Merge pull request #3297 from enquora/CPException-fix-missing
Fix undefined function call in CPArray range/argument exceptions
2026-08-27 22:04:25 -06:00
David Richardson 1f8e75388d Fix undefined function call in CPArray range/argument exceptions
Foundation/CPException.j: _CPRaiseRangeException and _CPRaiseInvalidArgumentException called METHOD_CALL_STRING(), undefined anywhere.

Every out-of-bounds CPArray access threw an
uncatchable JS ReferenceError instead of CPRangeException/
CPInvalidArgumentException.
Fixed to call the existing _CPMethodCallString(anObject, aSelector).

Tests/Foundation/CPArrayTest.j, CPMutableArrayTest.j: the defect
was invisible because test_objectAtIndex_ and test_objectsAtIndexes_
checked only that something was thrown, not what.
Added exception-identity checks, and fixed ConcreteArray/ConcreteMutableArray's
objectAtIndex: overrides, which threw a plain string and would have
failed the new checks.
2026-08-27 21:57:37 -06:00
David Richardson ee0c6fdf2d CPTreeNodeTest: fix child-move index arithmetic; correct a flawed test expectation
CPTreeNode: same-parent child moves no longer misplace the moved node — this corrects a defect in the class itself, properly exposed by the test.

Separately, the unit test's expectation for a root node's index path was itself wrong.
Corrected to match the class's existing, contract-correct behavior.

Test unit now runs cleanly.
2026-08-27 16:54:31 -06:00
David Richardson 54b7d24081 Merge branch 'main' into CPTreeNode-improve-tests 2026-08-27 16:02:08 -06:00
daboe01andGitHub bf76c7d2c7 Merge pull request #3241 from daboe01/setBoundsSize-fix
Fixed: scale accumulation in scaleUnitSquareToSize: when setting bounds size
2026-08-27 22:37:45 +02:00
daboe01andGitHub bad82ee587 Merge pull request #3296 from daboe01/pageunloadfix2
fix: replace legacy `unload` event listener cleanup with `pagehide`
2026-08-27 19:40:57 +02:00
daboe01 16beb1a86c fix: replace legacy unload event listener cleanup with pagehide 2026-08-27 19:28:31 +02:00
David Richardson 690b79f113 Revert "Merge pull request #3260 from enquora/modernize-CALayer"
This reverts commit 8134b6dff7, reversing
changes made to 7083f7b268.
2026-08-27 11:20:41 -06:00
David Richardson 4d13785119 Revert "Merge pull request #3257 from enquora/modernize-CABackingStore"
This reverts commit 5bdac195fc, reversing
changes made to 8134b6dff7.
2026-08-27 11:20:30 -06:00
David Richardson 4f29b77d65 Revert "Merge pull request #3261 from enquora/modernize-CPPlatformpasteboard"
This reverts commit 10351c3d4a, reversing
changes made to 5bdac195fc.
2026-08-27 11:20:20 -06:00
David Richardson be08bed01e Revert "Merge pull request #3256 from enquora/modernize-cgcontext-canvas"
This reverts commit e107e2d804, reversing
changes made to 10351c3d4a.
2026-08-27 11:19:56 -06:00
daboe01andGitHub e107e2d804 Merge pull request #3256 from enquora/modernize-cgcontext-canvas
Modernize CGContextCanvas.j: Remove CPP macros and legacy fallbacks
2026-08-27 10:06:21 +02:00
daboe01andGitHub 10351c3d4a Merge pull request #3261 from enquora/modernize-CPPlatformpasteboard
Refactor CPPlatformPasteboard: Remove CPP macros and legacy IE fallbacks
2026-08-27 10:00:33 +02:00
daboe01 67b4798caa formatting 2026-08-26 20:57:53 +02:00
daboe01 301e940236 formatting 2026-08-26 20:56:38 +02:00
daboe01andGitHub 5bdac195fc Merge pull request #3257 from enquora/modernize-CABackingStore
Refactor CABackingStore: Eliminate preprocessor directives and legacy…
2026-08-26 20:52:08 +02:00
daboe01andGitHub 8134b6dff7 Merge pull request #3260 from enquora/modernize-CALayer
Modernize CALayer, remove macro defined access in favour of ivar
2026-08-26 20:50:47 +02:00
daboe01andGitHub 7083f7b268 Merge pull request #3226 from daboe01/CPLanguageModel-and-friends
New: CPSystemLanguageModel and CPLanguageModelSession
2026-08-26 20:48:59 +02:00
daboe01andGitHub 72d2b22088 Merge pull request #3278 from daboe01/disable-googletranslator
new: prevent google translator in cappuccino
2026-08-26 20:47:40 +02:00
daboe01andGitHub acf410776d Merge pull request #3279 from daboe01/whitespace-cleanup
fixed: usage of tab character instead of 4 spaces
2026-08-26 20:46:52 +02:00
daboe01andGitHub 82f82190a1 Merge pull request #3294 from daboe01/right-contraint
new: constrain tab stop marker movement between preceding text and adjacent tab stops
2026-08-26 19:18:04 +02:00
daboe01 f85ac1ea10 new: constrain tab stop marker movement between preceding text and adjacent tab stops 2026-08-26 19:16:12 +02:00
daboe01andGitHub b6a245c852 Merge pull request #3293 from daboe01/tabstop-contraint
new: constrain tab stop marker dragging to preceding text boundary
2026-08-26 19:05:09 +02:00
daboe01 874792fa6e new: constrain tab stop marker dragging to preceding text boundary 2026-08-26 19:01:32 +02:00
daboe01andGitHub 378f7bbda1 Merge pull request #3292 from daboe01/tabstop-fix
fixed: resolve tab stop skipping and dragging positioning
2026-08-26 17:59:09 +02:00
daboe01 ca13595e37 formatting 2026-08-26 17:58:39 +02:00
daboe01 22a43bcfc5 fixed: resolve tab stop skipping and dragging positioning 2026-08-26 17:56:48 +02:00
daboe01andGitHub 4c54e6cd31 Merge pull request #3291 from daboe01/rulerviewfix
fixed: indentation paddle dragging and clientView binding
2026-08-26 17:19:43 +02:00
daboe01 9ffa4decd4 fixed: indentation paddle dragging and clientView binding 2026-08-26 17:06:34 +02:00
daboe01andGitHub 389ad61251 Merge pull request #3290 from daboe01/treecontroller-selection-fix
fixed: fix selection bindings and correct KVO dependencies in CPTreeController
2026-08-25 22:36:07 +02:00
daboe01 d8dd2e8636 improved: manual test for treecontroller 2026-08-25 22:18:37 +02:00
daboe01 8d1429d063 proxy fix 2026-08-25 21:09:51 +02:00
daboe01 d1b5c08272 fixed: KVO observer was missing 2026-08-25 21:03:07 +02:00
daboe01 6ef3cf776f new: selection tests 2026-08-25 20:39:34 +02:00
daboe01 0a6f2e569a fixed: fix selection bindings and correct KVO dependencies in CPTreeController 2026-08-25 20:35:09 +02:00
David Richardson ae409d05c1 Convert tabs to spaces 2026-08-21 09:21:51 -06:00
David Richardson 6b732da749 Merge branch 'main' into CPTreeNode-improve-tests 2026-08-21 08:54:19 -06:00
David RichardsonandGitHub 45741365f4 Merge pull request #3289 from enquora/IvarTest-fix-test-warnings
Include inline comment for IvarTest wrt warning
2026-08-20 22:02:46 -06:00
David Richardson 2c86863258 Include inline comment for IvarTest wrt warning
In this one case, a warning is the expected output and is the only viable way to test the case.
See inline comment at top of IvarTest.j for explanation.
2026-08-20 22:00:53 -06:00
David RichardsonandGitHub 8994806789 Merge pull request #3288 from enquora/CPSetTest-fix-test-warning
Fix static analysis warnings for unused iteration variables in Founda…
2026-08-20 21:23:40 -06:00
David Richardson e51f0df1a6 Fix static analysis warnings for unused iteration variables in Foundation tests
The `for...of` syntax tests in `CPSetTest` and `CPDictionaryTest` iterate over empty collections. This leaves the bound variables unread, which triggers the static analyzer and fails the zero-warning CI policy.

Standard Javascript idioms for handling blank identifiers (such as `_` or pure evaluation via `void`) are either unsupported or cause AST collisions within the Node.js parser. The variables are now explicitly evaluated using native Objective-J message sends. This registers a read operation for the analyzer, preserves the legacy parser's structural expectations, and ensures the runtime state remains pristine.
2026-08-20 21:21:56 -06:00
David RichardsonandGitHub a8a0c64a2a Merge pull request #3287 from enquora/_CPFontPanelPreviewView-address-build-warning
Clear _CPFontPanelPreviewView build warning
2026-08-20 20:15:40 -06:00
David Richardson 5449561fe2 Clear _CPFontPanelPreviewView build warning
CPFontPanel.j used _CPFontPanelPreviewView as an ivar type and instantiated it before its own @implementation, later in the same file, with no forward declaration. Added @class _CPFontPanelPreviewView, alongside the file's existing forward declarations.

This removes all build warnings.
2026-08-20 20:14:14 -06:00
David RichardsonandGitHub 073fae648e Merge pull request #3286 from enquora/CPTabStopType-clear-build-warning
Remove CPTabStopType build warning
2026-08-20 20:07:33 -06:00
David Richardson 6121caf75d Remove CPTabStopType build warning
CPParagraphStyle.j defined CPTabStopType's four constants directly, with a comment noting they were "missing" but no @typedef for the type itself.

_CPRTFParser.j uses CPTabStopType as an ivar type and imports CPParagraphStyle.j directly, so the fix belongs in the defining file.

Added the missing @typedef CPTabStopType, same pattern as CPRulerOrientation.
2026-08-20 20:05:38 -06:00
David RichardsonandGitHub 253d6669eb Merge pull request #3285 from enquora/CPRulerOrientation-address-build-warning
Address CPRulerOrientation build warning
2026-08-20 19:59:14 -06:00
David Richardson 533a1d46eb Address CPRulerOrientation build warning
CPRulerView.j declared CPRulerOrientation's constants directly,
with only a comment claiming it was a typedef.

No @typedef directive existed, so the type was unknown wherever used as an ivar or parameter type.

Added the missing @typedef CPRulerOrientation, matching the pattern already used for CPTextAlignment in CPText.j.
2026-08-20 19:57:35 -06:00
David Richardson c0b4fbfeb1 Merge branch 'main' into CPTreeNode-improve-tests 2026-08-20 16:31:42 -06:00
David RichardsonandGitHub f6d96bbf17 Merge pull request #3284 from enquora/CPTextTab-resolve-build-warnings
Add missing CPTextTab forward declaration in CPRulerView
2026-08-20 16:30:02 -06:00
David Richardson 52658b636a Add missing CPTextTab forward declaration in CPRulerView
CPRulerView.j referenced CPTextTab (isKindOfClass: and alloc/init) without a declaration.

Added @class CPTextTab; to resolve the symbol reference. A forward declaration was utilized rather than importing CPParagraphStyle.j to minimize dependency coupling, despite the absence of a circular import risk.

Resolves build warning.
2026-08-20 16:28:02 -06:00
David RichardsonandGitHub c32994af66 Merge pull request #3283 from enquora/_CPTableTextAttachment-resolve-build-warning
Fix build warnings in _CPTableTextAttachment
2026-08-20 15:35:15 -06:00
David Richardson a1ac821678 Fix build warnings in _CPTableTextAttachment
Replaced the CPTextView.j import with forward declarations for CPTextView and CPTextContainer (the latter previously reached via the removed import).

The previous import graph created a circular dependency (_CPTableTextAttachment.j -> CPTextView.j -> _CPRTFParser.j / _CPRTFProducer.j -> _CPTableTextAttachment.j).

This caused the legacy compiler to emit a class registration warning during clean builds, as the class was unregistered at the time of resolution. Incremental builds masked this warning via cached symbol tables.

Using forward declarations breaks the cycle and ensures warning-free clean and incremental builds.
2026-08-20 15:31:45 -06:00
David RichardsonandGitHub 548ed836a0 Merge pull request #3282 from enquora/CPScrollView-address-build-warnings
Remove CPScrollView build warning
2026-08-19 20:28:51 -06:00
David Richardson 78a0ebab6e Remove CPScrollView build warning
CPRulerView.j did not import CPScrollView.
A direct import would create a cycle, since CPScrollView.j already imports CPRulerView.j.
Added a forward declaration instead.
2026-08-19 20:23:33 -06:00
David Richardson fad987641b Improve and extend CPTreeNode tests 2026-08-19 11:41:39 -06:00
David RichardsonandGitHub 3aa053e7a8 Merge pull request #3280 from enquora/CPOutlineView-build-warnings-cleanup
Fix CPOutlineView build warnings and audit+improve CPTreeNode
2026-08-19 11:05:17 -06:00
David Richardson 7aebf371e9 Back out CPTreeNodeTest for addition under separate PR
GitHub CI uses existing CPTreeNodeTest and fails when new tests are included.

New tests must be added as a separate PR, independently of the changes in CPTreeNode.j
2026-08-19 10:31:15 -06:00
David Richardson ac8ce3eec3 Fix CPOutlineView build warnings and audit+improve CPTreeNode
CPOutlineView.j used CPTreeNode before AppKit.j imported it. This
triggered build warnings. This commit adds an import.

- Add @import "CPTreeNode.j" to CPOutlineView.j.

While addressing this warning, CPTreeNode was audited and found to have an algorithmic complexity regression and multiple structural inconsistencies in the KVO support code.

The test suite for CPTreeNode was Spartan in the extreme.

All of these have been addressed - see inline notes for details.
CPTreeNode is subject to further audit.
2026-08-19 10:11:20 -06:00
daboe01 567ec55875 fixed: usage of tab character instead of 4 spaces 2026-08-18 19:46:22 +02:00
daboe01 59569dcb34 new: prevent google translator in cappuccino 2026-08-17 18:20:09 +02:00
David RichardsonandGitHub 3b09a5bde6 Merge pull request #3277 from enquora/CPStackView-build-warnings-cleanup
Fix CPStackView compile errors and add minimal correctness fixes
2026-08-14 20:12:35 -06:00
David Richardson 01f7f9b601 Fix CPStackView compile errors and add minimal correctness fixes
CPStackView.j emited warnings during builds and tests which constituted
either real errors or indeterminate state.

These included four types that did not exist: CPUserInterfaceLayoutOrientation, CPLayoutAttribute,
CPEdgeInsets, and CPMapTable.

The missing types are now present.

- Add local typedefs for CPUserInterfaceLayoutOrientation and
  CPLayoutAttribute. Numeric values match the equivalent Cocoa
  constants.
- Add CPEdgeInsets as an alias for the existing CGInset struct.
  Add CPEdgeInsetsMake and CPEdgeInsetsEqualToEdgeInsets.
- Import Foundation/CPMapTable.j. CPMapTable already exists in
  Foundation.

This commit also fixes two logic errors found during review.

- arrangedSubviews did not match the true view order after
  insert or remove. Add _rebuildArrangedSubviews and call it
  from every method that changes view order.
- Trailing-gravity layout added one extra spacing gap past the
  last view. This shifted the returned layout boundary. Spacing
  is now added before each view, not after.

This commit adds one new property.

- Add a distribution property with storage and accessors. It
  has no effect on layout yet. This makes the property honest:
  before this change, the type existed but no property did.

The manual test, ./Tests/Manual/CPStackViewTest, used a Narwhal-era
Jakefile and would not build. This has been updated to reflect
usage under the Node toolchain.

This commit adds CPStackView.j to AppKit.j. The file was never
imported. Only the build script's wildcard file list included
it.

This commit adds a header comment to CPStackView.j. The comment
states that the class is a placeholder. It lists known
limitations. It states that a constraint-solver based
replacement is planned.

Why: CPStackView must compile and pass tests before capp-build
can use this tree as a build reference, and a class with unstated
limits invites misuse.
2026-08-14 20:09:17 -06:00
David RichardsonandGitHub 907ff374e6 Merge pull request #3273 from enquora/add-property-copy-test
Add test for @accessors(copy)
2026-08-13 16:51:51 -06:00
David Richardson a786418e19 Add test for @accessors(copy)
@accessors(copy) had no test in ./Tests.
The compiler's copy-accessor setter behaviour was unverified.

Add CopyAccessorTest.j to Tests/Objective-J. It asserts three
properties of the generated setter:
- the stored value is not identical to the assigned object
- the stored value is unaffected by later mutation of the original
- the stored value is equal in content to the original at assignment

This is added both as a matter of good coverage for the existing toolchain and so that new tooling has a reference for a piece of foundational behaviour.
2026-08-13 16:42:57 -06:00
daboe01andGitHub 6448f7ea12 Merge pull request #3272 from daboe01/pageunloadfix
replace unload event listener with pagehide
2026-08-13 14:16:09 +02:00
daboe01 ce2803f354 replace unload event listener with pagehide and add DOM safety checks 2026-08-12 16:58:12 +02:00
David RichardsonandGitHub 7e3d22b10e Merge pull request #3270 from enquora/CPMapTable-fix-build-warning
Fix legacy compiler warnings in CPMapTable
2026-08-12 07:50:43 -06:00
David Richardson 84dab55993 Fix legacy compiler warnings in CPMapTable
Using ES6 destructuring in the `for...of` loop declaration
(`var [key, value] of _map.entries()`) causes the legacy
Objective-J compiler to emit "uninitialized global variable"
warnings for `key` and `value`.

This raises concerns about variable scoping and generates
unacceptable noise in the CI pipeline. To resolve the warnings,
the loop has been restructured to use standard array indexing
inside the loop body.

A TODO has been added to revert to ES6 destructuring once the
legacy compiler is retired.
2026-08-11 13:04:05 -06:00
David Richardson f53a922ed4 Merge branch 'main' into aristo3 2026-08-11 08:18:52 -06:00
David RichardsonandGitHub 60a143eb7c Merge pull request #3268 from cappuccino/readme-aristo3-testing
Update README to reflect testing branch for the Aristo3 theme
2026-08-10 20:27:02 -06:00
David Richardson aa961ff518 Update README to reflect testing branch for the Aristo3 theme 2026-08-10 20:17:30 -06:00
daboe01 40cdc9108a Merge remote-tracking branch 'upstream/main' into Aristo3 2026-08-10 18:21:37 +02:00
David RichardsonandGitHub bbdc7e1fe1 Merge pull request #3266 from enquora/modernize-isNumeric-macro
Remove _IS_NUMERIC macro in favour of concrete function CPIsNumeric()

- Create Foundation/_CPFoundationUtilities.j to house global low-level utilities.
- Implement CPIsNumeric as a concrete JavaScript function, preserving the exact legacy logic.
- Import _CPFoundationUtilities.j in the Foundation.j umbrella manifest.
- Replace _IS_NUMERIC macro calls at all call sites with CPIsNumeric().
2026-08-05 13:50:00 -06:00
David Richardson b62721d79a Remove _IS_NUMERIC macro in favor of concrete funtion CPIsNumeric()
- Create Foundation/_CPFoundationUtilities.j to house global low-level utilities.
- Implement CPIsNumeric as a concrete JavaScript function, preserving the exact legacy logic.
- Import _CPFoundationUtilities.j in the Foundation.j umbrella manifest.
- Replace _IS_NUMERIC macro calls at all call sites with CPIsNumeric().
2026-08-05 13:47:28 -06:00
David RichardsonandGitHub 450db2678a Merge pull request #3265 from enquora/modernize-CPNumberFormatter-remove-cpp-directives
Foundation: remove preprocessor macro from CPNumberFormatter.j
2026-08-04 19:48:17 -06:00
David Richardson 02a5434e4f Foundation: remove preprocessor macro from CPNumberFormatter.j
Replace SET_NEEDS_NUMBER_HANDLER_UPDATE() with inline statements.
Add a comment at each of the 6 call sites to state the reason.
No behavior change.
2026-08-04 19:46:09 -06:00
David RichardsonandGitHub 51b10e2bc4 Merge pull request #3258 from enquora/modernize-CPTimer
Refactor CPTimer: Remove CPP dependencies and mark legacy anti-patterns
2026-08-04 19:09:46 -06:00
David RichardsonandGitHub 8cb3d7771c Merge pull request #3264 from enquora/modernize-_CPArray-cpp
refactor(foundation): expand placeholder redirection macro in CPArray
2026-08-04 18:42:58 -06:00
David Richardson 4ef40ff151 refactor(foundation): expand placeholder redirection macro in CPArray
Remove the pre-processor dependency on FORWARD_TO_CONCRETE_CLASS by  inlining the class cluster instantiation routing logic across all designated initializers to support the new Go-based toolchain architecture.
2026-08-04 18:40:57 -06:00
David RichardsonandGitHub d7e5c2ccac Merge pull request #3259 from enquora/modernize-CPNumber
Refactor CPNumber: Remove CPP macros and modernize syntax
2026-08-04 18:11:59 -06:00
David Richardson f414fae60a Replace tabs with spaces
Tab indentation inadvertenly applied previously.
2026-08-04 18:09:27 -06:00
David RichardsonandGitHub a6c57b7128 Merge pull request #3263 from enquora/modernize-CPException-inline-method-call-string
Refactor METHOD_CALL_STRING macro to Javascript function

Replace the unhygienic METHOD_CALL_STRING() C pre-processor macro 
in CPException.j with a standard JavaScript helper function, 
_CPMethodCallString().

Add a `// MARK: - Exception Utilities` navigation landmark. 

This removes a legacy text-substitution dependency, enabling 
single-pass AST generation for the native compilation pipeline.
2026-08-04 17:52:30 -06:00
David Richardson cbf1d35f24 Refactor METHOD_CALL_STRING macro to Javascript function
Replace the unhygienic METHOD_CALL_STRING() C pre-processor macro
in CPException.j with a standard JavaScript helper function,
_CPMethodCallString().

Add a `// MARK: - Exception Utilities` navigation landmark.

This removes a legacy text-substitution dependency, enabling
single-pass AST generation for the platform-native compilation pipeline.
2026-08-04 17:47:44 -06:00
David Richardson ecf36f12cb docs: Establish v1.5.0 baseline and direct legacy users to 1.4.0
Merge Aristo3 theme and make it default.
Update README to reflect transition to Cappuccino 2.
Change README extension from .markdown to .md for universal editor support.
2026-08-04 15:00:41 -06:00
daboe01 69c8c3d0a2 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-07-25 19:26:39 +02:00
daboe01 fa79df4309 Merge remote-tracking branch 'upstream/main' 2026-07-25 19:22:16 +02:00
David Richardson c97839905c Refactor CPPlatformPasteboard: Remove CPP macros and legacy IE fallbacks
As part of the ongoing technical debt cleanup, this commit modernizes
CPPlatformPasteboard.j by removing its reliance on the C-preprocessor
and stripping obsolete Internet Explorer compatibility code.

Key changes:
- Inlined the `SUPPRESS_CAPPUCCINO_CUT_FOR_EVENT` and `SUPPRESS_CAPPUCCINO_PASTE_FOR_EVENT`
  macros directly to standard property assignments.
- Removed the IE `srcElement` fallback in `hasEditableTarget`.
- Removed the IE `attachEvent`/`detachEvent` branch in `createDOMElements`,
  keeping only the standard `addEventListener` path.
- Replaced `var` with `const` and `let` for proper block scoping and immutability.
- Retained the `#if PLATFORM(DOM)` guards to protect the Node.js CI during
  the phased modernization effort.

All changes are annotated with `// MODIFICATION:` comments for clear
review tracking.
2026-07-23 17:22:36 -06:00
David Richardson d34149b236 Modernize CALayer, remove macro defined access in favour of ivar 2026-07-23 17:02:28 -06:00
David Richardson d9d3e5d613 Refactor CPNumber: Remove CPP macros and modernize syntax
Key changes:
- Removed the `CAST_TO_INT` macro and replaced it with native ES6
  `Math.trunc()` for float truncation.
- Replaced `var` with `let` for proper block scoping.
- Simplified boolean coercion in `boolValue` using the `!!` operator.
- Replaced the hostile `throw new Error` in `descriptionWithLocale:`
  with a safe fallback to `self.toString()`.
- Added `FIXME` comments to explicitly document architectural
  anti-patterns, including the global mutable state in `CPNumberUIDs`
  and the unimplemented `decimalValue` method.
2026-07-23 16:37:06 -06:00
David Richardson a745af8ead Refactor CPTimer: Remove CPP dependencies and mark legacy anti-patterns
As part of the ongoing technical debt cleanup, this commit modernizes
CPTimer.j by removing its reliance on the C-preprocessor and updating
syntax to modern JavaScript standards.

Key changes:
- Replaced `#define CPTimerDefaultTimeInterval` with a native `const`.
- Replaced `var` with `const`/`let` for proper block scoping and immutability.
- Replaced the build-time `PLATFORM(DOM)` guard with a runtime
  `typeof(window) !== 'undefined'` check, ensuring Foundation does not
  depend on build-time platform flags.
- Added `FIXME` comments to explicitly document architectural anti-patterns:
  - The invasive global override of `window.setTimeout` and `window.setInterval`.
  - The use of `new Function` for string evaluation (CSP violation).
  - The questionable exposure of `CPTimerDefaultTimeInterval` as a fallback.
2026-07-23 15:26:31 -06:00
David Richardson 6e0d2f97cc Refactor CABackingStore: Eliminate preprocessor directives and legacy compatibility
* Remove PIXEL macro and replace with native inline string concatenation.
* Remove CPHTMLCanvasFeature branching and obsolete CGBitmapGraphicsContextCreate fallback.
* Convert var declarations to block-scoped const.
* Standardize global function assignments to explicit C-style declarations.
* Remove unused CPCompatibility.j import.
2026-07-23 14:48:08 -06:00
David Richardson e288ea3690 Modernize CGContextCanvas.j: Remove CPP macros and legacy fallbacks
As part of the ongoing effort to remove the C-preprocessor (CPP) from
the new Lisette compiler pipeline, this commit refactors CGContextCanvas.j
to use native JavaScript and HTML5 Canvas APIs directly.

Key changes:
- Removed all `#define` macros that wrapped standard Canvas API calls
  (e.g., `_CGContextMoveToPointCanvas`). Direct method invocations are
  now used, eliminating the preprocessor pass and simplifying AST generation.
- Removed the `CPJavaScriptCanvasTransformFeature` runtime check and its
  complex mathematical fallbacks (`scale_rotate`, `rotate_scale`, `eigen`).
  Modern target environments universally support native canvas transformations.
- Removed obsolete vendor-prefixed line dash properties (`webkitLineDash`,
  `mozDash`) in favor of the standard `setLineDash`.
- Replaced `var` with `const`/`let` for proper block scoping and immutability.
- Replaced the `ROUND` macro with standard `Math.round`.

These changes strip away 2008-era browser compatibility hacks and micro-optimizations, resulting in cleaner, more maintainable, and strictly browser-targeted code.
2026-07-21 16:54:35 -06:00
David RichardsonandGitHub 87c1727ea0 Merge pull request #3255 from enquora/modernize-pragma-mark
Replace objc directive with native Javascript version // MARK: to facilitate elimination of pre-processing pass.
2026-07-21 16:16:00 -06:00
David Richardson 1a9a42ff54 Replace #pragma mark with // MARK:
Replace objc directive with native Javascript version // MARK: to facilitate elimination of preproccsing pass.
2026-07-21 15:15:53 -06:00
David RichardsonandGitHub 5592056351 Merge pull request #3254 from enquora/cleanup-formatting
Cleanup formatting in CPSet class cluster.
Align variable declarations.
Convert Xcode landmarks from c preprocessor pragmas to objj-native // MARK:
2026-07-21 11:11:53 -06:00
David Richardson 98bfd87446 Convert Xcode code landmarks from Objective-C to native Javascript
While objc `#pragma mark` works in objj files, it requires a preprocessor to handle the directive.

// MARK: is the fully functional and correct Objective-J variant.
2026-07-21 11:05:11 -06:00
David Richardson 3f63be7290 Align variable declarations 2026-07-21 10:56:38 -06:00
daboe01andGitHub b23d0cb8eb Merge pull request #3251 from daboe01/ruleeditor-drag-fix
fixed: CPRuleEditor: crash when dragging nested compound rows
2026-07-11 14:24:54 +02:00
daboe01andGitHub 0da009d1b9 Merge pull request #3246 from daboe01/markdown-manual-test
new: manual test for CPMarkdownParser
2026-07-11 13:51:37 +02:00
daboe01 b1fade86fe formatting 2026-07-11 13:51:04 +02:00
daboe01 04bad947e3 fixed: CPRuleEditor: crash when dragging nested compound rows 2026-07-10 16:14:29 +02:00
David RichardsonandGitHub f2cdb08e76 Merge pull request #3249 from enquora/resolve-duplicate-category-CPSet
Deconstruct _CPSet monolithic layout and relocate KVO proxies
2026-07-08 18:37:24 -06:00
David Richardson da3b0b5e21 fix(Foundation): implement valueForKey: for CPSet KVC compliance
Resolves testKVCCountSetOperators failure in CPSetTest. The previous implementation lacked an override for valueForKey:, causing the runtime to fall back to the default CPObject behavior, which failed to recognize KVC collection operators (e.g., @count).

Delegating valueForKey: to valueForKeyPath: ensures that CPSet correctly routes KVC operations through the existing collection operator logic.
2026-07-08 18:28:49 -06:00
David Richardson a240d312d0 Deconstruct _CPSet monolithic layout and relocate KVO proxies
•	Refactor @implementation _CPKVCSet and CPObject (CPSetKVO) from _CPSet.j to the tail of CPMutableSet.j.
•	Fix legacy compiler parse failures by ensuring the CPMutableSet superclass symbol is fully resolved within the translation unit prior to proxy evaluation.
•	Maintain strict DAG compliance across the modern toolchain pipeline topology.
•	Embed explicit #pragma mark navigation landmarks and enforce Allman brace layout to improve human structural ergonomics.
2026-07-08 17:35:33 -06:00
David RichardsonandGitHub bd48e2055e Merge pull request #3248 from enquora/foundation-resolve-duplicate-methods
Remove duplicate CPIndexSet -isEqual
2026-07-08 10:18:41 -06:00
David Richardson 42c212df64 Remove duplicate CPIndexSet -isEqual
Originally added in error, not realizing another author had just applied and committed the same fix.

Javascript-based tooling unable to catch this.
2026-07-08 10:16:25 -06:00
David RichardsonandGitHub 59e811328f Merge pull request #3247 from enquora/remove-import-cycles-foundation
Break Foundation import cycles for strict graph sorting
2026-07-08 09:16:16 -06:00
David Richardson 317c1a1475 Break Foundation import cycles for strict graph sorting
Disentangle circular dependencies Foundation framework primitives using
forward declarations.
2026-07-08 08:58:53 -06:00
daboe01 a93e67662b new: manual test for CPMarkdownParser 2026-06-26 19:42:42 +02:00
daboe01 a42f597463 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-24 16:54:37 +02:00
daboe01 14379b1be9 Merge remote-tracking branch 'upstream/main' 2026-06-24 16:53:48 +02:00
daboe01andGitHub 2e8767509e Merge pull request #3245 from daboe01/textview-selection-fix
new: Prefer e.data to capture the exact inserted character(s) from ke…
2026-06-24 16:53:22 +02:00
daboe01 429dfd7467 new: Prefer e.data to capture the exact inserted character(s) from key entry 2026-06-24 16:50:05 +02:00
daboe01 a1eddb9e50 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-21 17:36:16 +02:00
daboe01 71a7b54edd Merge remote-tracking branch 'upstream/main' 2026-06-21 17:36:04 +02:00
daboe01andGitHub ad05fbe97b Merge pull request #3244 from daboe01/textview-stalenes-fix
Fixed: CPLayoutManager false-positive layout rescue on zero-length-delta edits
2026-06-21 17:35:30 +02:00
daboe01 0fed962b37 Fixed: CPLayoutManager false-positive layout rescue on zero-length-delta edits 2026-06-21 17:30:18 +02:00
daboe01 29163884ce Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-20 17:54:23 +02:00
daboe01 ee36796180 Merge remote-tracking branch 'upstream/main' 2026-06-20 17:52:48 +02:00
daboe01 cff2fd8ed9 optimized version 2026-06-20 17:51:11 +02:00
daboe01 344cbd0660 formatting 2026-06-20 15:01:35 +02:00
daboe01 e6e676c91e more safety checks 2026-06-20 15:00:21 +02:00
daboe01 5fd2f49266 safety checks 2026-06-20 14:55:27 +02:00
daboe01 10fb3e6d31 Fixed: scale accumulation in scaleUnitSquareToSize: when setting bounds size 2026-06-20 14:35:15 +02:00
daboe01andGitHub 535315485a Merge pull request #3235 from daboe01/paste-as-plain-text
New: standard key binding for pasteAsPlainText:
2026-06-20 14:10:49 +02:00
daboe01 aa592b8bc6 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-20 12:37:15 +02:00
daboe01andGitHub 88146a5389 Merge pull request #3240 from daboe01/baseline-fix
Fixed: baseline alignment in _CPLineFragment to prevent overlapping text descenders
2026-06-20 12:36:57 +02:00
daboe01 c8789c5450 formatting 2026-06-20 12:32:10 +02:00
daboe01 766035f4b7 Fixed: baseline alignment in _CPLineFragment to prevent overlapping text descenders 2026-06-20 12:06:24 +02:00
daboe01andGitHub a90b504dc7 Merge pull request #3239 from daboe01/more-cptextview-fixes
new: heightTracksTextView support in CPTextContainer + rtf fixes
2026-06-20 10:42:26 +02:00
daboe01 26b2280fc2 fixed: color spill issue 2026-06-20 10:40:46 +02:00
daboe01 15bbca8d77 fixed: whitespace issue 2026-06-20 10:36:07 +02:00
daboe01 319bcdaba9 fixed: table roundtrip issue 2026-06-19 22:56:38 +02:00
daboe01 89445f94a2 fixed: whitespace before tab 2026-06-19 22:26:52 +02:00
daboe01 beb4aef424 new: heightTracksTextView support in CPTextContainer 2026-06-19 09:47:39 +02:00
daboe01andGitHub ef680c080d Merge pull request #3238 from daboe01/baseline-fixes
New: implement baseline offsets and superscript/subscript support
2026-06-19 08:52:06 +02:00
daboe01 c187f5de1d fixed: rtf roundtrip with baseline stuff 2026-06-19 08:48:17 +02:00
daboe01 d40a151e05 new: colorpanel sync 2026-06-19 07:18:52 +02:00
daboe01 e67c141921 new: color panel 2026-06-18 22:21:50 +02:00
daboe01 de2ffd3aad New: implement baseline offsets and superscript/subscript support 2026-06-18 19:08:45 +02:00
daboe01 4c8fd58471 fixed: leaky abstraction 2026-06-17 19:22:36 +02:00
daboe01 873a102872 New: standard key binding for pasteAsPlainText: 2026-06-17 18:24:31 +02:00
daboe01 6dc11de431 Revert "New: standard key binding for pasteAsPlainText:"
This reverts commit 9731c4b394.
2026-06-17 18:21:26 +02:00
daboe01 672f25ce27 New: standard key binding for pasteAsPlainText:
This reverts commit 9731c4b394.
2026-06-17 18:20:39 +02:00
daboe01 9731c4b394 New: standard key binding for pasteAsPlainText: 2026-06-17 18:18:39 +02:00
daboe01 b2c5955e7d Merge remote-tracking branch 'upstream/main' into CPLanguageModel-and-friends 2026-06-17 16:21:24 +02:00
daboe01 e0ce1603ff Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-17 16:21:09 +02:00
daboe01andGitHub bc0380e1cb Merge pull request #3233 from daboe01/fixed-Unable-to-preventDefault-inside-passive-event
new: register wheel event listeners as non-passive
2026-06-17 16:20:37 +02:00
daboe01 1223cfc965 new: register wheel event listeners as non-passive 2026-06-17 16:10:39 +02:00
daboe01 2f63a5fd10 formatting 2026-06-17 08:25:24 +02:00
daboe01 b827310c75 Merge remote-tracking branch 'upstream/main' into CPLanguageModel-and-friends 2026-06-17 08:09:34 +02:00
daboe01andGitHub 361a4203da Merge pull request #3232 from daboe01/table-in-textview-fixes
fixed: table sizing
2026-06-17 08:09:17 +02:00
daboe01 8de928d905 formatting 2026-06-17 08:07:26 +02:00
daboe01 5a3d6e30cb fixed: table sizing 2026-06-17 07:58:33 +02:00
daboe01 227eda9d92 new: spinner in manual test 2026-06-17 07:57:17 +02:00
daboe01 9fe0df74b3 formatting 2026-06-16 20:20:25 +02:00
daboe01 381c1880c2 cleanup 2026-06-16 20:15:34 +02:00
daboe01 5439e5d473 Merge remote-tracking branch 'upstream/main' into CPLanguageModel-and-friends 2026-06-16 19:48:16 +02:00
daboe01 0597e477ae Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-16 19:46:20 +02:00
daboe01andGitHub 50bac0a470 Merge pull request #3230 from daboe01/setfontfix
Fixed: CPInvalidArgumentException in CPTextField -setFont: when handling composite theme states
2026-06-16 19:45:49 +02:00
daboe01 cfff603508 Fixed: CPInvalidArgumentException in CPTextField -setFont: when handling composite theme states 2026-06-16 19:43:45 +02:00
daboe01 b9e734a21b Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-16 19:32:18 +02:00
daboe01 45bd822c28 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-16 19:31:19 +02:00
daboe01andGitHub 894a60ad45 Merge pull request #3229 from daboe01/rtf-producer-table-interface
NEW: add table support and other improvements to CPTextView
2026-06-16 19:28:45 +02:00
daboe01andGitHub acbe5885f1 Merge branch 'main' into rtf-producer-table-interface 2026-06-16 19:24:10 +02:00
daboe01 a981b8b04d improved: indentation markers 2026-06-16 19:17:44 +02:00
daboe01 d75c0ac452 improved: tab management 2026-06-16 17:28:03 +02:00
daboe01 da061aac1d improved: table generation 2026-06-16 10:30:00 +02:00
daboe01 77433a3a1c fixed: scrolling glitch 2026-06-16 07:16:14 +02:00
daboe01 4aaa32833a fixed: table roundtrip 2026-06-15 22:33:03 +02:00
daboe01 2a0cebb851 improved: rtf roundtrip 2026-06-15 19:42:53 +02:00
daboe01 1b23bb8a67 new: CPMarkdownParser 2026-06-15 16:43:58 +02:00
daboe01 5dc66c5b4e fixed: roundtrip 2026-06-14 22:56:23 +02:00
daboe01 49b1800027 improved: table generation 2026-06-14 22:42:33 +02:00
daboe01 1cad83aba8 initial display of the table 2026-06-14 21:06:51 +02:00
daboe01andGitHub e1f5238063 Merge pull request #3228 from daboe01/textview-dom-fix
removed: dead code
2026-06-13 22:47:30 +02:00
daboe01 5897d76c04 fixed: imports 2026-06-13 22:38:36 +02:00
daboe01 a0fc7723fc new: table support 2026-06-13 22:36:09 +02:00
daboe01andGitHub ec4a1d1724 Merge pull request #3225 from daboe01/textfield-setfontfix
fixed: ensure custom fonts are respected in all states, styles, and CIBs
2026-06-13 22:27:11 +02:00
daboe01 6139216146 new: RTFProducer PROTOCOL METHOD ADDITIONS 2026-06-13 19:53:39 +02:00
daboe01 861c504c41 NEW: add native table support via dynamic protocol detection 2026-06-13 19:47:24 +02:00
daboe01 c9df6e4d25 removed: dead code 2026-06-13 19:18:12 +02:00
daboe01 c9d3ccdf0d fixed: top was not applied to style 2026-06-13 18:42:34 +02:00
daboe01 2c275b279b new: markdown support in manual test 2026-06-13 18:13:51 +02:00
daboe01 44f6e0fded cosmetic fixes 2026-06-13 16:38:40 +02:00
daboe01 e5278fd17e new: run loop management 2026-06-13 16:30:16 +02:00
daboe01 1bd3c93717 formatting 2026-06-13 16:22:34 +02:00
daboe01 afc6691f07 formatting 2026-06-13 16:02:17 +02:00
daboe01 8c41c7b8ac fixed: import semantics 2026-06-13 15:54:07 +02:00
daboe01 5445d42eba Merge remote-tracking branch 'upstream/main' into CPLanguageModel-and-friends 2026-06-13 15:47:01 +02:00
daboe01andGitHub d88f2ef7c0 Merge pull request #3227 from daboe01/cptextsizefix
new: Clear the cached visible rect so it gets recalculated after size…
2026-06-13 15:46:28 +02:00
daboe01 14b5a67bf5 new: Clear the cached visible rect so it gets recalculated after size changes 2026-06-13 15:42:48 +02:00
daboe01 8e04b172ce simplification of demo 2026-06-13 15:34:21 +02:00
daboe01 5fff34be91 new: CPLanguageModel and manual test 2026-06-13 14:50:38 +02:00
daboe01 3467a60215 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-06-13 12:15:00 +02:00
daboe01andGitHub 210133d9e2 Merge pull request #3224 from daboe01/formatting-/-documentation-CPRuleEditor
new: Documentation for CPRuleEditor I8N stuff
2026-06-05 17:55:09 +02:00
daboe01 524b1df4c9 fix font issue 2026-06-05 17:38:04 +02:00
daboe01 9115949169 new: Documentation for CPRuleEditor I8N stuff 2026-06-04 21:39:02 +02:00
daboe01andGitHub 0b3aa6aac2 Merge pull request #3221 from daboe01/Fixed-CPRuleEditor-word-by-word-translation-issue
Fixed: CPRuleEditor word-by-word translation issue (#1834)
2026-06-04 14:12:08 +02:00
daboe01 e03e0c6fc4 fixed: exception after deleting the last row 2026-06-04 08:55:32 +02:00
daboe01 613a2722be new: dynamic mutilanguage demo 2026-06-04 08:15:52 +02:00
daboe01 e9b9d9702e fixed: localizer issues 2026-06-03 21:19:09 +02:00
daboe01 750c123d1e fixed: redraw issues 2026-06-03 19:19:36 +02:00
daboe01 5e0fc1cbb5 fixes + manual test 2026-06-02 22:20:44 +02:00
daboe01 831e0b4b85 new: rulerview demo 2026-06-01 20:40:52 +02:00
daboe01 d64966594d Merge remote-tracking branch 'upstream/main' into Aristo3 2026-05-30 15:12:50 +02:00
daboe01 015f027cf2 Merge remote-tracking branch 'upstream/main' 2026-05-30 15:12:31 +02:00
daboe01andGitHub c3d9dead19 Merge pull request #3192 from daboe01/fixed-CPControlTextDidBeginEditingNotification-is-not-correctly-triggered
Fixed: timing of CPControlTextDidBeginEditingNotification (#1941)
2026-05-30 15:09:34 +02:00
daboe01andGitHub b296f17d2b Merge pull request #3168 from daboe01/new-cprulerview
new: CPRulerview and friends
2026-05-30 15:08:56 +02:00
daboe01 22fdc971c7 improved: marker icons 2026-05-30 10:11:00 +02:00
daboe01 291be04dc3 improved: rtf parser 2026-05-30 09:40:25 +02:00
daboe01 5c7215c455 new: apply ruler to current paragraph in case of no selection 2026-05-30 09:25:26 +02:00
daboe01 2a83dcb64a fixed: adding new tabstops 2026-05-30 09:08:56 +02:00
daboe01 979118a86f restored: tabstop-fix 2026-05-30 08:55:25 +02:00
daboe01 4fbd50e81f revert: textTabForWidth-"fix" 2026-05-30 08:44:43 +02:00
daboe01 3b1c1c0886 fixed: tab could not be entered using the keyboard 2026-05-29 22:08:00 +02:00
daboe01 dbc8bfc7f3 fixed: pasting tab characters 2026-05-29 21:28:16 +02:00
daboe01 10bb6723f3 fixed: missing global symbols 2026-05-29 20:02:13 +02:00
daboe01 c58a5b520e fixed: tab copypaste 2026-05-29 18:19:03 +02:00
daboe01 7b6cb51f4d fixed: format menu 2026-05-29 11:45:17 +02:00
daboe01 c704880e13 improved: tabstop handles 2026-05-29 11:41:39 +02:00
daboe01 41c422ed03 new: visual feedback when "tearing off" 2026-05-29 10:55:22 +02:00
daboe01 c94ed00f41 fixed: basic ruler view support 2026-05-29 10:46:10 +02:00
daboe01 1d93cf2b1a new: cpscrollview fixes 2026-05-28 21:31:26 +02:00
daboe01 420f3a538d Update AppController.j 2026-05-28 21:23:01 +02:00
daboe01 453e8dbd2e Merge remote-tracking branch 'upstream/main' into new-cprulerview 2026-05-28 21:22:55 +02:00
daboe01 c6549867bd fixed: missing global variable 2026-05-28 21:13:42 +02:00
daboe01 3aecb3ea98 fixed: missing import 2026-05-28 21:11:51 +02:00
daboe01 2819546716 fixed: missing import 2026-05-28 21:07:43 +02:00
daboe01 7e0f03a6fc fixed: CI error 2026-05-28 21:03:31 +02:00
daboe01 6e36fc0b20 formatting 2026-05-28 17:51:10 +02:00
daboe01 e856605a09 _CPRuleEditorViewSliceRow integration 2026-05-28 17:38:14 +02:00
daboe01 d7315773e1 fixed: syntax issues 2026-05-28 17:15:41 +02:00
daboe01 a27aaf8bd0 Fixed: CPRuleEditor word-by-word translation issue (#1834) 2026-05-28 17:11:29 +02:00
daboe01 f2c10e9f4c Merge remote-tracking branch 'upstream/main' into Aristo3 2026-05-25 07:30:22 +02:00
daboe01andGitHub c0b875de5d Merge pull request #3220 from daboe01/rtf-parser-fix
Update _CPRTFParser.j
2026-05-25 06:59:44 +02:00
daboe01 141eb7b98e fixed: wrong characters in output 2026-05-25 06:56:32 +02:00
daboe01 6099311cbd Update _CPRTFParser.j 2026-05-25 06:48:27 +02:00
daboe01andGitHub dcb06fbc4f Fix formatting issues in README.markdown 2026-05-23 13:51:50 +02:00
daboe01andGitHub 8258c8ef0b Revise Cappuccino usage description in README 2026-05-23 13:51:25 +02:00
daboe01andGitHub 9312c96154 Clarify Cappuccino's purpose in README 2026-05-23 09:05:07 +02:00
daboe01andGitHub c27b48d27a Update documentation links in README 2026-05-23 08:46:29 +02:00
daboe01 a091a7c5d6 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-05-21 09:50:35 +02:00
daboe01andGitHub f3039fb77c Merge pull request #3219 from daboe01/cptextview-speed-fix
CPLayoutManager: Fix O(N^2) layout bottleneck when loading large text documents
2026-05-21 09:49:12 +02:00
daboe01 abe159eceb CPLayoutManager: Fix O(N^2) layout bottleneck when loading large text documents 2026-05-21 09:44:54 +02:00
daboe01 f06bdbb14f Merge remote-tracking branch 'upstream/main' into Aristo3 2026-05-19 18:53:15 +02:00
daboe01andGitHub ffb6b3e6fe Merge pull request #3218 from daboe01/cptextview-fixes
Fixed: rare layout issue after inserting multiple newlines and text layout performance improvement
2026-05-19 18:52:34 +02:00
daboe01 7f25de0fad improved: kerning safe optimization 2026-05-17 21:30:11 +02:00
daboe01 d6c5d8b4f2 formatting 2026-05-17 16:47:12 +02:00
daboe01 78e1ea43c8 new: layouting speedup in CPTextView 2026-05-17 15:58:16 +02:00
daboe01andGitHub 9d24c855e2 Update project status in README
Removed outdated information and clarified project status.
2026-05-06 19:55:15 +02:00
daboe01andGitHub 872af9ce2a Revise Cappuccino introduction and project status
Reorganized and condensed introductory information about Cappuccino, emphasizing its purpose and benefits for building desktop-class applications.
2026-05-06 19:54:43 +02:00
daboe01 76a3d0b6da improved: cancel button aesthetics in search field 2026-04-12 12:49:07 +02:00
daboe01andGitHub 18b2a668c5 Merge pull request #3213 from daboe01/double-action-tableview
new: doubleClickTarget and doubleClickArgument for CPTableView
2026-04-09 22:32:00 +02:00
daboe01andGitHub 72be296713 Merge pull request #3214 from daboe01/fixed-tableview-column-removal-issue
Fixed: CPTableView bug where removing a column breaks internal state
2026-04-09 22:30:59 +02:00
daboe01 078ab40d99 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-04-08 15:26:43 +02:00
daboe01 b620991770 Merge remote-tracking branch 'upstream/main' 2026-04-08 15:26:31 +02:00
daboe01andGitHub 732fc2d1e1 Merge pull request #3215 from daboe01/cptreecontroller-fixes
Fixed: CPTreeController selection bug for asynchronously loaded nodes
2026-04-08 15:26:17 +02:00
daboe01 79a9ae31d3 Fixed: CPTreeController selection bug for asynchronously loaded nodes 2026-04-08 15:23:45 +02:00
daboe01 e0e16eeca5 formatting 2026-04-08 15:18:46 +02:00
daboe01 a784435c2b formatting 2026-04-08 15:17:46 +02:00
daboe01 57987b6f67 Fixed: CPTableView bug where removing a column breaks internal state 2026-04-06 17:26:38 +02:00
daboe01 480917eeab new: doubleClickTarget and doubleClickArgument for CPTableView 2026-04-06 13:15:55 +02:00
daboe01andGitHub 013e7bdf7e Merge pull request #3210 from daboe01/cpwebview-resize-fix
Fixed: incorrect CPWebView sizing after animation
2026-04-06 12:08:35 +02:00
daboe01andGitHub c4032ecd1d Merge pull request #3212 from daboe01/tooltip-tableview-fix
New: toolTips for CPTableView and CPOutlineView
2026-04-06 11:59:14 +02:00
daboe01 2ea11eb5ab formatting 2026-04-06 11:58:00 +02:00
daboe01 7fad67484c new: manual tests 2026-04-06 11:56:23 +02:00
daboe01 f34cbbdf29 New: toolTips for CPTableView and CPOutlineView 2026-04-04 15:00:53 +02:00
daboe01 d44dd5da19 fixed: inconsistencies in focusring 2026-04-04 10:50:48 +02:00
daboe01 35132e7f46 fixed: drag-accepting style in colorwells was missing 2026-04-04 10:44:15 +02:00
daboe01 231b3052fc Merge remote-tracking branch 'upstream/main' into Aristo3 2026-04-03 19:01:37 +02:00
daboe01 1c0cc2acef Merge remote-tracking branch 'upstream/main' 2026-04-03 19:01:23 +02:00
daboe01andGitHub 14a4b04d9b Merge pull request #3211 from daboe01/fix-colorpanel-issues
fixed: colorpanel issue
2026-04-03 19:00:47 +02:00
daboe01 8aee2a511f fixed: colorpanel issue 2026-04-03 19:00:09 +02:00
daboe01 9bec13a72b new: color wells 2026-04-03 17:58:57 +02:00
daboe01 65cb048b1b Fixed: incorrect CPWebView sizing after animation 2026-04-03 17:40:45 +02:00
daboe01 fb348ed4f7 merge from main 2026-04-03 16:26:59 +02:00
daboe01 cf10b826d7 Merge remote-tracking branch 'upstream/main' 2026-04-03 16:01:18 +02:00
daboe01andGitHub b7ac5272d0 Merge pull request #3193 from daboe01/fixed-right-buttons-in-buttonbar
New: support for right-aligned buttons in CPButtonBar (#745)
2026-04-03 16:00:37 +02:00
daboe01 dc893f7ca3 Merge remote-tracking branch 'upstream/main' 2026-04-03 15:55:56 +02:00
daboe01andGitHub 206b1d4a05 Merge pull request #3209 from daboe01/cppredicateeditor-nil-value-fix
new: clear CPPredicateEditor rows when objectValue is set to nil
2026-04-03 15:33:10 +02:00
daboe01 0bd83b6635 new: clear CPPredicateEditor rows when objectValue is set to nil 2026-04-03 15:20:59 +02:00
daboe01 4dcfe992de Merge remote-tracking branch 'upstream/main' 2026-04-03 15:16:40 +02:00
daboe01andGitHub ef9d6662cb Merge pull request #3208 from daboe01/new-_CPKVOCollectionOperatorObserver
New:  support collection operators on child key paths
2026-04-03 14:56:29 +02:00
daboe01 0e5f3b1697 fixed caching 2026-04-03 13:49:33 +02:00
daboe01 7fbea7913a new: manual test 2026-04-03 13:39:42 +02:00
daboe01 4b81001330 new: testCollectionOperatorKeyPath 2026-04-03 13:33:06 +02:00
daboe01 043029cf41 new: _CPKVOCollectionOperatorObserver 2026-04-03 13:30:13 +02:00
daboe01 81988f1ec7 Merge remote-tracking branch 'upstream/main' 2026-03-25 19:34:03 +01:00
daboe01 e49144c80a Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-25 19:33:44 +01:00
daboe01andGitHub 9ecc739e8d Merge pull request #3186 from daboe01/colorpanel-fixes
Fix CPColorWell drag-and-drop and responder chain integration
2026-03-25 19:33:27 +01:00
daboe01 94799f19dc Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-24 21:36:21 +01:00
daboe01andGitHub 3d5f4eec18 Merge pull request #3207 from daboe01/cplocalefix
fixed: locale inference
2026-03-24 21:36:02 +01:00
daboe01 c7e89d3018 formatting 2026-03-24 21:34:39 +01:00
daboe01 63e3f6c3fc fixed single region of FF 2026-03-24 21:33:24 +01:00
daboe01 d39a583127 fixed: locale inference 2026-03-24 21:18:43 +01:00
daboe01 e1762fdcdd fixed: column dragging did not work when a panel is open 2026-03-21 11:26:42 +01:00
daboe01 f568427dc2 Merge remote-tracking branch 'upstream/main' 2026-03-15 17:44:59 +01:00
daboe01 fa077e4fc7 fixed: race condition during unfolding animation 2026-03-15 17:44:51 +01:00
daboe01 fd745d37a9 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-15 17:43:57 +01:00
daboe01 2da26b2de2 formatting 2026-03-15 17:41:51 +01:00
daboe01andGitHub 6e486bb30b Merge pull request #3205 from daboe01/fixed-missing-dom-protection
removed: erroneous code spillover
2026-03-15 17:40:54 +01:00
daboe01 5e297dd293 removed: erroneous code spillover 2026-03-15 17:39:33 +01:00
daboe01 17dc653149 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-15 17:09:21 +01:00
daboe01 63cbb04acc Merge remote-tracking branch 'upstream/main' 2026-03-15 17:09:10 +01:00
daboe01andGitHub 6f55c7bbba Merge pull request #3204 from daboe01/fixed-outlineview-animation-race-condition
fixed: racecondition in row expansion animation
2026-03-15 17:08:49 +01:00
daboe01 ea4adf1039 fixed: racecondition in row expansion animation 2026-03-15 17:08:21 +01:00
daboe01 3ff7818d58 Merge remote-tracking branch 'upstream/main' 2026-03-15 11:37:00 +01:00
daboe01 e779198a80 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-15 09:01:42 +01:00
daboe01andGitHub 3e4ebe8e47 Merge pull request #3203 from daboe01/fixed-treeviewbindings
fixed: treeview binding issues
2026-03-15 08:58:21 +01:00
daboe01 b77a374f48 formatting 2026-03-15 08:57:06 +01:00
daboe01 43936f640c formatting 2026-03-15 08:53:04 +01:00
daboe01 6671d371e9 fixed: treeview binding issues 2026-03-15 08:51:03 +01:00
daboe01 4fd99d2c52 fixed: tokenfield CPControlTextDidBeginEditingNotification notification 2026-03-14 19:25:50 +01:00
daboe01 092550e2a3 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-14 13:02:38 +01:00
daboe01andGitHub 6563e730a0 Merge pull request #3202 from daboe01/textview-caret-blinking-fix
fixed: caret is invisible at the end of the line
2026-03-14 13:02:28 +01:00
daboe01 b39c3e8d4b fixed: caret is invisible at the end of the line 2026-03-14 13:01:58 +01:00
daboe01 579129b891 fixed: usability issues with horizontal scroller 2026-03-14 12:51:46 +01:00
daboe01 ec8bb7e14d Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-13 16:04:26 +01:00
daboe01andGitHub 9f092a3c2e Merge pull request #3201 from daboe01/cptexctview-smartpaste-fix
fixed: smartpaste crash
2026-03-13 16:04:15 +01:00
daboe01 5b820b270c fixed: smartpaste crash 2026-03-13 16:03:30 +01:00
daboe01 4af4c6706f fixed: HUD scrollers 2026-03-12 19:53:41 +01:00
daboe01 da2c89daf3 Revert "stop tracking build artifacts"
This reverts commit ea425ae4c4.
2026-03-11 06:39:06 +01:00
daboe01 ea425ae4c4 stop tracking build artifacts 2026-03-11 06:35:24 +01:00
daboe01 fb9c0715b3 stop tracking generated imagesize 2026-03-11 06:34:34 +01:00
daboe01 8cedfebc07 stop tracking generated fontinfo 2026-03-11 06:34:11 +01:00
daboe01 93736b7ba9 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-11 06:29:57 +01:00
daboe01 37a6e8fde5 Merge remote-tracking branch 'upstream/main' 2026-03-11 06:29:40 +01:00
daboe01andGitHub 0274d9fee7 Merge pull request #3199 from daboe01/fixed-textsizing-via-canvas-not-functional-anymore
fixed: canvas text sizing is not functional anymore
2026-03-11 06:29:08 +01:00
daboe01 f223644640 fixed: canvas text sizing is not functional anymore 2026-03-11 06:26:10 +01:00
daboe01andGitHub 0aa4607d8e Merge pull request #3191 from daboe01/fixed-CPTextField-called-error-method-called-3-times
Fixed: multiple didFailToFormatString delegate calls in CPTextField (#1546)
2026-03-08 21:28:57 +01:00
daboe01andGitHub 37b68bb166 Merge pull request #3194 from daboe01/fixed-CPTokenField-autocomplete-does-not-work-when-placed-in-toolbar
fixed: CPTokenField autocomplete when placed in a CPToolbar
2026-03-08 21:27:59 +01:00
daboe01 e801064bd9 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-08 21:20:32 +01:00
daboe01andGitHub ae4eef5d16 Merge pull request #3156 from daboe01/cpoutlineview-delegate-fix
fixed: CPOutlineView should be its own tableView delegate and datasource
2026-03-08 21:20:09 +01:00
daboe01 fdba5f55c5 fixed> syntax error 2026-03-08 21:16:54 +01:00
daboe01 bfeaabc038 Merge remote-tracking branch 'upstream/main' into cpoutlineview-delegate-fix 2026-03-08 21:13:47 +01:00
daboe01 6b9bad37c2 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-08 21:09:57 +01:00
daboe01andGitHub a32b2d5f73 Merge pull request #3197 from daboe01/outlineview-fixes
removed: dead code
2026-03-08 21:09:20 +01:00
daboe01 9f4db09bec removed: dead code 2026-03-08 21:07:08 +01:00
daboe01 58fe3d3d27 Merge remote-tracking branch 'upstream/main' 2026-03-08 21:03:35 +01:00
daboe01andGitHub 28303a7893 Merge pull request #3196 from daboe01/new-CPTreeController
New: CPTreeController
2026-03-08 19:56:44 +01:00
daboe01 031e5e7ca3 fixed: selection issues 2026-03-08 19:52:58 +01:00
daboe01 c70079ae71 improved: bindings to CPOutlineView 2026-03-08 18:03:52 +01:00
daboe01 8ac2b94400 refac 2026-03-07 21:48:10 +01:00
daboe01 b1f2fb44a8 new: CPOutlineView bindings support 2026-03-07 21:43:41 +01:00
daboe01 cd4c3cffe0 fixed: test cases 2026-03-07 20:05:50 +01:00
daboe01 98c01b88e2 fixed various binding issues 2026-03-07 20:00:09 +01:00
daboe01 4970a2742d fixed: recursive tree building 2026-03-07 19:47:31 +01:00
daboe01 10d18e35ed formatting 2026-03-07 19:28:04 +01:00
daboe01 12960f8160 new: testcase 2026-03-07 19:27:01 +01:00
daboe01 622d738b44 new: CPTreeController 2026-03-07 19:25:32 +01:00
daboe01 4e5c0aed67 formatting 2026-03-07 17:29:49 +01:00
daboe01 96d3ad2c47 fixed: CPTokenField autocomplete when placed in a CPToolbar 2026-03-07 17:11:25 +01:00
daboe01 c519784ecc New: support for right-aligned buttons in CPButtonBar (#745) 2026-03-07 16:17:36 +01:00
daboe01 d0d7033f63 Fixed: timing of CPControlTextDidBeginEditingNotification (#1941) 2026-03-07 14:53:44 +01:00
daboe01 9aaa565657 fixed: accidental code spillover 2026-03-07 14:40:34 +01:00
daboe01 50e98d1335 Merge remote-tracking branch 'upstream/main' 2026-03-07 14:37:32 +01:00
daboe01 837df80b64 fixed: accidental code spill over 2026-03-07 14:33:31 +01:00
daboe01 f7a27cf905 fixed: delegate method was called more than once by textfield 2026-03-07 14:26:51 +01:00
daboe01 915047b996 fixed: scrollview white border view in HUD 2026-03-07 11:22:41 +01:00
daboe01 8231d8ddf1 new removal of canvas in _CPDatePickerClock 2026-03-07 10:28:47 +01:00
daboe01 125673880c fixed: cornerview in HUD 2026-03-06 19:45:55 +01:00
daboe01 b24cb2c48e fixed: disclosure triangle was canvas based 2026-03-06 19:21:55 +01:00
daboe01 a56458384c rework of tooltips to use only CSS + support for HUD 2026-03-05 08:31:01 +01:00
daboe01 063f2f0283 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-03-03 18:20:36 +01:00
daboe01andGitHub da35d6b6ed Merge pull request #3190 from daboe01/textview-copypaste-fix
Use setTimeout to prevent flickering on copy/paste
2026-03-03 18:19:59 +01:00
daboe01 fca30325e4 Use setTimeout to prevent flickering on copy/paste 2026-03-03 18:18:32 +01:00
daboe01 4aac83b50d removed: unnecessary triangle border 2026-03-02 20:57:10 +01:00
daboe01 48b4345e80 new: full animation support for CPOutlineView 2026-03-02 16:09:29 +01:00
daboe01 4636c0f3b8 fixed: double click error 2026-03-01 20:21:48 +01:00
daboe01 db5f5ba332 improved: view animation capabilities 2026-03-01 19:58:56 +01:00
daboe01 7c093e1a64 fixed: outline-view disclosure animation 2026-03-01 19:29:51 +01:00
daboe01 8f48d01c33 removed: enabled/disabled drawing emulation via alpha 2026-02-28 19:37:59 +01:00
daboe01 89d345dfdc fixed: added missing isActive 2026-02-28 19:35:51 +01:00
daboe01 1bbf87e2cb fixed: testcases 2026-02-28 18:26:47 +01:00
daboe01 ec9c658565 fixed: acceptsFirstResponder was uncoditionally true 2026-02-28 17:07:02 +01:00
daboe01 8db24fcaf6 new: testcases from enquora 2026-02-28 16:46:34 +01:00
daboe01 d9859af73c new: disabled state CPColorWell 2026-02-28 16:04:38 +01:00
daboe01 bce326de9d fixed: Colorwell did not reflect enabled state visually 2026-02-28 15:57:19 +01:00
daboe01 83bc94d1c3 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-02-23 14:25:34 +01:00
daboe01andGitHub 676ddc4601 Merge pull request #3189 from daboe01/fixed-key-duplication-on-alt
fixed: key duplication in textview on ALT
2026-02-23 14:25:19 +01:00
daboe01 19cceb4dd9 fixed: key duplication in textview on ALT 2026-02-23 14:24:09 +01:00
daboe01 3a4b8fe947 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-02-22 16:30:50 +01:00
daboe01andGitHub f31ac7cf21 Merge pull request #3188 from daboe01/windowcontenviewfix
Fixed: CPWindow setContentView: overlapping the toolbar
2026-02-22 16:30:25 +01:00
daboe01 802c644d94 Fixed: CPWindow setContentView: overlapping the toolbar 2026-02-22 14:54:46 +01:00
daboe01 5385e63fd2 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-02-22 11:33:31 +01:00
daboe01andGitHub 749909b23c Merge pull request #3187 from daboe01/fixed_keyequivalent_dom_bubbling_issue
fixed: menu key support conflicting with browser native menu keys
2026-02-22 11:32:33 +01:00
daboe01 df594ae48e fixed: copy/paste issue 2026-02-21 18:48:19 +01:00
daboe01 980e2f2c91 fixed: dom protection was missing 2026-02-21 12:08:47 +01:00
daboe01 e1a3f2b64d fixed: submenu positioning issue 2026-02-21 12:07:20 +01:00
daboe01 ea47767bb8 fixed: menu key support conflicting with browser native menu keys 2026-02-21 11:51:25 +01:00
daboe01 3d3674a7d8 fixed: out of bounds exception when dragging rule editor slices 2026-02-19 19:51:34 +01:00
daboe01 192b6ecfc4 fixed: rule editor selection 2026-02-19 19:44:11 +01:00
daboe01 79ff197cde fixed: HUD insertionpointcolor in demo app 2026-02-18 19:17:43 +01:00
daboe01 836698f8d2 fixed: caret color 2026-02-18 17:29:36 +01:00
daboe01 ac52d32c29 fixed: caret color in textview 2026-02-18 16:17:45 +01:00
daboe01 e66a0656c8 fixed: HUD style bridgewindow 2026-02-17 16:09:15 +01:00
daboe01 7dcf5629d7 fixed: combobox issue when selecting an element in placeholder state 2026-02-15 21:10:14 +01:00
daboe01 facb129183 fixed: HUD placeholder colors 2026-02-15 20:39:30 +01:00
daboe01 0b83c20648 fixed: life update 2026-02-15 19:53:17 +01:00
daboe01 0f9cadf8d3 fixed: life update 2026-02-15 19:53:00 +01:00
daboe01 c82e5750f0 fixed: the first version was not functional 2026-02-15 18:28:20 +01:00
daboe01 13557bd13f selection in colorwell 2026-02-15 18:27:01 +01:00
daboe01 2ff5eb39eb Fix CPColorWell drag-and-drop and responder chain integration 2026-02-15 12:32:13 +01:00
daboe01 dccdfb5635 fixed: popup HUD 2026-02-14 10:19:47 +01:00
daboe01 aba4c865e4 performance optimisation 2026-02-12 22:05:57 +01:00
daboe01 9709ca8b52 new: ThemingAdditions and HUD autosetter 2026-02-12 18:18:25 +01:00
daboe01 ea74a503a3 fixed: label truncation in segmented controls 2026-02-11 10:34:31 +01:00
daboe01 675d1ebd57 fixed: gap in segmented controls 2026-02-10 19:25:14 +01:00
daboe01 7eb042d985 fixed: missing dom protection 2026-02-09 19:53:01 +01:00
daboe01 dc4aa545f0 fixed: dom error 2026-02-09 19:48:46 +01:00
daboe01 b70abb730d fixed: unfocussed selection color in column 2026-02-09 19:36:44 +01:00
daboe01 36a2cc9a62 scroll out / -in fr fix 2026-02-09 18:27:20 +01:00
daboe01 113be1254e hud fix 2026-02-09 08:26:40 +01:00
daboe01 674a03dc23 fixed: table column dragging when selected 2026-02-08 22:36:22 +01:00
daboe01 9656985dbd fixed: animation header glitch 2026-02-08 20:46:07 +01:00
daboe01 0b4fe62f89 new: group row theming 2026-02-08 19:34:15 +01:00
daboe01 847a9c2b98 new: column-selection 2026-02-08 19:30:06 +01:00
daboe01 ce78d098ec group row fix 2026-02-08 19:03:09 +01:00
daboe01 18c1866db7 fixed: zebra fill 2026-02-08 17:11:17 +01:00
daboe01 1ae0566cf1 fixed: faulty test case 2026-02-08 16:00:58 +01:00
daboe01 383fb9d704 fixed: missing dom protection 2026-02-08 14:26:58 +01:00
daboe01 7f281d0442 restored: group row support 2026-02-08 12:20:48 +01:00
daboe01 2d76a03b01 new: dom based tableview background 2026-02-08 09:29:29 +01:00
daboe01 f96ffde1fb Merge remote-tracking branch 'upstream/main' into Aristo3 2026-02-07 10:03:31 +01:00
daboe01andGitHub e216f0a355 Merge pull request #3184 from daboe01/fixed-wrong-event-factory-cover-method
fixed: faulty event factory covermethod
2026-02-06 16:17:17 +01:00
daboe01 0e86264837 fixed: faulty event factory covermethod 2026-02-06 16:16:08 +01:00
daboe01 39fb7c6b5b formatting 2026-02-03 08:20:15 +01:00
daboe01 0fa2b62cc9 fixed: text jumping issues on FF 2026-02-03 07:14:20 +01:00
daboe01 ea69f8b9cc fixed: clock hands in FF 2026-02-02 15:55:49 +01:00
daboe01 b0e88390e5 new: tooltip 2026-02-01 21:23:46 +01:00
daboe01andGitHub 57d0750f3c Revise README for updated application demos and tutorials
Updated links and descriptions in the README to reflect current resources.
2026-02-01 21:02:42 +01:00
daboe01 4882f26142 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-02-01 19:44:07 +01:00
daboe01andGitHub 3be864e50f Merge pull request #3180 from daboe01/cptextview-changefont-fix
fixed: crash when changing typing attributes without selection
2026-02-01 19:43:50 +01:00
daboe01 d583403195 fixed: crash when changing typing attributes without selection 2026-02-01 19:43:17 +01:00
daboe01 373737cfd0 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-02-01 19:31:27 +01:00
daboe01andGitHub 946362f0d1 Merge pull request #3179 from daboe01/calendarstepper-fix
fixed: prevent timezone shift from reverting month navigation in _CPD…
2026-02-01 19:30:54 +01:00
daboe01 7ee4003840 fixed: prevent timezone shift from reverting month navigation in _CPDatePickerCalendar 2026-02-01 19:29:59 +01:00
daboe01 475945d329 improved: A3 showcase app 2026-02-01 19:28:19 +01:00
daboe01 5111a02672 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-31 21:18:09 +01:00
daboe01andGitHub f2bebcb2e6 Merge pull request #3178 from daboe01/improved-font-panel
new: font preview in fontpanel
2026-01-31 21:17:15 +01:00
daboe01 e413f3a9fd fixed: column sizing 2026-01-31 21:12:35 +01:00
daboe01 0c4d33dccc new: font preview in fontpanel 2026-01-31 18:21:41 +01:00
daboe01 12477179cb new: calendar in demo app 2026-01-31 18:05:15 +01:00
daboe01 ab81b1ad32 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-30 22:42:05 +01:00
daboe01andGitHub 4af8fcc008 Merge pull request #3177 from daboe01/menushortcut-textviewfix
fixed: keystrokes from menu shortcuts are inserted into textviews
2026-01-30 22:41:47 +01:00
daboe01 6800472725 fixed: keystrokes from menu shortcuts are inserted into textviews 2026-01-30 22:40:35 +01:00
daboe01 0af674ca74 fixed: textview sizing 2026-01-29 20:27:11 +01:00
daboe01 5b95490371 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-29 19:17:10 +01:00
daboe01andGitHub e6b9b9cfbd Merge pull request #3176 from daboe01/fixed-cpdatepicker-relied-on-deprecated-keycode-property
Fixed cpdatepicker relied on deprecated keycode property
2026-01-29 19:14:37 +01:00
daboe01 9dfaf293f2 Removed: hardcoded KeyCodes as they are unreliable 2026-01-29 19:12:17 +01:00
daboe01 fffcc85486 fixed: cpdatepicker relied on deprecated keycode property 2026-01-29 19:06:35 +01:00
daboe01 993e9a9e86 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-28 21:42:05 +01:00
daboe01andGitHub b349b23b81 Merge pull request #3175 from daboe01/fontmanager-font-trait-fix
fixed: addFontTrait
2026-01-28 21:41:36 +01:00
daboe01 886a4a422f fixed: addFontTrait 2026-01-28 21:41:15 +01:00
daboe01 2f32e5eaef Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-28 21:24:37 +01:00
daboe01andGitHub d8dd3d0660 Merge pull request #3174 from daboe01/new-texview-format-action-methods
new: CPTextView action methods for format menu
2026-01-28 21:24:12 +01:00
daboe01 f19901c214 new: action methods for format menu 2026-01-28 21:23:03 +01:00
daboe01 fcd1897883 new: format menu 2026-01-28 21:21:56 +01:00
daboe01 77063efe58 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-28 21:01:46 +01:00
daboe01andGitHub e198fbdc40 Merge pull request #3122 from daboe01/fixed-keycode-management-in-cptextview
fixed: Keyboard-event handling is based on the deprecated charCode
2026-01-28 20:57:07 +01:00
daboe01andGitHub 3dd97c0b49 Merge pull request #3135 from daboe01/ipad-double-tap-support
improved: double click emulation by double tapping
2026-01-28 20:56:34 +01:00
daboe01 57a53abbf7 fixed: textcolor in CPBrowser selected row 2026-01-28 19:59:59 +01:00
daboe01 e30380a8f9 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-28 19:39:50 +01:00
daboe01andGitHub b93aa732d2 Merge pull request #3173 from daboe01/fixed-datepicker-nextkeyview-loop
fixed: keyview loop trap
2026-01-28 19:39:04 +01:00
daboe01 16d8780812 fixed: keyview loop trap 2026-01-28 19:38:29 +01:00
daboe01 cdcaf1c4d4 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-28 19:28:42 +01:00
daboe01andGitHub febd1260cd Merge pull request #3172 from daboe01/cptext-fix
fixed: acceptsFirstMouse was missing
2026-01-28 19:24:57 +01:00
daboe01 45162a3fcb fixed: acceptsFirstMouse was missing 2026-01-28 19:24:29 +01:00
daboe01 e62b22da55 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-28 07:46:28 +01:00
daboe01andGitHub b598e80c58 Merge pull request #3171 from daboe01/textual-picker-key-navi-fix
Fixed: CPDatePicker tab navigation when elements are hidden
2026-01-28 07:28:01 +01:00
daboe01 41648b8605 Fixed: CPDatePicker tab navigation when elements are hidden 2026-01-28 07:26:02 +01:00
daboe01 7bd8660f89 browser hud 2026-01-28 07:22:58 +01:00
daboe01 d0c63345f2 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-27 20:04:29 +01:00
daboe01andGitHub 6b285cd7f0 Merge pull request #3170 from daboe01/fontpanel-fixes
fixed: fontpanel was crashing
2026-01-27 20:04:15 +01:00
daboe01 a5e9d65852 fixed: fontpanel was crashing 2026-01-27 20:03:05 +01:00
daboe01 1a7b7054fb improved: animation 2026-01-27 19:46:49 +01:00
daboe01 01fc279709 improved: animation 2026-01-27 19:41:18 +01:00
daboe01 5540ef8ca7 new: triangle animation in outline view 2026-01-26 22:38:49 +01:00
daboe01 ef3ee2e660 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-26 19:47:33 +01:00
daboe01 d661c83acc fixed disclosure colors in outlineview 2026-01-26 07:32:35 +01:00
daboe01 437bcc8078 revert: cpoutlineview 2026-01-26 07:26:22 +01:00
daboe01andGitHub 94195237d9 Merge pull request #3169 from daboe01/calayer-fixes
fixed: group animation semantics and test
2026-01-26 07:18:24 +01:00
daboe01 b8f63166cd fixed: group animation semantics and test 2026-01-26 07:18:02 +01:00
daboe01 68316732de improved: alert panels 2026-01-26 07:08:00 +01:00
daboe01 0a42b39a94 Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-25 19:35:20 +01:00
daboe01andGitHub fc91326a5f Merge pull request #3147 from daboe01/new-caanimationgroup
New: CAAnimationGroup and implement timer-based animations in CALayer
2026-01-25 19:34:34 +01:00
daboe01 0fc2ed7081 new: manual test 2026-01-25 19:33:33 +01:00
daboe01 8433d4a1d1 new: support for kCAMediaTimingFunctionEaseInEaseOut 2026-01-25 17:25:17 +01:00
daboe01 ac1407484a fixed: outlineview arrow colors 2026-01-25 17:19:07 +01:00
daboe01 a531dc6fc0 improved: demo app 2026-01-25 11:45:23 +01:00
daboe01 e42d5b860e fixed: A3 demo app layout issues 2026-01-24 19:25:01 +01:00
daboe01 57858db161 new: CPOutlineView 2026-01-24 19:15:37 +01:00
daboe01 f3392c7df1 fixed: RuleEditor was not functional 2026-01-24 16:55:26 +01:00
daboe01 18c2145138 fixed HUD rule editor 2026-01-24 12:14:08 +01:00
daboe01 ff6981bf10 fixed: HUD table view issues 2026-01-23 22:38:05 +01:00
daboe01 db82911b1f fixed: circular slider HUD 2026-01-23 19:52:36 +01:00
daboe01 768f5121cb fixed: column D&D animation issue when dragging outside 2026-01-23 19:47:53 +01:00
daboe01 c2d7a1dc74 cpstepper HUD fix 2026-01-23 19:39:41 +01:00
daboe01 61efb2fcdf ruleeditor fixes 2026-01-22 17:20:17 +01:00
daboe01 b6716f77e0 improved A3 app 2026-01-22 17:07:17 +01:00
daboe01 47c4bb957b fixed: datepicker in demoapp 2026-01-22 16:42:37 +01:00
daboe01 1a64819ab5 fixed: segmented control height 2026-01-22 16:08:09 +01:00
daboe01 ff7939df03 micro alignement fixes 2026-01-22 14:52:43 +01:00
daboe01 443ced0dce text baseline fixes 2026-01-22 08:15:15 +01:00
daboe01 baf505df52 HUD pulldown fix 2026-01-22 07:21:12 +01:00
daboe01 90331b075a hud popup fixes 2026-01-21 22:53:21 +01:00
daboe01 900e3b6ea1 fixed: pulldown HUD 2026-01-21 22:44:47 +01:00
daboe01 74d8463255 fixed: button types in A3 demo 2026-01-21 22:27:59 +01:00
daboe01 af6692d616 fixed: HUD stuff 2026-01-21 19:57:12 +01:00
daboe01 6611b74c19 HUD fixes 2026-01-21 19:53:01 +01:00
daboe01 37bff8b70b buttonbar HUD fixes 2026-01-21 17:16:28 +01:00
daboe01 d964b9f10a fixed: HUD combobox selection color 2026-01-21 09:57:44 +01:00
daboe01 189a2ddc3d fixed: combox textcolor in tableviews 2026-01-21 09:54:40 +01:00
daboe01 641b35d965 fixed: hud tableview header 2026-01-21 07:52:19 +01:00
daboe01 433e6606b6 new: CPBox in A3 test app 2026-01-21 07:36:00 +01:00
daboe01 bc88af047e fixed: hud for tableviews 2026-01-20 22:49:43 +01:00
daboe01 b93beb8730 improved: A3 demo 2026-01-20 07:28:35 +01:00
daboe01 24a176c736 improved: A3 kitchensink 2026-01-19 22:08:12 +01:00
daboe01 4d741040b6 fixed: CPSegmentedControl crash 2026-01-19 19:21:28 +01:00
daboe01 92a30edf6c fixed: textcolor in tableviews 2026-01-19 18:39:20 +01:00
daboe01andGitHub 2615577173 Fix Kitchen Sink demo link in README
Updated the link for the Kitchen Sink demo in the README.
2026-01-19 07:50:18 +01:00
daboe01 031c3acc57 new: hud split view 2026-01-18 22:39:14 +01:00
daboe01 500541a785 new: box hud 2026-01-18 22:33:57 +01:00
daboe01 60e01cdb33 fixed HUD recycling issue with popups 2026-01-18 19:48:40 +01:00
daboe01 c0c5325d8a fixed: circular slider disabled HUD 2026-01-18 15:27:03 +01:00
daboe01 fbe4b3d439 fixed: HUD combobox 2026-01-18 14:43:28 +01:00
daboe01 aa72c9e081 new: HUD button bar 2026-01-18 13:51:08 +01:00
daboe01 91db2f409e popup fix 2026-01-18 13:47:08 +01:00
daboe01 2c2211026f fixed: colors in levelindicator 2026-01-18 13:44:59 +01:00
daboe01 578f00172f improved: A3 demo app 2026-01-17 19:47:46 +01:00
daboe01 fb93d3dcf0 fixed: levelindicator 2026-01-17 19:42:46 +01:00
daboe01 10989ada31 fixed: segmented control hud 2026-01-17 19:29:48 +01:00
daboe01 28e9063c04 fixed: tokenfield HUD 2026-01-17 18:03:22 +01:00
daboe01 63ec5e78b6 fixed: stepper in HUD 2026-01-17 17:59:05 +01:00
daboe01 52f6503631 new: combobox HUD 2026-01-17 16:00:05 +01:00
daboe01 a5a91d7258 fixed: HUD issues 2026-01-17 11:22:08 +01:00
daboe01 a00b94ec33 new: KitchenSinkA3 (code only) 2026-01-17 09:13:32 +01:00
daboe01 78b1e292f9 fixed: comboboxes in tableviews 2026-01-16 23:34:08 +01:00
daboe01 d9d86df1bd formatting 2026-01-16 23:26:30 +01:00
daboe01 b5f9f05f9f formatting 2026-01-16 23:25:05 +01:00
daboe01 245561d40f fixed: nib2cib crashes with CPProgressIndicator 2026-01-16 23:22:23 +01:00
daboe01 9301ba7c25 fixed: button positions 2026-01-16 19:45:06 +01:00
daboe01 24e9eadfab fixed: button positions 2026-01-16 19:43:24 +01:00
daboe01 fe8f2deb6e shifted push buttons from IB 2px to the left 2026-01-16 19:00:06 +01:00
daboe01 5aa315e190 fixed: syntax errors 2026-01-16 17:17:00 +01:00
daboe01 d180a25f2e new: CPRulerview and friends 2026-01-16 17:08:50 +01:00
daboe01 1ae19f88b9 revert: nib2cib adjustment for push buttons 2026-01-16 17:02:38 +01:00
daboe01 50702a0560 fixed: combobox alignment issues 2026-01-16 09:39:07 +01:00
daboe01 fbee21dad3 removed: off-spec autostart of spinners 2026-01-16 08:56:20 +01:00
daboe01 13c3fe5771 fixed: missing visual feedback in buttobar gear icon 2026-01-15 22:44:28 +01:00
daboe01 fde9f56d4d fixed: nib2cib adjustment for push buttons 2026-01-15 19:32:46 +01:00
daboe01 f2ca8ab940 make control heights more consistent 2026-01-15 18:54:42 +01:00
daboe01 3d0b1b7680 fixed: window-close-button and friends did not highlight 2026-01-15 08:42:46 +01:00
daboe01 40172028e6 improved: progress indicators 2026-01-15 08:16:11 +01:00
daboe01 49923fa140 fixed: progress indicators 2026-01-15 07:47:10 +01:00
daboe01 b96a4e5b94 fixed textfield alignment issues 2026-01-14 19:44:40 +01:00
daboe01 9a50fc4789 fixed: pulldown glitch 2026-01-14 10:56:26 +01:00
daboe01 601daf9e72 fixed: docmodal black bar on top 2026-01-13 22:40:38 +01:00
daboe01 2658852ec2 Update ThemeDescriptors.j 2026-01-13 21:41:36 +01:00
daboe01 737fd115e4 fixed: button issues 2026-01-13 20:19:47 +01:00
daboe01 461f341abc fixed: button HUD styles 2026-01-12 20:27:04 +01:00
daboe01 c26feeb73e formatting 2026-01-11 19:49:47 +01:00
daboe01 29714ae18f default theme aristo3 in segmented control test 2026-01-11 19:22:07 +01:00
daboe01 496f934adb fixed: HUD menu scrolling indicator issues 2026-01-11 18:54:47 +01:00
daboe01 bf15c2bf11 fixed: scroll indicators in menus 2026-01-11 09:10:54 +01:00
daboe01 07cf8ac9be checkbox / radio / segmented control cleanup 2026-01-11 08:58:43 +01:00
daboe01 9708f80ad4 new: HUD animations 2026-01-11 08:28:58 +01:00
daboe01 0bd0dc6216 fixed: diverse HUD issues 2026-01-11 00:04:12 +01:00
daboe01 d3e5583070 new: HUD for scrollers 2026-01-10 17:25:40 +01:00
daboe01 10eedb2bb5 realign rounded textured with push buttons (IB correction) 2026-01-10 16:39:53 +01:00
daboe01 d381a602b7 move IB push buttons 6 pixels downward 2026-01-10 16:36:18 +01:00
daboe01 266251ffbf new: HUD support 2026-01-10 13:24:33 +01:00
daboe01 cd9bb7a86e make popup 0,5px larger 2026-01-10 12:46:33 +01:00
daboe01 97f98e3c93 Revert "fixed: popup-position from IB"
This reverts commit c72c761a60.
2026-01-10 12:41:27 +01:00
daboe01 c72c761a60 fixed: popup-position from IB 2026-01-10 10:19:08 +01:00
daboe01 2fe83853ac Revert "fixed: popup-position from IB"
This reverts commit cd940d64ed.
2026-01-10 10:12:51 +01:00
daboe01 cd940d64ed fixed: popup-position from IB 2026-01-10 10:08:44 +01:00
daboe01 15d4575b0a fixed: CPRuleEditor 2026-01-09 21:45:50 +01:00
daboe01 e21d23e911 fixed: popup-position from IB 2026-01-09 21:16:40 +01:00
daboe01 9e649ce96a fixed: sorting arrow was too small 2026-01-07 22:44:09 +01:00
daboe01 68526721b7 fixed: textured rounded button issues 2026-01-07 19:36:13 +01:00
daboe01 be3c5dac8a minor segmented control adjustment 2026-01-07 17:25:52 +01:00
daboe01 26cac2b84d removed: old artwork 2026-01-06 22:30:15 +01:00
daboe01 2f552abf94 fixed: disclosure button issue in outline view 2026-01-06 19:52:36 +01:00
daboe01 7129ebe884 removed: old artwork 2026-01-06 19:33:26 +01:00
daboe01 b9992215f8 new: make theme selectable in outline test 2026-01-06 19:32:49 +01:00
daboe01 0c55a5f372 removed: old artwork 2026-01-06 18:26:08 +01:00
daboe01 8cc33d1e37 fixed: datepicker 2026-01-06 18:15:40 +01:00
daboe01 73169f0be5 new: datepicker theme selectability 2026-01-06 11:30:27 +01:00
daboe01 7f8d3f289b fixed: splitview issues 2026-01-06 10:58:25 +01:00
daboe01 d8c74e81b8 fixed: button sizing issues 2026-01-06 10:29:46 +01:00
daboe01 3000254e67 formatting 2026-01-06 09:13:08 +01:00
daboe01 2356340f0b fixed: toolbar overplotting issue 2026-01-05 23:06:03 +01:00
daboe01 227d743666 fixed: pulldown menu 2026-01-05 22:25:53 +01:00
daboe01 b53feeb04c fixed: tokenfield issues 2026-01-05 19:53:30 +01:00
daboe01 3b1043a6b4 alternative image in button bar 2026-01-04 22:25:51 +01:00
daboe01 ba32f92e69 buttonbar fixes 2026-01-04 16:52:07 +01:00
daboe01 5c7d978245 fixed: #3059 2026-01-04 15:11:09 +01:00
daboe01 d96b642f4f fixed: #3051 2026-01-04 15:03:30 +01:00
daboe01 2366c5c1fd fixed: momentary push issue 2026-01-04 14:52:48 +01:00
daboe01 84a85a767c updated gear icon 2026-01-04 14:24:56 +01:00
daboe01 e0c9bd10a4 fixed: popupbutton were invisible when created in code 2026-01-04 11:33:07 +01:00
daboe01 eed6c93349 fixed: combo-box small and mini 2026-01-03 23:15:34 +01:00
daboe01 7023bb8b90 new: svg images for alert panel 2026-01-03 22:51:45 +01:00
daboe01 579814a5de fixed: images did not show in alert panels 2026-01-03 21:01:53 +01:00
daboe01 a2786a9aee fixed: image and shadow issues 2026-01-03 19:44:24 +01:00
daboe01 bcd0c725ce fixed: datepicker clipping issue 2026-01-02 23:25:29 +01:00
daboe01 3c1c01fd9f Merge remote-tracking branch 'upstream/main' into Aristo3 2026-01-02 21:53:59 +01:00
daboe01 3364d1c5cc code cleanup + refac to use svg instead of bitmap 2026-01-02 21:53:37 +01:00
daboe01andGitHub 8d61a5fbe1 Correct release year in project status
Update project status release year from 2025 to 2026.
2025-12-31 09:18:30 +01:00
daboe01 b2cd64b956 Revert "fixed: test-cases"
This reverts commit 53488c0adb.
2025-12-28 21:15:13 +01:00
daboe01 53488c0adb fixed: test-cases 2025-12-28 21:14:29 +01:00
daboe01andGitHub ca9b8a78b2 Merge pull request #3167 from michaelbach/main
Fix #3166: zero width/height for svg images
2025-12-27 22:15:15 +01:00
Michael BachandGitHub c05b900fe6 improve formatting of fox 2025-12-27 21:58:00 +01:00
Michael BachandGitHub 907450a63d Fix zero width/height for svg images 2025-12-27 21:38:14 +01:00
daboe01andGitHub 6b1e308dab Merge pull request #3157 from daboe01/fixed-does-not-properly-transform-the-DOMElements-bounds-if-the-view-has-a-non-zero-origin
Fixed: [CPView addSubview:] was ignoring bounds origin for DOM positioning
2025-12-26 12:34:21 +01:00
daboe01andGitHub e28df7d7d7 Merge pull request #3164 from daboe01/cpmenu-sticky-fix
Cpmenu top level item sticky selection fix
2025-12-26 12:21:47 +01:00
daboe01andGitHub 84d3a820f2 Merge pull request #3152 from daboe01/new-menu-icon-placement-issue-fix
new: Left-align menu bar icon and title
2025-12-26 12:16:01 +01:00
daboe01 dda325b51b fixed: wrong target for bounds 2025-12-26 12:09:15 +01:00
daboe01 f0e29069a9 fixed: sticky main menu selection issue 2025-12-26 12:06:18 +01:00
daboe01andGitHub 4730c23a97 Merge pull request #3154 from daboe01/Fixed-CPMenu-items-appearing-on-the-wrong-side-of-the-menu-bar
Fixed: CPMenu items appearing on the wrong side of the menu bar
2025-12-26 11:56:24 +01:00
daboe01andGitHub 593d098cc1 Merge pull request #3153 from daboe01/fixed-Main-menus-with-no-items-appear-in-the-menu-bar
new: Hide main menu items that do not have submenus
2025-12-26 11:51:52 +01:00
daboe01andGitHub 2e15f351a9 Merge branch 'main' into fixed-Main-menus-with-no-items-appear-in-the-menu-bar 2025-12-26 11:48:12 +01:00
daboe01 14a195592a new manual test 2025-12-26 11:43:54 +01:00
daboe01andGitHub 7c81471a3a Merge pull request #3149 from daboe01/new-CPMenu-Item-Change-Reflection
fixed: Update CPMenu immediately when a CPMenuItem changes
2025-12-26 11:36:42 +01:00
daboe01 42ea1a5972 new: manual test 2025-12-26 11:34:40 +01:00
daboe01andGitHub 1da107c404 Merge pull request #3160 from daboe01/new-CPStackView
new: CPStackView
2025-12-26 11:21:14 +01:00
daboe01 b2ada8a76f formatting 2025-12-26 11:16:46 +01:00
daboe01 5ac90c163a new: manual test 2025-12-26 11:10:44 +01:00
daboe01andGitHub 53e7d14e1f Merge pull request #3161 from daboe01/fixed-CPRuleEditor-did-not-resize-the-rhs-view-after-the-ruleeditor-has-been-shrunken
Fixed: CPRuleEditor rows did not resize after being shrunken
2025-12-26 11:01:50 +01:00
daboe01andGitHub 186e2e6130 Merge pull request #3150 from daboe01/fixed-when-performing-key-equivalent-for-a-MenuItem,-the-top-most-menu-item-should-highlight
new: Highlight top-level menu item when performing key equivalent
2025-12-26 10:53:18 +01:00
daboe01andGitHub fefa603b45 Merge pull request #3158 from daboe01/fixed-CPDocument-sends-windowWillClose-message-twice
fixed: CPDocument sends windowWillClose: message twice
2025-12-26 10:44:27 +01:00
daboe01 99cf8e6387 improved logic 2025-12-26 10:42:41 +01:00
daboe01andGitHub 53b4fe4fdc Merge pull request #3162 from daboe01/fixed-Toolbar-items-show-now-visual-feedback-when-clicked
Fixed: Toolbar items show now visual feedback when clicked
2025-12-26 10:21:34 +01:00
daboe01andGitHub 6773df15b9 Merge pull request #3163 from daboe01/new-slideback-animation-after-failed-drag
new: slideback animation after failed drag
2025-12-26 10:12:32 +01:00
daboe01 bc64d147a8 fixed: used wrong approach 2025-12-25 19:56:15 +01:00
daboe01 569f93549e new: slideback animation after failed drag
new: slideback animation after failed drag
2025-12-25 17:23:54 +01:00
daboe01andGitHub 2045d1eaeb Add cappuccino bin directory to .gitignore 2025-12-09 17:56:47 +01:00
daboe01 a2595093f8 Fixed: Toolbar items show now visual feedback when clicked 2025-12-07 21:23:07 +01:00
daboe01 9a9c9b8481 Fixed: CPRuleEditor rows did not resize after being shrunken 2025-12-07 19:46:11 +01:00
daboe01 99ec1af301 new: CPStackView 2025-12-07 18:14:52 +01:00
daboe01 f3fe384df1 fixed: CPDocument sends windowWillClose: message twice 2025-12-07 11:28:53 +01:00
daboe01 c7f3dd5b0f Fixed: [CPView addSubview:] was ignoring bounds origin for DOM positioning 2025-12-07 11:21:11 +01:00
daboe01 547be633b6 fixed: CPOutlineView should be its own tableView delegate and datasource 2025-12-07 09:18:36 +01:00
daboe01 a88002861b Fixed: CPMenu items appearing on the wrong side of the menu bar 2025-12-06 19:48:18 +01:00
daboe01 395022d652 new: Hide main menu items that do not have submenus 2025-12-06 19:39:53 +01:00
daboe01 dd24de5daf new: Left-align menu bar icon and title 2025-12-06 19:32:52 +01:00
daboe01 3c02cf5358 new: Highlight top-level menu item when performing key equivalent 2025-12-06 19:15:59 +01:00
daboe01 bf0f0ab509 fixed: Update CPMenu immediately when a CPMenuItem changes 2025-12-06 19:09:55 +01:00
daboe01 3d0639b6dc fixed: use requestAnimationFrame instead of setTimeout 2025-11-21 08:18:41 +01:00
daboe01 ed50f3b654 add test 2025-11-20 22:07:44 +01:00
daboe01 25d186bf5c New: CAAnimationGroup and implement timer-based animations in CALayer 2025-11-20 19:58:24 +01:00
daboe01andGitHub e02107102c Merge pull request #3142 from daboe01/new-CPSplitViewController
new: CPSplitViewController and CPSplitViewItem
2025-11-19 19:19:50 +01:00
daboe01andGitHub 1376466939 Merge pull request #3136 from daboe01/fixed-CAKeyframeAnimation-missing-properties-and-methods
fixed: CAKeyframeAnimation missing properties and methods
2025-11-19 19:18:05 +01:00
daboe01andGitHub f2c05c4841 Merge pull request #3141 from daboe01/fixed-scrollview-missing-notifications
fixed: CPScrollView did not send some notifications
2025-11-19 19:16:29 +01:00
daboe01andGitHub 17136d23f9 NEW: for..of iterator for CPDictionary (#3113) 2025-09-25 07:27:17 +02:00
daboe01 812f69f4a7 fixed: missing splitView:effectiveRect:forDrawnRect:ofDividerAtIndex: 2025-09-24 14:20:37 +02:00
Martin CarlbergandGitHub 7f286129de Create main-branch-publish-manual-tests.yaml 2025-09-17 16:21:12 +02:00
Martin CarlbergandGitHub b92459ba38 Merge pull request #3121 from daboe01/new-CPView-is-missing-rotateByAngle-method
Fixed: CPView was missing rotateByAngle: method
2025-09-12 12:56:13 +02:00
daboe01 51e9737114 improved: documentation 2025-09-11 18:26:53 +02:00
Martin CarlbergandGitHub 66051b066f Updated to use latest version of the runtime 2025-09-09 13:00:57 +02:00
daboe01 a3cb43bad8 fixed: missing api issues 2025-09-06 08:58:59 +02:00
Martin CarlbergandGitHub ba4f0f7e4d Merge pull request #3140 from daboe01/new-CPMapTable
New: CPMapTable.j
2025-09-05 11:42:10 +02:00
Martin CarlbergandGitHub ada5887deb Node version 25 and 26 are not yet available on GitHub 2025-09-05 11:39:01 +02:00
Martin CarlbergandGitHub af148b5008 Tests run with newer Node versions. Older is removed 2025-09-05 11:33:35 +02:00
daboe01 205b645de8 fixed: import statement for CPViewController 2025-09-04 12:14:06 +03:00
daboe01 f1f0703619 fixed: imports 2025-09-04 12:11:03 +03:00
daboe01 dc23fe49af new: unit tests 2025-09-04 11:54:06 +03:00
daboe01 44de0334b7 improved: documentation 2025-09-04 11:49:59 +03:00
daboe01 de96e0c22c fixed: missing import 2025-09-03 15:57:42 +03:00
daboe01 2f5593390e new: CPSplitViewController and CPSplitViewItem 2025-09-03 15:54:40 +03:00
daboe01 0ef1239283 fixed: CPScrollView did not send some notifications 2025-09-03 15:21:44 +03:00
daboe01 258dd7ba38 fixed: several css issues 2025-09-03 13:30:47 +03:00
daboe01 3e38560620 fixed: testcase 2025-09-03 11:09:22 +03:00
daboe01 1826a14afe improved: testcase 2025-09-03 10:39:11 +03:00
daboe01 e46fc1dc77 fixed: blue box was invisible 2025-09-03 08:24:19 +03:00
daboe01 debb43c1ca fixed: timing functions 2025-09-02 18:25:35 +03:00
daboe01 da8bf0abe1 fixed: property issues 2025-09-02 18:12:04 +03:00
daboe01 92b7583f9f fixed: SVGString 2025-09-02 17:38:10 +03:00
daboe01 8950c4f0e3 fixed: variable scope issues 2025-09-02 17:25:32 +03:00
daboe01 9442f6b7d7 new: manual tests 2025-09-02 17:04:51 +03:00
daboe01 c14e08633d fixed: testcase 2025-09-02 15:51:40 +03:00
daboe01 dfbf07b10c fixed: test suite 2025-09-02 15:44:39 +03:00
daboe01 b2b29c928f fixed: testcases 2025-09-02 15:41:34 +03:00
daboe01 c56448a29c fixed: keyEnumerator 2025-09-02 15:38:00 +03:00
daboe01 42a00edbd8 fixed: objectEnumerator 2025-09-02 15:35:53 +03:00
daboe01 18bb6daf10 fixed: nil and operator issues 2025-09-02 15:34:02 +03:00
daboe01 799cb189c9 new: test cases 2025-09-02 15:28:14 +03:00
daboe01 1112e658d4 removed: dealloc 2025-09-02 15:22:31 +03:00
daboe01 23cdee2f22 new: CPMapTable.j 2025-08-29 21:39:04 +03:00
daboe01 13688507dc new: restore old CPEvent factory method for backwards compatibility 2025-08-07 10:01:03 +02:00
daboe01 568d0faef6 fixed: missing parameter to CPEvent initializer 2025-08-06 17:19:14 +02:00
daboe01 41035a5b10 new: Implement missing CAKeyframeAnimation properties 2025-08-05 19:27:45 +02:00
daboe01 4cb0a87c68 fixed: syntax error 2025-08-03 22:26:09 +02:00
daboe01 cab5683cd9 fixed: CAKeyframeAnimation missing properties and methods 2025-08-03 22:22:42 +02:00
daboe01andGitHub 4d20007a9b Merge pull request #3133 from daboe01/collectionview-erroneous-offset-before-the-first-row
fixed: CPCollectionview displayed an erroneous offset before the first row of content
2025-08-02 16:55:25 +02:00
daboe01 56eb096903 fixed: accidental delete 2025-07-19 14:44:38 +02:00
daboe01 c077863e7a fixed: accidental changes 2025-07-19 14:29:46 +02:00
daboe01 49e5cb64ad Revert "removed: unwanted files"
This reverts commit 7e99e3ca20.
2025-07-19 14:23:52 +02:00
daboe01 7e99e3ca20 removed: unwanted files 2025-07-19 14:21:10 +02:00
daboe01 0b4d156b5b fixed: keyboard issues on ipad 2025-07-19 14:19:46 +02:00
daboe01 76ba6a4e64 fixed: ipad issue with backspace 2025-07-19 13:53:28 +02:00
daboe01 46bab97b49 fixed: backspace issue on ipad 2025-07-19 13:51:58 +02:00
daboe01 2a32934f86 fixed: ipad backspace issue 2025-07-19 09:40:14 +02:00
daboe01 bda5594f0c fixed: ipad softkeyboard trigger 2025-07-18 22:05:12 +02:00
daboe01 134688ef5c improved: double click emulation by double tapping 2025-07-18 21:48:09 +02:00
daboe01 e3fd7a295c fixed: ipad keyboard does not show 2025-07-17 19:41:48 +02:00
daboe01andGitHub c2d07b7b06 Merge pull request #3120 from daboe01/nil-in-cpviewcontroller-fix
fixed: subview's window setting did not happen BEFORE _setSuperview
2025-07-17 19:27:36 +02:00
daboe01 d9f31e8543 Revert "new: UIBuilder demo application"
This reverts commit 38f523b3c2.
2025-07-15 18:55:23 +02:00
daboe01 38f523b3c2 new: UIBuilder demo application 2025-07-15 18:54:09 +02:00
daboe01andGitHub 69a353d969 Update README.markdown 2025-07-15 07:21:35 +02:00
daboe01andGitHub 945e70c0ff Update README.markdown 2025-07-14 19:35:15 +02:00
daboe01andGitHub 277e9bee7b new: link to example app 2025-07-14 19:34:01 +02:00
daboe01andGitHub 95614d567c Update README.markdown 2025-07-14 19:14:55 +02:00
daboe01andGitHub 6a488af1ca Update README.markdown demo app 2025-07-14 19:14:17 +02:00
daboe01 a0f9cb5183 formatting 2025-07-13 19:55:34 +02:00
daboe01 1a74b4c692 fixed: CPCollectionview displayed an erroneous offset before the first row of content 2025-07-13 19:53:33 +02:00
daboe01andGitHub 746311c6cf Merge pull request #3124 from daboe01/fixed-touch-scrolling-had-no-momentum-support
fixed: touch scrolling did not support momentum
2025-07-09 22:23:42 +02:00
daboe01andGitHub 876aaa483e Merge pull request #3132 from daboe01/fixed-submenu-placement-issue
fixed: CPMenu Submenu Placement Issue
2025-07-09 22:22:28 +02:00
daboe01 570c31f248 fixed: richtext copypaste 2025-07-06 14:04:35 +02:00
daboe01 b3695ed710 formatting 2025-07-06 12:48:31 +02:00
daboe01 e9dddaad20 new: manual test 2025-07-06 10:58:19 +02:00
daboe01 2b254a6f16 fixed: CPMenu Submenu Placement Issue 2025-07-05 19:01:57 +02:00
daboe01andGitHub e9022d045c Merge pull request #3123 from daboe01/new-viewcontroller-responder-chain-issue
fixed: CPViewController doesn't participate fully in responder chain
2025-07-05 16:41:23 +02:00
daboe01 c70ea739ec fixed: unittest was overambitious 2025-07-05 16:39:10 +02:00
daboe01 85da0164ba fixed: designated initialiser was not used 2025-07-05 16:32:22 +02:00
daboe01 89b262103f Revert "fixed: _view was assigned bypassing the accessors"
This reverts commit cfcf8bc567.
2025-07-05 16:28:16 +02:00
daboe01 2c5744be57 formatting 2025-07-05 16:25:00 +02:00
daboe01 cfcf8bc567 fixed: _view was assigned bypassing the accessors 2025-07-05 16:21:19 +02:00
daboe01 d1acff5b44 improved setNextResponder assignment 2025-07-05 16:13:50 +02:00
daboe01 2add37983d new: unittest for responderchain 2025-07-05 15:56:44 +02:00
daboe01 ce00fdaae8 fixed: copy-paste-issues 2025-07-05 15:37:32 +02:00
daboe01 2fe29d4a26 Update .gitignore 2025-07-05 13:36:14 +02:00
daboe01andGitHub fc582d8125 Merge pull request #3131 from daboe01/fixed-CPTimeZone-initWithName-does-not-return-the-timeZone-with-the-good-daylight-saving-
fixed: CPTimeZone initWithName: does not return the timeZone with the good daylight saving
2025-07-05 13:16:56 +02:00
daboe01andGitHub c41307dc37 Merge branch 'main' into fixed-CPTimeZone-initWithName-does-not-return-the-timeZone-with-the-good-daylight-saving- 2025-07-05 12:58:01 +02:00
daboe01 27280f6da1 Update CPMenuTest.j 2025-07-05 12:35:43 +02:00
daboe01 ce7fec170a Update CPEventTest.j 2025-07-05 12:33:21 +02:00
daboe01 98ef6fd902 Update CPEventTest.j 2025-07-05 12:30:58 +02:00
daboe01 1c4d9b1d8f Update CPButtonTest.j 2025-07-05 12:29:11 +02:00
daboe01 b8b988c10b Update CPResponderTest.j 2025-07-05 09:04:26 +02:00
daboe01 0eb87f85b4 fixed: accidentally removed files 2025-07-05 09:01:12 +02:00
daboe01 a0136e2144 removed accidentally committed stuff 2025-07-05 08:58:57 +02:00
daboe01 d12770c65d fixed: testcase for keyevent 2025-07-05 08:57:29 +02:00
daboe01 b0186bf4f2 fixed: smart copy/paste 2025-07-05 08:49:08 +02:00
daboe01 9e15700f93 cleanup stuff 2025-07-03 22:10:57 +02:00
daboe01 6b2494ede4 fixed: arrow navigation 2025-07-02 19:54:52 +02:00
daboe01 266965f506 improved: native input manager 2025-07-02 07:50:46 +02:00
daboe01 1226f5120c improved: deadkey management 2025-07-01 22:55:53 +02:00
daboe01 f4ac0630b8 formatting 2025-07-01 22:25:20 +02:00
daboe01 b3cb22caef more modernisations 2025-07-01 22:16:33 +02:00
daboe01 b1d96dfdee improved reliance of key 2025-07-01 21:53:53 +02:00
daboe01 25732f2f52 fixed: second half of the fix was missing 2025-07-01 21:42:58 +02:00
daboe01 5ecdaafadf fixed: arrow keys did not work 2025-07-01 20:23:29 +02:00
daboe01 223bbc86e1 fixed: arrow keys did not work 2025-07-01 19:42:12 +02:00
daboe01 0867e718d1 Revert "fixed: arrow keys did not work"
This reverts commit c814b5daed.
2025-07-01 19:40:47 +02:00
daboe01 c814b5daed fixed: arrow keys did not work 2025-07-01 19:36:02 +02:00
daboe01andGitHub 0e8ee2f7d5 Merge pull request #3130 from daboe01/fixed-NSDateFormatter-unable-to-parse-dates-in-Javascript-Date.toISOString-format
fixed: NSDateFormatter was unable to parse dates in Javascript Date.toISOString format
2025-07-01 16:21:30 +02:00
daboe01andGitHub 4b22d67f42 Merge pull request #3117 from daboe01/null-marker-versus-nil-issue
fixed: CPObjectController returns 'null marker' instead of nil
2025-07-01 16:19:58 +02:00
daboe01andGitHub edf0a61653 Merge pull request #3119 from daboe01/CPTimeZone-fix
fixed: time zone methods return nil in Chrome and Firefox
2025-07-01 16:19:14 +02:00
daboe01andGitHub e50ede815c Merge pull request #3128 from daboe01/fixed-missing-documentation-of-CPOutlineView
fixed: missing documentation of CPOutlineViewDataSource protocol
2025-07-01 16:15:58 +02:00
daboe01andGitHub 6d2888e1c6 Merge pull request #3129 from daboe01/textfieldsizefix
fixed: nonsense addition accidentally turning the size into a string
2025-07-01 16:14:17 +02:00
daboe01 b6461ba4fb fixed: tests 2025-06-29 20:28:43 +02:00
daboe01 25708554fd fixed: typo 2025-06-29 20:22:38 +02:00
daboe01 74f204e6fa fixed: tests and implementation 2025-06-29 20:20:58 +02:00
daboe01 263ec36d80 fixed: test 2025-06-29 19:42:12 +02:00
daboe01 bb6b738fc7 fixed: CPTimeZone initWithName: does not return the timeZone with the good daylight saving 2025-06-29 19:34:56 +02:00
daboe01 fb1c2732ac fixed test 2025-06-29 18:00:19 +02:00
daboe01 1fb42fc119 fixed: NSDateFormatter was unable to parse dates in Javascript Date.toISOString format 2025-06-29 17:51:08 +02:00
daboe01 23f9170b90 fixed: nonsense addition accidentally turning the size into a string 2025-06-29 17:18:42 +02:00
daboe01 7be2005fae fixed: wrong documentation 2025-06-29 15:50:05 +02:00
daboe01 afadec517b fixed: missing documentation of CPOutlineViewDataSource protocol 2025-06-29 15:20:23 +02:00
daboe01 da5a12c938 formatting 2025-06-26 17:54:05 +02:00
daboe01 a9aa15d63f fixed CALayer class name 2025-06-26 17:52:11 +02:00
daboe01 e6d2d840e9 fixed: CALayer autocreate 2025-06-26 17:51:26 +02:00
daboe01 4963127c31 formatting 2025-06-26 17:49:36 +02:00
daboe01 62c7ac891f fixed: manual test 2025-06-26 17:43:51 +02:00
daboe01 e4b594f716 fixed: manual test 2025-06-26 17:42:03 +02:00
daboe01 0835f18721 new: manual test 2025-06-26 10:01:37 +02:00
daboe01 8231cbc55c fixed: wrong core animation symbol names 2025-06-26 08:01:45 +02:00
daboe01andGitHub b63cde48c6 Merge pull request #3111 from daboe01/CPImage_Drawing
new: CPImage method drawAtPoint:fromRect: operation: fraction:
2025-06-25 19:26:00 +02:00
daboe01andGitHub 30150178db Merge pull request #3116 from daboe01/doxygen-fix
fixed: make docs was not working in node version
2025-06-25 19:25:20 +02:00
daboe01andGitHub 61eebfcf46 Merge pull request #3118 from daboe01/fixed-capp-gen--l-issue
fixed: node fs issues in Generate.j
2025-06-25 19:24:22 +02:00
daboe01andGitHub 40154ed86e Update README.markdown 2025-06-25 10:58:27 +02:00
daboe01andGitHub 23605ff2b0 Merge pull request #3115 from daboe01/better-readme
Better readme
2025-06-25 10:56:42 +02:00
daboe01 964eb00ce1 formatting 2025-06-25 10:54:50 +02:00
daboe01 930c1e874c reordering faq 2025-06-25 10:54:08 +02:00
daboe01 1d96b09129 switch to passive voice 2025-06-25 10:53:41 +02:00
daboe01 9c6ce6d200 fixed: missing _momentumScrollStep 2025-06-23 09:40:27 +02:00
daboe01 a1aad41a6b fixed: missing ivars 2025-06-23 09:30:52 +02:00
daboe01 38cb3cb1a2 fixed: touch scrolling did not support momentum 2025-06-23 09:19:02 +02:00
daboe01 751e1d27a6 Update CPPlatformWindow+DOMKeys.j 2025-06-23 09:02:28 +02:00
daboe01 36d4bd32b5 Update CPPlatformWindow+DOM.j 2025-06-23 08:58:12 +02:00
daboe01 d835cf0c00 fixed: CPViewController doesn't participate fully in responder chain 2025-06-23 07:32:49 +02:00
daboe01 6ce85bae7e fixed: Keyboard-event handling is based on the deprecated charCode 2025-06-23 07:21:08 +02:00
daboe01 7d1df21b0e removed unused variable 2025-06-22 22:57:59 +02:00
daboe01 bbb87b4970 removed: wrong code 2025-06-22 22:56:35 +02:00
daboe01 14d9bb795d fixed: wrong code 2025-06-22 22:55:41 +02:00
daboe01 2eb1d1bfb9 fixed: CPView was missing rotateByAngle: method 2025-06-22 22:51:26 +02:00
daboe01 bae78b5055 formatting 2025-06-22 21:52:57 +02:00
daboe01 c0705448cd new: testcase 2025-06-22 21:47:26 +02:00
daboe01 e0a8fa3fde formatting 2025-06-22 21:34:19 +02:00
daboe01 64f4b0fc13 fixed: accidental removal of commented out code 2025-06-22 21:32:48 +02:00
daboe01 c28a05e968 fixed logic 2025-06-22 21:28:37 +02:00
daboe01 170d6ac2e7 fixed wrong logic 2025-06-22 21:19:03 +02:00
daboe01 64cc36a1ac new logic 2025-06-22 21:06:47 +02:00
daboe01 af61bcb93f fixed: wrong logic 2025-06-22 20:45:55 +02:00
daboe01 1f24e89c1b fixed wrong logic 2025-06-22 20:35:11 +02:00
daboe01 b12aee53d3 fixed: subview's window setting mus happen BEFORE _setSuperview 2025-06-22 19:47:19 +02:00
daboe01 feb8ea0316 new: test case for the new timezone abbreviation logic 2025-06-22 19:33:13 +02:00
daboe01 db51d5ca54 fixed: time zone methods return nil in Chrome and Firefox 2025-06-22 19:27:58 +02:00
daboe01 01e9f9181d fixed: node issues 2025-06-22 16:59:54 +02:00
daboe01 3a9db70426 fixed: CPObjectController returns 'null marker' instead of nil 2025-06-22 11:04:46 +02:00
daboe01 c7e850b95f fixed: accidentally removed markdown install instructions 2025-06-21 18:09:19 +02:00
daboe01 89b3fb003c formatting 2025-06-21 17:29:31 +02:00
daboe01 6abb8234fb fixed: docsetutil is nowadays missing from xcode 2025-06-21 17:26:46 +02:00
daboe01 4395663cc9 fixed: doc directories are spilled everywhere 2025-06-21 16:56:57 +02:00
daboe01 aeb982c616 formatting 2025-06-21 16:32:11 +02:00
daboe01 3fd26e681b fixed: make docs was not working in node version 2025-06-21 16:29:31 +02:00
daboe01 8bcf446187 fixed: cappuccino-cookbook was missing 2025-06-21 14:50:02 +02:00
daboe01 42d51dc808 Merge branch 'better-readme' of https://github.com/daboe01/cappuccino into better-readme 2025-06-21 13:16:12 +02:00
daboe01 b05aa3dd32 improved readme 2025-06-21 11:24:03 +02:00
daboe01 98a539657c fixed: type CGBlendMode missing 2025-06-19 09:15:08 +02:00
daboe01andGitHub 85f7125f22 New: for..of iteration for CPSet (#3114) 2025-06-18 10:22:41 +02:00
daboe01 2f8dd8c088 new: drawAtPoint:(CPPoint)point fromRect:(CPRect)fromRect operation:(CPCompositingOperation)op fraction:(CGFloat)delta 2025-06-11 14:14:30 +02:00
Martin CarlbergandGitHub 86d595b086 Fixed: Make the isa property on classes not enumerable. (#3100)
As we have a tool-free bridges between many classes and JavaScript types by setting the isa property on the type, for example CPArray and Array. Using the for...in enumeration the isa property will be included in the loop if the property is enumerable (this is the default behavior). This commit set the property as not enumerable.

Also added test case for check that the isa property on classes are not enumerable using a for...in loop.
2025-05-14 10:09:01 +02:00
daboe01andGitHub 2f563fb870 New: give nil values the chance to be transformed to true via CPNegateBoolean (#3103) 2025-04-28 15:40:57 +02:00
daboe01andGitHub c78a18dc3e Update README.markdown 2025-04-02 17:03:14 +02:00
daboe01andGitHub 0fa636dd79 Update README.markdown 2025-04-02 17:01:01 +02:00
Martin CarlbergandGitHub 7fc9fa70c1 Fixed: Github Action build with Node 22 and 23 too 2025-03-27 15:36:14 +01:00
daboe01andGitHub 9109cf3b54 Fixed: changing background color in CPTextView did not redraw properly (#3107) 2025-03-26 13:31:05 +01:00
David RichardsonandGitHub 50076efe1e Merge pull request #3106 from enquora/dark-mode-cleanup
Set default project details view (no project selected) to default colours
2025-01-27 09:45:48 -07:00
David Richardson 097785fb93 Set default project details view, when no project selected, to default colours
Remove hard-coded colours to allow dark mode support.
2025-01-27 09:41:58 -07:00
daboe01andGitHub 7e07deeb23 Update README for ECMA Script 2024 2025-01-14 15:46:42 +01:00
daboe01andGitHub e8c0c680ca Update README.markdown 2024-12-30 15:39:53 +01:00
daboe01andGitHub d9ee7b23c2 Update README.markdown 2024-12-30 15:36:34 +01:00
daboe01andGitHub 03339e3c5d Merge pull request #3102 from cappuccino/narwhal
merge of PR #1372 and #2018 into main
2024-12-30 14:05:09 +01:00
daboe01andGitHub c58c5554f9 Merge pull request #2018 from vidinoti/patch-1
Changing a CALayer in a menu callback doesn't trigger re-draw
2024-12-30 13:57:56 +01:00
daboe01andGitHub 16ae7b7e74 Merge pull request #1372 from kjamieson/scroll-fixes
If target view of a drag and drop is a CPTableView, set inset bounds based on the row height of the table
2024-12-30 13:51:00 +01:00
David RichardsonandGitHub 6d3fec88ec Merge pull request #3101 from enquora/dark-mode-cleanup
Dark mode cleanup
2024-11-13 10:48:25 -07:00
David Richardson 4b74e7da31 Increment patch component of version number to reflect dark mode support changes 2024-11-13 10:41:13 -07:00
David Richardson fa70ffc918 Clean up control colours for background and text to fully support dark mode 2024-11-13 10:34:04 -07:00
David RichardsonandGitHub fd177f4b9a Merge pull request #3072 from enquora/remove-narwhal-artifacts
Remove narwhal-specific artifacts
2024-10-17 10:01:08 -06:00
daboe01andGitHub 08c666a53f Merge pull request #3097 from cappuccino/remove-unused-local-variable-charCode
removed: unused local variable charCode
2024-10-07 19:44:13 +02:00
daboe01 639a0fe1c2 fixed: symbol size of combobox indicator in small and mini styles 2024-09-28 14:01:15 +02:00
daboe01andGitHub 668567d6e2 Merge pull request #3094 from enquora/editorconfig
Add editorconfig file
2024-09-27 13:36:07 +02:00
David Richardson 09f92407ec Cleanup
Make settings universal, across all file types.
2024-09-26 11:08:33 -06:00
daboe01andGitHub 9dc12c0142 Merge pull request #3091 from daboe01/cptextviewcopypastedocu
added documentation to the copy paste limitation
2024-09-22 13:03:52 +02:00
David RichardsonandGitHub 2fd821ca00 Merge pull request #3096 from enquora/fix-menubar-icon-visibility
Change rendering mode for menubar inactive icon from ‘Render As’ to ‘Template Image’
2024-09-21 12:58:57 -06:00
daboe01andGitHub 03195b66bc removed: unused local variable charCode 2024-09-21 19:12:18 +02:00
David Richardson a3d906165a Change menubar inactive icon ‘Render As’ mode to ‘Template Image’
Allows macOS to automatically manage blending mode and color of menubar icon.
Modern macOS renders the menubar with translucency, making icons with some fixed colors difficult to see with some wallpapers.
This was particularly pronounced with ‘status-icon-inactive’.
Changing render mode to ‘Template Image’ allows the OS to adjust icon color and blending mode dynamically — to suit current combination of Light/Dark mode and wallpaper color.
2024-09-15 16:03:23 -06:00
David Richardson 4c1ce50dd2 Add editorconfig file
Enforce/guide compliance with Cappuccino project coding standards.
Most modern editors supported directly or via plugins.
2024-08-29 19:20:16 -06:00
daboe01 b638242e6f added documentation to the copy paste limitation 2024-08-04 15:15:34 +02:00
daboe01andGitHub 2349aacc3e Update README.markdown 2024-07-21 21:34:53 +02:00
daboe01andGitHub 1be7bbe0dc Update README.markdown 2024-07-21 21:32:22 +02:00
daboe01andGitHub ea332d5492 Update README.markdown 2024-07-21 21:30:54 +02:00
daboe01andGitHub aedede7381 Update README.markdown 2024-07-21 21:22:52 +02:00
daboe01andGitHub d4cd46c331 Update README.markdown
stringWithFormat returns autoreleased instances iirc
2024-07-21 21:22:05 +02:00
daboe01andGitHub 62450c3bb1 Update README.markdown 2024-07-21 21:19:16 +02:00
daboe01andGitHub bafba81f56 Update README.markdown 2024-07-21 21:18:07 +02:00
daboe01andGitHub 651b445c75 Update README.markdown 2024-07-21 21:17:38 +02:00
daboe01andGitHub 5adc3c6a99 Update README.markdown 2024-07-21 21:17:04 +02:00
daboe01andGitHub 4914ff8205 Update README.markdown 2024-07-21 21:14:49 +02:00
daboe01andGitHub 783205c731 Update README.markdown 2024-07-21 19:32:24 +02:00
daboe01andGitHub 00ab2d1f3a Update README.markdown 2024-07-21 19:28:21 +02:00
daboe01andGitHub 98dcbdd87a Update README.markdown 2024-07-21 19:24:58 +02:00
daboe01andGitHub 4a936a6eef README.markdown: reduced redundant introduction 2024-07-21 19:10:41 +02:00
daboe01andGitHub ef7ee1b699 Merge pull request #3089 from enquora/README-refinements
Readme refinements
2024-07-21 19:06:48 +02:00
daboe01andGitHub 4e70c1fb10 Merge branch 'main' into README-refinements 2024-07-21 19:02:52 +02:00
daboe01andGitHub 21d4fa5176 Update README.markdown 2024-07-21 13:35:07 +02:00
daboe01andGitHub f16b2e8243 Update README.markdown 2024-07-21 13:32:34 +02:00
daboe01andGitHub 4e550a22b0 fixed: markdown syntax errors 2024-07-21 13:30:34 +02:00
David Richardson c2404d3c67 Reduce references to Cocoa, annotate remaining ones to indicate it is a registered trademark 2024-07-20 09:50:18 -06:00
David Richardson f1a5467d04 Refine and re-order benefits section 2024-07-20 09:19:56 -06:00
David Richardson 512486f2e8 Increase priority/visibility of toolchain stability as a benefit 2024-07-20 08:49:52 -06:00
daboe01andGitHub f1d95fa883 Merge pull request #3087 from enquora/README-refinements
README refinements
2024-07-20 16:48:52 +02:00
David Richardson 31cf9b8527 Add missing statement terminator in code example 2024-07-20 08:43:10 -06:00
David Richardson e0e8e8c6cc Clean up porting example gone wrong, further edits to increase brevity 2024-07-20 08:39:03 -06:00
daboe01andGitHub 6653690d0c Merge pull request #3086 from daboe01/segmentedcontrol-theme-fix
fixed: 1xp glitch with CPSegmentedControl in safari
2024-07-20 13:42:08 +02:00
David Richardson e63f59d33e Update source code installation to reflex new jake dist task 2024-07-19 16:08:20 -06:00
David Richardson 3702c18df5 README refinements
General refinements.
Move npm quickstart instructions to a more prominent position.
Add licensing FAQ.
Add FAQ for porting code from Objective-C to Objective-J
2024-07-19 16:05:05 -06:00
daboe01 dfe215f34c fixed: 1xp glitch with CPSegmentedControl in safari 2024-07-19 06:36:58 +02:00
daboe01andGitHub 621a559585 Update README.markdown 2024-07-18 10:07:25 +02:00
daboe01andGitHub 61317eff71 Update README.markdown (swift vs. objective j) 2024-07-18 10:06:37 +02:00
daboe01andGitHub b314a951da Update README.markdown 2024-07-17 12:31:51 +02:00
daboe01andGitHub 1a1c105c71 Update README.markdown 2024-07-17 07:38:24 +02:00
daboe01andGitHub 3f8ee35ddb Update README.markdown 2024-07-17 07:27:03 +02:00
daboe01andGitHub d2ea74ea14 Update README.markdown 2024-07-17 06:41:35 +02:00
daboe01andGitHub 8e1fb771e0 Update README.markdown 2024-07-17 06:35:36 +02:00
daboe01andGitHub bbe5c82700 Merge pull request #3083 from michaelbach/patch-2
fixied: bindings for case  'only stop at tick marks'
2024-07-16 19:13:32 +02:00
daboe01andGitHub 95e3ff3349 wrap fix in if (_allowsTickMarkValuesOnly) 2024-07-16 19:12:04 +02:00
daboe01andGitHub 00c3b2083b formatting 2024-07-16 19:08:58 +02:00
daboe01andGitHub 8549858951 Merge pull request #3084 from cappuccino/narwhal
fixed: selection and backspace are recently broken in CPTokenField
2024-07-16 19:07:18 +02:00
daboe01andGitHub 4730c3f4b5 Update README.markdown 2024-07-16 19:06:38 +02:00
daboe01andGitHub 19ba66fd9d Merge branch 'main' into narwhal 2024-07-16 19:04:08 +02:00
daboe01andGitHub 589c26192d Merge pull request #2894 from daboe01/tokenfield-fr-fix
fixed: selection and backspace are recently broken in CPTokenField
2024-07-16 19:01:25 +02:00
David RichardsonandGitHub 8471aeea1b Merge pull request #3082 from michaelbach/patch-1
Update README.markdown
2024-07-16 09:43:32 -06:00
Michael BachandGitHub 58c39c14a5 Update CPSlider.j (fixing bindings for case 'only stop at tick marks'
This fixes bindings to also work when 'only stop at tick marks' is selected; formerly the code would crash silently with `setObjectValue`.
2024-07-16 16:15:57 +02:00
Michael BachandGitHub 2cfe45950b Update README.markdown
mistype (LTS → Node.js), typography (- → –) and slight presentation change (bullet list).
2024-07-16 10:22:18 +02:00
daboe01andGitHub 688671db6a Merge pull request #3081 from enquora/update-README
Modernize project README
2024-07-16 07:23:38 +02:00
David Richardson 1d2e50dfa2 FAQ section added 2024-07-15 13:20:39 -06:00
David Richardson 7a70036c8f Further content edits
Link to description of message passing languages.
Style and content edits.
2024-07-15 09:54:11 -06:00
David Richardson ab88a3b236 Add comment about loose-coupled nature of message-passing architectures 2024-07-14 15:05:16 -06:00
David Richardson 266e14063e Modernize project README 2024-07-14 14:00:07 -06:00
David RichardsonandGitHub 3af0296779 Merge pull request #3080 from enquora/re-enable-capp_lint
Re-enable installation of capp_lint
2024-07-05 15:22:06 -06:00
David Richardson 5ff05503a4 Re-enable installation of capp_lint
Requires Python 2, but this is true for XcodeCapp also.
Installs to /usr/bin/local, but must be manually installed using install script in source directory.
2024-07-05 15:14:43 -06:00
David RichardsonandGitHub 13e6782cf1 Merge pull request #3077 from enquora/ibtool-fix-node
Update nib2cib's Converter.j to handle xib files with deployment targ…
2024-07-03 13:32:46 -06:00
David Richardson 24052e6369 Improve inline documentation, code formatting 2024-07-03 13:05:07 -06:00
David RichardsonandGitHub 9b17ce5524 Merge pull request #3078 from enquora/XcodeCapp-fix-deprecations
Xcode capp fix deprecations
2024-07-03 12:20:21 -06:00
David Richardson e4c2d62eb0 Clean up deprecation notices
Reduce debugging noise by removing deprecation notices.
2024-07-03 09:05:32 -06:00
David Richardson 27fa37a7e1 Update dataFromPropertyList usage to remove deprecation warning 2024-07-03 09:05:32 -06:00
David Richardson 987da2b812 Remove deprecation warning when reading settings plist 2024-07-03 09:05:32 -06:00
David Richardson d1611bae12 Update deprecated NSCenterTextAlignment usage to NSTextAlignmentCenter 2024-07-03 09:05:32 -06:00
David Richardson 96a3c4b9dd Remove extraneous 'SettingsView.cib' file
Not a part of XcodeCapp project, unclear why it was included.
2024-07-03 09:05:32 -06:00
David Richardson 8ef40dced5 Update 'About' dialog
Use property values in Info.plist rather than hard-coded values in dialog view.
2024-07-03 09:05:32 -06:00
David Richardson 4a6ddb901f Clean up alignment of assignment statements 2024-07-03 09:05:32 -06:00
David Richardson a5094e0acc Update nib2cib's Converter.j to handle xib files with deployment targets of Xcode 11 or later 2024-07-02 16:39:17 -06:00
David Richardson 966d9fe0d2 Remove bootstrap.sh and narwhal.local.conf
Used by/useful for Narwhal javascript engine - no longer needed.
2024-06-03 15:08:59 -06:00
daboe01andGitHub fffcca592d Merge pull request #3047 from daboe01/patch-8
Prepare README.markdown for the upcoming release
2024-06-02 21:19:22 +02:00
daboe01andGitHub d3cc6c29c9 Merge branch 'main' into Aristo3 2024-05-24 16:07:32 +02:00
Martin CarlbergandGitHub 341584c032 Change reference to branch main instead of node 2024-05-24 12:49:10 +02:00
Martin Carlberg a1e178d0d7 Merge remote-tracking branch 'origin/narwhal' 2024-05-24 12:18:28 +02:00
daboe01 89c00e193b fixed compatibility of theme jakefiles with node 2024-05-22 17:32:03 +02:00
daboe01 b38a5d19b1 update from node 2024-05-22 17:27:28 +02:00
daboe01 f7ae515d84 Update package-lock.json 2024-05-22 17:20:56 +02:00
Martin CarlbergandGitHub c59687b6e2 Fixed: Use latest version of actions as the old ones are deprecated 2024-04-10 11:34:50 +02:00
Martin CarlbergandGitHub c2bd9f26a7 Fixed: Github Action build with Node 20 and 21 too 2024-04-10 11:19:10 +02:00
David RichardsonandGitHub 6d78b9b6df Merge pull request #3065 from enquora/update-XcodeCapp-project-structure
Update xcode capp project structure
2024-03-20 10:15:51 -06:00
David Richardson 0669ce06f2 Update version check in XcodeCapp Jakefile
Match deployment version set in XcodeCapp project file - macOS 10.13.
2024-03-20 10:07:25 -06:00
David Richardson 767d9378e3 Move deployment target back from macOS 10.15 to 10.13,
the earliest version on-hand for testing.
2024-03-20 09:48:09 -06:00
David Richardson c2d62b7a13 Update Info.plist
Set Display Name property to 'XcodeCapp'.
Set App Category to 'Developer Tools'.
2024-03-20 09:25:16 -06:00
David Richardson 10e33298a9 Fixes to allow successful building under Xcode 15
Manually remove DSTROOT occurrences from project.pbxproj.
Their presence causes Xcode build process to believe a reference cycle exists - preventing compilation.

Update minimum installation target to macOS 10.15
Earlier targets require presence of 'libarclite' - no longer included with Xcode 15.
2024-03-20 09:23:11 -06:00
David RichardsonandGitHub ecc88112d5 Merge pull request #3063 from enquora/narwhal-jsc-sonoma 2024-03-19 08:11:08 -06:00
daboe01andGitHub b190063264 Merge pull request #3060 from daboe01/new-releaseWhenClosed-support
new: support for releasedWhenClosed in CPWindow
2024-03-19 15:04:44 +01:00
David RichardsonandGitHub 0c9c0c0239 Merge pull request #3064 from enquora/fix-host-os-version-check
Allow building XcodeCapp under any version greater than Sierra
2024-03-19 08:03:18 -06:00
David Richardson ae333ecb77 Allow building XcodeCapp under any version greater than Sierra
Individual new OS releases had support added individually until now.
2024-03-18 10:09:46 -06:00
David Richardson 72a85d11df Fix narwhal-jsc build under Sonoma
Remove newly-unsupported linker flag
2024-03-18 09:57:59 -06:00
Martin Carlberg f33ba954f5 Fixed: critical severity vulnerability in package xmldom 2024-01-09 14:28:15 +01:00
daboe01 f642330306 new: support for releasedWhenClosed in CPWindow 2023-12-23 19:08:38 +01:00
daboe01andGitHub ae1a39322e Merge pull request #3053 from daboe01/CPDatePickerUsabilityImprovement
fixed: poor user experience when entering dates that are too high for…
2023-12-21 20:00:53 +01:00
daboe01 29502d10eb formatting 2023-12-21 19:59:38 +01:00
daboe01andGitHub 37550b9fb0 Merge pull request #3048 from michaelbach/fix-typo-in-CPView-(_ephereralSubviews)
CPView.j, fix typo: _ephereralSubviews → _ephemeralSubviews
2023-12-21 19:24:11 +01:00
daboe01andGitHub efd2ed1960 Merge pull request #3055 from daboe01/cpstring+-containsString
fixed: CPString did not have containsString:
2023-12-21 19:19:49 +01:00
Martin Carlberg 150e44dcd5 Fixed: The objj2objcskeleton tool stop generating output if a SelectorLiteralExpression was used in the source file 2023-05-31 14:32:38 +02:00
daboe01 3a164c8080 fixed: CPString did not have containsString: 2023-03-05 21:37:50 +01:00
daboe01 fb9223c6c3 fixed: poor user experience when entering dates that are too high for the current month 2023-02-25 21:30:42 +01:00
Martin Carlberg 511ce4b07d Merge branch 'master' into node 2022-12-09 15:13:17 +01:00
Martin Carlberg aea3fb5f07 Merge remote-tracking branch 'origin/es2022' into node 2022-12-09 13:59:48 +01:00
Martin CarlbergandGitHub 5932a07eb2 Fixed: Make sure Jakefile both work for async and sync calls
The callback variable was not set if the call to initilize was synchronous.
It is now set before so both sync and async will work
2022-12-09 10:15:38 +01:00
Martin CarlbergandGitHub 2b07c4b662 Fixed: Make sure Jakefile both work for async and sync calls
The callback variable was not set if the call to initilize was synchronous.
It is now set before so both sync and async will work
2022-12-09 10:14:52 +01:00
Martin CarlbergandGitHub bc689b91dc Fixed: Added 'npm update' to use latest modules 2022-12-08 17:26:57 +01:00
Martin CarlbergandGitHub c6a42781e7 Fixed: Github Action build with Node 18 and 19 too 2022-12-08 14:25:01 +01:00
Martin Carlberg c92aedf433 Fixed: Quick fix for XcodeCapp so it will run without python2 scripts 2022-11-21 16:41:16 +01:00
cacaodevandMartin Carlberg 7857f92f19 FIXED: CPLikePredicateOperatorType was matching substrings
Fixes #2955
2022-11-21 16:33:56 +01:00
cacaodevandGitHub 9361e5d401 FIXED: CPLikePredicateOperatorType was matching substrings
Fixes #2955
2022-11-10 10:49:01 +01:00
Michael Bach 6c6f69d4e5 CPView.j, fix typo: _ephereralSubviews → _ephemeralSubviews
This typo occurs only once, line #3462 references the correct spelling.
2022-11-01 18:04:21 +01:00
daboe01andGitHub e836226174 Prepare README.markdown for the upcoming release 2022-11-01 17:32:37 +01:00
Martin CarlbergandGitHub ad1862a253 Update CPURLConnection.j
New: Async method for requesting data
2022-10-06 11:24:56 +02:00
daboe01 37fedd41e3 improved: sizing of combobox list 2022-09-30 19:22:16 +02:00
daboe01 3711461201 fixed: overlap between text and button in combobox 2022-09-30 11:15:26 +02:00
daboe01 4ddd8ac263 new: mini size combo box 2022-09-28 21:27:29 +02:00
daboe01 aa7a96cfb8 new: small size combo box 2022-09-28 19:04:08 +02:00
daboe01 2c2768a34f improved: A3 CSS for ComboBox 2022-09-19 19:36:35 +02:00
Martin Carlberg 4af137894a Fixed: Npm lock file with latest versions 2022-09-01 14:02:40 +02:00
Martin Carlberg 55aca1fde9 Fixed: Make sure we compile with es2022 as ecmaVersion in the parser 2022-09-01 13:53:52 +02:00
Alfred Wärnsäter 53e1e936d9 Reordered includes 2022-08-26 15:08:58 +02:00
Alfred Wärnsäter ff1448fb54 Fixed Objective-J framework using latest transpiler and parser 2022-08-26 12:25:40 +02:00
Alfred Wärnsäter 95fb19f311 New version 2022-08-25 17:57:57 +02:00
Alfred Wärnsäter 46d869a62f Updated lock file 2022-08-25 15:46:09 +02:00
Alfred Wärnsäter 03140dbf64 Updated Terser and added acorn walk dependency 2022-08-25 15:45:23 +02:00
Alfred Wärnsäter 052c96e05a Changes for compatibility with ES2022 transpiler 2022-08-25 15:34:19 +02:00
Alfred Wärnsäter 9a88f9c324 Added ES2022 as compile option 2022-08-25 15:32:43 +02:00
Alfred Wärnsäter 747ea627c9 Removed debugger statement 2022-08-25 15:30:02 +02:00
daboe01 91c2fd2085 new: focus ring for combobox 2022-06-10 09:09:36 +02:00
daboe01 9ab63ee854 fixed: handling combo-box over heights 2022-06-10 08:52:06 +02:00
daboe01 ef1dd16766 fixed: combobox text positioning issues 2022-06-09 22:57:20 +02:00
daboe01 39f4b573da proposed: CPComboBox style 2022-06-09 18:12:53 +02:00
Didier Korthoudt 2a0306b14d Update ThemeDescriptors.j
This commit fixes size and position of standard buttons in all sizes and in default button state.
2022-04-14 12:21:23 +02:00
Didier Korthoudt e0735a1d82 large-control-size
This commit adds compatibility with the new control size "Large" introduced in MacOS 11.
2022-04-14 12:00:13 +02:00
Didier Korthoudt 6f44fe9f93 Buttons-fix
This commit fixes buttons position and height. Compatibility with Xcode IB is also better.
2022-04-13 17:39:05 +02:00
daboe01 f390e5ed17 fixed: first item was hidden in buttonbar action menus 2022-04-13 08:24:27 +02:00
Didier Korthoudt ede3eb64ae Update CPTabView.j
Just a typo
2022-04-07 11:43:46 +02:00
Didier Korthoudt d0d4972681 Update CPSearchField.j
This commit adds "Search" as placeholder by default, as Cocoa does.
2022-04-07 11:40:32 +02:00
Didier Korthoudt 4be4a65c72 Update CPAlert.j
This fixes incorrect button bezel style in alerts, resulting in white text on white background, instead of default blue background.
2022-04-05 15:55:57 +02:00
Didier Korthoudt 3e009bbf26 Update CPSearchField.j
This fixes problems with search and cancel buttons, restoring correct behavior and animations.
2022-04-05 10:37:42 +02:00
daboe01andMartin Carlberg 89c0ab405a Fixed: å and Å did not work well on scandinavian keyboards in CPTextView (#3031) 2022-04-04 10:23:17 +02:00
daboe01andGitHub 04c2b98ae4 Fixed: å and Å did not work well on scandinavian keyboards in CPTextView (#3031) 2022-04-04 10:16:37 +02:00
daboe01 3db3f03e5d fixed: plus/minus buttons in buttonbar had been to small
->replaced with svg versions + added highlighted state
2022-04-03 19:51:44 +02:00
daboe01 698f58eaa0 fixed: action icon in button bar 2022-04-03 17:31:57 +02:00
daboe01 95cf933ab2 code cleanup 2022-04-03 14:07:18 +02:00
daboe01 692f365fed fixed: _CPButtonBarPopUpButton did not show icon 2022-04-02 23:41:37 +02:00
daboe01 96aa310839 replaced svg icons with the packed.png sprites 2022-04-02 17:52:28 +02:00
Martin Carlberg 24b36cdd95 Fixed: Allow space in path to .xib/.cib file when running nib2cib 2022-03-29 10:39:04 +02:00
daboe01 8d3da8e4fa update xib in manual test 2022-03-27 16:11:35 +02:00
daboe01 885145d43d updated xib in manual tests 2022-03-27 15:17:18 +02:00
daboe01 c893e4a809 fixed: stepper icons 2022-03-27 14:29:26 +02:00
daboe01 1536c55b99 improved: gears icon 2022-03-27 13:13:02 +02:00
daboe01 f3f94eec66 fixed: use of outdated code in CPAnimationContext 2022-03-26 22:38:10 +01:00
daboe01 51b633f0d7 fixed: mixup of variable definitions 2022-03-26 19:48:29 +01:00
daboe01 5f1007dcbc fixed: mini and small segmentedControls + references to obsolete images 2022-03-26 19:18:09 +01:00
daboe01 ae7ce81b8c fixed: font support 2022-03-25 22:49:35 +01:00
daboe01 8b72e5db31 improved: gear icon 2022-03-25 22:43:13 +01:00
daboe01 0d35ceda31 replaced material icons with svg 2022-03-25 22:29:09 +01:00
daboe01 ed59003a95 fixed: 404 errors from missing obsolete background images 2022-03-25 21:42:56 +01:00
daboe01 94501c4618 POC for inline svg standard icons instead of material icons 2022-03-25 19:48:43 +01:00
daboe01 bf3847ce59 fixed: wrong method name 2022-03-24 19:17:42 +01:00
daboe01 c6ea894f10 fixed: old style Jakefile 2022-03-23 19:54:35 +01:00
daboe01 8df4e1ee6e fixed: aristo3 jakefile 2022-03-23 19:30:29 +01:00
daboe01 b608709014 resolved: missed conflict 2022-03-23 17:52:36 +01:00
daboe01 0450136af3 Merge branch 'pl_2719' into Aristo3 2022-03-23 06:59:28 +01:00
daboe01 29e4695503 Merge branch 'pl_2835' into Aristo3 2022-03-23 06:58:23 +01:00
daboe01 a7a080f416 Merge branch 'pl_2918' into Aristo3 2022-03-23 06:57:54 +01:00
daboe01 effb274410 Merge branch 'pl_2932' into Aristo3 2022-03-23 06:56:39 +01:00
daboe01 45f6f4bc90 Merge branch 'pl_2933' into Aristo3 2022-03-23 06:56:17 +01:00
daboe01 82b91b2f64 Merge branch 'pl_2937' into Aristo3 2022-03-23 06:54:49 +01:00
daboe01 59a9d8c093 Merge branch 'pl_2938' into Aristo3 2022-03-23 06:54:12 +01:00
daboe01 ae42acaef3 Merge branch 'pl_2939' into Aristo3 2022-03-23 06:53:00 +01:00
daboe01 531be2db49 fixed: missed conflict 2022-03-22 23:07:12 +01:00
daboe01 8089973b7b fixed: missed conflict 2022-03-22 23:06:24 +01:00
daboe01 1e8cc3101b Merge branch 'Aristo3' of https://github.com/daboe01/cappuccino into Aristo3 2022-03-22 23:00:49 +01:00
daboe01 a27a5fbc32 Merge branch 'pl_2507' into aristo3 2022-03-22 19:54:43 +01:00
Martin Carlberg 3e83bd2363 Revert "Fixed: Before this PR, nib2cib failed if a color well or a scrollable text view was added in a CPBox (#2994)"
This reverts commit 6544aff88e.
2022-03-21 16:25:24 +01:00
Martin Carlberg 5c91a08eaf Revert "Fixed: Before this PR, nib2cib failed if a color well or a scrollable text view was added in a CPBox (#2994)"
This reverts commit 6544aff88e.
2022-03-21 16:24:17 +01:00
Martin Carlberg edfba15d6f Merge branch 'master' into node 2022-03-21 15:55:08 +01:00
Didier KorthoudtandGitHub 48e786e8b5 Fixed: This PR adapts views and custom views decoding to fix "not ready view" bugs (#2917) 2022-03-21 15:50:44 +01:00
daboe01andGitHub 1282f1ac0e Removed: Flash support (#2903) 2022-03-21 15:46:54 +01:00
KrisandGitHub ee2fb61fdd Fixed: Changed Cappuccino.doxygen EXCLUDE_PATTERNS to exclude nothing. (#2680)
Classes such as CPArray are no longer shown in the generated documentation

This should fix #1956
2022-03-21 15:42:46 +01:00
Martin CarlbergandGitHub 68a113e7ee Fixed: New Cocoa api that replace old deprecated for calculating content and frame size of scroll view (#3023)
Old deprecated api did not work as it was accessing ivars _horizontalScroller and _verticalScroller from class method.
New Cocoa api is added as described in Apple Developer Documentation.

Also added type CPScrollerStyle
2022-03-21 15:25:09 +01:00
Martin CarlbergandGitHub 3cf3b76446 Fixed: Correct init of CPTextView when running nib2cib (#3014) 2022-03-21 15:24:34 +01:00
Didier KorthoudtandGitHub d7d561d3a9 Fixed: Aristo3 - New _CPImageAndTextView & theme parameter (#2951) 2022-03-21 15:23:16 +01:00
David SiawandGitHub 73eeda3c09 Fixed: strange lines that appear in Google Chrome (#2863) 2022-03-21 15:14:14 +01:00
Didier KorthoudtandGitHub 3d514b5010 Fixed: Aristo3 - Various _CPImageAndTextView bugs (#2914) 2022-03-21 14:28:21 +01:00
Didier KorthoudtandGitHub 93fc8d29cc Fixed: Before this PR, imagesize would provide image size in points (that is, taking care of the image resolution) instead of pixels (#2965) 2022-03-21 14:12:51 +01:00
Didier KorthoudtandGitHub 145bf65542 Fixed: Before this PR, outlet connection decoding was done before views are ready (#2959) 2022-03-21 14:10:53 +01:00
daboe01andGitHub f21555bb6c Fixed: Width of text sizing was slightly off in chrome due to a Chrome bug (#2975)
This is a real bug in chrome. see https://bugs.chromium.org/p/chromium/issues/detail?id=1192834

Also fixed: ellipsis clipping in segmented controls
and
fixed: tooltip wrapping issues from fractional pixels
2022-03-21 14:08:45 +01:00
Martin CarlbergandGitHub be072a283f Fixed: Basic support for on/off/mixed state images for menuitems from the Interface Builder (#2991) 2022-03-21 13:38:39 +01:00
David RichardsonandGitHub 9e8d51c94d New: Add additional manual test for scaleUnitSquareToSize (#2979)
Currently failing to match behaviour of Objective-C equivalent.
2022-03-21 13:37:24 +01:00
Didier KorthoudtandGitHub b3051a5bd0 Fixed: Before this PR, CPBox followed the autoresizesSubviews flags while Cocoa NSBox always autoresizes its subviews, whatever the flag is set to. (#2992) 2022-03-21 13:35:22 +01:00
Didier KorthoudtandGitHub a523cfc381 Fixed: Before this PR, CGContextSetShadow wasn't initializing the shadow color (#2966) 2022-03-21 13:33:00 +01:00
Didier KorthoudtandGitHub 6544aff88e Fixed: Before this PR, nib2cib failed if a color well or a scrollable text view was added in a CPBox (#2994) 2022-03-21 13:29:31 +01:00
Michael BachandGitHub 7c1fdbc720 Fixed: Modernise "document.write" in «index.html» to "innerHTML" (#2998) 2022-03-21 13:26:11 +01:00
daboe01andGitHub bd84804e32 Fixed: Usage of eval instead of JSON.parse for parsing JSON (#3016)
Using eval for parsing JSON is considered bad practice and is also slower
2022-03-21 13:07:44 +01:00
David RichardsonandGitHub 1f2a257bab Fixed: CPBox - Suppress superfluous warnings and expand documentation (#2996)
Warnings about borderColor, borderWidth, cornerRadius and fillColor are suppressed when boxType is CPBoxSeparator.
They are not relevant and needlessly clutter verbose output when debugging and should be suppressed.
2022-03-21 13:06:18 +01:00
daboe01andGitHub b0684929e2 Fixed: key event issues of handling escape in recent firefox … (#3020) 2022-03-21 13:02:37 +01:00
daboe01andGitHub 22dc587a8f Fixed: caret was blinking in non-editable text in CPTextView (#3022) 2022-03-21 13:00:40 +01:00
daboe01andMartin Carlberg 622fcf740e Update README.markdown
make wording of system requirements more concise
2022-03-21 12:58:55 +01:00
cacaodevandGitHub 77b59c8a18 Merge pull request #3024 from cappuccino/revert-2963-compile_deep_structured_project_in_browser
Revert "New: Support to compile deep structured project in the web browser"
2022-03-17 21:10:03 +01:00
cacaodevandGitHub 462a18930b Revert "New: Support to compile deep structured project in the web browser" 2022-03-17 21:07:16 +01:00
cacaodevandGitHub fb07def5fa Merge pull request #3017 from daboe01/fixed-sheet-animation-click-issue
fixed: freeze when clicking during sheet animation
2022-03-05 18:12:27 +01:00
cacaodevandGitHub a03ee6726e Merge pull request #2963 from mrcarlberg/compile_deep_structured_project_in_browser
New: Support to compile deep structured project in the web browser
2022-03-05 18:11:08 +01:00
daboe01 1ef49ef290 formatting 2022-01-23 13:42:12 +01:00
daboe01 76d52e07d4 fixed: freeze when clicking during sheet animation
previously, the app froze when clicking somewhere during sheet open/close animations.
these adversarial clicks are simply ignored by this PR
2022-01-23 13:39:33 +01:00
Martin Carlberg 044b0bb0d2 Fixed: NibApplication template for 'capp' to use correct build dir 2022-01-04 14:51:43 +01:00
Martin Carlberg 472b59ef80 Fixed: Allow space in path to .xib/.cib file 2022-01-04 14:51:43 +01:00
Martin Carlberg 6b559ce283 1.2.2 2021-12-03 14:02:00 +01:00
Martin Carlberg c17b806fd5 1.2.1 2021-12-03 14:00:14 +01:00
Martin Carlberg 1dcea8fe4c Added: .npmignore for easier "npm publish" 2021-12-03 14:00:02 +01:00
Martin Carlberg d72a52b9ce Merge branch 'master' into node 2021-12-03 12:36:27 +01:00
Martin Carlberg 61e01b08e5 Fixed: Rename the README back to the original name 2021-12-03 12:29:37 +01:00
Didier KorthoudtandGitHub 37756a5853 Fixed: nib2cib: checks if there's a defined superview in resizeWithOldSuperviewSize (#2995) 2021-11-23 13:47:54 +01:00
David RichardsonandGitHub b66690e304 New: Implement missing indexPath method for CPTreeNode (#2999) 2021-11-23 13:45:10 +01:00
Martin CarlbergandGitHub ccc6007bab Fixed: Bezel state instance variable _bezelState must remove current state when changing to a new state (#3001)
If the bezel state was changed and some attribute was set like an "image". The image would not be found as there were two states active and it would not match.
2021-11-23 13:42:36 +01:00
David RichardsonandGitHub 3179d56879 Fixed: Include commented code to hide mainMenu (#3008)
Add commented-out code to capp gen NibApplication template.
The technique itself is easy to forget and not obvious to newcomers.
It is included in the standard capp gen application template
and added here for completeness.
2021-11-23 13:41:30 +01:00
Martin CarlbergandGitHub b631032857 Fixed: Node build badge can be clicked to actions 2021-11-09 12:43:32 +01:00
Martin CarlbergandGitHub 49574d1c54 Fixed: Node build badge can be clicked to actions 2021-11-09 12:41:01 +01:00
Martin CarlbergandGitHub b7d7368ce6 Fixed: Include the Node build status badge at top 2021-11-09 11:49:30 +01:00
Martin CarlbergandGitHub e221156c11 Fixed: Changed name on Build & Test GitHub action 2021-11-09 11:43:39 +01:00
Martin CarlbergandGitHub 8e346acdce Fixed: Changed travis build badge to Github 2021-11-09 11:34:14 +01:00
Martin CarlbergandGitHub 7c36fa3f56 Fixed: "capp gen" template for NApplication uses environment variable CAPP_BUILD 2021-11-09 10:14:37 +01:00
Martin CarlbergandGitHub 642e254522 Fixed: Use upper case ENV variable 2021-11-09 10:07:35 +01:00
Martin CarlbergandGitHub 72aa1b8416 Fixed: Better name on the Build and Test Action 2021-11-08 17:11:43 +01:00
Martin CarlbergandGitHub edb1ef7f98 Fixed: Remove action on Node version 12 and 14
We use npm package-lock file version 2 and it is not supported by version 12 and 14
2021-11-08 13:21:40 +01:00
Martin CarlbergandGitHub 92beaba1d6 Fixed: Add Node version 12, 14 and 17 in action 2021-11-08 13:12:37 +01:00
Martin CarlbergandGitHub 3b61b1c85d Fixed: Use node branch 2021-11-08 13:07:40 +01:00
Martin CarlbergandGitHub a529e752b3 Create BuildAndTest.yml 2021-11-08 13:05:26 +01:00
Martin Carlberg d9791673df Fixed: Make sure we can build on Linux. Tested on Ubuntu 20.04 2021-11-07 13:41:01 +00:00
David RichardsonandGitHub a49a20e2c2 Fixed: nib2cib under Xcode 13 (#3006)
Backwards-compatible changes to accommodate different ibtool output from Xcode 13 onwards
2021-10-19 08:31:54 +02:00
Martin CarlbergandGitHub 8570476cff New: Added link to install the new Node version 2021-10-06 12:18:51 +02:00
Martin Carlberg d0923efa1a Fixed: Updated package-lock file. 2021-10-06 09:26:15 +02:00
Martin Carlberg eab8fe2d64 Fixed: Divided 'jake install' into 'jake dist' and 'jake install'
'jake dist' will do everything that 'jake install' does but creating the global symlinks
for the 'dist' binaries at the 'npm prefix' path.
2021-10-05 11:34:25 +02:00
Martin Carlberg c9e8b2970b Fixed: Moved out nib2cib functions to correct scope so they can be accessed by catch 2021-10-04 12:51:12 +02:00
Martin Carlberg 1440c156b2 Fixed: Make the path to the Frameworks directory for each package 2021-10-01 19:32:53 +02:00
Martin Carlberg ddfa4445ae Fixed: Move the 'objj' tool to the right place 2021-10-01 13:11:57 +02:00
Martin Carlberg 1f501e6429 Fixed: Make sure environment variables are included when running test-only 2021-10-01 13:10:46 +02:00
Martin Carlberg 7969f118de Fixed: Build in project home directory if no environment variables are set
Earlier the build directory was placed in the parent directory
2021-10-01 08:45:58 +02:00
Martin Carlberg 706166dc5c Fixed: Make sure we use the built parts of Cappuccino when building parts that is dependent of former.
This is done by passing the environment variable 'OBJJ_OPT' when spawning a new jake task. The content
of OBJJ_OPT will be parsed as arguments when starting an Objective-J tool
2021-09-29 09:18:12 +02:00
Martin Carlberg 4a8667e0f3 Fixed: Exit with error code when test cases did fail 2021-09-28 15:31:01 +02:00
Martin Carlberg 094fbcc67c Fixed: Move Terser from a development dependency to a regular dependency 2021-09-22 09:37:22 +02:00
Martin Carlberg d34c47c167 Fixed: Use preset variable from common.jake for build directory 2021-09-21 20:49:05 +02:00
Martin Carlberg 7226330514 Fixed: Create soft link to node_modules in a simpler way 2021-09-21 20:31:29 +02:00
Martin Carlberg 852b2bd5d9 Fixed: Missing enquote of path when creating build directory and soft link to node_modules 2021-09-21 17:56:14 +02:00
Martin Carlberg 3d8ecfad47 Fixed: Use unique temp directory for each run with nib2cib 2021-09-21 16:04:10 +02:00
Martin Carlberg 9e6f1e0dc3 Fixed: Timezone abbreviation was not working with the latest changes on all setups.
This is still not 100% but looks like it works a little bit better
2021-09-21 15:38:51 +02:00
Martin Carlberg 4deb7a3f51 Merge branch 'node' of github.com:cappuccino/cappuccino into node 2021-09-21 12:54:00 +02:00
Martin Carlberg 5b0b030435 Fixed: Exclude the dist folder except cappuccino/bin and objective-j/bin 2021-09-21 12:52:48 +02:00
Martin Carlberg 4edec2df2e 1.2.0 2021-09-21 12:34:10 +02:00
Martin Carlberg e0596bdf75 Fixed: Added latest package.json files 2021-09-21 12:34:04 +02:00
Martin Carlberg 6430463b5d Fixed: Included the latest binaries into the dist folder. 2021-09-21 12:31:45 +02:00
Martin Carlberg d9e27e549f Fixed: Removed compiler warnings in test case 2021-09-21 11:11:57 +02:00
Martin Carlberg 9f14dac5d2 Fixed: Cleanup of the output from our test cases 2021-09-21 11:11:25 +02:00
Martin Carlberg d70199ca58 Fixed: Asynchronous and output changes from the new Terser compressor 2021-09-21 11:09:09 +02:00
Martin Carlberg 6b1cdbd19c Fixed: Removed compiler warnings from test cases 2021-09-21 10:58:03 +02:00
Martin Carlberg 5b99757a0d Fixed: The compiler might inline the 'message send' call so we do it manually in these test cases. 2021-09-21 10:56:10 +02:00
Martin Carlberg 6c49116c68 Fixed: Use date string that is not as old as the previous one.
JavaScript now handles time a lot better. Times from before around 1900 is different in different
parts of the world so we just changed this test case to be a bit more modern.
2021-09-21 10:55:16 +02:00
Martin Carlberg 68f0cf27df Fixed: Bundle test cases must run asynchronous as a bundle will also load asynchronous in Node.
Also removed some compilation warnings from the test cases.
2021-09-21 10:51:17 +02:00
Martin Carlberg 89757e35e6 Fixed: Class Swapper should convert NSView -> CPView.
This is needed when a plain NSView is use without a Custom class name as it will otherwise try to create a NSView.
Also the Class Swapper is only used when the 'Instantiation' is check for 'Prefer code' under
the 'Runtime Behavior' header in the Document tab in Xcode. If this is not checked the '_CPCibCustomView'
is used instead of the Class Swapper.
2021-09-21 10:46:18 +02:00
Martin Carlberg 24bf09b70c Fixed: Abbreviation for a timezone is not handled in JavaScript. This changes makes it better but not perfect. 2021-09-21 10:30:26 +02:00
Martin Carlberg 0ed2709124 Fixed: Better message when loading a cib file and the class swapper doesn't find a class 2021-09-21 10:26:33 +02:00
Martin Carlberg a835202db1 Fixed: Adjusted test cases for Node. XMLHttpRequest now demands a protocol. 2021-09-20 11:00:37 +02:00
Martin Carlberg 830fbbab26 Fixed: Removed old Rhino adjustments in test cases 2021-09-20 10:51:14 +02:00
Martin Carlberg 119e11cfe2 Fixed: Allow 'await' for loading a bundle with the method 'loadWithDelegate:' 2021-09-20 09:19:05 +02:00
Martin Carlberg 511e18b44f Fixed: Wait for the bundle load to finish with the new async bundle load function 2021-09-17 21:55:48 +02:00
Martin Carlberg 2f00d93b22 Fixed: Must check in Node if path exists when doing 'fs.lstatSync' as it will throw if not. 2021-09-17 10:39:11 +02:00
Martin Carlberg 973fa1b978 Fixed: Misspelled function name 2021-09-17 10:37:03 +02:00
Martin Carlberg 79f40d24ae Fixed: Replace soft link to the directory 'node_modules' when it is already there. 2021-09-17 09:39:37 +02:00
Martin Carlberg fdff92e5c8 Fixed: Ask Node for a temporary directory instead of using '/tmp' 2021-09-17 09:38:29 +02:00
Martin Carlberg 653dd07162 Fixed: Include the tool 'objj2objcskeleton' in the installed binaries 2021-09-15 17:38:24 +02:00
Martin Carlberg b7968ca4a7 Fixed: Make sure output from the tool 'ojtest' gets to the terminal.
Also suspend stack trace etc. when the tests fails with a try ... catch.
2021-09-15 17:37:04 +02:00
Martin Carlberg 2a0a6449e5 Fixed: Converting the test cases in ToolTest.j to Node 2021-09-15 17:33:21 +02:00
Martin Carlberg b7c04d7d16 Fixed: Converted the tool 'objj2objcskeleton' for Node 2021-09-15 17:32:31 +02:00
Martin Carlberg ab4c87e69f Fixed: Removed warnings and cleanup for test cases when converting to Node 2021-09-15 17:31:20 +02:00
Martin Carlberg 8257632706 Fixed: When creating a method the function name can't start with '0_' 2021-09-15 17:28:07 +02:00
Martin Carlberg 3f8821b43b Fixed: Adjust arguments for the tool objj
This has changed now when running on Node.
2021-09-15 17:26:40 +02:00
Martin Carlberg f6b8bc0c45 Fixed: Include source files when compiling ojtest 2021-09-15 17:25:36 +02:00
Martin Carlberg 0618fa9bb2 Fixed: Added protocol to data source and delegate for outline view 2021-09-15 17:24:31 +02:00
Martin Carlberg 2e5a483dce Fixed: Added examples how to add macros in the 'capp gen' templates index[-debug].html files 2021-09-13 09:38:02 +02:00
Martin Carlberg e608e0dbf3 Fixed: Partly adapted Tooltest for Node 2021-09-10 15:56:12 +02:00
Martin Carlberg a88e316a94 Fixed: Compile OJTest with source map for easier debugging 2021-09-10 15:55:40 +02:00
Martin Carlberg 51ffa256ca Fixed: Preprocessor Output test adapted for Node 2021-09-10 15:55:01 +02:00
Martin Carlberg 52bd654850 Fixed: The new script for the ojtest tool must be in the dist/cappuccino/bin directory 2021-09-04 09:15:24 +02:00
Martin Carlberg 0518d479d3 Fixed: Included ojtest as binary in the package.json file 2021-09-03 16:28:23 +02:00
Martin Carlberg a893f3f5c1 Fixed: The tool ojtest now works with the new Node version. 2021-09-03 14:31:11 +02:00
Martin Carlberg 9c2f37b43f Fixed: The Tool nib2cib will give information of used Resource directory. 2021-09-02 12:44:48 +02:00
Martin Carlberg 0289ba17f1 Fixed: Add test task for Framework template used by the tool capp gen
Plus some minor bugfixes
2021-09-02 11:23:32 +02:00
Martin Carlberg 5db94e1e52 Fixed: Cleanup of the Jakefile template for Application and Framework used by the tool "capp gen" 2021-09-01 16:28:55 +02:00
Martin Carlberg a4bc08c29e Fixed: Moved enquote function to utils package.
This function was originally in the Narwhal package OS
2021-09-01 16:27:16 +02:00
Martin Carlberg b638d8e904 Fixed: From around Xcode 12.5.1 ibtool starts to create a folder with two files.
We have to check for this and take action. We don't know of this is a temporary thing as Apple has no
information about this change.
2021-08-30 16:29:43 +02:00
Martin Carlberg 251ce7fdad Fixed: Info.plist file with just whitespaces is not treated as an empty file in Node. Trim it and check length. 2021-08-27 09:08:19 +02:00
Martin Carlberg a2337a2969 Fixed: Can't use generic array of numbers when writing to file with Node 2021-08-27 09:04:51 +02:00
Martin Carlberg 0c803e26ca Fixed: Must expand path to absolute to be able to get application name. Was translated to wrong Node function when converting from Narwhal. 2021-08-27 09:03:58 +02:00
Martin Carlberg ab25fadb1e Fixed: Function for imagesize used wrong and non declared argument 2021-08-27 09:02:26 +02:00
Martin Carlberg e697f4eca7 Fixed: Better debugging experience 2021-08-27 09:01:19 +02:00
Martin Carlberg 80158a8982 Fixed: Cleanup of fontinfo and imagesize Jakefile 2021-08-27 08:59:45 +02:00
Martin Carlberg 55bcfacf3b Fixed: Moved common function used in Jakefiles that was declared all over the place to a file.js in @objj/utils. Also some general cleanup. 2021-08-25 09:32:58 +02:00
Martin Carlberg 52b7a82b4d Fixed: Cleanup of Jakefiles for better Node adaption 2021-08-24 10:58:12 +02:00
Martin Carlberg 471e605871 Fixed: removed debug log message 2021-08-23 11:14:12 +02:00
Alfred Wärnsäter 5c635f17a7 require node 14 as minimum 2021-08-20 14:22:11 +02:00
Alfred Wärnsäter c27d604780 removed print statement 2021-08-20 09:29:59 +02:00
Alfred Wärnsäter ddaf575719 fixed --version option in nib2cib 2021-08-20 09:29:34 +02:00
Alfred Wärnsäter 0757f2ea80 corrected instructions for Node alpha 2021-08-20 09:28:11 +02:00
Alfred Wärnsäter 3f8dfb6516 removed debugger statement 2021-08-20 09:27:03 +02:00
Alfred Wärnsäter 45ee25adc2 removed print statement 2021-08-20 09:26:13 +02:00
Alfred Wärnsäter fcfb3d4083 added bin dir from dist 2021-08-19 17:31:21 +02:00
Alfred Wärnsäter 357f8bd684 1.1.1 2021-08-19 16:36:38 +02:00
Alfred Wärnsäter 173cd8b4ad bumped npm version 2021-08-19 16:36:27 +02:00
Alfred Wärnsäter d2ca5994c8 1.2.0 2021-08-19 16:35:39 +02:00
Alfred Wärnsäter fe04d177af added more instructions 2021-08-19 16:35:19 +02:00
Alfred Wärnsäter 2a6b18bc1b added more instructions 2021-08-19 16:33:15 +02:00
Alfred Wärnsäter 152cd272f6 updated readme for Node alpha version 2021-08-19 16:07:26 +02:00
Alfred Wärnsäter abbdc139e8 now using sudo only when necessary 2021-08-19 13:59:43 +02:00
Alfred Wärnsäter 7226019b6a use npm prefix for install path 2021-08-19 13:30:40 +02:00
Alfred Wärnsäter 78ea29bd48 added dist to to gitignore 2021-08-19 11:15:27 +02:00
Alfred Wärnsäter 5c90d1f769 added binary part of dist dir 2021-08-19 11:14:38 +02:00
Alfred Wärnsäter 2ecea40fdc lots of Node fixes 2021-08-19 10:56:13 +02:00
Martin Carlberg 8d9c11b6f2 Fixed: Make sure we return the result from an executed file in the callback 2021-08-18 15:56:36 +02:00
Martin Carlberg afd23e3457 Fixed: Added file translation dictionary for the Foundation framework
This allows the Foundation framework to be compiled while loading the Application in the Browser
2021-08-17 16:47:06 +02:00
Alfred Wärnsäter ddeaad74d0 added jake stuff to bundletask 2021-08-10 12:31:48 +02:00
Alfred Wärnsäter a82472f509 removed unused dependancies 2021-08-10 12:29:43 +02:00
Alfred Wärnsäter 4a43e376ed modified capp to work with node 2021-08-10 12:27:50 +02:00
Alfred Wärnsäter 9ab82e1e5e removed console.log statement 2021-08-10 12:24:20 +02:00
Didier KorthoudtandGitHub 4b28d0c38b Fixed: setTextColor on a CPTextField would not take visual effect before an event (#2993) 2021-08-06 12:17:07 +02:00
Alfred Wärnsäter 1924cd1822 removed fs-extra dependancy 2021-08-06 11:02:55 +02:00
Alfred Wärnsäter 730b2dd874 removed glob dependancy 2021-08-06 10:36:04 +02:00
Alfred Wärnsäter 1c2b383838 removed uuid dependancy 2021-08-06 09:43:49 +02:00
Alfred Wärnsäter 0b99f83d6f fixed bug that broke the build process when building twice 2021-08-05 17:53:45 +02:00
Alfred Wärnsäter dc5b3f48e8 fixed watch functionality in nib2cib 2021-08-05 16:22:36 +02:00
Alfred Wärnsäter d17671c99e added parsing of command line arguments 2021-08-04 15:19:10 +02:00
Alfred Wärnsäter b69259e83b swapped print to console.log 2021-08-04 15:16:41 +02:00
Alfred Wärnsäter f2c80dc815 added node_modules to .gitignore 2021-08-04 15:15:12 +02:00
Alfred Wärnsäter cbc281b173 added terser as compressor 2021-08-04 09:25:36 +02:00
Alfred Wärnsäter 472f859bd8 basic support for nib2cib 2021-08-03 13:39:54 +02:00
Alfred Wärnsäter e71f650650 removal of print and debugger statements + added some more color 2021-07-30 15:35:57 +02:00
Alfred Wärnsäter e64c9d9cd4 starting to port the capp tool to node 2021-07-30 14:09:11 +02:00
Alfred Wärnsäter 87a1c6621c ported nib2cib from narwhal to node, it now build using objj-jake 2021-07-29 13:20:30 +02:00
Didier KorthoudtandGitHub 09f49c4afa Fixed: CPButton should not have the same label text size whatever the control size (#2990)
Adding font size definitions to Aristo2.
2021-07-29 12:38:25 +02:00
eba1b2f999 Fixed: CPSearchField's bezel did not resize (#2987)
Co-authored-by: Didier Korthoudt <didier.korthoudt@icloud.com>
2021-07-29 11:39:42 +02:00
daboe01andMartin Carlberg 8e026279ac fixed: CPButton's images were lost when becoming disabled 2021-07-29 11:30:55 +02:00
Alfred Wärnsäter 3605e99914 minor bugfixes and clean up 2021-07-28 10:12:24 +02:00
Alfred Wärnsäter 5e9d479cef AppKit and Themes are now buildable 2021-07-27 08:59:05 +02:00
David RichardsonandMartin Carlberg fb20463449 Fix Java version check to cleanly identify both Oracle and OpenJDK variants
Set minimum supported version to 8 to simplify this check.
Java 8 is the last variant from Oracle to be free and unencumbered, and is classified LTS.
It is also available from OpenJDK.
2021-07-05 11:07:53 +02:00
Alfred Wärnsäter f5db73342f changed some code in blendtask.j to older javascript 2021-07-01 16:45:39 +02:00
Alfred Wärnsäter 9b2dc23197 finished porting blendtask.j 2021-07-01 16:30:30 +02:00
Alfred Wärnsäter 067052e1a8 ported blendtask.j to node api 2021-07-01 16:17:43 +02:00
Alfred Wärnsäter 441e5fbc05 ported nib2cib to node the node api 2021-07-01 16:00:32 +02:00
Alfred Wärnsäter 0a2aae3bc2 some restructuring of the repo, trying to fix problems when building with node 2021-06-30 10:13:52 +02:00
Alfred Wärnsäter a76c798500 Merge remote-tracking branch 'mrcarlberg/compile_deep_structured_project_in_browser' into tmp 2021-06-23 10:45:34 +02:00
Alfred Wärnsäter c238ebeef4 major changes, very much WIP, experimenting with async 2021-06-22 14:04:31 +02:00
Alfred Wärnsäter 206eddbdbd further removal of narwhal APIs 2021-06-16 15:43:19 +02:00
Alfred Wärnsäter 45549cdbcf removing narwhal api from jakefiles 2021-06-14 13:17:14 +02:00
cacaodevandGitHub e043b6a8c5 Merge pull request #2978 from daboe01/nib2cib-update
fixed: some cib files have been outdated
2021-05-22 10:48:30 +02:00
daboe01 677076b89d fixed: some cib files have been outdated 2021-04-01 18:04:06 +02:00
cacaodev 77c9b99f74 Manual test exposing issue #2970 2021-03-07 20:46:44 +01:00
cacaodevandGitHub c8cdda0c18 Merge pull request #2962 from mrcarlberg/cptextview_more_ib_options
Fixed: CPTextView now handles more options from Interface Builder
2021-03-07 08:48:50 +01:00
daboe01andGitHub 41cd73703e Fixed: sharedApplication was instantiating the wrong class in subclasses of CPApplication (#2968)
Previously, CPApplication was hard-coded. This PR makes sharedApplication
instantiating the CPApp of the correct class.
2021-01-19 09:03:37 +01:00
cacaodevandGitHub 607e84c052 Merge pull request #2964 from mrcarlberg/compiler_remove_unused
Fixed: Removed unused variables and statements in compiler
2020-12-23 07:36:29 +01:00
Martin Carlberg 8416390631 Fixed: Removed unused variables and statements in compiler 2020-12-22 20:16:30 +01:00
Martin Carlberg 6094d25cfb New: Support to compile deep structured project in the web browser
A Cappuccino project has always needed to have a flat file structure to
be able to compile from source in the web browser.

A new dictionary can be added to the project's Info.plist with the key
'CPFileTranslationDictionary'. It should contain all the path
translations in the project to allow the Browser to find out where in
the file structure the source files are. Check in the AppKit framework
for an example.

Also, a include list can be added in the Info.plist for the key
'CPCompileIncludeFileArray'. The file in the list will be included
by a '#include' statement for each file that is compiled in this project

A last new feature is to add macros in the 'OBJJ_COMPILER_FLAGS' global
variable. It is usually declared in the index.html file. It is done
with the format '-Dmacroname[=macrodefinition]'.

An updated Info.plist file in the AppKit framework will allow the AppKit
to compile from the source in the web browser. The following things is
needed to get this to work:

1. Replace the AppKit folder in your project's Frameworks folder with a
copy of the AppKit folder from the Cappuccino project.
2. Add a copy of the built Aristo2.blend folder to the AppKit's Resource
folder.
3. Add "-DPLATFORM_DOM", "-DPLATFORM_BROWSER" and optionally "-DDEBUG"
to the global variable 'OBJJ_COMPILER_FLAGS' in the project's index.html
file.

The app load time will increase (about 3 seconds on a 2018 MacBook Pro)
as the AppKit framework is compiled from source.

The Foundation framework is not yet tested but it might be working by
adding info about the file structure in the Info.plist file.
2020-12-21 11:14:36 +01:00
cacaodevandGitHub c80504efae Merge pull request #2960 from mrcarlberg/cptextview_exposedrect
Fixed: Prevent crash in CPTextView when _exposedRect is nil
2020-12-19 15:19:19 +01:00
cacaodevandGitHub 2589033523 Merge pull request #2961 from mrcarlberg/radio_multiple_value_bindings_test
New: Unit test to illustrate multiple value bindings on radio buttons
2020-12-19 15:18:27 +01:00
Martin Carlberg f74fed5ee0 Fixed: CPTextView now handles more options from Interface Builder
The new options are:
1. Resizable Horizontally
2. Resizable Vertically
3. Max Size

Also two options from the Text Container is recognized:
1. Tracks text view width
2. Tracks text view height

The last two are needed to allow the text view to recalculate
the size of its content if the frame size is changed.
2020-12-16 11:29:11 +01:00
Martin Carlberg 01e295084c New: Unit test to illustrate multiple value bindings on radio buttons 2020-12-14 13:11:24 +01:00
Martin Carlberg 9f923941a8 Fixed: Prevent crash when _exposedRect is nil 2020-12-14 12:47:34 +01:00
Didier KorthoudtandGitHub 3aba03eb28 Fixed: Missing call to super in NSTabView.j (#2956) 2020-11-22 11:01:14 +01:00
Didier KorthoudtandGitHub 1107195ab6 Fixed: Modern Cocoa behavior, new theme parameters, Aristo3 CSS theme ready for CPTabView (#2936) 2020-11-20 08:33:56 +01:00
Didier KorthoudtandGitHub b67384cdd1 Fixed: Running condition where the value is set before the radio button is associated in a radio group (#2952) 2020-11-20 08:25:03 +01:00
David RichardsonandGitHub 59603b550e Fixed: "Loading…" animation using modern layout (#2953)
Correct vertical alignment in all modern browsers. IE no longer a target.
2020-11-20 08:22:45 +01:00
David RichardsonandGitHub c52f714149 Fixed: Version check for XcodeCapp compatibility with Big Sur (#2954) 2020-11-20 08:20:19 +01:00
Didier KorthoudtandGitHub 35420732d1 Fixed: Modern Cocoa behavior and Aristo3 CSS theme ready for CPDatePicker (#2935)
Also, clock hands can be manipulated
2020-11-06 16:27:07 +01:00
David RichardsonandGitHub 7f48b84292 Fixed: Update template for NibApplication's xib and cib to modern format (#2946) 2020-11-06 08:31:22 +01:00
Didier KorthoudtandGitHub 5110c5706f Fixed: Compilation warnings (#2950) 2020-11-06 07:25:21 +01:00
Didier KorthoudtandGitHub 633511acda Fixed: Before this PR, placing a CPTableView in a CPBox would break nib2cib (#2949) 2020-10-31 17:56:13 +01:00
Didier KorthoudtandGitHub 75d0a69c02 Fixed: uncorrect CPStepper rendering (#2948) 2020-10-30 10:58:34 +01:00
Didier KorthoudtandGitHub e6fe9396f8 Fixed: Change default bezel style to CPRoundRectBezelStyle for CPButton (#2947)
Also removes unwanted comments
2020-10-27 11:01:18 +01:00
Didier Korthoudt fccd76ec4c v02
This commit :
- removes global variables direct access
- better handles Aristo2 retro-compatibility
2020-10-25 11:44:03 +01:00
Didier KorthoudtandGitHub 5c4107835b New: Aristo3 improvements for CPSearchField (#2934)
New theme parameters
Animations
Modern Cocoa behavior
Aristo3 CSS theme ready
2020-10-23 09:05:33 +02:00
Didier KorthoudtandGitHub 57cc90f89f New: Provides more information on an error message in CPScroller (#2931) 2020-10-23 08:43:59 +02:00
Didier KorthoudtandGitHub 7e08e48a8a New: Adds a new theme parameter "menu-offset" to CPPopUpButton instead of hard coded value (#2923) 2020-10-23 08:42:00 +02:00
Didier KorthoudtandGitHub 87719f1161 Fixed: Adds the missing isCSSBased method for CPView (#2945) 2020-10-12 08:51:49 +02:00
Didier KorthoudtandGitHub 39738b9ded Merge branch 'master' into 010-CPApplicationOSBehavior 2020-10-10 18:27:45 +02:00
Didier KorthoudtandGitHub 99d7c8d824 New: Modern Cocoa behavior for Menus (#2929)
More theme parameters
Modern Cocoa behavior
First menubar item can be displayed specifically
All 3 control sizes are now managed
2020-10-09 15:52:54 +02:00
Didier KorthoudtandGitHub 1caf4f99cf Fixed: Correct / complete theme states for themed values on CPStepper (#2930) 2020-10-09 14:39:38 +02:00
Didier KorthoudtandGitHub 78b3887e4a New: CSS shadow, new theme parameters and Aristo3 CSS theme ready for CPWindow (#2927) 2020-10-09 14:29:10 +02:00
Didier KorthoudtandGitHub bb064aacd5 New: The ability to control CPPopoverWindow background color (#2928)
This introduces a Cappuccino specific behavior that permits to control the background color of the popover by setting a background color on the content view.
2020-10-09 13:37:47 +02:00
Didier KorthoudtandGitHub d9e8321d9e Fixed: CPButton's now set their font using [self font] (#2943)
The corresponding adaptation in CPControl was missing in the previous PR
2020-10-09 13:05:51 +02:00
Didier KorthoudtandGitHub 5f6df95e30 New: Modern Cocoa behavior and methods, ticked sliders and Aristo3 CSS theme ready (#2926) 2020-10-09 11:47:18 +02:00
Didier KorthoudtandGitHub ef779c346e New: Support modern Cocoa behavior regarding radio buttons groups. (#2941) 2020-10-09 09:35:56 +02:00
Martin CarlbergandGitHub c1543d4a2f Fixed: Loading cached theme attributes will miss previous cached values if superclass is done before subclass (#2892) 2020-10-02 16:01:30 +02:00
Didier KorthoudtandGitHub 9145e27009 Fixed: Aristo3 CSS theme ready and replaces setTextFieldBackgroundColor by setBackgroundColor for CPTextField (#2925) 2020-10-02 14:47:50 +02:00
Didier KorthoudtandGitHub 299f1a9102 Fixed: Aristo3 ready and compatible with new button state management for CPRadio (#2922) 2020-10-02 14:03:25 +02:00
bedaltonandGitHub 6eab438778 Fixed: CPKeyedArchiver method call does not match selector tested (#2904)
Delegate methods described on lines 76 and 85 are not the selectors
checked on lines 305 and line 302, but are the methods actually called
on the delegate on lines 195 and 225. This fix updates the method
selectors checked on the delegate, to match those defined and called
within the CPKeyedArchiver class.

Fixes #2679
2020-10-02 13:52:42 +02:00
Didier KorthoudtandGitHub 2a623fbb8c Fixed: correct mask values used to determine image position for NSButton.j (#2906) 2020-10-02 13:49:11 +02:00
Didier KorthoudtandGitHub 7bde091f1b FIXED: when using a custom view with subviews, subviews were presented in the reversed order (#2913) 2020-10-02 13:31:45 +02:00
Didier KorthoudtandGitHub 412baf7872 Fixed: Aristo3 ready and modern Cocoa behavior for CPBox (#2924) 2020-10-02 13:28:06 +02:00
Didier KorthoudtandGitHub 010057d9e1 New: CPCheckBox Aristo3 ready and compatible with new button state management (#2921) 2020-10-02 13:05:59 +02:00
Didier KorthoudtandGitHub 6c7d8df565 Aristo3: CPButton (#2920) 2020-10-02 12:59:32 +02:00
Didier KorthoudtandGitHub 92598da06f New: themable-system-font (#2919) 2020-10-02 12:55:32 +02:00
Didier KorthoudtandGitHub 601d6f7c6c New: class method to BKThemeDescriptor that enables a view to inherit theme values of another view (#2916) 2020-10-02 12:31:22 +02:00
Didier KorthoudtandGitHub e13cebaa3a NEW: Material icon image (#2909) 2020-10-02 12:13:00 +02:00
Didier KorthoudtandGitHub 5724868c5a Fixed: restorePreviousCSSState method for CPColor must be a class method for internal reasons (#2912) 2020-10-02 10:58:20 +02:00
Didier KorthoudtandGitHub 03972f0aec Fixed: The classname for CSS theming on CPImage was not specified in the correct DOM element (#2908) 2020-10-02 10:55:55 +02:00
Didier KorthoudtandGitHub 6143ec4180 Fixed: Theme compilation problem because of lack of rgba capability of the compiler environment.(#2910) 2020-09-11 09:01:33 +02:00
Didier KorthoudtandGitHub c30464ee77 New: This adds the CSS dictionaries to the description of the color (#2911) 2020-09-11 08:55:10 +02:00
cacaodevandGitHub 1e1e6456cd Merge pull request #2902 from daboe01/test-attributedString-replacing
new: unittest for replaceOccurrencesOfString:withString:options:range:
2020-09-02 18:26:14 +02:00
cacaodevandGitHub 6c46bb4756 Merge pull request #2940 from didierkorthoudt/031-CPViewAnimator-fix
FIXED: This PR fixes correct parameter type in CPViewAnimator -setAlphaValue
2020-09-02 18:21:45 +02:00
Didier Korthoudt 3a18574838 Buttons fixes 2020-09-02 17:28:55 +02:00
Didier Korthoudt 5ac6b1d1f1 Update CPViewAnimator.j
This fixes parameter type.
2020-08-30 10:01:11 +02:00
Didier Korthoudt ec238f2cc3 000-Aristo3 2020-08-30 09:54:30 +02:00
Didier Korthoudt 8c08803fd0 030-CPTableView 2020-08-30 09:47:21 +02:00
Didier Korthoudt cc084692ae Update CPButtonBar.j 2020-08-29 23:42:21 +02:00
Didier Korthoudt 96a25dfcaa Update CPSegmentedControl.j 2020-08-29 22:14:02 +02:00
Didier Korthoudt 500237b2c8 Update CPScrollView.j
- new theme parameters
- Aristo3 CSS theme ready
2020-08-29 22:03:48 +02:00
Didier Korthoudt 67a0098c7a CPApplicationOSBehavior 2020-08-28 17:21:41 +02:00
daboe01 9c95c9c6e9 formatting 2020-07-13 20:37:52 +02:00
daboe01 4b052e74f1 test whether range restriction works 2020-07-05 16:06:04 +02:00
daboe01 bd6b8e4b7f fixed: comparison between wrong objects 2020-07-03 21:27:48 +02:00
daboe01 26e8432bb0 debugging 2020-07-03 19:55:51 +02:00
daboe01 05f9fd22fe formatting 2020-07-03 19:36:06 +02:00
daboe01 8f5bde2797 new: unittest for replaceOccurrencesOfString:withString:options:range: 2020-07-02 19:38:34 +02:00
daboe01andGitHub 77fe16faec Fixed: background color attribute was ignored by CPTextView (#2899) 2020-07-01 16:33:07 +02:00
Martin CarlbergandGitHub 38dd776049 Fixed: JavaScriptCore (WebKit) has a limit at 65536 on number of arguments in a function. (#2891)
The compiler will crash for really large Objective-J files as the array with code segments will hit this limit.
The solution is to append the array segment by segment.
2020-06-30 20:53:28 +02:00
daboe01andGitHub 7e3c4074e4 New: replaceOccurrencesOfString:(CPString)target withString:(CPString… (#2900)
New: replaceOccurrencesOfString:(CPString)target withString:(CPString)replacement options:(int)options range:(CSRange)searchRange
2020-06-30 20:52:34 +02:00
cacaodevandGitHub 89c8f8e80f Merge pull request #2895 from mrcarlberg/bad_merge
Fixed: Removed old unused line from a bad manual merge
2020-05-05 08:38:05 +02:00
Martin Carlberg 7397e681f4 Fixed: Removed old unused line from a bad manual merge 2020-05-04 13:42:37 +02:00
Didier KorthoudtandGitHub e7d5afe90e New: Added dynamic attributes set for CSS based themes (#2701) 2020-04-06 13:10:34 +02:00
Didier KorthoudtandGitHub 2d9d354a05 Fixed: When a CPSearchField predicate was bound specifying a predicate format using more than one time the value of the search field ($value), only the first occurence was correctly set, others were set to null (#2777) 2020-04-06 13:03:57 +02:00
Didier KorthoudtandGitHub 60a686d75c Fixed: _CPMenuItemStandardView didn't take in account the left-margin theme attribute (#2689) 2020-04-06 09:18:31 +02:00
Didier KorthoudtandGitHub 89b70843c7 Fixed: Nib2cib was using hard coded frame adjustment for CPBox (#2761) 2020-04-06 09:17:05 +02:00
daboe01 9f9044b164 fixed: selection and backspace are recently broken in CPTokenField
this bug was introduced by commit 26aab29
 26aab29 was meant to improve iOS experience but makes the tokenfield loose FR status prematurely
2020-03-22 11:59:24 +01:00
Didier KorthoudtandGitHub 617987f4a5 Fixed: CPTextField forced height to 29 instead of using theme value min-size (#2688) 2020-03-17 09:14:25 +01:00
daboe01andGitHub 5bb338d6ec New: CPTextField now supports the CPEditorRegistrationProtocol (#2169) 2020-03-11 10:30:00 +01:00
Didier KorthoudtandGitHub 8003d91c4a Fixed: [CPControl setTextColor:] was missing theme state attribute (#2828) 2020-03-11 10:20:04 +01:00
Didier KorthoudtandGitHub a4ef18ddab FIXED: Before this PR, only CPControl could use nib2cib-adjustment-frame. (#2831) 2020-03-11 10:17:14 +01:00
daboe01andGitHub 82e55b4761 Fixed: _glyphsFrames and _glyphsOffsets could be used uninitialized in CPTextView (#2886) 2020-03-03 17:04:52 +01:00
Didier KorthoudtandGitHub 3a51c386ca Fixed: Before this PR, a click in a not first key responder CPTextField would misplace the caret if text alignment was not CPLeftTextAlignment #2887
Adapts the calculation of where in the textfield text the mouse is clicked to take in account the text alignment
2020-03-03 17:02:42 +01:00
Didier KorthoudtandGitHub 9868519cc0 Fix: Before this PR, the method attributeBySettingValue ignored existing values #2888 2020-03-03 16:43:29 +01:00
Didier KorthoudtandGitHub 038c007915 FIXED: Before this PR, CPButton never declares that its label should be single line (#2889) 2020-03-03 13:44:07 +01:00
Didier KorthoudtandGitHub ba6350e24d NEW: CPSplitView modern Cocoa behavior implementation (#2876) 2020-02-21 14:32:53 +01:00
Martin CarlbergandGitHub 1c866931f3 New: The compiler will now create warnings for variables that are never read (#2871)
This new warning adds a lot of warnings in the Cappuccino frameworks. I have turned off
the warning in the Jakefiles when compiling most of the Cappuccino frameworks. But it is
on as default for any user projects.

So there is also a new feature to turn off/on warnings as a compiler flag.

These flags are (all flags are on as default):
-Wunused-but-set-variable                    Warning when a local variable is never read.
-Wshadow-ivar                                Warning when a local variable is shadowing an instance variable for the class.
-Wcreate-global-inside-function-or-method    Warning when creating a global variable inside a function or method.
-Wunknown-class-or-global                    Warning when a class or global variable is not known.
-Wunknown-ivar-type                          Warning when the type for an instance variable is not known.

To turn off a flag add a 'no-' prefix. Example: -Wno-unused-but-set-variable

For an example how to use it in a Jakefile please look at the Jakefiles in this commit.
2020-02-21 14:29:48 +01:00
cacaodevandGitHub b7aff28b5e Merge pull request #2884 from daboe01/documentation-for-attributedStringWithAttachment
fixed: documentation for attributedStringWithAttachment: was missing
2020-02-04 13:14:45 +01:00
cacaodevandGitHub f0897ffdf8 Merge pull request #2885 from mrcarlberg/predicate_not_equal_nil
Fixed: CPPredicate does never evaluate to true for 'something != nil'
2020-02-04 13:06:37 +01:00
Martin Carlberg f5937a6fad Fixed: CPComparisonPredicate does never evaluate to true for a predicate like 'something != nil'
An example:

var array = @[ @{@"Name": @"1"},
               @{@"Name": @"2", @"approveTime": @"Now"}
             ];

var predicate = [CPPredicate predicateWithFormat:@"approveTime != nil"];

CPLog(@"result: %@", [array filteredArrayUsingPredicate:predicate]); // result: <empty array>

If I run this in Cappuccino I get an empty array

If I run it in Cocoa on a Mac I get:

result: (
        {
        Name = 2;
        approveTime = Now;
    }
2020-01-31 14:24:29 +01:00
Martin CarlbergandGitHub 7dc77ed609 Fixed: Make sure we handle undefined when testing for nil values (#2862) 2020-01-31 13:43:58 +01:00
daboe01 d1bfe62a65 removed: obsolete fixme comment 2020-01-12 17:08:23 +01:00
daboe01 f7c8f24bff removed dead code 2020-01-11 15:13:30 +01:00
daboe01 055d63eeb5 formatting 2020-01-11 15:13:04 +01:00
daboe01 ef7f92ed15 fixed: documentation for attributedStringWithAttachment: was missing 2020-01-11 15:09:41 +01:00
daboe01andMartin Carlberg 8daa53dd3e Fixed: CPTextView keyboard issue in recent Firefox versions (#2874)
Wrong characters were sometimes emitted in keyboard events on Firefox
2020-01-07 12:34:39 +01:00
Martin CarlbergandGitHub 109003ae12 Fixed: Performance improvement on visibleRect when updating tracking areas (#2881)
Calculations of the visible rect can be a heavy operation as it depends of the superviews
visible rect. They have to be transformed and intersected together to create the result.
This calculation is a recursive operation that travels up the view hierarchy all the way
to the top.

Updating the tracking areas is also a recursive operation. But it travels down the view hierarchy
instead. It will calculate the new tracking area using the visible rect for the current view. For
each view it updates it will get the visible rect that has to travel all the way up the view
hierarchy to calculate it by transform and intersect them together. This results in that the visible
rect will be calculated for each view multible times. This makes it a very slow operation, specially
for deeper view hierarchies.

This fix will send along the visible rect for the superview when traveling down the
view hierarchy. This means that the visible rect does not need to travel up the view hierarchy
to be calculated. It will just need transform and intersect the provided rect for its superview
with the one from itself.
2020-01-06 12:48:40 +01:00
Martin CarlbergandGitHub 36f1abdbe6 Fixed: CPAppearance has much better performance now when views needs layout. (#2880)
This makes updating views much faster when they need layout. This will make resizing browser window and changing split views sizes much smoother.

The effectiveAppearance is inherited from the superview. The superviews appearance is passed along as it is recomputed down the view hierarchy.
Also the current appearance is saved on each view to make it possible to only change the theme states when the appearance is changed.
2020-01-06 12:35:38 +01:00
Martin CarlbergandGitHub 50519776e0 Fixed: Update Tracking areas only once when doing setFrame: (#2879)
This speed improvement is very notable when resizing a browser window of altering the size of split views.
The fix uses a variable on the window to control when to update the tracking areas.
If the view is not connected to a window the tracking areas will not be updated as they will
be when added to a window.
2020-01-06 12:32:35 +01:00
daboe01andMartin Carlberg 9e289574ff Fixed: attachment support was missing in CPTextView (#2872) 2019-12-19 09:08:33 +01:00
cacaodevandGitHub 2d96b06d4c Merge pull request #2878 from didierkorthoudt/CPButton-continous-bug
FIXED: Before this PR, disabled buttons that were continuous responded to mouse clicks
2019-12-17 13:27:06 +01:00
cacaodevandGitHub 0c706cfed2 Merge pull request #2866 from mrcarlberg/cpset_enumerator_use_stop_variable
Fixed: CPSet enumerateObjectsUsingBlock: will honor the stop variable
2019-12-16 11:27:37 +01:00
Didier Korthoudt 3f9e1c6c47 Continuous fix 2019-12-15 10:48:21 +01:00
jasperdebandMartin Carlberg 58c08cebd7 Fixed: Added underline support in CPTextView (#2875) 2019-12-06 09:12:31 +01:00
Martin CarlbergandGitHub fed0703ecf New: Allow lazy loading control for combined observer key paths (#2854)
This pull request adds a kvoValueForKey: method used by _CPKVOForwardingObserver for getting values.
The default action is to just return the valueForKey value.
Override this method if you want any other behavior.
It can be used to just return nil if you are implementing a lazy load behavior on a class.
It can allow a combined binding to observe this object without trigger any lazy loading.
2019-11-28 09:38:55 +01:00
Martin CarlbergandGitHub aaed1a934e Fixed: When in modal mode make sure a focus event will make the modal window the key window (#2867)
The default was to make the first window in the most background layer the key window if nothing else was used.
This does not work well if there is a modal window that should have all the attention.

This solution will first choose the modal window if in modal mode. If not the old variant is used.
2019-11-27 19:16:03 +01:00
Martin CarlbergandGitHub 11639af26e Fixed: Let the text field handle key commands when it is selectable. (#2868)
There was a problem introduced by pull request #2600 when trying to select and copy text in a selectable text field.
The problem only occurs when the text field is in a modal window.

It was caused by the modal run loop that is present as an eventListener on the CPApplication when in modal mode. It will
force a bail out from the sendEvent: method in CPApplication when trying to handle the event. As the check for key
equivalent is moved down by the #2600 pull request it will never be allowed to handle a copy command from the browser
menu or key equivalent.

The solution is to allow the text field to handle the event if it is selectable. This will also allow the text selection
to be altered from the keyboard with keys like shift-left/right/up/down arrow. Combinations like shift-option arrow also
work for whole word selection.
2019-11-26 09:20:47 +01:00
cacaodevandMartin Carlberg 623ad2b1dc Fixed: Previoulsly, clearsFilterPredicateOnInsertion was applied (removes filter predicate) when setting content or on content binding. (#2860)
With Tests: Foundation unit test.
Solves #2791
2019-11-12 14:02:35 +01:00
Brian M. PalmaandMartin Carlberg ac68fec6b1 FIXED: Add Dark Mode to XcodeCapp (#2856)
FIXED: Add Dark Mode to XcodeCapp

This commit also fixes an issue where two NSBox instances had a borderRadius of 100 (boxStatus and boxImport) in IB. The borderRadius values are now updated to be half the size of the height and width values, restoring the circle visual.

Update installation directory for XcodeCapp

- Replace $LOCAL_APPS_DIR with $USER_APPS_DIR
- Installation directory updated from /Applications to ~/Applications
2019-10-18 13:37:22 +02:00
Martin Carlberg dad49354aa Fixed: CPSet enumerateObjectsUsingBlock: will honor the stop variable
Test case also added.

Deprecated the very old behaviour that the block could return YES to abort the enumeration.
2019-10-18 13:01:04 +02:00
daboe01andMartin Carlberg ce4fa3c027 Fixed: Pressing capslock inserted whitespaces under certain conditions (#2857)
This was present in a CPTextView.

A press on caps lock should also result in a flagsChanged event.
An event should have the corresponding flag for caps lock in modifierFlags.
2019-09-10 08:34:07 +02:00
meelashandMartin Carlberg 02d1a12bf5 Fixed: Update nonworking link (#2859) 2019-09-02 09:23:17 +02:00
cacaodevandGitHub 78cbc3871e Merge pull request #2852 from mrcarlberg/msg_send_return_undefined_when_receiver_is_undefined
New: msgSend will return undefined instead of nil when the receiver is undefined.
2019-08-31 11:28:17 +02:00
daboe01andMartin Carlberg f9bb882ceb Formatting: make readme a litte more concise (#2858)
removed the wrong attribute 'demo' for our tutorials link
2019-08-26 09:24:58 +02:00
cacaodevandGitHub 87fc6bde1d Merge pull request #2853 from mrcarlberg/optimize_table_column_bindings_with_long_key_paths
Fixed: Optimization for bindings with longer key paths in table views.
2019-08-17 18:33:33 +02:00
Martin Carlberg f666367b5d Fixed: Optimization for bindings with longer key paths in table views.
This prevents a buildup of large arrays with a lot of values and then choose one row and throw away the rest. This is great for speed and a must for lazy loading.

Previous there was a optimization for this but it was only effective for short combined key path like 'a.b'. This pull request makes it effective for any kind of length of a combined key path like 'a.b.c.d...'.

This is done by returning the object at a row in the first found CPArray in the key path
that is divided in a first and second part.
The first part is never a combined key path. The second part can be a combined key path.
If this optimization is not done we will create an array with the valueForKeyPath value on each row and then pick
the wanted value for the row and throw away all the other rows. It is much more effective to first
pick the row and then do the valueForKeyPath on the rest of the key path.
2019-06-26 09:37:40 +02:00
Martin Carlberg 81c02f24c6 New: msgSend will return undefined instead of nil when the receiver is undefined.
The msgSend function has always returned nil if the receiver has been nil or undefined.
Example:

var a = undefined;
var b = [a someSelector]; // b = nil

The variable b is now nil.

This pull request adds the ability for the msgSend function to return undefined if the receiver is undefined. If the receiver is nil it still return nil.
The above example again:

var a = undefined;
var b = [a someSelector]; // b = undefined

The variable b is now undefined.

Background.
The use of nil in Objective-C corresponds to the use of null in C and C++ and stands for "no value". A fundamental function in Objective-C is when you send a message to a receiver that is nil the result is again a nil value. This can be very convenient as you don't need the check if a receiver is nil before sending a message to it.

Objective-J adds the ability the use class structures and message send functionality for Javascript in the same way as Objective-C adds this to C and C++. Javascript also has the value null and is handled in the same way for Objective-J. Javascript also has the value undefined that stands for "not yet defined". This can sometimes be confusing and many try to handle null and undefined as the same thing. This is almost what Objective-J and the Cappuccino frameworks always has been doing. They try to always check for both null and ``undefined and always return nil but never undefined. We can say that Objective-J understands undefined but will try to translate it to nil.

Why do we need this change.
Javascript has both null and undefined and Objective-J is a superset of Javascript. It is now very hard to use undefined in Objective-J code as it will always try to translate it to nil. There are some Javascript libraries that use both null and undefined values and they are very hard to use from Objective-J programs today.  Same if you decide to use nil and undefined as a value in your own Objective-J code. This small change will make undefined a full member of the Objective-J language. It should be as it is a superset of Javascript. The Cappuccino frameworks will still handle undefined but only return nil.

How will it impact.
Today most methods will never return undefined so this is a very limited problem. If any does this the main concern is if some code will only check for nil and not undefined.
Example:

var a = [someObject someSelector];
If (a === nil) a = 42;
...

If the variable someObject contains undefined the variable a will now be set to undefined instead of nil.  But the variable a will then never be set to 42.
The correct way is to check for both nil and undefined like this:

var a = [someObject someSelector];
If (a == nil) a = 42;
...
2019-06-24 17:36:15 +02:00
Didier KorthoudtandMartin Carlberg 1d01ed92d8 Fixed: CPSearchField, when no recent searches were done, the menu wasn’t showing, even if search categories were specified (#2846) 2019-06-13 16:30:53 +02:00
daboe01andMartin Carlberg 1a7ced34a7 Fixed: smart copy/paste cycle was leaving an additional whitespace on the LHS (#2776) 2019-06-13 16:17:52 +02:00
Martin CarlbergandGitHub 47ab94b5bc Fixed: If sourcemap is available include it when building with a nondebug version of the tools. (#2850)
The sourcemap was not included when building from command line with the release (the default) version of the tools.
2019-06-13 16:15:48 +02:00
Didier KorthoudtandMartin Carlberg bea0778acc Fixed: Before this PR, cell based table views that use specific font, reverted to standard font when selected/editing (#2845) 2019-06-13 16:14:48 +02:00
Didier KorthoudtandMartin Carlberg eeba5087b1 Fixed: Before this, under certain circumstances, CPControl didn't declare its tracking areas soon enough (#2827) 2019-06-13 16:12:52 +02:00
daboe01andMartin Carlberg 7bd8bf02f6 Fixed: Typo in function call to _CPDecimalSetZero and made the test case work properly (#2820) 2019-06-13 16:09:17 +02:00
Martin CarlbergandGitHub 378f87a634 Fixed: Temporary fix so finding the compiler can work both in the Narwhal and Node world (#2793) 2019-06-13 16:06:15 +02:00
Didier KorthoudtandMartin Carlberg 76dd5383ab Fixed: A «feature» of Xcode where IB sometimes stores NSFont values in the alternate image property. (#2844) 2019-06-13 16:04:59 +02:00
daboe01andMartin Carlberg 129ca185e4 Fixed: backspace triggered page back in FireFox (#2849) 2019-06-13 15:59:35 +02:00
daboe01andMartin Carlberg 1f4ef42625 Fixed: index.html and index-debug.html were outdated in the manual tests (#2848) 2019-06-13 15:58:34 +02:00
daboe01andMartin Carlberg eb55e4def6 Fixed: keyboard issues from FF66 alignmets to the other major browsers (#2847) 2019-05-24 12:57:57 +02:00
Didier Korthoudt 4fc80f4bbd A3-CPApplication 2019-04-16 10:25:52 +02:00
Alexandre WilhelmandGitHub acda834ad9 Merge pull request #2819 from daboe01/CPFontManager-duplicate-methods-removal
fixed: removed outdated duplicate method definitions in CPFontManager.j
2019-04-14 20:02:22 -07:00
Alexandre WilhelmandGitHub aba3e30d9c Merge pull request #2824 from daboe01/cpdocumentcontroller-return-type-fix
fixed: return type of openUntitledDocumentOfType:display:
2019-04-14 20:01:36 -07:00
Alexandre WilhelmandGitHub c9e55ff1dc Merge pull request #2825 from daboe01/CPTableHeaderView-return-type-fix
fixed: wrong return type of textField method in
2019-04-14 20:01:21 -07:00
Alexandre WilhelmandGitHub 013c5e9e58 Merge pull request #2826 from daboe01/cpproxy-return-type-fix
fixed: wrong return type of forward::
2019-04-14 20:01:07 -07:00
Didier Korthoudt 5e7f3dc24a Merge remote-tracking branch 'cappuccino/master' 2019-04-13 10:25:08 +02:00
daboe01 2ffa174900 fixed: wrong return type of forward:: 2019-04-08 14:42:23 +02:00
daboe01 26cbe17218 fixed: wrong return type of textField method in 2019-04-08 14:39:02 +02:00
daboe01 fc8f1dca4e fixed: return type of openUntitledDocumentOfType:display: 2019-04-08 14:32:06 +02:00
Alexandre WilhelmandGitHub 6b20a4f8f7 Merge pull request #2786 from didierkorthoudt/CPStepper-enabled-from-IB
FIXED: CPStepper was not receiving the enabled status from IB
2019-04-03 15:15:22 -07:00
Alexandre WilhelmandGitHub 091025a304 Merge pull request #2794 from mrcarlberg/initialize_missing_on_custom_root_class
Fixed: the class method +initialize was always sent even if the root class did not implement it.
2019-04-03 15:07:59 -07:00
Alexandre WilhelmandGitHub 1180789c0c Merge pull request #2823 from daboe01/CPBrowserDelegateMethodFix
fixed: CPBrowserDelegate_browser_imageValueForItem_ was defined twice
2019-04-03 14:37:33 -07:00
Alexandre WilhelmandGitHub ac056d4a06 Merge pull request #2822 from daboe01/cpcursor-fix
fixed: accidental creation of a global variable in CPCursor.j
2019-04-03 14:36:44 -07:00
Alexandre WilhelmandGitHub 7c196e098a Merge pull request #2821 from daboe01/CPGraphicsContext-typo-fix
fixed: typo in initWithGraphicsPort: declaration
2019-04-03 14:36:23 -07:00
daboe01 c612b13529 fixed: CPBrowserDelegate_browser_imageValueForItem_ was defined twice 2019-03-31 19:42:54 +02:00
daboe01 5f4c79f6c4 fixed: accidental creation of a global variable 2019-03-31 17:44:07 +02:00
daboe01 302cbf641e fixed: typo in initWithGraphicsPort: declaration 2019-03-31 17:37:44 +02:00
daboe01 4bc2e9ad44 fixed: removed outdated duplicate method definitions in CPFontManager.j 2019-03-31 17:24:03 +02:00
Alexandre WilhelmandGitHub 6853c4c212 Merge pull request #2779 from daboe01/textview-contextmenu
New: support contextmenus for CPTextView
2019-03-29 15:06:39 -07:00
Alexandre WilhelmandGitHub 800e15cfd0 Merge pull request #2803 from bedalton/fixed-return-type-CPPlatformPasteboard
Fixed: Return type CPPlatformPasteboard.j should return BOOL
2019-03-29 15:04:14 -07:00
Alexandre WilhelmandGitHub 873f184117 Merge pull request #2798 from bedalton/formatting-add-semi-colons-to-CPTextStorage
Formatting: Add semi-colons to CPTextStorage.j
2019-03-29 15:03:47 -07:00
Alexandre WilhelmandGitHub 3bae5cd5cb Merge pull request #2807 from bedalton/fixed-duplicate-method-in-cparraycontroller
Fixed: Duplicate method in CPArrayController
2019-03-29 15:03:26 -07:00
Alexandre WilhelmandGitHub 19300332e8 Merge pull request #2813 from bedalton/fixed-cpcontrol-misspelled-parameter-type
Fixed: CPControl misspelled parameter type
2019-03-29 15:02:12 -07:00
Alexandre WilhelmandGitHub 89d88c9644 Merge pull request #2811 from bedalton/formatting-remove-redundant-semi-colon-in-cptextview
Formatting: Remove redundant semi-colon in CPTextView
2019-03-29 15:01:52 -07:00
Alexandre WilhelmandGitHub 472014b1b1 Merge pull request #2812 from bedalton/fixed-cpwindowcontroller-returns-cpview
Fixed: Changed CPWindowController method return to CPView
2019-03-29 15:01:29 -07:00
Alexandre WilhelmandGitHub c094420428 Merge pull request #2810 from bedalton/fixed-cpscroller-return-style
Fixed: Change CPScroller's style method return type to int
2019-03-29 15:01:13 -07:00
Alexandre WilhelmandGitHub e948064063 Merge pull request #2809 from bedalton/fixed-cocolor-parameter-to-cpstring
Fixed: Changed CPColor parameter to CPString
2019-03-29 15:00:59 -07:00
Alexandre WilhelmandGitHub bdd3b7d2a5 Merge pull request #2808 from bedalton/fixed-cpbrowserdelegate-duplicate-method
Fixed: CPBrowserDelegate duplicate protocol method
2019-03-29 15:00:46 -07:00
Alexandre WilhelmandGitHub 404c37b54c Merge pull request #2800 from bedalton/fixed-mismatched-parameters-in-CPTextView
Fixed: mismatched parameters in CPTextView
2019-03-29 15:00:18 -07:00
Alexandre WilhelmandGitHub ac686a17fa Merge pull request #2799 from bedalton/fixed-mispelled-parameter-in-CPTextView
Fixed: Misspelled parameter in CPTextView.j
2019-03-29 14:59:55 -07:00
Alexandre WilhelmandGitHub bfc5068b5e Merge pull request #2796 from bedalton/formatting-remove-redundant-semi-colon-CPDatePicker
Formatting: Remove redundant semi-colon form CPDatePicker
2019-03-29 14:59:39 -07:00
Alexandre WilhelmandGitHub 649bee2330 Merge pull request #2806 from bedalton/fixed-cpbezier-path-nsinteger
Fixed: CPBezierPath using parameter type NSInteger
2019-03-29 14:59:18 -07:00
Alexandre WilhelmandGitHub 593587ea60 Merge pull request #2805 from bedalton/fixed-cpapplication-isactive-return-type
Fixed: CPApplication's isActive method return type
2019-03-29 14:59:02 -07:00
Alexandre WilhelmandGitHub 0ab81a7b32 Merge pull request #2804 from bedalton/fixed-_cpautocompletemenu-return-type
Fixed:  Changed void return to id in CPAutocompleteMenu.j
2019-03-29 14:58:50 -07:00
Alexandre WilhelmandGitHub 8bf937357c Merge pull request #2801 from bedalton/formatting-remove-semi-colon-_CPStandardWindowView
Formatting: Remove extraneous semi-colon _CPStandardWindowView.j
2019-03-29 14:58:16 -07:00
Alexandre WilhelmandGitHub 1e8b1fda81 Merge pull request #2797 from bedalton/fixed-return-type-_CPMenuBarWindow
Fixed: Return type in _CPMenuBarWindow
2019-03-29 14:57:43 -07:00
daniel cba9212150 Fixed: CPControl parameter type to CPVerticalTextAlignment
Parameter was set to type CPTextVerticalAlignment, but typedef was declared as CPVerticalTextAlignment. This commit fixes this mismatch
2019-03-29 11:58:51 -07:00
daniel a0a6c42227 Fixed: Change return in CPWindowController to CPView
In CPWindowController, method viewControllerContainerView, implies that it returns something, and it does. It returns the _viewControllerContainerView instance object, and return type should be changed from void to CPView
2019-03-28 15:19:59 -07:00
daniel c245d9de80 Formatting: Removed redundant semi-colon in CPTextField 2019-03-28 14:55:44 -07:00
daniel ca5cd8e09b Fixed: CPScroller's style method should have returned int
Despite returning an int and a comment stating it returns a value, CPScroller's style method had a return type of void.
2019-03-28 14:51:15 -07:00
daniel 34ac4cd23b Fixed: Changed CPColor parameter from string to CPString
Parameter type in CPColor was string, changed here to CPString, to make it more inline with other string parameter types.
2019-03-28 14:33:00 -07:00
daniel 8598fe8ad9 Revert "Fixed: Changed CPColor parameter type from string to CPString"
This reverts commit 06498672ab.
2019-03-28 14:32:00 -07:00
daniel 3699a31f28 Revert "Formatting: Removed extra semi-colon ThemeDescriptors.j"
This reverts commit 75cd5a75e1.
2019-03-28 14:31:17 -07:00
daniel 06498672ab Fixed: Changed CPColor parameter type from string to CPString
Parameter type in CPColor was string, changed here to CPString, to make it more inline with other string parameter types.
2019-03-28 14:29:50 -07:00
daniel cd3b92af7a Fixed:CPBrowserDelegate duplicate method
Method browser:imageValueForItem was defined twice in CPBrowserDelegate. Once on line 43, and the other on line 45. This removes the commit removed the second declaration
2019-03-28 14:26:08 -07:00
daniel e15cc29e2f Fixed: CPBezierPath used parameter types NSInteger
CPBezierPath has parameter type NSInteger. Assumed meant to be CPInteger
2019-03-28 14:19:09 -07:00
daniel dabeb066de Fixed: Duplicate method in CPArrayController.j
Method alwaysUsesMultipleValuesMarker is duplicated in class CPArrayController.j. Both methods have the same body and same selector, the only difference being their comments are slightly different. Both comments however communicate the same thing.
2019-03-28 14:11:28 -07:00
daniel c59e7cc456 Fixed: Changed CPApplication's isActive method return type to BOOL
Method has declared return type of void, despite the method returning a BOOL, and the name implying that it returns a BOOL
2019-03-28 14:08:00 -07:00
daniel 3c16bfef58 Fixed: Changed void return type to id in _CPAutocompleteMenu.j
tableView:objectValueForTableColumn:row: has return type set to void, despite returning an method call returning id. Similar methods also return id.
2019-03-28 14:01:31 -07:00
daniel ec24977d4e Revert "Fixed: changed void return type in _CPAutocompleMenu.j to id"
This reverts commit 10b4f57a0e.
2019-03-28 13:58:15 -07:00
daniel 10b4f57a0e Fixed: changed void return type in _CPAutocompleMenu.j to id
tableView:objectValueForTableColumn:row: has return type set to void, despite returning an method call returning id. Similar methods also return id.
2019-03-28 13:54:20 -07:00
daniel 75cd5a75e1 Formatting: Removed extra semi-colon ThemeDescriptors.j 2019-03-28 13:46:25 -07:00
daniel fb2d0ed170 Fixed: Return types in CPPlatformPasteboard.j should return BOOL
Method _mayRequireDOMPasteboardElementHack:flags had return type of void, despite returning a BOOL value, and also being annotated with a doc comment stating that it should return a BOOL value

Also some methods had return type "boolean", should possibly be BOOL
2019-03-28 13:42:39 -07:00
daniel d4e139eaf5 Fixed: Return type for method in CPPlatformPasteboard.j
Method return type is labeled as void despite returning a BOOL and the DOC comment stating that it should return a BOOL
2019-03-28 13:38:33 -07:00
daniel 49ef1276f6 Formatting: Removed extra semi-colon in _CPStandardWindowView.j 2019-03-28 13:32:56 -07:00
daniel 828788b643 Fixed: Mismatched parameter types in CPTextView
isBlinking had return type void, but returned a BOOL, and the method name implies that it returns a BOOL.

Some parameters were marked as integer, so were changed to int to coincide with most other names for integers.

setString had parameter type id, despite implying that parameter was a string, and the super class parameter being a string.
2019-03-28 13:21:34 -07:00
daniel 0ca8d7a258 Fixed: Mispelled DOMElement parameter in CPTextView.j 2019-03-28 13:12:30 -07:00
daniel 75de49d151 Formatting: Added potentially missing semi-colons in CPTextStorage 2019-03-28 13:08:19 -07:00
daniel d39e1c0c6e Fixed: Return type for font method should have been CPFont 2019-03-28 12:51:04 -07:00
daniel 8e7f201ca8 Formatting: Removed redundant semi-colon in CPDatePicker 2019-03-28 12:49:13 -07:00
daniel 85b2a9b0a0 Merge remote-tracking branch 'upstream/master' 2019-03-28 12:41:13 -07:00
Martin Carlberg d4e40faecc Fixed: the class method +initialize was always sent even if the root class did not implement it. Forwarding and Invocation worked also on the method.
To mimic Objective-C correctly the +initialize method should not be sent on a class hierarchy if it does not implement it.
Also the +initialize method should not allowed to be forwarded to another target with Invocation or any other forwarding mechanism.
Added test cases for this and cleaned up some test cases that succeeded for the wrong reason.

This change will not affect many projects as all classes inherit from CPObject.
2019-02-20 23:44:00 +01:00
Alexandre WilhelmandGitHub 0be913ab18 Merge pull request #2780 from daboe01/fixed-wrong-return-type-in-_CPCibClassSwapper
fixed: wrong return type in initializer of _CPCibClassSwapper
2019-02-06 16:58:44 -08:00
Alexandre WilhelmandGitHub bab30f3b61 Merge pull request #2781 from daboe01/fixed-wrong-return-type-in-shouldArchiveValueForKey-
fixed: wrong return type in shouldArchiveValueForKey:
2019-02-06 16:58:25 -08:00
Alexandre WilhelmandGitHub abb599c556 Merge pull request #2782 from daboe01/fixed-wrong-return-type-of-_menuWithName-
fixed: wrong return type of _menuWithName:
2019-02-06 16:57:59 -08:00
Alexandre WilhelmandGitHub 2b6c6e9ab3 Merge pull request #2783 from daboe01/fixed-wrong-return-type-of-backgroundColorForGlyphAtIndex-
fixed: wrong return type of backgroundColorForGlyphAtIndex:
2019-02-06 16:57:42 -08:00
Alexandre WilhelmandGitHub 0db0d744da Merge pull request #2784 from daboe01/fixed-wrong-return-type-in-isMovable
fixed: wrong return type in isMovable
2019-02-06 16:57:21 -08:00
Alexandre WilhelmandGitHub 6b9f2d29fc Merge pull request #2785 from daboe01/fixed-wrong-return-type-of-isMiniaturized
fixed: wrong return type of isMiniaturized
2019-02-06 16:56:49 -08:00
bedalton 2c141a5255 Revert "Fixed: CPMenuBarWindow did not return a value when expected"
This reverts commit 4f69a32700.
2019-01-04 17:24:14 -08:00
bedalton 4f69a32700 Fixed: CPMenuBarWindow did not return a value when expected
CPMenuBarWindows's font: method did not return a value when a CPFont was expected.
2019-01-04 17:24:05 -08:00
Didier Korthoudt 3d4c08ad20 CPStepper-enabled-from-IB 2018-10-27 12:01:57 +02:00
Didier Korthoudt 594d415976 Merge remote-tracking branch 'cappuccino/master' 2018-10-27 11:59:52 +02:00
daboe01 ae50fde4e1 fixed: wrong return type of isMiniaturized 2018-10-14 16:49:49 +02:00
daboe01 401461f1f0 fixed: wrong return type in isMovable 2018-10-14 13:36:53 +02:00
daboe01 676c6e106d fixed: wrong return type of backgroundColorForGlyphAtIndex: 2018-10-14 13:34:33 +02:00
daboe01 d0a066ccd3 fixed: wrong return type of _menuWithName: 2018-10-14 13:31:20 +02:00
daboe01 340e286277 fixed: wrong return type in shouldArchiveValueForKey: 2018-10-14 13:27:38 +02:00
daboe01 9211d41984 fixed: wrong return type in initializer of _CPCibClassSwapper 2018-10-14 13:24:03 +02:00
daboe01 686aa457d6 fixed: cut/copy did not autoenable 2018-10-07 21:22:37 +02:00
daboe01 1b1431f0d0 menu cleanup 2018-10-07 21:08:31 +02:00
daboe01 cbcb46597d fixed: syntax errors 2018-10-06 23:19:50 +02:00
daboe01 6644c85978 new: context menu support for CPTextView 2018-10-06 23:16:46 +02:00
Didier KorthoudtandMartin Carlberg dd781fd86b Fixed: Enabled state for CPSlider was not converted by nib2cib (#2775) 2018-09-17 09:11:36 +02:00
Didier Korthoudt 97209846ad Merge remote-tracking branch 'cappuccino/master' 2018-09-16 10:55:10 +02:00
Didier Korthoudt 801648fcfe Merge remote-tracking branch 'cappuccino/master' 2018-09-10 11:45:02 +02:00
Didier Korthoudt aa4f91b3b0 Merge remote-tracking branch 'cappuccino/master' 2018-08-30 09:13:16 +02:00
Didier Korthoudt 043cc13bb3 Merge remote-tracking branch 'cappuccino/master' 2018-08-27 23:24:52 +02:00
Didier KorthoudtandGitHub eca41e7474 Merge branch 'master' into CPScrollView-scrollerStyle-fix 2018-08-23 11:08:51 +02:00
Didier Korthoudt 9be52f639d Merge remote-tracking branch 'cappuccino/master' 2018-08-21 11:22:22 +02:00
Didier Korthoudt 257fe6dd3f Merge remote-tracking branch 'cappuccino/master' 2018-08-16 14:54:27 +02:00
Didier Korthoudt 9107322d28 setGlobalScrollerStyle-fixes 2018-06-16 17:51:52 +02:00
daboe01 88c1846e1a fixed: interpunctation 2018-06-12 13:23:56 +02:00
daboe01 be3d559d8a fixed: optical clutter, link duplications 2018-06-12 13:20:00 +02:00
Didier Korthoudt f5ca6c39f6 Revert "Revert "Revert "CPScrollView-scrollerStyle-fix"""
This reverts commit 653fdb999e.
2018-06-02 22:08:59 +02:00
Didier Korthoudt 653fdb999e Revert "Revert "CPScrollView-scrollerStyle-fix""
This reverts commit f25d76d0d6.
2018-05-29 12:19:03 +02:00
Didier Korthoudt f25d76d0d6 Revert "CPScrollView-scrollerStyle-fix"
This reverts commit 31fe918b3d.
2018-05-29 12:16:36 +02:00
Didier Korthoudt 41b0f80360 CPScrollViewTest-fix 2018-05-25 08:57:11 +02:00
Didier Korthoudt 31fe918b3d CPScrollView-scrollerStyle-fix 2018-05-23 23:58:48 +02:00
Didier Korthoudt 32495792dc Revert "NEW: Added automatic Xcode syntax coloring"
This reverts commit 0a497d8c3f.
2018-05-23 23:50:53 +02:00
daniel 8c72e77e0d Merge remote-tracking branch 'cappuccino/master' 2018-04-08 12:07:30 -07:00
Didier Korthoudt 30bdbb4544 Subviews-CSS-animations-removal 2016-11-08 15:25:58 +01:00
Mathieu Monney c528421a8e Added unit test for pull request #2018 2014-12-19 13:42:40 +01:00
Mathieu Monney 0cfb53cea4 Changing a CALayer in a menu callback doesn't trigger re-draw / re-layout 2013-11-18 15:29:41 +01:00
Kevin Jamieson b349f0a2fb If target view of a drag is a CPTableView, set inset bounds based on the row height of the table 2011-10-03 22:13:41 -07:00
1732 changed files with 150752 additions and 194165 deletions
+12
View File
@@ -0,0 +1,12 @@
# EditorConfig reference: https://editorconfig.org
# https://editorconfig.org/#file-format-details
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
+34
View File
@@ -0,0 +1,34 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [24.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: echo "${PWD}/dist/cappuccino/bin" >> $GITHUB_PATH
- run: echo "${PWD}/dist/objective-j/bin" >> $GITHUB_PATH
- run: npm install
- run: npm update
- run: jake dist
- run: jake test-only
@@ -0,0 +1,180 @@
name: Main branch - Build Testbook with fresh frameworks and manual tests & deploy to GitHub Pages
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
pages: write # required by deploy-pages
id-token: write # required by deploy-pages
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout cappuccino (this repo)
uses: actions/checkout@v5
- name: Checkout Cappuccino-Testbook into ./testbook
uses: actions/checkout@v5
with:
repository: ArgosOz/Cappuccino-Testbook
path: testbook
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 24.x
- run: echo "${PWD}/dist/cappuccino/bin" >> $GITHUB_PATH
- run: echo "${PWD}/dist/objective-j/bin" >> $GITHUB_PATH
- run: npm install
- run: npm update
- run: jake dist
- run: jake test-only
# Refresh Frameworks from dist → testbook/Frameworks
- name: Refresh Frameworks
run: |
set -euo pipefail
if [ ! -d dist ]; then
echo "❌ dist/ not found at repo root" >&2
exit 1
fi
mkdir -p testbook/Frameworks
rm -rf testbook/Frameworks/*
cp -a dist/cappuccino/Frameworks/{Foundation,AppKit} testbook/Frameworks/
cp -a dist/objective-j/Frameworks/Objective-J testbook/Frameworks/
echo "Frameworks populated:" && ls -la testbook/Frameworks || true
- name: Generate manifest of manual test directories
if: ${{ hashFiles('Tests/Manual/**') != '' }}
run: |
set -euo pipefail
mkdir -p artifacts
OUT="testbook/Resources/recipes.txt"
: > "$OUT"
if [ ! -d "Tests/Manual" ]; then
echo "❌ Tests/Manual not found at repo root" >&2
exit 1
fi
# Iterate over immediate subdirectories of Tests/Manual (null-safe for spaces)
while IFS= read -r -d '' d; do
name=$(basename "$d")
ts=$(date +%s%3N) # milliseconds since epoch
printf '%s|%s|\n' "$ts" "$name" >> "$OUT"
# Optional tiny sleep to help keep timestamps distinct:
sleep 0.01
done < <(find "Tests/Manual" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
echo "Wrote $OUT:"
cat "$OUT"
# Replace subdirectories inside testbook/Resources with Tests/Manual subdirectories
- name: Sync Resources from Tests/Manual
run: |
set -euo pipefail
if [ ! -d "Tests/Manual" ]; then
echo "❌ Tests/Manual not found at repo root" >&2
exit 1
fi
mkdir -p testbook/Resources
# Remove only immediate subdirectories (keep stray files if any)
find testbook/Resources -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r rm -rf
# Copy each immediate subdirectory from Tests/Manual → testbook/Resources
while IFS= read -r -d '' d; do
cp -a "$d" testbook/Resources/
done < <(find Tests/Manual -mindepth 1 -maxdepth 1 -type d -print0)
echo "Resources now contains:" && ls -la testbook/Resources || true
# Ensure each test Index.html includes the include path line before OBJJ_MAIN_FILE
- name: Inject OBJJ_INCLUDE_PATHS into Index.html files
run: |
set -euo pipefail
found=0
while IFS= read -r -d '' f; do
found=1
if grep -q 'OBJJ_INCLUDE_PATHS' "$f"; then
echo "Already updated: $f"
continue
fi
perl -0777 -i -pe 's/OBJJ_MAIN_FILE\s*=\s*"main\.j";/OBJJ_INCLUDE_PATHS = ["..\/..\/Frameworks"];\nOBJJ_MAIN_FILE = "main.j";/i' "$f"
perl -0777 -i -pe 's/Frameworks\/Objective-J\/Objective-J.js/\.\.\/\.\.\/Frameworks\/Objective-J\/Objective-J.js/' "$f"
echo "Updated: $f"
done < <(find testbook/Resources -mindepth 2 -maxdepth 2 -type f -iname "index.html" -print0)
if [ "$found" -eq 0 ]; then
echo "⚠️ No index.html files found under testbook/Resources/*/" >&2
fi
# Optional: prune VCS/CI metadata from the served content
- name: Clean testbook for Pages (optional)
run: |
set -euo pipefail
test -f testbook/index.html
test -d testbook/Resources
test -d testbook/Frameworks
rm -rf testbook/.git testbook/.github || true
find testbook -maxdepth 1 -type f -name ".git*" -delete || true
- name: Publish to gh-pages (preserve PR previews)
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: testbook
clean-exclude: pr-preview/ # keep PR preview folders
force: false # avoid force-push so previews survive
- name: Checkout gh-pages ./gh-pages
uses: actions/checkout@v5
with:
path: gh-pages
ref: gh-pages
- name: Clean gh-pages for Pages
run: |
set -euo pipefail
test -d gh-pages
rm -rf gh-pages/.git gh-pages/.github || true
find gh-pages -maxdepth 1 -type f -name ".git*" -delete || true
find gh-pages -type f -name "*.xib" -delete || true
find gh-pages -type f -name "*xcode*" -delete || true
find gh-pages -name "Jakefile" -delete || true
- name: Upload Pages artifact (testbook/)
uses: actions/upload-pages-artifact@v4
with:
path: gh-pages
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
concurrency:
group: pages
cancel-in-progress: true
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Comment Pages URL on PR
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
script: |
const url = `${{ toJSON(steps.deployment.outputs.page_url) }}`;
const body = `📄 GitHub Pages preview for this PR:\n\n${url}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
+11 -1
View File
@@ -17,4 +17,14 @@ Tests/Manual/**/*.xcodeproj
*.sublime-project
*.sublime-workspace
*.tm_properties
*.idea
*.idea
node_modules
*.vscode
/dist/objective-j/objj-executable
/dist/objective-j/package.json
/dist/objective-j/lib
/dist/cappuccino/package.json
/dist/cappuccino/lib
/dist/cappuccino/bin
Tests/Manual/.Frameworks
/Tests/Manual/index.html
+28
View File
@@ -0,0 +1,28 @@
.DS_Store
Frameworks
!/dist/objective-j/Frameworks
!/dist/cappuccino-j/Frameworks
Build
Demos
./Aristo
WebSite
.push-package
*.xcodeproj*
*.xcodeproj/*.pbxuser
*.xcodeproj/*.perspectivev3
xcuserdata/
!*.xcodeproj/project.pbxproj
*.xCodeSupport/
*.XcodeSupport/
*XcodeSupport/
Tests/Manual/**/*.xcodeproj
*.sublime-project
*.sublime-workspace
*.tm_properties
*.idea
node_modules
*.vscode
/dist/objective-j/objj-executable
/dist/objective-j/package.json
/dist/cappuccino/package.json
+3 -3
View File
@@ -62,8 +62,6 @@
@import "CPDocument.j"
@import "CPDocumentController.j"
@import "CPEvent.j"
@import "CPFlashMovie.j"
@import "CPFlashView.j"
@import "CPFont.j"
@import "CPFontManager.j"
@import "CPGradient.j"
@@ -116,4 +114,6 @@
@import "CPWebView.j"
@import "CPWindow.j"
@import "CPWindowController.j"
@import "CPWorkspace.j"
@import "CPWorkspace.j"
@import "CPFontPanel.j"
@import "CPTreeController.j"
+90 -40
View File
@@ -172,7 +172,7 @@ var bottomHeight = 71;
BOOL _needsLayout;
}
#pragma mark Creating Alerts
// MARK: Creating Alerts
/*!
Returns a CPAlert object with the provided info
@@ -249,8 +249,8 @@ var bottomHeight = 71;
}
#pragma mark -
#pragma mark Delegate
// MARK: -
// MARK: Delegate
/*!
Set the delegate of the receiver
@@ -272,7 +272,7 @@ var bottomHeight = 71;
}
#pragma mark Accessors
// MARK: Accessors
- (CPTheme)theme
{
@@ -402,7 +402,7 @@ var bottomHeight = 71;
_needsLayout = YES;
}
#pragma mark Accessing Buttons
// MARK: Accessing Buttons
/*!
Adds a button with a given title to the receiver.
@@ -418,27 +418,32 @@ var bottomHeight = 71;
*/
- (void)addButtonWithTitle:(CPString)aTitle
{
var bounds = [[_window contentView] bounds],
count = [_buttons count],
var count = [_buttons count],
button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
[button setTitle:aTitle];
[button setTag:count];
[button setTarget:self];
[button setAction:@selector(_takeReturnCodeFrom:)];
[button setBezelStyle:CPSmallSquareBezelStyle];
[[_window contentView] addSubview:button];
// Only add subview if the window has been created.
// Otherwise, _createWindowWithStyle will handle adding the buttons from the _buttons array later.
if (_window)
[[_window contentView] addSubview:button];
if (count == 0)
{
[button setKeyEquivalent:CPCarriageReturnCharacter];
[button setBezelStyle:CPRoundedBezelStyle];
}
else if ([aTitle lowercaseString] === @"cancel")
[button setKeyEquivalent:CPEscapeFunctionKey];
[_buttons insertObject:button atIndex:0];
}
#pragma mark Layout
// MARK: Layout
/*!
@ignore
@@ -530,6 +535,9 @@ var bottomHeight = 71;
[[_window contentView] addSubview:_suppressionButton];
}
/*!
@ignore
*/
/*!
@ignore
*/
@@ -539,25 +547,17 @@ var bottomHeight = 71;
minimumSize = [_themeView currentValueForThemeAttribute:@"size"],
buttonOffset = [_themeView currentValueForThemeAttribute:@"button-offset"],
helpLeftOffset = [_themeView currentValueForThemeAttribute:@"help-image-left-offset"],
aRepresentativeButton = [_buttons objectAtIndex:0],
defaultElementsMargin = [_themeView currentValueForThemeAttribute:@"default-elements-margin"],
panelSize = [[_window contentView] frame].size,
buttonsOriginY,
buttonMarginY,
buttonMarginX,
theme = [self theme],
offsetX;
[aRepresentativeButton setTheme:[self theme]];
[aRepresentativeButton sizeToFit];
panelSize.height = CGRectGetMaxY([lastView frame]) + defaultElementsMargin + [aRepresentativeButton frameSize].height;
if (panelSize.height < minimumSize.height)
panelSize.height = minimumSize.height;
buttonsOriginY = panelSize.height - [aRepresentativeButton frameSize].height + buttonOffset;
offsetX = panelSize.width - inset.right;
var isHUD = (_defaultWindowStyle & CPHUDBackgroundWindowMask) || (theme === [CPTheme defaultHudTheme]);
// 1. Determine Margins (Moved up so we can use them in height calculation)
switch ([_window styleMask])
{
case _CPModalWindowMask:
@@ -571,27 +571,61 @@ var bottomHeight = 71;
break;
}
// 2. Prepare buttons and get row height
var maxButtonHeight = 0.0;
for (var i = 0; i < [_buttons count]; i++)
{
var btn = _buttons[i];
[btn sizeToFit];
if (isHUD)
[btn setThemeState:CPThemeStateHUD];
else
[btn unsetThemeState:CPThemeStateHUD];
maxButtonHeight = MAX(maxButtonHeight, CGRectGetHeight([btn frame]));
}
// 3. Calculate Content Height
var lastViewMaxY = CGRectGetMaxY([lastView frame]);
// Use bottomHeight (71) to reserve space for the footer
var requiredContentHeight = lastViewMaxY + bottomHeight;
var finalContentSize = CGSizeMake(
[[_window contentView] frame].size.width,
MAX(requiredContentHeight, minimumSize.height)
);
// 4. Position Buttons
// Calculate the top Y coordinate to vertically center the button row within the bottomHeight area
// Center Y of footer = Height - (bottomHeight / 2.0)
// Top Y of button = Center Y - (maxButtonHeight / 2.0)
buttonsOriginY = finalContentSize.height - ((bottomHeight + maxButtonHeight) / 2.0) - buttonMarginY;
offsetX = finalContentSize.width - inset.right;
// Loop and set frames
for (var i = [_buttons count] - 1; i >= 0 ; i--)
{
var button = _buttons[i];
[button setTheme:[self theme]];
[button sizeToFit];
var buttonFrame = [button frame],
var button = _buttons[i],
buttonFrame = [button frame],
width = MAX(80.0, CGRectGetWidth(buttonFrame)),
height = CGRectGetHeight(buttonFrame);
height = CGRectGetHeight(buttonFrame),
yOffset = FLOOR((maxButtonHeight - height) / 2.0);
offsetX -= width;
[button setFrame:CGRectMake(offsetX + buttonMarginX, buttonsOriginY + buttonMarginY, width, height)];
[button setFrame:CGRectMake(offsetX + buttonMarginX, buttonsOriginY + buttonMarginY + yOffset, width, height)];
offsetX -= 10;
}
// Position Help Button if needed
if (_showHelp)
{
var helpImage = [_themeView currentValueForThemeAttribute:@"help-image"],
helpImagePressed = [_themeView currentValueForThemeAttribute:@"help-image-pressed"],
helpImageSize = helpImage ? [helpImage size] : CGSizeMakeZero(),
helpFrame = CGRectMake(helpLeftOffset, buttonsOriginY, helpImageSize.width, helpImageSize.height);
helpYOffset = FLOOR((maxButtonHeight - helpImageSize.height) / 2.0),
helpFrame = CGRectMake(helpLeftOffset, buttonsOriginY + buttonMarginY + helpYOffset, helpImageSize.width, helpImageSize.height);
[_alertHelpButton setImage:helpImage];
[_alertHelpButton setAlternateImage:helpImagePressed];
@@ -599,8 +633,7 @@ var bottomHeight = 71;
[_alertHelpButton setFrame:helpFrame];
}
panelSize.height += [aRepresentativeButton frameSize].height + inset.bottom + buttonOffset;
return panelSize;
return finalContentSize;
}
/*!
@@ -614,9 +647,14 @@ var bottomHeight = 71;
if (!_window)
[self _createWindowWithStyle:nil];
// Ensure the theme view knows if we are in HUD mode so it picks up the right specificities
if ((_defaultWindowStyle & CPHUDBackgroundWindowMask) || ([self theme] === [CPTheme defaultHudTheme]))
[_themeView setThemeState:CPThemeStateHUD];
else
[_themeView unsetThemeState:CPThemeStateHUD];
var iconOffset = [_themeView currentValueForThemeAttribute:@"image-offset"],
theImage = _icon,
finalSize;
theImage = _icon;
if (!theImage)
switch (_alertStyle)
@@ -648,11 +686,17 @@ var bottomHeight = 71;
else if (_accessoryView)
lastView = _accessoryView;
finalSize = [self _layoutButtonsFromView:lastView];
if ([_window styleMask] & CPDocModalWindowMask)
finalSize.height -= 26; // adjust the absence of title bar
[_window setFrameSize:finalSize];
// 1. Get the size needed for the *content* (text, buttons, padding)
var finalContentSize = [self _layoutButtonsFromView:lastView];
// 2. Convert Content Size -> Frame Size
// This accounts for the Title Bar and borders automatically.
var contentRect = CGRectMake(0.0, 0.0, finalContentSize.width, finalContentSize.height);
var frameRect = [[_window class] frameRectForContentRect:contentRect styleMask:[_window styleMask]];
// 3. Apply the calculated Frame Size
[_window setFrameSize:frameRect.size];
[_window center];
if ([_window styleMask] & _CPModalWindowMask || [_window styleMask] & CPHUDBackgroundWindowMask)
@@ -664,7 +708,7 @@ var bottomHeight = 71;
_needsLayout = NO;
}
#pragma mark Displaying Alerts
// MARK: Displaying Alerts
/*!
Displays the \c CPAlert panel as a modal dialog. The user will not be
@@ -742,7 +786,7 @@ var bottomHeight = 71;
[self beginSheetModalForWindow:aWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
}
#pragma mark Private
// MARK: Private
/*!
@ignore
@@ -752,6 +796,12 @@ var bottomHeight = 71;
var frame = CGRectMakeZero();
frame.size = [_themeView currentValueForThemeAttribute:@"size"];
// Propagate CPHUDBackgroundWindowMask from _defaultWindowStyle to forceStyle.
// This ensures that even if we force CPDocModalWindowMask (for sheets),
// the window still knows it should be a HUD.
if (_defaultWindowStyle & CPHUDBackgroundWindowMask)
forceStyle |= CPHUDBackgroundWindowMask;
_window = [[CPPanel alloc] initWithContentRect:frame styleMask:forceStyle || _defaultWindowStyle];
[_window setLevel:CPStatusWindowLevel];
[_window setPlatformWindow:[[CPApp keyWindow] platformWindow]];
+9 -9
View File
@@ -63,8 +63,8 @@ CPThemeStateAppearanceVibrantDark = CPThemeState("appearance-vibrant-dark")
}
#pragma mark -
#pragma mark Class Methods
// MARK: -
// MARK: Class Methods
/*! Returns the current default CPAppearance
*/
@@ -99,8 +99,8 @@ CPThemeStateAppearanceVibrantDark = CPThemeState("appearance-vibrant-dark")
}
#pragma mark -
#pragma mark Initialization
// MARK: -
// MARK: Initialization
/*! Creates a CPAppearance object initialized to the specified appearance file in the specified bundle
This method does actually nothing special. It just creates a default appearance object
@@ -122,8 +122,8 @@ CPThemeStateAppearanceVibrantDark = CPThemeState("appearance-vibrant-dark")
}
#pragma mark -
#pragma mark Implementation
// MARK: -
// MARK: Implementation
- (BOOL)isEqual:(id)anObject
{
@@ -139,8 +139,8 @@ CPThemeStateAppearanceVibrantDark = CPThemeState("appearance-vibrant-dark")
}
#pragma mark -
#pragma mark CPCoding
// MARK: -
// MARK: CPCoding
- (id)initWithCoder:(CPCoder)aCoder
{
@@ -159,4 +159,4 @@ CPThemeStateAppearanceVibrantDark = CPThemeState("appearance-vibrant-dark")
[aCoder encodeBool:_allowsVibrancy forKey:@"_allowsVibrancy"];
}
@end
@end
+77 -4
View File
@@ -122,6 +122,10 @@ var CPApplicationDelegate_applicationShouldTerminate_ = 1 << 0,
CPPanel _aboutPanel;
CPThemeBlend _themeBlend @accessors(property=themeBlend);
// OS behavior
CPApplicationOSBehavior _OSBehavior;
BOOL _simulatesWindows;
}
/*!
@@ -132,7 +136,7 @@ var CPApplicationDelegate_applicationShouldTerminate_ = 1 << 0,
+ (CPApplication)sharedApplication
{
if (!CPApp)
CPApp = [[CPApplication alloc] init];
CPApp = [[self alloc] init];
return CPApp;
}
@@ -154,6 +158,9 @@ var CPApplicationDelegate_applicationShouldTerminate_ = 1 << 0,
_eventListenerInsertionIndex = 0;
_windows = [[CPNull null]];
_OSBehavior = CPApplicationLegacyOSBehavior;
_simulatesWindows = NO;
}
return self;
@@ -479,7 +486,7 @@ var CPApplicationDelegate_applicationShouldTerminate_ = 1 << 0,
[self _didResignActive];
}
- (void)isActive
- (BOOL)isActive
{
return _isActive;
}
@@ -1260,7 +1267,45 @@ var CPApplicationDelegate_applicationShouldTerminate_ = 1 << 0,
+ (CPString)defaultThemeName
{
return ([[CPBundle mainBundle] objectForInfoDictionaryKey:"CPDefaultTheme"] || @"Aristo2");
return ([[CPBundle mainBundle] objectForInfoDictionaryKey:"CPDefaultTheme"] || @"Aristo3");
}
// See CPApplication_Constants.j for comments
- (void)setOSBehavior:(CPApplicationOSBehavior)anOSBehavior
{
// Verify if provided OS behavior is valid
if ([[CPApplicationOSBehaviors allKeysForObject:anOSBehavior] count] == 0)
{
CPLog.warn("CPApplication setOSBehavior: invalid CPApplicationOSBehavior (received "+anOSBehavior+"). Ignored.");
return;
}
_OSBehavior = anOSBehavior;
[[CPNotificationCenter defaultCenter] postNotificationName:CPApplicationOSBehaviorDidChangeNotification object:CPApp userInfo:nil];
}
- (CPApplicationOSBehavior)OSBehavior
{
return _OSBehavior;
}
- (BOOL)shouldMimicWindows
{
return (_OSBehavior == CPApplicationFollowOSBehavior) && (CPBrowserIsOperatingSystem(CPWindowsOperatingSystem) || _simulatesWindows);
}
- (void)setSimulatesWindows:(BOOL)shouldSimulateWindows
{
if (_simulatesWindows === shouldSimulateWindows)
return;
_simulatesWindows = shouldSimulateWindows;
}
- (BOOL)simulatesWindows
{
return _simulatesWindows;
}
@end
@@ -1375,7 +1420,7 @@ var _CPAppBootstrapperActions = nil;
var defaultThemeName = [CPApplication defaultThemeName],
themeURL = nil;
if (defaultThemeName === @"Aristo" || defaultThemeName === @"Aristo2")
if (defaultThemeName === @"Aristo" || defaultThemeName === @"Aristo2" || defaultThemeName === @"Aristo3")
themeURL = [[CPBundle bundleForClass:[CPApplication class]] pathForResource:defaultThemeName + @".blend"];
else
themeURL = [[CPBundle mainBundle] pathForResource:defaultThemeName + @".blend"];
@@ -1391,6 +1436,34 @@ var _CPAppBootstrapperActions = nil;
[[CPApplication sharedApplication] setThemeBlend:aThemeBlend];
[CPTheme setDefaultTheme:[CPTheme themeNamed:[CPApplication defaultThemeName]]];
// Search in the Info.plist if the special CPApplicationSimulateWindowsOS flag is set (for testing)
[CPApp setSimulatesWindows:!![[CPBundle mainBundle] objectForInfoDictionaryKey:"CPApplicationSimulateWindowsOS"]];
// Before loading the main CIB, try to find if a CPApplicationOSBehavior is specified in the Info.plist or in the user defaults
// (with user defaults precedence). Value stored must be a string representing the name of the OS behavior.
var plistOSBehavior = [[CPBundle mainBundle] objectForInfoDictionaryKey:"CPApplicationOSBehavior"],
userOSBehavior = [[CPUserDefaults standardUserDefaults] objectForKey:@"CPApplicationOSBehavior"];
if (userOSBehavior)
{
var osBehavior = [CPApplicationOSBehaviors objectForKey:userOSBehavior];
if (osBehavior)
[CPApp setOSBehavior:osBehavior];
else
CPLog.warn("Invalid CPApplicationOSBehavior specified in user defaults (found:"+userOSBehavior+"). Ignored.");
}
else if (plistOSBehavior)
{
var osBehavior = [CPApplicationOSBehaviors objectForKey:plistOSBehavior];
if (osBehavior)
[CPApp setOSBehavior:osBehavior];
else
CPLog.warn("Invalid CPApplicationOSBehavior specified in Info.plist (found:"+plistOSBehavior+"). Ignored.");
}
[self performActions];
}
+12
View File
@@ -39,3 +39,15 @@ CPTerminateLater = -1; // not currently supported
CPRunStoppedResponse = -1000;
CPRunAbortedResponse = -1001;
CPRunContinuesResponse = -1002;
// Should the application follow Cappuccino UX-UI (which is OSX like) or OS UX-UI (mainly Windows) ?
// See explanation on https://github.com/cappuccino/cappuccino/wiki/CPApplicationSelectedOSBehavior
@typedef CPApplicationOSBehavior
CPApplicationLegacyOSBehavior = 1;
CPApplicationFollowOSBehavior = 2;
CPApplicationOSBehaviorDidChangeNotification = @"CPApplicationOSBehaviorDidChangeNotification";
CPApplicationOSBehaviors = @{
@"CPApplicationLegacyOSBehavior": CPApplicationLegacyOSBehavior,
@"CPApplicationFollowOSBehavior": CPApplicationFollowOSBehavior
};
+24 -25
View File
@@ -219,17 +219,6 @@
_clearsFilterPredicateOnInsertion = aFlag;
}
/*!
Whether the receiver will always return the multiple values marker when multiple
items are selected, even if the items have the same value.
@return BOOL YES if the receiver always uses the multiple values marker
*/
- (BOOL)alwaysUsesMultipleValuesMarker
{
return _alwaysUsesMultipleValuesMarker;
}
/*!
Sets whether the receiver should always return the multiple values marker when multiple
items are selected, even if the items have the same value.
@@ -282,7 +271,7 @@
if (_disableSetContent)
return;
if (value === nil)
if (value == nil)
value = [];
if (![value isKindOfClass:[CPArray class]])
@@ -308,27 +297,18 @@
class.
*/
if (_clearsFilterPredicateOnInsertion)
[self willChangeValueForKey:@"filterPredicate"];
// Don't use [super setContent:] as that would fire the contentObject change.
// We need to be in control of when notifications fire.
// Note that if we have a contentArray binding, setting the content does /not/
// cause a reverse binding set.
_contentObject = value;
if (_clearsFilterPredicateOnInsertion && _filterPredicate != nil)
[self __setFilterPredicate:nil]; // Causes a _rearrangeObjects.
else
[self _rearrangeObjects];
[self _rearrangeObjects];
if ([self preservesSelection])
[self __setSelectedObjects:oldSelectedObjects];
else
[self __setSelectionIndexes:oldSelectionIndexes];
if (_clearsFilterPredicateOnInsertion)
[self didChangeValueForKey:@"filterPredicate"];
}
/*!
@@ -629,6 +609,25 @@
return YES;
}
- (void)_selectionWillChange
{
// Push back all data from the dirty editors before it is too late.
var editorsCount = [_editors count];
while (editorsCount--)
{
var allBindings = [CPBinder allBindingsForObject:_editors[editorsCount]],
allKeys = [allBindings allKeys],
keysCount = allKeys.length;
while (keysCount--)
[[allBindings objectForKey:allKeys[keysCount]] reverseSetValueFor:allKeys[keysCount]];
}
[super _selectionWillChange];
}
/*!
Returns an array of the selected objects.
@@ -774,7 +773,7 @@
_filterPredicate = nil;
[self _rearrangeObjects];
}
else if (_filterPredicate === nil || [_filterPredicate evaluateWithObject:object])
else if (_filterPredicate == nil || [_filterPredicate evaluateWithObject:object])
{
// Insert directly into the array.
var pos = [_arrangedObjects insertObject:object inArraySortedByDescriptors:_sortDescriptors];
@@ -787,7 +786,7 @@
[_selectionIndexes shiftIndexesStartingAtIndex:pos by:1];
}
/*
else if (_filterPredicate !== nil)
else if (_filterPredicate != nil)
...
// Implies _filterPredicate && ![_filterPredicate evaluateWithObject:object], so the new object does
// not appear in arrangedObjects and we do not have to update at all.
@@ -887,7 +886,7 @@
_disableSetContent = NO;
if (_filterPredicate === nil || [_filterPredicate evaluateWithObject:object])
if (_filterPredicate == nil || [_filterPredicate evaluateWithObject:object])
{
// selectionIndexes change notification will be fired as a result of the
// content change. Don't fire manually.
+46 -2
View File
@@ -231,7 +231,7 @@ var DefaultLineWidth = 1.0;
/*!
Cocoa compatibility.
*/
- (void)getLineDash:(CPArrayRef)patternRef count:(NSInteger)count phase:(CGFloatRef)phaseRef
- (void)getLineDash:(CPArrayRef)patternRef count:(CPInteger)count phase:(CGFloatRef)phaseRef
{
return [self getLineDash:patternRef phase:phaseRef];
}
@@ -250,7 +250,7 @@ var DefaultLineWidth = 1.0;
/*!
Cocoa compatibility.
*/
- (void)setLineDash:(CPArray)aPattern count:(NSInteger)count phase:(CGFloat)aPhase
- (void)setLineDash:(CPArray)aPattern count:(CPInteger)count phase:(CGFloat)aPhase
{
[self setLineDash:aPattern phase:aPhase];
}
@@ -378,3 +378,47 @@ var DefaultLineWidth = 1.0;
}
@end
@implementation CPBezierPath (AnimationAdditions)
- (CPString)SVGString
{
var pathString = "";
var elements = _path.elements;
var count = _path.count;
for (var i = 0; i < count; i++)
{
var element = elements[i];
// Use the kCGPathElement* constants defined in CGPath.j
switch (element.type)
{
case kCGPathElementMoveToPoint:
pathString += "M " + element.x + " " + element.y + " ";
break;
case kCGPathElementAddLineToPoint:
pathString += "L " + element.x + " " + element.y + " ";
break;
case kCGPathElementAddQuadCurveToPoint:
pathString += "Q " + element.cpx + " " + element.cpy + " " + element.x + " " + element.y + " ";
break;
case kCGPathElementAddCurveToPoint:
pathString += "C " + element.cp1x + " " + element.cp1y + " " + element.cp2x + " " + element.cp2y + " " + element.x + " " + element.y + " ";
break;
case kCGPathElementCloseSubpath:
pathString += "Z ";
break;
}
}
return pathString.trim();
}
@end
+367 -73
View File
@@ -22,13 +22,14 @@
@import "CPTextField.j"
@import "CPView.j"
@import <Foundation/CPGeometry.j>
// CPBoxType
@typedef CPBoxType
CPBoxPrimary = 0;
CPBoxSecondary = 1;
CPBoxSecondary = 1; // Deprecated
CPBoxSeparator = 2;
CPBoxOldStyle = 3;
CPBoxOldStyle = 3; // Deprecated
CPBoxCustom = 4;
// CPBorderType
@@ -58,12 +59,16 @@ CPBelowBottom = 6;
@implementation CPBox : CPView
{
CPBoxType _boxType;
CPBorderType _borderType;
CPBorderType _borderType; // deprecated
CPView _contentView;
CPView _boxView; // needed for CSS theming, will be transparent for non CSS themes
BOOL _transparent @accessors(getter=isTransparent);
CPString _title @accessors(getter=title);
int _titlePosition @accessors(getter=titlePosition);
CPString _title @accessors(getter=title);
int _titlePosition @accessors(getter=titlePosition);
CPTextField _titleView;
BOOL _cachedAutoresizesSubviews;
}
+ (Class)_binderClassForBinding:(CPString)aBinding
@@ -90,6 +95,14 @@ CPBelowBottom = 6;
@"inner-shadow-size": 6.0,
@"inner-shadow-color": [CPNull null],
@"content-margin": CGSizeMakeZero(),
@"title-font": [CPNull null],
@"title-left-offset": 5.0,
@"title-top-offset": 0.0,
@"title-color": [CPNull null],
@"nib2cib-adjustment-primary-frame": CGRectMake(4, -4, -8, -6),
@"content-adjustment": CGRectMakeZero(),
@"min-y-correction-no-title": 0,
@"min-y-correction-title": 0
};
}
@@ -114,16 +127,26 @@ CPBelowBottom = 6;
if (self)
{
_borderType = CPBezelBorder;
_borderType = CPGrooveBorder; // Was CPBezelBorder but Cocoa default is CPGrooveBorder
_boxType = CPBoxPrimary;
_titlePosition = CPNoTitle;
_titleView = [CPTextField labelWithTitle:@""];
[_titleView setFont:[self titleFont]];
[_titleView setTextColor:[self titleColor]];
_boxView = [[CPView alloc] initWithFrame:[self bounds]];
[_boxView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
_contentView = [[CPView alloc] initWithFrame:[self bounds]];
[_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[self setAutoresizesSubviews:YES];
[self addSubview:_contentView];
[self addSubview:_boxView];
[_boxView setAutoresizesSubviews:YES];
[_boxView addSubview:_contentView];
[self sizeToFit];
}
return self;
@@ -155,6 +178,8 @@ CPBelowBottom = 6;
*/
- (CPBorderType)borderType
{
CPLog.warn("CPBox borderType is deprecated.");
return _borderType;
}
@@ -177,7 +202,8 @@ CPBelowBottom = 6;
return;
_borderType = aBorderType;
[self setNeedsDisplay:YES];
[self refreshDisplay];
}
/*!
@@ -217,26 +243,72 @@ CPBelowBottom = 6;
*/
- (void)setBoxType:(CPBoxType)aBoxType
{
if ((aBoxType == CPBoxSecondary) || (aBoxType == CPBoxOldStyle))
CPLog.warn("CPBox setBoxType: CPBoxSecondary and CPBoxOldStyle are deprecated.");
if (_boxType === aBoxType)
return;
_boxType = aBoxType;
[self setNeedsDisplay:YES];
[self refreshDisplay];
}
- (void)setTransparent:(BOOL)shouldBeTransparent
{
if (_transparent == shouldBeTransparent)
return;
_transparent = shouldBeTransparent;
[self _manageTitlePositioning];
}
// MARK: -
// MARK: Style properties which override theme values
/*!
The borderColor, borderWidth, cornerRadius and fillColor properties for the receiver
are only supported for boxes with boxType === CPBoxCustom and borderType === CPLineBorder.
Boxes with the Primary boxType have fixed values which are defined by the system theme.
Apple does support lineTypes of Groove and Bezel for boxes of type CPBoxCustom, CPBoxSecondary and CPBoxOldStyle,
but they are deprecated as of macOS 10.15.
Cappuccino has supported these in the past but no longer does so - both to simplify CSS-based theming and
to avoid the effort needed for supporting something which will be very short-lived.
These styles can be recreated as custom theme elements by developers, as needed.
Additionally, boxes with boxType === CPBoxSeparator (horizontal and vertical lines) have never allowed changing these values.
No warnings are generated for separator boxes.
*/
// See discussion above.
// MARK: borderColor
- (CPColor)borderColor
{
return [self valueForThemeAttribute:@"border-color"];
return [self currentValueForThemeAttribute:@"border-color"];
}
- (void)setBorderColor:(CPColor)color
{
if (_boxType === CPBoxSeparator)
{
return;
}
if ((_boxType !== CPBoxCustom) || (_borderType !== CPLineBorder))
{
CPLog.warn("CPBox setBorderColor: the box must be of type CPBoxCustom AND border of type CPLineBorder in order to use setBorderColor. Property is ignored.");
return;
}
if ([color isEqual:[self borderColor]])
return;
[self setValue:color forThemeAttribute:@"border-color"];
}
// See discussion above.
// MARK: borderWidth
- (float)borderWidth
{
return [self valueForThemeAttribute:@"border-width"];
@@ -244,12 +316,25 @@ CPBelowBottom = 6;
- (void)setBorderWidth:(float)width
{
if (_boxType === CPBoxSeparator)
{
return;
}
if ((_boxType !== CPBoxCustom) || (_borderType !== CPLineBorder))
{
CPLog.warn("CPBox setBorderWidth: the box must be of type CPBoxCustom AND border of type CPLineBorder in order to use setBorderWidth. Property is ignored.");
return;
}
if (width === [self borderWidth])
return;
[self setValue:width forThemeAttribute:@"border-width"];
}
// See discussion above.
// MARK: cornerRadius
- (float)cornerRadius
{
return [self valueForThemeAttribute:@"corner-radius"];
@@ -257,12 +342,25 @@ CPBelowBottom = 6;
- (void)setCornerRadius:(float)radius
{
if (_boxType === CPBoxSeparator)
{
return;
}
if ((_boxType !== CPBoxCustom) || (_borderType !== CPLineBorder))
{
CPLog.warn("CPBox setCornerRadius: the box must be of type CPBoxCustom AND border of type CPLineBorder in order to use setCornerRadius. Property is ignored.");
return;
}
if (radius === [self cornerRadius])
return;
[self setValue:radius forThemeAttribute:@"corner-radius"];
}
// See discussion above.
// MARK: fillColor
- (CPColor)fillColor
{
return [self valueForThemeAttribute:@"background-color"];
@@ -270,6 +368,17 @@ CPBelowBottom = 6;
- (void)setFillColor:(CPColor)color
{
if (_boxType === CPBoxSeparator)
{
return;
}
if ((_boxType !== CPBoxCustom) || (_borderType !== CPLineBorder))
{
CPLog.warn("CPBox setFillColor: the box must be of type CPBoxCustom AND border of type CPLineBorder in order to use setFillColor. Property is ignored.");
return;
}
if ([color isEqual:[self fillColor]])
return;
@@ -286,21 +395,20 @@ CPBelowBottom = 6;
if (aView === _contentView)
return;
var borderWidth = [self borderWidth],
contentMargin = [self valueForThemeAttribute:@"content-margin"];
[aView setFrame:CGRectInset([self bounds], contentMargin.width + borderWidth, contentMargin.height + borderWidth)];
[aView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
// A nil contentView is allowed (tested in Cocoa 2013-02-22).
if (!aView)
[_contentView removeFromSuperview];
else if (_contentView)
[self replaceSubview:_contentView with:aView];
[_boxView replaceSubview:_contentView with:aView];
else
[self addSubview:aView];
[_boxView addSubview:aView];
_contentView = aView;
[self sizeToFit];
[self refreshDisplay];
}
- (CGSize)contentViewMargins
@@ -320,9 +428,14 @@ CPBelowBottom = 6;
{
var offset = [self _titleHeightOffset],
borderWidth = [self borderWidth],
contentMargin = [self valueForThemeAttribute:@"content-margin"];
contentMargin = [self valueForThemeAttribute:@"content-margin"],
contentAdjustment = [self valueForThemeAttribute:@"content-adjustment"],
minYCorrection = [self valueForThemeAttribute:(_titlePosition === CPNoTitle ? @"min-y-correction-no-title" : @"min-y-correction-title")];
[self setFrame:CGRectInset(aRect, -(contentMargin.width + borderWidth), -(contentMargin.height + offset[0] + borderWidth))];
[self setFrame:CGRectMake(aRect.origin.x - contentAdjustment.origin.x - contentMargin.width + borderWidth,
aRect.origin.y - contentAdjustment.origin.y - contentMargin.height + borderWidth - minYCorrection,
aRect.size.width + 2 * contentMargin.width - contentAdjustment.size.width,
aRect.size.height + 2 * contentMargin.height - contentAdjustment.size.height)];
}
- (void)setTitle:(CPString)aTitle
@@ -347,14 +460,42 @@ CPBelowBottom = 6;
- (CPFont)titleFont
{
return [_titleView font];
if ([self hasThemeAttribute:@"title-font"])
return [self valueForThemeAttribute:@"title-font"];
else
return [_titleView font];
}
- (void)setTitleFont:(CPFont)aFont
{
if ([aFont isEqual:[self titleFont]])
return;
if ([self hasThemeAttribute:@"title-font"])
[self setValue:aFont forThemeAttribute:@"title-font"];
[_titleView setFont:aFont];
}
- (CPColor)titleColor
{
if ([self hasThemeAttribute:@"title-color"])
return [self valueForThemeAttribute:@"title-color"];
else
return [_titleView textColor];
}
- (void)setTitleColor:(CPColor)aColor
{
if ([aColor isEqual:[self titleColor]])
return;
if ([self hasThemeAttribute:@"title-color"])
[self setValue:aColor forThemeAttribute:@"title-color"];
[_titleView setTextColor:aColor];
}
/*!
Return the text field used to display the receiver's title.
@@ -365,25 +506,39 @@ CPBelowBottom = 6;
return _titleView;
}
/*!
Return the rectangle in which the receivers title is drawn.
*/
- (CGRect)titleRect
{
return [_titleView frame];
}
- (void)_manageTitlePositioning
{
if (_titlePosition == CPNoTitle)
if ((_titlePosition == CPNoTitle) || _transparent)
{
[_titleView removeFromSuperview];
[self setNeedsDisplay:YES];
if (_boxType !== CPBoxSeparator)
[self sizeToFit];
[self refreshDisplay];
return;
}
[_titleView setStringValue:_title];
[_titleView sizeToFit];
[self addSubview:_titleView];
var titleLeftOffset = [self valueForThemeAttribute:@"title-left-offset"],
titleTopOffset = [self valueForThemeAttribute:@"title-top-offset"];
switch (_titlePosition)
{
case CPAtTop:
case CPAboveTop:
case CPBelowTop:
[_titleView setFrameOrigin:CGPointMake(5.0, 0.0)];
[_titleView setFrameOrigin:CGPointMake(titleLeftOffset, titleTopOffset)]; // FIXME: was 0.0
[_titleView setAutoresizingMask:CPViewNotSizable];
break;
@@ -391,39 +546,51 @@ CPBelowBottom = 6;
case CPAtBottom:
case CPBelowBottom:
var h = [_titleView frameSize].height;
[_titleView setFrameOrigin:CGPointMake(5.0, [self frameSize].height - h)];
[_titleView setFrameOrigin:CGPointMake(titleLeftOffset, [self frameSize].height - h - titleTopOffset)];
[_titleView setAutoresizingMask:CPViewMinYMargin];
break;
}
if (!_transparent)
[self addSubview:_titleView];
[self sizeToFit];
[self setNeedsDisplay:YES];
[self refreshDisplay];
}
- (void)sizeToFit
{
var contentFrame = [_contentView frame],
offset = [self _titleHeightOffset],
contentMargin = [self valueForThemeAttribute:@"content-margin"];
var offset = [self _titleHeightOffset],
size = [self frameSize];
if (!contentFrame)
[_boxView setFrame:CGRectMake(0, offset[1], size.width, size.height - offset[0])];
if (!_contentView)
return;
[_contentView setFrameOrigin:CGPointMake(contentMargin.width, contentMargin.height + offset[1])];
var boxSize = [_boxView frameSize],
contentMargin = [self valueForThemeAttribute:@"content-margin"],
contentAdjustment = [self valueForThemeAttribute:@"content-adjustment"],
borderWidth = [self valueForThemeAttribute:@"border-width"],
minYCorrection = [self valueForThemeAttribute:(_titlePosition === CPNoTitle ? @"min-y-correction-no-title" : @"min-y-correction-title")];
[_contentView setFrame:CGRectMake(contentAdjustment.origin.x + contentMargin.width - borderWidth,
contentAdjustment.origin.y + contentMargin.height - borderWidth + minYCorrection,
boxSize.width - 2 * contentMargin.width + contentAdjustment.size.width,
boxSize.height - 2 * contentMargin.height + contentAdjustment.size.height)];
}
- (float)_titleHeightOffset
- (CPArray)_titleHeightOffset
{
if (_titlePosition == CPNoTitle)
return [0.0, 0.0];
var titleTopOffset = [self valueForThemeAttribute:@"title-top-offset"];
switch (_titlePosition)
{
case CPAtTop:
return [[_titleView frameSize].height, [_titleView frameSize].height];
return [[_titleView frameSize].height + titleTopOffset, [_titleView frameSize].height + titleTopOffset];
case CPAtBottom:
return [[_titleView frameSize].height, 0.0];
return [[_titleView frameSize].height + titleTopOffset, 0.0];
default:
return [0.0, 0.0];
@@ -440,21 +607,24 @@ CPBelowBottom = 6;
- (void)drawRect:(CGRect)rect
{
if ([self isCSSBased] && (_boxType !== CPBoxCustom))
return;
var bounds = [self bounds];
switch (_boxType)
if (_boxType === CPBoxSeparator)
{
case CPBoxSeparator:
// NSBox does not include a horizontal flag for the separator type. We have to determine
// the type of separator to draw by the width and height of the frame.
if (CGRectGetWidth(bounds) === 5.0)
return [self _drawVerticalSeparatorInRect:bounds];
else if (CGRectGetHeight(bounds) === 5.0)
return [self _drawHorizontalSeparatorInRect:bounds];
break;
// NSBox does not include a horizontal flag for the separator type. We have to determine
// the type of separator to draw by the width and height of the frame.
if (CGRectGetWidth(bounds) === 5.0)
return [self _drawVerticalSeparatorInRect:bounds];
else if (CGRectGetHeight(bounds) === 5.0)
return [self _drawHorizontalSeparatorInRect:bounds];
}
if (_transparent)
return;
if (_titlePosition == CPAtTop)
{
bounds.origin.y += [_titleView frameSize].height;
@@ -475,9 +645,6 @@ CPBelowBottom = 6;
switch (_borderType)
{
case CPBezelBorder:
[self _drawBezelBorderInRect:bounds];
break;
case CPGrooveBorder:
case CPLineBorder:
[self _drawLineBorderInRect:bounds];
@@ -594,12 +761,83 @@ CPBelowBottom = 6;
@end
// MARK: -
@implementation CPBox (CSSTheming)
- (void)layoutSubviews
{
if (![self isCSSBased] || (_boxType === CPBoxCustom))
return;
var bounds = [self bounds];
if (_boxType === CPBoxSeparator)
{
if (bounds.size.width === 5.0)
{
// Vertical separator
[_boxView setFrame:CGRectMake(2,0,1,bounds.size.height)];
}
else
{
// Horizontal separator
[_boxView setFrame:CGRectMake(0,2,bounds.size.width,1)];
}
[_boxView setBackgroundColor:[self currentValueForThemeAttribute:@"border-color"]];
return;
}
// All types of boxes (beside custom which is not covered here) always draw the same way, unless they are CPNoBorder.
if ((_borderType !== CPNoBorder) && !_transparent)
{
[_boxView setBackgroundColor:[self valueForThemeAttribute:@"background-color"]];
return;
}
// No border or transparent
[_boxView setBackgroundColor:nil];
}
- (BOOL)isCSSBased
{
return [[self theme] isCSSBased];
}
- (void)refreshDisplay
{
if ([self isCSSBased] && (_boxType !== CPBoxCustom))
[self setNeedsLayout:YES];
else
[self setNeedsDisplay:YES];
}
- (void)setAutoresizesSubviews:(BOOL)flag
{
// CPBox should always resize its subviews, like in Cocoa, whatever is the corresponding flag set.
// We have to keep the flag value as we could have to return it in -autoresizesSubview method.
_cachedAutoresizesSubviews = !!flag;
[super setAutoresizesSubviews:YES];
}
- (BOOL)autoresizesSubview
{
return _cachedAutoresizesSubviews;
}
@end
// MARK: -
var CPBoxTypeKey = @"CPBoxTypeKey",
CPBoxBorderTypeKey = @"CPBoxBorderTypeKey",
CPBoxTitle = @"CPBoxTitle",
CPBoxTitlePosition = @"CPBoxTitlePosition",
CPBoxTitleView = @"CPBoxTitleView",
CPBoxContentView = @"CPBoxContentView";
CPBoxTitleKey = @"CPBoxTitleKey",
CPBoxTitlePositionKey = @"CPBoxTitlePositionKey",
CPBoxTitleViewKey = @"CPBoxTitleViewKey",
CPBoxContentViewKey = @"CPBoxContentViewKey",
CPBoxBoxViewKey = @"CPBoxBoxViewKey";
@implementation CPBox (CPCoding)
@@ -612,33 +850,56 @@ var CPBoxTypeKey = @"CPBoxTypeKey",
_boxType = [aCoder decodeIntForKey:CPBoxTypeKey];
_borderType = [aCoder decodeIntForKey:CPBoxBorderTypeKey];
_title = [aCoder decodeObjectForKey:CPBoxTitle];
_titlePosition = [aCoder decodeIntForKey:CPBoxTitlePosition];
_titleView = [aCoder decodeObjectForKey:CPBoxTitleView] || [CPTextField labelWithTitle:_title];
_title = [aCoder decodeObjectForKey:CPBoxTitleKey];
_titlePosition = [aCoder decodeIntForKey:CPBoxTitlePositionKey];
if (_boxType != CPBoxSeparator)
// Important : see comment on encodeWithCoder below
_boxView = [aCoder decodeObjectForKey:CPBoxBoxViewKey];
if (!_boxView)
{
// FIXME: we have a problem with CIB decoding here.
// We should be able to simply add : _contentView = [self subviews][0]
// but first box subview seems to be malformed (badly decoded).
// For example, when deployed, this view doesn't have its _trackingAreas array initialized.
// As a (temporary) workaround, we encode/decode the _contentView property. We then transfer the subview hierarchy
// and replace the first (and only) box subview with this _contentView
// We're coming from nib2cib.
_contentView = [aCoder decodeObjectForKey:CPBoxContentView] || [[CPView alloc] initWithFrame:[self bounds]];
var malformedContentView = [self subviews][0];
[_contentView setSubviews:[malformedContentView subviews]];
[self replaceSubview:malformedContentView with:_contentView];
_boxView = [[CPView alloc] initWithFrame:[self bounds]];
_titleView = [CPTextField labelWithTitle:_title];
}
else
{
_titlePosition = CPNoTitle;
// We're coming from elsewhere
_titleView = [aCoder decodeObjectForKey:CPBoxTitleViewKey];
}
[self setAutoresizesSubviews:YES];
_contentView = [aCoder decodeObjectForKey:CPBoxContentViewKey];
// FIXME: super-mega-hyper-trick : _contentView has a superview which is not normal !
// FIXME: (see encodeWithCoder to understand why this is not possible)
// FIXME: we fix this by hand. This is horrible so please find a structural solution !
if (_contentView)
_contentView._superview = nil;
[_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[_boxView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[_boxView setAutoresizesSubviews:YES];
[self setAutoresizesSubviews:YES];
if (_contentView)
[_boxView setSubviews:@[_contentView]];
[self addSubview:_boxView];
[self addSubview:_titleView];
if (_boxType === CPBoxSeparator)
_titlePosition = CPNoTitle;
[_titleView setFont:[self titleFont]];
[_titleView setTextColor:[self titleColor]];
[self _manageTitlePositioning];
[self refreshDisplay];
}
return self;
@@ -646,14 +907,47 @@ var CPBoxTypeKey = @"CPBoxTypeKey",
- (void)encodeWithCoder:(CPCoder)aCoder
{
// We have to distinguish between 2 cases :
// - we come from nib2cib
// - we come from elsewhere
//
// When coming from nib2cib, we have no _boxView, _contentView, _titleView.
// We fix _contentView to be the first (and only) subview.
// They will have to be added on decoding.
//
// When coming from elsewhere, we remove _boxView (and thus _contentView) and _titleView
// from the view hierarchy as we'll already encode them via variables.
// They will be putted back during decoding. This way, we reduce the space and speed needed for coding.
var subviews = [self subviews];
if (!_boxView)
{
// We're coming from nib2cib.
_contentView = subviews[0];
[_contentView removeFromSuperview];
}
else
{
// We're coming from elsewhere.
[_boxView removeFromSuperview];
[_titleView removeFromSuperview];
}
[super encodeWithCoder:aCoder];
[self setSubviews:subviews];
[aCoder encodeInt:_boxType forKey:CPBoxTypeKey];
[aCoder encodeInt:_borderType forKey:CPBoxBorderTypeKey];
[aCoder encodeObject:_title forKey:CPBoxTitle];
[aCoder encodeInt:_titlePosition forKey:CPBoxTitlePosition];
[aCoder encodeObject:_titleView forKey:CPBoxTitleView];
[aCoder encodeObject:_contentView forKey:CPBoxContentView];
[aCoder encodeObject:_title forKey:CPBoxTitleKey];
[aCoder encodeInt:_titlePosition forKey:CPBoxTitlePositionKey];
[aCoder encodeConditionalObject:_contentView forKey:CPBoxContentViewKey];
[aCoder encodeConditionalObject:_titleView forKey:CPBoxTitleViewKey];
[aCoder encodeConditionalObject:_boxView forKey:CPBoxBoxViewKey];
}
@end
+15 -20
View File
@@ -42,7 +42,6 @@
- (CPDragOperation)browser:(CPBrowser)browser validateDrop:(id)info proposedRow:(CPInteger)row column:(CPInteger)column dropOperation:(CPTableViewDropOperation)dropOperation;
- (CPImage)browser:(CPBrowser)browser imageValueForItem:(id)anItem;
- (CPImage)browser:(CPBrowser)browser draggingImageForRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(CPInteger)column withEvent:(CPEvent)event offset:(CGPoint)dragImageOffset;
- (CPImage)browser:(CPBrowser)browser imageValueForItem:(id)item;
- (CPIndexSet)browser:(CPBrowser)browser selectionIndexesForProposedSelection:(CPIndexSet)proposedSelectionIndexes inColumn:(CPInteger)column;
- (CPInteger)browser:(CPBrowser)browser numberOfChildrenOfItem:(id)item;
- (CPView)browser:(CPBrowser)browser draggingViewForRowsWithIndexes:(CPIndexSet)rowIndexes inColumn:(CPInteger)column withEvent:(CPEvent)event offset:(CGPoint)dragImageOffset;
@@ -62,19 +61,18 @@ var CPBrowserDelegate_browser_acceptDrop_atRow_column_dropOperation_
CPBrowserDelegate_browser_shouldSelectRowIndexes_inColumn_ = 1 << 4,
CPBrowserDelegate_browser_writeRowsWithIndexes_inColumn_toPasteboard_ = 1 << 5,
CPBrowserDelegate_browser_validateDrop_proposedRow_column_dropOperation_ = 1 << 6,
CPBrowserDelegate_browser_imageValueForItem_ = 1 << 7,
CPBrowserDelegate_browser_draggingImageForRowsWithIndexes_inColumn_withEvent_offset_ = 1 << 8,
CPBrowserDelegate_browser_imageValueForItem_ = 1 << 9,
CPBrowserDelegate_browser_selectionIndexesForProposedSelection_inColumn_ = 1 << 10,
CPBrowserDelegate_browser_numberOfChildrenOfItem_ = 1 << 11,
CPBrowserDelegate_browser_draggingViewForRowsWithIndexes_inColumn_withEvent_offset_ = 1 << 12,
CPBrowserDelegate_browser_child_ofItem_ = 1 << 13,
CPBrowserDelegate_browser_objectValueForItem_ = 1 << 14,
CPBrowserDelegate_rootItemForBrowser_ = 1 << 15,
CPBrowserDelegate_browser_didChangeLastColumn_toColumn_ = 1 << 16,
CPBrowserDelegate_browser_didResizeColumn_ = 1 << 17,
CPBrowserDelegate_browserSelectionIsChanging_ = 1 << 18,
CPBrowserDelegate_browserSelectionDidChange_ = 1 << 19;
CPBrowserDelegate_browser_draggingImageForRowsWithIndexes_inColumn_withEvent_offset_ = 1 << 7,
CPBrowserDelegate_browser_imageValueForItem_ = 1 << 8,
CPBrowserDelegate_browser_selectionIndexesForProposedSelection_inColumn_ = 1 << 9,
CPBrowserDelegate_browser_numberOfChildrenOfItem_ = 1 << 10,
CPBrowserDelegate_browser_draggingViewForRowsWithIndexes_inColumn_withEvent_offset_ = 1 << 11,
CPBrowserDelegate_browser_child_ofItem_ = 1 << 12,
CPBrowserDelegate_browser_objectValueForItem_ = 1 << 13,
CPBrowserDelegate_rootItemForBrowser_ = 1 << 14,
CPBrowserDelegate_browser_didChangeLastColumn_toColumn_ = 1 << 15,
CPBrowserDelegate_browser_didResizeColumn_ = 1 << 16,
CPBrowserDelegate_browserSelectionIsChanging_ = 1 << 17,
CPBrowserDelegate_browserSelectionDidChange_ = 1 << 18;
/*!
@ingroup appkit
@@ -155,7 +153,7 @@ var CPBrowserDelegate_browser_acceptDrop_atRow_column_dropOperation_
_prototypeView = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_prototypeView setVerticalAlignment:CPCenterVerticalTextAlignment];
[_prototypeView setValue:[CPColor whiteColor] forThemeAttribute:"text-color" inState:CPThemeStateSelectedDataView];
[_prototypeView setValue:[CPColor whiteColor] forThemeAttribute:"text-color" inState:CPThemeStateSelectedDataView.and(CPThemeStateTableDataView)];
[_prototypeView setLineBreakMode:CPLineBreakByTruncatingTail];
_horizontalScrollView = [[CPScrollView alloc] initWithFrame:[self bounds]];
@@ -211,9 +209,6 @@ var CPBrowserDelegate_browser_acceptDrop_atRow_column_dropOperation_
if ([_delegate respondsToSelector:@selector(browser:validateDrop:proposedRow:column:dropOperation:)])
_implementedDelegateMethods |= CPBrowserDelegate_browser_validateDrop_proposedRow_column_dropOperation_;
if ([_delegate respondsToSelector:@selector(browser:imageValueForItem:)])
_implementedDelegateMethods |= CPBrowserDelegate_browser_imageValueForItem_;
if ([_delegate respondsToSelector:@selector(browser:draggingImageForRowsWithIndexes:inColumn:withEvent:offset:)])
_implementedDelegateMethods |= CPBrowserDelegate_browser_draggingImageForRowsWithIndexes_inColumn_withEvent_offset_;
@@ -468,7 +463,7 @@ var CPBrowserDelegate_browser_acceptDrop_atRow_column_dropOperation_
- (id)itemAtRow:(CPInteger)row inColumn:(CPInteger)column
{
return [_tableDelegates[column] childAtIndex:row];
return [_tableDelegates[column] childAtIndex:row] || nil;
}
- (BOOL)isLeafItem:(id)item
@@ -478,7 +473,7 @@ var CPBrowserDelegate_browser_acceptDrop_atRow_column_dropOperation_
- (id)parentForItemsInColumn:(CPInteger)column
{
return [_tableDelegates[column] _item];
return [_tableDelegates[column] _item] || nil;
}
- (CPSet)selectedItems
+256 -170
View File
@@ -44,6 +44,7 @@ CPTexturedRoundedBezelStyle = 11; // Round Textured
CPRoundRectBezelStyle = 12; // Round Rect
CPRecessedBezelStyle = 13; // Recessed
CPRoundedDisclosureBezelStyle = 14; // Disclosure
CPInlineBezelStyle = 15; // Inline
CPHUDBezelStyle = -1;
@@ -72,14 +73,33 @@ CPPushInCellMask = CPPushInButtonMask;
CPChangeGrayCellMask = CPGrayButtonMask;
CPChangeBackgroundCellMask = CPBackgroundButtonMask;
CPButtonStateMixed = CPThemeState("mixed");
CPButtonStateBezelStyleRounded = CPThemeState("rounded");
CPButtonStateBezelStyleRoundRect = CPThemeState("roundRect");
CPButtonStateMixed = CPThemeState("mixed");
CPButtonStateBezelStyleRounded = CPThemeState("rounded"); // IB style : Push
CPButtonStateBezelStyleShadowlessSquare = CPThemeState("square"); // IB style : Square
CPButtonStateBezelStyleSmallSquare = CPThemeState("gradient"); // IB style : Gradient
CPButtonStateBezelStyleTexturedRounded = CPThemeState("textured-rounded"); // IB style : Textured rounded
CPButtonStateBezelStyleRoundRect = CPThemeState("roundRect"); // IB style : Round rect
CPButtonStateBezelStyleRecessed = CPThemeState("recessed"); // IB style : Recessed
CPButtonStateBezelStyleInline = CPThemeState("inline"); // IB style : Inline
CPButtonStateBezelStyleRegularSquare = CPThemeState("bevel"); // IB style : Bevel
CPButtonStateBezelStyleTextured = CPThemeState("textured"); // IB style : Textured
CPButtonStateBezelStyleDisclosure = CPThemeState("disclosure"); // IB style : Disclosure triangle
CPButtonStateBezelStyleRoundedDisclosure = CPThemeState("rounded-disclosure"); // IB style : Rounded disclosure
// add all future correspondance between bezel styles and theme state here.
var CPButtonBezelStyleStateMap = @{
CPRoundedBezelStyle: CPButtonStateBezelStyleRounded,
CPRoundRectBezelStyle: CPButtonStateBezelStyleRoundRect,
CPRoundedBezelStyle: CPButtonStateBezelStyleRounded,
CPShadowlessSquareBezelStyle: CPButtonStateBezelStyleShadowlessSquare,
CPSmallSquareBezelStyle: CPButtonStateBezelStyleSmallSquare,
CPTexturedRoundedBezelStyle: CPButtonStateBezelStyleTexturedRounded,
CPRoundRectBezelStyle: CPButtonStateBezelStyleRoundRect,
CPRecessedBezelStyle: CPButtonStateBezelStyleRecessed,
CPInlineBezelStyle: CPButtonStateBezelStyleInline,
CPRegularSquareBezelStyle: CPButtonStateBezelStyleRegularSquare,
CPTexturedSquareBezelStyle: CPButtonStateBezelStyleTextured,
CPDisclosureBezelStyle: CPButtonStateBezelStyleDisclosure,
CPRoundedDisclosureBezelStyle: CPButtonStateBezelStyleRoundedDisclosure,
CPHUDBezelStyle: CPThemeStateHUD
};
/// @cond IGNORE
@@ -108,6 +128,7 @@ CPButtonImageOffset = 3.0;
// NS-style Display Properties
CPBezelStyle _bezelStyle;
ThemeState _bezelState;
CPString _keyEquivalent;
unsigned _keyEquivalentModifierMask;
@@ -117,7 +138,7 @@ CPButtonImageOffset = 3.0;
float _periodicDelay;
float _periodicInterval;
BOOL _isTracking;
BOOL _isHighlighted;
}
+ (Class)_binderClassForBinding:(CPString)aBinding
@@ -154,9 +175,17 @@ CPButtonImageOffset = 3.0;
return @{
@"image": [CPNull null],
@"image-offset": 0.0,
@"image-vertical-offset": 0.0,
@"bezel-inset": CGInsetMakeZero(),
@"content-inset": CGInsetMakeZero(),
@"bezel-color": [CPNull null],
@"image-position": CPImageLeft,
@"vertical-alignment": CPCenterVerticalTextAlignment,
@"alignment": CPCenterTextAlignment,
@"image-scaling": CPImageScaleNone,
@"invert-image": NO,
@"invert-image-on-push": NO,
@"image-color": [CPNull null] // If null, image color follows text color
};
}
@@ -171,12 +200,6 @@ CPButtonImageOffset = 3.0;
if (self)
{
// Should we instead override the defaults?
[self setValue:CPCenterTextAlignment forThemeAttribute:@"alignment"];
[self setValue:CPCenterVerticalTextAlignment forThemeAttribute:@"vertical-alignment"];
[self setValue:CPImageLeft forThemeAttribute:@"image-position"];
[self setValue:CPImageScaleNone forThemeAttribute:@"image-scaling"];
[self setBezelStyle:CPRoundRectBezelStyle];
[self setBordered:YES];
@@ -198,8 +221,8 @@ CPButtonImageOffset = 3.0;
[self setButtonType:CPMomentaryPushInButton];
}
#pragma mark -
#pragma mark Control Size
// MARK: -
// MARK: Control Size
- (void)setControlSize:(CPControlSize)aControlSize
{
@@ -210,7 +233,7 @@ CPButtonImageOffset = 3.0;
}
#pragma mark -
// MARK: -
// Setting the state
/*!
@@ -258,30 +281,6 @@ CPButtonImageOffset = 3.0;
anObjectValue = CPOnState;
[super setObjectValue:anObjectValue];
switch ([self objectValue])
{
case CPMixedState:
[self unsetThemeState:CPThemeStateSelected];
[self setThemeState:CPButtonStateMixed];
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask))
[self setThemeState:CPThemeStateHighlighted];
else
[self unsetThemeState:CPThemeStateHighlighted];
break;
case CPOnState:
[self unsetThemeState:CPButtonStateMixed];
[self setThemeState:CPThemeStateSelected];
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask))
[self setThemeState:CPThemeStateHighlighted];
else
[self unsetThemeState:CPThemeStateHighlighted];
break;
case CPOffState:
[self unsetThemeStates:[CPThemeStateSelected, CPButtonStateMixed, CPThemeStateHighlighted]];
}
}
/*!
@@ -378,12 +377,21 @@ CPButtonImageOffset = 3.0;
- (void)setImage:(CPImage)anImage
{
[self setValue:anImage forThemeAttribute:@"image" inState:CPThemeStateNormal];
// This is needed when compiling themes
if (!_bezelState)
_bezelState = CPThemeStateNormal;
[self setValue:anImage forThemeAttribute:@"image" inState:_bezelState];
// if we omit this, images will disappear as soon as the button becomes disabled
[self setValue:anImage forThemeAttribute:@"image" inState:_bezelState.and(CPThemeStateDisabled)];
}
- (CPImage)image
{
return [self valueForThemeAttribute:@"image" inState:CPThemeStateNormal];
if (!_bezelState)
_bezelState = CPThemeStateNormal;
return [self valueForThemeAttribute:@"image" inState:_bezelState];
}
/*!
@@ -392,7 +400,8 @@ CPButtonImageOffset = 3.0;
*/
- (void)setAlternateImage:(CPImage)anImage
{
[self setValue:anImage forThemeAttribute:@"image" inState:CPThemeStateHighlighted];
[self setValue:anImage forThemeAttribute:@"image" inState:_bezelState.and(CPThemeStateHighlighted)];
[self setValue:anImage forThemeAttribute:@"image" inState:_bezelState.and(CPThemeStateSelected)];
}
/*!
@@ -400,7 +409,17 @@ CPButtonImageOffset = 3.0;
*/
- (CPImage)alternateImage
{
return [self valueForThemeAttribute:@"image" inState:CPThemeStateHighlighted];
return [self valueForThemeAttribute:@"image" inState:_bezelState.and(CPThemeStateSelected)];
}
- (void)setHoveredImage:(CPImage)anImage
{
[self setValue:anImage forThemeAttribute:@"image" inState:_bezelState.and(CPThemeStateHovered)];
}
- (CPImage)hoveredImage
{
return [self valueForThemeAttribute:@"image" inState:_bezelState.and(CPThemeStateHovered)];
}
- (void)setImageOffset:(float)theImageOffset
@@ -423,11 +442,6 @@ CPButtonImageOffset = 3.0;
_showsStateBy = aMask;
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask) && [self state] != CPOffState)
[self setThemeState:CPThemeStateHighlighted];
else
[self unsetThemeState:CPThemeStateHighlighted];
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
@@ -444,11 +458,8 @@ CPButtonImageOffset = 3.0;
_highlightsBy = aMask;
if ([self hasThemeState:CPThemeStateHighlighted])
{
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
- (CPInteger)highlightsBy
@@ -533,9 +544,20 @@ CPButtonImageOffset = 3.0;
_periodicInterval = anInterval;
}
- (void)highlight:(BOOL)shouldHighlight
{
if (_isHighlighted == shouldHighlight)
return;
_isHighlighted = shouldHighlight;
[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
- (void)mouseDown:(CPEvent)anEvent
{
if ([self isContinuous])
if ([self isEnabled] && [self isContinuous])
{
_continuousDelayTimer = [CPTimer scheduledTimerWithTimeInterval:_periodicDelay callback: function()
{
@@ -555,46 +577,12 @@ CPButtonImageOffset = 3.0;
[_target performSelector:_action withObject:self];
}
- (BOOL)startTrackingAt:(CGPoint)aPoint
{
_isTracking = YES;
var startedTracking = [super startTrackingAt:aPoint];
if (_highlightsBy & (CPPushInCellMask | CPChangeGrayCellMask))
{
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask))
[self highlight:[self state] == CPOffState];
else
[self highlight:YES];
}
else
{
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask))
[self highlight:[self state] != CPOffState];
else
[self highlight:NO];
}
return startedTracking;
}
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
_isTracking = NO;
if (mouseIsUp && CGRectContainsPoint([self bounds], aPoint))
[self setNextState];
else
{
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask))
[self highlight:[self state] != CPOffState];
else
[self highlight:NO];
}
[self setNeedsLayout];
[self setNeedsDisplay:YES];
[self highlight:NO];
[self invalidateTimers];
}
@@ -615,7 +603,7 @@ CPButtonImageOffset = 3.0;
- (CGRect)contentRectForBounds:(CGRect)bounds
{
var contentInset = [self currentValueForThemeAttribute:@"content-inset"];
var contentInset = [self valueForThemeAttribute:@"content-inset" inState:[self _contentVisualState]];
return CGRectInsetByInset(bounds, contentInset);
}
@@ -642,7 +630,7 @@ CPButtonImageOffset = 3.0;
size = [contentView frameSize];
}
else
size = [([self title] || " ") sizeWithFont:[self currentValueForThemeAttribute:@"font"]];
size = [([self title] || " ") sizeWithFont:[self font]];
var contentInset = [self currentValueForThemeAttribute:@"content-inset"],
minSize = [self currentValueForThemeAttribute:@"min-size"],
@@ -698,86 +686,169 @@ CPButtonImageOffset = 3.0;
return [[_CPImageAndTextView alloc] initWithFrame:CGRectMakeZero()];
}
- (CPThemeState)_backgroundVisualState
{
var visualState = [self themeState] || CPThemeStateNormal, // Needed during theme compilation
currentState = [self state],
buttonIsOn = (currentState !== CPOffState);
if (_isHighlighted && (_highlightsBy & (CPPushInCellMask | CPChangeGrayCellMask)))
visualState = visualState.and(CPThemeStateHighlighted);
else
visualState = visualState.without(CPThemeStateHighlighted);
if (buttonIsOn && (_showsStateBy & (CPPushInCellMask | CPChangeGrayCellMask)))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
else
visualState = visualState.without(CPThemeStateSelected);
return visualState;
}
// Note : We have to split content and image visual states as, for example, radio buttons don't follow push buttons behavior
- (CPThemeState)_contentVisualState
{
var visualState = [self themeState] || CPThemeStateNormal,
currentState = [self state],
buttonIsOn = (currentState !== CPOffState);
// Define masks that imply the background changes color (Blue/Gray)
// If the background changes, we usually want the text to turn White (Highlighted state).
var highlightMask = CPPushInCellMask | CPChangeGrayCellMask | CPChangeBackgroundCellMask;
// Only add CPThemeStateHighlighted if the button is configured to highlight visually (Background change)
if ((_isHighlighted && (_highlightsBy & highlightMask)) ||
(((_showsStateBy & CPChangeGrayCellMask) || (_showsStateBy & CPChangeBackgroundCellMask)) && buttonIsOn))
visualState = visualState.and(CPThemeStateHighlighted);
else
visualState = visualState.without(CPThemeStateHighlighted);
if (buttonIsOn && (_showsStateBy & CPContentsCellMask))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
else
visualState = visualState.without(CPThemeStateSelected);
return visualState;
}
- (CPThemeState)_imageVisualState
{
var visualState = [self themeState] || CPThemeStateNormal, // Needed during theme compilation
currentState = [self state],
buttonIsOn = (currentState !== CPOffState);
// Remove highlighted & selected theme states
visualState = visualState.without(CPThemeStateHighlighted);
visualState = visualState.without(CPThemeStateSelected);
// Note : We have to deal with special case where button is ON, highlightsBy and showsStateBy use content, and button is pushed
// BUT this should not be used for disclosure buttons !
if (_isHighlighted && buttonIsOn && (_highlightsBy & CPContentsCellMask) && (_showsStateBy & CPContentsCellMask) && (_bezelStyle !== CPDisclosureBezelStyle))
return visualState;
if (_isHighlighted && ((_highlightsBy & CPContentsCellMask) || (_highlightsBy & CPChangeGrayCellMask)))
visualState = visualState.and(CPThemeStateHighlighted);
if (buttonIsOn && (_showsStateBy & CPContentsCellMask))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
return visualState;
}
- (CPString)_currentTitle
{
var buttonIsOn = ([self state] !== CPOffState);
// Note : We have to deal with special case where button is ON, highlightsBy and showsStateBy use content, and button is pushed
if (_isHighlighted && buttonIsOn && (_highlightsBy & CPContentsCellMask) && (_showsStateBy & CPContentsCellMask))
return _title;
else if (_alternateTitle && ((_isHighlighted && (_highlightsBy & CPContentsCellMask)) || (buttonIsOn && (_showsStateBy & CPContentsCellMask))))
return _alternateTitle;
else
return _title;
}
- (CPImage)_currentImage
{
var visualState = [self _imageVisualState],
currentImage = [self valueForThemeAttribute:@"image" inState:visualState],
imageColor = [self valueForThemeAttribute:@"image-color" inState:visualState],
buttonIsOn = ([self state] !== CPOffState);
if ([currentImage isMaterialIconImage])
{
if (([self valueForThemeAttribute:@"invert-image" inState:visualState] || ([self valueForThemeAttribute:@"invert-image-on-push" inState:visualState] && (_isHighlighted || (((_showsStateBy & CPChangeGrayCellMask) || (_showsStateBy & CPChangeBackgroundCellMask)) && buttonIsOn)))))
currentImage = [currentImage invertedImage];
else if (imageColor && [imageColor isKindOfClass:CPColor])
// In some buttons, image color doesn't follow text color !
currentImage = [currentImage imageVersionWithColor:imageColor];
else
// By default, image color follows text color
currentImage = [currentImage imageVersionWithColor:[self valueForThemeAttribute:@"text-color" inState:[self _contentVisualState]]];
}
return currentImage;
}
- (void)layoutSubviews
{
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"content-view"];
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"content-view"],
[bezelView setBackgroundColor:[self currentValueForThemeAttribute:@"bezel-color"]];
var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
relativeToEphemeralSubviewNamed:@"bezel-view"],
if (contentView)
{
var title = nil,
image = nil;
image = [self _currentImage],
contentVisualState = [self _contentVisualState];
if (_isTracking)
{
if (_highlightsBy & CPContentsCellMask)
{
if (_showsStateBy & CPContentsCellMask)
{
title = ([self state] == CPOffState && _alternateTitle) ? _alternateTitle : _title;
image = ([self state] == CPOffState && [self alternateImage]) ? [self alternateImage] : [self image];
}
else
{
title = [self alternateTitle];
image = [self alternateImage];
}
}
else if (_showsStateBy & CPContentsCellMask)
{
title = ([self state] != CPOffState && _alternateTitle) ? _alternateTitle : _title;
image = ([self state] != CPOffState && [self alternateImage]) ? [self alternateImage] : [self image];
}
else
{
title = _title;
image = [self image];
}
}
else
{
if (_showsStateBy & CPContentsCellMask)
{
title = ([self state] != CPOffState && _alternateTitle) ? _alternateTitle : _title;
image = ([self state] != CPOffState && [self alternateImage]) ? [self alternateImage] : [self image];
}
else
{
title = _title;
image = [self image];
}
}
[bezelView setBackgroundColor:[self valueForThemeAttribute:@"bezel-color" inState:[self _backgroundVisualState]]];
[contentView setText:[self _currentTitle]];
[contentView setImage:image];
[contentView setText:title];
[contentView setImage:image];
[contentView setImageOffset:[self currentValueForThemeAttribute:@"image-offset"]];
[contentView setImageOffset:[self valueForThemeAttribute:@"image-offset" inState:contentVisualState]];
[contentView setImageVerticalOffset:[self valueForThemeAttribute:@"image-vertical-offset" inState:contentVisualState]];
[contentView setFont:[self currentValueForThemeAttribute:@"font"]];
[contentView setTextColor:[self currentValueForThemeAttribute:@"text-color"]];
[contentView setAlignment:[self currentValueForThemeAttribute:@"alignment"]];
[contentView setVerticalAlignment:[self currentValueForThemeAttribute:@"vertical-alignment"]];
[contentView setLineBreakMode:[self currentValueForThemeAttribute:@"line-break-mode"]];
[contentView setTextShadowColor:[self currentValueForThemeAttribute:@"text-shadow-color"]];
[contentView setTextShadowOffset:[self currentValueForThemeAttribute:@"text-shadow-offset"]];
[contentView setImagePosition:[self currentValueForThemeAttribute:@"image-position"]];
[contentView setImageScaling:[self currentValueForThemeAttribute:@"image-scaling"]];
[contentView setDimsImage:[self hasThemeState:CPThemeStateDisabled] && _imageDimsWhenDisabled];
}
[contentView setFont:[self font]];
[contentView setTextColor:[self valueForThemeAttribute:@"text-color" inState:contentVisualState]];
[contentView setAlignment:[self valueForThemeAttribute:@"alignment" inState:contentVisualState]];
[contentView setVerticalAlignment:[self valueForThemeAttribute:@"vertical-alignment" inState:contentVisualState]];
[contentView setLineBreakMode:[self valueForThemeAttribute:@"line-break-mode" inState:contentVisualState]];
[contentView _setUsesSingleLineMode:YES];
[contentView setTextShadowColor:[self valueForThemeAttribute:@"text-shadow-color" inState:contentVisualState]];
[contentView setTextShadowOffset:[self valueForThemeAttribute:@"text-shadow-offset" inState:contentVisualState]];
[contentView setImagePosition:[self valueForThemeAttribute:@"image-position"]];
[contentView setImageScaling:[self valueForThemeAttribute:@"image-scaling"]];
// We don't automatically dim material icon images as the color is driven by the theme
[contentView setDimsImage:[self hasThemeState:CPThemeStateDisabled] && _imageDimsWhenDisabled && ![image isMaterialIconImage]];
}
- (void)setBordered:(BOOL)shouldBeBordered
{
if (shouldBeBordered)
{
[self setThemeState:CPThemeStateBordered];
if (_bezelState)
_bezelState = _bezelState.and(CPThemeStateBordered);
else
_bezelState = CPThemeStateBordered;
}
else
{
[self unsetThemeState:CPThemeStateBordered];
if (_bezelState)
_bezelState = _bezelState.without(CPThemeStateBordered);
else
_bezelState = CPThemeStateNormal;
}
}
- (BOOL)isBordered
@@ -807,7 +878,7 @@ CPButtonImageOffset = 3.0;
{
var selfWindow = [self window];
if (selfWindow === aWindow || aWindow === nil)
if (selfWindow === aWindow || aWindow == nil)
return;
if ([selfWindow defaultButton] === self)
@@ -873,17 +944,7 @@ CPButtonImageOffset = 3.0;
[self setState:[self nextState]];
var shouldHighlight = NO;
if (_highlightsBy & (CPPushInCellMask | CPChangeGrayCellMask))
{
if (_showsStateBy & (CPChangeGrayCellMask | CPChangeBackgroundCellMask))
shouldHighlight = [self state] == CPOffState;
else
shouldHighlight = YES;
}
[self highlight:shouldHighlight];
[self highlight:YES];
try
{
@@ -895,8 +956,7 @@ CPButtonImageOffset = 3.0;
}
finally
{
if (shouldHighlight)
[CPTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unhighlightButtonTimerDidFinish:) userInfo:nil repeats:NO];
[CPTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unhighlightButtonTimerDidFinish:) userInfo:nil repeats:NO];
}
}
@@ -919,6 +979,22 @@ CPButtonImageOffset = 3.0;
[self setThemeState:newState];
_bezelStyle = aBezelStyle;
if (_bezelState && newState)
{
if (currentState)
_bezelState =_bezelState.without(currentState);
_bezelState = _bezelState.and(newState);
}
else
_bezelState = newState || CPThemeStateNormal;
// For disclosure triangle and rounded, we have to move away from
// what Xcode tells us as we implement visual behavior with images (so content)
// and not background
if ((_bezelStyle === CPDisclosureBezelStyle) || (_bezelStyle === CPRoundedDisclosureBezelStyle))
[self setShowsStateBy:CPContentsCellMask];
}
- (unsigned)bezelStyle
@@ -942,7 +1018,8 @@ var CPButtonImageKey = @"CPButtonImageKey",
CPButtonPeriodicDelayKey = @"CPButtonPeriodicDelayKey",
CPButtonPeriodicIntervalKey = @"CPButtonPeriodicIntervalKey",
CPButtonHighlightsByKey = @"CPButtonHighlightsByKey",
CPButtonShowsStateByKey = @"CPButtonShowsStateByKey";
CPButtonShowsStateByKey = @"CPButtonShowsStateByKey",
CPButtonBezelStyleKey = @"CPButtonBezelStyleKey";
@implementation CPButton (CPCoding)
@@ -991,6 +1068,12 @@ var CPButtonImageKey = @"CPButtonImageKey",
_keyEquivalentModifierMask = [aCoder decodeIntForKey:CPButtonKeyEquivalentMaskKey];
if ([aCoder containsValueForKey:CPButtonIsBorderedKey])
[self setBordered:[aCoder decodeBoolForKey:CPButtonIsBorderedKey]];
if ([aCoder containsValueForKey:CPButtonBezelStyleKey])
[self setBezelStyle:[aCoder decodeIntForKey:CPButtonBezelStyleKey]];
[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
@@ -1025,6 +1108,9 @@ var CPButtonImageKey = @"CPButtonImageKey",
[aCoder encodeObject:_periodicDelay forKey:CPButtonPeriodicDelayKey];
[aCoder encodeObject:_periodicInterval forKey:CPButtonPeriodicIntervalKey];
[aCoder encodeBool:[self isBordered] forKey:CPButtonIsBorderedKey];
[aCoder encodeInt: [self bezelStyle] forKey:CPButtonBezelStyleKey];
}
@end
+1724 -148
View File
File diff suppressed because it is too large Load Diff
+33 -20
View File
@@ -94,26 +94,9 @@ CPCheckBoxImageOffset = 4.0;
[self takeStateFromKeyPath:aKeyPath ofObjects:objects];
}
- (CPImage)image
{
return [self currentValueForThemeAttribute:@"image"];
}
- (CPImage)alternateImage
{
return [self currentValueForThemeAttribute:@"image"];
}
- (BOOL)startTrackingAt:(CGPoint)aPoint
{
var startedTracking = [super startTrackingAt:aPoint];
[self highlight:YES];
return startedTracking;
}
#pragma mark -
#pragma mark Override methods from CPButton
// MARK: -
// MARK: Override methods from CPButton
- (CGSize)_minimumFrameSize
{
@@ -135,6 +118,36 @@ CPCheckBoxImageOffset = 4.0;
return size;
}
- (CPThemeState)_contentVisualState
{
// Note : Behavior differs from CPButton as title doesn't follow the highlightsBy content flag
var visualState = [self themeState] || CPThemeStateNormal, // Needed during theme compilation
currentState = [self state];
if ((currentState !== CPOffState) && (_showsStateBy & CPContentsCellMask))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
return visualState;
}
- (CPThemeState)_imageVisualState
{
// Note : Behavior differs from CPButton as we don't force "not selected" theme state
// when button is highglighted and selected
var visualState = [self themeState] || CPThemeStateNormal, // Needed during theme compilation
currentState = [self state];
if (_isHighlighted && (_highlightsBy & CPContentsCellMask))
visualState = visualState.and(CPThemeStateHighlighted);
if ((currentState !== CPOffState) && (_showsStateBy & CPContentsCellMask))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
return visualState;
}
@end
@implementation _CPCheckBoxValueBinder : CPBinder
@@ -164,7 +177,7 @@ CPCheckBoxImageOffset = 4.0;
@end
#pragma mark -
// MARK: -
@implementation CPCheckBox (TableDataView)
+14 -7
View File
@@ -202,8 +202,8 @@ var HORIZONTAL_MARGIN = 2;
#pragma mark -
#pragma mark Delegate
// MARK: -
// MARK: Delegate
/*!
Set the delegate of the receiver
@@ -600,9 +600,12 @@ var HORIZONTAL_MARGIN = 2;
if (_maxNumberOfRows > 0)
numberOfRows = MIN(numberOfRows, _maxNumberOfRows);
height = MAX(height, numberOfRows * (_minItemSize.height + _verticalMargin));
// calculate the required height: (sum of item heights) + (sum of margins between items).
var requiredHeight = (numberOfRows * _minItemSize.height) + (MAX(0, numberOfRows - 1) * _verticalMargin);
height = MAX(height, requiredHeight);
var itemSizeHeight = FLOOR(height / numberOfRows) - _verticalMargin;
// calculate individual item height based on the total available height.
var itemSizeHeight = (numberOfRows > 0) ? FLOOR((height - (MAX(0, numberOfRows - 1) * _verticalMargin)) / numberOfRows) : 0;
if (maxItemSizeHeight > 0)
itemSizeHeight = MIN(itemSizeHeight, maxItemSizeHeight);
@@ -621,7 +624,7 @@ var HORIZONTAL_MARGIN = 2;
_horizontalMargin = _uniformSubviewsResizing ? FLOOR((aFrameSize.width - numberOfColumns * anItemSize.width) / (numberOfColumns + 1)) : HORIZONTAL_MARGIN;
var x = _horizontalMargin,
y = -anItemSize.height;
y = -anItemSize.height;
[displayItems enumerateObjectsUsingBlock:function(item, idx, stop)
{
@@ -636,7 +639,11 @@ var HORIZONTAL_MARGIN = 2;
if (idx % numberOfColumns == 0)
{
x = _horizontalMargin;
y += _verticalMargin + anItemSize.height;
// For the first row, don't add a margin. For all subsequent rows, add the margin.
if (idx === 0)
y += anItemSize.height;
else
y += _verticalMargin + anItemSize.height;
}
[view setFrameOrigin:CGPointMake(x, y)];
@@ -739,7 +746,7 @@ var HORIZONTAL_MARGIN = 2;
*/
- (void)setMinItemSize:(CGSize)aSize
{
if (aSize === nil || aSize === undefined)
if (aSize == nil)
[CPException raise:CPInvalidArgumentException reason:"Invalid value provided for minimum size"];
if (CGSizeEqualToSize(_minItemSize, aSize))
+19 -12
View File
@@ -87,10 +87,10 @@ var cachedBlackColor,
CPImage _patternImage;
CPString _cssString;
}
@global document
#pragma mark -
#pragma mark Theming
// MARK: -
// MARK: Theming
+ (CPString)defaultThemeClass
{
@@ -109,8 +109,8 @@ var cachedBlackColor,
}
#pragma mark -
#pragma mark Static methods
// MARK: -
// MARK: Static methods
/*!
Creates a color in the RGB colorspace, with an alpha value.
@@ -267,7 +267,7 @@ var cachedBlackColor,
@return an initialized RGB color
*/
+ (CPColor)colorWithHexString:(string)hex
+ (CPColor)colorWithHexString:(CPString)hex
{
var rgba = hexToRGB(hex);
return rgba ? [[CPColor alloc] _initWithRGBA: rgba] : null;
@@ -561,7 +561,11 @@ var cachedBlackColor,
- (void)_initCSSStringFromComponents
{
var hasAlpha = CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0;
// Fix to avoid a problem when compiling a theme (missing the alpha component as theme compiler doesn't have CSS rgba capability)
var hasAlpha = YES;
#if PLATFORM(DOM)
hasAlpha = CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0;
#endif
_cssString = (hasAlpha ? "rgba(" : "rgb(") +
parseInt(_components[0] * 255.0) + ", " +
@@ -800,6 +804,9 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
var description = [super description],
patternImage = [self patternImage];
if ([self isCSSBased])
return description + "\n" + [self cssDictionary]+ "\nBefore:\n" + [self cssBeforeDictionary] + "\nAfter:\n" + [self cssAfterDictionary];
if (!patternImage)
return description + " " + [self cssString];
@@ -877,8 +884,8 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
@end
#pragma mark -
#pragma mark CSS Theming
// MARK: -
// MARK: CSS Theming
// The code below adds support for CSS theming with 100% compatibility with current theming system.
// The idea is to extend CPColor (and CPImage) with CSS components and adapt low level UI components to
@@ -933,7 +940,7 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
// You can use -(BOOL)isCSSBased to determine how to cope with it in your code.
// -(BOOL)hasCSSDictionary, -(BOOL)hasCSSBeforeDictionary and -(BOOL)hasCSSAfterDictionary are convience methods you can use.
//
// Remark : -(void)restorePreviousCSSState and -(DOMElement)applyCSSColorForView are meant to be used by low level UI widgets (like CPView) to implement
// Remark : +(void)restorePreviousCSSState and -(DOMElement)applyCSSColorForView are meant to be used by low level UI widgets (like CPView) to implement
// CSS theme support.
@implementation CPColor (CSSTheming)
@@ -992,7 +999,7 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
return ([_cssAfterDictionary count] > 0);
}
- (void)restorePreviousCSSState:(CPArrayRef)aPreviousStateRef forDOMElement:(DOMElement)aDOMElement
+ (void)restorePreviousCSSState:(CPArrayRef)aPreviousStateRef forDOMElement:(DOMElement)aDOMElement
{
#if PLATFORM(DOM)
var aPreviousState = @deref(aPreviousStateRef);
@@ -1084,7 +1091,7 @@ url("data:image/png;base64,BASE64ENCODEDDATA") // if there is a pattern image
@end
#pragma mark -
// MARK: -
/// @cond IGNORE
var CPColorComponentsKey = @"CPColorComponentsKey",
+81 -33
View File
@@ -51,6 +51,7 @@ CPColorPickerViewWidth = 265;
CPColorPickerViewHeight = 370;
CPColorPanelColorDidChangeNotification = @"CPColorPanelColorDidChangeNotification";
CPColorDragType = CPColorPboardType;
var PREVIEW_HEIGHT = 20.0,
TOOLBAR_HEIGHT = 32.0,
@@ -129,8 +130,6 @@ var SharedColorPanel = nil,
if (self)
{
//[[self contentView] setBackgroundColor:[CPColor colorWithWhite:0.95 alpha:1.0]];
[self setTitle:@"Color Panel"];
[self setLevel:CPFloatingWindowLevel];
@@ -149,20 +148,37 @@ var SharedColorPanel = nil,
*/
- (void)setColor:(CPColor)aColor
{
if ([_color isEqual:aColor])
return;
_color = aColor;
[_previewView setBackgroundColor:_color];
[CPApp sendAction:@selector(changeColor:) to:nil from:self];
// Check if the color change originated from user interaction inside the panel itself.
// We only broadcast `changeColor:` if the user picked a color via the panel's UI.
// If an external CPColorWell called `setColor:` programmatically, broadcasting it
// back down the responder chain would incorrectly change the previous First Responder.
var currentEvent = [CPApp currentEvent],
isFromPanel = currentEvent && ([currentEvent window] === self);
if (_target && _action)
[CPApp sendAction:_action to:_target from:self];
if (isFromPanel)
{
// Push color via Responder Chain (targets First Responder, i.e., the active CPColorWell)
[CPApp sendAction:@selector(changeColor:) to:nil from:self];
if (_target && _action)
[CPApp sendAction:_action to:_target from:self];
}
[[CPNotificationCenter defaultCenter]
postNotificationName:CPColorPanelColorDidChangeNotification
object:self];
[_activePicker setColor:_color];
[_opacitySlider setFloatValue:[_color alphaComponent]];
if (_activePicker)
[_activePicker setColor:_color];
if (_opacitySlider)
[_opacitySlider setFloatValue:[_color alphaComponent]];
}
/*!
@@ -174,7 +190,7 @@ var SharedColorPanel = nil,
{
[self setColor:aColor];
if (bool)
if (bool && _activePicker)
[_activePicker setColor:_color];
}
@@ -332,7 +348,7 @@ var SharedColorPanel = nil,
buttonForLater = button;
}
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
// Preview
var previewBox = [[CPView alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + 10, CGRectGetWidth(bounds) - 86, PREVIEW_HEIGHT)];
_previewView = [[_CPColorPanelPreview alloc] initWithFrame:CGRectInset([previewBox bounds], 2.0, 2.0)];
@@ -350,7 +366,7 @@ var SharedColorPanel = nil,
[_previewLabel setTextColor:[CPColor blackColor]];
[_previewLabel setAlignment:CPRightTextAlignment];
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
// Swatches
var swatchBox = [[CPView alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + 10 + PREVIEW_HEIGHT + 5, CGRectGetWidth(bounds) - 86, SWATCH_HEIGHT + 2.0)];
[swatchBox setBackgroundColor:[CPColor colorWithWhite:0.8 alpha:1.0]];
@@ -391,8 +407,6 @@ var SharedColorPanel = nil,
[contentView addSubview:opacityLabel];
[contentView addSubview:_opacitySlider];
_target = nil;
_action = nil;
_activePicker = nil;
[_previewView setBackgroundColor:_color];
@@ -412,8 +426,6 @@ var SharedColorPanel = nil,
@end
CPColorDragType = "CPColorDragType";
var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
/* @ignore */
@@ -423,12 +435,14 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
CPColor _dragColor;
CPColorPanel _colorPanel;
CPCookie _swatchCookie;
CGPoint _mouseDownPoint;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
_mouseDownPoint = CGPointMake(0, 0);
[self setBackgroundColor:[CPColor grayColor]];
[self registerForDraggedTypes:[CPArray arrayWithObjects:CPColorDragType]];
@@ -442,7 +456,6 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
for (var i = 0; i < 50; i++)
{
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
var view = [[CPView alloc] initWithFrame:CGRectMake(13 * i + 1, 1, 12, 12)],
fillView = [[CPView alloc] initWithFrame:CGRectInset([view bounds], 1.0, 1.0)];
@@ -483,7 +496,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
];
}
var cookieValue = eval(cookieValue);
var cookieValue = JSON.parse(cookieValue);
return [cookieValue arrayByApplyingBlock:function(value)
{
@@ -494,7 +507,6 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
- (CPArray)saveColorList
{
var result = [];
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
for (var i = 0; i < _swatches.length; i++)
result.push([[[_swatches[i] subviews][0] backgroundColor] hexString]);
@@ -521,39 +533,44 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
- (void)setColor:(CPColor)aColor atIndex:(int)index
{
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
[[_swatches[index] subviews][0] setBackgroundColor:aColor];
[self saveColorList];
}
- (void)mouseDown:(CPEvent)anEvent
{
_mouseDownPoint = [anEvent locationInWindow];
}
- (void)mouseUp:(CPEvent)anEvent
{
var point = [self convertPoint:[anEvent locationInWindow] fromView:nil],
bounds = [self bounds];
if (!CGRectContainsPoint(bounds, point) || point.x > [self bounds].size.width - 1 || point.x < 1)
return NO;
return;
[_colorPanel setColor:[self colorAtIndex:FLOOR(point.x / 13)] updatePicker:YES];
}
- (void)mouseDragged:(CPEvent)anEvent
{
var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
var windowPoint = [anEvent locationInWindow];
// Prevent accidental drags from rapid clicking causing small micro-movements
if (ABS(windowPoint.x - _mouseDownPoint.x) < 3 && ABS(windowPoint.y - _mouseDownPoint.y) < 3)
return;
var point = [self convertPoint:windowPoint fromView:nil];
if (point.x > [self bounds].size.width - 1 || point.x < 1)
return NO;
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:[CPArray arrayWithObject:CPColorDragType] owner:self];
return;
var swatch = _swatches[FLOOR(point.x / 13)];
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
_dragColor = [[swatch subviews][0] backgroundColor];
var bounds = CGRectMakeCopy([swatch bounds]);
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
var dragView = [[CPView alloc] initWithFrame:bounds],
dragFillView = [[CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
@@ -562,11 +579,15 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[dragView addSubview:dragFillView];
var pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];
[pasteboard declareTypes:[CPArray arrayWithObject:CPColorDragType] owner:self];
[pasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_dragColor] forType:CPColorDragType];
[self dragView:dragView
at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
offset:CGPointMake(0.0, 0.0)
event:anEvent
pasteboard:nil
pasteboard:pasteboard
source:self
slideBack:YES];
}
@@ -577,7 +598,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[aPasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_dragColor] forType:aType];
}
- (void)performDragOperation:(id /*<CPDraggingInfo>*/)aSender
- (BOOL)performDragOperation:(id /*<CPDraggingInfo>*/)aSender
{
var location = [self convertPoint:[aSender draggingLocation] fromView:nil],
pasteboard = [aSender draggingPasteboard],
@@ -587,6 +608,13 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
return NO;
[self setColor:[CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]] atIndex:FLOOR(location.x / 13)];
return YES;
}
- (unsigned)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
return CPDragOperationCopy;
}
@end
@@ -595,11 +623,13 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
@implementation _CPColorPanelPreview : CPView
{
CPColorPanel _colorPanel;
CGPoint _mouseDownPoint;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
_mouseDownPoint = CGPointMake(0, 0);
[self registerForDraggedTypes:[CPArray arrayWithObjects:CPColorDragType]];
@@ -616,7 +646,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
return _colorPanel;
}
- (void)performDragOperation:(id /*<CPDraggingInfo>*/)aSender
- (BOOL)performDragOperation:(id /*<CPDraggingInfo>*/)aSender
{
var pasteboard = [aSender draggingPasteboard];
@@ -625,6 +655,8 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
var color = [CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]];
[_colorPanel setColor:color updatePicker:YES];
return YES;
}
- (BOOL)isOpaque
@@ -632,15 +664,22 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
return YES;
}
- (void)mouseDown:(CPEvent)anEvent
{
_mouseDownPoint = [anEvent locationInWindow];
}
- (void)mouseDragged:(CPEvent)anEvent
{
var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
var windowPoint = [anEvent locationInWindow];
if (ABS(windowPoint.x - _mouseDownPoint.x) < 3 && ABS(windowPoint.y - _mouseDownPoint.y) < 3)
return;
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:[CPColorDragType] owner:self];
var point = [self convertPoint:windowPoint fromView:nil];
var bounds = CGRectMake(0, 0, 15, 15);
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
var dragView = [[CPView alloc] initWithFrame:bounds],
dragFillView = [[CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
@@ -649,11 +688,15 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[dragView addSubview:dragFillView];
var pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];
[pasteboard declareTypes:[CPArray arrayWithObject:CPColorDragType] owner:self];
[pasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:[self backgroundColor]] forType:CPColorDragType];
[self dragView:dragView
at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
offset:CGPointMake(0.0, 0.0)
event:anEvent
pasteboard:nil
pasteboard:pasteboard
source:self
slideBack:YES];
}
@@ -664,6 +707,11 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[aPasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:[self backgroundColor]] forType:aType];
}
- (unsigned)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
return CPDragOperationCopy;
}
@end
@import "CPColorPicker.j"
+200 -136
View File
@@ -25,7 +25,7 @@
@import "CPView.j"
@import "CPColor.j"
@import "CPColorPanel.j"
@import "CPPasteboard.j"
var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiveNotification";
@@ -39,10 +39,10 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
*/
@implementation CPColorWell : CPControl
{
BOOL _active;
BOOL _bordered;
CPColor _color;
BOOL _isChangingColorFromPanel; // Guard flag to prevent recursion
CGPoint _mouseDownPoint;
}
+ (Class)_binderClassForBinding:(CPString)aBinding
@@ -77,52 +77,54 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
[theBinding reverseSetValueFor:@"color"];
}
- (BOOL)isFirstResponder
{
return [[self window] firstResponder] === self;
}
- (BOOL)acceptsFirstResponder
{
return [self isEnabled];
}
- (void)activate:(BOOL)shouldBeExclusive
{
[[self window] makeFirstResponder:self];
[[CPColorPanel sharedColorPanel] orderFront:self];
}
- (BOOL)isActive
{
return [self isFirstResponder] && [self isEnabled];
}
/*!
Deactivates the color well.
*/
- (void)deactivate
{
if ([self isFirstResponder])
[[self window] makeFirstResponder:nil];
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
_active = NO;
_color = [CPColor whiteColor];
_mouseDownPoint = CGPointMakeZero();
[self setBordered:YES];
[self registerForDraggedTypes:[CPArray arrayWithObject:CPColorPboardType]];
}
return self;
}
- (void)_registerNotifications
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter
addObserver:self
selector:@selector(colorWellDidBecomeExclusive:)
name:_CPColorWellDidBecomeExclusiveNotification
object:nil];
[defaultCenter
addObserver:self
selector:@selector(colorPanelWillClose:)
name:CPWindowWillCloseNotification
object:[CPColorPanel sharedColorPanel]];
}
- (void)_removeNotifications
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter
removeObserver:self
name:_CPColorWellDidBecomeExclusiveNotification
object:nil];
[defaultCenter
removeObserver:self
name:CPWindowWillCloseNotification
object:[CPColorPanel sharedColorPanel]];
}
// MARK: -
// MARK: Draw
/*!
Sets whether the color well is bordered.
@@ -143,7 +145,8 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
return [self hasThemeState:CPThemeStateBordered];
}
// Managing Color From Color Wells
// MARK: -
// MARK: Managing Color
/*!
Returns the color well's current color.
@@ -158,12 +161,17 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
*/
- (void)setColor:(CPColor)aColor
{
if (_color == aColor)
if ([_color isEqual:aColor])
return;
_color = aColor;
[self setNeedsLayout];
// Only push back to the panel if we initiated the change (not if the panel pushed it to us)
// AND if we are the current focus.
if (!_isChangingColorFromPanel && [self isFirstResponder])
[[CPColorPanel sharedColorPanel] setColor:_color];
}
/*!
@@ -175,96 +183,175 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
[self setColor:[aSender color]];
}
// Activating and Deactivating Color Wells
/*!
Standard action method sent by CPColorPanel via the Responder Chain.
*/
- (void)changeColor:(id)aSender
{
if ([aSender isKindOfClass:[CPColorPanel class]])
{
_isChangingColorFromPanel = YES;
[self setColor:[aSender color]];
_isChangingColorFromPanel = NO;
// Forward the action to our target (e.g. controller)
[self sendAction:[self action] to:[self target]];
}
}
// MARK: -
// MARK: Activating and Deactivating
/*!
Activates the color well, displays the color panel, and makes the panel's current color the same as its own.
If exclusive is \c YES, deactivates any other CPColorWells. \c NO, keeps them active.
@param shouldBeExclusive whether other color wells should be deactivated.
*/
- (void)activate:(BOOL)shouldBeExclusive
- (BOOL)becomeFirstResponder
{
if (shouldBeExclusive)
// FIXME: make this queue!
[[CPNotificationCenter defaultCenter]
postNotificationName:_CPColorWellDidBecomeExclusiveNotification
object:self];
[self setThemeState:CPThemeStateFirstResponder];
var panel = [CPColorPanel sharedColorPanel];
// EXPLICITLY set ourselves as the target.
// This ensures that when the user clicks the panel (making Panel key),
// the panel still knows to send messages back to us.
[panel setTarget:self];
[panel setAction:@selector(changeColor:)];
// Sync panel to our current color
[panel setColor:_color];
if ([self isActive])
return;
_active = YES;
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(colorPanelDidChangeColor:)
name:CPColorPanelColorDidChangeNotification
object:[CPColorPanel sharedColorPanel]];
}
/*!
Deactivates the color well.
*/
- (void)deactivate
{
if (![self isActive])
return;
_active = NO;
[[CPNotificationCenter defaultCenter]
removeObserver:self
name:CPColorPanelColorDidChangeNotification
object:[CPColorPanel sharedColorPanel]];
}
/*!
Returns \c YES if the color well is active.
*/
- (BOOL)isActive
{
return _active;
}
- (void)colorPanelDidChangeColor:(CPNotification)aNotification
{
[self takeColorFrom:[aNotification object]];
[self sendAction:[self action] to:[self target]];
}
- (void)colorWellDidBecomeExclusive:(CPNotification)aNotification
{
if (self != [aNotification object])
[self deactivate];
}
- (void)colorPanelWillClose:(CPNotification)aNotification
{
[self deactivate];
}
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
[self highlight:NO];
if (!mouseIsUp || !CGRectContainsPoint([self bounds], aPoint) || ![self isEnabled])
[[CPNotificationCenter defaultCenter] postNotificationName:_CPColorWellDidBecomeExclusiveNotification object:self];
return YES;
}
- (BOOL)resignFirstResponder
{
[self unsetThemeState:CPThemeStateFirstResponder];
var panel = [CPColorPanel sharedColorPanel];
// Clean up if we were the target
if ([panel target] == self)
[panel setTarget:nil];
return YES;
}
// MARK: -
// MARK: Event Handling
- (void)mouseDown:(CPEvent)anEvent
{
if (![self isEnabled])
return;
_mouseDownPoint = [anEvent locationInWindow];
[self activate:YES];
var colorPanel = [CPColorPanel sharedColorPanel];
[colorPanel setPlatformWindow:[[self window] platformWindow]];
[colorPanel setColor:_color];
[colorPanel orderFront:self];
}
- (void)mouseDragged:(CPEvent)anEvent
{
if (![self isEnabled])
return;
var windowPoint = [anEvent locationInWindow];
// Prevent accidental drags from rapid clicking causing small micro-movements
if (ABS(windowPoint.x - _mouseDownPoint.x) < 3 && ABS(windowPoint.y - _mouseDownPoint.y) < 3)
return;
var bounds = CGRectMake(0, 0, 15, 15);
var dragView = [[CPView alloc] initWithFrame:bounds],
dragFillView = [[CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
[dragView setBackgroundColor:[CPColor blackColor]];
[dragFillView setBackgroundColor:_color];
[dragView addSubview:dragFillView];
var pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];
[pasteboard declareTypes:[CPArray arrayWithObject:CPColorPboardType] owner:self];
[pasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_color] forType:CPColorPboardType];
var point = [self convertPoint:windowPoint fromView:nil];
[self dragView:dragView
at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
offset:CGPointMake(0.0, 0.0)
event:anEvent
pasteboard:pasteboard
source:self
slideBack:YES];
}
// MARK: -
// MARK: Drag and Drop
- (void)draggingEntered:(id)sender
{
var pasteboard = [sender draggingPasteboard];
if ([[pasteboard types] containsObject:CPColorPboardType])
{
[self setThemeState:CPThemeStateHighlighted];
return CPDragOperationCopy;
}
return CPDragOperationNone;
}
- (void)draggingExited:(id)sender
{
[self unsetThemeState:CPThemeStateHighlighted];
}
- (BOOL)performDragOperation:(id)sender
{
var pasteboard = [sender draggingPasteboard];
if ([[pasteboard types] containsObject:CPColorPboardType])
{
var data = [pasteboard dataForType:CPColorPboardType],
newColor = [CPKeyedUnarchiver unarchiveObjectWithData:data];
if (newColor && [newColor isKindOfClass:[CPColor class]])
{
[self setColor:newColor];
[self sendAction:[self action] to:[self target]];
// Activate nicely after drop
[self activate:YES];
[self unsetThemeState:CPThemeStateHighlighted];
return YES;
}
}
return NO;
}
- (void)pasteboard:(CPPasteboard)aPasteboard provideDataForType:(CPString)aType
{
if (aType == CPColorPboardType)
[aPasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_color] forType:aType];
}
- (unsigned)draggingSourceOperationMaskForLocal:(BOOL)isLocal
{
return CPDragOperationCopy;
}
// MARK: -
// MARK: Layout
- (CGRect)contentRectForBounds:(CGRect)bounds
{
var contentInset = [self currentValueForThemeAttribute:@"content-inset"];
return CGRectInsetByInset(bounds, contentInset);
}
@@ -318,7 +405,6 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
[contentView setBackgroundColor:_color];
var contentBorderView = [self layoutEphemeralSubviewNamed:@"content-border-view"
@@ -328,28 +414,6 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
[contentBorderView setBackgroundColor:[self currentValueForThemeAttribute:@"content-border-color"]];
}
#pragma mark -
#pragma mark Observers method
- (void)_addObservers
{
if (_isObserving)
return;
[super _addObservers];
[self _registerNotifications];
}
- (void)_removeObservers
{
if (!_isObserving)
return;
[super _removeObservers];
[self _removeNotifications];
}
@end
@implementation CPColorWellValueBinder : CPBinder
@@ -398,9 +462,9 @@ var CPColorWellColorKey = "CPColorWellColorKey",
if (self)
{
_active = NO;
_color = [aCoder decodeObjectForKey:CPColorWellColorKey];
[self setBordered:[aCoder decodeBoolForKey:CPColorWellBorderedKey]];
[self registerForDraggedTypes:[CPArray arrayWithObject:CPColorPboardType]];
}
return self;
+22 -32
View File
@@ -91,7 +91,7 @@ var CPComboBoxTextSubview = @"text",
{
return @{
@"popup-button-size": CGSizeMake(21.0, 29.0),
@"border-inset": CGInsetMake(3.0, 3.0, 3.0, 3.0),
@"border-inset": CGInsetMake(3.0, 3.0, 3.0, 3.0)
};
}
@@ -133,7 +133,7 @@ var CPComboBoxTextSubview = @"text",
[self setThemeState:CPComboBoxStateButtonBordered];
}
#pragma mark Setting Display Attributes
// MARK: Setting Display Attributes
- (BOOL)hasVerticalScroller
{
@@ -214,7 +214,7 @@ var CPComboBoxTextSubview = @"text",
_numberOfVisibleItems = MAX(visibleItems, 1);
}
#pragma mark Setting a Delegate
// MARK: Setting a Delegate
- (id <CPComboBoxDelegate>)delegate
{
@@ -254,7 +254,7 @@ var CPComboBoxTextSubview = @"text",
[super setDelegate:aDelegate];
}
#pragma mark Setting a Data Source
// MARK: Setting a Data Source
- (id <CPComboBoxDataSource>)dataSource
{
@@ -305,7 +305,7 @@ var CPComboBoxTextSubview = @"text",
[self reloadData];
}
#pragma mark Working with an Internal List
// MARK: Working with an Internal List
- (void)addItemsWithObjectValues:(CPArray)objects
{
@@ -378,7 +378,7 @@ var CPComboBoxTextSubview = @"text",
return _items.length;
}
#pragma mark Manipulating the Displayed List
// MARK: Manipulating the Displayed List
/*!
Returns the delegate to be used when creating the pop up list.
@@ -533,7 +533,7 @@ var CPComboBoxTextSubview = @"text",
CPComboBoxFocusRingWidth = inset.bottom;
}
[_listDelegate popUpRelativeToRect:[self _borderFrame] view:self offset:CPComboBoxFocusRingWidth - 1];
[_listDelegate popUpRelativeToRect:[self bounds] view:self offset:CPComboBoxFocusRingWidth - 1];
[self _selectMatchingItem];
}
@@ -564,12 +564,19 @@ var CPComboBoxTextSubview = @"text",
var selectedStringValue = [_listDelegate selectedStringValue];
if (selectedStringValue === nil)
if (selectedStringValue == nil)
return NO;
else
_selectedStringValue = selectedStringValue;
[self setStringValue:_selectedStringValue];
[self _updatePlaceholderState];
#if PLATFORM(DOM)
[self _setCSSStyleForInputElement];
#endif
[self _reverseSetBinding];
return YES;
@@ -594,7 +601,7 @@ var CPComboBoxTextSubview = @"text",
[self sendAction:[self action] to:[self target]];
}
#pragma mark Manipulating the Selection
// MARK: Manipulating the Selection
- (void)deselectItemAtIndex:(int)index
{
@@ -646,7 +653,7 @@ var CPComboBoxTextSubview = @"text",
[self selectItemAtIndex:index];
}
#pragma mark Completing the Text Field
// MARK: Completing the Text Field
- (BOOL)completes
{
@@ -693,7 +700,7 @@ var CPComboBoxTextSubview = @"text",
_forceSelection = !!flag;
}
#pragma mark CPTextField Delegate Methods and Overrides
// MARK: CPTextField Delegate Methods and Overrides
/*! @ignore */
- (BOOL)sendAction:(SEL)anAction to:(id)anObject
@@ -893,7 +900,7 @@ var CPComboBoxTextSubview = @"text",
[_listDelegate setAlignment:alignment];
}
#pragma mark Pop Up Button Layout
// MARK: Pop Up Button Layout
- (CGRect)popupButtonRectForBounds:(CGRect)bounds
{
@@ -938,7 +945,7 @@ var CPComboBoxTextSubview = @"text",
relativeToEphemeralSubviewNamed:@"content-view"];
}
#pragma mark Internal Helpers
// MARK: Internal Helpers
/*! @ignore */
- (void)_dataSourceWarningForMethod:(SEL)cmd condition:(CPString)flag
@@ -975,23 +982,6 @@ var CPComboBoxTextSubview = @"text",
}
}
/*!
Calculate the frame in base coordinates that will nestle just below the visible border of the text field.
@ignore
*/
- (CGRect)_borderFrame
{
var inset = [self currentValueForThemeAttribute:@"border-inset"],
frame = [self bounds];
frame.origin.x += inset.left;
frame.origin.y += inset.top;
frame.size.width -= inset.left + inset.right;
frame.size.height -= inset.top + inset.bottom;
return frame;
}
/* @ignore */
- (void)_popUpButtonWasClicked
{
@@ -1016,8 +1006,8 @@ var CPComboBoxTextSubview = @"text",
}
#pragma mark -
#pragma mark Observers method
// MARK: -
// MARK: Observers method
- (void)_addObservers
{
+5
View File
@@ -84,6 +84,7 @@ CPAltEnterTextAreaFeature = 32;
CPCSSAnimationFeature = 33;
CPBackspaceTriggersPageBack = 34;
/*
When an absolutely positioned div (CPView) with an absolutely positioned canvas in it (CPView with drawRect:) moves things on top of the canvas (subviews) don't redraw correctly. E.g. if you have a bunch of text fields in a CPBox in a sheet which animates in, some of the text fields might not be visible because the CPBox has a canvas at the bottom and the box moved form offscreen to onscreen. This bug is probably very related: https://bugs.webkit.org/show_bug.cgi?id=67203
*/
@@ -234,6 +235,7 @@ else if (USER_AGENT.indexOf("Gecko") !== -1) // Must follow KHTML check.
PLATFORM_ENGINE |= CPGeckoBrowserEngine;
PLATFORM_FEATURES[CPJavaScriptCanvasDrawFeature] = YES;
PLATFORM_FEATURES[CPBackspaceTriggersPageBack] = YES;
var index = USER_AGENT.indexOf("Firefox"),
version = (index === -1) ? 2.0 : parseFloat(USER_AGENT.substring(index + "Firefox".length + 1));
@@ -244,6 +246,9 @@ else if (USER_AGENT.indexOf("Gecko") !== -1) // Must follow KHTML check.
if (version < 3.0)
PLATFORM_FEATURES[CPJavaScriptMouseWheelValues_8_15] = YES;
if (version >= 66)
PLATFORM_FEATURES[CPJavaScriptRemedialKeySupport] = YES;
// Some day this might be fixed and should be version prefixed. No known fixed version yet.
PLATFORM_FEATURES[CPInput1PxLeftPadding] = YES;
+36 -20
View File
@@ -23,12 +23,13 @@
@import <Foundation/CPFormatter.j>
@import <Foundation/CPTimer.j>
@import "CPFont.j"
@import "CPShadow.j"
@import "CPText.j"
@import "CPKeyValueBinding.j"
@import "CPTrackingArea.j"
@class CPFont
@global CPApp
@protocol CPControlTextEditingDelegate <CPObject>
@@ -47,6 +48,10 @@
CPRegularControlSize = 0;
CPSmallControlSize = 1;
CPMiniControlSize = 2;
CPLargeControlSize = 3; // Since MacOS 11, there's a new control size "Large"
// To get the theme state corresponding to a control size, use CPControlSizeThemeStates[controlSize]
CPControlSizeThemeStates = @[CPThemeStateControlSizeRegular, CPThemeStateControlSizeSmall, CPThemeStateControlSizeMini, CPThemeStateControlSizeLarge];
@typedef CPLineBreakMode
CPLineBreakByWordWrapping = 0;
@@ -131,14 +136,13 @@ var CPControlBlackColor = [CPColor blackColor];
@"vertical-alignment": CPTopVerticalTextAlignment,
@"line-break-mode": CPLineBreakByClipping,
@"text-color": [CPColor blackColor],
@"font": [CPFont systemFontOfSize:CPFontCurrentSystemSize],
@"font": [CPNull null],
@"text-shadow-color": [CPNull null],
@"text-shadow-offset": CGSizeMakeZero(),
@"image-position": CPImageLeft,
@"image-scaling": CPScaleToFit,
@"min-size": CGSizeMakeZero(),
@"max-size": CGSizeMake(-1.0, -1.0),
@"nib2cib-adjustment-frame": CGRectMakeZero()
@"max-size": CGSizeMake(-1.0, -1.0)
};
}
@@ -196,13 +200,16 @@ var CPControlBlackColor = [CPColor blackColor];
{
_sendActionOn = CPLeftMouseUpMask;
_trackingMouseDownFlags = 0;
[self setControlSize:CPThemeStateControlSizeRegular];
[self updateTrackingAreas];
}
return self;
}
#pragma mark -
#pragma mark Control Size
// MARK: -
// MARK: Control Size
/*!
Returns the control's control size
@@ -242,6 +249,9 @@ var CPControlBlackColor = [CPColor blackColor];
case CPMiniControlSize:
return CPThemeStateControlSizeMini;
case CPLargeControlSize:
return CPThemeStateControlSizeLarge;
case CPRegularControlSize:
default:
@@ -280,7 +290,7 @@ var CPControlBlackColor = [CPColor blackColor];
}
#pragma mark -
// MARK: -
/*!
Sets the receiver's target action.
@@ -620,15 +630,15 @@ var CPControlBlackColor = [CPColor blackColor];
*/
- (CPString)stringValue
{
if (_formatter && _value !== undefined)
if (_formatter && _value != nil)
{
var formattedValue = [self hasThemeState:CPThemeStateEditing] ? [_formatter editingStringForObjectValue:_value] : [_formatter stringForObjectValue:_value];
if (formattedValue !== nil && formattedValue !== undefined)
if (formattedValue != nil)
return formattedValue;
}
return (_value === undefined || _value === nil) ? @"" : String(_value);
return _value == nil ? @"" : String(_value);
}
/*!
@@ -637,7 +647,7 @@ var CPControlBlackColor = [CPColor blackColor];
- (void)setStringValue:(CPString)aString
{
// Cocoa raises an invalid parameter assertion and returns if you pass nil.
if (aString === nil || aString === undefined)
if (aString == nil)
{
CPLog.warn("nil or undefined sent to CPControl -setStringValue");
return;
@@ -803,7 +813,7 @@ var CPControlBlackColor = [CPColor blackColor];
CPBottomVerticalTextAlignment
</pre>
*/
- (void)setVerticalAlignment:(CPTextVerticalAlignment)alignment
- (void)setVerticalAlignment:(CPVerticalTextAlignment)alignment
{
[self setValue:alignment forThemeAttribute:@"vertical-alignment"];
}
@@ -848,7 +858,12 @@ var CPControlBlackColor = [CPColor blackColor];
*/
- (void)setTextColor:(CPColor)aColor
{
[self setValue:aColor forThemeAttribute:@"text-color"];
[self setValue:aColor forThemeAttribute:@"text-color" inState:[self themeState]];
}
- (void)setTextColor:(CPColor)aColor inThemeStates:(CPArray)themeStates
{
[self setValue:aColor forThemeAttribute:@"text-color" inStates:themeStates];
}
/*!
@@ -906,7 +921,7 @@ var CPControlBlackColor = [CPColor blackColor];
*/
- (CPFont)font
{
return [self valueForThemeAttribute:@"font"];
return [self currentValueForThemeAttribute:@"font"] || [CPFont systemFontForControlSize:_controlSize];
}
/*!
@@ -1012,8 +1027,8 @@ var CPControlBlackColor = [CPColor blackColor];
}
#pragma mark -
#pragma mark Base writing direction
// MARK: -
// MARK: Base writing direction
/*!
Sets the initial writing direction of the receiver
@@ -1116,6 +1131,7 @@ var CPControlActionKey = @"CPControlActionKey",
[self setControlSize:[aCoder decodeIntForKey:CPControlControlSizeKey]];
[self setBaseWritingDirection:[aCoder decodeIntForKey:CPControlBaseWrittingDirectionKey]];
[self updateTrackingAreas];
}
return self;
@@ -1135,18 +1151,18 @@ var CPControlActionKey = @"CPControlActionKey",
var objectValue = [self objectValue];
if (objectValue !== nil)
if (objectValue != nil)
[aCoder encodeObject:objectValue forKey:CPControlValueKey];
if (_target !== nil)
if (_target != nil)
[aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
if (_action !== nil)
if (_action != nil)
[aCoder encodeObject:_action forKey:CPControlActionKey];
[aCoder encodeInt:_sendActionOn forKey:CPControlSendActionOnKey];
if (_formatter !== nil)
if (_formatter != nil)
[aCoder encodeObject:_formatter forKey:CPControlFormatterKey];
[aCoder encodeInt:_controlSize forKey:CPControlControlSizeKey];
+2
View File
@@ -37,6 +37,8 @@
CPString _expires;
}
@global document
/*!
Initializes a cookie with a given name \c aName.
@param the name for the cookie
Executable → Regular
+2 -3
View File
@@ -193,9 +193,8 @@ CPCursorPlatformBoth = 3;
if (typeof cursor === "undefined")
{
var themeResourcePath = [[[CPApp themeBlend] bundle] resourcePath],
extension = CPBrowserIsOperatingSystem(CPWindowsOperatingSystem) ? @"cur" : @"png";
cssString = [CPString stringWithFormat:@"url(%@cursors/%@.%@), %@", themeResourcePath, cursorName, extension, aString];
extension = CPBrowserIsOperatingSystem(CPWindowsOperatingSystem) ? @"cur" : @"png",
cssString = [CPString stringWithFormat:@"url(%@cursors/%@.%@), %@", themeResourcePath, cursorName, extension, aString];
cursors[cursorName] = cursor = [[CPCursor alloc] initWithCSSString:cssString];
}
+204 -105
View File
@@ -1,7 +1,7 @@
/* CPDatePicker.j
* AppKit
*
* Created by Alexandre Wilhelm
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
@@ -59,31 +59,31 @@ CPEraDatePickerElementFlag = 0x0100;
*/
@implementation CPDatePicker : CPControl
{
BOOL _isBordered @accessors(getter=isBordered, setter=setBordered:);
BOOL _isBezeled @accessors(getter=isBezeled, setter=setBezeled:);
BOOL _drawsBackground @accessors(property=drawsBackground);
CPDate _dateValue @accessors(property=dateValue);
CPDate _minDate @accessors(property=minDate);
CPDate _maxDate @accessors(property=maxDate);
CPFont _textFont @accessors(property=textFont);
CPLocale _locale @accessors(property=locale);
//CPCalendar _calendar @accessors(property=calendar);
CPTimeZone _timeZone @accessors(property=timeZone);
id _delegate @accessors(property=delegate);
CPInteger _datePickerElements @accessors(property=datePickerElements);
CPInteger _datePickerMode @accessors(property=datePickerMode);
CPInteger _datePickerStyle @accessors(property=datePickerStyle);
CPInteger _timeInterval @accessors(property=timeInterval);
BOOL _isBordered @accessors(getter=isBordered, setter=setBordered:);
BOOL _isBezeled @accessors(getter=isBezeled, setter=setBezeled:);
BOOL _drawsBackground @accessors(property=drawsBackground);
CPDate _dateValue @accessors(property=dateValue);
CPDate _minDate @accessors(property=minDate);
CPDate _maxDate @accessors(property=maxDate);
CPFont _textFont @accessors(property=textFont);
CPLocale _locale @accessors(property=locale);
//CPCalendar _calendar @accessors(property=calendar);
CPTimeZone _timeZone @accessors(property=timeZone);
id _delegate @accessors(property=delegate);
CPInteger _datePickerElements @accessors(property=datePickerElements);
CPInteger _datePickerMode @accessors(property=datePickerMode);
CPInteger _datePickerStyle @accessors(property=datePickerStyle);
CPInteger _timeInterval @accessors(property=timeInterval);
BOOL _invokedByUserEvent;
_CPDatePickerTextField _datePickerTextfield;
_CPDatePickerCalendar _datePickerCalendar;
unsigned _implementedCDatePickerDelegateMethods;
BOOL _isTextual;
id _datePickerComponent;
}
#pragma mark -
#pragma mark Theme methods
// MARK: -
// MARK: Theme methods
+ (CPString)defaultThemeClass
{
@@ -144,12 +144,38 @@ CPEraDatePickerElementFlag = 0x0100;
@"hour-hand-size": CGSizeMakeZero(),
@"middle-hand-size": CGSizeMakeZero(),
@"minute-hand-size": CGSizeMakeZero(),
@"previous-button-size": CGSizeMakeZero(),
@"current-button-size": CGSizeMakeZero(),
@"next-button-size": CGSizeMakeZero(),
@"title-inset": [CPNull null],
@"day-label-inset": [CPNull null],
@"tile-content-inset": CGInsetMakeZero(),
@"tile-margin": [CPNull null],
@"tile-inset": CGInsetMakeZero(),
@"separator-color": [CPNull null],
@"separator-margin-width": 0,
@"separator-height": 0,
@"bezel-color-calendar-left": [CPNull null],
@"bezel-color-calendar-middle": [CPNull null],
@"bezel-color-calendar-right": [CPNull null],
@"tile-vertical-alignment": CPCenterVerticalTextAlignment,
@"tile-text-alignment": CPCenterTextAlignment,
@"hour-ampm-margin": 2,
@"time-separator-content-inset": CGInsetMakeZero(),
@"clock-second-hand-over": NO,
@"clock-draws-hours": NO,
@"clock-hours-font": [CPNull null],
@"clock-hours-text-color": [CPColor clearColor],
@"clock-hours-radius": 0,
@"calendar-clock-margin": 10,
@"clock-only-nib2cib-adjustment-frame": CPRectMakeZero(),
@"uses-focus-ring": NO
};
}
#pragma mark -
#pragma mark Binding methods
// MARK: -
// MARK: Binding methods
+ (Class)_binderClassForBinding:(CPString)theBinding
{
@@ -174,8 +200,8 @@ CPEraDatePickerElementFlag = 0x0100;
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
- (id)initWithFrame:(CGRect)aFrame
{
@@ -206,34 +232,61 @@ CPEraDatePickerElementFlag = 0x0100;
if (!_locale)
_locale = [CPLocale currentLocale];
_datePickerTextfield = [[_CPDatePickerTextField alloc] initWithFrame:[self bounds] withDatePicker:self];
[_datePickerTextfield setDateValue:_dateValue];
_datePickerComponent = nil;
_datePickerCalendar = [[_CPDatePickerCalendar alloc] initWithFrame:[self bounds] withDatePicker:self];
[_datePickerCalendar setDateValue:_dateValue];
// We might have been unarchived in a disabled state.
[_datePickerTextfield setEnabled:[self isEnabled]];
[self _createComponents];
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
- (void)_createComponents
{
_isTextual = (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle) || (_datePickerStyle == CPTextFieldDatePickerStyle);
#pragma mark -
#pragma mark Control Size
if (_datePickerComponent)
{
[_datePickerComponent removeFromSuperview];
_datePickerComponent = nil;
}
_datePickerComponent = [[(_isTextual ? _CPDatePickerTextField : _CPDatePickerCalendar) alloc] initWithFrame:[self bounds] withDatePicker:self];
[_datePickerComponent setDateValue:_dateValue];
[_datePickerComponent setControlSize:[self controlSize]];
[_datePickerComponent setDatePickerElements:_datePickerElements];
// FIXME: Don't know why but next line will cause theme compilation to fail...
// Workaround: added "if PLATFORM(DOM)"
#if PLATFORM(DOM)
[_datePickerComponent setEnabled:[self isEnabled]];
#endif
if (_isTextual)
// We need to transmit text color to the text field version (Cocoa doesn't permit adapting the calendar view text color)
[_datePickerComponent setTextColor:[self textColor]];
[self addSubview:_datePickerComponent];
}
// MARK: -
// MARK: Control Size
- (void)setControlSize:(CPControlSize)aControlSize
{
[super setControlSize:aControlSize];
if ([self datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [self datePickerStyle] == CPTextFieldDatePickerStyle)
[_datePickerComponent setControlSize:aControlSize];
if (_isTextual)
[self _sizeToControlSize];
}
#pragma mark -
#pragma mark Delegate methods
// MARK: -
// MARK: Delegate methods
/*! Set the delegate of the datePicker
@param aDelegate delegate of the datePicker
@@ -249,42 +302,19 @@ CPEraDatePickerElementFlag = 0x0100;
}
#pragma mark -
#pragma mark Layout method
// MARK: -
// MARK: Layout method
/*! Layout the subviews
*/
- (void)layoutSubviews
{
[super layoutSubviews];
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
{
if (![_datePickerTextfield superview])
[self addSubview:_datePickerTextfield];
if ([_datePickerCalendar superview])
[_datePickerCalendar removeFromSuperview];
[_datePickerTextfield setControlSize:[self controlSize]];
[_datePickerTextfield setNeedsLayout];
[_datePickerTextfield setNeedsDisplay:YES];
}
else
{
if (![_datePickerCalendar superview])
[self addSubview:_datePickerCalendar];
if ([_datePickerTextfield superview])
[_datePickerTextfield removeFromSuperview];
[_datePickerCalendar setNeedsLayout];
[_datePickerCalendar setNeedsDisplay:YES];
}
[_datePickerComponent setNeedsLayout];
[_datePickerComponent setNeedsDisplay:YES];
}
#pragma mark -
#pragma mark Setter
// MARK: -
// MARK: Setter
/*! Return the objectValue of the datePicker. The objectValue should take the timeZoneEffect
*/
@@ -341,10 +371,7 @@ CPEraDatePickerElementFlag = 0x0100;
if ([aDateValue isEqualToDate:_dateValue] && aTimeInterval == _timeInterval)
{
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield setDateValue:_dateValue];
else
[_datePickerCalendar setDateValue:_dateValue];
[_datePickerComponent setDateValue:_dateValue];
return;
}
@@ -372,10 +399,7 @@ CPEraDatePickerElementFlag = 0x0100;
if (_invokedByUserEvent)
[self sendAction:[self action] to:[self target]];
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield setDateValue:_dateValue];
else
[_datePickerCalendar setDateValue:_dateValue];
[_datePickerComponent setDateValue:_dateValue];
}
/*! Set the minDate of the datePicker
@@ -383,6 +407,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setMinDate:(CPDate)aMinDate
{
if (_minDate === aMinDate)
return;
[self willChangeValueForKey:@"minDate"];
_minDate = aMinDate;
[self didChangeValueForKey:@"minDate"];
@@ -395,6 +422,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setMaxDate:(CPDate)aMaxDate
{
if (_maxDate === aMaxDate)
return;
[self willChangeValueForKey:@"maxDate"];
_maxDate = aMaxDate;
[self didChangeValueForKey:@"maxDate"];
@@ -407,10 +437,32 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setDatePickerStyle:(CPInteger)aDatePickerStyle
{
if (_datePickerStyle === aDatePickerStyle)
return;
_datePickerStyle = aDatePickerStyle;
// This is needed in order to specify different theme attributes values for textual / graphical date picker
if (_datePickerStyle === CPClockAndCalendarDatePickerStyle)
[self setThemeState:CPThemeStateAlternateState];
else
[self unsetThemeState:CPThemeStateAlternateState];
// This is needed in order to specify different theme attributes values for with / without stepper textual date picker
if (_datePickerStyle === CPTextFieldAndStepperDatePickerStyle)
[self setThemeState:CPThemeStateComposedControl];
else
[self unsetThemeState:CPThemeStateComposedControl];
[self setControlSize:[self controlSize]];
if (_datePickerComponent)
{
// We already have a component so we need to update it
[_datePickerComponent resignFirstResponder];
[self _createComponents];
}
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
@@ -420,8 +472,14 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setDatePickerElements:(CPInteger)aDatePickerElements
{
if (_datePickerElements === aDatePickerElements)
return;
_datePickerElements = aDatePickerElements;
// Notify the component of the new value
[_datePickerComponent setDatePickerElements:_datePickerElements];
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
@@ -431,6 +489,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setDatePickerMode:(CPInteger)aDatePickerMode
{
if (_datePickerMode === aDatePickerMode)
return;
_datePickerMode = aDatePickerMode;
if (_datePickerMode == CPSingleDateMode)
@@ -456,6 +517,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setLocale:(CPLocale)aLocale
{
if (_locale === aLocale)
return;
_locale = aLocale;
if (_formatter)
@@ -466,7 +530,9 @@ CPEraDatePickerElementFlag = 0x0100;
}
// This will update the textFields (usefull when changing with a date with pm and am)
[_datePickerTextfield setDateValue:_dateValue];
if (_isTextual)
[_datePickerComponent setDateValue:_dateValue];
[self setNeedsDisplay:YES];
[self setNeedsLayout];
}
@@ -477,6 +543,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setBezeled:(BOOL)shouldBeBezeled
{
if (_isBezeled === shouldBeBezeled)
return;
_isBezeled = shouldBeBezeled;
if (shouldBeBezeled)
@@ -491,6 +560,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setBordered:(BOOL)shouldBeBordered
{
if (_isBordered === shouldBeBordered)
return;
_isBordered = shouldBeBordered;
if (shouldBeBordered)
@@ -506,6 +578,22 @@ CPEraDatePickerElementFlag = 0x0100;
- (void)setTextFont:(CPFont)aFont
{
[self setFont:aFont];
if (_isTextual)
[_datePickerComponent setTextFont:aFont];
}
/*!
Sets the color of the control.
@param aColor
*/
- (void)setTextColor:(CPColor)aColor
{
[super setTextColor:aColor];
if (_isTextual)
[_datePickerComponent setTextColor:aColor];
// REM: in Cocoa, setTextColor has no effect on calendar view
}
/*! Sets the enabled status of the control. Controls that are not enabled can not be used by the user and obtain the CPThemeStateDisabled theme state.
@@ -515,8 +603,10 @@ CPEraDatePickerElementFlag = 0x0100;
{
[super setEnabled:aBoolean];
[_datePickerTextfield setEnabled:aBoolean];
[_datePickerCalendar setEnabled:aBoolean];
[_datePickerComponent setEnabled:aBoolean];
if (!aBoolean)
[self resignFirstResponder];
}
/*! Set the background color of the datePicker
@@ -533,6 +623,9 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setDrawsBackground:(BOOL)aBoolean
{
if (_drawsBackground === aBoolean)
return;
[self willChangeValueForKey:@"drawsBackground"];
_drawsBackground = aBoolean;
[self didChangeValueForKey:@"drawsBackground"];
@@ -545,32 +638,32 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (void)setTimeZone:(CPTimeZone)aTimeZone
{
if (_timeZone === aTimeZone)
return;
[self willChangeValueForKey:@"timeZone"];
_timeZone = aTimeZone;
[self didChangeValueForKey:@"timeZone"];
[self setNeedsLayout];
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield setDateValue:_dateValue];
else
[_datePickerCalendar setDateValue:_dateValue];
[_datePickerComponent setDateValue:_dateValue];
}
#pragma mark -
#pragma mark First responder methods
// MARK: -
// MARK: First responder methods
/*! Return YES if style is set to CPTextFieldAndStepperDatePickerStyle or CPTextFieldDatePickerStyle
*/
- (BOOL)becomeFirstResponder
{
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
if (_isTextual)
{
if (![super becomeFirstResponder])
return NO;
[_datePickerTextfield _selectTextFieldWithFlags:[[CPApp currentEvent] modifierFlags]];
[_datePickerComponent _selectTextFieldWithFlags:[[CPApp currentEvent] modifierFlags]];
return YES;
}
@@ -589,15 +682,15 @@ CPEraDatePickerElementFlag = 0x0100;
*/
- (BOOL)resignFirstResponder
{
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield resignFirstResponder];
if (_isTextual)
[_datePickerComponent resignFirstResponder];
return YES;
}
#pragma mark -
#pragma mark getter
// MARK: -
// MARK: getter
/*!
Returns \c YES if the textfield is bezeled.
@@ -630,16 +723,16 @@ CPEraDatePickerElementFlag = 0x0100;
return [[_locale objectForKey:CPLocaleCountryCode] isEqualToString:@"US"];
}
#pragma mark -
#pragma mark Key event
// MARK: -
// MARK: Key event
/*! Key down event
@param anEvent
*/
- (void)keyDown:(CPEvent)anEvent
{
if (_datePickerStyle == CPTextFieldAndStepperDatePickerStyle || _datePickerStyle == CPTextFieldDatePickerStyle)
[_datePickerTextfield keyDown:anEvent];
if (_isTextual)
[_datePickerComponent keyDown:anEvent];
}
@end
@@ -665,20 +758,22 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
if (self)
{
_textFont = [aCoder decodeObjectForKey:CPTextFontKey];
_minDate = [aCoder decodeObjectForKey:CPMinDateKey] || [CPDate distantPast];
_maxDate = [aCoder decodeObjectForKey:CPMaxDateKey] || [CPDate distantFuture];
_timeInterval = [aCoder decodeDoubleForKey:CPIntervalKey];
_datePickerMode = [aCoder decodeIntForKey:CPDatePickerModeKey];
_datePickerElements = [aCoder decodeIntForKey:CPDatePickerElementsKey];
[self setDatePickerStyle:[aCoder decodeIntForKey:CPDatePickerStyleKey]];
_locale = [aCoder decodeObjectForKey:CPLocaleKey];
_dateValue = [aCoder decodeObjectForKey:CPDateValueKey];
_backgroundColor = [aCoder decodeObjectForKey:CPBackgroundColorKey];
_drawsBackground = [aCoder decodeBoolForKey:CPDrawsBackgroundKey];
_isBordered = [aCoder decodeBoolForKey:CPBorderedKey];
[self setBordered:[aCoder decodeBoolForKey:CPBorderedKey]];
[self setDrawsBackground:[aCoder decodeBoolForKey:CPDrawsBackgroundKey]];
[self setDatePickerElements:[aCoder decodeIntForKey:CPDatePickerElementsKey]];
[self setDatePickerMode:[aCoder decodeIntForKey:CPDatePickerModeKey]];
[self setDatePickerStyle:[aCoder decodeIntForKey:CPDatePickerStyleKey]];
[self setMinDate:[aCoder decodeObjectForKey:CPMinDateKey] || [CPDate distantPast]];
[self setMaxDate:[aCoder decodeObjectForKey:CPMaxDateKey] || [CPDate distantFuture]];
[self setLocale:[aCoder decodeObjectForKey:CPLocaleKey]];
[self _init];
[self setTextFont:[aCoder decodeObjectForKey:CPTextFontKey]];
[self setTimeInterval:[aCoder decodeDoubleForKey:CPIntervalKey]];
[self setDateValue:[aCoder decodeObjectForKey:CPDateValueKey]];
}
return self
@@ -686,7 +781,10 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
- (void)encodeWithCoder:(CPCoder)aCoder
{
// FIXME Do we need to encode _datePickerTextfield and _datePickerCalendar? As subviews they'll be encoded, but when we decode we recreate them anyhow.
// Before encoding, we remove all subviews as we'll recreate them at loading
while ([[self subviews] count] > 0)
[[[self subviews] lastObject] removeFromSuperview];
[super encodeWithCoder:aCoder];
[aCoder encodeDouble:_timeInterval forKey:CPIntervalKey];
@@ -695,7 +793,7 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
[aCoder encodeInt:_datePickerElements forKey:CPDatePickerElementsKey];
[aCoder encodeObject:_minDate forKey:CPMinDateKey];
[aCoder encodeObject:_maxDate forKey:CPMaxDateKey];
[aCoder encodeObject:_dateValue forKey:CPDateValueKey];;
[aCoder encodeObject:_dateValue forKey:CPDateValueKey];
[aCoder encodeObject:_textFont forKey:CPTextFontKey];
[aCoder encodeObject:_locale forKey:CPLocaleKey];
[aCoder encodeObject:_backgroundColor forKey:CPBackgroundColorKey];
@@ -706,6 +804,7 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
@end
// FIXME: add support for CPEditorRegistrationProtocol as implemented for CPTextField
@implementation _CPDatePickerValueBinder : CPBinder
{
}
+98
View File
@@ -0,0 +1,98 @@
/* _CPDatePickerBox.j
* AppKit
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import "CPView.j"
@class CPDatePicker
@implementation _CPDatePickerBox : CPView
{
CPDatePicker _datePicker @accessors(property=datePicker);
}
- (void)drawRect:(CGRect)aRect
{
[super drawRect:aRect];
if ([_datePicker isCSSBased])
return;
if ([_datePicker isBordered])
{
var context = [[CPGraphicsContext currentContext] graphicsPort],
borderWidth = [_datePicker valueForThemeAttribute:@"border-width"] / 2;
CGContextBeginPath(context);
CGContextSetStrokeColor(context, [_datePicker valueForThemeAttribute:@"border-color" inState:[_datePicker themeState]]);
CGContextSetLineWidth(context, [_datePicker valueForThemeAttribute:@"border-width"]);
CGContextMoveToPoint(context, borderWidth, borderWidth);
CGContextAddLineToPoint(context, aRect.size.width - borderWidth, borderWidth);
CGContextAddLineToPoint(context, aRect.size.width - borderWidth, aRect.size.height - borderWidth);
CGContextAddLineToPoint(context, borderWidth, aRect.size.height - borderWidth);
CGContextAddLineToPoint(context, borderWidth,borderWidth);
CGContextStrokePath(context);
CGContextClosePath(context);
}
}
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
{
if (aName === "bezel-view")
return [self bounds];
return [super rectForEphemeralSubviewNamed:aName];
}
- (CPView)createEphemeralSubviewNamed:(CPString)aName
{
if (aName === "bezel-view")
{
var view = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[view setHitTests:NO];
return view;
}
return [super createEphemeralSubviewNamed:aName];
}
- (void)layoutSubviews
{
if ([_datePicker isCSSBased])
{
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[bezelView setBackgroundColor:[_datePicker currentValueForThemeAttribute:@"bezel-color"]];
}
if ([_datePicker drawsBackground])
[self setBackgroundColor:[_datePicker backgroundColor]];
else
[self setBackgroundColor:[CPColor clearColor]];
}
@end
File diff suppressed because it is too large Load Diff
+349 -191
View File
@@ -20,10 +20,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/CPKeyedArchiver.j>
@import <Foundation/CPKeyedUnarchiver.j>
@import "CPView.j"
@import "CPTextField.j"
@import "CPImageView.j"
@import "CALayer.j"
@import "CPImage.j"
@class _CPCibCustomResource
@class CPDatePicker
@@ -34,168 +36,238 @@
var RADIANS = Math.PI / 180;
@typedef _CPDatePickerClockHand
_CPDatePickerClockHours = 1;
_CPDatePickerClockMinutes = 2;
_CPDatePickerClockSeconds = 3;
@implementation _CPDatePickerClock : CPView
@implementation _CPDatePickerClock : CPControl
{
BOOL _isEnabled;
CALayer _rootLayer;
CALayer _hourHandLayer;
CALayer _minuteHandLayer;
CALayer _secondHandLayer;
CALayer _middleHandLayer;
CPDatePicker _datePicker;
CPTextField _PMAMTextField;
BOOL _isEnabled;
// Pure DOM Views
CPImageView _hourHandView;
CPImageView _minuteHandView;
CPImageView _secondHandView;
CPImageView _middleHandView;
CPArray _hourLabels;
CPTextField _PMAMTextField;
CPDatePicker _datePicker;
CPView _currentHandView;
_CPDatePickerClockHand _currentHand;
CPInteger _currentRepresentedValue;
float _currentValueShift;
CPInteger _numberOfUnits;
BOOL _trackingHand;
CPInteger _representedHours;
CPInteger _representedMinutes;
CPInteger _representedSeconds;
BOOL _representedHourIsPM;
// Angles for Hit-Testing
float _hourAngle;
float _minuteAngle;
float _secondAngle;
CPInteger _datePickerElements @accessors(getter=datePickerElements);
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
- (id)initWithFrame:(CGRect)aFrame datePicker:(CPDatePicker)aDatePicker
{
if (self = [super initWithFrame:aFrame])
{
_datePicker = aDatePicker;
_datePicker = aDatePicker;
_datePickerElements = [_datePicker datePickerElements];
_trackingHand = NO;
_isEnabled = YES;
// 1. Initialize AM/PM Label
_PMAMTextField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-font" inState:CPThemeStateNormal] forThemeAttribute:@"font" inState:CPThemeStateNormal];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-text-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-color" inState:CPThemeStateNormal];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-text-shadow-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-text-shadow-offset" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-font" inState:CPThemeStateDisabled] forThemeAttribute:@"font" inState:CPThemeStateDisabled];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-text-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-color" inState:CPThemeStateDisabled];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-text-shadow-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateDisabled];
[_PMAMTextField setValue:[_datePicker valueForThemeAttribute:@"clock-text-shadow-offset" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateDisabled];
[_PMAMTextField setAlignment:CPCenterTextAlignment];
[_PMAMTextField setVerticalAlignment:CPCenterVerticalTextAlignment];
[self addSubview:_PMAMTextField];
var middleHandSize = [_datePicker valueForThemeAttribute:@"middle-hand-size"],
minuteHandSize = [_datePicker valueForThemeAttribute:@"minute-hand-size"],
hourHandSize = [_datePicker valueForThemeAttribute:@"hour-hand-size"],
secondHandSize = [_datePicker valueForThemeAttribute:@"second-hand-size"];
// 2. Initialize Number Labels (1 to 12)
_hourLabels = [CPArray array];
// We use layer to make the rotation possible
_hourHandLayer = [[HandLayer alloc] initWithSize:hourHandSize];
[_hourHandLayer setBounds:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height)];
[_hourHandLayer setAnchorPoint:CGPointMakeZero()];
[_hourHandLayer setPosition:CGPointMake(0.0, 0.0)];
for (var i = 1; i <= 12; i++)
{
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setStringValue:String(i)];
[label setAlignment:CPCenterTextAlignment];
[label setVerticalAlignment:CPCenterVerticalTextAlignment];
[self addSubview:label];
[_hourLabels addObject:label];
}
_minuteHandLayer = [[HandLayer alloc] initWithSize:minuteHandSize];
[_minuteHandLayer setBounds:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height)];
[_minuteHandLayer setAnchorPoint:CGPointMakeZero()];
[_minuteHandLayer setPosition:CGPointMake(0.0, 0.0)];
// 3. Initialize Hand Views
_hourHandView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
_minuteHandView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
_secondHandView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
_middleHandView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
_secondHandLayer = [[HandLayer alloc] initWithSize:secondHandSize];
[_secondHandLayer setBounds:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height)];
[_secondHandLayer setAnchorPoint:CGPointMakeZero()];
[_secondHandLayer setPosition:CGPointMake(0.0, 0.0)];
// Ensure images stretch accurately across the bounds of the image view
[_hourHandView setImageScaling:CPImageScaleAxesIndependently];
[_minuteHandView setImageScaling:CPImageScaleAxesIndependently];
[_secondHandView setImageScaling:CPImageScaleAxesIndependently];
[_middleHandView setImageScaling:CPImageScaleAxesIndependently];
_middleHandLayer = [[HandLayer alloc] initWithSize:middleHandSize];
[_middleHandLayer setBounds:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height)];
[_middleHandLayer setAnchorPoint:CGPointMakeZero()];
[_middleHandLayer setPosition:CGPointMake(0.0, 0.0)];
// 4. Add subviews in correct Z-Order
[self addSubview:_hourHandView];
[self addSubview:_minuteHandView];
_rootLayer = [CALayer layer];
[self setWantsLayer:YES];
[self setLayer:_rootLayer];
[_hourHandLayer setNeedsDisplay];
[_middleHandLayer setNeedsDisplay];
[_secondHandLayer setNeedsDisplay];
[_minuteHandLayer setNeedsDisplay];
[_rootLayer addSublayer:_hourHandLayer];
[_rootLayer addSublayer:_minuteHandLayer];
[_rootLayer addSublayer:_secondHandLayer];
[_rootLayer addSublayer:_middleHandLayer];
[_rootLayer setNeedsDisplay];
if ([_datePicker valueForThemeAttribute:@"clock-second-hand-over"])
{
[self addSubview:_middleHandView];
[self addSubview:_secondHandView];
}
else
{
[self addSubview:_secondHandView];
[self addSubview:_middleHandView];
}
}
return self;
}
- (void)_initHands
{
// FIX: Using 'duplicate' prevents CPImageViews from stealing the DOM element from each other!
[_middleHandView setImage:[[_datePicker currentValueForThemeAttribute:@"middle-hand-image"] duplicate]];
[_hourHandView setImage:[[_datePicker currentValueForThemeAttribute:@"hour-hand-image"] duplicate]];
[_minuteHandView setImage:[[_datePicker currentValueForThemeAttribute:@"minute-hand-image"] duplicate]];
[_secondHandView setImage:[[_datePicker currentValueForThemeAttribute:@"second-hand-image"] duplicate]];
#pragma mark -
#pragma mark Layout methods
var font = [_datePicker currentValueForThemeAttribute:@"clock-font"],
textColor = [_datePicker currentValueForThemeAttribute:@"clock-text-color"],
shadowCol = [_datePicker currentValueForThemeAttribute:@"clock-text-shadow-color"],
shadowOff = [_datePicker currentValueForThemeAttribute:@"clock-text-shadow-offset"];
if (font)
[_PMAMTextField setFont:font];
if (textColor)
[_PMAMTextField setTextColor:textColor];
if (shadowCol)
[_PMAMTextField setTextShadowColor:shadowCol];
if (shadowOff)
[_PMAMTextField setTextShadowOffset:shadowOff];
var hoursFont = [_datePicker currentValueForThemeAttribute:@"clock-hours-font"],
hoursColor = [_datePicker currentValueForThemeAttribute:@"clock-hours-text-color"],
drawsHours = [_datePicker currentValueForThemeAttribute:@"clock-draws-hours"];
for (var i = 0; i < 12; i++)
{
var label = _hourLabels[i];
[label setHidden:!drawsHours];
if (drawsHours) {
if (hoursFont) [label setFont:hoursFont];
if (hoursColor) [label setTextColor:hoursColor];
[label sizeToFit];
}
}
}
- (void)setDatePickerElements:(CPInteger)aDatePickerElements
{
_datePickerElements = aDatePickerElements;
[_secondHandView setHidden:!((_datePickerElements & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)];
}
// MARK: Layout methods
- (void)layoutSubviews
{
if ([_datePicker datePickerStyle] == CPTextFieldAndStepperDatePickerStyle || [_datePicker datePickerStyle] == CPTextFieldDatePickerStyle)
[self _initHands];
if (_trackingHand)
return;
[super layoutSubviews];
[self setBackgroundColor:[_datePicker currentValueForThemeAttribute:@"bezel-color-clock"]];
var bounds = [self bounds],
dateValue = [[_datePicker dateValue] copy];
var dateValue = [[_datePicker dateValue] copy];
[dateValue _dateWithTimeZone:[_datePicker timeZone]];
[self setBackgroundColor:[_datePicker currentValueForThemeAttribute:@"bezel-color-clock"]];
[_middleHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"middle-hand-image"]];
[_hourHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"hour-hand-image"]];
[_minuteHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"minute-hand-image"]];
[_secondHandLayer setImage:[_datePicker currentValueForThemeAttribute:@"second-hand-image"]];
_representedHours = dateValue.getHours();
_representedMinutes = dateValue.getMinutes();
_representedSeconds = dateValue.getSeconds();
_representedHourIsPM = (_representedHours > 11);
if ([_datePicker _isAmericanFormat])
{
if (dateValue.getHours() > 11)
[_PMAMTextField setStringValue:@"PM"];
else
[_PMAMTextField setStringValue:@"AM"];
_representedHours -= (_representedHourIsPM ? 12 : 0);
[_PMAMTextField sizeToFit];
[_PMAMTextField setFrameOrigin:CGPointMake(bounds.size.width / 2 - [_PMAMTextField frameSize].width / 2, bounds.size.height / 2 + 15)];
[_PMAMTextField setHidden:NO];
}
else
var bounds = [self bounds],
centerX = bounds.size.width / 2.0,
centerY = bounds.size.height / 2.0;
[_PMAMTextField setStringValue:_representedHourIsPM ? @"PM" : @"AM"];
[_PMAMTextField sizeToFit];
[_PMAMTextField setFrameOrigin:CGPointMake(centerX - [_PMAMTextField frameSize].width / 2.0, centerY + 15.0)];
if ([_datePicker currentValueForThemeAttribute:@"clock-draws-hours"])
{
[_PMAMTextField setHidden:YES];
var radius = [_datePicker currentValueForThemeAttribute:@"clock-hours-radius"] || 50.0;
for (var i = 0, angle = 60.0; i < 12; i++, angle -= 30.0)
{
var label = _hourLabels[i],
size = [label frameSize],
x = centerX + radius * COS(angle * RADIANS) - size.width / 2.0,
y = centerY - radius * SIN(angle * RADIANS) - size.height / 2.0;
[label setFrameOrigin:CGPointMake(x, y)];
}
}
[_hourHandLayer setRotationRadians:[self _hourPositionRadianForDate:dateValue]];
[_minuteHandLayer setRotationRadians:[self _minutePositionRadianForDate:dateValue]];
[_secondHandLayer setRotationRadians:[self _secondPositionRadianForDate:dateValue]];
var centerView = function(view, size) {[view setFrame:CGRectMake(centerX - size.width / 2.0, centerY - size.height / 2.0, size.width, size.height)];
};
[_PMAMTextField setEnabled:_isEnabled];
[_hourHandLayer setEnabled:_isEnabled];
[_middleHandLayer setEnabled:_isEnabled];
[_secondHandLayer setEnabled:_isEnabled];
[_minuteHandLayer setEnabled:_isEnabled];
var hSize = [_datePicker currentValueForThemeAttribute:@"hour-hand-size"] || CGSizeMake(4, 64),
mSize = [_datePicker currentValueForThemeAttribute:@"minute-hand-size"] || CGSizeMake(4, 96),
sSize = [_datePicker currentValueForThemeAttribute:@"second-hand-size"] || CGSizeMake(4, 96),
midSize = [_datePicker currentValueForThemeAttribute:@"middle-hand-size"] || CGSizeMake(8, 8);
// Check if we have to display the hand second
if (([_datePicker datePickerElements] & CPHourMinuteSecondDatePickerElementFlag) == CPHourMinuteSecondDatePickerElementFlag)
[_secondHandLayer setHidden:NO];
else
[_secondHandLayer setHidden:YES];
centerView(_hourHandView, hSize);
centerView(_minuteHandView, mSize);
centerView(_secondHandView, sSize);
centerView(_middleHandView, midSize);
[_rootLayer setNeedsDisplay];
[self _updateHands];
}
#pragma mark -
#pragma mark Accessors
- (float)_hourPositionRadianForDate:(CPDate)aDate
// Applies Pure CSS Transforms to rotate the elements natively in the browser
- (void)_rotateView:(CPView)view byAngle:(float)radians
{
var hours = aDate.getHours() + aDate.getMinutes() / 60;
return (360 * hours / 12) * RADIANS;
#if PLATFORM(DOM)
var style = view._DOMElement.style;
style[CPBrowserStyleProperty("transformOrigin")] = "50% 50%";
style[CPBrowserStyleProperty("transform")] = "rotate(" + radians + "rad)";
#endif
}
- (float)_secondPositionRadianForDate:(CPDate)aDate
- (void)_updateHands
{
return (360 * aDate.getSeconds() / 60) * RADIANS;
_hourAngle = (360.0 * (_representedHours + _representedMinutes / 60.0) / 12.0) * RADIANS;
_minuteAngle = (360.0 * (_representedMinutes + _representedSeconds / 60.0) / 60.0) * RADIANS;
_secondAngle = (360.0 * _representedSeconds / 60.0) * RADIANS;
[self _rotateView:_hourHandView byAngle:_hourAngle];
[self _rotateView:_minuteHandView byAngle:_minuteAngle];
[self _rotateView:_secondHandView byAngle:_secondAngle];
}
- (float)_minutePositionRadianForDate:(CPDate)aDate
{
var minutes = aDate.getMinutes() + aDate.getSeconds() / 60;
return (360 * minutes / 60) * RADIANS;
}
// MARK: Accessors
- (void)setEnabled:(BOOL)shouldEnable
{
@@ -205,109 +277,195 @@ var RADIANS = Math.PI / 180;
return;
_isEnabled = shouldEnable;
[self setNeedsLayout];
// FIXME: This is a workaround for an apparent bug in CALayer.
// Without pumping the event loop, the sublayers of _rootLayer
// (the hands) are not redrawn until an event occurs.
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
@end
// MARK: Mouse actions
@implementation HandLayer : CALayer
// Since we rotate using Pure CSS, Cappuccino's `convertPoint:` doesn't know about it.
// So we use standard Trigonometry to perfectly hit-test the rotated hands!
- (BOOL)_hitTestHandWithSize:(CGSize)size angle:(float)radians atPoint:(CGPoint)aPoint
{
BOOL _isEnabled @accessors(setter=setEnabled:, getter=isEnabled);
var bounds = [self bounds],
centerX = bounds.size.width / 2.0,
centerY = bounds.size.height / 2.0;
CPImage _image;
CALayer _imageLayer;
float _rotationRadians;
// 1. Move point to center
var tx = aPoint.x - centerX,
ty = aPoint.y - centerY;
// 2. Rotate point backwards by the angle of the hand
var cosA = COS(-radians),
sinA = SIN(-radians),
rx = tx * cosA - ty * sinA,
ry = tx * sinA + ty * cosA;
// 3. Test if point is within the unrotated hand's rectangle
// The visual needle is in the top half of the hand's box (y from -h/2 to 0)
var w2 = size.width / 2.0,
h2 = size.height / 2.0;
if (rx >= -w2 && rx <= w2 && ry >= -h2 && ry <= 0)
return YES;
return NO;
}
#pragma mark -
#pragma mark Init methods
- (id)initWithSize:(CGSize)aSize
- (void)mouseDown:(CPEvent)anEvent
{
if (self = [super init])
if (!_isEnabled)
return;
var currentLocation = [self convertPoint:[anEvent locationInWindow] fromView:nil];
var sSize = [_datePicker currentValueForThemeAttribute:@"second-hand-size"] || CGSizeMake(4, 96),
mSize = [_datePicker currentValueForThemeAttribute:@"minute-hand-size"] || CGSizeMake(4, 96),
hSize = [_datePicker currentValueForThemeAttribute:@"hour-hand-size"] || CGSizeMake(4, 64);
if (![_secondHandView isHidden] && [self _hitTestHandWithSize:sSize angle:_secondAngle atPoint:currentLocation])
{
_isEnabled = YES;
_imageLayer = [CALayer layer];
_rotationRadians = 0;
[_imageLayer setDelegate:self];
[_imageLayer setBounds:CGRectMake(0.0, 0.0, aSize.width, aSize.height)];
[self addSublayer:_imageLayer];
_currentHandView = _secondHandView;
_currentHand = _CPDatePickerClockSeconds;
_currentRepresentedValue = _representedSeconds;
_currentValueShift = 0;
_numberOfUnits = 60;
}
else if (![_minuteHandView isHidden] && [self _hitTestHandWithSize:mSize angle:_minuteAngle atPoint:currentLocation])
{
_currentHandView = _minuteHandView;
_currentHand = _CPDatePickerClockMinutes;
_currentRepresentedValue = _representedMinutes;
_currentValueShift = _representedSeconds / 60;
_numberOfUnits = 60;
}
else if (![_hourHandView isHidden] && [self _hitTestHandWithSize:hSize angle:_hourAngle atPoint:currentLocation])
{
_currentHandView = _hourHandView;
_currentHand = _CPDatePickerClockHours;
_currentRepresentedValue = _representedHours;
_currentValueShift = _representedMinutes / 60;
_numberOfUnits = 12;
}
else
{
_currentHandView = nil;
_currentHand = CPNotFound;
_currentRepresentedValue = CPNotFound;
_currentValueShift = CPNotFound;
_numberOfUnits = CPNotFound;
}
return self;
if (_currentHandView)
[self trackMouse:anEvent];
}
#pragma mark -
#pragma mark Setter Getter methods
/*!
Set the bounds of the layer. The imageLayer will be at the center of this bounds.
*/
- (void)setBounds:(CGRect)aRect
- (BOOL)tracksMouseOutsideOfFrame
{
[super setBounds:aRect];
[_imageLayer setPosition:CGPointMake(CGRectGetMidX(aRect), CGRectGetMidY(aRect))];
return YES;
}
- (void)setImage:(CPImage)anImage
- (BOOL)startTrackingAt:(CGPoint)aPoint
{
if (_image === anImage)
return;
if ([anImage isKindOfClass:[_CPCibCustomResource class]])
_image = [anImage imageFromCoder:nil];
else
_image = anImage;
[_imageLayer setNeedsDisplay];
_trackingHand = YES;
return YES;
}
- (void)setRotationRadians:(float)radians
- (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
{
if (_rotationRadians === radians)
return;
var dx = aPoint.x - _bounds.size.width / 2,
dy = _bounds.size.height / 2 - aPoint.y,
angle = (PI_2 - ATAN2(dy,dx) + PI2) % PI2,
value = ROUND(angle * _numberOfUnits / PI2 - _currentValueShift) % _numberOfUnits;
_rotationRadians = radians;
if (value !== _currentRepresentedValue)
{
var movedForward = (_currentRepresentedValue > _numberOfUnits * 3/4) && (value < _numberOfUnits / 4),
movedBackward = (_currentRepresentedValue < _numberOfUnits / 4) && (value > _numberOfUnits * 3/4),
dateValue = [[_datePicker dateValue] copy];
[_imageLayer setAffineTransform:CGAffineTransformScale(
CGAffineTransformMakeRotation(_rotationRadians),
1.0, 1.0)];
[dateValue _dateWithTimeZone:[_datePicker timeZone]];
switch (_currentHand)
{
case _CPDatePickerClockHours:
if (movedForward || movedBackward)
{
_representedHourIsPM = !_representedHourIsPM;
if (movedForward && !_representedHourIsPM)
dateValue.setDate(dateValue.getDate() + 1);
else if (movedBackward && _representedHourIsPM)
dateValue.setDate(dateValue.getDate() - 1);
}
dateValue.setHours(value + (_representedHourIsPM ? 12 : 0));
break;
case _CPDatePickerClockMinutes:
if (movedForward)
// Hours++
dateValue.setHours(dateValue.getHours() + 1);
else if (movedBackward)
// Hours--
dateValue.setHours(dateValue.getHours() - 1);
dateValue.setMinutes(value);
break;
case _CPDatePickerClockSeconds:
if (movedForward)
// Minutes++
dateValue.setMinutes(dateValue.getMinutes() + 1);
else if (movedBackward)
// Minutes--
dateValue.setMinutes(dateValue.getMinutes() - 1);
dateValue.setSeconds(value);
break;
}
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = YES;
#endif
[_datePicker _setDateValue:dateValue timeInterval:[_datePicker timeInterval]];
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = NO;
#endif
_representedHours = dateValue.getHours();
_representedMinutes = dateValue.getMinutes();
_representedSeconds = dateValue.getSeconds();
_representedHourIsPM = (_representedHours > 11);
_representedHours -= (_representedHourIsPM ? 12 : 0);
switch (_currentHand) {
case _CPDatePickerClockHours:
_currentRepresentedValue = _representedHours;
break;
case _CPDatePickerClockMinutes:
_currentRepresentedValue = _representedMinutes;
break;
case _CPDatePickerClockSeconds:
_currentRepresentedValue = _representedSeconds;
break;
}
[self _updateHands];
}
return YES;
}
- (void)setEnabled:(BOOL)shouldEnable
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
shouldEnable = !!shouldEnable;
if (_isEnabled === shouldEnable)
return;
_isEnabled = shouldEnable;
[self setNeedsDisplay];
[_imageLayer setNeedsDisplay];
}
- (void)imageDidLoad:(CPImage)anImage
{
[_imageLayer setNeedsDisplay];
}
- (void)drawLayer:(CALayer)aLayer inContext:(CGContext)aContext
{
if ([_image loadStatus] != CPImageLoadStatusCompleted)
[_image setDelegate:self];
else
CGContextDrawImage(aContext, [aLayer bounds], _image);
_trackingHand = NO;
}
@end
+280
View File
@@ -0,0 +1,280 @@
/* _CPDatePickerDayView.j
* AppKit
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import "_CPDatePickerDayViewTextField.j"
@class CPDatePicker
@implementation _CPDatePickerDayView : CPControl
{
CPDate _date @accessors(property=date);
BOOL _isDisabled;
BOOL _isHighlighted;
BOOL _isSelected;
CPDatePicker _datePicker;
CPTextField _textField;
CPInteger _dayInWeek @accessors(property=dayInWeek);
BOOL _firstSelected @accessors(property=firstSelected);
BOOL _lastSelected @accessors(property=lastSelected);
}
// MARK: Init methods
/*! Create a new instance of _CPDatePickerDayView
@param aFrame
@param aDatePicker
@return a new instance of _CPDatePickerDayView
*/
- (id)initWithFrame:(CGRect)aFrame withDatePicker:(CPDatePicker)aDatePicker
{
if (self = [super initWithFrame:aFrame])
{
[self setHitTests:NO];
_datePicker = aDatePicker;
// FIXME: Beginning with Aristo3, the text field is directly themed based on a new class _CPDatePickerDayViewTextField
if ([self isCSSBased])
{
_textField = [[_CPDatePickerDayViewTextField alloc] initWithFrame:aFrame];
}
else
{
_textField = [[CPTextField alloc] initWithFrame:aFrame];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-alignment"] forThemeAttribute:@"alignment"];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-vertical-alignment"] forThemeAttribute:@"vertical-alignment"];
var contentInset = [_datePicker valueForThemeAttribute:@"tile-content-inset"];
if (contentInset)
[_textField setValue:contentInset forThemeAttribute:@"content-inset"];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inState:CPThemeStateNormal] forThemeAttribute:@"font" inState:CPThemeStateNormal];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-color" inState:CPThemeStateNormal];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inState:CPThemeStateSelected] forThemeAttribute:@"font" inState:CPThemeStateSelected];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inState:CPThemeStateSelected] forThemeAttribute:@"text-color" inState:CPThemeStateSelected];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inState:CPThemeStateSelected] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateSelected];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inState:CPThemeStateSelected] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateSelected];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inState:CPThemeStateDisabled] forThemeAttribute:@"font" inState:CPThemeStateDisabled];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-color" inState:CPThemeStateDisabled];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateDisabled];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateDisabled];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inStates:[CPThemeStateDisabled, CPThemeStateSelected]] forThemeAttribute:@"font" inStates:[CPThemeStateDisabled, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inStates:[CPThemeStateDisabled, CPThemeStateSelected]]forThemeAttribute:@"text-color" inStates:[CPThemeStateDisabled, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inStates:[CPThemeStateDisabled, CPThemeStateSelected]] forThemeAttribute:@"text-shadow-color" inStates:[CPThemeStateDisabled, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inStates:[CPThemeStateDisabled, CPThemeStateSelected]] forThemeAttribute:@"text-shadow-offset" inStates:[CPThemeStateDisabled, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inState:CPThemeStateHighlighted] forThemeAttribute:@"font" inState:CPThemeStateHighlighted];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inState:CPThemeStateHighlighted] forThemeAttribute:@"text-color" inState:CPThemeStateHighlighted];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inState:CPThemeStateHighlighted] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateHighlighted];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inState:CPThemeStateHighlighted] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateHighlighted];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"font" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"text-color" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"text-shadow-color" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"text-shadow-offset" inStates:[CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"font" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"text-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"text-shadow-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]] forThemeAttribute:@"text-shadow-offset" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted, CPThemeStateSelected]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-font" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]] forThemeAttribute:@"font" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]] forThemeAttribute:@"text-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]] forThemeAttribute:@"text-shadow-color" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]];
[_textField setValue:[_datePicker valueForThemeAttribute:@"tile-text-shadow-offset" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]] forThemeAttribute:@"text-shadow-offset" inStates:[CPThemeStateDisabled, CPThemeStateHighlighted]];
}
[self addSubview:_textField];
[self setNeedsLayout];
}
return self;
}
// MARK: -
// MARK: Theme methods
/*! Set a theme
*/
- (BOOL)setThemeState:(ThemeState)aState
{
[_textField setThemeState:aState];
[super setThemeState:aState];
}
/*! Unset a theme
*/
- (BOOL)unsetThemeState:(ThemeState)aState
{
[_textField unsetThemeState:aState];
[super unsetThemeState:aState];
}
// MARK: -
// MARK: Getter methods
/*! Select the tile
*/
- (void)setSelected:(BOOL)shouldBeSelected
{
if (_isSelected === shouldBeSelected)
return;
_isSelected = shouldBeSelected;
if (_isSelected)
[self setThemeState:CPThemeStateSelected];
else
[self unsetThemeState:CPThemeStateSelected];
}
/*! Disabled the tile (used for previous and next month tile)
*/
- (void)setDisabled:(BOOL)shouldBeDisabled
{
if (_isDisabled === shouldBeDisabled)
return;
_isDisabled = shouldBeDisabled;
if (_isDisabled)
[self setThemeState:CPThemeStateDisabled];
else
[self unsetThemeState:CPThemeStateDisabled];
}
- (BOOL)isDisabled
{
return _isDisabled;
}
/*! Highlight the tile (used for current day)
*/
- (void)setHighlighted:(BOOL)shouldBeHighlighted
{
if (_isHighlighted === shouldBeHighlighted)
return;
_isHighlighted = shouldBeHighlighted;
if (_isHighlighted)
[self setThemeState:CPThemeStateHighlighted];
else
[self unsetThemeState:CPThemeStateHighlighted];
}
/*! Set the stringValue of the tile
@param aStringValue
*/
- (void)setStringValue:(CPString)aStringValue
{
[_textField setStringValue:aStringValue];
}
// MARK: -
// MARK: Layout methods
/*! Layout the subviews
*/
- (void)layoutSubviews
{
if ([_datePicker isCSSBased])
{
var attributeName = @"bezel-color-calendar";
if (_isSelected)
{
if (_firstSelected && !_lastSelected)
attributeName = @"bezel-color-calendar-left";
else if (_lastSelected && !_firstSelected)
attributeName = @"bezel-color-calendar-right";
else if (!_firstSelected && !_lastSelected)
{
if (_dayInWeek == 0)
attributeName = @"bezel-color-calendar-left";
else if (_dayInWeek == 6)
attributeName = @"bezel-color-calendar-right";
else
attributeName = @"bezel-color-calendar-middle";
}
}
[self setBackgroundColor:[_datePicker valueForThemeAttribute:attributeName inState:[self themeState]]];
return;
}
var bounds = [self bounds];
[_textField sizeToFit];
[_textField setFrameOrigin:CGPointMake(bounds.size.width / 2 - [_textField frameSize].width / 2 + [_datePicker valueForThemeAttribute:@"border-width"], bounds.size.height / 2 - [_textField frameSize].height / 2)];
}
- (void)setFrame:(CGRect)aFrame
{
[super setFrame:aFrame];
[_textField setFrame:CGRectMake(0, 0, aFrame.size.width, aFrame.size.height)];
}
/*! Drawrect
*/
- (void)drawRect:(CGRect)aRect
{
[super drawRect:aRect];
if ([_datePicker isCSSBased])
return;
var themeState = [self themeState],
context = [[CPGraphicsContext currentContext] graphicsPort];
if (themeState.hasThemeState(CPThemeStateSelected))
{
[self setBackgroundColor:[_datePicker valueForThemeAttribute:@"bezel-color-calendar" inState:themeState]];
CGContextSetLineWidth(context, [_datePicker valueForThemeAttribute:@"border-width"]);
CGContextSetStrokeColor(context, [_datePicker valueForThemeAttribute:@"border-color" inState:themeState]);
CGContextAddRect(context, [self bounds]);
CGContextStrokeRect(context, [self bounds]);
}
else
{
// Clear color, because the original color of a tile is handle by his superview
[self setBackgroundColor:[CPColor clearColor]];
}
}
@end
@@ -0,0 +1,48 @@
/* _CPDatePickerDayViewTextField.j
* AppKit
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import "CPTextField.j"
@implementation _CPDatePickerDayViewTextField : CPTextField
+ (CPString)defaultThemeClass
{
return @"datePickerDayViewTextField";
}
+ (CPDictionary)themeAttributes
{
return @{
@"min-size": CGSizeMakeZero(),
@"content-inset": CGInsetMakeZero(),
@"text-color": [CPColor blackColor],
@"text-shadow-color": [CPColor clearColor],
@"text-shadow-offset": CGSizeMakeZero(),
@"font": [CPNull null],
@"vertical-alignment": CPCenterVerticalTextAlignment,
@"alignment": CPCenterTextAlignment,
};
}
@end
@@ -0,0 +1,604 @@
/* _CPDatePickerElementTextField.j
* AppKit
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPTextField.j"
@class CPDatePicker
@class _CPDatePickerElementView
CPDatePickerElementTextFieldBecomeFirstResponder = @"CPDatePickerElementTextFieldBecomeFirstResponder";
CPDatePickerElementTextFieldAMPMChangedNotification = @"CPDatePickerElementTextFieldAMPMChangedNotification";
// Removed hardcoded KeyCodes (CPZeroKeyCode, etc) as they are unreliable across browsers/layouts.
CPMonthDateType = 0;
CPDayDateType = 1;
CPYearDateType = 2;
CPHourDateType = 3;
CPSecondDateType = 4;
CPMinuteDateType = 5;
CPAMPMDateType = 6;
/*! An element textField
*/
@implementation _CPDatePickerElementTextField : CPTextField
{
_CPDatePickerElementTextField _nextTextField @accessors(property=nextTextField);
_CPDatePickerElementTextField _previousTextField @accessors(property=previousTextField);
_CPDatePickerElementView _datePickerElementView @accessors(property=datePickerElementView);
CPDatePicker _datePicker @accessors(setter=setDatePicker:);
int _dateType @accessors(getter=dateType);
int _maxNumber @accessors(getter=maxNumber);
int _minNumber @accessors(getter=minNumber);
BOOL _firstEvent;
CPTimer _timerEdition;
}
+ (CPString)defaultThemeClass
{
return @"datePickerElementTextField";
}
+ (CPDictionary)themeAttributes
{
return @{
@"content-inset": CGInsetMake(1.0, 0.0, 0.0, 0.0),
@"bezel-color": [CPNull null],
@"min-size": CGSizeMakeZero()
};
}
- (id)init
{
if (self = [super init])
{
_firstEvent = YES;
}
return self;
}
/*! @ignore */
- (BOOL)acceptsFirstResponder
{
return [_datePicker isEnabled];
}
/*! Set the dateType of the textField
*/
- (void)setDateType:(int)aDateType
{
_dateType = aDateType;
switch (aDateType)
{
case CPMonthDateType:
_minNumber = 1;
_maxNumber = 12;
break;
case CPDayDateType:
_minNumber = 1;
_maxNumber = 31;
break;
case CPYearDateType:
_minNumber = 0;
_maxNumber = 9999;
break;
case CPHourDateType:
_minNumber = 0;
_maxNumber = 23;
break;
case CPSecondDateType:
_minNumber = 0;
_maxNumber = 59;
break;
case CPMinuteDateType:
_minNumber = 0;
_maxNumber = 59;
break;
}
}
/*! Return the maxNumber of the textField
*/
- (int)maxNumber
{
if (_dateType == CPDayDateType)
return [[_datePicker dateValue] _daysInMonth];
return _maxNumber;
}
/*! Return the maxNumber of the textField depending of the maxDate
*/
- (int)_maxNumberWithMaxDate
{
var maxDate = [_datePicker maxDate],
date = [_datePicker dateValue];
if (maxDate)
{
switch (_dateType)
{
case CPMonthDateType:
if (maxDate.getFullYear() == date.getFullYear())
return maxDate.getMonth();
break;
case CPDayDateType:
if (maxDate.getFullYear() == date.getFullYear() && maxDate.getMonth() == date.getMonth())
return maxDate.getDate();
break;
case CPYearDateType:
return maxDate.getFullYear();
case CPHourDateType:
if (maxDate.getFullYear() == date.getFullYear() && maxDate.getMonth() == date.getMonth() && maxDate.getDate() == date.getDate())
return maxDate.getHours();
break;
case CPSecondDateType:
if (maxDate.getFullYear() == date.getFullYear() && maxDate.getMonth() == date.getMonth() && maxDate.getDate() == date.getDate() && maxDate.getHours() == date.getHours() && maxDate.getMinutes() == date.getMinutes())
return maxDate.getSeconds();
break;
case CPMinuteDateType:
if (maxDate.getFullYear() == date.getFullYear() && maxDate.getMonth() == date.getMonth() && maxDate.getDate() == date.getDate() && maxDate.getHours() == date.getHours())
return maxDate.getMinutes();
break;
}
}
return _maxNumber;
}
/*! Set the stringValue of the textField. This is going to check if there is 2 or 4 letters. If not it adds a space. Check also the maxDate
It's called when the user is editing with the keyboard
@param aStringValue a CPString
*/
- (void)setValueForKeyEvent:(CPEvent)anEvent
{
var keyCode = [anEvent keyCode],
characters = [anEvent characters];
// Check if the event is a deletion
var isDelete = (keyCode === CPDeleteKeyCode || keyCode === CPDeleteForwardKeyCode);
// Check if the event is a numeric input.
// By testing the character string against a regex, we support num-pads and
// international keyboards correctly, rather than relying on keyCode ranges.
var isNumeric = (characters && [characters length] > 0 && /^[0-9]$/.test(characters));
// If it is neither a delete command nor a digit, we ignore it.
if (!isDelete && !isNumeric)
return;
var newValue = [self stringValue].replace(/\s/g, ''),
length = [newValue length];
if (isDelete)
{
[_timerEdition invalidate];
_timerEdition = nil;
// Ensure we don't substring if length is 0
if (length > 0)
newValue = [newValue substringToIndex:(length - 1)];
}
else
{
// Since isNumeric is true, characters is a valid digit string
var eventKeyValue = characters;
if (!_timerEdition)
{
_timerEdition = [CPTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(_timerKeyEvent:) userInfo:nil repeats:NO];
if (_firstEvent || !length)
newValue = eventKeyValue;
else
newValue = parseInt(newValue).toString() + eventKeyValue;
}
else
{
var newFireDate = [CPDate date];
newFireDate.setSeconds(newFireDate.getSeconds() + 2);
[_timerEdition setFireDate:newFireDate];
newValue = parseInt(newValue).toString() + eventKeyValue;
}
}
// Safety check for NaN before comparison
var numericValue = parseInt(newValue);
if (isNaN(numericValue))
numericValue = 0;
if (numericValue > [self _maxNumberWithMaxDate] || ([_datePicker _isAmericanFormat] && _dateType == CPHourDateType && numericValue > 12))
return;
_firstEvent = NO;
[super setObjectValue:newValue];
}
/*!
End of the timer
*/
- (void)_timerKeyEvent:(id)sender
{
var stringValue = [self stringValue];
_timerEdition = nil;
if ([stringValue length])
{
if ([_datePicker _isAmericanFormat] && [self dateType] == CPHourDateType)
{
var isAMHour = [[self superview] _isAMHour];
if (!isAMHour && stringValue != 12)
stringValue = parseInt(stringValue) + 12;
if (stringValue == 12 && !isAMHour)
stringValue = 12;
else if (stringValue == 12)
stringValue = 0;
}
[self setObjectValue:stringValue];
}
}
/*!
We force to end the timer
*/
- (void)_invalidTimer
{
if (_timerEdition)
{
[_timerEdition invalidate];
_timerEdition = nil;
}
}
/*!
We force to end the timer and to update the objectValue of the datePicker
*/
- (void)_endEditing
{
if (_timerEdition)
[_timerEdition invalidate];
_timerEdition = nil;
var objectValue = [self stringValue];
if (![objectValue length])
objectValue = [self objectValue];
if ([_datePicker _isAmericanFormat] && [self dateType] == CPHourDateType)
{
var isAMHour = [[self superview] _isAMHour];
if (!isAMHour && objectValue != 12)
objectValue = parseInt(objectValue) + 12;
if (objectValue == 12 && !isAMHour)
objectValue = 12;
else if (objectValue == 12)
objectValue = 0;
}
[self setObjectValue:objectValue];
}
/*! Set the stringValue of the TextField. Add some zeros of there isn't 2/4 letters in the value. It's called at the end of the editing process
@param aStringValue a CPString
*/
- (void)setStringValue:(CPString)aStringValue
{
if (_dateType == CPYearDateType)
{
while ([aStringValue length] < 4)
aStringValue = "0" + aStringValue;
}
else if (_dateType != CPAMPMDateType)
{
if (_dateType == CPHourDateType && [_datePicker _isAmericanFormat])
{
var value = parseInt(aStringValue);
if (value == 0)
value = 12;
else if (value > 12)
value = value - 12;
aStringValue = value.toString();
}
while ([aStringValue length] < 2)
{
if (_dateType == CPSecondDateType || _dateType == CPMinuteDateType)
aStringValue = @"0" + aStringValue;
else
aStringValue = @" " + aStringValue;
}
}
[super setObjectValue:aStringValue];
}
/*! Set the objectValue. This will update the dateValue of the datePicker also. It's called with the binding of the stepper or arrows
This is not going to update the objectValue of the control !!! It updates the dateValue of the datePicker who's going to update the datePickerTextField if necessary
It's a bit tricky
@param aObjectValue
*/
- (void)setObjectValue:(id)anObjectValue
{
var dateValue = [[_datePicker dateValue] copy],
lengthString = [[self stringValue] length],
objectValue = parseInt(anObjectValue);
switch (_dateType)
{
case CPMonthDateType:
if (objectValue == 0 || !lengthString)
{
[self setStringValue:(dateValue.getMonth() + 1).toString()];
return;
}
var dateNextMonth = [dateValue copy];
dateNextMonth.setDate(1);
dateNextMonth.setMonth(parseInt(anObjectValue) - 1);
var numberDayNextMonth = [dateNextMonth _daysInMonth];
if (numberDayNextMonth < [dateValue _daysInMonth] && dateValue.getDate() > numberDayNextMonth)
[_datePickerElementView setDayDateValue:numberDayNextMonth.toString()];
[super setObjectValue:objectValue];
break;
case CPDayDateType:
if (objectValue == 0 || !lengthString)
{
[self setStringValue:dateValue.getDate().toString()];
return;
}
// if we enter a day that is too high for the current month
// we need to increase the month by one
// if we do not do this, the user input would be silently reset
// very poor user experience
if (parseInt(anObjectValue, 10) > [dateValue _daysInMonth])
{
[_datePickerElementView._textFieldMonth setIntValue:(dateValue.getMonth() + 2)];
[super setObjectValue:objectValue];
return;
}
[super setObjectValue:objectValue];
break;
case CPYearDateType:
if (objectValue == 0 || !lengthString)
{
[self setStringValue:dateValue.getFullYear().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPHourDateType:
if (!lengthString)
{
[self setStringValue:dateValue.getHours().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPSecondDateType:
if (!lengthString)
{
[self setStringValue:dateValue.getSeconds().toString()];
return;
}
[super setObjectValue:objectValue];
break;
case CPMinuteDateType:
if (!lengthString)
{
[self setStringValue:dateValue.getMinutes().toString()];
return;
}
[super setObjectValue:objectValue];
break;
}
var newDateValue = [_datePickerElementView dateValue],
timeZone = [_datePicker timeZone];
if (timeZone)
{
var secondsFromGMT = [timeZone secondsFromGMTForDate:newDateValue],
secondsFromGMTTimeZone = [timeZone secondsFromGMT];
newDateValue.setSeconds(newDateValue.getSeconds() + secondsFromGMT - secondsFromGMTTimeZone);
}
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = YES;
#endif
[_datePicker _setDateValue:newDateValue timeInterval:[_datePicker timeInterval]];
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = NO;
#endif
}
// MARK: -
// MARK: Mouse event
/*! Mouse down event. Launch a notification to notif the new first responder textField
*/
- (void)mouseDown:(CPEvent)anEvent
{
if (![self isEnabled])
return;
[super mouseDown:anEvent];
[[CPNotificationCenter defaultCenter] postNotificationName:CPDatePickerElementTextFieldBecomeFirstResponder object:[[self superview] superview] userInfo:[CPDictionary dictionaryWithObject:self forKey:@"textField"]];
}
// MARK: -
// MARK: Theme functions
/*! Set the theme CPThemeStateSelected
*/
- (void)makeSelectable
{
[self setThemeState:CPThemeStateSelected];
[_datePicker setThemeState:CPThemeStateEditing];
}
/*! Unsert the theme CPThemeStateSelected
*/
- (void)makeDeselectable
{
_firstEvent = YES;
[self unsetThemeState:CPThemeStateSelected];
[_datePicker unsetThemeState:CPThemeStateEditing];
}
// MARK: -
// MARK: Override
/*!
We override this method to get all the time the good width
*/
- (CGSize)_minimumFrameSize
{
var frameSize = [self frameSize],
contentInset = [self currentValueForThemeAttribute:@"content-inset"],
minSize = [self currentValueForThemeAttribute:@"min-size"],
maxSize = [self currentValueForThemeAttribute:@"max-size"],
lineBreakMode = [self lineBreakMode],
text = (_dateType == CPYearDateType) ? @"0000" : (_dateType == CPMonthDateType) ? @"10" : @"00",
textSize = CGSizeMakeCopy(frameSize),
font = [self currentValueForThemeAttribute:@"font"];
textSize.width -= contentInset.left + contentInset.right;
textSize.height -= contentInset.top + contentInset.bottom;
if (_dateType == CPAMPMDateType)
text = [self stringValue];
if (frameSize.width !== 0 &&
![self isBezeled] &&
(lineBreakMode === CPLineBreakByWordWrapping || lineBreakMode === CPLineBreakByCharWrapping))
{
textSize = [text sizeWithFont:font inWidth:textSize.width];
}
else
{
textSize = [text sizeWithFont:font];
// Account for possible fractional pixels at right edge
textSize.width += 1;
}
// Account for possible fractional pixels at bottom edge
textSize.height += 1;
frameSize.height = textSize.height + contentInset.top + contentInset.bottom;
if ([self isBezeled])
{
frameSize.height = MAX(frameSize.height, minSize.height);
if (maxSize.width > 0.0)
frameSize.width = MIN(frameSize.width, maxSize.width);
if (maxSize.height > 0.0)
frameSize.height = MIN(frameSize.height, maxSize.height);
}
else
frameSize.width = textSize.width + contentInset.left + contentInset.right;
frameSize.width = MAX(frameSize.width, minSize.width);
return frameSize;
}
- (CGRect)bezelRectForBounds:(CGRect)bounds
{
return CGRectMakeCopy(bounds);
}
@end
// MARK: -
@implementation _CPDatePickerElementSeparator : CPTextField
+ (CPString)defaultThemeClass
{
return @"datePickerElementSeparator";
}
+ (CPDictionary)themeAttributes
{
return @{
@"content-inset": CGInsetMake(1.0, 0.0, 0.0, 0.0),
@"min-size": CGSizeMakeZero()
};
}
@end
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,306 @@
/* _CPDatePickerHeaderView.j
* AppKit
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import "CPControl.j"
@import "CPTextField.j"
@import "CPButton.j"
@class CPDatePicker
var CPShortWeekDayNameArrayEn = [@"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa", @"Su"],
CPShortWeekDayNameArrayUS = [@"Su", @"Mo", @"Tu", @"We", @"Th", @"Fr", @"Sa"],
CPShortWeekDayNameArrayFr = [@"L", @"M", @"M", @"J", @"V", @"S", @"D"],
CPShortWeekDayNameArrayDe = [@"M", @"D", @"M", @"D", @"F", @"S", @"S"],
CPShortWeekDayNameArrayEs = [@"L", @"M", @"X", @"J", @"V", @"S", @"D"],
CPShortMonthNameArrayEn = [@"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun", @"Jul", @"Aug", @"Sep", @"Oct", @"Nov", @"Dec"],
CPShortMonthNameArrayFr = [@"janv.", String.fromCharCode(102, 233, 118, 46), @"mars", @"apr.", @"mai", @"juin", @"juil.", String.fromCharCode(97, 111, 251, 116), @"sept.", @"oct.", @"nov.", String.fromCharCode(100, 233, 99, 46)],
CPShortMonthNameArrayDe = [@"Jan", @"Feb", String.fromCharCode(77, 228, 114), @"Apr", @"Mai", @"Jun", @"Jul", @"Aug", @"Sep", @"Okt", @"Nov", @"Dez"],
CPShortMonthNameArrayEs = [@"ene", @"feb", @"mar", @"abr", @"may", @"jun", @"jul", @"ago", @"sep", @"oct", @"nov", @"dic"];
@implementation _CPDatePickerHeaderView : CPControl
{
CPArray _dayLabels;
CPArray _monthNames;
CPButton _nextButton;
CPButton _previousButton;
CPButton _currentButton;
CPDatePicker _datePicker;
CPDate _date;
CPTextField _title;
}
// MARK: Init methods
/*! Init a new instance of _CPDatePickerHeaderView
@param aFrame
@param aDatePicker
@return a new instance of _CPDatePickerHeaderView
*/
- (id)initWithFrame:(CGRect)aFrame datePicker:(CPDatePicker)aDatePicker delegate:(id)aDelegate
{
self = [super initWithFrame:aFrame];
if (self)
{
_datePicker = aDatePicker;
// Title
_title = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-font" inState:CPThemeStateNormal] forThemeAttribute:@"font" inState:CPThemeStateNormal];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-text-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-color" inState:CPThemeStateNormal];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-text-shadow-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-text-shadow-offset" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-font" inState:CPThemeStateDisabled] forThemeAttribute:@"font" inState:CPThemeStateDisabled];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-text-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-color" inState:CPThemeStateDisabled];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-text-shadow-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateDisabled];
[_title setValue:[_datePicker valueForThemeAttribute:@"title-text-shadow-offset" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateDisabled];
[self addSubview:_title];
_dayLabels = [CPArray array];
// Days
for (var i = 0, count = [[self _dayNames] count]; i < count; i++)
{
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[label setValue:[_datePicker valueForThemeAttribute:@"tile-text-alignment"] forThemeAttribute:@"alignment"];
var contentInset = [_datePicker valueForThemeAttribute:@"tile-content-inset"];
if (contentInset)
[label setValue:contentInset forThemeAttribute:@"content-inset"];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-font" inState:CPThemeStateNormal] forThemeAttribute:@"font" inState:CPThemeStateNormal];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-text-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-color" inState:CPThemeStateNormal];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-text-shadow-color" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateNormal];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-text-shadow-offset" inState:CPThemeStateNormal] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateNormal];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-font" inState:CPThemeStateDisabled] forThemeAttribute:@"font" inState:CPThemeStateDisabled];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-text-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-color" inState:CPThemeStateDisabled];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-text-shadow-color" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-color" inState:CPThemeStateDisabled];
[label setValue:[_datePicker valueForThemeAttribute:@"weekday-text-shadow-offset" inState:CPThemeStateDisabled] forThemeAttribute:@"text-shadow-offset" inState:CPThemeStateDisabled];
[_dayLabels addObject:label];
[self addSubview:label];
}
// Arrows
var size = [_datePicker valueForThemeAttribute:@"previous-button-size"];
_previousButton = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
[_previousButton setButtonType:CPMomentaryChangeButton];
[_previousButton setBordered:NO];
[_previousButton setImage:[_datePicker valueForThemeAttribute:@"arrow-image-left"]];
[_previousButton setAlternateImage:[_datePicker valueForThemeAttribute:@"arrow-image-left-highlighted"]];
[self addSubview:_previousButton];
size = [_datePicker valueForThemeAttribute:@"next-button-size"];
_nextButton = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
[_nextButton setButtonType:CPMomentaryChangeButton];
[_nextButton setBordered:NO];
[_nextButton setImage:[_datePicker valueForThemeAttribute:@"arrow-image-right"]];
[_nextButton setAlternateImage:[_datePicker valueForThemeAttribute:@"arrow-image-right-highlighted"]];
[self addSubview:_nextButton];
size = [_datePicker valueForThemeAttribute:@"current-button-size"];
_currentButton = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
[_currentButton setButtonType:CPMomentaryChangeButton];
[_currentButton setBordered:NO];
[_currentButton setImage:[_datePicker valueForThemeAttribute:@"circle-image"]];
[_currentButton setAlternateImage:[_datePicker valueForThemeAttribute:@"circle-image-highlighted"]];
[self addSubview:_currentButton];
[_previousButton setTarget:aDelegate];
[_previousButton setAction:@selector(_clickArrowPrevious:)];
[_previousButton setContinuous:YES];
[_nextButton setTarget:aDelegate];
[_nextButton setAction:@selector(_clickArrowNext:)];
[_nextButton setContinuous:YES];
[_currentButton setTarget:aDelegate];
[_currentButton setAction:@selector(_currentMonth:)];
[self setNeedsLayout];
}
return self;
}
// MARK: -
// MARK: Getter Setter methods
/*! Return the day names depending on the CPLocale of the datePicker
@return an array
*/
- (CPArray)_dayNames
{
switch ([[_datePicker locale] objectForKey:CPLocaleLanguageCode])
{
case @"en":
// Check if it's in the american format. If yes the week will begin the sunday
if ([_datePicker _isAmericanFormat])
return CPShortWeekDayNameArrayUS;
else
return CPShortWeekDayNameArrayEn;
break;
case @"es":
return CPShortWeekDayNameArrayEs;
break;
case @"de":
return CPShortWeekDayNameArrayDe;
break;
case @"fr":
return CPShortWeekDayNameArrayFr;
break;
default:
return CPShortWeekDayNameArrayEn;
break;
}
}
/*! Return the month names depending on the CPLocale of the datePicker
@return an array
*/
- (CPArray)_monthNames
{
switch ([[_datePicker locale] objectForKey:CPLocaleLanguageCode])
{
case @"en":
return CPShortMonthNameArrayEn;
break;
case @"es":
return CPShortMonthNameArrayEs;
break;
case @"de":
return CPShortMonthNameArrayDe;
break;
case @"fr":
return CPShortMonthNameArrayFr;
break;
default:
return CPShortMonthNameArrayEn;
break;
}
}
/*! Set the monthDate of the header
@aMonthDate the new monthDate
*/
- (void)setMonthForDate:(CPDate)aMonthDate
{
_date = aMonthDate;
[self setNeedsLayout];
}
/*! Set enabled
@param aBoolean
*/
- (void)setEnabled:(BOOL)aBoolean
{
[_previousButton setEnabled:aBoolean];
[_nextButton setEnabled:aBoolean];
[_currentButton setEnabled:aBoolean];
[_dayLabels makeObjectsPerformSelector:@selector(setEnabled:) withObject:aBoolean];
[_title setEnabled:aBoolean];
}
// MARK: -
// MARK: Layout methods
/*! Layout the subviews
*/
- (void)layoutSubviews
{
var bounds = [self bounds],
dayNames = [self _dayNames],
width = CGRectGetWidth(bounds),
buttonInset = [_datePicker valueForThemeAttribute:@"arrow-inset"],
numberOfLabels = [_dayLabels count],
labelWidth = width / numberOfLabels,
sizeButtonLeft = [[_datePicker valueForThemeAttribute:@"arrow-image-left"] size],
sizeButtonRight = [[_datePicker valueForThemeAttribute:@"arrow-image-right"] size],
sizeButtonCircle = [[_datePicker valueForThemeAttribute:@"circle-image"] size],
sizeTileWidth = [_datePicker valueForThemeAttribute:@"size-tile"].width,
titleInset = [_datePicker valueForThemeAttribute:@"title-inset"],
dayLabelInset = [_datePicker valueForThemeAttribute:@"day-label-inset"];
// Arrows
[_nextButton setFrame:CGRectMake(width - [_nextButton frameSize].width - buttonInset.right, buttonInset.top, sizeButtonRight.width, sizeButtonRight.height)];
[_currentButton setFrame:CGRectMake(CGRectGetMinX([_nextButton frame]) - sizeButtonCircle.width - buttonInset.left - buttonInset.right, buttonInset.top, sizeButtonCircle.width, sizeButtonCircle.height)];
[_previousButton setFrame:CGRectMake(CGRectGetMinX([_currentButton frame]) - sizeButtonLeft.width - buttonInset.left - buttonInset.right, buttonInset.top, sizeButtonLeft.width, sizeButtonLeft.height)];
var firstDayTileX;
// Weekday label
for (var i = 0; i < numberOfLabels; i++)
{
var dayLabel = _dayLabels[i];
[dayLabel setStringValue:dayNames[i]];
if (dayLabelInset) // Beginning with Aristo3
{
var thisWidth = ROUND((i+1) * sizeTileWidth) - ROUND(i * sizeTileWidth);
[dayLabel sizeToFit];
[dayLabel setFrame:CGRectMake(dayLabelInset.left + ROUND(i * sizeTileWidth), dayLabelInset.top, thisWidth, [dayLabel frameSize].height)];
}
else
{
[dayLabel sizeToFit];
[dayLabel setFrameOrigin:CGPointMake(sizeTileWidth * (i + 1) - sizeTileWidth / 2 - [dayLabel frameSize].width / 2, 23)];
if (i == 0)
firstDayTileX = sizeTileWidth * (i + 1) - sizeTileWidth / 2 - [dayLabel frameSize].width / 2;
}
}
// Title
[_title setStringValue:[CPString stringWithFormat:@"%s %i", [self _monthNames][_date.getMonth()], _date.getFullYear()]];
[_title sizeToFit];
if (titleInset) // Beginning with Aristo3
[_title setFrameOrigin:CGPointMake(titleInset.left, titleInset.top)];
else
[_title setFrameOrigin:CGPointMake(firstDayTileX, 6)];
}
@end
@@ -0,0 +1,636 @@
/* _CPDatePickerMonthView.j
* AppKit
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import "CPControl.j"
@import "_CPDatePickerDayView.j"
@class CPDatePicker
@global CPSingleDateMode
@global CPRangeDateMode
@implementation _CPDatePickerMonthView : CPControl
{
BOOL _isMonthJustChanged;
CPArray _dayTiles;
CPDate _clickDate;
CPDate _dragDate;
CPDate _date;
CPDate _previousMonth @accessors(property=previousMonth);
CPDate _nextMonth @accessors(property=nextMonth);
CPDatePicker _datePicker;
CPEvent _eventDragged;
CPTimer _timerMonth;
id _delegate;
int _indexDayTile;
}
// MARK: Init methods
/*! Init a _CPDatePickerMonthView
@param aFrame
@param aDatePicker
@return a new _CPDatePickerMonthView
*/
- (id)initWithFrame:(CGRect)aFrame datePicker:(CPDatePicker)aDatePicker delegate:(id)aDelegate
{
if (self = [super initWithFrame:aFrame])
{
_delegate = aDelegate;
_isMonthJustChanged = NO;
_indexDayTile = -1;
_datePicker = aDatePicker;
_dayTiles = [CPArray array];
// Create tiles
for (var i = 0; i < 42; i++)
{
var dayView = [[_CPDatePickerDayView alloc] initWithFrame:CGRectMakeZero() withDatePicker:_datePicker];
[self addSubview:dayView];
[_dayTiles addObject:dayView];
}
[self setNeedsLayout];
}
return self;
}
// MARK: -
// MARK: Getter Setter methods
/*! Set the monthDate of the component
@param aDate
*/
- (void)setMonthForDate:(CPDate)aDate
{
if (_dragDate)
{
if (_dragDate.getMonth() != _date.getMonth())
_isMonthJustChanged = YES;
_date = [_dragDate copy];
}
else
{
_date = [aDate copy];
}
if (![aDate isEqualToDate:[CPDate distantFuture]])
{
// Reset the date to the first day of the month & midnight
_date.setDate(1);
[_date _resetToMidnight];
// There must be a better way to do this.
var firstDay = [_date copy];
firstDay.setDate(1);
// Set the previous and next month date. This is usefull for the tile of the next/previous month
_previousMonth = new Date(firstDay.getTime() - 86400000);
_previousMonth.setDate(1);
_nextMonth = new Date(firstDay.getTime() + (([_date _daysInMonth] + 1) * 86400000));
_nextMonth.setDate(1);
}
[self reloadData];
if (_isMonthJustChanged)
{
var dayTile = [_dayTiles objectAtIndex:_indexDayTile];
if ([dayTile date].getMonth() == _date.getMonth())
{
[self mouseDragged:_eventDragged];
}
else
{
if ([dayTile date].getMonth() - _date.getMonth() == 1 || [dayTile date].getFullYear() - _date.getFullYear() == 1)
_timerMonth = [CPTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(_timerNextMonthEvent:) userInfo:nil repeats:NO];
else
_timerMonth = [CPTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(_timerPreviousMonthEvent:) userInfo:nil repeats:NO];
}
}
}
- (void)monthDate
{
return _date;
}
/*! Return the size of a tile
*/
- (CGSize)tileSize
{
return [_datePicker valueForThemeAttribute:@"size-tile"];
}
/*! Return the first index day of the month
*/
- (int)startOfWeekForDate:(CPDate)aDate
{
var day = aDate.getDay();
// American people begins the week the sunday
if (![_datePicker _isAmericanFormat])
return (day + 6) % 7;
return day;
}
/*! Set enabled
@param aBoolean
*/
- (void)setEnabled:(BOOL)aBoolean
{
[super setEnabled:aBoolean];
[self reloadData];
}
/*! Return the index of tile depending of the giving event
@param anEvent
@return an index
*/
- (CPInteger)indexOfTileForEvent:(CPEvent)anEvent
{
var locationInView = [self convertPoint:[anEvent locationInWindow] fromView:nil],
tileSize = [self tileSize],
borderWidth = [_datePicker valueForThemeAttribute:@"border-width"],
margin = [_datePicker valueForThemeAttribute:@"tile-margin"] || CGSizeMakeZero(),
tileInset = [_datePicker valueForThemeAttribute:@"tile-inset"] || CGInsetMakeZero();
// Get the week row
var rowIndex = FLOOR((locationInView.y - tileInset.top - margin.height) / (tileSize.height + 2 * margin.height + borderWidth)),
columnIndex = FLOOR((locationInView.x - tileInset.left) / (tileSize.width + 2 * margin.width + borderWidth));
columnIndex = MIN(MAX(columnIndex, 0), 6);
rowIndex = MIN(MAX(rowIndex, 0), 5);
var tileIndex = (rowIndex * 7) + columnIndex;
return tileIndex;
}
// MARK: -
// MARK: Reload data
/*! Reload the data
*/
- (void)reloadData
{
if (!_date)
return;
var currentMonth = _date,
startOfMonthDay = [self startOfWeekForDate:currentMonth],
daysInPreviousMonth = [_previousMonth _daysInMonth],
firstDayToShowInPreviousMonth = daysInPreviousMonth - startOfMonthDay,
currentDate = new Date(_previousMonth.getFullYear(), _previousMonth.getMonth(), firstDayToShowInPreviousMonth),
now = [CPDate date],
dateValue = [_datePicker dateValue];
// Update the tiles
for (var i = 0; i < [_dayTiles count]; i++)
{
var dayTile = _dayTiles[i];
// Increment to next day
currentDate.setTime(currentDate.getTime() + 90000000);
[currentDate _resetToMidnight];
var isPresentMonth = (now.getMonth() == currentDate.getMonth()
&& now.getFullYear() == currentDate.getFullYear());
[dayTile setDate:[currentDate copy]];
[dayTile setStringValue:currentDate.getDate()];
[dayTile setDisabled:/*![self isEnabled] ||*/ currentDate.getMonth() !== currentMonth.getMonth() || currentDate < [_datePicker minDate] || currentDate > [_datePicker maxDate]];
[dayTile setHighlighted:isPresentMonth && currentDate.getDate() == now.getDate()];
}
// Select the dates
[self _selectDate:[_datePicker dateValue] timeInterval:[_datePicker timeInterval]];
}
// MARK: -
// MARK: Select methods
/*! Select one date or several date depending of the giving interval
@param aStartDate
@param anInterval;
*/
- (void)_selectDate:(CPDate)aStartDate timeInterval:(CPInteger)anInterval
{
var endDate = [[CPDate alloc] initWithTimeInterval:anInterval sinceDate:aStartDate],
tilesCount = [_dayTiles count];
aStartDate = [aStartDate copy];
[aStartDate _resetToMidnight];
[endDate _resetToMidnight];
var firstSelected = NO;
for (var i = 0; i < tilesCount; i++)
{
var tile = _dayTiles[i],
tileDate = [[tile date] copy],
selected = NO;
[tileDate _resetToMidnight];
if (aStartDate)
selected = tileDate >= aStartDate && tileDate <= endDate;
// Select a tile
[tile setSelected:selected];
// If we are disabled, we have to disable selected tiles so they will appear disabled
[tile setDisabled:[tile isDisabled] || (selected && ![self isEnabled])];
if (selected)
{
if (!firstSelected)
{
firstSelected = YES;
[tile setFirstSelected:YES];
}
else
[tile setFirstSelected:NO];
[tile setLastSelected:NO];
}
else
{
if (firstSelected)
{
firstSelected = NO;
// As there was a first selected and we are now on an unselected tile,
// we are sure that i > 0
[_dayTiles[i-1] setLastSelected:YES];
}
}
}
}
// MARK: -
// MARK: Layout methods
/*! Tile the view
*/
- (void)tile
{
var tileSize = [self tileSize],
width = tileSize.width,
height = tileSize.height,
tilesCount = [_dayTiles count],
borderWidth = [_datePicker valueForThemeAttribute:@"border-width"],
margin = [_datePicker valueForThemeAttribute:@"tile-margin"],
tileInset = [_datePicker valueForThemeAttribute:@"tile-inset"],
thisWidth,
thisX,
dayInWeek,
weekInMonth,
tileFrame,
tileIndex;
// Set the frame of the tiles
for (tileIndex = 0; tileIndex < tilesCount; tileIndex++)
{
dayInWeek = tileIndex % 7;
weekInMonth = (tileIndex - dayInWeek) / 7;
tileFrame;
if (margin) // Beginning with Aristo3
{
thisX = ROUND(dayInWeek * (width + 2 * margin.width));
thisWidth = ROUND((dayInWeek+1) * (width + 2 * margin.width)) - thisX;
tileFrame = CGRectMake(tileInset.left + thisX, tileInset.top + margin.height + weekInMonth * (height + 2 * margin.height), thisWidth + borderWidth, height + borderWidth);
}
else
tileFrame = CGRectMake(dayInWeek * width, weekInMonth * height, width + borderWidth, height + borderWidth);
[_dayTiles[tileIndex] setFrame:tileFrame];
[_dayTiles[tileIndex] setDayInWeek:dayInWeek];
}
[self reloadData];
}
/*! Layout the subviews
*/
- (void)layoutSubviews
{
[super layoutSubviews];
[self tile];
[_dayTiles makeObjectsPerformSelector:@selector(setNeedsLayout)];
}
/*! Draw the component. This draws the border of the tile.
The selected tile are drawed in the drawRect method of the tile. But the unselected tile here.
It avoids some problems with tiles over other tiles (otherwise the color of the tile border would be different).
Rememeber that the first pixel of a tile are over the last pixel of the last tile (because the border)
*/
- (void)drawRect:(CGRect)aRect
{
[super drawRect:aRect];
if ([_datePicker isCSSBased])
{
// We just have to draw the separator (if any)
// No separator color means no separator
var separatorColor = [_datePicker valueForThemeAttribute:@"separator-color"],
separatorHeight = [_datePicker valueForThemeAttribute:@"separator-height"],
separatorMarginWidth = [_datePicker valueForThemeAttribute:@"separator-margin-width"];
if (separatorColor)
{
var context = [[CPGraphicsContext currentContext] graphicsPort],
bounds = [self bounds];
CGContextBeginPath(context);
CGContextSetStrokeColor(context, separatorColor);
CGContextSetLineWidth(context, separatorHeight);
CGContextMoveToPoint(context, separatorMarginWidth, 0.5);
CGContextAddLineToPoint(context, bounds.size.width - separatorMarginWidth, 0.5);
CGContextStrokePath(context);
CGContextClosePath(context);
}
return;
}
var context = [[CPGraphicsContext currentContext] graphicsPort],
width = [self tileSize].width,
height = [self tileSize].height,
isBorderPair = ([_datePicker valueForThemeAttribute:@"border-width"] % 2) == 0;
CGContextBeginPath(context);
CGContextSetStrokeColor(context, [_datePicker valueForThemeAttribute:@"border-color" inState:[_datePicker themeState]]);
CGContextSetLineWidth(context, [_datePicker valueForThemeAttribute:@"border-width"]);
if ([_datePicker isBordered])
{
for (var i = 0; i < 6; i++)
{
var y = i * height;
// Very usefull to avoid to have a line of two pixels instead one
if (!isBorderPair)
y += 0.5;
CGContextMoveToPoint(context, 0, y);
CGContextAddLineToPoint(context, [self bounds].size.width, y);
}
for (var i = 0; i < 7; i++)
{
var x = i * width;
// Very usefull to avoid to have a line of two pixels instead one
if (!isBorderPair)
x += 0.5;
CGContextMoveToPoint(context, x, 0);
CGContextAddLineToPoint(context, x, [self bounds].size.height);
}
}
else
{
var y = 0;
// Very usefull to avoid to have a line of two pixels instead one
if (!isBorderPair)
y += 0.5;
CGContextMoveToPoint(context, 0, y);
CGContextAddLineToPoint(context, [self bounds].size.width, y);
}
CGContextStrokePath(context);
CGContextClosePath(context);
}
// MARK: -
// MARK: Mouse event
/*! Mouse down event
*/
- (void)mouseDown:(CPEvent)anEvent
{
if (![self isEnabled])
return;
var dayTile = [_dayTiles objectAtIndex:[self indexOfTileForEvent:anEvent]],
dateTile = [[dayTile date] copy],
dateValue = [_datePicker dateValue];
_clickDate = [dateTile copy];
_dragDate = nil;
_indexDayTile = -1;
_eventDragged = nil;
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = YES;
#endif
// Check if we have to change or not the month of the component
if ([dayTile date].getMonth() == _date.getMonth())
{
if ([_datePicker datePickerMode] == CPRangeDateMode && [anEvent modifierFlags] & CPShiftKeyMask)
{
var dateValueAtMidnight = [[_datePicker dateValue] copy];
[dateValueAtMidnight _resetToMidnight];
if (dateTile < dateValueAtMidnight)
{
var interval;
if (dateTile == dateValueAtMidnight)
interval = [_datePicker timeInterval];
else
interval = ([dateValueAtMidnight timeIntervalSinceDate:dateTile] + [_datePicker timeInterval]);
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:dateTile] timeInterval:interval];
}
else if ([[dayTile date] isEqualToDate:dateValueAtMidnight])
{
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:dateTile] timeInterval:0];
}
else
{
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:[dateValueAtMidnight copy]] timeInterval:([dateTile timeIntervalSinceDate:dateValueAtMidnight])];
}
// Be sure to display the good month
[_delegate setDateValue:dateTile];
}
else
{
var minDate = [[_datePicker minDate] copy],
maxDate = [[_datePicker maxDate] copy];
[minDate _resetToMidnight];
[maxDate _resetToLastSeconds];
if (dateTile >= minDate && dateTile <= maxDate)
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:dateTile] timeInterval:0];
}
}
else
{
// Check the year and the month. The year is usefull when changing from Jan to Dec.
if (_date.getMonth() - [dayTile date].getMonth() == 1 || _date.getFullYear() - [dayTile date].getFullYear() == 1)
[_delegate _displayPreviousMonth];
else
[_delegate _displayNextMonth];
}
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = NO;
#endif
}
/*! Mouse dragged event
*/
- (void)mouseDragged:(CPEvent)anEvent
{
if (![self isEnabled] || !CGRectContainsPoint([self bounds],[self convertPoint:[anEvent locationInWindow] fromView:nil]))
return;
var dayTile = [_dayTiles objectAtIndex:[self indexOfTileForEvent:anEvent]],
dateTile = [[dayTile date] copy],
dateValue = [_datePicker dateValue];
_dragDate = [dateTile copy];
_indexDayTile = [self indexOfTileForEvent:anEvent];
_eventDragged = anEvent;
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = YES;
#endif
if ([_datePicker datePickerMode] == CPSingleDateMode)
{
// Check if we have to change or not the month of the component
if ([dayTile date].getMonth() == _date.getMonth())
{
[_timerMonth invalidate];
_isMonthJustChanged = NO;
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:dateTile] timeInterval:0];
}
else if (!_isMonthJustChanged)
{
[_timerMonth invalidate];
_isMonthJustChanged = NO;
// Check the year and the month. The year is usefull when changing from Jan to Dec.
if (_date.getMonth() - [dayTile date].getMonth() == 1 || _date.getFullYear() - [dayTile date].getFullYear() == 1)
[_delegate _displayPreviousMonth];
else
[_delegate _displayNextMonth];
}
}
else
{
if (dateTile.getMonth() == _date.getMonth() || !_isMonthJustChanged)
{
[_timerMonth invalidate];
_isMonthJustChanged = NO;
var dateValueAtMidnight = [[_datePicker dateValue] copy];
[dateValueAtMidnight _resetToMidnight];
if (dateTile < _clickDate)
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:dateTile] timeInterval:[_clickDate timeIntervalSinceDate:dateTile]];
else if ([[dayTile date] isEqualToDate:_clickDate])
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:dateTile] timeInterval:0];
else
[_datePicker _setDateValue:[self _hoursMinutesSecondsFromDatePickerForDate:_clickDate] timeInterval:[dateTile timeIntervalSinceDate:dateValueAtMidnight]];
}
}
#if PLATFORM(DOM)
_datePicker._invokedByUserEvent = NO;
#endif
}
- (void)mouseUp:(CPEvent)anEvent
{
[_timerMonth invalidate];
_dragDate = nil;
_clickDate = nil;
_isMonthJustChanged = NO;
_indexDayTile = -1;
_eventDragged = nil;
}
// MARK: -
// MARK: Timer
- (void)_timerNextMonthEvent:(CPEvent)anEvent
{
if (_isMonthJustChanged)
{
_dragDate.setMonth(_date.getMonth() + 1);
[_delegate _displayNextMonth];
}
}
- (void)_timerPreviousMonthEvent:(CPEvent)anEvent
{
if (_isMonthJustChanged)
{
_dragDate.setMonth(_date.getMonth() - 1);
[_delegate _displayPreviousMonth];
}
}
// MARK: -
// MARK: Date methods
- (CPDate)_hoursMinutesSecondsFromDatePickerForDate:(CPDate)aDate
{
var dateValue = [_datePicker dateValue];
aDate.setHours(dateValue.getHours());
aDate.setMinutes(dateValue.getMinutes());
aDate.setSeconds(dateValue.getSeconds());
return aDate;
}
@end
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -69,7 +69,7 @@
aNewObject._controller = self;
aNewObject._key = aKey;
if (aValue !== nil)
if (aValue != nil)
[aNewObject setValue:aValue];
return aNewObject;
@@ -98,7 +98,7 @@
var iter = [[CPSet setWithArray:allKeys] objectEnumerator],
obj;
while ((obj = [iter nextObject]) !== nil)
while ((obj = [iter nextObject]) != nil)
if (![_excludedKeys containsObject:obj])
[array addObject:[self _newObjectWithKey:obj value:nil]];
+5 -2
View File
@@ -871,10 +871,13 @@ var CPDocumentUntitledCount = 0;
{
var theDelegate = context.delegate;
if (aDocument === self && shouldClose)
// Only close the document explicitly if there is NO delegate to handle the action.
// If a delegate exists (e.g., the CPWindow), it is responsible for performing the close
// upon receiving the callback below. Calling [self close] here would cause a double-close.
if (aDocument === self && shouldClose && theDelegate == nil)
[self close];
if (theDelegate != null)
if (theDelegate)
theDelegate.isa.objj_msgSend3(theDelegate, context.selector, aDocument, shouldClose, context.context);
}
+2 -2
View File
@@ -106,7 +106,7 @@ var CPSharedDocumentController = nil;
@param aType the type of the new document
@param shouldDisplay whether to display the document on screen
*/
- (void)openUntitledDocumentOfType:(CPString)aType display:(BOOL)shouldDisplay
- (CPDocument)openUntitledDocumentOfType:(CPString)aType display:(BOOL)shouldDisplay
{
var theDocument = [self makeUntitledDocumentOfType:aType error:nil];
@@ -297,7 +297,7 @@ var CPSharedDocumentController = nil;
var iter = [_documents objectEnumerator],
obj;
while ((obj = [iter nextObject]) !== nil)
while ((obj = [iter nextObject]) != nil)
{
if ([obj isDocumentEdited])
return YES;
+56 -2
View File
@@ -26,6 +26,7 @@
@import "CPPasteboard.j"
@import "CPView.j"
@import "CPWindow_Constants.j"
@import "CPViewAnimation.j"
@class CPWindow // This file is imported by CPWindow.j
@class _CPDOMDataTransferPasteboard
@@ -132,6 +133,10 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0,
unsigned _dragOperation;
CPTimer _draggingUpdateTimer;
// Animation State
CGPoint _pendingEndLocation;
CPDragOperation _pendingEndOperation;
}
/*
@@ -261,10 +266,19 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0,
{
var contentView = [scrollView contentView],
bounds = [contentView bounds],
insetBounds = CGRectInset(bounds, 30, 30),
eventLocation = [contentView convertPoint:_draggingLocation fromView:nil],
deltaX = 0,
deltaY = 0;
deltaY = 0,
insetSize = 30;
if ([contentView respondsToSelector:@selector(documentView)] &&
[[contentView documentView] respondsToSelector:@selector(rowHeight)])
{
// Adjust inset bounds based on CPTableView row height
insetSize = MAX(insetSize, [[contentView documentView] rowHeight]);
}
var insetBounds = CGRectInset(bounds, insetSize, insetSize);
if (!CGRectContainsPoint(insetBounds, eventLocation))
{
@@ -316,6 +330,46 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0,
[_draggingUpdateTimer invalidate];
_draggingUpdateTimer = nil;
// Check if we should slide back (drag failed + slideBack requested)
if (![CPPlatform supportsDragAndDrop] && _shouldSlideBack && anOperation === CPDragOperationNone)
{
// Store state to finalize drag after animation completes
_pendingEndLocation = aLocation;
_pendingEndOperation = anOperation;
var currentFrame = [_draggedWindow frame],
targetFrame = CGRectMake(_startDragLocation.x, _startDragLocation.y, currentFrame.size.width, currentFrame.size.height);
// We use CPViewAnimation. Even though _draggedWindow is a CPWindow,
// CPViewAnimation supports targets that respond to setFrame: (like NSViewAnimation does for NSWindow).
var animation = [[CPViewAnimation alloc] initWithViewAnimations:[
[CPDictionary dictionaryWithObjects:[_draggedWindow, currentFrame, targetFrame]
forKeys:[CPViewAnimationTargetKey, CPViewAnimationStartFrameKey, CPViewAnimationEndFrameKey]]
]];
[animation setAnimationCurve:CPAnimationEaseOut];
[animation setDuration:0.25];
[animation setDelegate:self];
[animation startAnimation];
return;
}
[self _performFinalCleanupWithLocation:aLocation operation:anOperation];
}
- (void)animationDidEnd:(CPAnimation)anAnimation
{
[self _performFinalCleanupWithLocation:_pendingEndLocation operation:_pendingEndOperation];
}
- (void)animationDidStop:(CPAnimation)anAnimation
{
[self _performFinalCleanupWithLocation:_pendingEndLocation operation:_pendingEndOperation];
}
- (void)_performFinalCleanupWithLocation:(CGPoint)aLocation operation:(CPDragOperation)anOperation
{
[_draggedView removeFromSuperview];
if (![CPPlatform supportsDragAndDrop])
+32 -4
View File
@@ -70,6 +70,7 @@ var _CPEventPeriodicEventPeriod = 0,
BOOL _isARepeat;
unsigned _keyCode;
DOMEvent _DOMEvent;
BOOL _isActionKey;
int _data1;
int _data2;
short _subtype;
@@ -110,17 +111,28 @@ var _CPEventPeriodicEventPeriod = 0,
@param unmodCharacters the string of keys pressed without the presence of any modifiers other than Shift
@param repeatKey \c YES if this is caused by the system repeat as opposed to the user pressing the key again
@param code a number associated with the keyboard key of this event
@param isAnActionKey a BOOL indicating whether this key is an action key (e.g. a function key)
@throws CPInternalInconsistencyException if \c anEventType is not a CPKeyDown,
CPKeyUp or CPFlagsChanged
@return the keyboard event
*/
+ (CPEvent)keyEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(unsigned int)modifierFlags
timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)repeatKey keyCode:(unsigned short)code
characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)repeatKey keyCode:(unsigned short)code isActionKey:(BOOL)isAnActionKey
{
return [[self alloc] _initKeyEventWithType:anEventType location:aPoint modifierFlags:modifierFlags
timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext
characters:characters charactersIgnoringModifiers:unmodCharacters isARepeat:repeatKey keyCode:code];
characters:characters charactersIgnoringModifiers:unmodCharacters isARepeat:repeatKey keyCode:code isActionKey:isAnActionKey];
}
// for backwards compatibility only
+ (CPEvent)keyEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(unsigned int)modifierFlags
timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)repeatKey keyCode:(unsigned short)code
{
return [[self alloc] _initKeyEventWithType:anEventType location:aPoint modifierFlags:modifierFlags
timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext
characters:characters charactersIgnoringModifiers:unmodCharacters isARepeat:repeatKey keyCode:code isActionKey:NO];
}
/*!
@@ -252,7 +264,7 @@ var _CPEventPeriodicEventPeriod = 0,
/* @ignore */
- (id)_initKeyEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(unsigned int)modifierFlags
timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)isARepeat keyCode:(unsigned short)code
characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)isARepeat keyCode:(unsigned short)code isActionKey:(BOOL)isAnActionKey
{
if (self = [self _initWithType:anEventType])
{
@@ -264,6 +276,7 @@ var _CPEventPeriodicEventPeriod = 0,
_charactersIgnoringModifiers = unmodCharacters;
_isARepeat = isARepeat;
_keyCode = code;
_isActionKey = isAnActionKey;
_windowNumber = aWindowNumber;
}
@@ -571,6 +584,21 @@ var _CPEventPeriodicEventPeriod = 0,
return !firstResponderIsText;
}
- (BOOL)_isActionOrCommandEvent
{
// This method is now platform-agnostic. It checks for abstract properties
// of the event, including the _isActionKey flag that was set at creation time.
return (
// Is it a command shortcut?
(_modifierFlags & (CPCommandKeyMask | CPControlKeyMask)) ||
// Is it a key that doesn't produce a character?
([_characters length] === 0) ||
// Was it identified as an action key by the platform-specific layer?
_isActionKey
);
}
/*!
Return YES if this event is a part of processing a browser controlled cut or paste event
where the browser will go ahead and do the work of cutting or pasting within the input
@@ -608,7 +636,7 @@ var _CPEventPeriodicEventPeriod = 0,
*/
+ (void)stopPeriodicEvents
{
if (_CPEventPeriodicEventTimer === nil)
if (_CPEventPeriodicEventTimer == nil)
return;
window.clearTimeout(_CPEventPeriodicEventTimer);
-85
View File
@@ -1,85 +0,0 @@
/*
* CPFlashMovie.j
* AppKit
*
* Created by Francisco Tolmasky.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/CPObject.j>
/*!
@ingroup appkit
@class CPFlashMovie
CPFlashMovie is used to represent a Flash movie in the Cappuccino framework.
*/
@implementation CPFlashMovie : CPObject
{
CPString _filename;
}
/*!
Creates a new Flash movie with the swf at \c aFileName.
@param aFilename the swf to load
@return the initialized CPFlashMovie
*/
+ (id)flashMovieWithFile:(CPString)aFilename
{
return [[self alloc] initWithFile:aFilename];
}
/*!
Initializes the Flash movie.
@param aFilename the swf to load
@return the initialized CPFlashMovie
*/
- (id)initWithFile:(CPString)aFilename
{
self = [super init];
if (self)
_filename = aFilename;
return self;
}
- (CPString)filename
{
return _filename;
}
@end
var CPFlashMovieFilenameKey = "CPFlashMovieFilenameKey";
@implementation CPFlashMovie (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
_filename = [aCoder decodeObjectForKey:CPFlashMovieFilenameKey];
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:_filename forKey:CPFlashMovieFilenameKey];
}
@end
-215
View File
@@ -1,215 +0,0 @@
/*
* CPFlashView.j
* AppKit
*
* Created by Francisco Tolmasky.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPFlashMovie.j"
@import "CPView.j"
var IEFlashCLSID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
/*!
@ingroup appkit
*/
@implementation CPFlashView : CPView
{
CPFlashMovie _flashMovie;
CPDictionary _params;
CPDictionary _paramElements;
#if PLATFORM(DOM)
DOMElement _DOMParamElement;
DOMElement _DOMObjectElement;
#endif
}
- (id)initWithFrame:(CGRect)aFrame
{
CPLog.warn("CPFlashView is deprecated and it will be removed in version 1.1.");
self = [super initWithFrame:aFrame];
if (self)
{
#if PLATFORM(DOM)
if (!CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
{
_DOMObjectElement = document.createElement(@"object");
_DOMObjectElement.id = [self elementID];
_DOMObjectElement.width = @"100%";
_DOMObjectElement.height = @"100%";
_DOMObjectElement.style.top = @"0px";
_DOMObjectElement.style.left = @"0px";
_DOMObjectElement.type = @"application/x-shockwave-flash";
_DOMParamElement = document.createElement(@"param");
_DOMParamElement.name = @"movie";
_DOMObjectElement.appendChild(_DOMParamElement);
_DOMElement.appendChild(_DOMObjectElement);
}
else
[self _rebuildIEObjects];
#endif
}
return self;
}
- (void)setFlashMovie:(CPFlashMovie)aFlashMovie
{
if (_flashMovie == aFlashMovie)
return;
_flashMovie = aFlashMovie;
#if PLATFORM(DOM)
if (!CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
{
_DOMParamElement.value = [aFlashMovie filename];
_DOMObjectElement.data = [aFlashMovie filename];
}
else
[self _rebuildIEObjects];
#endif
}
- (CPFlashMovie)flashMovie
{
return _flashMovie;
}
- (void)setFlashVars:(CPDictionary)aDictionary
{
var varString = @"",
enumerator = [aDictionary keyEnumerator],
key;
if (key = [enumerator nextObject])
varString = [varString stringByAppendingFormat:@"%@=%@", key, [aDictionary objectForKey:key]];
while (key = [enumerator nextObject])
varString = [varString stringByAppendingFormat:@"&%@=%@", key, [aDictionary objectForKey:key]];
if (!_params)
_params = @{};
[_params setObject:varString forKey:@"flashvars"];
[self setParameters:_params];
}
- (CPDictionary)flashVars
{
return [_params objectForKey:@"flashvars"];
}
- (void)setParameters:(CPDictionary)aDictionary
{
#if PLATFORM(DOM)
if (_paramElements && !CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
{
var elements = [_paramElements allValues],
count = [elements count];
for (var i = 0; i < count; i++)
_DOMObjectElement.removeChild([elements objectAtIndex:i]);
}
#endif
if (!_params)
_params = aDictionary;
else
[_params addEntriesFromDictionary:aDictionary];
#if PLATFORM(DOM)
if (!CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
{
_paramElements = @{};
var enumerator = [_params keyEnumerator],
key;
while (_DOMObjectElement && (key = [enumerator nextObject]) !== nil)
{
var param = document.createElement(@"param");
param.name = key;
param.value = [_params objectForKey:key];
_DOMObjectElement.appendChild(param);
[_paramElements setObject:param forKey:key];
}
}
else
[self _rebuildIEObjects];
#endif
}
- (CPDictionary)parameters
{
return _params;
}
#if PLATFORM(DOM)
- (void)_rebuildIEObjects
{
_DOMElement.innerHTML = @"";
if (![_flashMovie filename])
return;
var paramString = [CPString stringWithFormat:@"<param name='movie' value='%@' />", [_flashMovie filename]],
paramEnumerator = [_params keyEnumerator],
key;
while ((key = [paramEnumerator nextObject]) !== nil)
paramString = [paramString stringByAppendingFormat:@"<param name='%@' value='%@' />", key, [_params objectForKey:key]];
_DOMObjectElement = document.createElement(@"object");
_DOMElement.appendChild(_DOMObjectElement);
_DOMObjectElement.outerHTML = [CPString stringWithFormat:@"<object id=%@ classid=%@ width=%@ height=%@>%@</object>", [self elementID], IEFlashCLSID, CGRectGetWidth([self bounds]), CGRectGetHeight([self bounds]), paramString];
}
#endif
- (CPString)elementID
{
return @"CPFV_" + [self UID];
}
- (void)mouseMoved:(CPEvent)sommit
{
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
}
- (void)mouseDragged:(CPEvent)anEvent
{
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
}
- (void)mouseDown:(CPEvent)anEvent
{
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
}
- (void)mouseUp:(CPEvent)anEvent
{
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
}
@end
+131 -11
View File
@@ -25,6 +25,8 @@
@import "CPView.j"
@import "CPFontDescriptor.j"
@import "_CPObject+Theme.j"
@import "CPControl.j"
CPFontDefaultSystemFontFace = @"Arial, sans-serif";
CPFontDefaultSystemFontSize = 12;
@@ -38,12 +40,15 @@ CPFontCurrentSystemSize = -1;
// For internal use only by this class and subclasses
_CPFontSystemFacePlaceholder = "_CPFontSystemFacePlaceholder";
var _CPFontCache = {},
_CPSystemFontCache = {},
_CPFontSystemFontFace = CPFontDefaultSystemFontFace,
_CPFontSystemFontSize = 12,
_CPFontFallbackFaces = CPFontDefaultSystemFontFace.split(", "),
_CPFontStripRegExp = new RegExp("(^\\s*[\"']?|[\"']?\\s*$)", "g");
var _CPFontCache = {},
_CPSystemFontCache = {},
_CPFontSystemFontFace = CPFontDefaultSystemFontFace,
_CPFontSystemFontSize = CPFontDefaultSystemFontSize,
_CPFontSystemFontSizeSmall = CPFontDefaultSystemFontSize - 1,
_CPFontSystemFontSizeMini = CPFontDefaultSystemFontSize - 2,
_CPFontFallbackFaces = CPFontDefaultSystemFontFace.split(", "),
_CPFontStripRegExp = new RegExp("(^\\s*[\"']?|[\"']?\\s*$)", "g"),
_CPFontSystemFontFaceSpecified = NO;
#define _CPRealFontSize(aSize) (aSize <= 0 ? _CPFontSystemFontSize : aSize)
@@ -109,7 +114,7 @@ following:
<string>Asap</string>
@endcode
*/
@implementation CPFont : CPObject
@implementation CPFont : CPObject <CPTheme>
{
CPString _name;
float _size;
@@ -123,6 +128,22 @@ following:
CPString _cssString;
}
+ (CPString)defaultThemeClass
{
return @"font";
}
+ (CPDictionary)themeAttributes
{
return @{
@"system-font-face": [CPNull null],
@"system-font-style": [CPNull null],
@"system-font-size-regular": [CPNull null],
@"system-font-size-small": [CPNull null],
@"system-font-size-mini": [CPNull null]
};
}
+ (void)initialize
{
if (self !== [CPFont class])
@@ -134,7 +155,10 @@ following:
systemFontFace = [[CPBundle bundleForClass:[CPView class]] objectForInfoDictionaryKey:@"CPSystemFontFace"];
if (systemFontFace)
{
_CPFontSystemFontFace = _CPFontNormalizedNames(systemFontFace);
_CPFontSystemFontFaceSpecified = YES;
}
var systemFontSize = [[CPBundle mainBundle] objectForInfoDictionaryKey:@"CPSystemFontSize"];
@@ -142,7 +166,62 @@ following:
systemFontSize = [[CPBundle bundleForClass:[CPView class]] objectForInfoDictionaryKey:@"CPSystemFontSize"];
if (systemFontSize)
{
_CPFontSystemFontSize = systemFontSize;
_CPFontSystemFontFaceSpecified = YES;
}
}
+ (void)initializeSystemFontFromTheme:(CPTheme)aTheme
{
// If something was specified via +initialize (from an Info.plist file), don't do anything
if (_CPFontSystemFontFaceSpecified)
return;
// Reset all system font caches
_CPSystemFontCache = {};
// Now, try to get information from the theme
var systemFontFace = [aTheme valueForAttributeWithName:@"system-font-face" forClass:[CPFont class]];
if (systemFontFace)
{
[self _invalidateSystemFontCache];
_CPFontSystemFontFace = _CPFontNormalizedNames(systemFontFace);
}
var systemFontSize = [aTheme valueForAttributeWithName:@"system-font-size-regular" forClass:[CPFont class]];
if (systemFontSize)
{
[self _invalidateSystemFontCache];
_CPFontSystemFontSize = systemFontSize;
}
systemFontSize = [aTheme valueForAttributeWithName:@"system-font-size-small" forClass:[CPFont class]];
if (systemFontSize)
{
[self _invalidateSystemFontCache];
_CPFontSystemFontSizeSmall = systemFontSize;
}
systemFontSize = [aTheme valueForAttributeWithName:@"system-font-size-mini" forClass:[CPFont class]];
if (systemFontSize)
{
[self _invalidateSystemFontCache];
_CPFontSystemFontSizeMini = systemFontSize;
}
// Is there something to add to the global syle definition ?
var systemFontStyle = [aTheme valueForAttributeWithName:@"system-font-style" forClass:[CPFont class]];
if (systemFontStyle)
{
// Yes, so install it in the DOM Style element
document.getElementsByTagName("STYLE")[0].innerHTML += "\n" + [aTheme setCSSResourcesPath:systemFontStyle];
}
}
/*!
@@ -177,14 +256,13 @@ following:
+ (CPFont)systemFontForControlSize:(CPControlSize)aSize
{
// TODO These sizes should be themable or made less arbitrary in some other way.
switch (aSize)
{
case CPSmallControlSize:
return [self systemFontOfSize:_CPFontSystemFontSize - 1];
return [self systemFontOfSize:_CPFontSystemFontSizeSmall];
case CPMiniControlSize:
return [self systemFontOfSize:_CPFontSystemFontSize - 2];
return [self systemFontOfSize:_CPFontSystemFontSizeMini];
case CPRegularControlSize:
default:
@@ -315,6 +393,10 @@ following:
_isItalic = isItalic;
_isSystem = isSystem;
_theme = [CPTheme defaultTheme];
_themeState = CPThemeStateNormal;
[self _loadThemeAttributes];
if (isSystem)
{
_name = aName;
@@ -382,6 +464,22 @@ following:
return _CPRealFontSize(_size);
}
/*!
Returns the font size. Cocoa/AppKit compatibility alias for -size.
*/
- (float)pointSize
{
return [self size];
}
/*!
Returns the font name. Cocoa/AppKit compatibility alias for -familyName.
*/
- (CPString)fontName
{
return [self familyName];
}
/*!
Returns the font as a CSS string
*/
@@ -432,6 +530,22 @@ following:
_lineHeight = [metrics objectForKey:@"lineHeight"];
}
- (CPControlSize)controlSizeCorrespondingToFontSize
{
switch (_size)
{
case _CPFontSystemFontSizeSmall:
return CPSmallControlSize;
case _CPFontSystemFontSizeMini:
return CPMiniControlSize;
default:
// If we can't find a corresponding size, return regular control size
return CPRegularControlSize;
}
}
@end
@implementation CPFont(DescriptorAdditions)
@@ -492,7 +606,11 @@ var CPFontNameKey = @"CPFontNameKey",
isItalic = [aCoder decodeBoolForKey:CPFontIsItalicKey],
isSystem = [aCoder decodeBoolForKey:CPFontIsSystemKey];
return [self _initWithName:fontName size:size bold:isBold italic:isItalic system:isSystem];
self = [self _initWithName:fontName size:size bold:isBold italic:isItalic system:isSystem];
[self _decodeThemeObjectsWithCoder:aCoder];
return self;
}
/*!
@@ -506,6 +624,8 @@ var CPFontNameKey = @"CPFontNameKey",
[aCoder encodeBool:_isBold forKey:CPFontIsBoldKey];
[aCoder encodeBool:_isItalic forKey:CPFontIsItalicKey];
[aCoder encodeBool:_isSystem forKey:CPFontIsSystemKey];
[self _encodeThemeObjectsWithCoder:aCoder];
}
@end
+10 -31
View File
@@ -29,6 +29,8 @@
@global CPApp
@class CPFontPanel
@global document
CPItalicFontMask = 1 << 0;
CPBoldFontMask = 1 << 1;
CPUnboldFontMask = 1 << 2;
@@ -190,35 +192,6 @@ CPRemoveTraitFontAction = 7;
return ([aFont isBold] ? CPBoldFontMask : 0) | ([aFont isItalic] ? CPItalicFontMask : 0);
}
- (CPFont)convertFont:(CPFont)aFont
{
if (!_activeChange)
return aFont;
var addTraits = [_activeChange valueForKey:@"addTraits"];
if (addTraits)
aFont = [self convertFont:aFont toHaveTrait:addTraits];
return aFont;
}
- (CPFont)convertFont:(CPFont)aFont toHaveTrait:(CPFontTraitMask)addTraits
{
if (!aFont)
return nil;
var shouldBeBold = ([aFont isBold] || (addTraits & CPBoldFontMask)) && !(addTraits & CPUnboldFontMask),
shouldBeItalic = ([aFont isItalic] || (addTraits & CPItalicFontMask)) && !(addTraits & CPUnitalicFontMask),
shouldBeSize = [aFont size];
// XXX On the current platform there will always be a bold/italic version of each font, but still leave
// || aFont in here for future platforms.
aFont = [CPFont _fontWithName:[aFont familyName] size:shouldBeSize bold:shouldBeBold italic:shouldBeItalic] || aFont;
return aFont;
}
- (CPFont)convertFont:(CPFont)aFont toFace:(CPString)aTypeface
{
if (!aFont)
@@ -235,8 +208,12 @@ CPRemoveTraitFontAction = 7;
- (@action)addFontTrait:(id)sender
{
var tag = [sender tag];
_activeChange = tag === nil ? @{} : @{ @"addTraits": tag };
var tag = sender;
if ([sender respondsToSelector:@selector(tag)])
tag = [sender tag];
_activeChange = tag == nil ? @{} : @{ @"addTraits": tag };
_fontAction = CPAddTraitFontAction;
[self sendAction];
@@ -386,6 +363,7 @@ CPRemoveTraitFontAction = 7;
- (CPFont)convertFont:(CPFont)aFont
{
var newFont = nil;
switch (_fontAction)
{
case CPNoFontChangeAction:
@@ -398,6 +376,7 @@ CPRemoveTraitFontAction = 7;
case CPAddTraitFontAction:
newFont = aFont;
if (!_activeChange)
break;
+1 -1
View File
@@ -92,7 +92,7 @@ var CPGraphicsContextCurrent = nil,
@param aGraphicsPort the graphics port to initialize with
@return the initialized context
*/
- (id)initWithGraphicsPort:(CPContext)aGraphicsPort
- (id)initWithGraphicsPort:(CGContext)aGraphicsPort
{
self = [super init];
+244 -8
View File
@@ -26,10 +26,15 @@
@import <Foundation/CPRunLoop.j>
@import <Foundation/CPString.j>
@import <Foundation/CPData.j>
@import <Foundation/CPKeyedArchiver.j>
@import <Foundation/CPKeyedUnarchiver.j>
@import "CGGeometry.j"
@import "CPCompatibility.j"
@import "CPGraphicsContext.j"
@class CPColor
@global document
@protocol CPImageDelegate <CPObject>
@@ -85,9 +90,7 @@ function CPImageInBundle()
if (typeof(arguments[1]) === "number")
{
if (arguments[1] !== nil && arguments[1] !== undefined)
size = CGSizeMake(arguments[1], arguments[2]);
size = CGSizeMake(arguments[1], arguments[2]);
bundle = arguments[3];
}
else if (typeof(arguments[1]) === "object")
@@ -161,7 +164,7 @@ function CPAppKitImage(aFilename, aSize)
- (id)initByReferencingFile:(CPString)aFilename size:(CGSize)aSize
{
// Quietly return nil like in Cocoa, rather than crashing later.
if (aFilename === undefined || aFilename === nil)
if (aFilename == nil)
return nil;
self = [super init];
@@ -446,6 +449,11 @@ function CPAppKitImage(aFilename, aSize)
return NO;
}
- (BOOL)isMaterialIconImage
{
return NO;
}
- (CPString)description
{
var filename = [self filename],
@@ -509,8 +517,8 @@ function CPAppKitImage(aFilename, aSize)
@end
#pragma mark -
#pragma mark CSS Theming
// MARK: -
// MARK: CSS Theming
// The code below adds support for CSS theming with 100% compatibility with current theming system.
// The idea is to extend CPImage (and CPColor) with CSS components and adapt low level UI components to
@@ -564,6 +572,7 @@ function CPAppKitImage(aFilename, aSize)
CPDictionary _cssDictionary @accessors(property=cssDictionary);
CPDictionary _cssBeforeDictionary @accessors(property=cssBeforeDictionary);
CPDictionary _cssAfterDictionary @accessors(property=cssAfterDictionary);
CGSize _displaySize;
}
+ (CPImage)imageWithCSSDictionary:(CPDictionary)aDictionary size:(CGSize)aSize
@@ -582,6 +591,16 @@ function CPAppKitImage(aFilename, aSize)
return [[CPImage alloc] initWithCSSDictionary:@{} beforeDictionary:nil afterDictionary:nil size:aSize];
}
+ (CPImage)imageWithMaterialIconNamed:(CPString)iconName size:(CGSize)size
{
return [_CPMaterialIconImage imageWithIconNamed:iconName size:size];
}
+ (CPImage)imageWithMaterialIconNamed:(CPString)iconName size:(CGSize)size color:(CPColor)color
{
return [_CPMaterialIconImage imageWithIconNamed:iconName size:size color:color];
}
- (id)initWithCSSDictionary:(CPDictionary)aDictionary beforeDictionary:(CPDictionary)beforeDictionary afterDictionary:(CPDictionary)afterDictionary size:(CGSize)aSize
{
self = [super init];
@@ -594,6 +613,7 @@ function CPAppKitImage(aFilename, aSize)
_cssDictionary = aDictionary;
_cssBeforeDictionary = beforeDictionary;
_cssAfterDictionary = afterDictionary;
_displaySize = CGSizeMakeCopy(aSize);
}
return self;
@@ -685,7 +705,7 @@ function CPAppKitImage(aFilename, aSize)
aStyleNode.replaceChild(styleDescription, aStyleNode.firstChild);
}
[aView setDOMClassName:@"CP"+[aView UID]];
aDOMElement.className = @"CP"+[aView UID];
}
else
{
@@ -707,13 +727,18 @@ function CPAppKitImage(aFilename, aSize)
#endif
}
- (BOOL)_shouldBeResized
{
return NO;
}
@end
var CPImageCSSDictionaryKey = @"CPImageCSSDictionaryKey",
CPImageCSSBeforeDictionaryKey = @"CPImageCSSBeforeDictionaryKey",
CPImageCSSAfterDictionaryKey = @"CPImageCSSAfterDictionaryKey";
#pragma mark -
// MARK: -
@implementation CPImage (CPCoding)
@@ -750,6 +775,206 @@ var CPImageCSSDictionaryKey = @"CPImageCSSDictionaryKey",
@end
// MARK: -
// MARK: Drawing
@implementation CPImage (Drawing)
- (void)drawAtPoint:(CGPoint)point fromRect:(CPRect)fromRect operation:(CGBlendMode)op fraction:(float)delta
{
if (_loadStatus !== CPImageLoadStatusCompleted)
return;
var context = [CPGraphicsContext currentContext].graphicsPort;
if (!context)
return;
CGContextSaveGState(context);
CGContextSetBlendMode(context, op);
CGContextSetAlpha(context, delta);
context.drawImage(
_image,
fromRect.origin.x,
fromRect.origin.y,
fromRect.size.width,
fromRect.size.height,
point.x,
point.y,
fromRect.size.width,
fromRect.size.height
);
CGContextRestoreGState(context);
}
@end
// MARK: -
@implementation _CPMaterialIconImage : CPImage
{
CPMutableDictionary _cachedColorVersions;
CPColor _cachedInvertedColor;
}
+ (_CPMaterialIconImage)imageWithIconNamed:(CPString)iconName size:(CGSize)size
{
return [[_CPMaterialIconImage alloc] initWithIconName:iconName size:size];
}
+ (_CPMaterialIconImage)imageWithIconNamed:(CPString)iconName size:(CGSize)size color:(CPColor)color
{
return [[_CPMaterialIconImage alloc] initWithIconName:iconName size:size color:color];
}
+ (_CPMaterialIconImage)imageWithIconNamed:(CPString)iconName size:(CGSize)size color:(CPColor)color additionalCSSDictionary:(CPDictionary)additionalCSSDictionary
{
return [[_CPMaterialIconImage alloc] initWithIconName:iconName size:size color:color additionalCSSDictionary:additionalCSSDictionary];
}
- (CPDictionary)_baseMaterialIconCSSDictionaryForIconName:(CPString)iconName size:(CGSize)size
{
return @{
@"width": size.width + @"px",
@"height": size.height + @"px",
@"top": @"0px",
@"left": @"0px",
@"content": @"'" + iconName + @"'",
@"position": @"absolute",
@"z-index": @"300",
@"font-family": @"'Material Icons'",
@"font-weight": @"normal",
@"font-style": @"normal",
@"font-size": MIN(size.width, size.height) + @"px",
@"display": @"inline-block",
@"line-height": @"1",
@"text-transform": @"none",
@"letter-spacing": @"normal",
@"word-wrap": @"normal",
@"white-space": @"nowrap",
@"direction": @"ltr",
@"-webkit-font-smoothing": @"antialiased",
@"text-rendering": @"optimizeLegibility",
@"-moz-osx-font-smoothing": @"grayscale",
@"font-feature-settings": @"'liga'"
};
}
- (_CPMaterialIconImage)initWithIconName:(CPString)iconName size:(CGSize)size
{
return [super initWithCSSDictionary:@{}
beforeDictionary:@{}
afterDictionary:[self _baseMaterialIconCSSDictionaryForIconName:iconName size:size]
size:size];
}
- (_CPMaterialIconImage)initWithIconName:(CPString)iconName size:(CGSize)size color:(CPColor)color
{
var materialIconCSSDictionary = [self _baseMaterialIconCSSDictionaryForIconName:iconName size:size];
[materialIconCSSDictionary setObject:[color cssString] forKey:@"color"];
return [super initWithCSSDictionary:@{}
beforeDictionary:@{}
afterDictionary:materialIconCSSDictionary
size:size];
}
- (void)addRotationEffectWithAngle:(float)angle
{
[self addCSSDictionary:@{
@"transform": @"rotate("+angle+"deg)",
@"transition": @"transform 0.35s ease"
}];
}
- (void)addCSSDictionary:(CPDictionary)additionalCSSDictionary
{
[_cssAfterDictionary addEntriesFromDictionary:additionalCSSDictionary];
}
- (void)setSize:(CGSize)aSize
{
[self _setDisplaySize:aSize];
[super setSize:aSize];
}
- (void)_setDisplaySize:(CGSize)aSize
{
if (CGSizeEqualToSize(_displaySize, aSize))
return;
_displaySize = CGSizeMakeCopy(aSize);
[_cssAfterDictionary setObject:(aSize.width + @"px") forKey:@"width"];
[_cssAfterDictionary setObject:(aSize.height + @"px") forKey:@"height"];
[_cssAfterDictionary setObject:(MIN(aSize.width, aSize.height) + @"px") forKey:@"font-size"];
}
- (BOOL)_shouldBeResized
{
return YES;
}
- (BOOL)isMaterialIconImage
{
return YES;
}
- (_CPMaterialIconImage)invertedImage
{
if (!_cachedInvertedColor)
{
var sourceCSSColor = [_cssAfterDictionary objectForKey:@"color"] || @"rgba(0,0,0,1)",
sourceColor = [CPColor colorWithCSSString:sourceCSSColor];
_cachedInvertedColor = [CPColor colorWithRed:(1-[sourceColor redComponent])
green:(1-[sourceColor greenComponent])
blue:(1-[sourceColor blueComponent])
alpha:[sourceColor alphaComponent]];
}
return [self imageVersionWithColor:_cachedInvertedColor];
}
- (_CPMaterialIconImage)imageVersionWithColor:(CPColor)aColor
{
// We can't just set the color in the cssAfterDictionary as this would not be noticed as a new image,
// so -setImage won't do anything, so no visual refresh won't occur.
// The trick here is to keep in cache a clone of this image for each needed color.
var colorCSSString = [aColor cssString];
if (!_cachedColorVersions)
_cachedColorVersions = @{};
var cachedColorVersion = [_cachedColorVersions objectForKey:colorCSSString];
if (!cachedColorVersion)
{
cachedColorVersion = [self duplicate];
[cachedColorVersion _setCSSColor:colorCSSString];
[_cachedColorVersions setObject:cachedColorVersion forKey:colorCSSString];
}
return cachedColorVersion;
}
- (void)_setCSSColor:(CPString)aCSSColor
{
[_cssAfterDictionary setObject:aCSSColor forKey:@"color"];
}
@end
// MARK: -
@implementation CPThreePartImage : CPObject
{
CPArray _imageSlices;
@@ -890,3 +1115,14 @@ var CPNinePartImageImageSlicesKey = @"CPNinePartImageImageSlicesKey";
}
@end
// MARK: -
@implementation CPImage (Duplication)
- (CPImage)duplicate
{
return [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:self]];
}
@end
+24 -2
View File
@@ -29,6 +29,8 @@
@global CPImagesPboardType
@global appkit_tag_dom_elements
@global document
@typedef CPImageAlignment
CPImageAlignCenter = 0;
CPImageAlignTop = 1;
@@ -99,8 +101,8 @@ var CPImageViewEmptyPlaceholderImage = nil;
{
#if PLATFORM(DOM)
var image = [self objectValue],
isCSSBasedImage = [image isCSSBased],
isIMGImageElement = _DOMImageElement && (_DOMImageElement.nodeName == "IMG");
isCSSBasedImage = [image isCSSBased],
isIMGImageElement = _DOMImageElement && (_DOMImageElement.nodeName == "IMG");
// First, check if we need to destroy a current DOM image element. This is the case if :
// - we have one but not the right one (that is a DIV but needing an IMG, and vice versa)
@@ -235,6 +237,8 @@ var CPImageViewEmptyPlaceholderImage = nil;
if (_hasShadow)
{
[self setClipsToBounds:NO];
_shadowView = [[CPShadowView alloc] initWithFrame:[self bounds]];
[self addSubview:_shadowView];
@@ -444,6 +448,24 @@ var CPImageViewEmptyPlaceholderImage = nil;
#endif
}
#if PLATFORM(DOM)
if ([image isCSSBased] && [image _shouldBeResized])
{
[image _setDisplaySize:CGSizeMake(ROUND(width), ROUND(height))];
_cssStyleNode = [image applyCSSImageForView:self
onDOMElement:_DOMImageElement
styleNode:_cssStyleNode
previousState:@ref(_cssStylePreviousState)];
}
if ([image isCSSBased])
{
_DOMImageElement.style.width = _DOMImageElement.width + 'px';
_DOMImageElement.style.height = _DOMImageElement.height + 'px';
}
#endif
_imageRect = CGRectMake(x, y, width, height);
if (_hasShadow)
+1
View File
@@ -30,6 +30,7 @@ CPStandardKeyBindings = {
@"@.": @"cancelOperation:",
@"@a": @"selectAll:",
@"@~$v": @"pasteAsPlainText:",
@"^a": @"moveToBeginningOfParagraph:",
@"^$a": @"moveToBeginningOfParagraphAndModifySelection:",
@"^b": @"moveBackward:",
+8 -4
View File
@@ -208,7 +208,11 @@ var CPBindingOperationAnd = 0,
options = [_info objectForKey:CPOptionsKey],
newValue = [destination valueForKeyPath:keyPath];
if (CPIsControllerMarker(newValue))
// give nil values the chance to be transformed to true via CPNegateBoolean (issue #1986)
if ((newValue == nil || CPIsControllerMarker(newValue)) && [options objectForKey:CPValueTransformerNameBindingOption] === CPNegateBooleanTransformerName)
[self setValue:[self transformValue:NO withOptions:options] forBinding:theBinding];
else if (CPIsControllerMarker(newValue))
{
[self raiseIfNotApplicable:newValue forKeyPath:keyPath options:options];
@@ -293,7 +297,7 @@ var CPBindingOperationAnd = 0,
// If the value is nil AND the source doesn't respond to setPlaceholderString: then
// we set the value to the placeholder. Otherwise, we do not want to short cut the process
// of setting the placeholder that is based on the fact that the value is nil.
if ((aValue === undefined || aValue === nil || aValue === [CPNull null])
if ((aValue == nil || aValue === [CPNull null])
&& ![_source respondsToSelector:@selector(setPlaceholderString:)])
aValue = [options objectForKey:CPNullPlaceholderBindingOption] || nil;
@@ -653,7 +657,7 @@ var CPBindingOperationAnd = 0,
keyPath = [info objectForKey:CPObservedKeyPathKey],
value = [object valueForKeyPath:keyPath];
if (value === nil || value === undefined)
if (value == nil)
{
[_source setEnabled:NO];
return;
@@ -796,7 +800,7 @@ var CPBindingOperationAnd = 0,
else
value = [theBinding transformValue:value withOptions:options];
if (value === nil || value === undefined)
if (value == nil)
value = @"";
result.value = result.value.replace("%{" + _patternPlaceholder + count + "}@", [value description]);
+27 -28
View File
@@ -22,15 +22,10 @@
@import "CPControl.j"
@import "CPWindow_Constants.j"
@import "CPSlider.j"
@global CPApp
@typedef CPTickMarkPosition
CPTickMarkBelow = 0;
CPTickMarkAbove = 1;
CPTickMarkLeft = CPTickMarkAbove;
CPTickMarkRight = CPTickMarkBelow;
@typedef CPLevelIndicatorStyle
CPRelevancyLevelIndicatorStyle = 0;
CPContinuousCapacityLevelIndicatorStyle = 1;
@@ -93,43 +88,61 @@ CPRatingLevelIndicatorStyle = 3;
- (void)layoutSubviews
{
// 1. Calculate the Theme State
// We explicitly check the window style mask to see if we are in a HUD.
// This allows us to pass CPThemeStateHUD to the theme system, even if the control
// itself isn't explicitly set to HUD, inheriting the style from the window.
var themeState = [self themeState];
if ([[self window] styleMask] & CPHUDBackgroundWindowMask)
themeState = themeState.and(CPThemeStateHUD);
// 2. Layout the Bezel
var bezelView = [self layoutEphemeralSubviewNamed:"bezel"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
// TODO Make themable.
[bezelView setBackgroundColor:[self valueForThemeAttribute:@"bezel-color"]];
[bezelView setBackgroundColor:[self valueForThemeAttribute:@"bezel-color" inState:themeState]];
var segmentCount = _maxValue - _minValue;
if (segmentCount <= 0)
return;
var filledColor = [self valueForThemeAttribute:@"color-normal"],
// 3. Determine the Color based on Value and Thresholds
// We pass 'themeState' here. If it contains CPThemeStateHUD, the ThemeDescriptor
// will return the monochrome color for normal/warning/critical.
// If not, it returns Green/Yellow/Red.
var filledColor = [self valueForThemeAttribute:@"color-normal" inState:themeState],
value = [self doubleValue];
if (_warningValue < _criticalValue)
{
// Standard ascending scale (e.g. Volume)
if (value >= _criticalValue)
filledColor = [self valueForThemeAttribute:@"color-critical"];
filledColor = [self valueForThemeAttribute:@"color-critical" inState:themeState];
else if (value >= _warningValue)
filledColor = [self valueForThemeAttribute:@"color-warning"];
filledColor = [self valueForThemeAttribute:@"color-warning" inState:themeState];
}
else
{
// Descending scale (e.g. Battery Life)
if (value <= _criticalValue)
filledColor = [self valueForThemeAttribute:@"color-critical"];
filledColor = [self valueForThemeAttribute:@"color-critical" inState:themeState];
else if (value <= _warningValue)
filledColor = [self valueForThemeAttribute:@"color-warning"];
filledColor = [self valueForThemeAttribute:@"color-warning" inState:themeState];
}
var emptyColor = [self valueForThemeAttribute:@"color-empty" inState:themeState];
// 4. Paint Segments
for (var i = 0; i < segmentCount; i++)
{
var segmentView = [self layoutEphemeralSubviewNamed:"segment-bezel-" + i
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:bezelView];
[segmentView setBackgroundColor:(_minValue + i) < value ? filledColor : [self valueForThemeAttribute:@"color-empty"]];
[segmentView setBackgroundColor:(_minValue + i) < value ? filledColor : emptyColor];
}
}
@@ -310,20 +323,6 @@ CPRatingLevelIndicatorStyle = 3;
[self setNeedsLayout];
}
/*
- (CPTickMarkPosition)tickMarkPosition;
- (void)setTickMarkPosition:(CPTickMarkPosition)position;
- (int)numberOfTickMarks;
- (void)setNumberOfTickMarks:(int)count;
- (int)numberOfMajorTickMarks;
- (void)setNumberOfMajorTickMarks:(int)count;
- (double)tickMarkValueAtIndex:(int)index;
- (CGRect)rectOfTickMarkAtIndex:(int)index;
*/
@end
var CPLevelIndicatorStyleKey = "CPLevelIndicatorStyleKey",
+141 -4
View File
@@ -27,6 +27,7 @@
@import "CPKeyValueBinding.j"
@import "CPMenuItem.j"
@import "CALayer.j"
@global CPApp
@@ -164,7 +165,7 @@ var _CPMenuBarVisible = NO,
+ (void)_setOrRemoveMenuBarAttribute:(id)aValue forKey:(id)aKey
{
if (aValue === nil)
if (aValue == nil)
[_CPMenuBarAttributes removeObjectForKey:aKey];
else
[_CPMenuBarAttributes setObject:aValue forKey:aKey];
@@ -268,10 +269,13 @@ var _CPMenuBarVisible = NO,
if (self)
{
_title = aTitle;
_items = [];
// Use CPMutableArray instead of raw JS array for consistency with removeAllItems
_items = [CPMutableArray array];
_autoenablesItems = YES;
_showsStateColumn = YES;
_themeState = CPThemeStateNormal;
[self setMinimumWidth:0];
}
@@ -284,6 +288,37 @@ var _CPMenuBarVisible = NO,
return [self initWithTitle:@""];
}
// Managing Theme States (HUD Support)
- (void)setThemeState:(CPThemeState)aState
{
if ([self hasThemeState:aState])
return;
_themeState = _themeState.and(aState);
// Propagate to the view if the menu is currently visible
if (_menuWindow)
[[_menuWindow _menuView] setThemeState:_themeState];
}
- (void)unsetThemeState:(CPThemeState)aState
{
if (![self hasThemeState:aState])
return;
_themeState = _themeState.without(aState);
// Propagate to the view if the menu is currently visible
if (_menuWindow)
[[_menuWindow _menuView] setThemeState:_themeState];
}
- (CPThemeState)themeState
{
return _themeState;
}
// Setting Up Menu Commands
/*!
Inserts a menu item at the specified index.
@@ -373,6 +408,10 @@ var _CPMenuBarVisible = NO,
[self willChangeValueForKey:@"items"];
_items = [CPMutableArray array];
[self didChangeValueForKey:@"items"];
// Ensure the main menu updates if cleared
if (self === [CPApp mainMenu] && _CPMenuBarSharedWindow)
[_CPMenuBarSharedWindow setMenu:self];
}
/*!
@@ -389,6 +428,9 @@ var _CPMenuBarVisible = NO,
if ([aMenuItem menu] !== self || !_items)
return;
if (_menuWindow)
[[_menuWindow _menuView] tile];
[aMenuItem setValue:[aMenuItem valueForKey:@"changeCount"] + 1 forKey:@"changeCount"];
[[CPNotificationCenter defaultCenter]
@@ -789,6 +831,10 @@ var _CPMenuBarVisible = NO,
// Create the window for our menu.
var menuWindow = [_CPMenuWindow menuWindowWithMenu:self font:[self font]];
// This pushes the state (e.g., CPThemeStateHUD) to the actual view that renders the menu
if (_themeState)
[[menuWindow _menuView] setThemeState:_themeState];
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];
if (anItem)
@@ -879,6 +925,10 @@ var _CPMenuBarVisible = NO,
var theWindow = [aView window],
menuWindow = [_CPMenuWindow menuWindowWithMenu:aMenu font:aFont];
// --- APPLY THEME STATE FROM MENU OBJECT TO VIEW ---
if ([aMenu respondsToSelector:@selector(themeState)])
[[menuWindow _menuView] setThemeState:[aMenu themeState]];
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];
var constraintRect = [CPMenu _constraintRectForView:aView],
@@ -1016,6 +1066,10 @@ var _CPMenuBarVisible = NO,
// an additional mouse move after all this, but not in other browsers.
// This will be fixed correctly with the coming run loop changes.
[_CPDisplayServer run];
// If layers are updated within the menu callback, the re-draw & re-layout doesn't occur until a mouse move.
// We force the update here.
[CALayer runLoopUpdateLayers];
}
/* @ignore */
@@ -1057,7 +1111,23 @@ var _CPMenuBarVisible = NO,
if ([anEvent _triggersKeyEquivalent:[item keyEquivalent] withModifierMask:[item keyEquivalentModifierMask]])
{
if ([item isEnabled])
{
// Flash the top-level item if this is the Main Menu
if (self === [CPApp mainMenu])
[self _flashItemAtIndex:index];
anEvent._isKeyEquivalent = YES; // prevent the menu keystroke from beeing inserted into textview
[self performActionForItemAtIndex:index];
#if PLATFORM(DOM)
// we are done with this event in cappuccino space. do not let the browser do something weird additionally (e.g. command-o).
// but we must not stop copy/paste events as these can only be handled by the browser at this time even if they are in our menu
// (until we move to CPTextView as the fieleditor)
if (characters != "c" && characters != "x" && characters != "v")
_CPDOMEventStop(anEvent._DOMEvent);
#endif
}
else
{
//beep?
@@ -1067,7 +1137,13 @@ var _CPMenuBarVisible = NO,
}
if ([[item submenu] performKeyEquivalent:anEvent])
{
// Flash the top-level item if a submenu handled the event
if (self === [CPApp mainMenu])
[self _flashItemAtIndex:index];
return YES;
}
}
return NO;
@@ -1131,7 +1207,7 @@ var _CPMenuBarVisible = NO,
}
}
- (void)_menuWithName:(CPString)aName
- (CPMenu)_menuWithName:(CPString)aName
{
if (aName === _name)
return self;
@@ -1147,6 +1223,25 @@ var _CPMenuBarVisible = NO,
return nil;
}
//
/*
@ignore
*/
- (void)_flashItemAtIndex:(int)anIndex
{
// If we are using a native bridge (like a desktop wrapper), let the OS handle the visual feedback.
if ([CPPlatform supportsNativeMainMenu])
return;
[self _highlightItemAtIndex:anIndex];
[self performSelector:@selector(_stopFlashingItem) withObject:nil afterDelay:0.2];
}
- (void)_stopFlashingItem
{
[self _highlightItemAtIndex:CPNotFound];
}
@end
@@ -1218,6 +1313,11 @@ var _CPMenuBarVisible = NO,
postNotificationName:CPMenuDidAddItemNotification
object:self
userInfo:@{ @"CPMenuItemIndex": anIndex }];
// FIX #1222: If this is the main menu, force the shared menu bar window to refresh its layout.
// This ensures new items are positioned correctly (e.g. not pushed to the far right by previous layout states).
if (self === [CPApp mainMenu] && _CPMenuBarSharedWindow)
[_CPMenuBarSharedWindow setMenu:self];
}
- (void)removeObjectFromItemsAtIndex:(CPUInteger)anIndex
@@ -1233,6 +1333,10 @@ var _CPMenuBarVisible = NO,
postNotificationName:CPMenuDidRemoveItemNotification
object:self
userInfo:@{ @"CPMenuItemIndex": anIndex }];
// FIX #1222: Ensure the shared menu bar updates layout when items are removed.
if (self === [CPApp mainMenu] && _CPMenuBarSharedWindow)
[_CPMenuBarSharedWindow setMenu:self];
}
@end
@@ -1265,6 +1369,9 @@ var CPMenuTitleKey = @"CPMenuTitleKey",
_autoenablesItems = ![aCoder containsValueForKey:CPMenuAutoEnablesItemsKey] || [aCoder decodeBoolForKey:CPMenuAutoEnablesItemsKey];
// Ensure theme state is initialized to avoid undefined issues.
_themeState = CPThemeStateNormal;
[self setMinimumWidth:0];
}
@@ -1293,6 +1400,36 @@ var CPMenuTitleKey = @"CPMenuTitleKey",
@end
// MARK: -
@implementation CPMenu (CSSTheming)
+ (void)setNamedValue:(CPString)aName forKey:(CPString)aKey inAttributes:(CPDictionary)aDictionary forTheme:(CPTheme)aTheme
{
var value = [aTheme valueForAttributeWithName:aName forClass:_CPMenuView];
if (value)
[aDictionary setObject:value forKey:aKey];
else
[aDictionary removeObjectForKey:aKey];
}
+ (void)updateMenuBarAttributesWithTheme:(CPTheme)aTheme
{
var newAttributes = @{};
[CPMenu setNamedValue:@"menu-bar-text-color" forKey:@"CPMenuBarTextColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setNamedValue:@"menu-bar-title-color" forKey:@"CPMenuBarTitleColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setNamedValue:@"menu-bar-text-shadow-color" forKey:@"CPMenuBarTextShadowColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setNamedValue:@"menu-bar-title-shadow-color" forKey:@"CPMenuBarTitleShadowColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setNamedValue:@"menu-bar-highlight-color" forKey:@"CPMenuBarHighlightColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setNamedValue:@"menu-bar-highlight-text-color" forKey:@"CPMenuBarHighlightTextColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setNamedValue:@"menu-bar-highlight-text-shadow-color" forKey:@"CPMenuBarHighlightTextShadowColor" inAttributes:newAttributes forTheme:aTheme];
[CPMenu setMenuBarAttributes:newAttributes];
}
@end
@import "_CPMenuBarWindow.j"
@import "_CPMenuWindow.j"
+67 -26
View File
@@ -25,11 +25,14 @@
@class _CPMenuView
@class CPMenu
@class CPMenuItem
@global CPMenuDidAddItemNotification
@global CPMenuDidChangeItemNotification
@global CPMenuDidRemoveItemNotification
@global document
@implementation _CPMenuBarWindow : CPPanel
{
CPView _highlightView;
@@ -129,10 +132,12 @@
- (void)setColor:(CPColor)aColor
{
var targetView = [[CPTheme defaultTheme] valueForAttributeWithName:@"css-based" forClass:CPView] ? [[self contentView] superview] : [self contentView];
if (!aColor)
[[self contentView] setBackgroundColor:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-background-color" forClass:_CPMenuView]];
[targetView setBackgroundColor:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-background-color" forClass:_CPMenuView]];
else
[[self contentView] setBackgroundColor:aColor];
[targetView setBackgroundColor:aColor];
}
- (void)setTextColor:(CPColor)aColor
@@ -277,6 +282,16 @@
[menuItemView setTextColor:_textColor];
[menuItemView setHidden:[item isHidden]];
// If first menu item has tag -1 and if there is a special theme value menu-bar-window-first-item-font,
// set the corresponding font. This is used to set bold on the first item of the menubar (à la Cocoa)
if ((index == 0) && ([item tag] == -1))
{
var firstItemFont = [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-first-item-font" forClass:_CPMenuView];
if (firstItemFont)
[item setFont:firstItemFont];
}
[menuItemView synchronizeWithMenuItem];
[contentView addSubview:menuItemView];
@@ -350,17 +365,46 @@
- (CPFont)font
{
[CPFont systemFontOfSize:[CPFont systemFontSize]];
return [CPFont systemFontOfSize:[CPFont systemFontSize]];
}
- (void)tile
{
var bounds = [[self contentView] bounds],
height = CGRectGetHeight(bounds),
x = [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-left-margin" forClass:_CPMenuView];
// 1. Layout the Icon (if present)
if (_iconImageView && ![_iconImageView isHidden])
{
var iconFrame = [_iconImageView frame];
iconFrame.origin.x = x;
// Vertically center
iconFrame.origin.y = (height - CGRectGetHeight(iconFrame)) / 2.0;
[_iconImageView setFrame:iconFrame];
x = CGRectGetMaxX(iconFrame) + 6.0; // Spacing between icon and title
}
// 2. Layout the Title (if present)
if (_titleField && [_titleField stringValue] && [[_titleField stringValue] length] > 0)
{
var titleFrame = [_titleField frame];
titleFrame.origin.x = x;
titleFrame.origin.y = (height - CGRectGetHeight(titleFrame)) / 2.0;
[_titleField setFrame:titleFrame];
x = CGRectGetMaxX(titleFrame) + 12.0; // Spacing between title and menu items
}
// 3. Layout the Menu Items
var items = [_menu itemArray],
index = 0,
count = items.length,
x = [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-window-left-margin" forClass:_CPMenuView],
y = 0.0,
count = items ? items.length : 0,
isLeftAligned = YES;
for (; index < count; ++index)
@@ -375,11 +419,18 @@
continue;
}
if ([item isHidden])
// Fix for #1742: If a main menu item does not have a submenu, it should not appear in the menu bar.
if ([item isHidden] || ![item submenu])
{
[[item _menuItemView] setHidden:YES];
continue;
}
var menuItemView = [item _menuItemView],
frame = [menuItemView frame];
var menuItemView = [item _menuItemView];
[menuItemView setHidden:NO];
var frame = [menuItemView frame];
if (isLeftAligned)
{
@@ -394,21 +445,6 @@
x = CGRectGetMinX([menuItemView frame]);
}
}
var bounds = [[self contentView] bounds],
titleFrame = [_titleField frame];
if ([_iconImageView isHidden])
[_titleField setFrameOrigin:CGPointMake((CGRectGetWidth(bounds) - CGRectGetWidth(titleFrame)) / 2.0, (CGRectGetHeight(bounds) - CGRectGetHeight(titleFrame)) / 2.0)];
else
{
var iconFrame = [_iconImageView frame],
iconWidth = CGRectGetWidth(iconFrame),
totalWidth = iconWidth + CGRectGetWidth(titleFrame);
[_iconImageView setFrameOrigin:CGPointMake((CGRectGetWidth(bounds) - totalWidth) / 2.0, (CGRectGetHeight(bounds) - CGRectGetHeight(iconFrame)) / 2.0)];
[_titleField setFrameOrigin:CGPointMake((CGRectGetWidth(bounds) - totalWidth) / 2.0 + iconWidth, (CGRectGetHeight(bounds) - CGRectGetHeight(titleFrame)) / 2.0)];
}
}
- (void)setFrame:(CGRect)aRect display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate
@@ -449,13 +485,18 @@
{
var item = items[index];
if ([item isHidden] || [item isSeparatorItem])
if ([item isHidden] || [item isSeparatorItem] || ![item submenu])
continue;
if (CGRectContainsPoint([self rectForItemAtIndex:index], aPoint))
return index;
}
// If the mouse is within the menu bar bounds but not over an item
// (e.g. dragging far left or right), force the menu to unhighlight.
if (CGRectContainsPoint([[self contentView] bounds], aPoint))
[_menu _highlightItemAtIndex:CPNotFound];
return CPNotFound;
}
+39 -26
View File
@@ -28,6 +28,8 @@
@class CPWindow
@class _CPMenuWindow
@class _CPMenuView
@class CPMenuItem
@global CPApp
@@ -223,7 +225,7 @@ var STICKY_TIME_INTERVAL = 0.4,
_lastGlobalLocation = globalLocation;
// If the item isn't enabled its as if we clicked on nothing.
if (![activeItem isEnabled] || [activeItem _isMenuBarButton])
if ([activeItem _isMenuBarButton])
{
activeItemIndex = CPNotFound;
activeItem = nil;
@@ -352,7 +354,23 @@ var STICKY_TIME_INTERVAL = 0.4,
if ([activeMenuContainer isMenuBar])
newMenuOrigin = CGPointMake(CGRectGetMinX(activeItemRect), CGRectGetMaxY(activeItemRect));
else
newMenuOrigin = CGPointMake(CGRectGetMaxX(activeItemRect), CGRectGetMinY(activeItemRect));
{
// New theme attributes to have more precise submenus positioning
var defaultTheme = [CPTheme defaultTheme],
themeDeltaX = [defaultTheme valueForAttributeWithName:@"menu-window-submenu-delta-x" forClass:_CPMenuView],
themeDeltaY = [defaultTheme valueForAttributeWithName:@"menu-window-submenu-delta-y" forClass:_CPMenuView],
themeFirstDeltaY = [defaultTheme valueForAttributeWithName:@"menu-window-submenu-first-level-delta-y" forClass:_CPMenuView],
activeMenuIndex = [_menuContainerStack indexOfObject:activeMenuContainer],
deltaX = themeDeltaX ? themeDeltaX : 0,
deltaY = themeDeltaY ? themeDeltaY : 0;
if (themeFirstDeltaY && (activeMenuIndex == 1) && [_menuContainerStack[0] isMenuBar])
deltaY += themeFirstDeltaY;
newMenuOrigin = CGPointMake(CGRectGetMaxX(activeItemRect)+deltaX, CGRectGetMinY(activeItemRect)+deltaY);
}
newMenuOrigin = [activeMenuContainer convertBaseToGlobal:newMenuOrigin];
@@ -553,7 +571,7 @@ var STICKY_TIME_INTERVAL = 0.4,
var iter = [selectorNames objectEnumerator],
obj;
while ((obj = [iter nextObject]) !== nil)
while ((obj = [iter nextObject]) != nil)
{
var aSelector = CPSelectorFromString(obj);
@@ -580,6 +598,8 @@ var STICKY_TIME_INTERVAL = 0.4,
[self selectNextItemBeginningWith:_keyBuffer inMenu:menu];
_lastGlobalLocation = nil;
}
[[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO];
}
- (void)selectNextItemBeginningWith:(CPString)characters inMenu:(CPMenu)menu
@@ -587,7 +607,7 @@ var STICKY_TIME_INTERVAL = 0.4,
var iter = [[menu itemArray] objectEnumerator],
obj;
while ((obj = [iter nextObject]) !== nil)
while ((obj = [iter nextObject]) != nil)
{
if ([obj isHidden] || ![obj isEnabled])
continue;
@@ -725,39 +745,32 @@ var STICKY_TIME_INTERVAL = 0.4,
- (void)moveDown:(CPMenu)menu
{
var index = menu._highlightedIndex + 1;
var index = menu._highlightedIndex + 1,
item;
// Search for the next enabled item
while ((index < [menu numberOfItems]) && (item = [menu itemAtIndex:index]) && ([item isSeparatorItem] || [item isHidden] || ![item isEnabled]))
index++;
if (index < [menu numberOfItems])
{
[menu _highlightItemAtIndex:index];
var item = [menu highlightedItem];
if ([item isSeparatorItem] || [item isHidden] || ![item isEnabled])
[self moveDown:menu];
}
else if (menu == [CPApp mainMenu])
[menu _highlightItemAtIndex:0];
}
- (void)moveUp:(CPMenu)menu
{
var index = menu._highlightedIndex - 1;
var index = menu._highlightedIndex - 1,
item;
if (index < 0)
{
if (index != CPNotFound || menu == [CPApp mainMenu])
[menu _highlightItemAtIndex:[menu numberOfItems] - 1];
// Search for the previous enabled item
while ((index >= 0) && (item = [menu itemAtIndex:index]) && ([item isSeparatorItem] || [item isHidden] || ![item isEnabled]))
index--;
return;
}
[menu _highlightItemAtIndex:index];
var item = [menu highlightedItem];
if ([item isSeparatorItem] || [item isHidden] || ![item isEnabled])
[self moveUp:menu];
if (index >= 0)
[menu _highlightItemAtIndex:index];
else if (menu == [CPApp mainMenu])
[menu _highlightItemAtIndex:[menu numberOfItems] - 1];
}
- (void)insertNewline:(CPMenu)menu
+106 -10
View File
@@ -26,6 +26,7 @@
@import "_CPMenuManager.j"
@class _CPMenuView
@class CPMenuItem
var _CPMenuWindowPool = [],
_CPMenuWindowPoolCapacity = 5,
@@ -61,6 +62,9 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
// Do this so that coordinates will be accurate.
[menuWindow setFrameOrigin:CGPointMakeZero()];
// we need to reset the HUD state as this may be a recycled instance with HUD rund on non-HUD
[[menuWindow _windowView] unsetThemeState:CPThemeStateHUD];
[[menuWindow _menuView] unsetThemeState:CPThemeStateHUD];
}
else
menuWindow = [[_CPMenuWindow alloc] init];
@@ -107,23 +111,33 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
[contentView addSubview:_menuClipView];
_moreAboveView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
[_moreAboveView setImage:[_menuView valueForThemeAttribute:@"menu-window-more-above-image"]];
[_moreAboveView setFrameSize:[[_menuView valueForThemeAttribute:@"menu-window-more-above-image"] size]];
[contentView addSubview:_moreAboveView];
_moreBelowView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
[_moreBelowView setImage:[_menuView valueForThemeAttribute:@"menu-window-more-below-image"]];
[_moreBelowView setFrameSize:[[_menuView valueForThemeAttribute:@"menu-window-more-below-image"] size]];
[contentView addSubview:_moreBelowView];
// Initial setup using default attributes
[self updateScrollArrows];
}
return self;
}
- (void)updateScrollArrows
{
if (!_menuView)
return;
var aboveImage = [_menuView currentValueForThemeAttribute:@"menu-window-more-above-image"],
belowImage = [_menuView currentValueForThemeAttribute:@"menu-window-more-below-image"];
[_moreAboveView setImage:aboveImage];
[_moreAboveView setFrameSize:[aboveImage size]];
[_moreBelowView setImage:belowImage];
[_moreBelowView setFrameSize:[belowImage size]];
}
+ (float)_standardLeftMargin
{
return [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-window-margin-inset" forClass:_CPMenuView].left;
@@ -161,7 +175,12 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
- (void)setBackgroundStyle:(_CPMenuWindowBackgroundStyle)aBackgroundStyle
{
[self setBackgroundColor:[[self class] backgroundColorForBackgroundStyle:aBackgroundStyle]];
var color = [_menuView currentValueForThemeAttribute:@"menu-window-pop-up-background-style-color"];
if (!color)
color = [[self class] backgroundColorForBackgroundStyle:aBackgroundStyle];
[self setBackgroundColor:color];
}
- (void)setMenu:(CPMenu)aMenu
@@ -233,6 +252,32 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
// FIXME: This gets called far too often.
_unconstrainedFrame = CGRectMakeCopy(aFrame);
// If we are a submenu and we are being displayed off the right of the screen,
// we should try and display on the left of our supermenu.
var supermenu = [[self menu] supermenu];
if (supermenu)
{
if (CGRectGetMaxX(_unconstrainedFrame) > CGRectGetMaxX(_constraintRect))
{
var supermenuWindow = supermenu._menuWindow;
if (supermenuWindow)
{
var supermenuFrame = [supermenuWindow frame];
_unconstrainedFrame.origin.x = CGRectGetMinX(supermenuFrame) - CGRectGetWidth(_unconstrainedFrame);
}
}
// Shift true submenus vertically to fit within the screen if they extend past the bottom
if (supermenu !== [CPApp mainMenu] && CGRectGetMaxY(_unconstrainedFrame) > CGRectGetMaxY(_constraintRect))
_unconstrainedFrame.origin.y -= CGRectGetMaxY(_unconstrainedFrame) - CGRectGetMaxY(_constraintRect);
}
// Ensure no menu starts above the visible screen area, preventing it from incorrectly
// starting scrolled with a top arrow.
if (CGRectGetMinY(_unconstrainedFrame) < CGRectGetMinY(_constraintRect))
_unconstrainedFrame.origin.y = CGRectGetMinY(_constraintRect);
var constrainedFrame = CGRectIntersection(_unconstrainedFrame, _constraintRect),
marginInset = [_menuView valueForThemeAttribute:@"menu-window-margin-inset"],
scrollIndicatorHeight = [_menuView valueForThemeAttribute:@"menu-window-scroll-indicator-height"];
@@ -254,7 +299,8 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
[super setFrame:constrainedFrame display:shouldDisplay animate:shouldAnimate];
// This needs to happen before changing the frame.
var menuViewOrigin = CGPointMake(CGRectGetMinX(aFrame) + marginInset.left, CGRectGetMinY(aFrame) + marginInset.top),
// Base the view origin on our modified _unconstrainedFrame instead of aFrame
var menuViewOrigin = CGPointMake(CGRectGetMinX(_unconstrainedFrame) + marginInset.left, CGRectGetMinY(_unconstrainedFrame) + marginInset.top),
moreAbove = menuViewOrigin.y < CGRectGetMinY(constrainedFrame) + marginInset.top,
moreBelow = menuViewOrigin.y + CGRectGetHeight([_menuView frame]) > CGRectGetMaxY(constrainedFrame) - marginInset.bottom,
@@ -419,6 +465,21 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
@end
// MARK: -
@implementation _CPMenuWindow (CSSTheming)
- (void)_setThemeIncludingDescendants:(CPTheme)aTheme
{
[[self contentView] _setThemeIncludingDescendants:aTheme];
[_menuView _setThemeIncludingDescendants:aTheme];
[_menuView tile];
}
@end
// MARK: -
/*
@ignore
*/
@@ -449,6 +510,7 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
@"menu-bar-window-background-color": [CPNull null],
@"menu-bar-window-background-selected-color": [CPNull null],
@"menu-bar-window-font": [CPNull null],
@"menu-bar-window-first-item-font": [CPNull null],
@"menu-bar-window-height": 30.0,
@"menu-bar-window-margin": 10.0,
@"menu-bar-window-left-margin": 10.0,
@@ -466,9 +528,27 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
@"menu-general-icon-new": [CPNull null],
@"menu-general-icon-save": [CPNull null],
@"menu-general-icon-open": [CPNull null],
@"menu-window-submenu-delta-x": 0.0,
@"menu-window-submenu-delta-y": 0.0,
@"menu-window-submenu-first-level-delta-y": 0.0
};
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
[_menuItemViews makeObjectsPerformSelector:@selector(setThemeState:) withObject:aState];
if ([[self window] respondsToSelector:@selector(updateScrollArrows)])
[[self window] updateScrollArrows];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
[_menuItemViews makeObjectsPerformSelector:@selector(unsetThemeState:) withObject:aState];
}
- (unsigned)numberOfUnhiddenItems
{
return _visibleMenuItemInfos.length;
@@ -552,6 +632,7 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
[view setFrameOrigin:CGPointMake(0.0, y)];
[view _setThemeIncludingDescendants:[CPTheme defaultTheme]];
[self addSubview:view];
var size = [view minSize],
@@ -582,3 +663,18 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
}
@end
// MARK: -
@implementation _CPMenuView (CSSTheming)
- (void)_setThemeIncludingDescendants:(CPTheme)aTheme
{
[self setTheme:aTheme];
[_menuItemViews makeObjectsPerformSelector:@selector(_setThemeIncludingDescendants:) withObject:aTheme];
for (var i = 0, items = [[self menu] itemArray], count = [items count]; i < count; i++)
[[items[i] _menuItemView] _setThemeIncludingDescendants:aTheme];
}
@end
+25 -5
View File
@@ -826,7 +826,7 @@ CPControlKeyMask
return [[self menu] highlightedItem] == self;
}
#pragma mark CPObject Overrides
// MARK: CPObject Overrides
/*!
Returns a copy of the item. The copy does not belong If the item has a submenu, it is NOT copied.
@@ -867,7 +867,7 @@ CPControlKeyMask
return [self copy];
}
#pragma mark Internal
// MARK: Internal
/*
@ignore
@@ -897,6 +897,20 @@ CPControlKeyMask
@end
// MARK: -
@implementation CPMenuItem (CSSTheming)
- (void)_setThemeIncludingDescendants:(CPTheme)aTheme
{
[_view _setThemeIncludingDescendants:aTheme];
[_menuItemView _setThemeIncludingDescendants:aTheme];
}
@end
// MARK: -
var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
CPMenuItemTitleKey = @"CPMenuItemTitleKey",
@@ -911,6 +925,9 @@ var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
CPMenuItemImageKey = @"CPMenuItemImageKey",
CPMenuItemAlternateImageKey = @"CPMenuItemAlternateImageKey",
CPMenuItemOnStateImageKey = @"CPMenuItemOnStateImageKey",
CPMenuItemOffStateImageKey = @"CPMenuItemOffStateImageKey",
CPMenuItemMixedStateImageKey = @"CPMenuItemMixedStateImageKey",
CPMenuItemSubmenuKey = @"CPMenuItemSubmenuKey",
CPMenuItemMenuKey = @"CPMenuItemMenuKey",
@@ -955,9 +972,9 @@ var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
_image = [aCoder decodeObjectForKey:CPMenuItemImageKey];
_alternateImage = [aCoder decodeObjectForKey:CPMenuItemAlternateImageKey];
// CPImage _onStateImage;
// CPImage _offStateImage;
// CPImage _mixedStateImage;
_onStateImage = [aCoder decodeObjectForKey:CPMenuItemOnStateImageKey];
_offStateImage = [aCoder decodeObjectForKey:CPMenuItemOffStateImageKey];
_mixedStateImage = [aCoder decodeObjectForKey:CPMenuItemMixedStateImageKey];
// This order matters because setSubmenu: needs _menu to be around.
_menu = [aCoder decodeObjectForKey:CPMenuItemMenuKey];
@@ -1003,6 +1020,9 @@ var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
ENCODE_IFNOT(CPMenuItemImageKey, _image, nil);
ENCODE_IFNOT(CPMenuItemAlternateImageKey, _alternateImage, nil);
ENCODE_IFNOT(CPMenuItemOnStateImageKey, _onStateImage, nil);
ENCODE_IFNOT(CPMenuItemOffStateImageKey, _offStateImage, nil);
ENCODE_IFNOT(CPMenuItemMixedStateImageKey, _mixedStateImage, nil);
ENCODE_IFNOT(CPMenuItemSubmenuKey, _submenu, nil);
ENCODE_IFNOT(CPMenuItemMenuKey, _menu, nil);
+19 -4
View File
@@ -31,7 +31,9 @@
+ (id)view
{
return [[self alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 10.0)];
var themedHeight = [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-item-separator-view-height" forClass:_CPMenuItemStandardView];
return [[self alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, (themedHeight ? themedHeight : 10.0))];
}
- (id)initWithFrame:(CGRect)aFrame
@@ -47,12 +49,25 @@
- (void)drawRect:(CGRect)aRect
{
var context = [[CPGraphicsContext currentContext] graphicsPort],
bounds = [self bounds];
bounds = [self bounds],
height = CGRectGetMaxY(bounds),
themedHeight = [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-item-separator-height" forClass:_CPMenuItemStandardView],
lineHeight = themedHeight ? themedHeight : 1.0;
CGContextBeginPath(context);
CGContextMoveToPoint(context, CGRectGetMinX(bounds), FLOOR(CGRectGetMidY(bounds)) - 0.5);
CGContextAddLineToPoint(context, CGRectGetMaxX(bounds), FLOOR(CGRectGetMidY(bounds)) - 0.5);
CGContextSetLineWidth(context, lineHeight);
if (!!((height - lineHeight) % 2))
{
CGContextMoveToPoint(context, CGRectGetMinX(bounds), FLOOR(CGRectGetMidY(bounds)) - 0.5);
CGContextAddLineToPoint(context, CGRectGetMaxX(bounds), FLOOR(CGRectGetMidY(bounds)) - 0.5);
}
else
{
CGContextMoveToPoint(context, CGRectGetMinX(bounds), FLOOR(CGRectGetMidY(bounds)));
CGContextAddLineToPoint(context, CGRectGetMaxX(bounds), FLOOR(CGRectGetMidY(bounds)));
}
CGContextSetStrokeColor(context, [[CPTheme defaultTheme] valueForAttributeWithName:@"menu-item-separator-color" forClass:_CPMenuItemStandardView]);
CGContextStrokePath(context);
+128 -23
View File
@@ -41,6 +41,8 @@
_CPImageAndTextView _imageAndTextView;
_CPImageAndTextView _keyEquivalentView;
CPView _submenuIndicatorView;
BOOL _hasSubmenuIndicatorImage;
}
+ (CPString)defaultThemeClass
@@ -63,12 +65,17 @@
@"menu-item-default-mixed-state-image": [CPNull null],
@"menu-item-default-mixed-state-highlighted-image": [CPNull null],
@"menu-item-separator-color": [CPNull null],
@"menu-item-separator-height": 1.0,
@"menu-item-separator-view-height": 10.0,
@"left-margin": 3.0,
@"right-margin": 17.0,
@"state-column-width": 14.0,
@"indentation-width": 17.0,
@"vertical-margin": 4.0,
@"vertical-offset": 0.0,
@"right-columns-margin": 30.0,
@"submenu-indicator-image": [CPNull null],
@"submenu-indicator-highlighted-image": [CPNull null]
};
}
@@ -91,6 +98,7 @@
_stateView = [[CPImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 0.0)];
[_stateView setImageScaling:CPImageScaleNone];
[_stateView setImageAlignment:CPImageAlignCenter];
[self addSubview:_stateView];
@@ -109,9 +117,24 @@
[self addSubview:_keyEquivalentView];
_submenuIndicatorView = [[_CPMenuItemSubmenuIndicatorView alloc] initWithFrame:CGRectMake(0.0, 0.0, 8.0, 10.0)];
// Do we have a submenu indicator image specified in the theme ?
_hasSubmenuIndicatorImage = !![self valueForThemeAttribute:@"submenu-indicator-image"];
if (_hasSubmenuIndicatorImage)
{
// Yes, then use an imageView
_submenuIndicatorView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
[_submenuIndicatorView setImageAlignment:CPImageAlignCenter];
}
else
{
// No, then use self drawing _CPMenuItemSubmenuIndicatorView
_submenuIndicatorView = [[_CPMenuItemSubmenuIndicatorView alloc] initWithFrame:CGRectMake(0.0, 0.0, 8.0, 10.0)];
[_submenuIndicatorView setColor:[self valueForThemeAttribute:@"submenu-indicator-color"]];
}
[_submenuIndicatorView setColor:[self valueForThemeAttribute:@"submenu-indicator-color"]];
[_submenuIndicatorView setAutoresizingMask:CPViewMinXMargin];
[self addSubview:_submenuIndicatorView];
@@ -122,6 +145,26 @@
return self;
}
- (void)setThemeState:(CPThemeState)aState
{
var oldState = [self themeState];
[super setThemeState:aState];
// If the state changed (e.g. adding HUD), we must re-run update
// to fetch the new text color defined for that state.
if (oldState !== [self themeState])
[self update];
}
- (void)unsetThemeState:(CPThemeState)aState
{
var oldState = [self themeState];
[super unsetThemeState:aState];
if (oldState !== [self themeState])
[self update];
}
- (CPColor)textColor
{
if (![_menuItem isEnabled])
@@ -130,7 +173,7 @@
if (_highlighted)
return [CPColor whiteColor];
return [self valueForThemeAttribute:@"menu-item-text-color"];
return [self currentValueForThemeAttribute:@"menu-item-text-color"];
}
- (CPColor)textShadowColor
@@ -141,7 +184,7 @@
if (_highlighted)
return nil;
return [self valueForThemeAttribute:@"menu-item-text-shadow-color"];
return [self currentValueForThemeAttribute:@"menu-item-text-shadow-color"];
}
- (void)setFont:(CPFont)aFont
@@ -149,11 +192,31 @@
_font = aFont;
}
- (CPFont)font
{
// Menu item font is forced local font or _menuItem font or system font
return _font || [_menuItem font] || [CPFont systemFontOfSize:CPFontCurrentSystemSize];
}
// override needed to cancel out the standard HUD propagation
- (void)viewDidMoveToWindow
{
}
// FIXME: update is called 2 times at each display. Find why and fix.
- (void)update
{
var x = [self valueForThemeAttribute:@"left-margin"] + [_menuItem indentationLevel] * [self valueForThemeAttribute:@"indentation-width"],
height = 0.0,
hasStateColumn = [[_menuItem menu] showsStateColumn];
hasStateColumn = [[_menuItem menu] showsStateColumn],
myFont = [self font],
// When possible, use specific vertical margin/offset value based on font size (which could have been set by control size)
correspondingControlSize = [myFont controlSizeCorrespondingToFontSize],
controlSizeState = CPControlSizeThemeStates[correspondingControlSize],
queryState = [self themeState] ? [self themeState].and(controlSizeState) : controlSizeState,
verticalMargin = [self valueForThemeAttribute:@"vertical-margin" inState:CPControlSizeThemeStates[correspondingControlSize]],
verticalOffset = [self valueForThemeAttribute:@"vertical-offset" inState:CPControlSizeThemeStates[correspondingControlSize]];
if (hasStateColumn)
{
@@ -163,27 +226,32 @@
switch ([_menuItem state])
{
case CPOnState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-on-state-image"]];
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-on-state-image" inState:queryState] || [_menuItem onStateImage]];
break;
case CPOffState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-off-state-image"]];
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-off-state-image" inState:queryState] || [_menuItem offStateImage]];
break;
case CPMixedState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-mixed-state-image"]];
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-mixed-state-image" inState:queryState] || [_menuItem mixedStateImage]];
break;
default:
break;
}
var stateViewFrameOrigin = [_stateView frameOrigin];
stateViewFrameOrigin.x = x;
[_stateView setFrameOrigin:stateViewFrameOrigin];
x += [self valueForThemeAttribute:@"state-column-width"];
}
else
[_stateView setHidden:YES];
[_imageAndTextView setFont:[_menuItem font] || _font];
[_imageAndTextView setFont:myFont];
[_imageAndTextView setVerticalAlignment:CPCenterVerticalTextAlignment];
[_imageAndTextView setImage:[_menuItem image]];
[_imageAndTextView setText:[_menuItem title]];
@@ -196,7 +264,7 @@
imageAndTextViewFrame.origin.x = x;
x += CGRectGetWidth(imageAndTextViewFrame);
height = MAX(height, CGRectGetHeight(imageAndTextViewFrame));
height = MAX(height, CGRectGetHeight(imageAndTextViewFrame)); // FIXME: here, height = 0 -> MAX useless
var hasKeyEquivalent = !![_menuItem keyEquivalent],
hasSubmenu = [_menuItem hasSubmenu];
@@ -206,14 +274,14 @@
if (hasKeyEquivalent)
{
[_keyEquivalentView setFont:[_menuItem font] || _font];
[_keyEquivalentView setFont:myFont];
[_keyEquivalentView setVerticalAlignment:CPCenterVerticalTextAlignment];
[_keyEquivalentView setImage:[_menuItem image]];
[_keyEquivalentView setText:[_menuItem keyEquivalentStringRepresentation]];
[_keyEquivalentView setTextColor:[self textColor]];
[_keyEquivalentView setTextShadowColor:[self textShadowColor]];
[_keyEquivalentView setTextShadowOffset:CGSizeMake(0, 1)];
[_keyEquivalentView setFrameOrigin:CGPointMake(x, [self valueForThemeAttribute:@"vertical-margin"])];
[_keyEquivalentView setFrameOrigin:CGPointMake(x, verticalMargin)];
[_keyEquivalentView sizeToFit];
var keyEquivalentViewFrame = [_keyEquivalentView frame];
@@ -230,6 +298,14 @@
if (hasSubmenu)
{
if (_hasSubmenuIndicatorImage)
{
var submenuIndicatorImage = [self valueForThemeAttribute:@"submenu-indicator-image" inState:CPControlSizeThemeStates[correspondingControlSize]];
[_submenuIndicatorView setImage:submenuIndicatorImage];
[_submenuIndicatorView setFrameSize:[submenuIndicatorImage size]];
}
[_submenuIndicatorView setHidden:NO];
var submenuViewFrame = [_submenuIndicatorView frame];
@@ -242,9 +318,9 @@
else
[_submenuIndicatorView setHidden:YES];
height += 2.0 * [self valueForThemeAttribute:@"vertical-margin"];
height += 2.0 * verticalMargin;
imageAndTextViewFrame.origin.y = FLOOR((height - CGRectGetHeight(imageAndTextViewFrame)) / 2.0);
imageAndTextViewFrame.origin.y = FLOOR((height - CGRectGetHeight(imageAndTextViewFrame)) / 2.0) + verticalOffset;
[_imageAndTextView setFrame:imageAndTextViewFrame];
if (hasStateColumn)
@@ -252,7 +328,7 @@
if (hasKeyEquivalent)
{
keyEquivalentViewFrame.origin.y = FLOOR((height - CGRectGetHeight(keyEquivalentViewFrame)) / 2.0);
keyEquivalentViewFrame.origin.y = FLOOR((height - CGRectGetHeight(keyEquivalentViewFrame)) / 2.0) + verticalOffset;
[_keyEquivalentView setFrame:keyEquivalentViewFrame];
}
@@ -277,6 +353,11 @@
_highlighted = shouldHighlight;
var correspondingControlSize = [[self font] controlSizeCorrespondingToFontSize],
// Construct the query state including the view's current theme state (e.g. HUD)
controlSizeState = CPControlSizeThemeStates[correspondingControlSize],
queryState = [self themeState] ? [self themeState].and(controlSizeState) : controlSizeState;
[_imageAndTextView setTextColor:[self textColor]];
[_keyEquivalentView setTextColor:[self textColor]];
[_imageAndTextView setTextShadowColor:[self textShadowColor]];
@@ -286,13 +367,21 @@
{
[self setBackgroundColor:[self valueForThemeAttribute:@"menu-item-selection-color"]];
[_imageAndTextView setImage:[_menuItem alternateImage] || [_menuItem image]];
[_submenuIndicatorView setColor:[self textColor]];
if (_hasSubmenuIndicatorImage)
[_submenuIndicatorView setImage:[self valueForThemeAttribute:@"submenu-indicator-highlighted-image" inState:queryState]];
else
[_submenuIndicatorView setColor:[self textColor]];
}
else
{
[self setBackgroundColor:nil];
[_imageAndTextView setImage:[_menuItem image]];
[_submenuIndicatorView setColor:[self valueForThemeAttribute:@"submenu-indicator-color"]];
if (_hasSubmenuIndicatorImage)
[_submenuIndicatorView setImage:[self valueForThemeAttribute:@"submenu-indicator-image" inState:queryState]];
else
[_submenuIndicatorView setColor:[self valueForThemeAttribute:@"submenu-indicator-color"]];
}
if ([[_menuItem menu] showsStateColumn])
@@ -302,15 +391,15 @@
switch ([_menuItem state])
{
case CPOnState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-on-state-highlighted-image"]];
[_stateView setImage:[_menuItem onStateImage] || [self valueForThemeAttribute:@"menu-item-default-on-state-highlighted-image" inState:queryState]];
break;
case CPOffState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-off-state-highlighted-image"]];
[_stateView setImage:[_menuItem offStateImage] || [self valueForThemeAttribute:@"menu-item-default-off-state-highlighted-image" inState:queryState]];
break;
case CPMixedState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-mixed-state-highlighted-image"]];
[_stateView setImage:[_menuItem mixedImage] || [self valueForThemeAttribute:@"menu-item-default-mixed-state-highlighted-image" inState:queryState]];
break;
default:
@@ -322,15 +411,15 @@
switch ([_menuItem state])
{
case CPOnState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-on-state-image"]];
[_stateView setImage:[_menuItem onStateImage] || [self valueForThemeAttribute:@"menu-item-default-on-state-image" inState:queryState]];
break;
case CPOffState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-off-state-image"]];
[_stateView setImage:[_menuItem offStateImage] || [self valueForThemeAttribute:@"menu-item-default-off-state-image" inState:queryState]];
break;
case CPMixedState:
[_stateView setImage:[self valueForThemeAttribute:@"menu-item-default-mixed-state-image"]];
[_stateView setImage:[_menuItem mixedImage] || [self valueForThemeAttribute:@"menu-item-default-mixed-state-image" inState:queryState]];
break;
default:
@@ -347,6 +436,22 @@
@end
// MARK: -
@implementation _CPMenuItemStandardView (CSSTheming)
// MARK: Override
- (void)_setThemeIncludingDescendants:(CPTheme)aTheme
{
[self setTheme:aTheme];
[[self subviews] makeObjectsPerformSelector:@selector(_setThemeIncludingDescendants:) withObject:aTheme];
}
@end
// MARK: -
@implementation _CPMenuItemSubmenuIndicatorView : CPView
{
CPColor _color;
+47
View File
@@ -83,6 +83,28 @@
return self;
}
// override needed to cancel out the standard HUD propagation
- (void)viewDidMoveToWindow
{
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
// Propagate state to the actual content view (StandardView, Separator, etc.)
if ([_view respondsToSelector:@selector(setThemeState:)])
[_view setThemeState:aState];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
if ([_view respondsToSelector:@selector(unsetThemeState:)])
[_view unsetThemeState:aState];
}
- (CGSize)minSize
{
return _minSize;
@@ -252,6 +274,31 @@
@end
// MARK: -
@implementation _CPMenuItemView (CSSTheming)
// MARK: Override
- (void)_setThemeIncludingDescendants:(CPTheme)aTheme
{
[self setTheme:aTheme];
[_view _setThemeIncludingDescendants:aTheme];
// Items must also perform this (without this, only the selected item does)
[_imageAndTextView _setThemeIncludingDescendants:aTheme];
[_submenuView _setThemeIncludingDescendants:aTheme];
[[_menuItem view] _setThemeIncludingDescendants:aTheme];
if ([_view respondsToSelector:@selector(update)])
[_view update];
}
@end
// MARK: -
@implementation _CPMenuItemArrowView : CPView
{
CPColor _color;
+27 -4
View File
@@ -384,13 +384,35 @@
*/
- (void)_selectionDidChange
{
if (_selection === undefined || _selection === nil)
if (_selection == nil)
_selection = [[CPControllerSelectionProxy alloc] initWithController:self];
[_selection controllerDidChange];
[self didChangeValueForKey:@"selection"];
}
/*!
@ignore
These two private methods map CPTextField notifications to the CPEditorRegistration protocol
This should be generalized in the future:
The CPEditorRegistrationProtocol can be implemented in all controls that support editing, not just CPTextField.
In CPArrayController there are other cases than selection change when we need to review all editor pending changes. They should be covered, including the selection change, by the wider concept described by the methods commitEditing: (forces to end editing) and discardEditing: (pending changes are lost).
*/
- (void)_objectDidBeginEditing:(CPNotification)notification
{
[self objectDidBeginEditing:[notification object]];
}
/*!
@ignore
*/
- (void) _objectDidEndEditing:(CPNotification)notification
{
[self objectDidEndEditing:[notification object]];
}
/*!
@return id - Returns the keys which are being observed.
*/
@@ -770,7 +792,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
}
}
if (value === nil || value.isa && [value isEqual:[CPNull null]])
if (value == nil || value.isa && [value isEqual:[CPNull null]])
value = CPNullMarker;
return value;
@@ -786,7 +808,8 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
var value = [self _controllerMarkerForValues:values];
[_cachedValues setObject:value forKey:theKeyPath];
return value;
// Apple's implementation returns nil instead of CPNullMarker
return value === CPNullMarker ? nil : value;
}
else
return values;
@@ -926,4 +949,4 @@ var CPManagedProxyEntityNameKey = @"CPManagedProxyEntity
[aCoder encodeObject:[self fetchPredicate] forKey:CPManagedProxyFetchPredicateKey];
}
@end
@end
+1014 -142
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -121,8 +121,8 @@ CPDocModalWindowMask = 1 << 6;
}
#pragma mark -
#pragma mark Overrides
// MARK: -
// MARK: Overrides
/*!
@ignore
+1
View File
@@ -46,6 +46,7 @@ CPImagesPboardType = @"CPImagesPboardType";
CPVideosPboardType = @"CPVideosPboardType";
CPRTFPboardType = @"CPRTFPboardType";
_CPSmartPboardType = @"_CPSmartPboardType";
_CPASPboardType = @"_CPASPboardType";
UTF8PboardType = @"public.utf8-plain-text";
+19 -2
View File
@@ -45,6 +45,13 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
return "popup-button";
}
+ (CPDictionary)themeAttributes
{
return @{
@"menu-offset": CGSizeMake(0, 0)
};
}
+ (CPSet)keyPathsForValuesAffectingSelectedIndex
{
return [CPSet setWithObject:@"objectValue"];
@@ -72,6 +79,8 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
if (self)
{
[self setBezelStyle:CPRoundedBezelStyle];
[self selectItemAtIndex:CPNotFound];
_preferredEdge = CPMaxYEdge;
@@ -682,17 +691,25 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
// FIXME: setFont: should set the font on the menu.
[menu setFont:[self font]];
// Propagate the HUD theme state to the menu
if ([self hasThemeState:CPThemeStateHUD])
[menu setThemeState:CPThemeStateHUD];
else
[menu unsetThemeState:CPThemeStateHUD];
if ([self pullsDown])
{
var positionedItem = nil,
location = CGPointMake(0.0, CGRectGetMaxY(bounds) - 1);
menuOffset = [self currentValueForThemeAttribute:@"menu-offset"],
location = CGPointMake(menuOffset.width, CGRectGetMaxY(bounds) + menuOffset.height);
}
else
{
var contentRect = [self contentRectForBounds:bounds],
positionedItem = [self selectedItem],
standardLeftMargin = [_CPMenuWindow _standardLeftMargin] + [_CPMenuItemStandardView _standardLeftMargin],
location = CGPointMake(CGRectGetMinX(contentRect) - standardLeftMargin, 0.0);
menuOffset = [self currentValueForThemeAttribute:@"menu-offset"],
location = CGPointMake(CGRectGetMinX(contentRect) - standardLeftMargin + menuOffset.width, menuOffset.height);
minimumWidth += standardLeftMargin;
+10 -10
View File
@@ -84,8 +84,8 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0,
}
#pragma mark -
#pragma mark Initialization
// MARK: -
// MARK: Initialization
/*!
Initialize the CPPopover witn default values
@@ -105,8 +105,8 @@ var CPPopoverDelegate_popover_willShow_ = 1 << 0,
}
#pragma mark -
#pragma mark Getters / Setters
// MARK: -
// MARK: Getters / Setters
/*!
Returns the current rect of the popover
@@ -220,8 +220,8 @@ Set the behavior of the CPPopover. It can be:
_implementedDelegateMethods |= CPPopoverDelegate_popover_didClose_;
}
#pragma mark -
#pragma mark Positioning
// MARK: -
// MARK: Positioning
/*!
Show the popover
@@ -298,8 +298,8 @@ Set the behavior of the CPPopover. It can be:
}
#pragma mark -
#pragma mark Action
// MARK: -
// MARK: Action
/*!
Close the popover
@@ -318,8 +318,8 @@ Set the behavior of the CPPopover. It can be:
}
#pragma mark -
#pragma mark Delegates
// MARK: -
// MARK: Delegates
/*! @ignore */
- (BOOL)_popoverWindowShouldClose
+121 -33
View File
@@ -43,7 +43,6 @@ CPProgressIndicatorSpinningStyle = 1;
*/
CPProgressIndicatorHUDBarStyle = 2;
var CPProgressIndicatorSpinningStyleColors = [];
/*!
@ingroup appkit
@@ -71,6 +70,43 @@ var CPProgressIndicatorSpinningStyleColors = [];
BOOL _isDisplayedWhenStopped;
}
// Inject CSS Keyframes for spinning animation (Standard + WebKit)
+ (void)initialize
{
if (self !== [CPProgressIndicator class])
return;
#if PLATFORM(DOM)
if (document.getElementById("cp-progress-indicator-style"))
return;
var style = document.createElement("style");
style.id = "cp-progress-indicator-style";
style.type = "text/css";
// We define two animations:
// 1. cp-progress-indicator-spin: Rotates 360 degrees (for spinners)
// 2. cp-progress-indicator-bar-slide: Moves background-position (for striped bars)
var css =
"@keyframes cp-progress-indicator-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } " +
"@-webkit-keyframes cp-progress-indicator-spin { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(360deg); } } " +
"@keyframes cp-progress-indicator-bar-slide { 0% { background-position: 0 0; } 100% { background-position: 30px 0; } } " +
"@-webkit-keyframes cp-progress-indicator-bar-slide { 0% { background-position: 0 0; } 100% { background-position: 30px 0; } }";
if (style.styleSheet)
style.styleSheet.cssText = css;
else
style.appendChild(document.createTextNode(css));
var head = document.getElementsByTagName("head")[0];
if (head)
head.appendChild(style);
#endif
}
+ (CPString)defaultThemeClass
{
return @"progress-indicator";
@@ -83,12 +119,19 @@ var CPProgressIndicatorSpinningStyleColors = [];
@"bar-color": [CPNull null],
@"default-height": 20,
@"bezel-color": [CPNull null],
@"spinning-mini-gif": [CPNull null],
@"spinning-small-gif": [CPNull null],
@"spinning-regular-gif": [CPNull null],
// CSS Spinner Attributes
@"spinner-color": [CPColor grayColor],
@"spinner-track-color": [CPColor colorWithWhite:0.9 alpha:1.0],
@"spinner-line-width": 3.0,
@"circular-border-color": [CPNull null],
@"circular-border-size": 1,
@"circular-color": [CPNull null]
@"circular-color": [CPNull null],
@"spinning-mini-gif": [CPNull null],
@"spinning-small-gif": [CPNull null],
@"spinning-regular-gif": [CPNull null]
};
}
@@ -138,6 +181,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
_isAnimating = YES;
[self _hideOrDisplay];
[self setNeedsLayout]; // Trigger layout to update CSS animation state
}
/*!
@@ -149,6 +193,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
_isAnimating = NO;
[self _hideOrDisplay];
[self setNeedsLayout]; // Trigger layout to remove CSS animation state
}
/*!
@@ -233,7 +278,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
_controlSize = aControlSize;
[self updateBackgroundColor];
[self setNeedsLayout];
}
/*!
@@ -285,7 +330,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
_indeterminate = indeterminate;
[self updateBackgroundColor];
[self setNeedsLayout];
}
/*!
@@ -307,9 +352,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
_style = aStyle;
[self setTheme:(_style === CPProgressIndicatorHUDBarStyle) ? [CPTheme defaultHudTheme] : [CPTheme defaultTheme]];
[self updateBackgroundColor];
[self setNeedsLayout];
}
/*!
@@ -318,7 +361,14 @@ var CPProgressIndicatorSpinningStyleColors = [];
- (void)sizeToFit
{
if (_style == CPProgressIndicatorSpinningStyle)
[self setFrameSize:[[CPProgressIndicatorSpinningStyleColors[_controlSize] patternImage] size]];
{
var size = 32.0;
if (_controlSize === CPMiniControlSize) size = 16.0;
else if (_controlSize === CPSmallControlSize) size = 24.0;
else if (_controlSize === CPRegularControlSize) size = 32.0;
[self setFrameSize:CGSizeMake(size, size)];
}
else
[self setFrameSize:CGSizeMake(CGRectGetWidth([self frame]), [self valueForThemeAttribute:@"default-height"])];
}
@@ -381,6 +431,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aViewName
{
// Handle the standard Bar View
if (aViewName === @"bar-view" && _style !== CPProgressIndicatorSpinningStyle)
{
var width = CGRectGetWidth([self bounds]),
@@ -394,41 +445,78 @@ var CPProgressIndicatorSpinningStyleColors = [];
return CGRectMake(0, 0, barWidth, [self valueForThemeAttribute:@"default-height"]);
}
return nil;
}
/* @ignore */
- (void)updateBackgroundColor
{
if ([CPProgressIndicatorSpinningStyleColors count] === 0)
// Handle the Spinning View (CSS Spinner)
if (aViewName === @"spinner-view" && _style == CPProgressIndicatorSpinningStyle && _indeterminate)
{
CPProgressIndicatorSpinningStyleColors[CPMiniControlSize] = [self valueForThemeAttribute:@"spinning-mini-gif"];
CPProgressIndicatorSpinningStyleColors[CPSmallControlSize] = [self valueForThemeAttribute:@"spinning-small-gif"];
CPProgressIndicatorSpinningStyleColors[CPRegularControlSize] = [self valueForThemeAttribute:@"spinning-regular-gif"];
return [self bounds];
}
[self setNeedsLayout];
// Return nil for views that shouldn't appear in the current style
return nil;
}
- (void)layoutSubviews
{
if (YES)//_isBezeled)
{
// === SPINNING STYLE ===
if (_style == CPProgressIndicatorSpinningStyle)
{
if (!_indeterminate)
return;
// If indeterminate, use CSS spinner
if (_indeterminate)
{
var spinnerView = [self layoutEphemeralSubviewNamed:"spinner-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:nil];
// Ensure other views are hidden
[self layoutEphemeralSubviewNamed:"bar-view" positioned:CPWindowBelow relativeToEphemeralSubviewNamed:nil];
// This will cause the bar view to go away due to having a nil rect when _style == CPProgressIndicatorSpinningStyle.
[self layoutEphemeralSubviewNamed:"bar-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
// Configure CSS on the subview, NOT self._DOMElement, to avoid transform conflicts
var domEl = spinnerView._DOMElement,
spinnerColor = [self currentValueForThemeAttribute:@"spinner-color"],
trackColor = [self currentValueForThemeAttribute:@"spinner-track-color"],
lineWidth = [self currentValueForThemeAttribute:@"spinner-line-width"],
widthStr = lineWidth + "px";
[self setBackgroundColor:CPProgressIndicatorSpinningStyleColors[_controlSize]];
domEl.style.boxSizing = "border-box";
domEl.style.borderRadius = "50%";
domEl.style.borderStyle = "solid";
domEl.style.borderWidth = widthStr;
domEl.style.borderColor = [trackColor cssString];
domEl.style.borderTopColor = [spinnerColor cssString];
// Animation logic
if (_isAnimating)
{
var anim = "cp-progress-indicator-spin 1s linear infinite";
domEl.style.animation = anim;
domEl.style.WebkitAnimation = anim;
}
else
{
domEl.style.animation = "none";
domEl.style.WebkitAnimation = "none";
}
// Ensure main view is transparent
[self setBackgroundColor:nil];
}
else
{
// Determinate Spinner (Pie Chart drawn in drawRect)
// Hide CSS spinner
[self layoutEphemeralSubviewNamed:"spinner-view" positioned:CPWindowBelow relativeToEphemeralSubviewNamed:nil];
[self setBackgroundColor:nil];
}
}
// === BAR STYLE ===
else
{
// Hide spinner
[self layoutEphemeralSubviewNamed:"spinner-view" positioned:CPWindowBelow relativeToEphemeralSubviewNamed:nil];
[self setBackgroundColor:[self currentValueForThemeAttribute:@"bezel-color"]];
var barView = [self layoutEphemeralSubviewNamed:"bar-view"
@@ -447,6 +535,8 @@ var CPProgressIndicatorSpinningStyleColors = [];
- (void)drawRect:(CGRect)aRect
{
// Handle determinate state for Spinning style (Pie chart progress) via CoreGraphics.
// If indeterminate, the CSS animation (spinner-view) takes over and we draw nothing.
if (_style == CPProgressIndicatorSpinningStyle && !_indeterminate)
{
var context = [[CPGraphicsContext currentContext] graphicsPort],
@@ -512,7 +602,7 @@ var CPProgressIndicatorSpinningStyleColors = [];
_isDisplayedWhenStoppedSet = [aCoder decodeObjectForKey:@"_isDisplayedWhenStoppedSet"];
_isDisplayedWhenStopped = [aCoder decodeObjectForKey:@"_isDisplayedWhenStopped"];
[self updateBackgroundColor];
[self setNeedsLayout];
}
return self;
@@ -520,8 +610,6 @@ var CPProgressIndicatorSpinningStyleColors = [];
- (void)encodeWithCoder:(CPCoder)aCoder
{
// Don't encode the background colour. It can be recreated based on the flags
// and if encoded causes hardcoded image paths in the cib while just wasting space.
var backgroundColor = [self backgroundColor];
[self setBackgroundColor:nil];
[super encodeWithCoder:aCoder];
+109 -11
View File
@@ -67,6 +67,18 @@ CPRadioImageOffset = 4.0;
[[button1 radioGroup] selectedRadio] returns the currently selected
option.
UPDATE 09/2020 : Implementation of modern Cocoa behavior :
As in Cocoa, radio buttons grouping is now automatic.
To be associated in a common group (and so being mutually exclusive),
radio buttons must combine 2 criteria :
- same superview (enclosing view)
- same action
TODO: This first implementation uses "as is" CPRadioGroup. This could
be simplified (no more need for radio group action, for example)
*/
@implementation CPRadio : CPButton
{
@@ -160,6 +172,71 @@ CPRadioImageOffset = 4.0;
[CPApp sendAction:[_radioGroup action] to:[_radioGroup target] from:_radioGroup];
}
- (void)viewDidMoveToSuperview
{
[self _setRadioGroup];
[super viewDidMoveToSuperview];
}
- (void)setAction:(SEL)anAction
{
if (anAction === _action)
return;
[super setAction:anAction];
[self _setRadioGroup];
}
// MARK: Private methods
- (void)_setRadioGroup
{
// Implementation of modern Cocoa behavior : automatic radio group
// If no action is set or no superview, no grouping can be done.
if (![self action] || ![self superview])
{
// If this radio is in a group (size > 1), remove it.
if ([[self radioGroup] size] > 1)
{
[self setRadioGroup:[CPRadioGroup new]];
if ([self state] === CPOnState)
[_radioGroup _setSelectedRadio:self];
}
return;
}
// Search in superview subviews for other radio buttons having the same action.
// Take the one with the radio group having the greatest number of members.
var radioGroup;
for (var i = 0, superviewSubviews = [[self superview] subviews], count = [superviewSubviews count], aSubview, myAction = [self action], radioGroupSize = -1; (i < count); i++)
{
aSubview = superviewSubviews[i];
if ([aSubview isKindOfClass:CPRadio] && (aSubview !== self) && ([aSubview action] === myAction) && ([[aSubview radioGroup] size] > radioGroupSize))
{
radioGroup = [aSubview radioGroup];
radioGroupSize = [radioGroup size];
}
}
if (radioGroup)
[self setRadioGroup:radioGroup];
else
// No other radio buttons to group with found.
// It may be because this radio button was in a radio group and its action was changed.
// If this is the case, we must reisolate it in a new radio group.
if ([_radioGroup size] > 1)
[self setRadioGroup:[CPRadioGroup new]];
if ([self state] === CPOnState)
[_radioGroup _setSelectedRadio:self];
}
@end
var CPRadioRadioGroupKey = @"CPRadioRadioGroupKey";
@@ -183,21 +260,37 @@ var CPRadioRadioGroupKey = @"CPRadioRadioGroupKey";
[aCoder encodeObject:_radioGroup forKey:CPRadioRadioGroupKey];
}
- (CPImage)image
// MARK: -
// MARK: Override methods from CPButton
- (CPThemeState)_contentVisualState
{
return [self currentValueForThemeAttribute:@"image"];
// Note : Behavior differs from CPButton as title doesn't follow the highlightsBy content flag
var visualState = [self themeState] || CPThemeStateNormal, // Needed during theme compilation
currentState = [self state];
if ((currentState !== CPOffState) && (_showsStateBy & CPContentsCellMask))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
return visualState;
}
- (CPImage)alternateImage
- (CPThemeState)_imageVisualState
{
return [self currentValueForThemeAttribute:@"image"];
}
// Note : Behavior differs from CPButton as we don't force "not selected" theme state
// when button is highglighted and selected
- (BOOL)startTrackingAt:(CGPoint)aPoint
{
var startedTracking = [super startTrackingAt:aPoint];
[self highlight:YES];
return startedTracking;
var visualState = [self themeState] || CPThemeStateNormal, // Needed during theme compilation
currentState = [self state];
if (_isHighlighted && (_highlightsBy & CPContentsCellMask))
visualState = visualState.and(CPThemeStateHighlighted);
if ((currentState !== CPOffState) && (_showsStateBy & CPContentsCellMask))
visualState = visualState.and((currentState === CPOnState) ? CPThemeStateSelected : CPButtonStateMixed);
return visualState;
}
@end
@@ -304,6 +397,11 @@ var CPRadioRadioGroupKey = @"CPRadioRadioGroupKey";
return _radios;
}
- (int)size
{
return [_radios count];
}
- (void)setEnabled:(BOOL)enabled
{
[_radios makeObjectsPerformSelector:@selector(setEnabled:) withObject:enabled];
@@ -314,7 +412,7 @@ var CPRadioRadioGroupKey = @"CPRadioRadioGroupKey";
[_radios makeObjectsPerformSelector:@selector(setHidden:) withObject:hidden];
}
#pragma mark Private
// MARK: Private
- (void)_addRadio:(CPRadio)aRadio
{
+1 -1
View File
@@ -397,7 +397,7 @@ var CPResponderNextResponderKey = @"CPResponderNextResponderKey",
- (void)encodeWithCoder:(CPCoder)aCoder
{
// This will come out nil on the other side with decodeObjectForKey:
if (_nextResponder !== nil)
if (_nextResponder != nil)
[aCoder encodeConditionalObject:_nextResponder forKey:CPResponderNextResponderKey];
[aCoder encodeObject:_menu forKey:CPResponderMenuKey];
+11 -6
View File
@@ -34,7 +34,7 @@
SEL _predicateAction @accessors(property=action);
}
#pragma mark public methods
// MARK: public methods
/*!
@ingroup appkit
@class CPPredicateEditor
@@ -251,7 +251,7 @@
return tree;
}
#pragma mark Set the Predicate
// MARK: Set the Predicate
- (void)setObjectValue:(id)objectValue
{
@@ -269,6 +269,8 @@
_currentAnimation = nil;
_sendAction = NO;
var rows = [];
if (predicate != nil)
{
if ((_nestingMode == CPRuleEditorNestingModeSimple || _nestingMode == CPRuleEditorNestingModeCompound)
@@ -276,10 +278,13 @@
predicate = [[CPCompoundPredicate alloc] initWithType:[self _compoundPredicateTypeForRootRows] subpredicates:[CPArray arrayWithObject:predicate]];
var row = [self _rowObjectFromPredicate:predicate];
if (row != nil)
[_boundArrayOwner setValue:[CPArray arrayWithObject:row] forKey:_boundArrayKeyPath];
[rows addObject:row];
}
[_boundArrayOwner setValue:rows forKey:_boundArrayKeyPath];
[self setAnimation:animation];
}
@@ -369,7 +374,7 @@
return row;
}
#pragma mark Get the predicate
// MARK: Get the predicate
- (void)_updatePredicate
{
@@ -447,7 +452,7 @@
return CPAndPredicateType;
}
#pragma mark Control delegate
// MARK: Control delegate
- (void)_sendRuleAction
{
@@ -482,7 +487,7 @@
}
*/
#pragma mark RuleEditor delegate methods
// MARK: RuleEditor delegate methods
- (int)_queryNumberOfChildrenOfItem:(id)rowItem withRowType:(CPRuleEditorRowType)type
{
+189 -70
View File
@@ -80,6 +80,35 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
@n An ordered to-many relation containing the display values for the row.
@n@n @c @@"criteria"
@n An ordered to-many relation containing the criteria for the row.
@n@n
Localization & Positional Reordering
@n
CPRuleEditor supports complete localization of menu items and grammatical positional reordering (sentence structure layout adjustment) via strings resource files (.strings) or custom programmatic CPDictionary tables.
@n@n
Since sentence structures vary significantly across languages, the editor can dynamically reposition views (such as popups, static labels, and text fields) from left to right to form grammatically correct sentences.
@n@n
Formatting Keys (English representation):
@n @c %[%]@@
@n Represents a popup button displaying its selected value (e.g. @c %[firstName]@@).
@n @c %@@
@n Represents an editable text input field.
@n Static text represents a literal label placed directly inside the formatting key.
@n@n
Example English format key:
@n @c "%[firstName]@ %[is equal to]@ %@"
@n@n
Translation Patterns (Target language):
@n Positional specifiers such as @c %1$@@, @c %2$@@, @c %3$@@ dictate the visual order of views from left to right.
@n Bracketed values inside positional specifiers (e.g. @c %1$[Nombre]@@) define the localized title for popup selection items.
@n Literal text outside the specifiers (such as @c "y" or @c "und") is automatically instantiated as static text labels positioned between controls.
@n@n
Example translations:
@n@n
Spanish (Reorders to: [1: Name] y [3: Value] [2: are equal]):
@n @c "%[firstName]@ %[is equal to]@ %@" = "%1$[Nombre]@ y %3$@ %2$[son iguales]@";
@n@n
German (Reorders to: [1: First Name] und [3: Value] [2: are equal]):
@n @c "%[firstName]@ %[is equal to]@ %@" = "%1$[Vorname]@ und %3$@ %2$[sind gleich]@";
*/
@implementation CPRuleEditor : CPControl
@@ -127,7 +156,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
BOOL _isKeyDown;
BOOL _nestingModeDidChange;
_CPRuleEditorLocalizer _standardLocalizer @accessors(property=standardLocalizer);
_CPRuleEditorLocalizer _standardLocalizer;
CPDictionary _itemsAndValuesToAddForRowType;
}
@@ -157,7 +186,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self !== nil)
if (self)
{
_slices = [[CPMutableArray alloc] init];
@@ -207,8 +236,34 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
[self registerForDraggedTypes:[CPArray arrayWithObjects:CPRuleEditorItemPBoardType,nil]];
[_boundArrayOwner addObserver:self forKeyPath:_boundArrayKeyPath options:CPKeyValueObservingOptionOld | CPKeyValueObservingOptionNew context:boundArrayContext];
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(_ruleEditorLocalizerDidLoad:)
name:@"_CPRuleEditorLocalizerDidLoadNotification"
object:nil];
}
- (void)_ruleEditorLocalizerDidLoad:(CPNotification)aNotification
{
if ([aNotification object] === [self standardLocalizer])
{
// Defer execution to the next run loop cycle so that any active slice
// insertions have fully completed and are present in the `_slices` array.
[[CPRunLoop mainRunLoop] performBlock:function() {
var count = [_slices count];
for (var i = 0; i < count; i++)
{
var slice = [_slices objectAtIndex:i];
[slice _reconfigureSubviews];
[slice _updateButtonVisibilities]; // Force updates on row button tooltips
}
[self _updatePredicate];
[self _sendRuleAction];
} argument:nil order:0 modes:[CPDefaultRunLoopMode]];
}
}
/*! @endcond */
/*!
@@ -384,7 +439,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
*/
- (CPDictionary)formattingDictionary
{
return [_standardLocalizer dictionary];
return [[self standardLocalizer] dictionary];
}
/*!
@@ -396,6 +451,9 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
*/
- (void)setFormattingDictionary:(CPDictionary)dictionary
{
if (_standardLocalizer == nil)
_standardLocalizer = [_CPRuleEditorLocalizer new];
[_standardLocalizer setDictionary:dictionary];
_stringsFilename = nil;
}
@@ -419,7 +477,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
*/
- (void)setFormattingStringsFilename:(CPString)stringsFilename
{
if (_standardLocalizer === nil)
if (_standardLocalizer == nil)
_standardLocalizer = [_CPRuleEditorLocalizer new];
if (_stringsFilename !== stringsFilename)
@@ -427,19 +485,32 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
// Convert an empty string to nil
_stringsFilename = stringsFilename || nil;
if (stringsFilename !== nil)
if (stringsFilename != nil)
{
if (![stringsFilename hasSuffix:@".strings"])
stringsFilename = stringsFilename + @".strings";
var path = [[CPBundle mainBundle] pathForResource:stringsFilename];
if (path !== nil)
if (path != nil)
[_standardLocalizer loadContentOfURL:[CPURL URLWithString:path]];
}
}
}
- (_CPRuleEditorLocalizer)standardLocalizer
{
if (_standardLocalizer == nil)
_standardLocalizer = [_CPRuleEditorLocalizer new];
return _standardLocalizer;
}
- (void)setStandardLocalizer:(_CPRuleEditorLocalizer)aLocalizer
{
_standardLocalizer = aLocalizer;
}
/*!
@name Providing Data
*/
@@ -465,7 +536,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
*/
- (void)setCriteria:(CPArray)criteria andDisplayValues:(CPArray)values forRowAtIndex:(int)rowIndex
{
if (criteria === nil || values === nil)
if (criteria == nil || values == nil)
[CPException raise:CPInvalidArgumentException reason:_cmd + @". criteria and values parameters must not be nil."];
if (rowIndex < 0 || rowIndex >= [self numberOfRows])
@@ -538,7 +609,7 @@ var CPRuleEditorItemPBoardType = @"CPRuleEditorItemPBoardType",
if ([self rowTypeForRow:current_index] === CPRuleEditorRowTypeCompound)
{
var candidate = [[self _rowCacheForIndex:current_index] rowObject],
subObjects = [[self _subrowObjectsOfObject:candidate] _representedObject];
subObjects = [self _subrowObjectsOfObject:candidate]; // Standard direct array query
if ([subObjects indexOfObjectIdenticalTo:targetObject] !== CPNotFound)
return current_index;
@@ -605,7 +676,7 @@ TODO: implement
for (var i = rowIndex + 1; i < count; i++)
{
var candidate = [[self _rowCacheForIndex:i] rowObject],
indexInSubrows = [[subobjects _representedObject] indexOfObjectIdenticalTo:candidate];
indexInSubrows = [subobjects indexOfObjectIdenticalTo:candidate]; // Standard direct array query
if (indexInSubrows !== CPNotFound)
{
@@ -774,7 +845,7 @@ TODO: implement
while (current_index !== CPNotFound)
{
var rowObject = [[self _rowCacheForIndex:current_index] rowObject],
relativeChildIndex = [[subrows _representedObject] indexOfObjectIdenticalTo:rowObject];
relativeChildIndex = [subrows indexOfObjectIdenticalTo:rowObject]; // Standard direct array query
if (relativeChildIndex !== CPNotFound)
[childsIndexes addIndex:relativeChildIndex];
@@ -831,7 +902,6 @@ TODO: implement
for (i = 0; i < count; i++)
{
var item = [items objectAtIndex:i],
//var displayValue = [self _queryValueForItem:item inRow:aRow]; Ask the delegate or get cached value ?.
displayValue = [[self displayValuesForRow:aRow] objectAtIndex:i],
predpart = [self _sendDelegateRuleEditorPredicatePartsForCriterion:item withDisplayValue:displayValue inRow:aRow];
@@ -849,10 +919,11 @@ TODO: implement
return nil;
var current_index = [subrowsIndexes firstIndex];
while (current_index !== CPNotFound)
{
var subpredicate = [self predicateForRow:current_index];
if (subpredicate !== nil)
if (subpredicate != nil)
[subpredicates addObject:subpredicate];
current_index = [subrowsIndexes indexGreaterThanIndex:current_index];
@@ -888,33 +959,33 @@ TODO: implement
modifier = [predicateParts objectForKey:CPRuleEditorPredicateComparisonModifier],
selector = CPSelectorFromString([predicateParts objectForKey:CPRuleEditorPredicateCustomSelector]);
if (lhs === nil)
if (lhs == nil)
{
CPLogConsole(@"missing left expression in predicate parts dictionary");
return NULL;
}
if (rhs === nil)
if (rhs == nil)
{
CPLogConsole(@"missing right expression in predicate parts dictionary");
return NULL;
}
if (selector === nil && operator === nil)
if (selector == nil && operator == nil)
{
CPLogConsole(@"missing operator and selector in predicate parts dictionary");
return NULL;
}
if (modifier === nil)
if (modifier == nil)
CPLogConsole(@"missing modifier in predicate parts dictionary. Setting default: CPDirectPredicateModifier");
if (options === nil)
if (options == nil)
CPLogConsole(@"missing options in predicate parts dictionary. Setting default: CPCaseInsensitivePredicateOption");
try
{
if (selector !== nil)
if (selector != nil)
predicate = [CPComparisonPredicate predicateWithLeftExpression:lhs
rightExpression:rhs
customSelector:selector
@@ -1167,7 +1238,7 @@ TODO: implement
- (BOOL)_wantsRowAnimations
{
return (_currentAnimation !== nil);
return (_currentAnimation != nil);
}
- (void)_updateButtonVisibilities
@@ -1233,7 +1304,7 @@ TODO: implement
return shouldHide;
}
#pragma mark Rows management
// MARK: Rows management
- (id)_rowCacheForIndex:(int)index
{
@@ -1278,23 +1349,28 @@ TODO: implement
while (current_index !== CPNotFound)
{
var parentIndex = [self parentRowForRow:current_index],
subrowsIndexes = [self subrowIndexesForRow:parentIndex];
if ([subrowsIndexes count] === 1)
var parentIndex = [self parentRowForRow:current_index];
// If the row has a valid parent in the editor (i.e. not a root row)
if (parentIndex !== -1)
{
if (parentIndex !== -1)
return [CPIndexSet indexSetWithIndex:0];
var subrowsIndexes = [self subrowIndexesForRow:parentIndex];
var childlessGranPa = [self _childlessParentsIfSlicesWereDeletedAtIndexes:[CPIndexSet indexSetWithIndex:parentIndex]];
[childlessParents addIndexes:childlessGranPa];
// If deleting this row leaves the parent with no remaining child rows
if ([subrowsIndexes count] === 1)
{
[childlessParents addIndex:parentIndex];
// Recursively check if deleting this parent row leaves the grandparent childless
var childlessGranPa = [self _childlessParentsIfSlicesWereDeletedAtIndexes:[CPIndexSet indexSetWithIndex:parentIndex]];
[childlessParents addIndexes:childlessGranPa];
}
}
current_index = [indexes indexGreaterThanIndex:current_index];
}
return childlessParents;
// (id)-[RuleEditor _includeSubslicesForSlicesAtIndexes:]
}
- (CPIndexSet)_includeSubslicesForSlicesAtIndexes:(CPIndexSet)indexes
@@ -1356,8 +1432,25 @@ TODO: implement
if ([self rowTypeForRow:row] === type && itemIndex < [aCriteria count])
{
var crit = [aCriteria objectAtIndex:itemIndex];
[current_criterions addObject:crit];
// Verify that this row's parent path matches the path currently being built
var pathMatches = true;
for (var p = 0; p < itemIndex; p++)
{
var criterionA = [aCriteria objectAtIndex:p],
criterionB = [items objectAtIndex:p];
if (criterionA !== criterionB && (typeof criterionA.isEqual !== "function" || ![criterionA isEqual:criterionB]))
{
pathMatches = false;
break;
}
}
if (pathMatches)
{
var crit = [aCriteria objectAtIndex:itemIndex];
[current_criterions addObject:crit];
}
}
}
@@ -1473,7 +1566,7 @@ TODO: implement
return row;
}
#pragma mark Key value observing
// MARK: Key value observing
- (void)_startObservingRowObjectsRecursively:(CPArray)rowObjects
{
@@ -1753,7 +1846,7 @@ TODO: implement
{
var subpredicate = [self predicateForRow:current_index];
if (subpredicate !== nil)
if (subpredicate != nil)
[subpredicates addObject:subpredicate];
current_index = [subindexes indexGreaterThanIndex:current_index];
@@ -1774,7 +1867,12 @@ TODO: implement
- (_CPRuleEditorViewSliceRow)_createNewSliceWithFrame:(CGRect)frame ruleEditorView:(CPRuleEditor)editor
{
return [[_CPRuleEditorViewSliceRow alloc] initWithFrame:frame ruleEditorView:editor];
var slice = [[_CPRuleEditorViewSliceRow alloc] initWithFrame:frame ruleEditorView:editor];
// Ensure the slice resizes with the editor
[slice setAutoresizingMask:CPViewWidthSizable];
return slice;
}
- (void)_reconfigureSubviewsAnimate:(BOOL)animate
@@ -1795,7 +1893,7 @@ TODO: implement
startRect = [aslice frame],
startIndex = [aslice rowIndex] - 1;
if ([aslice superview] === nil)
if ([aslice superview] == nil)
{
startRect = CGRectMake(0, startIndex * _sliceHeight, CGRectGetWidth(startRect), _sliceHeight);
[aslice _reconfigureSubviews];
@@ -1859,57 +1957,63 @@ TODO: implement
- (CPArray)_backgroundColors
{
return [self valueForThemeAttribute:@"alternating-row-colors"];
return [self currentValueForThemeAttribute:@"alternating-row-colors"];
}
- (CPColor)_selectedRowColor
{
return [self valueForThemeAttribute:@"selected-color"];
return [self currentValueForThemeAttribute:@"selected-color"];
}
- (CPColor)_sliceTopBorderColor
{
return [self valueForThemeAttribute:@"slice-top-border-color"];
return [self currentValueForThemeAttribute:@"slice-top-border-color"];
}
- (CPColor)_sliceBottomBorderColor
{
return [self valueForThemeAttribute:@"slice-bottom-border-color"];
return [self currentValueForThemeAttribute:@"slice-bottom-border-color"];
}
- (CPColor)_sliceLastBottomBorderColor
{
return [self valueForThemeAttribute:@"slice-last-bottom-border-color"];
return [self currentValueForThemeAttribute:@"slice-last-bottom-border-color"];
}
- (CPFont)font
{
return [self valueForThemeAttribute:@"font"];
return [self currentValueForThemeAttribute:@"font"];
}
- (CPColor)_fontColor
{
return [self valueForThemeAttribute:@"font-color"];
return [self currentValueForThemeAttribute:@"font-color"];
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
[_slices makeObjectsPerformSelector:@selector(setThemeState:) withObject:aState];
}
- (CPImage)_imageAdd
{
return [self valueForThemeAttribute:@"add-image" inState:CPThemeStateNormal];
return [self valueForThemeAttribute:@"add-image" inState:CPThemeStateNormal.and([self themeState])];
}
- (CPImage)_imageAddHighlighted
{
return [self valueForThemeAttribute:@"add-image" inState:CPThemeStateHighlighted];
return [self valueForThemeAttribute:@"add-image" inState:CPThemeStateHighlighted.and([self themeState])];
}
- (CPImage)_imageRemove
{
return [self valueForThemeAttribute:@"remove-image" inState:CPThemeStateNormal];
return [self valueForThemeAttribute:@"remove-image" inState:CPThemeStateNormal.and([self themeState])];
}
- (CPImage)_imageRemoveHighlighted
{
return [self valueForThemeAttribute:@"remove-image" inState:CPThemeStateHighlighted];
return [self valueForThemeAttribute:@"remove-image" inState:CPThemeStateHighlighted.and([self themeState])];
}
- (CPVerticalTextAlignment)_verticalAlignment
@@ -1919,17 +2023,17 @@ TODO: implement
- (CPString)_toolTipForAddCompoundRowButton
{
return [_standardLocalizer localizedStringForString:@"Add compound row"];
return [[self standardLocalizer] localizedStringForString:@"Add compound row"];
}
- (CPString)_toolTipForAddSimpleRowButton
{
return [_standardLocalizer localizedStringForString:@"Add row"];
return [[self standardLocalizer] localizedStringForString:@"Add row"];
}
- (CPString)_toolTipForDeleteRowButton
{
return [_standardLocalizer localizedStringForString:@"Delete row"];
return [[self standardLocalizer] localizedStringForString:@"Delete row"];
}
- (void)_updateSliceIndentations
@@ -2121,7 +2225,13 @@ TODO: implement
return;
var point = [self convertPoint:[event locationInWindow] fromView:nil],
view = [_slices objectAtIndex:FLOOR(MAX(0, point.y) / _sliceHeight)];
index = FLOOR(MAX(0, point.y) / _sliceHeight);
// Check bounds before accessing the array to prevent CPRangeException
if (index >= [_slices count])
return;
var view = [_slices objectAtIndex:FLOOR(MAX(0, point.y) / _sliceHeight)];
if ([self _dragShouldBeginFromMouseDown:view])
[self _performDragForSlice:view withEvent:event];
@@ -2129,7 +2239,7 @@ TODO: implement
- (BOOL)_dragShouldBeginFromMouseDown:(CPView)view
{
return (([self nestingMode] === CPRuleEditorNestingModeList || [view rowIndex] !== 0) && _editable && [view isKindOfClass:[_CPRuleEditorViewSliceRow class]] && _draggingRows === nil);
return (([self nestingMode] === CPRuleEditorNestingModeList || [view rowIndex] !== 0) && _editable && [view isKindOfClass:[_CPRuleEditorViewSliceRow class]] && _draggingRows == nil);
}
- (BOOL)_performDragForSlice:(id)slice withEvent:(CPEvent)event
@@ -2244,33 +2354,41 @@ TODO: implement
- (BOOL)performDragOperation:(id /*< CPDraggingInfo >*/)info
{
var aboveInsertIndexCount = 0,
object,
removeIndex;
var object;
var rowObjects = [_rowCache valueForKey:@"rowObject"],
index = [_draggingRows lastIndex];
var parentRowIndex = [self parentRowForRow:index], // first index of draggingrows
var firstDraggingIndex = [_draggingRows firstIndex],
parentRowIndex = [self parentRowForRow:firstDraggingIndex],
parentRowObject = (parentRowIndex === -1) ? _boundArrayOwner : [[self _rowCacheForIndex:parentRowIndex] rowObject],
insertIndex = _subviewIndexOfDropLine;
while (index !== CPNotFound)
{
if (index >= insertIndex)
// Identify if this row's parent is also inside the dragging set.
// If it is, we skip it because it will move automatically with its parent.
var parentOfCurrent = [self parentRowForRow:index];
if (parentOfCurrent !== -1 && [_draggingRows containsIndex:parentOfCurrent])
{
removeIndex = index + aboveInsertIndexCount;
aboveInsertIndexCount += 1;
}
else
{
removeIndex = index;
insertIndex -= 1;
index = [_draggingRows indexLessThanIndex:index];
continue;
}
object = [rowObjects objectAtIndex:removeIndex];
[self removeRowAtIndex:removeIndex];
[[self _subrowObjectsOfObject:parentRowObject] insertObject:object atIndex:insertIndex - parentRowIndex - 1];
object = [rowObjects objectAtIndex:index];
// Find the current live index of the object inside the editor
var cache = [self _searchCacheForRowObject:object];
var liveIndex = [_rowCache indexOfObjectIdenticalTo:cache];
if (liveIndex !== CPNotFound)
{
if (liveIndex < insertIndex)
insertIndex -= 1;
[self removeRowAtIndex:liveIndex];
[[self _subrowObjectsOfObject:parentRowObject] insertObject:object atIndex:insertIndex - parentRowIndex - 1];
}
index = [_draggingRows indexLessThanIndex:index];
}
@@ -2280,6 +2398,7 @@ TODO: implement
return YES;
}
- (CPIndexSet)_draggingTypes
{
return [CPIndexSet indexSetWithIndex:CPDragOperationMove];
@@ -2321,7 +2440,7 @@ TODO: implement
- (void)_postRowCountChangedNotificationOfType:(CPString)notificationName indexes:indexes
{
var userInfo = indexes === nil ? @{} : @{ "indexes": indexes };
var userInfo = indexes == nil ? @{} : @{ "indexes": indexes };
[[CPNotificationCenter defaultCenter] postNotificationName:notificationName object:self userInfo:userInfo];
}
@@ -2386,7 +2505,7 @@ TODO: implement
var criteria = [self criteriaForRow:aRow];
indexofCriterion = [criteria indexOfObject:criterion];
if (parentItem !== nil
if (parentItem != nil
&& indexofCriterion !== CPNotFound
&& indexofCriterion < [criteria count] - 1)
{
@@ -2469,7 +2588,7 @@ var CPRuleEditorAlignmentGridWidthKey = @"CPRuleEditorAlignmentGridWidth",
- (id)initWithCoder:(CPCoder)coder
{
self = [super initWithCoder:coder];
if (self !== nil)
if (self)
{
[self setFormattingStringsFilename:[coder decodeObjectForKey:CPRuleEditorStringsFilenameKey]];
_alignmentGridWidth = [coder decodeFloatForKey:CPRuleEditorAlignmentGridWidthKey];
@@ -2553,7 +2672,7 @@ var CriteriaKey = @"criteria",
- (id)initWithCoder:(CPCoder)coder
{
self = [super init];
if (self !== nil)
if (self)
{
subrows = [coder decodeObjectForKey:SubrowsKey];
criteria = [coder decodeObjectForKey:CriteriaKey];
@@ -131,7 +131,7 @@
{
var title = [self title];
if (title !== nil)
if (title != nil)
return title;
return [self templateView];
+234 -4
View File
@@ -40,7 +40,7 @@ var LocalizerStringsRegex = new RegExp("\"(.+)\"\\s*=\\s*\"(.+)\"\\s*;\\s*(//.+)
- (void)reloadIfNeeded
{
if (connection !== nil) // Connection waiting
if (connection != nil) // Connection waiting
{
connection = nil;
@@ -51,7 +51,7 @@ var LocalizerStringsRegex = new RegExp("\"(.+)\"\\s*=\\s*\"(.+)\"\\s*;\\s*(//.+)
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)rawString
{
if (connection !== nil && rawString !== nil)
if (connection != nil && rawString != nil)
[self loadContent:rawString];
connection = nil;
@@ -77,21 +77,251 @@ var LocalizerStringsRegex = new RegExp("\"(.+)\"\\s*=\\s*\"(.+)\"\\s*;\\s*(//.+)
}
_dictionary = [CPDictionary dictionaryWithDictionary:dict];
// Post notification to let the rule editor know the translation dictionary is ready
[[CPNotificationCenter defaultCenter] postNotificationName:@"_CPRuleEditorLocalizerDidLoadNotification" object:self];
}
- (CPString)localizedStringForString:(CPString)aString
{
[self reloadIfNeeded];
if (_dictionary !== nil && aString !== nil)
if (_dictionary != nil && aString != nil)
{
var localized = [_dictionary objectForKey:aString];
if (localized !== nil)
if (localized != nil)
return localized;
}
return aString;
}
// MARK: - Formatting & Reordering Helpers
- (CPString)_englishRepresentationForView:(id)aView
{
if ([aView isKindOfClass:[CPPopUpButton class]])
{
var selectedItem = [aView selectedItem];
if (selectedItem)
{
var originalTitle = selectedItem._originalTitle;
// Fallback: If not cached directly, inspect representedObject payload dictionary
if (!originalTitle)
{
var rep = [selectedItem representedObject];
if (rep && typeof rep === "object" && [rep respondsToSelector:@selector(objectForKey:)])
{
originalTitle = [rep objectForKey:@"value"];
}
else if (rep && typeof rep === "string")
{
originalTitle = rep;
}
}
if (!originalTitle)
{
originalTitle = [selectedItem title];
}
return "%[" + originalTitle + "]@";
}
return "%[]@";
}
else if ([aView isKindOfClass:[CPTextField class]] && ![aView isEditable])
{
return aView._originalText || [aView stringValue];
}
else
{
return "%@";
}
}
- (CPString)formattingKeyForViews:(CPArray)views
{
var keyParts = [];
var count = [views count];
for (var i = 0; i < count; i++)
{
var view = [views objectAtIndex:i];
[keyParts addObject:[self _englishRepresentationForView:view]];
}
return [keyParts componentsJoinedByString:@" "];
}
- (void)localizeMenuItemsForViews:(CPArray)views
{
var count = [views count];
for (var i = 0; i < count; i++)
{
var view = [views objectAtIndex:i];
if ([view isKindOfClass:[CPPopUpButton class]])
{
var menuItems = [view itemArray];
var menuItemsCount = [menuItems count];
var selectedItem = [view selectedItem];
for (var j = 0; j < menuItemsCount; j++)
{
var item = [menuItems objectAtIndex:j];
if (!item._originalTitle)
{
var rep = [item representedObject];
if (rep && typeof rep === "object" && [rep respondsToSelector:@selector(objectForKey:)])
{
item._originalTitle = [rep objectForKey:@"value"];
}
else
{
item._originalTitle = [item title];
}
}
// Temporarily select item to generate formatting key context
[view selectItem:item];
var tempKey = [self formattingKeyForViews:views];
var tempPattern = [self localizedStringForString:tempKey];
if (tempPattern !== tempKey)
{
var regex = /%(\d+)\$(?:\[([^\]]+)\])?@/g;
var match;
while ((match = regex.exec(tempPattern)) !== null)
{
var position = parseInt(match[1], 10) - 1;
var translatedValue = match[2];
if (position === i && translatedValue)
{
[item setTitle:translatedValue];
break;
}
}
}
else
{
[item setTitle:item._originalTitle];
}
}
if (selectedItem)
{
[view selectItem:selectedItem];
}
}
}
}
- (CPArray)localizeAndReorderViews:(CPArray)views
{
var key = [self formattingKeyForViews:views];
var localizedPattern = [self localizedStringForString:key];
if (localizedPattern === key)
{
var count = [views count];
for (var i = 0; i < count; i++)
{
var originalView = [views objectAtIndex:i];
if ([originalView isKindOfClass:[CPPopUpButton class]])
{
var selectedItem = [originalView selectedItem];
if (selectedItem && selectedItem._originalTitle)
{
[selectedItem setTitle:selectedItem._originalTitle];
}
}
else if ([originalView respondsToSelector:@selector(setStringValue:)] && originalView._originalText)
{
[originalView setStringValue:originalView._originalText];
if ([originalView isKindOfClass:[CPTextField class]] && ![originalView isEditable])
{
var font = [originalView font] || [CPFont systemFontOfSize:[CPFont systemFontSize]],
size = [originalView._originalText sizeWithFont:font];
[originalView setFrameSize:CGSizeMake(size.width + 4, CGRectGetHeight([originalView frame]))];
}
}
}
return views;
}
var newViews = [CPMutableArray array];
var regex = /%(\d+)\$(?:\[([^\]]+)\])?@/g;
var lastIndex = 0;
var match;
while ((match = regex.exec(localizedPattern)) !== null)
{
var literalText = localizedPattern.substring(lastIndex, match.index);
// Only add a label if there are actual non-whitespace characters (like 'y')
if (literalText.length > 0 && /\S/.test(literalText))
{
var label = [CPTextField labelWithTitle:literalText];
[newViews addObject:label];
}
var position = parseInt(match[1], 10) - 1;
var translatedValue = match[2];
if (position >= 0 && position < [views count])
{
var originalView = [views objectAtIndex:position];
if (translatedValue !== undefined && translatedValue !== null)
{
if ([originalView isKindOfClass:[CPPopUpButton class]])
{
var selectedItem = [originalView selectedItem];
if (selectedItem)
{
if (!selectedItem._originalTitle)
{
selectedItem._originalTitle = [selectedItem title];
}
[selectedItem setTitle:translatedValue];
}
}
else if ([originalView respondsToSelector:@selector(setStringValue:)])
{
[originalView setStringValue:translatedValue];
// Recalculate frame size if it is a static CPTextField to avoid visual clipping
if ([originalView isKindOfClass:[CPTextField class]] && ![originalView isEditable])
{
var font = [originalView font] || [CPFont systemFontOfSize:[CPFont systemFontSize]],
size = [translatedValue sizeWithFont:font];
[originalView setFrameSize:CGSizeMake(size.width + 4, CGRectGetHeight([originalView frame]))];
}
}
}
[newViews addObject:originalView];
}
lastIndex = regex.lastIndex;
}
if (lastIndex < localizedPattern.length)
{
var literalText = localizedPattern.substring(lastIndex);
// Only add a label if there are actual non-whitespace characters
if (literalText.length > 0 && /\S/.test(literalText))
{
var label = [CPTextField labelWithTitle:literalText];
[newViews addObject:label];
}
}
return newViews;
}
@end
+67 -23
View File
@@ -49,6 +49,13 @@
return self;
}
- (void)setRowIndex:(int)anIndex
{
_rowIndex = anIndex;
[self _updateBackgroundColor];
[self setNeedsDisplay:YES];
}
- (void)_setSelected:(BOOL)select
{
if (select == _selected)
@@ -57,6 +64,47 @@
var selector = select ? @selector(setThemeState:) : @selector(unsetThemeState:);
[[self subviews] makeObjectsPerformSelector:selector withObject:CPThemeStateSelectedDataView];
_selected = select;
[self _updateBackgroundColor];
[self setNeedsDisplay:YES];
}
- (void)_updateBackgroundColor
{
var color = nil;
if ([self _isSelected])
{
color = [_ruleEditor _selectedRowColor];
}
else
{
var colors = [_ruleEditor _backgroundColors],
count = [colors count];
if (count > 0)
color = [colors objectAtIndex:(_rowIndex % count)];
}
[self setBackgroundColor:color];
}
- (void)viewDidMoveToWindow
{
[super viewDidMoveToWindow];
[self _updateBackgroundColor];
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
[self _updateBackgroundColor];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
[self _updateBackgroundColor];
}
- (void)drawRect:(CGRect)rect
@@ -66,35 +114,31 @@
maxX = CGRectGetWidth(bounds),
maxY = CGRectGetHeight(bounds);
// Draw background
if ([self _isSelected])
_backgroundColor = [_ruleEditor _selectedRowColor];
else
{
var colors = [_ruleEditor _backgroundColors],
count = [colors count];
_backgroundColor = [colors objectAtIndex:(_rowIndex % count)];
}
CGContextSetFillColor(context, _backgroundColor);
CGContextFillRect(context, rect);
// Note: Background is now handled by setBackgroundColor in _updateBackgroundColor
// to support CSS-based colors and transparency correctly.
// Draw Top Border
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, maxX, 0);
CGContextSetStrokeColor(context, [_ruleEditor _sliceTopBorderColor]);
CGContextStrokePath(context);
var topColor = [_ruleEditor _sliceTopBorderColor];
if (topColor)
{
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, maxX, 0);
CGContextSetStrokeColor(context, topColor);
CGContextStrokePath(context);
}
// Draw Bottom Border
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, maxY);
CGContextAddLineToPoint(context, maxX, maxY);
var bottomColor = (_rowIndex == [_ruleEditor _lastRow]) ? [_ruleEditor _sliceLastBottomBorderColor] : [_ruleEditor _sliceBottomBorderColor];
CGContextSetStrokeColor(context, bottomColor);
CGContextStrokePath(context);
if (bottomColor)
{
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, maxY);
CGContextAddLineToPoint(context, maxX, maxY);
CGContextSetStrokeColor(context, bottomColor);
CGContextStrokePath(context);
}
}
- (void)mouseDown:(CPEvent)theEvent
+86 -18
View File
@@ -67,6 +67,23 @@
[self setAutoresizingMask:CPViewWidthSizable];
}
- (void)_setSelected:(BOOL)isSelected
{
[super _setSelected:isSelected];
[self _updateButtonImages];
}
- (void)_updateButtonImages
{
var rowState = [self themeState];
if ([self _isSelected])
rowState = rowState.and(CPThemeStateSelected);
[_addButton setImage:[_ruleEditor valueForThemeAttribute:@"add-image" inState:rowState]];
[_subtractButton setImage:[_ruleEditor valueForThemeAttribute:@"remove-image" inState:rowState]];
}
- (CPButton)_createRowButton
{
var button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
@@ -89,6 +106,8 @@
var button = [self _createRowButton];
[button setToolTip:[_ruleEditor _toolTipForAddSimpleRowButton]];
// Initial setup, _updateButtonImages will be called later to set correct state-based images
[button setValue:[_ruleEditor _imageAdd] forThemeAttribute:@"image" inState:CPThemeStateNormal];
[button setValue:[_ruleEditor _imageAddHighlighted] forThemeAttribute:@"image" inState:CPThemeStateHighlighted];
@@ -103,6 +122,8 @@
var button = [self _createRowButton];
[button setToolTip:[_ruleEditor _toolTipForDeleteRowButton]];
// Initial setup
[button setValue:[_ruleEditor _imageRemove] forThemeAttribute:@"image" inState:CPThemeStateNormal];
[button setValue:[_ruleEditor _imageRemoveHighlighted] forThemeAttribute:@"image" inState:CPThemeStateHighlighted];
@@ -114,8 +135,32 @@
- (CPMenuItem)_createMenuItemWithTitle:(CPString )title
{
title = [[_ruleEditor standardLocalizer] localizedStringForString:title];
return [[CPMenuItem alloc] initWithTitle:title action:nil keyEquivalent:@""];
var originalTitle = title;
var localizedTitle = [[_ruleEditor standardLocalizer] localizedStringForString:title];
var item = [[CPMenuItem alloc] initWithTitle:localizedTitle action:nil keyEquivalent:@""];
// Cache the raw English title for pattern-matching
item._originalTitle = originalTitle;
return item;
}
- (CPTextField)_createStaticTextFieldWithStringValue:(CPString)text
{
var textField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()],
ruleEditorFont = [_ruleEditor font],
font = [CPFont fontWithName:[ruleEditorFont familyName] size:[ruleEditorFont size] + 2],
localizedText = [[_ruleEditor standardLocalizer] localizedStringForString:text],
size = [localizedText sizeWithFont:font];
[textField setFrameSize:CGSizeMake(size.width + 4, [_ruleEditor rowHeight])];
[textField setValue:font forThemeAttribute:@"font"];
[textField setValue:[_ruleEditor _verticalAlignment] forThemeAttribute:@"vertical-alignment"];
[textField setStringValue:localizedText];
// Cache the raw English text for pattern-matching
textField._originalText = text;
return textField;
}
- (CPPopUpButton)_createPopUpButtonWithItems:(CPArray)itemsArray selectedItemIndex:(int)index
@@ -142,22 +187,6 @@
return [CPMenuItem separatorItem];
}
- (CPTextField)_createStaticTextFieldWithStringValue:(CPString)text
{
var textField = [[CPTextField alloc] initWithFrame:CGRectMakeZero()],
ruleEditorFont = [_ruleEditor font],
font = [CPFont fontWithName:[ruleEditorFont familyName] size:[ruleEditorFont size] + 2],
localizedText = [[_ruleEditor standardLocalizer] localizedStringForString:text],
size = [localizedText sizeWithFont:font];
[textField setFrameSize:CGSizeMake(size.width + 4, [_ruleEditor rowHeight])];
[textField setValue:font forThemeAttribute:@"font"];
[textField setValue:[_ruleEditor _verticalAlignment] forThemeAttribute:@"vertical-alignment"];
[textField setStringValue:localizedText];
return textField;
}
- (void)_addOption:(id)sender
{
if (_rowIndex == [_ruleEditor numberOfRows] - 1)
@@ -334,6 +363,28 @@
[_correspondingRuleItems setArray:ruleItems];
// Localize drop-down options in context and reorder/insert intermediate labels natively
var localizer = [_ruleEditor standardLocalizer];
if (localizer)
{
[localizer localizeMenuItemsForViews:_ruleOptionViews];
_ruleOptionViews = [localizer localizeAndReorderViews:_ruleOptionViews];
}
// Rebuild frame configurations to match the new localized layout order
[_ruleOptionFrames removeAllObjects];
[_ruleOptionInitialViewFrames removeAllObjects];
var newCount = [_ruleOptionViews count];
for (var i = 0; i < newCount; i++)
{
var view = [_ruleOptionViews objectAtIndex:i],
frame = [view frame];
[_ruleOptionFrames addObject:frame];
[_ruleOptionInitialViewFrames addObject:frame];
}
if (!_editable)
[self _updateEnabledStateForSubviews];
@@ -410,6 +461,9 @@
{
[_addButton setHidden:[_ruleEditor _shouldHideAddButtonForSlice:self]];
[_subtractButton setHidden:[_ruleEditor _shouldHideSubtractButtonForSlice:self]];
[_addButton setToolTip:[_ruleEditor _toolTipForAddSimpleRowButton]];
[_subtractButton setToolTip:[_ruleEditor _toolTipForDeleteRowButton]];
}
- (void)_configurePlusButtonByRowType:(CPRuleEditorRowType)type
@@ -492,9 +546,23 @@
- (void)viewDidMoveToWindow
{
[super viewDidMoveToWindow];
[self _updateButtonImages];
[self layoutSubviews];
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
[self _updateButtonImages];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
[self _updateButtonImages];
}
- (void)_addObservers
{
if (_isObserving)
+357 -49
View File
@@ -29,6 +29,10 @@
@import "CPClipView.j"
@import "CPScroller.j"
@import "CPView.j"
@import "CPRulerView.j"
@class CPTableView
@class CPRulerView
#define SHOULD_SHOW_CORNER_VIEW() (_scrollerStyle === CPScrollerStyleLegacy && _verticalScroller && ![_verticalScroller isHidden])
@@ -92,9 +96,19 @@ var TIMER_INTERVAL = 0.2,
CPScrollViewFadeOutTime = 1.3;
var CPScrollViewWillStartLiveScrollNotification = @"CPScrollViewWillStartLiveScrollNotification",
CPScrollViewDidLiveScrollNotification = @"CPScrollViewDidLiveScrollNotification",
CPScrollViewDidEndLiveScrollNotification = @"CPScrollViewDidEndLiveScrollNotification";
var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
CPScrollerStyleGlobalChangeNotification = @"CPScrollerStyleGlobalChangeNotification";
var CPScrollViewBorderSuffixes = @[@"no-border", @"line-border", @"bezel-border", @"groove-border"];
// _CPScrollViews will hold all created CPScrollView's in order to propagate changes
// of scroller global style
var _CPScrollViews;
/*!
@ingroup appkit
@class CPScrollView
@@ -134,11 +148,19 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
int _scrollerStyle;
int _scrollerKnobStyle;
// Ruler Support
BOOL _hasVerticalRuler;
BOOL _hasHorizontalRuler;
BOOL _rulersVisible;
CPRulerView _verticalRuler;
CPRulerView _horizontalRuler;
}
#pragma mark -
#pragma mark Class methods
// MARK: -
// MARK: Class methods
+ (void)initialize
{
@@ -147,10 +169,12 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
var globalValue = [[CPBundle mainBundle] objectForInfoDictionaryKey:@"CPScrollersGlobalStyle"];
if (globalValue === nil || globalValue === -1)
if (globalValue == nil || globalValue === -1)
CPScrollerStyleGlobal = _isBrowserUsingOverlayScrollers() ? CPScrollerStyleOverlay : CPScrollerStyleLegacy
else
CPScrollerStyleGlobal = globalValue;
_CPScrollViews = @[];
}
+ (CPString)defaultThemeClass
@@ -162,24 +186,66 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
{
return @{
@"bottom-corner-color": [CPColor whiteColor],
@"border-color": [CPColor blackColor]
@"border-color": [CPColor blackColor],
@"content-inset-no-border": CGInsetMake(0, 0, 0, 0),
@"content-inset-line-border": CGInsetMake(1, 1, 1, 1),
@"content-inset-bezel-border": CGInsetMake(1, 1, 1, 1),
@"content-inset-groove-border": CGInsetMake(2, 2, 2, 2),
@"background-color-no-border": [CPNull null],
@"background-color-line-border": [CPNull null],
@"background-color-bezel-border": [CPNull null],
@"background-color-groove-border": [CPNull null]
};
}
/*! Deprecated
*/
+ (CGSize)contentSizeForFrameSize:(CGSize)frameSize hasHorizontalScroller:(BOOL)hFlag hasVerticalScroller:(BOOL)vFlag borderType:(CPBorderType)borderType
{
return [self contentSizeForFrameSize:frameSize
horizontalScrollerClass:hFlag ? [CPScroller class] : nil
verticalScrollerClass:vFlag ? [CPScroller class] : nil
borderType:borderType
controlSize:CPRegularControlSize
scrollerStyle:CPScrollerStyleGlobal];
}
+ (CGSize)contentSizeForFrameSize:(CGSize)frameSize
horizontalScrollerClass:(Class)horizontalScrollerClass
verticalScrollerClass:(Class)verticalScrollerClass
borderType:(CPBorderType)borderType
controlSize:(CPControlSize)controlSize
scrollerStyle:(CPScrollerStyle)scrollerStyle
{
var bounds = [self _insetBounds:CGRectMake(0.0, 0.0, frameSize.width, frameSize.height) borderType:borderType];
if (hFlag)
bounds.size.height -= [_horizontalScroller scrollerWidth];
if (horizontalScrollerClass)
bounds.size.height -= [horizontalScrollerClass scrollerWidthInStyle:scrollerStyle];
if (vFlag)
bounds.size.width -= [_verticalScroller scrollerWidth];
if (verticalScrollerClass)
bounds.size.width -= [verticalScrollerClass scrollerWidthForControlSize:scrollerStyle];
return bounds.size;
}
/*! Deprecated
*/
+ (CGSize)frameSizeForContentSize:(CGSize)contentSize hasHorizontalScroller:(BOOL)hFlag hasVerticalScroller:(BOOL)vFlag borderType:(CPBorderType)borderType
{
return [self frameSizeForContentSize:contentSize
horizontalScrollerClass:hFlag ? [CPScroller class] : nil
verticalScrollerClass:vFlag ? [CPScroller class] : nil
borderType:borderType
controlSize:CPRegularControlSize
scrollerStyle:CPScrollerStyleGlobal];
}
+ (CGSize)frameSizeForContentSize:(CGSize)contentSize
horizontalScrollerClass:(Class)horizontalScrollerClass
verticalScrollerClass:(Class)verticalScrollerClass
borderType:(CPBorderType)borderType
controlSize:(CPControlSize)controlSize
scrollerStyle:(CPScrollerStyle)scrollerStyle
{
var bounds = [self _insetBounds:CGRectMake(0.0, 0.0, contentSize.width, contentSize.height) borderType:borderType],
widthInset = contentSize.width - bounds.size.width,
@@ -187,29 +253,45 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
frameSize = CGSizeMake(contentSize.width + widthInset, contentSize.height + heightInset);
if (hFlag)
frameSize.height += [_horizontalScroller scrollerWidth];
frameSize.height += [horizontalScrollerClass scrollerWidthInStyle:scrollerStyle];
if (vFlag)
frameSize.width += [_verticalScroller scrollerWidth];
frameSize.width += [verticalScrollerClass scrollerWidthForControlSize:scrollerStyle];
return frameSize;
}
+ (CGRect)_insetBounds:(CGRect)bounds borderType:(CPBorderType)borderType
{
// First, we have to check if we are compiling a theme or running an application because if working on a theme,
// we can't use theme attributes to determine the inset ! This would be a kind of circular reference...
var compilingATheme = [[[CPBundle mainBundle] objectForInfoDictionaryKey:@"CPApplicationDelegateClass"] isEqualToString:@"BKShowcaseController"];
if (compilingATheme)
return bounds;
var contentInset = [[CPTheme defaultTheme] valueForAttributeWithName:@"content-inset-"+CPScrollViewBorderSuffixes[borderType] forClass:CPScrollView];
// As this is a class method, we don't have object attributes, so if the theme doesn't declare content insets, we don't automatically get default value.
// Get it by hand.
if (!contentInset)
contentInset = [[self themeAttributes] objectForKey:@"content-inset-"+CPScrollViewBorderSuffixes[borderType]];
switch (borderType)
{
case CPNoBorder:
case CPLineBorder:
case CPBezelBorder:
return CGRectInset(bounds, 1.0, 1.0);
return CGRectInsetByInset(bounds, contentInset);
case CPGrooveBorder:
bounds = CGRectInset(bounds, 2.0, 2.0);
// FIXME: Do something better with this
bounds = CGRectInsetByInset(bounds, contentInset);
++bounds.origin.y;
--bounds.size.height;
return bounds;
case CPNoBorder:
default:
return bounds;
}
@@ -218,7 +300,7 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
/*!
Get the system wide scroller style.
*/
+ (int)globalScrollerStyle
+ (CPScrollerStyle)globalScrollerStyle
{
return CPScrollerStyleGlobal;
}
@@ -228,15 +310,18 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
@param aStyle the scroller style to set all scroller views to use (CPScrollerStyleLegacy or CPScrollerStyleOverlay)
*/
+ (void)setGlobalScrollerStyle:(int)aStyle
+ (void)setGlobalScrollerStyle:(CPScrollerStyle)aStyle
{
CPScrollerStyleGlobal = aStyle;
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollerStyleGlobalChangeNotification object:nil];
// We propagate the new scroller global style to all existing CPScrollView's
for (var i = 0, count = [_CPScrollViews count]; i < count; i++)
[_CPScrollViews[i] setScrollerStyle:CPScrollerStyleGlobal];
}
#pragma mark -
#pragma mark Initialization
// MARK: -
// MARK: Initialization
- (id)initWithFrame:(CGRect)aFrame
{
@@ -266,17 +351,23 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
_scrollerKnobStyle = CPScrollerKnobStyleDefault;
[self setScrollerStyle:CPScrollerStyleGlobal];
_hasVerticalRuler = NO;
_hasHorizontalRuler = NO;
_rulersVisible = NO;
_delegate = nil;
_scrollTimer = nil;
_implementedDelegateMethods = 0;
[_CPScrollViews addObject:self];
}
return self;
}
#pragma mark -
#pragma mark Getters / Setters
// MARK: -
// MARK: Getters / Setters
/*!
The delegate of the scroll view
@@ -309,7 +400,7 @@ Notifies the delegate when the scroll view has finished scrolling.
_delegate = aDelegate;
_implementedDelegateMethods = 0;
if (_delegate === nil)
if (_delegate == nil)
return;
if ([_delegate respondsToSelector:@selector(scrollViewWillScroll:)])
@@ -319,7 +410,7 @@ Notifies the delegate when the scroll view has finished scrolling.
_implementedDelegateMethods |= CPScrollViewDelegate_scrollViewDidScroll_;
}
- (int)scrollerStyle
- (CPScrollerStyle)scrollerStyle
{
return _scrollerStyle;
}
@@ -330,7 +421,7 @@ Notifies the delegate when the scroll view has finished scrolling.
- CPScrollerStyleLegacy: Standard scrollers like Windows or Mac OS X prior to 10.7
- CPScrollerStyleOverlay: scrollers like those in Mac OS X 10.7+
*/
- (void)setScrollerStyle:(int)aStyle
- (void)setScrollerStyle:(CPScrollerStyle)aStyle
{
if (_scrollerStyle === aStyle)
return;
@@ -754,8 +845,105 @@ Notifies the delegate when the scroll view has finished scrolling.
}
#pragma mark -
#pragma mark Privates
// MARK: -
// MARK: Rulers
- (BOOL)hasHorizontalRuler
{
return _hasHorizontalRuler;
}
- (void)setHasHorizontalRuler:(BOOL)shouldHaveHorizontalRuler
{
if (_hasHorizontalRuler === shouldHaveHorizontalRuler)
return;
_hasHorizontalRuler = shouldHaveHorizontalRuler;
if (_hasHorizontalRuler && !_horizontalRuler)
{
_horizontalRuler = [[CPRulerView alloc] initWithScrollView:self orientation:CPRulerOrientationHorizontal];
}
[self tile];
}
- (BOOL)hasVerticalRuler
{
return _hasVerticalRuler;
}
- (void)setHasVerticalRuler:(BOOL)shouldHaveVerticalRuler
{
if (_hasVerticalRuler === shouldHaveVerticalRuler)
return;
_hasVerticalRuler = shouldHaveVerticalRuler;
if (_hasVerticalRuler && !_verticalRuler)
{
_verticalRuler = [[CPRulerView alloc] initWithScrollView:self orientation:CPRulerOrientationVertical];
}
[self tile];
}
- (BOOL)rulersVisible
{
return _rulersVisible;
}
- (void)setRulersVisible:(BOOL)areRulersVisible
{
if (_rulersVisible === areRulersVisible)
return;
_rulersVisible = areRulersVisible;
[self tile];
}
- (CPRulerView)horizontalRulerView
{
return _horizontalRuler;
}
- (void)setHorizontalRulerView:(CPRulerView)aRulerView
{
if (_horizontalRuler === aRulerView)
return;
[_horizontalRuler removeFromSuperview];
_horizontalRuler = aRulerView;
if (_horizontalRuler)
[self addSubview:_horizontalRuler];
[self tile];
}
- (CPRulerView)verticalRulerView
{
return _verticalRuler;
}
- (void)setVerticalRulerView:(CPRulerView)aRulerView
{
if (_verticalRuler === aRulerView)
return;
[_verticalRuler removeFromSuperview];
_verticalRuler = aRulerView;
if (_verticalRuler)
[self addSubview:_verticalRuler];
[self tile];
}
// MARK: -
// MARK: Privates
/* @ignore */
- (void)_updateScrollerStyle
@@ -951,6 +1139,8 @@ Notifies the delegate when the scroll view has finished scrolling.
[self _sendDelegateMessages];
[_contentView scrollToPoint:contentBounds.origin];
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollViewDidLiveScrollNotification object:self];
}
/* @ignore */
@@ -989,6 +1179,8 @@ Notifies the delegate when the scroll view has finished scrolling.
[_contentView scrollToPoint:contentBounds.origin];
[_headerClipView scrollToPoint:CGPointMake(contentBounds.origin.x, 0.0)];
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollViewDidLiveScrollNotification object:self];
}
/* @ignore */
@@ -999,6 +1191,7 @@ Notifies the delegate when the scroll view has finished scrolling.
if (!_scrollTimer)
{
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollViewWillStartLiveScrollNotification object:self];
[self _scrollViewWillScroll];
_scrollTimer = [CPTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL target:self selector:@selector(_scrollViewDidScroll) userInfo:nil repeats:YES];
}
@@ -1037,6 +1230,8 @@ Notifies the delegate when the scroll view has finished scrolling.
[_contentView scrollToPoint:constrainedOrigin];
[_headerClipView scrollToPoint:CGPointMake(constrainedOrigin.x, 0.0)];
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollViewDidLiveScrollNotification object:self];
if (extraX || extraY)
[enclosingScrollView _respondToScrollWheelEventWithDeltaX:extraX deltaY:extraY];
}
@@ -1056,6 +1251,8 @@ Notifies the delegate when the scroll view has finished scrolling.
if (_implementedDelegateMethods & CPScrollViewDelegate_scrollViewDidScroll_)
[_delegate scrollViewDidScroll:self];
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollViewDidEndLiveScrollNotification object:self];
}
/*! @ignore*/
@@ -1066,18 +1263,15 @@ Notifies the delegate when the scroll view has finished scrolling.
#pragma mark -
#pragma mark Utilities
// MARK: -
// MARK: Utilities
/*!
Lays out the scroll view's components.
*/
- (void)tile
{
// yuck.
// RESIZE: tile->setHidden AND refl
// Outside Change: refl->tile->setHidden AND refl
// scroll: refl.
[self reflectScrolledClipView:_contentView];
}
/*!
@@ -1121,6 +1315,41 @@ Notifies the delegate when the scroll view has finished scrolling.
contentFrame.origin.y += headerClipViewHeight;
contentFrame.size.height -= headerClipViewHeight;
// Adjust content view based on horizontal / vertical ruler presence
var showHorizontalRuler = _rulersVisible && _hasHorizontalRuler && _horizontalRuler,
showVerticalRuler = _rulersVisible && _hasVerticalRuler && _verticalRuler;
var horizRulerThickness = showHorizontalRuler ? ([_horizontalRuler respondsToSelector:@selector(ruleThickness)] ? [_horizontalRuler ruleThickness] : 16.0) : 0.0,
vertRulerThickness = showVerticalRuler ? ([_verticalRuler respondsToSelector:@selector(ruleThickness)] ? [_verticalRuler ruleThickness] : 24.0) : 0.0;
if (showHorizontalRuler)
{
if ([_horizontalRuler superview] !== self)
[self addSubview:_horizontalRuler];
[_horizontalRuler setHidden:NO];
}
else if (_horizontalRuler)
{
[_horizontalRuler setHidden:YES];
}
if (showVerticalRuler)
{
if ([_verticalRuler superview] !== self)
[self addSubview:_verticalRuler];
[_verticalRuler setHidden:NO];
}
else if (_verticalRuler)
{
[_verticalRuler setHidden:YES];
}
contentFrame.origin.y += horizRulerThickness;
contentFrame.size.height -= horizRulerThickness;
contentFrame.origin.x += vertRulerThickness;
contentFrame.size.width -= vertRulerThickness;
var difference = CGSizeMake(CGRectGetWidth(documentFrame) - CGRectGetWidth(contentFrame), CGRectGetHeight(documentFrame) - CGRectGetHeight(contentFrame)),
verticalScrollerWidth = [_verticalScroller scrollerWidth],
horizontalScrollerHeight = [_horizontalScroller scrollerWidth],
@@ -1213,6 +1442,7 @@ Notifies the delegate when the scroll view has finished scrolling.
[_contentView setFrame:contentFrame];
[_headerClipView setFrame:[self _headerClipViewFrame]];
[[_headerClipView documentView] setNeedsDisplay:YES];
if (SHOULD_SHOW_CORNER_VIEW())
{
[_cornerView setFrame:[self _cornerViewFrame]];
@@ -1223,10 +1453,43 @@ Notifies the delegate when the scroll view has finished scrolling.
if (_scrollerStyle === CPScrollerStyleLegacy)
{
[[self bottomCornerView] setFrame:[self _bottomCornerViewFrame]];
var bottomCornerFrame = [self _bottomCornerViewFrame];
[[self bottomCornerView] setFrame:bottomCornerFrame];
[[self bottomCornerView] setHidden:CGRectIsEmpty(bottomCornerFrame)];
[[self bottomCornerView] setBackgroundColor:[self currentValueForThemeAttribute:@"bottom-corner-color"]];
}
// Position and redraw rulers to track viewport updates
if (showHorizontalRuler)
{
[_horizontalRuler setFrame:CGRectMake(
CGRectGetMinX(contentFrame),
CGRectGetMinY(contentFrame) - horizRulerThickness,
CGRectGetWidth(contentFrame),
horizRulerThickness
)];
if ([_horizontalRuler respondsToSelector:@selector(updateRuler)])
[_horizontalRuler updateRuler];
else
[_horizontalRuler setNeedsDisplay:YES];
}
if (showVerticalRuler)
{
[_verticalRuler setFrame:CGRectMake(
CGRectGetMinX(contentFrame) - vertRulerThickness,
CGRectGetMinY(contentFrame),
vertRulerThickness,
CGRectGetHeight(contentFrame)
)];
if ([_verticalRuler respondsToSelector:@selector(updateRuler)])
[_verticalRuler updateRuler];
else
[_verticalRuler setNeedsDisplay:YES];
}
--_recursionCount;
}
@@ -1267,9 +1530,8 @@ Notifies the delegate when the scroll view has finished scrolling.
return [_contentView documentVisibleRect];
}
#pragma mark -
#pragma mark Overrides
// MARK: -
// MARK: Overrides
- (void)_removeObservers
{
@@ -1288,9 +1550,6 @@ Notifies the delegate when the scroll view has finished scrolling.
if (_isObserving)
return;
//Make sure to have the last global style for the scroller
[self _didReceiveDefaultStyleChange:nil];
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didReceiveDefaultStyleChange:)
name:CPScrollerStyleGlobalChangeNotification
@@ -1299,13 +1558,11 @@ Notifies the delegate when the scroll view has finished scrolling.
[super _addObservers];
}
- (void)drawRect:(CGRect)aRect
{
[super drawRect:aRect];
if (_borderType == CPNoBorder)
if ([self isCSSBased] || (_borderType == CPNoBorder))
return;
var strokeRect = [self bounds],
@@ -1389,8 +1646,8 @@ Notifies the delegate when the scroll view has finished scrolling.
y = maxY - 1.5;
CGContextMoveToPoint(context, maxX - 1.0, y);
CGContextAddLineToPoint(context, minX + 2.0, y);
CGContextMoveToPoint(maxX - 1.0, y);
CGContextAddLineToPoint(minX + 2.0, y);
x = minX + 0.5;
@@ -1508,6 +1765,37 @@ Notifies the delegate when the scroll view has finished scrolling.
@end
// MARK: -
@implementation CPScrollView (CSSTheming)
- (void)layoutSubviews
{
if (![self isCSSBased])
return;
if (_borderType !== CPNoBorder)
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color-"+CPScrollViewBorderSuffixes[_borderType]]];
if (_scrollerStyle === CPScrollerStyleLegacy)
[[self bottomCornerView] setBackgroundColor:[self currentValueForThemeAttribute:@"bottom-corner-color"]];
}
- (BOOL)isCSSBased
{
return [[self theme] isCSSBased];
}
- (void)refreshDisplay
{
if ([self isCSSBased])
[self setNeedsLayout:YES];
else
[self setNeedsDisplay:YES];
}
@end
#pragma mark -
@implementation CPScrollView (FirstResponder)
@@ -1552,7 +1840,7 @@ Notifies the delegate when the scroll view has finished scrolling.
@end
#pragma mark -
// MARK: -
var CPScrollViewContentViewKey = @"CPScrollViewContentView",
CPScrollViewHeaderClipViewKey = @"CPScrollViewHeaderClipViewKey",
@@ -1569,7 +1857,14 @@ var CPScrollViewContentViewKey = @"CPScrollViewContentView",
CPScrollViewBottomCornerViewKey = @"CPScrollViewBottomCornerViewKey",
CPScrollViewBorderTypeKey = @"CPScrollViewBorderTypeKey",
CPScrollViewScrollerStyleKey = @"CPScrollViewScrollerStyleKey",
CPScrollViewScrollerKnobStyleKey = @"CPScrollViewScrollerKnobStyleKey";
CPScrollViewScrollerKnobStyleKey = @"CPScrollViewScrollerKnobStyleKey",
// Ruler Coding Keys
CPScrollViewHasVRulerKey = @"CPScrollViewHasVRuler",
CPScrollViewHasHRulerKey = @"CPScrollViewHasHRuler",
CPScrollViewRulersVisibleKey = @"CPScrollViewRulersVisible",
CPScrollViewVRulerKey = @"CPScrollViewVRuler",
CPScrollViewHRulerKey = @"CPScrollViewHRuler";
@implementation CPScrollView (CPCoding)
@@ -1604,6 +1899,14 @@ var CPScrollViewContentViewKey = @"CPScrollViewContentView",
_cornerView = [aCoder decodeObjectForKey:CPScrollViewCornerViewKey];
_bottomCornerView = [aCoder decodeObjectForKey:CPScrollViewBottomCornerViewKey];
// Ruler decoding
_hasVerticalRuler = [aCoder decodeBoolForKey:CPScrollViewHasVRulerKey];
_hasHorizontalRuler = [aCoder decodeBoolForKey:CPScrollViewHasHRulerKey];
_rulersVisible = [aCoder decodeBoolForKey:CPScrollViewRulersVisibleKey];
_verticalRuler = [aCoder decodeObjectForKey:CPScrollViewVRulerKey];
_horizontalRuler = [aCoder decodeObjectForKey:CPScrollViewHRulerKey];
_delegate = nil;
_scrollTimer = nil;
_implementedDelegateMethods = 0;
@@ -1611,10 +1914,7 @@ var CPScrollViewContentViewKey = @"CPScrollViewContentView",
_scrollerStyle = [aCoder decodeObjectForKey:CPScrollViewScrollerStyleKey] || CPScrollerStyleGlobal;
_scrollerKnobStyle = [aCoder decodeObjectForKey:CPScrollViewScrollerKnobStyleKey] || CPScrollerKnobStyleDefault;
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didReceiveDefaultStyleChange:)
name:CPScrollerStyleGlobalChangeNotification
object:nil];
[_CPScrollViews addObject:self];
}
return self;
@@ -1657,6 +1957,14 @@ var CPScrollViewContentViewKey = @"CPScrollViewContentView",
[aCoder encodeInt:_scrollerStyle forKey:CPScrollViewScrollerStyleKey];
[aCoder encodeInt:_scrollerKnobStyle forKey:CPScrollViewScrollerKnobStyleKey];
// Ruler encoding
[aCoder encodeBool:_hasVerticalRuler forKey:CPScrollViewHasVRulerKey];
[aCoder encodeBool:_hasHorizontalRuler forKey:CPScrollViewHasHRulerKey];
[aCoder encodeBool:_rulersVisible forKey:CPScrollViewRulersVisibleKey];
[aCoder encodeObject:_verticalRuler forKey:CPScrollViewVRulerKey];
[aCoder encodeObject:_horizontalRuler forKey:CPScrollViewHRulerKey];
}
@end
+42 -24
View File
@@ -23,12 +23,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../Foundation/Foundation.h"
@import "CPAnimation.j"
@import "CPControl.j"
@import "CPWindow_Constants.j"
@import "CPViewAnimation.j"
@import "CPWindow_Constants.j"
@global CPApp
@@ -62,6 +61,7 @@ NAMES_FOR_PARTS[CPScrollerKnobSlot] = @"knob-slot";
NAMES_FOR_PARTS[CPScrollerKnob] = @"knob";
@typedef CPScrollerStyle
CPScrollerStyleLegacy = 0;
CPScrollerStyleOverlay = 1;
@@ -101,8 +101,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Class methods
// MARK: -
// MARK: Class methods
+ (CPString)defaultThemeClass
{
@@ -134,7 +134,7 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
/*!
Returns the CPScroller's width for a CPRegularControlSize.
*/
+ (float)scrollerWidthInStyle:(int)aStyle
+ (float)scrollerWidthInStyle:(CPScrollerStyle)aStyle
{
if (!_CACHED_THEME_SCROLLER)
_CACHED_THEME_SCROLLER = [[self alloc] init];
@@ -166,8 +166,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Initialization
// MARK: -
// MARK: Initialization
- (id)initWithFrame:(CGRect)aFrame
{
@@ -202,13 +202,13 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Getters / Setters
// MARK: -
// MARK: Getters / Setters
/*!
Returns the scroller's style
*/
- (void)style
- (int)style
{
return _style;
}
@@ -217,7 +217,7 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
Set the scroller's control size
@param aStyle the scroller style: CPScrollerStyleLegacy or CPScrollerStyleOverlay
*/
- (void)setStyle:(id)aStyle
- (void)setStyle:(CPScrollerStyle)aStyle
{
if (_style != nil && _style === aStyle)
return;
@@ -258,8 +258,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
*/
- (void)setKnobProportion:(float)aProportion
{
if (!_IS_NUMERIC(aProportion))
[CPException raise:CPInvalidArgumentException reason:"aProportion must be numeric"];
if (!CPIsNumeric(aProportion))
[CPException raise:CPInvalidArgumentException reason:"aProportion must be numeric, was: "+aProportion];
_knobProportion = MIN(1.0, MAX(0.0001, aProportion));
@@ -268,8 +268,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Privates
// MARK: -
// MARK: Privates
/*! @ignore */
- (void)_adjustScrollerSize
@@ -294,8 +294,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Utilities
// MARK: -
// MARK: Utilities
- (CGRect)rectForPart:(CPScrollerPart)aPart
{
@@ -320,7 +320,25 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
if (![self hasThemeState:CPThemeStateSelected] && ![self hasThemeState:CPThemeStateScrollViewLegacy])
return CPScrollerNoPart;
if (CGRectContainsPoint([self rectForPart:CPScrollerKnob], aPoint))
// Fetch the visual rect for the knob
var bounds = [self bounds],
knobRect = [self rectForPart:CPScrollerKnob],
hitKnobRect = CGRectMake(CGRectGetMinX(knobRect), CGRectGetMinY(knobRect), CGRectGetWidth(knobRect), CGRectGetHeight(knobRect));
// Expand the hit test rect to span the entire track on the minor axis
// so dragging works smoothly even if the user clicks slightly off-center.
if ([self isVertical])
{
hitKnobRect.origin.x = 0;
hitKnobRect.size.width = CGRectGetWidth(bounds);
}
else
{
hitKnobRect.origin.y = 0;
hitKnobRect.size.height = CGRectGetHeight(bounds);
}
if (CGRectContainsPoint(hitKnobRect, aPoint))
return CPScrollerKnob;
if (CGRectContainsPoint([self rectForPart:CPScrollerDecrementPage], aPoint))
@@ -467,8 +485,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Drawing
// MARK: -
// MARK: Drawing
/*!
Draws the specified arrow and sets the highlight.
@@ -702,8 +720,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
}
#pragma mark -
#pragma mark Overrides
// MARK: -
// MARK: Overrides
- (id)currentValueForThemeAttribute:(CPString)anAttributeName
{
@@ -779,8 +797,8 @@ CPThemeStateScrollerKnobDark = CPThemeState("scroller-knob-dark");
return [self currentValueForThemeAttribute:@"scroller-width"];
}
#pragma mark -
#pragma mark Delegates
// MARK: -
// MARK: Delegates
- (void)animationDidEnd:(CPAnimation)animation
{
+249 -39
View File
@@ -24,8 +24,12 @@
@import "CPMenu.j"
@import "CPMenuItem.j"
@import "CPTextField.j"
@import "CPAnimationContext.j"
@import "CPViewAnimator.j"
@import "CPArrayController.j"
@class CPUserDefaults
@class CALayer
@global CPApp
@@ -58,6 +62,9 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
BOOL _sendsSearchStringImmediately;
BOOL _canResignFirstResponder;
CPTimer _partialStringTimer;
CPView _contentView;
BOOL _isBecomingFirstResponder;
}
+ (CPString)defaultThemeClass
@@ -74,8 +81,10 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
@"image-cancel-pressed": [CPNull null],
@"image-search-inset" : CGInsetMake(0, 0, 0, 5),
@"image-cancel-inset" : CGInsetMake(0, 5, 0, 0),
@"search-menu-offset": CGPointMake(10, -4),
@"search-right-margin": 2
@"search-button-rect-function": [CPNull null],
@"layout-function": [CPNull null],
@"search-right-margin": 2,
@"search-menu-offset": CGPointMake(10, -4)
};
}
@@ -95,6 +104,8 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
_sendsWholeSearchString = NO;
_sendsSearchStringImmediately = NO;
_recentsAutosaveName = nil;
[self setPlaceholderString:@"Search"];
[self _init];
}
@@ -113,8 +124,13 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
[self setContinuous:YES];
var bounds = [self bounds],
cancelButton = [[CPButton alloc] initWithFrame:[self cancelButtonRectForBounds:bounds]],
searchButton = [[CPButton alloc] initWithFrame:[self searchButtonRectForBounds:bounds]];
cancelButton = nil,
searchButton = nil;
#if PLATFORM(DOM)
cancelButton = [[CPButton alloc] initWithFrame:[self cancelButtonRectForBounds:bounds]];
searchButton = [[CPButton alloc] initWithFrame:[self searchButtonRectForBounds:bounds]];
#endif
[self setCancelButton:cancelButton];
[self resetCancelButton];
@@ -123,11 +139,12 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
[self resetSearchButton];
_canResignFirstResponder = YES;
_isBecomingFirstResponder = NO;
}
#pragma mark -
#pragma mark Override observers
// MARK: -
// MARK: Override observers
- (void)_removeObservers
{
@@ -183,7 +200,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (void)resetSearchButton
{
var button = [self searchButton],
searchButtonImage = (_searchMenuTemplate === nil) ? [self currentValueForThemeAttribute:@"image-search"] : [self currentValueForThemeAttribute:@"image-find"];
searchButtonImage = (_searchMenuTemplate == nil) ? [self currentValueForThemeAttribute:@"image-search"] : [self currentValueForThemeAttribute:@"image-find"];
[button setBordered:NO];
[button setImageScaling:CPImageScaleAxesIndependently];
@@ -230,8 +247,8 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
var button = [self cancelButton];
[button setBordered:NO];
[button setImageScaling:CPImageScaleAxesIndependently];
[button setImage:[self valueForThemeAttribute:@"image-cancel"]];
[button setAlternateImage:[self valueForThemeAttribute:@"image-cancel-pressed"]];
[button setImage:[self currentValueForThemeAttribute:@"image-cancel"]];
[button setAlternateImage:[self currentValueForThemeAttribute:@"image-cancel-pressed"]];
[button setAutoresizingMask:CPViewMinXMargin];
[button setTarget:self];
[button setAction:@selector(cancelOperation:)];
@@ -253,7 +270,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
if (_searchButton)
{
var searchBounds = [self searchButtonRectForBounds:bounds],
rightMargin = [self currentValueForThemeAttribute:@"search-right-margin"];
rightMargin = [self _potentialCurrentValueForThemeAttribute:@"search-right-margin"];
leftOffset = CGRectGetMaxX(searchBounds) + rightMargin;
}
@@ -273,10 +290,18 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
*/
- (CGRect)searchButtonRectForBounds:(CGRect)rect
{
var size = [[self currentValueForThemeAttribute:@"image-search"] size] || CGSizeMakeZero(),
inset = [self currentValueForThemeAttribute:@"image-search-inset"];
var themedRectFunction = [self _potentialCurrentValueForThemeAttribute:@"search-button-rect-function"];
return CGRectMake(inset.left - inset.right, inset.top - inset.bottom + (CGRectGetHeight(rect) - size.height) / 2, size.width, size.height);
if (themedRectFunction)
// There's a theme defined positioning function, just use it
return objj_eval("("+themedRectFunction+")")(self, rect);
else
{
var size = [[self _potentialCurrentValueForThemeAttribute:@"image-search"] size] || CGSizeMakeZero(),
inset = [self _potentialCurrentValueForThemeAttribute:@"image-search-inset"];
return CGRectMake(inset.left - inset.right, inset.top - inset.bottom + (CGRectGetHeight(rect) - size.height) / 2, size.width, size.height);
}
}
/*!
@@ -286,8 +311,8 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
*/
- (CGRect)cancelButtonRectForBounds:(CGRect)rect
{
var size = [[self currentValueForThemeAttribute:@"image-cancel"] size] || CGSizeMakeZero(),
inset = [self currentValueForThemeAttribute:@"image-cancel-inset"];
var size = [[self _potentialCurrentValueForThemeAttribute:@"image-cancel"] size] || CGSizeMakeZero(),
inset = [self _potentialCurrentValueForThemeAttribute:@"image-cancel-inset"];
return CGRectMake(CGRectGetWidth(rect) - size.width + inset.left - inset.right, inset.top - inset.bottom + (CGRectGetHeight(rect) - size.width) / 2, size.height, size.height);
}
@@ -395,8 +420,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
{
var max = MIN([self maximumRecents], [searches count]);
searches = [searches subarrayWithRange:CPMakeRange(0, max)];
_recentSearches = searches;
_recentSearches = [searches subarrayWithRange:CPMakeRange(0, max)];
[self _autosaveRecentSearchList];
}
@@ -481,6 +505,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (BOOL)sendAction:(SEL)anAction to:(id)anObject
{
[self selectAll:nil];
[super sendAction:anAction to:anObject];
[_partialStringTimer invalidate];
@@ -491,7 +516,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (void)_addStringToRecentSearches:(CPString)string
{
if (string === nil || string === @"" || [_recentSearches containsObject:string])
if (string == nil || string === @"" || [_recentSearches containsObject:string])
return;
var searches = [CPMutableArray arrayWithArray:_recentSearches];
@@ -579,6 +604,8 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
[item setTarget:self];
[template addItem:item];
[self _addSeparatorToMenu:template];
item = [[CPMenuItem alloc] initWithTitle:@"Recent Searches"
action:nil
keyEquivalent:@""];
@@ -598,7 +625,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (void)_updateSearchMenu
{
if (_searchMenuTemplate === nil)
if (_searchMenuTemplate == nil)
return;
var menu = [[CPMenu alloc] init],
@@ -616,9 +643,6 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
case CPSearchFieldRecentsTitleMenuItemTag:
if (countOfRecents === 0)
continue;
if ([menu numberOfItems] > 0)
[self _addSeparatorToMenu:menu];
break;
case CPSearchFieldRecentsMenuItemTag:
@@ -641,9 +665,6 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
if (countOfRecents === 0)
continue;
if ([menu numberOfItems] > 0)
[self _addSeparatorToMenu:menu];
[item setAction:@selector(_searchFieldClearRecents:)];
[item setTarget:self];
break;
@@ -651,9 +672,6 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
case CPSearchFieldNoRecentsMenuItemTag:
if (countOfRecents !== 0)
continue;
if ([menu numberOfItems] > 0)
[self _addSeparatorToMenu:menu];
break;
}
@@ -670,6 +688,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
{
var separator = [CPMenuItem separatorItem];
[separator setEnabled:NO];
[separator setTag:CPSearchFieldRecentsTitleMenuItemTag];
[aMenu addItem:separator];
}
@@ -687,7 +706,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (void)_showMenu
{
if (_searchMenu === nil || [_searchMenu numberOfItems] === 0 || ![self isEnabled] || ([_recentSearches count] === 0))
if (_searchMenu === nil || [_searchMenu numberOfItems] === 0 || ![self isEnabled])
return;
var aFrame = [[self superview] convertRect:[self frame] toView:nil],
@@ -708,10 +727,14 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (void)cancelOperation:(id)sender
{
[self setObjectValue:@""];
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
// If something was entered, the search field must deactivate itself (else, do nothing)
if ([[self stringValue] length] > 0)
{
[self setObjectValue:@""];
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
[self _updateCancelButtonVisibility];
[[self window] makeFirstResponder:[self window]];
}
}
- (void)_searchFieldSearch:(id)sender
@@ -761,15 +784,197 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
- (void)_loadRecentSearchList
{
var name = [self recentsAutosaveName];
if (name === nil)
if (name == nil)
return;
var list = [[CPUserDefaults standardUserDefaults] objectForKey:name];
if (list !== nil)
if (list != nil)
_recentSearches = list;
}
@end
// MARK: -
@implementation CPSearchField (ThemingAdditions)
// Overwrite CPTextField method to permit themed layout functions
- (void)layoutSubviews
{
if (!_contentView)
{
// Search for the CPImageAndTextView subview of mine
for (var i = 0, subviews = [self subviews], nb = [subviews count]; (!_contentView && (i < nb)); i++)
if ([subviews[i] isKindOfClass:_CPImageAndTextView])
_contentView = subviews[i];
}
var bezelColor = [self currentValueForThemeAttribute:@"bezel-color"];
if ([bezelColor isCSSBased])
{
// CSS Styling
// We don't need bezelView as we apply CSS styling directly on the search view itself
[self _setBackgroundColor:bezelColor];
if (!_contentView)
_contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:nil];
}
else
{
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"content-view"];
[bezelView setBackgroundColor:bezelColor];
if (!_contentView)
_contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
}
if (_contentView)
{
[_contentView setHidden:(_stringValue && _stringValue.length > 0) && [self hasThemeState:CPThemeStateEditing]];
[_contentView setText:[self hasThemeState:CPTextFieldStatePlaceholder] ? [self placeholderString] : _stringValue];
[_contentView setTextColor:[self currentValueForThemeAttribute:@"text-color"]];
[_contentView setFont:[self font]]; //[self currentValueForThemeAttribute:@"font"]];
[_contentView setAlignment:[self currentValueForThemeAttribute:@"alignment"]];
[_contentView setVerticalAlignment:[self currentValueForThemeAttribute:@"vertical-alignment"]];
[_contentView setLineBreakMode:[self currentValueForThemeAttribute:@"line-break-mode"]];
[_contentView setTextShadowColor:[self currentValueForThemeAttribute:@"text-shadow-color"]];
[_contentView setTextShadowOffset:[self currentValueForThemeAttribute:@"text-shadow-offset"]];
}
if (_isEditing)
[self _setCSSStyleForInputElement];
[self updateSearchButton];
[self updateTrackingAreas];
}
// As CPTextField redefines setBackgroundColor, we have to bypass it
- (void)_setBackgroundColor:(CPColor)aColor
{
var grannyMethod = class_getInstanceMethod([[self superclass] superclass], @selector(setBackgroundColor:)),
grannyImplementation = method_getImplementation(grannyMethod);
grannyImplementation(self, @selector(setBackgroundColor:), aColor);
}
- (void)_layoutSubviews
{
var themedLayoutFunction = [self currentValueForThemeAttribute:@"layout-function"];
if (themedLayoutFunction)
// There's a theme defined layout function, just use it
objj_eval("("+themedLayoutFunction+")")(self);
else
// Call directly the completion handler
[self themedLayoutFunctionCompletionHandler];
}
- (void)updateSearchButton
{
[_searchButton setImage:(_searchMenuTemplate ? [self currentValueForThemeAttribute:@"image-find"] : [self currentValueForThemeAttribute:@"image-search"])];
[self updateTrackingAreas];
}
- (void)themedLayoutFunctionCompletionHandler
{
if (_isBecomingFirstResponder)
{
_isBecomingFirstResponder = NO;
// Call the real _becomeFirstKeyResponder to finish setting the input element
[super _becomeFirstKeyResponder];
// For some (unknown yet) reason, input field doesn't focus and text field visual state is not updated
var element = [self _inputElement];
element.focus();
[self layoutSubviews];
[CALayer runLoopUpdateLayers]; // Thank you @daboe01 for suggesting adding this
}
else
[self layoutSubviews];
}
// We override CPTextField method in order to delay the display of the input element until the end of the animation
- (BOOL)_becomeFirstKeyResponder
{
// As we have to return a result, we check if response could be NO
if (![self _isWithinUsablePlatformRect] || ![self isEditable])
return NO;
// We are now sure that response will be YES
_isBecomingFirstResponder = YES;
// We have to do this now in order to avoid running conditions messing things among multiple textfields
_stringValue = [self stringValue];
var element = [self _inputElement];
element.value = _stringValue;
[self _layoutSubviews];
return YES;
}
- (void)textDidEndEditing:(CPNotification)note
{
if ([note object] != self)
return;
[self _layoutSubviews];
[super textDidEndEditing:note];
}
- (void)_windowDidResignKey:(CPNotification)aNotification
{
// When the window resigns key, if the search field is empty, it must cancel first responder
if ([[self stringValue] length] == 0)
[[self window] makeFirstResponder:[self window]];
[super _windowDidResignKey:aNotification];
[self _layoutSubviews];
}
- (void)setPlaceholderString:(CPString)aStringValue
{
[super setPlaceholderString:aStringValue];
[self _layoutContent];
}
- (void)_layoutContent
{
[_searchButton setFrame:[self searchButtonRectForBounds:[self bounds]]];
[_contentView setFrame:[self contentRectForBounds:[self bounds]]];
[_cancelButton setFrame:[self cancelButtonRectForBounds:[self bounds]]];
[self updateTrackingAreas];
}
- (void)setFrameSize:(CGSize)aSize
{
[super setFrameSize:aSize];
[self _layoutContent];
}
- (id)_potentialCurrentValueForThemeAttribute:(CPString)aName
{
if (_isBecomingFirstResponder)
return [self valueForThemeAttribute:aName inState:[self themeState].and(CPThemeStateEditing)];
else
return [self currentValueForThemeAttribute:aName];
}
- (void)unbind:(CPString)aBinding
{
[super unbind:aBinding];
@@ -782,7 +987,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
@end
#pragma mark -
// MARK: -
@implementation CPSearchField (CPTrackingArea)
{
@@ -814,7 +1019,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
[self addTrackingArea:_searchButtonTrackingArea];
}
if (_cancelButton)
if (_cancelButton && ![_cancelButton isHidden])
{
_cancelButtonTrackingArea = [[CPTrackingArea alloc] initWithRect:[_cancelButton frame]
options:CPTrackingCursorUpdate | CPTrackingActiveInKeyWindow
@@ -837,7 +1042,7 @@ var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotificat
@end
#pragma mark -
// MARK: -
var CPRecentsAutosaveNameKey = @"CPRecentsAutosaveNameKey",
CPSendsWholeSearchStringKey = @"CPSendsWholeSearchStringKey",
@@ -915,16 +1120,21 @@ var CPRecentsAutosaveNameKey = @"CPRecentsAutosaveNameKey",
var destination = [_info objectForKey:CPObservedObjectKey],
keyPath = [_info objectForKey:CPObservedKeyPathKey];
var formatString = _predicateFormat.replace(/\$value/g, "%@");
[self suppressSpecificNotificationFromObject:destination keyPath:keyPath];
if (aValue)
[_controller setFilterPredicate:[CPPredicate predicateWithFormat:formatString, aValue]];
{
var values = @[],
formatString = _predicateFormat.replace(/\$value/g, function(x) {[values addObject:aValue]; return "%@";});
[_controller setFilterPredicate:[CPPredicate predicateWithFormat:formatString argumentArray:values]];
}
else
[_controller setFilterPredicate:nil];
[self unsuppressSpecificNotificationFromObject:destination keyPath:keyPath];
}
- (CPString)searchFieldValue
{
return [_source stringValue];
+284 -153
View File
@@ -71,7 +71,7 @@ CPSegmentSwitchTrackingMomentary = 2;
@"right-segment-bezel-color": [CPNull null],
@"center-segment-bezel-color": [CPNull null],
@"divider-bezel-color": [CPNull null],
@"divider-thickness": 1.0,
@"divider-thickness": 1.0
};
}
@@ -316,7 +316,7 @@ CPSegmentSwitchTrackingMomentary = 2;
// Working with Individual Segments
/*!
Sets the width of the specified segment.
@param aWidth the new width for the segment
@param aWidth the new width for the segment (0 for automatic width)
@param aSegment the segment to set the width for
@throws CPRangeException if \c aSegment is out of bounds
*/
@@ -420,7 +420,14 @@ CPSegmentSwitchTrackingMomentary = 2;
[segment setSelected:isSelected];
_themeStates[aSegment] = isSelected ? CPThemeStateSelected : CPThemeStateNormal;
if (_themeStates[aSegment] == undefined)
_themeStates[aSegment] = CPThemeStateNormal;
// Update state using .and() / .without() to preserve existing states (like Disabled)
if (isSelected)
_themeStates[aSegment] = _themeStates[aSegment].and(CPThemeStateSelected);
else
_themeStates[aSegment] = _themeStates[aSegment].without(CPThemeStateSelected);
// We need to do some cleanup if we only allow one selection.
if (isSelected)
@@ -432,7 +439,10 @@ CPSegmentSwitchTrackingMomentary = 2;
if (_trackingMode == CPSegmentSwitchTrackingSelectOne && oldSelectedSegment != aSegment && oldSelectedSegment != -1 && oldSelectedSegment < _segments.length)
{
[_segments[oldSelectedSegment] setSelected:NO];
_themeStates[oldSelectedSegment] = CPThemeStateNormal;
// Update old segment using .without() to preserve other states
// Previously: _themeStates[oldSelectedSegment] = CPThemeStateNormal;
_themeStates[oldSelectedSegment] = _themeStates[oldSelectedSegment].without(CPThemeStateSelected);
[self drawSegmentBezel:oldSelectedSegment highlight:NO];
}
@@ -530,12 +540,24 @@ CPSegmentSwitchTrackingMomentary = 2;
- (float)_leftOffsetForSegment:(unsigned)segment
{
if (segment == 0)
return [self currentValueForThemeAttribute:@"bezel-inset"].left;
if ([[self actualTheme] isCSSBased])
{
// CSS styling
if (segment == 0)
return 0;
var thickness = [self currentValueForThemeAttribute:@"divider-thickness"];
return [self _leftOffsetForSegment:segment - 1] + CGRectGetWidth([self frameForSegment:segment - 1]) - 2; // FIXME: -2 for collapse of borders
}
else
{
// Legacy styling
if (segment == 0)
return [self currentValueForThemeAttribute:@"bezel-inset"].left;
return [self _leftOffsetForSegment:segment - 1] + CGRectGetWidth([self frameForSegment:segment - 1]) + thickness;
var thickness = [self currentValueForThemeAttribute:@"divider-thickness"];
return [self _leftOffsetForSegment:segment - 1] + CGRectGetWidth([self frameForSegment:segment - 1]) + thickness;
}
}
- (unsigned)_indexOfLastSegment
@@ -561,26 +583,36 @@ CPSegmentSwitchTrackingMomentary = 2;
}
else if (aName === "right-segment-bezel")
{
return CGRectMake(CGRectGetWidth([self bounds]) - contentInset.right,
bezelInset.top,
contentInset.right,
height);
// we have to FLOOR the coordinates to prevent a 1px glitch in Safari
return CGRectMake(FLOOR(CGRectGetWidth([self bounds]) - contentInset.right),
FLOOR(bezelInset.top),
FLOOR(contentInset.right),
FLOOR(height));
}
else if (aName.indexOf("segment-bezel") === 0)
{
var segment = parseInt(aName.substring("segment-bezel-".length), 10),
if ([[self actualTheme] isCSSBased])
{
var segment = parseInt(aName.substring("segment-bezel-".length), 10);
return [self bezelFrameForSegment:segment];
}
else
{
var segment = parseInt(aName.substring("segment-bezel-".length), 10),
frame = CGRectCreateCopy([self frameForSegment:segment]);
if (segment === 0)
{
frame.origin.x += contentInset.left;
frame.size.width -= contentInset.left;
if (segment === 0)
{
frame.origin.x += contentInset.left;
frame.size.width -= contentInset.left;
}
if (segment === [self segmentCount] - 1)
frame.size.width = CGRectGetWidth([self bounds]) - contentInset.right - frame.origin.x;
return frame;
}
if (segment === [self segmentCount] - 1)
frame.size.width = CGRectGetWidth([self bounds]) - contentInset.right - frame.origin.x;
return frame;
}
else if (aName.indexOf("divider-bezel") === 0)
{
@@ -619,48 +651,85 @@ CPSegmentSwitchTrackingMomentary = 2;
if ([self segmentCount] <= 0)
return;
var themeState = _themeStates[0],
isDisabled = [self hasThemeState:CPThemeStateDisabled],
isControlSizeSmall = [self hasThemeState:CPThemeStateControlSizeSmall],
isControlSizeMini = [self hasThemeState:CPThemeStateControlSizeMini];
// Check for HUD state globally
var isHUD = [self hasThemeState:CPThemeStateHUD];
themeState = isDisabled ? themeState.and(CPThemeStateDisabled) : themeState;
if (isControlSizeSmall)
themeState = themeState.and(CPThemeStateControlSizeSmall);
else if (isControlSizeMini)
themeState = themeState.and(CPThemeStateControlSizeMini);
var leftCapColor = [self valueForThemeAttribute:@"left-segment-bezel-color"
inState:themeState],
leftBezelView = [self layoutEphemeralSubviewNamed:@"left-segment-bezel"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[leftBezelView setBackgroundColor:leftCapColor];
var themeState = _themeStates[_themeStates.length - 1];
themeState = isDisabled ? themeState.and(CPThemeStateDisabled) : themeState;
if (isControlSizeSmall)
themeState = themeState.and(CPThemeStateControlSizeSmall);
else if (isControlSizeMini)
themeState = themeState.and(CPThemeStateControlSizeMini);
var rightCapColor = [self valueForThemeAttribute:@"right-segment-bezel-color"
inState:themeState],
rightBezelView = [self layoutEphemeralSubviewNamed:@"right-segment-bezel"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[rightBezelView setBackgroundColor:rightCapColor];
for (var i = 0, count = _themeStates.length; i < count; i++)
if ([[self actualTheme] isCSSBased])
{
var themeState = _themeStates[i];
// CSS Styling
var isDisabled = [self hasThemeState:CPThemeStateDisabled],
isControlSizeSmall = [self hasThemeState:CPThemeStateControlSizeSmall],
isControlSizeMini = [self hasThemeState:CPThemeStateControlSizeMini],
isKeyWindow = [self hasThemeState:CPThemeStateKeyWindow];
for (var i = 0, count = _themeStates.length; i < count; i++)
{
var themeState = _themeStates[i];
themeState = isDisabled ? themeState.and(CPThemeStateDisabled) : themeState;
if (isControlSizeSmall)
themeState = themeState.and(CPThemeStateControlSizeSmall);
else if (isControlSizeMini)
themeState = themeState.and(CPThemeStateControlSizeMini);
// Apply HUD state to lookup
if (isHUD)
themeState = themeState.and(CPThemeStateHUD);
themeState = isKeyWindow ? themeState.and(CPThemeStateKeyWindow) : themeState;
var bezelColor,
segment = _segments[i],
bezelView = [self layoutEphemeralSubviewNamed:"segment-bezel-" + i
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil],
contentView = [self layoutEphemeralSubviewNamed:@"segment-content-" + i
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:"segment-bezel-" + i];
if (i == 0)
bezelColor = [self valueForThemeAttribute:@"left-segment-bezel-color" inState:themeState];
else if (i < count - 1)
bezelColor = [self valueForThemeAttribute:@"center-segment-bezel-color" inState:themeState];
else
bezelColor = [self valueForThemeAttribute:@"right-segment-bezel-color" inState:themeState];
[bezelView setBackgroundColor:bezelColor];
// Trick : Put selected segments over unselected ones to automaticaly manage borders
#if PLATFORM(DOM)
contentView._DOMElement.style.zIndex = ([segment selected] ? 1 : 0);
bezelView._DOMElement.style.zIndex = ([segment selected] ? 1 : 0);
#endif
[contentView setText:[segment label]];
[contentView setImage:[segment image]];
[contentView setFont:[self valueForThemeAttribute:@"font" inState:themeState]];
[contentView setTextColor:[self valueForThemeAttribute:@"text-color" inState:([segment enabled] ? themeState : themeState.and(CPThemeStateDisabled))]];
[contentView setAlignment:[self valueForThemeAttribute:@"alignment" inState:themeState]];
[contentView setVerticalAlignment:[self valueForThemeAttribute:@"vertical-alignment" inState:themeState]];
[contentView setLineBreakMode:[self valueForThemeAttribute:@"line-break-mode" inState:themeState]];
[contentView setTextShadowColor:[self valueForThemeAttribute:@"text-shadow-color" inState:themeState]];
[contentView setTextShadowOffset:[self valueForThemeAttribute:@"text-shadow-offset" inState:themeState]];
[contentView setImageScaling:[self valueForThemeAttribute:@"image-scaling" inState:themeState]];
if ([segment image] && [segment label])
[contentView setImagePosition:[self valueForThemeAttribute:@"image-position" inState:themeState]];
else if ([segment image])
[contentView setImagePosition:CPImageOnly];
}
}
else
{
// Legacy (Canvas) Styling
var themeState = _themeStates[0],
isDisabled = [self hasThemeState:CPThemeStateDisabled],
isControlSizeSmall = [self hasThemeState:CPThemeStateControlSizeSmall],
isControlSizeMini = [self hasThemeState:CPThemeStateControlSizeMini];
themeState = isDisabled ? themeState.and(CPThemeStateDisabled) : themeState;
@@ -669,59 +738,114 @@ CPSegmentSwitchTrackingMomentary = 2;
else if (isControlSizeMini)
themeState = themeState.and(CPThemeStateControlSizeMini);
var bezelColor = [self valueForThemeAttribute:@"center-segment-bezel-color"
inState:themeState],
// Apply HUD state to Left Cap
if (isHUD)
themeState = themeState.and(CPThemeStateHUD);
bezelView = [self layoutEphemeralSubviewNamed:"segment-bezel-" + i
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
var leftCapColor = [self valueForThemeAttribute:@"left-segment-bezel-color"
inState:themeState],
[bezelView setBackgroundColor:bezelColor];
leftBezelView = [self layoutEphemeralSubviewNamed:@"left-segment-bezel"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
// layout image/title views
var segment = _segments[i],
contentView = [self layoutEphemeralSubviewNamed:@"segment-content-" + i
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"segment-bezel-" + i];
[leftBezelView setBackgroundColor:leftCapColor];
[contentView setText:[segment label]];
[contentView setImage:[segment image]];
var themeState = _themeStates[_themeStates.length - 1];
[contentView setFont:[self valueForThemeAttribute:@"font" inState:themeState]];
[contentView setTextColor:[self valueForThemeAttribute:@"text-color" inState:themeState]];
[contentView setAlignment:[self valueForThemeAttribute:@"alignment" inState:themeState]];
[contentView setVerticalAlignment:[self valueForThemeAttribute:@"vertical-alignment" inState:themeState]];
[contentView setLineBreakMode:[self valueForThemeAttribute:@"line-break-mode" inState:themeState]];
[contentView setTextShadowColor:[self valueForThemeAttribute:@"text-shadow-color" inState:themeState]];
[contentView setTextShadowOffset:[self valueForThemeAttribute:@"text-shadow-offset" inState:themeState]];
[contentView setImageScaling:[self valueForThemeAttribute:@"image-scaling" inState:themeState]];
if ([segment image] && [segment label])
[contentView setImagePosition:[self valueForThemeAttribute:@"image-position" inState:themeState]];
else if ([segment image])
[contentView setImagePosition:CPImageOnly];
if (i == count - 1)
continue;
var borderState = _themeStates[i].and(_themeStates[i + 1]);
borderState = isDisabled ? borderState.and(CPThemeStateDisabled) : borderState;
themeState = isDisabled ? themeState.and(CPThemeStateDisabled) : themeState;
if (isControlSizeSmall)
borderState = borderState.and(CPThemeStateControlSizeSmall);
themeState = themeState.and(CPThemeStateControlSizeSmall);
else if (isControlSizeMini)
borderState = borderState.and(CPThemeStateControlSizeMini);
themeState = themeState.and(CPThemeStateControlSizeMini);
var borderColor = [self valueForThemeAttribute:@"divider-bezel-color"
inState:borderState],
// Apply HUD state to Right Cap
if (isHUD)
themeState = themeState.and(CPThemeStateHUD);
var rightCapColor = [self valueForThemeAttribute:@"right-segment-bezel-color"
inState:themeState],
rightBezelView = [self layoutEphemeralSubviewNamed:@"right-segment-bezel"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[rightBezelView setBackgroundColor:rightCapColor];
for (var i = 0, count = _themeStates.length; i < count; i++)
{
var themeState = _themeStates[i];
themeState = isDisabled ? themeState.and(CPThemeStateDisabled) : themeState;
if (isControlSizeSmall)
themeState = themeState.and(CPThemeStateControlSizeSmall);
else if (isControlSizeMini)
themeState = themeState.and(CPThemeStateControlSizeMini);
// Apply HUD state to Center Segments
if (isHUD)
themeState = themeState.and(CPThemeStateHUD);
var bezelColor = [self valueForThemeAttribute:@"center-segment-bezel-color"
inState:themeState],
bezelView = [self layoutEphemeralSubviewNamed:"segment-bezel-" + i
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[bezelView setBackgroundColor:bezelColor];
// layout image/title views
var segment = _segments[i],
contentView = [self layoutEphemeralSubviewNamed:@"segment-content-" + i
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"segment-bezel-" + i];
[contentView setText:[segment label]];
[contentView setImage:[segment image]];
[contentView setFont:[self valueForThemeAttribute:@"font" inState:themeState]];
[contentView setTextColor:[self valueForThemeAttribute:@"text-color" inState:themeState]];
[contentView setAlignment:[self valueForThemeAttribute:@"alignment" inState:themeState]];
[contentView setVerticalAlignment:[self valueForThemeAttribute:@"vertical-alignment" inState:themeState]];
[contentView setLineBreakMode:[self valueForThemeAttribute:@"line-break-mode" inState:themeState]];
[contentView setTextShadowColor:[self valueForThemeAttribute:@"text-shadow-color" inState:themeState]];
[contentView setTextShadowOffset:[self valueForThemeAttribute:@"text-shadow-offset" inState:themeState]];
[contentView setImageScaling:[self valueForThemeAttribute:@"image-scaling" inState:themeState]];
if ([segment image] && [segment label])
[contentView setImagePosition:[self valueForThemeAttribute:@"image-position" inState:themeState]];
else if ([segment image])
[contentView setImagePosition:CPImageOnly];
if (i == count - 1)
continue;
var borderState = _themeStates[i].and(_themeStates[i + 1]);
borderState = isDisabled ? borderState.and(CPThemeStateDisabled) : borderState;
if (isControlSizeSmall)
borderState = borderState.and(CPThemeStateControlSizeSmall);
else if (isControlSizeMini)
borderState = borderState.and(CPThemeStateControlSizeMini);
// Apply HUD state to Dividers
if (isHUD)
borderState = borderState.and(CPThemeStateHUD);
var borderColor = [self valueForThemeAttribute:@"divider-bezel-color"
inState:borderState],
borderView = [self layoutEphemeralSubviewNamed:"divider-bezel-" + i
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[borderView setBackgroundColor:borderColor];
[borderView setBackgroundColor:borderColor];
}
}
}
@@ -802,7 +926,10 @@ CPSegmentSwitchTrackingMomentary = 2;
label = [segment label],
image = [segment image];
width = (label ? [label sizeWithFont:[self font]].width : 4.0) + (image ? [image size].width : 0) + contentInsetWidth;
contentInsetWidth += ([[self actualTheme] isCSSBased] && ((aSegment == 0) || (aSegment == [self _indexOfLastSegment])) ? [self valueForThemeAttribute:@"divider-thickness" inState:themeState] : 0);
// add 1 pixel to account for possible fractional pixels at right edge
width = CEIL((label ? [label sizeWithFont:[self font]].width + 1: 4.0) + (image ? [image size].width : 0) + contentInsetWidth);
}
return CGRectMake(left, top, width, height);
@@ -810,6 +937,14 @@ CPSegmentSwitchTrackingMomentary = 2;
- (CGRect)contentFrameForSegment:(unsigned)aSegment
{
if ([[self actualTheme] isCSSBased])
{
var bezelFrame = [self bezelFrameForSegment:aSegment],
contentInset = [self currentValueForThemeAttribute:@"content-inset"];
return CGRectInsetByInset(bezelFrame, contentInset);
}
var height = [self currentValueForThemeAttribute:@"min-size"].height,
contentInset = [self currentValueForThemeAttribute:@"content-inset"],
width = CGRectGetWidth([self frameForSegment:aSegment]),
@@ -872,68 +1007,64 @@ CPSegmentSwitchTrackingMomentary = 2;
var type = [anEvent type],
location = [self convertPoint:[anEvent locationInWindow] fromView:nil];
switch (type)
if (type == CPLeftMouseUp)
{
case CPLeftMouseUp:
if (_trackingSegment === CPNotFound)
return;
if (_trackingSegment === [self testSegment:location])
{
if (_trackingMode == CPSegmentSwitchTrackingSelectAny)
{
[self setSelected:![self isSelectedForSegment:_trackingSegment] forSegment:_trackingSegment];
// With ANY, _selectedSegment means last pressed.
_selectedSegment = _trackingSegment;
}
else
[self setSelected:YES forSegment:_trackingSegment];
[self sendAction:[self action] to:[self target]];
if (_trackingMode == CPSegmentSwitchTrackingMomentary)
{
[self setSelected:NO forSegment:_trackingSegment];
_selectedSegment = CPNotFound;
}
}
[self drawSegmentBezel:_trackingSegment highlight:NO];
_trackingSegment = CPNotFound;
if (_trackingSegment == -1)
return;
case CPLeftMouseDown:
var trackingSegment = [self testSegment:location];
if (trackingSegment > CPNotFound && [self isEnabledForSegment:trackingSegment])
if (_trackingSegment === [self testSegment:location])
{
if (_trackingMode == CPSegmentSwitchTrackingSelectAny)
{
_trackingHighlighted = YES;
_trackingSegment = trackingSegment;
[self drawSegmentBezel:_trackingSegment highlight:YES];
[self setSelected:![self isSelectedForSegment:_trackingSegment] forSegment:_trackingSegment];
// With ANY, _selectedSegment means last pressed.
_selectedSegment = _trackingSegment;
}
else
[self setSelected:YES forSegment:_trackingSegment];
break;
[self sendAction:[self action] to:[self target]];
case CPLeftMouseDragged:
if (_trackingSegment === CPNotFound)
return;
var highlighted = [self testSegment:location] === _trackingSegment;
if (highlighted != _trackingHighlighted)
if (_trackingMode == CPSegmentSwitchTrackingMomentary)
{
_trackingHighlighted = highlighted;
[self setSelected:NO forSegment:_trackingSegment];
[self drawSegmentBezel:_trackingSegment highlight:_trackingHighlighted];
_selectedSegment = CPNotFound;
}
}
break;
[self drawSegmentBezel:_trackingSegment highlight:NO];
_trackingSegment = -1;
return;
}
if (type == CPLeftMouseDown)
{
var trackingSegment = [self testSegment:location];
if (trackingSegment > -1 && [self isEnabledForSegment:trackingSegment])
{
_trackingHighlighted = YES;
_trackingSegment = trackingSegment;
[self drawSegmentBezel:_trackingSegment highlight:YES];
}
}
else if (type == CPLeftMouseDragged)
{
if (_trackingSegment == -1)
return;
var highlighted = [self testSegment:location] === _trackingSegment;
if (highlighted != _trackingHighlighted)
{
_trackingHighlighted = highlighted;
[self drawSegmentBezel:_trackingSegment highlight:_trackingHighlighted];
}
}
[CPApp setTarget:self selector:@selector(trackSegment:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
+1 -1
View File
@@ -102,6 +102,7 @@ CPThemeStateShadowViewHeavy = CPThemeState("shadowview-style-heavy");
[self setWeight:CPLightShadow];
[self setHitTests:NO];
[self setClipsToBounds:NO];
}
return self;
@@ -169,7 +170,6 @@ CPThemeStateShadowViewHeavy = CPThemeState("shadowview-style-heavy");
- (void)layoutSubviews
{
[super layoutSubviews];
[self setBackgroundColor:[self currentValueForThemeAttribute:@"bezel-color"]];
}
+808 -150
View File
File diff suppressed because it is too large Load Diff
+12 -11
View File
@@ -32,6 +32,7 @@
@end
@global document
var CPSoundDelegate_sound_didFinishPlaying_ = 1 << 1;
@@ -65,8 +66,8 @@ CPSoundPlayBackStatePause = 2;
unsigned _implementedDelegateMethods;
}
#pragma mark -
#pragma mark Initialization
// MARK: -
// MARK: Initialization
- (id)init
{
@@ -146,8 +147,8 @@ CPSoundPlayBackStatePause = 2;
}
#pragma mark -
#pragma mark Delegate methods
// MARK: -
// MARK: Delegate methods
/*!
Sets the sound's delegate.
@@ -165,8 +166,8 @@ CPSoundPlayBackStatePause = 2;
_implementedDelegateMethods |= CPSoundDelegate_sound_didFinishPlaying_;
}
#pragma mark -
#pragma mark Events listener
// MARK: -
// MARK: Events listener
/*! @ignore
*/
@@ -198,8 +199,8 @@ CPSoundPlayBackStatePause = 2;
}
#pragma mark -
#pragma mark Media controls
// MARK: -
// MARK: Media controls
/*!
Play the sound.
@@ -323,8 +324,8 @@ CPSoundPlayBackStatePause = 2;
_audioTag.volume = aVolume;
}
#pragma mark -
#pragma mark Accessors
// MARK: -
// MARK: Accessors
/*!
Returns the duration in seconds of the sound.
@@ -363,4 +364,4 @@ CPSoundPlayBackStatePause = 2;
[_delegate sound:self didFinishPlaying:finishedPlaying];
}
@end
@end
+914 -522
View File
File diff suppressed because it is too large Load Diff
+388
View File
@@ -0,0 +1,388 @@
/*
* CPSplitViewController.j
*
* Created by Daniel Boehringer on September 2, 2025.
* Copyright (c) 2025 Daniel Boehringer. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPViewController.j"
@import "CPSplitView.j"
var CPSplitViewControllerAutomaticDimension = -1.0;
/**
* A container view controller that manages two or more child view
* controllers in a split view interface.
*
* This class provides a controller-level abstraction for CPSplitView,
* managing the addition, removal, and arrangement of view controllers
* through CPSplitViewItem instances.
*
* This implementation was synthesized with the assistance of an LLM,
* directed by the author.
*/
@implementation CPSplitViewController : CPViewController <CPSplitViewDelegate>
{
/** @private The underlying split view that arranges the child views. */
CPSplitView _splitView;
/** @private An array of CPSplitViewItem objects managed by this controller. */
CPMutableArray _splitViewItems;
/** @private The minimum thickness for sidebars to be displayed inline. */
CPNumber _minimumThicknessForInlineSidebars;
}
// MARK: - Initialization
- (id)init
{
if (self = [super init])
{
_splitViewItems = [CPMutableArray array];
_minimumThicknessForInlineSidebars = 20.0;
}
return self;
}
// MARK: - View Lifecycle
- (void)loadView
{
if (!_splitView)
{
_splitView = [[CPSplitView alloc] initWithFrame:CGRectMake(0,0,400,400)];
[_splitView setDelegate:self];
}
[self setView:_splitView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (var i = 0; i < [_splitViewItems count]; i++)
{
var viewController = [[_splitViewItems objectAtIndex:i] viewController];
[[self splitView] addArrangedSubview:[viewController view]];
}
}
// MARK: - Accessors
/**
* Returns the CPSplitView instance managed by the controller.
*
* @returns {CPSplitView} The split view.
*/
- (CPSplitView)splitView
{
return _splitView;
}
/**
* Sets a custom split view for the controller.
*
* @param {CPSplitView} splitView The custom split view to use.
*/
- (void)setSplitView:(CPSplitView)splitView
{
if (_splitView !== splitView)
{
_splitView = splitView;
[_splitView setDelegate:self];
if ([self isViewLoaded])
[self setView:_splitView];
}
}
/**
* Returns the array of split view items.
*
* @returns {CPArray} The array of CPSplitViewItem objects.
*/
- (CPArray)splitViewItems
{
return _splitViewItems;
}
/**
* Sets the array of split view items, replacing any existing items.
*
* @param {CPArray} splitViewItems An array of CPSplitViewItem objects.
*/
- (void)setSplitViewItems:(CPArray)splitViewItems
{
// Remove all existing items
while ([_splitViewItems count] > 0)
{
[self removeSplitViewItem:[_splitViewItems lastObject]];
}
// Add new items
for (var i = 0; i < [splitViewItems count]; i++)
{
[self addSplitViewItem:[splitViewItems objectAtIndex:i]];
}
}
// MARK: - Managing Split View Items
/**
* Adds a split view item to the end of the split view.
*
* @param {CPSplitViewItem} splitViewItem The split view item to add.
*/
- (void)addSplitViewItem:(CPSplitViewItem)splitViewItem
{
[self insertSplitViewItem:splitViewItem atIndex:[_splitViewItems count]];
}
/**
* Inserts a split view item at a specific index.
*
* @param {CPSplitViewItem} splitViewItem The split view item to insert.
* @param {CPInteger} index The zero-based index at which to insert the item.
*/
- (void)insertSplitViewItem:(CPSplitViewItem)splitViewItem atIndex:(CPInteger)index
{
[splitViewItem _setSplitViewController:self];
[_splitViewItems insertObject:splitViewItem atIndex:index];
[self addChildViewController:[splitViewItem viewController]];
if ([self isViewLoaded])
[[self splitView] insertArrangedSubview:[[splitViewItem viewController] view] atIndex:index];
}
/**
* Removes the specified split view item.
*
* @param {CPSplitViewItem} splitViewItem The split view item to remove.
*/
- (void)removeSplitViewItem:(CPSplitViewItem)splitViewItem
{
var viewController = [splitViewItem viewController];
if ([self isViewLoaded])
[[viewController view] removeFromSuperview];
[viewController removeFromParentViewController];
[splitViewItem _setSplitViewController:nil];
[_splitViewItems removeObject:splitViewItem];
}
/**
* Retrieves the split view item associated with a given view controller.
*
* @param {CPViewController} viewController The view controller to find.
* @returns {CPSplitViewItem | null} The corresponding split view item, or nil if not found.
*/
- (CPSplitViewItem)splitViewItemForViewController:(CPViewController)viewController
{
for (var i = 0; i < [_splitViewItems count]; i++)
{
var item = [_splitViewItems objectAtIndex:i];
if ([item viewController] === viewController)
return item;
}
return nil;
}
// MARK: - Managing Sidebars and Inspectors
/**
* Toggles the collapsed state of the first split view item, typically a sidebar.
*
* @param {id} sender The object that initiated the action.
*/
- (void)toggleSidebar:(id)sender
{
if ([_splitViewItems count] > 0)
{
var sidebarItem = [_splitViewItems objectAtIndex:0];
[sidebarItem setCollapsed:![sidebarItem isCollapsed]];
}
}
/**
* Toggles the collapsed state of the last split view item, typically an inspector.
*
* @param {id} sender The object that initiated the action.
*/
- (void)toggleInspector:(id)sender
{
if ([_splitViewItems count] > 1)
{
var inspectorItem = [_splitViewItems lastObject];
[inspectorItem setCollapsed:![inspectorItem isCollapsed]];
}
}
/**
* Returns the minimum thickness for sidebars to be displayed inline.
*
* @returns {CPNumber} The minimum thickness.
*/
- (CPNumber)minimumThicknessForInlineSidebars
{
return _minimumThicknessForInlineSidebars;
}
// MARK: - CPSplitViewDelegate Methods
// Note: A more complete implementation would forward these delegate methods
// to a separate delegate property on the CPSplitViewController itself.
// For now, these are stubbed to demonstrate where they would be handled.
- (BOOL)splitView:(CPSplitView)splitView canCollapseSubview:(CPView)subview
{
// Default behavior: allow all subviews to be collapsed.
return YES;
}
- (CGFloat)splitView:(CPSplitView)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(CPInteger)dividerIndex
{
return proposedMinimumPosition;
}
- (CGFloat)splitView:(CPSplitView)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(CPInteger)dividerIndex
{
return proposedMaximumPosition;
}
- (CGRect)splitView:(CPSplitView)splitView effectiveRect:(CGRect)proposedEffectiveRect forDrawnRect:(CGRect)drawnRect ofDividerAtIndex:(CPInteger)dividerIndex
{
// Default behavior: return the proposed rectangle.
// This can be overridden to provide a larger or custom hit area for the divider.
return proposedEffectiveRect;
}
- (void)splitViewDidResizeSubviews:(CPNotification)notification
{
// Can be used to respond to user-initiated resizing.
}
@end
/**
* An object that manages a view controller within a CPSplitViewController.
*
* A CPSplitViewItem acts as a wrapper around a CPViewController,
* maintaining properties like its collapsed state within the parent
* split view controller.
*/
@implementation CPSplitViewItem : CPObject
{
/** @private The view controller managed by this item. */
CPViewController _viewController;
/** @private A boolean indicating whether the item is collapsed. */
BOOL _isCollapsed;
/** @private A weak reference to the owning split view controller. */
CPSplitViewController _splitViewController;
}
// MARK: - Class Methods
/**
* Creates and returns a new split view item with the specified view controller.
*
* @param {CPViewController} viewController The view controller for the new item.
* @returns {instancetype} A new CPSplitViewItem instance.
*/
+ (instancetype)splitViewItemWithViewController:(CPViewController)viewController
{
return [[self alloc] initWithViewController:viewController];
}
// MARK: - Initialization
/**
* Initializes a new split view item with the specified view controller.
*
* @param {CPViewController} viewController The view controller for the new item.
* @returns {id} The initialized CPSplitViewItem instance.
*/
- (id)initWithViewController:(CPViewController)viewController
{
if (self = [super init])
{
_viewController = viewController;
_isCollapsed = NO;
}
return self;
}
// MARK: - Accessors
/**
* Returns the view controller associated with the item.
*
* @returns {CPViewController} The associated view controller.
*/
- (CPViewController)viewController
{
return _viewController;
}
/**
* Returns a boolean value indicating whether the item is collapsed.
*
* @returns {BOOL} YES if the item is collapsed, otherwise NO.
*/
- (BOOL)isCollapsed
{
return _isCollapsed;
}
/**
* Sets the collapsed state of the item.
* When collapsed, the view controller's view is hidden.
*
* @param {BOOL} shouldCollapse YES to collapse the item, NO to expand it.
*/
- (void)setCollapsed:(BOOL)shouldCollapse
{
if (_isCollapsed === shouldCollapse)
return;
_isCollapsed = shouldCollapse;
[[_viewController view] setHidden:shouldCollapse];
}
/**
* Returns the split view controller that owns this item.
*
* @returns {CPSplitViewController | null} The parent split view controller.
*/
- (CPSplitViewController)splitViewController
{
return _splitViewController;
}
/**
* @private
* Sets the owning split view controller. This method is for internal use by
* CPSplitViewController.
*
* @param {CPSplitViewController} splitViewController The parent controller.
*/
- (void)_setSplitViewController:(CPSplitViewController)splitViewController
{
_splitViewController = splitViewController;
}
@end
+698
View File
@@ -0,0 +1,698 @@
/*
* CPStackView.j
* AppKit
*
* Created by Daniel Boehringer.
* Copyright 2025, Cappuccino Project.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPView.j"
// Gravity Areas
@typedef CPStackViewGravity
CPStackViewGravityTop = 1;
CPStackViewGravityLeading = 1;
CPStackViewGravityCenter = 2;
CPStackViewGravityBottom = 3;
CPStackViewGravityTrailing = 3;
// Distribution (Deprecated in modern macOS, but kept for compatibility/logic)
@typedef CPStackViewDistribution
CPStackViewDistributionGravityAreas = 0;
CPStackViewDistributionFill = 1;
CPStackViewDistributionFillEqually = 2;
CPStackViewDistributionFillProportionally = 3;
CPStackViewDistributionEqualSpacing = 4;
CPStackViewDistributionEqualCentering = 5;
// Visibility Priority
@typedef CPStackViewVisibilityPriority
CPStackViewVisibilityPriorityMustHold = 1000.0;
CPStackViewVisibilityPriorityNotVisible = 0.0;
var CPStackViewSpacingUseDefault = 3.40282347e+38; // FLT_MAX
/*!
@ingroup appkit
@class CPStackView
CPStackView arranges an array of views horizontally or vertically and updates
their placement and sizing when the window size changes.
Unlike a simple list, CPStackView supports "Gravity Areas" (Leading, Center, Trailing),
allowing you to pin groups of views to specific sections of the layout.
*/
@implementation CPStackView : CPView
{
CPUserInterfaceLayoutOrientation _orientation;
CPLayoutAttribute _alignment;
float _spacing;
CPEdgeInsets _edgeInsets;
BOOL _detachesHiddenViews;
// View Storage by Gravity
CPMutableArray _viewsLeading;
CPMutableArray _viewsCenter;
CPMutableArray _viewsTrailing;
// Internal cache of all arranged subviews to maintain order for hittesting/iterating
CPMutableArray _arrangedSubviews;
// Custom Spacing storage
CPMapTable _customSpacings;
// Visibility Priorities
CPMapTable _visibilityPriorities;
}
// MARK: -
// MARK: Initialization
+ (CPStackView)stackViewWithViews:(CPArray)views
{
var stackView = [[CPStackView alloc] initWithFrame:CGRectMakeZero()];
for (var i = 0, count = [views count]; i < count; i++)
[stackView addView:views[i] inGravity:CPStackViewGravityLeading];
return stackView;
}
- (id)initWithFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
_orientation = CPUserInterfaceLayoutOrientationHorizontal;
_alignment = CPLayoutAttributeCenterY; // Default alignment
_spacing = 8.0; // Default Cocoa spacing
_edgeInsets = CPEdgeInsetsMake(0, 0, 0, 0);
_detachesHiddenViews = YES;
_viewsLeading = [[CPMutableArray alloc] init];
_viewsCenter = [[CPMutableArray alloc] init];
_viewsTrailing = [[CPMutableArray alloc] init];
_arrangedSubviews = [[CPMutableArray alloc] init];
_customSpacings = [[CPMapTable alloc] init];
_visibilityPriorities = [[CPMapTable alloc] init];
}
return self;
}
// MARK: -
// MARK: Configuration
/*!
The horizontal or vertical layout direction of the stack view.
*/
- (CPUserInterfaceLayoutOrientation)orientation
{
return _orientation;
}
- (void)setOrientation:(CPUserInterfaceLayoutOrientation)anOrientation
{
if (_orientation === anOrientation)
return;
_orientation = anOrientation;
// Reset default alignment based on new orientation if needed,
// though usually developer sets alignment explicitly.
// If switching to Vertical, CenterY makes less sense, usually CenterX.
if (_orientation === CPUserInterfaceLayoutOrientationVertical)
{
if (_alignment === CPLayoutAttributeCenterY)
_alignment = CPLayoutAttributeCenterX;
}
else
{
if (_alignment === CPLayoutAttributeCenterX)
_alignment = CPLayoutAttributeCenterY;
}
[self setNeedsLayout:YES];
}
/*!
The view alignment within the stack view.
Common values:
Horizontal: CPLayoutAttributeTop, CPLayoutAttributeBottom, CPLayoutAttributeCenterY, CPLayoutAttributeHeight (fill)
Vertical: CPLayoutAttributeLeading, CPLayoutAttributeTrailing, CPLayoutAttributeCenterX, CPLayoutAttributeWidth (fill)
*/
- (CPLayoutAttribute)alignment
{
return _alignment;
}
- (void)setAlignment:(CPLayoutAttribute)anAlignment
{
if (_alignment === anAlignment)
return;
_alignment = anAlignment;
[self setNeedsLayout:YES];
}
/*!
The minimum spacing, in points, between adjacent views in the stack view.
*/
- (float)spacing
{
return _spacing;
}
- (void)setSpacing:(float)aSpacing
{
if (_spacing === aSpacing)
return;
_spacing = aSpacing;
[self setNeedsLayout:YES];
}
/*!
The geometric padding, in points, inside the stack view, surrounding its views.
*/
- (CPEdgeInsets)edgeInsets
{
return _edgeInsets;
}
- (void)setEdgeInsets:(CPEdgeInsets)insets
{
if (CPEdgeInsetsEqualToEdgeInsets(_edgeInsets, insets))
return;
_edgeInsets = insets;
[self setNeedsLayout:YES];
}
/*!
A Boolean value that indicates whether the stack view removes hidden views from its view hierarchy.
*/
- (BOOL)detachesHiddenViews
{
return _detachesHiddenViews;
}
- (void)setDetachesHiddenViews:(BOOL)shouldDetach
{
if (_detachesHiddenViews === shouldDetach)
return;
_detachesHiddenViews = shouldDetach;
[self setNeedsLayout:YES];
}
// MARK: -
// MARK: Managing Views in Gravity Areas
- (CPArray)_containerForGravity:(CPStackViewGravity)gravity
{
if (gravity === CPStackViewGravityCenter)
return _viewsCenter;
else if (gravity === CPStackViewGravityTrailing) // or Bottom
return _viewsTrailing;
return _viewsLeading; // Leading or Top
}
/*!
Adds a view to the end of the stack view gravity area.
*/
- (void)addView:(CPView)aView inGravity:(CPStackViewGravity)gravity
{
var container = [self _containerForGravity:gravity];
// Check if view is already in a container
if ([_arrangedSubviews containsObject:aView])
[self removeView:aView];
[container addObject:aView];
[_arrangedSubviews addObject:aView];
// Add as actual subview
if ([aView superview] !== self)
[self addSubview:aView];
[self setNeedsLayout:YES];
}
/*!
Adds a view to a stack view gravity area at a specified index position.
*/
- (void)insertView:(CPView)aView atIndex:(CPInteger)index inGravity:(CPStackViewGravity)gravity
{
var container = [self _containerForGravity:gravity];
if ([_arrangedSubviews containsObject:aView])
[self removeView:aView];
if (index >= [container count])
[container addObject:aView];
else
[container insertObject:aView atIndex:index];
[_arrangedSubviews addObject:aView];
if ([aView superview] !== self)
[self addSubview:aView];
[self setNeedsLayout:YES];
}
/*!
Specifies an array of views for a specified gravity area in the stack view, replacing any previous views in that area.
*/
- (void)setViews:(CPArray)views inGravity:(CPStackViewGravity)gravity
{
var container = [self _containerForGravity:gravity];
// Remove old views from arranged list and superview
for (var i = 0; i < [container count]; i++)
{
var oldView = container[i];
[oldView removeFromSuperview];
[_arrangedSubviews removeObject:oldView];
}
[container removeAllObjects];
for (var i = 0; i < [views count]; i++)
{
var newView = views[i];
[container addObject:newView];
[_arrangedSubviews addObject:newView];
[self addSubview:newView];
}
[self setNeedsLayout:YES];
}
/*!
Removes a specified view from the stack view.
*/
- (void)removeView:(CPView)aView
{
if (![_arrangedSubviews containsObject:aView])
return;
[_viewsLeading removeObject:aView];
[_viewsCenter removeObject:aView];
[_viewsTrailing removeObject:aView];
[_arrangedSubviews removeObject:aView];
[aView removeFromSuperview];
[self setNeedsLayout:YES];
}
/*!
Returns the array of views in the specified gravity area in the stack view.
*/
- (CPArray)viewsInGravity:(CPStackViewGravity)gravity
{
return [[self _containerForGravity:gravity] copy];
}
/*!
The array of views arranged by the stack view.
*/
- (CPArray)arrangedSubviews
{
return [_arrangedSubviews copy];
}
/*!
Adds the specified view to the end of the arranged subviews list.
(Defaults to Leading gravity if not specified).
*/
- (void)addArrangedSubview:(CPView)view
{
[self addView:view inGravity:CPStackViewGravityLeading];
}
/*!
Removes the provided view from the stacks array of arranged subviews.
*/
- (void)removeArrangedSubview:(CPView)view
{
[self removeView:view];
}
// MARK: -
// MARK: Custom Spacing
- (float)customSpacingAfterView:(CPView)aView
{
var val = [_customSpacings objectForKey:aView];
if (val)
return [val floatValue];
return CPStackViewSpacingUseDefault;
}
- (void)setCustomSpacing:(float)spacing afterView:(CPView)aView
{
if (spacing === CPStackViewSpacingUseDefault)
[_customSpacings removeObjectForKey:aView];
else
[_customSpacings setObject:spacing forKey:aView];
[self setNeedsLayout:YES];
}
- (float)_spacingAfterView:(CPView)aView
{
var custom = [self customSpacingAfterView:aView];
if (custom !== CPStackViewSpacingUseDefault)
return custom;
return _spacing;
}
// MARK: -
// MARK: Visibility Priority
- (void)setVisibilityPriority:(float)priority forView:(CPView)aView
{
[_visibilityPriorities setObject:priority forKey:aView];
if (priority === CPStackViewVisibilityPriorityNotVisible)
{
[aView setHidden:YES];
}
else if (priority === CPStackViewVisibilityPriorityMustHold)
{
[aView setHidden:NO];
}
// Note: Intermediate priorities require complex constraint logic
// or a multi-pass layout system to determine fitting, which is
// simplified here to basic Hidden/Visible states.
[self setNeedsLayout:YES];
}
- (float)visibilityPriorityForView:(CPView)aView
{
var val = [_visibilityPriorities objectForKey:aView];
if (val)
return [val floatValue];
return CPStackViewVisibilityPriorityMustHold;
}
// MARK: -
// MARK: Layout
- (void)resizeSubviewsWithOldSize:(CGSize)oldSize
{
[self layoutSubviews];
}
- (void)layoutSubviews
{
if (_orientation === CPUserInterfaceLayoutOrientationVertical)
[self _layoutVertical];
else
[self _layoutHorizontal];
}
- (void)_layoutHorizontal
{
var bounds = [self bounds],
availWidth = CGRectGetWidth(bounds) - _edgeInsets.left - _edgeInsets.right,
availHeight = CGRectGetHeight(bounds) - _edgeInsets.top - _edgeInsets.bottom,
currentX = _edgeInsets.left;
// 1. Layout Leading Views
currentX = [self _layoutViews:_viewsLeading startOffset:currentX availableOrthogonalSize:availHeight direction:1];
// 2. Layout Trailing Views
// We layout backwards from the right
var startRight = CGRectGetWidth(bounds) - _edgeInsets.right;
[self _layoutViews:_viewsTrailing startOffset:startRight availableOrthogonalSize:availHeight direction:-1];
// 3. Layout Center Views
if ([_viewsCenter count] > 0)
{
// Calculate total width of center stack
var centerStackWidth = 0.0;
for (var i = 0; i < [_viewsCenter count]; i++)
{
var view = _viewsCenter[i];
if (_detachesHiddenViews && [view isHidden]) continue;
centerStackWidth += CGRectGetWidth([view frame]);
if (i < [_viewsCenter count] - 1)
centerStackWidth += [self _spacingAfterView:view];
}
var centerStart = (CGRectGetWidth(bounds) / 2.0) - (centerStackWidth / 2.0);
// Clamp to prevent overlap with Leading (simplified collision logic)
// ideally stack view compresses views, but here we just shift/clip
if (centerStart < currentX)
centerStart = currentX;
[self _layoutViews:_viewsCenter startOffset:centerStart availableOrthogonalSize:availHeight direction:1];
}
}
- (void)_layoutVertical
{
var bounds = [self bounds],
availWidth = CGRectGetWidth(bounds) - _edgeInsets.left - _edgeInsets.right,
availHeight = CGRectGetHeight(bounds) - _edgeInsets.top - _edgeInsets.bottom,
currentY = _edgeInsets.top;
// 1. Layout Top (Leading) Views
currentY = [self _layoutViews:_viewsLeading startOffset:currentY availableOrthogonalSize:availWidth direction:1];
// 2. Layout Bottom (Trailing) Views
var startBottom = CGRectGetHeight(bounds) - _edgeInsets.bottom;
[self _layoutViews:_viewsTrailing startOffset:startBottom availableOrthogonalSize:availWidth direction:-1];
// 3. Layout Center Views
if ([_viewsCenter count] > 0)
{
var centerStackHeight = 0.0;
for (var i = 0; i < [_viewsCenter count]; i++)
{
var view = _viewsCenter[i];
if (_detachesHiddenViews && [view isHidden]) continue;
centerStackHeight += CGRectGetHeight([view frame]);
if (i < [_viewsCenter count] - 1)
centerStackHeight += [self _spacingAfterView:view];
}
var centerStart = (CGRectGetHeight(bounds) / 2.0) - (centerStackHeight / 2.0);
if (centerStart < currentY)
centerStart = currentY;
[self _layoutViews:_viewsCenter startOffset:centerStart availableOrthogonalSize:availWidth direction:1];
}
}
// Helper to layout a specific array of views in one direction
// Returns the ending offset
- (float)_layoutViews:(CPArray)views startOffset:(float)offset availableOrthogonalSize:(float)orthoSize direction:(int)dir
{
var cursor = offset;
var isVert = (_orientation === CPUserInterfaceLayoutOrientationVertical);
// If direction is -1 (Trailing/Bottom), we iterate backwards
// However, the standard behavior for trailing gravity is that the *last* view added is at the *end*.
// Leading: [A] [B] ->
// Trailing: -> [C] [D] (where D is rightmost)
// To support Trailing logic: We start at Right Edge, move left by Width(D), place D, move left by Spacing...
var count = [views count];
if (count === 0) return cursor;
// If direction is negative (Trailing), we process list in reverse order to stack them from edge inwards
var i = (dir === 1) ? 0 : count - 1;
var limit = (dir === 1) ? count : -1;
var step = (dir === 1) ? 1 : -1;
for (; i !== limit; i += step)
{
var view = views[i];
if (_detachesHiddenViews && [view isHidden])
continue;
var viewFrame = [view frame];
var viewSizePrimary = isVert ? CGRectGetHeight(viewFrame) : CGRectGetWidth(viewFrame);
// Handle Alignment (Orthogonal Axis)
var orthoPos = 0.0;
var viewOrthoSize = isVert ? CGRectGetWidth(viewFrame) : CGRectGetHeight(viewFrame);
// Apply Stretch/Fill Alignment
if (isVert)
{
// Vertical Stack, dealing with Width
if (_alignment === CPLayoutAttributeWidth || _alignment === CPLayoutAttributeLeading || _alignment === CPLayoutAttributeTrailing)
{
// Note: CPLayoutAttributeLeading/Trailing in this context implies filling width usually,
// or aligning to edges. Let's assume Width/Fill for Leading/Trailing/Left/Right
// in this simplified implementation, or strictly left/right.
if (_alignment === CPLayoutAttributeWidth || _alignment === CPLayoutAttributeLeft || _alignment === CPLayoutAttributeLeading)
{
// Fill width if explicit, or just align left
if (_alignment === CPLayoutAttributeWidth) viewOrthoSize = orthoSize;
orthoPos = _edgeInsets.left;
}
else if (_alignment === CPLayoutAttributeRight || _alignment === CPLayoutAttributeTrailing)
{
orthoPos = _edgeInsets.left + (orthoSize - viewOrthoSize);
}
else // CenterX
{
orthoPos = _edgeInsets.left + (orthoSize - viewOrthoSize) / 2.0;
}
}
else // Default CenterX
{
orthoPos = _edgeInsets.left + (orthoSize - viewOrthoSize) / 2.0;
}
}
else
{
// Horizontal Stack, dealing with Height
if (_alignment === CPLayoutAttributeHeight || _alignment === CPLayoutAttributeTop || _alignment === CPLayoutAttributeBottom)
{
if (_alignment === CPLayoutAttributeHeight)
{
viewOrthoSize = orthoSize;
orthoPos = _edgeInsets.top;
}
else if (_alignment === CPLayoutAttributeTop)
{
orthoPos = _edgeInsets.top;
}
else if (_alignment === CPLayoutAttributeBottom)
{
orthoPos = _edgeInsets.top + (orthoSize - viewOrthoSize);
}
else // CenterY
{
orthoPos = _edgeInsets.top + (orthoSize - viewOrthoSize) / 2.0;
}
}
else // Default CenterY
{
orthoPos = _edgeInsets.top + (orthoSize - viewOrthoSize) / 2.0;
}
}
// Calculate Position
var originX = 0.0, originY = 0.0;
var sizeW = 0.0, sizeH = 0.0;
if (isVert)
{
// Vertical
sizeH = viewSizePrimary;
sizeW = viewOrthoSize;
originX = orthoPos;
if (dir === 1) {
originY = cursor;
cursor += sizeH + [self _spacingAfterView:view];
} else {
cursor -= sizeH;
originY = cursor;
cursor -= [self _spacingAfterView:view];
}
}
else
{
// Horizontal
sizeW = viewSizePrimary;
sizeH = viewOrthoSize;
originY = orthoPos;
if (dir === 1) {
originX = cursor;
cursor += sizeW + [self _spacingAfterView:view];
} else {
cursor -= sizeW;
originX = cursor;
cursor -= [self _spacingAfterView:view];
}
}
[view setFrame:CGRectMake(originX, originY, sizeW, sizeH)];
}
return cursor;
}
// MARK: -
// MARK: CPCoding
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
_orientation = [aCoder decodeIntForKey:@"CPStackViewOrientation"];
_alignment = [aCoder decodeIntForKey:@"CPStackViewAlignment"];
_spacing = [aCoder decodeFloatForKey:@"CPStackViewSpacing"];
_edgeInsets = [aCoder decodeObjectForKey:@"CPStackViewEdgeInsets"]; // Assuming CPEdgeInsets supports obj coding or manual decode
if (!_edgeInsets) _edgeInsets = CPEdgeInsetsMake(0,0,0,0);
_detachesHiddenViews = [aCoder decodeBoolForKey:@"CPStackViewDetachesHiddenViews"];
_viewsLeading = [aCoder decodeObjectForKey:@"CPStackViewViewsLeading"] || [];
_viewsCenter = [aCoder decodeObjectForKey:@"CPStackViewViewsCenter"] || [];
_viewsTrailing = [aCoder decodeObjectForKey:@"CPStackViewViewsTrailing"] || [];
// Rebuild arranged subviews cache
_arrangedSubviews = [[CPMutableArray alloc] init];
[_arrangedSubviews addObjectsFromArray:_viewsLeading];
[_arrangedSubviews addObjectsFromArray:_viewsCenter];
[_arrangedSubviews addObjectsFromArray:_viewsTrailing];
_customSpacings = [aCoder decodeObjectForKey:@"CPStackViewCustomSpacings"] || [[CPMapTable alloc] init];
_visibilityPriorities = [[CPMapTable alloc] init]; // usually not persisted
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeInt:_orientation forKey:@"CPStackViewOrientation"];
[aCoder encodeInt:_alignment forKey:@"CPStackViewAlignment"];
[aCoder encodeFloat:_spacing forKey:@"CPStackViewSpacing"];
[aCoder encodeObject:_edgeInsets forKey:@"CPStackViewEdgeInsets"];
[aCoder encodeBool:_detachesHiddenViews forKey:@"CPStackViewDetachesHiddenViews"];
[aCoder encodeObject:_viewsLeading forKey:@"CPStackViewViewsLeading"];
[aCoder encodeObject:_viewsCenter forKey:@"CPStackViewViewsCenter"];
[aCoder encodeObject:_viewsTrailing forKey:@"CPStackViewViewsTrailing"];
[aCoder encodeObject:_customSpacings forKey:@"CPStackViewCustomSpacings"];
}
@end
+76 -15
View File
@@ -42,8 +42,8 @@
CPButton _buttonUp;
}
#pragma mark -
#pragma mark Initialization
// MARK: -
// MARK: Initialization
/*!
Initializes a CPStepper with given values.
@@ -147,8 +147,8 @@
[self _sizeToFit];
}
#pragma mark -
#pragma mark Superclass overrides
// MARK: -
// MARK: Superclass overrides
/*!
Set if the CPStepper is enabled or not.
@@ -175,12 +175,53 @@
[super setFrame:frame];
}
- (void)setThemeState:(CPThemeState)aState
{
[super setThemeState:aState];
// Force a layout update because the internal buttons (_buttonUp and _buttonDown)
// rely on layoutSubviews to receive the new theme attributes (like HUD colors).
[self setNeedsLayout];
}
- (void)unsetThemeState:(CPThemeState)aState
{
[super unsetThemeState:aState];
[self setNeedsLayout];
}
/*! @ignore */
- (void)layoutSubviews
{
var controlSizeThemeState = [self _controlSizeThemeState],
aFrame = [self frame],
upSize = [self valueForThemeAttribute:@"up-button-size" inState:controlSizeThemeState],
isHUD = [self hasThemeState:CPThemeStateHUD],
// 1. Prepare Lookup States (To fetch the correct image/color from the Stepper's theme)
normalLookupStates = [controlSizeThemeState, CPThemeStateBordered],
disabledLookupStates = [controlSizeThemeState, CPThemeStateBordered, CPThemeStateDisabled],
highlightedLookupStates = [controlSizeThemeState, CPThemeStateBordered, CPThemeStateHighlighted],
// 2. Prepare Target States (To tell the child buttons when to use this image)
normalTargetStates = [CPThemeStateBordered, CPButtonStateBezelStyleRoundRect],
disabledTargetStates = [CPThemeStateBordered, CPThemeStateDisabled, CPButtonStateBezelStyleRoundRect],
highlightedTargetStates = [CPThemeStateBordered, CPThemeStateHighlighted, CPButtonStateBezelStyleRoundRect];
// If we are in HUD mode, add CPThemeStateHUD to both lookup and target arrays
if (isHUD)
{
// Lookup: Ask theme for "HUD" version of the stepper arrows
normalLookupStates.push(CPThemeStateHUD);
disabledLookupStates.push(CPThemeStateHUD);
highlightedLookupStates.push(CPThemeStateHUD);
// Target: Tell the child buttons "Use this when you are in HUD state"
normalTargetStates.push(CPThemeStateHUD);
disabledTargetStates.push(CPThemeStateHUD);
highlightedTargetStates.push(CPThemeStateHUD);
}
var upSize = [self valueForThemeAttribute:@"up-button-size" inState:controlSizeThemeState],
downSize = [self valueForThemeAttribute:@"down-button-size" inState:controlSizeThemeState],
upFrame = CGRectMake(0, 0, upSize.width, upSize.height),
downFrame = CGRectMake(0, upSize.height, downSize.width, downSize.height);
@@ -188,12 +229,31 @@
[_buttonUp setFrame:upFrame];
[_buttonDown setFrame:downFrame];
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inStates:[controlSizeThemeState, CPThemeStateBordered]] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateDisabled]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateDisabled]];
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateHighlighted]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateHighlighted]];
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inStates:[controlSizeThemeState, CPThemeStateBordered]] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateDisabled]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateDisabled]];
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inStates:[controlSizeThemeState, CPThemeStateBordered, CPThemeStateHighlighted]] forThemeAttribute:@"bezel-color" inStates:[CPThemeStateBordered, CPThemeStateHighlighted]];
// Apply Up Button Attributes
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inStates:normalLookupStates]
forThemeAttribute:@"bezel-color"
inStates:normalTargetStates];
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inStates:disabledLookupStates]
forThemeAttribute:@"bezel-color"
inStates:disabledTargetStates];
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inStates:highlightedLookupStates]
forThemeAttribute:@"bezel-color"
inStates:highlightedTargetStates];
// Apply Down Button Attributes
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inStates:normalLookupStates]
forThemeAttribute:@"bezel-color"
inStates:normalTargetStates];
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inStates:disabledLookupStates]
forThemeAttribute:@"bezel-color"
inStates:disabledTargetStates];
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inStates:highlightedLookupStates]
forThemeAttribute:@"bezel-color"
inStates:highlightedTargetStates];
}
- (void)_sizeToFit
@@ -230,8 +290,8 @@
[super setDoubleValue:aValue];
}
#pragma mark -
#pragma mark Actions
// MARK: -
// MARK: Actions
/*! @ignore */
- (IBAction)_buttonDidClick:(id)aSender
@@ -266,8 +326,8 @@
}
#pragma mark -
#pragma mark Theming
// MARK: -
// MARK: Theming
+ (CPString)defaultThemeClass
{
@@ -323,6 +383,7 @@ var CPStepperMinValue = @"CPStepperMinValue",
_autorepeat = [aCoder decodeBoolForKey:CPStepperAutorepeat];
[self _init];
[self setEnabled:[self isEnabled]];
}
return self;
+15 -19
View File
@@ -32,7 +32,7 @@ var CPStringSizeWithFontInWidthCache = [],
CPStringSizeWithFontHeightCache = [],
CPStringSizeMeasuringContext;
CPStringSizeCachingEnabled = YES;
CPCanvasStringSizingIsFunctional = NO;
@implementation CPString (CPStringDrawing)
@@ -63,36 +63,38 @@ CPStringSizeCachingEnabled = YES;
return;
#if PLATFORM(DOM)
if (CPFeatureIsCompatible(CPHTMLCanvasFeature) && !CPStringSizeMeasuringContext)
CPStringSizeMeasuringContext = CGBitmapGraphicsContextCreate();
if (CPFeatureIsCompatible(CPHTMLCanvasFeature))
{
if (!CPStringSizeMeasuringContext)
CPStringSizeMeasuringContext = CGBitmapGraphicsContextCreate();
// This is to make sure that Canvas based string sizing is functional before we use it.
// Unfortunately, as of today canvas sizing is not funtional any more. Neither in Chrome nor in FF
CPCanvasStringSizingIsFunctional = NO;
}
#endif
}
- (CGSize)_sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
- (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
{
var size;
#if PLATFORM(DOM)
if (!CPStringSizeCachingEnabled)
return [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth];
var sizeCacheForFont = CPStringSizeWithFontInWidthCache[self];
if (sizeCacheForFont === undefined)
sizeCacheForFont = CPStringSizeWithFontInWidthCache[self] = [];
if (!aWidth)
aWidth = '0';
var cssString = [aFont cssString],
cacheKey = cssString + '_' + aWidth;
cacheKey = cssString + '_' + (aWidth ? aWidth : '0');
size = sizeCacheForFont[cacheKey];
if (size !== undefined && sizeCacheForFont.hasOwnProperty(cacheKey))
return CGSizeMakeCopy(size);
if (!CPFeatureIsCompatible(CPHTMLCanvasFeature) || aWidth > 0)
if (!CPCanvasStringSizingIsFunctional || aWidth)
size = [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth];
else
{
@@ -109,15 +111,9 @@ CPStringSizeCachingEnabled = YES;
sizeCacheForFont[cacheKey] = size;
#else
size = CGSizeMake(0, 0);
size = CGSizeMake(0, 0);
#endif
return CGSizeMakeCopy(size);
}
- (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
{
var size = [self _sizeWithFont:aFont inWidth:aWidth];
return CGSizeMake(CEIL(size.width), size.height);
}
@end
+118 -17
View File
@@ -79,6 +79,20 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
unsigned _delegateSelectors;
}
+ (CPString)defaultThemeClass
{
return @"tab-view";
}
+ (CPDictionary)themeAttributes
{
return @{
@"nib2cib-adjustment-frame": [CPNull null],
@"should-center-on-border": NO,
@"box-content-inset": CGInsetMakeZero()
};
}
- (id)initWithFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
@@ -95,14 +109,18 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
{
_tabs = [[_CPSegmentedControl alloc] initWithFrame:CGRectMakeZero()];
[_tabs setTabView:self];
[_tabs setHitTests:NO];
[_tabs setSegments:[CPArray array]];
[_tabs setAction:@selector(_reflectSelectedTab:)];
[_tabs setTarget:self];
var height = [_tabs valueForThemeAttribute:@"min-size"].height;
[_tabs setFrameSize:CGSizeMake(0, height)];
_box = [[_CPTabViewBox alloc] initWithFrame:[self bounds]];
_box = [[_CPTabViewBox alloc] initWithFrame:[self bounds]];
[_box setTabView:self];
[self setBackgroundColor:[CPColor colorWithCalibratedWhite:0.95 alpha:1.0]];
[_box setContentInset:[self currentValueForThemeAttribute:@"box-content-inset"]];
[_box setContentViewMargins:CGSizeMakeZero()];
[self addSubview:_box];
[self addSubview:_tabs];
@@ -275,7 +293,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
*/
- (void)selectNextTabViewItem:(id)aSender
{
if (_selectedTabViewItem === nil)
if (_selectedTabViewItem == nil)
return;
var nextIndex = [self indexOfTabViewItem:_selectedTabViewItem] + 1;
@@ -293,7 +311,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
*/
- (void)selectPreviousTabViewItem:(id)aSender
{
if (_selectedTabViewItem === nil)
if (_selectedTabViewItem == nil)
return;
var previousIndex = [self indexOfTabViewItem:_selectedTabViewItem] - 1;
@@ -353,15 +371,15 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
{
var controller = [aTabViewItem viewController];
if (controller !== nil && ![controller isViewLoaded])
if (controller != nil && ![controller isViewLoaded])
{
[controller loadViewWithCompletionHandler:function(view, error)
{
if (error !== nil)
if (error != nil)
{
CPLog.warn("Could not load the view for item " + aTabViewItem + ". " + error);
}
else if (view !== nil)
else if (view != nil)
{
[aTabViewItem setView:view];
@@ -463,10 +481,10 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
{
var aFrame = [self frame],
segmentedHeight = CGRectGetHeight([_tabs frame]),
origin = _type === CPTopTabsBezelBorder ? segmentedHeight / 2 : 0;
borderWidth = [self currentValueForThemeAttribute:@"should-center-on-border"] ? [_box borderWidth] : 0,
origin = _type === CPTopTabsBezelBorder ? (segmentedHeight - borderWidth) / 2 : 0;
[_box setFrame:CGRectMake(0, origin, CGRectGetWidth(aFrame),
CGRectGetHeight(aFrame) - segmentedHeight / 2)];
[_box setFrame:CGRectMake(0, origin, CGRectGetWidth(aFrame), CGRectGetHeight(aFrame) - (segmentedHeight - borderWidth) / 2)];
[self _repositionTabs];
}
@@ -526,6 +544,11 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
return [_box backgroundColor];
}
- (void)mouseDown:(CPEvent)anEvent
{
[_tabs trackSegment:anEvent];
}
- (void)_repositionTabs
{
var horizontalCenterOfSelf = CGRectGetWidth([self bounds]) / 2,
@@ -542,6 +565,11 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
[_box setContentView:aView];
}
- (void)_reflectSelectedTab:(id)aSender
{
[self selectTabViewItemAtIndex:[_tabs selectedSegment]];
}
// DELEGATE METHODS
- (BOOL)_sendDelegateShouldSelectTabViewItem:(CPTabViewItem)aTabViewItem
@@ -599,7 +627,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
{
var theBinder = [self binderForBinding:CPSelectionIndexesBinding];
if (theBinder !== nil)
if (theBinder != nil)
[theBinder reverseSetValueFor:@"selectionIndexes"];
else
{
@@ -668,8 +696,8 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1,
[self _displayItemView:_placeholderView];
}
#pragma mark -
#pragma mark Override
// MARK: -
// MARK: Override
/*!
Enabled controls accept first mouse by default.
@@ -858,14 +886,47 @@ var CPTabViewItemsKey = "CPTabViewItemsKey",
@end
// MARK: -
@implementation CPTabView (CSSTheming)
// MARK: Override
- (void)_setThemeIncludingDescendants:(CPTheme)aTheme
{
[self setTheme:aTheme];
[[self subviews] makeObjectsPerformSelector:@selector(_setThemeIncludingDescendants:) withObject:aTheme];
// Items must also perform this (without this, only the selected item does)
for (var i = 0, allItems = [self items], count = allItems.length; i < count; i++)
if (allItems[i] != _selectedTabViewItem)
[[allItems[i] view] _setThemeIncludingDescendants:aTheme];
}
@end
// MARK: -
@implementation _CPTabViewBox : CPBox
{
CPTabView _tabView @accessors(property=tabView);
CPTabView _tabView @accessors(property=tabView);
CGInset _contentInset @accessors(property=contentInset);
}
#pragma mark -
#pragma mark Override
// MARK: -
// MARK: Override
- (id)initWithFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
[self setBoxType:CPBoxPrimary];
}
return self;
}
- (CPView)hitTest:(CGPoint)aPoint
{
@@ -879,6 +940,46 @@ var CPTabViewItemsKey = "CPTabViewItemsKey",
return [super hitTest:aPoint];
}
// Some CPBox overrides because CPTabView use of CPBox differs from legacy CPBox regarding layout.
- (void)setContentView:(CPView)aView
{
if (aView === _contentView)
return;
if (_contentInset)
[aView setFrame:CGRectInsetByInset([self bounds], _contentInset)];
[aView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
// A nil contentView is allowed (tested in Cocoa 2013-02-22).
if (!aView)
[_contentView removeFromSuperview];
else if (_contentView)
[_boxView replaceSubview:_contentView with:aView];
else
[_boxView addSubview:aView];
_contentView = aView;
[self refreshDisplay];
}
- (void)sizeToFit
{
var offset = [self _titleHeightOffset],
size = [self frameSize];
[_boxView setFrame:CGRectMake(0, offset[1], size.width, size.height - offset[0])];
if (!_contentView)
return;
var boxSize = [_boxView frameSize];
if (_contentInset)
[_contentView setFrame:CGRectMake(_contentInset.left, _contentInset.top, boxSize.width - _contentInset.left - _contentInset.right, boxSize.height - _contentInset.top - _contentInset.bottom)];
}
@end
# pragma mark -
@@ -914,7 +1015,7 @@ var CPTabViewItemsKey = "CPTabViewItemsKey",
{
[self setSelected:YES forSegment:_trackingSegment];
_selectedSegment = _trackingSegment;
[_tabView selectTabViewItemAtIndex:_selectedSegment];
[self sendAction:[self action] to:[self target]];
}
[self drawSegmentBezel:_trackingSegment highlight:NO];
+55 -9
View File
@@ -593,7 +593,7 @@ CPTableColumnUserResizingMask = 1 << 1;
{
var options = [_info objectForKey:CPOptionsKey],
optionValue = [options objectForKey:CPCreatesSortDescriptorBindingOption];
return optionValue === nil ? YES : [optionValue boolValue];
return optionValue == nil ? YES : [optionValue boolValue];
}
@end
@@ -639,6 +639,53 @@ CPTableColumnUserResizingMask = 1 << 1;
}
}
/*!
@ignore
This method will return the object at a row in the first found CPArray in the key path
that is divided in a first and second part.
The first part is never a combined key path. The second part can be a combined key path.
If this optimization is not done we will create an array with the valueForKeyPath value on each row and then pick
the wanted value for the row and throw away all the other rows. It is much more effective to first
pick the row and then do the valueForKeyPath on the rest of the key path.
When the second part is depleated it will stop the search for a CPArray and return the
current object for the first part. The second part will then be nil.
The secondPartRef will always be updated with the rest of the key path that can be applied
to the returned object.
It will stop the search if the object is nil
*/
- (CPValueCoding)_firstObjectInArrayUsingKeyPathFirstPart:(CPString)firstPart secondPart:(CPStringRef)secondPartRef sourceObject:(CPValueCoding)source forRow:(unsigned)aRow
{
var firstValue = [source valueForKeyPath:firstPart];
if (firstValue == nil)
return firstValue;
if ([firstValue isKindOfClass:CPArray])
return [firstValue objectAtIndex:aRow];
var secondPart = @deref(secondPartRef);
if (secondPart == nil)
return firstValue;
var dotIndex = secondPart.indexOf(".");
if (dotIndex === CPNotFound)
{
firstPart = secondPart;
@deref(secondPartRef) = nil;
}
else
{
firstPart = secondPart.substring(0, dotIndex);
@deref(secondPartRef) = secondPart.substring(dotIndex + 1);
}
return [self _firstObjectInArrayUsingKeyPathFirstPart:firstPart secondPart:secondPartRef sourceObject:firstValue forRow:aRow];
}
/*!
@ignore
*/
@@ -655,7 +702,7 @@ CPTableColumnUserResizingMask = 1 << 1;
bindingInfo = binding._info,
destination = [bindingInfo objectForKey:CPObservedObjectKey],
keyPath = [bindingInfo objectForKey:CPObservedKeyPathKey],
dotIndex = keyPath.lastIndexOf("."),
dotIndex = keyPath.indexOf("."),
value;
if (dotIndex === CPNotFound)
@@ -670,17 +717,16 @@ CPTableColumnUserResizingMask = 1 << 1;
The optimization is to get the array and access the value directly. This
turns the operation into a single access regardless of how long the model
array is.
array is or how long the key path is.
*/
var firstPart = keyPath.substring(0, dotIndex),
secondPart = keyPath.substring(dotIndex + 1),
firstValue = [destination valueForKeyPath:firstPart];
secondPart = keyPath.substring(dotIndex + 1);
if ([firstValue isKindOfClass:CPArray])
value = [[firstValue objectAtIndex:aRow] valueForKeyPath:secondPart];
else
value = [[firstValue valueForKeyPath:secondPart] objectAtIndex:aRow];
value = [self _firstObjectInArrayUsingKeyPathFirstPart:firstPart secondPart:@ref(secondPart) sourceObject:destination forRow:aRow];
if (secondPart != nil)
value = [value valueForKeyPath:secondPart];
}
value = [binding transformValue:value withOptions:[bindingInfo objectForKey:CPOptionsKey]];
+232 -24
View File
@@ -25,6 +25,10 @@
@import "CPCursor.j"
@import "_CPImageAndTextView.j"
@import "CPTrackingArea.j"
@import "CPAnimationContext.j"
@import "CPViewAnimator.j"
@import "CPScrollView.j"
@import <Foundation/CPGeometry.j>
@class CPTableView
@@ -50,10 +54,16 @@
@"text-color": [CPNull null],
@"font": [CPNull null],
@"text-shadow-color": [CPNull null],
@"text-shadow-offset": CGSizeMakeZero()
@"text-shadow-offset": CGSizeMakeZero(),
@"dont-draw-separator": NO
};
}
- (BOOL)acceptsFirstMouse:(CPEvent)anEvent
{
return YES;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
@@ -66,18 +76,22 @@
- (void)_init
{
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
var inset = [self valueForThemeAttribute:@"text-inset"];
_textField = [[_CPImageAndTextView alloc] initWithFrame:
CGRectMake(5.0, 0.0, CGRectGetWidth([self bounds]) - 10.0, CGRectGetHeight([self bounds]))];
CGRectMake(inset.left, inset.top, CGRectGetWidth([self bounds]) - (inset.left + inset.right), CGRectGetHeight([self bounds]) - (inset.top + inset.bottom))];
[_textField setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[_textField setLineBreakMode:CPLineBreakByTruncatingTail];
[_textField setTextColor:[CPColor colorWithRed:51.0 / 255.0 green:51.0 / 255.0 blue:51.0 / 255.0 alpha:1.0]];
[_textField setFont:[CPFont boldSystemFontOfSize:12.0]];
[_textField setAlignment:CPLeftTextAlignment];
[_textField setLineBreakMode:[self valueForThemeAttribute:@"line-break-mode"]];
[_textField setTextColor:[self valueForThemeAttribute:@"text-color"]];
[_textField setFont:[self valueForThemeAttribute:@"font"]];
[_textField setAlignment:[self valueForThemeAttribute:@"text-alignment"]];
[_textField setVerticalAlignment:CPCenterVerticalTextAlignment];
[_textField setTextShadowColor:[CPColor whiteColor]];
[_textField setTextShadowOffset:CGSizeMake(0,1)];
[_textField setTextShadowColor:[self valueForThemeAttribute:@"text-shadow-color"]];
[_textField setTextShadowOffset:[self valueForThemeAttribute:@"text-shadow-offset"]];
[self addSubview:_textField];
}
@@ -108,7 +122,7 @@
return [_textField text];
}
- (void)textField
- (CPTextField)textField
{
return _textField;
}
@@ -188,6 +202,9 @@
- (void)drawRect:(CGRect)aRect
{
if ([self valueForThemeAttribute:@"dont-draw-separator"])
return;
var bounds = [self bounds];
if (!CGRectIntersectsRect(aRect, bounds))
@@ -223,7 +240,8 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[self _init];
[self _setIndicatorImage:[aCoder decodeObjectForKey:_CPTableColumnHeaderViewImageKey]];
[self setStringValue:[aCoder decodeObjectForKey:_CPTableColumnHeaderViewStringValueKey]];
[self setFont:[aCoder decodeObjectForKey:_CPTableColumnHeaderViewFontKey]];
// FIXME: pourquoi dans actif, font=null ?
// [self setFont:[aCoder decodeObjectForKey:_CPTableColumnHeaderViewFontKey]];
}
return self;
@@ -257,11 +275,13 @@ var CPTableHeaderViewResizeZone = 3.0,
BOOL _isResizing;
BOOL _isDragging;
BOOL _isAnimating;
BOOL _canDragColumn;
CPView _columnDragView;
CPView _columnDragHeaderView;
CPView _columnDragClipView;
CPScrollView _columnDragScrollView;
float _columnOldWidth;
@@ -278,7 +298,9 @@ var CPTableHeaderViewResizeZone = 3.0,
return @{
@"background-color": [CPNull null],
@"divider-color": [CPColor grayColor],
@"divider-thickness": 1.0
@"divider-thickness": 1.0,
@"swap-animation": [CPNull null],
@"return-animation": [CPNull null]
};
}
@@ -340,7 +362,24 @@ var CPTableHeaderViewResizeZone = 3.0,
- (CPInteger)columnAtPoint:(CGPoint)aPoint
{
return [_tableView columnAtPoint:aPoint];
var tableView = [self tableView],
tableColumns = [tableView tableColumns],
count = [tableColumns count],
bounds = [self bounds],
// Create a point that keeps the X position but forces Y to be safely
// in the middle of the header view.
constrainedPoint = CGPointMake(aPoint.x, CGRectGetMidY(bounds));
// Iterate through columns to find which one contains the constrained X coordinate
for (var i = 0; i < count; i++)
{
// headerRectOfColumn: is a utility method defined in CPTableHeaderView
// that handles the coordinate conversion from the table view relative to the header.
if (CGRectContainsPoint([self headerRectOfColumn:i], constrainedPoint))
return i;
}
return -1;
}
- (CGRect)headerRectOfColumn:(CPInteger)aColumnIndex
@@ -365,6 +404,8 @@ var CPTableHeaderViewResizeZone = 3.0,
- (void)layoutSubviews
{
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
var tableColumns = [_tableView tableColumns],
count = [tableColumns count];
@@ -442,6 +483,14 @@ var CPTableHeaderViewResizeZone = 3.0,
}
else if (_isDragging)
{
// First, we have to avoid a running condition where user stops dragging while a swap animation is running
if (_isAnimating)
{
[CPTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(_retry_mouseUp:) userInfo:theEvent repeats:NO];
return;
}
[self _stopDraggingTableColumn:_activeColumn];
}
else if (_activeColumn != -1)
@@ -458,6 +507,11 @@ var CPTableHeaderViewResizeZone = 3.0,
_activeColumn = -1;
}
- (void)_retry_mouseUp:(CPTimer)aTimer
{
[self mouseUp:[aTimer userInfo]];
}
@end
@implementation CPTableHeaderView (CPTrackingArea)
@@ -562,7 +616,21 @@ var CPTableHeaderViewResizeZone = 3.0,
pressure:[theEvent pressure]];
[self autoscroll:constrainedEvent];
var contentView = [_tableView superview],
boundsOriginBefore = [contentView boundsOrigin];
[_tableView autoscroll:constrainedEvent];
var boundsOriginAfter = [contentView boundsOrigin],
deltaX = boundsOriginAfter.x - boundsOriginBefore.x;
if (_isDragging)
{
var dragContentView = [_columnDragScrollView contentView],
dragContentBoundsOrigin = [dragContentView boundsOrigin];
[dragContentView setBoundsOrigin:CGPointMake(dragContentBoundsOrigin.x + deltaX, dragContentBoundsOrigin.y)];
}
}
- (CGRect)_headerRectOfLastVisibleColumn
@@ -584,16 +652,91 @@ var CPTableHeaderViewResizeZone = 3.0,
- (CGPoint)_constrainDragPoint:(CGPoint)aPoint
{
// This effectively clamps the value between the minimum and maximum
var visibleRect = [_tableView visibleRect],
lastColumnRect = [self _headerRectOfLastVisibleColumn],
activeColumnRect = [self headerRectOfColumn:_activeColumn],
maxX = CGRectGetMaxX(lastColumnRect) - CGRectGetWidth(activeColumnRect) - CGRectGetMinX(visibleRect),
point = CGPointMake(MAX(MIN(aPoint.x, maxX), -CGRectGetMinX(visibleRect)), aPoint.y);
var tableFrame = [_tableView frame],
dragFrame = [_columnDragView frame],
maxX = tableFrame.size.width - dragFrame.size.width,
point = CGPointMake(MAX(MIN(aPoint.x, maxX),0), aPoint.y);
return point;
}
- (void)_moveColumn:(CPInteger)aFromIndex toColumn:(CPInteger)aToIndex
{
if (_isAnimating)
return;
var swapAnimation = [self currentValueForThemeAttribute:@"swap-animation"];
if (swapAnimation)
{
_isAnimating = YES;
// There's a theme defined animation function, just use it
objj_eval("("+swapAnimation+")")(self, aFromIndex, aToIndex, _columnDragClipView, _columnDragView);
// var animatedColumn = [[_tableView tableColumns] objectAtIndex:aToIndex],
// animatedHeader = [animatedColumn headerView],
// animatedHeaderOrigin = [animatedHeader frameOrigin],
//
// destinationX,
// draggedHeader = [[[_tableView tableColumns] objectAtIndex:aFromIndex] headerView],
//
// scrollView = [self enclosingScrollView],
// animatedView = [_tableView _animationViewForColumn:aToIndex],
// animatedOrigin = [animatedView frameOrigin];
//
// [_columnDragClipView addSubview:animatedView positioned:CPWindowBelow relativeTo:_columnDragView];
//
// [[animatedHeader subviews] makeObjectsPerformSelector:@selector(setHidden:) withObject:YES];
// [animatedHeader setThemeState:CPThemeStateVertical];
//
// if (aFromIndex < aToIndex)
// destinationX = CGRectGetMinX([_tableView rectOfColumn:aFromIndex]);
// else
// destinationX = animatedOrigin.x + CGRectGetWidth([_tableView rectOfColumn:aFromIndex]);
//
// [CPAnimationContext beginGrouping];
//
// var context = [CPAnimationContext currentContext];
//
// [context setDuration:0.15];
// [context setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
// [context setCompletionHandler:function() {
// [animatedView removeFromSuperview];
//
// [self _finalize_moveColumn:aFromIndex toColumn:aToIndex];
//
// [animatedHeader unsetThemeState:CPThemeStateVertical];
// [[animatedHeader subviews] makeObjectsPerformSelector:@selector(setHidden:) withObject:NO];
//
// if ([animatedView isSelected])
// {
// [animatedHeader setThemeState:CPThemeStateSelected];
//
// // We have to reselect the animated column
// [[_tableView selectedColumnIndexes] addIndex:aFromIndex];
// }
//
// // Reload animated column
// var columnVisRect = CGRectIntersection([_tableView rectOfColumn:aFromIndex], [_tableView visibleRect]),
// rowsIndexes = [CPIndexSet indexSetWithIndexesInRange:[_tableView rowsInRect:columnVisRect]],
// columnsIndexes = [CPIndexSet indexSetWithIndex:aFromIndex];
//
// [_tableView _loadDataViewsInRows:rowsIndexes columns:columnsIndexes];
// [_tableView _layoutViewsForRowIndexes:rowsIndexes columnIndexes:columnsIndexes];
//
// [_tableView._tableDrawView displayRect:columnVisRect];
// }];
//
// [[animatedView animator] setFrameOrigin:CGPointMake(destinationX, animatedOrigin.y)];
//
// [CPAnimationContext endGrouping];
}
else
[self _finalize_moveColumn:aFromIndex toColumn:aToIndex];
}
- (void)_finalize_moveColumn:(CPInteger)aFromIndex toColumn:(CPInteger)aToIndex
{
[_tableView moveColumn:aFromIndex toColumn:aToIndex];
_activeColumn = aToIndex;
@@ -602,6 +745,8 @@ var CPTableHeaderViewResizeZone = 3.0,
[_tableView _setDraggedColumn:_activeColumn];
[self setNeedsDisplay:YES];
_isAnimating = NO;
}
- (BOOL)isDragging
@@ -618,17 +763,30 @@ var CPTableHeaderViewResizeZone = 3.0,
// Create a new clip view for the drag view that clips to the header + visible content
var headerHeight = CGRectGetHeight([self frame]),
scrollView = [self enclosingScrollView],
contentFrame = [[scrollView contentView] frame];
contentFrame = [[scrollView contentView] frame],
contentBounds = [[scrollView contentView] bounds];
contentFrame.origin.y -= headerHeight;
contentFrame.size.height += headerHeight;
_columnDragClipView = [[CPView alloc] initWithFrame:contentFrame];
_columnDragScrollView = [[CPScrollView alloc] initWithFrame:contentFrame];
[_columnDragScrollView setHasHorizontalScroller:NO];
[_columnDragScrollView setHasVerticalScroller:NO];
[_columnDragScrollView setBorderType:CPNoBorder];
var tableFrame = [_tableView frame],
clipFrame = CGRectMake(0, 0, tableFrame.size.width, contentFrame.size.height);
_columnDragClipView = [[CPView alloc] initWithFrame:clipFrame];
[_columnDragClipView addSubview:_columnDragView];
[_columnDragScrollView setDocumentView:_columnDragClipView];
[[_columnDragScrollView contentView] setBoundsOrigin:CGPointMake(contentBounds.origin.x, 0)];
// Insert the clip view above the table header (and content)
[scrollView addSubview:_columnDragClipView positioned:CPWindowAbove relativeTo:self];
[scrollView addSubview:_columnDragScrollView positioned:CPWindowAbove relativeTo:self];
// Hide the underlying column header subviews, we just want to draw the chrome
var headerView = [[[_tableView tableColumns] objectAtIndex:aColumnIndex] headerView];
@@ -638,6 +796,9 @@ var CPTableHeaderViewResizeZone = 3.0,
// The underlying column header shows normal state
[headerView unsetThemeStates:[CPThemeStateHighlighted, CPThemeStateSelected]];
// FIXME: Just a little hack to get a special background (using an unused theme state)
[headerView setThemeState:CPThemeStateVertical];
// Keep track of the location within the column header where the original mousedown occurred
_columnDragHeaderView = [_columnDragView viewWithTag:CPTableHeaderViewDragColumnHeaderTag];
@@ -692,10 +853,43 @@ var CPTableHeaderViewResizeZone = 3.0,
}
- (void)_stopDraggingTableColumn:(CPInteger)aColumnIndex
{
var returnAnimation = [self currentValueForThemeAttribute:@"return-animation"];
if (returnAnimation)
{
_isAnimating = YES;
// There's a theme defined animation function, just use it
objj_eval("("+returnAnimation+")")(self, aColumnIndex, _columnDragView);
// var animatedColumn = [[_tableView tableColumns] objectAtIndex:aColumnIndex],
// animatedHeader = [animatedColumn headerView],
// animatedHeaderOrigin = [animatedHeader frameOrigin];
//
// [CPAnimationContext beginGrouping];
//
// var context = [CPAnimationContext currentContext];
//
// [context setDuration:0.15];
// [context setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
// [context setCompletionHandler:function() {
//
// [self _finalize_stopDraggingTableColumn:aColumnIndex];
// }];
//
// [[_columnDragView animator] setFrameOrigin:CGPointMake(animatedHeaderOrigin.x, 0)];
//
// [CPAnimationContext endGrouping];
}
else
[self _finalize_stopDraggingTableColumn:aColumnIndex];
}
- (void)_finalize_stopDraggingTableColumn:(CPInteger)aColumnIndex
{
_isDragging = NO;
[_columnDragClipView removeFromSuperview];
[_tableView _setDraggedColumn:-1];
var tableColumn = [[_tableView tableColumns] objectAtIndex:aColumnIndex],
@@ -703,16 +897,30 @@ var CPTableHeaderViewResizeZone = 3.0,
[[headerView subviews] makeObjectsPerformSelector:@selector(setHidden:) withObject:NO];
// Restore headerView background
[headerView unsetThemeState:CPThemeStateVertical];
if (_tableView._draggedColumnIsSelected)
[headerView setThemeState:CPThemeStateSelected];
[_tableView _reloadDataViews];
[[_tableView headerView] setNeedsLayout];
// Reload animated column
var columnVisRect = CGRectIntersection([_tableView rectOfColumn:aColumnIndex], [_tableView visibleRect]),
rowsIndexes = [CPIndexSet indexSetWithIndexesInRange:[_tableView rowsInRect:columnVisRect]],
columnsIndexes = [CPIndexSet indexSetWithIndex:aColumnIndex];
[[CPCursor arrowCursor] set];
[_tableView _loadDataViewsInRows:rowsIndexes columns:columnsIndexes];
[_tableView _layoutViewsForRowIndexes:rowsIndexes columnIndexes:columnsIndexes];
[_tableView _updateDataViewsFocusState];
[_tableView._tableDrawView displayRect:columnVisRect];
[[CPCursor arrowCursor] set]; // FIXME: retirer ?
[self updateTrackingAreas];
[_columnDragScrollView removeFromSuperview];
[_tableView _sendDelegateDidDragTableColumn:tableColumn];
_isAnimating = NO;
}
- (BOOL)_shouldResizeTableColumn:(CPInteger)aColumnIndex at:(CGPoint)aPoint
+578 -490
View File
File diff suppressed because it is too large Load Diff
+17 -1
View File
@@ -84,6 +84,18 @@ CPCenterTextAlignment = 2;
CPJustifiedTextAlignment = 3;
CPNaturalTextAlignment = 4;
@typedef CPUnderlineStyle
CPUnderlineStyleNone = 0;
CPUnderlineStyleSingle = 1;
CPUnderlineStyleThick = 2;
CPUnderlineStyleDouble = 3;
CPUnderlineStylePatternSolid = 4;
CPUnderlineStylePatternDot = 5;
CPUnderlineStylePatternDash = 6;
CPUnderlineStylePatternDashDot = 7;
CPUnderlineStylePatternDashDotDot = 8;
CPUnderlineStyleByWord = 9;
/*
CPText notifications
*/
@@ -167,7 +179,11 @@ CPKernAttributeName = @"CPKernAttributeName";
{
var pasteboard = [CPPasteboard generalPasteboard],
dataForPasting = [pasteboard stringForType:CPRTFPboardType],
stringForPasting = [pasteboard stringForType:CPStringPboardType];
stringForPasting = [pasteboard stringForType:CPStringPboardType],
attributedStringData = [pasteboard stringForType:_CPASPboardType];
if ([self isRichText] && attributedStringData)
return [CPKeyedUnarchiver unarchiveObjectWithData:[CPData dataWithRawString:attributedStringData]];
if (dataForPasting || [stringForPasting hasPrefix:"{\\rtf1\\ansi"])
stringForPasting = [[_CPRTFParser new] parseRTF:dataForPasting ? dataForPasting : stringForPasting];
+282 -53
View File
@@ -34,6 +34,8 @@
@global CPStringPboardType
@global CPCursor
@global document
@protocol CPTextFieldDelegate <CPControlTextEditingDelegate>
@end
@@ -66,7 +68,11 @@ var CPTextFieldDOMCurrentElement = nil,
CPTextFieldCachedDragFunction = nil,
CPTextFieldBlurHandler = nil,
CPTextFieldInputFunction = nil,
CPTexFieldCurrentCSSSelectableField = nil;
CPTexFieldCurrentCSSSelectableField = nil,
CPTextFieldLastValidationFailureEvent = nil,
CPTextFieldLastValidationFailureString = nil,
CPTextFieldLastValidationFailureField = nil,
CPTextFieldLastValidationFailureResult = NO;
var CPSecureTextFieldCharacter = "\u2022";
@@ -169,7 +175,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
+ (CPTextField)textFieldWithStringValue:(CPString)aStringValue placeholder:(CPString)aPlaceholder width:(float)aWidth theme:(CPTheme)aTheme
{
var textField = [[self alloc] initWithFrame:CGRectMake(0.0, 0.0, aWidth, 29.0)];
var minSize = aTheme ? [aTheme valueForAttributeWithName:@"min-size" forClass:CPTextField] : CGSizeMake(0,0),
textField = [[self alloc] initWithFrame:CGRectMake(0.0, 0.0, aWidth, minSize.height)];
[textField setTheme:aTheme];
[textField setStringValue:aStringValue];
@@ -190,7 +197,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
+ (CPTextField)roundedTextFieldWithStringValue:(CPString)aStringValue placeholder:(CPString)aPlaceholder width:(float)aWidth theme:(CPTheme)aTheme
{
var textField = [[CPTextField alloc] initWithFrame:CGRectMake(0.0, 0.0, aWidth, 29.0)];
var minSize = aTheme ? [aTheme valueForAttributeWithName:@"min-size" forClass:CPTextField] : CGSizeMake(0,0),
textField = [[self alloc] initWithFrame:CGRectMake(0.0, 0.0, aWidth, minSize.height)];
[textField setTheme:aTheme];
[textField setStringValue:aStringValue];
@@ -231,12 +239,14 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
@"bezel-inset": CGInsetMakeZero(),
@"content-inset": CGInsetMake(1.0, 0.0, 0.0, 0.0),
@"bezel-color": [CPNull null],
@"min-size": CGSizeMake(0, 29),
@"background-inset": CGInsetMakeZero()
};
}
#pragma mark -
#pragma mark Control Size
// MARK: -
// MARK: Control Size
- (void)setControlSize:(CPControlSize)aControlSize
{
@@ -247,7 +257,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
}
#pragma mark -
// MARK: -
#if PLATFORM(DOM)
- (DOMElement)_inputElement
@@ -326,7 +336,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
characters:nil
charactersIgnoringModifiers:nil
isARepeat:NO
keyCode:nil];
keyCode:nil
isActionKey:NO];
[CPTextFieldInputOwner keyUp:cappEvent];
@@ -365,14 +376,12 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
[self setPlaceholderString:@""];
_sendActionOn = CPKeyUpMask | CPKeyDownMask;
[self setValue:CPNaturalTextAlignment forThemeAttribute:@"alignment"];
}
return self;
}
#pragma mark Controlling Editability and Selectability
// MARK: Controlling Editability and Selectability
/*!
Sets whether or not the receiver text field can be edited. If NO, any
@@ -557,9 +566,9 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
Sets the background color, which is shown for non-bezeled text fields with drawsBackground set to YES
@param aColor The background color
*/
- (void)setTextFieldBackgroundColor:(CPColor)aColor
- (void)setBackgroundColor:(CPColor)aColor
{
if (_textFieldBackgroundColor == aColor)
if (_backgroundColor == aColor)
return;
_textFieldBackgroundColor = aColor;
@@ -571,7 +580,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
/*!
Returns the background color.
*/
- (CPColor)textFieldBackgroundColor
- (CPColor)backgroundColor
{
return _textFieldBackgroundColor;
}
@@ -686,8 +695,38 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
}
else
{
var point = CGPointMake([self convertPointFromBase:[[CPApp currentEvent] locationInWindow]].x - [self currentValueForThemeAttribute:@"content-inset"].left, 0),
position = [CPPlatformString charPositionOfString:[self stringValue] withFont:[self font] forPoint:point];
var x = [self convertPointFromBase:[[CPApp currentEvent] locationInWindow]].x,
contentInset = [self currentValueForThemeAttribute:@"content-inset"],
text = [self stringValue],
font = [self font];
switch ([self alignment]) {
case CPCenterTextAlignment:
var contentWidth = [self bounds].size.width - contentInset.left - contentInset.right,
textWidth = [text sizeWithFont:font].width;
x -= (contentWidth - textWidth) / 2 + contentInset.left;
break;
case CPRightTextAlignment:
var contentWidth = [self bounds].size.width - contentInset.left - contentInset.right,
textWidth = [text sizeWithFont:font].width;
x -= (contentWidth - textWidth) + contentInset.left;
break;
default: // CPLeftTextAlignment, CPJustifiedTextAlignment, CPNaturalTextAlignment
x -= contentInset.left;
break;
}
var position = [CPPlatformString charPositionOfString:text withFont:font forPoint:CGPointMake(x, 0)];
[self setSelectedRange:CPMakeRange(position, 0)];
}
@@ -726,39 +765,33 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
#if PLATFORM(DOM)
var element = [self _inputElement],
font = [self currentValueForThemeAttribute:@"font"],
font = [self font],
lineHeight = [font defaultLineHeightForFont],
contentRect = [self contentRectForBounds:[self bounds]],
verticalAlign = [self currentValueForThemeAttribute:"vertical-alignment"],
left = CGRectGetMinX(contentRect);
// If the browser has a built in left padding, compensate for it. We need the input text to be exactly on top of the original text.
if (CPFeatureIsCompatible(CPInput1PxLeftPadding))
left -= 1;
switch (verticalAlign)
{
case CPTopVerticalTextAlignment:
var topPoint = CGRectGetMinY(contentRect) + "px";
var topPoint = CEIL(CGRectGetMinY(contentRect)) + "px";
break;
case CPCenterVerticalTextAlignment:
var topPoint = (CGRectGetMidY(contentRect) - (lineHeight / 2)) + "px";
var topPoint = CEIL((CGRectGetMidY(contentRect) - (lineHeight / 2))) + "px";
break;
case CPBottomVerticalTextAlignment:
var topPoint = (CGRectGetMaxY(contentRect) - lineHeight) + "px";
var topPoint = CEIL((CGRectGetMaxY(contentRect) - lineHeight)) + "px";
break;
default:
var topPoint = CGRectGetMinY(contentRect) + "px";
var topPoint = CEIL(CGRectGetMinY(contentRect)) + "px";
break;
}
if ([self hasThemeState:CPTextFieldStatePlaceholder])
element.style.color = [[self valueForThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder] cssString];
else
element.style.color = [[self valueForThemeAttribute:@"text-color" inState:CPThemeStateEditing] cssString];
// Use currentValueForThemeAttribute to respect all current states (HUD, Placeholder, Editing, etc.)
element.style.color = [[self currentValueForThemeAttribute:@"text-color"] cssString];
switch ([self alignment])
{
@@ -783,7 +816,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
element.style.zIndex = 1000;
element.style.top = topPoint;
element.style.lineHeight = ROUND(lineHeight) + "px";
element.style.height = isTextArea ? CGRectGetHeight(contentRect) + "px" : ROUND(lineHeight) + "px";;
element.style.height = isTextArea ? CGRectGetHeight(contentRect) + "px" : ROUND(lineHeight) + "px";
element.style.width = CGRectGetWidth(contentRect) + "px";
element.style.left = left + "px";
element.style.verticalAlign = "top";
@@ -962,7 +995,26 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
var acceptInvalidValue = NO;
if (_implementedDelegateMethods & CPTextFieldDelegate_control_didFailToFormatString_errorDescription_)
acceptInvalidValue = [_delegate control:self didFailToFormatString:aValue errorDescription:error];
{
var currentEvent = [CPApp currentEvent];
if (currentEvent &&
CPTextFieldLastValidationFailureField === self &&
CPTextFieldLastValidationFailureString === aValue &&
CPTextFieldLastValidationFailureEvent === currentEvent)
{
acceptInvalidValue = CPTextFieldLastValidationFailureResult;
}
else
{
acceptInvalidValue = [_delegate control:self didFailToFormatString:aValue errorDescription:error];
CPTextFieldLastValidationFailureField = self;
CPTextFieldLastValidationFailureString = aValue;
CPTextFieldLastValidationFailureEvent = currentEvent;
CPTextFieldLastValidationFailureResult = acceptInvalidValue;
}
}
if (acceptInvalidValue === NO)
return NO;
@@ -1092,9 +1144,16 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)keyDown:(CPEvent)anEvent
{
if (!([self isEnabled] && [self isEditable]))
// Has to be enabled, and it also has to be editable or selectable.
if (![self isEnabled] || !([self isEditable] || [self isSelectable]))
return;
if ([self isEditable] && !_isEditing)
{
_isEditing = YES;
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
}
// CPTextField uses an HTML input element to take the input so we need to
// propagate the dom event so the element is updated. This has to be done
// before interpretKeyEvents: though so individual commands have a chance
@@ -1236,6 +1295,16 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
[super textDidChange:note];
}
- (void)validateEditing
{
#if PLATFORM(DOM)
var element = [self _inputElement];
if (element)
[self _setStringValue:element.value isNewValue:YES errorDescription:nil];
#endif
}
- (void)textDidBeginEditing:(CPNotification)note
{
//this looks to prevent false propagation of notifications for other objects
@@ -1331,7 +1400,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
// If there is a formatter, make sure the object value can be formatted successfully
var formattedString = [self hasThemeState:CPThemeStateEditing] ? [formatter editingStringForObjectValue:aValue] : [formatter stringForObjectValue:aValue];
if (formattedString === nil)
if (formattedString == nil)
{
var value = nil;
@@ -1341,7 +1410,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
value = undefined;
[super setObjectValue:value];
_stringValue = (value === nil || value === undefined) ? @"" : String(value);
_stringValue = (value == nil) ? @"" : String(value);
}
else
_stringValue = formattedString;
@@ -1428,7 +1497,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
lineBreakMode = [self lineBreakMode],
text = (_stringValue || @" "),
textSize = CGSizeMakeCopy(frameSize),
font = [self currentValueForThemeAttribute:@"font"];
font = [self font];
textSize.width -= contentInset.left + contentInset.right;
textSize.height -= contentInset.top + contentInset.bottom;
@@ -1497,7 +1566,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
else
[[CPRunLoop mainRunLoop] performBlock:function(){ element.select(); } argument:nil order:0 modes:[CPDefaultRunLoopMode]];
}
else if (wind !== nil && [wind makeFirstResponder:self])
else if (wind != nil && [wind makeFirstResponder:self])
[self _selectText:sender immediately:immediately];
}
else
@@ -1507,7 +1576,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
#else
// Even if we can't actually select the text we need to preserve the first
// responder side effect.
if (wind !== nil && [wind firstResponder] !== self)
if (wind != nil && [wind firstResponder] !== self)
[wind makeFirstResponder:self];
#endif
}
@@ -1779,7 +1848,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
[self _didEdit];
}
#pragma mark Setting the Delegate
// MARK: Setting the Delegate
- (void)setDelegate:(id <CPTextFieldDelegate>)aDelegate
{
@@ -1832,6 +1901,12 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
if (aName === "bezel-view")
return [self bezelRectForBounds:[self bounds]];
else if (aName === "background-view")
{
var backgroundInset = [self currentValueForThemeAttribute:@"background-inset"];
return CGRectInsetByInset([self bounds], backgroundInset);
}
else if (aName === "content-view")
return [self contentRectForBounds:[self bounds]];
@@ -1848,6 +1923,14 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
return view;
}
else if (aName === "background-view")
{
var view = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[view setHitTests:NO];
return view;
}
else
{
var view = [[_CPImageAndTextView alloc] initWithFrame:CGRectMakeZero()];
@@ -1862,16 +1945,37 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
- (void)layoutSubviews
{
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"content-view"];
var bezelColor = [self currentValueForThemeAttribute:@"bezel-color"];
if ([bezelColor isCSSBased])
{
// CSS Styling
// We don't need bezelView as we apply CSS styling directly on the text field view itself
if (bezelView)
[bezelView setBackgroundColor:[self currentValueForThemeAttribute:@"bezel-color"]];
// We need to call [super setBackgroundColor:] as we have redefined it here
[super setBackgroundColor:bezelColor];
var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:nil],
backgroundView = [self layoutEphemeralSubviewNamed:@"background-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"content-view"];
var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
[backgroundView setBackgroundColor:(_drawsBackground ? _textFieldBackgroundColor : [CPColor clearColor])];
}
else
{
var bezelView = [self layoutEphemeralSubviewNamed:@"bezel-view"
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:@"content-view"];
[bezelView setBackgroundColor:bezelColor];
var contentView = [self layoutEphemeralSubviewNamed:@"content-view"
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
}
if (contentView)
{
@@ -1892,7 +1996,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
[contentView setText:string];
[contentView setTextColor:[self currentValueForThemeAttribute:@"text-color"]];
[contentView setFont:[self currentValueForThemeAttribute:@"font"]];
[contentView setFont:[self font]];
[contentView setAlignment:[self currentValueForThemeAttribute:@"alignment"]];
[contentView setVerticalAlignment:[self currentValueForThemeAttribute:@"vertical-alignment"]];
[contentView setLineBreakMode:[self currentValueForThemeAttribute:@"line-break-mode"]];
@@ -1904,6 +2008,43 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
[self _setCSSStyleForInputElement];
}
// MARK: Overrides
/*!
Sets the font of the receiver.
@param aFont - A CPFont object.
*/
- (void)setFont:(CPFont)aFont
{
if ([self currentValueForThemeAttribute:@"font"] === aFont)
return;
// Apply the font to the default/normal state
[self setValue:aFont forThemeAttribute:@"font"];
// Apply to standard editing and border states
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateEditing];
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateBezeled];
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateBordered];
[self setValue:aFont forThemeAttribute:@"font" inState:CPTextFieldStateRounded];
// Use CPThemeState() function to create composite states instead of array literals
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeState(CPTextFieldStateRounded, CPThemeStateEditing)];
// Apply across all standard control size states
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateControlSizeRegular];
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateControlSizeSmall];
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateControlSizeMini];
// Apply to table data view states (ensuring Interface Builder-style lists respect the font)
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeStateTableDataView];
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView)];
[self setValue:aFont forThemeAttribute:@"font" inState:CPThemeState(CPThemeStateTableDataView, CPThemeStateSelectedDataView, CPThemeStateFirstResponder, CPThemeStateKeyWindow)];
[self layoutSubviews];
}
- (void)takeValueFromKeyPath:(CPString)aKeyPath ofObjects:(CPArray)objects
{
var count = objects.length,
@@ -1920,7 +2061,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
}
}
#pragma mark Overrides
// MARK: Overrides
/*!
Sets the text color of the receiver.
@@ -1932,8 +2073,28 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
// We don't want to change the text-color of the placeHolder of the textField
var placeholderColor = [self valueForThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder];
[super setTextColor:aColor];
// If the text field is a cell based table data view, we need to fix the color for all possible states
if ([self hasThemeState:CPThemeStateTableDataView])
{
[self setTextColor:aColor inThemeStates:[CPThemeStateTableDataView]];
[self setTextColor:aColor inThemeStates:[CPThemeStateTableDataView, CPThemeStateSelectedDataView]];
[self setTextColor:aColor inThemeStates:[CPThemeStateTableDataView, CPThemeStateSelectedDataView, CPThemeStateFirstResponder, CPThemeStateKeyWindow]];
}
else
{
if ([self hasThemeState:CPTextFieldStateRounded])
{
[self setTextColor:aColor inThemeStates:[CPTextFieldStateRounded]];
[self setTextColor:aColor inThemeStates:[CPTextFieldStateRounded, CPThemeStateEditing]];
}
[self setTextColor:aColor inThemeStates:[CPThemeStateNormal]];
[self setTextColor:aColor inThemeStates:[CPThemeStateEditing]];
}
[self setValue:placeholderColor forThemeAttribute:@"text-color" inState:CPTextFieldStatePlaceholder];
[self layoutSubviews];
}
- (void)viewDidHide
@@ -1969,7 +2130,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
return YES;
}
#pragma mark Private
// MARK: Private
- (BOOL)_isWithinUsablePlatformRect
{
@@ -2075,8 +2236,7 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
[self setSelectable:[aCoder decodeBoolForKey:CPTextFieldIsSelectableKey]];
[self setDrawsBackground:[aCoder decodeBoolForKey:CPTextFieldDrawsBackgroundKey]];
[self setTextFieldBackgroundColor:[aCoder decodeObjectForKey:CPTextFieldBackgroundColorKey]];
[self setBackgroundColor:[aCoder decodeObjectForKey:CPTextFieldBackgroundColorKey]];
[self setLineBreakMode:[aCoder decodeIntForKey:CPTextFieldLineBreakModeKey]];
[self setAlignment:[aCoder decodeIntForKey:CPTextFieldAlignmentKey]];
@@ -2086,6 +2246,7 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
[self _setUsesSingleLineMode:[aCoder decodeBoolForKey:CPTextFieldUsesSingleLineMode]];
[self _setWraps:[aCoder decodeBoolForKey:CPTextFieldWraps]];
[self _setScrolls:[aCoder decodeBoolForKey:CPTextFieldScrolls]];
[self updateTrackingAreas];
}
return self;
@@ -2120,6 +2281,56 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
@implementation _CPTextFieldValueBinder : CPBinder
+ (void)unbind:(CPString)aBinding forObject:(id)anObject
{
var theBinding = [self getBinding:aBinding forObject:anObject],
notificationCenter = [CPNotificationCenter defaultCenter];
if (theBinding)
{
[notificationCenter removeObserver:[theBinding._info objectForKey:CPObservedObjectKey]
name:CPControlTextDidBeginEditingNotification
object:anObject];
[notificationCenter removeObserver:[theBinding._info objectForKey:CPObservedObjectKey]
name:CPControlTextDidEndEditingNotification
object:anObject];
[super unbind:aBinding forObject:anObject];
}
}
- (id)initWithBinding:(CPString)aBinding name:(CPString)aName to:(id)aDestination keyPath:(CPString)aKeyPath options:(CPDictionary)options from:(id)aSource
{
self = [super initWithBinding:aBinding
name:aName
to:aDestination
keyPath:aKeyPath
options:options
from:aSource];
var notificationCenter = [CPNotificationCenter defaultCenter];
// This gives us support for the CPEditorRegistration informal protocol
if ([aDestination respondsToSelector:@selector(_objectDidBeginEditing:)])
{
[notificationCenter addObserver:aDestination
selector:@selector(_objectDidBeginEditing:)
name:CPControlTextDidBeginEditingNotification
object:aSource];
}
if ([aDestination respondsToSelector:@selector(_objectDidEndEditing:)])
{
[notificationCenter addObserver:aDestination
selector:@selector(_objectDidEndEditing:)
name:CPControlTextDidEndEditingNotification
object:aSource];
}
return self;
}
- (void)_updatePlaceholdersWithOptions:(CPDictionary)options forBinding:(CPString)aBinding
{
[super _updatePlaceholdersWithOptions:options];
@@ -2152,7 +2363,7 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
newValue = [self valueForBinding:aBinding],
value = [destination valueForKeyPath:keyPath];
if (CPIsControllerMarker(value) && newValue === nil)
if (CPIsControllerMarker(value) && newValue == nil)
return;
newValue = [self reverseTransformValue:newValue withOptions:options];
@@ -2218,7 +2429,7 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
@end
#pragma mark -
// MARK: -
@implementation CPTextField (TableDataView)
@@ -2235,4 +2446,22 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
@end
// MARK: -
@implementation CPTextField (Deprecated)
- (void)setTextFieldBackgroundColor:(CPColor)aColor
{
CPLog.error("[CPTextField setTextFieldBackgroundColor:] is deprecated, use [CPTextField setBackgroundColor:] instead.");
[self setBackgroundColor:aColor];
}
- (CPColor)textFieldBackgroundColor
{
CPLog.info("[CPTextField textFieldBackgroundColor] is deprecated, use [CPTextField backgroundColor] instead.");
return [self backgroundColor];
}
@end
+263 -71
View File
@@ -1,34 +1,29 @@
/*
* CPFontPanel.j
* AppKit
*
* TODOs:
* 1. make browser-width for size smaller and fix columns
* 2. add all the missing features from the MacOS X counterpart (sampleview)
*
*
* Created by Daniel Boehringer on 2/JAN/2014.
* All modifications copyright Daniel Boehringer 2013.
* Extensive code formatting and review by Andrew Hankinson
* Based on original work by
* Created by Emmanuel Maillard on 06/03/2010.
* Copyright Emmanuel Maillard 2010.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
CPFontPanel.j
AppKit
Created by Daniel Boehringer on 2/JAN/2014.
All modifications copyright Daniel Boehringer 2013.
Extensive code formatting and review by Andrew Hankinson
Based on original work by
Created by Emmanuel Maillard on 06/03/2010.
Copyright Emmanuel Maillard 2010.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPPanel.j"
@import "CPColorWell.j"
@@ -37,7 +32,6 @@
@import "CPText.j"
@import "CPFontManager.j"
@class CPTextStorage
@class CPLayoutManager
@class CPTextContainer
@@ -46,27 +40,30 @@
/*
Collection indexes
*/
var kTypefaceIndex_Normal = 0,
kTypefaceIndex_Italic = 1,
kTypefaceIndex_Bold = 2,
var kTypefaceIndex_Normal = 0,
kTypefaceIndex_Italic = 1,
kTypefaceIndex_Bold = 2,
kTypefaceIndex_BoldItalic = 3,
kToolbarHeight = 32,
kBorderSpacing = 6,
kInnerSpacing = 2,
kNothingChanged = 0,
kFontNameChanged = 1,
kTypefaceChanged = 2,
kSizeChanged = 3,
kTextColorChanged = 4,
kBackgroundColorChanged = 5,
kUnderlineChanged = 6,
kWeightChanged = 7,
kToolbarHeight = 32,
kPreviewHeight = 70,
kBorderSpacing = 6,
kInnerSpacing = 2,
kNothingChanged = 0,
kFontNameChanged = 1,
kTypefaceChanged = 2,
kSizeChanged = 3,
kTextColorChanged = 4,
kBackgroundColorChanged = 5,
kUnderlineChanged = 6,
kWeightChanged = 7,
_sharedFontPanel;
// FIXME<!> Locale support
var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
_availableSizes = [@"9", @"10", @"11", @"12", @"13", @"14", @"18", @"24", @"36", @"48", @"72", @"96"];
var _availableTraits = [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
_availableSizes = [@"9", @"10", @"11", @"12", @"13", @"14", @"18", @"24", @"36", @"48", @"64", @"72", @"96", @"144", @"288"];
/*!
@ingroup appkit
@@ -77,6 +74,10 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
id _fontBrowser;
id _traitBrowser;
id _sizeBrowser;
// Preview
_CPFontPanelPreviewView _previewView;
CPArray _availableFonts;
id _textColorWell;
CPColor _textColor;
@@ -85,16 +86,15 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
int _fontChanges;
}
#pragma mark -
#pragma mark Class methods
// MARK: -
// MARK: Class methods
/*!
Check if the shared Font panel exists.
*/
+ (BOOL)sharedFontPanelExists
{
return _sharedFontPanel !== nil;
return _sharedFontPanel != nil;
}
/*!
@@ -108,14 +108,18 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
return _sharedFontPanel;
}
- (BOOL)acceptsFirstResponder
{
return NO;
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
/*! @ignore */
- (id)init
{
if (self = [super initWithContentRect:CGRectMake(100, 90, 450, 394) styleMask:(CPTitledWindowMask | CPClosableWindowMask /*| CPResizableWindowMask*/ )])
if (self = [super initWithContentRect:CGRectMake(100, 90, 450, 420) styleMask:(CPTitledWindowMask | CPClosableWindowMask | CPResizableWindowMask)])
{
[[self contentView] setBackgroundColor:[CPColor colorWithWhite:0.95 alpha:1.0]];
[self setTitle:@"Font Panel"];
@@ -152,10 +156,49 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
[aBrowser setDoubleAction:@selector(dblClicked:)];
[aBrowser setAllowsEmptySelection:NO];
[aBrowser setAllowsMultipleSelection:NO];
// Config Scrollers
//[aBrowser setHasHorizontalScroller:NO];
//[aBrowser setHasVerticalScroller:YES];
//[aBrowser setAutohidesScrollers:YES];
//[aBrowser setMaxVisibleColumns:1];
[aBrowser setDelegate:self];
[[self contentView] addSubview:aBrowser];
}
- (void)_layoutBrowsers
{
var contentView = [self contentView],
contentBounds = [contentView bounds],
previewY = kBorderSpacing + kToolbarHeight + kInnerSpacing,
browserY = previewY + kPreviewHeight + 10,
browserHeight = CGRectGetHeight(contentBounds) - browserY - 10,
availableWidth = CGRectGetWidth(contentBounds) - 20; // 10px padding L/R
// Layout Calculations
// Increase sizeWidth slightly to 60 to allow space for the vertical scrollbar without clipping text
var sizeWidth = 90,
spacing = 5,
remainingWidth = availableWidth - sizeWidth - (spacing * 2),
// Split remaining roughly 60% font name, 40% trait
fontWidth = FLOOR(remainingWidth * 0.60),
traitWidth = remainingWidth - fontWidth;
// Apply frames and column constraints
[_fontBrowser setFrame:CGRectMake(10, browserY, fontWidth, browserHeight)];
[_fontBrowser setDefaultColumnWidth:fontWidth];
[_fontBrowser setLastColumn:0];
[_traitBrowser setFrame:CGRectMake(10 + fontWidth + spacing, browserY, traitWidth, browserHeight)];
[_traitBrowser setDefaultColumnWidth:traitWidth];
[_traitBrowser setLastColumn:0];
[_sizeBrowser setFrame:CGRectMake(10 + fontWidth + traitWidth + (spacing * 2), browserY, sizeWidth, browserHeight)];
[_sizeBrowser setDefaultColumnWidth:sizeWidth];
[_sizeBrowser setLastColumn:0];
}
- (void)_setupContents
{
if (_setupDone)
@@ -163,33 +206,53 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
_setupDone = YES;
// We set ourselves as delegate to handle resizing layout manually
[self setDelegate:self];
[self _setupToolbarView];
var contentView = [self contentView],
label = [CPTextField labelWithTitle:@"Font name"],
contentBounds = [contentView bounds],
upperView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(contentBounds), CGRectGetHeight(contentBounds) - (kBorderSpacing + kToolbarHeight + kInnerSpacing))];
contentBounds = [contentView bounds];
[contentView addSubview:_toolbarView];
_fontBrowser = [[CPBrowser alloc] initWithFrame:CGRectMake(10, 35, 150, 350)];
_traitBrowser = [[CPBrowser alloc] initWithFrame:CGRectMake(155, 35, 150, 350)];
_sizeBrowser = [[CPBrowser alloc] initWithFrame:CGRectMake(300, 35, 140, 350)];
// Preview View
var previewY = kBorderSpacing + kToolbarHeight + kInnerSpacing;
_previewView = [[_CPFontPanelPreviewView alloc] initWithFrame:CGRectMake(10, previewY, CGRectGetWidth(contentBounds) - 20, kPreviewHeight)];
[_previewView setAutoresizingMask:CPViewWidthSizable];
[contentView addSubview:_previewView];
// Initialize Browsers with zero rect, _layoutBrowsers will size them
_fontBrowser = [[CPBrowser alloc] initWithFrame:CGRectMakeZero()];
_traitBrowser = [[CPBrowser alloc] initWithFrame:CGRectMakeZero()];
_sizeBrowser = [[CPBrowser alloc] initWithFrame:CGRectMakeZero()];
// Disable autoresizing masks because we are laying out manually in windowDidResize
[_fontBrowser setAutoresizingMask:CPViewNotSizable];
[_traitBrowser setAutoresizingMask:CPViewNotSizable];
[_sizeBrowser setAutoresizingMask:CPViewNotSizable];
[self _setupBrowser:_fontBrowser];
[self _setupBrowser:_traitBrowser];
[self _setupBrowser:_sizeBrowser];
// Perform initial layout
[self _layoutBrowsers];
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(textViewDidChangeSelection:)
name:CPTextViewDidChangeSelectionNotification
object:nil];
}
- (void)windowDidResize:(CPNotification)aNotification
{
[self _layoutBrowsers];
}
- (void)textViewDidChangeSelection:(CPNotification)notification
{
[self _refreshWithTextView:[notification object]];
[self _refreshWithTextView:[notification object]];
}
- (void)_refreshWithTextView:(CPTextView)textView
@@ -197,6 +260,9 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
if (![self isVisible])
return;
if (![textView respondsToSelector:@selector(_attributesForFontPanel)])
return;
var attribs = [textView _attributesForFontPanel],
font = [attribs objectForKey:CPFontAttributeName] || [[textView textStorage] font] || [CPFont systemFontOfSize:12.0],
color = [attribs objectForKey:CPForegroundColorAttributeName];
@@ -217,6 +283,9 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
[self setCurrentTrait:trait];
[self setCurrentSize:[font size] + ""]; //cast to string
// Update Preview
[_previewView setPreviewFont:font];
if (!color)
return;
@@ -253,7 +322,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
{
case kFontNameChanged:
newFont = [CPFont fontWithDescriptor:[[aFont fontDescriptor] fontDescriptorByAddingAttributes:
[CPDictionary dictionaryWithObject:[self currentFont] forKey:CPFontNameAttribute]] size:0.0];
[CPDictionary dictionaryWithObject:[self currentFont] forKey:CPFontNameAttribute]] size:0.0];
break;
case kTypefaceChanged:
@@ -272,12 +341,13 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
newFont = [[CPFontManager sharedFontManager] convertFont:aFont toSize:[self currentSize]];
break;
case kNothingChanged:
case kNothingChanged:
break;
default:
CPLog.trace(@"FIXME: -[" + [self className] + " " + _cmd + "] unhandled _fontChanges: " + _fontChanges);
break;
}
return newFont;
@@ -285,7 +355,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
- (void)setCurrentSize:(CGSize)aSize
{
[_sizeBrowser selectRow:[_availableSizes indexOfObject:aSize] inColumn:0];
[_sizeBrowser selectRow:[_availableSizes indexOfObject:aSize] inColumn:0];
}
- (CPString)currentSize
@@ -295,7 +365,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
- (void)setCurrentFont:(CPFont)aFont
{
[_fontBrowser selectRow:[_availableFonts indexOfObject:[aFont familyName]] inColumn:0];
[_fontBrowser selectRow:[_availableFonts indexOfObject:[aFont familyName]] inColumn:0];
}
- (CPString)currentFont
@@ -320,9 +390,10 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
case kTypefaceIndex_BoldItalic:
row = 3;
break;
}
[_traitBrowser selectRow:row inColumn:0];
[_traitBrowser selectRow:row inColumn:0];
}
// FIXME<!> Locale support
@@ -370,6 +441,8 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
if ([self currentTrait] != typefaceIndex)
[self setCurrentTrait:typefaceIndex ];
[_previewView setPreviewFont:font];
_fontChanges = kNothingChanged;
}
@@ -382,23 +455,30 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
////////////////////////////////////////////////////////////////////
// TODO: ask CPFontManager for traits //
- (void)browserClicked:(id)aBrowser
{
if (aBrowser === _fontBrowser)
{
_fontChanges = kFontNameChanged;
[[CPFontManager sharedFontManager] modifyFontViaPanel:self];
}
else if (aBrowser === _traitBrowser)
{
_fontChanges = kTypefaceChanged;
[[CPFontManager sharedFontManager] modifyFontViaPanel:self];
}
else if (aBrowser === _sizeBrowser)
{
_fontChanges = kSizeChanged;
[[CPFontManager sharedFontManager] modifyFontViaPanel:self];
}
// Apply change immediately to manager (standard behavior)
[[CPFontManager sharedFontManager] modifyFontViaPanel:self];
// Update our preview manually because convertFont: calls rely on selected rows
// We construct a temporary font to update the preview view immediately
var updatedFont = [self panelConvertFont:[_previewView font]];
if (updatedFont)
[_previewView setPreviewFont:updatedFont];
}
- (void)dblClicked:(id)sender
@@ -414,7 +494,7 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
if (aBrowser === _traitBrowser)
return [_availableTraits count];
return [_availableSizes count]
return [_availableSizes count];
}
- (id)browser:(id)aBrowser child:(int)index ofItem:(id)anItem
@@ -440,4 +520,116 @@ var _availableTraits= [@"Normal", @"Italic", @"Bold", @"Bold Italic"],
@end
// -----------------------------------------------------------------------------
// _CPFontPanelPreviewView
// A helper class to display a font sample with metrics grid
// -----------------------------------------------------------------------------
@implementation _CPFontPanelPreviewView : CPView
{
CPTextField _sampleText;
CPColor _gridColor;
float _gridSize;
}
- (id)initWithFrame:(CGRect)aRect
{
self = [super initWithFrame:aRect];
if (self)
{
[self setBackgroundColor:[CPColor whiteColor]];
_gridColor = [CPColor colorWithHexString:@"e4f4ff"];
_gridSize = 10.0;
_sampleText = [[CPTextField alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(aRect), CGRectGetHeight(aRect))];
[_sampleText setStringValue:@"AaYy-0123"];
[_sampleText setAlignment:CPCenterTextAlignment];
[_sampleText setVerticalAlignment:CPCenterVerticalTextAlignment];
[_sampleText setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[_sampleText setTextColor:[CPColor blackColor]];
[self addSubview:_sampleText];
}
return self;
}
- (void)setPreviewFont:(CPFont)aFont
{
[_sampleText setFont:aFont];
[self setNeedsDisplay:YES];
}
- (CPFont)font
{
return [_sampleText font];
}
- (void)drawRect:(CGRect)dirtyRect
{
// Draw Grid (from MetricsView inspiration)
var context = [[CPGraphicsContext currentContext] graphicsPort],
bounds = [self bounds],
maxX = CGRectGetMaxX(bounds),
maxY = CGRectGetMaxY(bounds);
CGContextSetLineWidth(context, 1.0);
CGContextSetStrokeColor(context, _gridColor);
CGContextBeginPath(context);
for (var y = 0.5; y <= maxY; y += _gridSize)
{
CGContextMoveToPoint(context, 0.0, y);
CGContextAddLineToPoint(context, maxX, y);
}
for (var x = 0.5; x <= maxX; x += _gridSize)
{
CGContextMoveToPoint(context, x, 0.0);
CGContextAddLineToPoint(context, x, maxY);
}
CGContextStrokePath(context);
// Draw Baseline/Ascender/Descender (from BaselineView inspiration)
var font = [_sampleText font];
if (!font) return;
var ascender = [font ascender],
descender = [font descender],
lineHeight = [font defaultLineHeightForFont];
// Calculate the baseline.
// CPTextField with CPCenterVerticalTextAlignment usually centers the line height.
// Top of line = midY - (lineHeight / 2.0)
// Baseline = Top of line + ascender
var midY = maxY / 2.0,
baselineY = midY - (lineHeight / 2.0) + ascender;
CGContextSetStrokeColor(context, [CPColor redColor]);
CGContextBeginPath(context);
// Baseline
CGContextMoveToPoint(context, 0, baselineY);
CGContextAddLineToPoint(context, maxX, baselineY);
// Ascender Line
CGContextMoveToPoint(context, 0, baselineY - ascender);
CGContextAddLineToPoint(context, maxX, baselineY - ascender);
// Descender Line
CGContextMoveToPoint(context, 0, baselineY - descender);
CGContextAddLineToPoint(context, maxX, baselineY - descender);
CGContextStrokePath(context);
}
- (void)mouseDown:(CPEvent)anEvent
{
var text = prompt("Enter sample text:", [_sampleText stringValue]);
if (text)
[_sampleText setStringValue:text];
}
@end
[CPFontManager setFontPanelFactory:[CPFontPanel class]];
+322 -109
View File
@@ -2,9 +2,6 @@
* CPLayoutManager.j
* AppKit
*
* FIXME remove from DOM when scrolled out of visible area? (as done in CPTableView)
*
*
* Created by Daniel Boehringer on 27/12/2013.
* All modifications copyright Daniel Boehringer 2013.
* Extensive code formatting and review by Andrew Hankinson
@@ -34,6 +31,9 @@
@import "CPFont.j"
@global _MakeRangeFromAbs
@global document
@global CPBaselineOffsetAttributeName
@global CPSuperscriptAttributeName
@class CPTextContainer
@class CPTextView
@@ -72,11 +72,12 @@ _oncontextmenuhandler = function () { return false; };
BOOL _isValidatingLayoutAndGlyphs;
CPRange _removeInvalidLineFragmentsRange;
CPRange _lastEditedRange;
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
- (id)init
{
@@ -96,13 +97,14 @@ _oncontextmenuhandler = function () { return false; };
_textContainers = [[CPMutableArray alloc] init];
_textStorage = [[CPTextStorage alloc] init];
_typesetter = [CPTypesetter sharedSystemTypesetter];
_lastEditedRange = nil;
[_textStorage addLayoutManager:self];
}
#pragma mark -
#pragma mark Text containes method
// MARK: -
// MARK: Text containes method
- (void)insertTextContainer:(CPTextContainer)aContainer atIndex:(int)index
{
@@ -259,6 +261,9 @@ _oncontextmenuhandler = function () { return false; };
{
if (_lineFragments[i]._isInvalid)
{
while (i > 0 && !_lineFragments[i - 1]._isLast)
i--;
startIndex = _lineFragments[i]._range.location;
removeRange.location = i;
removeRange.length = l - i;
@@ -284,11 +289,12 @@ _oncontextmenuhandler = function () { return false; };
if (removeRange.length)
_removeInvalidLineFragmentsRange = CPMakeRangeCopy(removeRange);
else
_removeInvalidLineFragmentsRange = nil;
// We erased all lines
if (!startIndex)
[self setExtraLineFragmentRect:CGRectMake(0, 0) usedRect:CGRectMake(0, 0) textContainer:nil];
// document.title=startIndex;
[_typesetter layoutGlyphsInLayoutManager:self startingAtGlyphIndex:startIndex maxNumberOfLineFragments:-1 nextGlyphIndex:nil];
@@ -301,13 +307,17 @@ _oncontextmenuhandler = function () { return false; };
- (BOOL)_rescuingInvalidFragmentsWasPossibleForGlyphRange:(CPRange)aRange
{
var l = _lineFragments.length,
location = aRange.location,
found = NO,
targetLine = 0;
// 1. EARLY EXIT: If there are no fragments to rescue (e.g. setting new text), do nothing.
if (!_lineFragmentsForRescue || _lineFragmentsForRescue.length === 0)
return NO;
// try to find the first linefragment of the desired range
for (; targetLine < l; targetLine++)
var l = _lineFragments.length,
location = aRange.location,
found = NO,
targetLine = l - 1; // Start from the END of the array
// 2. REVERSE SEARCH: The fragment we want is almost always at the end.
for (; targetLine >= 0; targetLine--)
{
if (CPLocationInRange(location, _lineFragments[targetLine]._range))
{
@@ -330,9 +340,6 @@ _oncontextmenuhandler = function () { return false; };
newLength = [[_textStorage string].length],
removalSkip = 1;
// if (ABS(newLength - oldLength) > 1)
// return NO;
if (![oldLineFragment isVisuallyIdenticalToFragment:newLineFragment])
{
isIdentical = NO;
@@ -361,10 +368,20 @@ _oncontextmenuhandler = function () { return false; };
if (ABS(rangeOffset) !== ABS(newLength - oldLength))
return NO;
var verticalOffset = _lineFragments[targetLine]._fragmentRect.origin.y - _lineFragmentsForRescue[startLineForDOMRemoval]._fragmentRect.origin.y,
var verticalOffset = CGRectGetMaxY(_lineFragments[targetLine]._fragmentRect) - CGRectGetMaxY(_lineFragmentsForRescue[startLineForDOMRemoval]._fragmentRect),
l = _lineFragmentsForRescue.length,
newTargetLine = startLineForDOMRemoval + removalSkip;
// Ensure that the remaining lines we are attempting to rescue
// start after the end of the edited region.
if (newTargetLine < l && _lastEditedRange)
{
var firstRescuedLineNewLocation = _lineFragmentsForRescue[newTargetLine]._range.location + rangeOffset;
if (firstRescuedLineNewLocation < CPMaxRange(_lastEditedRange))
return NO;
}
for (; newTargetLine < l; newTargetLine++)
{
_lineFragmentsForRescue[newTargetLine]._isInvalid = NO; // protect them from final removal
@@ -436,6 +453,8 @@ _oncontextmenuhandler = function () { return false; };
{
var actualRange = CPMakeRange(CPNotFound,0);
_lastEditedRange = CPMakeRangeCopy(charRange);
[self invalidateLayoutForCharacterRange:invalidatedRange isSoft:NO actualCharacterRange:actualRange];
[self invalidateDisplayForGlyphRange:actualRange];
[self _validateLayoutAndGlyphs];
@@ -495,16 +514,6 @@ _oncontextmenuhandler = function () { return false; };
}
- (void)drawUnderlineForGlyphRange:(CPRange)glyphRange
underlineType:(int)underlineVal
baselineOffset:(float)baselineOffset
lineFragmentRect:(CGRect)lineFragmentRect
lineFragmentGlyphRange:(CPRange)lineGlyphRange
containerOrigin:(CGPoint)containerOrigin
{
// FIXME
}
- (void)drawGlyphsForGlyphRange:(CPRange)aRange atPoint:(CGPoint)aPoint
{
var lineFragments = _objectsInRange(_lineFragments, aRange);
@@ -537,20 +546,26 @@ _oncontextmenuhandler = function () { return false; };
var frames = [fragment glyphFrames],
len = fragment._range.length;
for (var j = 0; j < len; j++)
if (frames)
{
if (CGRectContainsPoint(frames[j], point))
{
if (partialFraction)
partialFraction[0] = (point.x - frames[j].origin.x) / frames[j].size.width;
var maxLen = MIN(len, frames.length);
return fragment._range.location + j;
for (var j = 0; j < maxLen; j++)
{
var frame = frames[j];
if (frame && CGRectContainsPoint(frame, point))
{
if (partialFraction)
partialFraction[0] = (point.x - frame.origin.x) / frame.size.width;
return fragment._range.location + j;
}
}
}
}
}
// Not found, maybe a point left to the last character was clicked -> search again with broader constraints
if ([[_textStorage string] length])
{
for (var i = 0; i < c; i++)
@@ -559,30 +574,33 @@ _oncontextmenuhandler = function () { return false; };
if (fragment._textContainer === container)
{
// Within the horizontal territory of the current (not-empty) line?
if (fragment._range.length > 0 && point.y > fragment._fragmentRect.origin.y &&
point.y <= fragment._fragmentRect.origin.y + fragment._fragmentRect.size.height)
if (fragment._range.length > 0 && point.y > fragment._fragmentRect.origin.y &&
point.y <= fragment._fragmentRect.origin.y + fragment._fragmentRect.size.height)
{
if (i < c - 1 && _lineFragments[i + 1]._fragmentRect.origin.y === fragment._fragmentRect.origin.y)
continue;
var nlLoc = CPMaxRange(fragment._range),
frames = [fragment glyphFrames];
if (frames && frames.length > 0)
{
// Skip tabs and move on the last fragment in this line
if (i < c - 1 && _lineFragments[i + 1]._fragmentRect.origin.y === fragment._fragmentRect.origin.y)
continue;
var lastFrame = frames[frames.length - 1],
firstFrame = frames[0];
var nlLoc = CPMaxRange(fragment._range),
lastFrame = [fragment glyphFrames][fragment._range.length - 1],
firstFrame = [fragment glyphFrames][0];
if (lastFrame && firstFrame)
{
if (_isNewlineCharacter([[_textStorage string] characterAtIndex:nlLoc > 0 ? nlLoc - 1 : 0]))
nlLoc--;
// stay on the line the newline character belongs to
if (_isNewlineCharacter([[_textStorage string] characterAtIndex:nlLoc > 0 ? nlLoc - 1 : 0]))
nlLoc--;
// Clicked right to the last character
if (point.x > CGRectGetMaxX(lastFrame))
return nlLoc;
// Clicked left to the last character
else if (point.x <= CGRectGetMinX(firstFrame))
return fragment._range.location;
else
return nlLoc;
if (point.x > CGRectGetMaxX(lastFrame))
return nlLoc;
else if (point.x <= CGRectGetMinX(firstFrame))
return fragment._range.location;
else
return nlLoc;
}
}
}
}
}
@@ -671,12 +689,10 @@ _oncontextmenuhandler = function () { return false; };
{
var j = i;
while (--j > 0 && !_lineFragments[j]._isLast)
{
// body intentionally left empty
}
while (j > 0 && !_lineFragments[j - 1]._isLast)
j--;
return _lineFragments[j + 1];
return _lineFragments[j];
}
}
@@ -686,13 +702,16 @@ _oncontextmenuhandler = function () { return false; };
{
var l = _lineFragments.length;
if (location >= CPMaxRange(_lineFragments[l - 1]._range))
return _lineFragments[l - 1];
for (var i = 0; i < l; i++)
{
if (CPLocationInRange(location, _lineFragments[i]._range))
{
var j = i;
while (!_lineFragments[j]._isLast)
while (j < l && !_lineFragments[j]._isLast)
j++;
return _lineFragments[j];
@@ -711,7 +730,11 @@ _oncontextmenuhandler = function () { return false; };
var index = location - lineFragment._range.location;
return lineFragment._glyphsOffsets[index];
if (index < 0 || !lineFragment._glyphsOffsets || index >= lineFragment._glyphsOffsets.length)
return 0.0;
var offset = lineFragment._glyphsOffsets[index];
return (offset === undefined) ? 0.0 : offset;
}
- (double)_descentAtLocation:(unsigned)location
@@ -723,7 +746,11 @@ _oncontextmenuhandler = function () { return false; };
var index = location - lineFragment._range.location;
return lineFragment._glyphsFrames[index]._descent;
if (index < 0 || !lineFragment._glyphsFrames || index >= lineFragment._glyphsFrames.length)
return 0.0;
var frame = lineFragment._glyphsFrames[index];
return (frame && frame._descent !== undefined) ? frame._descent : 0.0;
}
- (void)setLineFragmentRect:(CGRect)fragmentRect forGlyphRange:(CPRange)glyphRange usedRect:(CGRect)usedRect
@@ -847,11 +874,16 @@ _oncontextmenuhandler = function () { return false; };
{
if (_lineFragments.length > 0 && index >= [self numberOfGlyphs] - 1)
{
var lineFragment= _lineFragments[_lineFragments.length - 1],
var lineFragment = _lineFragments[_lineFragments.length - 1],
glyphFrames = [lineFragment glyphFrames];
if (glyphFrames.length > 0)
return CGPointCreateCopy(glyphFrames[glyphFrames.length - 1].origin);
if (glyphFrames && glyphFrames.length > 0)
{
var frame = glyphFrames[glyphFrames.length - 1];
if (frame)
return CGPointCreateCopy(frame.origin);
}
}
var lineFragment = _objectWithLocationInRange(_lineFragments, index);
@@ -862,8 +894,17 @@ _oncontextmenuhandler = function () { return false; };
return CGPointCreateCopy(lineFragment._location);
var glyphFrames = [lineFragment glyphFrames];
var relativeIndex = index - lineFragment._range.location;
return CGPointCreateCopy(glyphFrames[index - lineFragment._range.location].origin);
if (glyphFrames && relativeIndex >= 0 && relativeIndex < glyphFrames.length)
{
var frame = glyphFrames[relativeIndex];
if (frame)
return CGPointCreateCopy(frame.origin);
}
return CGPointCreateCopy(lineFragment._location);
}
return CGPointMakeZero();
@@ -909,7 +950,6 @@ _oncontextmenuhandler = function () { return false; };
inTextContainer:(CPTextContainer)container
rectCount:(CGRectPointer)rectCount
{
var rectArray = [],
lineFragments = _objectsInRange(_lineFragments, selectedCharRange);
@@ -928,21 +968,23 @@ _oncontextmenuhandler = function () { return false; };
rect = nil,
len = fragment._range.length;
for (var j = 0; j < len; j++)
if (frames)
{
if (CPLocationInRange(fragment._range.location + j, selectedCharRange))
for (var j = 0; j < len; j++)
{
var correctedRect = CGRectCreateCopy(frames[j]);
correctedRect.size.height -= frames[j]._descent;
correctedRect.origin.y -= frames[j]._descent;
if (!rect)
rect = CGRectCreateCopy(correctedRect);
else
rect = CGRectUnion(rect, correctedRect);
if (_isNewlineCharacter([[_textStorage string] characterAtIndex:MAX(0, CPMaxRange(selectedCharRange) - 1)]))
if (j < frames.length && CPLocationInRange(fragment._range.location + j, selectedCharRange))
{
rect.size.width = containerSize.width - rect.origin.x;
var frame = frames[j];
if (frame)
{
var correctedRect = CGRectCreateCopy(frame);
if (!rect)
rect = CGRectCreateCopy(correctedRect);
else
rect = CGRectUnion(rect, correctedRect);
}
}
}
}
@@ -954,7 +996,7 @@ _oncontextmenuhandler = function () { return false; };
var len = rectArray.length;
for (var i = 0; i < len - 1; i++) // extend the width of all but the last one
for (var i = 0; i < len - 1; i++)
{
if (FLOOR(CGRectGetMaxY(rectArray[i])) == FLOOR(CGRectGetMaxY(rectArray[i + 1])))
continue;
@@ -1090,17 +1132,25 @@ var _objectsInRange = function(aList, aRange)
CPMutableArray _runs;
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
- (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)aColor
{
return [self createDOMElementWithText:aString andFont:aFont andColor:aColor andBackgroundColor:nil andUnderline:nil ];
}
- (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)fgColor andBackgroundColor:(CPColor)bgColor andUnderline:(CPUnderlineStyle)aUnderline
{
if (!aString || aString.length === 0)
return nil;
#if PLATFORM(DOM)
var style,
span = document.createElement("span");
span.oncontextmenu = span.onmousedown = span.onselectstart = _oncontextmenuhandler;
// span.contentEditable = true; // this unfortunately does not work to make native pasting work on safari
style = span.style;
style.position = "absolute";
@@ -1110,16 +1160,42 @@ var _objectsInRange = function(aList, aRange)
style.whiteSpace = "pre";
style.backgroundColor = "transparent";
style.font = [aFont cssString];
if (aUnderline)
{
style.textDecoration = "underline";
switch (aUnderline)
{
case CPUnderlineStyleSingle:
style.textDecorationStyle = "solid";
break;
if (aColor)
style.color = [aColor cssString];
case CPUnderlineStyleDouble:
style.textDecorationStyle = "double";
break;
case CPUnderlineStylePatternDot:
style.textDecorationStyle = "dotted";
break;
case CPUnderlineStylePatternDash:
style.textDecorationStyle = "dashed";
break;
}
}
if (fgColor)
style.color = [fgColor cssString];
if (bgColor)
style.backgroundColor = [bgColor cssString];
if (CPFeatureIsCompatible(CPJavaScriptInnerTextFeature))
span.innerText = aString;
else if (CPFeatureIsCompatible(CPJavaScriptTextContentFeature))
span.textContent = aString;
//<!> FIXME aString.replace(/&/g,'&amp;')
return span;
#else
return nil;
@@ -1139,7 +1215,9 @@ var _objectsInRange = function(aList, aRange)
_range = CPMakeRangeCopy(aRange);
_textContainer = aContainer;
_isInvalid = NO;
_runs = [[CPMutableArray alloc] init];
_runs = [];
_glyphsFrames = [];
_glyphsOffsets = [];
for (location = aRange.location; location < CPMaxRange(aRange); location = CPMaxRange(effectiveRange))
{
@@ -1148,16 +1226,115 @@ var _objectsInRange = function(aList, aRange)
effectiveRange = attributes ? CPIntersectionRange(aRange, effectiveRange) : aRange;
var string = [textStorage._string substringWithRange:effectiveRange],
font = [textStorage font] || [CPFont systemFontOfSize:12.0];
underline = [attributes objectForKey:CPUnderlineStyleAttributeName] || CPUnderlineStyleNone,
paragraphStyle = [attributes objectForKey:CPParagraphStyleAttributeName] || [CPParagraphStyle defaultParagraphStyle];
if ([attributes containsKey:CPFontAttributeName])
font = [attributes objectForKey:CPFontAttributeName];
// this is an attachment -> create a run for it
if (string === _CPAttachmentCharacterAsString)
{
if (![attributes objectForKey:_CPAttachmentInvisible])
{
var view = [attributes objectForKey:_CPAttachmentView];
var run = {_range:CPMakeRangeCopy(effectiveRange), color:nil, font:nil, elem:nil, string:nil, view:view, paragraphStyle:paragraphStyle, underline:underline, baselineOffset:0.0};
_runs.push(run);
}
}
else
{
var color = [attributes objectForKey:CPForegroundColorAttributeName],
bgcolor = [attributes objectForKey:CPBackgroundColorAttributeName],
font = [attributes objectForKey:CPFontAttributeName] || [textStorage font] || [CPFont systemFontOfSize:12.0];
var color = [attributes objectForKey:CPForegroundColorAttributeName],
elem = [self createDOMElementWithText:string andFont:font andColor:color],
run = {_range:CPMakeRangeCopy(effectiveRange), color:color, font:font, elem:nil, string:string};
var baselineOffset = [attributes objectForKey:CPBaselineOffsetAttributeName],
superscript = [attributes objectForKey:CPSuperscriptAttributeName];
_runs.push(run);
if (baselineOffset === nil || baselineOffset === undefined || typeof baselineOffset !== "number")
baselineOffset = 0.0;
if (superscript === nil || superscript === undefined || typeof superscript !== "number")
superscript = 0;
if (superscript !== 0)
{
var size = [font size],
scaledSize = size * 0.65,
fontName = [font familyName],
isBold = [font isBold],
isItalic = [font isItalic];
font = [CPFont _fontWithName:fontName size:scaledSize bold:isBold italic:isItalic];
if (baselineOffset === 0.0)
{
if (superscript > 0)
baselineOffset = size * 0.35;
else
baselineOffset = -size * 0.15;
}
}
var currentLoc = effectiveRange.location,
strLen = string.length,
startIdx = 0;
for (var i = 0; i < strLen; i++)
{
if (string.charCodeAt(i) === 9) // Tabulator-Zeichen '\t'
{
if (i > startIdx)
{
var subString = string.substring(startIdx, i),
subRange = CPMakeRange(currentLoc + startIdx, i - startIdx),
run = {
_range: subRange,
color: color,
font: font,
elem: nil,
string: subString,
bgcolor: bgcolor,
paragraphStyle: paragraphStyle,
underline: underline,
baselineOffset: baselineOffset
};
_runs.push(run);
}
var tabRange = CPMakeRange(currentLoc + i, 1),
tabRun = {
_range: tabRange,
color: nil,
font: nil,
elem: nil,
string: nil,
bgcolor: nil,
paragraphStyle: paragraphStyle,
underline: underline,
baselineOffset: 0.0
};
_runs.push(tabRun);
startIdx = i + 1;
}
}
if (startIdx < strLen)
{
var subString = string.substring(startIdx, strLen),
subRange = CPMakeRange(currentLoc + startIdx, strLen - startIdx),
run = {
_range: subRange,
color: color,
font: font,
elem: nil,
string: subString,
bgcolor: bgcolor,
paragraphStyle: paragraphStyle,
underline: underline,
baselineOffset: baselineOffset
};
_runs.push(run);
}
}
if (!CPMaxRange(effectiveRange))
break;
@@ -1180,7 +1357,10 @@ var _objectsInRange = function(aList, aRange)
{
_glyphsFrames[i] = CGRectMake(origin.x, origin.y, someAdvancements[i].width, height);
_glyphsFrames[i]._descent = someAdvancements[i].descent;
_glyphsOffsets[i] = height - someAdvancements[i].height;
// Align the run's baseline with the common line baseline (_location.y)
_glyphsOffsets[i] = _location.y - someAdvancements[i].height;
origin.x += someAdvancements[i].width;
}
}
@@ -1228,6 +1408,9 @@ var _objectsInRange = function(aList, aRange)
for (var i = 0; i < l; i++)
{
if (_runs[i].view && _runs[i].DOMactive)
[_runs[i].view removeFromSuperview];
if (_runs[i].elem && _runs[i].DOMactive)
_textContainer._textView._DOMElement.removeChild(_runs[i].elem);
@@ -1242,14 +1425,15 @@ var _objectsInRange = function(aList, aRange)
c = runs.length,
orig = CGPointMake(_fragmentRect.origin.x, _fragmentRect.origin.y);
if (_runs.length === 0)
return;
for (var i = 0; i < c; i++)
{
var run = runs[i];
if (!run.elem && CPRectIntersectsRect([_textContainer._textView exposedRect], _fragmentRect))
{
run.elem=[self createDOMElementWithText:run.string andFont:run.font andColor:run.color];
}
run.elem = [self createDOMElementWithText:run.string andFont:run.font andColor:run.color andBackgroundColor:run.bgcolor andUnderline:run.underline];
if (run.DOMactive && !run.DOMpatched)
continue;
@@ -1258,26 +1442,42 @@ var _objectsInRange = function(aList, aRange)
continue;
var loc = run._range.location - _runs[0]._range.location;
// Safety bounds check to protect against uninitialized/empty glyph frames or offsets
if (loc < 0 || loc >= _glyphsFrames.length || !_glyphsFrames[loc] || !_glyphsOffsets || loc >= _glyphsOffsets.length)
continue;
orig.x = _glyphsFrames[loc].origin.x + aPoint.x;
orig.y = _glyphsFrames[loc].origin.y + aPoint.y + _glyphsOffsets[loc];
if(run.elem)
if(run.elem || run.view)
{
run.elem.style.left = (orig.x) + "px";
run.elem.style.top = (orig.y) + "px";
if (run.elem)
{
run.elem.style.left = (orig.x) + "px";
run.elem.style.top = (orig.y) + "px";
}
if (run.view)
[run.view setFrameOrigin:orig];
if (!run.DOMactive)
_textContainer._textView._DOMElement.appendChild(run.elem);
{
if (run.view)
[_textContainer._textView addSubview:run.view];
if (run.elem)
_textContainer._textView._DOMElement.appendChild(run.elem);
}
run.DOMactive = YES;
}
run.DOMpatched = NO;
}
}
- (void)backgroundColorForGlyphAtIndex:(unsigned)index
- (CPColor)backgroundColorForGlyphAtIndex:(unsigned)index
{
var run = _objectWithLocationInRange(_runs, index);
@@ -1305,9 +1505,17 @@ var _objectsInRange = function(aList, aRange)
if (!_RectEqualToRectHorizontally(newLineFragment._fragmentRect, _fragmentRect))
return NO;
if (newFragmentRuns[i].color !== oldFragmentRuns[i].color || newFragmentRuns[i].font !== oldFragmentRuns[i].font)
if (newFragmentRuns[i].color !== oldFragmentRuns[i].color ||
newFragmentRuns[i].bgcolor !== oldFragmentRuns[i].bgcolor ||
newFragmentRuns[i].font !== oldFragmentRuns[i].font ||
newFragmentRuns[i].baselineOffset !== oldFragmentRuns[i].baselineOffset)
return NO;
var oldStyle = oldFragmentRuns[i].paragraphStyle || [CPParagraphStyle defaultParagraphStyle],
newStyle = newFragmentRuns[i].paragraphStyle || [CPParagraphStyle defaultParagraphStyle];
if (![oldStyle isEqual:newStyle])
return NO;
}
return YES;
@@ -1323,9 +1531,14 @@ var _objectsInRange = function(aList, aRange)
{
_runs[i]._range.location += rangeOffset;
if (verticalOffset && _runs[i].elem)
if (verticalOffset)
{
_runs[i].elem.top = (_runs[i].elem.top + verticalOffset) + 'px';
if (_runs[i].view)
_runs[i].view._frame.origin.y += verticalOffset;
if (_runs[i].elem)
_runs[i].elem.top = (_runs[i].elem.top + verticalOffset) + 'px';
_runs[i].DOMpatched = YES;
}
}
+304 -141
View File
@@ -2,10 +2,6 @@
* CPParagraphStyle.j
* AppKit
*
* FIXME
* This is basically a stub.
* We need to store all the spacing informations as well as writing direction (among others)
*
* Created by Daniel Boehringer on 11/01/2014
* Copyright Daniel Boehringer 2014.
*
@@ -26,198 +22,365 @@
@import <Foundation/CPObject.j>
@import <Foundation/CPArray.j>
@import "CPText.j"
CPLeftTabStopType = 0;
@import <Foundation/CPDictionary.j>
CPParagraphStyleAttributeName = @"CPParagraphStyleAttributeName";
var _sharedDefaultParagraphStyle,
_defaultTabStopArray;
// Define missing global tab stop type constants
CPLeftTabStopType = 0;
CPRightTabStopType = 1;
CPCenterTabStopType = 2;
CPDecimalTabStopType = 3;
@implementation CPParagraphStyle : CPObject
// Standard Tab Interval (28pts is roughly 4 spaces in standard fonts)
var kDefaultTabInterval = 28.0;
// MARK: - CPTextTab Implementation
@implementation CPTextTab : CPObject
{
CPArray _tabStops @accessors(property=tabStops);
CPTextAlignment _alignment @accessors(property=alignment);
unsigned _firstLineHeadIndent @accessors(property=firstLineHeadIndent);
unsigned _headIndent @accessors(property=headIndent);
unsigned _tailIndent @accessors(property=tailIndent);
unsigned _paragraphSpacing @accessors(property=paragraphSpacing);
unsigned _minimumLineHeight @accessors(property=minimumLineHeight);
unsigned _maximumLineHeight @accessors(property=maximumLineHeight);
unsigned _lineSpacing @accessors(property=lineSpacing);
CPTextAlignment _alignment @accessors(readonly, property=alignment);
float _location @accessors(readonly, property=location);
CPDictionary _options @accessors(readonly, property=options);
}
#pragma mark -
#pragma mark Class methods
+ (CPParagraphStyle)defaultParagraphStyle
- (id)initWithTextAlignment:(CPTextAlignment)anAlignment location:(float)aLocation options:(CPDictionary)options
{
if (!_sharedDefaultParagraphStyle)
_sharedDefaultParagraphStyle = [self new];
return _sharedDefaultParagraphStyle;
}
+ (CPArray)_defaultTabStops
{
if (!_defaultTabStopArray)
if (self = [super init])
{
var i;
_defaultTabStopArray = [];
// <!> FIXME: Define constants for these magic numbers: 13, 28
for (i = 1; i < 16 ; i++)
{
_defaultTabStopArray.push([[CPTextTab alloc] initWithType:CPLeftTabStopType location:i * 28]);
}
_alignment = anAlignment;
_location = aLocation;
_options = [options copy];
}
return _defaultTabStopArray;
}
#pragma mark -
#pragma mark Init methods
- (id)init
{
[self _initWithDefaults];
return self;
}
- (CPParagraphStyle)initWithParagraphStyle:(CPParagraphStyle)other
// Convenience initializer matching AppKit behavior
- (id)initWithType:(CPTabStopType)aType location:(float)aLocation
{
self = [super init];
_tabStops = [other._tabStops copy];
_alignment = other._alignment;
_firstLineHeadIndent = other._firstLineHeadIndent;
_headIndent = other._headIndent;
_tailIndent = other._tailIndent;
_paragraphSpacing = other._paragraphSpacing;
_minimumLineHeight = other._minimumLineHeight;
_maximumLineHeight = other._maximumLineHeight;
_lineSpacing = other._lineSpacing;
return self;
// Map old TabStopType to TextAlignment for modern compatibility
return [self initWithTextAlignment:aType location:aLocation options:nil];
}
- (void)_initWithDefaults
// Added to resolve the unrecognized selector exception in the RTF producer
- (CPTabStopType)tabStopType
{
_alignment = CPLeftTextAlignment;
_tabStops = [[[self class] _defaultTabStops] copy];
return _alignment;
}
- (void)addTabStop:(CPTextTab)aStop
- (BOOL)isEqual:(id)other
{
_tabStops.push(aStop);
if (self === other) return YES;
if (![other isKindOfClass:[CPTextTab class]]) return NO;
return _location === [other location] &&
_alignment === [other alignment] &&
((_options == nil && [other options] == nil) || [_options isEqualToDictionary:[other options]]);
}
- (id)copy
{
var other = [[self class] alloc];
return [other initWithParagraphStyle:self];
return [[CPTextTab alloc] initWithTextAlignment:_alignment location:_location options:_options];
}
@end
var CPParagraphStyleTabStopsKey = @"CPParagraphStyleTabStopsKey",
CPParagraphStyleAlignmentKey = @"CPParagraphStyleAlignmentKey",
CPParagraphStyleFirstLineHeadIndentKey = @"CPParagraphStyleFirstLineHeadIndentKey",
CPParagraphStyleHeadIndentKey = @"CPParagraphStyleHeadIndentKey",
CPParagraphStyleTailIndentKey = @"CPParagraphStyleTailIndentKey",
CPParagraphStyleParagraphSpacingKey = @"CPParagraphStyleParagraphSpacingKey",
CPParagraphStyleMinimumLineHeightKey = @"CPParagraphStyleMinimumLineHeightKey",
CPParagraphStyleMaximumLineHeightKey = @"CPParagraphStyleMaximumLineHeightKey",
CPParagraphStyleLineSpacingKey = @"CPParagraphStyleLineSpacingKey";
@implementation CPParagraphStyle (CPCoding)
- (id)initWithCoder:(id)aCoder
- (id)initWithCoder:(CPCoder)aCoder
{
self = [self init];
if (self)
if (self = [super init])
{
_tabStops = [aCoder decodeObjectForKey:"CPParagraphStyleTabStopsKey"];
_alignment = [aCoder decodeIntForKey:"CPParagraphStyleAlignmentKey"];
_firstLineHeadIndent = [aCoder decodeIntForKey:"CPParagraphStyleFirstLineHeadIndentKey"];
_headIndent = [aCoder decodeIntForKey:"CPParagraphStyleHeadIndentKey"];
_tailIndent = [aCoder decodeIntForKey:"CPParagraphStyleTailIndentKey"];
_paragraphSpacing = [aCoder decodeIntForKey:"CPParagraphStyleParagraphSpacingKey"];
_minimumLineHeight = [aCoder decodeIntForKey:"CPParagraphStyleMinimumLineHeightKey"];
_maximumLineHeight = [aCoder decodeIntForKey:"CPParagraphStyleMaximumLineHeightKey"];
_lineSpacing = [aCoder decodeIntForKey:"CPParagraphStyleLineSpacingKey"];
_alignment = [aCoder decodeIntForKey:@"CPTextTabAlignment"];
_location = [aCoder decodeFloatForKey:@"CPTextTabLocation"];
_options = [aCoder decodeObjectForKey:@"CPTextTabOptions"];
}
return self;
}
- (void)encodeWithCoder:(id)aCoder
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeInt:_alignment forKey:"CPParagraphStyleAlignmentKey"];
[aCoder encodeObject:_tabStops forKey:"CPParagraphStyleTabStopsKey"];
[aCoder encodeInt:_firstLineHeadIndent forKey:"CPParagraphStyleFirstLineHeadIndentKey"];
[aCoder encodeInt:_headIndent forKey:"CPParagraphStyleHeadIndentKey"];
[aCoder encodeInt:_tailIndent forKey:"CPParagraphStyleTailIndentKey"];
[aCoder encodeInt:_paragraphSpacing forKey:"CPParagraphStyleParagraphSpacingKey"];
[aCoder encodeInt:_minimumLineHeight forKey:"CPParagraphStyleMinimumLineHeightKey"];
[aCoder encodeInt:_maximumLineHeight forKey:"CPParagraphStyleMaximumLineHeightKey"];
[aCoder encodeInt:_lineSpacing forKey:"CPParagraphStyleLineSpacingKey"];
[aCoder encodeInt:_alignment forKey:@"CPTextTabAlignment"];
[aCoder encodeFloat:_location forKey:@"CPTextTabLocation"];
[aCoder encodeObject:_options forKey:@"CPTextTabOptions"];
}
@end
@implementation CPTextTab : CPObject
// MARK: - CPParagraphStyle Implementation
var _sharedDefaultParagraphStyle = nil;
@implementation CPParagraphStyle : CPObject
{
int _type @accessors(property = tabStopType);
double _location @accessors(property = location);
float _lineSpacing @accessors(readonly, property=lineSpacing);
float _paragraphSpacing @accessors(readonly, property=paragraphSpacing);
CPTextAlignment _alignment @accessors(readonly, property=alignment);
float _headIndent @accessors(readonly, property=headIndent);
float _tailIndent @accessors(readonly, property=tailIndent);
float _firstLineHeadIndent @accessors(readonly, property=firstLineHeadIndent);
float _minimumLineHeight @accessors(readonly, property=minimumLineHeight);
float _maximumLineHeight @accessors(readonly, property=maximumLineHeight);
CPLineBreakMode _lineBreakMode @accessors(readonly, property=lineBreakMode);
CPWritingDirection _baseWritingDirection @accessors(readonly, property=baseWritingDirection);
float _lineHeightMultiple @accessors(readonly, property=lineHeightMultiple);
float _paragraphSpacingBefore @accessors(readonly, property=paragraphSpacingBefore);
float _defaultTabInterval @accessors(readonly, property=defaultTabInterval);
CPArray _tabStops @accessors(readonly, property=tabStops);
}
- (id)initWithType:(CPTabStopType) aType location:(double) aLocation
+ (CPParagraphStyle)defaultParagraphStyle
{
if ([self = [super init]])
if (!_sharedDefaultParagraphStyle)
{
_type = aType;
_location = aLocation;
_sharedDefaultParagraphStyle = [[CPParagraphStyle alloc] init];
// Ensure defaults are set on the shared instance internal vars
// Since it's immutable, we rely on the init to set these.
}
return _sharedDefaultParagraphStyle;
}
+ (CPWritingDirection)defaultWritingDirectionForLanguage:(CPString)languageName
{
// Simplified: Cappuccino usually assumes LTR unless specified otherwise.
return CPWritingDirectionLeftToRight;
}
- (id)init
{
if (self = [super init])
{
_lineSpacing = 0.0;
_paragraphSpacing = 0.0;
_alignment = CPLeftTextAlignment;
_headIndent = 0.0;
_tailIndent = 0.0;
_firstLineHeadIndent = 0.0;
_minimumLineHeight = 0.0;
_maximumLineHeight = 0.0;
_lineBreakMode = CPLineBreakByWordWrapping;
_baseWritingDirection = CPWritingDirectionNatural;
_lineHeightMultiple = 0.0;
_paragraphSpacingBefore = 0.0;
_defaultTabInterval = kDefaultTabInterval;
// Generate default tab stops
_tabStops = [];
for (var i = 1; i <= 12; i++)
{
[_tabStops addObject:[[CPTextTab alloc] initWithType:CPLeftTextAlignment
location:i * kDefaultTabInterval]];
}
}
return self;
}
@end
var CPTextTabTypeKey = @"CPTextTabTypeKey",
CPTextTabLocationKey = @"CPTextTabLocationKey";
@implementation CPTextTab (CPCoding)
- (id)initWithCoder:(id)aCoder
- (id)initWithParagraphStyle:(CPParagraphStyle)other
{
self = [self init];
if (self)
if (self = [super init])
{
_type = [aCoder decodeIntForKey:"CPTextTabTypeKey"];
_location = [aCoder decodeDoubleForKey:"CPTextTabLocationKey"];
_lineSpacing = [other lineSpacing];
_paragraphSpacing = [other paragraphSpacing];
_alignment = [other alignment];
_headIndent = [other headIndent];
_tailIndent = [other tailIndent];
_firstLineHeadIndent = [other firstLineHeadIndent];
_minimumLineHeight = [other minimumLineHeight];
_maximumLineHeight = [other maximumLineHeight];
_lineBreakMode = [other lineBreakMode];
_baseWritingDirection = [other baseWritingDirection];
_lineHeightMultiple = [other lineHeightMultiple];
_paragraphSpacingBefore = [other paragraphSpacingBefore];
_defaultTabInterval = [other defaultTabInterval];
_tabStops = [[other tabStops] copy];
}
return self;
}
- (void)encodeWithCoder:(id)aCoder
- (id)copy
{
[aCoder encodeInt:_type forKey:"CPTextTabTypeKey"];
[aCoder encodeDouble:_location forKey:"CPTextTabLocationKey"];
// Since this class is immutable, return self.
// Subclasses (Mutable) will override.
if ([self class] === [CPParagraphStyle class])
return self;
return [[CPParagraphStyle alloc] initWithParagraphStyle:self];
}
- (id)mutableCopy
{
return [[CPMutableParagraphStyle alloc] initWithParagraphStyle:self];
}
// MARK: - Coding Support
- (id)initWithCoder:(CPCoder)aCoder
{
if (self = [super init])
{
_lineSpacing = [aCoder decodeFloatForKey:@"CPParagraphStyleLineSpacing"];
_paragraphSpacing = [aCoder decodeFloatForKey:@"CPParagraphStyleParagraphSpacing"];
_alignment = [aCoder decodeIntForKey:@"CPParagraphStyleAlignment"];
_headIndent = [aCoder decodeFloatForKey:@"CPParagraphStyleHeadIndent"];
_tailIndent = [aCoder decodeFloatForKey:@"CPParagraphStyleTailIndent"];
_firstLineHeadIndent = [aCoder decodeFloatForKey:@"CPParagraphStyleFirstLineHeadIndent"];
_minimumLineHeight = [aCoder decodeFloatForKey:@"CPParagraphStyleMinimumLineHeight"];
_maximumLineHeight = [aCoder decodeFloatForKey:@"CPParagraphStyleMaximumLineHeight"];
_lineBreakMode = [aCoder decodeIntForKey:@"CPParagraphStyleLineBreakMode"];
_baseWritingDirection = [aCoder decodeIntForKey:@"CPParagraphStyleBaseWritingDirection"];
_lineHeightMultiple = [aCoder decodeFloatForKey:@"CPParagraphStyleLineHeightMultiple"];
_paragraphSpacingBefore = [aCoder decodeFloatForKey:@"CPParagraphStyleParagraphSpacingBefore"];
_defaultTabInterval = [aCoder decodeFloatForKey:@"CPParagraphStyleDefaultTabInterval"];
_tabStops = [aCoder decodeObjectForKey:@"CPParagraphStyleTabStops"];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeFloat:_lineSpacing forKey:@"CPParagraphStyleLineSpacing"];
[aCoder encodeFloat:_paragraphSpacing forKey:@"CPParagraphStyleParagraphSpacing"];
[aCoder encodeInt:_alignment forKey:@"CPParagraphStyleAlignment"];
[aCoder encodeFloat:_headIndent forKey:@"CPParagraphStyleHeadIndent"];
[aCoder encodeFloat:_tailIndent forKey:@"CPParagraphStyleTailIndent"];
[aCoder encodeFloat:_firstLineHeadIndent forKey:@"CPParagraphStyleFirstLineHeadIndent"];
[aCoder encodeFloat:_minimumLineHeight forKey:@"CPParagraphStyleMinimumLineHeight"];
[aCoder encodeFloat:_maximumLineHeight forKey:@"CPParagraphStyleMaximumLineHeight"];
[aCoder encodeInt:_lineBreakMode forKey:@"CPParagraphStyleLineBreakMode"];
[aCoder encodeInt:_baseWritingDirection forKey:@"CPParagraphStyleBaseWritingDirection"];
[aCoder encodeFloat:_lineHeightMultiple forKey:@"CPParagraphStyleLineHeightMultiple"];
[aCoder encodeFloat:_paragraphSpacingBefore forKey:@"CPParagraphStyleParagraphSpacingBefore"];
[aCoder encodeFloat:_defaultTabInterval forKey:@"CPParagraphStyleDefaultTabInterval"];
[aCoder encodeObject:_tabStops forKey:@"CPParagraphStyleTabStops"];
}
// MARK: - Equality
- (BOOL)isEqual:(id)other
{
if (self === other) return YES;
if (![other isKindOfClass:[CPParagraphStyle class]]) return NO;
return _lineSpacing === [other lineSpacing] &&
_paragraphSpacing === [other paragraphSpacing] &&
_alignment === [other alignment] &&
_headIndent === [other headIndent] &&
_tailIndent === [other tailIndent] &&
_firstLineHeadIndent === [other firstLineHeadIndent] &&
_lineBreakMode === [other lineBreakMode] &&
[_tabStops isEqualToArray:[other tabStops]];
}
@end
// MARK: - CPMutableParagraphStyle Implementation
@implementation CPMutableParagraphStyle : CPParagraphStyle
{
}
- (id)initWithParagraphStyle:(CPParagraphStyle)other
{
if (self = [super initWithParagraphStyle:other])
{
// Ensure our tab stops array is mutable in the mutable subclass
_tabStops = [[other tabStops] mutableCopy];
}
return self;
}
- (id)initWithCoder:(CPCoder)aCoder
{
if (self = [super initWithCoder:aCoder])
{
_tabStops = [_tabStops mutableCopy];
}
return self;
}
- (void)setLineSpacing:(float)aLineSpacing
{
_lineSpacing = aLineSpacing;
}
- (void)setParagraphSpacing:(float)aParagraphSpacing
{
_paragraphSpacing = aParagraphSpacing;
}
- (void)setAlignment:(CPTextAlignment)anAlignment
{
_alignment = anAlignment;
}
- (void)setHeadIndent:(float)aHeadIndent
{
_headIndent = aHeadIndent;
}
- (void)setTailIndent:(float)aTailIndent
{
_tailIndent = aTailIndent;
}
- (void)setFirstLineHeadIndent:(float)aFirstLineHeadIndent
{
_firstLineHeadIndent = aFirstLineHeadIndent;
}
- (void)setMinimumLineHeight:(float)aMinimumLineHeight
{
_minimumLineHeight = aMinimumLineHeight;
}
- (void)setMaximumLineHeight:(float)aMaximumLineHeight
{
_maximumLineHeight = aMaximumLineHeight;
}
- (void)setLineBreakMode:(CPLineBreakMode)aLineBreakMode
{
_lineBreakMode = aLineBreakMode;
}
- (void)setBaseWritingDirection:(CPWritingDirection)aBaseWritingDirection
{
_baseWritingDirection = aBaseWritingDirection;
}
- (void)setLineHeightMultiple:(float)aLineHeightMultiple
{
_lineHeightMultiple = aLineHeightMultiple;
}
- (void)setParagraphSpacingBefore:(float)aParagraphSpacingBefore
{
_paragraphSpacingBefore = aParagraphSpacingBefore;
}
- (void)setDefaultTabInterval:(float)aDefaultTabInterval
{
_defaultTabInterval = aDefaultTabInterval;
}
- (void)addTabStop:(CPTextTab)aTabStop
{
[_tabStops addObject:aTabStop];
}
- (void)removeTabStop:(CPTextTab)aTabStop
{
[_tabStops removeObject:aTabStop];
}
- (void)setTabStops:(CPArray)newTabStops
{
if (_tabStops === newTabStops) return;
_tabStops = [newTabStops mutableCopy];
}
- (id)copyWithZone:(CPZone)aZone
{
// Return an immutable copy
return [[CPParagraphStyle alloc] initWithParagraphStyle:self];
}
@end
+670
View File
@@ -0,0 +1,670 @@
/*
* CPRulerView.j
* AppKit
*
* Created by Daniel Boehringer on 11/01/2014
* Copyright Daniel Boehringer 2014.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/CPObject.j>
@import "CPView.j"
@import "CPTextField.j"
@import "CPColor.j"
@import "CPFont.j"
@import "CPMenu.j"
@import "CPMenuItem.j"
// Orientations matching AppKit standards
// typedef enum CPRulerOrientation
CPHorizontalRuler = 0,
CPVerticalRuler = 1,
CPRulerOrientationHorizontal = 0,
CPRulerOrientationVertical = 1
@class CPRulerView;
// MARK: - CPRulerMarker (Interactive Handles with Dynamic Alignment Icons)
@implementation CPRulerMarker : CPView
{
CPRulerView _rulerView @accessors(property=rulerView);
float _imageValue @accessors(property=imageValue);
id _representedObject @accessors(property=representedObject);
CPTextField _label;
CPView _customHandleView;
}
- (id)initWithRulerView:(CPRulerView)aRulerView markerLocation:(float)aLocation imageValue:(float)anImageValue representedObject:(id)anObject
{
if (self = [super initWithFrame:CGRectMake(0, 0, 12, 12)])
{
_rulerView = aRulerView;
_imageValue = anImageValue;
_representedObject = anObject;
_label = [[CPTextField alloc] initWithFrame:CGRectMake(0, 0, 12, 12)];
[_label setFont:[CPFont systemFontOfSize:10.0]];
[_label setTextColor:[CPColor colorWithWhite:0.2 alpha:1.0]];
[_label setAlignment:CPCenterTextAlignment];
[self addSubview:_label];
_customHandleView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[self addSubview:_customHandleView];
[self updateMarkerIcon];
}
return self;
}
- (CPTextField)label
{
return _label;
}
- (void)setRepresentedObject:(id)anObject
{
_representedObject = anObject;
[self updateMarkerIcon];
}
- (void)setFrame:(CGRect)aFrame
{
[super setFrame:aFrame];
[self updateMarkerIcon];
}
// Dynamically sets the Unicode triangle direction based on the alignment or indent type,
// or draws custom split-height grab handles for indentation controls.
- (void)updateMarkerIcon
{
var isIndentMarker = (_representedObject === @"CPFirstLineIndent" || _representedObject === @"CPHeadIndent");
if (isIndentMarker)
{
[_label setHidden:YES];
[_customHandleView setHidden:NO];
var frame = [self bounds];
[_customHandleView setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
// Remove old internal rendering to update cleanly
[[_customHandleView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
var isFirstLine = (_representedObject === @"CPFirstLineIndent");
// Dark outline/border representation
[_customHandleView setBackgroundColor:[CPColor colorWithWhite:0.5 alpha:1.0]];
// Inner fill (top handle is lighter, bottom is slightly darker)
var innerView = [[CPView alloc] initWithFrame:CGRectMake(1.0, 1.0, frame.size.width - 2.0, frame.size.height - 2.0)];
if (isFirstLine)
[innerView setBackgroundColor:[CPColor colorWithWhite:0.92 alpha:1.0]];
else
[innerView setBackgroundColor:[CPColor colorWithWhite:0.80 alpha:1.0]];
[_customHandleView addSubview:innerView];
// Horizontal indicator line to visually guide drag interactions
var gripLine = [[CPView alloc] initWithFrame:CGRectMake(Math.floor(frame.size.width / 2.0) - 1.0, 2.0, 1.0, frame.size.height - 4.0)];
[gripLine setBackgroundColor:[CPColor colorWithWhite:0.6 alpha:1.0]];
[innerView addSubview:gripLine];
}
else
{
[_label setHidden:NO];
[_customHandleView setHidden:YES];
[_label setFrame:[self bounds]];
if ([_representedObject isKindOfClass:[CPTextTab class]])
{
var align = [_representedObject alignment];
if (align === CPLeftTextAlignment)
[_label setStringValue:@"▶"]; // Left-aligned points Right
else if (align === CPCenterTextAlignment)
[_label setStringValue:@"▼"]; // Center-aligned points Down
else if (align === CPRightTextAlignment)
[_label setStringValue:@"◀"]; // Right-aligned points Left
}
else if ([_representedObject isKindOfClass:[CPString class]])
{
if (_representedObject === @"CPTailIndent")
[_label setStringValue:@"⥘"]; // Solid downward triangle for tail indent
else
[_label setStringValue:@"⇡"]; // Fallback standard up marker
}
else
{
[_label setStringValue:@"⇡"]; // Fallback standard up marker
}
}
}
// MARK: -
// MARK: Context Menu Support
- (CPMenu)menuForEvent:(CPEvent)anEvent
{
var menu = [[CPMenu alloc] initWithTitle:@"Marker Context Menu"];
// If the marker represents a standard tab stop, allow changing its type
if ([_representedObject isKindOfClass:[CPTextTab class]])
{
var itemLeft = [menu addItemWithTitle:@"Left Tab Stop" action:@selector(changeTypeToLeft:) keyEquivalent:@""],
itemCenter = [menu addItemWithTitle:@"Center Tab Stop" action:@selector(changeTypeToCenter:) keyEquivalent:@""],
itemRight = [menu addItemWithTitle:@"Right Tab Stop" action:@selector(changeTypeToRight:) keyEquivalent:@""];
[itemLeft setTarget:self];
[itemCenter setTarget:self];
[itemRight setTarget:self];
var align = [_representedObject alignment];
if (align === CPLeftTextAlignment) [itemLeft setState:CPOnState];
else if (align === CPCenterTextAlignment) [itemCenter setState:CPOnState];
else if (align === CPRightTextAlignment) [itemRight setState:CPOnState];
[menu addItem:[CPMenuItem separatorItem]];
}
// Determine the context-specific delete title
var deleteTitle = @"Delete Tab Stop";
if ([_representedObject isKindOfClass:[CPString class]])
{
if (_representedObject === @"CPFirstLineIndent")
deleteTitle = @"Delete 1st line indentation marker";
else if (_representedObject === @"CPHeadIndent")
deleteTitle = @"Delete head indentation marker";
else if (_representedObject === @"CPTailIndent")
deleteTitle = @"Delete tail indentation marker";
}
var itemDelete = [menu addItemWithTitle:deleteTitle action:@selector(deleteMarker:) keyEquivalent:@""];
[itemDelete setTarget:self];
return menu;
}
- (void)changeTypeToLeft:(id)sender
{
[self _changeAlignment:CPLeftTextAlignment];
}
- (void)changeTypeToCenter:(id)sender
{
[self _changeAlignment:CPCenterTextAlignment];
}
- (void)changeTypeToRight:(id)sender
{
[self _changeAlignment:CPRightTextAlignment];
}
- (void)_changeAlignment:(CPTextAlignment)alignment
{
if (![_representedObject isKindOfClass:[CPTextTab class]])
return;
var oldTab = _representedObject;
var newTab = [[CPTextTab alloc] initWithType:alignment location:_imageValue];
// Using setRepresentedObject: automatically updates the marker triangle direction
[self setRepresentedObject:newTab];
var client = [_rulerView clientView];
if (client && [client respondsToSelector:@selector(rulerView:didUpdateMarker:oldTab:)])
{
[client rulerView:_rulerView didUpdateMarker:self oldTab:oldTab];
}
}
- (void)deleteMarker:(id)sender
{
var client = [_rulerView clientView];
if (client && [client respondsToSelector:@selector(rulerView:didRemoveMarker:)])
{
[client rulerView:_rulerView didRemoveMarker:self];
}
[_rulerView removeMarker:self];
}
@end
// MARK: - CPRulerView (Pure DOM + Interactive Engine)
@implementation CPRulerView : CPView
{
CPScrollView _scrollView @accessors(property=scrollView);
CPRulerOrientation _orientation @accessors(property=orientation);
CPView _clientView @accessors(property=clientView);
float _ruleThickness @accessors(property=ruleThickness);
float _reservedThicknessForMarkers;
CPArray _markers;
// Dragger variables
CPRulerMarker _draggingMarker;
CGPoint _dragStartPoint;
float _dragStartLocation;
}
- (id)initWithScrollView:(CPScrollView)aScrollView orientation:(CPRulerOrientation)anOrientation
{
if (self = [super initWithFrame:CGRectMakeZero()])
{
_scrollView = aScrollView;
_orientation = anOrientation;
_clientView = [aScrollView documentView];
_ruleThickness = (anOrientation === CPHorizontalRuler) ? 16.0 : 24.0;
_reservedThicknessForMarkers = 0.0;
_markers = [];
[self setBackgroundColor:[CPColor colorWithWhite:0.96 alpha:1.0]];
}
return self;
}
- (void)setFrame:(CGRect)aFrame
{
[super setFrame:aFrame];
[self updateRuler];
}
// Markers registration
- (void)addMarker:(CPRulerMarker)aMarker
{
if ([_markers containsObject:aMarker])
return;
[_markers addObject:aMarker];
[self addSubview:aMarker];
[self _positionMarker:aMarker];
}
- (void)removeMarker:(CPRulerMarker)aMarker
{
[_markers removeObject:aMarker];
[aMarker removeFromSuperview];
}
- (void)setMarkers:(CPArray)newMarkers
{
for (var i = 0; i < [_markers count]; i++)
[[_markers objectAtIndex:i] removeFromSuperview];
_markers = [newMarkers mutableCopy];
for (var i = 0; i < [_markers count]; i++)
{
var marker = [_markers objectAtIndex:i];
[self addSubview:marker];
[self _positionMarker:marker];
}
}
- (CPRulerMarker)_markerAtPoint:(CGPoint)aPoint
{
for (var i = 0; i < [_markers count]; i++)
{
var marker = [_markers objectAtIndex:i];
if (CGRectContainsPoint([marker frame], aPoint))
return marker;
}
return nil;
}
- (void)_positionMarker:(CPRulerMarker)aMarker
{
if (!_scrollView)
return;
var clipView = [_scrollView contentView],
scrollPoint = [clipView bounds].origin,
isHorizontal = (_orientation === CPHorizontalRuler || _orientation === CPRulerOrientationHorizontal),
rulerHeight = CGRectGetHeight([self bounds]),
rulerWidth = CGRectGetWidth([self bounds]),
markerLocation = [aMarker imageValue];
if (isHorizontal)
{
var x = markerLocation - scrollPoint.x - 6.0, // Center the 12px wide marker
y = rulerHeight - 11.0,
w = 12.0,
h = 12.0;
// Align the First Line Indent (upper half) and Head Indent (lower half) controls
if ([aMarker representedObject] === @"CPFirstLineIndent")
{
y = 0.0;
h = Math.floor(rulerHeight / 2.0);
}
else if ([aMarker representedObject] === @"CPHeadIndent")
{
y = Math.floor(rulerHeight / 2.0);
h = rulerHeight - y - 1.0; // Subtract 1px to stay cleanly above bottom border
}
else
{
// Keep normal horizontal markers within the bounds of the ruler to prevent clipping
if (x < 0.0)
x = 0.0;
else if (x + 12.0 > rulerWidth)
x = rulerWidth - 12.0;
}
[aMarker setFrame:CGRectMake(x, y, w, h)];
}
else
{
var x = rulerWidth - 11.0,
y = markerLocation - scrollPoint.y - 6.0;
// Keep vertical marker within the bounds of the ruler to prevent clipping
if (y < 0.0)
y = 0.0;
else if (y + 12.0 > rulerHeight)
y = rulerHeight - 12.0;
[aMarker setFrame:CGRectMake(x, y, 12.0, 12.0)];
}
}
// MARK: -
// MARK: Interaction Handlers
- (void)mouseDown:(CPEvent)anEvent
{
var locationInWindow = [anEvent locationInWindow],
localPoint = [self convertPoint:locationInWindow fromView:nil],
clipView = [_scrollView contentView],
scrollPoint = [clipView bounds].origin,
isHorizontal = (_orientation === CPHorizontalRuler || _orientation === CPRulerOrientationHorizontal);
var rulerLocation = isHorizontal ? (localPoint.x + scrollPoint.x) : (localPoint.y + scrollPoint.y);
// 1. Check if clicked an existing marker
var clickedMarker = [self _markerAtPoint:localPoint];
if (clickedMarker)
{
_draggingMarker = clickedMarker;
_dragStartPoint = localPoint;
_dragStartLocation = [_draggingMarker imageValue];
}
// 2. Otherwise, create a new marker dynamically where the user clicked
else
{
var newMarker = [[CPRulerMarker alloc] initWithRulerView:self
markerLocation:rulerLocation
imageValue:rulerLocation
representedObject:nil];
[self addMarker:newMarker];
// Notify the client view (e.g., CPTextView) that a new marker was added
var client = [self clientView];
if (client && [client respondsToSelector:@selector(rulerView:didAddMarker:)])
[client rulerView:self didAddMarker:newMarker];
_draggingMarker = newMarker;
_dragStartPoint = localPoint;
_dragStartLocation = rulerLocation;
}
}
- (void)mouseDragged:(CPEvent)anEvent
{
if (!_draggingMarker)
return;
var locationInWindow = [anEvent locationInWindow],
localPoint = [self convertPoint:locationInWindow fromView:nil],
isHorizontal = (_orientation === CPHorizontalRuler || _orientation === CPRulerOrientationHorizontal);
var delta = isHorizontal ? (localPoint.x - _dragStartPoint.x) : (localPoint.y - _dragStartPoint.y),
newLocation = _dragStartLocation + delta;
if (newLocation < 0) newLocation = 0;
[_draggingMarker setImageValue:newLocation];
// Smoothly redraw ruler and margin bounds on every drag step
[self updateRuler];
// Check if dragged off the ruler (more than 15px off the boundary)
var draggedOff = isHorizontal ? (localPoint.y < -15 || localPoint.y > CGRectGetHeight([self bounds]) + 15)
: (localPoint.x < -15 || localPoint.x > CGRectGetWidth([self bounds]) + 15);
if (draggedOff)
{
// Visual feedback: Dim the handle to 40% and turn the triangle icon gray
[_draggingMarker setAlphaValue:0.4];
[[_draggingMarker label] setTextColor:[CPColor grayColor]];
}
else
{
// Restore standard styling when dragged back into the active strip
[_draggingMarker setAlphaValue:1.0];
[[_draggingMarker label] setTextColor:[CPColor colorWithWhite:0.2 alpha:1.0]];
}
// Notify the CPTextView that the marker coordinates shifted
var client = [self clientView];
if (client && [client respondsToSelector:@selector(rulerView:didMoveMarker:)])
[client rulerView:self didMoveMarker:_draggingMarker];
}
- (void)mouseUp:(CPEvent)anEvent
{
if (!_draggingMarker)
return;
var localPoint = [self convertPoint:[anEvent locationInWindow] fromView:nil],
isHorizontal = (_orientation === CPHorizontalRuler || _orientation === CPRulerOrientationHorizontal),
// If dragged more than 15 pixels off the ruler, delete the marker
draggedOff = isHorizontal ? (localPoint.y < -15 || localPoint.y > CGRectGetHeight([self bounds]) + 15)
: (localPoint.x < -15 || localPoint.x > CGRectGetWidth([self bounds]) + 15);
if (draggedOff)
{
var client = [self clientView];
if (client && [client respondsToSelector:@selector(rulerView:didRemoveMarker:)])
[client rulerView:self didRemoveMarker:_draggingMarker];
[self removeMarker:_draggingMarker];
}
else
{
// Ensure marker style is fully restored if not deleted
[_draggingMarker setAlphaValue:1.0];
[[_draggingMarker label] setTextColor:[CPColor colorWithWhite:0.2 alpha:1.0]];
}
_draggingMarker = nil;
[self updateRuler];
}
// MARK: -
// MARK: DOM Layout Builder
- (void)updateRuler
{
// Wipe subviews to redraw the dynamic visible tick lines/numbers
[self setSubviews:@[]];
if (!_scrollView)
return;
var clipView = [_scrollView contentView],
scrollBounds = [clipView bounds],
scrollPoint = scrollBounds.origin,
visibleSize = scrollBounds.size,
isHorizontal = (_orientation === CPHorizontalRuler || _orientation === CPRulerOrientationHorizontal);
if (isHorizontal)
{
var start = Math.floor(scrollPoint.x / 10) * 10,
end = scrollPoint.x + visibleSize.width,
rulerHeight = CGRectGetHeight([self bounds]),
rulerWidth = CGRectGetWidth([self bounds]);
// Draw solid horizontal bottom border (pure, razor-sharp CSS DOM view)
var bottomBorder = [[CPView alloc] initWithFrame:CGRectMake(0, rulerHeight - 1, rulerWidth, 1)];
[bottomBorder setBackgroundColor:[CPColor colorWithWhite:0.75 alpha:1.0]];
[self addSubview:bottomBorder];
// Find indent markers to determine background highlight boundaries
var firstLineMarker = nil,
headMarker = nil;
for (var i = 0; i < [_markers count]; i++)
{
var m = [_markers objectAtIndex:i];
if ([m representedObject] === @"CPFirstLineIndent")
firstLineMarker = m;
else if ([m representedObject] === @"CPHeadIndent")
headMarker = m;
}
var halfHeight = Math.floor(rulerHeight / 2.0);
// Draw First Line Indent background - top half (lighter gray)
if (firstLineMarker)
{
var firstLineX = [firstLineMarker imageValue] - scrollPoint.x;
if (firstLineX > 0)
{
var firstLineBg = [[CPView alloc] initWithFrame:CGRectMake(0, 0, firstLineX, halfHeight)];
[firstLineBg setBackgroundColor:[CPColor colorWithWhite:0.93 alpha:1.0]];
[self addSubview:firstLineBg];
}
}
// Draw Head Indent background - bottom half (slightly darker gray)
if (headMarker)
{
var headX = [headMarker imageValue] - scrollPoint.x;
if (headX > 0)
{
var headBg = [[CPView alloc] initWithFrame:CGRectMake(0, halfHeight, headX, rulerHeight - halfHeight - 1.0)];
[headBg setBackgroundColor:[CPColor colorWithWhite:0.86 alpha:1.0]];
[self addSubview:headBg];
}
}
// Render ruler tick lines and labels on top of shaded areas
for (var val = start; val <= end; val += 10)
{
if (val < 0) continue;
var screenX = val - scrollPoint.x,
isMajor = (val % 50 === 0),
tickHeight = isMajor ? 8.0 : 4.0,
tickY = rulerHeight - tickHeight - 1.0;
// Tick mark CSS line view
var tick = [[CPView alloc] initWithFrame:CGRectMake(screenX, tickY, 1.0, tickHeight)];
[tick setBackgroundColor:[CPColor colorWithWhite:0.65 alpha:1.0]];
[self addSubview:tick];
// Unit label
if (isMajor)
{
var labelX = screenX - 20.0,
alignment = CPCenterTextAlignment;
// Adjust label frame and alignment if it lands near left/right bounds
if (labelX < 0.0)
{
labelX = Math.max(0.0, screenX);
alignment = CPLeftTextAlignment;
}
else if (labelX + 40.0 > rulerWidth)
{
labelX = rulerWidth - 40.0;
alignment = CPRightTextAlignment;
}
var label = [[CPTextField alloc] initWithFrame:CGRectMake(labelX, 1.0, 40.0, 12.0)];
[label setStringValue:[CPString stringWithFormat:@"%d", val]];
[label setFont:[CPFont systemFontOfSize:8.0]];
[label setTextColor:[CPColor colorWithWhite:0.4 alpha:1.0]];
[label setAlignment:alignment];
[self addSubview:label];
}
}
}
else
{
// Vertical Ruler
var start = Math.floor(scrollPoint.y / 10) * 10,
end = scrollPoint.y + visibleSize.height,
rulerHeight = CGRectGetHeight([self bounds]),
rulerWidth = CGRectGetWidth([self bounds]);
// Draw solid vertical right border (pure DOM)
var rightBorder = [[CPView alloc] initWithFrame:CGRectMake(rulerWidth - 1, 0, 1, rulerHeight)];
[rightBorder setBackgroundColor:[CPColor colorWithWhite:0.75 alpha:1.0]];
[self addSubview:rightBorder];
for (var val = start; val <= end; val += 10)
{
if (val < 0) continue;
var screenY = val - scrollPoint.y,
isMajor = (val % 50 === 0),
tickWidth = isMajor ? 8.0 : 4.0,
tickX = rulerWidth - tickWidth - 1.0;
// Tick mark CSS line view
var tick = [[CPView alloc] initWithFrame:CGRectMake(tickX, screenY, tickWidth, 1.0)];
[tick setBackgroundColor:[CPColor colorWithWhite:0.65 alpha:1.0]];
[self addSubview:tick];
// Unit label
if (isMajor)
{
var labelY = screenY - 6.0;
// Adjust label frame if it lands near top/bottom bounds
if (labelY < 0.0)
labelY = 0.0;
else if (labelY + 12.0 > rulerHeight)
labelY = rulerHeight - 12.0;
var label = [[CPTextField alloc] initWithFrame:CGRectMake(1.0, labelY, rulerWidth - 12.0, 12.0)];
[label setStringValue:[CPString stringWithFormat:@"%d", val]];
[label setFont:[CPFont systemFontOfSize:8.0]];
[label setTextColor:[CPColor colorWithWhite:0.4 alpha:1.0]];
[label setAlignment:CPRightTextAlignment];
[self addSubview:label];
}
}
}
// Reposition and display active markers
for (var i = 0; i < [_markers count]; i++)
{
var marker = [_markers objectAtIndex:i];
if ([marker superview] !== self)
[self addSubview:marker];
[self _positionMarker:marker];
}
}
@end
+69 -15
View File
@@ -84,11 +84,13 @@ CPLineMovesUp = 4;
CPLayoutManager _layoutManager @accessors(property=layoutManager);
CPTextView _textView @accessors(property=textView);
BOOL _inResizing;
BOOL _widthTracksTextView;
BOOL _heightTracksTextView;
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
- (id)initWithContainerSize:(CGSize)aSize
{
@@ -116,8 +118,8 @@ CPLineMovesUp = 4;
[_layoutManager addTextContainer:self];
}
#pragma mark -
#pragma mark Setter methods
// MARK: -
// MARK: Setter methods
- (void)setContainerSize:(CGSize)someSize
{
@@ -139,28 +141,65 @@ CPLineMovesUp = 4;
}
// Controls whether the receiver adjusts the width of its bounding rectangle when its text view is resized.
- (BOOL)widthTracksTextView
{
return _widthTracksTextView;
}
- (void)setWidthTracksTextView:(BOOL)flag
{
[_textView setPostsFrameChangedNotifications:flag];
if (_widthTracksTextView === flag)
return;
if (flag)
{
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(textViewFrameChanged:)
name:CPViewFrameDidChangeNotification
object:_textView];
}
else
_widthTracksTextView = flag;
[self _updateFrameObserver];
}
// Controls whether the receiver adjusts the height of its bounding rectangle when its text view is resized.
- (BOOL)heightTracksTextView
{
return _heightTracksTextView;
}
- (void)setHeightTracksTextView:(BOOL)flag
{
if (_heightTracksTextView === flag)
return;
_heightTracksTextView = flag;
[self _updateFrameObserver];
}
- (void)_updateFrameObserver
{
if (_textView)
{
[[CPNotificationCenter defaultCenter] removeObserver:self
name:CPViewFrameDidChangeNotification
object:_textView];
var flag = _widthTracksTextView || _heightTracksTextView;
[_textView setPostsFrameChangedNotifications:flag];
if (flag)
{
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(textViewFrameChanged:)
name:CPViewFrameDidChangeNotification
object:_textView];
}
}
}
- (void)textViewFrameChanged:(CPNotification)aNotification
{
var newSize = CGSizeMake([_textView frame].size.width, _size.height);
var newSize = CGSizeMake(_size.width, _size.height);
if (_widthTracksTextView)
newSize.width = [_textView frame].size.width;
if (_heightTracksTextView)
newSize.height = [_textView frame].size.height;
[self setContainerSize:newSize];
}
@@ -168,12 +207,20 @@ CPLineMovesUp = 4;
- (void)setTextView:(CPTextView)aTextView
{
if (_textView)
{
[[CPNotificationCenter defaultCenter] removeObserver:self
name:CPViewFrameDidChangeNotification
object:_textView];
[_textView setTextContainer:nil];
}
_textView = aTextView;
if (_textView)
{
[self _updateFrameObserver];
[_textView setTextContainer:self];
}
[_layoutManager textContainerChangedTextView:self];
}
@@ -222,7 +269,9 @@ CPLineMovesUp = 4;
var CPTextContainerSizeKey = @"CPTextContainerSizeKey",
CPTextContainerLayoutManagerKey = @"CPTextContainerLayoutManagerKey";
CPTextContainerLayoutManagerKey = @"CPTextContainerLayoutManagerKey",
CPTextContainerWidthTracksTextViewKey = @"CPTextContainerWidthTracksTextViewKey",
CPTextContainerHeightTracksTextViewKey = @"CPTextContainerHeightTracksTextViewKey";
@implementation CPTextContainer (CPCoding)
@@ -238,6 +287,9 @@ var CPTextContainerSizeKey = @"CPTextContainerSizeKey",
_layoutManager = [aCoder decodeObjectForKey:CPTextContainerLayoutManagerKey];
[_layoutManager addTextContainer:self];
_widthTracksTextView = [aCoder decodeBoolForKey:CPTextContainerWidthTracksTextViewKey];
_heightTracksTextView = [aCoder decodeBoolForKey:CPTextContainerHeightTracksTextViewKey];
}
return self;
@@ -247,6 +299,8 @@ var CPTextContainerSizeKey = @"CPTextContainerSizeKey",
{
[aCoder encodeSize:_size forKey:CPTextContainerSizeKey];
[aCoder encodeObject:_layoutManager forKey:CPTextContainerLayoutManagerKey];
[aCoder encodeBool:_widthTracksTextView forKey:CPTextContainerWidthTracksTextViewKey];
[aCoder encodeBool:_heightTracksTextView forKey:CPTextContainerHeightTracksTextViewKey];
}
@end
+30 -32
View File
@@ -42,6 +42,11 @@ CPTextStorageDidProcessEditingNotification = @"CPTextStorageDidProcessEditingNot
@end
CPAttachmentCharacter = 65532; // "\ufffc";
_CPAttachmentCharacterAsString = String.fromCharCode(CPAttachmentCharacter);
_CPAttachmentView = "_CPAttachmentView";
_CPAttachmentInvisible = "_CPAttachmentInvisible";
var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
CPTextStorageDelegate_textStorageDidProcessEditing_ = 1 << 2;
@@ -65,8 +70,8 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
}
#pragma mark -
#pragma mark Init methods
// MARK: -
// MARK: Init methods
- (id)initWithString:(CPString)aString attributes:(CPDictionary)attributes
{
@@ -94,8 +99,8 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
}
#pragma mark -
#pragma mark Delegate methods
// MARK: -
// MARK: Delegate methods
- (void)setDelegate:(id <CPTextStorageDelegate>)aDelegate
{
@@ -116,13 +121,13 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
}
#pragma mark -
#pragma mark Layout manager methods
// MARK: -
// MARK: Layout manager methods
- (void)addLayoutManager:(CPLayoutManager)aManager
{
if ([_layoutManagers containsObject:aManager])
return
return;
[aManager setTextStorage:self];
[_layoutManagers addObject:aManager];
@@ -131,7 +136,7 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
- (void)removeLayoutManager:(CPLayoutManager)aManager
{
if (![_layoutManagers containsObject:aManager])
return
return;
[aManager setTextStorage:nil];
[_layoutManagers removeObject:aManager];
@@ -143,8 +148,8 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
}
#pragma mark -
#pragma mark Editing methods
// MARK: -
// MARK: Editing methods
- (void)processEditing
{
@@ -257,6 +262,21 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
return [super attributedSubstringFromRange:aRange];
}
/*!
Returns an instance of CPTextStorage that contains the provided instance of CPView.
This can be used to insert arbitrary views into the text. These views are treated as individual characters during editing.
This works only with views that conform to the CPCoding protocol
*/
+ (id)attributedStringWithAttachment:(CPView)someView
{
var result = [[self alloc] initWithString:_CPAttachmentCharacterAsString];
[result setAttributes:@{_CPAttachmentView:someView} range:CPMakeRange(0, 1)];
return result;
}
@end
@@ -279,25 +299,3 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
}
@end
@implementation CPTextStorage (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
}
@end
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More