* Moved the window item sort logic as static method into the TWindowMenuItem

class.
* Changed ExpandoMenuBar to use that logic as well, so that your entries will
  always keep the same sort order.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33704 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-10-21 13:59:55 +00:00
parent b18f133db3
commit 1c7348a787
4 changed files with 72 additions and 43 deletions

View File

@ -739,10 +739,9 @@ TExpandoMenuBar::DrawBackground(BRect)
}
/** Something to help determine if we are showing too many apps
* need to add in scrolling functionality.
*/
/*! Something to help determine if we are showing too many apps
need to add in scrolling functionality.
*/
void
TExpandoMenuBar::CheckForSizeOverrun()
{
@ -833,7 +832,9 @@ TExpandoMenuBar::monitor_team_windows(void* arg)
((1 << current_workspace())
& wInfo->workspaces) != 0, false);
item->ExpandedItem(true);
teamMenu->AddItem(item, i + 1);
teamMenu->AddItem(item,
TWindowMenuItem::InsertIndexFor(
teamMenu, i + 1, item));
resize = true;
}
}

View File

@ -143,7 +143,8 @@ TWindowMenu::AttachedToWindow()
if (dragging)
item->SetEnabled(false);
AddItem(item, addIndex);
AddItem(item,
TWindowMenuItem::InsertIndexFor(this, 0, item));
} else {
TTeamMenuItem* parentItem
= static_cast<TTeamMenuItem*>(Superitem());

View File

@ -56,7 +56,8 @@ const BRect kIconRect(1.0f, 1.0f, 13.0f, 14.0f);
TWindowMenuItem::TWindowMenuItem(const char* title, int32 id, bool mini,
bool currentWorkspace, bool dragging)
: BMenuItem(title, NULL),
:
BMenuItem(title, NULL),
fID(id),
fMini(mini),
fCurrentWorkSpace(currentWorkspace),
@ -85,6 +86,7 @@ TWindowMenuItem::Initialize(const char* title)
BFont font(be_plain_font);
fTitleWidth = ceilf(font.StringWidth(title));
fFullTitle = title;
font_height fontHeight;
font.GetHeight(&fontHeight);
fTitleAscent = ceilf(fontHeight.ascent);
@ -134,6 +136,27 @@ TWindowMenuItem::SetLabel(const char* string)
}
const char*
TWindowMenuItem::FullTitle() const
{
return fFullTitle.String();
}
/*static*/ int32
TWindowMenuItem::InsertIndexFor(BMenu* menu, int32 startIndex,
TWindowMenuItem* newItem)
{
for (int32 index = startIndex;; index++) {
TWindowMenuItem* item
= dynamic_cast<TWindowMenuItem*>(menu->ItemAt(index));
if (item == NULL
|| strcasecmp(item->FullTitle(), newItem->FullTitle()) > 0)
return index;
}
}
int32
TWindowMenuItem::ID()
{

View File

@ -31,14 +31,10 @@ of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
// individual windows of an application
// item for WindowMenu, sub of TeamMenuItem
// all DB positions
#ifndef WINDOWMENUITEM_H
#define WINDOWMENUITEM_H
#include <MenuItem.h>
#include <String.h>
#include <WindowInfo.h>
@ -47,43 +43,51 @@ All rights reserved.
class BBitmap;
/*! Individual windows of an application item for WindowMenu,
sub of TeamMenuItem all DB positions
*/
class TWindowMenuItem : public BMenuItem {
public:
TWindowMenuItem(const char* title, int32 id, bool mini,
bool currentWorkSpace, bool dragging = false);
public:
TWindowMenuItem(const char* title, int32 id,
bool mini, bool currentWorkSpace,
bool dragging = false);
void ExpandedItem(bool state);
void SetTo(const char* title, int32 id, bool mini,
bool currentWorkSpace, bool dragging = false);
int32 ID();
void SetRequireUpdate();
bool RequiresUpdate();
bool ChangedState();
void ExpandedItem(bool state);
void SetTo(const char* title, int32 id, bool mini,
bool currentWorkSpace,
bool dragging = false);
int32 ID();
void SetRequireUpdate();
bool RequiresUpdate();
bool ChangedState();
virtual void SetLabel(const char* string);
virtual void SetLabel(const char* string);
const char* FullTitle() const;
protected:
void Initialize(const char* title);
virtual void GetContentSize(float* width, float* height);
virtual void DrawContent();
virtual status_t Invoke(BMessage* message = NULL);
virtual void Draw();
static int32 InsertIndexFor(BMenu* menu, int32 startIndex,
TWindowMenuItem* item);
private:
int32 fID;
bool fMini;
bool fCurrentWorkSpace;
const BBitmap* fBitmap;
float fTitleWidth;
float fTitleAscent;
float fTitleDescent;
bool fDragging;
bool fExpanded;
bool fRequireUpdate;
bool fModified;
BString fFullTitle;
protected:
void Initialize(const char* title);
virtual void GetContentSize(float* width, float* height);
virtual void DrawContent();
virtual status_t Invoke(BMessage* message = NULL);
virtual void Draw();
private:
int32 fID;
bool fMini;
bool fCurrentWorkSpace;
const BBitmap* fBitmap;
float fTitleWidth;
float fTitleAscent;
float fTitleDescent;
bool fDragging;
bool fExpanded;
bool fRequireUpdate;
bool fModified;
BString fFullTitle;
};
#endif /* WINDOWMENUITEM_H */