Esempio n. 1
0
void snap_windows(WINDOWPOS *wp, bool sizing, int *content)
{
	SIZE adjusted_content;
	if (content && sizing)
	{
		adjusted_content.cx = content[0] + 2*plugin_snap_padding;
		adjusted_content.cy = content[1] + 2*plugin_snap_padding;
		content = (int*)&adjusted_content;
	}
	SnapWindowToEdge(wp, (LPARAM)content, sizing ? SNAP_FULLSCREEN|SNAP_CONTENT|SNAP_SIZING : SNAP_FULLSCREEN|SNAP_CONTENT);
}
Esempio n. 2
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int gap = bevelWidth + borderWidth;

	switch (message)
	{
		case WM_PAINT:
		{
			OnPaint(hwnd);
		}
		break;

		// ==========

		case BB_RECONFIGURE:
		{
			if (myMenu){ DelMenu(myMenu); myMenu = NULL;}
			GetStyleSettings();
			InvalidateRect(hwndPlugin, NULL, true);
		}
		break;

		// for bbStylemaker
		case BB_REDRAWGUI:
		{
			GetStyleSettings();
			InvalidateRect(hwndPlugin, NULL, true);
		}
		break;

		case WM_DISPLAYCHANGE:
		{
			if(!inSlit)
			{
				// IntelliMove(tm)... <g>
				// (c) 2003 qwilk
				//should make this a function so it can be used on startup in case resolution changed since
				//the last time blackbox was used.
				int relx, rely;
				int oldscreenwidth = ScreenWidth;
				int oldscreenheight = ScreenHeight;
				ScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
				ScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
				if (xpos > oldscreenwidth / 2)
				{
					relx = oldscreenwidth - xpos;
					xpos = ScreenWidth - relx;
				}
				if (ypos > oldscreenheight / 2)
				{
					rely = oldscreenheight - ypos;
					ypos = ScreenHeight - rely;
				}
				MoveWindow(hwndPlugin, xpos, ypos, width, height, true);
			}
		}
		break;

		// ==========

		case BB_BROADCAST:
		{
			szTemp = (char*)lParam;

			if (!_stricmp(szTemp, "@BBShowPlugins") &&  pluginToggle && !inSlit)
			{
				// Show window and force update...
				ShowWindow( hwndPlugin, SW_SHOW);
				InvalidateRect( hwndPlugin, NULL, true);
			}
			else if (!_stricmp(szTemp, "@BBHidePlugins") && pluginToggle && !inSlit)
			{
				// Hide window...
				ShowWindow( hwndPlugin, SW_HIDE);
			}

			//===================

			if (strnicmp(szTemp, "@BBSeekbar", 10))
				return 0;
			szTemp += 10;

			if (!_stricmp(szTemp, "About"))
			{
				char tmp_str[MAX_LINE_LENGTH];
				SendMessage(hwndBlackbox, BB_HIDEMENU, 0, 0);
				sprintf(tmp_str, "%s", szVersion);
				MessageBox(hwndBlackbox, tmp_str, szAppName, MB_OK | MB_TOPMOST);
			}

			//===================

			else if (!_strnicmp(szTemp, "StyleType", 9))
			{
				styleType = atoi(szTemp + 10);
				GetStyleSettings();
				InvalidateRect(hwndPlugin, NULL, true);
			}
			else if (!_strnicmp(szTemp, "TrackStyle", 10))
			{
				trackStyleType = atoi(szTemp + 11);
				GetStyleSettings();
				InvalidateRect(hwndPlugin, NULL, true);
			}
			else if (!_strnicmp(szTemp, "KnobStyle", 9))
			{
				knobStyleType = atoi(szTemp + 10);
				GetStyleSettings();
				InvalidateRect(hwndPlugin, NULL, true);
			}

			else if (!_strnicmp(szTemp, "Appearance", 10))
			{
				appearance = atoi(szTemp + 11);
				track_needsupdate = true;
				knob_needsupdate = true;
				InvalidateRect(hwndPlugin, NULL, true);
				ShowMyMenu(false);
			}
			else if (!_strnicmp(szTemp, "PlayerType", 10))
			{
				playerType = atoi(szTemp + 11);

				// Stop the monitor...
				unsigned long exitcode;
				GetExitCodeThread(hThread_Time, &exitcode);
				TerminateThread(hThread_Time, exitcode);

				FreeLibrary(controlPlugin);
				if(!loadPlayerControl(hInstance, playerType)){
					MessageBox(hwndBlackbox, "Player control plugin not found", szAppName, MB_OK | MB_ICONERROR | MB_TOPMOST);
				}

				// Start the monitoring threads...
				hThread_Time = CreateThread(NULL, 0, TimeProc, NULL, 0, &dwThreadId_Time);

				knob_needsupdate = true;
				InvalidateRect(hwndPlugin, NULL, true);
				ShowMyMenu(false);
			}

			//===================

			else if (!_strnicmp(szTemp, "WidthSize", 9))
			{
				newWidth = atoi(szTemp + 10);
				if(ResizeMyWindow(newWidth, height)){
					track_needsupdate = true;
					knob_needsupdate = true;
					InvalidateRect(hwndPlugin, NULL, true);
				}
			}
			else if (!_strnicmp(szTemp, "HeightSize", 10))
			{
				newHeight = atoi(szTemp + 11);
				if(ResizeMyWindow(width, newHeight)){
					track_needsupdate = true;
					knob_needsupdate = true;
					InvalidateRect(hwndPlugin, NULL, true);
				}
			}

			//===================

			else if (!_stricmp(szTemp, "pluginToggle"))
			{
				pluginToggle = (pluginToggle ? false : true);
				SetWindowModes();
			}
			else if (!_stricmp(szTemp, "OnTop"))
			{
				alwaysOnTop = (alwaysOnTop ? false : true);
				if(!inSlit)SetWindowPos( hwndPlugin,
                                                         alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
                                                         0, 0, 0, 0,
                                                         SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);

				ShowMyMenu(false);
			}

			else if (!_stricmp(szTemp, "InSlit"))
			{
				if(inSlit && hSlit){
					// We are in the slit, so lets unload and get out..
					SendMessage(hSlit, SLIT_REMOVE, NULL, (LPARAM)hwndPlugin);

					// Here you can move to where ever you want ;)
					SetWindowPos(hwndPlugin, NULL, xpos, ypos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
					inSlit = false;
					SetWindowModes();
				}
				/* Make sure before you try and load into the slit that you have
				* the HWND of the slit ;)
				*/
				else if(hSlit){
					// (Back) into the slit..
					inSlit = true;
					SetWindowModes();
					SendMessage(hSlit, SLIT_ADD, NULL, (LPARAM)hwndPlugin);
				}
			}

			else if (!_stricmp(szTemp, "Transparent"))
			{
				transparency = (transparency ? false : true);
				SetWindowModes();
			}
			else if (!_strnicmp(szTemp, "AlphaValue", 10))
			{
				alpha = atoi(szTemp + 11);
				SetWindowModes();
			}
			else if (!_stricmp(szTemp, "SnapToEdge"))
			{
				snapWindow = (snapWindow ? false : true);
				ShowMyMenu(false);
			}
			else if (!_stricmp(szTemp, "ShowBorder"))
			{
				showBorder = (showBorder ? false : true);
				InvalidateRect(hwndPlugin, NULL, false);
				ShowMyMenu(false);
			}
			else if (!_stricmp(szTemp, "AllowTip"))
			{
				allowtip = (allowtip ? false : true);
				SetAllowTip(allowtip);
				ShowMyMenu(false);
			}

			else if (!_stricmp(szTemp, "Vertical"))
			{
				vertical = (vertical ? false : true);
				if(ResizeMyWindow(height, width)){
					track_needsupdate = true;
					knob_needsupdate = true;
					InvalidateRect(hwndPlugin, NULL, true);
				}
				ShowMyMenu(false);
			}
			else if (!_stricmp(szTemp, "Reversed"))
			{
				reversed = (reversed ? false : true);
				track_needsupdate = true;
				knob_needsupdate = true;
				InvalidateRect(hwndPlugin, NULL, true);
				ShowMyMenu(false);
			}

			//===================

			else if (!_stricmp(szTemp, "EditRC"))
			{
				BBExecute(GetDesktopWindow(), NULL,
				ReadString(extensionsrcPath(), "blackbox.editor:", "notepad.exe"),
                                          rcpath, NULL, SW_SHOWNORMAL, false);
			}
			else if (!_stricmp(szTemp, "ReloadSettings"))
			{
				ReadRCSettings();
				GetStyleSettings();

				if(inSlit && hSlit)
				{
					SetWindowModes();
					SendMessage(hSlit, SLIT_UPDATE, NULL, NULL);
				}
				else if(!inSlit || !hSlit)
					SendMessage(hSlit, SLIT_REMOVE, NULL, (LPARAM)hwndPlugin);

				else inSlit = false;
			}
			else if (!_stricmp(szTemp, "SaveSettings"))
			{
				WriteRCSettings();
			}
		}
		break;

		// ==========

		case WM_WINDOWPOSCHANGING:
		{
			// Is SnapWindowToEdge enabled?
			if (!inSlit && snapWindow)
			{
				// Snap window to screen edges (if the last bool is false it uses the current DesktopArea)
				if(IsWindowVisible(hwnd)) SnapWindowToEdge((WINDOWPOS*)lParam, 10, true);
			}
		}
		break;

		// ==========

		case WM_WINDOWPOSCHANGED:
		{
			if(!inSlit)
			{
				WINDOWPOS* windowpos = (WINDOWPOS*)lParam;
				if (0 == (windowpos->flags & SWP_NOMOVE))
				{
					xpos = windowpos->x;
					ypos = windowpos->y;
				}

				if(ResizeMyWindow(windowpos->cx, windowpos->cy) && 0 == (windowpos->flags & SWP_NOSIZE))
				{
					track_needsupdate = true;
					knob_needsupdate = true;
					InvalidateRect(hwndPlugin, NULL, true);
				}
			}
		}
		break;

		// ==========

		case WM_NCHITTEST:
		{
			if (!inSlit && GetKeyState(VK_MENU) & 0xF0)
			{
				return HTBOTTOMRIGHT;
			}
			else
			if (!inSlit && GetKeyState(VK_CONTROL) & 0xF0)
			{
				return HTCAPTION;
			}
		}
		return HTCLIENT;

		// ==========

		case WM_LBUTTONDOWN:
			SetFocus(hwnd);
			SetCapture(hwnd);

			InvalidateRect(hwndPlugin, NULL, false);
			dragging = true;
			SliderOnValueChange(lParam);
			break;
	
		case WM_MOUSEMOVE:
			if (!dragging) break;
			InvalidateRect(hwndPlugin, NULL, false);
			SliderOnValueChange(lParam);
			break;

		case WM_LBUTTONUP:
			ReleaseCapture();

		case WM_KILLFOCUS: 
			dragging = false;
			break;

		// ==========

		case WM_RBUTTONUP:
			ReleaseCapture();

		case WM_NCRBUTTONUP:
			ShowMyMenu(true);
			break;

		case WM_CLOSE:
			break;

		// bring window into foreground on sizing/moving-start
		case WM_NCLBUTTONDOWN:
			SetWindowPos(hwnd, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
			UpdateWindow(hwnd);
			// fall through
 		// ==========
		default:
			return DefWindowProc(hwnd,message,wParam,lParam);
	}
	return 0;
}
Esempio n. 3
0
LRESULT CALLBACK BBP_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static UINT msgs[] = { BB_RECONFIGURE, BB_BROADCAST, BB_DESKCLICK, 0};

    LRESULT Result = 0;
    plugin_info *PI  = (plugin_info *)GetWindowLongPtr(hwnd, 0);

    //dbg_printf("message %x", message);

    if (NULL == PI)
    {
        if (WM_NCCREATE == message)
        {
            // bind the window to the structure
            PI = (plugin_info *)((CREATESTRUCT*)lParam)->lpCreateParams;
            PI->hwnd = hwnd;
            SetWindowLongPtr(hwnd, 0, (LONG_PTR)PI);
        }
        return DefWindowProc(hwnd, message, wParam, lParam);
    }

    switch (message)
    {
        case WM_CREATE:
            SendMessage(GetBBWnd(), BB_REGISTERMESSAGE, (WPARAM)hwnd, (LPARAM)msgs);
            MakeSticky(hwnd);
            goto pass_nothing;

        case WM_DESTROY:
            SendMessage(GetBBWnd(), BB_UNREGISTERMESSAGE, (WPARAM)hwnd, (LPARAM)msgs);
            RemoveSticky(hwnd);
            goto pass_nothing;

        // ==========
        case BB_BROADCAST:
        {
            const char *temp = (LPCSTR)lParam;
            int f, len;

            if (0 == stricmp(temp, "@BBShowPlugins")) {
                PI->toggled_hidden = false;
                BBP_set_window_modes(PI);
                goto pass_result;
            }
            if (0 == stricmp(temp, "@BBHidePlugins")) {
                if (PI->pluginToggle) {
                    PI->toggled_hidden = true;
                    BBP_set_window_modes(PI);
                }
                goto pass_result;
            }

            if ('@' != *temp++)
                goto pass_nothing;

            len = PI->broam_key_len;
            if (len && 0 == memicmp(temp, PI->broam_key, len) && '.' == temp[len]) {
                f = 0;
                temp += len + 1;
                goto do_broam;
            }

            if (PI->next)
                goto pass_nothing;

            len = PI->broam_key_len_common;
            if (len && 0 == memicmp(temp, PI->broam_key, len)) {
                f = BBP_BROAM_COMMON;
                temp += len;
                goto do_broam;
            }

            goto pass_nothing;

        do_broam:
            f |= BBP_handle_broam(PI, temp);
            PI->process_broam(_THIS_ temp, f);
            goto pass_result;
        }

        // ==========

        case BB_DESKCLICK:
            if (lParam == 0
             && PI->clickRaise
             && false == PI->alwaysOnTop
             && false == PI->inSlit)
                SetWindowPos(hwnd, HWND_TOP,
                    0,0,0,0, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
            goto pass_nothing;

        // ==========

        case WM_WINDOWPOSCHANGING:
            if (PI->is_moving) {
                if (false == PI->inSlit
                 && 0 == (0x8000 & GetAsyncKeyState(VK_SHIFT)))
				 SnapWindowToEdge((WINDOWPOS*)lParam, PI->snapWindow, true);
                if (PI->is_sizing) {
                    WINDOWPOS* wp = (WINDOWPOS*)lParam;
                    if (wp->cx < 12) wp->cx = 12;
                    if (wp->cy < 12) wp->cy = 12;
                }
            }
            goto pass_nothing;

        case WM_WINDOWPOSCHANGED:
            if (PI->is_sizing) {
                WINDOWPOS* wp = (WINDOWPOS*)lParam;
                PI->width = wp->cx;
                PI->height = wp->cy;
                InvalidateRect(hwnd, NULL, FALSE);
            }
			SnapWindowToEdge((WINDOWPOS*)lParam, PI->snapWindow, true);
            goto pass_nothing;

        case WM_ENTERSIZEMOVE:
            PI->is_moving = true;
            goto pass_nothing;

        case WM_EXITSIZEMOVE:
            BBP_exit_moving(PI);
            BBP_set_autoHide(PI, PI->autoHide);
            if (PI->inSlit)
                SendMessage(PI->hSlit, SLIT_UPDATE, 0, (LPARAM)PI->hwnd);
            goto pass_nothing;

        // ==========
        case WM_LBUTTONDOWN:
            SetFocus(hwnd);
            UpdateWindow(hwnd);
            if (false == PI->inSlit && (MK_CONTROL & wParam)) {
                // start moving, when control-key is held down
                PostMessage(hwnd, WM_SYSCOMMAND, 0xf012, 0);
                goto pass_result;
            }
            goto pass_nothing;

        case WM_MOUSEMOVE:
            if (false == PI->mouse_over)
            {
                PI->mouse_over = true;
                set_autohide_timer(PI, true);
            }

            if (PI->auto_hidden)
            {
                PI->auto_shown = true;
                BBP_set_window_modes(PI);
                goto pass_result;
            }

            goto pass_nothing;

        case WM_TIMER:
            if (AUTOHIDE_TIMER != wParam)
                goto pass_nothing;

            if (check_mouse(hwnd))
                goto pass_result;
#if 0
            {
                POINT pt;
                GetCursorPos(&pt);
                if (PI->hMon != GetMonitorRect(&pt, NULL, GETMON_FROM_POINT))
                    goto pass_result;
            }
#endif
            if (PI->mouse_over) {
                POINT pt;
                GetCursorPos(&pt);
                ScreenToClient(hwnd, &pt);
                PostMessage(hwnd, WM_MOUSELEAVE, 0, MAKELPARAM(pt.x, pt.y));
                PI->mouse_over = false;
            }

            if (PI->auto_shown) {
                if (PI->suspend_autohide && BBVERSION_LEAN)
                    goto pass_result;
                PI->auto_shown = false;
                BBP_set_window_modes(PI);
            }

            set_autohide_timer(PI, false);
            goto pass_result;


        case BB_AUTOHIDE:
            if (PI->inSlit)
                PostMessage(PI->hSlit, message, wParam, lParam);

            if (wParam)
                PI->suspend_autohide |= lParam;
            else
                PI->suspend_autohide &= ~lParam;

            if (PI->suspend_autohide && PI->auto_hidden) {
                PI->auto_shown = true;
                BBP_set_window_modes(PI);
            }

            set_autohide_timer(PI, true);
            goto pass_result;

        case WM_CLOSE:
            goto pass_result;

        case WM_ERASEBKGND:
            Result = TRUE;
            goto pass_result;

        default:
        pass_nothing:
            return PI->wnd_proc(_THIS_ hwnd, message, wParam, lParam, NULL);
    }
pass_result:
    return PI->wnd_proc(_THIS_ hwnd, message, wParam, lParam, &Result);
}
Esempio n. 4
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static int msgs[] = { BB_RECONFIGURE, BB_BROADCAST, 0};

    switch (message)
    {
        case WM_CREATE:
            /* Register to reveive these message */
            SendMessage(BBhwnd, BB_REGISTERMESSAGE, (WPARAM)hwnd, (LPARAM)msgs);
            /* Make the window appear on all workspaces */
            MakeSticky(hwnd);
            break;

        case WM_DESTROY:
            /* as above, in reverse */
            RemoveSticky(hwnd);
            SendMessage(BBhwnd, BB_UNREGISTERMESSAGE, (WPARAM)hwnd, (LPARAM)msgs);
            break;

        /* ---------------------------------------------------------- */
        /* Blackbox sends a "BB_RECONFIGURE" message on style changes etc. */

        case BB_RECONFIGURE:
            ReadRCSettings();
            GetStyleSettings();
            set_window_modes();
            break;

        /* ---------------------------------------------------------- */
        /* Painting directly on screen. Good enough for static plugins. */
#if 1
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc;
            RECT r;

            /* get screen DC */
            hdc = BeginPaint(hwnd, &ps);

            /* Setup the rectangle */
            r.left = r.top = 0;
            r.right = my.width;
            r.bottom =  my.height;

            /* and paint everything on it*/
            paint_window(hdc, &r);

            /* Done */
            EndPaint(hwnd, &ps);
            break;
        }

        /* ---------------------------------------------------------- */
        /* Painting with a cached double-buffer. If your plugin updates
           frequently, this avoids flicker */
#else
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc, hdc_buffer;
            HGDIOBJ otherbmp;
            RECT r;

            /* get screen DC */
            hdc = BeginPaint(hwnd, &ps);

            /* create a DC for the buffer */
            hdc_buffer = CreateCompatibleDC(hdc);

            if (NULL == my.bufbmp) /* No bitmap yet? */
            {
                /* Make a bitmap ... */
                my.bufbmp = CreateCompatibleBitmap(hdc, my.width, my.height);

                /* ... and select it into the DC, saving the previous default. */
                otherbmp = SelectObject(hdc_buffer, my.bufbmp);

                /* Setup the rectangle */
                r.left = r.top = 0;
                r.right = my.width;
                r.bottom =  my.height;

                /* and paint everything on it*/
                paint_window(hdc_buffer, &r);
            }
            else
            {
                /* Otherwise it has been painted already,
                   so just select it into the DC */
                otherbmp = SelectObject(hdc_buffer, my.bufbmp);
            }

            /* Copy the buffer on the screen, within the invalid rectangle: */
            BitBltRect(hdc, hdc_buffer, &ps.rcPaint);

            /* Put back the previous default bitmap */
            SelectObject(hdc_buffer, otherbmp);
            /* clean up */
            DeleteDC(hdc_buffer);

            /* Done. */
            EndPaint(hwnd, &ps);
            break;
        }
