Ticket #7052: Deskbar_Switcher_cpp_style_fix.diff

File Deskbar_Switcher_cpp_style_fix.diff, 16.2 KB (added by jscipione, 13 years ago)
  • src/apps/deskbar/Switcher.cpp

    diff --git a/src/apps/deskbar/Switcher.cpp b/src/apps/deskbar/Switcher.cpp
    index ef2503d..106dbfd 100644
    a b Except as contained in this notice, the name of Be Incorporated shall not be  
    2626used in advertising or otherwise to promote the sale, use or other dealings in
    2727this Software without prior written authorization from Be Incorporated.
    2828
    29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
    30 of Be Incorporated in the United States and other countries. Other brand product
    31 names are registered trademarks or trademarks of their respective holders.
     29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered
     30trademarks of Be Incorporated in the United States and other countries. Other
     31brand product names are registered trademarks or trademarks of their respective
     32holders.
    3233All rights reserved.
    3334*/
    3435
    public:  
    99100                                TSwitchManager* manager);
    100101    virtual                 ~TSwitcherWindow();
    101102
    102     virtual bool            QuitRequested();
    103     virtual void            MessageReceived(BMessage* message);
    104     virtual void            Show();
    105     virtual void            Hide();
    106     virtual void            WindowActivated(bool state);
     103    virtual bool            QuitRequested();
     104    virtual void            MessageReceived(BMessage* message);
     105    virtual void            Show();
     106    virtual void            Hide();
     107    virtual void            WindowActivated(bool state);
    107108
    108109            void            DoKey(uint32 key, uint32 modifiers);
    109110            TIconView*      IconView();
    public:  
    133134            void            UpdateGroup(int32 groupIndex, int32 windowIndex);
    134135
    135136    virtual void            AttachedToWindow();
    136     virtual void            Draw(BRect update);
    137     virtual void            Pulse();
    138     virtual void            GetPreferredSize(float* w, float* h);
     137    virtual void            Draw(BRect update);
     138    virtual void            Pulse();
     139    virtual void            GetPreferredSize(float* w, float* h);
    139140            void            ScrollTo(float x, float y)
    140                                 { ScrollTo(BPoint(x,y)); }
    141     virtual void            ScrollTo(BPoint where);
     141                            {
     142                                ScrollTo(BPoint(x, y));
     143                            }
     144    virtual void            ScrollTo(BPoint where);
    142145
    143146            void            ShowIndex(int32 windex);
    144147            BRect           FrameOf(int32 index) const;
    public:  
    160163            void            Hiding();
    161164
    162165    virtual void            KeyDown(const char* bytes, int32 numBytes);
    163     virtual void            Pulse();
    164     virtual void            MouseDown(BPoint point);
    165     virtual void            Draw(BRect updateRect);
     166    virtual void            Pulse();
     167    virtual void            MouseDown(BPoint point);
     168    virtual void            Draw(BRect updateRect);
    166169
    167170            void            ScrollTo(float x, float y)
    168                                 { ScrollTo(BPoint(x,y)); }
    169     virtual void    ScrollTo(BPoint where);
     171                            {
     172                                ScrollTo(BPoint(x, y));
     173                            }
     174    virtual void    ScrollTo(BPoint where);
    170175            void            Update(int32 previous, int32 current,
    171176                                int32 previousSlot, int32 currentSlot,
    172177                                bool forward);
    public:  
    197202
    198203    virtual void            Draw(BRect update);
    199204    virtual void            AllAttached();
    200     virtual void            DrawIconScrollers(bool force);
    201     virtual void            DrawWindowScrollers(bool force);
    202     virtual void            MouseDown(BPoint where);
     205    virtual void            DrawIconScrollers(bool force);
     206    virtual void            DrawWindowScrollers(bool force);
     207    virtual void            MouseDown(BPoint where);
    203208
    204209private:
    205210            TSwitchManager* fManager;
    LowBitIndex(uint32 value)  
    250255inline bool
    251256IsVisibleInCurrentWorkspace(const window_info* windowInfo)
    252257{
    253     /*
    254      The window list is always ordered from the top
    255      front visible window (the first on the list), going down through all
    256      the other visible windows, then all the hidden or non workspace
    257      visible window at the end.
    258 
    259      layer > 2 : normal visible window.
    260      layer == 2 : reserved for the desktop window (visible also).
    261      layer < 2 : hidden (0) and non workspace visible window (1)
    262     */
     258    // The window list is always ordered from the top front visible window
     259    // (the first on the list), going down through all the other visible
     260    // windows, then all hidden or non-workspace visible windows at the end.
     261    //     layer > 2  : normal visible window
     262    //     layer == 2 : reserved for the desktop window (visible also)
     263    //     layer < 2  : hidden (0) and non workspace visible window (1)
    263264    return windowInfo->layer > 2;
    264265}
    265266
    bool  
    278279IsWindowOK(const window_info* windowInfo)
    279280{
    280281    // is_mini (true means that the window is minimized).
    281     // if not, then
    282     // show_hide >= 1 means that the window is hidden.
    283     //
     282    // if not, then show_hide >= 1 means that the window is hidden.
    284283    // If the window is both minimized and hidden, then you get :
    285     //  TWindow->is_mini = false;
    286     //  TWindow->was_mini = true;
    287     //  TWindow->show_hide >= 1;
     284    //    TWindow->is_mini = false;
     285    //    TWindow->was_mini = true;
     286    //    TWindow->show_hide >= 1;
    288287
    289288    if (windowInfo->feel != _STD_W_TYPE_)
    290289        return false;
    SmartStrcmp(const char* s1, const char* s2)  
    330329            s2++;
    331330            continue;
    332331        }
    333         if (*s1 != *s2)
    334             return 1;       // they differ
     332        if (*s1 != *s2) {
     333            // they differ
     334            return 1;
     335        }
    335336        s1++;
    336337        s2++;
    337338    }
    338339
    339340    // if one of the strings ended before the other
    340     // ??? could process trailing spaces & underscores!
     341    // TODO: could process trailing spaces and underscores
    341342    if (*s1)
    342343        return 1;
    343344    if (*s2)
    TSwitchManager::TSwitchManager(BPoint point)  
    446447    TBarApp::Subscribe(BMessenger(this), &tmpList);
    447448
    448449    for (int32 i = 0; ; i++) {
    449         BarTeamInfo *barTeamInfo = (BarTeamInfo *)tmpList.ItemAt(i);
     450        BarTeamInfo* barTeamInfo = (BarTeamInfo*)tmpList.ItemAt(i);
    450451        if (!barTeamInfo)
    451452            break;
    452453
    TSwitchManager::MessageReceived(BMessage* message)  
    483484            int i = 0;
    484485            TTeamGroup* tinfo;
    485486            message->FindInt32("team", &teamID);
     487
    486488            while ((tinfo = (TTeamGroup*)fGroupList.ItemAt(i)) != NULL) {
    487489                if (tinfo->TeamList()->HasItem((void*)teamID)) {
    488490                    fGroupList.RemoveItem(i);
    TSwitchManager::MessageReceived(BMessage* message)  
    517519                delete teams;
    518520                break;
    519521            }
     522
    520523            delete smallIcon;
     524
    521525            if (message->FindString("sig", &signature) != B_OK) {
    522526                delete teams;
    523527                break;
    524528            }
     529
    525530            if (message->FindInt32("flags", (int32*)&flags) != B_OK) {
    526531                delete teams;
    527532                break;
    528533            }
     534
    529535            if (message->FindString("name", &name) != B_OK) {
    530536                delete teams;
    531537                break;
    TSwitchManager::MessageReceived(BMessage* message)  
    546552            const char* signature = message->FindString("sig");
    547553            team_id team = message->FindInt32("team");
    548554
    549             int32 numItems = fGroupList.CountItems();
    550             for (int32 i = 0; i < numItems; i++) {
     555            for (int32 i = 0; i < fGroupList.CountItems(); i++) {
    551556                TTeamGroup* tinfo = (TTeamGroup*)fGroupList.ItemAt(i);
    552557                if (strcasecmp(tinfo->Signature(), signature) == 0) {
    553558                    if (!(tinfo->TeamList()->HasItem((void*)team)))
    TSwitchManager::MessageReceived(BMessage* message)  
    562567        {
    563568            team_id team = message->FindInt32("team");
    564569
    565             int32 numItems = fGroupList.CountItems();
    566             for (int32 i = 0; i < numItems; i++) {
     570            for (int32 i = 0; i < fGroupList.CountItems(); i++) {
    567571                TTeamGroup* tinfo = (TTeamGroup*)fGroupList.ItemAt(i);
    568572                if (tinfo->TeamList()->HasItem((void*)team)) {
    569573                    tinfo->TeamList()->RemoveItem((void*)team);
    TSwitchManager::MessageReceived(BMessage* message)  
    584588            // starts differentiating initial key_downs from KeyDowns generated
    585589            // by auto-repeat. Until then the fSkipUntil stuff helps, but it
    586590            // isn't perfect.
    587 
    588591            if (time < fSkipUntil)
    589592                break;
    590593
    TSwitchManager::_SortApps()  
    620623    team_id* teams;
    621624    int32 count;
    622625    if (BPrivate::get_application_order(current_workspace(), &teams, &count)
    623             != B_OK)
     626        != B_OK)
    624627        return;
    625628
    626629    BList groups;
    TSwitchManager::MainEntry(BMessage* message)  
    656659{
    657660    bigtime_t now = system_time();
    658661    bigtime_t timeout = now + 180000;
    659         // The delay above was arrived at by trial and error and
    660         // has a good "feel"
     662        // The above delay has a good "feel" found by trial and error
    661663
    662664    app_info appInfo;
    663665    be_roster->GetActiveAppInfo(&appInfo);
    TSwitchManager::_FindNextValidApp(bool forward)  
    885887            if (fCurrentIndex < 0)
    886888                fCurrentIndex = max - 1;
    887889        }
     890
    888891        if (fCurrentIndex == startIndex) {
    889892            // we've gone completely through the list without finding
    890893            // a good app. Oh well.
    TSwitchManager::_FindNextValidApp(bool forward)  
    898901    return false;
    899902}
    900903
     904
    901905void
    902906TSwitchManager::SwitchToApp(int32 previousIndex, int32 newIndex, bool forward)
    903907{
    TSwitchManager::ActivateApp(bool forceShow, bool allowWorkspaceSwitch)  
    930934
    931935    int32 currentWorkspace = current_workspace();
    932936    TTeamGroup* teamGroup = (TTeamGroup*)fGroupList.ItemAt(fCurrentIndex);
     937
    933938    // Let's handle the easy case first: There's only 1 team in the group
    934939    if (teamGroup->TeamList()->CountItems() == 1) {
    935940        bool result;
    TSwitchManager::ActivateApp(bool forceShow, bool allowWorkspaceSwitch)  
    988993    if (tokens == NULL) {
    989994        ASSERT(windowInfo);
    990995        free(windowInfo);
    991         return true;    // weird error, so don't try to recover
     996        return true;
     997            // weird error, so don't try to recover
    992998    }
    993999
    9941000    BList windowsToActivate;
    TSwitchManager::QuitApp()  
    10401046
    10411047    TTeamGroup* teamGroup;
    10421048    int32 count = 0;
     1049
    10431050    for (int32 i = fCurrentIndex + 1; i < fGroupList.CountItems(); i++) {
    10441051        teamGroup = (TTeamGroup*)fGroupList.ItemAt(i);
    10451052
    TBox::MouseDown(BPoint where)  
    12961303    if (fLeftScroller) {
    12971304        BRect lhit(0, frame.top, frame.left, frame.bottom);
    12981305        if (lhit.Contains(where)) {
    1299             // Want to scroll by NUMSLOTS-1 slots
     1306            // Want to scroll by NUMSLOTS - 1 slots
    13001307            int32 previousIndex = fManager->CurrentIndex();
    13011308            int32 previousSlot = fManager->CurrentSlot();
    13021309            int32 newSlot = previousSlot - (kNumSlots - 1);
    TBox::MouseDown(BPoint where)  
    13111318    if (fRightScroller) {
    13121319        BRect rhit(frame.right, frame.top, bounds.right, frame.bottom);
    13131320        if (rhit.Contains(where)) {
    1314             // Want to scroll by NUMSLOTS-1 slots
     1321            // Want to scroll by NUMSLOTS - 1 slots
    13151322            int32 previousIndex = fManager->CurrentIndex();
    13161323            int32 previousSlot = fManager->CurrentSlot();
    1317             int32 newSlot = previousSlot + (kNumSlots-1);
     1324            int32 newSlot = previousSlot + (kNumSlots - 1);
    13181325            int32 newIndex = fIconView->IndexAt(newSlot);
    13191326
    13201327            if (newIndex < 0) {
    13211328                // don't have a page full to scroll
    13221329                int32 valid = fManager->CountVisibleGroups();
    1323                 newIndex = fIconView->IndexAt(valid-1);
     1330                newIndex = fIconView->IndexAt(valid - 1);
    13241331            }
    13251332            fManager->SwitchToApp(previousIndex, newIndex, true);
    13261333        }
    TBox::MouseDown(BPoint where)  
    13291336    frame = fWindow->WindowView()->Frame();
    13301337    if (fUpScroller) {
    13311338        BRect hit1(frame.left - 10, frame.top, frame.left,
    1332             (frame.top+frame.bottom)/2);
     1339            (frame.top + frame.bottom) / 2);
    13331340        BRect hit2(frame.right, frame.top, frame.right + 10,
    1334             (frame.top+frame.bottom)/2);
     1341            (frame.top + frame.bottom) / 2);
    13351342        if (hit1.Contains(where) || hit2.Contains(where)) {
    13361343            // Want to scroll up 1 window
    13371344            fManager->CycleWindow(false, false);
    TBox::MouseDown(BPoint where)  
    13391346    }
    13401347
    13411348    if (fDownScroller) {
    1342         BRect hit1(frame.left - 10, (frame.top+frame.bottom) / 2, frame.left,
    1343             frame.bottom);
    1344         BRect hit2(frame.right, (frame.top+frame.bottom) / 2, frame.right + 10,
    1345             frame.bottom);
     1349        BRect hit1(frame.left - 10, (frame.top + frame.bottom) / 2,
     1350            frame.left, frame.bottom);
     1351        BRect hit2(frame.right, (frame.top + frame.bottom) / 2,
     1352            frame.right + 10, frame.bottom);
    13461353        if (hit1.Contains(where) || hit2.Contains(where)) {
    13471354            // Want to scroll down 1 window
    13481355            fManager->CycleWindow(true, false);
    TBox::Draw(BRect update)  
    13741381
    13751382    // Fill the area with dark gray
    13761383    SetHighColor(darkGray);
    1377     box.InsetBy(1,1);
     1384    box.InsetBy(1, 1);
    13781385    FillRect(box);
    13791386
    1380     box.InsetBy(-1,-1);
     1387    box.InsetBy(-1, -1);
    13811388
    13821389    BeginLineArray(50);
    13831390
    13841391    // The main frame around the icon view
    1385     AddLine(box.LeftTop(), BPoint(center-kWedge, box.top), veryDarkGray);
    1386     AddLine(BPoint(center+kWedge, box.top), box.RightTop(), veryDarkGray);
     1392    AddLine(box.LeftTop(), BPoint(center - kWedge, box.top), veryDarkGray);
     1393    AddLine(BPoint(center + kWedge, box.top), box.RightTop(), veryDarkGray);
    13871394
    1388     AddLine(box.LeftBottom(), BPoint(center-kWedge, box.bottom), veryDarkGray);
    1389     AddLine(BPoint(center+kWedge, box.bottom), box.RightBottom(), veryDarkGray);
     1395    AddLine(box.LeftBottom(), BPoint(center - kWedge, box.bottom),
     1396        veryDarkGray);
     1397    AddLine(BPoint(center + kWedge, box.bottom), box.RightBottom(),
     1398        veryDarkGray);
    13901399    AddLine(box.LeftBottom() + BPoint(1, 1),
    1391         BPoint(center-kWedge, box.bottom + 1), white);
    1392     AddLine(BPoint(center+kWedge, box.bottom) + BPoint(0, 1),
     1400        BPoint(center - kWedge, box.bottom + 1), white);
     1401    AddLine(BPoint(center + kWedge, box.bottom) + BPoint(0, 1),
    13931402        box.RightBottom() + BPoint(1, 1), white);
    13941403
    13951404    AddLine(box.LeftTop(), box.LeftBottom(), veryDarkGray);
    13961405    AddLine(box.RightTop(), box.RightBottom(), veryDarkGray);
    1397     AddLine(box.RightTop() + BPoint(1, 1),
    1398         box.RightBottom() + BPoint(1, 1), white);
     1406    AddLine(box.RightTop() + BPoint(1, 1), box.RightBottom() + BPoint(1, 1),
     1407        white);
    13991408
    14001409    // downward pointing area at top of frame
    14011410    BPoint point(center - kWedge, box.top);
    14021411    AddLine(point, point + BPoint(kWedge, kWedge), veryDarkGray);
    1403     AddLine(point + BPoint(kWedge, kWedge),
    1404         BPoint(center+kWedge, point.y), veryDarkGray);
     1412    AddLine(point + BPoint(kWedge, kWedge), BPoint(center + kWedge, point.y),
     1413        veryDarkGray);
    14051414
    1406     AddLine(point + BPoint(1, 0),
    1407         point + BPoint(1, 0) + BPoint(kWedge - 1, kWedge - 1), white);
     1415    AddLine(point + BPoint(1, 0), point + BPoint(1, 0)
     1416        + BPoint(kWedge - 1, kWedge - 1), white);
    14081417
    14091418    AddLine(point + BPoint(2, -1) + BPoint(kWedge - 1, kWedge - 1),
    1410         BPoint(center+kWedge-1, point.y), darkGray);
     1419        BPoint(center + kWedge - 1, point.y), darkGray);
    14111420
    14121421    BPoint topPoint = point;
    14131422
    TBox::Draw(BRect update)  
    14161425    point.x = center - kWedge;
    14171426    AddLine(point, point + BPoint(kWedge, -kWedge), veryDarkGray);
    14181427    AddLine(point + BPoint(kWedge, -kWedge),
    1419         BPoint(center+kWedge, point.y), veryDarkGray);
     1428        BPoint(center + kWedge, point.y), veryDarkGray);
    14201429
    14211430    AddLine(point + BPoint(1, 0),
    14221431        point + BPoint(1, 0) + BPoint(kWedge - 1, -(kWedge - 1)), white);
    TBox::Draw(BRect update)  
    14361445
    14371446    // fill the upward pointing arrow area
    14381447    SetHighColor(standardGray);
    1439     FillTriangle(bottomPoint + BPoint(2,0),
     1448    FillTriangle(bottomPoint + BPoint(2, 0),
    14401449        bottomPoint + BPoint(2, 0) + BPoint(kWedge - 2, -(kWedge - 2)),
    14411450        BPoint(center + kWedge - 2, bottomPoint.y));
    14421451
    TBox::DrawIconScrollers(bool force)  
    14671476    }
    14681477
    14691478    int32 maxIndex = fManager->GroupList()->CountItems() - 1;
    1470             // last_frame is in fIconView coordinate space
     1479    // last_frame is in fIconView coordinate space
    14711480    BRect lastFrame = fIconView->FrameOf(maxIndex);
    14721481
    14731482    if (lastFrame.right > rect.right) {
    TIconView::CacheIcons(TTeamGroup* teamGroup)  
    18931902void
    18941903TIconView::AnimateIcon(BBitmap* startIcon, BBitmap* endIcon)
    18951904{
    1896     BRect centerRect(kCenterSlot*kSlotSize, 0,
     1905    BRect centerRect(kCenterSlot * kSlotSize, 0,
    18971906        (kCenterSlot + 1) * kSlotSize - 1, kSlotSize - 1);
    18981907    BRect startIconBounds = startIcon->Bounds();
    18991908    BRect bounds = Bounds();
    TIconView::AnimateIcon(BBitmap* startIcon, BBitmap* endIcon)  
    19171926    fOffBitmap->Lock();
    19181927
    19191928    for (int i = 0; i < 2; i++) {
    1920         startIconBounds.InsetBy(amount,amount);
     1929        startIconBounds.InsetBy(amount, amount);
    19211930        snooze(20000);
    19221931        fOffView->SetDrawingMode(B_OP_COPY);
    19231932        fOffView->FillRect(fOffView->Bounds());
    TIconView::AnimateIcon(BBitmap* startIcon, BBitmap* endIcon)  
    19271936        DrawBitmap(fOffBitmap, destRect);
    19281937    }
    19291938    for (int i = 0; i < 2; i++) {
    1930         startIconBounds.InsetBy(amount,amount);
     1939        startIconBounds.InsetBy(amount, amount);
    19311940        snooze(20000);
    19321941        fOffView->SetDrawingMode(B_OP_COPY);
    19331942        fOffView->FillRect(fOffView->Bounds());
    int32  
    20542063TIconView::SlotOf(int32 index) const
    20552064{
    20562065    BRect rect = FrameOf(index);
     2066
    20572067    return (int32)(rect.left / kSlotSize) - kCenterSlot;
    20582068}
    20592069
    TIconView::DrawTeams(BRect update)  
    21072117
    21082118            SetDrawingMode(B_OP_COPY);
    21092119        }
    2110         rect.OffsetBy(kSlotSize,0);
     2120        rect.OffsetBy(kSlotSize, 0);
    21112121    }
    21122122}
    21132123
    TWindowView::ScrollTo(BPoint where)  
    22012211}
    22022212
    22032213
    2204 
    22052214BRect
    22062215TWindowView::FrameOf(int32 index) const
    22072216{
    TWindowView::Draw(BRect update)  
    22752284    int32 groupIndex = fManager->CurrentIndex();
    22762285    TTeamGroup* teamGroup
    22772286        = (TTeamGroup*)fManager->GroupList()->ItemAt(groupIndex);
     2287
    22782288    if (teamGroup == NULL)
    22792289        return;
    22802290