summaryrefslogtreecommitdiffstats
path: root/lib/kotext/KoVariable.h
blob: 88f1797522e8f9968a1a67c44e23fa59a3a56f0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef kovariable_h
#define kovariable_h

#include <tqstring.h>
#include <tqdatetime.h>
#include <tqasciidict.h>
#include <tqptrlist.h>
#include <tqmap.h>
#include <tqobject.h>
#include <kaction.h>
#include "KoRichText.h"
#include <tqvariant.h>
#include <koffice_export.h>

class TQDomElement;
// Always add new types at the _end_ of this list (but before VT_ALL of course).
// (and update KWView::setupActions)
enum VariableType {
    VT_NONE             = -1,

    VT_DATE             = 0,
    VT_DATE_VAR_KWORD10 = 1,
    VT_TIME             = 2,
    VT_TIME_VAR_KWORD10 = 3,
    VT_PGNUM            = 4,
    // No number 5
    VT_CUSTOM           = 6,
    VT_MAILMERGE        = 7,
    VT_FIELD            = 8,
    VT_LINK             = 9,
    VT_NOTE             = 10,
    VT_FOOTNOTE         = 11,
    VT_STATISTIC        = 12,

    VT_ALL              = 256
};

enum VariableFormat {
    VF_DATE   = 0,
    VF_TIME   = 1,
    VF_STRING = 2,
    VF_NUM    = 3
};

class KoVariable;
class KoOasisSettings;

class KOTEXT_EXPORT KoVariableSettings
{
 public:
    KoVariableSettings();
    virtual ~KoVariableSettings();

    int startingPageNumber()const { return m_startingPageNumber; }
    void setStartingPageNumber(int num) { m_startingPageNumber=num; }

    bool displayLink() const{ return m_displayLink; }
    void setDisplayLink( bool b) { m_displayLink=b; }

    bool underlineLink() const { return m_underlineLink; }
    void setUnderlineLink( bool b) { m_underlineLink=b; }

    bool displayComment() const { return m_displayComment; }
    void setDisplayComment( bool b) { m_displayComment=b; }

    bool displayFieldCode() const { return m_displayFieldCode; }
    void setDisplayFieldCode( bool b) { m_displayFieldCode=b; }

    virtual void save( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );

    TQDateTime lastPrintingDate() const;
    void setLastPrintingDate( const TQDateTime & _date);

    TQDateTime creationDate() const;
    void setCreationDate( const TQDateTime & _date);

    TQDateTime modificationDate() const;
    void setModificationDate( const TQDateTime & _date);

    virtual void saveOasis( KoXmlWriter &settingsWriter ) const;
    virtual void loadOasis(const KoOasisSettings&settingsDoc);


 private:
    int m_startingPageNumber;
    bool m_displayLink;
    bool m_displayComment;
    bool m_underlineLink;
    bool m_displayFieldCode;
    class KoVariableSettingPrivate;
    KoVariableSettingPrivate *d;
};

/**
 * Class: KoVariableFormat
 * Base class for a variable format - held by KWDocument.
 * Example of formats are time, date, string, number, floating-point number...
 * The reason for formats to be separated is that it allows to
 * customize the formats, to implement subformats (various date formats, etc.).
 */
class KOTEXT_EXPORT KoVariableFormat
{
public:
    KoVariableFormat() {}
    virtual ~KoVariableFormat() {}
    /**
     * Return a key describing this format.
     * Used for the flyweight pattern in KoVariableFormatCollection
     */
    virtual TQCString key() const = 0;
    /**
     * @return the key for a given set of properties.
     * Use this key to lookup the format in the "variable format" collection.
     * @param props properties of this format, e.g. DD/MM/YYYY for a date format.
     */
    virtual TQCString getKey( const TQString& props ) const = 0;
    /**
     * Create a format from this key.
     */
    virtual void load( const TQCString &key ) = 0;
    /**
     * Use this format to convert a piece of data into a string.
     */
    virtual TQString convert(const TQVariant& data ) const = 0;
    /**
     * Set the properties of this format, e.g. DD/MM/YYYY for a date format.
     * WARNING: if you call this, you might be modifying a format that
     * other variables use as well. Don't do it, use getKey.
     */
    virtual void setFormatProperties( const TQString& ) {}
    /**
     * @return the properties of this format, e.g. DD/MM/YYYY for a date format.
     */
    virtual TQString formatProperties() const { return TQString(); }
    /**
     * @return the list of available properties strings (e.g. hh:mm:ss)
     */
    virtual TQStringList formatPropsList() const { return TQStringList(); }
    /**
     * @return the translated version of the list of format properties
     */
    virtual TQStringList translatedFormatPropsList() const { return TQStringList(); }
};

