Ejemplo n.º 1
0
void StatusWnd::onCommand(UINT id, HIMC hIMC)
{
	switch( id )
	{
	case ID_CHI_ENG:
		toggleChiEngMode(hIMC);
		break;
	case ID_FULL_HALF:
		toggleShapeMode(hIMC);
		break;
	case ID_MENU:
		{
			HMENU menu = LoadMenu( g_dllInst, LPCTSTR(IDR_POPUP));
			HMENU popup = GetSubMenu( menu, 0 );
			RECT rc;
			GetWindowRect(hwnd, &rc);
			rc.left += 9;
			UINT flag;
			long y;
			if((rc.top * 2) > GetSystemMetrics(SM_CYSCREEN) )
			{
				y = rc.top;
				flag = TPM_BOTTOMALIGN|TPM_LEFTALIGN;
			}
			else
			{
				y = rc.bottom;
				flag = TPM_TOPALIGN|TPM_LEFTALIGN;
			}
			TrackPopupMenu( popup, flag, rc.left, y, 0, hwnd, NULL);
			DestroyMenu(menu);
			break;
		}
	case ID_CONFIG:
	case ID_ABOUT:
		try {
			HWND top = hwnd;
			HWND desktop = GetDesktopWindow(), parent = NULL;
			while( (parent=GetParent(top)) != desktop && parent )
				top = parent;
			EnableWindow( hwnd, FALSE );
			if( id == ID_CONFIG )
				ConfigureChewingIME(top);
			else
				DialogBox(g_dllInst, LPCTSTR(IDD_ABOUT), top, (DLGPROC)AboutDlgProc);
			EnableWindow( hwnd, TRUE );
		}   catch (...)
        {
            OutputDebugString("Using die wnd");
        }
		break;
	case ID_WEBSITE:
		ShellExecute( NULL, "open", _T("http://chewing.im/"), NULL, NULL, SW_SHOWNORMAL );
		break;
	case ID_GROUP:
		ShellExecute( NULL, "open", _T("http://groups.google.com/group/chewing"), NULL, NULL, SW_SHOWNORMAL );
		break;
	case ID_BUGREPORT:
		ShellExecute( NULL, "open", _T("http://code.google.com/p/chewing/issues"), NULL, NULL, SW_SHOWNORMAL );
		break;
	case ID_DICT_BUGREPORT:
		ShellExecute( NULL, "open", _T("http://of.openfoundry.org/projects/436/rt"), NULL, NULL, SW_SHOWNORMAL );
		break;
	case ID_HASHED:
	case ID_CHEWING_HELP:
	case ID_CHECK_NEW_VER:
		{
			TCHAR path[MAX_PATH];
			GetSystemDirectory( path, MAX_PATH );
			_tcscat( path, _T("\\IME\\Chewing\\") );
			int showcmd;
			if( id == ID_CHEWING_HELP ) {
				_tcscat( path, _T("Chewing.chm"));
				showcmd = SW_SHOWMAXIMIZED;
			}
			else if( id == ID_CHECK_NEW_VER ) {
				_tcscat( path, _T("Update.exe"));
				showcmd = SW_SHOWNORMAL;
			}
			else {
				_tcscat( path, _T("HashEd.exe"));
				showcmd = SW_SHOWNORMAL;
			}
			ShellExecute( NULL, "open", path, NULL, NULL, showcmd );
			break;
		}
	case ID_DICT:
	case ID_SIMPDICT:
	case ID_LITTLEDICT:
	case ID_PROVERBDICT:
		{
			LPCTSTR url[]={
			_T("http://dict.revised.moe.edu.tw/"),
			_T("http://dict.concised.moe.edu.tw/main/cover/main.htm"),
			_T("http://dict.mini.moe.edu.tw/"),
			_T("http://dict.idioms.moe.edu.tw/sort_pho.htm")};
			ShellExecute( NULL, "open", url[ id - ID_DICT ], NULL, NULL, SW_SHOWNORMAL );
			break;
		}

	}
}
Ejemplo n.º 2
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
	case TRAY_CALLBACK:
	{
		switch(lParam)
		{
		case WM_LBUTTONDBLCLK:
			if (IsWindowVisible(hWnd))
				ShowWindow(hWnd, SW_HIDE);
			else
				ShowWindow(hWnd, SW_RESTORE);
			break;
		case WM_MOUSEMOVE:
			{
				CString sInfoTip;
				NOTIFYICONDATA SystemTray;
				sInfoTip.Format(_T("Cached Directories : %ld\nWatched paths : %ld"), 
					CGitStatusCache::Instance().GetCacheSize(),
					CGitStatusCache::Instance().GetNumberOfWatchedPaths());

				SystemTray.cbSize = sizeof(NOTIFYICONDATA);
				SystemTray.hWnd   = hTrayWnd;
				SystemTray.uID    = TRAY_ID;
				SystemTray.uFlags = NIF_TIP;
				_tcscpy_s(SystemTray.szTip, sInfoTip);
				Shell_NotifyIcon(NIM_MODIFY, &SystemTray);
			}
			break;
		case WM_RBUTTONUP:
		case WM_CONTEXTMENU:
			{
				POINT pt;
				DWORD ptW = GetMessagePos();
				pt.x = GET_X_LPARAM(ptW);
				pt.y = GET_Y_LPARAM(ptW);
				HMENU hMenu = CreatePopupMenu();
				if(hMenu)
				{
					InsertMenu(hMenu, (UINT)-1, MF_BYPOSITION, TRAYPOP_EXIT, _T("Exit"));
					SetForegroundWindow(hWnd);
					TrackPopupMenu(hMenu, TPM_BOTTOMALIGN, pt.x, pt.y, 0, hWnd, NULL);
					DestroyMenu(hMenu);
				}
			}
			break;
		}
	}
	break;
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hWnd, &ps);
			RECT rect;
			GetClientRect(hWnd, &rect);
			// clear the background
			HBRUSH background = CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
			HGDIOBJ oldbrush = SelectObject(hdc, background);
			FillRect(hdc, &rect, background);

			int line = 0;
			SIZE fontsize = {0};
			AutoLocker print(critSec);
			GetTextExtentPoint32( hdc, szCurrentCrawledPath[0], (int)_tcslen(szCurrentCrawledPath[0]), &fontsize );
			for (int i=nCurrentCrawledpathIndex; i<MAX_CRAWLEDPATHS; ++i)
			{
				TextOut(hdc, 0, line*fontsize.cy, szCurrentCrawledPath[i], (int)_tcslen(szCurrentCrawledPath[i]));
				line++;
			}
			for (int i=0; i<nCurrentCrawledpathIndex; ++i)
			{
				TextOut(hdc, 0, line*fontsize.cy, szCurrentCrawledPath[i], (int)_tcslen(szCurrentCrawledPath[i]));
				line++;
			}
			
			
			SelectObject(hdc,oldbrush);
			EndPaint(hWnd, &ps); 
			DeleteObject(background);
			return 0L; 
		}
		break;
	case WM_COMMAND:
		{
			WORD wmId    = LOWORD(wParam);

			switch (wmId)
			{
			case TRAYPOP_EXIT:
				DestroyWindow(hWnd);
				break;
			}
			return 1;
		}
	case WM_QUERYENDSESSION:
		{
			ATLTRACE("WM_QUERYENDSESSION\n");
			if (CGitStatusCache::Instance().WaitToWrite(200))
			{
				CGitStatusCache::Instance().Stop();
				CGitStatusCache::Instance().Done();
			}
			return TRUE;
		}
		break;
	case WM_CLOSE:
	case WM_ENDSESSION:
	case WM_DESTROY:
	case WM_QUIT:
		{
			ATLTRACE("WM_CLOSE/DESTROY/ENDSESSION/QUIT\n");
			CGitStatusCache::Instance().WaitToWrite();
			CGitStatusCache::Instance().Stop();
			CGitStatusCache::Instance().SaveCache();
			if (message != WM_QUIT)
				PostQuitMessage(0);
			bRun = false;
			return 1;
		}
		break;
	case WM_DEVICECHANGE:
		{
			DEV_BROADCAST_HDR * phdr = (DEV_BROADCAST_HDR*)lParam;
			switch (wParam)
			{
			case DBT_CUSTOMEVENT:
				{
					ATLTRACE("WM_DEVICECHANGE with DBT_CUSTOMEVENT\n");
					if (phdr->dbch_devicetype == DBT_DEVTYP_HANDLE)
					{
						DEV_BROADCAST_HANDLE * phandle = (DEV_BROADCAST_HANDLE*)lParam;
						if (IsEqualGUID(phandle->dbch_eventguid, GUID_IO_VOLUME_DISMOUNT))
						{
							ATLTRACE("Device to be dismounted\n");
							CGitStatusCache::Instance().WaitToWrite();
							CGitStatusCache::Instance().CloseWatcherHandles(phandle->dbch_hdevnotify);
							CGitStatusCache::Instance().Done();
						}
						if (IsEqualGUID(phandle->dbch_eventguid, GUID_IO_VOLUME_LOCK))
						{
							ATLTRACE("Device lock event\n");
							CGitStatusCache::Instance().WaitToWrite();
							CGitStatusCache::Instance().CloseWatcherHandles(phandle->dbch_hdevnotify);
							CGitStatusCache::Instance().Done();
						}
					}
				}
				break;
			case DBT_DEVICEREMOVEPENDING:
				ATLTRACE("WM_DEVICECHANGE with DBT_DEVICEREMOVEPENDING\n");
				if (phdr->dbch_devicetype == DBT_DEVTYP_HANDLE)
				{
					DEV_BROADCAST_HANDLE * phandle = (DEV_BROADCAST_HANDLE*)lParam;
					CGitStatusCache::Instance().WaitToWrite();
					CGitStatusCache::Instance().CloseWatcherHandles(phandle->dbch_hdevnotify);
					CGitStatusCache::Instance().Done();
				}
				else
				{
					CGitStatusCache::Instance().WaitToWrite();
					CGitStatusCache::Instance().CloseWatcherHandles(INVALID_HANDLE_VALUE);
					CGitStatusCache::Instance().Done();
				}
				break;
			case DBT_DEVICEQUERYREMOVE:
				ATLTRACE("WM_DEVICECHANGE with DBT_DEVICEQUERYREMOVE\n");
				if (phdr->dbch_devicetype == DBT_DEVTYP_HANDLE)
				{
					DEV_BROADCAST_HANDLE * phandle = (DEV_BROADCAST_HANDLE*)lParam;
					CGitStatusCache::Instance().WaitToWrite();
					CGitStatusCache::Instance().CloseWatcherHandles(phandle->dbch_hdevnotify);
					CGitStatusCache::Instance().Done();
				}
				else
				{
					CGitStatusCache::Instance().WaitToWrite();
					CGitStatusCache::Instance().CloseWatcherHandles(INVALID_HANDLE_VALUE);
					CGitStatusCache::Instance().Done();
				}
				break;
			case DBT_DEVICEREMOVECOMPLETE:
				ATLTRACE("WM_DEVICECHANGE with DBT_DEVICEREMOVECOMPLETE\n");
				if (phdr->dbch_devicetype == DBT_DEVTYP_HANDLE)
				{
					DEV_BROADCAST_HANDLE * phandle = (DEV_BROADCAST_HANDLE*)lParam;
					CGitStatusCache::Instance().WaitToWrite();
					CGitStatusCache::Instance().CloseWatcherHandles(phandle->dbch_hdevnotify);
					CGitStatusCache::Instance().Done();
				}
				else
				{
					CGitStatusCache::Instance().WaitToWrite();
					CGitStatusCache::Instance().CloseWatcherHandles(INVALID_HANDLE_VALUE);
					CGitStatusCache::Instance().Done();
				}
				break;
			}
		}
		break;
	default:
		break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}
Ejemplo n.º 3
0
static LRESULT CALLBACK
MainWndProc(HWND hwnd,
            UINT msg,
            WPARAM wParam,
            LPARAM lParam)
{
    PMAIN_WND_INFO Info;
    LRESULT Ret = 0;

    /* Get the window context */
    Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd,
                                            GWLP_USERDATA);
    if (Info == NULL && msg != WM_CREATE)
    {
        goto HandleDefaultMessage;
    }

    switch(msg)
    {
        case WM_CREATE:
        {
            Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams);

            /* Initialize the main window context */
            Info->hMainWnd = hwnd;
            Info->SelectedItem = NO_ITEM_SELECTED;

            SetWindowLongPtr(hwnd,
                             GWLP_USERDATA,
                             (LONG_PTR)Info);

            if (!InitMainWnd(Info))
                return -1;

            /* Fill the list-view before showing the main window */
            RefreshServiceList(Info);

            /* Show the window */
            ShowWindow(hwnd,
                       Info->nCmdShow);

            SetFocus(Info->hListView);
        }
        break;

        case WM_SIZE:
        {
            MainWndResize(Info,
                          LOWORD(lParam),
                          HIWORD(lParam));
        }
        break;

        case WM_NOTIFY:
        {
            LPNMHDR pnmhdr = (LPNMHDR)lParam;

            switch (pnmhdr->code)
            {
                case NM_DBLCLK:
                {
                    POINT pt;
                    RECT rect;

                    GetCursorPos(&pt);
                    GetWindowRect(Info->hListView, &rect);

                    if (PtInRect(&rect, pt))
                    {
                        SendMessage(hwnd,
                                    WM_COMMAND,
                                    //ID_PROP,
                                    MAKEWPARAM((WORD)ID_PROP, (WORD)0),
                                    0);
                    }

                    //OpenPropSheet(Info);
                }
                break;

                case NM_RETURN:
                {
                    SendMessage(hwnd,
                                WM_COMMAND,
                                //ID_PROP,
                                MAKEWPARAM((WORD)ID_PROP, (WORD)0),
                                0);
                }
                break;

                case LVN_COLUMNCLICK:
                {
                    LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
                    HDITEM       hdi;

                    /* get pending sort direction for clicked column */
                    hdi.mask = HDI_LPARAM;
                    (void)Header_GetItem(Info->hHeader, pnmv->iSubItem, &hdi);

                    /* get new sort parameters */
                    Info->SortSelection = pnmv->iSubItem;
                    Info->SortDirection = hdi.lParam;

                    /* set new sort direction and save */
                    hdi.lParam = (hdi.lParam == ORD_ASCENDING) ?
                                 ORD_DESCENDING : ORD_ASCENDING;

                    (void)Header_SetItem(Info->hHeader, pnmv->iSubItem, &hdi);

                    (void)ListView_SortItemsEx(Info->hListView,
                                               CompareFunc,
                                               (LPARAM)Info);
                }
                break;
                case LVN_ITEMCHANGED:
                {
                    LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;

                    if (pnmv->uNewState != 0)
                    {
                        ListViewSelectionChanged(Info, pnmv);
                        SetMenuAndButtonStates(Info);
                    }
                }
                break;

                case TTN_GETDISPINFO:
                {
                    LPTOOLTIPTEXT lpttt;
                    UINT idButton;

                    lpttt = (LPTOOLTIPTEXT)lParam;

                    /* Specify the resource identifier of the descriptive
                     * text for the given button. */
                    idButton = (UINT)lpttt->hdr.idFrom;
                    switch (idButton)
                    {
                        case ID_PROP:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
                        break;

                        case ID_REFRESH:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
                        break;

                        case ID_EXPORT:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT);
                        break;

                        case ID_CREATE:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_CREATE);
                        break;

                        case ID_DELETE:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DELETE);
                        break;

                        case ID_START:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START);
                        break;

                        case ID_STOP:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
                        break;

                        case ID_PAUSE:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE);
                        break;

                        case ID_RESTART:
                            lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);
                        break;
                    }
                }
                break;
            }
        }
        break;

        case WM_CONTEXTMENU:
            {
                POINT pt;
                RECT lvRect;

                INT xPos = GET_X_LPARAM(lParam);
                INT yPos = GET_Y_LPARAM(lParam);

                GetCursorPos(&pt);

                /* display popup when cursor is in the list view */
                GetWindowRect(Info->hListView, &lvRect);
                if (PtInRect(&lvRect, pt))
                {
                    TrackPopupMenuEx(GetSubMenu(Info->hShortcutMenu, 0),
                                     TPM_RIGHTBUTTON,
                                     xPos,
                                     yPos,
                                     Info->hMainWnd,
                                     NULL);
                }
            }
        break;

        case WM_COMMAND:
        {
            MainWndCommand(Info,
                           LOWORD(wParam),
                           (HWND)lParam);
            goto HandleDefaultMessage;
        }

        case WM_MENUSELECT:
        {
            if (Info->hStatus != NULL)
            {
                if (!MainWndMenuHint(Info,
                                     LOWORD(wParam),
                                     MainMenuHintTable,
                                     sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]),
                                     IDS_HINT_BLANK))
                {
                    MainWndMenuHint(Info,
                                    LOWORD(wParam),
                                    SystemMenuHintTable,
                                    sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]),
                                    IDS_HINT_BLANK);
                }
            }
        }
        break;

        case WM_ENTERMENULOOP:
        {
            Info->bInMenuLoop = TRUE;
            UpdateMainStatusBar(Info);
            break;
        }

        case WM_EXITMENULOOP:
        {
            Info->bInMenuLoop = FALSE;
            UpdateMainStatusBar(Info);
            break;
        }

        case WM_CLOSE:
        {
            HeapFree(ProcessHeap,
                     0,
                     Info->pAllServices);

            DestroyMenu(Info->hShortcutMenu);
            DestroyWindow(hwnd);
        }
        break;

        case WM_DESTROY:
        {
            HeapFree(ProcessHeap,
                     0,
                     Info);
            SetWindowLongPtr(hwnd,
                             GWLP_USERDATA,
                             0);

            PostQuitMessage(0);
        }
        break;

        default:
        {
HandleDefaultMessage:

            Ret = DefWindowProc(hwnd,
                                msg,
                                wParam,
                                lParam);
        }
        break;
    }

    return Ret;
}
Ejemplo n.º 4
0
/* Message handler for dialog box. */
INT_PTR CALLBACK
TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
#if 0
    HDC              hdc;
    PAINTSTRUCT      ps;
    RECT             rc;
#endif
    LPRECT           pRC;
    LPNMHDR          pnmh;
    WINDOWPLACEMENT  wp;

    switch (message) {
    case WM_INITDIALOG:
        hMainWnd = hDlg;
        return OnCreate(hDlg);

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
            EndDialog(hDlg, LOWORD(wParam));
            return TRUE;
        }
        /* Process menu commands */
        switch (LOWORD(wParam))
        {
        case ID_FILE_NEW:
            TaskManager_OnFileNew();
            break;
        case ID_OPTIONS_ALWAYSONTOP:
            TaskManager_OnOptionsAlwaysOnTop();
            break;
        case ID_OPTIONS_MINIMIZEONUSE:
            TaskManager_OnOptionsMinimizeOnUse();
            break;
        case ID_OPTIONS_HIDEWHENMINIMIZED:
            TaskManager_OnOptionsHideWhenMinimized();
            break;
        case ID_OPTIONS_SHOW16BITTASKS:
            TaskManager_OnOptionsShow16BitTasks();
            break;
        case ID_RESTORE:
            TaskManager_OnRestoreMainWindow();
            break;
        case ID_VIEW_LARGE:
        case ID_VIEW_SMALL:
        case ID_VIEW_DETAILS:
            ApplicationPage_OnView(LOWORD(wParam));
            break;
        case ID_VIEW_SHOWKERNELTIMES:
            PerformancePage_OnViewShowKernelTimes();
            break;
        case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
            PerformancePage_OnViewCPUHistoryOneGraphAll();
            break;
        case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
            PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
            break;
        case ID_VIEW_UPDATESPEED_HIGH:
        case ID_VIEW_UPDATESPEED_NORMAL:
        case ID_VIEW_UPDATESPEED_LOW:
        case ID_VIEW_UPDATESPEED_PAUSED:
            TaskManager_OnViewUpdateSpeed(LOWORD(wParam));
            break;
        case ID_VIEW_SELECTCOLUMNS:
            ProcessPage_OnViewSelectColumns();
            break;
        case ID_VIEW_REFRESH:
            PostMessageW(hDlg, WM_TIMER, 0, 0);
            break;
        case ID_WINDOWS_TILEHORIZONTALLY:
            ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL);
            break;
        case ID_WINDOWS_TILEVERTICALLY:
            ApplicationPage_OnWindowsTile(MDITILE_VERTICAL);
            break;
        case ID_WINDOWS_MINIMIZE:
            ApplicationPage_OnWindowsMinimize();
            break;
        case ID_WINDOWS_MAXIMIZE:
            ApplicationPage_OnWindowsMaximize();
            break;
        case ID_WINDOWS_CASCADE:
            ApplicationPage_OnWindowsCascade();
            break;
        case ID_WINDOWS_BRINGTOFRONT:
            ApplicationPage_OnWindowsBringToFront();
            break;
        case ID_APPLICATION_PAGE_SWITCHTO:
            ApplicationPage_OnSwitchTo();
            break;
        case ID_APPLICATION_PAGE_ENDTASK:
            ApplicationPage_OnEndTask();
            break;
        case ID_APPLICATION_PAGE_GOTOPROCESS:
            ApplicationPage_OnGotoProcess();
            break;
        case ID_PROCESS_PAGE_ENDPROCESS:
            ProcessPage_OnEndProcess();
            break;
        case ID_PROCESS_PAGE_ENDPROCESSTREE:
            ProcessPage_OnEndProcessTree();
            break;
        case ID_PROCESS_PAGE_DEBUG:
            ProcessPage_OnDebug();
            break;
        case ID_PROCESS_PAGE_SETAFFINITY:
            ProcessPage_OnSetAffinity();
            break;
        case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
            DoSetPriority(REALTIME_PRIORITY_CLASS);
            break;
        case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
            DoSetPriority(HIGH_PRIORITY_CLASS);
            break;
        case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
            DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS);
            break;
        case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
            DoSetPriority(NORMAL_PRIORITY_CLASS);
            break;
        case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
            DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS);
            break;
        case ID_PROCESS_PAGE_SETPRIORITY_LOW:
            DoSetPriority(IDLE_PRIORITY_CLASS);
            break;
        case ID_PROCESS_PAGE_DEBUGCHANNELS:
            ProcessPage_OnDebugChannels();
            break;
        case ID_HELP_ABOUT:
            OnAbout();
            break;
        case ID_FILE_EXIT:
            EndDialog(hDlg, IDOK);
            break;
        }
        break;

    case WM_ONTRAYICON:
        switch(lParam)
        {
        case WM_RBUTTONDOWN:
            {
            POINT pt;
            BOOL OnTop;
            HMENU hMenu, hPopupMenu;

            GetCursorPos(&pt);

            OnTop = ((GetWindowLongPtrW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);

            hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP));
            hPopupMenu = GetSubMenu(hMenu, 0);

            if(IsWindowVisible(hMainWnd))
            {
              DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
            }
            else
            {
              SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
            }

            if(OnTop)
            {
              CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
            } else
            {
              CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_UNCHECKED);
            }

            SetForegroundWindow(hMainWnd);
            TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);

            DestroyMenu(hMenu);
            break;
            }
        case WM_LBUTTONDBLCLK:
            TaskManager_OnRestoreMainWindow();
            break;
        }
        break;

    case WM_NOTIFY:
        pnmh = (LPNMHDR)lParam;
        if ((pnmh->hwndFrom == hTabWnd) &&
            (pnmh->idFrom == IDC_TAB) &&
            (pnmh->code == TCN_SELCHANGE))
        {
            TaskManager_OnTabWndSelChange();
        }
        break;
