Ticket #8555: ital_actions.patch

File ital_actions.patch, 4.5 KB (added by ahartford, 12 years ago)

Patch to italicize links on mouse over.

  • src/apps/aboutsystem/HyperTextView.cpp

    From 83580696439302a7fb3111b9de4508f49d35edc8 Mon Sep 17 00:00:00 2001
    From: Adam Hartford <adam.s.hartford@gmail.com>
    Date: Sun, 17 Jun 2012 09:11:28 +0000
    Subject: [PATCH] Italicized links on mouse over (Ticket #8555)
    
    * Added MouseEnter and MouseLeave events.
    * Added helper function to retrieve text offset positions.
    * Eating mouse button events.
    ---
     src/apps/aboutsystem/HyperTextView.cpp |   61 ++++++++++++++++++++++++++++----
     src/apps/aboutsystem/HyperTextView.h   |   10 +++++
     2 files changed, 64 insertions(+), 7 deletions(-)
    
    diff --git a/src/apps/aboutsystem/HyperTextView.cpp b/src/apps/aboutsystem/HyperTextView.cpp
    index d1bc4e6..134ef70 100644
    a b HyperTextAction::Clicked(HyperTextView* view, BPoint where, BMessage* message)  
    4040}
    4141
    4242
     43void
     44HyperTextAction::MouseEnter(HyperTextView* view, BPoint where,
     45    int32 startOffset, int32 endOffset, BMessage* message)
     46{
     47    BFont font(be_plain_font);
     48    font.SetFace(B_ITALIC_FACE);
     49    view->SetFontAndColor(startOffset, endOffset, &font);
     50}
     51
     52
     53void
     54HyperTextAction::MouseLeave(HyperTextView* view, BPoint where,
     55    int32 startOffset, int32 endOffset, BMessage* message)
     56{
     57    BFont font(be_plain_font);
     58    font.SetFace(B_REGULAR_FACE);
     59    view->SetFontAndColor(startOffset, endOffset, &font);
     60}       
     61
     62
    4363// #pragma mark - HyperTextView
    4464
    4565
    void  
    114134HyperTextView::MouseDown(BPoint where)
    115135{
    116136    // We eat all mouse button events.
    117 
    118     BTextView::MouseDown(where);
    119137}
    120138
    121139
    HyperTextView::MouseUp(BPoint where)  
    127145    HyperTextAction* action = _ActionAt(where);
    128146    if (action != NULL)
    129147        action->Clicked(this, where, message);
    130 
    131     BTextView::MouseUp(where);
    132148}
    133149
    134150
    HyperTextView::MouseMoved(BPoint where, uint32 transit,  
    139155    BMessage* message = Window()->CurrentMessage();
    140156
    141157    uint32 buttons;
    142     HyperTextAction* action;
     158    const ActionInfo* info = _ActionInfoAt(where);
    143159    if (message->FindInt32("buttons", (int32*)&buttons) == B_OK
    144         && buttons == 0 && (action = _ActionAt(where)) != NULL) {
     160        && buttons == 0 && info != NULL) {
     161        HyperTextAction* action = info->action;
    145162        action->MouseOver(this, where, message);
     163        if (fActiveInfo == NULL) {
     164            fActiveInfo = info;
     165            action->MouseEnter(this, where, info->startOffset, info->endOffset,
     166                message);
     167        } else if (fActiveInfo != info) {
     168            // This is the scenario where mouse moves from one action directly
     169            // into another.
     170            action->MouseEnter(this, where, info->startOffset, info->endOffset,
     171                message);
     172            fActiveInfo->action->MouseLeave(this, where, fActiveInfo->startOffset,
     173                fActiveInfo->endOffset, message);
     174            fActiveInfo = info;
     175        }
    146176        return;
     177    } else if (fActiveInfo != NULL) {
     178        fActiveInfo->action->MouseLeave(this, where, fActiveInfo->startOffset,
     179            fActiveInfo->endOffset, message);
     180        fActiveInfo = NULL;
    147181    }
    148182
    149183    BTextView::MouseMoved(where, transit, dragMessage);
    HyperTextView::InsertHyperText(const char* inText, int32 inLength,  
    193227HyperTextAction*
    194228HyperTextView::_ActionAt(const BPoint& where) const
    195229{
     230    const ActionInfo* info = _ActionInfoAt(where);
     231    if (info != NULL) {
     232        return info->action;
     233    }
     234
     235    return NULL;
     236}
     237
     238
     239const HyperTextView::ActionInfo*
     240HyperTextView::_ActionInfoAt(const BPoint& where) const
     241{
    196242    int32 offset = OffsetAt(where);
    197243
    198244    ActionInfo pointer(offset, offset + 1, NULL);
    HyperTextView::_ActionAt(const BPoint& where) const  
    204250        BRegion textRegion;
    205251        GetTextRegion(action->startOffset, action->endOffset, &textRegion);
    206252        if (textRegion.Contains(where))
    207             return action->action;
     253            return action;
    208254    }
    209255
    210256    return NULL;
    211257}
    212258
     259
  • src/apps/aboutsystem/HyperTextView.h

    diff --git a/src/apps/aboutsystem/HyperTextView.h b/src/apps/aboutsystem/HyperTextView.h
    index b9d6c2a..f413e2f 100644
    a b public:  
    2424                                    BMessage* message);
    2525    virtual void                Clicked(HyperTextView* view, BPoint where,
    2626                                    BMessage* message);
     27    virtual void                MouseEnter(HyperTextView* view, BPoint where,
     28                                    int32 startOffset, int32 endOffset,
     29                                    BMessage* message);
     30    virtual void                MouseLeave(HyperTextView* view, BPoint where,
     31                                    int32 startOffset, int32 endOffset,
     32                                    BMessage* message);
    2733};
    2834
    2935
    private:  
    5965            class ActionInfoList;
    6066
    6167            ActionInfoList*     fActionInfos;
     68           
     69            const ActionInfo*   _ActionInfoAt(const BPoint& where) const;
     70           
     71            const ActionInfo*   fActiveInfo;
    6272};
    6373
    6474