[haiku-commits] r33704 - haiku/trunk/src/apps/deskbar

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 21 Oct 2009 15:59:55 +0200 (CEST)

Author: axeld
Date: 2009-10-21 15:59:55 +0200 (Wed, 21 Oct 2009)
New Revision: 33704
Changeset: http://dev.haiku-os.org/changeset/33704/haiku

Modified:
   haiku/trunk/src/apps/deskbar/ExpandoMenuBar.cpp
   haiku/trunk/src/apps/deskbar/WindowMenu.cpp
   haiku/trunk/src/apps/deskbar/WindowMenuItem.cpp
   haiku/trunk/src/apps/deskbar/WindowMenuItem.h
Log:
* 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.


Modified: haiku/trunk/src/apps/deskbar/ExpandoMenuBar.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/ExpandoMenuBar.cpp     2009-10-21 13:42:25 UTC 
(rev 33703)
+++ haiku/trunk/src/apps/deskbar/ExpandoMenuBar.cpp     2009-10-21 13:59:55 UTC 
(rev 33704)
@@ -739,10 +739,9 @@
 }
 
 
-/**    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 @@
                                                                                
((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;
                                                                }
                                                        }

Modified: haiku/trunk/src/apps/deskbar/WindowMenu.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/WindowMenu.cpp 2009-10-21 13:42:25 UTC (rev 
33703)
+++ haiku/trunk/src/apps/deskbar/WindowMenu.cpp 2009-10-21 13:59:55 UTC (rev 
33704)
@@ -143,7 +143,8 @@
                                        if (dragging)
                                                item->SetEnabled(false);
 
-                                       AddItem(item, addIndex);
+                                       AddItem(item,
+                                               
TWindowMenuItem::InsertIndexFor(this, 0, item));
                                } else {
                                        TTeamMenuItem* parentItem
                                                = 
static_cast<TTeamMenuItem*>(Superitem());

Modified: haiku/trunk/src/apps/deskbar/WindowMenuItem.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/WindowMenuItem.cpp     2009-10-21 13:42:25 UTC 
(rev 33703)
+++ haiku/trunk/src/apps/deskbar/WindowMenuItem.cpp     2009-10-21 13:59:55 UTC 
(rev 33704)
@@ -56,7 +56,8 @@
 
 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 @@
 
        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 @@
 }
 
 
+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()
 {

Modified: haiku/trunk/src/apps/deskbar/WindowMenuItem.h
===================================================================
--- haiku/trunk/src/apps/deskbar/WindowMenuItem.h       2009-10-21 13:42:25 UTC 
(rev 33703)
+++ haiku/trunk/src/apps/deskbar/WindowMenuItem.h       2009-10-21 13:59:55 UTC 
(rev 33704)
@@ -31,14 +31,10 @@
 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 @@
 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 */
-


Other related posts:

  • » [haiku-commits] r33704 - haiku/trunk/src/apps/deskbar - axeld