1 /*
2   FXiTe - The Free eXtensIble Text Editor
3   Copyright (c) 2009-2013 Jeffrey Pohlmeyer <yetanothergeek@gmail.com>
4 
5   This program is free software; you can redistribute it and/or modify it
6   under the terms of the GNU General Public License version 3 as
7   published by the Free Software Foundation.
8 
9   This software is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13 
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18 
19 #include <fx.h>
20 
21 #include "color_funcs.h"
22 #include "menuspec.h"
23 #include "intl.h"
24 
25 #include "statusbar.h"
26 
27 
28 FXDEFMAP(StatusBar) StatusBarMap[]={};
29 
30 FXIMPLEMENT(StatusBar,FXHorizontalFrame,StatusBarMap,ARRAYNUMBER(StatusBarMap));
31 
32 
33 
StatusBar(FXComposite * p,void * dont_freeze)34 StatusBar::StatusBar(FXComposite *p, void* dont_freeze):
35     FXHorizontalFrame(p,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|FRAME_RAISED, 0,0,0,0, 3,3,3,3, 7,3)
36 {
37   coords=new FXTextField(this,12,NULL,FRAME_RAISED|FRAME_SUNKEN|TEXTFIELD_READONLY);
38   coords->setEditable(false);
39 
40   FXHorizontalFrame*hf=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|FRAME_NONE, 0,0,0,0, 0,0,0,0, 0,0);
41   docname=new FXTextField(hf, 1024, NULL, FRAME_RAISED|FRAME_SUNKEN|TEXTFIELD_READONLY|LAYOUT_FILL_X);
42   docname->setEditable(false);
43 
44   encname=new FXTextField(this, 8, NULL, FRAME_RAISED|FRAME_SUNKEN|TEXTFIELD_READONLY);
45   encname->setEditable(false);
46 
47   mode=new FXLabel(this, FXString::null, NULL,JUSTIFY_LEFT|LAYOUT_FIX_Y);
48   mode->setY(6);
49   mode->hide();
50   mode->setUserData(dont_freeze);
51 
52   Colorize();
53 }
54 
55 
56 
SetKillID(FXSelector kill_id)57 void StatusBar::SetKillID(FXSelector kill_id)
58 {
59   id_kill=kill_id;
60 }
61 
62 
63 
Coords(long line,long col)64 void StatusBar::Coords(long line, long col)
65 {
66   char rowcol[16];
67   memset(rowcol,0,sizeof(rowcol));
68   snprintf(rowcol,sizeof(rowcol)-1," %ld:%ld",line+1,col);
69   coords->setText(rowcol);
70 }
71 
72 
73 
FileInfo(const FXString & filename,const char * enc,long line,long column)74 void StatusBar::FileInfo(const FXString &filename, const char* enc, long line, long column)
75 {
76   docname->setText(filename);
77   encname->setText(enc);
78   Coords(line,column);
79 }
80 
81 
82 
Running(const char * what)83 void StatusBar::Running(const char*what)
84 {
85   FXString status;
86   status.format(_("Running %s (press %s to cancel)"), what, MenuMgr::LookupMenu(id_kill)->accel);
87   Mode(status.text());
88 }
89 
90 
91 
Normal()92 void StatusBar::Normal()
93 {
94   Mode("");
95 }
96 
97 
98 
Recording(bool recording)99 void StatusBar::Recording(bool recording)
100 {
101   Mode(recording?_("(recording)"):"");
102 }
103 
104 
105 
Clear()106 void StatusBar::Clear()
107 {
108   Normal();
109   docname->setText("");
110   encname->setText("");
111   Coords(0,0);
112 }
113 
114 
115 
Colorize()116 void StatusBar::Colorize()
117 {
118   FXColor clr=getBaseColor();
119   coords->setShadowColor(clr);
120   coords->setBackColor(clr);
121   coords->setEditable(false);
122   docname->setShadowColor(clr);
123   docname->setBackColor(clr);
124   encname->setShadowColor(clr);
125   encname->setBackColor(clr);
126   mode->setBackColor(HexToRGB("#FFFFCC"));
127   mode->setTextColor(HexToRGB("#FF0000"));
128 }
129 
130 
131 
Mode(const char * msg)132 void StatusBar::Mode(const char*msg)
133 {
134   mode->setText(msg);
135   if (msg&&*msg) {
136     mode->show();
137   } else {
138     mode->hide();
139   }
140 }
141 
142 
143 
Show(bool showit)144 void StatusBar::Show(bool showit)
145 {
146   if (showit) { show(); } else { hide(); }
147   getParent()->layout();  // <=Layout doesn't work right without this
148 }
149 
150