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); }
void dsp_preset_switcher::findDspNames( pfc::list_t<pfc::string8> &out ) const { // storing menu handles may not be a good idea, since the user can change DSP preset settings without notify this component out.remove_all(); // enumerate mainmenu items service_enum_t<mainmenu_commands> e; service_ptr_t<mainmenu_commands_v2> ptr; while( e.next( ptr ) ) { for( t_uint32 i = 0 , imax = ptr->get_command_count(); i < imax; ++i ) { // lock-on on DSP settings pfc::string8 group_name; ptr->get_name( i , group_name ); const char *DSP_PARENT_STR = "DSP"; // partial match, hope to work with non-English locale if( strstr( group_name.toString() , DSP_PARENT_STR ) == nullptr ) continue; // should be a dynamic item if( !ptr->is_command_dynamic( i ) ) { console::printf( CONSOLE_HEADER "%s(): item is NOT dynamic!!" , __FUNCTION__ ); continue; } const mainmenu_node::ptr dsp_group_node = ptr->dynamic_instantiate( i ); // should be a group node if( dsp_group_node->get_type() != mainmenu_node::type_group ) { console::printf( CONSOLE_HEADER "%s(): node is NOT type_group!!" , __FUNCTION__ ); continue; } // enumerate dsp names for( t_size j = 0 , jmax = dsp_group_node->get_children_count(); ( j < jmax ) && ( jmax > 1 ) ; ++j ) // jmax == 1 when there only exist "Preferences" items { const mainmenu_node::ptr dsp_item_node = dsp_group_node->get_child( j ); if( dsp_item_node->get_type() == mainmenu_node::type_command ) { pfc::string8 n; t_uint32 d; dsp_item_node->get_display( n , d ); out.add_item( n ); //console::printf( CONSOLE_HEADER "%s" , n.toString() ); } else if( dsp_item_node->get_type() == mainmenu_node::type_separator ) { // stop when encountered type_separator break; } } return; } } return; }
//public: unsigned get_num_items() { //return 1; // see if we already cached all this jazz if ( g_mm_names.get_count() > 0 ) { return g_mm_names.get_count(); } unsigned total = 0; service_enum_t<mainmenu_commands> e; service_ptr_t<mainmenu_commands> ptr; g_mm_names.remove_all(); g_mm_guids.remove_all(); while(e.next(ptr)) { unsigned count = ptr->get_command_count(); for ( unsigned n = 0; n < count; n++ ) { pfc::string8 path; pfc::string8 name; GUID guid; t_uint32 p_flags; pfc::string8 str_display; ptr->get_display( n, str_display, p_flags ); ptr->get_name( n, name ); guid = ptr->get_command( n ); find_menu_path( ptr->get_parent(), path ); g_mm_names.add_item( name ); g_mm_guids.add_item( guid ); g_mm_paths.add_item( path ); } total += count; } return total; }
void dsp_preset_switcher::initEntries( pfc::list_t<pfc::string8> &out ) const { // clear existing entries addEntry( "" ); // ensure a 1-item height empty item-list is displayed clearEntires(); // get dsp names out.remove_all(); findDspNames( out ); // add to combo box for( t_size i = 0 , imax = out.get_count(); i < imax ; ++i ) { addEntry( out[i] ); } return; }