#if 0
    case WM_NCPAINT:
        hdc = GetDC(hDlg);
        GetClientRect(hDlg, &rc);
        Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
        ReleaseDC(hDlg, hdc);
        break;

    case WM_PAINT:
        hdc = BeginPaint(hDlg, &ps);
        GetClientRect(hDlg, &rc);
        Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
        EndPaint(hDlg, &ps);
        break;
#endif
    case WM_SIZING:
        /* Make sure the user is sizing the dialog */
        /* in an acceptable range */
        pRC = (LPRECT)lParam;
        if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
            /* If the width is too small enlarge it to the minimum */
            if (nMinimumWidth > (pRC->right - pRC->left))
                pRC->left = pRC->right - nMinimumWidth;
        } else {
            /* If the width is too small enlarge it to the minimum */
            if (nMinimumWidth > (pRC->right - pRC->left))
                pRC->right = pRC->left + nMinimumWidth;
        }
        if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
            /* If the height is too small enlarge it to the minimum */
            if (nMinimumHeight > (pRC->bottom - pRC->top))
                pRC->top = pRC->bottom - nMinimumHeight;
        } else {
            /* If the height is too small enlarge it to the minimum */
            if (nMinimumHeight > (pRC->bottom - pRC->top))
                pRC->bottom = pRC->top + nMinimumHeight;
        }
        return TRUE;
        break;

    case WM_SIZE:
        /* Handle the window sizing in it's own function */
        OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
        break;

    case WM_MOVE:
        /* Handle the window moving in it's own function */
        OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
        break;

    case WM_DESTROY:
        ShowWindow(hDlg, SW_HIDE);
        TrayIcon_ShellRemoveTrayIcon();
        wp.length = sizeof(WINDOWPLACEMENT);
        GetWindowPlacement(hDlg, &wp);
        TaskManagerSettings.Left = wp.rcNormalPosition.left;
        TaskManagerSettings.Top = wp.rcNormalPosition.top;
        TaskManagerSettings.Right = wp.rcNormalPosition.right;
        TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
        if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
            TaskManagerSettings.Maximized = TRUE;
        else
            TaskManagerSettings.Maximized = FALSE;
        return DefWindowProcW(hDlg, message, wParam, lParam);

    case WM_TIMER:
        /* Refresh the performance data */
        PerfDataRefresh();
        RefreshApplicationPage();
        RefreshProcessPage();
        RefreshPerformancePage();
        TrayIcon_ShellUpdateTrayIcon();
        break;

    case WM_ENTERMENULOOP:
        TaskManager_OnEnterMenuLoop(hDlg);
        break;
    case WM_EXITMENULOOP:
        TaskManager_OnExitMenuLoop(hDlg);
        break;
    case WM_MENUSELECT:
        TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
        break;
    case WM_SYSCOLORCHANGE:
        /* Forward WM_SYSCOLORCHANGE to common controls */
        SendMessage(hApplicationPageListCtrl, WM_SYSCOLORCHANGE, 0, 0);
        SendMessage(hProcessPageListCtrl, WM_SYSCOLORCHANGE, 0, 0);
        SendMessage(hProcessPageHeaderCtrl, WM_SYSCOLORCHANGE, 0, 0);
        break;
    }

    return 0;
}
Ejemplo n.º 5
0
/*
** Opens the context menu in given coordinates.
*/
void ContextMenu::ShowMenu(POINT pos, MeterWindow* meterWindow)
{
	static const MenuTemplate s_Menu[] =
	{
		MENU_ITEM(IDM_MANAGE, ID_STR_MANAGE),
		MENU_ITEM(IDM_ABOUT, ID_STR_ABOUT),
		MENU_ITEM(IDM_SHOW_HELP, ID_STR_HELP),
		MENU_SEPARATOR(),
		MENU_SUBMENU(ID_STR_SKINS,
			MENU_ITEM_GRAYED(0, ID_STR_NOSKINS),
			MENU_SEPARATOR(),
			MENU_ITEM(IDM_OPENSKINSFOLDER, ID_STR_OPENFOLDER),
			MENU_ITEM(IDM_DISABLEDRAG, ID_STR_DISABLEDRAGGING)),
		MENU_SUBMENU(ID_STR_THEMES,
			MENU_ITEM_GRAYED(0, ID_STR_NOTHEMES)),
		MENU_SEPARATOR(),
		MENU_ITEM(IDM_EDITCONFIG, ID_STR_EDITSETTINGS),
		MENU_ITEM(IDM_REFRESH, ID_STR_REFRESHALL),
		MENU_SEPARATOR(),
		MENU_SUBMENU(ID_STR_LOGGING,
			MENU_ITEM(IDM_SHOWLOGFILE, ID_STR_SHOWLOGFILE),
			MENU_SEPARATOR(),
			MENU_ITEM(IDM_STARTLOG, ID_STR_STARTLOGGING),
			MENU_ITEM(IDM_STOPLOG, ID_STR_STOPLOGGING),
			MENU_SEPARATOR(),
			MENU_ITEM(IDM_DELETELOGFILE, ID_STR_DELETELOGFILE),
			MENU_ITEM(IDM_DEBUGLOG, ID_STR_DEBUGMODE)),
		MENU_SEPARATOR(),
		MENU_ITEM(IDM_QUIT, ID_STR_EXIT)
	};

	if (m_MenuActive || (meterWindow && meterWindow->IsClosing())) return;

	// Show context menu, if no actions were executed
	HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
	if (!menu) return;

	m_MenuActive = true;
	Rainmeter& rainmeter = GetRainmeter();

	SetMenuDefaultItem(menu, IDM_MANAGE, MF_BYCOMMAND);

	if (_waccess(GetLogger().GetLogFilePath().c_str(), 0) == -1)
	{
		EnableMenuItem(menu, IDM_SHOWLOGFILE, MF_BYCOMMAND | MF_GRAYED);
		EnableMenuItem(menu, IDM_DELETELOGFILE, MF_BYCOMMAND | MF_GRAYED);
		EnableMenuItem(menu, IDM_STOPLOG, MF_BYCOMMAND | MF_GRAYED);
	}
	else
	{
		EnableMenuItem(
			menu,
			(GetLogger().IsLogToFile()) ? IDM_STARTLOG : IDM_STOPLOG,
			MF_BYCOMMAND | MF_GRAYED);
	}

	if (rainmeter.m_Debug)
	{
		CheckMenuItem(menu, IDM_DEBUGLOG, MF_BYCOMMAND | MF_CHECKED);
	}

	HMENU allSkinsMenu = GetSubMenu(menu, 4);
	if (allSkinsMenu)
	{
		if (!rainmeter.m_SkinRegistry.IsEmpty())
		{
			DeleteMenu(allSkinsMenu, 0, MF_BYPOSITION);  // "No skins available" menuitem
			CreateAllSkinsMenu(allSkinsMenu);
		}

		if (rainmeter.m_DisableDragging)
		{
			CheckMenuItem(allSkinsMenu, IDM_DISABLEDRAG, MF_BYCOMMAND | MF_CHECKED);
		}
	}

	HMENU layoutMenu = GetSubMenu(menu, 5);
	if (layoutMenu)
	{
		if (!rainmeter.m_Layouts.empty())
		{
			DeleteMenu(layoutMenu, 0, MF_BYPOSITION);  // "No layouts available" menuitem
			CreateLayoutMenu(layoutMenu);
		}
	}

	if (meterWindow)
	{
		HMENU rainmeterMenu = menu;
		menu = CreateSkinMenu(meterWindow, 0, allSkinsMenu);

		InsertMenu(menu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)rainmeterMenu, L"Rainmeter");
		InsertMenu(menu, IDM_CLOSESKIN, MF_BYCOMMAND | MF_SEPARATOR, 0, nullptr);
	}
	else
	{
		InsertMenu(menu, 12, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);

		// Create a menu for all active skins
		int index = 0;
		std::map<std::wstring, MeterWindow*>::const_iterator iter = rainmeter.m_MeterWindows.begin();
		for (; iter != rainmeter.m_MeterWindows.end(); ++iter)
		{
			MeterWindow* mw = ((*iter).second);
			HMENU skinMenu = CreateSkinMenu(mw, index, allSkinsMenu);
			InsertMenu(menu, 12, MF_BYPOSITION | MF_POPUP, (UINT_PTR)skinMenu, mw->GetFolderPath().c_str());
			++index;
		}

		// Add update notification item
		if (rainmeter.m_NewVersion)
		{
			InsertMenu(menu, 0, MF_BYPOSITION, IDM_NEW_VERSION, GetString(ID_STR_UPDATEAVAILABLE));
			HiliteMenuItem(rainmeter.GetTrayWindow()->GetWindow(), menu, 0, MF_BYPOSITION | MF_HILITE);
			InsertMenu(menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);
		}
	}

	HWND hWnd = WindowFromPoint(pos);
	if (hWnd != nullptr)
	{
		MeterWindow* mw = rainmeter.GetMeterWindow(hWnd);
		if (mw)
		{
			// Cancel the mouse event beforehand
			mw->SetMouseLeaveEvent(true);
		}
	}

	// Set the window to foreground
	hWnd = meterWindow ? meterWindow->GetWindow() : rainmeter.m_TrayWindow->GetWindow();
	HWND hWndForeground = GetForegroundWindow();
	if (hWndForeground != hWnd)
	{
		const DWORD foregroundThreadID = GetWindowThreadProcessId(hWndForeground, nullptr);
		const DWORD currentThreadID = GetCurrentThreadId();
		AttachThreadInput(currentThreadID, foregroundThreadID, TRUE);
		SetForegroundWindow(hWnd);
		AttachThreadInput(currentThreadID, foregroundThreadID, FALSE);
	}

	// Show context menu
	TrackPopupMenu(
		menu,
		TPM_RIGHTBUTTON | TPM_LEFTALIGN | (*GetString(ID_STR_ISRTL) == L'1' ? TPM_LAYOUTRTL : 0),
		pos.x,
		pos.y,
		0,
		hWnd,
		nullptr);

	DestroyMenu(menu);

	m_MenuActive = false;
}
Ejemplo n.º 6
0
LRESULT CALLBACK ContactListSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	TVITEM tvi;
	CCList *dat = CWndUserData(GetParent(hWnd)).GetCList();

	switch (Msg) {
	case INTM_CONTACTDELETED: // wParam = (HANDLE)hContact
		{
			HTREEITEM hItem = dat->FindContact(wParam);
			if (hItem)
				TreeView_DeleteItem(hWnd, hItem);
		}
		break;

	case INTM_ICONCHANGED: // wParam = (HANDLE)hContact, lParam = IconID
		tvi.hItem = dat->FindContact(wParam);
		if (tvi.hItem) {
			tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
			tvi.iImage = tvi.iSelectedImage = lParam;
			TreeView_SetItem(hWnd, &tvi);
			dat->SortContacts();
			InvalidateRect(hWnd, NULL, false);
		}
		break;

	case INTM_INVALIDATE:
		InvalidateRect(hWnd, NULL, true);
		break;

	case WM_RBUTTONDOWN:
		SetFocus(hWnd);
		{
			TVHITTESTINFO hitTest;
			hitTest.pt.x = (short)LOWORD(lParam);
			hitTest.pt.y = (short)HIWORD(lParam);
			TreeView_HitTest(hWnd, &hitTest);
			if (hitTest.hItem && hitTest.flags & TVHT_ONITEM)
				TreeView_SelectItem(hWnd, hitTest.hItem);
		}
		return DefWindowProc(hWnd, Msg, wParam, lParam);

	case WM_LBUTTONDOWN:
		{
			POINT pt = { (short)LOWORD(lParam), (short)HIWORD(lParam) };
			DWORD hitFlags;
			HTREEITEM hItem = dat->HitTest(&pt, &hitFlags);
			if (!hItem)
				break;

			if (hitFlags & MCLCHT_ONITEMICON) {
				if (TreeView_GetChild(hWnd, hItem)) { // if it's a group, then toggle its state
					NMTREEVIEW nmtv;
					nmtv.hdr.hwndFrom = hWnd;
					nmtv.hdr.idFrom = GetDlgCtrlID(hWnd);
					nmtv.hdr.code = TVN_ITEMEXPANDING;
					nmtv.action = TVE_TOGGLE;
					nmtv.itemNew.hItem = hItem;
					nmtv.itemNew.mask = TVIF_HANDLE | TVIF_STATE | TVIF_PARAM;
					TreeView_GetItem(hWnd, &nmtv.itemNew);
					nmtv.ptDrag = pt;
					if (SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nmtv))
						return 0;

					HTREEITEM hOldSelItem = TreeView_GetSelection(hWnd);
					TreeView_Expand(hWnd, hItem, TVE_TOGGLE);
					HTREEITEM hNewSelItem = TreeView_GetSelection(hWnd);
					if (hNewSelItem != hOldSelItem) {
						TreeView_SetItemState(hWnd, hOldSelItem, (dat->SelectedItems.Find(hOldSelItem) == -1) ? 0 : TVIS_SELECTED, TVIS_SELECTED);
						TreeView_SetItemState(hWnd, hNewSelItem, (dat->SelectedItems.Find(hNewSelItem) == -1) ? 0 : TVIS_SELECTED, TVIS_SELECTED);
					}
					nmtv.hdr.code = TVN_ITEMEXPANDED;
					TreeView_GetItem(hWnd, &nmtv.itemNew);
					SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nmtv);
					return 0;
				}
			}
			if (hitFlags & MCLCHT_ONITEM) {
				if (wParam & MK_CONTROL) {
					SetFocus(hWnd);
					TREEITEMARRAY OldSelection = dat->SelectedItems;
					int nIndex = dat->SelectedItems.Find(hItem);
					if (nIndex == -1) {
						TreeView_SetItemState(hWnd, hItem, TVIS_SELECTED, TVIS_SELECTED);
						dat->SelectedItems.AddElem(hItem);
					}
					else {
						TreeView_SetItemState(hWnd, hItem, 0, TVIS_SELECTED);
						dat->SelectedItems.RemoveElem(nIndex);
					}
					dat->SelectGroups(hItem, nIndex == -1);
					NMCLIST nm;
					nm.hdr.code = MCLN_SELCHANGED;
					nm.hdr.hwndFrom = hWnd;
					nm.hdr.idFrom = GetDlgCtrlID(hWnd);
					nm.OldSelection = &OldSelection;
					nm.NewSelection = &dat->SelectedItems;
					SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nm);
					return 0;
				}
				// if it was a click on the selected item and there's need to do something in this case, then send SELCHANGED notification by ourselves, as the tree control doesn't do anything
				if (hItem == TreeView_GetSelection(hWnd) && (dat->SelectedItems.GetSize() != 1 || (dat->SelectedItems.GetSize() == 1 && dat->SelectedItems[0] != hItem))) {
					TreeView_SetItemState(hWnd, hItem, TVIS_SELECTED, TVIS_SELECTED);
					NMTREEVIEW nm = { 0 };
					nm.hdr.code = TVN_SELCHANGED;
					nm.hdr.hwndFrom = hWnd;
					nm.hdr.idFrom = GetDlgCtrlID(hWnd);
					nm.itemOld.hItem = TreeView_GetSelection(hWnd);
					nm.itemOld.mask = TVIF_HANDLE | TVIF_STATE | TVIF_PARAM;
					TreeView_GetItem(hWnd, &nm.itemOld);
					nm.itemNew = nm.itemOld;
					SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nm);
				}
			}
		}
		break;

	case WM_SETFOCUS:
	case WM_KILLFOCUS:
		for (int i = 0; i < dat->SelectedItems.GetSize(); i++) {
			RECT rc;
			if (TreeView_GetItemRect(hWnd, dat->SelectedItems[i], &rc, false))
				InvalidateRect(hWnd, &rc, false);
		}
		break;

	case WM_SIZE:
	case WM_HSCROLL:
		InvalidateRect(hWnd, NULL, false);
		break;

	case WM_MEASUREITEM:
		if (!wParam) // if the message was sent by a menu
			return Menu_MeasureItem((LPMEASUREITEMSTRUCT)lParam);
		break;

	case WM_DRAWITEM:
		if (!wParam) // if the message was sent by a menu
			return Menu_DrawItem((LPDRAWITEMSTRUCT)lParam);
		break;

	case WM_CONTEXTMENU:
		{
			POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
			HTREEITEM hItem = NULL;
			if (pt.x == -1 && pt.y == -1) {
				if (dat->SelectedItems.GetSize() == 1) {
					hItem = dat->SelectedItems[0];
					TreeView_EnsureVisible(hWnd, hItem);
					RECT rc;
					TreeView_GetItemRect(hWnd, hItem, &rc, true);
					pt.x = rc.left;
					pt.y = rc.bottom;
				}
			}
			else {
				DWORD hitFlags;
				ScreenToClient(hWnd, &pt);
				hItem = dat->HitTest(&pt, &hitFlags);
				if (!(hitFlags & MCLCHT_ONITEM))
					hItem = NULL;
			}
			if (hItem) {
				MCONTACT hContact = dat->GetItemData(hItem).hContact;
				if (IsHContactContact(hContact)) {
					HMENU hMenu = Menu_BuildContactMenu(hContact);
					if (hMenu) {
						ClientToScreen(hWnd, &pt);
						CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL), MPCF_CONTACTMENU), hContact);
						DestroyMenu(hMenu);
						return 0;
					}
				}
			}
		}
		break;

	case WM_DESTROY:
		if (dat->ExtraImageList)
			ImageList_Destroy(dat->ExtraImageList);
		dat->SelectedItems.RemoveAll();
		dat->Items.RemoveAll();
		break;
	}
	return CallWindowProc(dat->OrigTreeViewProc, hWnd, Msg, wParam, lParam);
}
Ejemplo n.º 7
0
void PopupMenu( intf_thread_t *p_intf, HWND p_parent, POINT point )
{
#define MAX_POPUP_ITEMS 45

    vlc_object_t *p_object, *p_input;
    char *ppsz_varnames[MAX_POPUP_ITEMS];
    vlc_object_t * pi_objects[MAX_POPUP_ITEMS];
    int i = 0, i_last_separator = 0;

    /* Initializations */
    memset( pi_objects, 0, MAX_POPUP_ITEMS * sizeof(vlc_object_t *) );

    ppsz_varnames[i] = "VLC media player";
    pi_objects[i++] = 0;
    ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator = i;

    /* Input menu */
    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
        ppsz_varnames[i] = "bookmark";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "title";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "chapter";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "program";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "navigation";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "dvd_menus";
        pi_objects[i++] = p_object;

        ppsz_varnames[i] = "video-es";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "audio-es";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "spu-es";
        pi_objects[i++] = p_object;
    }
    p_input = p_object;
    if( !p_input ) goto interfacemenu;

    /* Video menu */
    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator = i;

    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
        vlc_object_t *p_dec_obj;

        ppsz_varnames[i] = "fullscreen";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "zoom";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "deinterlace-mode";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "aspect-ratio";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "crop";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "video-on-top";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "directx-wallpaper";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "video-snapshot";
        pi_objects[i++] = p_object;

        p_dec_obj = (vlc_object_t *)vlc_object_find( p_object,
                                                     VLC_OBJECT_DECODER,
                                                     FIND_PARENT );
        if( p_dec_obj != NULL )
        {
            ppsz_varnames[i] = "ffmpeg-pp-q";
            pi_objects[i++] = p_dec_obj;
            vlc_object_release( p_dec_obj );
        }

        vlc_object_release( p_object );
    }

    /* Audio menu */
    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator  = i;

    p_object = (vlc_object_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
                                                FIND_ANYWHERE );
    if( p_object != NULL )
    {
        ppsz_varnames[i] = "audio-device";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "audio-channels";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "visual";
        pi_objects[i++] = p_object;
        ppsz_varnames[i] = "equalizer";
        pi_objects[i++] = p_object;
        vlc_object_release( p_object );
    }

 interfacemenu:
    /* Interface menu */
    if( i != i_last_separator ) ppsz_varnames[i++] = NULL; /* Separator */
    i_last_separator = i;


    /* Build menu */
    vector<MenuItemExt*> popup_menu;
    HMENU hmenu = CreatePopupMenu();
    RefreshMenu( p_intf, &popup_menu, hmenu, i,
                 ppsz_varnames, pi_objects, PopupMenu_Events );
    MenuItemExt::ClearList( &popup_menu );


    /* Add static entries */
    if( p_input != NULL )
    {
        vlc_value_t val;
        AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
        AppendMenu( hmenu, MF_STRING, StopStream_Event, _T("Stop") );
        AppendMenu( hmenu, MF_STRING, PrevStream_Event, _T("Previous") );
        AppendMenu( hmenu, MF_STRING, NextStream_Event, _T("Next") );

        var_Get( p_input, "state", &val );
        if( val.i_int == PAUSE_S )
            AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
        else
            AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Pause") );

        vlc_object_release( p_input );
    }
    else
    {
        playlist_t * p_playlist = pl_Hold( p_intf );
        if( p_playlist && !playlist_IsEmpty( p_playlist ) )
        {
            AppendMenu( hmenu, MF_SEPARATOR, 0, _T("") );
            AppendMenu( hmenu, MF_STRING, PlayStream_Event, _T("Play") );
        }
        if( p_playlist ) pl_Release( p_intf );
    }

    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)MiscMenu( p_intf ),
                _T("Miscellaneous") );
    AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT)OpenStreamMenu( p_intf ),
                _T("Open") );

    TrackPopupMenu( hmenu, 0, point.x, point.y, 0, p_parent, 0 );
    PostMessage( p_parent, WM_NULL, 0, 0 );
    DestroyMenu( hmenu );
}
Ejemplo n.º 8
0
/**
 * name:	CtrlContactWndProc
 * desc:	window procedure for the extended combobox class
 * param:	hwnd	- handle to a extended combobox window
 *			msg		- message to handle
 *			wParam	- message specific
 *			lParam	- message specific
 * return:	message specific
 **/
