Ticket #3825: People[#3825].patch

File People[#3825].patch, 3.8 KB (added by kitallis, 14 years ago)

sorry about the multiple posts, some weird whitespace problems were creeping in.

  • src/apps/people/TTextControl.h

     
    33//  TextControl.h
    44//
    55//  Written by: Robert Polic
     6//              Akshay Gupta
    67// 
    78//--------------------------------------------------------------------
    89/*
     
    1314#ifndef TEXTCONTROL_H
    1415#define TEXTCONTROL_H
    1516
     17#ifndef B_URL_MIME
     18#define B_URL_MIME  "application/x-vnd.Be.URL."
     19#endif
     20
    1621#include <TextControl.h>
    1722
    1823class TTextControl : public BTextControl {
     
    2227        ~TTextControl();
    2328
    2429        virtual void AttachedToWindow(void);
     30        virtual void MouseDown(BPoint);
     31        virtual void MouseMoved(BPoint, uint32, const BMessage*);
    2532
    2633        bool Changed(void);
    2734        void Revert(void);
    2835        void Update(void);
    2936
    3037    private:
     38        BRect   _VisibleLabelBounds() const;
     39        void    _HandleLabelClicked(const char*);
    3140        char    *fOriginal;
    3241};
    3342
  • src/apps/people/TTextControl.cpp

     
    33//  TTextControl.cpp
    44//
    55//  Written by: Robert Polic
     6//              Akshay Gupta
    67// 
    78//--------------------------------------------------------------------
    89/*
     
    1011    This file may be used under the terms of the Be Sample Code License.
    1112*/
    1213
     14#include <Roster.h>
     15#include <Cursor.h>
     16#include <StorageKit.h>
     17#include <support/String.h>
     18
    1319#include <string.h>
    1420#include <malloc.h>
    1521#include <Font.h>
    1622
     23#include "PeopleApp.h"
    1724#include "TTextControl.h"
    1825
    1926
     
    5764}
    5865
    5966
     67void
     68TTextControl::MouseDown(BPoint mousePosition)
     69{
     70    if(_VisibleLabelBounds().Contains(mousePosition))
     71        _HandleLabelClicked(Text());
     72    else
     73        BTextControl::MouseDown(mousePosition);
     74}
     75
     76void
     77TTextControl::MouseMoved(BPoint mousePosition, uint32 transit, const BMessage* dragMessage)
     78{
     79    if (_VisibleLabelBounds().Contains(mousePosition)) {
     80        BCursor linkCursor(B_CURSOR_ID_FOLLOW_LINK);
     81        SetViewCursor(&linkCursor, true);
     82    } else
     83        SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true);
     84
     85    BTextControl::MouseMoved(mousePosition, transit, dragMessage);
     86}
     87
     88       
    6089bool
    6190TTextControl::Changed(void)
    6291{
     
    78107    fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1);
    79108    strcpy(fOriginal, Text());
    80109}
     110
     111
     112void
     113TTextControl::_HandleLabelClicked(const char *text)
     114{
     115    BString argument(text);
     116   
     117    if (BString(gFields[F_URL].name).Append(":") == Label()) {
     118       
     119        if (argument.IFindFirst("www") == 0)
     120            argument.Prepend("http://");
     121        else if (argument.IFindFirst("ftp") == 0)
     122            argument.Prepend("ftp://");
     123           
     124        const char *args[] = {argument.String(), 0};
     125       
     126        if (argument.IFindFirst("http://") == 0
     127                || argument.IFindFirst("ftp://") == 0
     128                    || argument.IFindFirst("https://") == 0) {     
     129            BString mimeType = B_URL_MIME;
     130            mimeType.Append(argument, argument.FindFirst(':'));
     131            if (!BMimeType::IsValid(mimeType.String()))
     132                return;
     133            be_roster->Launch(mimeType.String(), 1, const_cast<char **>(args));
     134        }
     135    }
     136   
     137    if (BString(gFields[F_EMAIL].name).Append(":") == Label()) {
     138        if (argument.IFindFirst("mailto:") != 0 && argument != "")
     139            argument.Prepend("mailto:");
     140
     141        // TODO: Could check for possible e-mail patterns.
     142        if (argument != "") {
     143            const char *args[] = {argument.String(), 0};
     144            be_roster->Launch("text/x-email", 1, const_cast<char **>(args));
     145        }
     146    }
     147}
     148
     149
     150BRect
     151TTextControl::_VisibleLabelBounds() const
     152{
     153    // TODO: Could actually check current alignment of the label.
     154    // The code below works only for right aligned labels.
     155    BRect bounds(Bounds());
     156    bounds.right = Divider();
     157    bounds.left = bounds.right - StringWidth(Label());
     158    return bounds;
     159}