/**
 * Implementation of the "date" formats
 * TODO: merge with KoVariableTimeFormat, for a single TQDateTime-based class.
 */
class KOTEXT_EXPORT KoVariableDateFormat : public KoVariableFormat
{
public:
    KoVariableDateFormat();
    virtual TQString convert(const TQVariant& data ) const;
    virtual TQCString key() const;
    virtual TQCString getKey( const TQString& props ) const;
    virtual void load( const TQCString &key );

    /// Set the format string (e.g. DDMMYYYY)
    virtual void setFormatProperties( const TQString& props ) {
        m_strFormat = props;
    }
    /// @return the format string (e.g. DDMMYYYY)
    virtual TQString formatProperties() const { return m_strFormat; }

    /// @return the list of available format strings
    virtual TQStringList formatPropsList() const { return staticFormatPropsList(); }

    /// @return the translated version of the list of formats
    virtual TQStringList translatedFormatPropsList() const { return staticTranslatedFormatPropsList(); }

    static TQStringList staticFormatPropsList();
    static TQStringList staticTranslatedFormatPropsList();

private:
    TQString m_strFormat;
};

/**
 * Implementation of the "time" formats
 */
class KOTEXT_EXPORT KoVariableTimeFormat : public KoVariableFormat
{
public:
    KoVariableTimeFormat();
    virtual TQString convert(const TQVariant& data ) const;
    virtual TQCString key() const;
    virtual TQCString getKey( const TQString& props ) const;
    virtual void load( const TQCString & /*key*/ );

    /// Set the format string (e.g. hh:mm:ss)
    virtual void setFormatProperties( const TQString& props ) {
        m_strFormat = props;
    }
    /// @return the format string (e.g. hh:mm:ss)
    virtual TQString formatProperties() const { return m_strFormat; }

    /// @return the list of available properties strings (e.g. hh:mm:ss)
    virtual TQStringList formatPropsList() const { return staticFormatPropsList(); }

    /// @return the translated version of the list of format properties
    virtual TQStringList translatedFormatPropsList() const { return staticTranslatedFormatPropsList(); }

    static TQStringList staticFormatPropsList();
    static TQStringList staticTranslatedFormatPropsList();

private:
    TQString m_strFormat;
};


/**
 * Implementation of the string format
 */
class KoVariableStringFormat : public KoVariableFormat
{
public:
    KoVariableStringFormat() : KoVariableFormat() {}
    virtual TQString convert(const TQVariant& data ) const;
    virtual TQCString key() const;
    virtual TQCString getKey( const TQString& props ) const;
    virtual void load( const TQCString & /*key*/ ) {}
};


class KOTEXT_EXPORT KoVariableNumberFormat : public KoVariableFormat
{
public:
    KoVariableNumberFormat() : KoVariableFormat() {}
    virtual TQString convert(const TQVariant& data ) const;
    virtual TQCString key() const;
    virtual TQCString getKey( const TQString& props ) const;
    virtual void load( const TQCString & /*key*/ ) {}
};


/**
 * The collection of formats for variables.
 * Example: date (short or long), time, string (prefix/suffix), number (prefix/suffix, decimals?)...
 * Implements the flyweight pattern to share formats and create them on demand.
 * Each KoDocument holds a KoVariableFormatCollection.
 */
class KOTEXT_EXPORT KoVariableFormatCollection
{
public:
    KoVariableFormatCollection();

    /**
     * Forget (and erase) all the formats this collection knows about
     */
    void clear() { m_dict.clear(); }

    /**
     * Find or create the format for the given @p key
     */
    KoVariableFormat *format( const TQCString &key );

    // TODO Refcounting and removing unused formats
    // Not critical, that we don't delete unused formats until closing the doc...
protected:
    KoVariableFormat *createFormat( const TQCString &key );

private:
    TQAsciiDict<KoVariableFormat> m_dict;
};

