Esempio n. 1
1
LRESULT menu_extension::on_message(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
{
	switch (msg) 
	{
		case WM_CREATE:
		{
			initialised = true;

			mainmenu_root_group::g_get_root_items(m_buttons);
			t_size button_count = m_buttons.get_count();

			pfc::array_t<TBBUTTON> tbb;
			tbb.set_size(button_count);
			memset(tbb.get_ptr(), 0, tbb.get_size() * sizeof(TBBUTTON));

			wnd_menu = CreateWindowEx(/*TBSTYLE_EX_MIXEDBUTTONS|*/WS_EX_TOOLWINDOW, TOOLBARCLASSNAME, NULL,
				WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_LIST | CCS_NORESIZE | CCS_NOPARENTALIGN | CCS_NODIVIDER,
				0, 0, 0, 25, wnd, (HMENU)ID_MENU, core_api::get_my_instance(), NULL);

			if (wnd_menu)
			{
				SetWindowLongPtr(wnd_menu, GWLP_USERDATA, (LPARAM)(this));

				SendMessage(wnd_menu, TB_SETBITMAPSIZE, (WPARAM)0, MAKELONG(0, 0));
				SendMessage(wnd_menu, TB_SETBUTTONSIZE, (WPARAM)0, MAKELONG(0,/*GetSystemMetrics(SM_CYMENUSIZE)*/0));

				SendMessage(wnd_menu, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);

				unsigned n, count = tbb.get_size();
				for (n = 0; n < count; n++)
				{
					tbb[n].iBitmap = I_IMAGECALLBACK;
					tbb[n].idCommand = n + 1;
					tbb[n].fsState = TBSTATE_ENABLED;
					tbb[n].fsStyle = BTNS_DROPDOWN | BTNS_AUTOSIZE;
					tbb[n].dwData = 0;
					tbb[n].iString = (int)m_buttons[n].m_name_with_accelerators.get_ptr();
				}

				SendMessage(wnd_menu, TB_ADDBUTTONS, (WPARAM)tbb.get_size(), (LPARAM)(LPTBBUTTON)tbb.get_ptr());

				//			SendMessage(wnd_menu, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);

				//			SendMessage(wnd_menu, TB_AUTOSIZE, 0, 0); 

							//if (is_win2k_or_newer())
				{
					BOOL a = true;
					SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &a, 0);
					SendMessage(wnd_menu, WM_UPDATEUISTATE, MAKEWPARAM(a ? UIS_CLEAR : UIS_SET, UISF_HIDEACCEL), 0);
				}

				//			SendMessage(wnd_menu, TB_SETPARENT, (WPARAM) (HWND)wnd_host, 0);
				menuproc = (WNDPROC)SetWindowLongPtr(wnd_menu, GWLP_WNDPROC, (LPARAM)main_hook);
			}


			break;
		}
		case WM_WINDOWPOSCHANGED:
		{
			LPWINDOWPOS lpwp = (LPWINDOWPOS)lp;
			if (!(lpwp->flags & SWP_NOSIZE))
			{
				//SIZE sz = {0,0};
				//SendMessage(wnd_menu, TB_GETMAXSIZE, NULL, (LPARAM)&sz);

				RECT rc = { 0,0,0,0 };
				t_size count = m_buttons.get_count();
				int cx = lpwp->cx;
				int cy = lpwp->cy;
				int extra = 0;
				if (count && (BOOL)SendMessage(wnd_menu, TB_GETITEMRECT, count - 1, (LPARAM)(&rc)))
				{
					cx = min(cx, rc.right);
					cy = min(cy, rc.bottom);
					extra = (lpwp->cy - rc.bottom) / 2;
				}
				SetWindowPos(wnd_menu, 0, 0, extra, cx, cy, SWP_NOZORDER);
				RedrawWindow(wnd, 0, 0, RDW_ERASE | RDW_INVALIDATE);
			}
			break;
		}

		case WM_NOTIFY:
		{
			if (((LPNMHDR)lp)->idFrom == ID_MENU) {
				switch (((LPNMHDR)lp)->code)
				{
				case TBN_HOTITEMCHANGE:
				{
					if (!(((LPNMTBHOTITEM)lp)->dwFlags & HICF_LEAVING) && (((LPNMTBHOTITEM)lp)->dwFlags & HICF_MOUSE || ((LPNMTBHOTITEM)lp)->dwFlags & HICF_LMOUSE))
						redrop = true;
					break;
				}
				case TBN_DROPDOWN:
				{
					if (redrop)
						PostMessage(wnd, MSG_CREATE_MENU, ((LPNMTOOLBAR)lp)->iItem, 0);
					else
						redrop = true;

					return TBDDRET_DEFAULT;
				}
				}
			}
			break;
		}
		case MSG_HIDE_MENUACC:
		{
			//if (is_win2k_or_newer())
			{
				BOOL a = true;
				SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &a, 0);
				if ((SendMessage(wnd_menu, WM_QUERYUISTATE, 0, 0) & UISF_HIDEACCEL) != !a)
					SendMessage(wnd_menu, WM_UPDATEUISTATE, MAKEWPARAM(a ? UIS_CLEAR : UIS_SET, UISF_HIDEACCEL), 0);
			}
			break;
		}
		case MSG_SHOW_MENUACC:
		{
			//if (is_win2k_or_newer())
			{
				SendMessage(wnd_menu, WM_UPDATEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL), 0);
			}
			break;
		}
		case MSG_CREATE_MENU:
		{
			if (lp) SetFocus(wnd_menu);
			active_item = wp;

			make_menu(wp);
			break;
		}
		case WM_MENUSELECT:
		{
			if (HIWORD(wp) & MF_POPUP)
			{
				is_submenu = true;
				m_status_override.release();
			}
			else
			{
				is_submenu = false;
				if (p_manager.is_valid())
				{
					unsigned id = LOWORD(wp);

					bool set = false;

					pfc::string8 blah;

					set = p_manager->get_description(id - 1, blah);

					service_ptr_t<ui_status_text_override> p_status_override;

					if (set)
					{
						get_host()->override_status_text_create(p_status_override);

						if (p_status_override.is_valid())
						{
							p_status_override->override_text(blah);
						}
					}
					m_status_override = p_status_override;
				}
			}
			break;
		}
		case WM_INITMENUPOPUP:
		{
			sub_menu_ref_count++;
			break;
		}
		case WM_UNINITMENUPOPUP:
		{
			sub_menu_ref_count--;
			break;
		}
		case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO mmi = LPMINMAXINFO(lp);

			RECT rc = { 0,0,0,0 };
			SendMessage(wnd_menu, TB_GETITEMRECT, m_buttons.get_count() - 1, (LPARAM)(&rc));

			//SIZE sz = {0,0};
			//SendMessage(wnd_menu, TB_GETMAXSIZE, NULL, (LPARAM)&sz);
			//console::formatter() << sz.cx << sz.cy;

			mmi->ptMinTrackSize.x = rc.right;
			mmi->ptMinTrackSize.y = rc.bottom;
			mmi->ptMaxTrackSize.y = rc.bottom;
			return 0;
		}
		case WM_SETTINGCHANGE:
		{
			if (wp == SPI_SETNONCLIENTMETRICS)
			{
				PostMessage(wnd, MSG_SIZE_LIMIT_CHANGE, 0, 0);
			}
			break;
		}
		case SPI_GETKEYBOARDCUES:
		{
			BOOL a = TRUE;
			SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &a, 0);
			SendMessage(wnd_menu, WM_UPDATEUISTATE, MAKEWPARAM((a || GetFocus() == wnd_menu) ? UIS_CLEAR : UIS_SET, UISF_HIDEACCEL), 0);
			break;
		}
		case MSG_SIZE_LIMIT_CHANGE:
		{
			get_host()->on_size_limit_change(wnd, uie::size_limit_minimum_height | uie::size_limit_maximum_height | uie::size_limit_minimum_width);
			break;
		}
		case WM_DESTROY:
		{
			DestroyWindow(wnd_menu);
			wnd_menu = NULL;
			m_buttons.remove_all();
			initialised = false;
			break;
		}
	}
	return DefWindowProc(wnd, msg, wp, lp);
}
Esempio n. 2
0
	void retag_commit(abort_callback &p_abort)
	{
		m_file.release();
		filesystem::g_open(m_file, filename, filesystem::open_mode_write_new, p_abort);
		this->p_abort = &p_abort;
		ByteWriter bw = { this, static_write };
		if (!ASAPWriter_Write(filename, bw, ASAP_GetInfo(asap), module, module_len, FALSE))
			throw exception_io_unsupported_format();
	}
