1 /**
2  *  Yudit Unicode Editor Source File
3  *
4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2,
8  *  dated June 1991. See file COPYYING for details.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef SToolBar_h
21 #define SToolBar_h
22 
23 #include "stoolkit/SProperties.h"
24 #include "swidget/SPanel.h"
25 #include "swidget/SButton.h"
26 #include "swidget/SLabel.h"
27 #include "stoolkit/SBinVector.h"
28 #include "stoolkit/SCharClass.h"
29 #include "stoolkit/SEvent.h"
30 
31 class SIconUpdater : public SEventTarget
32 {
33 public:
34   SIconUpdater (SWindow* _w, SButton* label,
35        int* currentEvent, int* displayEvent);
36   ~SIconUpdater();
37   bool timeout (const SEventSource* s);
38   void start ();
39   void setEncrypted(bool is);
40 private:
41   bool           isEncrypted;
42   SButton*       label;
43   int*           currentEvent;
44   int*           displayEvent;
45   STimer*        eventTimer;
46   SWindow*       window;
47 };
48 
49 /**
50  * A caret that redraws itself differently for lr and rl text
51  */
52 class SToolBarListener
53 {
54 public:
55   SToolBarListener(void);
56   virtual ~SToolBarListener();
57   virtual void toolBarButtonPressed (void* src, int button, bool accel)=0;
58   virtual void toolBarButtonEnter (void* src, int button);
59   virtual void toolBarButtonLeave (void* src, int button);
60 };
61 
62 class SToolBar  : public SPanel, public SButtonListener, public SSyntaxListener
63 {
64 public:
65   enum SButtonIndex {SS_OPEN=0,
66    SS_SAVE, SS_PRINT, SS_PRINT_PREVIEW, SS_FIND, SS_GOTO,
67    SS_UNDO, SS_REDO, SS_DOCUMENT_EMBEDDING, SS_SET_OVERRIDE, SS_SET_EMBEDDING,
68    SS_YIELD_EMBEDDING, SS_MAGNIFY_MINUS, SS_MAGNIFY_PLUS,
69    SS_HIGHLIGHTING,
70    SS_FONT, SS_INPUT, SS_PARAGRAPH_BREAK, SS_MAX };
71 
72   SToolBar (const SProperties props);
73   virtual ~SToolBar ();
74 
75   SButton* buttons[SS_MAX];
76   void setListener (SToolBarListener* listener);
77   void setFileName (const SString& fileName, const SString& encoding);
78   void setEncrypted (bool is);
79   void setHighlightName (const SString& _fileType);
80   void inputChanged (const SStringVector& _inputs, unsigned int _current);
81 
82   virtual void buttonPressedAccel (void* source, const SAccelerator* accel);
83   virtual void leaveComponent (void* source);
84   virtual void enterComponent (void* source);
85   virtual void redraw(SCanvas* w, int x, int y,
86      unsigned int width ,unsigned int height);
87   virtual void resize(const SDimension & d);
88   // SSyntaxListener
89   virtual void syntaxChanged (SS_EventType _evnt);
90 
91   unsigned int  currentFontSize;
92   SStringVector fontsizes;
93   unsigned int  currentInput;
94   SStringVector inputs;
95   unsigned int  currentFont;
96   SStringVector fonts;
97 
98   enum SFormatIndex { SS_FORMAT_UNIX=0, SS_FORMAT_DOS,
99      SS_FORMAT_MAC, SS_FORMAT_PS };
100 
101   void setParagraphSeparator (int index, bool notify);
102   void setEmbedding (SS_Embedding index, bool notify);
103 
104   SStringVector paragraphBreakStrings;
105   unsigned int  currentParagraphSeparator;
106   SS_Embedding  currentEmbedding;
107   SStringVector paragraphBreaks;
108   void          directionChanged (bool islr);
109   bool   editorLR;
110 
111   void   setModified (bool flag);
112   void   setPrinting (bool flag);
113 
114   bool   overrideLR;
115   bool   embedLR;
116   bool   currentLR;
117 
118   bool   modified;
119   bool   printing;
120 
121 private:
122   SOpaqueLabel*     title;
123   SOpaqueLabel*     titleEncoding;
124   SLabel*           tooltip;
125   SStringVector     displayInputs;
126   SIconUpdater*     iconUpdater;
127   SString           highlightName;
128 
129   void setFont (int index);
130   void setFontSize (int index);
131   void setInput (int index);
132   void setButton (SButtonIndex index, const SString& txt, bool notify);
133   void buildDisplayInputs();
134 
135   SDimension getMaxSize(SButton* b, const SStringVector&l, const SString& str);
136   void setFAccelerator (SButton* b, unsigned int se, bool ctrl);
137   int getFAccelerator (const SAccelerator* accel);
138   unsigned int preferredWidth;
139   SToolBarListener* listener;
140   bool  xmanagerCludge;
141   int   currentEvent;
142   int   displayEvent;
143 };
144 
145 #endif /* SToolBar_h */
146