1////////////////////////////////////////////////////////////////////////////////
2//
3// ADOBE SYSTEMS INCORPORATED
4// Copyright 2007-2010 Adobe Systems Incorporated
5// All Rights Reserved.
6//
7// NOTICE:  Adobe permits you to use, modify, and distribute this file
8// in accordance with the terms of the license agreement accompanying it.
9//
10////////////////////////////////////////////////////////////////////////////////
11package flashx.textLayout.elements
12{
13	import flash.display.BlendMode;
14	import flash.display.Sprite;
15	import flash.system.Capabilities;
16
17	import flashx.textLayout.compose.StandardFlowComposer;
18	import flashx.textLayout.edit.SelectionFormat;
19	import flashx.textLayout.formats.FormatValue;
20	import flashx.textLayout.formats.IListMarkerFormat;
21	import flashx.textLayout.formats.ITextLayoutFormat;
22	import flashx.textLayout.formats.ListMarkerFormat;
23	import flashx.textLayout.formats.TextDecoration;
24	import flashx.textLayout.formats.TextLayoutFormat;
25	import flashx.textLayout.tlf_internal;
26
27	use namespace tlf_internal;
28
29	/**
30	* The Configuration class is a primary point of integration between the Text Layout Framework and an application. You can
31	* include a Configuration object as a parameter to the <code>TextFlow()</code> constructor when you create a new TextFlow
32	* instance. It allows the application to initially control how the Text Layout Framework behaves.
33	*
34	* <p>The Configuration class allows you to specify initial, paragraph and container formats for the text flow
35	* through the <code>textFlowInitialFormat</code> property. It also allows you to specify initial format attributes for links, selection,
36	* scrolling, and for handling the Tab and Enter keys.</p>
37	*
38	* @includeExample examples\ConfigurationExample.as -noswf
39	*
40	* @playerversion Flash 10
41	* @playerversion AIR 1.5
42	* @langversion 3.0
43	*
44	* @see flashx.textLayout.formats.ITextLayoutFormat ITextLayoutFormat
45	* @see flashx.textLayout.edit.SelectionFormat SelectionFormat
46	* @see TextFlow
47	*/
48
49	public class Configuration implements IConfiguration
50	{
51		/** @private */
52		static tlf_internal function versionIsAtLeast(major:int,minor:int):Boolean
53		{
54			var versionData:Array = Capabilities.version.split(" ")[1].split(",");
55			return int(versionData[0]) > major || (int(versionData[0]) == major && int(versionData[1]) >= minor);
56		}
57
58		/** @private The player may disable the feature for older swfs.  */
59		static tlf_internal const playerEnablesArgoFeatures:Boolean = versionIsAtLeast(10,1);
60
61		/** @private The player may disable the feature for older swfs, so its not enough to check
62		the Player version number, the SWF must also be marked as a version 11 SWF to use Spicy features.  */
63		static tlf_internal const playerEnablesSpicyFeatures:Boolean = versionIsAtLeast(10,2) && (new Sprite).hasOwnProperty("needsSoftKeyboard");
64		static tlf_internal const hasTouchScreen:Boolean = playerEnablesArgoFeatures && Capabilities["touchScreenType"] != "none";
65
66		/** If manageTabKey and manageEnterKey are false, the client must handle those keys on their own. */
67		private var _manageTabKey:Boolean;
68		private var _manageEnterKey:Boolean;
69
70		private var _overflowPolicy:String;
71
72		private var _enableAccessibility:Boolean;
73		private var _releaseLineCreationData:Boolean;
74
75		private var _defaultLinkNormalFormat:ITextLayoutFormat;
76		private var _defaultLinkActiveFormat:ITextLayoutFormat;
77		private var _defaultLinkHoverFormat:ITextLayoutFormat;
78
79		private var _defaultListMarkerFormat:IListMarkerFormat;
80
81		private var _textFlowInitialFormat:ITextLayoutFormat;
82
83		private var _focusedSelectionFormat:SelectionFormat;
84		private var _unfocusedSelectionFormat:SelectionFormat;
85		private var _inactiveSelectionFormat:SelectionFormat;
86
87		// scrolling vars
88		private var _scrollDragDelay:Number;
89		private var _scrollDragPixels:Number;
90		private var _scrollPagePercentage:Number;
91		private var _scrollMouseWheelMultiplier:Number;
92
93		private var _flowComposerClass:Class;
94		private var _inlineGraphicResolverFunction:Function;
95
96		/** Constructor - creates a default configuration.
97		*
98		* @param initializeWithDefaults Specifies whether to initialize the configuration with
99		* the default values. Default is <code>true</code>. If set to <code>false</code>, initializes
100		* without default values, thereby saving some objects. The <code>clone()</code> method sets this
101		* to <code>false</code> and copies the properties from the original object.
102		*
103		* @playerversion Flash 10
104		* @playerversion AIR 1.5
105	 	* @langversion 3.0
106	 	*
107		* @see flashx.textLayout.edit.SelectionFormat SelectionFormat
108		* @see flashx.textLayout.compose.StandardFlowComposer StandardFlowComposer
109		*/
110		public function Configuration(initializeWithDefaults:Boolean = true)
111		{
112			if (initializeWithDefaults)
113				initialize()
114		}
115
116		private function initialize():void
117		{
118			var scratchFormat:TextLayoutFormat;
119
120			_manageTabKey = false;
121			_manageEnterKey = true;
122			_overflowPolicy = OverflowPolicy.FIT_DESCENDERS;
123			_enableAccessibility = false;
124			_releaseLineCreationData = false;
125
126			_focusedSelectionFormat = new SelectionFormat(0xffffff, 1.0, BlendMode.DIFFERENCE);
127			_unfocusedSelectionFormat = new SelectionFormat(0xffffff, 0, BlendMode.DIFFERENCE, 0xffffff, 0.0, BlendMode.DIFFERENCE, 0);
128			_inactiveSelectionFormat  = _unfocusedSelectionFormat;
129
130			scratchFormat = new TextLayoutFormat();
131			scratchFormat.textDecoration = TextDecoration.UNDERLINE;
132			scratchFormat.color = 0x0000FF;//default link color is blue
133			_defaultLinkNormalFormat = scratchFormat;
134
135			var listMarkerFormat:ListMarkerFormat = new ListMarkerFormat();
136			listMarkerFormat.paragraphEndIndent = 4;
137			_defaultListMarkerFormat = listMarkerFormat;
138
139			scratchFormat = new TextLayoutFormat();
140			scratchFormat.lineBreak = FormatValue.INHERIT;
141			scratchFormat.paddingLeft = FormatValue.INHERIT;
142			scratchFormat.paddingRight = FormatValue.INHERIT;
143			scratchFormat.paddingTop = FormatValue.INHERIT;
144			scratchFormat.paddingBottom = FormatValue.INHERIT;
145			scratchFormat.verticalAlign = FormatValue.INHERIT;
146			scratchFormat.columnCount = FormatValue.INHERIT;
147			scratchFormat.columnCount = FormatValue.INHERIT;
148			scratchFormat.columnGap = FormatValue.INHERIT;
149			scratchFormat.columnWidth = FormatValue.INHERIT;
150			_textFlowInitialFormat = scratchFormat;
151
152			_scrollDragDelay = 35;
153			_scrollDragPixels = 20;
154			_scrollPagePercentage = 7.0/8.0;
155			_scrollMouseWheelMultiplier = 20;
156
157			_flowComposerClass = StandardFlowComposer;
158		}
159
160		private var _immutableClone:IConfiguration;
161
162		/** TextFlows are configured with an immutable clone of a Configuration.  Once a TextFlow is create it uses an immutable configuration. @private */
163		tlf_internal function getImmutableClone():IConfiguration
164		{
165			if (!_immutableClone)
166			{
167				var clonedConifg:Configuration = clone();
168				_immutableClone = clonedConifg;
169				// an immutable clone is its own immutable clone
170				clonedConifg._immutableClone = clonedConifg;
171			}
172			return _immutableClone;
173		}
174
175		/** Creates a clone of the Configuration object.
176		*
177		* @playerversion Flash 10
178		* @playerversion AIR 1.5
179	 	* @langversion 3.0
180	 	*/
181		public function clone():Configuration
182		{
183			var config:Configuration = new Configuration(false);
184			// must copy all values
185			config.defaultLinkActiveFormat = defaultLinkActiveFormat;
186			config.defaultLinkHoverFormat  = defaultLinkHoverFormat;
187			config.defaultLinkNormalFormat = defaultLinkNormalFormat;
188			config.defaultListMarkerFormat = defaultListMarkerFormat;
189			config.textFlowInitialFormat = _textFlowInitialFormat;
190			config.focusedSelectionFormat = _focusedSelectionFormat;
191			config.unfocusedSelectionFormat = _unfocusedSelectionFormat;
192			config.inactiveSelectionFormat = _inactiveSelectionFormat;
193
194			config.manageTabKey = _manageTabKey;
195			config.manageEnterKey = _manageEnterKey;
196			config.overflowPolicy = _overflowPolicy;
197			config.enableAccessibility = _enableAccessibility;
198			config.releaseLineCreationData = _releaseLineCreationData;
199
200			config.scrollDragDelay = _scrollDragDelay;
201			config.scrollDragPixels = _scrollDragPixels;
202			config.scrollPagePercentage = _scrollPagePercentage;
203			config.scrollMouseWheelMultiplier = _scrollMouseWheelMultiplier;
204
205			config.flowComposerClass = _flowComposerClass;
206			config._inlineGraphicResolverFunction = _inlineGraphicResolverFunction;
207			return config;
208		}
209
210		/** @copy IConfiguration#manageTabKey
211		*
212		* @playerversion Flash 10
213		* @playerversion AIR 1.5
214	 	* @langversion 3.0
215		*/
216
217		public function get manageTabKey():Boolean
218		{ return _manageTabKey; }
219		public function set manageTabKey(val:Boolean):void
220		{ _manageTabKey = val; _immutableClone = null; }
221
222		/**
223		* @copy IConfiguration#manageEnterKey
224		*
225		* @playerversion Flash 10
226		* @playerversion AIR 1.5
227	 	* @langversion 3.0
228		*/
229
230		public function get manageEnterKey():Boolean
231		{ return _manageEnterKey; }
232		public function set manageEnterKey(val:Boolean):void
233		{ _manageEnterKey = val; _immutableClone = null; }
234
235
236
237		/**
238		* @copy IConfiguration#overflowPolicy
239		*
240		* @playerversion Flash 10
241		* @playerversion AIR 1.5
242	 	* @langversion 3.0
243	 	*
244		* @see OverflowPolicy
245		*/
246
247		public function get overflowPolicy():String
248		{ 	return _overflowPolicy; }
249		public function set overflowPolicy(value:String):void
250		{ 	_overflowPolicy = value; }
251
252		/**
253		* @copy IConfiguration#defaultLinkNormalFormat
254		*
255		* @playerversion Flash 10
256		* @playerversion AIR 1.5
257	 	* @langversion 3.0
258	 	*
259		* @see FlowElement#linkNormalFormat
260		* @see flashx.textLayout.formats.ITextLayoutFormat ITextLayoutFormat
261		* @see LinkElement
262		*/
263
264		public function get defaultLinkNormalFormat():ITextLayoutFormat
265		{ return _defaultLinkNormalFormat; }
266		public function set defaultLinkNormalFormat(val:ITextLayoutFormat):void
267		{ _defaultLinkNormalFormat = val; _immutableClone = null; }
268
269		/**
270		 * @copy IConfiguration#defaultListMarkerFormat
271		 *
272		 * @playerversion Flash 10
273		 * @playerversion AIR 1.5
274		 * @langversion 3.0
275		 *
276		 * @see FlowElement#listMarkerFormat
277		 * @see flashx.textLayout.formats.IListMarkerFormat IListMarkerFormat
278		 * @see LinkElement
279		 */
280
281		public function get defaultListMarkerFormat():IListMarkerFormat
282		{ return _defaultListMarkerFormat; }
283		public function set defaultListMarkerFormat(val:IListMarkerFormat):void
284		{ _defaultListMarkerFormat = val; _immutableClone = null; }
285
286		/**
287		* @copy IConfiguration#defaultLinkHoverFormat
288		*
289		* @playerversion Flash 10
290		* @playerversion AIR 1.5
291	 	* @langversion 3.0
292	 	*
293		* @see  FlowElement#linkHoverFormat
294		* @see flashx.textLayout.formats.ITextLayoutFormat ITextLayoutFormat
295		* @see LinkElement
296		*/
297
298		public function get defaultLinkHoverFormat():ITextLayoutFormat
299		{ return _defaultLinkHoverFormat; }
300		public function set defaultLinkHoverFormat(val:ITextLayoutFormat):void
301		{ _defaultLinkHoverFormat = val; _immutableClone = null; }
302
303		/**
304		* @copy IConfiguration#defaultLinkActiveFormat
305		*
306		* @playerversion Flash 10
307		* @playerversion AIR 1.5
308	 	* @langversion 3.0
309	 	*
310		* @see FlowElement#linkActiveFormat
311		* @see flashx.textLayout.formats.ITextLayoutFormat ITextLayoutFormat
312		* @see LinkElement
313		*/
314
315		public function get defaultLinkActiveFormat():ITextLayoutFormat
316		{ return _defaultLinkActiveFormat; }
317		public function set defaultLinkActiveFormat(val:ITextLayoutFormat):void
318		{ _defaultLinkActiveFormat = val; _immutableClone = null; }
319
320		/**
321		* @copy IConfiguration#textFlowInitialFormat
322		*
323		* @playerversion Flash 10
324		* @playerversion AIR 1.5
325	 	* @langversion 3.0
326	 	*
327		* @see TextFlow
328		* @see flashx.textLayout.formats.ITextLayoutFormat ITextLayoutFormat
329		*/
330
331		public function get textFlowInitialFormat():ITextLayoutFormat
332		{ return _textFlowInitialFormat; }
333		public function set textFlowInitialFormat(val:ITextLayoutFormat):void
334		{ _textFlowInitialFormat = val; _immutableClone = null; }
335
336
337
338		/**
339		* @copy IConfiguration#focusedSelectionFormat
340		*
341		* @playerversion Flash 10
342		* @playerversion AIR 1.5
343	 	* @langversion 3.0
344	 	*
345	 	* @see flashx.textLayout.edit.SelectionFormat SelectionFormat
346		* @see flashx.textLayout.edit.SelectionManager#focusedSelectionFormat SelectionManager.focusedSelectionFormat
347		* @see TextFlow
348		*/
349
350		public function get focusedSelectionFormat():SelectionFormat
351		{ return _focusedSelectionFormat; }
352		public function set focusedSelectionFormat(val:SelectionFormat):void
353		{	if (val != null)
354			{
355				_focusedSelectionFormat = val;
356				_immutableClone = null;
357			}
358		}
359
360		/**
361		* @copy IConfiguration#unfocusedSelectionFormat
362		*
363		* @playerversion Flash 10
364		* @playerversion AIR 1.5
365	 	* @langversion 3.0
366	 	*
367	 	* @see flashx.textLayout.edit.SelectionFormat SelectionFormat
368		* @see flashx.textLayout.edit.SelectionManager#unfocusedSelectionFormat SelectionManager.unfocusedSelectionFormat
369		* @see TextFlow
370		*/
371
372		public function get unfocusedSelectionFormat():SelectionFormat
373		{ return _unfocusedSelectionFormat; }
374		public function set unfocusedSelectionFormat(val:SelectionFormat):void
375		{	if (val != null)
376			{
377				_unfocusedSelectionFormat = val;
378				_immutableClone = null;
379			}
380		}
381
382		/**
383		* @copy IConfiguration#inactiveSelectionFormat
384		*
385		* @playerversion Flash 10
386		* @playerversion AIR 1.5
387	 	* @langversion 3.0
388	 	*
389	 	* @see flashx.textLayout.edit.SelectionFormat SelectionFormat
390		* @see flashx.textLayout.edit.SelectionManager#inactiveSelectionFormat SelectionManager.inactiveSelectionFormat
391		* @see TextFlow
392		*/
393
394		public function get inactiveSelectionFormat():SelectionFormat
395		{ return _inactiveSelectionFormat; }
396		public function set inactiveSelectionFormat(val:SelectionFormat):void
397		{
398			if (val != null)
399			{
400				_inactiveSelectionFormat = val;
401				_immutableClone = null;
402			}
403		}
404
405		/**
406		* @copy IConfiguration#scrollDragDelay
407		*
408		* @playerversion Flash 10
409		* @playerversion AIR 1.5
410	 	* @langversion 3.0
411		*/
412
413		public function get scrollDragDelay():Number
414		{ return _scrollDragDelay; }
415		public function set scrollDragDelay(val:Number):void
416		{
417			if (val > 0) {
418				_scrollDragDelay = val;
419				_immutableClone = null;
420			}
421		}
422
423		/**
424		* @copy IConfiguration#scrollDragPixels
425		*
426		* @playerversion Flash 10
427		* @playerversion AIR 1.5
428	 	* @langversion 3.0
429		*/
430
431		public function get scrollDragPixels():Number
432		{ return _scrollDragPixels; }
433		public function set scrollDragPixels(val:Number):void
434		{
435			if (val > 0) {
436				_scrollDragPixels = val;
437				_immutableClone = null;
438			}
439		}
440
441		/**
442		* @copy IConfiguration#scrollPagePercentage
443		*
444		* @playerversion Flash 10
445		* @playerversion AIR 1.5
446	 	* @langversion 3.0
447		*/
448
449		public function get scrollPagePercentage(): Number
450		{ return _scrollPagePercentage; }
451		public function set scrollPagePercentage(val:Number):void
452		{
453			if (val > 0) {
454				_scrollPagePercentage = val;
455				_immutableClone = null;
456			}
457		}
458
459		/**
460		* @copy IConfiguration#scrollMouseWheelMultiplier
461		*
462		* @playerversion Flash 10
463		* @playerversion AIR 1.5
464	 	* @langversion 3.0
465		*/
466
467		public function get scrollMouseWheelMultiplier(): Number
468		{ return _scrollMouseWheelMultiplier; }
469		public function set scrollMouseWheelMultiplier(val:Number):void
470		{
471			if (val > 0) {
472				_scrollMouseWheelMultiplier = val;
473				_immutableClone = null;
474			}
475		}
476
477		/**
478		* @copy IConfiguration#flowComposerClass
479		*
480		* @playerversion Flash 10
481		* @playerversion AIR 1.5
482	 	* @langversion 3.0
483	 	*
484	 	* @see flashx.textLayout.compose.StandardFlowComposer StandardFlowComposer
485		* @see flashx.textLayout.elements.TextFlow TextFlow
486		*/
487
488		public function get flowComposerClass(): Class
489		{ return _flowComposerClass; }
490		public function set flowComposerClass(val:Class):void
491		{
492			_flowComposerClass = val;
493			_immutableClone = null;
494		}
495
496		/**
497		* @copy IConfiguration#enableAccessibility
498		*
499		* @playerversion Flash 10
500		* @playerversion AIR 1.5
501	 	* @langversion 3.0
502	 	*
503	 	* @see TextFlow
504		*/
505
506		public function get enableAccessibility():Boolean
507		{ return _enableAccessibility; }
508		public function set enableAccessibility(val:Boolean):void
509		{
510			_enableAccessibility = val;
511			_immutableClone = null;
512		}
513
514		/**
515		* @copy IConfiguration#releaseLineCreationData
516		*
517		* @playerversion Flash 10
518		* @playerversion AIR 1.5
519		* @langversion 3.0
520		*
521		* @see flashx.textLayout.compose.StandardFlowComposer StandardFlowComposer
522		* @see flash.text.engine.TextBlock#releaseLineCreationData() TextBlock.releaseLineCreationData()
523		*/
524
525		public function get releaseLineCreationData():Boolean
526		{ return _releaseLineCreationData; }
527		public function set releaseLineCreationData(val:Boolean):void
528		{
529			_releaseLineCreationData = val;
530			_immutableClone = null;
531		}
532
533		/** Returns true if the ActionScript text engine was built with debugging code enabled. @private */
534		static tlf_internal function get debugCodeEnabled():Boolean
535		{
536			CONFIG::debug   { return true; }
537			CONFIG::release { return false; }
538		}
539
540		/**
541		* @copy IConfiguration#inlineGraphicResolverFunction
542		*
543		* @playerversion Flash 10
544		* @playerversion AIR 1.5
545		* @langversion 3.0
546		*
547		* @see flashx.textLayout.elements.InlineGraphicElement InlineGraphicElement
548		*/
549		public function get inlineGraphicResolverFunction():Function
550		{
551			return _inlineGraphicResolverFunction;
552		}
553		public function set inlineGraphicResolverFunction(val:Function):void
554		{
555			_inlineGraphicResolverFunction = val;
556			_immutableClone = null;
557		}
558	}
559}
560