class KoVariable;
class KoVariableFormat;
class KoDocument;
class KoVariableFormatCollection;
class KoTextDocument;
class KoVariableCollection;
class KOTEXT_EXPORT KoVariableCollection : public TQObject
{
    Q_OBJECT
  TQ_OBJECT
public:
    // Note that the KoVariableSettings becomes owned by the collection;
    // we take it as argument so that it can be subclassed though.
    KoVariableCollection(KoVariableSettings *settings, KoVariableFormatCollection *formatCollection);
    ~KoVariableCollection();
    void registerVariable( KoVariable *var );
    void unregisterVariable( KoVariable *var );
    TQValueList<KoVariable *> recalcVariables(int type);

    // For custom variables
    void setVariableValue( const TQString &name, const TQString &value );
    TQString getVariableValue( const TQString &name ) const;

    const TQPtrList<KoVariable>& getVariables() const {
        return variables;
    }
    void clear();

    bool customVariableExist(const TQString &varname)const ;

    virtual KoVariable *createVariable( int type, short int subtype, KoVariableFormatCollection * coll, KoVariableFormat *varFormat,KoTextDocument *textdoc, KoDocument * doc, int _correct , bool _forceDefaultFormat=false, bool loadFootNote= true );

    /// Load variable from OASIS file format (called "field" in the OASIS format)
    virtual KoVariable* loadOasisField( KoTextDocument* textdoc, const TQDomElement& tag, KoOasisContext& context );
    virtual KoVariable* loadOasisFieldCreateVariable( KoTextDocument* textdoc, const TQDomElement& tag, KoOasisContext& context, const TQString &key, int type );

    KoVariableSettings *variableSetting() const { return m_variableSettings; }
    KoVariableFormatCollection *formatCollection() const { return m_formatCollection; }

    /// Variable that's under the popupmenu
    void setVariableSelected(KoVariable * var);
    KoVariable *selectedVariable()const {return m_varSelected;}

    /// List of KActions to put into the popupmenu on a variable
    TQPtrList<KAction> popupActionList() const;

 protected slots:
    // This is here because variables and formats are not TQObjects
    void slotChangeSubType();
    void slotChangeFormat();

 private:
    //typedef TQMap<KAction *, int> VariableSubTextMap;
    //VariableSubTextMap m_variableSubTextMap;

    TQPtrList<KoVariable> variables;
    TQMap< TQString, TQString > varValues; // for custom variables
    KoVariableSettings *m_variableSettings;
    KoVariable *m_varSelected;
    KoVariableFormatCollection *m_formatCollection;
};


// ----------------------------------------------------------------
//                KoVariable and derived classes


class KoDocument;
class KoVariable;
class TQDomElement;
class KoTextFormat;


/**
 * A KoVariable is a custom item, i.e. considered as a single character.
 * KoVariable is the abstract base class.
 */
class KOTEXT_EXPORT KoVariable : public KoTextCustomItem
{
public:
    KoVariable( KoTextDocument *fs, KoVariableFormat *varFormat,KoVariableCollection *varColl );
    virtual ~KoVariable();

    virtual VariableType type() const = 0;
    virtual short int subType() const { return 0; }

    // KoTextCustomItem stuff
    virtual Placement placement() const { return PlaceInline; }
    virtual void resize();
    virtual int ascent() const { return m_ascent; } // for text, ascent != height!
    virtual int widthHint() const { return width; }
    virtual int minimumWidth() const { return width; }
    virtual void drawCustomItem( TQPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int cx, int cy, int cw, int ch, const TQColorGroup& cg, bool selected, int offset,  bool drawingShadow);

    /**
     * Called by drawCustomItem. Some special variables can
     * reimplement drawCustomItem to change the parameters passed to
     * drawCustomItemHelper
     */
    void drawCustomItemHelper( TQPainter* p, int x, int y, int wpix, int hpix, int ascentpix, const TQColorGroup& cg, bool selected, int offset, KoTextFormat* fmt, const TQFont& font, TQColor textColor, bool drawingShadow );

    void setVariableFormat( KoVariableFormat *_varFormat );

    KoVariableFormat *variableFormat() const
        { return m_varFormat; }

