1 // Copyright (c) 2008-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
20 #include <WNT_IconBox.hxx>
22 #include <WNT_GraphicDevice.hxx>
23 #include <WNT_ImageManager.hxx>
24 #include <WNT_Icon.hxx>
29 //=======================================================================
30 //function : HandleEvent
32 //=======================================================================
34 WNT_Long WNT_IconBox::HandleEvent (
35 const Aspect_Handle hwnd,
37 const WNT_Dword& wParam,
38 const WNT_Dword& lParam
50 GetClientRect ( ( HWND )hwnd, &r );
52 myIncX = myIconWidth + X_SPACING + 6;
53 myNX = r.right / myIncX;
55 if ( myNX == 0 ) ++myNX;
57 myIncY = myIconHeight + Y_SPACING + 11 + myIconHeight / Y_SPACING;
58 myNY = r.bottom / myIncY;
60 if ( myNY == 0 ) ++myNY;
62 len = myImages -> Size ();
64 if ( myNX * myNY >= len )
66 ShowScrollBar ( ( HWND )hwnd, SB_VERT, FALSE );
70 si.cbSize = sizeof ( SCROLLINFO );
71 si.fMask = SIF_POS | SIF_RANGE;
74 si.nMax = myMaxPos = len / myNX;
76 SetScrollInfo ( ( HWND )hwnd, SB_VERT, &si, TRUE );
77 ShowScrollBar ( ( HWND )hwnd, SB_VERT, TRUE );
94 nScrollCode = ( Standard_Integer )LOWORD( wParam );
95 len = myImages -> Size ();
97 switch ( nScrollCode ) {
102 newStart = myStart - myNX;
103 myStart = newStart >= 1 ? --myNPos, newStart : ( ( myNPos = 0 ), 1 );
110 newStart = myStart + myNX;
111 myStart = ( newStart <= len - myNX + 1 ) ? ( ++myNPos, newStart ) :
112 ( ( myNPos = myMaxPos ),
120 myNPos = ( Standard_Integer )HIWORD( wParam );
121 myStart = myNPos * myNX;
131 if ( myStart == 0 ) ++myStart;
133 nCurPos = GetScrollPos ( ( HWND )hwnd, SB_VERT );
135 if ( nCurPos == myNPos ) return 0;
137 si.cbSize = sizeof ( SCROLLINFO );
141 SetScrollInfo ( ( HWND )hwnd, SB_VERT, &si, TRUE );
142 InvalidateRect ( ( HWND )hwnd, NULL, TRUE );
155 int i, j, x, y, ow, oh, cnt, len;
157 Handle( WNT_Icon ) icon;
159 Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
160 DownCast ( GraphicDevice () );
164 hDCdst = BeginPaint ( ( HWND )hwnd, &ps );
165 hDCsrc = CreateCompatibleDC ( hDCdst );
167 if ( gDev -> IsPaletteDevice () ) {
169 hOldPal = SelectPalette ( hDCdst, ( HPALETTE )( gDev -> HPalette () ), FALSE );
170 RealizePalette ( hDCdst );
174 len = myImages -> Size ();
175 hOldPen = SelectPen ( hDCdst, myPen );
176 hOldFont = SelectFont ( hDCdst, myFont );
177 SetTextAlign ( hDCdst, TA_CENTER | TA_TOP );
178 SetStretchBltMode ( hDCdst, COLORONCOLOR );
180 for ( i = 0, y = Y_SPACING, cnt = myStart; i < myNY; ++i, y += myIncY )
182 for ( j = 0, x = X_SPACING; j < myNX; ++j, ++cnt, x += myIncX ) {
184 if ( cnt > len ) goto exit_display;
186 icon = Handle( WNT_Icon ) :: DownCast ( myImages -> Image ( cnt ) );
188 if ( icon.IsNull () ) continue;
190 myImages -> Dim ( cnt, ow, oh );
191 SelectBitmap ( hDCsrc, icon -> myImage );
193 Rectangle ( hDCdst, x, y, x + myIconWidth + 4, y + myIconHeight + 4 );
195 hDCdst, x + myIconWidth / 2, y + myIconHeight + 10,
196 icon -> myName, strlen ( icon -> myName )
200 hDCdst, x + 2, y + 2, myIconWidth, myIconHeight,
201 hDCsrc, 0, 0, ow, oh,
209 SelectFont ( hDCdst, hOldFont );
210 SelectPen ( hDCdst, hOldPen );
212 if ( gDev -> IsPaletteDevice () )
214 SelectPalette ( hDCdst, hOldPal, FALSE );
217 EndPaint ( ( HWND )hwnd, &ps );
223 return DefWindowProc ( ( HWND )hwnd, uMsg, wParam, lParam );
227 case WM_ENTERSIZEMOVE :
233 case WM_EXITSIZEMOVE :
236 InvalidateRect ( ( HWND )hwnd, NULL, TRUE );
240 case WM_QUERYNEWPALETTE: {
242 HDC hDC = GetDC ( ( HWND )hwnd );
243 WINDOW_DATA* wd = (WINDOW_DATA* )GetWindowLongPtr ((HWND )hwnd, GWLP_USERDATA);
245 SelectPalette ( hDC, wd -> hPal, FALSE );
247 // if ( RealizePalette ( hDC ) );
248 if ( RealizePalette ( hDC ) )
249 InvalidateRect ( ( HWND )hwnd, NULL, FALSE );
251 ReleaseDC ( ( HWND )hwnd, hDC );
255 } // WM_QUERYNEWPALETTE
257 case WM_PALETTECHANGED:
259 if ( hwnd != ( HWND )wParam ) {
261 HDC hDC = GetDC ( ( HWND )hwnd );
262 WINDOW_DATA* wd = (WINDOW_DATA* )GetWindowLongPtr ((HWND )hwnd, GWLP_USERDATA);
263 SelectPalette ( hDC, wd -> hPal, TRUE );
265 if ( RealizePalette ( hDC ) )
267 UpdateColors ( hDC );
269 ReleaseDC ( ( HWND )hwnd, hDC );
277 return DefWindowProc ( ( HWND )hwnd, uMsg, wParam, lParam );
281 } // end WNT_IconBox :: HandleEvent