static LRESULT CALLBACK CtrlContactWndProc(HWND hwnd, UINT msg,	WPARAM wParam, LPARAM lParam) 
{
	LPCBEX	cbex = (LPCBEX)GetWindowLongPtr(hwnd, 0);

	switch (msg) {

	/**
	* name:	WM_NCCREATE
	* desc:	is called to initiate the window creation
	* param:	wParam - not used
	*			lParam - pointer to a CREATESTRUCT
	*
	* return:	FALSE on error, TRUE if initialisation was ok
	**/
	case WM_NCCREATE:
	{
		LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam;

		if (!(cbex = (LPCBEX)mir_calloc(1*sizeof(CBEX))))
			return FALSE;
		SetWindowLongPtr(hwnd, 0, (LONG_PTR)cbex);
		cbex->bLocked = 1;
		cbex->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
		cbex->hInstance = cs->hInstance;
		cbex->iSelectedItem = -1;
		cbex->rect.left = cs->x;
		cbex->rect.top = cs->y;
		cbex->rect.right = cs->x + cs->cx;
		cbex->rect.bottom = cs->y + cs->cy;
		return TRUE;
	}

	/**
		* name:	WM_NCCREATE
		* desc:	is called to create all subitems
		* param:	wParam - not used
		*			lParam - not used
		*
		* return:	FALSE on error, TRUE if initialisation was ok
		**/
	case WM_CREATE:
	{
		WORD wHeight = (WORD)(cbex->rect.bottom - cbex->rect.top);
		WORD wWidth = 130;
		WORD x = 0;

		if (!(cbex->hBtnEdit = CreateWindowEx(WS_EX_NOPARENTNOTIFY,
				UINFOBUTTONCLASS, 
				_T("none"),
				WS_VISIBLE|WS_CHILD|WS_TABSTOP, 0, 0,
				wWidth, wHeight,
				hwnd,
				NULL,
				cbex->hInstance, NULL))) {
			cbex->bLocked = 0;
			return FALSE;
		}
		x += wWidth + 2;
		wWidth = wHeight;
		if (!(cbex->hBtnMenu = CreateWindowEx(WS_EX_NOPARENTNOTIFY,
				UINFOBUTTONCLASS,
				NULL,
				WS_VISIBLE|WS_CHILD|WS_TABSTOP|MBS_PUSHBUTTON|MBS_DOWNARROW,
				x, 0,
				wWidth, wHeight,
				hwnd,
				NULL,
				cbex->hInstance, NULL))) {
			DestroyWindow(cbex->hBtnEdit);
			cbex->bLocked = 0;
			return FALSE;
		}
		x += wWidth + 2;
		wWidth = (WORD)(cbex->rect.right - cbex->rect.left - x - (2 * (wHeight + 2)));
		if (!(cbex->hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
				_T("Edit"), 
				NULL,
				WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL,
				x, 1,
				wWidth,	wHeight - 2,
				hwnd,
				NULL,
				cbex->hInstance, NULL))) {
			DestroyWindow(cbex->hBtnEdit);
			DestroyWindow(cbex->hBtnMenu);
			cbex->bLocked = 0;
			return FALSE;
		}
		x += wWidth + 2;
		wWidth = wHeight;
		if (!(cbex->hBtnAdd = CreateWindowEx(WS_EX_NOPARENTNOTIFY,
				UINFOBUTTONCLASS,
				NULL,
				WS_VISIBLE|WS_CHILD|WS_TABSTOP|MBS_FLAT,
				x, 0,
				wWidth, wHeight,
				hwnd,
				NULL,
				cbex->hInstance, NULL))) {
			DestroyWindow(cbex->hBtnEdit);
			DestroyWindow(cbex->hBtnMenu);
			DestroyWindow(cbex->hEdit);
			cbex->bLocked = 0;
			return FALSE;
		}
		x += wWidth + 2;
		if (!(cbex->hBtnDel = CreateWindowEx(WS_EX_NOPARENTNOTIFY,
				UINFOBUTTONCLASS,
				NULL,
				WS_VISIBLE|WS_CHILD|WS_TABSTOP|MBS_FLAT,
				x, 0,
				wWidth, wHeight,
				hwnd,
				NULL,
				cbex->hInstance, NULL))) {
			DestroyWindow(cbex->hBtnEdit);
			DestroyWindow(cbex->hBtnMenu);
			DestroyWindow(cbex->hEdit);
			DestroyWindow(cbex->hBtnAdd);
			cbex->bLocked = 0;
			return FALSE;
		}

		// set ids
		SetWindowLongPtr(cbex->hBtnEdit, GWLP_ID, BTN_EDIT);
		SetWindowLongPtr(cbex->hBtnMenu, GWLP_ID, BTN_MENU);
		SetWindowLongPtr(cbex->hEdit, GWLP_ID, EDIT_VALUE);
		SetWindowLongPtr(cbex->hBtnAdd, GWLP_ID, BTN_ADD);
		SetWindowLongPtr(cbex->hBtnDel, GWLP_ID, BTN_DEL);
		// set fonts & maximum edit control charachters
		SendMessage(cbex->hEdit, WM_SETFONT, (WPARAM)cbex->hFont, NULL);
		SendMessage(cbex->hEdit, EM_LIMITTEXT, (WPARAM)MAXDATASIZE, NULL);
		// add tooltips
		SendMessage(cbex->hBtnMenu, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Choose the item to display"), MBBF_TCHAR);
		SendMessage(cbex->hBtnEdit, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Edit the currently displayed item"), MBBF_TCHAR);
		SendMessage(cbex->hBtnAdd, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Add a new custom item"), MBBF_TCHAR);
		SendMessage(cbex->hBtnDel, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete the selected item"), MBBF_TCHAR);
		// reload icons
		CtrlContactWndProc(hwnd, WM_SETICON, NULL, NULL);
		cbex->bLocked = 0;
		return TRUE;
	}

	/**
		* name:	WM_DESTROY
		* desc:	default destroy message, so clear up memory
		* param:	wParam - not used
		*			lParam - not used
		* return:	return value of DefWindowProc
		**/
	case WM_DESTROY:
		CtrlContactWndProc(hwnd, CBEXM_DELALLITEMS, NULL, NULL);
		DestroyWindow(cbex->hBtnEdit);
		DestroyWindow(cbex->hBtnMenu);
		DestroyWindow(cbex->hBtnAdd);
		DestroyWindow(cbex->hBtnDel);
		DestroyWindow(cbex->hEdit);
		MIR_FREE(cbex);
		break;

	/**
		* name:	WM_CTLCOLOREDIT
		* desc:	is called on a paint message for a dialog item to determine its colour scheme
		* param:	wParam - pointer to a HDC
		*			lParam - pointer to a HWND
		* return:	a brush
		**/
	case WM_CTLCOLOREDIT:
		if (!db_get_b(NULL, MODNAME, SET_PROPSHEET_SHOWCOLOURS, 1) || (HWND)lParam != cbex->hEdit || !cbex->pItems || cbex->iSelectedItem < 0) 
			break;
		return Ctrl_SetTextColour((HDC)wParam, cbex->pItems[cbex->iSelectedItem].wFlags);

	case WM_CTLCOLORSTATIC:
		if ((HWND)lParam == cbex->hEdit)
			return (INT_PTR)GetSysColor(COLOR_WINDOW);
		return FALSE;
	/**
		* name:	WM_SETICON
		* desc:	updates the icons of this control
		* param:	wParam - not used
		*			lParam - not used
		* return:	always 0
		**/
	case WM_SETICON:
	{
		HICON hIcon = IcoLib_GetIcon(ICO_BTN_ADD);
		SendMessage(cbex->hBtnAdd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
		SetWindowText(cbex->hBtnAdd, (hIcon ? _T("") : _T("+")));

		hIcon = IcoLib_GetIcon(ICO_BTN_DELETE);
		SendMessage(cbex->hBtnDel, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
		SetWindowText(cbex->hBtnDel, (hIcon ? _T("") : _T("-")));

		if (cbex->pItems && cbex->numItems > 0) {
			for (int i = 0; i < cbex->numItems; i++)
				cbex->pItems[i].hIcon = IcoLib_GetIcon(cbex->pItems[i].pszIcon);

			if (cbex->iSelectedItem >= 0 && cbex->iSelectedItem < cbex->numItems)
				SendMessage(cbex->hBtnEdit, BM_SETIMAGE, IMAGE_ICON, (LPARAM)cbex->pItems[cbex->iSelectedItem].hIcon);
		}
		return 0;
	}

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		/**
		* name:	BTN_MENU
		* desc:	the button to dropdown the list to show all items is pressed
		**/
		case BTN_MENU:
			if (HIWORD(wParam) == BN_CLICKED) {
				POINT pt = { 0, 0 };
				RECT rc;
				int i, nItems;
				HMENU hMenu;

				if (!(hMenu = CreatePopupMenu())) return 0;
				SetFocus((HWND)lParam);

				MENUITEMINFO mii = { 0 };
				mii.cbSize = sizeof(mii);
				mii.fMask = MIIM_ID|MIIM_STRING|MIIM_FTYPE|MIIM_STATE;
				mii.fType = MFT_STRING;

				// insert the items
				for (i = nItems = 0; i < cbex->numItems; i++) {
					if ((cbex->pItems[i].wFlags & CBEXIF_DELETED) || *cbex->pItems[i].szCat == 0) continue;
					mii.fState = (cbex->pItems[i].pszVal && *cbex->pItems[i].pszVal) ? MFS_CHECKED : MFS_UNCHECKED;
					mii.wID = CBEXM_MENIITEMFIRST + i;
					mii.dwTypeData = cbex->pItems[i].szCat;
					if (!InsertMenuItem(hMenu, i, TRUE, &mii)) {
						DestroyMenu(hMenu);
						return 0;
					}
					nItems++;
				}
				// add separator between default and custom items
				if (nItems > 3) {
					mii.fMask = MIIM_FTYPE;
					mii.fType = MFT_SEPARATOR;
					mii.wID = 0;
					mii.dwItemData = 0;
					InsertMenuItem(hMenu, 3, TRUE, &mii);
				}
				ClientToScreen((HWND)lParam, &pt);
				GetClientRect((HWND)lParam, &rc);
				i = TrackPopupMenuEx(hMenu, TPM_RIGHTALIGN|TPM_RETURNCMD, pt.x + rc.right, pt.y + rc.bottom, hwnd, NULL);
				SendMessage(cbex->hBtnMenu, BM_SETCHECK, NULL, NULL);
				if (i >= CBEXM_MENIITEMFIRST && i < CBEXM_MENIITEMFIRST + cbex->numItems) {
					CtrlContactWndProc(hwnd, CBEXM_SETCURSEL, (WPARAM)i - CBEXM_MENIITEMFIRST, NULL);
				}
				DestroyMenu(hMenu);
				return 0;
			}
			break;

		/**
			* name:	BTN_ADD
			* desc:	the button to add a new entry is pressed
			**/
		case BTN_ADD:
			if (HIWORD(wParam) == BN_CLICKED) {
				DLGPROC dlgProc;
				WORD dlgID;
				TCHAR szCat[MAX_CAT] = { 0 };
				TCHAR szVal[MAXDATASIZE] = { 0 };
				CBEXITEM cbi;
				HWND hDlgDetails;

				SetFocus((HWND)lParam);
				if (!(hDlgDetails = GetParent(GetParent(hwnd)))) return 1;
				if (SendMessage(hDlgDetails, PSM_ISLOCKED, NULL, NULL)) return 0;
						
				switch (GetWindowLongPtr(hwnd, GWLP_ID)) {
					case EDIT_PHONE:
						dlgID = IDD_ADDPHONE;
						dlgProc = DlgProc_Phone;
						cbi.pszIcon = ICO_BTN_CUSTOMPHONE;
						break;
					case EDIT_EMAIL:
						dlgID = IDD_ADDEMAIL;
						dlgProc = DlgProc_EMail;
						cbi.pszIcon = ICO_BTN_EMAIL;
						break;
					default:
						return 1;
				}
							
				cbi.iItem = -1;
				cbi.wMask = CBEXIM_CAT|CBEXIM_VAL|CBEXIM_FLAGS|CBEXIM_ICONTEXT;
				cbi.pszCat = szCat;
				cbi.pszVal = szVal;
				cbi.ccCat = MAX_CAT;
				cbi.ccVal = MAXDATASIZE;
				cbi.wFlags = 0;
				cbi.dwID = 0;

				if (DialogBoxParam(ghInst, MAKEINTRESOURCE(dlgID), GetParent(hwnd), dlgProc, (LPARAM)&cbi) == IDOK) {
					MCONTACT hContact = NULL;
							
					SendMessage(hDlgDetails, PSM_GETCONTACT, NULL, (LPARAM)&hContact);
					if (hContact) cbi.wFlags |= CTRLF_HASCUSTOM;
					cbi.wFlags |= CTRLF_CHANGED;
					if (SendMessage(hwnd, CBEXM_ADDITEM, NULL, (LPARAM)&cbi) > CB_ERR) {
						SendMessage(hDlgDetails, PSM_CHANGED, NULL, NULL);
						cbex->bIsChanged = TRUE;
						SendMessage(hwnd, CBEXM_SETCURSEL, cbex->numItems - 1, NULL);
					}
				}
				return 0;
			}
			break;

		/**
			* name:	BTN_EDIT
			* desc:	the button to edit an existing entry is pressed
			**/
		case BTN_EDIT:
			if (HIWORD(wParam) == BN_CLICKED) {
				DLGPROC dlgProc;
				WORD dlgID;
				TCHAR szCat[MAX_CAT] = { 0 };
				TCHAR szVal[MAXDATASIZE] = { 0 };
				CBEXITEM cbi;
				HWND hDlgDetails;

				SetFocus((HWND)lParam);
				if (!(hDlgDetails = GetParent(GetParent(hwnd)))) return 1;
				if (SendMessage(hDlgDetails, PSM_ISLOCKED, NULL, NULL)) return 0;
				if (!cbex->pItems || cbex->iSelectedItem == -1) return 0;

				switch (GetWindowLongPtr(hwnd, GWLP_ID)) {
					case EDIT_PHONE:
						dlgID = IDD_ADDPHONE;
						dlgProc = DlgProc_Phone;
						break;
					case EDIT_EMAIL:
						dlgID = IDD_ADDEMAIL;
						dlgProc = DlgProc_EMail;
						break;
					default:
						return 1;
				}
				cbi.iItem = cbex->iSelectedItem;
				cbi.dwID = 0;
				cbi.wMask = CBEXIM_CAT|CBEXIM_VAL|CBEXIM_FLAGS;
				cbi.pszCat = szCat;
				cbi.pszVal = szVal;
				cbi.ccCat = MAX_CAT;
				cbi.ccVal = MAXDATASIZE;
				if (!CtrlContactWndProc(hwnd, CBEXM_GETITEM, NULL, (LPARAM)&cbi)) {
					MsgErr(hwnd, LPGENT("CRITICAL: Unable to edit current entry!\nThis should not happen!"));
					return 1;
				}

				if (DialogBoxParam(ghInst, MAKEINTRESOURCE(dlgID), GetParent(hwnd), dlgProc, (LPARAM)&cbi) == IDOK) {
					MCONTACT hContact;

					SendMessage(hDlgDetails, PSM_GETCONTACT, NULL, (LPARAM)&hContact);
					if (hContact) cbi.wFlags |= CTRLF_HASCUSTOM;
					cbi.wFlags |= CTRLF_CHANGED;
					SendMessage(hwnd, CBEXM_SETITEM, NULL, (LPARAM)&cbi);
					SendMessage(hDlgDetails, PSM_CHANGED, NULL, NULL);
					cbex->bIsChanged = TRUE;
				}
				return 0;
			}
			break;

		/**
			* name:	BTN_DEL
			* desc:	the button to delete an existing entry is pressed
			**/
		case BTN_DEL:
			if (HIWORD(wParam) == BN_CLICKED) {
				HWND hDlgDetails;
				MSGBOX mBox;
				TCHAR szMsg[MAXDATASIZE];
					
				SetFocus((HWND)lParam);
				if (!(hDlgDetails = GetParent(GetParent(hwnd))) ||
						SendMessage(hDlgDetails, PSM_ISLOCKED, NULL, NULL) ||
						!cbex->pItems ||
						cbex->iSelectedItem < 0 ||
						cbex->iSelectedItem >= cbex->numItems ||
						FAILED(mir_sntprintf(szMsg, TranslateT("Do you really want to delete the current selected item?\n\t%s\n\t%s"),
						cbex->pItems[cbex->iSelectedItem].szCat, cbex->pItems[cbex->iSelectedItem].pszVal))
			)
				{
						return 1;
				}
				mBox.cbSize = sizeof(MSGBOX);
				mBox.hParent = hDlgDetails;
				mBox.hiLogo = IcoLib_GetIcon(ICO_DLG_PHONE);
				mBox.uType = MB_YESNO|MB_ICON_QUESTION|MB_NOPOPUP;
				mBox.ptszTitle = TranslateT("Delete");
				mBox.ptszMsg = szMsg;
				if (IDYES == MsgBoxService(NULL, (LPARAM)&mBox)) {
					// clear value for standard entry
					if (cbex->pItems[cbex->iSelectedItem].wFlags & CBEXIF_CATREADONLY) {
						MIR_FREE(cbex->pItems[cbex->iSelectedItem].pszVal);
						SetWindowText(cbex->hEdit, _T(""));
						cbex->pItems[cbex->iSelectedItem].wFlags &= ~CBEXIF_SMS;
						cbex->pItems[cbex->iSelectedItem].wFlags |= CTRLF_CHANGED;
					}
					// clear values for customized database entry
					else 
					if (cbex->pItems[cbex->iSelectedItem].dwID != 0) {
						MIR_FREE(cbex->pItems[cbex->iSelectedItem].pszVal);
						*cbex->pItems[cbex->iSelectedItem].szCat = 0;
						cbex->pItems[cbex->iSelectedItem].wFlags |= CTRLF_CHANGED|CBEXIF_DELETED;
						CtrlContactWndProc(hwnd, CBEXM_SETCURSEL, cbex->iSelectedItem - 1, FALSE);
					}
					// delete default entry
					else
						CtrlContactWndProc(hwnd, CBEXM_DELITEM, NULL, cbex->iSelectedItem);

					SendMessage(hDlgDetails, PSM_CHANGED, NULL, NULL);
					cbex->bIsChanged = TRUE;
				}
				return 0;
			}
			break;

		/**
			* name:	EDIT_VALUE
			* desc:	the edit control wants us to act
			**/
		case EDIT_VALUE:
			switch (HIWORD(wParam)) {
				case EN_UPDATE:
				{
					TCHAR szVal[MAXDATASIZE] = { 0 };
					int ccVal;
					MCONTACT hContact;
					HWND hDlgDetails = GetParent(GetParent(hwnd));
							
					EnableWindow(cbex->hBtnDel, GetWindowTextLength(cbex->hEdit) > 0);

					if (SendMessage(hDlgDetails, PSM_ISLOCKED, NULL, NULL) ||
						cbex->bLocked || 
						!cbex->pItems || 
						cbex->iSelectedItem < 0 || 
						cbex->iSelectedItem >= cbex->numItems) return 1;

					// get the edit control's text value and check it for syntax
					switch (GetWindowLongPtr(hwnd, GWLP_ID)) {
						case EDIT_PHONE:
						{
							int errorPos;
							TCHAR szEdit[MAXDATASIZE];

							if (ccVal = GetWindowText(cbex->hEdit, szEdit, _countof(szEdit))) {
								if (!(ccVal = CheckPhoneSyntax(szEdit, szVal, MAXDATASIZE, errorPos)) || errorPos > -1) {
									SetWindowText(cbex->hEdit, szVal);
									SendMessage(cbex->hEdit, EM_SETSEL, errorPos, errorPos);
								}
							}
							break;
						}
						case EDIT_EMAIL:
							ccVal = GetWindowText(cbex->hEdit, szVal, _countof(szVal));
							break;
						default:
							ccVal = GetWindowText(cbex->hEdit, szVal, _countof(szVal));
							break;
					}
							
					SendMessage(hDlgDetails, PSM_GETCONTACT, NULL, (LPARAM)&hContact);
					if ((cbex->pItems[cbex->iSelectedItem].wFlags & CTRLF_CHANGED) && !(hContact && (cbex->pItems[cbex->iSelectedItem].wFlags & CTRLF_HASCUSTOM))) return 0;
							
					if (*szVal == 0 || !cbex->pItems[cbex->iSelectedItem].pszVal || mir_tstrcmp(szVal, cbex->pItems[cbex->iSelectedItem].pszVal)) {
						cbex->pItems[cbex->iSelectedItem].wFlags |= CTRLF_CHANGED;
						cbex->pItems[cbex->iSelectedItem].wFlags |= (hContact ? CTRLF_HASCUSTOM : CTRLF_HASPROTO);
						cbex->bIsChanged = TRUE;
						InvalidateRect((HWND)lParam, NULL, TRUE);
						SendMessage(hDlgDetails, PSM_CHANGED, NULL, NULL);
					}
					return 0;
				}
				case EN_KILLFOCUS:
				{
					int ccText;
							
					if (!cbex->pItems || cbex->iSelectedItem < 0 || cbex->iSelectedItem >= cbex->numItems) return 1;
					if (!(cbex->pItems[cbex->iSelectedItem].wFlags & CTRLF_CHANGED)) return 0;

					if ((ccText = GetWindowTextLength(cbex->hEdit)) <= 0) {
						if (cbex->pItems[cbex->iSelectedItem].wFlags & CBEXIF_CATREADONLY) {
							MIR_FREE(cbex->pItems[cbex->iSelectedItem].pszVal);
							SetWindowText(cbex->hEdit, _T(""));
							cbex->pItems[cbex->iSelectedItem].wFlags &= ~CBEXIF_SMS;
						}
						else
							CtrlContactWndProc(hwnd, CBEXM_DELITEM, NULL, cbex->iSelectedItem);
						SendMessage(GetParent(GetParent(hwnd)), PSM_CHANGED, NULL, NULL);
						cbex->bIsChanged = TRUE;
					}
					else
					if (cbex->pItems[cbex->iSelectedItem].pszVal = (LPTSTR)mir_realloc(cbex->pItems[cbex->iSelectedItem].pszVal, (ccText + 2) * sizeof(TCHAR))) {
						cbex->pItems[cbex->iSelectedItem].pszVal[ccText + 1] = 0;
						GetWindowText(cbex->hEdit, cbex->pItems[cbex->iSelectedItem].pszVal, ccText + 1);
					}
					return 0;
				}
			}
			break;
		}
		break;

	/**
		* name:	CBEXM_ADDITEM
		* desc:	add a item to the control
		* param:	wParam - not used
		*			lParam - (LPCBEXITEM)&item
		* return:	CB_ERR on failure, new item index if successful
		**/
	case CBEXM_ADDITEM:
	{
		LPCBEXITEM	pItem = (LPCBEXITEM)lParam;

		if (!pItem) return FALSE;

		// if an item with the id of pItem exists, change it instead of adding a new one
		// but only if it has not been changed by the user yet.
		if ((pItem->wMask & CBEXIM_ID) && cbex->pItems && pItem->dwID != 0) {
			int iIndex;
				
			for (iIndex = 0; iIndex < cbex->numItems; iIndex++) {
				if (cbex->pItems[iIndex].dwID == pItem->dwID) {
					pItem->iItem = iIndex;
					if (cbex->pItems[iIndex].wFlags & CTRLF_CHANGED)
						pItem->wFlags |= CTRLF_CHANGED;
					else
						CtrlContactWndProc(hwnd, CBEXM_SETITEM, 0, lParam);
					return iIndex;
				}
			}
		}

		// add a new item to the combobox
		if (!(cbex->pItems = (LPCBEXITEMINTERN)mir_realloc(cbex->pItems, (cbex->numItems + 1) * sizeof(CBEXITEMINTERN)))) {
			cbex->numItems = 0;
			return CB_ERR;
		}
		
		// set the ID
		cbex->pItems[cbex->numItems].dwID = (pItem->wMask & CBEXIM_ID) ? pItem->dwID : 0;

		// set category string
		if (!pItem->pszCat || !pItem->pszCat[0] || !mir_tstrncpy(cbex->pItems[cbex->numItems].szCat, pItem->pszCat, MAX_CAT)) {
			mir_sntprintf(cbex->pItems[cbex->numItems].szCat, _T("%s %d"), TranslateT("Other"), ++cbex->numOther);
		}

		// set value string
		if ((pItem->wMask & CBEXIM_VAL) && pItem->pszVal && pItem->pszVal[0])
			cbex->pItems[cbex->numItems].pszVal = mir_tstrdup(pItem->pszVal);
		else
			cbex->pItems[cbex->numItems].pszVal = NULL;
		// set icon
		if ((pItem->wMask & CBEXIM_ICONTEXT) && pItem->pszIcon) {
			cbex->pItems[cbex->numItems].pszIcon = pItem->pszIcon;
			cbex->pItems[cbex->numItems].hIcon = IcoLib_GetIcon(pItem->pszIcon);
		}
		// set flags
		cbex->pItems[cbex->numItems].wFlags = (pItem->wMask & CBEXIM_CAT) ? pItem->wFlags : 0;

		cbex->numItems++;
		return cbex->numItems;
	}

	/**
		* name:	CBEXM_SETITEM
		* desc:	Set an item's information of the control.
		*			If iItem member of CBEXITEM is -1, the currently selected item is changed.
		* param:	wParam - not used
		*			lParam - (LPCBEXITEM)&item
		* return:	CB_ERR on failure, new item index if successful
		**/
	case CBEXM_SETITEM:
	{
		LPCBEXITEM	pItem = (LPCBEXITEM)lParam;

		if (!PtrIsValid(pItem) || !pItem->wMask || !PtrIsValid(cbex->pItems)) return FALSE;
		if (pItem->iItem == -1) pItem->iItem = cbex->iSelectedItem;
		if (pItem->iItem < 0 || pItem->iItem >= cbex->numItems) return FALSE;

		// set new category string
		if (pItem->wMask & CBEXIM_CAT) {
			// set category string
			if (!pItem->pszCat || !pItem->pszCat[0] || !mir_tstrncpy(cbex->pItems[pItem->iItem].szCat, pItem->pszCat, _countof(cbex->pItems[pItem->iItem].szCat))) 
				mir_sntprintf(cbex->pItems[pItem->iItem].szCat, _T("%s %d"), TranslateT("Other"), ++cbex->numOther);
			if (pItem->iItem == cbex->iSelectedItem)
				SetWindowText(cbex->hBtnEdit, cbex->pItems[pItem->iItem].szCat);
		}
		// set new value
		if (pItem->wMask & CBEXIM_VAL) {
			MIR_FREE(cbex->pItems[pItem->iItem].pszVal);
			if (pItem->pszVal && pItem->pszVal[0])
				cbex->pItems[pItem->iItem].pszVal = mir_tstrdup(pItem->pszVal);
			if (pItem->iItem == cbex->iSelectedItem)
				SetWindowText(cbex->hEdit, cbex->pItems[pItem->iItem].pszVal ? cbex->pItems[pItem->iItem].pszVal : _T(""));
		}

		// set icon
		if ((pItem->wMask & CBEXIM_ICONTEXT) && pItem->pszIcon) {
			cbex->pItems[pItem->iItem].pszIcon = pItem->pszIcon;
			cbex->pItems[pItem->iItem].hIcon = IcoLib_GetIcon(pItem->pszIcon);
			if (pItem->iItem == cbex->iSelectedItem)
				SendMessage(cbex->hBtnEdit, BM_SETIMAGE, IMAGE_ICON, (LPARAM)cbex->pItems[pItem->iItem].hIcon);
		}
		if (pItem->wMask & CBEXIM_FLAGS) {
			cbex->pItems[pItem->iItem].wFlags = pItem->wFlags;
			CtrlContactWndProc(hwnd, CBEXM_ENABLEITEM, NULL, NULL);
		}
		return TRUE;
	}

	/**
		* name:	CBEXM_GETITEM
		* desc:	Get an item from the control.
		*			If iItem member of CBEXITEM is -1, the currently selected item is returned.
		* param:	wParam - not used
		*			lParam - (LPCBEXITEM)&item
		* return:	CB_ERR on failure, new item index if successful
		**/
	case CBEXM_GETITEM:
	{
		LPCBEXITEM	pItem = (LPCBEXITEM)lParam;

		if (!pItem || !cbex->pItems) return FALSE;
			
		// try to find item by id
		if ((pItem->wMask & CBEXIM_ID) && pItem->dwID != 0) {
			int i;

			for (i = 0; i < cbex->numItems; i++) {
				if (cbex->pItems[i].dwID == pItem->dwID)
					break;
			}
			pItem->iItem = i;
		}
		else
		if (pItem->iItem == -1) pItem->iItem = cbex->iSelectedItem;
		if (pItem->iItem < 0 || pItem->iItem >= cbex->numItems) return FALSE;
			
		// return only currently selected itemindex
		if (!pItem->wMask) return TRUE;
		// return the unique id
		if (pItem->wMask & CBEXIM_ID) 
			pItem->dwID = cbex->pItems[pItem->iItem].dwID;
		// return category string
		if ((pItem->wMask & CBEXIM_CAT) && pItem->pszCat) {
			if (*cbex->pItems[pItem->iItem].szCat != 0)
				mir_tstrncpy(pItem->pszCat, cbex->pItems[pItem->iItem].szCat, pItem->ccCat - 1);
			else
				*pItem->pszCat = 0;
		}
		// return value string
		if ((pItem->wMask & CBEXIM_VAL) && pItem->pszVal) {
			if (cbex->pItems[pItem->iItem].pszVal)
				mir_tstrncpy(pItem->pszVal, cbex->pItems[pItem->iItem].pszVal, pItem->ccVal - 1);
			else
				*pItem->pszVal = 0;
		}
		// return the icon
		if (pItem->wMask & CBEXIM_ICONTEXT)
			pItem->pszIcon = cbex->pItems[pItem->iItem].pszIcon;
		// return the flags
		if (pItem->wMask & CBEXIM_FLAGS)
			pItem->wFlags = cbex->pItems[pItem->iItem].wFlags;
		return TRUE;
	}

	/**
		* name:	CBEXM_DELITEM
		* desc:	delete an item from the control
		* param:	wParam - not used
		*			lParam - item index
		* return:	CB_ERR on failure, new item index if successful
		**/
	case CBEXM_DELITEM:
	{
		if (!cbex->pItems || (int)lParam < 0 || (int)lParam >= cbex->numItems || (cbex->pItems[lParam].wFlags & CBEXIF_CATREADONLY))
			return FALSE;	
		MIR_FREE(cbex->pItems[(int)lParam].pszVal);
		memmove(cbex->pItems + (int)lParam, 
			cbex->pItems + (int)lParam + 1,
			(cbex->numItems - (int)lParam - 1) * sizeof(CBEXITEMINTERN));
		cbex->numItems--;
		memset((cbex->pItems + cbex->numItems), 0, sizeof(CBEXITEMINTERN));
		CtrlContactWndProc(hwnd, CBEXM_SETCURSEL, lParam - 1, FALSE);
		return TRUE;
	}

	/**
		* name:	CBEXM_DELITEM
		* desc:	delete an item from the control
		* param:	wParam - not used
		*			lParam - item index
		* return:	CB_ERR on failure, new item index if successful
		**/
	case CBEXM_DELALLITEMS:
	{
		int i;

		if (PtrIsValid(cbex)) {
			if (PtrIsValid(cbex->pItems)) {
				for (i = 0; i < cbex->numItems; i++) {
					MIR_FREE(cbex->pItems[i].pszVal);
				}
				MIR_FREE(cbex->pItems);
				cbex->pItems = NULL;
			}
			cbex->numItems = 0;
			cbex->iSelectedItem = -1;
			SetWindowText(cbex->hEdit, _T(""));
			SetWindowText(cbex->hBtnEdit, _T(""));
			SendMessage(cbex->hBtnEdit, WM_SETICON, NULL, NULL);
		}
		return TRUE;
	}

	/**
		* name:	CBEXM_ENABLEITEM
		* desc:	enables or disables the current item
		* param:	wParam - not used
		*			lParam - not used
		* return:	always 0
		**/
	case CBEXM_ENABLEITEM:
		if (cbex->iSelectedItem >= 0 && cbex->iSelectedItem < cbex->numItems) {
			MCONTACT hContact;
			BYTE bEnabled;
				
			PSGetContact(GetParent(hwnd), hContact);

			bEnabled	= !hContact ||
						(cbex->pItems[cbex->iSelectedItem].wFlags & CTRLF_HASCUSTOM) || 
						!(cbex->pItems[cbex->iSelectedItem].wFlags & (CTRLF_HASPROTO|CTRLF_HASMETA)) ||
						!db_get_b(NULL, MODNAME, SET_PROPSHEET_PCBIREADONLY, 0);

			EnableWindow(cbex->hBtnEdit, bEnabled);
			EnableWindow(cbex->hBtnDel, bEnabled && GetWindowTextLength(cbex->hEdit) > 0);
			EnableWindow(cbex->hEdit, bEnabled);
		}
		break;

	/**
		* name:	CBEXM_ISCHANGED
		* desc:	returns whether the control contains changed values or not
		* param:	wParam - not used
		*			lParam - not used
		* return:	TRUE if control was changed, FALSE if nothing was edited
		**/
	case CBEXM_ISCHANGED:
		return cbex->bIsChanged;

	/**
		* name:	CBEXM_RESETCHANGED
		* desc:	resets changed flag to FALSE
		* param:	wParam - not used
		*			lParam - not used
		* return:	always FALSE
		**/
	case CBEXM_RESETCHANGED:
		cbex->bIsChanged = 0;
		return 0;

	/**
		* name:	CBEXM_SETCURSEL
		* desc:	selects a certain item
		* param:	wParam - index of the item to select
		*			lParam - (BYTE)bValid - if TRUE, the next item with a value is selected
		* return:	always FALSE
		**/
	case CBEXM_SETCURSEL:
	{
		int i;

		if (!cbex->pItems) return 1;
		if ((int)wParam < 0 || (int)wParam >= cbex->numItems) wParam = max(cbex->iSelectedItem, 0);
		cbex->bLocked = 1;
			
		if ((BYTE)lParam == TRUE) {
			i = (int)wParam;

			cbex->iSelectedItem = (int)wParam;
			while (i < cbex->numItems) {
				if (cbex->pItems[i].pszVal && *cbex->pItems[i].pszVal) {
					cbex->iSelectedItem = i;
					break;
				}
				i++;
			}
		}
		else {
			// search for the next none deleted item
			for (i = (int)wParam; i < cbex->numItems && *cbex->pItems[i].szCat == 0; i++);
			if (i == cbex->numItems && (int)wParam > 0) {
				for (i = 0; i < (int)wParam && *cbex->pItems[i].szCat == 0; i++);
				cbex->iSelectedItem = i == (int)wParam ? 0 : i;
			}
			else
				cbex->iSelectedItem = i;

		}
		SetWindowText(cbex->hBtnEdit, cbex->pItems[cbex->iSelectedItem].szCat);
		SetWindowText(cbex->hEdit, cbex->pItems[cbex->iSelectedItem].pszVal ? cbex->pItems[cbex->iSelectedItem].pszVal : _T(""));
		SendMessage(cbex->hBtnEdit, BM_SETIMAGE, IMAGE_ICON, (LPARAM)cbex->pItems[cbex->iSelectedItem].hIcon);
		CtrlContactWndProc(hwnd, CBEXM_ENABLEITEM, NULL, NULL);
		cbex->bLocked = 0;
		return 0;
	}
	case CBEXM_SORT:
		if (cbex->numItems > 4) {
			qsort(cbex->pItems + 3, cbex->numItems - 3, sizeof(CBEXITEMINTERN), compareProc);
		}
		return 0;

	case WM_ERASEBKGND:
		return 1;

	case WM_SETFOCUS:
		SetFocus(cbex->hEdit);
		SendMessage(cbex->hEdit, EM_SETSEL, 0, (LPARAM)-1);
		return 0;
	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Ejemplo n.º 9
0
Archivo: Main.cpp Proyecto: d3x0r/SACK
//---------------------------------------------------------------------------------------------
// MainWindow WindowProc
//---------------------------------------------------------------------------------------------
long WINAPI WindowProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
		case WM_TIMER:
		{
			int wTimerID = wParam;
			if( AnimFile.isAnimation == 1 && wTimerID == 2 )
			{
				UpdateMNG();
				SendMessage( hPicWin, WM_PAINT, 0, 0 );
			}
		}
		break;

        case WM_COMMAND:
            switch( LOWORD(wParam) )
            {
				case FILE_OPEN:
					LoadOFN(hwnd);
					break;

				case FILE_SAVE:
					SaveSFN(hwnd);
					break;

				case FILE_EXIT:
					DestroyWindow( hPicWin );
					break;

				case HELP_ABOUT:
					Warning( 
						"MNGView Sample Application for VC6.\n" \
						"This Code is Public Domain.\n" \
						"Created by Nikolaus Brennig."
					);
					break;
			}
			break;

	    case WM_ERASEBKGND:
			return 0L;

        case WM_PAINT:
			// GetDC:
			GetClientRect( hPicWin, &rcRect );
			hdc = GetDC( hPicWin );

			if( MemDC == 0 ) 
			{
				BitBlt( hdc, 0, 0, rcRect.right, rcRect.bottom, MemDC, 0, 0, BLACKNESS );
				ReleaseDC( hPicWin, hdc );
				break;
			}

			// Erase:
			// Upper area...
			BitBlt( hdc, 0, 0, rcRect.right, (0+dy), MemDC, 0, 0, BLACKNESS );
			// Lower area...
			BitBlt( hdc, 0, (0+dy)+H, rcRect.right, rcRect.bottom - ((0+dy)+H), MemDC, 0, 0, BLACKNESS );
			// Left area...
			BitBlt( hdc, 0, 0, (0+dx), rcRect.bottom, MemDC, 0, 0, BLACKNESS );
			// Right area...
			BitBlt( hdc, (0+dx)+W, 0, rcRect.right, rcRect.bottom, MemDC, 0, 0, BLACKNESS );
	
			// Show Imageframe:
			BitBlt( hdc, dx, dy, W, H, MemDC, 0, 0, SRCCOPY );

			// Release DC...
			ReleaseDC( hPicWin, hdc );
            break;

		case WM_HSCROLL:
		{
			int nScrollCode = (int) LOWORD(wParam);  // scroll bar value 
			if( nScrollCode == SB_LINELEFT	) dx += 10;
			if( nScrollCode == SB_LINERIGHT ) dx -= 10;
			SendMessage( hwnd, WM_PAINT, 0, 0 );
		}
		break;

		case WM_VSCROLL:
		{
			int nScrollCode = (int) LOWORD(wParam);  // scroll bar value 
			if( nScrollCode == SB_LINEUP	) dy += 10;
			if( nScrollCode == SB_LINEDOWN  ) dy -= 10;
			SendMessage( hwnd, WM_PAINT, 0, 0 );
		}
		break;

        case WM_GETMINMAXINFO:
			((MINMAXINFO*)lParam)->ptMinTrackSize.x = 550;
			((MINMAXINFO*)lParam)->ptMinTrackSize.y = 450;
            return 0L;

		case WM_DESTROY:
			if( AnimFile.isAnimation == 1 ) 
				CleanUpMNG();
			if( hMenu ) DestroyMenu( hMenu );
            PostQuitMessage(0);
            return 0L;
	}
    
	return DefWindowProc( hwnd, message, wParam, lParam );
}
Ejemplo n.º 10
0
HRESULT STDMETHODCALLTYPE CPopupMenu::QueryContextMenu(THIS_ HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
	if(!IsWorkCopy(&m_Files, m_NumFiles, m_WcPath)){
		if(m_NumFiles >= 2){
		}
		else{
			if (FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(m_Files[0].c_str())){
				int i = 0;
				HMENU SubMenu = CreatePopupMenu();
				m_hInstance = GetModuleHandle("TeamExplorerShellMenu.dll");

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 1, _T("Set Environment"));
				m_hSetEnv = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_SETENV)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hSetEnv, m_hSetEnv);

				InsertMenu(hmenu, indexMenu, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

				InsertMenu(hmenu, indexMenu+1, MF_POPUP | MF_BYPOSITION, (UINT)SubMenu, _T("Team Explorer"));
				m_hPopupMenu = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_POPUPMENU)); 
				SetMenuItemBitmaps(hmenu, indexMenu+1, MF_BYPOSITION, m_hPopupMenu, m_hPopupMenu);

				InsertMenu(hmenu, indexMenu+2, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

				DestroyMenu(SubMenu);
			}
		}
	}
	else{
		if(!IsTeamExplorer(m_WcPath)){
			return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(13 + 1));
		}

		int i = 0;
		HMENU SubMenu = CreatePopupMenu();
		m_hInstance = GetModuleHandle("TeamExplorerShellMenu.dll");

		if(IsProductOrTags(m_WcPath)){
			InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 2, _T("Update"));
			m_hUpdate = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_UPDATE)); 
			SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hUpdate, m_hUpdate);
		}
		else{
			if(CouldWrite(&m_Files, &m_WriteFiles, m_NumFiles)){
				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 3, _T("Check out"));
				m_hCheckout = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_CHECKOUT)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hCheckout, m_hCheckout);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 4, _T("Commit"));
				m_hCommit = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_COMMIT)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hCommit, m_hCommit);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 5, _T("Check in"));
				m_hCheckin = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_CHECKIN)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hCheckin, m_hCheckin);

				InsertMenu(SubMenu, i++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 2, _T("Update"));
				m_hUpdate = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_UPDATE)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hUpdate, m_hUpdate);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 6, _T("Cancel"));
				m_hCancel = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_CANCEL)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hCancel, m_hCancel);

				InsertMenu(SubMenu, i++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 8, _T("Revert"));
				m_hRevert = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_REVERT)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hRevert, m_hRevert);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 9, _T("Merge"));
				m_hMerge = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_MERGE)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hMerge, m_hMerge);
			}
			else{
				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 3, _T("Check out"));
				m_hCheckout = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_CHECKOUT)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hCheckout, m_hCheckout);

				InsertMenu(SubMenu, i++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 7, _T("Add"));
				m_hAdd = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_ADD)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hAdd, m_hAdd);

				InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 2, _T("Update"));
				m_hUpdate = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_UPDATE)); 
				SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hUpdate, m_hUpdate);
			}
		}

		InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 10, _T("Show log"));
		m_hShowLog = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_SHOWLOG)); 
		SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hShowLog, m_hShowLog);

		InsertMenu(SubMenu, i++, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);

		InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 11, _T("Diff"));
		m_hDiff = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_DIFF));
		SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hDiff, m_hDiff);

		InsertMenu(SubMenu, i++, MF_STRING | MF_BYPOSITION, idCmdFirst + 12, _T("Compare"));
		m_hCompare = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_COMPARE));
		SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hCompare, m_hCompare);

		InsertMenu(SubMenu, i++, MF_BYPOSITION | MF_STRING, idCmdFirst + 13, _T("Update Rely Files"));
		m_hDownload = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_DOWNLOAD));
		SetMenuItemBitmaps(SubMenu, i-1, MF_BYPOSITION, m_hDownload, m_hDownload);

		InsertMenu(hmenu, indexMenu, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

		InsertMenu(hmenu, indexMenu+1, MF_POPUP | MF_BYPOSITION, (UINT)SubMenu, _T("Team Explorer"));
		m_hPopupMenu = ::LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_POPUPMENU)); 
		SetMenuItemBitmaps(hmenu, indexMenu+1, MF_BYPOSITION, m_hPopupMenu, m_hPopupMenu);

		InsertMenu(hmenu, indexMenu+2, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

		DestroyMenu(SubMenu);
	}

	return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(13 + 1));
}
Ejemplo n.º 11
0
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	enum
	{
		WM_APP_TRAYICON = WM_APP_RELOAD + 1,
	};
	static NOTIFYICONDATA nid;
	static HMENU hMenu;

	switch (uMsg) {
	case WM_APP_TRAYICON:
		switch (lParam) {
		case WM_RBUTTONDOWN:
			SetCapture(hWnd);
			break;
		case WM_RBUTTONUP:
			ReleaseCapture();
			{
				RECT rc;
				POINT pt;
				GetCursorPos(&pt);
				GetWindowRect(GetDesktopWindow(), &rc);
				SetForegroundWindow(hWnd);
				TrackPopupMenu(GetSubMenu(hMenu, 0),
					(pt.x < (rc.left + rc.right) / 2 ? TPM_LEFTALIGN : TPM_RIGHTALIGN) |
					(pt.y < (rc.top + rc.bottom) / 2 ? TPM_TOPALIGN : TPM_BOTTOMALIGN) |
					TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
				PostMessage(hWnd, WM_NULL, 0, 0);
			}
			break;
		case NIN_BALLOONHIDE:
		case NIN_BALLOONTIMEOUT:
		case NIN_BALLOONUSERCLICK:
			/* error message closed */
			DestroyWindow(hWnd);
			break;
		}
		return 0;
	case WM_APP_RELOAD:
		{
			Config_Load();
		}
		return 0;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case ID_CONF:
			{
				TCHAR cmd[MAX_PATH];
				GetModuleFileName(NULL, cmd, ARRAYSIZE(cmd));
				lstrcpy(cmd + lstrlen(cmd) - 4, TEXT("cf"));
				Exec(cmd);
			}
			break;
		case ID_QUIT:
			DestroyWindow(hWnd);
			break;
		}
		break;
	case WM_CREATE:
		{
			HINSTANCE hInstance = ((LPCREATESTRUCT)lParam)->hInstance;

			Config_Load();

			/* menu */
			hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDM_MAIN));

			/* tray icon */
			ZeroMemory(&nid, sizeof nid);
			nid.cbSize           = sizeof nid;
			nid.hWnd             = hWnd;
			nid.uID              = 100;
			nid.uFlags           = NIF_ICON | NIF_MESSAGE | NIF_TIP;
			nid.uCallbackMessage = WM_APP_TRAYICON;
			nid.hIcon            = Global.hIconLarge;
			lstrcpy(nid.szTip, App.Title);
			Shell_NotifyIcon(NIM_ADD, &nid);
			/* error message balloon tip */
			nid.uFlags      = NIF_INFO;
			nid.dwInfoFlags = NIIF_WARNING;
			LoadString(hInstance, IDS_DEVICE_NOT_FOUND, nid.szInfo, ARRAYSIZE(nid.szInfo));
			lstrcpy(nid.szInfoTitle, App.Title);

			/* low level keyboard hook */
			Global.hHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0);

			if (!SpecialKey_Prepare())
				Shell_NotifyIcon(NIM_MODIFY, &nid);
		}
		break;
	case WM_DESTROY:
		{
			SpecialKey_Cleanup();
			UnhookWindowsHookEx(Global.hHook);
			Shell_NotifyIcon(NIM_DELETE, &nid);
			DestroyMenu(hMenu);
		}
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Ejemplo n.º 12
0
LRESULT CALLBACK 
ClientWndProc (HWND hwnd, UINT mMsg, WPARAM wParam, LPARAM lParam)
     {
	RECT rect;

     switch (mMsg)
          {
          case WM_CREATE :
			   poppad_ini( hwnd,lParam );
               return 0 ;

          case WM_DESTROY :
               //DeleteObject (hbr) ;
			   DestroyMenu(hMenu) ;
			   poppad_bye();
               return 0 ;

		  case WM_INITMENUPOPUP :
			   return poppad_menupop( (WPARAM)hSubMenu, -1 );

//          case WM_CTLCOLOREDIT :
//               {
//               DefWindowProc (hwnd, mMsg, wParam, lParam) ;
//               SetBkColor ((HDC) wParam, crBack) ;
//               //SetBkMode ((HDC) wParam, TRANSPARENT) ;
//			   SetTextColor( (HDC) wParam, crText );
//               return (LRESULT) (HBRUSH) hbr ;
//               }

          case WM_SETFOCUS :
//               hwndNotify = GetWindow (hwnd, GW_CHILD) ;
//               SetFocus (hwndNotify) ;
			   Footy2SetFocus(activeFootyID, 0);
               return 0 ;

          case WM_SIZE :
               {
//               hwndNotify = GetWindow (hwnd, GW_CHILD) ;
               int cx = LOWORD (lParam) ;
               int cy = HIWORD (lParam) ;

               // Ignore if notification window is absent.
//               if (hwndNotify != NULL)
//                    {
//                    MoveWindow (hwndNotify, 0, 0, cx, cy, TRUE) ;
//                    }
			   MoveWindow(hwndTab, 0, 0, cx, cy, TRUE);
			   GetClientRect(hwndTab, &rect);
			   TabCtrl_AdjustRect(hwndTab, FALSE, &rect);
			   Footy2Move(activeFootyID, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
			   poppad_setsb_current(activeFootyID);

			   return 0 ;
               }

          case WM_NOTIFY:
			  switch (((NMHDR *)lParam)->code){
				   case TCN_SELCHANGE:
				   {
					   int presID = activeID, newID = TabCtrl_GetCurSel(hwndTab);
					   ActivateTab(presID, newID);
					   ChangeZOrder(presID, newID);
					   return 0;
				   }

				   case NM_RCLICK:
					   POINT pt, cpt;
					   int i;

					   GetCursorPos(&pt);
					   cpt = pt;
					   ScreenToClient(hwndTab, &cpt);

					   for(i = 0; TabCtrl_GetItemCount(hwndTab); i++){
						   TabCtrl_GetItemRect(hwndTab, i, &rect);
						   if(rect.left <= cpt.x && cpt.x <= rect.right && rect.top <= cpt.y && cpt.y <= rect.bottom){
							   TrackPopupMenu(hSubMenu2, TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwndClient, NULL);
							   ClickID = i;
							   break;
						   }

					   }
 					   return 0;
			  }
			  return 0;

          default :
               return (EditProc (hwnd, mMsg, wParam, lParam)) ;
               //return (DefWindowProc (hwnd, mMsg, wParam, lParam)) ;
          }
     }
Ejemplo n.º 13
0
/****************************************************************************
*                             text_ExitInstance
* Result: void
*       
* Effect: 
*       Does whatever cleanup is necessary.  In this case, destroys the
*       menu handle.
****************************************************************************/
void text_ExitInstance()
  {
   DestroyMenu(TextMenu);
   DestroyMenu(TextContextMenu);
  }
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
VOID CMainWnd::OnDestroy(WPARAM wParam, LPARAM lParam)
{
	DestroyMenu(hCurMenu);//销毁菜单资源
	PostQuitMessage(0);//如果破坏窗体,则退出主线程
	return;
}
Ejemplo n.º 16
0
LRESULT CSEShellView::OnNotify( LPNMHDR pNmhdr )
{
    TRACE_FUNCTION();
    if( pNmhdr )
    {
        if( pNmhdr->code == NM_DBLCLK )
        {
            int iIndex = ListView_GetNextItem( m_hWnd, -1, LVNI_FOCUSED );
            if (iIndex == -1)
            {
                return S_OK;
            }
            LV_ITEM item = {0};
            item.iItem = iIndex;
            item.iSubItem = 0;
            item.mask = LVIF_PARAM;
            ListView_GetItem( m_hWnd, &item );
            if ( item.lParam )
            {               
                LPITEMIDLIST pItem = m_pidlManager.Copy( ITEMLISTPTR(item.lParam) );
                if( m_pidlManager.GetItemType( pItem ) == CPidlManager::FOLDER )
                {
                    LOG(_T("%s 打开文件夹 %s"), __TFUNCTION__, m_pidlManager.GetItemName( pItem ) );
                    //打开文件夹
                    m_pShellBrowser->BrowseObject( pItem , SBSP_DEFBROWSER | SBSP_RELATIVE );
                }
                else
                {   
                    TCHAR szPath[MAX_PATH] = {0};
                    DWORD dwLen = MAX_PATH;
                    LPITEMIDLIST pFullItem = m_pidlManager.Concatenate(m_pFolder->GetRootPath(), pItem );
                    m_pidlManager.GetFullName( pFullItem, szPath, &dwLen );
                    m_pidlManager.ReplaceRoot( szPath );
                    m_pidlManager.Delete( pFullItem );
                    //打开文件
                    LONG ret = (LONG)(LONG_PTR)ShellExecute(NULL, _T("open"),  szPath, NULL, NULL, SW_SHOWNORMAL);
                    if ( ret > 32 )
                    {
                        return TRUE;
                    }
                    switch ( ret )
                    {
                    case ERROR_BAD_FORMAT:
                        {
                            ::MessageBox( NULL, _T("文件已损坏"), _T("提示"), MB_OK );
                        }
                        break;
                    case SE_ERR_ASSOCINCOMPLETE:
                    case SE_ERR_NOASSOC:
                        {
                            TCHAR szRunParam[MAX_PATH<<1] = {0};
                            _sntprintf( szRunParam, MAX_PATH<<1, _T("shell32.dll,OpenAs_RunDLL \"%s\""), szPath );
                            ShellExecute(NULL, NULL, _T("rundll32.exe "), szRunParam, NULL, SW_SHOW); 
                        }
                        break;
                    default:
                        {
                        }
                    }
                }
                m_pidlManager.Delete( pItem );
                pItem = NULL;
            }
        }
        else if( pNmhdr->code == NM_RCLICK )
        {
            LPITEMIDLIST* ppIdl = NULL;
            int nSelCount = ListView_GetSelectedCount(m_hWnd);
            if ( nSelCount > 0 )
            {
                ppIdl = (LPITEMIDLIST*)_Module.m_Allocator.Alloc( sizeof(LPITEMIDLIST)*nSelCount );
                int iIndex = ListView_GetNextItem( m_hWnd, -1, LVIS_SELECTED );
                LV_ITEM item = {0};
                item.iSubItem = 0;
                item.mask = LVIF_PARAM;
                int _i = 0;
                while( iIndex >= 0 
                    && _i < nSelCount )
                {    
                    item.iItem = iIndex;
                    ListView_GetItem( m_hWnd, &item );
                    ppIdl[_i] = m_pidlManager.Copy( ITEMLISTPTR(item.lParam) );
                    ++_i;
                    iIndex = ListView_GetNextItem( m_hWnd, -1, LVIS_SELECTED );
                }
            }
            LPCONTEXTMENU pMenu = NULL;
            HRESULT hr = E_FAIL;
            hr = m_pFolder->GetUIObjectOf( m_hWnd, nSelCount, \
                (LPCITEMIDLIST*)ppIdl, IID_IContextMenu, NULL, (void**)&pMenu );
            if ( FAILED(hr)
                || !pMenu)
            {
                LOG(_T("IID_IContextMenu Failed"));
                if ( nSelCount > 0 )
                {
                    for ( int _i = 0; _i < nSelCount; ++_i )
                    {
                        m_pidlManager.Delete( ppIdl[_i] );
                    }
                    _Module.m_Allocator.Free( ppIdl );
                }
                return S_OK;
            }
            HMENU hMenu = ::CreatePopupMenu();
            if ( !hMenu )
            {
                if ( nSelCount > 0 )
                {
                    for ( int _i = 0; _i < nSelCount; ++_i )
                    {
                        m_pidlManager.Delete( ppIdl[_i] );
                    }
                    _Module.m_Allocator.Free( ppIdl );
                }
                return S_OK;
            }
            hr = pMenu->QueryContextMenu( hMenu, 0, 10, 32767, CMF_NORMAL | CMF_EXPLORE );
            if ( FAILED(hr) )
            {
                if ( nSelCount > 0 )
                {
                    for ( int _i = 0; _i < nSelCount; ++_i )
                    {
                        m_pidlManager.Delete( ppIdl[_i] );
                    }
                    _Module.m_Allocator.Free( ppIdl );
                }
                DestroyMenu( hMenu );
                return hr;
            }
            POINT point = {0};
            GetCursorPos( &point );
            UINT command = (UINT)TrackPopupMenu ( hMenu, TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, 0, m_hWnd, NULL );
            CMINVOKECOMMANDINFO cmi = {0};
            cmi.cbSize = sizeof (CMINVOKECOMMANDINFO);
            cmi.lpVerb = (LPSTR) MAKEINTRESOURCE (command-10);
            cmi.nShow = SW_SHOWNORMAL;
            pMenu->InvokeCommand( &cmi );
            pMenu->Release();
            if ( nSelCount > 0 )
            {
                for ( int _i = 0; _i < nSelCount; ++_i )
                {
                    m_pidlManager.Delete( ppIdl[_i] );
                }
                _Module.m_Allocator.Free( ppIdl );
            }
            DestroyMenu( hMenu );
        }
    }
    TRACE_RETURN S_OK;
}
Ejemplo n.º 17
0
static void TaskManager_OnTabWndSelChange(void)
{
    int   i;
    HMENU hMenu;
    HMENU hOptionsMenu;
    HMENU hViewMenu;
    HMENU hSubMenu;

    WCHAR wszLargeIcons[255];
    WCHAR wszSmallIcons[255];
    WCHAR wszDetails[255];
    WCHAR wszWindows[255];
    WCHAR wszSelectColumns[255];
    WCHAR wszShow16bTasks[255];
    WCHAR wszOneGraphAllCPU[255];
    WCHAR wszOneGraphPerCPU[255];
    WCHAR wszCPUHistory[255];
    WCHAR wszShowKernelTimes[255];

    LoadStringW(hInst, IDS_VIEW_LARGE, wszLargeIcons, sizeof(wszLargeIcons)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_SMALL, wszSmallIcons, sizeof(wszSmallIcons)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_DETAILS, wszDetails, sizeof(wszDetails)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_WINDOWS, wszWindows, sizeof(wszWindows)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_SELECTCOLUMNS, wszSelectColumns, sizeof(wszSelectColumns)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_OPTIONS_SHOW16BITTASKS, wszShow16bTasks, sizeof(wszShow16bTasks)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU, sizeof(wszOneGraphAllCPU)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU, sizeof(wszOneGraphPerCPU)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_CPUHISTORY, wszCPUHistory, sizeof(wszCPUHistory)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_VIEW_SHOWKERNELTIMES, wszShowKernelTimes, sizeof(wszShowKernelTimes)/sizeof(WCHAR));

    hMenu = GetMenu(hMainWnd);
    hViewMenu = GetSubMenu(hMenu, 2);
    hOptionsMenu = GetSubMenu(hMenu, 1);
    TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
    for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
        hSubMenu = GetSubMenu(hViewMenu, i);
        if (hSubMenu)
            DestroyMenu(hSubMenu);
        RemoveMenu(hViewMenu, i, MF_BYPOSITION);
    }
    RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
    switch (TaskManagerSettings.ActiveTabPage) {
    case 0:
        ShowWindow(hApplicationPage, SW_SHOW);
        ShowWindow(hProcessPage, SW_HIDE);
        ShowWindow(hPerformancePage, SW_HIDE);
        BringWindowToTop(hApplicationPage);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails);

        if (GetMenuItemCount(hMenu) <= 4) {
            hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));
            InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows);
            DrawMenuBar(hMainWnd);
        }
        if (TaskManagerSettings.View_LargeIcons)
            CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
        else if (TaskManagerSettings.View_SmallIcons)
            CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
        else
            CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
        /*
         * Give the application list control focus
         */
        SetFocus(hApplicationPageListCtrl);
        break;

    case 1:
        ShowWindow(hApplicationPage, SW_HIDE);
        ShowWindow(hProcessPage, SW_SHOW);
        ShowWindow(hPerformancePage, SW_HIDE);
        BringWindowToTop(hProcessPage);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns);
        AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks);
        if (TaskManagerSettings.Show16BitTasks)
            CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
        if (GetMenuItemCount(hMenu) > 4)
        {
            RemoveMenu(hMenu, 3, MF_BYPOSITION);
            DrawMenuBar(hMainWnd);
        }
        /*
         * Give the process list control focus
         */
        SetFocus(hProcessPageListCtrl);
        break;

    case 2:
        ShowWindow(hApplicationPage, SW_HIDE);
        ShowWindow(hProcessPage, SW_HIDE);
        ShowWindow(hPerformancePage, SW_SHOW);
        BringWindowToTop(hPerformancePage);
        if (GetMenuItemCount(hMenu) > 4) {
            RemoveMenu(hMenu, 3, MF_BYPOSITION);
            DrawMenuBar(hMainWnd);
        }
        hSubMenu = CreatePopupMenu();
        AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU);
        AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU);
        AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes);
        if (TaskManagerSettings.ShowKernelTimes)
            CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
        else
            CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
        if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
            CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
        else
            CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
        /*
         * Give the tab control focus
         */
        SetFocus(hTabWnd);
        break;
    }
}
Ejemplo n.º 18
0
STDAPI CLangBarItemButton::OnClick(TfLBIClick click, POINT pt, const RECT *prcArea)
{
    if(IsEqualGUID(_LangBarItemInfo.guidItem, GUID_LBI_INPUTMODE))
    {
        switch(click)
        {
        case TF_LBI_CLK_RIGHT:
        {
            HMENU hMenu = LoadMenuW(g_hInst, MAKEINTRESOURCEW(IDR_SYSTRAY_MENU));
            if(hMenu)
            {
                UINT check = IDM_DEFAULT;
                for(int i = 0; i < _countof(menuItems); i++)
                {
                    if(_pTextService->inputmode == menuItems[i].inputmode)
                    {
                        check = menuItems[i].id;
                        break;
                    }
                }
                CheckMenuRadioItem(hMenu, IDM_HIRAGANA, IDM_DEFAULT, check, MF_BYCOMMAND);
                HMENU hSubMenu = GetSubMenu(hMenu, 0);
                if(hSubMenu)
                {
                    TPMPARAMS tpm;
                    TPMPARAMS *ptpm = nullptr;
                    if(prcArea != nullptr)
                    {
                        tpm.cbSize = sizeof(tpm);
                        tpm.rcExclude = *prcArea;
                        ptpm = &tpm;
                    }
                    BOOL bRet = TrackPopupMenuEx(hSubMenu,
                                                 TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_VERTICAL,
                                                 pt.x, pt.y, GetFocus(), ptpm);
                    this->OnMenuSelect(bRet);
                }
                DestroyMenu(hMenu);
            }
        }
        break;
        case TF_LBI_CLK_LEFT:
        {
            BOOL fOpen = _pTextService->_IsKeyboardOpen();

            if(fOpen)
            {
                _pTextService->_ClearComposition();
            }
            else
            {
                _pTextService->inputmode = im_disable;
            }

            _pTextService->_SetKeyboardOpen(fOpen ? FALSE : TRUE);
        }
        break;
        default:
            break;
        }
    }

    return S_OK;
}
Ejemplo n.º 19
0
/*
 * Change by PRB ([email protected]), 31/10/93.  Prepend a hot key
 * specifier to each item in the list.  This means allocating the
 * memory for each item (& freeing it) rather than just using the window
 * title directly.  */
