1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // composant graphique de type console (terminal)
|
---|
3 | // R. Ansari 12/97
|
---|
4 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
5 |
|
---|
6 | #ifndef PICONSOLE_H
|
---|
7 | #define PICONSOLE_H
|
---|
8 |
|
---|
9 | #include "pisysdep.h"
|
---|
10 |
|
---|
11 | #include PISTDWDG_H
|
---|
12 | #include PICONT_H
|
---|
13 | #include PIBWDG_H
|
---|
14 |
|
---|
15 | enum PIVAType {
|
---|
16 | PIVA_Def = 0,
|
---|
17 | PIVA_Bold = 1 << 0,
|
---|
18 | PIVA_Ital = 1 << 1,
|
---|
19 | PIVA_Reverse = 1 << 2,
|
---|
20 | // Le 4eme bit (<<3) est reserve pour l'usage interne (PIVA_Select)
|
---|
21 | PIVA_DefCol = 0,
|
---|
22 | PIVA_Red = 1 << 4,
|
---|
23 | PIVA_Blue = 2 << 4,
|
---|
24 | PIVA_Green = 3 << 4,
|
---|
25 | PIVA_Yellow = 4 << 4,
|
---|
26 | PIVA_Magenta = 5 << 4
|
---|
27 | };
|
---|
28 |
|
---|
29 | class PIConsole : public PIBaseWdg {
|
---|
30 | public:
|
---|
31 | PIConsole(PIContainer* par, char* nom, PIMessage msg, int nl, int nc,
|
---|
32 | int sx=300, int sy=200, int px=0, int py=0, bool scb=true);
|
---|
33 | ~PIConsole();
|
---|
34 |
|
---|
35 | // Interface d utilisation :
|
---|
36 | void AddChar(char c, unsigned char va= PIVA_Def, bool ref=true);
|
---|
37 | void AddStr(const char* strg, unsigned char va= PIVA_Def, bool ref=true);
|
---|
38 |
|
---|
39 | void SelectFont(PIFontSize sz=PI_NormalSizeFont);
|
---|
40 | void AutoSize(int nl=-1, int nc=-1);
|
---|
41 | void PreferedSize(int& sx, int& sy);
|
---|
42 | void AcceptCmd(bool acc=true, int nrecmx=20);
|
---|
43 | void SetPrompt(const char* prompt);
|
---|
44 |
|
---|
45 | inline int WindNbLines() { return mWSzL; }
|
---|
46 | inline int NbLines() { return mNL; }
|
---|
47 | inline string GetCmdString() { return(mCmd); }
|
---|
48 |
|
---|
49 | // Gestion des evenements input/draw
|
---|
50 | virtual void Draw(PIGraphic* g, int x0, int y0, int dx, int dy);
|
---|
51 | virtual void Resize();
|
---|
52 | virtual void Keyboard(int key, PIKeyModifier kmod);
|
---|
53 | virtual void But1Press(int x, int y);
|
---|
54 | virtual void Ptr1Move(int x, int y);
|
---|
55 | virtual void But1Release(int x, int y);
|
---|
56 | virtual void But2Press(int x, int y);
|
---|
57 | virtual void But3Press(int x, int y);
|
---|
58 |
|
---|
59 | // Gestion de copier/coller
|
---|
60 | virtual void PasteSelection(unsigned int typ, void *pdata, unsigned int l);
|
---|
61 | virtual void* ProvideSelection(unsigned int& typ, unsigned int& len);
|
---|
62 | virtual void SelectionLost();
|
---|
63 | virtual void SelectionTransferEnd();
|
---|
64 |
|
---|
65 | protected:
|
---|
66 | void AssocScrollBar(PIContainer* par, char* nom, bool scb, int sx, int sy, int px, int py);
|
---|
67 | void ScrollUp();
|
---|
68 | void SetDispOffset(int ldeb=-1);
|
---|
69 | void ClearLine(int l);
|
---|
70 | void DisplayLines(PIGraphicGen* g, int l1, int l2);
|
---|
71 | void UpdCmdLine();
|
---|
72 | void ClrCmd();
|
---|
73 | void CmdAddChar(int key);
|
---|
74 | void SelFgBgCol(PIColors fc=PI_Black, PIColors bc=PI_White);
|
---|
75 | void SaveSelection(); // Pour copier la selection dans un buffer
|
---|
76 |
|
---|
77 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
78 |
|
---|
79 |
|
---|
80 | int mNL, mNC; // Nb de lignes, colonnes total de la console
|
---|
81 | int mCurL, mCurC; // Numero de ligne, colonne courante
|
---|
82 | int mWSzL, mWSzC; // Taille de fenetre en lignes, colonnes
|
---|
83 | int mOffL; // Offset d affichage (lignes)
|
---|
84 | int mNCmdL, mLCOff; // Nb de lignes reserve a l entree des commandes
|
---|
85 | int mDCOff; // Offset (en caractere) pour l affichage de la ligne de commande
|
---|
86 | char* mText; // Contenu de la console
|
---|
87 | unsigned char* mAtt; // Attributs du contenu (bold, ...)
|
---|
88 | int* mLPo; // Adresse des lignes ds les tableaux mText, mAtt
|
---|
89 | char* mStrBuf; // Buffer
|
---|
90 | int mFHaut, mFLarg; // Hauteur, Largeur des caracteres
|
---|
91 | PIFontSize mFTaille; // Taille des caracteres
|
---|
92 | PIColors mFgC, mBgC; // Couleur Avant - arriere plan
|
---|
93 | char mPrompt[32]; // Le prompt
|
---|
94 | char* mCmdStr; // La commande
|
---|
95 | int mCCP, mCLC; // Position du curseur, longeur de la commande
|
---|
96 | string mCmd; // Le string de la derniere commande validee
|
---|
97 |
|
---|
98 | // Pour le rappel des commandes
|
---|
99 | int NMxRecall, mNComm; // Profondeur de la pile de rappels, nb de commandes
|
---|
100 | string * mRStr; // Stockage des chaines
|
---|
101 | int mRCindx, mRindx; // Index pour le rappel
|
---|
102 | bool mChangeFg; // Texte modifie
|
---|
103 |
|
---|
104 | // Gestion du buffer de copie
|
---|
105 | char* mCPBuffer;
|
---|
106 | unsigned int mCPBufLen;
|
---|
107 | int mCPbeginC, mCPbeginL;
|
---|
108 | int mCPendC, mCPendL;
|
---|
109 |
|
---|
110 | // S il y a un scroll-bar associe
|
---|
111 | PIScrollBar* mScb;
|
---|
112 | PIMessage msgScb;
|
---|
113 | };
|
---|
114 |
|
---|
115 |
|
---|
116 | #endif
|
---|