Exemple #1
0
RECT TaskList::adjustSize()
{
	RECT rc;
	ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON);
	const int imgWidth = rc.right - rc.left;
	const int marge = 30;

	// Temporary set "selected" font to get the worst case widths
	::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFontSelected), 0);
	int maxwidth = -1;

	_rc.left = 0;
	_rc.top = 0;
	_rc.bottom = 0;
	for (int i = 0 ; i < _nbItem ; i++)
	{
		TCHAR buf[MAX_PATH];
		ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH);
		int width = ListView_GetStringWidth(_hSelf, buf);
		if (width > maxwidth)
			maxwidth = width;
		_rc.bottom += rc.bottom - rc.top;
	}
	_rc.right = maxwidth + imgWidth + marge;
	::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0);

	reSizeTo(_rc);
	return _rc;
}
Exemple #2
0
long GetLinestoFit( HWND hDlg, short win )
{
	long bh,h,t;
	RECT	rc;
	long numlines;
	HWND	hctrl = GetDlgItem(hDlg, IDC_FILEVIEW);

	AddToListView( hctrl, 0, "x" );
	ListView_GetItemRect( hctrl, 0, &rc, LVIR_BOUNDS );
	ListView_DeleteItem( hctrl, 0 );

	t = ListView_GetItemCount(hctrl);
	bh = rc.bottom - rc.top;

	GetControlRect( hDlg, hctrl, &rc );
	h = rc.bottom - rc.top;

	numlines = (h/bh)-1;
	if ( numlines != winStats[win].linesInWin )
	{
		// Changed the size of the window (vertically)
		winStats[win].resetScroll = 1;
		winStats[win].linesInWin = numlines;
	}

	return numlines;
}
bool ListView_GetContextMenuPoint(HWND p_list,LPARAM p_coords,POINT & p_point,int & p_selection) {
	if ((DWORD)p_coords == (DWORD)infinite) {
		int firstsel = ListView_GetFirstSelection(p_list);
		if (firstsel >= 0) {
			RECT rect;
			if (!ListView_GetItemRect(p_list,firstsel,&rect,LVIR_BOUNDS)) return false;
			p_point.x = (rect.left + rect.right) / 2;
			p_point.y = (rect.top + rect.bottom) / 2;
			if (!ClientToScreen(p_list,&p_point)) return false;
		} else {
			RECT rect;
			if (!GetClientRect(p_list,&rect)) return false;
			p_point.x = (rect.left + rect.right) / 2;
			p_point.y = (rect.top + rect.bottom) / 2;
			if (!ClientToScreen(p_list,&p_point)) return false;
		}
		p_selection = firstsel;
		return true;
	} else {
		POINT pt = {(short)LOWORD(p_coords),(short)HIWORD(p_coords)};
		p_point = pt;
		POINT client = pt;
		if (!ScreenToClient(p_list,&client)) return false;
		LVHITTESTINFO info;
		memset(&info,0,sizeof(info));
		info.pt = client;
		p_selection = ListView_HitTest(p_list,&info);
		return true;
	}
}
RECT TaskList::adjustSize()
{
	RECT rc;
	ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON);
	const int imgWidth = rc.right - rc.left;
	const int leftMarge = 30;
	const int xpBottomMarge = 5;
	const int w7BottomMarge = 15;

	// Temporary set "selected" font to get the worst case widths
	::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFontSelected), 0);
	int maxwidth = -1;

	_rc.left = 0;
	_rc.top = 0;
	_rc.bottom = 0;
	for (int i = 0 ; i < _nbItem ; ++i)
	{
		TCHAR buf[MAX_PATH];
		ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH);
		int width = ListView_GetStringWidth(_hSelf, buf);
		if (width > maxwidth)
			maxwidth = width;
		_rc.bottom += rc.bottom - rc.top;
	}
	_rc.right = maxwidth + imgWidth + leftMarge;
	ListView_SetColumnWidth(_hSelf, 0, _rc.right);
	::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0);

	reSizeTo(_rc);
	winVer ver = (NppParameters::getInstance())->getWinVersion();
	_rc.bottom += (ver <= WV_XP && ver != WV_UNKNOWN)?xpBottomMarge:w7BottomMarge;
	return _rc;
}
RECT TaskList::adjustSize()
{
	RECT rc;
	ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON);
	const int imgWidth = rc.right - rc.left;
	const int marge = 30;

	for (int i = 0 ; i < _nbItem ; i++)
	{
		char buf[MAX_PATH];
		ListView_GetItemText(_hSelf, i, 0, buf, sizeof(buf));
		int width = ListView_GetStringWidth(_hSelf, buf);

		if (width > (_rc.right - _rc.left))
			_rc.right = _rc.left + width + imgWidth + marge;

		_rc.bottom += rc.bottom - rc.top;

	}

	// additional space for horizontal scroll-bar
	_rc.bottom += rc.bottom - rc.top;

	reSizeTo(_rc);
	return _rc;
}
void ListView_GetContextMenuPoint(HWND p_list,LPARAM p_coords,POINT & p_point,int & p_selection) {
	if ((DWORD)p_coords == (DWORD)(-1)) {
		int firstsel = ListView_GetFirstSelection(p_list);
		if (firstsel >= 0) {
			ListView_EnsureVisible(p_list, firstsel, FALSE);
			RECT rect;
			WIN32_OP_D( ListView_GetItemRect(p_list,firstsel,&rect,LVIR_BOUNDS) );
			p_point.x = (rect.left + rect.right) / 2;
			p_point.y = (rect.top + rect.bottom) / 2;
			WIN32_OP_D( ClientToScreen(p_list,&p_point) );
		} else {
			RECT rect;
			WIN32_OP_D(GetClientRect(p_list,&rect));
			p_point.x = (rect.left + rect.right) / 2;
			p_point.y = (rect.top + rect.bottom) / 2;
			WIN32_OP_D(ClientToScreen(p_list,&p_point));
		}
		p_selection = firstsel;
	} else {
		POINT pt = {(short)LOWORD(p_coords),(short)HIWORD(p_coords)};
		p_point = pt;
		POINT client = pt;
		WIN32_OP_D( ScreenToClient(p_list,&client) );
		LVHITTESTINFO info = {};
		info.pt = client;
		p_selection = ListView_HitTest(p_list,&info);
	}
}
Exemple #7
0
bool QueueWindow::GetSelectedQueueRect(RECT * pRect) {
	int selectedindex = ListView_GetNextItem(m_hwnd, -1, LVNI_ALL|LVNI_SELECTED);
	if (selectedindex == -1)
		return false;

	BOOL res = ListView_GetItemRect(m_hwnd, selectedindex, pRect, LVIR_LABEL);
	return (res == TRUE);
}
Exemple #8
0
// AutoSizeControl ----------------------------------------------------------
void CCodeListCtrl::AutoSizeControl()
{
   HDC hdc = ::GetDC( m_hWnd );
   int iItems = GetItemCount();
   CRect rWnd, rSize, rClient, rScreen;
   DWORD dwStyle = GetWindowLong( GWL_STYLE );
   DWORD dwExStyle = GetWindowLong( GWL_EXSTYLE );

   // Get the height of a single line of text
   VERIFY( ListView_GetItemRect( m_hWnd, 0, &rSize, LVIR_BOUNDS ) );

   // Client area should be big enough for about 10 lines, unless there are
   // fewer than 10 lines to begin with...
   //
   rClient.bottom = rSize.Height() * min( 10, iItems );

   // Get the width required to display entire column + scroll bar
   SendMessage( LVM_SETCOLUMNWIDTH, 0, LVSCW_AUTOSIZE );

   rClient.right = SendMessage( LVM_GETCOLUMNWIDTH, 0, 0 );

   // Add space for scroll bar only if necessary.
   if( iItems > 10 )
      rClient.right += ::GetSystemMetrics( SM_CXVSCROLL );

   // Keep control on visible part of screen, if possible
   ::SystemParametersInfo( SPI_GETWORKAREA, 0, (PVOID)&rScreen, 0 );

   if( rClient.Width() > rScreen.Width() )
   {
      rClient.right = rScreen.Width();
      rClient.bottom += ::GetSystemMetrics( SM_CYHSCROLL );
   }

   ::AdjustWindowRectEx( &rClient, dwStyle, FALSE, dwExStyle );
   GetWindowRect( &rWnd );

   if( rWnd.left + rClient.Width() > rScreen.Width() )
      rWnd.left = rScreen.Width() - rClient.Width();

   if( rWnd.left < rScreen.left )
      rWnd.left = rScreen.left;

   if( rWnd.top + rClient.Height() > rScreen.Height() )
      rWnd.top = rScreen.Height() - rClient.Height();

   if( rWnd.top < rScreen.top )
      rWnd.top = rScreen.top;

   // Reposition and/or resize the window
   ::MoveWindow( m_hWnd, rWnd.left, rWnd.top, rClient.Width(),
      rClient.Height(), TRUE );
}
Exemple #9
0
void LV_InvalidateRow(HWND hwnd, INT iRow = -1)
{
    if (iRow == -1)
        iRow = ListView_GetNextItem(hwnd, -1, LVNI_SELECTED);
    if (iRow == -1)
        return;

    RECT Rect;
    LPRECT GccIsWhining = &Rect;
    ListView_GetItemRect(hwnd, iRow, GccIsWhining, LVIR_BOUNDS);
    InvalidateRect(hwnd, &Rect, FALSE);
}
Exemple #10
0
void SelectFoundTextInList( long item, long pos, long scrollOffset )
{
	int state = LVIS_SELECTED|LVIS_FOCUSED;
	ListView_SetItemState( hWndLangBuilderListView, pos, state, state );
	currItemSel = pos;
	RECT rc;
	ListView_GetItemRect( hWndLangBuilderListView, pos, &rc, LVIR_LABEL );
	int rowHeight = rc.bottom-rc.top;
	int scrollTo;
	int count = ListView_GetItemCount( hWndLangBuilderListView );
	if ( item > 0 )
		scrollTo = (pos-item+scrollOffset+1) * rowHeight;
	else 
		scrollTo = (pos-item-count+scrollOffset+1) * rowHeight;
	ListView_Scroll( hWndLangBuilderListView, 0, scrollTo );
	DisplayCurrListItemInTextBox( pos );
}
Exemple #11
0
void CPpcMainWnd::OnMouseMove(int fKey, int x, int y)
{
	if (m_fListDrag) {
		RECT rcItem;
		if (!ListView_GetItemRect(m_hwndLV, 0, &rcItem, LVIR_BOUNDS))
			return;

		POINT pt = {x, y};
		ClientToScreen(m_hWnd, &pt);
		ScreenToClient(m_hwndLV, &pt);

		RECT rcLV;
		GetClientRect(m_hwndLV, &rcLV);
		if (pt.y < RECT_HEIGHT(&rcItem)) {
			ListView_Scroll(m_hwndLV, 0, -RECT_HEIGHT(&rcItem));
			OnFileUp();
			m_nListDragItem = max(m_nListDragItem - 1, 0);
		}
		else if (pt.y > rcLV.bottom - RECT_HEIGHT(&rcItem)) {
			ListView_Scroll(m_hwndLV, 0, RECT_HEIGHT(&rcItem));
			OnFileDown();
			m_nListDragItem = min(m_nListDragItem + 1, ListView_GetItemCount(m_hwndLV) - 1);
		}
		else {
			LVHITTESTINFO lvhti;
			lvhti.pt.x = pt.x; 
			lvhti.pt.y = pt.y;
			int nItem = ListView_HitTest(m_hwndLV, &lvhti);
			if (nItem == -1)
				return;

			if (nItem - m_nListDragItem > 0) {
				for (int i = 0; i < nItem - m_nListDragItem; i++)
					OnFileDown();
				m_nListDragItem = nItem;
			}
			else if (nItem - m_nListDragItem < 0) {
				for (int i = 0; i < m_nListDragItem - nItem; i++)
					OnFileUp();
				m_nListDragItem = nItem;
			}
		}
	}
	else
		CMainWnd::OnMouseMove(fKey, x, y);
}
Exemple #12
0
void CPlayListDlg::OnMouseMove(int x, int y)
{
	if (m_fListDrag) {
		RECT rcItem;
		HWND hwndLV = GetDlgItem(m_hWnd, IDC_PLAY_LIST);
		if (!ListView_GetItemRect(hwndLV, 0, &rcItem, LVIR_BOUNDS))
			return;

		POINT pt = {x, y};
		ClientToScreen(m_hWnd, &pt);
		ScreenToClient(hwndLV, &pt);

		RECT rcLV;
		GetClientRect(hwndLV, &rcLV);
		if (pt.y < RECT_HEIGHT(&rcItem)) {
			ListView_Scroll(hwndLV, 0, -RECT_HEIGHT(&rcItem));
			OnUp(FALSE);
			m_nDragItem = max(m_nDragItem - 1, 0);
		}
		else if (pt.y > rcLV.bottom - RECT_HEIGHT(&rcItem)) {
			ListView_Scroll(hwndLV, 0, RECT_HEIGHT(&rcItem));
			OnDown(FALSE);
			m_nDragItem = min(m_nDragItem + 1, ListView_GetItemCount(hwndLV) - 1);
		}
		else {
			LVHITTESTINFO lvhti;
			lvhti.pt.x = pt.x; 
			lvhti.pt.y = pt.y;
			int nItem = ListView_HitTest(hwndLV, &lvhti);
			if (nItem == -1)
				return;

			if (nItem - m_nDragItem > 0) {
				for (int i = 0; i < nItem - m_nDragItem; i++)
					OnDown(FALSE);
				m_nDragItem = nItem;
			}
			else if (nItem - m_nDragItem < 0) {
				for (int i = 0; i < m_nDragItem - nItem; i++)
					OnUp(FALSE);
				m_nDragItem = nItem;
			}
		}
	}
}
Exemple #13
0
BOOLEAN PhGetListViewContextMenuPoint(
    __in HWND ListViewHandle,
    __out PPOINT Point
    )
{
    INT selectedIndex;
    RECT bounds;
    RECT clientRect;

    // The user pressed a key to display the context menu.
    // Suggest where the context menu should display.

    if ((selectedIndex = ListView_GetNextItem(ListViewHandle, -1, LVNI_SELECTED)) != -1)
    {
        if (ListView_GetItemRect(ListViewHandle, selectedIndex, &bounds, LVIR_BOUNDS))
        {
            Point->x = bounds.left + PhSmallIconSize.X / 2;
            Point->y = bounds.top + PhSmallIconSize.Y / 2;

            GetClientRect(ListViewHandle, &clientRect);

            if (Point->x < 0 || Point->y < 0 || Point->x >= clientRect.right || Point->y >= clientRect.bottom)
            {
                // The menu is going to be outside of the control. Just put it at the top-left.
                Point->x = 0;
                Point->y = 0;
            }

            ClientToScreen(ListViewHandle, Point);

            return TRUE;
        }
    }

    Point->x = 0;
    Point->y = 0;
    ClientToScreen(ListViewHandle, Point);

    return FALSE;
}
Exemple #14
0
void TcodecsPage::moveCBX(bool isscroll)
{
    if (isscroll && !IsWindowVisible(hcbx)) {
        return;
    }
    LVCOLUMN lvc0,lvc1;
    lvc0.mask=lvc1.mask=LVCF_WIDTH;
    ListView_GetColumn(hlv,0,&lvc0);
    ListView_GetColumn(hlv,1,&lvc1);
    RECT lvr;
    GetWindowRect(hlv,&lvr);
    RECT pr;
    GetWindowRect(GetParent(hlv),&pr);
    OffsetRect(&lvr,-pr.left,-pr.top);
    RECT ir;
    int iItem=lvGetSelItem(IDC_LV_INCODECS);
    ListView_GetItemRect(hlv,iItem,&ir,LVIR_BOUNDS);
    MoveWindow(hcbx,lvr.left+lvc0.cx+3,lvr.top+ir.top-1,lvc1.cx,12,TRUE);
    show(true,IDC_CBX_INCODECS);
    SetWindowPos(hcbx,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
    SetFocus(hcbx);
}
void Dlg_MemBookmark::UpdateBookmarks( bool bForceWrite )
{
	if ( !IsWindowVisible( m_hMemBookmarkDialog ) )
		return;

	if ( m_vBookmarks.size() == 0 )
		return;

	HWND hList = GetDlgItem( m_hMemBookmarkDialog, IDC_RA_LBX_ADDRESSES );

	int index = 0;
	for ( MemBookmark* bookmark : m_vBookmarks )
	{
		if ( bookmark->Frozen() && !bForceWrite )
		{
			WriteFrozenValue( *bookmark );
			index++;
			continue;
		}

		unsigned int mem_value = GetMemory( bookmark->Address(), bookmark->Type() );

		if ( bookmark->Value() != mem_value )
		{
			bookmark->SetPrevious( bookmark->Value() );
			bookmark->SetValue( mem_value );
			bookmark->IncreaseCount();

			RECT rcBounds;
			ListView_GetItemRect(hList, index, &rcBounds, LVIR_BOUNDS);
			InvalidateRect(hList, &rcBounds, FALSE);
		}

		index++;
	}
}
INT_PTR Dlg_MemBookmark::MemBookmarkDialogProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	PMEASUREITEMSTRUCT pmis;
	PDRAWITEMSTRUCT pdis;
	int nSelect;
	HWND hList;
	int offset = 2;

	RECT rcBounds, rcLabel;

	switch ( uMsg )
	{
		case WM_INITDIALOG:
		{
			GenerateResizes( hwnd );

			m_hMemBookmarkDialog = hwnd;
			hList = GetDlgItem( m_hMemBookmarkDialog, IDC_RA_LBX_ADDRESSES );

			SetupColumns( hList );

			// Auto-import bookmark file when opening dialog
			if ( g_pCurrentGameData->GetGameID() != 0 )
			{
				std::string file = RA_DIR_BOOKMARKS + std::to_string( g_pCurrentGameData->GetGameID() ) + "-Bookmarks.txt";
				ImportFromFile( file );
			}

			RestoreWindowPosition( hwnd, "Memory Bookmarks", true, false );
			return TRUE;
		}

		case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
			lpmmi->ptMinTrackSize = pDlgMemBookmarkMin;
		}
		break;

		case WM_SIZE:
		{
			RARect winRect;
			GetWindowRect( hwnd, &winRect );

			for ( ResizeContent content : vDlgMemBookmarkResize )
				content.Resize( winRect.Width(), winRect.Height() );

			//InvalidateRect( hwnd, NULL, TRUE );
			RememberWindowSize(hwnd, "Memory Bookmarks");
		}
		break;

		case WM_MOVE:
			RememberWindowPosition(hwnd, "Memory Bookmarks");
			break;

		case WM_MEASUREITEM:
			pmis = (PMEASUREITEMSTRUCT)lParam;
			pmis->itemHeight = 16;
			return TRUE;

		case WM_DRAWITEM:
		{
			pdis = (PDRAWITEMSTRUCT)lParam;

			// If there are no list items, skip this message.
			if ( pdis->itemID == -1 )
				break;

			switch ( pdis->itemAction )
			{
				case ODA_SELECT:
				case ODA_DRAWENTIRE:

					hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );

					ListView_GetItemRect( hList, pdis->itemID, &rcBounds, LVIR_BOUNDS );
					ListView_GetItemRect( hList, pdis->itemID, &rcLabel, LVIR_LABEL );
					RECT rcCol ( rcBounds );
					rcCol.right = rcCol.left + ListView_GetColumnWidth( hList, 0 );

					// Draw Item Label - Column 0
					wchar_t buffer[ 512 ];
					if ( m_vBookmarks[ pdis->itemID ]->Decimal() )
						swprintf_s ( buffer, 512, L"(D)%s", m_vBookmarks[ pdis->itemID ]->Description().c_str() );
					else
						swprintf_s ( buffer, 512, L"%s", m_vBookmarks[ pdis->itemID ]->Description().c_str() );

					if ( pdis->itemState & ODS_SELECTED )
					{
						SetTextColor( pdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
						SetBkColor( pdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
						FillRect( pdis->hDC, &rcBounds, GetSysColorBrush( COLOR_HIGHLIGHT ) );
					}
					else
					{
						SetTextColor( pdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) );

						COLORREF color;

						if ( m_vBookmarks[ pdis->itemID ]->Frozen() )
							color = RGB( 255, 255, 160 );
						else
							color = GetSysColor( COLOR_WINDOW );

						HBRUSH hBrush = CreateSolidBrush( color );
						SetBkColor( pdis->hDC, color );
						FillRect( pdis->hDC, &rcBounds, hBrush );
						DeleteObject( hBrush );
					}

					if ( wcslen( buffer ) > 0 )
					{
						rcLabel.left += ( offset / 2 );
						rcLabel.right -= offset;

						DrawTextW( pdis->hDC, buffer, wcslen( buffer ), &rcLabel, DT_SINGLELINE | DT_LEFT | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS );
					}

					// Draw Item Label for remaining columns
					LV_COLUMN lvc;
					lvc.mask = LVCF_FMT | LVCF_WIDTH;

					for ( size_t i = 1; ListView_GetColumn( hList, i, &lvc ); ++i )
					{
						rcCol.left = rcCol.right;
						rcCol.right += lvc.cx;

						switch ( i )
						{
							case CSI_ADDRESS:
								swprintf_s ( buffer, 512, L"%06x", m_vBookmarks[ pdis->itemID ]->Address() );
								break;
							case CSI_VALUE:
								if ( m_vBookmarks[ pdis->itemID ]->Decimal() )
									swprintf_s ( buffer, 512, L"%u", m_vBookmarks[ pdis->itemID ]->Value() );
								else
								{
									switch ( m_vBookmarks[ pdis->itemID ]->Type() )
									{
										case 1: swprintf_s ( buffer, 512, L"%02x", m_vBookmarks[ pdis->itemID ]->Value() ); break;
										case 2: swprintf_s ( buffer, 512, L"%04x", m_vBookmarks[ pdis->itemID ]->Value() ); break;
										case 3: swprintf_s ( buffer, 512, L"%08x", m_vBookmarks[ pdis->itemID ]->Value() ); break;
									}
								}
								break;
							case CSI_PREVIOUS:
								if ( m_vBookmarks[ pdis->itemID ]->Decimal() )
									swprintf_s ( buffer, 512, L"%u", m_vBookmarks[ pdis->itemID ]->Previous() );
								else
								{
									switch ( m_vBookmarks[ pdis->itemID ]->Type() )
									{
										case 1: swprintf_s ( buffer, 512, L"%02x", m_vBookmarks[ pdis->itemID ]->Previous() ); break;
										case 2: swprintf_s ( buffer, 512, L"%04x", m_vBookmarks[ pdis->itemID ]->Previous() ); break;
										case 3: swprintf_s ( buffer, 512, L"%08x", m_vBookmarks[ pdis->itemID ]->Previous() ); break;
									}
								}
								break;
							case CSI_CHANGES:
								swprintf_s ( buffer, 512, L"%d", m_vBookmarks[ pdis->itemID ]->Count() );
								break;
							default:
								swprintf_s ( buffer, 512, L"" );
								break;
						}

						if ( wcslen( buffer ) == 0 )
							continue;

						UINT nJustify = DT_LEFT;
						switch ( lvc.fmt & LVCFMT_JUSTIFYMASK )
						{
							case LVCFMT_RIGHT:
								nJustify = DT_RIGHT;
								break;
							case LVCFMT_CENTER:
								nJustify = DT_CENTER;
								break;
							default:
								break;
						}

						rcLabel = rcCol;
						rcLabel.left += offset;
						rcLabel.right -= offset;

						DrawTextW( pdis->hDC, buffer, wcslen( buffer ), &rcLabel, nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS );
					}

					//if (pdis->itemState & ODS_SELECTED) //&& (GetFocus() == this)
					//	DrawFocusRect(pdis->hDC, &rcBounds);

					break;

				case ODA_FOCUS:
					break;
			}
			return TRUE;
		}

		case WM_NOTIFY:
		{
			switch ( LOWORD( wParam ) )
			{
				case IDC_RA_LBX_ADDRESSES:
					if ( ( (LPNMHDR)lParam )->code == NM_CLICK )
					{
						hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );

						nSelect = ListView_GetNextItem( hList, -1, LVNI_FOCUSED );

						if ( nSelect == -1 )
							break;
					}
					else if ( ( (LPNMHDR)lParam )->code == NM_DBLCLK )
					{
						hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );

						LPNMITEMACTIVATE pOnClick = (LPNMITEMACTIVATE)lParam;

						if ( pOnClick->iItem != -1 && pOnClick->iSubItem == CSI_DESC )
						{
							nSelItemBM = pOnClick->iItem;
							nSelSubItemBM = pOnClick->iSubItem;

							EditLabel ( pOnClick->iItem, pOnClick->iSubItem );
						}
						else if ( pOnClick->iItem != -1 && pOnClick->iSubItem == CSI_ADDRESS )
						{
							g_MemoryDialog.SetWatchingAddress( m_vBookmarks[ pOnClick->iItem ]->Address() );
							MemoryViewerControl::setAddress( ( m_vBookmarks[ pOnClick->iItem ]->Address() & 
								~( 0xf ) ) - ( (int)( MemoryViewerControl::m_nDisplayedLines / 2 ) << 4 ) + ( 0x50 ) );
						}
					}
			}
			return TRUE;
		}
		case WM_COMMAND:
		{
			switch ( LOWORD( wParam ) )
			{
				case IDOK:
				case IDCLOSE:
				case IDCANCEL:
					EndDialog( hwnd, true );
					return TRUE;

				case IDC_RA_ADD_BOOKMARK:
				{
					if ( g_MemoryDialog.GetHWND() != nullptr )
						AddAddress();

					return TRUE;
				}
				case IDC_RA_DEL_BOOKMARK:
				{
					HWND hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );
					int nSel = ListView_GetNextItem( hList, -1, LVNI_SELECTED );

					if ( nSel != -1 )
					{
						while ( nSel >= 0 )
						{
							MemBookmark* pBookmark = m_vBookmarks[ nSel ];

							// Remove from vector
							m_vBookmarks.erase( m_vBookmarks.begin() + nSel );

							// Remove from map
							std::vector<const MemBookmark*> *pVector;
							pVector = &m_BookmarkMap.find( pBookmark->Address() )->second;
							pVector->erase( std::find( pVector->begin(), pVector->end(), pBookmark ) );
							if ( pVector->size() == 0 )
								m_BookmarkMap.erase( pBookmark->Address() );

							delete pBookmark;

							ListView_DeleteItem( hList, nSel );

							nSel = ListView_GetNextItem( hList, -1, LVNI_SELECTED );
						}

						InvalidateRect( hList, NULL, FALSE );
					}

					return TRUE;
				}
				case IDC_RA_FREEZE:
				{
					if ( m_vBookmarks.size() > 0 )
					{
						hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );
						unsigned int uSelectedCount = ListView_GetSelectedCount( hList );

						if ( uSelectedCount > 0 )
						{
							for ( int i = ListView_GetNextItem( hList, -1, LVNI_SELECTED ); i >= 0; i = ListView_GetNextItem( hList, i, LVNI_SELECTED ) )
								m_vBookmarks[ i ]->SetFrozen( !m_vBookmarks[ i ]->Frozen() );
						}
						ListView_SetItemState( hList, -1, LVIF_STATE, LVIS_SELECTED );
					}
					return TRUE;
				}
				case IDC_RA_CLEAR_CHANGE:
				{
					if ( m_vBookmarks.size() > 0 )
					{
						hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );
						int idx = -1;
						for ( MemBookmark* bookmark : m_vBookmarks )
						{
							idx++;

							bookmark->ResetCount();
						}
						
						InvalidateRect( hList, NULL, FALSE );
					}

					return TRUE;
				}
				case IDC_RA_DECIMALBOOKMARK:
				{
					if ( m_vBookmarks.size() > 0 )
					{
						hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES );
						unsigned int uSelectedCount = ListView_GetSelectedCount( hList );

						if ( uSelectedCount > 0 )
						{
							for ( int i = ListView_GetNextItem( hList, -1, LVNI_SELECTED ); i >= 0; i = ListView_GetNextItem( hList, i, LVNI_SELECTED ) )
								m_vBookmarks[ i ]->SetDecimal( !m_vBookmarks[ i ]->Decimal() );
						}
						ListView_SetItemState( hList, -1, LVIF_STATE, LVIS_SELECTED );
					}
					return TRUE;
				}
				case IDC_RA_SAVEBOOKMARK:
				{
					ExportJSON();
					return TRUE;
				}
				case IDC_RA_LOADBOOKMARK:
				{
					std::string file = ImportDialog();
					if (file.length() > 0 )
						ImportFromFile( file );
					return TRUE;
				}
				default:
					return FALSE;
			}
		}
		default:
			break;
	}

	return FALSE;
}
Exemple #17
0
int populate_insert_dlg(HWND hwnd,HWND hlistview,TABLE_WINDOW *win)
{
	int i,count,widths[4]={0,0,0,0};
	int row_sel;
	char *cols[]={"field","data","type","size"};
	if(hlistview==0 || win==0)
		return FALSE;

	for(i=0;i<4;i++)
		widths[i]=lv_add_column(hlistview,cols[i],i);

	row_sel=ListView_GetSelectionMark(win->hlistview);

	count=lv_get_column_count(win->hlistview);

	for(i=0;i<count;i++){
		int w;
		char str[80]={0};
		lv_get_col_text(win->hlistview,i,str,sizeof(str));
		lv_insert_data(hlistview,i,FIELD_POS,str);
		w=get_str_width(hlistview,str);
		if(w>widths[FIELD_POS])
			widths[FIELD_POS]=w;
		if(row_sel>=0){
			str[0]=0;
			ListView_GetItemText(win->hlistview,row_sel,i,str,sizeof(str));
			lv_insert_data(hlistview,i,DATA_POS,str);
			w=get_str_width(hlistview,str);
			if(w>widths[DATA_POS])
				widths[DATA_POS]=w;
		}
		if(win->col_attr!=0){
			char *s="";
			if(!find_sql_type_str(win->col_attr[i].type,&s)){
				_snprintf(str,sizeof(str),"%i",win->col_attr[i].type);
				lv_insert_data(hlistview,i,TYPE_POS,str);
			}
			else
				lv_insert_data(hlistview,i,TYPE_POS,s);
			w=get_str_width(hlistview,s);
			if(w>widths[TYPE_POS])
				widths[TYPE_POS]=w;

			_snprintf(str,sizeof(str),"%i",win->col_attr[i].length);
			lv_insert_data(hlistview,i,SIZE_POS,str);
			w=get_str_width(hlistview,str);
			if(w>widths[SIZE_POS])
				widths[SIZE_POS]=w;
		}
	}
	{
		int total_width=0;
		for(i=0;i<4;i++){
			widths[i]+=12;
			ListView_SetColumnWidth(hlistview,i,widths[i]);
			total_width+=widths[i];
		}
		if(total_width>0){
			int width,height;
			RECT rect={0},irect={0},nrect={0};
			GetWindowRect(hwnd,&irect);
			get_nearest_monitor(irect.left,irect.top,total_width,100,&nrect);
			ListView_GetItemRect(hlistview,0,&rect,LVIR_BOUNDS);
			height=80+(count*(rect.bottom-rect.top+2));
			if((irect.top+height)>nrect.bottom){
				height=nrect.bottom-nrect.top-irect.top;
				if(height<320)
					height=320;
			}
			width=total_width+20;
			SetWindowPos(hwnd,NULL,0,0,width,height,SWP_NOMOVE|SWP_NOZORDER);
		}
	}

	return TRUE;
}
Exemple #18
0
LRESULT CALLBACK insert_dlg_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static TABLE_WINDOW *win=0;
	static HWND hlistview=0,hgrippy=0,hedit=0;
	static HFONT hfont=0;
	static WNDPROC origlistview=0;
	if(FALSE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		if(hwnd==hlistview)
			printf("-");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
	if(origlistview!=0 && hwnd==hlistview){
		if(msg==WM_GETDLGCODE){
			return DLGC_WANTARROWS;
		}
		return CallWindowProc(origlistview,hwnd,msg,wparam,lparam);
	}
	switch(msg){
	case WM_INITDIALOG:
		if(lparam==0){
			EndDialog(hwnd,0);
			break;
		}
		hedit=0;
		win=lparam;
		hlistview=CreateWindow(WC_LISTVIEW,"",WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS,
                                     0,0,
                                     0,0,
                                     hwnd,
                                     IDC_LIST1,
                                     ghinstance,
                                     NULL);
		if(hlistview!=0){
			ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT);
			hfont=SendMessage(win->hlistview,WM_GETFONT,0,0);
			if(hfont!=0)
				SendMessage(hlistview,WM_SETFONT,hfont,0);
			populate_insert_dlg(hwnd,hlistview,win);
			ListView_SetItemState(hlistview,0,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
			origlistview=SetWindowLong(hlistview,GWL_WNDPROC,(LONG)insert_dlg_proc);
		}
		set_title(hwnd,win);
		hgrippy=create_grippy(hwnd);
		resize_insert_dlg(hwnd);
		break;
	case WM_NOTIFY:
		{
			NMHDR *nmhdr=lparam;
			if(nmhdr!=0){
				switch(nmhdr->code){
				case NM_DBLCLK:
					if(hedit==0 && nmhdr->hwndFrom==hlistview)
						SendMessage(hwnd,WM_COMMAND,IDOK,0);
					break;
				case  LVN_COLUMNCLICK:
					{
						static sort_dir=0;
						NMLISTVIEW *nmlv=lparam;
						if(nmlv!=0){
							sort_listview(hlistview,sort_dir,nmlv->iSubItem);
							sort_dir=!sort_dir;
						}
					}
					break;
				case LVN_KEYDOWN:
					if(nmhdr->hwndFrom==hlistview)
					{
						LV_KEYDOWN *key=lparam;
						switch(key->wVKey){
						case VK_DOWN:
						case VK_RIGHT:
						case VK_NEXT:
							{
								int count,row_sel;
								count=ListView_GetItemCount(hlistview);
								row_sel=ListView_GetSelectionMark(hlistview);
								if(count>0 && row_sel==count-1)
									SetFocus(GetDlgItem(hwnd,IDOK));
							}
							break;
						case VK_DELETE:
							clear_selected_items(hlistview);
							break;
						case VK_F5:
							if(task_insert_row(win,hlistview))
								SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");
							break;
						case 'A':
							if(GetKeyState(VK_CONTROL)&0x8000){
								int i,count;
								count=ListView_GetItemCount(hlistview);
								for(i=0;i<count;i++){
									ListView_SetItemState(hlistview,i,LVIS_SELECTED,LVIS_SELECTED);
								}
								break;
							}
						default:
							{
								int ignore=FALSE;
								if(!is_entry_key(key->wVKey))
									ignore=TRUE;
								if(GetKeyState(VK_CONTROL)&0x8000)
									ignore=TRUE;
								if(ignore)
									return 1;
							}
						case ' ':
						case VK_F2:
						case VK_INSERT:
							{
								int row_sel=ListView_GetSelectionMark(hlistview);
								if(row_sel>=0 && hedit==0){
									hedit=CreateWindow("EDIT","",WS_THICKFRAME|WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|
											ES_LEFT|ES_AUTOHSCROLL,
											0,0,
											0,0,
											hwnd,
											IDC_EDIT1,
											ghinstance,
											NULL);
									if(hedit!=0){
										RECT rect={0},crect={0};
										int x,y,w,h;
										ListView_GetItemRect(hlistview,row_sel,&rect,LVIR_BOUNDS);
										lv_get_col_rect(hlistview,DATA_POS,&crect);
										x=crect.left-2;
										y=rect.top-2;
										w=crect.right-crect.left+8;
										h=rect.bottom-rect.top+8;
										SetWindowPos(hedit,HWND_TOP,x,y,w,h,0);
										if(hfont!=0)
											SendMessage(hedit,WM_SETFONT,hfont,0);
										if(is_entry_key(key->wVKey)){
											char str[2];
											char c=tolower(key->wVKey);
											if((GetKeyState(VK_SHIFT)&0x8000) || (GetKeyState(VK_CAPITAL)&1))
												c=toupper(c);
											str[0]=c;
											str[1]=0;
											SetWindowText(hedit,str);
											SendMessage(hedit,EM_SETSEL,1,1);

										}else{
											populate_edit_control(hlistview,hedit,row_sel);
										}
										SetFocus(hedit);
										wporigtedit=SetWindowLong(hedit,GWL_WNDPROC,(LONG)sc_edit);
									}
								}
							}
							break;
						}

					}
					break;
				}

			}
		}
		break;
	case WM_HSCROLL:
		if(lparam==hgrippy)
			SetFocus(hlistview);
		break;
	case WM_USER:
		if(hedit!=0 && lparam==hedit){
			hedit=0;
			SetFocus(hlistview);
		}
		else if(lparam==hlistview){
			if(wparam==IDOK){
				add_row_tablewindow(win,hlistview);
			}
			else
				SetFocus(GetDlgItem(hwnd,IDCANCEL));

			SetWindowText(GetDlgItem(hwnd,IDOK),"OK");
		}
		break;
	case WM_SIZE:
		resize_insert_dlg(hwnd);
		grippy_move(hwnd,hgrippy);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDOK:
			if(hedit!=0){
				if(GetFocus()==hedit){
					char str[80]={0};
					int count,row_sel=ListView_GetSelectionMark(hlistview);
					GetWindowText(hedit,str,sizeof(str));
					resize_column(hwnd,hlistview,str,1);
					lv_update_data(hlistview,row_sel,DATA_POS,str);
					SendMessage(hedit,WM_CLOSE,0,0);
					count=ListView_GetItemCount(hlistview);
					if(row_sel < (count-1)){
						ListView_SetItemState(hlistview,row_sel,0,LVIS_SELECTED|LVIS_FOCUSED);
						row_sel++;
						ListView_SetItemState(hlistview,row_sel,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
						ListView_SetSelectionMark(hlistview,row_sel);
					}
					hedit=0;
				}
				break;
			}
			else if(GetFocus()==hlistview){
				static LV_KEYDOWN lvk={0};
				lvk.hdr.hwndFrom=hlistview;
				lvk.hdr.code=LVN_KEYDOWN;
				lvk.wVKey=VK_INSERT;
				SendMessage(hwnd,WM_NOTIFY,0,&lvk);
				break;
			}
			else{
				if(task_insert_row(win,hlistview))
					SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");

			}
			break;
		case IDCANCEL:
			if(hedit!=0){
				SendMessage(hedit,WM_CLOSE,0,0);
				hedit=0;
				break;
			}
			EndDialog(hwnd,0);
			break;
		}
		break;	
	}
	return 0;
}
Exemple #19
0
/* List window Proc */
LRESULT CALLBACK NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	BOOL bUpdateFocusItem = FALSE;

	switch(message) {

	/* filter keyboard input for the control */
#if !defined(WIN_CE_SMARTPHONE)
	case WM_KEYDOWN:
	case WM_KEYUP: {
		MSG msg;

		if( PeekMessage(&msg, hWnd, WM_CHAR, WM_CHAR, PM_REMOVE) ) {
			if( onListChar(GetParent(hWnd), hWnd, (char)msg.wParam)==-2 ) {
				return 0;
			}
		}

		if( wParam==VK_LEFT || wParam==VK_RIGHT )
			bUpdateFocusItem = TRUE;
	} break;

#else /* defined(WIN_CE_SMARTPHONE) */
	case WM_KEYDOWN:
		if( wParam==VK_TACTION ) {
			if( onListChar(GetParent(hWnd), hWnd, ' ')==-2 ) {
				return 0;
			}
		} else if( NHSPhoneTranslateKbdMessage(wParam, lParam, TRUE) ) {
			PMSNHEvent	evt;
			BOOL processed = FALSE;
			if( mswin_have_input() ) {
				evt = mswin_input_pop();
				if( evt->type==NHEVENT_CHAR && 
					onListChar(GetParent(hWnd), hWnd, evt->kbd.ch)==-2 ) {
					processed = TRUE;
				}

				/* eat the rest of the events */
				if( mswin_have_input() ) mswin_input_pop();
			}
			if( processed ) return 0;
		}

		if( wParam==VK_LEFT || wParam==VK_RIGHT )
			bUpdateFocusItem = TRUE;
	break;

	case WM_KEYUP:
		/* translate SmartPhone keyboard message */
		if( NHSPhoneTranslateKbdMessage(wParam, lParam, FALSE) )
			return 0;
	break;

	/* tell Windows not to process default button on VK_RETURN */
	case WM_GETDLGCODE: 
		return DLGC_DEFPUSHBUTTON | DLGC_WANTALLKEYS |
			   (wndProcListViewOrig? 
						CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, lParam) 
						: 0 );