    KoVariableCollection *variableColl() const
        { return m_varColl; }

    /**
     * Returns the text to be displayed for this variable
     * It doesn't need to be cached, convert() is fast, and it's the actual
     * value (date, time etc.) that is cached in the variable already.
     */
    virtual TQString text(bool realValue=false);

    virtual TQString fieldCode();

    /// Return the variable value, as a TQVariant, before format conversion
    TQVariant varValue() const { return m_varValue; }

    /**
     * Ask this variable to recalculate and to tqrepaint itself
     * Only use this if you're working on a single variable (e.g. popupmenu).
     * Otherwise, better do the repainting all at once.
     * @see KoVariableCollection::recalcVariables()
     */
    void recalcAndRepaint();

    /** Save the variable. Public API, does the common job and then calls saveVariable. */
    virtual void save( TQDomElement &parentElem );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );

    /** Part of the KoTextCustomItem interface. Returns the code for a variable, see DTD.
      * Do NOT reimplement in koVariable-derived classes.
      */
    virtual int typeId() const { return 4; }

    /// List of available subtypes (translated). Use variableSubType() to map index to ID
    virtual TQStringList subTypeList();

    /// Set this variable's subtype.
    virtual void setVariableSubType( short int /*subtype*/ ) {}

    /**
     * Converts the @p menuNumber to variable subtype number (VST_x)
     */
    virtual short int variableSubType(short int menuNumber){ return menuNumber; }

    TQString convertKlocaleToTQDateTimeFormat( const TQString & _format );

protected:
    /** Variable should reimplement this to implement saving. */
    virtual void saveVariable( TQDomElement &parentElem ) = 0;
    virtual int correctValue() const { return 0;}

    KoVariableFormat *m_varFormat;
    KoVariableCollection *m_varColl;
    TQVariant m_varValue;
    int m_ascent;

    //typedef TQMap<KAction *, int> SubTextMap;
    //SubTextMap m_subTextMap;
    class Private;
    Private *d;
};


/**
 * Date-related variables
 */
class KOTEXT_EXPORT KoDateVariable : public KoVariable
{
public:
    KoDateVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *_varFormat,KoVariableCollection *_varColl , int _correctDate = 0);

    virtual VariableType type() const
    { return VT_DATE; }

    enum { VST_DATE_FIX = 0, VST_DATE_CURRENT = 1, VST_DATE_LAST_PRINTING = 2, VST_DATE_CREATE_FILE = 3, VST_DATE_MODIFY_FILE =4 };
    static TQStringList actionTexts();

    virtual void recalc();
    virtual TQString fieldCode();
    virtual void resize();
    void setDate( const TQDate & _date ) { m_varValue = TQVariant(_date); }

    virtual void saveVariable( TQDomElement &parentElem );
    virtual int correctValue() const { return m_correctDate;}
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    virtual TQStringList subTypeList();
    /// Set this variable's subtype.
    virtual void setVariableSubType( short int subtype )
        { m_subtype = subtype; }
    virtual short int subType() const { return m_subtype; }
    /**
     * Ask the user and return the date format string with prefix "DATE"
     */
    static TQCString formatStr( int & correct );
    /**
     * Return the default date format for old file.
     */
    static TQCString defaultFormat();

protected:
    short int m_subtype;
    int m_correctDate;
};


/**
 * Time-related variables
 */
class KOTEXT_EXPORT KoTimeVariable : public KoVariable
{
public:
    KoTimeVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *varFormat, KoVariableCollection *_varColl,  int _correct);

    virtual VariableType type() const
    { return VT_TIME; }

    enum { VST_TIME_FIX = 0, VST_TIME_CURRENT = 1 };
    static TQStringList actionTexts();

    virtual void recalc();
    virtual void resize();
    virtual TQString fieldCode();

    void setTime( const TQTime & _time ) { m_varValue = TQVariant(_time); }

    virtual void saveVariable( TQDomElement &parentElem );
    virtual int correctValue() const { return m_correctTime;}
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    virtual TQStringList subTypeList();
    virtual void setVariableSubType( short int subtype )
        { m_subtype = subtype; }
    virtual short int subType() const { return m_subtype; }
    /**
     * Returns the time format string with prefix "TIME"
     */
    static TQCString formatStr(int & _correct);
    /**
     * Return the default date format for old file.
     */
    static TQCString defaultFormat();