#endif
        /* ---------------------------------------------------------- */
        /* Manually moving/sizing has been started */

        case WM_ENTERSIZEMOVE:
            my.is_moving = true;
            break;

        case WM_EXITSIZEMOVE:
            if (my.is_moving)
            {
                if (my.is_inslit)
                {
                    /* moving in the slit is not really supported but who
                       knows ... */
                    SendMessage(g_hSlit, SLIT_UPDATE, 0, (LPARAM)hwnd);
                }
                else
                {
                    /* if not in slit, record new position */
                    WriteInt(rcpath, RC_KEY("xpos"), my.xpos);
                    WriteInt(rcpath, RC_KEY("ypos"), my.ypos);
                }

                if (my.is_sizing)
                {
                    /* record new size */
                    WriteInt(rcpath, RC_KEY("width"), my.width);
                    WriteInt(rcpath, RC_KEY("height"), my.height);
                }
            }
            my.is_moving = my.is_sizing = false;
            set_window_modes();
            break;

        /* --------------------------------------------------- */
        /* snap to edges on moving */

        case WM_WINDOWPOSCHANGING:
            if (my.is_moving)
            {
                WINDOWPOS* wp = (WINDOWPOS*)lParam;
                if (my.snapWindow && false == my.is_sizing)
                    SnapWindowToEdge(wp, 10, SNAP_FULLSCREEN);

                /* set a minimum size */
                if (wp->cx < 40)
                    wp->cx = 40;

                if (wp->cy < 20)
                    wp->cy = 20;
            }
            break;

        /* --------------------------------------------------- */
        /* record new position or size */

        case WM_WINDOWPOSCHANGED:
            if (my.is_moving)
            {
                WINDOWPOS* wp = (WINDOWPOS*)lParam;
                if (my.is_sizing)
                {
                    /* record sizes */
                    my.width = wp->cx;
                    my.height = wp->cy;

                    /* redraw window */
                    invalidate_window();
                }

                if (false == my.is_inslit)
                {
                    /* record position, if not in slit */
                    my.xpos = wp->x;
                    my.ypos = wp->y;
                }
            }
            break;

        /* ---------------------------------------------------------- */
        /* start moving or sizing accordingly to keys held down */

        case WM_LBUTTONDOWN:
            UpdateWindow(hwnd);
            if (GetAsyncKeyState(VK_MENU) & 0x8000)
            {
                /* start sizing, when alt-key is held down */
                PostMessage(hwnd, WM_SYSCOMMAND, 0xf008, 0);
                my.is_sizing = true;
            }
            else
            if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
            {
                /* start moving, when control-key is held down */
                PostMessage(hwnd, WM_SYSCOMMAND, 0xf012, 0);
            }
            break;

        /* ---------------------------------------------------------- */
        /* normal mouse clicks */

        case WM_LBUTTONUP:
            /* code goes here ... */
            break;

        case WM_RBUTTONUP:
            /* Show the user menu on right-click (might test for control-key
               held down if wanted */
            /* if (wParam & MK_CONTROL) */
            ShowMyMenu(true);
            break;

        case WM_LBUTTONDBLCLK:
            /* Do something here ... */
            about_box();
            break;

        /* ---------------------------------------------------------- */
        /* Blackbox sends Broams to all windows... */

        case BB_BROADCAST:
        {
            const char *msg = (LPCSTR)lParam;
            struct msg_test msg_test;

            /* check general broams */
            if (!stricmp(msg, "@BBShowPlugins"))
            {
                if (my.is_hidden)
                {
                    my.is_hidden = false;
                    ShowWindow(hwnd, SW_SHOWNA);
                }
                break;
            }

            if (!stricmp(msg, "@BBHidePlugins"))
            {
                if (my.pluginToggle && false == my.is_inslit)
                {
                    my.is_hidden = true;
                    ShowWindow(hwnd, SW_HIDE);
                }
                break;
            }

            /* if the broam is not for us, return now */
            if (0 != memicmp(msg, BROAM_PREFIX, sizeof BROAM_PREFIX - 1))
                break;

            msg_test.msg = msg + sizeof BROAM_PREFIX - 1;

            if (scan_broam(&msg_test, "useSlit"))
            {
                eval_broam(&msg_test, M_BOL, &my.useSlit);
                break;
            }

            if (scan_broam(&msg_test, "alwaysOnTop"))
            {
                eval_broam(&msg_test, M_BOL, &my.alwaysOnTop);
                break;
            }

            if (scan_broam(&msg_test, "drawBorder"))
            {
                eval_broam(&msg_test, M_BOL, &my.drawBorder);
                break;
            }

            if (scan_broam(&msg_test, "snapWindow"))
            {
                eval_broam(&msg_test, M_BOL, &my.snapWindow);
                break;
            }

            if (scan_broam(&msg_test, "pluginToggle"))
            {
                eval_broam(&msg_test, M_BOL, &my.pluginToggle);
                break;
            }

            if (scan_broam(&msg_test, "alphaEnabled"))
            {
                eval_broam(&msg_test, M_BOL, &my.alphaEnabled);
                break;
            }

            if (scan_broam(&msg_test, "alphaValue"))
            {
                eval_broam(&msg_test, M_INT, &my.alphaValue);
                break;
            }

            if (scan_broam(&msg_test, "windowText"))
            {
                eval_broam(&msg_test, M_STR, &my.windowText);
                break;
            }

            if (scan_broam(&msg_test, "editRC"))
            {
                edit_rc(rcpath);
                break;
            }

            if (scan_broam(&msg_test, "About"))
            {
                about_box();
                break;
            }

            break;
        }

        /* ---------------------------------------------------------- */
        /* prevent the user from closing the plugin with alt-F4 */

        case WM_CLOSE:
            break;

        /* ---------------------------------------------------------- */
        /* let windows handle any other message */
        default:
            return DefWindowProc(hwnd,message,wParam,lParam);
    }
    return 0;
}
Esempio n. 5
0
//===========================================================================
LRESULT CALLBACK Toolbar_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static UINT msgs[] =
	{
		BB_RECONFIGURE,
		BB_TASKSUPDATE,
		BB_SETTOOLBARLABEL,
		BB_BROADCAST,
		BB_DESKTOPINFO,
		BB_REDRAWGUI,
		0
		};

	switch (message)
	{
		//====================
	case WM_CREATE:
		DisableInputMethod(hwnd);
		TBInfo.hwnd = Toolbar_hwnd = hwnd;
		MessageManager_AddMessages (hwnd, msgs);
		MakeSticky(hwnd);
		Toolbar_UpdatePosition();
		break;

		//====================
	case WM_DESTROY:
		RemoveSticky(hwnd);
		MessageManager_RemoveMessages (hwnd, msgs);
		SetDesktopMargin(Toolbar_hwnd, 0, 0);
		if (Toolbar_hFont) DeleteObject(Toolbar_hFont), Toolbar_hFont = NULL;
		TBInfo.hwnd = Toolbar_hwnd = NULL;
		break;

		//====================
	case BB_RECONFIGURE:
	tbreconfig:
		Toolbar_UpdatePosition();
		Toolbar_ShowMenu(false);
		InvalidateRect(hwnd, NULL, FALSE);
		break;

		//====================
	case BB_REDRAWGUI:
		if (wParam & BBRG_TOOLBAR)
		{
			Toolbar_force_button_pressed = 0 != (wParam & BBRG_PRESSED);
			Toolbar_UpdatePosition();
			InvalidateRect(hwnd, NULL, FALSE);
		}
		break;

		//====================
	case BB_TASKSUPDATE:
	showlabel:
		Toolbar_setlabel();
		InvalidateRect(hwnd, NULL, FALSE);
		break;

	case BB_DESKTOPINFO:
		Toolbar_setlabel();
		InvalidateRect(hwnd, NULL, FALSE);
		break;

		//====================
	case WM_ACTIVATEAPP:
		if (wParam) SetOnTop(hwnd);
		break;

		//====================

	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hwnd, &ps);
			PaintToolbar(hdc, &ps.rcPaint);
			EndPaint(hwnd, &ps);
			break;
		}

		//====================

	case BB_SETTOOLBARLABEL:
		SetTimer(hwnd, TOOLBAR_SETLABEL_TIMER, 2000, (TIMERPROC)NULL);
		Toolbar_ShowingExternalLabel = true;
		strcpy_max(Toolbar_CurrentWindow, (LPCTSTR)lParam, sizeof(Toolbar_CurrentWindow)/sizeof(TCHAR));
		InvalidateRect(hwnd, NULL, FALSE);
		break;

		//====================

	case WM_TIMER:
		if (wParam == TOOLBAR_AUTOHIDE_TIMER)
		{
			if (TBInfo.autoHide)
			{
				if (check_mouse(hwnd) || (TBInfo.bbsb_hwnd && check_mouse(TBInfo.bbsb_hwnd)))
					break;

				Toolbar_AutoHide(true);
			}
			KillTimer(hwnd, wParam);
			break;
		}

		if (wParam == TOOLBAR_UPDATE_TIMER)
		{
			Toolbar_setclock();
			InvalidateRect(hwnd, NULL, FALSE);
			break;
		}

		KillTimer(hwnd, wParam);

		if (wParam == TOOLBAR_SETLABEL_TIMER)
		{
			Toolbar_ShowingExternalLabel = false;
			goto showlabel;
		}

		break;

		//====================
		/*
        case WM_DROPFILES:
            drop_style((HDROP)wParam);
            break;
		 */
		//====================

	case WM_LBUTTONDOWN:
		if (wParam & MK_CONTROL)
		{
			// Allow window to move if control key is being held down,
			UpdateWindow(hwnd);
			SendMessage(hwnd, WM_SYSCOMMAND, 0xf012, 0);
			break;
		}
		goto left_mouse;

	case WM_LBUTTONDBLCLK:
		if (wParam & MK_CONTROL)
		{
			// double click moves the window back to the default position
			Toolbar_set_pos();
			break;
		}
		goto left_mouse;

	case WM_MOUSEMOVE:
		if (TBInfo.autohidden)
		{
			// bring back from autohide
			SetTimer(hwnd, TOOLBAR_AUTOHIDE_TIMER, 250, NULL);
			Toolbar_AutoHide(false);
			break;
		}
		goto left_mouse;

	case WM_LBUTTONUP:
	left_mouse:
		{
			POINT MouseEventPoint;
			MouseEventPoint.x = (short)LOWORD(lParam);
			MouseEventPoint.y = (short)HIWORD(lParam);
			if (HandleCapture(hwnd, message, MouseEventPoint))
				break;

			for (int i=0; i<5; i++)
				if (CheckButton(
					hwnd,
					message,
					MouseEventPoint,
					&Toolbar_Button[i].r,
					&Toolbar_Button[i].pressed,
					Toolbar_button_event,
					i
					)) goto _break;

			if (message == WM_LBUTTONDOWN)
				SetActiveWindow(hwnd);
		}
	_break:
		break;

		//====================
		// show menus

	case WM_RBUTTONUP:
		{
			int x = (short)LOWORD(lParam);
			if (x < tbClockW)
				PostMessage(BBhwnd, BB_MENU, BB_MENU_TASKS, 0);
			else
				if (x >= TBInfo.width - tbClockW)
					PostMessage(BBhwnd, BB_MENU, BB_MENU_ROOT, 0);
				else
					Toolbar_ShowMenu(true);
			break;
		}

		//====================

	case WM_MBUTTONUP:
		// Is shift key held down?
		if (wParam & MK_SHIFT)
			PostMessage(BBhwnd, BB_TOGGLEPLUGINS, 0, 0);
		else
			PostMessage(BBhwnd, BB_TOGGLETRAY, 0, 0);
		break;

		//====================
		// If moved, snap window to screen edges...

	case WM_WINDOWPOSCHANGING:
		if (Toolbar_moving)
			SnapWindowToEdge((WINDOWPOS*)lParam, 0, SNAP_FULLSCREEN);
		break;

	case WM_ENTERSIZEMOVE:
		Toolbar_moving = true;
		break;

	case WM_EXITSIZEMOVE:
		Toolbar_moving = false;
		break;

		//====================

	case BB_BROADCAST:
		if (0 == _tmemcmp((LPTSTR)lParam, _T("@Toolbar"), 8))
		{
			const TCHAR *argument = (LPTSTR)lParam;
			const struct cfgmenu *p_menu, *p_item;
			const void *v = exec_internal_broam(argument, tb_main, &p_menu, &p_item);
			if (v) goto tbreconfig;
			break;
		}
		if (!_tcsicmp((LPCTSTR)lParam, _T("@BBShowPlugins")))
		{
			Toolbar_hidden = false;
			Toolbar_UpdatePosition();
			break;
		}
		if (!_tcsicmp((LPCTSTR)lParam, _T("@BBHidePlugins")))
		{
			if (Settings_toolbarPluginToggle)
			{
				Toolbar_hidden = true;
				Toolbar_UpdatePosition();
			}
			break;
		}
		break;

	case WM_CLOSE:
		break;

	default:
		return DefWindowProc(hwnd,message,wParam,lParam);

		//====================
	}
	return 0;
}