summaryrefslogtreecommitdiff
path: root/src/WNT/WNT_IconBox_1.cxx
blob: 8deefa69eba970b9859726dd64949e43fbd9e78f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// File:      WNT_IconBox_1.cxx
// Copyright: Open Cascade 2008

#include <windows.h>
#include <WNT_IconBox.hxx>

#include <WNT_GraphicDevice.hxx>
#include <WNT_ImageManager.hxx>
#include <WNT_Icon.hxx>

#define X_SPACING 10
#define Y_SPACING 10

//=======================================================================
//function : HandleEvent
//purpose  :
//=======================================================================

WNT_Long WNT_IconBox::HandleEvent (
          const Aspect_Handle  hwnd,
          const WNT_Uint&      uMsg,
          const WNT_Dword&     wParam,
          const WNT_Dword&     lParam
         )
{

  switch ( uMsg ) {

  case WM_SIZE : {

   int        len;
   RECT       r;
   SCROLLINFO si;

   GetClientRect (  ( HWND )hwnd, &r  );

   myIncX = myIconWidth + X_SPACING + 6;
   myNX   = r.right  / myIncX;

   if ( myNX == 0 ) ++myNX;

   myIncY = myIconHeight + Y_SPACING + 11 + myIconHeight / Y_SPACING;
   myNY   = r.bottom / myIncY;

   if ( myNY == 0 ) ++myNY;

   len = myImages -> Size ();

   if ( myNX * myNY >= len )

    ShowScrollBar (  ( HWND )hwnd, SB_VERT, FALSE  );

   else {

    si.cbSize = sizeof ( SCROLLINFO );
	si.fMask  = SIF_POS | SIF_RANGE;
	si.nPos   = myNPos = 0;
	si.nMin   = 0;
	si.nMax   = myMaxPos = len / myNX;

    SetScrollInfo (  ( HWND )hwnd, SB_VERT, &si, TRUE );
   	ShowScrollBar (  ( HWND )hwnd, SB_VERT, TRUE  );
	myStart = 1;

   }  // end else

   return 0;

  }  // WM_SIZE

  case WM_VSCROLL : {

   int        nCurPos;
   int        nScrollCode;
   int        newStart;
   int        len;
   SCROLLINFO si;

   nScrollCode = ( Standard_Integer )LOWORD( wParam );
   len         = myImages -> Size ();

   switch ( nScrollCode ) {

   	case SB_LINEUP :
	case SB_PAGEUP :

	 newStart = myStart - myNX;
	 myStart    = newStart >= 1 ? --myNPos, newStart : (  ( myNPos = 0 ), 1  );

	break;

	case SB_LINEDOWN :
	case SB_PAGEDOWN :

	 newStart = myStart + myNX;
	 myStart    = ( newStart <= len - myNX + 1 ) ? ( ++myNPos, newStart ) :
	                                               (  ( myNPos = myMaxPos ),
	                                                  ( len - myNX + 1  )
	                                               );

	break;

	case SB_THUMBTRACK :

     myNPos  = ( Standard_Integer )HIWORD( wParam );
     myStart = myNPos * myNX;

	break;

	case SB_ENDSCROLL :

	return 0;

   }  // end switch

   if ( myStart == 0 ) ++myStart;

   nCurPos = GetScrollPos (  ( HWND )hwnd, SB_VERT  );

   if ( nCurPos == myNPos ) return 0;

   si.cbSize = sizeof ( SCROLLINFO );
   si.fMask  = SIF_POS;
   si.nPos   = myNPos;

   SetScrollInfo (  ( HWND )hwnd, SB_VERT, &si, TRUE  );
   InvalidateRect (  ( HWND )hwnd, NULL, TRUE  );

   return 0;

  }  // WM_VSCROLL

  case WM_PAINT : {

   HDC         hDCsrc, hDCdst;
   PAINTSTRUCT ps;
   HPEN        hOldPen = NULL;
   HFONT       hOldFont = NULL;
   HPALETTE    hOldPal = NULL;
   int         i, j, x, y, ow, oh, cnt, len;

   Handle( WNT_Icon ) icon;

   Handle( WNT_GraphicDevice ) gDev = Handle( WNT_GraphicDevice ) ::
                                       DownCast (  GraphicDevice ()  );

   if ( !myDragging ) {

    hDCdst = BeginPaint (  ( HWND )hwnd, &ps  );
    hDCsrc = CreateCompatibleDC ( hDCdst );

    if (  gDev -> IsPaletteDevice ()  ) {

   	 hOldPal = SelectPalette ( hDCdst, ( HPALETTE )(  gDev -> HPalette ()  ), FALSE );
	 RealizePalette ( hDCdst );

    }  // end if

     len      = myImages -> Size ();
	 hOldPen  = SelectPen ( hDCdst, myPen );
	 hOldFont = SelectFont ( hDCdst, myFont );
	 SetTextAlign ( hDCdst, TA_CENTER | TA_TOP );
	 SetStretchBltMode ( hDCdst, COLORONCOLOR );

	 for ( i = 0, y = Y_SPACING, cnt = myStart; i < myNY; ++i, y += myIncY )

	  for ( j = 0, x = X_SPACING; j < myNX; ++j, ++cnt, x += myIncX ) {

       if ( cnt > len ) goto exit_display;

	   icon = Handle( WNT_Icon ) :: DownCast (  myImages -> Image ( cnt )  );

	   if (  icon.IsNull ()  ) continue;

	   myImages -> Dim ( cnt, ow, oh );
	   SelectBitmap ( hDCsrc, icon -> myImage );

       Rectangle ( hDCdst, x, y, x + myIconWidth + 4, y + myIconHeight + 4 );
       TextOut  (
        hDCdst, x + myIconWidth / 2, y + myIconHeight + 10,
        icon -> myName, strlen ( icon -> myName )
       );

       StretchBlt (
        hDCdst, x + 2, y + 2, myIconWidth, myIconHeight,
        hDCsrc, 0,     0,     ow,          oh,
        SRCCOPY
       );

	  }  // end for

exit_display:

     SelectFont ( hDCdst, hOldFont );
	 SelectPen ( hDCdst, hOldPen );

    if (  gDev -> IsPaletteDevice ()  )

     SelectPalette ( hDCdst, hOldPal, FALSE );

    DeleteDC ( hDCsrc );
    EndPaint (  ( HWND )hwnd, &ps  );

    return 0;

   } else

    return DefWindowProc (  ( HWND )hwnd, uMsg, wParam, lParam  );

  }  // WM_PAINT

  case WM_ENTERSIZEMOVE :

   myDragging = TRUE;

   return 0;

  case WM_EXITSIZEMOVE :

   myDragging = FALSE;
   InvalidateRect (  ( HWND )hwnd, NULL, TRUE  );

   return 0;

  case WM_QUERYNEWPALETTE: {

   HDC          hDC = GetDC (  ( HWND )hwnd  );
   WINDOW_DATA* wd  = (WINDOW_DATA* )GetWindowLongPtr ((HWND )hwnd, GWLP_USERDATA);

   SelectPalette ( hDC, wd -> hPal, FALSE );

//   if (  RealizePalette ( hDC )  );
   if (  RealizePalette ( hDC )  )
    InvalidateRect (  ( HWND )hwnd, NULL, FALSE  );

   ReleaseDC (  ( HWND )hwnd, hDC  );

   return TRUE;

  }  // WM_QUERYNEWPALETTE

  case WM_PALETTECHANGED:

   if (  hwnd != ( HWND )wParam  ) {

    HDC          hDC = GetDC (  ( HWND )hwnd  );
    WINDOW_DATA* wd  = (WINDOW_DATA* )GetWindowLongPtr ((HWND )hwnd, GWLP_USERDATA);
    SelectPalette ( hDC, wd -> hPal, TRUE );

    if (  RealizePalette ( hDC )  )

     UpdateColors ( hDC );

    ReleaseDC (  ( HWND )hwnd, hDC  );

    return 0;

   }  // end if

  default:

   return DefWindowProc (  ( HWND )hwnd, uMsg, wParam, lParam  );

 }  // end switch

}  // end WNT_IconBox :: HandleEvent