1 /********************************************************************************
2 * *
3 * C o l o r D i a l o g *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,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 "FXEvent.h"
38 #include "FXWindow.h"
39 #include "FXApp.h"
40 #include "FXFrame.h"
41 #include "FXLabel.h"
42 #include "FXButton.h"
43 #include "FXComposite.h"
44 #include "FXPacker.h"
45 #include "FXShell.h"
46 #include "FXTopWindow.h"
47 #include "FXDialogBox.h"
48 #include "FXColorSelector.h"
49 #include "FXColorDialog.h"
50
51
52 /*
53 Notes:
54 - Need shared instance of this dialog to pop up when double-clicking
55 on a color well.
56 */
57
58 using namespace FX;
59
60 /*******************************************************************************/
61
62 namespace FX {
63
64 // Color dialog registry section name
65 const FXchar FXColorDialog::sectionName[]="Color Dialog";
66
67
68 // Map
69 FXDEFMAP(FXColorDialog) FXColorDialogMap[]={
70 FXMAPFUNC(SEL_CHANGED,FXColorDialog::ID_COLORSELECTOR,FXColorDialog::onChgColor),
71 FXMAPFUNC(SEL_COMMAND,FXColorDialog::ID_COLORSELECTOR,FXColorDialog::onCmdColor),
72 FXMAPFUNC(SEL_COMMAND,FXColorDialog::ID_SETINTVALUE,FXColorDialog::onCmdSetIntValue),
73 FXMAPFUNC(SEL_COMMAND,FXColorDialog::ID_GETINTVALUE,FXColorDialog::onCmdGetIntValue),
74 };
75
76
77 // Object implementation
FXIMPLEMENT(FXColorDialog,FXDialogBox,FXColorDialogMap,ARRAYNUMBER (FXColorDialogMap))78 FXIMPLEMENT(FXColorDialog,FXDialogBox,FXColorDialogMap,ARRAYNUMBER(FXColorDialogMap))
79
80
81 // Construct color dialog box
82 FXColorDialog::FXColorDialog(FXWindow* own,const FXString& name,FXuint opts,FXint x,FXint y,FXint w,FXint h):FXDialogBox(own,name,opts|DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_CLOSE,x,y,w,h,0,0,0,0,4,4){
83 colorbox=new FXColorSelector(this,this,ID_COLORSELECTOR,LAYOUT_FILL_X|LAYOUT_FILL_Y);
84 colorbox->acceptButton()->setTarget(this);
85 colorbox->acceptButton()->setSelector(FXDialogBox::ID_ACCEPT);
86 colorbox->cancelButton()->setTarget(this);
87 colorbox->cancelButton()->setSelector(FXDialogBox::ID_CANCEL);
88 }
89
90
91 // Construct free-floating color dialog box
FXColorDialog(FXApp * a,const FXString & name,FXuint opts,FXint x,FXint y,FXint w,FXint h)92 FXColorDialog::FXColorDialog(FXApp* a,const FXString& name,FXuint opts,FXint x,FXint y,FXint w,FXint h):FXDialogBox(a,name,opts|DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_CLOSE,x,y,w,h,0,0,0,0,4,4){
93 colorbox=new FXColorSelector(this,this,ID_COLORSELECTOR,LAYOUT_FILL_X|LAYOUT_FILL_Y);
94 colorbox->acceptButton()->setTarget(this);
95 colorbox->acceptButton()->setSelector(FXDialogBox::ID_ACCEPT);
96 colorbox->cancelButton()->setTarget(this);
97 colorbox->cancelButton()->setSelector(FXDialogBox::ID_CANCEL);
98 }
99
100
101 // Create server-side resources
create()102 void FXColorDialog::create(){
103 setActivePanel(getApp()->reg().readIntEntry(sectionName,"activecolorpane",COLORTAB_COLOR_RING));
104 setWellColor( 0,getApp()->reg().readColorEntry(sectionName,"WA",FXRGBA(255,255,255,255)));
105 setWellColor( 1,getApp()->reg().readColorEntry(sectionName,"WB",FXRGBA(204,204,204,255)));
106 setWellColor( 2,getApp()->reg().readColorEntry(sectionName,"WC",FXRGBA(153,153,153,255)));
107 setWellColor( 3,getApp()->reg().readColorEntry(sectionName,"WD",FXRGBA(102,102,102,255)));
108 setWellColor( 4,getApp()->reg().readColorEntry(sectionName,"WE",FXRGBA( 51, 51, 51,255)));
109 setWellColor( 5,getApp()->reg().readColorEntry(sectionName,"WF",FXRGBA( 0, 0, 0,255)));
110 setWellColor( 6,getApp()->reg().readColorEntry(sectionName,"WG",FXRGBA(255, 0, 0,255)));
111 setWellColor( 7,getApp()->reg().readColorEntry(sectionName,"WH",FXRGBA( 0,255, 0,255)));
112 setWellColor( 8,getApp()->reg().readColorEntry(sectionName,"WI",FXRGBA( 0, 0,255,255)));
113 setWellColor( 9,getApp()->reg().readColorEntry(sectionName,"WJ",FXRGBA( 0,255,255,255)));
114 setWellColor(10,getApp()->reg().readColorEntry(sectionName,"WK",FXRGBA(255,255, 0,255)));
115 setWellColor(11,getApp()->reg().readColorEntry(sectionName,"WL",FXRGBA(255, 0,255,255)));
116 setWellColor(12,getApp()->reg().readColorEntry(sectionName,"WM",FXRGBA(255,165, 0,255)));
117 setWellColor(13,getApp()->reg().readColorEntry(sectionName,"WN",FXRGBA(153, 0, 0,255)));
118 setWellColor(14,getApp()->reg().readColorEntry(sectionName,"WO",FXRGBA( 0,153, 0,255)));
119 setWellColor(15,getApp()->reg().readColorEntry(sectionName,"WP",FXRGBA( 0, 0,153,255)));
120 setWellColor(16,getApp()->reg().readColorEntry(sectionName,"WQ",FXRGBA( 0,153,153,255)));
121 setWellColor(17,getApp()->reg().readColorEntry(sectionName,"WR",FXRGBA(153,153, 0,255)));
122 setWellColor(18,getApp()->reg().readColorEntry(sectionName,"WS",FXRGBA(153, 0,153,255)));
123 setWellColor(19,getApp()->reg().readColorEntry(sectionName,"WT",FXRGBA(255,175,175,255)));
124 setWellColor(20,getApp()->reg().readColorEntry(sectionName,"WU",FXRGBA(175,255,175,255)));
125 setWellColor(21,getApp()->reg().readColorEntry(sectionName,"WV",FXRGBA(175,175,255,255)));
126 setWellColor(22,getApp()->reg().readColorEntry(sectionName,"WW",FXRGBA(175,255,255,255)));
127 setWellColor(23,getApp()->reg().readColorEntry(sectionName,"WX",FXRGBA(255,255,175,255)));
128 FXDialogBox::create();
129 }
130
131
132 // Destroy server-side resources
destroy()133 void FXColorDialog::destroy(){
134 getApp()->reg().writeIntEntry(sectionName,"activecolorpane",getActivePanel());
135 getApp()->reg().writeColorEntry(sectionName,"WA",getWellColor( 0));
136 getApp()->reg().writeColorEntry(sectionName,"WB",getWellColor( 1));
137 getApp()->reg().writeColorEntry(sectionName,"WC",getWellColor( 2));
138 getApp()->reg().writeColorEntry(sectionName,"WD",getWellColor( 3));
139 getApp()->reg().writeColorEntry(sectionName,"WE",getWellColor( 4));
140 getApp()->reg().writeColorEntry(sectionName,"WF",getWellColor( 5));
141 getApp()->reg().writeColorEntry(sectionName,"WG",getWellColor( 6));
142 getApp()->reg().writeColorEntry(sectionName,"WH",getWellColor( 7));
143 getApp()->reg().writeColorEntry(sectionName,"WI",getWellColor( 8));
144 getApp()->reg().writeColorEntry(sectionName,"WJ",getWellColor( 9));
145 getApp()->reg().writeColorEntry(sectionName,"WK",getWellColor(10));
146 getApp()->reg().writeColorEntry(sectionName,"WL",getWellColor(11));
147 getApp()->reg().writeColorEntry(sectionName,"WM",getWellColor(12));
148 getApp()->reg().writeColorEntry(sectionName,"WN",getWellColor(13));
149 getApp()->reg().writeColorEntry(sectionName,"WO",getWellColor(14));
150 getApp()->reg().writeColorEntry(sectionName,"WP",getWellColor(15));
151 getApp()->reg().writeColorEntry(sectionName,"WQ",getWellColor(16));
152 getApp()->reg().writeColorEntry(sectionName,"WR",getWellColor(17));
153 getApp()->reg().writeColorEntry(sectionName,"WS",getWellColor(18));
154 getApp()->reg().writeColorEntry(sectionName,"WT",getWellColor(19));
155 getApp()->reg().writeColorEntry(sectionName,"WU",getWellColor(20));
156 getApp()->reg().writeColorEntry(sectionName,"WV",getWellColor(21));
157 getApp()->reg().writeColorEntry(sectionName,"WW",getWellColor(22));
158 getApp()->reg().writeColorEntry(sectionName,"WX",getWellColor(23));
159 FXDialogBox::destroy();
160 }
161
162
163 // Change RGBA color
setRGBA(FXColor clr)164 void FXColorDialog::setRGBA(FXColor clr){
165 colorbox->setRGBA(clr);
166 }
167
168
169 // Retrieve RGBA color
getRGBA() const170 FXColor FXColorDialog::getRGBA() const {
171 return colorbox->getRGBA();
172 }
173
174
175 // Forward ColorSelector color change to target [a color well]
onChgColor(FXObject *,FXSelector,void * ptr)176 long FXColorDialog::onChgColor(FXObject*,FXSelector,void* ptr){
177 return target && target->tryHandle(this,FXSEL(SEL_CHANGED,message),ptr);
178 }
179
180
181 // Forward ColorSelector color command to target [a color well]
onCmdColor(FXObject *,FXSelector,void * ptr)182 long FXColorDialog::onCmdColor(FXObject*,FXSelector,void* ptr){
183 return target && target->tryHandle(this,FXSEL(SEL_COMMAND,message),ptr);
184 }
185
186
187 // Update color dialog from a message
onCmdSetIntValue(FXObject *,FXSelector,void * ptr)188 long FXColorDialog::onCmdSetIntValue(FXObject*,FXSelector,void* ptr){
189 setRGBA(*((FXColor*)ptr));
190 return 1;
191 }
192
193
194 // Obtain value from color dialog
onCmdGetIntValue(FXObject *,FXSelector,void * ptr)195 long FXColorDialog::onCmdGetIntValue(FXObject*,FXSelector,void* ptr){
196 *((FXColor*)ptr)=getRGBA();
197 return 1;
198 }
199
200
201 // Change active panel
setActivePanel(FXint pnl)202 void FXColorDialog::setActivePanel(FXint pnl){
203 colorbox->setActivePanel(pnl);
204 }
205
206
207 // Return active panel
getActivePanel() const208 FXint FXColorDialog::getActivePanel() const {
209 return colorbox->getActivePanel();
210 }
211
212
213 // Change well color
setWellColor(FXint w,FXColor clr)214 void FXColorDialog::setWellColor(FXint w,FXColor clr){
215 colorbox->setWellColor(w,clr);
216 }
217
218
219 // Return well color
getWellColor(FXint w) const220 FXColor FXColorDialog::getWellColor(FXint w) const {
221 return colorbox->getWellColor(w);
222 }
223
224
225 // Change opaque only mode
setOpaqueOnly(FXbool forceopaque)226 void FXColorDialog::setOpaqueOnly(FXbool forceopaque){
227 colorbox->setOpaqueOnly(forceopaque);
228 }
229
230
231 // Return true if only opaque colors allowed
isOpaqueOnly() const232 FXbool FXColorDialog::isOpaqueOnly() const {
233 return colorbox->isOpaqueOnly();
234 }
235
236
237 // Save data
save(FXStream & store) const238 void FXColorDialog::save(FXStream& store) const {
239 FXDialogBox::save(store);
240 store << colorbox;
241 }
242
243
244 // Load data
load(FXStream & store)245 void FXColorDialog::load(FXStream& store){
246 FXDialogBox::load(store);
247 store >> colorbox;
248 }
249
250
251 // Cleanup
~FXColorDialog()252 FXColorDialog::~FXColorDialog(){
253 destroy();
254 colorbox=(FXColorSelector*)-1L;
255 }
256
257 }
258