00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "CATListBox.h"
00015 #include "CATWindow.h"
00016 #include "CATEventDefs.h"
00017
00018 CATListBox::CATListBox( const CATString& element,
00019 const CATString& rootDir)
00020 : CATControlWnd(element, rootDir)
00021 {
00022 fCurSel = -1;
00023 fValue = -1;
00024 fMinValue = -1;
00025 fMaxValue = -1;
00026 fFont = 0;
00027
00028 this->fWindowStyle = WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | LBS_DISABLENOSCROLL | WS_VSCROLL | LBS_HASSTRINGS | LBS_OWNERDRAWFIXED;
00029 this->fWindowType = "LISTBOX";
00030 }
00031
00032
00033 bool CATListBox::OnControlEvent( const CATEvent& event, CATInt32& result)
00034 {
00035 return false;
00036 }
00037
00038 CATResult CATListBox::OSEvent( const CATEvent& event, CATInt32& retVal)
00039 {
00040
00041
00042
00043 switch (event.fEventCode)
00044 {
00045 case CATEVENT_WINDOWS_EVENT:
00046 switch (event.fIntParam2)
00047 {
00048 case WM_COMMAND:
00049 if (event.fIntParam4 == (CATInt32)this->fControlWnd)
00050 {
00051 switch (HIWORD((CATUInt32)event.fIntParam3))
00052 {
00053 case LBN_SELCHANGE:
00054 {
00055 int item = ::SendMessage(fControlWnd,LB_GETCURSEL,0,0);
00056 if (item >= 0)
00057 {
00058 CATLISTINFO* listInfo = 0;
00059 listInfo = (CATLISTINFO*)::SendMessage(fControlWnd,LB_GETITEMDATA,item,0);
00060 if (listInfo != 0)
00061 {
00062 this->fCurSel = item;
00063 this->fValue = (CATFloat32)fCurSel;
00064 ((CATGuiObj*)fParent)->OnCommand(this->GetCommand(), this);
00065 this->GetWindow()->OSHideToolTip();
00066 return CAT_SUCCESS;
00067 }
00068 }
00069 }
00070 break;
00071 }
00072 }
00073 break;
00074 }
00075 break;
00076 }
00077
00078 return CATControlWnd::OnEvent(event,retVal);
00079 }
00080
00081 void CATListBox::OnParentCreate()
00082 {
00083 CATControlWnd::OnParentCreate();
00084
00085 this->SetCurSel(-1);
00086
00087 fFont = GetWindow()->OSGetFont(fFontName,fFontSize);
00088 ::SendMessage(this->fControlWnd, WM_SETFONT,(WPARAM)fFont,0);
00089 }
00090
00091
00092 void CATListBox::OnParentDestroy()
00093 {
00094 if (fFont != 0)
00095 {
00096 GetWindow()->OSReleaseFont(fFont);
00097 }
00098 CATControlWnd::OnParentDestroy();
00099 }
00100
00101
00102 void CATListBox::OSClearList()
00103 {
00104 SendMessage(fControlWnd, LB_RESETCONTENT,0,0);
00105 }
00106
00107 CATResult CATListBox::OSAddItem( CATInt32 index, const CATString& displayText, const CATLISTINFO* listInfo)
00108 {
00109 CATInt32 item = SendMessage(fControlWnd,LB_ADDSTRING,0,(LONG)(const char*)displayText);
00110 if (item < 0)
00111 {
00112 return false;
00113 }
00114
00115 SendMessage(fControlWnd, LB_SETITEMDATA, item, (LONG)listInfo);
00116 return true;
00117
00118 }
00119
00120 CATResult CATListBox::OSRemoveItem( CATInt32 index )
00121 {
00122 SendMessage(fControlWnd,LB_DELETESTRING, index, 0);
00123 return CAT_SUCCESS;
00124 }
00125
00126 CATInt32 CATListBox::OSGetCurSel()
00127 {
00128 CATInt32 item = SendMessage(fControlWnd,LB_GETCURSEL,0,0);
00129 return item;
00130 }
00131
00132 CATResult CATListBox::OSSetCurSel( CATInt32 index )
00133 {
00134 SendMessage(fControlWnd,LB_SETCURSEL,index,0);
00135 return CAT_SUCCESS;
00136 }
00137
00138 void CATListBox::OSOnMeasureItem(CATLISTINFO* listItem, CATUInt32& width, CATUInt32& height)
00139 {
00140
00141
00142 CATFONT measureFont = this->GetWindow()->OSGetFont(fFontName,fFontSize);
00143 HWND hwnd = this->GetWindow()->OSGetWnd();
00144 HDC curDC = ::GetDC(hwnd);
00145 CATFONT oldFont = (HFONT)::SelectObject(curDC,measureFont);
00146
00147
00148 SIZE textSize;
00149 textSize.cx = 0;
00150 textSize.cy = 0;
00151 CATString filtered = FilterGUIString(listItem->DisplayText);
00152
00153 if (filtered.IsEmpty() == false)
00154 {
00155 ::GetTextExtentExPoint( curDC,
00156 filtered.GetUnicodeBuffer(),
00157 filtered.LengthCalc(),
00158 this->GetWindow()->GetRect().Width(),
00159 NULL,
00160 NULL,
00161 &textSize);
00162
00163 filtered.ReleaseBuffer();
00164 }
00165
00166 height = CATMax((CATUInt32)(textSize.cy + 2), (CATUInt32)10 );
00167 width = textSize.cx + 25;
00168
00169
00170 ::SelectObject(curDC,oldFont);
00171 ::ReleaseDC(hwnd,curDC);
00172 this->GetWindow()->OSReleaseFont(measureFont);
00173 }
00174
00175 void CATListBox::OSOnDrawItem( CATLISTINFO* listItem, bool selected, CATDRAWCONTEXT hDC, CATRect rect )
00176 {
00177 CATColor colorFore = GetColorFore();
00178 CATColor colorBack = GetColorBack();
00179
00180 RECT drawRect;
00181 ::SetRect(&drawRect, rect.left, rect.top,rect.right,rect.bottom);
00182
00183 if (selected & ODS_SELECTED)
00184 {
00185 CATSwap(colorFore,colorBack);
00186 }
00187
00188 HBRUSH bgBrush = ::CreateSolidBrush(RGB(colorBack.r, colorBack.g, colorBack.b));
00189 ::FillRect(hDC, &drawRect, bgBrush);
00190
00191 int oldMode = ::SetBkMode(hDC,TRANSPARENT);
00192 COLORREF oldColor = ::SetTextColor(hDC,RGB(colorFore.r,colorFore.g,colorFore.b));
00193
00194 if (listItem->DisplayText.IsEmpty())
00195 {
00196
00197 CATInt32 yPos = (drawRect.top + drawRect.bottom)/2;
00198 HPEN linePen = ::CreatePen(PS_SOLID,1,RGB(colorFore.r, colorFore.g, colorFore.b));
00199 HPEN oldPen = (HPEN)::SelectObject(hDC, linePen);
00200
00201 ::MoveToEx (hDC, drawRect.left + 2, yPos, NULL);
00202 ::LineTo (hDC, drawRect.right - 2, yPos);
00203
00204 ::SelectObject(hDC,oldPen);
00205 ::DeleteObject(oldPen);
00206
00207 }
00208 else
00209 {
00210
00211 CATFONT drawFont = this->GetWindow()->OSGetFont(fFontName,fFontSize);
00212 CATFONT oldFont = (HFONT)::SelectObject(hDC,drawFont);
00213
00214
00215 DWORD textStyle = DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_SINGLELINE;
00216
00217 RECT rcText;
00218 ::SetRect(&rcText, drawRect.left, drawRect.top, drawRect.right, drawRect.bottom);
00219 rcText.left += 10;
00220
00221
00222 CATString filtered = FilterGUIString(listItem->DisplayText);
00223 ::DrawTextEx( hDC,
00224 filtered.GetUnicodeBuffer(),
00225 -1,
00226 &rcText,textStyle,NULL);
00227 ::SelectObject(hDC,oldFont);
00228 this->GetWindow()->OSReleaseFont(drawFont);
00229 }
00230
00231
00232
00233
00234
00235 ::SetTextColor(hDC,oldColor);
00236 ::SetBkMode(hDC, oldMode);
00237
00238 ::DeleteObject(bgBrush);
00239
00240 }