summaryrefslogtreecommitdiff
path: root/src/modules/clist/genmenu.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-06-17 11:11:01 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-06-17 11:11:01 +0000
commit12af7262aa5d8bafecb5a3466cdafee9ca4a0b8b (patch)
tree7a777a136bc11c3f19ceea11dd6790453469b48b /src/modules/clist/genmenu.cpp
parent5fa194797fb9eec6824f9be030817d40178d6f2b (diff)
menu item processing optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@453 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/clist/genmenu.cpp')
-rw-r--r--src/modules/clist/genmenu.cpp63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/modules/clist/genmenu.cpp b/src/modules/clist/genmenu.cpp
index 59fe7a84b2..4c6edd416d 100644
--- a/src/modules/clist/genmenu.cpp
+++ b/src/modules/clist/genmenu.cpp
@@ -791,49 +791,56 @@ static DWORD GetMenuItemType(HMENU hMenu, int uItem)
return mii.fType;
}
+static UINT GetMenuItemTypeData(HMENU hMenu, int uItem, PMO_IntMenuItem& p)
+{
+ MENUITEMINFO mii = { 0 };
+ mii.cbSize = MENUITEMINFO_V4_SIZE;
+ mii.fMask = MIIM_DATA | MIIM_TYPE;
+ GetMenuItemInfo(hMenu, uItem, TRUE, &mii);
+ p = MO_GetIntMenuItem(( HGENMENU )mii.dwItemData );
+ return mii.fType;
+}
+
+static void InsertSeparator(HMENU hMenu, int uItem)
+{
+ MENUITEMINFO mii;
+ mii.cbSize = MENUITEMINFO_V4_SIZE;
+ mii.fMask = MIIM_TYPE;
+ mii.fType = MFT_SEPARATOR;
+ InsertMenuItem( hMenu, uItem, TRUE, &mii );
+}
+
static void InsertMenuItemWithSeparators(HMENU hMenu, int uItem, MENUITEMINFO *lpmii)
{
- PMO_IntMenuItem pimi = MO_GetIntMenuItem(( HGENMENU )lpmii->dwItemData );
+ PMO_IntMenuItem pimi = MO_GetIntMenuItem(( HGENMENU )lpmii->dwItemData ), p;
if (pimi == NULL)
return;
- MENUITEMINFO mii = { 0 };
- mii.cbSize = MENUITEMINFO_V4_SIZE;
//check for separator before
- if ( uItem ) {
- mii.fMask = MIIM_DATA;
- GetMenuItemInfo( hMenu, uItem-1, TRUE, &mii );
- PMO_IntMenuItem p = MO_GetIntMenuItem(( HGENMENU )mii.dwItemData );
- if ( p != NULL && mii.fType != MFT_SEPARATOR) {
- int needSeparator = (p->mi.position / SEPARATORPOSITIONINTERVAL) != (pimi->mi.position / SEPARATORPOSITIONINTERVAL);
- if ( needSeparator) {
+ if (uItem) {
+ UINT fType = GetMenuItemTypeData( hMenu, uItem-1, p);
+ if (p != NULL && fType != MFT_SEPARATOR) {
+ if ((p->mi.position / SEPARATORPOSITIONINTERVAL) != (pimi->mi.position / SEPARATORPOSITIONINTERVAL)) {
//but might be supposed to be after the next one instead
- if ( uItem < GetMenuItemCount(hMenu) && GetMenuItemType(hMenu, uItem) != MFT_SEPARATOR) {
- mii.fMask = MIIM_TYPE;
- mii.fType = MFT_SEPARATOR;
- InsertMenuItem( hMenu, uItem, TRUE, &mii );
- }
+ if ( uItem < GetMenuItemCount(hMenu) && GetMenuItemType(hMenu, uItem) != MFT_SEPARATOR)
+ InsertSeparator(hMenu, uItem);
+
uItem++;
} } }
//check for separator after
if ( uItem < GetMenuItemCount( hMenu )) {
- mii.fMask = MIIM_TYPE;
- GetMenuItemInfo( hMenu, uItem, TRUE, &mii );
- PMO_IntMenuItem p = MO_GetIntMenuItem(( HGENMENU )mii.dwItemData );
- if ( p != NULL && mii.fType == MFT_SEPARATOR ) {
- int needSeparator = (p->mi.position / SEPARATORPOSITIONINTERVAL) != (pimi->mi.position / SEPARATORPOSITIONINTERVAL);
- if ( needSeparator) {
- mii.fMask = MIIM_TYPE;
- mii.fType = MFT_SEPARATOR;
- InsertMenuItem( hMenu, uItem, TRUE, &mii );
- } } }
+ UINT fType = GetMenuItemTypeData( hMenu, uItem, p);
+ if (p != NULL && fType != MFT_SEPARATOR)
+ if ((p->mi.position / SEPARATORPOSITIONINTERVAL) != (pimi->mi.position / SEPARATORPOSITIONINTERVAL))
+ InsertSeparator(hMenu, uItem);
+ }
// create local copy *lpmii so we can change some flags
- mii = *lpmii;
+ MENUITEMINFO mii = *lpmii;
- int count = GetMenuItemCount( hMenu );
- if (count != 0 && (count % 33 ) == 0 && pimi->mi.root != NULL ) {
+ int count = GetMenuItemCount(hMenu);
+ if (count != 0 && (count % 33) == 0 && pimi->mi.root != NULL ) {
if ( !( mii.fMask & MIIM_FTYPE ))
mii.fType = 0;
mii.fMask |= MIIM_FTYPE;