#endif

	case WM_SIZE:
	case WM_HSCROLL:
		bUpdateFocusItem = TRUE;
	break;

	}

	if(	bUpdateFocusItem ) {
		int i;
		RECT rt;

		/* invalidate the focus rectangle */
		i = ListView_GetNextItem(hWnd, -1,	LVNI_FOCUSED);
		if( i!=-1 ) {
			ListView_GetItemRect(hWnd, i, &rt, LVIR_BOUNDS);
			InvalidateRect(hWnd, &rt, TRUE);
		}
	}

	if( wndProcListViewOrig ) 
		return CallWindowProc(wndProcListViewOrig, hWnd, message, wParam, lParam);
	else 
		return 0;
}
Exemple #20
0
void Picker_HandleDrawItem(HWND hWnd, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	struct PickerInfo *pPickerInfo;
	HDC         hDC = lpDrawItemStruct->hDC;
	RECT        rcItem = lpDrawItemStruct->rcItem;
	UINT        uiFlags = ILD_TRANSPARENT;
	HIMAGELIST  hImageList;
	int         nItem = lpDrawItemStruct->itemID;
	COLORREF    clrTextSave = 0;
	COLORREF    clrBkSave = 0;
	COLORREF    clrImage = GetSysColor(COLOR_WINDOW);
	static TCHAR szBuff[MAX_PATH];
	BOOL        bFocus = (GetFocus() == hWnd);
	LPCTSTR     pszText;
	UINT        nStateImageMask;
	BOOL        bSelected;
	LV_COLUMN   lvc;
	LV_ITEM     lvi;
	RECT        rcAllLabels;
	RECT        rcLabel;
	RECT        rcIcon;
	int         offset;
	SIZE        size;
	int         i, j;
	int         nColumn;
	int         nColumnMax = 0;
	int         *order;
	BOOL        bDrawAsChild;
	int indent_space;
	BOOL		bColorChild = FALSE;
	BOOL		bParentFound = FALSE;
	int nParent;
	HBITMAP		hBackground = GetBackgroundBitmap();
	MYBITMAPINFO *pbmDesc = GetBackgroundInfo();

	pPickerInfo = GetPickerInfo(hWnd);

	order = malloc(pPickerInfo->nColumnCount * sizeof(*order));
	if (!order)
		return;
	nColumnMax = Picker_GetNumColumns(hWnd);

	if (GetUseOldControl())
	{
		pPickerInfo->pCallbacks->pfnGetColumnOrder(order);
	}
	else
	{
		/* Get the Column Order and save it */
		ListView_GetColumnOrderArray(hWnd, nColumnMax, order);

		/* Disallow moving column 0 */
		if (order[0] != 0)
		{
			for (i = 0; i < nColumnMax; i++)
			{
				if (order[i] == 0)
				{
					order[i] = order[0];
					order[0] = 0;
				}
			}
			ListView_SetColumnOrderArray(hWnd, nColumnMax, order);
		}
	}

	/* Labels are offset by a certain amount */
	/* This offset is related to the width of a space character */
	GetTextExtentPoint32(hDC, " ", 1 , &size);
	offset = size.cx;

	lvi.mask	   = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_PARAM;
	lvi.iItem	   = nItem;
	lvi.iSubItem   = order[0];
	lvi.pszText	   = szBuff;
	lvi.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]);
	lvi.stateMask  = 0xFFFF;	   /* get all state flags */
	ListView_GetItem(hWnd, &lvi);

	bSelected = ((lvi.state & LVIS_DROPHILITED) || ( (lvi.state & LVIS_SELECTED)
		&& ((bFocus) || (GetWindowLong(hWnd, GWL_STYLE) & LVS_SHOWSELALWAYS))));

	/* figure out if we indent and draw grayed */
	if (pPickerInfo->pCallbacks->pfnFindItemParent)
		nParent = pPickerInfo->pCallbacks->pfnFindItemParent(hWnd, lvi.lParam);
	else
		nParent = -1;
	bDrawAsChild = (pPickerInfo->pCallbacks->pfnGetViewMode() == VIEW_GROUPED && (nParent >= 0));

	/* only indent if parent is also in this view */
	if ((nParent >= 0) && bDrawAsChild)
	{
		for (i = 0; i < ListView_GetItemCount(hWnd); i++)
		{
			lvi.mask = LVIF_PARAM;
			lvi.iItem = i;
			ListView_GetItem(hWnd, &lvi);

			if (lvi.lParam == nParent)
			{
				bParentFound = TRUE;
				break;
			}
		}
	}

	if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren())
	{
		if (!bParentFound && bDrawAsChild)
		{
			/*Reset it, as no Parent is there*/
			bDrawAsChild = FALSE;
			bColorChild = TRUE;
		}
		else
		{
			nParent = -1;
			bParentFound = FALSE;
		}
	}

	ListView_GetItemRect(hWnd, nItem, &rcAllLabels, LVIR_BOUNDS);

	ListView_GetItemRect(hWnd, nItem, &rcLabel, LVIR_LABEL);
	rcAllLabels.left = rcLabel.left;

	if (hBackground != NULL)
	{
		RECT		rcClient;
		HRGN		rgnBitmap;
		RECT		rcTmpBmp = rcItem;
		RECT		rcFirstItem;
		HPALETTE	hPAL;
		HDC 		htempDC;
		HBITMAP 	oldBitmap;

		htempDC = CreateCompatibleDC(hDC);

		oldBitmap = SelectObject(htempDC, hBackground);

		GetClientRect(hWnd, &rcClient);
		rcTmpBmp.right = rcClient.right;
		/* We also need to check whether it is the last item
		   The update region has to be extended to the bottom if it is */
		if (nItem == ListView_GetItemCount(hWnd) - 1)
			rcTmpBmp.bottom = rcClient.bottom;

		rgnBitmap = CreateRectRgnIndirect(&rcTmpBmp);
		SelectClipRgn(hDC, rgnBitmap);
		DeleteObject(rgnBitmap);

		hPAL = GetBackgroundPalette();
		if (hPAL == NULL)
			hPAL = CreateHalftonePalette(hDC);

		if (GetDeviceCaps(htempDC, RASTERCAPS) & RC_PALETTE && hPAL != NULL)
		{
			SelectPalette(htempDC, hPAL, FALSE);
			RealizePalette(htempDC);
		}

		ListView_GetItemRect(hWnd, 0, &rcFirstItem, LVIR_BOUNDS);

		for (i = rcFirstItem.left; i < rcClient.right; i += pbmDesc->bmWidth)
			for (j = rcFirstItem.top; j < rcClient.bottom; j +=  pbmDesc->bmHeight)
				BitBlt(hDC, i, j, pbmDesc->bmWidth, pbmDesc->bmHeight, htempDC, 0, 0, SRCCOPY);

		SelectObject(htempDC, oldBitmap);
		DeleteDC(htempDC);

		if (GetBackgroundPalette() == NULL)
		{
			DeleteObject(hPAL);
			hPAL = NULL;
		}
	}

	indent_space = 0;

	if (bDrawAsChild)
	{
		RECT rect;
		ListView_GetItemRect(hWnd, nItem, &rect, LVIR_ICON);

		/* indent width of icon + the space between the icon and text
		 * so left of clone icon starts at text of parent
         */
		indent_space = rect.right - rect.left + offset;
	}

	rcAllLabels.left += indent_space;

	if (bSelected)
	{
		HBRUSH hBrush;
		HBRUSH hOldBrush;

		if (bFocus)
		{
			clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			clrBkSave	= SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
			hBrush		= CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
		}
		else
		{
			clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT));
			clrBkSave	= SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
			hBrush		= CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
		}

		hOldBrush = SelectObject(hDC, hBrush);
		FillRect(hDC, &rcAllLabels, hBrush);
		SelectObject(hDC, hOldBrush);
		DeleteObject(hBrush);
	}
	else
	{
		if (hBackground == NULL)
		{
			HBRUSH hBrush;
			
			hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
			FillRect(hDC, &rcAllLabels, hBrush);
			DeleteObject(hBrush);
		}
		
		if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren())
		{
			if (bDrawAsChild || bColorChild)
				clrTextSave = SetTextColor(hDC, GetListCloneColor());
			else
				clrTextSave = SetTextColor(hDC, GetListFontColor());
		}
		else
		{
			if (bDrawAsChild)
				clrTextSave = SetTextColor(hDC, GetListCloneColor());
			else
				clrTextSave = SetTextColor(hDC, GetListFontColor());
		}

		clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_WINDOW));
	}


	if (lvi.state & LVIS_CUT)
	{
		clrImage = GetSysColor(COLOR_WINDOW);
		uiFlags |= ILD_BLEND50;
	}
	else if (bSelected)
	{
		if (bFocus)
			clrImage = GetSysColor(COLOR_HIGHLIGHT);
		else
			clrImage = GetSysColor(COLOR_BTNFACE);

		uiFlags |= ILD_BLEND50;
	}

	nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK;

	if (nStateImageMask)
	{
		int nImage = (nStateImageMask >> 12) - 1;
		hImageList = ListView_GetImageList(hWnd, LVSIL_STATE);
		if (hImageList)
			ImageList_Draw(hImageList, nImage, hDC, rcItem.left, rcItem.top, ILD_TRANSPARENT);
	}

	ListView_GetItemRect(hWnd, nItem, &rcIcon, LVIR_ICON);

	rcIcon.left += indent_space;

	ListView_GetItemRect(hWnd, nItem, &rcItem, LVIR_LABEL);

	hImageList = ListView_GetImageList(hWnd, LVSIL_SMALL);
	if (hImageList)
	{
		UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK;
		if (rcIcon.left + 16 + indent_space < rcItem.right)
		{
			ImageList_DrawEx(hImageList, lvi.iImage, hDC, rcIcon.left, rcIcon.top, 16, 16,
							 GetSysColor(COLOR_WINDOW), clrImage, uiFlags | nOvlImageMask);
		}
	}

	ListView_GetItemRect(hWnd, nItem, &rcItem, LVIR_LABEL);

	pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2*offset + indent_space);

	rcLabel = rcItem;
	rcLabel.left  += offset + indent_space;
	rcLabel.right -= offset;

	DrawText(hDC, pszText, -1, &rcLabel,
			 DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);

	for (nColumn = 1; nColumn < nColumnMax; nColumn++)
	{
		int 	nRetLen;
		UINT	nJustify;
		LV_ITEM lvItem;

		lvc.mask = LVCF_FMT | LVCF_WIDTH;
		ListView_GetColumn(hWnd, order[nColumn], &lvc);

		lvItem.mask 	  = LVIF_TEXT;
		lvItem.iItem	  = nItem;
		lvItem.iSubItem   = order[nColumn];
		lvItem.pszText	  = szBuff;
		lvItem.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]);

		if (ListView_GetItem(hWnd, &lvItem) == FALSE)
			continue;

		rcItem.left   = rcItem.right;
		rcItem.right += lvc.cx;

		nRetLen = strlen(szBuff);
		if (nRetLen == 0)
			continue;

		pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2 * offset);

		nJustify = DT_LEFT;

		if (pszText == szBuff)
		{
			switch (lvc.fmt & LVCFMT_JUSTIFYMASK)
			{
			case LVCFMT_RIGHT:
				nJustify = DT_RIGHT;
				break;

			case LVCFMT_CENTER:
				nJustify = DT_CENTER;
				break;

			default:
				break;
			}
		}

		rcLabel = rcItem;
		rcLabel.left  += offset;
		rcLabel.right -= offset;
		DrawText(hDC, pszText, -1, &rcLabel,
				 nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);
	}

	if (lvi.state & LVIS_FOCUSED && bFocus)
		DrawFocusRect(hDC, &rcAllLabels);

	SetTextColor(hDC, clrTextSave);
	SetBkColor(hDC, clrBkSave);
	free(order);
}
Exemple #21
0
// SetTipText ---------------------------------------------------------------
BOOL CCodeListCtrl::SetTipText( LPCTSTR pszText )
{
   // Destroy the tooltip window if an empty string was passed in.
   if( NULL == pszText || 0 == lstrlen( pszText ) )
   {
      if( ::IsWindow( m_hwndToolTip ) )
         ::DestroyWindow( m_hwndToolTip );

      m_hwndToolTip = NULL;
      return TRUE;
   }

   // Can't set tip if the window isn't visible yet!
   if( !::IsWindowVisible( m_hWnd ) )
      return FALSE;

   // Set up the TOOLINFO structure
   TOOLINFO ti = { sizeof(TOOLINFO) };

   ti.uFlags = TTF_TRACK | TTF_IDISHWND;
   ti.hwnd = m_hWnd;
   ti.uId = (UINT)m_hWnd;
   ti.lpszText = (LPTSTR)pszText;

   // Make sure the tooltip window exists...
   if( NULL == m_hwndToolTip )
   {
      extern HINSTANCE hInstance;

      m_hwndToolTip = CreateWindow( TOOLTIPS_CLASS, NULL,
         WS_POPUP | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,
         CW_USEDEFAULT, CW_USEDEFAULT, m_hWnd, NULL, hInstance, NULL );

      ASSERT( NULL != m_hwndToolTip );

      if( m_hwndToolTip )
      {
         ::SetWindowPos( m_hwndToolTip, HWND_TOPMOST,0, 0, 0, 0,
            SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );

         // Attach the tooltip control to the listview control window
         ::SendMessage( m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti );
      }
   }

   if( m_hwndToolTip )
   {
      // Initially position the tooltip to the right of the item selected
      // in the listview control or, if nothing is selected, at the top-
      // right corner of the control.
      //
      RECT rect = {0};
      int iSel = GetCurSel();

      if( -1 == iSel )
         GetWindowRect( &rect );
      else
      {
         ListView_GetItemRect( m_hWnd, iSel, &rect, LVIR_BOUNDS );
         ClientToScreen( &rect );
      }

      ::SendMessage( m_hwndToolTip, TTM_TRACKPOSITION, 0,
         MAKELONG( rect.right, rect.top ) );

      // Set the tooltip text...
      ::SendMessage( m_hwndToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti );

      // ...and display it!
      ::SendMessage( m_hwndToolTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti );

      return TRUE;
   }

   return FALSE;
}
Exemple #22
0
LRESULT CALLBACK MainDlg(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static HWND grippy=0;
	static int col=0,dir=0;

#ifdef _DEBUG
	// if(FALSE)
//	if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE)
	if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_DRAWITEM
		&&msg!=WM_CTLCOLORBTN&&msg!=WM_CTLCOLOREDIT)
	//if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		printf("*");
		print_msg(msg,lparam,wparam);
		tick=GetTickCount();
	}
