1 /********************************************************************************
2 *                                                                               *
3 *                            S p l a s h    W i n d o w                         *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2004,2021 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU Lesser General Public License as published by   *
10 * the Free Software Foundation; either version 3 of the License, or             *
11 * (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                 *
16 * GNU Lesser General Public License for more details.                           *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public License      *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
20 ********************************************************************************/
21 #include "xincs.h"
22 #include "fxver.h"
23 #include "fxdefs.h"
24 #include "fxmath.h"
25 #include "fxkeys.h"
26 #include "FXArray.h"
27 #include "FXHash.h"
28 #include "FXMutex.h"
29 #include "FXStream.h"
30 #include "FXString.h"
31 #include "FXSize.h"
32 #include "FXPoint.h"
33 #include "FXRectangle.h"
34 #include "FXStringDictionary.h"
35 #include "FXSettings.h"
36 #include "FXRegistry.h"
37 #include "FXAccelTable.h"
38 #include "FXEvent.h"
39 #include "FXWindow.h"
40 #include "FXDCWindow.h"
41 #include "FXApp.h"
42 #include "FXShell.h"
43 #include "FXIcon.h"
44 #include "FXTopWindow.h"
45 #include "FXSplashWindow.h"
46 
47 /*
48   Notes:
49 
50   - We need to allow some additional widgets inside it (and layout options).
51   - We need to place it anywere, not just center of screen.
52   - Perhaps signal user has clicked or timer expired.
53 */
54 
55 using namespace FX;
56 
57 
58 /*******************************************************************************/
59 
60 namespace FX {
61 
62 
63 // Map
64 FXDEFMAP(FXSplashWindow) FXSplashWindowMap[]={
65   FXMAPFUNC(SEL_PAINT,0,FXSplashWindow::onPaint),
66   };
67 
68 
69 // Implementation
FXIMPLEMENT(FXSplashWindow,FXTopWindow,FXSplashWindowMap,ARRAYNUMBER (FXSplashWindowMap))70 FXIMPLEMENT(FXSplashWindow,FXTopWindow,FXSplashWindowMap,ARRAYNUMBER(FXSplashWindowMap))
71 
72 
73 // For deserialization
74 FXSplashWindow::FXSplashWindow(){
75   flags|=FLAG_ENABLED;
76   icon=NULL;
77   delay=0;
78   }
79 
80 
81 // Splash window
FXSplashWindow(FXApp * ap,FXIcon * ic,FXuint opts,FXTime ns)82 FXSplashWindow::FXSplashWindow(FXApp* ap,FXIcon* ic,FXuint opts,FXTime ns):FXTopWindow(ap,FXString::null,NULL,NULL,opts&~DECOR_ALL,0,0,ic->getWidth(),ic->getHeight(),0,0,0,0,0,0){
83   flags|=FLAG_ENABLED;
84   delay=ns;
85   icon=ic;
86   }
87 
88 
89 // Splash window
FXSplashWindow(FXWindow * ow,FXIcon * ic,FXuint opts,FXTime ns)90 FXSplashWindow::FXSplashWindow(FXWindow* ow,FXIcon* ic,FXuint opts,FXTime ns):FXTopWindow(ow,FXString::null,NULL,NULL,opts&~DECOR_ALL,0,0,ic->getWidth(),ic->getHeight(),0,0,0,0,0,0){
91   flags|=FLAG_ENABLED;
92   delay=ns;
93   icon=ic;
94   }
95 
96 
97 // Create and show window
create()98 void FXSplashWindow::create(){
99   FXTopWindow::create();
100   icon->create();
101   if(options&SPLASH_SHAPED) setShape(icon);
102   }
103 
104 //#ifndef WIN32
105 //  Atom list[2]={getApp()->wmWindowTypes[5],getApp()->wmWindowTypes[13]};
106 //  XChangeProperty((Display*)getApp()->getDisplay(),xid,getApp()->wmNetWindowType,XA_ATOM,32,PropModeReplace,(unsigned char*)list,2);
107 //#endif
108 
109 // Detach window
detach()110 void FXSplashWindow::detach(){
111   FXTopWindow::detach();
112   icon->detach();
113   }
114 
115 
116 // Show splash window
show()117 void FXSplashWindow::show(){
118   if(!shown()){
119     FXTopWindow::show();
120     if(options&SPLASH_DESTROY){
121       getApp()->addTimeout(this,ID_DELETE,delay);
122       }
123     else{
124       getApp()->addTimeout(this,ID_HIDE,delay);
125       }
126     }
127   }
128 
129 
130 // Show splash window with a given placement
show(FXuint placement)131 void FXSplashWindow::show(FXuint placement){
132   if(!shown()){
133     FXTopWindow::show(placement);
134     if(options&SPLASH_DESTROY){
135       getApp()->addTimeout(this,ID_DELETE,delay);
136       }
137     else{
138       getApp()->addTimeout(this,ID_HIDE,delay);
139       }
140     }
141   }
142 
143 
144 // Hide splash window
hide()145 void FXSplashWindow::hide(){
146   if(shown()){
147     FXTopWindow::hide();
148     if(options&SPLASH_DESTROY){
149       getApp()->removeTimeout(this,ID_DELETE);
150       }
151     else{
152       getApp()->removeTimeout(this,ID_HIDE);
153       }
154     }
155   }
156 
157 
158 // Get default width
getDefaultWidth()159 FXint FXSplashWindow::getDefaultWidth(){
160   return icon->getWidth();
161   }
162 
163 
164 // Get default height
getDefaultHeight()165 FXint FXSplashWindow::getDefaultHeight(){
166   return icon->getHeight();
167   }
168 
169 
170 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)171 long FXSplashWindow::onPaint(FXObject*,FXSelector,void* ptr){
172   FXDCWindow dc(this,(FXEvent*)ptr);
173   dc.setForeground(backColor);
174   dc.fillRectangle(0,0,width,height);
175   dc.drawIcon(icon,0,0);
176   return 1;
177   }
178 
179 
180 // Change icon
setIcon(FXIcon * ic)181 void FXSplashWindow::setIcon(FXIcon* ic){
182   if(icon!=ic){
183     icon=ic;
184     if(options&SPLASH_SHAPED) setShape(icon);
185     resize(icon->getWidth(),icon->getHeight());
186     update();
187     }
188   }
189 
190 
191 // Set or change delay
setDelay(FXTime ns)192 void FXSplashWindow::setDelay(FXTime ns){
193   delay=ns;
194   if(shown()){
195     if(options&SPLASH_DESTROY){
196       getApp()->addTimeout(this,ID_DELETE,delay);
197       }
198     else{
199       getApp()->addTimeout(this,ID_HIDE,delay);
200       }
201     }
202   }
203 
204 
205 // Save object to stream
save(FXStream & store) const206 void FXSplashWindow::save(FXStream& store) const {
207   FXTopWindow::save(store);
208   store << icon;
209   store << delay;
210   }
211 
212 
213 // Load object from stream
load(FXStream & store)214 void FXSplashWindow::load(FXStream& store){
215   FXTopWindow::load(store);
216   store >> icon;
217   store >> delay;
218   }
219 
220 
221 // Destroy main window
~FXSplashWindow()222 FXSplashWindow::~FXSplashWindow(){
223   getApp()->removeTimeout(this,ID_DELETE);
224   getApp()->removeTimeout(this,ID_HIDE);
225   if(options&SPLASH_OWNS_ICON) delete icon;
226   icon=(FXIcon*)-1L;
227   }
228 
229 }
230