void
do_windowList (XEvent *eventp, Window w, FVWMWIN *tmp_win,
		ulong context, char *action, int *Module)
{
	MenuRoot	*mr;
	FVWMWIN	*t;
	char		*tname;
	char		loc[40], *name = NULL;
	int		dwidth, dheight;
	char		tlabel[50];
	int		last_desk_done = MY_INT_MIN;
	int		next_desk;
	int		val1, val2, val1_unit, val2_unit, n;
	char		*t_hot;			/* Menu label with hotkey added */
	char		scut = '0';		/* Current short cut key */
	
	n = GetTwoArguments (action, &val1, &val2, &val1_unit, &val2_unit);

	sprintf (tlabel, "Desk corrente: %d\tGeometria", Scr.CurrentDesk);
	mr = NewMenuRoot (tlabel, 0);
	AddToMenu (mr, tlabel, "TITLE");      

	next_desk = 0;
	while (next_desk != MY_INT_MAX)
	{
		/* Sort window list by desktop number */
		if (val1 < 2 && val1 > -2)
		{
			next_desk = MY_INT_MAX;
			for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
			{
				if
				(	(t->Desk > last_desk_done) &&
					(t->Desk < next_desk)
				)
					next_desk = t->Desk;
			}
		}
		else if (val1 < 4 && val1 > -4)
		{
			if (last_desk_done  == MY_INT_MIN)
				next_desk = Scr.CurrentDesk;
			else
				next_desk = MY_INT_MAX;
		}
		else 
		{
			if (last_desk_done  == MY_INT_MIN)
				next_desk = val2;
			else
				next_desk = MY_INT_MAX;
		}

		last_desk_done = next_desk;
		for (t = Scr.FvwmRoot.next; t != NULL; t = t->next)
		{
			if
			(	t->Desk == next_desk &&
				(t->flags & WINDOWLISTSKIP) == 0
			)
			{
				if (++scut == ('9' + 1))
					scut = 'A';	/* Next shortcut key */

				if (val1 % 2 != 0)
					name = t->icon_name;
				else
					name = t->name;

				t_hot = safemalloc (strlen (name) + 48);
				sprintf (t_hot, "&%c.  %s", scut, name); /* Generate label */
	      
				tname = safemalloc(40);
				tname[0] = 0;

				if(t->flags & ICONIFIED)
					strcpy (tname, "(");

				sprintf (loc, "%d:", t->Desk);
				strcat (tname, loc);

				if (t->frame_x >= 0)
					sprintf (loc, "+%d", t->frame_x);
				else
					sprintf (loc, "%d", t->frame_x);

				strcat (tname, loc);

				if (t->frame_y >=0)
					sprintf (loc, "+%d", t->frame_y);
				else
					sprintf (loc, "%d", t->frame_y);

				strcat (tname, loc);

				dheight = t->frame_height - t->title_height - 2*t->boundary_width;
				dwidth = t->frame_width - 2*t->boundary_width;
	      
				dwidth -= t->hints.base_width;
				dheight -= t->hints.base_height;
	      
				dwidth /= t->hints.width_inc;
				dheight /= t->hints.height_inc;

				sprintf (loc, "x%d", dwidth);
				strcat (tname, loc);
				sprintf (loc, "x%d", dheight);
				strcat (tname, loc);

				if (t->flags & ICONIFIED)
					strcat (tname, ")");

				sprintf (tlabel, "RAISE_IT %ld %ld", t, t->w);
				strcat (t_hot, "\t");
				strcat (t_hot, tname);

				AddToMenu (mr, t_hot, tlabel);

				free (t_hot);
				free (tname);
			}
		}
	}

	MakeMenu (mr);

  /* If the menu is a result of a ButtonPress, then tell do_menu()
     to expect (and ignore) a button release event. Otherwise, it was
     as a result of a keypress or something, so we shouldn't expect
     a button release event. Fixes problem with keyboard short cuts not
     working if window list is popped up by keyboard.
         [email protected], 27/6/96 */

	if (eventp->type == ButtonPress)
		do_menu (mr,1);
	else
		do_menu (mr,0);

	DestroyMenu (mr);

}	/* end do_windowList */
Ejemplo n.º 20
0
INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	RECT rc, pos;
	HWND button;
	HMENU hMenu, hMenu1;
	TCHAR str[4096];
	switch (msg) {
	case WM_INITDIALOG:
		opt_startup = TRUE;
		// set windows position, make it top-most
		GetWindowRect(hdlg, &rc);
		SetWindowPos(hdlg, HWND_TOPMOST, rc.left, rc.top, 0, 0, SWP_NOSIZE);
		TranslateDialogDefault(hdlg);
		// generate the display text for variable list
		_tcscpy(str, TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temp\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set\n----------\n\\n\tnew line"));
		SetDlgItemText(hdlg, IDC_VARLIST, str);

		// make the more variable and other buttons flat
		SendDlgItemMessage(hdlg, IDC_MORE, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM1, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM2, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM3, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM4, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM5, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM6, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM7, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_TM8, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hdlg, IDC_RESET, BUTTONSETASFLATBTN, TRUE, 0);
		// load the settings
		LoadTextSettings(hdlg);
		opt_startup = FALSE;
		return TRUE;

	case WM_COMMAND:
		if (opt_startup)	return TRUE;
		switch (LOWORD(wParam)) {
		case IDC_CTEXT:
		case IDC_BTITLE:
		case IDC_BTEXT:
		case IDC_NTEXT:
		case IDC_XTEXT:
		case IDC_ETEXT:
		case IDC_HTEXT:
		case IDC_BTITLE2:
			if (HIWORD(wParam) == EN_CHANGE)
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_MORE:
			// display custom variables list
			MoreVarList();
			break;

		case IDC_TM1:
		case IDC_TM2:
		case IDC_TM3:
		case IDC_TM4:
		case IDC_TM5:
		case IDC_TM6:
		case IDC_TM7:
		case IDC_TM8:
			WEATHERINFO winfo;
			// display the menu
			button = GetDlgItem(hdlg, LOWORD(wParam));
			GetWindowRect(button, &pos);
			hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_TMMENU));
			hMenu1 = GetSubMenu(hMenu, 0);
			TranslateMenu(hMenu1);
			switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL)) {
			case ID_MPREVIEW:
				// show the preview in a message box, using the weather data from the default station
				winfo = LoadWeatherInfo(opt.DefStn);
				GetDisplay(&winfo, *var[LOWORD(wParam) - IDC_TM1], str);
				MessageBox(NULL, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST);
				break;

			case ID_MRESET:
				unsigned varo = LOWORD(wParam) - IDC_TM1;
				// remove the old setting from db and free memory
				TCHAR* vartmp = *var[varo];
				wfree(&vartmp);
				SetTextDefault(varname[varo]);
				SetDlgItemText(hdlg, cname[varo], *var[varo]);
				break;
			}
			DestroyMenu(hMenu);
			break;

		case IDC_RESET:
			// left click action selection menu
			button = GetDlgItem(hdlg, IDC_RESET);
			GetWindowRect(button, &pos);
			hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_TMENU));
			hMenu1 = GetSubMenu(hMenu, 0);
			TranslateMenu(hMenu1);
			switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL)) {
			case ID_T1:
				// reset to the strings in memory, discard all changes
				LoadTextSettings(hdlg);
				break;

			case ID_T2:
				// reset to the default setting
				FreeTextVar();
				SetTextDefault("CbBENHX");
				LoadTextSettings(hdlg);
				break;
			}
			DestroyMenu(hMenu);
			break;
		}
		return TRUE;
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			// save the option
			TCHAR textstr[MAX_TEXT_SIZE];
			// free memory for old settings
			FreeTextVar();
			// save new settings to memory
			GetDlgItemText(hdlg, IDC_CTEXT, textstr, SIZEOF(textstr));
			wSetData(&opt.cText, textstr);
			GetDlgItemText(hdlg, IDC_BTEXT, textstr, SIZEOF(textstr));
			wSetData(&opt.bText, textstr);
			GetDlgItemText(hdlg, IDC_BTITLE, textstr, SIZEOF(textstr));
			wSetData(&opt.bTitle, textstr);
			GetDlgItemText(hdlg, IDC_ETEXT, textstr, SIZEOF(textstr));
			wSetData(&opt.eText, textstr);
			GetDlgItemText(hdlg, IDC_NTEXT, textstr, SIZEOF(textstr));
			wSetData(&opt.nText, textstr);
			GetDlgItemText(hdlg, IDC_HTEXT, textstr, SIZEOF(textstr));
			wSetData(&opt.hText, textstr);
			GetDlgItemText(hdlg, IDC_XTEXT, textstr, SIZEOF(textstr));
			wSetData(&opt.xText, textstr);
			GetDlgItemText(hdlg, IDC_BTITLE2, textstr, SIZEOF(textstr));
			wSetData(&opt.sText, textstr);
			SaveOptions();
			UpdateAllInfo(0, 0);
			break;
		}
		break;
	}
	return FALSE;
}
Ejemplo n.º 21
0
// IDocHostUIHandler
STDMETHODIMP IEView::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispReserved) {
	IOleCommandTarget * pOleCommandTarget;
    IOleWindow * pOleWindow;
	HWND hSPWnd;
	if (builder == NULL) {
   //     return S_OK;
	}
#ifdef GECKO
	{
		return E_NOTIMPL;
/*
		HMENU hMenu;
		hMenu = GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXTMENU)),0);
		CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)hMenu,0);
		if (dwID == 6) { // anchor
			EnableMenuItem(hMenu, ID_MENU_COPYLINK, MF_BYCOMMAND | MF_ENABLED);
		} else if (dwID == 5) { // text select
			EnableMenuItem(hMenu, ID_MENU_COPY, MF_BYCOMMAND | MF_ENABLED);
		} else if (dwID == 1) { // control (image)
			EnableMenuItem(hMenu, ID_MENU_SAVEIMAGE, MF_BYCOMMAND | MF_ENABLED);
		}
		if (builder!=NULL) {

		}
		int iSelection = TrackPopupMenu(hMenu,
										  TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
										  ppt->x,
										  ppt->y,
										  0,
										  hwnd,
										  (RECT*)NULL);
		DestroyMenu(hMenu);
		if (iSelection == ID_MENU_CLEARLOG) {
			clear(NULL);
		} else {
			SendMessage(hSPWnd, WM_COMMAND, iSelection, (LPARAM) NULL);
		}
*/
	}
#else
    if (SUCCEEDED(pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&pOleCommandTarget))) {
		if (SUCCEEDED(pOleCommandTarget->QueryInterface(IID_IOleWindow, (void**)&pOleWindow))) {
    		pOleWindow->GetWindow(&hSPWnd);
			HMENU hMenu;
			hMenu = GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXTMENU)),0);
		 	CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)hMenu,0);
			if (dwID == 5) { // anchor
				EnableMenuItem(hMenu, ID_MENU_COPYLINK, MF_BYCOMMAND | MF_ENABLED);
			} else if (dwID == 4) { // text select
				EnableMenuItem(hMenu, ID_MENU_COPY, MF_BYCOMMAND | MF_ENABLED);
			} else if (dwID == 1) { // control (image)
				EnableMenuItem(hMenu, ID_MENU_SAVEIMAGE, MF_BYCOMMAND | MF_ENABLED);
			}
            if (builder!=NULL) {

			}
		 	int iSelection = TrackPopupMenu(hMenu,
		                                      TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
		                                      ppt->x,
		                                      ppt->y,
		                                      0,
		                                      hwnd,
		                                      (RECT*)NULL);
			DestroyMenu(hMenu);
			if (iSelection == ID_MENU_CLEARLOG) {
				clear(NULL);
			} else {
		    	SendMessage(hSPWnd, WM_COMMAND, iSelection, (LPARAM) NULL);
			}
    		pOleWindow->Release();
		}
	    pOleCommandTarget->Release();
	}
