1 /********************************************************************************
2 * *
3 * S p l a s h W i n d o w *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,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: FXSplashWindow.cpp 3297 2015-12-14 20:30:04Z arthurcnorman $ *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "fxkeys.h"
28 #include "FXHash.h"
29 #include "FXThread.h"
30 #include "FXStream.h"
31 #include "FXString.h"
32 #include "FXSize.h"
33 #include "FXPoint.h"
34 #include "FXRectangle.h"
35 #include "FXRegistry.h"
36 #include "FXAccelTable.h"
37 #include "FXApp.h"
38 #include "FXAccelTable.h"
39 #include "FXDCWindow.h"
40 #include "FXShell.h"
41 #include "FXIcon.h"
42 #include "FXTopWindow.h"
43 #include "FXSplashWindow.h"
44
45 /*
46 Notes:
47
48 - We need to allow some additional widgets inside it (and layout options).
49 - We need to place it anywere, not just center of screen.
50 - Perhaps signal user has clicked or timer expired.
51 */
52
53 using namespace FX;
54
55
56 /*******************************************************************************/
57
58 namespace FX {
59
60
61 // Map
62 FXDEFMAP(FXSplashWindow) FXSplashWindowMap[]={
63 FXMAPFUNC(SEL_PAINT,0,FXSplashWindow::onPaint),
64 };
65
66
67 // Implementation
FXIMPLEMENT(FXSplashWindow,FXTopWindow,FXSplashWindowMap,ARRAYNUMBER (FXSplashWindowMap))68 FXIMPLEMENT(FXSplashWindow,FXTopWindow,FXSplashWindowMap,ARRAYNUMBER(FXSplashWindowMap))
69
70
71 // For deserialization
72 FXSplashWindow::FXSplashWindow(){
73 flags|=FLAG_ENABLED;
74 }
75
76
77 // Splash window
FXSplashWindow(FXApp * ap,FXIcon * ic,FXuint opts,FXuint ms)78 FXSplashWindow::FXSplashWindow(FXApp* ap,FXIcon* ic,FXuint opts,FXuint ms):FXTopWindow(ap,FXString::null,NULL,NULL,opts&~DECOR_ALL,0,0,ic->getWidth(),ic->getHeight(),0,0,0,0,0,0){
79 flags|=FLAG_ENABLED;
80 delay=ms;
81 icon=ic;
82 }
83
84
85 // Splash window
FXSplashWindow(FXWindow * ow,FXIcon * ic,FXuint opts,FXuint ms)86 FXSplashWindow::FXSplashWindow(FXWindow* ow,FXIcon* ic,FXuint opts,FXuint ms):FXTopWindow(ow,FXString::null,NULL,NULL,opts&~DECOR_ALL,0,0,ic->getWidth(),ic->getHeight(),0,0,0,0,0,0){
87 flags|=FLAG_ENABLED;
88 delay=ms;
89 icon=ic;
90 }
91
92
93 // Create and show window
create()94 void FXSplashWindow::create(){
95 FXTopWindow::create();
96 icon->create();
97 if(options&SPLASH_SHAPED) setShape(icon);
98 }
99
100
101 // Detach window
detach()102 void FXSplashWindow::detach(){
103 FXTopWindow::detach();
104 icon->detach();
105 }
106
107
108 // Show splash window
show()109 void FXSplashWindow::show(){
110 if(!shown()){
111 FXTopWindow::show();
112 if(options&SPLASH_DESTROY){
113 getApp()->addTimeout(this,ID_DELETE,delay);
114 }
115 else{
116 getApp()->addTimeout(this,ID_HIDE,delay);
117 }
118 }
119 }
120
121
122 // Show splash window with a given placement
show(FXuint placement)123 void FXSplashWindow::show(FXuint placement){
124 if(!shown()){
125 FXTopWindow::show(placement);
126 if(options&SPLASH_DESTROY){
127 getApp()->addTimeout(this,ID_DELETE,delay);
128 }
129 else{
130 getApp()->addTimeout(this,ID_HIDE,delay);
131 }
132 }
133 }
134
135
136 // Hide splash window
hide()137 void FXSplashWindow::hide(){
138 if(shown()){
139 FXTopWindow::hide();
140 if(options&SPLASH_DESTROY){
141 getApp()->removeTimeout(this,ID_DELETE);
142 }
143 else{
144 getApp()->removeTimeout(this,ID_HIDE);
145 }
146 }
147 }
148
149
150 // Get default width
getDefaultWidth()151 FXint FXSplashWindow::getDefaultWidth(){
152 return icon->getWidth();
153 }
154
155
156 // Get default height
getDefaultHeight()157 FXint FXSplashWindow::getDefaultHeight(){
158 return icon->getHeight();
159 }
160
161
162 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)163 long FXSplashWindow::onPaint(FXObject*,FXSelector,void* ptr){
164 FXDCWindow dc(this,(FXEvent*)ptr);
165 dc.setForeground(backColor);
166 dc.fillRectangle(0,0,width,height);
167 dc.drawIcon(icon,0,0);
168 return 1;
169 }
170
171
172 // Change icon
setIcon(FXIcon * ic)173 void FXSplashWindow::setIcon(FXIcon* ic){
174 if(icon!=ic){
175 icon=ic;
176 if(options&SPLASH_SHAPED) setShape(icon);
177 resize(icon->getWidth(),icon->getHeight());
178 update();
179 }
180 }
181
182
183 // Set or change delay
setDelay(FXuint ms)184 void FXSplashWindow::setDelay(FXuint ms){
185 delay=ms;
186 if(shown()){
187 if(options&SPLASH_DESTROY){
188 getApp()->addTimeout(this,ID_DELETE,delay);
189 }
190 else{
191 getApp()->addTimeout(this,ID_HIDE,delay);
192 }
193 }
194 }
195
196
197 // Save object to stream
save(FXStream & store) const198 void FXSplashWindow::save(FXStream& store) const {
199 FXTopWindow::save(store);
200 store << icon;
201 store << delay;
202 }
203
204
205 // Load object from stream
load(FXStream & store)206 void FXSplashWindow::load(FXStream& store){
207 FXTopWindow::load(store);
208 store >> icon;
209 store >> delay;
210 }
211
212
213 // Destroy main window
~FXSplashWindow()214 FXSplashWindow::~FXSplashWindow(){
215 getApp()->removeTimeout(this,ID_DELETE);
216 getApp()->removeTimeout(this,ID_HIDE);
217 if(options&SPLASH_OWNS_ICON) delete icon;
218 icon=(FXIcon*)-1L;
219 }
220
221 }
222