Changeset 45 for trunk/src/helpers/winh.c
- Timestamp:
- Mar 10, 2001, 12:58:28 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/winh.c
r43 r45 272 272 273 273 /* 274 *@@ winhCopyMenuItem: 275 * copies a menu item from hmenuSource to hmenuTarget. 276 * 277 * This creates a full duplicate. If usID specifies 278 * a submenu, the entire submenu is copied as well 279 * (this will then recurse). 280 * 281 * NOTE: Copying submenus will work only if each item 282 * in the submenu has a unique menu ID. This is due 283 * to the dumb implementation of menus in PM where 284 * it is impossible to query menu items without 285 * knowing their ID. 286 * 287 *@@added V0.9.9 (2001-03-09) [umoeller] 288 */ 289 290 BOOL winhCopyMenuItem(HWND hmenuTarget, 291 HWND hmenuSource, 292 USHORT usID, 293 SHORT sTargetPosition) // in: position to insert at or MIT_END 294 { 295 BOOL brc = FALSE; 296 MENUITEM mi = {0}; 297 if (WinSendMsg(hmenuSource, 298 MM_QUERYITEM, 299 MPFROM2SHORT(usID, 300 FALSE), 301 (MPARAM)&mi)) 302 { 303 // found in source: 304 // is it a separator? 305 if (mi.afStyle & MIS_SEPARATOR) 306 winhInsertMenuSeparator(hmenuTarget, 307 sTargetPosition, 308 usID); 309 else 310 { 311 // no separator: 312 // get item text 313 PSZ pszSource = winhQueryMenuItemText(hmenuSource, 314 usID); 315 if (pszSource) 316 { 317 if ( (mi.afStyle & MIS_SUBMENU) 318 && (mi.hwndSubMenu) 319 ) 320 { 321 // this is the top of a submenu: 322 HWND hwndSubMenu = winhInsertSubmenu(hmenuTarget, 323 sTargetPosition, 324 mi.id, 325 pszSource, 326 mi.afStyle, 327 0, 328 NULL, 329 0, 330 0); 331 if (hwndSubMenu) 332 { 333 // now copy all the items in the submenu 334 SHORT cMenuItems = (SHORT)WinSendMsg(mi.hwndSubMenu, 335 MM_QUERYITEMCOUNT, 336 0, 0); 337 // loop through all entries in the original submenu 338 ULONG i; 339 for (i = 0; 340 i < cMenuItems; 341 i++) 342 { 343 CHAR szItemText[100]; 344 SHORT id = (SHORT)WinSendMsg(mi.hwndSubMenu, 345 MM_ITEMIDFROMPOSITION, 346 MPFROMSHORT(i), 347 0); 348 // recurse 349 winhCopyMenuItem(hwndSubMenu, 350 mi.hwndSubMenu, 351 id, 352 MIT_END); 353 } 354 355 // now check... was the original submenu 356 // "conditional cascade"? 357 if (WinQueryWindowULong(mi.hwndSubMenu, 358 QWL_STYLE) 359 & MS_CONDITIONALCASCADE) 360 // yes: 361 { 362 // get the original default item 363 SHORT sDefID = (SHORT)WinSendMsg(mi.hwndSubMenu, 364 MM_QUERYDEFAULTITEMID, 365 0, 0); 366 // set "conditional cascade style" on target too 367 WinSetWindowBits(hwndSubMenu, 368 QWL_STYLE, 369 MS_CONDITIONALCASCADE, 370 MS_CONDITIONALCASCADE); 371 // and set default item id 372 WinSendMsg(hwndSubMenu, 373 MM_SETDEFAULTITEMID, 374 (MPARAM)sDefID, 375 0); 376 } 377 } // end if (hwndSubmenu) 378 } // end if ( (mi.afStyle & MIS_SUBMENU) 379 else 380 { 381 // no submenu: 382 // just copy that item 383 SHORT s; 384 mi.iPosition = sTargetPosition; 385 s = (SHORT)WinSendMsg(hmenuTarget, 386 MM_INSERTITEM, 387 MPFROMP(&mi), 388 MPFROMP(pszSource)); 389 if (s != MIT_MEMERROR && s != MIT_ERROR) 390 brc = TRUE; 391 } 392 393 free(pszSource); 394 } // end if (pszSource) 395 } // end else if (mi.afStyle & MIS_SEPARATOR) 396 } // end if (WinSendMsg(hmenuSource, MM_QUERYITEM,... 397 398 return (brc); 399 } 400 401 /* 402 *@@ winhMergeIntoSubMenu: 403 * creates a new submenu in hmenuTarget with the 404 * specified title at the specified position 405 * and copies the entire contents of hmenuSource 406 * into that. 407 * 408 * Returns the window handle of the new submenu 409 * or NULLHANDLE on errors. 410 * 411 * NOTE: Copying submenus will work only if each item 412 * in the submenu has a unique menu ID. This is due 413 * to the dumb implementation of menus in PM where 414 * it is impossible to query menu items without 415 * knowing their ID. 416 * 417 *@@added V0.9.9 (2001-03-09) [umoeller] 418 */ 419 420 HWND winhMergeIntoSubMenu(HWND hmenuTarget, // in: menu where to create submenu 421 SHORT sTargetPosition, // in: position to insert at or MIT_END 422 const char *pcszTitle, // in: title of new submenu 423 SHORT sID, // in: ID of new submenu 424 HWND hmenuSource) // in: menu to merge 425 { 426 HWND hwndNewSubmenu = WinCreateMenu(hmenuTarget, NULL); 427 if (hwndNewSubmenu) 428 { 429 MENUITEM mi = {0}; 430 SHORT src = 0; 431 SHORT s = 0; 432 mi.iPosition = MIT_END; 433 mi.afStyle = MIS_TEXT | MIS_SUBMENU; 434 mi.id = 2000; 435 mi.hwndSubMenu = hwndNewSubmenu; 436 437 WinSetWindowUShort(hwndNewSubmenu, QWS_ID, sID); 438 439 // insert new submenu into hmenuTarget 440 src = SHORT1FROMMR(WinSendMsg(hmenuTarget, 441 MM_INSERTITEM, 442 (MPARAM)&mi, 443 (MPARAM)pcszTitle)); 444 if ( (src != MIT_MEMERROR) 445 && (src != MIT_ERROR) 446 ) 447 { 448 int i; 449 SHORT cMenuItems = (SHORT)WinSendMsg(hmenuSource, 450 MM_QUERYITEMCOUNT, 451 0, 0); 452 453 // loop through all entries in the original menu 454 for (i = 0; i < cMenuItems; i++) 455 { 456 SHORT id = (SHORT)WinSendMsg(hmenuSource, 457 MM_ITEMIDFROMPOSITION, 458 MPFROMSHORT(i), 459 0); 460 winhCopyMenuItem(hwndNewSubmenu, 461 hmenuSource, 462 id, 463 MIT_END); 464 } 465 } 466 else 467 { 468 // error: 469 WinDestroyWindow(hwndNewSubmenu); 470 hwndNewSubmenu = NULLHANDLE; 471 } 472 } 473 474 return (hwndNewSubmenu); 475 } 476 477 /* 274 478 *@@ winhQueryMenuItemText: 275 479 * this returns a menu item text as a PSZ
Note:
See TracChangeset
for help on using the changeset viewer.