1 /* vim:tabstop=4:expandtab:shiftwidth=4
2 *
3 * Idesk -- XIconWithShadow.cpp
4 *
5 * Copyright (c) 2002, Chris (nikon) (nikon@sc.rr.com)
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name of the <ORGANIZATION> nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * (See the included file COPYING / BSD )
23 */
24
25 #include "XIconWithShadow.h"
26 #include "XImlib2Shadow.h"
27
XIconWithShadow(AbstractContainer * cont,AbstractConfig * con,AbstractIconConfig * iConfig)28 XIconWithShadow::XIconWithShadow(AbstractContainer * cont, AbstractConfig * con,
29 AbstractIconConfig * iConfig)
30 : XIcon(cont, con, iConfig)
31 {
32 //cout << "XIconWithShadow()\n";
33 DesktopIconConfig * dIcon = dynamic_cast<DesktopIconConfig *>(iconConfig);
34
35 valid = true;
36
37 if (dIcon->isRaster())
38 shadowImage = new XImlib2Shadow(cont, this, config, iconConfig);
39 else
40 {
41 cout << "Unknown file format:" << iconConfig->getPictureFilename() << "\n" << endl;
42 // implement way to skip icon and not segfault
43 valid = false;
44 }
45 }
46
~XIconWithShadow()47 XIconWithShadow::~XIconWithShadow()
48 {
49 delete shadowImage;
50 }
51
createIcon()52 bool XIconWithShadow::createIcon()
53 {
54 if(!XIcon::createIcon()) return false;
55
56 XImlib2Shadow * sImage = dynamic_cast<XImlib2Shadow *>(shadowImage);
57
58 shadowVisible = false;
59 sImage->configure();
60 sImage->createWindow();
61 sImage->initalize();
62 sImage->lowerWindow();
63 return true;
64 }
65
dragMotionNotify(XEvent ev)66 void XIconWithShadow::dragMotionNotify(XEvent ev)
67 {
68 XIcon::dragMotionNotify(ev);
69
70 //XImlib2Image * sImage = dynamic_cast<XImlib2Image *>(shadowImage);
71 //sImage->repaint();
72 shadowImage->repaint();
73 snapShadow();
74 }
75
snapShadow()76 void XIconWithShadow::snapShadow()
77 {
78 //cout << "XIconWithShadow::snapShadow()\n";
79 int tempX, tempY;
80 XImlib2Shadow * xImage = dynamic_cast<XImlib2Shadow *>(shadowImage);
81
82 if (shadowVisible)
83 {
84 tempX = x;
85 tempY = y;
86
87 findSnapPosition(tempX, tempY);
88 fixPosition(tempX, tempY);
89
90 if (tempX != shadowX || tempY != shadowY)
91 {
92 shadowX = tempX;
93 shadowY = tempY;
94
95 xImage->moveWindow(shadowX, shadowY);
96 xImage->refreshIcon();
97 }
98 }
99 else
100 {
101 shadowVisible = true;
102 shadowX = x;
103 shadowY = y;
104
105 findSnapPosition(shadowX, shadowY);
106 fixPosition(shadowX, shadowY);
107
108 xImage->moveWindow(shadowX, shadowY);
109 xImage->mapWindow();
110 xImage->refreshIcon();
111 }
112 }
113
dragButtonRelease(XEvent ev)114 void XIconWithShadow::dragButtonRelease(XEvent ev)
115 {
116 XImlib2Shadow * xImage = dynamic_cast<XImlib2Shadow *>(shadowImage);
117
118 XIcon::dragButtonRelease(ev);
119 xImage->unmapWindow();
120
121 shadowVisible = false;
122 }
123
lowerIcon()124 void XIconWithShadow::lowerIcon()
125 {
126 XImlib2Image * xImage = dynamic_cast<XImlib2Image *>(image);
127 XImlib2Shadow * sImage = dynamic_cast<XImlib2Shadow *>(shadowImage);
128 xImage->lowerWindow();
129
130 if (captionOn)
131 {
132 XImlib2Caption * xCaption = dynamic_cast<XImlib2Caption *>(caption);
133 xCaption->lowerWindow();
134 }
135 sImage->lowerWindow();
136
137 }
138
findSnapPosition(int & xCord,int & yCord)139 void XIconWithShadow::findSnapPosition(int &xCord, int &yCord)
140 {
141 DesktopConfig * dConfig =
142 dynamic_cast<DesktopConfig *>(config);
143 XDesktopContainer * xContainer =
144 dynamic_cast<XDesktopContainer *>(container);
145
146 if (!dConfig->getStartSnapLeft())
147 xCord = xContainer->widthOfScreen() - xCord;
148 if (!dConfig->getStartSnapTop())
149 yCord = xContainer->heightOfScreen() - yCord;
150
151 int xMid = xCord + image->getWidth()/2;
152 int yMid = yCord + image->getHeight()/2;
153
154 xCord = xMid - xMid % (dConfig->getSnapWidth());
155 yCord = yMid - yMid % (dConfig->getSnapHeight());
156
157 xCord += dConfig->getSnapWidth()/2 - image->getWidth()/2;
158 yCord += dConfig->getSnapHeight()/2 - image->getHeight()/2;
159
160 if (!dConfig->getStartSnapLeft())
161 xCord = xContainer->widthOfScreen() - xCord;
162 if (!dConfig->getStartSnapTop())
163 yCord = xContainer->heightOfScreen() - yCord;
164 }
165
renderShadowToImage(Pixmap & buffer,int fX,int fY)166 void XIconWithShadow::renderShadowToImage(Pixmap &buffer, int fX, int fY)
167 {
168 XImlib2Shadow * sImage = dynamic_cast<XImlib2Shadow *>(shadowImage);
169 sImage->renderShadowToImage(buffer, fX, fY);
170 }
171