1 /********************************************************************************
2 * *
3 * M e n u S e p a r a t o r W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,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: FXMenuSeparator.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 "FXApp.h"
37 #include "FXDCWindow.h"
38 #include "FXMenuSeparator.h"
39
40 /*
41 Notes:
42 - Accelerators.
43 - Help text from constructor is third part; second part should be
44 accelerator key combination.
45 - When menu label changes, hotkey might have to be adjusted.
46 - Fix it so menu stays up when after Alt-F, you press Alt-E.
47 - MenuItems should be derived from FXLabel.
48 - FXMenuCascade should send ID_POST/IDUNPOST to self.
49 */
50
51
52 #define LEADSPACE 22
53 #define TRAILSPACE 16
54
55 using namespace FX;
56
57 /*******************************************************************************/
58
59 namespace FX {
60
61 // Map
62 FXDEFMAP(FXMenuSeparator) FXMenuSeparatorMap[]={
63 FXMAPFUNC(SEL_PAINT,0,FXMenuSeparator::onPaint),
64 };
65
66
67 // Object implementation
FXIMPLEMENT(FXMenuSeparator,FXWindow,FXMenuSeparatorMap,ARRAYNUMBER (FXMenuSeparatorMap))68 FXIMPLEMENT(FXMenuSeparator,FXWindow,FXMenuSeparatorMap,ARRAYNUMBER(FXMenuSeparatorMap))
69
70
71 // Deserialization
72 FXMenuSeparator::FXMenuSeparator(){
73 flags|=FLAG_SHOWN;
74 }
75
76 // Separator item
FXMenuSeparator(FXComposite * p,FXuint opts)77 FXMenuSeparator::FXMenuSeparator(FXComposite* p,FXuint opts):
78 FXWindow(p,opts,0,0,0,0){
79 flags|=FLAG_SHOWN;
80 defaultCursor=getApp()->getDefaultCursor(DEF_RARROW_CURSOR);
81 hiliteColor=getApp()->getHiliteColor();
82 shadowColor=getApp()->getShadowColor();
83 }
84
85
86 // Handle repaint
onPaint(FXObject *,FXSelector,void * ptr)87 long FXMenuSeparator::onPaint(FXObject*,FXSelector,void* ptr){
88 FXEvent *ev=(FXEvent*)ptr;
89 FXDCWindow dc(this,ev);
90 dc.setForeground(backColor);
91 dc.fillRectangle(ev->rect.x,ev->rect.y,ev->rect.w,ev->rect.h);
92 dc.setForeground(shadowColor);
93 //dc.drawLine(1,0,width-1,0);
94 dc.fillRectangle(1,0,width,1);
95 dc.setForeground(hiliteColor);
96 //dc.drawLine(1,1,width-1,1);
97 dc.fillRectangle(1,1,width,1);
98 return 1;
99 }
100
101
102 // Get default size
getDefaultWidth()103 FXint FXMenuSeparator::getDefaultWidth(){
104 return LEADSPACE+TRAILSPACE;
105 }
106
107
getDefaultHeight()108 FXint FXMenuSeparator::getDefaultHeight(){
109 return 2;
110 }
111
112
113 // Set highlight color
setHiliteColor(FXColor clr)114 void FXMenuSeparator::setHiliteColor(FXColor clr){
115 if(clr!=hiliteColor){
116 hiliteColor=clr;
117 update();
118 }
119 }
120
121
122 // Set shadow color
setShadowColor(FXColor clr)123 void FXMenuSeparator::setShadowColor(FXColor clr){
124 if(clr!=shadowColor){
125 shadowColor=clr;
126 update();
127 }
128 }
129
130
131 // Save object to stream
save(FXStream & store) const132 void FXMenuSeparator::save(FXStream& store) const {
133 FXWindow::save(store);
134 store << hiliteColor;
135 store << shadowColor;
136 }
137
138
139 // Load object from stream
load(FXStream & store)140 void FXMenuSeparator::load(FXStream& store){
141 FXWindow::load(store);
142 store >> hiliteColor;
143 store >> shadowColor;
144 }
145
146 }
147
148