|
1 /* |
|
2 * Copyright (c) 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 using System; |
|
18 using System.IO; |
|
19 using System.Text; |
|
20 using System.Threading; |
|
21 using System.Collections; |
|
22 using System.Drawing; |
|
23 |
|
24 namespace SymbianUtils |
|
25 { |
|
26 #region Enumerations |
|
27 public enum TNotUsingThread |
|
28 { |
|
29 ENotUsingThread |
|
30 } |
|
31 #endregion |
|
32 |
|
33 public abstract class AsyncTextWriterBase : DisposableObject |
|
34 { |
|
35 #region Events |
|
36 public enum TEvent |
|
37 { |
|
38 EWritingStarted = 0, |
|
39 EWritingProgress, |
|
40 EWritingComplete |
|
41 } |
|
42 |
|
43 public delegate void Observer( TEvent aEvent, AsyncTextWriterBase aObject ); |
|
44 public event Observer iObserver; |
|
45 #endregion |
|
46 |
|
47 #region Construct & destruct |
|
48 public AsyncTextWriterBase() |
|
49 : this( System.Threading.ThreadPriority.BelowNormal ) |
|
50 { |
|
51 } |
|
52 |
|
53 public AsyncTextWriterBase( System.Threading.ThreadPriority aPriority ) |
|
54 { |
|
55 iWorkerThread = new Thread( new System.Threading.ThreadStart( WorkerThreadFunction ) ); |
|
56 iWorkerThread.Name = "WorkerThreadFunction_" + this.ToString(); |
|
57 iWorkerThread.Priority = aPriority; |
|
58 iWorkerThread.IsBackground = true; |
|
59 } |
|
60 |
|
61 public AsyncTextWriterBase( TNotUsingThread aNotUsingThread ) |
|
62 { |
|
63 } |
|
64 #endregion |
|
65 |
|
66 #region API |
|
67 public void AsyncWrite() |
|
68 { |
|
69 lock( this ) |
|
70 { |
|
71 if ( iWorkerThread != null ) |
|
72 { |
|
73 iWorkerThread.Start(); |
|
74 } |
|
75 } |
|
76 } |
|
77 #endregion |
|
78 |
|
79 #region From DisposableObject - Cleanup Framework |
|
80 protected override void CleanupManagedResources() |
|
81 { |
|
82 try |
|
83 { |
|
84 } |
|
85 finally |
|
86 { |
|
87 base.CleanupManagedResources(); |
|
88 } |
|
89 } |
|
90 |
|
91 protected override void CleanupUnmanagedResources() |
|
92 { |
|
93 try |
|
94 { |
|
95 } |
|
96 finally |
|
97 { |
|
98 base.CleanupUnmanagedResources(); |
|
99 } |
|
100 } |
|
101 #endregion |
|
102 |
|
103 #region Properties |
|
104 public bool IsReady |
|
105 { |
|
106 get |
|
107 { |
|
108 lock(this) |
|
109 { |
|
110 return iReady; |
|
111 } |
|
112 } |
|
113 set |
|
114 { |
|
115 lock( this ) |
|
116 { |
|
117 iReady = value; |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 public int Progress |
|
123 { |
|
124 get |
|
125 { |
|
126 lock(this) |
|
127 { |
|
128 if (Size == 0) |
|
129 return 0; |
|
130 else |
|
131 { |
|
132 float positionAsFloat = (float)Position; |
|
133 float sizeAsFloat = (float)Size; |
|
134 int progress = (int)((positionAsFloat / sizeAsFloat) * 100.0); |
|
135 // |
|
136 return System.Math.Max(1, System.Math.Min(100, progress)); |
|
137 } |
|
138 } |
|
139 } |
|
140 } |
|
141 #endregion |
|
142 |
|
143 #region Write handlers |
|
144 protected virtual bool ContinueProcessing() |
|
145 { |
|
146 return false; |
|
147 } |
|
148 |
|
149 protected virtual void HandleWriteStarted() |
|
150 { |
|
151 } |
|
152 |
|
153 protected virtual void HandleWriteCompleted() |
|
154 { |
|
155 } |
|
156 |
|
157 protected virtual void HandleWriteException( Exception aException ) |
|
158 { |
|
159 } |
|
160 #endregion |
|
161 |
|
162 #region Abstract writing framework |
|
163 public abstract void ExportData(); |
|
164 public abstract long Size { get; } |
|
165 public abstract long Position { get; } |
|
166 #endregion |
|
167 |
|
168 #region Internal methods |
|
169 private void NotifyEvent( TEvent aEvent ) |
|
170 { |
|
171 if ( iObserver != null ) |
|
172 { |
|
173 iObserver( aEvent, this ); |
|
174 } |
|
175 } |
|
176 |
|
177 private void AsyncWriteLines() |
|
178 { |
|
179 bool forcedContinue = false; |
|
180 lock( this ) |
|
181 { |
|
182 forcedContinue = ContinueProcessing(); |
|
183 } |
|
184 |
|
185 while( Progress != KAllWorkCompletedPercentage || forcedContinue ) |
|
186 { |
|
187 ExportData(); |
|
188 |
|
189 lock( this ) |
|
190 { |
|
191 NotifyEvent( TEvent.EWritingProgress ); |
|
192 forcedContinue = ContinueProcessing(); |
|
193 } |
|
194 } |
|
195 } |
|
196 |
|
197 private void WorkerThreadFunction() |
|
198 { |
|
199 try |
|
200 { |
|
201 lock( this ) |
|
202 { |
|
203 iReady = false; |
|
204 HandleWriteStarted(); |
|
205 NotifyEvent( TEvent.EWritingStarted ); |
|
206 } |
|
207 |
|
208 AsyncWriteLines(); |
|
209 } |
|
210 catch( Exception exception ) |
|
211 { |
|
212 lock( this ) |
|
213 { |
|
214 HandleWriteException( exception ); |
|
215 } |
|
216 } |
|
217 finally |
|
218 { |
|
219 lock( this ) |
|
220 { |
|
221 HandleWriteCompleted(); |
|
222 iReady = true; |
|
223 NotifyEvent( TEvent.EWritingComplete ); |
|
224 } |
|
225 } |
|
226 } |
|
227 #endregion |
|
228 |
|
229 #region Internal constants |
|
230 protected const int KAllWorkCompletedPercentage = 100; |
|
231 #endregion |
|
232 |
|
233 #region Data members |
|
234 protected bool iReady = true; |
|
235 private readonly Thread iWorkerThread; |
|
236 #endregion |
|
237 } |
|
238 |
|
239 public abstract class AsyncTextFileWriter : AsyncTextWriterBase |
|
240 { |
|
241 #region Construct & destruct |
|
242 public AsyncTextFileWriter( string aFileName ) |
|
243 { |
|
244 iSourceFileName = aFileName; |
|
245 } |
|
246 |
|
247 public AsyncTextFileWriter( string aFileName, TNotUsingThread aNotUsingThread ) |
|
248 : this( aNotUsingThread ) |
|
249 { |
|
250 iSourceFileName = aFileName; |
|
251 } |
|
252 |
|
253 public AsyncTextFileWriter( TNotUsingThread aNotUsingThread ) |
|
254 : base( aNotUsingThread ) |
|
255 { |
|
256 } |
|
257 #endregion |
|
258 |
|
259 #region API |
|
260 public void ConstructWriter() |
|
261 { |
|
262 iWriter = new StreamWriter( FileName ); |
|
263 } |
|
264 |
|
265 public void WriteLine( string aLine ) |
|
266 { |
|
267 iWriter.WriteLine( aLine ); |
|
268 } |
|
269 #endregion |
|
270 |
|
271 #region Properties |
|
272 public StreamWriter Writer |
|
273 { |
|
274 get { return iWriter; } |
|
275 } |
|
276 |
|
277 public string FileName |
|
278 { |
|
279 get { return iSourceFileName; } |
|
280 } |
|
281 #endregion |
|
282 |
|
283 #region From DisposableObject - Cleanup Framework |
|
284 protected override void CleanupManagedResources() |
|
285 { |
|
286 try |
|
287 { |
|
288 Cleanup(); |
|
289 } |
|
290 finally |
|
291 { |
|
292 base.CleanupManagedResources(); |
|
293 } |
|
294 } |
|
295 #endregion |
|
296 |
|
297 #region From AsyncTextWriterBase |
|
298 protected override void HandleWriteStarted() |
|
299 { |
|
300 if ( iWriter == null ) |
|
301 { |
|
302 ConstructWriter(); |
|
303 } |
|
304 |
|
305 base.HandleWriteStarted(); |
|
306 } |
|
307 |
|
308 protected override void HandleWriteCompleted() |
|
309 { |
|
310 try |
|
311 { |
|
312 Cleanup(); |
|
313 } |
|
314 finally |
|
315 { |
|
316 base.HandleWriteCompleted(); |
|
317 } |
|
318 } |
|
319 #endregion |
|
320 |
|
321 #region Internal methods |
|
322 private void Cleanup() |
|
323 { |
|
324 lock( this ) |
|
325 { |
|
326 if ( iWriter != null ) |
|
327 { |
|
328 iWriter.Close(); |
|
329 iWriter = null; |
|
330 } |
|
331 } |
|
332 } |
|
333 #endregion |
|
334 |
|
335 #region Data members |
|
336 private StreamWriter iWriter; |
|
337 private readonly string iSourceFileName; |
|
338 #endregion |
|
339 } |
|
340 |
|
341 public abstract class AsyncHTMLFileWriter : AsyncTextFileWriter |
|
342 { |
|
343 #region Construct & destruct |
|
344 public AsyncHTMLFileWriter( string aFileName ) |
|
345 : base( aFileName ) |
|
346 { |
|
347 } |
|
348 |
|
349 public AsyncHTMLFileWriter( TNotUsingThread aNotUsingThread ) |
|
350 : base( aNotUsingThread ) |
|
351 { |
|
352 } |
|
353 |
|
354 public AsyncHTMLFileWriter( string aFileName, TNotUsingThread aNotUsingThread ) |
|
355 : base( aFileName ) |
|
356 { |
|
357 } |
|
358 #endregion |
|
359 |
|
360 #region Enumerations |
|
361 public enum TAlignment |
|
362 { |
|
363 EAlignNone = -1, |
|
364 EAlignLeft = 0, |
|
365 EAlignRight, |
|
366 EAlignCenter, |
|
367 EAlignJustify |
|
368 } |
|
369 #endregion |
|
370 |
|
371 #region Helper methods - document |
|
372 public void WriteDocumentBegin() |
|
373 { |
|
374 WriteLine( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" ); |
|
375 WriteLine( "<HTML>" ); |
|
376 } |
|
377 |
|
378 public void WriteDocumentEnd() |
|
379 { |
|
380 WriteLine( "</HTML>" ); |
|
381 } |
|
382 #endregion |
|
383 |
|
384 #region Helper methods - header |
|
385 public void WriteHeadBegin() |
|
386 { |
|
387 WriteLine( "<HEAD>" ); |
|
388 } |
|
389 |
|
390 public void WriteHeadEnd() |
|
391 { |
|
392 Writer.WriteLine( "</HEAD>" ); |
|
393 } |
|
394 |
|
395 public void WriteTitle( string aTitle ) |
|
396 { |
|
397 Writer.WriteLine( "<TITLE>" + aTitle + "</TITLE>" ); |
|
398 } |
|
399 |
|
400 public void WriteStyleBegin() |
|
401 { |
|
402 WriteLine( "<META HTTP-EQUIV=\"Content-Style-Type\" CONTENT=\"text/css\">" ); |
|
403 WriteLine( "<STYLE TYPE=\"text/css\" MEDIA=\"screen, print, projection\">" ); |
|
404 } |
|
405 |
|
406 public void WriteStyleName( string aName ) |
|
407 { |
|
408 WriteLine( aName ); |
|
409 } |
|
410 |
|
411 public void WriteStyleBodyBegin() |
|
412 { |
|
413 WriteLine( "{" ); |
|
414 } |
|
415 |
|
416 public void WriteStyleBody( string aStyle ) |
|
417 { |
|
418 WriteLine( " " + aStyle ); |
|
419 } |
|
420 |
|
421 public void WriteStyleBodyEnd() |
|
422 { |
|
423 WriteLine( "}" ); |
|
424 } |
|
425 |
|
426 public void WriteStyleEnd() |
|
427 { |
|
428 Writer.WriteLine( "</STYLE>" ); |
|
429 } |
|
430 #endregion |
|
431 |
|
432 #region Helper methods - body |
|
433 public void WriteBodyBegin() |
|
434 { |
|
435 WriteLine( "<BODY>" ); |
|
436 } |
|
437 |
|
438 public void WriteBodyEnd() |
|
439 { |
|
440 WriteLine( "</BODY>" ); |
|
441 } |
|
442 #endregion |
|
443 |
|
444 #region Helper methods - tables |
|
445 public void WriteTableBegin() |
|
446 { |
|
447 WriteTableBegin( 100 ); |
|
448 } |
|
449 |
|
450 public void WriteTableBegin( int aWidthPercentage ) |
|
451 { |
|
452 WriteLine( "<TABLE WIDTH=\"" + aWidthPercentage.ToString() + "%\">" ); |
|
453 } |
|
454 |
|
455 public void WriteTableBeginWidthPixels( int aWidthPixels, Color aColor ) |
|
456 { |
|
457 string color = ColorString( aColor ); |
|
458 WriteLine( "<TABLE WIDTH=\"" + aWidthPixels.ToString() + "px\" bgcolor=\"" + color + "\">" ); |
|
459 } |
|
460 |
|
461 public void WriteTableEnd() |
|
462 { |
|
463 Writer.WriteLine( "</TABLE>" ); |
|
464 } |
|
465 |
|
466 public void WriteTableRowBegin() |
|
467 { |
|
468 WriteLine( "<TR>" ); |
|
469 } |
|
470 |
|
471 public void WriteTableRowEnd() |
|
472 { |
|
473 WriteLine( "</TR>" ); |
|
474 } |
|
475 |
|
476 public void WriteTableColumnBegin() |
|
477 { |
|
478 WriteTableColumnBegin( TAlignment.EAlignNone, string.Empty ); |
|
479 } |
|
480 |
|
481 public void WriteTableColumnBegin( TAlignment aAlignment, string aStyle ) |
|
482 { |
|
483 WriteTableColumnBegin( aAlignment, aStyle, -1 ); |
|
484 } |
|
485 |
|
486 public void WriteTableColumnBegin( TAlignment aAlignment, string aStyle, int aPixelWidth ) |
|
487 { |
|
488 StringBuilder line = new StringBuilder(); |
|
489 line.Append( "<TD" ); |
|
490 line.Append( FormattedClass( aStyle ) ); |
|
491 line.Append( FormattedAlignment( aAlignment ) ); |
|
492 line.Append( FormattedWidthPixel( aPixelWidth ) ); |
|
493 line.Append( ">" ); |
|
494 WriteLine( line.ToString() ); |
|
495 } |
|
496 |
|
497 public void WriteTableColumnEnd() |
|
498 { |
|
499 WriteLine( "</TD>" ); |
|
500 } |
|
501 |
|
502 public void WriteTableColumn( string aValue ) |
|
503 { |
|
504 WriteTableColumn( aValue, TAlignment.EAlignNone, string.Empty ); |
|
505 } |
|
506 |
|
507 public void WriteTableColumn( string aValue, TAlignment aAlignment ) |
|
508 { |
|
509 WriteTableColumn( aValue, aAlignment, string.Empty ); |
|
510 } |
|
511 |
|
512 public void WriteTableColumn( string aValue, string aStyle ) |
|
513 { |
|
514 WriteTableColumn( aValue, TAlignment.EAlignNone, aStyle ); |
|
515 } |
|
516 |
|
517 public void WriteTableColumn( string aValue, TAlignment aAlignment, string aStyle ) |
|
518 { |
|
519 WriteTableColumnBegin( aAlignment, aStyle ); |
|
520 Writer.Write( aValue ); |
|
521 WriteTableColumnEnd(); |
|
522 } |
|
523 |
|
524 public void WriteTableColumnFormatted( long aNumber, string aFormat ) |
|
525 { |
|
526 WriteTableColumnFormatted( aNumber, aFormat, TAlignment.EAlignNone ); |
|
527 } |
|
528 |
|
529 public void WriteTableColumnFormatted( long aNumber, string aFormat, TAlignment aAlignment ) |
|
530 { |
|
531 WriteTableColumnFormatted( aNumber, aFormat, aAlignment, string.Empty ); |
|
532 } |
|
533 |
|
534 public void WriteTableColumnFormatted( long aNumber, string aFormat, TAlignment aAlignment, string aStyle ) |
|
535 { |
|
536 WriteTableColumn( aNumber.ToString( aFormat ), aAlignment, aStyle ); |
|
537 } |
|
538 |
|
539 public void WriteTableColumn( long aNumber ) |
|
540 { |
|
541 WriteTableColumn( aNumber, "d" ); |
|
542 } |
|
543 |
|
544 public void WriteTableColumn( long aNumber, string aStyle ) |
|
545 { |
|
546 WriteTableColumnFormatted( aNumber, "d", TAlignment.EAlignNone, aStyle ); |
|
547 } |
|
548 |
|
549 public void WriteTableColumn( long aNumber, TAlignment aAlignment ) |
|
550 { |
|
551 WriteTableColumnFormatted( aNumber, "d", aAlignment, string.Empty ); |
|
552 } |
|
553 |
|
554 public void WriteTableColumn( long aNumber, TAlignment aAlignment, string aStyle ) |
|
555 { |
|
556 WriteTableColumnFormatted( aNumber, "d", aAlignment, aStyle ); |
|
557 } |
|
558 |
|
559 public void WriteTableColumnHex( long aNumber ) |
|
560 { |
|
561 WriteTableColumnHex( aNumber, string.Empty ); |
|
562 } |
|
563 |
|
564 public void WriteTableColumnHex( long aNumber, string aStyle ) |
|
565 { |
|
566 WriteTableColumnHex( aNumber, TAlignment.EAlignNone, aStyle ); |
|
567 } |
|
568 |
|
569 public void WriteTableColumnHex( long aNumber, TAlignment aAlignment, string aStyle ) |
|
570 { |
|
571 WriteTableColumn( aNumber.ToString( "x8" ), aAlignment, aStyle ); |
|
572 } |
|
573 |
|
574 public void WriteTableColumnHexAddress( long aNumber ) |
|
575 { |
|
576 WriteTableColumnHexAddress( aNumber, TAlignment.EAlignNone ); |
|
577 } |
|
578 |
|
579 public void WriteTableColumnHexAddress( long aNumber, TAlignment aAlignment ) |
|
580 { |
|
581 WriteTableColumnHexAddress( aNumber, aAlignment, string.Empty ); |
|
582 } |
|
583 |
|
584 public void WriteTableColumnHexAddress( long aNumber, TAlignment aAlignment, string aStyle ) |
|
585 { |
|
586 WriteTableColumn( "0x" + aNumber.ToString( "x8" ), aAlignment, aStyle ); |
|
587 } |
|
588 |
|
589 public void WriteTableColumnSpace() |
|
590 { |
|
591 WriteTableColumnBegin(); |
|
592 WriteLine( " " ); |
|
593 WriteTableColumnEnd(); |
|
594 } |
|
595 |
|
596 public void WriteTableColumnSpace( int aPixelWidth ) |
|
597 { |
|
598 WriteTableColumnBegin(); |
|
599 WriteLine( " " ); |
|
600 WriteTableColumnEnd(); |
|
601 } |
|
602 |
|
603 public void WriteTableColumnEmpty() |
|
604 { |
|
605 WriteTableColumnBegin(); |
|
606 WriteTableColumnEnd(); |
|
607 } |
|
608 #endregion |
|
609 |
|
610 #region Helper methods - blocks/paragraphs |
|
611 public void WriteDivisionBegin() |
|
612 { |
|
613 WriteLine( "<DIV>" ); |
|
614 } |
|
615 |
|
616 public void WriteDivisionBegin( string aStyle ) |
|
617 { |
|
618 WriteDivisionBegin( TAlignment.EAlignNone, aStyle ); |
|
619 } |
|
620 |
|
621 public void WriteDivisionBeginWithId( string aId ) |
|
622 { |
|
623 WriteDivisionBegin( TAlignment.EAlignNone, string.Empty, aId ); |
|
624 } |
|
625 |
|
626 public void WriteDivisionBegin( TAlignment aAlignment ) |
|
627 { |
|
628 WriteDivisionBegin( aAlignment, string.Empty ); |
|
629 } |
|
630 |
|
631 public void WriteDivisionBegin( TAlignment aAlignment, string aStyle ) |
|
632 { |
|
633 WriteDivisionBegin( aAlignment, aStyle, string.Empty ); |
|
634 } |
|
635 |
|
636 public void WriteDivisionBegin( TAlignment aAlignment, string aStyle, string aId ) |
|
637 { |
|
638 StringBuilder line = new StringBuilder(); |
|
639 line.Append( "<DIV" ); |
|
640 line.Append( FormattedClass( aStyle ) ); |
|
641 line.Append( FormattedAlignment( aAlignment ) ); |
|
642 line.Append( FormattedId( aId ) ); |
|
643 line.Append( ">" ); |
|
644 // |
|
645 WriteLine( line.ToString() ); |
|
646 } |
|
647 |
|
648 public void WriteDivisionEnd() |
|
649 { |
|
650 WriteLine( "</DIV>" ); |
|
651 } |
|
652 |
|
653 public void WriteParagraphBegin() |
|
654 { |
|
655 WriteLine( "<P>" ); |
|
656 } |
|
657 |
|
658 public void WriteParagraphBegin( string aClass ) |
|
659 { |
|
660 WriteLine( "<P CLASS=\"" + aClass + "\">" ); |
|
661 } |
|
662 |
|
663 public void WriteParagraphEnd() |
|
664 { |
|
665 WriteLine( "</P>" ); |
|
666 } |
|
667 |
|
668 public void WriteSpanBegin() |
|
669 { |
|
670 WriteSpanBegin( string.Empty ); |
|
671 } |
|
672 |
|
673 public void WriteSpanBegin( string aClass ) |
|
674 { |
|
675 WriteSpanBegin( aClass, string.Empty ); |
|
676 } |
|
677 |
|
678 public void WriteSpanBegin( string aClass, string aId ) |
|
679 { |
|
680 Writer.Write( "<SPAN" ); |
|
681 Writer.Write( FormattedClass( aClass ) ); |
|
682 Writer.Write( FormattedId( aId ) ); |
|
683 Writer.Write( ">" ); |
|
684 } |
|
685 |
|
686 public void WriteSpanEnd() |
|
687 { |
|
688 WriteLine( "</SPAN>" ); |
|
689 } |
|
690 |
|
691 public void WriteNewLine() |
|
692 { |
|
693 WriteLine( "<BR>" ); |
|
694 } |
|
695 #endregion |
|
696 |
|
697 #region Helper methods - text |
|
698 public void WriteText( string aText ) |
|
699 { |
|
700 Writer.Write( aText ); |
|
701 } |
|
702 |
|
703 public void WriteText( string aText, string aStyle ) |
|
704 { |
|
705 Writer.Write( "<SPAN CLASS=\"" + aStyle + "\">" ); |
|
706 Writer.Write( aText ); |
|
707 Writer.Write( "</SPAN>" ); |
|
708 } |
|
709 |
|
710 public void WriteLine( string aText, string aStyle ) |
|
711 { |
|
712 StringBuilder line = new StringBuilder(); |
|
713 // |
|
714 line.Append( "<SPAN CLASS=\"" + aStyle + "\">" ); |
|
715 line.Append( aText ); |
|
716 line.Append( "</SPAN>" ); |
|
717 // |
|
718 WriteLine( line.ToString() ); |
|
719 } |
|
720 |
|
721 public void WriteSpace() |
|
722 { |
|
723 Writer.Write( " " ); |
|
724 } |
|
725 #endregion |
|
726 |
|
727 #region Helper methods - links (anchors) |
|
728 public void WriteAnchorBegin( string aPageAddress ) |
|
729 { |
|
730 WriteAnchorBeginWithStyle( aPageAddress, string.Empty ); |
|
731 } |
|
732 |
|
733 public void WriteAnchorBeginWithStyle( string aPageAddress, string aStyle ) |
|
734 { |
|
735 StringBuilder line = new StringBuilder(); |
|
736 line.Append( "<A " ); |
|
737 line.Append( FormattedClass( aStyle ) ); |
|
738 line.Append( "HREF=\"" ); |
|
739 line.Append( aPageAddress ); |
|
740 line.Append( "\"" ); |
|
741 // |
|
742 line.Append( ">" ); |
|
743 Writer.Write( line.ToString() ); |
|
744 } |
|
745 |
|
746 public void WriteAnchorEnd() |
|
747 { |
|
748 WriteLine( "</A>" ); |
|
749 } |
|
750 |
|
751 public void WriteAnchorWithName( string aName ) |
|
752 { |
|
753 WriteAnchorWithName( aName, string.Empty ); |
|
754 } |
|
755 |
|
756 public void WriteAnchorWithName( string aName, string aValue ) |
|
757 { |
|
758 StringBuilder line = new StringBuilder(); |
|
759 line.Append( "<A " ); |
|
760 line.Append( "NAME=\"#" ); |
|
761 line.Append( aName ); |
|
762 line.Append( "\"" ); |
|
763 line.Append( ">" ); |
|
764 line.Append( aValue ); |
|
765 line.Append( "</A>" ); |
|
766 Writer.Write( line.ToString() ); |
|
767 } |
|
768 |
|
769 public void WriteAnchorWithTarget( string aTargetName, string aURL, string aText ) |
|
770 { |
|
771 StringBuilder line = new StringBuilder(); |
|
772 line.Append( "<A " ); |
|
773 line.Append( "TARGET=\"" ); |
|
774 line.Append( aTargetName ); |
|
775 line.Append( "\" " ); |
|
776 line.Append( "HREF=\"" ); |
|
777 line.Append( aURL ); |
|
778 line.Append( "\"" ); |
|
779 line.Append( ">" ); |
|
780 line.Append( aText ); |
|
781 line.Append( "</A>" ); |
|
782 Writer.Write( line.ToString() ); |
|
783 } |
|
784 #endregion |
|
785 |
|
786 #region Helper methods - colors |
|
787 public static string ColorString( Color aColor ) |
|
788 { |
|
789 StringBuilder ret = new StringBuilder(); |
|
790 // |
|
791 ret.Append( "#" ); |
|
792 ret.Append( aColor.R.ToString("x2") ); |
|
793 ret.Append( aColor.G.ToString("x2") ); |
|
794 ret.Append( aColor.B.ToString("x2") ); |
|
795 // |
|
796 return ret.ToString(); |
|
797 } |
|
798 #endregion |
|
799 |
|
800 #region Internal methods |
|
801 static string FormattedId( string aId ) |
|
802 { |
|
803 string ret = string.Empty; |
|
804 // |
|
805 if ( aId != string.Empty ) |
|
806 { |
|
807 ret = " ID=\"" + aId + "\" "; |
|
808 } |
|
809 // |
|
810 return ret; |
|
811 } |
|
812 |
|
813 static string FormattedClass( string aStyleName ) |
|
814 { |
|
815 string ret = string.Empty; |
|
816 // |
|
817 if ( aStyleName != string.Empty ) |
|
818 { |
|
819 ret = " CLASS=\"" + aStyleName + "\""; |
|
820 } |
|
821 // |
|
822 return ret; |
|
823 } |
|
824 |
|
825 static string FormattedWidthPixel( int aWidth ) |
|
826 { |
|
827 string ret = string.Empty; |
|
828 // |
|
829 if ( aWidth > 0 ) |
|
830 { |
|
831 ret = " WIDTH=\"" + aWidth.ToString() + "px\""; |
|
832 } |
|
833 // |
|
834 return ret; |
|
835 } |
|
836 |
|
837 static string FormattedWidthPercent( int aWidth ) |
|
838 { |
|
839 string ret = string.Empty; |
|
840 // |
|
841 if ( aWidth > 0 ) |
|
842 { |
|
843 ret = " WIDTH=\"" + aWidth.ToString() + "%\""; |
|
844 } |
|
845 // |
|
846 return ret; |
|
847 } |
|
848 |
|
849 static string FormattedAlignment( TAlignment aAlignment ) |
|
850 { |
|
851 StringBuilder line = new StringBuilder(); |
|
852 // |
|
853 if ( aAlignment != TAlignment.EAlignNone ) |
|
854 { |
|
855 line.Append( " ALIGN=\"" ); |
|
856 switch( aAlignment ) |
|
857 { |
|
858 case TAlignment.EAlignLeft: |
|
859 line.Append( "LEFT" ); |
|
860 break; |
|
861 case TAlignment.EAlignRight: |
|
862 line.Append( "RIGHT" ); |
|
863 break; |
|
864 case TAlignment.EAlignCenter: |
|
865 line.Append( "CENTER" ); |
|
866 break; |
|
867 case TAlignment.EAlignJustify: |
|
868 line.Append( "JUSTIFY" ); |
|
869 break; |
|
870 default: |
|
871 case TAlignment.EAlignNone: |
|
872 break; |
|
873 } |
|
874 line.Append( "\"" ); |
|
875 } |
|
876 // |
|
877 return line.ToString(); |
|
878 } |
|
879 #endregion |
|
880 } |
|
881 } |