1 /********************************************************************************
2 * *
3 * C o l o r D i a l o g *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,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: FXColorDialog.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 "FXSettings.h"
36 #include "FXRegistry.h"
37 #include "FXApp.h"
38 #include "FXId.h"
39 #include "FXDrawable.h"
40 #include "FXWindow.h"
41 #include "FXFrame.h"
42 #include "FXLabel.h"
43 #include "FXButton.h"
44 #include "FXComposite.h"
45 #include "FXPacker.h"
46 #include "FXShell.h"
47 #include "FXTopWindow.h"
48 #include "FXDialogBox.h"
49 #include "FXColorSelector.h"
50 #include "FXColorDialog.h"
51
52
53 /*
54 Notes:
55 - Need shared instance of this dialog to pop up when double-clicking
56 on a color well.
57 */
58
59 using namespace FX;
60
61 /*******************************************************************************/
62
63 namespace FX {
64
65 // Map
66 FXDEFMAP(FXColorDialog) FXColorDialogMap[]={
67 FXMAPFUNC(SEL_CHANGED,FXColorDialog::ID_COLORSELECTOR,FXColorDialog::onChgColor),
68 FXMAPFUNC(SEL_COMMAND,FXColorDialog::ID_COLORSELECTOR,FXColorDialog::onCmdColor),
69 };
70
71
72 // Object implementation
FXIMPLEMENT(FXColorDialog,FXDialogBox,FXColorDialogMap,ARRAYNUMBER (FXColorDialogMap))73 FXIMPLEMENT(FXColorDialog,FXDialogBox,FXColorDialogMap,ARRAYNUMBER(FXColorDialogMap))
74
75
76
77 // Separator item
78 FXColorDialog::FXColorDialog(FXWindow* owner,const FXString& name,FXuint opts,FXint x,FXint y,FXint w,FXint h):
79 FXDialogBox(owner,name,opts|DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE|DECOR_CLOSE,x,y,w,h,0,0,0,0,4,4){
80 colorbox=new FXColorSelector(this,this,ID_COLORSELECTOR,LAYOUT_FILL_X|LAYOUT_FILL_Y);
81 colorbox->acceptButton()->setTarget(this);
82 colorbox->acceptButton()->setSelector(FXDialogBox::ID_ACCEPT);
83 colorbox->cancelButton()->setTarget(this);
84 colorbox->cancelButton()->setSelector(FXDialogBox::ID_CANCEL);
85 }
86
87
88 // Change RGBA color
setRGBA(FXColor clr)89 void FXColorDialog::setRGBA(FXColor clr){
90 colorbox->setRGBA(clr);
91 }
92
93
94 // Retrieve RGBA color
getRGBA() const95 FXColor FXColorDialog::getRGBA() const {
96 return colorbox->getRGBA();
97 }
98
99
100 // Forward ColorSelector color change to target [a color well]
onChgColor(FXObject *,FXSelector,void * ptr)101 long FXColorDialog::onChgColor(FXObject*,FXSelector,void* ptr){
102 return target && target->tryHandle(this,FXSEL(SEL_CHANGED,message),ptr);
103 }
104
105
106 // Forward ColorSelector color command to target [a color well]
onCmdColor(FXObject *,FXSelector,void * ptr)107 long FXColorDialog::onCmdColor(FXObject*,FXSelector,void* ptr){
108 return target && target->tryHandle(this,FXSEL(SEL_COMMAND,message),ptr);
109 }
110
111
112 // Return true if only opaque colors allowed
isOpaqueOnly() const113 FXbool FXColorDialog::isOpaqueOnly() const {
114 return colorbox->isOpaqueOnly();
115 }
116
117
118 // Change opaque only mode
setOpaqueOnly(FXbool forceopaque)119 void FXColorDialog::setOpaqueOnly(FXbool forceopaque){
120 colorbox->setOpaqueOnly(forceopaque);
121 }
122
123
124 // Save data
save(FXStream & store) const125 void FXColorDialog::save(FXStream& store) const {
126 FXDialogBox::save(store);
127 store << colorbox;
128 }
129
130
131 // Load data
load(FXStream & store)132 void FXColorDialog::load(FXStream& store){
133 FXDialogBox::load(store);
134 store >> colorbox;
135 }
136
137
138 // Cleanup
~FXColorDialog()139 FXColorDialog::~FXColorDialog(){
140 colorbox=(FXColorSelector*)-1L;
141 }
142
143 }
144