protected:
    short int m_subtype;
    int m_correctTime; // in minutes
};



/**
 * A custom variable is a variable whose value is entered
 * by the user.
 */
class KOTEXT_EXPORT KoCustomVariable : public KoVariable
{
public:
    KoCustomVariable(KoTextDocument *textdoc , const TQString &name, KoVariableFormat *varFormat,KoVariableCollection *_varcoll );

    virtual VariableType type() const
    { return VT_CUSTOM; }
    static TQStringList actionTexts();

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    TQString name() const { return m_varValue.toString(); }
    virtual void recalc();
    virtual TQString fieldCode();

    virtual TQString text(bool realValue=false);

    TQString value() const;
    void setValue( const TQString &v );

protected:
};


/**
 * Any variable that is a string, and whose value is automatically
 * determined - as opposed to custom variables whose value is
 * entered by the user
 */
class KOTEXT_EXPORT KoFieldVariable : public KoVariable
{
public:
    KoFieldVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *varFormat,KoVariableCollection *_varColl, KoDocument *_doc );

    // Do not change existing values, they are saved in document files
    enum FieldSubType { VST_NONE = -1,
                        VST_FILENAME = 0, VST_DIRECTORYNAME = 1,
                        VST_AUTHORNAME = 2, VST_EMAIL = 3, VST_COMPANYNAME = 4,
			VST_PATHFILENAME = 5, VST_FILENAMEWITHOUTEXTENSION=6,
                        VST_TELEPHONE_WORK = 7, VST_FAX = 8, VST_COUNTRY = 9,
                        VST_TITLE = 10, VST_ABSTRACT = 11,
                        VST_POSTAL_CODE = 12, VST_CITY = 13, VST_STREET = 14,
                        VST_AUTHORTITLE = 15, VST_INITIAL = 16, VST_TELEPHONE_HOME = 17, VST_SUBJECT = 18, VST_KEYWORDS=19,VST_AUTHORPOSITION = 20 };

    virtual VariableType type() const
    { return VT_FIELD; }

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;
    virtual TQString fieldCode();

    virtual void recalc();
    virtual TQString text(bool realValue=false);

    TQString value() const { return m_varValue.toString(); }

    static TQStringList actionTexts();
    /**
     * Converts @p menuNumber to field variable subtype number
     */
    virtual short int variableSubType( short int menuNumber );
    /**
     * Converts @p menuNumber to field variable subtype number
     */
    static FieldSubType fieldSubType( short int menuNumber);

    virtual TQStringList subTypeList();
    virtual void setVariableSubType( short int subtype )
        { m_subtype = subtype; }
    virtual short int subType() const { return m_subtype; }

protected:
    short int m_subtype;
    KoDocument *m_doc;
};


class KOTEXT_EXPORT KoMailMergeVariable : public KoVariable
{
public:
    KoMailMergeVariable( KoTextDocument *textdoc, const TQString &name, KoVariableFormat *varFormat, KoVariableCollection *_varColl );

    virtual VariableType type() const
    { return VT_MAILMERGE; }
    static TQStringList actionTexts();
    virtual TQString fieldCode();

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    virtual TQString text(bool realValue=false);
    TQString name() const { return m_varValue.toString(); }
    virtual TQString value() const;

protected:
};


/**
 * "current page number" and "number of pages" variables
 * This is a base class, it must be inherited by applications,
 * to provide recalc().
 */
class KOTEXT_EXPORT KoPageVariable : public KoVariable
{
public:
    KoPageVariable( KoTextDocument *textdoc, short int subtype, KoVariableFormat *varFormat ,KoVariableCollection *_varColl);

    virtual VariableType type() const
    { return VT_PGNUM; }

    enum { VST_PGNUM_CURRENT = 0, VST_PGNUM_TOTAL = 1, VST_CURRENT_SECTION = 2 , VST_PGNUM_PREVIOUS = 3, VST_PGNUM_NEXT = 4 };
    static TQStringList actionTexts();
    virtual TQString fieldCode();

    virtual TQStringList subTypeList();

    virtual void setVariableSubType( short int subtype );

