1 /********************************************************************************
2 *                                                                               *
3 *                       S t a t u s   L i n e   W i d g e t                     *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1999,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXStatusLine.cpp 3297 2015-12-14 20:30:04Z arthurcnorman $                    *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "FXHash.h"
28 #include "FXThread.h"
29 #include "FXStream.h"
30 #include "FXString.h"
31 #include "FXSize.h"
32 #include "FXPoint.h"
33 #include "FXRectangle.h"
34 #include "FXRegistry.h"
35 #include "FXAccelTable.h"
36 #include "FXApp.h"
37 #include "FXDCWindow.h"
38 #include "FXFont.h"
39 #include "FXHorizontalFrame.h"
40 #include "FXDragCorner.h"
41 #include "FXStatusLine.h"
42 
43 
44 
45 /*
46   Notes:
47   - Fallback text is displayed when neither cursor window or
48     target object supply temporary help string.
49   - Show only status line information from same topwindow as where
50     status line is
51 */
52 
53 using namespace FX;
54 
55 /*******************************************************************************/
56 
57 namespace FX {
58 
59 // Map
60 FXDEFMAP(FXStatusLine) FXStatusLineMap[]={
61   FXMAPFUNC(SEL_PAINT,0,FXStatusLine::onPaint),
62   FXMAPFUNC(SEL_UPDATE,0,FXStatusLine::onUpdate),
63   FXMAPFUNC(SEL_COMMAND,FXStatusLine::ID_SETSTRINGVALUE,FXStatusLine::onCmdSetStringValue),
64   FXMAPFUNC(SEL_COMMAND,FXStatusLine::ID_GETSTRINGVALUE,FXStatusLine::onCmdGetStringValue),
65   };
66 
67 
68 // Object implementation
FXIMPLEMENT(FXStatusLine,FXFrame,FXStatusLineMap,ARRAYNUMBER (FXStatusLineMap))69 FXIMPLEMENT(FXStatusLine,FXFrame,FXStatusLineMap,ARRAYNUMBER(FXStatusLineMap))
70 
71 
72 // Deserialization
73 FXStatusLine::FXStatusLine(){
74   flags|=FLAG_SHOWN;
75   }
76 
77 
78 // Construct and init
FXStatusLine(FXComposite * p,FXObject * tgt,FXSelector sel)79 FXStatusLine::FXStatusLine(FXComposite* p,FXObject* tgt,FXSelector sel):
80   FXFrame(p,FRAME_SUNKEN|LAYOUT_LEFT|LAYOUT_FILL_Y|LAYOUT_FILL_X,0,0,0,0, 4,4,2,2){
81   flags|=FLAG_SHOWN;
82   status=normal=tr("Ready.");
83   font=getApp()->getNormalFont();
84   textColor=getApp()->getForeColor();
85   textHighlightColor=getApp()->getForeColor();
86   target=tgt;
87   message=sel;
88   }
89 
90 
91 // Create Window
create()92 void FXStatusLine::create(){
93   FXFrame::create();
94   font->create();
95   }
96 
97 
98 // Detach Window
detach()99 void FXStatusLine::detach(){
100   FXFrame::detach();
101   font->detach();
102   }
103 
104 
105 // Get default width; as text changes often, exact content does not matter
getDefaultWidth()106 FXint FXStatusLine::getDefaultWidth(){
107   return padleft+padright+(border<<1)+8;
108   }
109 
110 
111 // Get default height; just care about font height
getDefaultHeight()112 FXint FXStatusLine::getDefaultHeight(){
113   return font->getFontHeight()+padtop+padbottom+(border<<1);
114   }
115 
116 
117 // Slightly different from Frame border
onPaint(FXObject *,FXSelector,void * ptr)118 long FXStatusLine::onPaint(FXObject*,FXSelector,void* ptr){
119   FXEvent *ev=(FXEvent*)ptr;
120   FXDCWindow dc(this,ev);
121   FXint ty=padtop+(height-padtop-padbottom-font->getFontHeight())/2;
122   FXint pos,len;
123   dc.setForeground(backColor);
124   dc.fillRectangle(ev->rect.x,ev->rect.y,ev->rect.w,ev->rect.h);
125   if(!status.empty()){
126     dc.setFont(font);
127     pos=status.find('\n');
128     len=status.length();
129     if(pos>=0){
130       dc.setForeground(textHighlightColor);
131       dc.drawText(padleft,ty+font->getFontAscent(),status.text(),pos);
132       dc.setForeground(textColor);
133       dc.drawText(padleft+font->getTextWidth(status.text(),pos),ty+font->getFontAscent(),status.text()+pos+1,len-pos-1);
134       }
135     else{
136       dc.setForeground(textColor);
137       dc.drawText(padleft,ty+font->getFontAscent(),status.text(),len);
138       }
139     }
140   drawFrame(dc,0,0,width,height);
141   return 1;
142   }
143 
144 
145 // If the cursor is inside a widget, flash its help text;
146 // Otherwise, unflash back to the regular status message.
onUpdate(FXObject * sender,FXSelector sel,void * ptr)147 long FXStatusLine::onUpdate(FXObject* sender,FXSelector sel,void* ptr){
148   FXWindow *helpsource=getApp()->getCursorWindow();
149 
150   // Regular GUI update
151   FXFrame::onUpdate(sender,sel,ptr);
152 
153   // Ask the help source for a new status text first, but only if the
154   // statusline's shell is a direct or indirect owner of the help source
155   if(helpsource && getShell()->isOwnerOf(helpsource) && helpsource->handle(this,FXSEL(SEL_QUERY_HELP,0),NULL)){
156     return 1;
157     }
158 
159   // Otherwise, supply normal message
160   setText(normal);
161   return 1;
162   }
163 
164 
165 // Update value from a message
onCmdSetStringValue(FXObject *,FXSelector,void * ptr)166 long FXStatusLine::onCmdSetStringValue(FXObject*,FXSelector,void* ptr){
167   setText(*((FXString*)ptr));
168   return 1;
169   }
170 
171 
172 // Obtain value from text field
onCmdGetStringValue(FXObject *,FXSelector,void * ptr)173 long FXStatusLine::onCmdGetStringValue(FXObject*,FXSelector,void* ptr){
174   *((FXString*)ptr)=getText();
175   return 1;
176   }
177 
178 
179 // Set currently displayed message
setText(const FXString & text)180 void FXStatusLine::setText(const FXString& text){
181   if(status!=text){
182     status=text;
183     update(border,border,width-(border<<1),height-(border<<1));
184     repaint(border,border,width-(border<<1),height-(border<<1));
185     getApp()->flush();
186     }
187   }
188 
189 
190 // Set permanently displayed message
setNormalText(const FXString & text)191 void FXStatusLine::setNormalText(const FXString& text){
192   if(normal!=text){
193     normal=text;
194     update(border,border,width-(border<<1),height-(border<<1));
195     repaint(border,border,width-(border<<1),height-(border<<1));
196     getApp()->flush();
197     }
198   }
199 
200 
201 // Change the font
setFont(FXFont * fnt)202 void FXStatusLine::setFont(FXFont* fnt){
203   if(!fnt){ fxerror("%s::setFont: NULL font specified.\n",getClassName()); }
204   if(font!=fnt){
205     font=fnt;
206     recalc();
207     update();
208     }
209   }
210 
211 
212 // Set text color
setTextColor(FXColor clr)213 void FXStatusLine::setTextColor(FXColor clr){
214   if(textColor!=clr){
215     textColor=clr;
216     update(border,border,width-(border<<1),height-(border<<1));
217     }
218   }
219 
220 
221 // Set text highlight color
setTextHighlightColor(FXColor clr)222 void FXStatusLine::setTextHighlightColor(FXColor clr){
223   if(textHighlightColor!=clr){
224     textHighlightColor=clr;
225     update(border,border,width-(border<<1),height-(border<<1));
226     }
227   }
228 
229 
230 // Save object to stream
save(FXStream & store) const231 void FXStatusLine::save(FXStream& store) const {
232   FXFrame::save(store);
233   store << status;
234   store << normal;
235   store << font;
236   store << textColor;
237   store << textHighlightColor;
238   }
239 
240 
241 // Load object from stream
load(FXStream & store)242 void FXStatusLine::load(FXStream& store){
243   FXFrame::load(store);
244   store >> status;
245   store >> normal;
246   store >> font;
247   store >> textColor;
248   store >> textHighlightColor;
249   }
250 
251 
252 // Destruct
~FXStatusLine()253 FXStatusLine::~FXStatusLine(){
254   font=(FXFont*)-1L;
255   }
256 
257 }
258