Esempio n. 3
0
void refresh_all_playlist_views()
{
	if (playlist_view::g_get_cache().is_active())
	{
		g_to_global.release();
		g_to_global_colour.release();
		playlist_view::g_reset_columns();
		unsigned m, pcount = playlist_view::list_playlist.get_count();
		for (m = 0; m < pcount; m++)
		{
			playlist_view * p_playlist = playlist_view::list_playlist.get_item(m);
			p_playlist->create_header();
			if (p_playlist->wnd_header)
				p_playlist->move_header();
		}
		playlist_view::update_all_windows();
	}
}
Esempio n. 4
0
	void retag_commit(abort_callback &p_abort)
	{
		byte out_module[ASAP_MODULE_MAX];
		int out_len = ASAP_SetModuleInfo(&module_info, module, module_len, out_module);
		if (out_len <= 0)
			throw exception_io_unsupported_format();
		m_file.release();
		filesystem::g_open(m_file, filename, filesystem::open_mode_write_new, p_abort);
		m_file->write(out_module, out_len, p_abort);
	}
Esempio n. 5
0
void spectrum_extension::disable()
{
	b_active = false;

	list_vis.remove_item(this);

	static_api_ptr_t<play_callback_manager>()->unregister_callback(this);
	if (static_api_ptr_t<play_control>()->is_playing())
		g_deregister_stream(this);

	if (!list_vis.get_count())
		g_stream.release();

	p_host.release();
}
Esempio n. 6
0
void menu_extension::make_menu(unsigned idx)
{
	if (idx == actual_active || hooked || idx < 1 || idx > m_buttons.get_count()) return;

	service_ptr_t<menu_extension> dummy = this; //menu command may delete us
	
	actual_active = idx;
	
	RECT rc;
	POINT pt;
	
	SendMessage(wnd_menu, TB_GETRECT,	idx, (LPARAM)&rc);
	
	MapWindowPoints(wnd_menu, HWND_DESKTOP, (LPPOINT)&rc, 2);  
	
	pt.x = rc.left;
	pt.y = rc.bottom;

	HMENU menu = CreatePopupMenu();

	hooked = true;
//	p_hooked_menu = this;
	message_hook_manager::register_hook(message_hook_manager::type_message_filter, this);
	//msghook = uSetWindowsHookEx(WH_MSGFILTER, menu_hook_t_proc, 0, GetCurrentThreadId());
	service_ptr_t<mainmenu_manager> p_menu = standard_api_create_t<mainmenu_manager>();

	bool b_keyb = standard_config_objects::query_show_keyboard_shortcuts_in_menus();


	if (p_menu.is_valid())
	{
		p_menu->instantiate(m_buttons[idx-1].m_guid);
		p_menu->generate_menu_win32(menu,1,-1,b_keyb ? mainmenu_manager::flag_show_shortcuts : 0);
		menu_helpers::win32_auto_mnemonics(menu);
	}

	SendMessage(wnd_menu, TB_PRESSBUTTON, idx, TRUE);
	SendMessage(wnd_menu, TB_SETHOTITEM, idx-1, 0);
	is_submenu = false;

	sub_menu_ref_count = -1; //we get a notificationwhen the inital menu is created

//	RECT rc_desktop;
//	if (GetWindowRect(GetDesktopWindow(), &rc_desktop))

//	if (pt.x < rc_desktop.left) pt.x = rc_desktop.left;
//	else if (pt.x > rc_desktop.right) pt.x = rc_desktop.right;

	p_manager = p_menu;

	TPMPARAMS tpmp;
	memset(&tpmp, 0, sizeof(TPMPARAMS));
	tpmp.cbSize = sizeof(tpmp);

	GetWindowRect(wnd_menu, &tpmp.rcExclude);

	HMONITOR mon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

	if (mon)
	{
		MONITORINFO mi;
		memset(&mi, 0, sizeof(MONITORINFO));
		mi.cbSize = sizeof(MONITORINFO);
		if (uGetMonitorInfo(mon, &mi))
		{
			if (pt.x < mi.rcMonitor.left) pt.x = mi.rcMonitor.left;
			tpmp.rcExclude.left = mi.rcMonitor.left;
			tpmp.rcExclude.right = mi.rcMonitor.right;
		}
	}

//	menu_info::MENU_A_BASE = 1;
//	menu_info::MENU_B_BASE = -1;

	if (GetFocus() != wnd_menu) 
		wnd_prev_focus = GetFocus();

	int cmd = TrackPopupMenuEx(menu,TPM_LEFTBUTTON|TPM_RETURNCMD,pt.x,pt.y,get_wnd(),&tpmp);
//	int cmd = TrackPopupMenuEx(menu,TPM_LEFTBUTTON|TPM_RETURNCMD,pt.x,pt.y,g_main_window,0);
	
	m_status_override.release();

	//SendMessage(wnd_menu, TB_PRESSBUTTON, idx, FALSE);

	PostMessage(wnd_menu, TB_PRESSBUTTON, idx, FALSE);
	if (GetFocus() != wnd_menu) 
	{
		PostMessage(wnd_menu, TB_SETHOTITEM, -1, 0);
	}



	DestroyMenu(menu);

	if (cmd>0 && p_menu.is_valid())
	{
//		SendMessage(wnd_menu, TB_SETHOTITEM, -1, 0);
		if (IsWindow(wnd_prev_focus))
			SetFocus(wnd_prev_focus);
		p_menu->execute_command(cmd - 1);
	}

//	if (p_menu.is_valid()) 
	{
		p_manager.release();
		p_menu.release();
	}

	//UnhookWindowsHookEx(msghook); // hook may not be freed instantly, so dont make msghook = 0
	message_hook_manager::deregister_hook(message_hook_manager::type_message_filter, this);
	hooked = false;
	//p_hooked_menu=0;

	actual_active = 0;
}