    // For the 'current page' variable. This is called by the app e.g. when painting
    // a given page (see KWTextFrameSet::drawFrame and KPTextObject::recalcPageNum)
    void setPgNum( int pgNum ) { m_varValue = TQVariant( pgNum); }
    // For the 'current section title' variable. Same thing.
    void setSectionTitle( const TQString& title );

    virtual short int subType() const { return m_subtype; }

    virtual void recalc() = 0;

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;
protected:
    short int m_subtype;
};


class KOTEXT_EXPORT KoLinkVariable : public KoVariable
{
public:
    KoLinkVariable( KoTextDocument *textdoc, const TQString & _linkName, const TQString & _ulr,KoVariableFormat *varFormat, KoVariableCollection *_varColl );
    virtual void drawCustomItem( TQPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int /*cx*/, int /*cy*/, int /*cw*/, int /*ch*/, const TQColorGroup& cg, bool selected, int offset, bool drawingShadow );

    virtual VariableType type() const
    { return VT_LINK; }

    static TQStringList actionTexts();
    virtual TQString fieldCode();

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    virtual TQString text(bool realValue=false);
    TQString value() const { return m_varValue.toString(); }
    TQString url() const { return m_url;}

    virtual void recalc();

    void setLink(const TQString & _linkName, const TQString &_url)
	{
	    m_varValue=TQVariant(_linkName);
	    m_url=_url;
	}

protected:
    TQString m_url;
};


// A custom item that display a small yellow rect. Right-clicking on it shows the comment.
class KOTEXT_EXPORT KoNoteVariable : public KoVariable
{
public:
    KoNoteVariable( KoTextDocument *textdoc, const TQString & _note,KoVariableFormat *varFormat, KoVariableCollection *_varColl );
    virtual void drawCustomItem( TQPainter* p, int x, int y, int wpix, int hpix, int ascentpix, int /*cx*/, int /*cy*/, int /*cw*/, int /*ch*/, const TQColorGroup& cg, bool selected, int offset, bool drawingShadow );

    virtual VariableType type() const
    { return VT_NOTE; }

    static TQStringList actionTexts();
    virtual TQString fieldCode();

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    virtual TQString text(bool realValue=false);
    TQString note() const { return m_varValue.toString(); }
    void setNote( const TQString & _note) { m_varValue = TQVariant(_note); }
    virtual void recalc();

    TQString createdNote() const;
protected:
    TQDate m_createdNoteDate;
};


class KOTEXT_EXPORT KoStatisticVariable : public KoVariable
{
public:
    KoStatisticVariable( KoTextDocument *textdoc, short int subtype,
			 KoVariableFormat *varFormat,
			 KoVariableCollection *_varColl);

    enum {
	VST_STATISTIC_NB_WORD                      = 0,
	VST_STATISTIC_NB_SENTENCE                  = 1,
	VST_STATISTIC_NB_LINES                     = 2,
	VST_STATISTIC_NB_CHARACTERE                = 3,
	VST_STATISTIC_NB_NON_WHITESPACE_CHARACTERE = 4,
	VST_STATISTIC_NB_SYLLABLE                  = 5,
	VST_STATISTIC_NB_FRAME                     = 6,
	VST_STATISTIC_NB_EMBEDDED                  = 7,
	VST_STATISTIC_NB_PICTURE                   = 8,
	VST_STATISTIC_NB_TABLE                     = 9
    };

    virtual VariableType type() const
    { return VT_STATISTIC; }
    static TQStringList actionTexts();

    virtual TQStringList subTypeList();

    virtual void saveVariable( TQDomElement &parentElem );
    virtual void load( TQDomElement &elem );
    virtual void loadOasis( const TQDomElement &elem, KoOasisContext& context );
    virtual void saveOasis( KoXmlWriter& writer, KoSavingContext& context ) const;

    virtual short int subType() const { return m_subtype; }

    virtual void setVariableSubType( short int subtype );

    TQString name() const { return m_varValue.toString(); }
    virtual TQString fieldCode();

    TQString value() const;
    void setValue( const TQString &v );
    static void setExtendedType( bool _b) { m_extendedType = _b; }
    static bool extendedType() { return m_extendedType; }
protected:
    short int m_subtype;
    // extend type for kword.
    static bool m_extendedType;
};


#endif