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();
50 /**********************************************************************/
52 CACListWnd::~CACListWnd()
54 m_SearchList
.RemoveAll();
55 m_DisplayList
.RemoveAll();
59 /*********************************************************************/
61 void CACListWnd::OnActivateApp(BOOL bActive
, DWORD dwThreadID
)
63 #if (_MSC_VER >= 1300)
64 CWnd::OnActivateApp(bActive
, dwThreadID
); //vc7 FIX 1.2
66 CWnd::OnActivateApp(bActive
, (HTASK
)dwThreadID
); //vc6 FIX 1.2
73 BEGIN_MESSAGE_MAP(CACListWnd
, CWnd
)
74 //{{AFX_MSG_MAP(CACListWnd)
96 /////////////////////////////////////////////////////////////////////////////
97 // Behandlungsroutinen für Nachrichten CACListWnd
99 void CACListWnd::DrawItem(CDC
* pDC
,long m_lItem
,long width
)
101 long y
= m_lItem
- m_lTopIndex
;
102 CRect
rcLabel(2,y
*m_ItemHeight
,width
,(y
+1)*m_ItemHeight
);
104 pDC
->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT
));
106 if(m_lItem
== m_lSelItem
)
109 pDC
->FillSolidRect(rcLabel
,::GetSysColor(COLOR_HIGHLIGHT
));
110 pDC
->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT
));
115 m_DisplayStr
= m_PrefixChar
+ m_DisplayList
.GetAt(m_lItem
);
117 m_DisplayStr
= m_DisplayList
.GetAt(m_lItem
);
119 pDC
->DrawText(m_DisplayStr
, -1, rcLabel
, DT_LEFT
| DT_SINGLELINE
|
120 DT_NOPREFIX
| DT_VCENTER
| DT_END_ELLIPSIS
);
123 /*********************************************************************/
125 void CACListWnd::OnPaint()
128 CRect rcWnd
,m_rect
, rc
;
130 CBitmap m_bitmap
, *m_pOldBitmap
;
136 rc
.left
= rc
.right
-GetSystemMetrics(SM_CXHSCROLL
);
137 rc
.top
= rc
.bottom
-GetSystemMetrics(SM_CYVSCROLL
);
139 m_rect
.right
-= ScrollBarWidth();
141 MemDC
.CreateCompatibleDC(&dc
);
143 m_bitmap
.CreateCompatibleBitmap(&dc
, m_rect
.Width(), m_rect
.Height());
144 m_pOldBitmap
= MemDC
.SelectObject(&m_bitmap
);
146 MemDC
.SetWindowOrg(m_rect
.left
, m_rect
.top
);
148 long width
= rcWnd
.Width() - ScrollBarWidth();
150 MemDC
.FillSolidRect(rcWnd
,::GetSysColor(COLOR_WINDOW
));
151 MemDC
.SelectObject(GetStockObject(DEFAULT_GUI_FONT
));
152 MemDC
.SetBkMode(TRANSPARENT
);
154 for(i
= m_lTopIndex
; i
< m_lCount
;i
++)
156 DrawItem(&MemDC
,i
,width
);
160 CPen
m_Pen1(PS_SOLID
, 1, ::GetSysColor(COLOR_WINDOW
));
161 CPen
m_Pen2(PS_SOLID
, 1, ::GetSysColor(COLOR_BTNFACE
));
162 CPen
m_Pen3(PS_SOLID
, 1, ::GetSysColor(COLOR_3DSHADOW
));
166 if(m_VertBar
.IsWindowVisible())
167 dc
.FillSolidRect(rc
, ::GetSysColor(COLOR_BTNFACE
) );
171 CPen
*pOldPen
= (CPen
*)pDC
->SelectObject(&m_Pen1
);
174 width
= GetSystemMetrics(SM_CXHSCROLL
);
175 bottom
= (rcWnd
.bottom
-GetSystemMetrics(SM_CXHSCROLL
))-1;
178 for( i
= 0; i
< 20 ;i
++,a
++)
181 pDC
->SelectObject(&m_Pen1
);
183 pDC
->SelectObject(&m_Pen2
);
185 pDC
->SelectObject(&m_Pen3
);
189 pDC
->MoveTo(rc
.left
+ i
- 1, rcWnd
.bottom
);
190 pDC
->LineTo(rc
.left
+ i
+ width
, bottom
);
193 dc
.BitBlt(m_rect
.left
, m_rect
.top
, m_rect
.Width(), m_rect
.Height(),
194 &MemDC
, m_rect
.left
, m_rect
.top
, SRCCOPY
);
196 pDC
->SelectObject( pOldPen
);
197 MemDC
.SelectObject(m_pOldBitmap
);
200 /*********************************************************************/
202 void CACListWnd::Init(CWnd
*pWnd
)
204 VERIFY(m_VertBar
.Create(WS_VISIBLE
|SBS_VERT
|SBS_LEFTALIGN
,
205 CRect(0,0,GetSystemMetrics(SM_CYVSCROLL
),100),this,0));
208 m_pEditParent
= (CEdit
*)pWnd
;
210 m_lCount
= (long)m_DisplayList
.GetSize();
211 m_VertBar
.SetScrollPos(0,false);
218 m_pDC
->SelectObject(GetStockObject(DEFAULT_GUI_FONT
));
219 CSize m_Size
= m_pDC
->GetOutputTextExtent(_T("Hg"));
220 m_ItemHeight
= m_Size
.cy
;
225 /*********************************************************************/
227 void CACListWnd::SetScroller()
230 GetClientRect(rcWnd
);
232 if(m_VertBar
.GetSafeHwnd())
236 rcBar
.left
= (rcWnd
.Width()-GetSystemMetrics(SM_CYVSCROLL
));
237 rcBar
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
238 m_VertBar
.MoveWindow(rcBar
);
239 rcBar
.top
= rcWnd
.bottom
-20;
240 rcBar
.bottom
= rcWnd
.bottom
;
242 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
247 /*********************************************************************/
249 void CACListWnd::OnSize(UINT nType
, int cx
, int cy
)
251 CWnd::OnSize(nType
, cx
, cy
);
255 if(!m_LastSize
.IsRectEmpty())
256 GetWindowRect(m_LastSize
);
259 /*********************************************************************/
261 long CACListWnd::ScrollBarWidth()
263 if(m_VertBar
.IsWindowVisible())
264 return GetSystemMetrics(SM_CYVSCROLL
);
269 /*********************************************************************/
271 void CACListWnd::SetProp()
278 CWnd::GetWindowRect(rcWnd
);
279 ScreenToClient(rcWnd
);
282 si
.cbSize
= sizeof(SCROLLINFO
);
283 si
.fMask
= SIF_PAGE
|SIF_RANGE
;
285 si
.nMax
= m_lCount
-1;
286 m_VisibleItems
= si
.nPage
= rcWnd
.Height()/m_ItemHeight
;
288 m_VertBar
.SetScrollRange(0,m_lCount
-1);
289 m_VertBar
.SetScrollInfo(&si
);
291 if(m_VisibleItems
> m_lCount
-1)
292 m_VertBar
.ShowWindow(false);
294 m_VertBar
.ShowWindow(true);
296 if(m_lTopIndex
+m_VisibleItems
> m_lCount
)
298 m_lTopIndex
= m_lCount
-m_VisibleItems
;
301 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
305 /*********************************************************************/
307 BOOL
CACListWnd::OnEraseBkgnd(CDC
* /*pDC*/)
312 /*********************************************************************/
314 void CACListWnd::OnNcPaint()
317 CRect rectClient
, rectWindow
,rcWnd
;
319 GetClientRect(rectClient
);
320 GetWindowRect(rectWindow
);
321 ScreenToClient(rectWindow
);
323 rectClient
.OffsetRect(-(rectWindow
.left
), -(rectWindow
.top
));
324 dc
.ExcludeClipRect(rectClient
);
326 rectWindow
.OffsetRect(-rectWindow
.left
, -rectWindow
.top
);
328 dc
.FillSolidRect(rectWindow
,::GetSysColor(COLOR_WINDOWTEXT
));
331 /*********************************************************************/
333 void CACListWnd::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
335 CWnd::OnKeyDown(nChar
, nRepCnt
, nFlags
);
337 if (nChar
== VK_ESCAPE
)
341 /*********************************************************************/
343 void CACListWnd::OnNcCalcSize(BOOL
/*bCalcValidRects*/, NCCALCSIZE_PARAMS FAR
* lpncsp
)
345 ::InflateRect(lpncsp
->rgrc
,
346 -GetSystemMetrics(SM_CXBORDER
), -GetSystemMetrics(SM_CYBORDER
));
349 /*********************************************************************/
351 int CACListWnd::HitTest(CPoint point
)
356 GetClientRect(rcWnd
);
357 long width
= rcWnd
.Width() - ScrollBarWidth();
359 for(int i
= m_lTopIndex
; i
< m_lCount
; i
++)
361 long y
= i
- m_lTopIndex
;
362 rcItem
.SetRect(2,y
*m_ItemHeight
,width
,(y
+1)*m_ItemHeight
);
364 if(PtInRect(&rcItem
, point
))
365 return (m_lSelItem
= (y
+m_lTopIndex
));
371 /*********************************************************************/
373 LRESULT
CACListWnd::OnNcHitTest(CPoint point
)
376 GetWindowRect(rectClient
);
378 rectClient
.left
= rectClient
.right
- GetSystemMetrics(SM_CYVSCROLL
);
379 rectClient
.top
= rectClient
.bottom
- GetSystemMetrics(SM_CXVSCROLL
);
381 if(rectClient
.PtInRect(point
))
382 return HTBOTTOMRIGHT
;
387 /*********************************************************************/
389 void CACListWnd::OnLButtonDown(UINT nFlags
, CPoint point
)
391 CWnd::OnLButtonDown(nFlags
, point
);
392 int sel
= HitTest(point
);
396 if(!EnsureVisible(sel
,true))
399 m_pEditParent
->SendMessage(ENAC_UPDATE
, WM_KEYDOWN
, GetDlgCtrlID());
400 DoPaintMessageLoop();
408 if(!rc
.PtInRect(point
))
413 /*********************************************************************/
415 void CACListWnd::OnRButtonDown(UINT nFlags
, CPoint point
)
417 CWnd::OnRButtonDown(nFlags
, point
);
421 /*********************************************************************/
423 BOOL
CACListWnd::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
428 GetWindowRect(rectClient
);
429 ScreenToClient(&rectClient
);
431 rectClient
.left
= rectClient
.right
- GetSystemMetrics(SM_CYVSCROLL
);
432 rectClient
.top
= rectClient
.bottom
- GetSystemMetrics(SM_CXVSCROLL
);
435 GetCursorPos(&ptCursor
);
436 ScreenToClient(&ptCursor
);
438 if(rectClient
.PtInRect(ptCursor
)) // Vergrößerungs-Cursor
440 return CWnd::OnSetCursor(pWnd
, nHitTest
, message
);
443 ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW
));
447 /*********************************************************************/
449 void CACListWnd::InvalidateAndScroll()
451 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
453 DoPaintMessageLoop();
456 /*********************************************************************/
458 bool CACListWnd::EnsureVisible(int item
, bool m_bWait
)
460 if(item
> m_lTopIndex
&& item
< m_lTopIndex
+ m_VisibleItems
)
461 return false; // ist visible
463 if(item
> m_lTopIndex
) // scroll down
466 for(int i
= m_lTopIndex
; i
< m_len
; i
++)
468 if(i
>= m_lCount
-m_VisibleItems
)
470 if(i
>= m_lCount
-m_VisibleItems
|| i
+ m_VisibleItems
> item
)
479 InvalidateAndScroll();
481 DoPaintMessageLoop();
484 InvalidateAndScroll();
488 if(item
< m_lTopIndex
) // scroll up
490 while(item
< m_lTopIndex
)
501 InvalidateAndScroll();
503 DoPaintMessageLoop();
507 InvalidateAndScroll();
514 /*********************************************************************/
516 bool CACListWnd::SelectItem(int item
)
523 EnsureVisible(m_lSelItem
,false);
530 if(!EnsureVisible(item
,true))
536 /*********************************************************************/
538 int CACListWnd::FindStringExact( int nStartAfter
, LPCTSTR lpszString
)
540 if(nStartAfter
> m_SearchList
.GetSize())
543 for(int i
= nStartAfter
+1; i
< m_SearchList
.GetSize(); i
++)
544 if(m_SearchList
.GetAt(i
).Compare(lpszString
) == 0)
549 /*********************************************************************/
552 * NEW: m_bDisplayOnly
554 int CACListWnd::FindString(int nStartAfter
, LPCTSTR lpszString
, bool m_bDisplayOnly
)
556 long m_AktCount
= (long)m_DisplayList
.GetSize();
560 CString m_Str1
,m_Str2
= lpszString
;
567 if(nStartAfter
> m_SearchList
.GetSize())
579 m_DisplayList
.RemoveAll();
583 for(int i
= nStartAfter
+1; i
< m_SearchList
.GetSize(); i
++)
586 m_Str1
= m_PrefixChar
;
590 m_Str1
+= m_SearchList
.GetAt(i
);
594 if(m_lMode
& _MODE_FIND_ALL_
)
596 if(m_Str1
.Find(m_Str2
) >= 0)
598 m_DisplayList
.Add(m_SearchList
.GetAt(i
));
601 else // _MODE_FIND_EXACT_
603 if(m_Str1
.Find(m_Str2
) == 0)
605 m_DisplayList
.Add(m_SearchList
.GetAt(i
));
610 m_lCount
= (long)m_DisplayList
.GetSize();
617 m_pEditParent
->GetWindowRect(rcWnd
);
625 iHeight
= m_lCount
*m_ItemHeight
+(GetSystemMetrics(SM_CYBORDER
)*2);
627 if(m_lCount
> _MAX_ENTRYS_
)
628 iHeight
= _MAX_ENTRYS_
*m_ItemHeight
+(GetSystemMetrics(SM_CYBORDER
)*2);
630 if(!m_LastSize
.IsRectEmpty())
632 iWight
= m_LastSize
.Width();
633 iHeight
= m_LastSize
.Height();
634 rcWnd
.top
+= rcWnd
.Height();
635 rcWnd
.right
= rcWnd
.left
+iWight
;
636 rcWnd
.bottom
= rcWnd
.top
+iHeight
;
638 SetWindowPos(&CWnd::wndTopMost
, rcWnd
.left
,
645 SetWindowPos(&CWnd::wndTopMost
, rcWnd
.left
,
646 rcWnd
.top
+ rcWnd
.Height(),
651 if(m_AktCount
!= m_DisplayList
.GetSize())
654 SortList(m_DisplayList
);
664 /*********************************************************************/
666 int CACListWnd::SelectString(LPCTSTR lpszString
)
668 int item
= FindString(-1, lpszString
);
673 /*********************************************************************/
675 bool CACListWnd::GetText(int item
, CString
& m_Text
)
677 if(item
< 0 || item
> m_SearchList
.GetSize())
679 m_Text
= m_SearchList
.GetAt(item
);
683 /*********************************************************************/
685 void CACListWnd::OnShowWindow(BOOL bShow
, UINT nStatus
)
689 m_nIDTimer
= (long)SetTimer( IDTimerInstall
, 200, NULL
);
690 m_pEditParent
->GetParent()->GetWindowRect(m_ParentRect
);
695 KillTimer(IDTimerInstall
);
701 CWnd::OnShowWindow(bShow
, nStatus
);
702 ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW
));
705 /*********************************************************************/
707 void CACListWnd::OnNcLButtonDown(UINT nHitTest
, CPoint point
)
710 if(OnNcHitTest(point
) == HTBOTTOMRIGHT
)
711 GetWindowRect(m_LastSize
);
712 CWnd::OnNcLButtonDown(nHitTest
, point
);
715 /*********************************************************************/
717 CString
CACListWnd::GetString()
719 int i
= (int)m_DisplayList
.GetSize();
723 if(i
<= m_lSelItem
|| m_lSelItem
== -1)
728 return m_DisplayList
.GetAt(i
);
731 /*********************************************************************/
733 void CACListWnd::OnVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
735 CWnd::OnVScroll(nSBCode
, nPos
, pScrollBar
);
736 long m_oldlTopIndex
= m_lTopIndex
;
744 m_lTopIndex
-= m_VisibleItems
;
750 m_lTopIndex
+= m_VisibleItems
;
751 if(m_lTopIndex
>= m_lCount
-m_VisibleItems
)
752 m_lTopIndex
= m_lCount
-m_VisibleItems
;
763 if(m_lTopIndex
>= m_lCount
-m_VisibleItems
)
764 m_lTopIndex
= m_lCount
-m_VisibleItems
;
772 m_VertBar
.SetScrollPos(m_lTopIndex
,true);
774 if(m_oldlTopIndex
!= m_lTopIndex
)
778 /*********************************************************************/
780 CString
CACListWnd::GetNextString(int nChar
)
793 m_lSelItem
-= m_VisibleItems
;
799 m_lSelItem
+= m_VisibleItems
;
800 if(m_lSelItem
>= m_lCount
-1)
801 m_lSelItem
= m_lCount
-1;
809 m_lSelItem
= m_lCount
-1;
814 m_lSelItem
= m_lCount
-1;
816 if(m_lSelItem
>= m_lCount
)
819 if(EnsureVisible(m_lSelItem
,(m_lCount
> 50) ? false : true))
820 InvalidateAndScroll();
825 /*********************************************************************/
827 void CACListWnd::OnMouseMove(UINT nFlags
, CPoint point
)
829 CWnd::OnMouseMove(nFlags
, point
);
830 int sel
= HitTest(point
);
837 /*********************************************************************/
839 void CACListWnd::OnTimer(UINT_PTR nIDEvent
)
841 CWnd::OnTimer(nIDEvent
);
844 m_pEditParent
->GetParent()->GetWindowRect(m_ParentRect1
);
845 if(!m_ParentRect1
.EqualRect(m_ParentRect
))
849 /*********************************************************************/
851 void CACListWnd::OnGetMinMaxInfo(MINMAXINFO FAR
* lpMMI
)
856 long m_lMinY1
= GetSystemMetrics(SM_CYHSCROLL
)*2 + GetSystemMetrics(SM_CYSIZEFRAME
) + GetSystemMetrics(SM_CXHTHUMB
),
857 m_lMinY2
= m_lCount
* m_ItemHeight
+ (GetSystemMetrics(SM_CYBORDER
)*2);
859 if(m_VisibleItems
> m_lCount
-1 && m_lMinY2
< m_lMinY1
)
860 lpMMI
->ptMinTrackSize
.y
= m_lMinY2
;
862 lpMMI
->ptMinTrackSize
.y
= m_lMinY1
;
865 lpMMI
->ptMinTrackSize
.x
= GetSystemMetrics(SM_CXHSCROLL
)*4;
869 if(m_pEditParent
!= NULL
)
872 m_pEditParent
->GetWindowRect (&rc
);
873 lpMMI
->ptMinTrackSize
.x
= rc
.right
- rc
.left
;
877 CWnd::OnGetMinMaxInfo(lpMMI
);
880 /*********************************************************************/
882 int CACListWnd::CompareString(const void* p1
, const void* p2
)
884 return _stricmp( * ( char** ) p1
, * ( char** ) p2
);
887 /*********************************************************************/
889 void CACListWnd::SortList(CStringArray
& m_List
)
891 int m_Count
= (int)m_List
.GetSize();
896 CStringArray m_Liste1
;
897 m_Liste1
.Copy(m_List
);
899 LPCTSTR
* ppSortArray
= new LPCTSTR
[m_Count
+1];
902 for(i
=0; i
< m_Count
; i
++)
904 ppSortArray
[i
] = (LPCTSTR
)m_Liste1
.GetAt(i
);
909 qsort(ppSortArray
, m_Count
, sizeof(LPCTSTR
), CompareString
);
911 for(i
=0; i
< m_Count
; i
++)
913 m_List
.Add((LPCTSTR
) ppSortArray
[i
]);
915 m_Liste1
.RemoveAll();
916 delete [] ppSortArray
;
920 /*********************************************************************/
925 void CACListWnd::CopyList()
927 m_DisplayList
.Copy(m_SearchList
);
928 m_lCount
= (long)m_DisplayList
.GetSize();
930 FindString(0,_T(""),true);
933 /*********************************************************************/