#endif
	return S_OK;
}
Ejemplo n.º 22
0
//subclass proc for the list view
BOOL CALLBACK PopupsListSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_CONTEXTMENU:
		{
			int x = LOWORD(lParam);
			int y = HIWORD(lParam);
			int selection;		
			
			HMENU hMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING, POPUPMENU_TITLE, TranslateT("Copy title to clipboard"));
			AppendMenu(hMenu, MF_STRING, POPUPMENU_MESSAGE, TranslateT("Copy message to clipboard"));
			AppendMenu(hMenu, MF_STRING, POPUPMENU_TIMESTAMP, TranslateT("Copy timestamp to clipboard"));
			selection = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, x, y, 0, hWnd, NULL);
			DestroyMenu(hMenu);
			if (selection)
			{
				CopyPopupDataToClipboard(hWnd, selection);
			}
		
			break;
		}
		
		case WM_KEYUP:
		{
			switch (wParam)
			{
				case 'C':
				{
					if (GetKeyState(VK_CONTROL))
					{
						CopyPopupDataToClipboard(hWnd, POPUPMENU_MESSAGE);
					}
					
					break;
				}
				
				case VK_ESCAPE:
				{
					SendMessage(GetParent(hWnd), WM_CLOSE, 0, 0);
					
					break;
				}
				
			}
			 
			break;
		}
		
		case WM_SYSKEYDOWN:
		{
			if (wParam == 'X')
			{
				SendMessage(GetParent(hWnd), WM_CLOSE, 0, 0);
			}
			
			break;
		}
	}
	
	return CallWindowProc(oldPopupsListProc, hWnd, msg, wParam, lParam);
}
Ejemplo n.º 23
0
void TaskManager_OnTabWndSelChange(void)
{
    int    i;
    HMENU  hMenu;
    HMENU  hOptionsMenu;
    HMENU  hViewMenu;
    HMENU  hSubMenu;
    WCHAR  szTemp[256];
    SYSTEM_INFO sysInfo;

    hMenu = GetMenu(hMainWnd);
    hViewMenu = GetSubMenu(hMenu, 2);
    hOptionsMenu = GetSubMenu(hMenu, 1);
    TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
    for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
        hSubMenu = GetSubMenu(hViewMenu, i);
        if (hSubMenu)
            DestroyMenu(hSubMenu);
        RemoveMenu(hViewMenu, i, MF_BYPOSITION);
    }
    RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
    switch (TaskManagerSettings.ActiveTabPage) {
    case 0:
        ShowWindow(hApplicationPage, SW_SHOW);
        ShowWindow(hProcessPage, SW_HIDE);
        ShowWindow(hPerformancePage, SW_HIDE);
        BringWindowToTop(hApplicationPage);

        LoadStringW(hInst, IDS_MENU_LARGEICONS, szTemp, 256);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, szTemp);

        LoadStringW(hInst, IDS_MENU_SMALLICONS, szTemp, 256);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, szTemp);

        LoadStringW(hInst, IDS_MENU_DETAILS, szTemp, 256);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, szTemp);

        if (GetMenuItemCount(hMenu) <= 4) {
            hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));

            LoadStringW(hInst, IDS_MENU_WINDOWS, szTemp, 256);
            InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR) hSubMenu, szTemp);

            DrawMenuBar(hMainWnd);
        }
        CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, TaskManagerSettings.ViewMode, MF_BYCOMMAND);

        /*
         * Give the application list control focus
         */
        SetFocus(hApplicationPageListCtrl);
        break;

    case 1:
        ShowWindow(hApplicationPage, SW_HIDE);
        ShowWindow(hProcessPage, SW_SHOW);
        ShowWindow(hPerformancePage, SW_HIDE);
        BringWindowToTop(hProcessPage);

        LoadStringW(hInst, IDS_MENU_SELECTCOLUMNS, szTemp, 256);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, szTemp);

        LoadStringW(hInst, IDS_MENU_16BITTASK, szTemp, 256);
        AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, szTemp);

        if (TaskManagerSettings.Show16BitTasks)
            CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
        if (GetMenuItemCount(hMenu) > 4)
        {
            DeleteMenu(hMenu, 3, MF_BYPOSITION);
            DrawMenuBar(hMainWnd);
        }
        /*
         * Give the process list control focus
         */
        SetFocus(hProcessPageListCtrl);
        break;

    case 2:
        ShowWindow(hApplicationPage, SW_HIDE);
        ShowWindow(hProcessPage, SW_HIDE);
        ShowWindow(hPerformancePage, SW_SHOW);
        BringWindowToTop(hPerformancePage);
        if (GetMenuItemCount(hMenu) > 4) {
            DeleteMenu(hMenu, 3, MF_BYPOSITION);
            DrawMenuBar(hMainWnd);
        }

        GetSystemInfo(&sysInfo);

        /* Hide CPU graph options on single CPU systems */
        if (sysInfo.dwNumberOfProcessors > 1)
        {
            hSubMenu = CreatePopupMenu();

            LoadStringW(hInst, IDS_MENU_ONEGRAPHALLCPUS, szTemp, 256);
            AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, szTemp);

            LoadStringW(hInst, IDS_MENU_ONEGRAPHPERCPU, szTemp, 256);
            AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, szTemp);

            LoadStringW(hInst, IDS_MENU_CPUHISTORY, szTemp, 256);
            AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR) hSubMenu, szTemp);

            if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
                CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
            else
                CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
        }

        LoadStringW(hInst, IDS_MENU_SHOWKERNELTIMES, szTemp, 256);
        AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, szTemp);

        if (TaskManagerSettings.ShowKernelTimes)
            CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
        else
            CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);

        /*
         * Give the tab control focus
         */
        SetFocus(hTabWnd);
        break;
    }
}
HRESULT STDMETHODCALLTYPE playlists_tabs_extension::playlists_tabs_drop_target::Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
{
	POINT pt = { ptl.x, ptl.y };
	bool isAltDown = (grfKeyState & MK_ALT) != 0;
	if (m_DropTargetHelper.is_valid()) m_DropTargetHelper->Drop(pDataObj, &pt, *pdwEffect);

	p_list->kill_switch_timer();
	m_DataObject.release();
	last_over.x = 0;
	last_over.y = 0;

	if (!m_is_accepted_type)
	{
		mmh::ole::SetDropDescription(m_DataObject.get_ptr(), DROPIMAGE_INVALID, "", "");
		return S_OK;
	}

	static_api_ptr_t<playlist_manager> playlist_api;

	POINT pti, ptm;
	pti.y = pt.y;
	pti.x = pt.x;

	ptm = pti;
	ScreenToClient(p_list->get_wnd(), &ptm);

	HWND wnd = ChildWindowFromPointEx(p_list->get_wnd(), ptm, CWP_SKIPINVISIBLE);

	if (wnd)
	{

		bool process = !ui_drop_item_callback::g_on_drop(pDataObj);

		bool send_new_playlist = false;

		if (process && m_last_rmb)
		{
			process = false;
			enum { ID_DROP = 1, ID_NEW_PLAYLIST, ID_CANCEL };

			HMENU menu = CreatePopupMenu();

			uAppendMenu(menu, (MF_STRING), ID_DROP, "&Add files here");
			uAppendMenu(menu, (MF_STRING), ID_NEW_PLAYLIST, "&Add files to new playlist");
			uAppendMenu(menu, MF_SEPARATOR, 0, 0);
			uAppendMenu(menu, MF_STRING, ID_CANCEL, "&Cancel");

			int cmd = TrackPopupMenu(menu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, p_list->get_wnd(), 0);
			DestroyMenu(menu);

			if (cmd)
			{
				switch (cmd)
				{
				case ID_DROP:
					process = true;
					break;
				case ID_NEW_PLAYLIST:
					process = true;
					send_new_playlist = true;
					break;
				}
			}
		}

		if (process)
		{
			metadb_handle_list data;
			static_api_ptr_t<playlist_incoming_item_filter> incoming_api;
			incoming_api->process_dropped_files(pDataObj, data, true, p_list->get_wnd());

			POINT pttab, ptpl;
			pttab = pti;
			ptpl = pti;


			int idx = -1;
			t_size newPlaylistIndex = pfc_infinite;
			//	if ((g_tab && wnd == g_tab) || g_plist && wnd == g_plist)


			//	bool processed = false;
			t_size target_index = playlist_api->get_active_playlist();


			if (p_list->wnd_tabs && wnd == p_list->wnd_tabs)
			{
				RECT tabs;

				GetWindowRect(p_list->wnd_tabs, &tabs);
				if (ScreenToClient(p_list->wnd_tabs, &pttab))
				{
					TCHITTESTINFO hittest;
					hittest.pt.x = pttab.x;
					hittest.pt.y = pttab.y;
					int idx = TabCtrl_HitTest(p_list->wnd_tabs, &hittest);
					int old = playlist_api->get_active_playlist();
					if (send_new_playlist || idx < 0 || isAltDown)
					{
						send_new_playlist = true;
						if (idx >= 0)
							newPlaylistIndex = idx;
					}
					else target_index = idx;
				}

			}


			if (send_new_playlist)
			{
				pfc::string8 playlist_name("Untitled");

				bool named = false;

				if (1 || 1)
				{
					FORMATETC   fe;
					STGMEDIUM   sm;
					HRESULT     hr = E_FAIL;

					//					memset(&sm, 0, sizeof(0));

					fe.cfFormat = CF_HDROP;
					fe.ptd = NULL;
					fe.dwAspect = DVASPECT_CONTENT;
					fe.lindex = -1;
					fe.tymed = TYMED_HGLOBAL;

					// User has dropped on us. Get the data from drag source
					hr = pDataObj->GetData(&fe, &sm);
					if (SUCCEEDED(hr))
					{

						// Display the data and release it.
						pfc::string8 temp;

						unsigned int /*n,*/t = uDragQueryFileCount((HDROP)sm.hGlobal);
						if (t == 1)
						{
							{
								uDragQueryFile((HDROP)sm.hGlobal, 0, temp);
								if (uGetFileAttributes(temp) & FILE_ATTRIBUTE_DIRECTORY)
								{
									playlist_name.set_string(pfc::string_filename_ext(temp));
									named = true;
								}
								else
								{
									playlist_name.set_string(pfc::string_filename(temp));
									named = true;
#if 0
									pfc::string_extension ext(temp);

									service_enum_t<playlist_loader> e;
									service_ptr_t<playlist_loader> l;
									if (e.first(l))
										do
										{
											if (!strcmp(l->get_extension(), ext))
											{
												playlist_name.set_string(pfc::string_filename(temp));
												named = true;
												l.release();
												break;
											}
											l.release();
										} while (e.next(l));
#endif
								}

							}
						}

						ReleaseStgMedium(&sm);
					}
				}

				unsigned new_idx;
				if (newPlaylistIndex == pfc_infinite)
					newPlaylistIndex = playlist_api->get_playlist_count();

				if (named && cfg_replace_drop_underscores) playlist_name.replace_char('_', ' ', 0);
				if (!named && cfg_pgen_tf) new_idx = playlist_api->create_playlist(string_pn(data, cfg_pgenstring), pfc_infinite, newPlaylistIndex);

				else  new_idx = playlist_api->create_playlist(playlist_name, pfc_infinite, newPlaylistIndex);

				playlist_api->playlist_add_items(new_idx, data, bit_array_false());
				if (main_window::config_get_activate_target_playlist_on_dropped_items())
					playlist_api->set_active_playlist(new_idx);

			}
			else
			{
				playlist_api->playlist_clear_selection(target_index);
				playlist_api->playlist_insert_items(target_index, idx, data, bit_array_true());
				if (main_window::config_get_activate_target_playlist_on_dropped_items())
					playlist_api->set_active_playlist(target_index);
			}

			data.remove_all();
		}
	}

	return S_OK;
}
Ejemplo n.º 25
0
INT_PTR CJabberDlgGcJoin::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_DELETEITEM:
		{
			LPDELETEITEMSTRUCT lpdis = (LPDELETEITEMSTRUCT)lParam;
			if (lpdis->CtlID != IDC_ROOM)
				break;

			RoomInfo *info = (RoomInfo *)lpdis->itemData;
			mir_free(info->line1);
			mir_free(info->line2);
			mir_free(info);
		}
		break;

	case WM_MEASUREITEM:
		{
			LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam;
			if (lpmis->CtlID != IDC_ROOM)
				break;

			lpmis->itemHeight = 2 * sttTextLineHeight;
			if (lpmis->itemID == -1)
				lpmis->itemHeight = sttTextLineHeight - 1;

		}
		break;

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
			if (lpdis->CtlID != IDC_ROOM)
				break;

			RoomInfo *info = (RoomInfo *)SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_GETITEMDATA, lpdis->itemID, 0);
			COLORREF clLine1, clBack;

			if (lpdis->itemState & ODS_SELECTED) {
				FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
				clBack = GetSysColor(COLOR_HIGHLIGHT);
				clLine1 = GetSysColor(COLOR_HIGHLIGHTTEXT);
			}
			else {
				FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_WINDOW));
				clBack = GetSysColor(COLOR_WINDOW);
				clLine1 = GetSysColor(COLOR_WINDOWTEXT);
			}
			COLORREF clLine2 = RGB(
				GetRValue(clLine1) * 0.66 + GetRValue(clBack) * 0.34,
				GetGValue(clLine1) * 0.66 + GetGValue(clBack) * 0.34,
				GetBValue(clLine1) * 0.66 + GetBValue(clBack) * 0.34);

			SetBkMode(lpdis->hDC, TRANSPARENT);

			RECT rc = lpdis->rcItem;
			rc.bottom -= (rc.bottom - rc.top) / 2;
			rc.left += 20;
			SetTextColor(lpdis->hDC, clLine1);
			DrawText(lpdis->hDC, info->line1, -1, &rc, DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);

			rc = lpdis->rcItem;
			rc.top += (rc.bottom - rc.top) / 2;
			rc.left += 20;
			SetTextColor(lpdis->hDC, clLine2);
			DrawText(lpdis->hDC, info->line2, -1, &rc, DT_LEFT | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS);

			DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("group"), 16, 16, 0, NULL, DI_NORMAL);
			switch (info->overlay) {
			case RoomInfo::ROOM_WAIT:
				DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("disco_progress"), 16, 16, 0, NULL, DI_NORMAL);
				break;
			case RoomInfo::ROOM_FAIL:
				DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("disco_fail"), 16, 16, 0, NULL, DI_NORMAL);
				break;
			case RoomInfo::ROOM_BOOKMARK:
				DrawIconEx(lpdis->hDC, lpdis->rcItem.left + 1, lpdis->rcItem.top + 1, m_proto->LoadIconEx("disco_ok"), 16, 16, 0, NULL, DI_NORMAL);
				break;
			}
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_SERVER:
			switch (HIWORD(wParam)) {
			case CBN_EDITCHANGE:
			case CBN_SELCHANGE:
				{
					int iqid = GetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA);
					if (iqid) {
						m_proto->m_iqManager.ExpireIq(iqid);
						SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA, 0);
					}
					SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_RESETCONTENT, 0, 0);
				}
				break;
			}
			break;

		case IDC_ROOM:
			switch (HIWORD(wParam)) {
			case CBN_DROPDOWN:
				if (!SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_GETCOUNT, 0, 0)) {
					int iqid = GetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA);
					if (iqid) {
						m_proto->m_iqManager.ExpireIq(iqid);
						SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA, 0);
					}

					SendDlgItemMessage(m_hwnd, IDC_ROOM, CB_RESETCONTENT, 0, 0);

					int len = GetWindowTextLength(GetDlgItem(m_hwnd, IDC_SERVER)) + 1;
					TCHAR *server = (TCHAR*)_alloca(len * sizeof(TCHAR));
					GetDlgItemText(m_hwnd, IDC_SERVER, server, len);

					if (*server) {
						sttRoomListAppend(GetDlgItem(m_hwnd, IDC_ROOM), RoomInfo::ROOM_WAIT, TranslateT("Loading..."), TranslateT("Please wait for room list to download."), _T(""));

						CJabberIqInfo *pInfo = m_proto->AddIQ(&CJabberProto::OnIqResultDiscovery, JABBER_IQ_TYPE_GET, server, 0, -1, (void*)GetDlgItem(m_hwnd, IDC_ROOM));
						pInfo->SetTimeout(30000);
						XmlNodeIq iq(pInfo);
						iq << XQUERY(JABBER_FEAT_DISCO_ITEMS);
						m_proto->m_ThreadInfo->send(iq);

						SetWindowLongPtr(GetDlgItem(m_hwnd, IDC_ROOM), GWLP_USERDATA, pInfo->GetIqId());
					}
					else
						sttRoomListAppend(GetDlgItem(m_hwnd, IDC_ROOM), RoomInfo::ROOM_FAIL,
						TranslateT("Jabber Error"),
						TranslateT("Please specify group chat directory first."),
						_T(""));
				}
				break;
			}
			break;

		case IDC_BOOKMARKS:
			{
				HMENU hMenu = CreatePopupMenu();

				LISTFOREACH(i, m_proto, LIST_BOOKMARK)
				{
					JABBER_LIST_ITEM *item = 0;
					if (item = m_proto->ListGetItemPtrFromIndex(i))
						if (!mir_tstrcmp(item->type, _T("conference")))
							AppendMenu(hMenu, MF_STRING, (UINT_PTR)item, item->name);
				}
				AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
				AppendMenu(hMenu, MF_STRING, (UINT_PTR)-1, TranslateT("Bookmarks..."));
				AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel"));

				RECT rc; GetWindowRect(GetDlgItem(m_hwnd, IDC_BOOKMARKS), &rc);
				CheckDlgButton(m_hwnd, IDC_BOOKMARKS, BST_CHECKED);
				int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, m_hwnd, NULL);
				CheckDlgButton(m_hwnd, IDC_BOOKMARKS, BST_UNCHECKED);
				DestroyMenu(hMenu);

				if (res == -1)
					m_proto->OnMenuHandleBookmarks(0, 0);
				else if (res) {
					JABBER_LIST_ITEM *item = (JABBER_LIST_ITEM *)res;
					TCHAR *room = NEWTSTR_ALLOCA(item->jid);
					if (room) {
						TCHAR *server = _tcschr(room, _T('@'));
						if (server) {
							*server++ = 0;

							SendMessage(m_hwnd, WM_COMMAND, MAKEWPARAM(IDC_SERVER, CBN_EDITCHANGE), (LPARAM)GetDlgItem(m_hwnd, IDC_SERVER));

							SetDlgItemText(m_hwnd, IDC_SERVER, server);
							SetDlgItemText(m_hwnd, IDC_ROOM, room);
							SetDlgItemText(m_hwnd, IDC_NICK, item->nick);
							SetDlgItemText(m_hwnd, IDC_PASSWORD, item->password);
						}
					}
				}
			}
			break;

		case IDC_RECENT1:
		case IDC_RECENT2:
		case IDC_RECENT3:
		case IDC_RECENT4:
		case IDC_RECENT5:
			JabberGcRecentInfo info(m_proto, LOWORD(wParam) - IDC_RECENT1);
			info.fillForm(m_hwnd);
			if (GetAsyncKeyState(VK_CONTROL))
				break;

			OnBtnOk(NULL);
			Close();
		}
		break;

	case WM_JABBER_CHECK_ONLINE:
		if (!m_proto->m_bJabberOnline)
			EndDialog(m_hwnd, 0);
		break;
	}