#endif	
	switch(msg)
	{
	case WM_INITDIALOG:
		hlistview=CreateWindow(WC_LISTVIEW,"",WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS,
                                     0,0,
                                     0,0,
                                     hwnd,
                                     IDC_LIST1,
                                     ghinstance,
                                     NULL);
		ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT);		
		populate_list(hlistview,TRUE);
		sort_listview(hlistview,dir,col);
		grippy=create_grippy(hwnd);
		PostMessage(hwnd,WM_SIZE,0,0);
		//dump_main(hwnd);
		break;
	case WM_HELP:
		show_main_help(hwnd,(HELPINFO *)lparam);
		return TRUE;
		break;
	case WM_SIZE:
		grippy_move(hwnd,grippy);
		resize_main(hwnd);
		break;
	case WM_CONTEXTMENU:
		break;
	case WM_NOTIFY:
		{
			NMHDR *nmhdr=lparam;
			if(nmhdr!=0 && nmhdr->idFrom==IDC_LIST1){
				LV_HITTESTINFO lvhit={0};
				switch(nmhdr->code){
				case NM_DBLCLK:
					GetCursorPos(&lvhit.pt);
					ScreenToClient(nmhdr->hwndFrom,&lvhit.pt);
					if(ListView_SubItemHitTest(nmhdr->hwndFrom,&lvhit)>=0)
						do_regjump(hlistview);
					break;
				case NM_RCLICK:
				case NM_CLICK:
					GetCursorPos(&lvhit.pt);
					ScreenToClient(nmhdr->hwndFrom,&lvhit.pt);
					if(ListView_SubItemHitTest(nmhdr->hwndFrom,&lvhit)>=0){
					}
					printf("item = %i\n",lvhit.iSubItem);
					break;
				case LVN_ITEMCHANGED:
					{
					}
					break;
				case LVN_KEYDOWN:
					{
					}
					break;
				case LVN_COLUMNCLICK:
					{
						NMLISTVIEW *nmlv=lparam;
						col=nmlv->iSubItem;
						dir=!dir;
						sort_listview(hlistview,dir,col);
					}
					break;
				}
			}
		}
		break;

	case WM_VKEYTOITEM:
		switch(LOWORD(wparam)){
		case '0':case '1':case'2':case'3':case'4':case'5':
			break;
		}
		return -1;
		break;
	case WM_CHARTOITEM:
		switch(wparam){
		case 'z':
			break;
		case 'x':
			break;
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDC_REFRESH:
			{
			RECT rect={0};
			RECT newrect={0};
			int dx,dy,mark;
			ListView_GetItemRect(hlistview,0,&rect,LVIR_BOUNDS);
			mark=ListView_GetSelectionMark(hlistview);

			populate_list(hlistview,FALSE);
			sort_listview(hlistview,dir,col);

			ListView_GetItemRect(hlistview,0,&newrect,LVIR_BOUNDS);
			dx=-rect.left+newrect.left;
			dy=-rect.top+newrect.top;
			ListView_Scroll(hlistview,dx,dy);
			if(mark>=0)
				ListView_SetItemState(hlistview,mark,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
				SetFocus(hlistview);
			}
			break;
		case IDC_INFO:
			do_regjump(hlistview);
			break;
		case IDOK:
			break;
		case IDCANCEL:
			DestroyWindow(hwnd);
			PostQuitMessage(0);
			return TRUE;
			break;
		}
		break;
	case WM_QUERYENDSESSION:
		SetWindowLong(hwnd,DWL_MSGRESULT,TRUE); //ok to end session
		return TRUE;
	case WM_ENDSESSION:
		if(wparam){
			SetWindowLong(hwnd,DWL_MSGRESULT,0);
			DestroyWindow(hwnd);
			PostQuitMessage(0);
			return TRUE;
		}
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		PostQuitMessage(0);
		return TRUE;
		break;
	}
	return 0;
}
Exemple #23
0
/**
 * name:	DlgProcPspAbout()
 * desc:	dialog procedure
 *
 * return:	0 or 1
 **/
