|
1 /* |
|
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef TCUSTOMWRAP_H_ |
|
20 |
|
21 #include <frmtlay.h> |
|
22 #include <linebreak.h> |
|
23 |
|
24 // ------------ TTestCustomWrap --------- |
|
25 |
|
26 /** |
|
27 * A custom wrapping class that allows line breaks anywhere, but allows (Latin) |
|
28 * commas, full-stops and closing brackets to "wrap-up" to the previous line. |
|
29 */ |
|
30 class TTestCustomWrap : public MFormCustomWrap |
|
31 { |
|
32 // All characters are given the same class. It does not matter which it is |
|
33 // as long as it is not ESpLineBreakClass. Spaces must not be treated |
|
34 // differently from other characters. |
|
35 TUint LineBreakClass(TUint /*aCode*/,TUint& aRangeStart,TUint& aRangeEnd) const |
|
36 { |
|
37 // All characters have the same class.. |
|
38 aRangeStart = 0; |
|
39 aRangeEnd = 0x110000; |
|
40 // ..this class is Ideographic |
|
41 return MTmCustom::EIdLineBreakClass; |
|
42 } |
|
43 TBool LineBreakPossible(TUint /*aPrevClass*/, |
|
44 TUint /*aNextClass*/, TBool /*aHaveSpaces*/) const |
|
45 { |
|
46 // Line breaking allowed between any class of characters. |
|
47 // In practice they will all be EIdLineBreakClass, because we have |
|
48 // fixed it so that they will be. |
|
49 return ETrue; |
|
50 } |
|
51 TBool IsHangingCharacter(TUint aChar) const |
|
52 { |
|
53 // Allow commas, full stops and closing brackets to hang over the |
|
54 // margins. In practice, ideographic commas, full-stops and brackets |
|
55 // should be allowed as well as many other types of closing punctuation. |
|
56 if (aChar == ',' || aChar == '.' || aChar == ')') |
|
57 return ETrue; |
|
58 return EFalse; |
|
59 } |
|
60 }; |
|
61 |
|
62 /** |
|
63 * A custom wrapping class that allows line breaks between alphabetic and |
|
64 * break after classes |
|
65 */ |
|
66 class TTestCustomWrap2 : public MFormCustomWrap |
|
67 { |
|
68 |
|
69 TBool LineBreakPossible(TUint aPrevClass, |
|
70 TUint aNextClass, TBool aHaveSpaces) const |
|
71 { |
|
72 TBool breakAllowed; |
|
73 breakAllowed = MFormCustomWrap::LineBreakPossible(aPrevClass,aNextClass,aHaveSpaces); |
|
74 |
|
75 if(!breakAllowed) |
|
76 { |
|
77 //Specifically allow breaking between alphabetic and break after |
|
78 //classes (e.g. Tab character) |
|
79 breakAllowed = ((aPrevClass == MLineBreaker::EAlLineBreakClass) |
|
80 && (aNextClass == MLineBreaker::EBaLineBreakClass)); |
|
81 } |
|
82 |
|
83 return breakAllowed; |
|
84 } |
|
85 |
|
86 }; |
|
87 |
|
88 /** |
|
89 * A custom wrapping class that allows line breaks between alphabetic and |
|
90 * break after classes, but allows (Latin) commas, full-stops, |
|
91 * closing brackets and tabs to "wrap-up" to the previous line. |
|
92 */ |
|
93 class TTestCustomWrap3 : public MFormCustomWrap |
|
94 { |
|
95 |
|
96 TBool LineBreakPossible(TUint aPrevClass, |
|
97 TUint aNextClass, TBool aHaveSpaces) const |
|
98 { |
|
99 |
|
100 TBool breakAllowed; |
|
101 breakAllowed = MFormCustomWrap::LineBreakPossible(aPrevClass,aNextClass,aHaveSpaces); |
|
102 |
|
103 if(!breakAllowed) |
|
104 { |
|
105 //Specifically allow breaking between alphabetic and break after |
|
106 //classes (e.g. Tab character) |
|
107 breakAllowed = ((aPrevClass == MLineBreaker::EAlLineBreakClass) |
|
108 && (aNextClass == MLineBreaker::EBaLineBreakClass)); |
|
109 } |
|
110 |
|
111 return breakAllowed; |
|
112 } |
|
113 |
|
114 TBool IsHangingCharacter(TUint aChar) const |
|
115 { |
|
116 // Allow commas, full stops, closing brackets and tabs to hang over the |
|
117 // margins. In practice, ideographic commas, full-stops and brackets |
|
118 // should be allowed as well as many other types of closing punctuation. |
|
119 if (aChar == ',' || aChar == '.' || aChar == ')' || aChar == '\t') |
|
120 return ETrue; |
|
121 return EFalse; |
|
122 } |
|
123 }; |
|
124 |
|
125 /** |
|
126 * A custom wrapping class that sets tabs as space breaking characters |
|
127 */ |
|
128 class TTestCustomWrap4 : public MFormCustomWrap |
|
129 { |
|
130 TUint LineBreakClass(TUint aCode,TUint& aRangeStart,TUint& aRangeEnd) const |
|
131 { |
|
132 TUint breakClass; |
|
133 |
|
134 //Set tabs to be space breaking class |
|
135 if(aCode == 0x09) |
|
136 { |
|
137 breakClass = MLineBreaker::ESpLineBreakClass; |
|
138 } |
|
139 else |
|
140 { |
|
141 breakClass = MFormCustomWrap::LineBreakClass(aCode,aRangeStart, aRangeEnd); |
|
142 } |
|
143 return breakClass; |
|
144 } |
|
145 }; |
|
146 |
|
147 |
|
148 #endif |