Ejemplo n.º 26
0
LRESULT album_list_window::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{

	switch (msg)
	{
	case WM_CREATE:
	{
		list_wnd.add_item(this);

		initialised = true;

		modeless_dialog_manager::g_add(wnd);

		m_dd_theme = IsThemeActive() && IsAppThemed() ? OpenThemeData(wnd, VSCLASS_DRAGDROP) : NULL;

		create_tree();
		create_filter();

		if (cfg_populate) refresh_tree();

		static_api_ptr_t<library_manager_v3>()->register_callback(this);
	}
	break;
	case WM_THEMECHANGED:
	{
		if (m_dd_theme) CloseThemeData(m_dd_theme);
		m_dd_theme = IsThemeActive() && IsAppThemed() ? OpenThemeData(wnd, VSCLASS_DRAGDROP) : NULL;
	}
	break;
	/*case WM_GETMINMAXINFO:
	{
	LPMINMAXINFO mmi = LPMINMAXINFO(lp);
	mmi->ptMinTrackSize.y = cfg_height;
	return 0;
	}*/
	case WM_SIZE:
		on_size(LOWORD(lp), HIWORD(lp));
		break;
		/*	case DM_GETDEFID:
		return (DC_HASDEFID<<16|IDOK);
		case WM_GETDLGCODE:
		return DLGC_DEFPUSHBUTTON;*/
		//		break;
	case WM_TIMER:
		if (wp == EDIT_TIMER_ID)
		{
			refresh_tree();
			KillTimer(wnd, wp);
			m_timer = false;
		}
		break;
	case WM_COMMAND:
		switch (wp)
		{
		case IDC_FILTER | (EN_CHANGE << 16) :
			if (m_timer)
				KillTimer(wnd_edit, 500);
			m_timer = SetTimer(wnd, EDIT_TIMER_ID, 500, NULL) != 0;
			return TRUE;
		case IDOK:
			if (GetKeyState(VK_SHIFT) & KF_UP) do_playlist(p_selection, false);
			else if (GetKeyState(VK_CONTROL) & KF_UP) do_playlist(p_selection, true, true);
			else do_playlist(p_selection, true);
			return 0;
		}
		break;
	case WM_CONTEXTMENU:
	{
		enum { ID_SEND = 1, ID_ADD, ID_NEW, ID_AUTOSEND, ID_REFRESH, ID_FILT, ID_CONF, ID_VIEW_BASE };

		HMENU menu = CreatePopupMenu();

		POINT pt = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
		service_ptr_t<contextmenu_manager> p_menu_manager;

		unsigned IDM_MANAGER_BASE = 0;

		HWND list = wnd_tv;

		HTREEITEM treeitem = NULL;

		TVHITTESTINFO ti;
		memset(&ti, 0, sizeof(ti));

		if (pt.x != -1 && pt.y != -1)
		{
			ti.pt = pt;
			ScreenToClient(list, &ti.pt);
			uSendMessage(list, TVM_HITTEST, 0, (long)&ti);
			if (ti.hItem && (ti.flags & TVHT_ONITEM))
			{
				//FIX THIS AND AUTOSEND
				//TreeView_Select(list, ti.hItem, TVGN_DROPHILITE);
				//uSendMessage(list,TVM_SELECTITEM,TVGN_DROPHILITE,(long)ti.hItem);
				treeitem = ti.hItem;
			}
		}
		else
		{
			treeitem = TreeView_GetSelection(list);
			RECT rc;
			if (treeitem && TreeView_GetItemRect(wnd_tv, treeitem, &rc, TRUE))
			{
				MapWindowPoints(wnd_tv, HWND_DESKTOP, (LPPOINT)&rc, 2);

				pt.x = rc.left;
				pt.y = rc.top + (rc.bottom - rc.top) / 2;

			}
			else
			{
				GetMessagePos(&pt);
			}
		}

		TreeView_Select(list, treeitem, TVGN_DROPHILITE);

		HMENU menu_view = CreatePopupMenu();
		unsigned n, m = cfg_view_list.get_count();
		string8_fastalloc temp;
		temp.prealloc(32);

		uAppendMenu(menu_view, MF_STRING | (!stricmp_utf8(directory_structure_view_name, view) ? MF_CHECKED : 0), ID_VIEW_BASE + 0, directory_structure_view_name);

		list_t<string_simple, pfc::alloc_fast> views;

		views.add_item(string_simple(directory_structure_view_name));

		for (n = 0; n<m; n++)
		{
			temp = cfg_view_list.get_name(n);
			string_simple item(temp.get_ptr());

			if (item)
			{
				uAppendMenu(menu_view, MF_STRING | (!stricmp_utf8(temp, view) ? MF_CHECKED : 0), ID_VIEW_BASE + views.add_item(item), temp);
			}

		}


		IDM_MANAGER_BASE = ID_VIEW_BASE + views.get_count();

		uAppendMenu(menu, MF_STRING | MF_POPUP, (UINT)menu_view, "View");

		if (!m_populated && !cfg_populate)
			uAppendMenu(menu, MF_STRING, ID_REFRESH, "Populate");
		uAppendMenu(menu, MF_STRING | (m_filter ? MF_CHECKED : 0), ID_FILT, "Filter");
		uAppendMenu(menu, MF_STRING, ID_CONF, "Settings");

		bool show_shortcuts = standard_config_objects::query_show_keyboard_shortcuts_in_menus();

		node * p_node = NULL;
		TVITEMEX tvi;
		memset(&tvi, 0, sizeof(tvi));
		tvi.hItem = treeitem;
		tvi.mask = TVIF_HANDLE | TVIF_PARAM;
		TreeView_GetItem(list, &tvi);
		p_node = (node*)tvi.lParam;

		if (treeitem && p_node)
		{
			uAppendMenu(menu, MF_SEPARATOR, 0, "");
			uAppendMenu(menu, MF_STRING, ID_SEND, (show_shortcuts ? "&Send to playlist\tEnter" : "&Send to playlist"));
			uAppendMenu(menu, MF_STRING, ID_ADD, show_shortcuts ? "&Add to playlist\tShift+Enter" : "&Add to playlist");
			uAppendMenu(menu, MF_STRING, ID_NEW, show_shortcuts ? "Send to &new playlist\tCtrl+Enter" : "Send to &new playlist");
			uAppendMenu(menu, MF_STRING, ID_AUTOSEND, "Send to &autosend playlist");

			uAppendMenu(menu, MF_SEPARATOR, 0, "");

			contextmenu_manager::g_create(p_menu_manager);
			p_node->sort_entries();

			if (p_menu_manager.is_valid())
			{
				p_menu_manager->init_context(p_node->get_entries(), 0);

				p_menu_manager->win32_build_menu(menu, IDM_MANAGER_BASE, -1);
				menu_helpers::win32_auto_mnemonics(menu);
			}
		}

		int cmd = TrackPopupMenu(menu, TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, get_wnd(), 0);
		DestroyMenu(menu);

		TreeView_Select(list, NULL, TVGN_DROPHILITE);

		if (cmd)
		{
			if (p_menu_manager.is_valid() && (unsigned)cmd >= IDM_MANAGER_BASE)
			{
				p_menu_manager->execute_by_id(cmd - IDM_MANAGER_BASE);
			}
			else if (cmd >= ID_VIEW_BASE)
			{
				unsigned n = cmd - ID_VIEW_BASE;
				if (n<views.get_count())
				{
					view = views[n].get_ptr();
					refresh_tree();
				}
			}
			else if (cmd<ID_VIEW_BASE)
			{
				unsigned cmd2 = 0;
				switch (cmd)
				{
				case ID_NEW:
					do_playlist(p_node, true, true);
					break;
				case ID_SEND:
					do_playlist(p_node, true);
					break;
				case ID_ADD:
					do_playlist(p_node, false);
					break;
				case ID_AUTOSEND:
					do_autosend_playlist(p_node, view, true);
					break;
				case ID_CONF:
				{
					static_api_ptr_t<ui_control>()->show_preferences(g_guid_preferences_album_list_panel);
				}
				break;
				case ID_FILT:
				{
					m_filter = !m_filter;
					create_or_destroy_filter();
				}
				break;
				case ID_REFRESH:
					if (!m_populated && !cfg_populate)
						refresh_tree();
					break;
				}
				if (cmd2) uSendMessage(get_wnd(), WM_COMMAND, cmd2, 0);
			}
		}

		p_menu_manager.release();

		/*			if (treeitem_context && (treeitem_context != treeitem) && cfg_autosend)
		TreeView_SelectItem(wnd_tv,treeitem);*/


	}
	return 0;
	case WM_NOTIFY:
	{
		LPNMHDR hdr = (LPNMHDR)lp;

		switch (hdr->idFrom)
		{

		case IDC_TREE:
		{
			if (hdr->code == TVN_ITEMEXPANDING)
			{
				LPNMTREEVIEW param = (LPNMTREEVIEW)hdr;
				if (cfg_picmixer && (param->action == TVE_EXPAND))
				{
					TreeView_CollapseOtherNodes(param->hdr.hwndFrom, param->itemNew.hItem);
				}
			}

			else if (hdr->code == TVN_SELCHANGED)
			{
				LPNMTREEVIEW param = (LPNMTREEVIEW)hdr;

				p_selection = (node*)param->itemNew.lParam;
				if ((param->action == TVC_BYMOUSE || param->action == TVC_BYKEYBOARD))
				{
					if (cfg_autosend)
						do_autosend_playlist(p_selection, view);
				}
				if (m_selection_holder.is_valid())
				{
					m_selection_holder->set_selection(p_selection.is_valid() ? p_selection->get_entries() : metadb_handle_list());
				}
#if 0
				if (cfg_picmixer)
				{
					HTREEITEM ti_parent_old = TreeView_GetParent(param->hdr.hwndFrom, param->itemOld.hItem);
					HTREEITEM ti_parent_new = TreeView_GetParent(param->hdr.hwndFrom, param->itemNew.hItem);

					if (/*ti_parent_old != param->itemNew.hItem &&  */!TreeView_IsChild(param->hdr.hwndFrom, param->itemNew.hItem, param->itemOld.hItem))
					{
						HTREEITEM ti = //TreeView_GetLevel(param->hdr.hwndFrom, param->itemNew.hItem) < TreeView_GetLevel(param->hdr.hwndFrom, param->itemOld.hItem) ? 
							TreeView_GetCommonParentChild(param->hdr.hwndFrom, param->itemOld.hItem, param->itemNew.hItem)
							//: param->itemOld.hItem
							;
						if (ti && ti != TVI_ROOT) TreeView_Expand(param->hdr.hwndFrom, ti, TVE_COLLAPSE);
					}

					if (ti_parent_new)
					{

						HTREEITEM child = TreeView_GetChild(param->hdr.hwndFrom, ti_parent_new);
						while (child)
						{
							if (child != param->itemNew.hItem)
							{

							}
						}
					}
				}
#endif
			}
		}
		break;
		}

	}
	break;
	case WM_DESTROY:
		static_api_ptr_t<library_manager_v3>()->unregister_callback(this);
		modeless_dialog_manager::g_remove(wnd);
		destroy_tree();
		destroy_filter();
		m_selection_holder.release();
		m_root.release();
		p_selection.release();
		if (m_dd_theme)
		{
			CloseThemeData(m_dd_theme);
			m_dd_theme = NULL;
		}

		if (initialised)
		{
			list_wnd.remove_item(this);
			if (list_wnd.get_count() == 0)
			{
				DeleteFont(g_font);
				g_font = 0;
			}
			initialised = false;
		}
		break;
	}
	return DefWindowProc(wnd, msg, wp, lp);
}
Ejemplo n.º 27
0
INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			TCHAR szPath[450];
			CLISTEVENT* cle = (CLISTEVENT*)lParam;

			dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData));
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
			dat->hContact = cle->hContact;
			dat->hDbEvent = cle->hDbEvent;
			dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN);
			dat->dwTicks = GetTickCount();

			EnumChildWindows(hwndDlg, ClipSiblingsChildEnumProc, 0);

			Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE);
			Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list"));
			Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details"));
			Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history"));
			Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu"));

			TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0);
			SetDlgItemText(hwndDlg, IDC_FROM, contactName);
			GetContactReceivedFilesDir(dat->hContact, szPath, SIZEOF(szPath), TRUE);
			SetDlgItemText(hwndDlg, IDC_FILEDIR, szPath);
			SHAutoComplete(GetWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), GW_CHILD), 1);

			for (int i = 0; i < MAX_MRU_DIRS; i++) {
				char idstr[32];
				mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i);

				DBVARIANT dbv;
				if (db_get_ts(NULL, "SRFile", idstr, &dbv))
					break;
				SendDlgItemMessage(hwndDlg, IDC_FILEDIR, CB_ADDSTRING, 0, (LPARAM)dbv.ptszVal);
				db_free(&dbv);
			}

			db_event_markRead(dat->hContact, dat->hDbEvent);

			DBEVENTINFO dbei = { sizeof(dbei) };
			dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent);
			if (dbei.cbBlob > 4 && dbei.cbBlob <= 8196) {
				dbei.pBlob = (PBYTE)alloca(dbei.cbBlob + 1);
				db_event_get(dat->hDbEvent, &dbei);
				dbei.pBlob[dbei.cbBlob] = 0;
				dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob;

				char *str = (char*)dbei.pBlob + 4;
				ptrT ptszFileName(DbGetEventStringT(&dbei, str));
				SetDlgItemText(hwndDlg, IDC_FILENAMES, ptszFileName);

				unsigned len = (unsigned)strlen(str) + 1;
				if (len + 4 < dbei.cbBlob) {
					str += len;
					ptrT ptszDescription(DbGetEventStringT(&dbei, str));
					SetDlgItemText(hwndDlg, IDC_MSG, ptszDescription);
				}
			}
			else DestroyWindow(hwndDlg);

			TCHAR datetimestr[64];
			tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0);
			SetDlgItemText(hwndDlg, IDC_DATE, datetimestr);

			char* szProto = GetContactProto(dat->hContact);
			if (szProto) {
				int hasName = 0;
				char buf[128];

				CONTACTINFO ci = { 0 };
				ci.cbSize = sizeof(ci);
				ci.hContact = dat->hContact;
				ci.szProto = szProto;
				ci.dwFlag = CNF_UNIQUEID;
				if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
					switch (ci.type) {
					case CNFT_ASCIIZ:
						hasName = 1;
						mir_snprintf(buf, SIZEOF(buf), "%s", ci.pszVal);
						mir_free(ci.pszVal);
						break;
					case CNFT_DWORD:
						hasName = 1;
						mir_snprintf(buf, SIZEOF(buf), "%u", ci.dVal);
						break;
					}
				}
				if (hasName)
					SetDlgItemTextA(hwndDlg, IDC_NAME, buf);
				else
					SetDlgItemText(hwndDlg, IDC_NAME, contactName);
			}

			if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) {
				RECT rcBtn1, rcBtn2, rcDateCtrl;
				GetWindowRect(GetDlgItem(hwndDlg, IDC_ADD), &rcBtn1);
				GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rcBtn2);
				GetWindowRect(GetDlgItem(hwndDlg, IDC_DATE), &rcDateCtrl);
				SetWindowPos(GetDlgItem(hwndDlg, IDC_DATE), 0, 0, 0, rcDateCtrl.right - rcDateCtrl.left - (rcBtn2.left - rcBtn1.left), rcDateCtrl.bottom - rcDateCtrl.top, SWP_NOZORDER | SWP_NOMOVE);
			}
			else if (db_get_b(NULL, "SRFile", "AutoAccept", 0)) {
				//don't check auto-min here to fix BUG#647620
				PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDOK));
			}
			if (!db_get_b(dat->hContact, "CList", "NotOnList", 0))
				ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE);
		}
		return TRUE;

	case WM_MEASUREITEM:
		return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
			if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) {
				char *szProto = GetContactProto(dat->hContact);
				if (szProto) {
					HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0);
					if (hIcon) {
						DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
						DestroyIcon(hIcon);
		}	}	}	}
		return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);

	case WM_COMMAND:
		if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact))
			break;

		switch (LOWORD(wParam)) {
		case IDC_FILEDIRBROWSE:
			{
				TCHAR szDirName[MAX_PATH], szExistingDirName[MAX_PATH];

				GetDlgItemText(hwndDlg, IDC_FILEDIR, szDirName, SIZEOF(szDirName));
				GetLowestExistingDirName(szDirName, szExistingDirName, SIZEOF(szExistingDirName));
				if (BrowseForFolder(hwndDlg, szExistingDirName))
					SetDlgItemText(hwndDlg, IDC_FILEDIR, szExistingDirName);
			}
			break;

		case IDOK:
			{	//most recently used directories
				TCHAR szRecvDir[MAX_PATH], szDefaultRecvDir[MAX_PATH];
				GetDlgItemText(hwndDlg, IDC_FILEDIR, szRecvDir, SIZEOF(szRecvDir));
				RemoveInvalidPathChars(szRecvDir);
				GetContactReceivedFilesDir(NULL, szDefaultRecvDir, SIZEOF(szDefaultRecvDir), TRUE);
				if (_tcsnicmp(szRecvDir, szDefaultRecvDir, lstrlen(szDefaultRecvDir))) {
					char idstr[32];
					int i;
					DBVARIANT dbv;
					for (i = MAX_MRU_DIRS-2;i>=0;i--) {
						mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i);
						if (db_get_ts(NULL, "SRFile", idstr, &dbv)) continue;
						mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i+1);
						db_set_ts(NULL, "SRFile", idstr, dbv.ptszVal);
						db_free(&dbv);
					}
					db_set_ts(NULL, "SRFile", idstr, szRecvDir);
				}
			}
			EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAMES), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_FILEDIRBROWSE), FALSE);

			GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, SIZEOF(dat->szSavePath));
			GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, SIZEOF(dat->szFilenames));
			GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, SIZEOF(dat->szMsg));
			dat->hwndTransfer = FtMgr_AddTransfer(dat);
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
			//check for auto-minimize here to fix BUG#647620
			if (db_get_b(NULL, "SRFile", "AutoAccept", 0) && db_get_b(NULL, "SRFile", "AutoMin", 0)) {
				ShowWindow(hwndDlg, SW_HIDE);
				ShowWindow(hwndDlg, SW_SHOWMINNOACTIVE);
			}
			DestroyWindow(hwndDlg);
			break;

		case IDCANCEL:
			if (dat->fs) CallContactService(dat->hContact, PSS_FILEDENYT, (WPARAM)dat->fs, (LPARAM)TranslateT("Canceled"));
			dat->fs = NULL; /* the protocol will free the handle */
			DestroyWindow(hwndDlg);
			break;

		case IDC_ADD:
			{	
				ADDCONTACTSTRUCT acs = { 0 };
				acs.hContact = dat->hContact;
				acs.handleType = HANDLE_CONTACT;
				acs.szProto = "";
				CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
				if (!db_get_b(dat->hContact, "CList", "NotOnList", 0))
					ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE);
			}
			break;

		case IDC_USERMENU:
			{
				RECT rc;
				HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0);
				GetWindowRect((HWND)lParam, &rc);
				TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
				DestroyMenu(hMenu);
			}
			break;

		case IDC_DETAILS:
			CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0);
			break;

		case IDC_HISTORY:
			CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0);
			break;
		}
		break;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);

		if (dat) FreeFileDlgData(dat);
		break;
	}
	return FALSE;
}
Ejemplo n.º 28
0
INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			struct FileSendData *fsd = (struct FileSendData*)lParam;

			dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData));
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
			dat->hContact = fsd->hContact;
			dat->send = 1;
			dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN);
			dat->fs = NULL;
			dat->dwTicks = GetTickCount();

			EnumChildWindows(hwndDlg, ClipSiblingsChildEnumProc, 0);
			mir_subclassWindow(GetDlgItem(hwndDlg, IDC_MSG), SendEditSubclassProc);

			Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE);
			Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details"));
			Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history"));
			Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu"));

			EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);

			if (fsd->ppFiles != NULL && fsd->ppFiles[0] != NULL) {
				int totalCount, i;
				for (totalCount = 0; fsd->ppFiles[totalCount]; totalCount++);
				dat->files = (TCHAR**)mir_alloc(sizeof(TCHAR*)*(totalCount + 1)); // Leaks
				for (i = 0; i < totalCount; i++)
					dat->files[i] = mir_tstrdup(fsd->ppFiles[i]);
				dat->files[totalCount] = NULL;
				SetFileListAndSizeControls(hwndDlg, dat);
			}

			TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0);
			SetDlgItemText(hwndDlg, IDC_TO, contactName);

			char *szProto = GetContactProto(dat->hContact);
			if (szProto) {
				int hasName = 0;
				char buf[128];

				CONTACTINFO ci = { sizeof(ci) };
				ci.hContact = dat->hContact;
				ci.szProto = szProto;
				ci.dwFlag = CNF_UNIQUEID;
				if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
					switch (ci.type) {
					case CNFT_ASCIIZ:
						hasName = 1;
						strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE);
						mir_free(ci.pszVal);
						break;
					case CNFT_DWORD:
						hasName = 1;
						mir_snprintf(buf, "%u", ci.dVal);
						break;
					}
				}

				if (hasName)
					SetDlgItemTextA(hwndDlg, IDC_NAME, buf);
				else
					SetDlgItemText(hwndDlg, IDC_NAME, contactName);
			}

			if (fsd->ppFiles == NULL) {
				EnableWindow(hwndDlg, FALSE);
				dat->closeIfFileChooseCancelled = 1;
				PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_CHOOSE, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDC_CHOOSE));
			}
		}
		return TRUE;

	case WM_MEASUREITEM:
		return Menu_MeasureItem((LPMEASUREITEMSTRUCT)lParam);

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
			if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) {
				char *szProto = GetContactProto(dat->hContact);
				if (szProto) {
					HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0);
					if (hIcon) {
						DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
						DestroyIcon(hIcon);
					}
				}
			}
		}
		return Menu_DrawItem((LPDRAWITEMSTRUCT)lParam);

	case M_FILECHOOSEDONE:
		if (lParam != 0) {
			FilenameToFileList(hwndDlg, dat, (TCHAR*)lParam);
			mir_free((TCHAR*)lParam);
			dat->closeIfFileChooseCancelled = 0;
		}
		else if (dat->closeIfFileChooseCancelled)
			PostMessage(hwndDlg, WM_COMMAND, IDCANCEL, 0);

		EnableWindow(hwndDlg, TRUE);
		break;

	case WM_COMMAND:
		if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact))
			break;

		switch (LOWORD(wParam)) {
		case IDC_CHOOSE:
			EnableWindow(hwndDlg, FALSE);
			forkthread(ChooseFilesThread, 0, hwndDlg);
			break;

		case IDOK:
			NotifyEventHooks(hDlgSucceeded, dat->hContact, (LPARAM)hwndDlg);

			EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSE), FALSE);

			GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, _countof(dat->szSavePath));
			GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, _countof(dat->szFilenames));
			GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, _countof(dat->szMsg));
			dat->hwndTransfer = FtMgr_AddTransfer(dat);
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
			DestroyWindow(hwndDlg);
			return TRUE;

		case IDCANCEL:
			NotifyEventHooks(hDlgCanceled, dat->hContact, (LPARAM)hwndDlg);
			DestroyWindow(hwndDlg);
			return TRUE;

		case IDC_USERMENU:
			{
				RECT rc;
				GetWindowRect((HWND)lParam, &rc);
				HMENU hMenu = Menu_BuildContactMenu(dat->hContact);
				TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
				DestroyMenu(hMenu);
			}
			break;

		case IDC_DETAILS:
			CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0);
			return TRUE;

		case IDC_HISTORY:
			CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0);
			return TRUE;
		}
		break;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY);
		Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU);

		FreeFileDlgData(dat);
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
		return TRUE;
	}
	return FALSE;
}
Ejemplo n.º 29
0
BOOL ZipDlg::OnListNotify( HWND hDlg, WPARAM wParam, LPARAM lParam)
{
	NMHDR*	nmhdr = (NMHDR*)lParam ;

	// キーダウン
	if( nmhdr->code == LVN_KEYDOWN)
	{
		// デリート
		if( ( (LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
		{
			ListDel( ) ;
			EnableWindow( hwndOk, ( ListView_GetItemCount( hwndList) != 0 ? TRUE : FALSE)) ;
		}
		// Ctrl + A
		else if( GetKeyState( VK_CONTROL) < 0 && ( (LPNMLVKEYDOWN)lParam)->wVKey == 'A')
		{
			ListView_SetItemState( hwndList, -1, LVIS_SELECTED, LVIS_SELECTED) ;
		}
		// Alt + ↑↓
		else if( GetKeyState( VK_MENU) < 0)
		{
			if( ( (LPNMLVKEYDOWN)lParam)->wVKey == VK_UP)
			{
				ListMove( TRUE) ;
			}
			else if( ( (LPNMLVKEYDOWN)lParam)->wVKey == VK_DOWN)
			{
				ListMove( FALSE) ;
			}
		}
		return TRUE ;
	}
	// 選択変更時
	else if( nmhdr->code == LVN_ITEMCHANGED)
	{
		EnableWindow( hwndOk, ( ListView_GetItemCount( hwndList) != 0 ? TRUE : FALSE)) ;
		EnableWindow( hwndDel, ( ListView_GetSelectedCount( hwndList) != 0 ? TRUE : FALSE)) ;
		return TRUE ;
	}
	// ヘッダ部分クリック
	else if( nmhdr->code == LVN_COLUMNCLICK)
	{
		ListView_SortItems( hwndList, ListSortProc, ( (NMLISTVIEW*)lParam)->iSubItem) ;
		ListReload() ;
		return TRUE ;
	}
	// 右クリック
	else if( nmhdr->code == NM_RCLICK)
	{
		POINT pt ;
		GetCursorPos( &pt) ;
		HMENU hMenu = LoadMenu( hInstance, MAKEINTRESOURCE(IDR_POPMENU)) ;
		HMENU hMenuPopup = GetSubMenu( hMenu, 0) ;
		if( ListView_GetSelectedCount( hwndList) == 0)
		{
			EnableMenuItem( hMenuPopup, IDM_DEL, MF_BYCOMMAND | MF_GRAYED) ;
			EnableMenuItem( hMenuPopup, IDM_SETFOLDER, MF_BYCOMMAND | MF_GRAYED) ;
			EnableMenuItem( hMenuPopup, IDM_UP, MF_BYCOMMAND | MF_GRAYED) ;
			EnableMenuItem( hMenuPopup, IDM_DOWN, MF_BYCOMMAND | MF_GRAYED) ;
		}
		if( ListView_GetItemCount( hwndList) == 0)
		{
			EnableMenuItem( hMenuPopup, IDM_SORTFILE, MF_BYCOMMAND | MF_GRAYED) ;
			EnableMenuItem( hMenuPopup, IDM_SORTPATH, MF_BYCOMMAND | MF_GRAYED) ;
			EnableMenuItem( hMenuPopup, IDM_SORTZIP, MF_BYCOMMAND | MF_GRAYED) ;
		}

		DWORD dwID = TrackPopupMenu( hMenuPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD, 
			pt.x, pt.y, 0, hDlg, NULL) ;
		switch( dwID)
		{
			case IDM_ADD:
				ListAddFileDlg() ;
				break ;
			case IDM_DEL:
				ListDel() ;
				break ;
			case IDM_UP:
			case IDM_DOWN:
				ListMove( dwID == IDM_UP) ;
				break ;
			case IDM_SORTPATH:
				ListView_SortItems( hwndList, ListSortProc, 1) ;
				ListReload() ;
				break ;
			case IDM_SORTFILE:
				ListView_SortItems( hwndList, ListSortProc, 2) ;
				ListReload() ;
				break ;
			case IDM_SORTZIP:
				ListView_SortItems( hwndList, ListSortProc, 0) ;
				ListReload() ;
				break ;
			case IDM_SETFOLDER:
				ListSetFolder() ;
				break ;
		}

		DestroyMenu( hMenu) ;
	}

	return FALSE ;
}
void CTutorialWindow::OnContextMenu(HWND hWnd, CPoint point) {
	// We need some IDs for the context menu.
	enum {
		// ID for "Choose font..."
		ID_FONT = 1,
		// The range ID_CONTEXT_FIRST through ID_CONTEXT_LAST is reserved
		// for menu entries from menu_manager.
		ID_CONTEXT_FIRST,
		ID_CONTEXT_LAST = ID_CONTEXT_FIRST + 1000,
	};

	// Create new popup menu.
	HMENU hMenu = CreatePopupMenu();

	// Add our "Choose font..." command.
	AppendMenu(hMenu, MF_STRING, ID_FONT, TEXT("Choose font..."));

	// Get the currently playing track.
	metadb_handle_list items;
	static_api_ptr_t<play_control> pc;
	metadb_handle_ptr handle;
	if (pc->get_now_playing(handle)) {
		// Insert it into a list.
		items.add_item(handle);
	}

	// Create a menu_manager that will build the context menu.
	service_ptr_t<contextmenu_manager> cmm;
	contextmenu_manager::g_create(cmm);
	// Query setting for showing keyboard shortcuts.
	const bool show_shortcuts = config_object::g_get_data_bool_simple(standard_config_objects::bool_show_keyboard_shortcuts_in_menus, false);
	// Set up flags for contextmenu_manager::init_context.
	unsigned flags = show_shortcuts ? contextmenu_manager::FLAG_SHOW_SHORTCUTS : 0;
	// Initialize menu_manager for using a context menu.
	cmm->init_context(items, flags);
	// If the menu_manager has found any applicable commands,
	// add them to our menu (after a separator).
	if (cmm->get_root()) {
		uAppendMenu(hMenu, MF_SEPARATOR, 0, 0);
		cmm->win32_build_menu(hMenu, ID_CONTEXT_FIRST, ID_CONTEXT_LAST);
	}

	// Use menu helper to gnereate mnemonics.
	menu_helpers::win32_auto_mnemonics(hMenu);

	// Get the location of the mouse pointer.
	// WM_CONTEXTMENU provides position of mouse pointer in argument lp,
	// but this isn't reliable (for example when the user pressed the
	// context menu key on the keyboard).
	CPoint pt;
	GetCursorPos(pt);
	// Show the context menu.
	int cmd = TrackPopupMenu(hMenu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_RIGHTBUTTON, 
		pt.x, pt.y, 0, m_hWnd, 0);

	// Check what command has been chosen. If cmd == 0, then no command
	// was chosen.
	if (cmd == ID_FONT) {
		// Show font configuration.
		t_font_description font = cfg_font;
		if (font.popup_dialog(m_hWnd)) {
			cfg_font = font;
			m_font = font.create();
			::RedrawWindow(m_hWnd, 0, 0, RDW_INVALIDATE|RDW_UPDATENOW);
		}
	} else if (cmd >= ID_CONTEXT_FIRST && cmd <= ID_CONTEXT_LAST ) {
		// Let the menu_manager execute the chosen command.
		cmm->execute_by_id(cmd - ID_CONTEXT_FIRST);
	}

	// contextmenu_manager instance is released automatically, as is the metadb_handle we used.

	// Finally, destroy the popup menu.
	DestroyMenu(hMenu);
}