INT_PTR CALLBACK PSPProcContactProfile(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HWND hList = GetDlgItem(hDlg, LIST_PROFILE);
	LPLISTCTRL pList;

	switch (uMsg) {
		case WM_INITDIALOG:
		{
			LVCOLUMN lvc;
			RECT rc;
			LOGFONT lf;
			HFONT hFont;
			TOOLINFO ti;

			if (!hList || !(pList = (LPLISTCTRL)mir_alloc(sizeof(LISTCTRL)))) 
				return FALSE;
			ZeroMemory(pList, sizeof(LISTCTRL));

			TranslateDialogDefault(hDlg);
			Ctrl_InitTextColours();

			// init info structure
			pList->hList = hList;
			pList->nType = CTRL_LIST_PROFILE;
			ZeroMemory(&pList->labelEdit, sizeof(pList->labelEdit));
			SetUserData(hList, pList);

			// set new window procedure
			OldListViewProc = (WNDPROC)SetWindowLongPtr(hList, GWLP_WNDPROC, (LONG_PTR)&ProfileList_SubclassProc);
			
			// remove static edge in aero mode
			if (IsAeroMode())
				SetWindowLongPtr(hList, GWL_EXSTYLE, GetWindowLongPtr(hList, GWL_EXSTYLE)&~WS_EX_STATICEDGE);

			// insert columns into the listboxes					
			ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);


			PSGetBoldFont(hDlg, hFont);
			SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)hFont, 0);

			// set listfont
			pList->hFont = (HFONT)SendMessage(hList, WM_GETFONT, 0, 0);
			pList->wFlags |= LVF_EDITLABEL;
			GetObject(pList->hFont, sizeof(lf), &lf);
			lf.lfHeight -= 6;
			hFont = CreateFontIndirect(&lf);
			SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0);

			GetClientRect(hList, &rc);
			rc.right -= GetSystemMetrics(SM_CXVSCROLL);

			// initiate the tooltips
			pList->hTip = CreateWindowEx(WS_EX_TOPMOST,	TOOLTIPS_CLASS, NULL,
				WS_POPUP|TTS_BALLOON|TTS_NOPREFIX|TTS_ALWAYSTIP,
				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
				hList, NULL, ghInst, NULL);
			if (pList->hTip) {
				SetWindowPos(pList->hTip, HWND_TOPMOST,
					CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
					SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

				ZeroMemory(&ti, sizeof(TOOLINFO));
				ti.cbSize = sizeof(TOOLINFO);
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS|TTF_TRANSPARENT;
				ti.hinst = ghInst;
				ti.hwnd = hList;
				ti.uId = (UINT_PTR)hList;
				SendMessage(pList->hTip, TTM_ADDTOOL, NULL, (LPARAM)&ti);
				SendMessage(pList->hTip, TTM_ACTIVATE, FALSE, (LPARAM)&ti);
			}		

			// insert columns into the listboxes					
			lvc.mask = LVCF_WIDTH;
			lvc.cx = rc.right / 8 * 3;
			ListView_InsertColumn(hList, 0, &lvc);
			lvc.cx = rc.right / 8 * 5;
			ListView_InsertColumn(hList, 1, &lvc);
			return TRUE;
		}

		case WM_CTLCOLORSTATIC:
		case WM_CTLCOLORDLG:
			if (IsAeroMode())
				return (INT_PTR)GetStockBrush(WHITE_BRUSH);
			break;

		case WM_NOTIFY:
			switch (((LPNMHDR)lParam)->idFrom) {
				case 0:
				{
					HANDLE hContact = (HANDLE)((LPPSHNOTIFY)lParam)->lParam;
					LPCSTR pszProto;
					
					if (!PtrIsValid(pList = (LPLISTCTRL)GetUserData(hList))) break;

					switch (((LPNMHDR)lParam)->code) {
						// some account data may have changed so reread database
						case PSN_INFOCHANGED:
						{
							BYTE msgResult = 0;
							LPIDSTRLIST idList;
							UINT nList;
							BYTE i;
							INT iItem = 0,
								iGrp = 0,
								numProtoItems,
								numUserItems;

							if (!(pList->wFlags & CTRLF_CHANGED) && PSGetBaseProto(hDlg, pszProto) && *pszProto != 0) {
								ProfileList_Clear(hList);

								// insert the past information
								for (i = 0; i < 3; i++) {
									pFmt[i].GetList((WPARAM)&nList, (LPARAM)&idList);
									if ((numProtoItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hContact, pszProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASPROTO)) < 0)
										return FALSE;

									// scan all basic protocols for the subcontacts
									if (DB::Module::IsMetaAndScan(pszProto)) {
										INT iDefault = CallService(MS_MC_GETDEFAULTCONTACTNUM, (WPARAM)hContact, NULL);
										HANDLE hSubContact, hDefContact;
										LPCSTR pszSubBaseProto;
										INT j, numSubs;
										
										if ((hDefContact = (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, iDefault)) &&
											 (pszSubBaseProto = DB::Contact::Proto(hDefContact)))
										{
											if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hDefContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA|CTRLF_HASPROTO)) < 0)
												return FALSE;

											// copy the missing settings from the other subcontacts
											numSubs = CallService(MS_MC_GETNUMCONTACTS, (WPARAM)hContact, NULL);
											for (j = 0; j < numSubs; j++) {
												if (j == iDefault) continue;
												if (!(hSubContact = (HANDLE)CallService(MS_MC_GETSUBCONTACT, (WPARAM)hContact, j))) continue;
												if (!(pszSubBaseProto = DB::Contact::Proto(hSubContact))) continue;
												if ((numProtoItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, pszSubBaseProto, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA|CTRLF_HASPROTO)) < 0)
													return FALSE;
												//if ((numUserItems += ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hSubContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASMETA|CTRLF_HASPROTO)) < 0)
												//	return FALSE;
											}
										}
									}
									if ((numUserItems = ProfileList_AddItemlistFromDB(pList, iItem, idList, nList, hContact, USERINFO, pFmt[i].szCatFmt, pFmt[i].szValFmt, CTRLF_HASCUSTOM)) < 0)
										return FALSE;
									if (numUserItems || numProtoItems) {
										msgResult = PSP_CHANGED;
										ProfileList_AddGroup(hList, pFmt[i].szGroup, iGrp);
										iGrp = ++iItem;
									}
								}
							}
							SetWindowLongPtr(hDlg, DWLP_MSGRESULT, msgResult);
							break;
						}
						// user swiches to another propertysheetpage
						case PSN_KILLACTIVE:
							ProfileList_EndLabelEdit(hList, TRUE);
							break;
						// user selected to apply settings to the database
						case PSN_APPLY:
							if (pList->wFlags & CTRLF_CHANGED) {
								BYTE iFmt = -1;
								INT iItem;
								LVITEM lvi;
								TCHAR szGroup[MAX_PATH];
								CHAR pszSetting[MAXSETTING];
								LPLCITEM pItem;
								LPSTR pszModule = USERINFO;

								if (!hContact) PSGetBaseProto(hDlg, pszModule);

								*szGroup = 0;
								lvi.mask = LVIF_TEXT|LVIF_PARAM;
								lvi.pszText = szGroup;
								lvi.cchTextMax = MAX_PATH;

								for (iItem = lvi.iItem = lvi.iSubItem = 0; ListView_GetItem(hList, &lvi); lvi.iItem++) {
									if (!PtrIsValid(pItem = (LPLCITEM)lvi.lParam)) {
										// delete reluctant items
										if (iFmt >= 0 && iFmt < SIZEOF(pFmt)) {
											DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szCatFmt, iItem);
											DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szValFmt, iItem);
										}
										// find information about the group
										for (iFmt = 0; iFmt < SIZEOF(pFmt); iFmt++) {
											if (!_tcscmp(szGroup, pFmt[iFmt].szGroup)) {
												break;
											}
										}
										// indicate, no group was found. should not happen!!
										if (iFmt == SIZEOF(pFmt)) {
											*szGroup = 0;
											iFmt = -1;
										}
										iItem = 0;
									}
									else
									if (iFmt >= 0 && iFmt < SIZEOF(pFmt)) {
										// save value
										if (!pItem->pszText[1] || !*pItem->pszText[1])
											continue;
										if (!(pItem->wFlags & (CTRLF_HASPROTO|CTRLF_HASMETA))) {
											mir_snprintf(pszSetting, MAXSETTING, pFmt[iFmt].szValFmt, iItem);
											DB::Setting::WriteTString(hContact, pszModule, pszSetting, pItem->pszText[1]);
											// save category
											mir_snprintf(pszSetting, MAXSETTING, pFmt[iFmt].szCatFmt, iItem);
											if (pItem->idstrList && pItem->iListItem > 0 && pItem->iListItem < pItem->idstrListCount)
												DB::Setting::WriteAString(hContact, pszModule, pszSetting, (LPSTR)pItem->idstrList[pItem->iListItem].pszText);
											else 
											if (pItem->pszText[0] && *pItem->pszText[0])
												DB::Setting::WriteTString(hContact, pszModule, pszSetting, (LPTSTR)pItem->pszText[0]);
											else									
												DB::Setting::Delete(hContact, pszModule, pszSetting);
											// redraw the item if required
											if (pItem->wFlags & CTRLF_CHANGED) {
												pItem->wFlags &= ~CTRLF_CHANGED;
												ListView_RedrawItems(hList, lvi.iItem, lvi.iItem);
											}
											iItem++;
										}
									}
								}
								// delete reluctant items
								if (iFmt >= 0 && iFmt < SIZEOF(pFmt)) {
									DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szCatFmt, iItem);
									DB::Setting::DeleteArray(hContact, pszModule, pFmt[iFmt].szValFmt, iItem);
								}

								pList->wFlags &= ~CTRLF_CHANGED;
							}
							break;
					}
					break;
				}

				//
				// handle notification messages from the list control
				//
				case LIST_PROFILE:
				{
					LPLISTCTRL pList = (LPLISTCTRL)GetUserData(((LPNMHDR)lParam)->hwndFrom);

					switch (((LPNMHDR)lParam)->code) {
						case NM_RCLICK:
						{
							HMENU hMenu = CreatePopupMenu();
							MENUITEMINFO mii;
							HANDLE hContact;
							LVHITTESTINFO hi;
							LPLCITEM pItem;
							POINT pt;
							
							if (!hMenu) return 1;
							PSGetContact(hDlg, hContact);
							GetCursorPos(&pt);
							hi.pt = pt;
							ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hi.pt);
							ListView_SubItemHitTest(((LPNMHDR)lParam)->hwndFrom, &hi);
							pItem = ProfileList_GetItemData(((LPNMHDR)lParam)->hwndFrom, hi.iItem);

							// insert menuitems
							ZeroMemory(&mii, sizeof(MENUITEMINFO));
							mii.cbSize = sizeof(MENUITEMINFO);
							mii.fMask = MIIM_ID|MIIM_STRING;
							// insert "Add" Menuitem
							mii.wID = BTN_ADD_intEREST;
							mii.dwTypeData = TranslateT("Add Interest");
							InsertMenuItem(hMenu, 0, TRUE, &mii);
							mii.wID = BTN_ADD_AFFLIATION;
							mii.dwTypeData = TranslateT("Add Affliation");
							InsertMenuItem(hMenu, 1, TRUE, &mii);
							mii.wID = BTN_ADD_PAST;
							mii.dwTypeData = TranslateT("Add Past");
							InsertMenuItem(hMenu, 2, TRUE, &mii);

							if (hi.iItem != -1 && PtrIsValid(pItem) && !(hContact && (pItem->wFlags & CTRLF_HASPROTO))) {
								// insert separator
								mii.fMask = MIIM_FTYPE;
								mii.fType = MFT_SEPARATOR;
								InsertMenuItem(hMenu, 3, TRUE, &mii);
								// insert "Delete" Menuitem
								mii.fMask = MIIM_ID|MIIM_STRING;
								mii.wID = BTN_EDIT_CAT;
								mii.dwTypeData = TranslateT("Edit Category");
								InsertMenuItem(hMenu, 4, TRUE, &mii);
								mii.wID = BTN_EDIT_VAL;
								mii.dwTypeData = TranslateT("Edit Value");
								InsertMenuItem(hMenu, 5, TRUE, &mii);
								mii.fMask = MIIM_FTYPE;
								mii.fType = MFT_SEPARATOR;
								InsertMenuItem(hMenu, 6, TRUE, &mii);
								// insert "Delete" Menuitem
								mii.fMask = MIIM_ID|MIIM_STRING;
								mii.wID = BTN_DEL;
								mii.dwTypeData = TranslateT("Delete");
								InsertMenuItem(hMenu, 7, TRUE, &mii);
							}
							TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hDlg, 0);
							DestroyMenu(hMenu);
							return 0;
						}
						/*case LVN_BEGINSCROLL:
							SetFocus(((LPNMHDR)lParam)->hwndFrom);
							break;
							*/
						case LVN_GETDISPINFO:
							if (pList->labelEdit.iTopIndex != ListView_GetTopIndex(hList))
								ProfileList_EndLabelEdit(((LPNMHDR)lParam)->hwndFrom, FALSE);
							break;
						case NM_CUSTOMDRAW:
						{
							LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)lParam;
							LPLCITEM pItem = (LPLCITEM)cd->nmcd.lItemlParam;
							RECT rc;

							switch (cd->nmcd.dwDrawStage) {
								case CDDS_PREPAINT:
									SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
									return TRUE;
								
								case CDDS_ITEMPREPAINT:
									ListView_GetItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, &rc, LVIR_BOUNDS);
									if (!PtrIsValid(pItem)) {
										HFONT hBold, hFont;
										TCHAR szText[MAX_PATH];
										
										PSGetBoldFont(hDlg, hBold);
										hFont = (HFONT)SelectObject(cd->nmcd.hdc, hBold);
										SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW));
										ProfileList_GetItemText(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, 0, szText, MAX_PATH);
										rc.left += 6;
										DrawText(cd->nmcd.hdc, TranslateTS(szText), -1, &rc, DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);

										rc.bottom -= 2;
										rc.top = rc.bottom - 1;
										rc.left -= 6;
										DrawEdge(cd->nmcd.hdc, &rc, BDR_SUNKENOUTER, BF_RECT);

										SelectObject(cd->nmcd.hdc, hFont);
										SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
										return TRUE;
									}
									// draw selected item
									if ((cd->nmcd.uItemState & CDIS_SELECTED) || (pList->labelEdit.iItem == cd->nmcd.dwItemSpec)) {
										SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
										FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_HIGHLIGHT));
									}
									// draw background of unselected item
									else {
										SetTextColor(cd->nmcd.hdc, 
											(pItem->wFlags & CTRLF_CHANGED) 
												? clrChanged : (pItem->wFlags & CTRLF_HASMETA)
													? clrMeta : ((pItem->wFlags & (CTRLF_HASCUSTOM)) && (pItem->wFlags & CTRLF_HASPROTO))
														? clrBoth : (pItem->wFlags & CTRLF_HASCUSTOM)
															? clrCustom	: clrNormal);
										FillRect(cd->nmcd.hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
									}
									SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW);
									return TRUE;
								
								case CDDS_SUBITEM|CDDS_ITEMPREPAINT:
								{
									HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, pList->hFont);

									ListView_GetSubItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, cd->iSubItem, LVIR_BOUNDS, &rc);
									if (cd->iSubItem == 0) {
										RECT rc2;
										ListView_GetSubItemRect(cd->nmcd.hdr.hwndFrom, cd->nmcd.dwItemSpec, 1, LVIR_BOUNDS, &rc2);
										rc.right = rc2.left;
									}
									rc.left += 3;
									DrawText(cd->nmcd.hdc,
										pItem->pszText[cd->iSubItem] 
											? pItem->pszText[cd->iSubItem] 
											: (cd->iSubItem == 0 && pItem->idstrList && pItem->iListItem > 0 && pItem->iListItem < pItem->idstrListCount)
												? pItem->idstrList[pItem->iListItem].ptszTranslated
												: TranslateT("<empty>"),
										-1, &rc, DT_END_ELLIPSIS|DT_NOCLIP|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);
									SetWindowLongPtr(hDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);
									return TRUE;
								}
							} /* switch (cd->nmcd.dwDrawStage) */
							break;
						} /* case NM_CUSTOMDRAW: */
					} /* (((LPNMHDR)lParam)->code) */
					break;
				}
			}
			break; /* case WM_NOTIFY: */

		case WM_COMMAND:
		{
			switch (LOWORD(wParam)) {
				case BTN_ADD_intEREST:
					return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[2]);
				case BTN_ADD_AFFLIATION:
					return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[1]);
				case BTN_ADD_PAST:
					return ProfileList_AddNewItem(hDlg, (LPLISTCTRL)GetUserData(hList), &pFmt[0]);
				case BTN_EDIT_CAT:
					ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 0);
					break;
				case BTN_EDIT_VAL:
					ProfileList_BeginLabelEdit(hList, ListView_GetSelectionMark(hList), 1);
					break;
				case BTN_DEL:
					if (IDYES == MsgBox(hDlg, MB_YESNO|MB_ICON_QUESTION, LPGENT("Question"), LPGENT("Delete an entry"), LPGENT("Do you really want to delete this entry?"))) {
						INT iItem = ListView_GetSelectionMark(hList);
						LPLISTCTRL pList = (LPLISTCTRL)GetUserData(hList);

						ProfileList_DeleteItem(hList, iItem);
						if (PtrIsValid(pList)) pList->wFlags |= CTRLF_CHANGED;
						SendMessage(GetParent(hDlg), PSM_CHANGED, NULL, NULL);
						// check if to delete any devider
						if (!ProfileList_GetItemData(hList, iItem--) && !ProfileList_GetItemData(hList, iItem))
							ListView_DeleteItem(hList, iItem);
					}
					break;
			}
			break;
		}
	}
	return FALSE;
}
Exemple #24
0
static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwndList = GetDlgItem(hwndDlg, IDC_LANGLIST);
	LVITEM lvi;

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		hwndLangOpt = hwndDlg;
		ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT|LVS_EX_LABELTIP);
		ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */
		{	
			LVCOLUMN lvc;
			lvc.mask = LVCF_TEXT;
			lvc.pszText = TranslateT("Installed Languages");
			ListView_InsertColumn(hwndList, 0, &lvc);
		}
		if ( ServiceExists(MS_FLAGS_LOADFLAGICON))
			ListView_SetImageList(hwndList, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR24, 8, 8), LVSIL_SMALL); 
		
		TCHAR szPath[MAX_PATH];
		GetPackPath(szPath, SIZEOF(szPath), FALSE, _T(""));
		SetDlgItemText(hwndDlg, IDC_SKINROOTFOLDER, szPath);

		SendMessage(hwndDlg, M_RELOADLIST, 0, 0);
		SendMessage(hwndDlg, M_SHOWFILECOL, 0, 1);
		return TRUE;

	case M_RELOADLIST:
		/* init list */
		ListView_DeleteAllItems(hwndList);
		ListView_DeleteColumn(hwndList, 1); /* if present */
		{
			HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL);
			ImageList_RemoveAll(himl);
			/* enum all packs */
			EnumPacks(InsertPackItemEnumProc, _T("langpack_*.txt"), "Miranda Language Pack Version 1", (WPARAM)hwndList, (LPARAM)himl);
			/* make it use current langpack locale for sort */
			ListView_SortItems(hwndList, CompareListItem, CallService(MS_LANGPACK_GETLOCALE, 0, 0));
			//CheckDlgButton(hwndDlg, IDC_ENABLEAUTOUPDATES, db_get_b(NULL, "LangMan", "EnableAutoUpdates", SETTING_ENABLEAUTOUPDATES_DEFAULT) != 0);
			/* show selection */
			int iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
			if (iItem != -1)
				ListView_EnsureVisible(hwndList, iItem, FALSE);
		}
		return TRUE;

	case M_SHOWFILECOL:
		if ((BOOL)lParam && ListView_GetItemCount(hwndList) > 1) {
			/* add column */
			LVCOLUMN lvc;
			ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
			lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
			lvc.pszText = TranslateT("File");
			lvc.cx = 160;
			ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc);
			ListView_SetColumnWidth(hwndList, 0, ListView_GetColumnWidth(hwndList, 0) - lvc.cx);

			/* add text */
			lvi.mask = LVIF_PARAM;
			lvi.iSubItem = 0;
			for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
				LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
				ListView_SetItemText(hwndList, lvi.iItem, 1, (pack->flags&LPF_DEFAULT) ? TranslateT("built-in") : pack->szFileName);
			}
		}
		else {
			ListView_DeleteColumn(hwndList, 1);
			ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
		}
		return TRUE;

	case WM_DESTROY:
		ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LANGLIST));
		return TRUE;

	case WM_THEMECHANGED:
	case WM_SETTINGCHANGE:
		{
			HIMAGELIST himl = ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */
			if (himl != NULL)
				ImageList_Destroy(himl);
		}
		break;

	case WM_CTLCOLORLISTBOX: /* mimic readonly edit */
		return (BOOL)SendMessage(hwndDlg, WM_CTLCOLORSTATIC, wParam, lParam);

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDC_LANGEMAIL:
			{
				char buf[512];
				lstrcpyA(buf, "mailto:");
				if (GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), &buf[7], sizeof(buf)-7))
					CallService(MS_UTILS_OPENURL, FALSE, (LPARAM)buf);
				return TRUE;
			}

		case IDC_MORELANG:
			CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)"http://miranda-ng.org/");
			return TRUE;
		}
		break;

	case WM_CONTEXTMENU:
		if (GetDlgCtrlID((HWND)wParam) == IDC_LANGLIST) {
			/* get item */
			LVHITTESTINFO hti;
			POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
			if (hti.pt.x == -1 && hti.pt.y == -1) {
				/* keyboard invoked */
				hti.iItem = ListView_GetNextItem((HWND)wParam, -1, LVNI_SELECTED);
				if (hti.iItem != -1)
					break;

				RECT rc;
				if (!ListView_GetItemRect((HWND)wParam, hti.iItem, &rc, LVIR_SELECTBOUNDS))
					break;

				hti.pt.x = rc.left + (rc.right - rc.left) / 2;
				hti.pt.y = rc.top + (rc.bottom - rc.top) / 2;
				ClientToScreen((HWND)wParam, &hti.pt);
			}
			else {
				ScreenToClient((HWND)wParam, &hti.pt);
				if (ListView_HitTest((HWND)wParam, &hti) == -1 || !(hti.flags&LVHT_ONITEM))
					break;
				POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
			}

			/* param */
			lvi.iItem = hti.iItem;
			lvi.iSubItem = 0;
			lvi.mask = LVIF_PARAM;
			if (!ListView_GetItem((HWND)wParam, &lvi))
				break;

			/* context menu */
			LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
			if (!(pack->flags & LPF_DEFAULT)) {
				HMENU hContextMenu = CreatePopupMenu();
				if (hContextMenu != NULL) {
					AppendMenu(hContextMenu, MF_STRING, 2, TranslateT("&Remove..."));
					if (TrackPopupMenuEx(hContextMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION, hti.pt.x, hti.pt.y, (HWND)wParam, NULL))
						DeletePackFile(hwndDlg, (HWND)wParam, hti.iItem, pack);
					DestroyMenu(hContextMenu);
				}
			}
			return TRUE;
		}
		break;

	case WM_NOTIFYFORMAT:
		SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, NFR_UNICODE);
		return TRUE;

	case WM_NOTIFY:
		NMHDR *nmhdr = (NMHDR*)lParam;
		switch (nmhdr->idFrom) {
		case IDC_LANGLIST:
			switch (nmhdr->code) {
			case LVN_DELETEITEM:
				lvi.iItem = ((NMLISTVIEW*)lParam)->iItem; /* nmlv->lParam is invalid */
				lvi.iSubItem = 0;
				lvi.mask = LVIF_PARAM;
				if (ListView_GetItem(nmhdr->hwndFrom, &lvi))
					mir_free((LANGPACK_INFO*)lvi.lParam);
				break;

			case LVN_ITEMCHANGED:
				{
					NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
					if (!(nmlv->uChanged&LVIF_STATE))
						break;

					/* display info and check radio item */
					if (nmlv->uNewState&LVIS_SELECTED && !(nmlv->uOldState&LVIS_SELECTED)) {
						ListView_SetItemState(nmhdr->hwndFrom, nmlv->iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
						DisplayPackInfo(hwndDlg, (LANGPACK_INFO*)nmlv->lParam);
					}
					/* disable all other radio items */
					else if (nmlv->uNewState&INDEXTOSTATEIMAGEMASK(2)) {
						for (int iItem = ListView_GetItemCount(nmhdr->hwndFrom) - 1; iItem != -1; --iItem)
							if (iItem != nmlv->iItem)
								ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);

						/* enable apply */
						if (nmlv->uOldState) {
							SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
							ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
						}
					}
				}
				break;

			case LVN_KEYDOWN:
				{
					int iItem = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED);
					switch (((NMLVKEYDOWN*)lParam)->wVKey) {
					case VK_SPACE:
						ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
						break;

					case VK_DELETE:
						lvi.iItem = iItem;
						lvi.iSubItem = 0;
						lvi.mask = LVIF_PARAM;
						if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) {
							LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
							if (!(pack->flags&LPF_DEFAULT))
								DeletePackFile(hwndDlg, nmhdr->hwndFrom, iItem, pack);
						}
						break;
					}
				}
				break;

			case NM_CLICK:
				LVHITTESTINFO hti;
				lParam = GetMessagePos();
				POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
				ScreenToClient(nmhdr->hwndFrom, &hti.pt);
				if (ListView_HitTest(nmhdr->hwndFrom, &hti) != -1)
					if (hti.flags&(LVHT_ONITEMSTATEICON | LVHT_ONITEMICON)) /* one of them */
						ListView_SetItemState(nmhdr->hwndFrom, hti.iItem, LVIS_SELECTED, LVIS_SELECTED);
			}
			break;

		case 0:
			switch (nmhdr->code) {
			case PSN_APPLY:
				lvi.mask = LVIF_STATE | LVIF_PARAM;
				lvi.stateMask = LVIS_STATEIMAGEMASK;
				lvi.iSubItem = 0;
				for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
					LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
					if (lvi.state&INDEXTOSTATEIMAGEMASK(2) && !(pack->flags & LPF_ENABLED)) {
						if(!(pack->flags & LPF_DEFAULT))
							db_set_ws(NULL, "LangMan", "Langpack", pack->szFileName);
						else
							db_unset(NULL, "LangMan", "Langpack");
						TCHAR szPath[MAX_PATH];
						GetPackPath(szPath, SIZEOF(szPath), FALSE, pack->szFileName);
						CallService(MS_LANGPACK_RELOAD, 0, (LPARAM)szPath);
						pack->flags |= LPF_ENABLED;
						CloseWindow(GetParent(hwndDlg));
						DestroyWindow(GetParent(hwndDlg));
					}
					else pack->flags &= ~LPF_ENABLED;
				}
				return TRUE;
			}
		}
		break;
	}
	return FALSE;
}
Exemple #25
0
INT_PTR CALLBACK ChangeInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	ChangeInfoData* dat = (ChangeInfoData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);

		dat = new ChangeInfoData();
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

		dat->hwndDlg = hwndDlg;
		dat->ppro = (CIcqProto*)lParam;
		dat->hwndList = GetDlgItem(hwndDlg, IDC_LIST);

		ListView_SetExtendedListViewStyle(dat->hwndList, LVS_EX_FULLROWSELECT);
		dat->iEditItem = -1;
		{
			dat->hListFont = (HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0);

			LOGFONT lf;
			GetObject(dat->hListFont, sizeof(lf), &lf);
			lf.lfHeight -= 5;
			HFONT hFont = CreateFontIndirect(&lf);
			SendMessage(dat->hwndList, WM_SETFONT, (WPARAM)hFont, 0);

			// Prepare ListView Columns
			RECT rc;
			GetClientRect(dat->hwndList, &rc);
			rc.right -= GetSystemMetrics(SM_CXVSCROLL);

			LV_COLUMN lvc = { 0 };
			lvc.mask = LVCF_WIDTH;
			lvc.cx = rc.right / 3;
			ListView_InsertColumn(dat->hwndList, 0, &lvc);
			lvc.cx = rc.right - lvc.cx;
			ListView_InsertColumn(dat->hwndList, 1, &lvc);

			// Prepare Setting Items
			LV_ITEM lvi = { 0 };
			lvi.mask = LVIF_PARAM | LVIF_TEXT;
			for (lvi.iItem = 0; lvi.iItem < settingCount; lvi.iItem++) {
				TCHAR text[MAX_PATH];
				lvi.lParam = lvi.iItem;
				lvi.pszText = text;
				utf8_to_tchar_static(setting[lvi.iItem].szDescription, text, _countof(text));
				ListView_InsertItem(dat->hwndList, &lvi);
			}
		}

		SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		return TRUE;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_PARAMCHANGED:
				dat->ppro = (CIcqProto*)((PSHNOTIFY*)lParam)->lParam;
				dat->LoadSettingsFromDb(0);
				{
					char *pwd = dat->ppro->GetUserPassword(TRUE);
					mir_strcpy(dat->Password, (pwd) ? pwd : ""); /// FIXME
				}
				break;

			case PSN_INFOCHANGED:
				dat->LoadSettingsFromDb(1);
				break;

			case PSN_KILLACTIVE:
				dat->EndStringEdit(1);
				dat->EndListEdit(1);
				break;

			case PSN_APPLY:
				if (dat->ChangesMade()) {
					if (MessageBox(hwndDlg, TranslateT("You've made some changes to your ICQ details but it has not been saved to the server. Are you sure you want to close this dialog?"), TranslateT("Change ICQ Details"), MB_YESNOCANCEL) != IDYES) {
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
						return TRUE;
					}
				}
			}
			break;

		case IDC_LIST:
			switch (((LPNMHDR)lParam)->code) {
			case LVN_GETDISPINFO:
				if (dat->iEditItem != -1) {
					if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) {
						dat->EndStringEdit(1);
						dat->EndListEdit(1);
					}
				}
				break;

			case NM_CUSTOMDRAW:
				{
					LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)lParam;

					switch (cd->nmcd.dwDrawStage) {
					case CDDS_PREPAINT:
						SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
						return TRUE;

					case CDDS_ITEMPREPAINT:
						if (dat->iEditItem != -1) {
							if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) {
								dat->EndStringEdit(1);
								dat->EndListEdit(1);
							}
						}
						{
							RECT rcItem;
							ListView_GetItemRect(dat->hwndList, cd->nmcd.dwItemSpec, &rcItem, LVIR_BOUNDS);

							if (GetWindowLongPtr(dat->hwndList, GWL_STYLE) & WS_DISABLED) {  // Disabled List
								SetTextColor(cd->nmcd.hdc, cd->clrText);
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_3DFACE));
							}
							else if ((cd->nmcd.uItemState & CDIS_SELECTED || dat->iEditItem == (int)cd->nmcd.dwItemSpec)
										&& setting[cd->nmcd.lItemlParam].displayType != LI_DIVIDER) {  // Selected item
								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
							}
							else { // Unselected item
								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_WINDOWTEXT));
								FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_WINDOW));
							}

							HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, dat->hListFont);

							if (setting[cd->nmcd.lItemlParam].displayType == LI_DIVIDER) {
								RECT rcLine;
								SIZE textSize;
								char str[MAX_PATH];
								char *szText = ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH);

								SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW));
								DrawTextUtf(cd->nmcd.hdc, szText, &rcItem, DT_CENTER | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER, &textSize);
								rcLine.top = (rcItem.top + rcItem.bottom) / 2 - 1;
								rcLine.bottom = rcLine.top + 2;
								rcLine.left = rcItem.left + 3;
								rcLine.right = (rcItem.left + rcItem.right - textSize.cx) / 2 - 3;
								DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT);
								rcLine.left = (rcItem.left + rcItem.right + textSize.cx) / 2 + 3;
								rcLine.right = rcItem.right - 3;
								DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT);
							}
							else {
								RECT rcItemDescr, rcItemValue;
								char str[MAX_PATH];

								ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 0, LVIR_BOUNDS, &rcItemDescr);
								ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 1, LVIR_BOUNDS, &rcItemValue);

								rcItemDescr.right = rcItemValue.left;
								rcItemDescr.left += 2;
								DrawTextUtf(cd->nmcd.hdc, ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH), &rcItemDescr, DT_END_ELLIPSIS | DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER, NULL);

								dat->PaintItemSetting(cd->nmcd.hdc, &rcItemValue, cd->nmcd.lItemlParam, cd->nmcd.uItemState);
							}
							SelectObject(cd->nmcd.hdc, hoFont);

							SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT);

							return TRUE;
						}
					}
				}
				break;

			case NM_CLICK:
				{
					LPNMLISTVIEW nm = (LPNMLISTVIEW)lParam;
					LV_ITEM lvi;
					RECT rc;

					dat->EndStringEdit(1);
					dat->EndListEdit(1);
					if (nm->iSubItem != 1) break;
					lvi.mask = LVIF_PARAM | LVIF_STATE;
					lvi.stateMask = 0xFFFFFFFF;
					lvi.iItem = nm->iItem; lvi.iSubItem = nm->iSubItem;
					ListView_GetItem(dat->hwndList, &lvi);
					if (!(lvi.state & LVIS_SELECTED)) break;
					ListView_EnsureVisible(dat->hwndList, lvi.iItem, FALSE);
					ListView_GetSubItemRect(dat->hwndList, lvi.iItem, lvi.iSubItem, LVIR_BOUNDS, &rc);
					dat->editTopIndex = ListView_GetTopIndex(dat->hwndList);
					switch (setting[lvi.lParam].displayType & LIM_TYPE) {
					case LI_STRING:
					case LI_LONGSTRING:
					case LI_NUMBER:
						dat->BeginStringEdit(nm->iItem, &rc, lvi.lParam, 0);
						break;
					case LI_LIST:
						dat->BeginListEdit(nm->iItem, &rc, lvi.lParam, 0);
						break;
					}
				}
				break;

			case LVN_KEYDOWN:
				{
					LPNMLVKEYDOWN nm = (LPNMLVKEYDOWN)lParam;
					LV_ITEM lvi;
					RECT rc;

					dat->EndStringEdit(1);
					dat->EndListEdit(1);
					if (nm->wVKey == VK_SPACE || nm->wVKey == VK_RETURN || nm->wVKey == VK_F2) nm->wVKey = 0;
					if (nm->wVKey && (nm->wVKey<'0' || (nm->wVKey>'9' && nm->wVKey<'A') || (nm->wVKey>'Z' && nm->wVKey < VK_NUMPAD0) || nm->wVKey >= VK_F1))
						break;
					lvi.mask = LVIF_PARAM | LVIF_STATE;
					lvi.stateMask = 0xFFFFFFFF;
					lvi.iItem = ListView_GetNextItem(dat->hwndList, -1, LVNI_ALL | LVNI_SELECTED);
					if (lvi.iItem == -1) break;
					lvi.iSubItem = 1;
					ListView_GetItem(dat->hwndList, &lvi);
					ListView_EnsureVisible(dat->hwndList, lvi.iItem, FALSE);
					ListView_GetSubItemRect(dat->hwndList, lvi.iItem, lvi.iSubItem, LVIR_BOUNDS, &rc);
					dat->editTopIndex = ListView_GetTopIndex(dat->hwndList);
					switch (setting[lvi.lParam].displayType & LIM_TYPE) {
					case LI_STRING:
					case LI_LONGSTRING:
					case LI_NUMBER:
						dat->BeginStringEdit(lvi.iItem, &rc, lvi.lParam, nm->wVKey);
						break;
					case LI_LIST:
						dat->BeginListEdit(lvi.iItem, &rc, lvi.lParam, nm->wVKey);
						break;
					}
					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
				}
				return TRUE;

			case NM_KILLFOCUS:
				if (!IsStringEditWindow(GetFocus()))
					dat->EndStringEdit(1);
				if (!IsListEditWindow(GetFocus()))
					dat->EndListEdit(1);
			}
		}
		break;

	case WM_KILLFOCUS:
		dat->EndStringEdit(1);
		dat->EndListEdit(1);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(GetParent(hwndDlg), msg, wParam, lParam);
			break;

		case IDC_SAVE:
			if (!dat->SaveSettingsToDb(hwndDlg))
				break;

			EnableDlgItem(hwndDlg, IDC_SAVE, FALSE);
			EnableDlgItem(hwndDlg, IDC_LIST, FALSE);
			SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload in progress..."));
			EnableDlgItem(hwndDlg, IDC_UPLOADING, TRUE);
			ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_SHOW);
			dat->hAckHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, DM_PROTOACK);

			if (!dat->UploadSettings()) {
				EnableDlgItem(hwndDlg, IDC_SAVE, TRUE);
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_HIDE);
				UnhookEvent(dat->hAckHook);
				dat->hAckHook = NULL;
			}
		}
		break;

	case WM_SIZE:
		if (IsIconic(hwndDlg))
			break;
		
		Utils_ResizeDialog(hwndDlg, hInst, MAKEINTRESOURCEA(IDD_INFO_CHANGEINFO), ChangeInfoDlg_Resize);
		{
			RECT rc; // update listview column widths
			GetClientRect(dat->hwndList, &rc);
			rc.right -= GetSystemMetrics(SM_CXVSCROLL);
			ListView_SetColumnWidth(dat->hwndList, 0, rc.right / 3);
			ListView_SetColumnWidth(dat->hwndList, 1, rc.right - rc.right / 3);
		}
		break;

	case DM_PROTOACK:
		{
			ACKDATA *ack = (ACKDATA*)lParam;
			int i, done;

			if (ack->type != ACKTYPE_SETINFO) break;
			if (ack->result == ACKRESULT_SUCCESS) {
				for (i = 0; i < _countof(dat->hUpload); i++)
					if (dat->hUpload[i] && ack->hProcess == dat->hUpload[i]) break;

				if (i == _countof(dat->hUpload)) break;
				dat->hUpload[i] = NULL;
				for (done = 0, i = 0; i < _countof(dat->hUpload); i++)
					done += dat->hUpload[i] == NULL;
				TCHAR buf[MAX_PATH];
				mir_sntprintf(buf, TranslateT("Upload in progress...%d%%"), 100 * done / (_countof(dat->hUpload)));
				SetDlgItemText(hwndDlg, IDC_UPLOADING, buf);
				if (done < _countof(dat->hUpload)) break;

				dat->ClearChangeFlags();
				UnhookEvent(dat->hAckHook);
				dat->hAckHook = NULL;
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE);
				SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload complete"));
				SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0);
			}
			else if (ack->result == ACKRESULT_FAILED) {
				UnhookEvent(dat->hAckHook);
				dat->hAckHook = NULL;
				EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
				EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE);
				SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload FAILED"));
				SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0);
				EnableDlgItem(hwndDlg, IDC_SAVE, TRUE);
			}
		}
		break;

	case WM_DESTROY:
		if (dat->hAckHook) {
			UnhookEvent(dat->hAckHook);
			dat->hAckHook = NULL;
		}

		DeleteObject((HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0));

		dat->FreeStoredDbSettings();
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
		delete dat;
		break;
	}
	return FALSE;
}
static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DlgProfData *dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		EnsureCheckerLoaded(true);
		{
			dat = (DlgProfData*)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

			// set columns
			LVCOLUMN col;
			col.mask = LVCF_TEXT | LVCF_WIDTH;
			col.pszText = TranslateT("Profile");
			col.cx = 100;
			ListView_InsertColumn(hwndList, 0, &col);

			col.pszText = TranslateT("Driver");
			col.cx = 150 - GetSystemMetrics(SM_CXVSCROLL);
			ListView_InsertColumn(hwndList, 1, &col);

			col.pszText = TranslateT("Size");
			col.cx = 60;
			ListView_InsertColumn(hwndList, 2, &col);

			// icons
			HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 1);
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS));
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE));

			// LV will destroy the image list
			SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | LVS_SORTASCENDING);
			ListView_SetImageList(hwndList, hImgList, LVSIL_SMALL);
			ListView_SetExtendedListViewStyle(hwndList,
				ListView_GetExtendedListViewStyle(hwndList) | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);

			// find all the profiles
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0);

			dat->hFileNotify = FindFirstChangeNotification(dat->pd->szProfileDir, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE);
			if (dat->hFileNotify != INVALID_HANDLE_VALUE)
				SetTimer(hwndDlg, 0, 1200, NULL);
			return TRUE;
		}

	case WM_DESTROY:
		KillTimer(hwndDlg, 0);
		FindCloseChangeNotification(dat->hFileNotify);
		break;

	case WM_TIMER:
		if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0) {
			ListView_DeleteAllItems(hwndList);
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			FindNextChangeNotification(dat->hFileNotify);
		}
		break;

	case WM_FOCUSTEXTBOX:
		SetFocus(hwndList);
		if (dat->pd->szProfile[0] == 0 || ListView_GetSelectedCount(hwndList) == 0)
			ListView_SetItemState(hwndList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
		break;

	case WM_SHOWWINDOW:
		if (wParam) {
			SetWindowText(dat->hwndOK, TranslateT("&Run"));
			EnableWindow(dat->hwndSM, TRUE);
			EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);
		}
		break;

	case WM_CONTEXTMENU:
		{
			LVHITTESTINFO lvht = { 0 };
			lvht.pt.x = GET_X_LPARAM(lParam);
			lvht.pt.y = GET_Y_LPARAM(lParam);
			ScreenToClient(hwndList, &lvht.pt);

			if (ListView_HitTest(hwndList, &lvht) < 0) {
				if (lParam != -1)
					break;

				lvht.iItem = ListView_GetSelectionMark(hwndList);
				RECT rc = { 0 };
				if (!ListView_GetItemRect(hwndList, lvht.iItem, &rc, LVIR_LABEL))
					break;
				
				lvht.pt.x = rc.left;
				lvht.pt.y = rc.bottom;
				ClientToScreen(hwndList, &lvht.pt);
			}
			else {
				lvht.pt.x = GET_X_LPARAM(lParam);
				lvht.pt.y = GET_Y_LPARAM(lParam);
			}

			HMENU hMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
			AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
			if (ServiceExists(MS_DB_CHECKPROFILE)) {
				AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database"));
				AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
			}
			AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
			int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL);
			switch (index) {
			case 1:
				SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0);
				break;

			case 2:
				CheckProfile(hwndList, lvht.iItem, dat);
				break;

			case 3:
				DeleteProfile(hwndList, lvht.iItem, dat);
				break;
			}
			DestroyMenu(hMenu);
		}
		break;

	case WM_NOTIFY:
		LPNMHDR hdr = (LPNMHDR)lParam;
		if (hdr && hdr->code == PSN_INFOCHANGED)
			break;

		if (hdr && hdr->idFrom == IDC_PROFILELIST) {
			switch (hdr->code) {
			case LVN_ITEMCHANGED:
				EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);

			case NM_DBLCLK:
				if (dat != NULL) {
					TCHAR profile[MAX_PATH];
					LVITEM item = { 0 };
					item.mask = LVIF_TEXT;
					item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL);
					item.pszText = profile;
					item.cchTextMax = SIZEOF(profile);

					if (ListView_GetItem(hwndList, &item)) {
						// profile is placed in "profile_name" subfolder
						TCHAR tmpPath[MAX_PATH];
						mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->szProfileDir, profile);
						HANDLE hFile = CreateFile(tmpPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
						if (hFile == INVALID_HANDLE_VALUE)
							mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profile, profile);
						else
							_tcscpy(dat->pd->szProfile, tmpPath);
						CloseHandle(hFile);
						if (hdr->code == NM_DBLCLK) EndDialog(GetParent(hwndDlg), 1);
					}
				}
				return TRUE;

			case LVN_KEYDOWN:
				if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
					DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat);
				break;

			case LVN_GETINFOTIP:
				NMLVGETINFOTIP *pInfoTip = (NMLVGETINFOTIP *)lParam;
				if (pInfoTip != NULL) {
					TCHAR profilename[MAX_PATH], fullpath[MAX_PATH];
					struct _stat statbuf;
					ListView_GetItemText(hwndList, pInfoTip->iItem, 0, profilename, MAX_PATH);
					mir_sntprintf(fullpath, SIZEOF(fullpath), _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profilename, profilename);
					_tstat(fullpath, &statbuf);
					mir_sntprintf(pInfoTip->pszText, pInfoTip->cchTextMax, _T("%s\n%s: %s\n%s: %s"), fullpath, TranslateT("Created"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_ctime))), TranslateT("Modified"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_mtime))));
				}
			}
		}
		break;
	}

	return FALSE;
}
/*
================
rvGENavigator::WndProc

Window Procedure
================
*/
LRESULT CALLBACK rvGENavigator::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
	rvGENavigator *nav = ( rvGENavigator * ) GetWindowLong( hWnd, GWL_USERDATA );
	switch( msg ) {
	case WM_INITMENUPOPUP:
		return SendMessage( gApp.GetMDIFrame( ), msg, wParam, lParam );
	case WM_ACTIVATE:
		common->ActivateTool( LOWORD( wParam ) != WA_INACTIVE );
		break;
	case WM_ERASEBKGND:
		return TRUE;
	case WM_DESTROY:
		gApp.GetOptions().SetWindowPlacement( "navigator", hWnd );
		break;
	case WM_CLOSE:
		gApp.GetOptions().SetNavigatorVisible( false );
		nav->Show( false );
		return 0;
	case WM_DRAWITEM: {
		DRAWITEMSTRUCT	*dis = ( DRAWITEMSTRUCT * ) lParam;
		idWindow		*window = ( idWindow * )dis->itemData;
		if( window ) {
			rvGEWindowWrapper	*wrapper	= rvGEWindowWrapper::GetWrapper( window );
			idStr				name    = window->GetName();
			RECT				rDraw;
			float				offset;
			bool				disabled;
			idWindow *parent = window;
			offset = 1;
			disabled = false;
			while( parent = parent->GetParent( ) ) {
				if( rvGEWindowWrapper::GetWrapper( parent )->IsHidden( ) ) {
					disabled = true;
				}
				offset += 10;
			}
			CopyRect( &rDraw, &dis->rcItem );
			rDraw.right = rDraw.left + GENAV_ITEMHEIGHT;
			rDraw.top ++;
			rDraw.right ++;
			FrameRect( dis->hDC, &rDraw, ( HBRUSH )GetStockObject( BLACK_BRUSH ) );
			rDraw.right --;
			FillRect( dis->hDC, &rDraw, GetSysColorBrush( COLOR_3DFACE ) );
			Draw3dRect( dis->hDC, &rDraw, GetSysColorBrush( COLOR_3DHILIGHT ), GetSysColorBrush( COLOR_3DSHADOW ) );
			InflateRect( &rDraw, -3, -3 );
			Draw3dRect( dis->hDC, &rDraw, GetSysColorBrush( COLOR_3DSHADOW ), GetSysColorBrush( COLOR_3DHILIGHT ) );
			if( !wrapper->IsHidden( ) ) {
				DrawIconEx( dis->hDC, rDraw.left, rDraw.top, disabled ? nav->mVisibleIconDisabled : nav->mVisibleIcon, 16, 16, 0, NULL, DI_NORMAL );
			}
			CopyRect( &rDraw, &dis->rcItem );
			rDraw.left += GENAV_ITEMHEIGHT;
			rDraw.left += 1;
			if( dis->itemState & ODS_SELECTED ) {
				FillRect( dis->hDC, &rDraw, GetSysColorBrush( COLOR_HIGHLIGHT ) );
			} else {
				FillRect( dis->hDC, &rDraw, GetSysColorBrush( COLOR_WINDOW ) );
			}
			if( wrapper->CanHaveChildren( ) && window->GetChildCount( ) ) {
				if( wrapper->IsExpanded( ) ) {
					DrawIconEx( dis->hDC, rDraw.left + offset, rDraw.top + 3, nav->mCollapseIcon, 16, 16, 0, NULL, DI_NORMAL );
				} else {
					DrawIconEx( dis->hDC, rDraw.left + offset, rDraw.top + 3, nav->mExpandIcon, 16, 16, 0, NULL, DI_NORMAL );
				}
			}
			HPEN pen = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ) );
			HPEN oldpen = ( HPEN )SelectObject( dis->hDC, pen );
			MoveToEx( dis->hDC, rDraw.left, dis->rcItem.top, NULL );
			LineTo( dis->hDC, dis->rcItem.right, dis->rcItem.top );
			MoveToEx( dis->hDC, rDraw.left, dis->rcItem.bottom, NULL );
			LineTo( dis->hDC, dis->rcItem.right, dis->rcItem.bottom );
			SelectObject( dis->hDC, oldpen );
			DeleteObject( pen );
			rDraw.left += offset;
			rDraw.left += 20;
			int colorIndex = ( ( dis->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT );
			SetTextColor( dis->hDC, GetSysColor( colorIndex ) );
			DrawText( dis->hDC, name, name.Length(), &rDraw, DT_LEFT | DT_VCENTER | DT_SINGLELINE );
			if( wrapper->GetVariableDict().GetNumKeyVals( ) || wrapper->GetScriptDict().GetNumKeyVals( ) ) {
				DrawIconEx( dis->hDC, dis->rcItem.right - 16, ( dis->rcItem.bottom + dis->rcItem.top ) / 2 - 6, ( dis->itemState & ODS_SELECTED ) ? nav->mScriptsLightIcon : nav->mScriptsIcon, 13, 13, 0, NULL, DI_NORMAL );
			}
		}
		break;
	}
	case WM_MEASUREITEM: {
		MEASUREITEMSTRUCT *mis = ( MEASUREITEMSTRUCT * ) lParam;
		mis->itemHeight = 22;
		break;
	}
	case WM_CREATE: {
		LPCREATESTRUCT	cs;
		LVCOLUMN		col;
		// Attach the class to the window first
		cs = ( LPCREATESTRUCT ) lParam;
		nav = ( rvGENavigator * ) cs->lpCreateParams;
		SetWindowLong( hWnd, GWL_USERDATA, ( LONG )nav );
		// Create the List view
		nav->mTree = CreateWindowEx( 0, "SysListView32", "", WS_VSCROLL | WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_NOCOLUMNHEADER | LVS_SHOWSELALWAYS, 0, 0, 0, 0, hWnd, ( HMENU )IDC_GUIED_WINDOWTREE, win32.hInstance, 0 );
		ListView_SetExtendedListViewStyle( nav->mTree, LVS_EX_FULLROWSELECT );
		ListView_SetBkColor( nav->mTree, GetSysColor( COLOR_3DFACE ) );
		ListView_SetTextBkColor( nav->mTree, GetSysColor( COLOR_3DFACE ) );
		nav->mListWndProc = ( WNDPROC )GetWindowLong( nav->mTree, GWL_WNDPROC );
		SetWindowLong( nav->mTree, GWL_USERDATA, ( LONG )nav );
		SetWindowLong( nav->mTree, GWL_WNDPROC, ( LONG )ListWndProc );
		// Insert the only column
		col.mask = 0;
		ListView_InsertColumn( nav->mTree, 0, &col );
		break;
	}
	case WM_SIZE: {
		RECT rClient;
		MoveWindow( nav->mTree, 0, 0, LOWORD( lParam ), HIWORD( lParam ), TRUE );
		GetClientRect( nav->mTree, &rClient );
		ListView_SetColumnWidth( nav->mTree, 0, rClient.right - rClient.left - 1 );
		break;
	}
	case WM_NCACTIVATE:
		return gApp.ToolWindowActivate( gApp.GetMDIFrame(), msg, wParam, lParam );
	case WM_NOTIFY: {
		LPNMHDR nh;
		nh = ( LPNMHDR ) lParam;
		switch( nh->code ) {
		case NM_CLICK:
		case NM_DBLCLK: {
			DWORD dwpos = GetMessagePos();
			LVHITTESTINFO info;
			info.pt.x = LOWORD( dwpos );
			info.pt.y = HIWORD( dwpos );
			MapWindowPoints( HWND_DESKTOP, nh->hwndFrom, &info.pt, 1 );
			int index = ListView_HitTest( nav->mTree, &info );
			if( index != -1 ) {
				RECT	rItem;
				int		offset;
				ListView_GetItemRect( nav->mTree, index, &rItem, LVIR_BOUNDS );
				LVITEM item;
				item.mask = LVIF_PARAM;
				item.iItem = index;
				ListView_GetItem( nav->mTree, &item );
				idWindow *window = ( idWindow * )item.lParam;
				rvGEWindowWrapper *wrapper = rvGEWindowWrapper::GetWrapper( window );
				offset = wrapper->GetDepth( ) * 10 + 1;
				if( info.pt.x < GENAV_ITEMHEIGHT ) {
					if( !rvGEWindowWrapper::GetWrapper( window )->IsHidden( ) ) {
						nav->mWorkspace->HideWindow( window );
					} else {
						nav->mWorkspace->UnhideWindow( window );
					}
				} else if( info.pt.x > GENAV_ITEMHEIGHT + offset && info.pt.x < GENAV_ITEMHEIGHT + offset + 16 ) {
					if( wrapper->CanHaveChildren( ) && window->GetChildCount( ) ) {
						if( wrapper->IsExpanded( ) ) {
							wrapper->Collapse( );
							nav->Update( );
						} else {
							wrapper->Expand( );
							nav->Update( );
						}
					}
				} else if( nh->code == NM_DBLCLK ) {
					SendMessage( gApp.GetMDIFrame( ), WM_COMMAND, MAKELONG( ID_GUIED_ITEM_PROPERTIES, 0 ), 0 );
				}
			}
			break;
		}
		case NM_RCLICK: {
			DWORD dwpos = GetMessagePos();
			LVHITTESTINFO info;
			info.pt.x = LOWORD( dwpos );
			info.pt.y = HIWORD( dwpos );
			MapWindowPoints( HWND_DESKTOP, nh->hwndFrom, &info.pt, 1 );
			int index = ListView_HitTest( nav->mTree, &info );
			if( index != -1 ) {
				ClientToScreen( hWnd, &info.pt );
				HMENU menu = GetSubMenu( LoadMenu( gApp.GetInstance(), MAKEINTRESOURCE( IDR_GUIED_ITEM_POPUP ) ), 0 );
				TrackPopupMenu( menu, TPM_RIGHTBUTTON | TPM_LEFTALIGN, info.pt.x, info.pt.y, 0, gApp.GetMDIFrame( ), NULL );
				DestroyMenu( menu );
			}
			break;
		}
		case LVN_ITEMCHANGED: {
			NMLISTVIEW *nml = ( NMLISTVIEW * ) nh;
			if( ( nml->uNewState & LVIS_SELECTED ) != ( nml->uOldState & LVIS_SELECTED ) ) {
				LVITEM item;
				item.iItem = nml->iItem;
				item.mask = LVIF_PARAM;
				ListView_GetItem( nav->mTree, &item );
				if( nml->uNewState & LVIS_SELECTED ) {
					nav->mWorkspace->GetSelectionMgr().Add( ( idWindow * )item.lParam, false );
				} else {
					nav->mWorkspace->GetSelectionMgr().Remove( ( idWindow * )item.lParam );
				}
			}
			break;
		}
		}
		break;
	}
	}
	return DefWindowProc( hWnd, msg, wParam, lParam );
}
Exemple #28
0
/*
* MainWindowProc
*
* Purpose:
*
* Main window procedure.
*
*/
LRESULT CALLBACK MainWindowProc(
    _In_ HWND hwnd,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
)
{
    INT                 mark;
    RECT                ToolBarRect, crc;
    LPDRAWITEMSTRUCT    pds;
    LPMEASUREITEMSTRUCT pms;

    switch (uMsg) {
    case WM_CONTEXTMENU:

        RtlSecureZeroMemory(&crc, sizeof(crc));

        if ((HWND)wParam == g_hwndObjectTree) {
            TreeView_GetItemRect(g_hwndObjectTree, TreeView_GetSelection(g_hwndObjectTree), &crc, TRUE);
            crc.top = crc.bottom;
            ClientToScreen(g_hwndObjectTree, (LPPOINT)&crc);
            supHandleTreePopupMenu(hwnd, (LPPOINT)&crc);
        }

        if ((HWND)wParam == g_hwndObjectList) {
            mark = ListView_GetSelectionMark(g_hwndObjectList);

            if (lParam == MAKELPARAM(-1, -1)) {
                ListView_GetItemRect(g_hwndObjectList, mark, &crc, TRUE);
                crc.top = crc.bottom;
                ClientToScreen(g_hwndObjectList, (LPPOINT)&crc);
            }
            else
                GetCursorPos((LPPOINT)&crc);

            supHandleObjectPopupMenu(hwnd, g_hwndObjectList, mark, (LPPOINT)&crc);
        }
        break;

    case WM_COMMAND:
        MainWindowHandleWMCommand(hwnd, wParam, lParam);
        break;

    case WM_NOTIFY:
        MainWindowHandleWMNotify(hwnd, wParam, lParam);
        break;

    case WM_MEASUREITEM:
        pms = (LPMEASUREITEMSTRUCT)lParam;
        if (pms && pms->CtlType == ODT_MENU) {
            pms->itemWidth = 16;
            pms->itemHeight = 16;
        }
        break;

    case WM_DRAWITEM:
        pds = (LPDRAWITEMSTRUCT)lParam;
        if (pds && pds->CtlType == ODT_MENU) {
            DrawIconEx(pds->hDC, pds->rcItem.left - 15,
                pds->rcItem.top,
                (HICON)pds->itemData,
                16, 16, 0, NULL, DI_NORMAL);
        }
        break;

    case WM_CLOSE:
        PostQuitMessage(0);
        break;

    case WM_LBUTTONDOWN:
        SetCapture(MainWindow);
        break;

    case WM_LBUTTONUP:
        ReleaseCapture();
        break;

    case WM_MOUSEMOVE:
        if ((wParam & MK_LBUTTON) != 0) {
            GetClientRect(MainWindow, &ToolBarRect);
            SplitterPos = (SHORT)LOWORD(lParam);
            if (SplitterPos < SplitterMargin)
                SplitterPos = SplitterMargin;
            if (SplitterPos > ToolBarRect.right - SplitterMargin)
                SplitterPos = ToolBarRect.right - SplitterMargin;
            SendMessage(MainWindow, WM_SIZE, 0, 0);
            UpdateWindow(MainWindow);
        }
        break;

    case WM_SIZE:
        if (!IsIconic(hwnd)) {
            MainWindowResizeHandler(SplitterPos);
        }
        break;

    case WM_GETMINMAXINFO:
        if (lParam) {
            ((PMINMAXINFO)lParam)->ptMinTrackSize.x = 400;
            ((PMINMAXINFO)lParam)->ptMinTrackSize.y = 256;
        }
        break;
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void SearchResults::rebuild()
{
  EnterCriticalSection(&lock);

  static char colNames[colCount][32] = {
    "Name", "Date", "Size", "Game name", "Lineup", "Length", "Mode"
  };
  int colPos[colCount];
  getColPos(colPos);
  int colOrder[colCount];
  int numOrder = 0;
  for (int i = 0; i < colCount; i++)
    if (colPos[cfg.colOrder[i]] >= 0)
      colOrder[numOrder++] = colPos[cfg.colOrder[i]];

  Dictionary<uint32> selected;
  for (int sel = ListView_GetNextItem(hWnd, -1, LVNI_SELECTED); sel >= 0;
      sel = ListView_GetNextItem(hWnd, sel, LVNI_SELECTED))
    selected.set(items[sel].path, 1);
  int scrollPosX = GetScrollPos(hWnd, SB_HORZ);
  int scrollPosY = GetScrollPos(hWnd, SB_VERT);
  if (items.length() > 0)
  {
    RECT rc;
    ListView_GetItemRect(hWnd, 0, &rc, LVIR_BOUNDS);
    scrollPosY *= rc.bottom - rc.top;
  }

  setRedraw(false);
  clear();
  clearColumns();
  for (int i = 0; i < colCount; i++)
    if (colPos[i] >= 0)
      insertColumn(colPos[i], colNames[i]);
  if (colPos[colName] >= 0)
    setColumnUTF8(colPos[colName], true);
  ListView_SetColumnOrderArray(hWnd, numOrder, colOrder);

  int colSort = (cfg.colSort[0] & 0x80000000 ? ~cfg.colSort[0] : cfg.colSort[0]);
  if (colSort >= 0 && colSort < colCount && colPos[colSort] >= 0 && items.length() > 0)
  {
    HBITMAP image = NULL;
    if (cfg.colSort[0] & 0x80000000)
      image = getApp()->getImageLibrary()->getBitmap("SortUp");
    else
      image = getApp()->getImageLibrary()->getBitmap("SortDown");
    if (image)
    {
      HWND hHeader = ListView_GetHeader(hWnd);
      HDITEM hdi;
      memset(&hdi, 0, sizeof hdi);
      hdi.mask = HDI_FORMAT;
      Header_GetItem(hHeader, colSort, &hdi);
      hdi.mask |= HDI_BITMAP;
      hdi.fmt |= HDF_BITMAP | HDF_BITMAP_ON_RIGHT;
      hdi.hbm = image;
      Header_SetItem(hHeader, colSort, &hdi);
    }
  }

  items.sort(compItems);
  for (int i = 0; i < items.length(); i++)
    addItem(i, false);

  for (int i = 0; i < items.length(); i++)
    if (selected.has(items[i].path))
      ListView_SetItemState(hWnd, i, LVIS_SELECTED, LVIS_SELECTED);
  for (int i = 0; i < colCount; i++)
    if (colPos[i] >= 0)
      setColumnWidth(colPos[i], cfg.colWidth[i]);
  setRedraw(true);
  ListView_Scroll(hWnd, scrollPosX, scrollPosY);

  LeaveCriticalSection(&lock);
}
void NListView::ListView_HandleInsertionMark(HWND hListView,int iItemFocus,POINT *ppt)
{
	/* Remove the insertion mark. */
	if(ppt == NULL)
	{
		LVINSERTMARK lvim;
		lvim.cbSize		= sizeof(LVINSERTMARK);
		lvim.dwFlags	= 0;
		lvim.iItem		= -1;
		ListView_SetInsertMark(hListView,&lvim);

		return;
	}

	RECT ItemRect;
	DWORD dwFlags = 0;
	int iNext;

	LV_HITTESTINFO item;
	item.pt = *ppt;

	int iItem = ListView_HitTest(hListView,&item);

	if(iItem != -1 && item.flags & LVHT_ONITEM)
	{
		ListView_GetItemRect(hListView,item.iItem,&ItemRect,LVIR_BOUNDS);

		/* If the cursor is on the left side
		of this item, set the insertion before
		this item; if it is on the right side
		of this item, set the insertion mark
		after this item. */
		if((ppt->x - ItemRect.left) >
			((ItemRect.right - ItemRect.left)/2))
		{
			iNext = iItem;
			dwFlags = LVIM_AFTER;
		}
		else
		{
			iNext = iItem;
			dwFlags = 0;
		}
	}
	else
	{
		dwFlags = 0;

		/* VK_UP finds whichever item is "above" the cursor.
		This item may be in the same row as the cursor is in
		(e.g. an item in the next row won't be found until the
		cursor passes into that row). Appears to find the item
		on the right side. */
		LVFINDINFO lvfi;
		lvfi.flags			= LVFI_NEARESTXY;
		lvfi.pt				= *ppt;
		lvfi.vkDirection	= VK_UP;
		iNext = ListView_FindItem(hListView,-1,&lvfi);

		if(iNext == -1)
		{
			lvfi.flags			= LVFI_NEARESTXY;
			lvfi.pt				= *ppt;
			lvfi.vkDirection	= VK_LEFT;
			iNext = ListView_FindItem(hListView,-1,&lvfi);
		}

		ListView_GetItemRect(hListView,iNext,&ItemRect,LVIR_BOUNDS);

		/* This situation only occurs at the
		end of the row. Prior to this, it is
		always the item on the right side that
		is found, with the insertion mark been
		inserted before that item.
		Once the end of the row is reached, the
		item found will be on the left side of
		the cursor. */
		if(ppt->x > ItemRect.left +
			((ItemRect.right - ItemRect.left)/2))
		{
			/* At the end of a row, VK_UP appears to
			find the next item up. Therefore, if we're
			at the end of a row, and the cursor is
			completely below the "next" item, find the
			one under it instead (if there is an item
			under it), and anchor the insertion mark
			there. */
			if(ppt->y > ItemRect.bottom)
			{
				int iBelow;

				iBelow = ListView_GetNextItem(hListView,iNext,LVNI_BELOW);

				if(iBelow != -1)
					iNext = iBelow;
			}

			dwFlags = LVIM_AFTER;
		}

		int nItems = ListView_GetItemCount(hListView);

		/* Last item is at position nItems - 1. */
		ListView_GetItemRect(hListView,nItems - 1,&ItemRect,LVIR_BOUNDS);

		/* Special case needed for very last item. If cursor is within 0.5 to 1.5 width
		of last item, and is greater than it's y coordinate, snap the insertion mark to
		this item. */
		if((ppt->x > ItemRect.left + ((ItemRect.right - ItemRect.left)/2)) &&
			ppt->x < ItemRect.right + ((ItemRect.right - ItemRect.left)/2) + 2 &&
			ppt->y > ItemRect.top)
		{
			iNext = nItems - 1;
			dwFlags = LVIM_AFTER;
		}
	}

	LVINSERTMARK lvim;
	lvim.cbSize			= sizeof(LVINSERTMARK);
	lvim.dwFlags		= dwFlags;
	lvim.iItem			= iNext;
	ListView_SetInsertMark(hListView,&lvim);
}