1 // ACWnd.cpp: Implementierungsdatei
10 static char THIS_FILE
[] = __FILE__
;
13 static UINT auIDStatusBar
[] =
18 #define _MAX_ENTRYS_ 8
19 #define _MODE_FIND_ALL_ (1L << 5)
21 /////////////////////////////////////////////////////////////////////////////
24 void DoPaintMessageLoop()
27 while(::PeekMessage(&message1
,NULL
,WM_PAINT
,WM_PAINT
, PM_REMOVE
))
29 ::TranslateMessage(&message1
);
30 ::DispatchMessage(&message1
);
34 /**********************************************************************/
36 CACListWnd::CACListWnd()
44 m_LastSize
.SetRectEmpty();
49 /**********************************************************************/
51 CACListWnd::~CACListWnd()
53 m_SearchList
.RemoveAll();
54 m_DisplayList
.RemoveAll();
58 /*********************************************************************/
60 void CACListWnd::OnActivateApp(BOOL bActive
, DWORD dwThreadID
)
62 #if (_MSC_VER >= 1300)
63 CWnd::OnActivateApp(bActive
, dwThreadID
); //vc7 FIX 1.2
65 CWnd::OnActivateApp(bActive
, (HTASK
)dwThreadID
); //vc6 FIX 1.2
72 BEGIN_MESSAGE_MAP(CACListWnd
, CWnd
)
73 //{{AFX_MSG_MAP(CACListWnd)
95 /////////////////////////////////////////////////////////////////////////////
96 // Behandlungsroutinen für Nachrichten CACListWnd
98 void CACListWnd::DrawItem(CDC
* pDC
,long m_lItem
,long width
)
100 long y
= m_lItem
- m_lTopIndex
;
101 CRect
rcLabel(2,y
*m_ItemHeight
,width
,(y
+1)*m_ItemHeight
);
103 pDC
->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT
));
105 if(m_lItem
== m_lSelItem
)
108 pDC
->FillSolidRect(rcLabel
,::GetSysColor(COLOR_HIGHLIGHT
));
109 pDC
->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT
));
114 m_DisplayStr
= m_PrefixChar
+ m_DisplayList
.GetAt(m_lItem
);
116 m_DisplayStr
= m_DisplayList
.GetAt(m_lItem
);
118 pDC
->DrawText(m_DisplayStr
, -1, rcLabel
, DT_LEFT
| DT_SINGLELINE
|
119 DT_NOPREFIX
| DT_VCENTER
| DT_END_ELLIPSIS
);
122 /*********************************************************************/
124 void CACListWnd::OnPaint()
127 CRect rcWnd
,m_rect
, rc
;
129 CBitmap m_bitmap
, *m_pOldBitmap
;
135 rc
.left
= rc
.right
-GetSystemMetrics(SM_CXHSCROLL
);
136 rc
.top
= rc
.bottom
-GetSystemMetrics(SM_CYVSCROLL
);
138 m_rect
.right
-= ScrollBarWidth();
140 MemDC
.CreateCompatibleDC(&dc
);
142 m_bitmap
.CreateCompatibleBitmap(&dc
, m_rect
.Width(), m_rect
.Height());
143 m_pOldBitmap
= MemDC
.SelectObject(&m_bitmap
);
145 MemDC
.SetWindowOrg(m_rect
.left
, m_rect
.top
);
147 long width
= rcWnd
.Width() - ScrollBarWidth();
149 MemDC
.FillSolidRect(rcWnd
,::GetSysColor(COLOR_WINDOW
));
150 MemDC
.SelectObject(GetStockObject(DEFAULT_GUI_FONT
));
151 MemDC
.SetBkMode(TRANSPARENT
);
153 for(i
= m_lTopIndex
; i
< m_lCount
;i
++)
155 DrawItem(&MemDC
,i
,width
);
159 CPen
m_Pen1(PS_SOLID
, 1, ::GetSysColor(COLOR_WINDOW
));
160 CPen
m_Pen2(PS_SOLID
, 1, ::GetSysColor(COLOR_BTNFACE
));
161 CPen
m_Pen3(PS_SOLID
, 1, ::GetSysColor(COLOR_3DSHADOW
));
165 if(m_VertBar
.IsWindowVisible())
166 dc
.FillSolidRect(rc
, ::GetSysColor(COLOR_BTNFACE
) );
170 CPen
*pOldPen
= (CPen
*)pDC
->SelectObject(&m_Pen1
);
173 width
= GetSystemMetrics(SM_CXHSCROLL
);
174 bottom
= (rcWnd
.bottom
-GetSystemMetrics(SM_CXHSCROLL
))-1;
177 for( i
= 0; i
< 20 ;i
++,a
++)
180 pDC
->SelectObject(&m_Pen1
);
182 pDC
->SelectObject(&m_Pen2
);
184 pDC
->SelectObject(&m_Pen3
);
188 pDC
->MoveTo(rc
.left
+ i
- 1, rcWnd
.bottom
);
189 pDC
->LineTo(rc
.left
+ i
+ width
, bottom
);
192 dc
.BitBlt(m_rect
.left
, m_rect
.top
, m_rect
.Width(), m_rect
.Height(),
193 &MemDC
, m_rect
.left
, m_rect
.top
, SRCCOPY
);
195 pDC
->SelectObject( pOldPen
);
196 MemDC
.SelectObject(m_pOldBitmap
);
199 /*********************************************************************/
201 void CACListWnd::Init(CWnd
*pWnd
)
203 VERIFY(m_VertBar
.Create(WS_VISIBLE
|SBS_VERT
|SBS_LEFTALIGN
,
204 CRect(0,0,GetSystemMetrics(SM_CYVSCROLL
),100),this,0));
207 m_pEditParent
= (CEdit
*)pWnd
;
209 m_lCount
= m_DisplayList
.GetSize();
210 m_VertBar
.SetScrollPos(0,false);
217 m_pDC
->SelectObject(GetStockObject(DEFAULT_GUI_FONT
));
218 CSize m_Size
= m_pDC
->GetOutputTextExtent(_T("Hg"));
219 m_ItemHeight
= m_Size
.cy
;
224 /*********************************************************************/
226 void CACListWnd::SetScroller()
229 GetClientRect(rcWnd
);
231 if(m_VertBar
.GetSafeHwnd())
235 rcBar
.left
= (rcWnd
.Width()-GetSystemMetrics(SM_CYVSCROLL
));
236 rcBar
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
237 m_VertBar
.MoveWindow(rcBar
);
238 rcBar
.top
= rcWnd
.bottom
-20;
239 rcBar
.bottom
= rcWnd
.bottom
;
241 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
246 /*********************************************************************/
248 void CACListWnd::OnSize(UINT nType
, int cx
, int cy
)
250 CWnd::OnSize(nType
, cx
, cy
);
254 if(!m_LastSize
.IsRectEmpty())
255 GetWindowRect(m_LastSize
);
258 /*********************************************************************/
260 long CACListWnd::ScrollBarWidth()
262 if(m_VertBar
.IsWindowVisible())
263 return GetSystemMetrics(SM_CYVSCROLL
);
268 /*********************************************************************/
270 void CACListWnd::SetProp()
277 CWnd::GetWindowRect(rcWnd
);
278 ScreenToClient(rcWnd
);
281 si
.cbSize
= sizeof(SCROLLINFO
);
282 si
.fMask
= SIF_PAGE
|SIF_RANGE
;
284 si
.nMax
= m_lCount
-1;
285 m_VisibleItems
= si
.nPage
= rcWnd
.Height()/m_ItemHeight
;
287 m_VertBar
.SetScrollRange(0,m_lCount
-1);
288 m_VertBar
.SetScrollInfo(&si
);
290 if(m_VisibleItems
> m_lCount
-1)
291 m_VertBar
.ShowWindow(false);
293 m_VertBar
.ShowWindow(true);
295 if(m_lTopIndex
+m_VisibleItems
> m_lCount
)
297 m_lTopIndex
= m_lCount
-m_VisibleItems
;
300 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
304 /*********************************************************************/
306 BOOL
CACListWnd::OnEraseBkgnd(CDC
* /*pDC*/)
311 /*********************************************************************/
313 void CACListWnd::OnNcPaint()
316 CRect rectClient
, rectWindow
,rcWnd
;
318 GetClientRect(rectClient
);
319 GetWindowRect(rectWindow
);
320 ScreenToClient(rectWindow
);
322 rectClient
.OffsetRect(-(rectWindow
.left
), -(rectWindow
.top
));
323 dc
.ExcludeClipRect(rectClient
);
325 rectWindow
.OffsetRect(-rectWindow
.left
, -rectWindow
.top
);
327 dc
.FillSolidRect(rectWindow
,::GetSysColor(COLOR_WINDOWTEXT
));
330 /*********************************************************************/
332 void CACListWnd::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
334 CWnd::OnKeyDown(nChar
, nRepCnt
, nFlags
);
336 if (nChar
== VK_ESCAPE
)
340 /*********************************************************************/
342 void CACListWnd::OnNcCalcSize(BOOL
/*bCalcValidRects*/, NCCALCSIZE_PARAMS FAR
* lpncsp
)
344 ::InflateRect(lpncsp
->rgrc
,
345 -GetSystemMetrics(SM_CXBORDER
), -GetSystemMetrics(SM_CYBORDER
));
348 /*********************************************************************/
350 int CACListWnd::HitTest(CPoint point
)
355 GetClientRect(rcWnd
);
356 long width
= rcWnd
.Width() - ScrollBarWidth();
358 for(int i
= m_lTopIndex
; i
< m_lCount
; i
++)
360 long y
= i
- m_lTopIndex
;
361 rcItem
.SetRect(2,y
*m_ItemHeight
,width
,(y
+1)*m_ItemHeight
);
363 if(PtInRect(&rcItem
, point
))
364 return (m_lSelItem
= (y
+m_lTopIndex
));
370 /*********************************************************************/
372 LRESULT
CACListWnd::OnNcHitTest(CPoint point
)
375 GetWindowRect(rectClient
);
377 rectClient
.left
= rectClient
.right
- GetSystemMetrics(SM_CYVSCROLL
);
378 rectClient
.top
= rectClient
.bottom
- GetSystemMetrics(SM_CXVSCROLL
);
380 if(rectClient
.PtInRect(point
))
381 return HTBOTTOMRIGHT
;
386 /*********************************************************************/
388 void CACListWnd::OnLButtonDown(UINT nFlags
, CPoint point
)
390 CWnd::OnLButtonDown(nFlags
, point
);
391 int sel
= HitTest(point
);
395 if(!EnsureVisible(sel
,true))
398 m_pEditParent
->SendMessage(ENAC_UPDATE
, WM_KEYDOWN
, GetDlgCtrlID());
399 DoPaintMessageLoop();
407 if(!rc
.PtInRect(point
))
412 /*********************************************************************/
414 void CACListWnd::OnRButtonDown(UINT nFlags
, CPoint point
)
416 CWnd::OnRButtonDown(nFlags
, point
);
420 /*********************************************************************/
422 BOOL
CACListWnd::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
427 GetWindowRect(rectClient
);
428 ScreenToClient(&rectClient
);
430 rectClient
.left
= rectClient
.right
- GetSystemMetrics(SM_CYVSCROLL
);
431 rectClient
.top
= rectClient
.bottom
- GetSystemMetrics(SM_CXVSCROLL
);
434 GetCursorPos(&ptCursor
);
435 ScreenToClient(&ptCursor
);
437 if(rectClient
.PtInRect(ptCursor
)) // Vergrößerungs-Cursor
439 return CWnd::OnSetCursor(pWnd
, nHitTest
, message
);
442 ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW
));
446 /*********************************************************************/
448 void CACListWnd::InvalidateAndScroll()
450 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
452 DoPaintMessageLoop();
455 /*********************************************************************/
457 bool CACListWnd::EnsureVisible(int item
, bool m_bWait
)
459 if(item
> m_lTopIndex
&& item
< m_lTopIndex
+ m_VisibleItems
)
460 return false; // ist visible
462 if(item
> m_lTopIndex
) // scroll down
465 for(int i
= m_lTopIndex
; i
< m_len
; i
++)
467 if(i
>= m_lCount
-m_VisibleItems
)
469 if(i
>= m_lCount
-m_VisibleItems
|| i
+ m_VisibleItems
> item
)
478 InvalidateAndScroll();
480 DoPaintMessageLoop();
483 InvalidateAndScroll();
487 if(item
< m_lTopIndex
) // scroll up
489 while(item
< m_lTopIndex
)
500 InvalidateAndScroll();
502 DoPaintMessageLoop();
506 InvalidateAndScroll();
513 /*********************************************************************/
515 bool CACListWnd::SelectItem(int item
)
522 EnsureVisible(m_lSelItem
,false);
529 if(!EnsureVisible(item
,true))
535 /*********************************************************************/
537 int CACListWnd::FindStringExact( int nStartAfter
, LPCTSTR lpszString
)
539 if(nStartAfter
> m_SearchList
.GetSize())
542 for(int i
= nStartAfter
+1; i
< m_SearchList
.GetSize(); i
++)
543 if(m_SearchList
.GetAt(i
).Compare(lpszString
) == 0)
548 /*********************************************************************/
551 * NEW: m_bDisplayOnly
553 int CACListWnd::FindString(int nStartAfter
, LPCTSTR lpszString
, bool m_bDisplayOnly
)
555 long m_AktCount
= m_DisplayList
.GetSize();
559 CString m_Str1
,m_Str2
= lpszString
;
566 if(nStartAfter
> m_SearchList
.GetSize())
578 m_DisplayList
.RemoveAll();
582 for(int i
= nStartAfter
+1; i
< m_SearchList
.GetSize(); i
++)
585 m_Str1
= m_PrefixChar
;
589 m_Str1
+= m_SearchList
.GetAt(i
);
593 if(m_lMode
& _MODE_FIND_ALL_
)
595 if(m_Str1
.Find(m_Str2
) >= 0)
597 m_DisplayList
.Add(m_SearchList
.GetAt(i
));
600 else // _MODE_FIND_EXACT_
602 if(m_Str1
.Find(m_Str2
) == 0)
604 m_DisplayList
.Add(m_SearchList
.GetAt(i
));
609 m_lCount
= m_DisplayList
.GetSize();
616 m_pEditParent
->GetWindowRect(rcWnd
);
624 iHeight
= m_lCount
*m_ItemHeight
+(GetSystemMetrics(SM_CYBORDER
)*2);
626 if(m_lCount
> _MAX_ENTRYS_
)
627 iHeight
= _MAX_ENTRYS_
*m_ItemHeight
+(GetSystemMetrics(SM_CYBORDER
)*2);
629 if(!m_LastSize
.IsRectEmpty())
631 iWight
= m_LastSize
.Width();
632 iHeight
= m_LastSize
.Height();
633 rcWnd
.top
+= rcWnd
.Height();
634 rcWnd
.right
= rcWnd
.left
+iWight
;
635 rcWnd
.bottom
= rcWnd
.top
+iHeight
;
637 SetWindowPos(&CWnd::wndTopMost
, rcWnd
.left
,
644 SetWindowPos(&CWnd::wndTopMost
, rcWnd
.left
,
645 rcWnd
.top
+ rcWnd
.Height(),
650 if(m_AktCount
!= m_DisplayList
.GetSize())
653 SortList(m_DisplayList
);
663 /*********************************************************************/
665 int CACListWnd::SelectString(LPCTSTR lpszString
)
667 int item
= FindString(-1, lpszString
);
672 /*********************************************************************/
674 bool CACListWnd::GetText(int item
, CString
& m_Text
)
676 if(item
< 0 || item
> m_SearchList
.GetSize())
678 m_Text
= m_SearchList
.GetAt(item
);
682 /*********************************************************************/
684 void CACListWnd::OnShowWindow(BOOL bShow
, UINT nStatus
)
688 m_nIDTimer
= SetTimer( IDTimerInstall
, 200, NULL
);
689 m_pEditParent
->GetParent()->GetWindowRect(m_ParentRect
);
694 KillTimer(IDTimerInstall
);
700 CWnd::OnShowWindow(bShow
, nStatus
);
701 ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW
));
704 /*********************************************************************/
706 void CACListWnd::OnNcLButtonDown(UINT nHitTest
, CPoint point
)
709 if(OnNcHitTest(point
) == HTBOTTOMRIGHT
)
710 GetWindowRect(m_LastSize
);
711 CWnd::OnNcLButtonDown(nHitTest
, point
);
714 /*********************************************************************/
716 CString
CACListWnd::GetString()
718 int i
= m_DisplayList
.GetSize();
722 if(i
<= m_lSelItem
|| m_lSelItem
== -1)
727 return m_DisplayList
.GetAt(i
);
730 /*********************************************************************/
732 void CACListWnd::OnVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
734 CWnd::OnVScroll(nSBCode
, nPos
, pScrollBar
);
735 long m_oldlTopIndex
= m_lTopIndex
;
743 m_lTopIndex
-= m_VisibleItems
;
749 m_lTopIndex
+= m_VisibleItems
;
750 if(m_lTopIndex
>= m_lCount
-m_VisibleItems
)
751 m_lTopIndex
= m_lCount
-m_VisibleItems
;
762 if(m_lTopIndex
>= m_lCount
-m_VisibleItems
)
763 m_lTopIndex
= m_lCount
-m_VisibleItems
;
771 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
773 if(m_oldlTopIndex
!= m_lTopIndex
)
777 /*********************************************************************/
779 CString
CACListWnd::GetNextString(int nChar
)
792 m_lSelItem
-= m_VisibleItems
;
798 m_lSelItem
+= m_VisibleItems
;
799 if(m_lSelItem
>= m_lCount
-1)
800 m_lSelItem
= m_lCount
-1;
808 m_lSelItem
= m_lCount
-1;
813 m_lSelItem
= m_lCount
-1;
815 if(m_lSelItem
>= m_lCount
)
818 if(EnsureVisible(m_lSelItem
,(m_lCount
> 50) ? false : true))
819 InvalidateAndScroll();
824 /*********************************************************************/
826 void CACListWnd::OnMouseMove(UINT nFlags
, CPoint point
)
828 CWnd::OnMouseMove(nFlags
, point
);
829 int sel
= HitTest(point
);
836 /*********************************************************************/
838 void CACListWnd::OnTimer(UINT_PTR nIDEvent
)
840 CWnd::OnTimer(nIDEvent
);
843 m_pEditParent
->GetParent()->GetWindowRect(m_ParentRect1
);
844 if(!m_ParentRect1
.EqualRect(m_ParentRect
))
848 /*********************************************************************/
850 void CACListWnd::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
855 long m_lMinY1
= GetSystemMetrics(SM_CYHSCROLL
)*2 + GetSystemMetrics(SM_CYSIZEFRAME
) + GetSystemMetrics(SM_CXHTHUMB
),
856 m_lMinY2
= m_lCount
* m_ItemHeight
+ (GetSystemMetrics(SM_CYBORDER
)*2);
858 if(m_VisibleItems
> m_lCount
-1 && m_lMinY2
< m_lMinY1
)
859 lpMMI
->ptMinTrackSize
.y
= m_lMinY2
;
861 lpMMI
->ptMinTrackSize
.y
= m_lMinY1
;
864 lpMMI
->ptMinTrackSize
.x
= GetSystemMetrics(SM_CXHSCROLL
)*4;
868 if(m_pEditParent
!= NULL
)
871 m_pEditParent
->GetWindowRect (&rc
);
872 lpMMI
->ptMinTrackSize
.x
= rc
.right
- rc
.left
;
876 CWnd::OnGetMinMaxInfo(lpMMI
);
879 /*********************************************************************/
881 int CACListWnd::CompareString(const void* p1
, const void* p2
)
883 return _stricmp( * ( char** ) p1
, * ( char** ) p2
);
886 /*********************************************************************/
888 void CACListWnd::SortList(CStringArray
& m_List
)
890 int m_Count
= m_List
.GetSize();
895 CStringArray m_Liste1
;
896 m_Liste1
.Copy(m_List
);
898 LPCTSTR
* ppSortArray
= new LPCTSTR
[m_Count
+1];
901 for(i
=0; i
< m_Count
; i
++)
903 ppSortArray
[i
] = (LPCTSTR
)m_Liste1
.GetAt(i
);
908 qsort(ppSortArray
, m_Count
, sizeof(LPCTSTR
), CompareString
);
910 for(i
=0; i
< m_Count
; i
++)
912 m_List
.Add((LPCTSTR
) ppSortArray
[i
]);
914 m_Liste1
.RemoveAll();
915 delete [] ppSortArray
;
919 /*********************************************************************/
924 void CACListWnd::CopyList()
926 m_DisplayList
.Copy(m_SearchList
);
927 m_lCount
= m_DisplayList
.GetSize();
929 FindString(0,_T(""),true);
932 /*********************************************************************/