Ticket #3825: People[#3825]2.patch

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

Here's an improved version that calls the gFields[] from PeopleApp.h and checks for specific labels with the current label in the TextControl fields (currently handling E-mail and URL). It also handles ftp:// now. It does not handle MouseMoved() as BTextControl cannot directly call it. It also handles ftp:// now. I'd like some reviews on this and possible improvements?

  • BFSBackup/haiku/haiku/src/apps/people/TTextControl.h

     
    1313#ifndef TEXTCONTROL_H
    1414#define TEXTCONTROL_H
    1515
     16#ifndef B_URL_MIME
     17#define B_URL_MIME  "application/x-vnd.Be.URL."
     18#endif
     19
    1620#include <TextControl.h>
    1721
    1822class TTextControl : public BTextControl {
     
    2226        ~TTextControl();
    2327
    2428        virtual void AttachedToWindow(void);
     29        virtual void MouseDown(BPoint);
    2530
    2631        bool Changed(void);
    2732        void Revert(void);
    2833        void Update(void);
     34        void LoadLabels(const char*);
    2935
    3036    private:
     37        BRect   VisibleLabelBounds() const;
    3138        char    *fOriginal;
    3239};
    3340
  • BFSBackup/haiku/haiku/src/apps/people/TTextControl.cpp

     
    1010    This file may be used under the terms of the Be Sample Code License.
    1111*/
    1212
     13#include <Roster.h>
     14#include <StorageKit.h>
     15#include <support/String.h>
     16
    1317#include <string.h>
    1418#include <malloc.h>
    1519#include <Font.h>
    1620
     21#include "PeopleApp.h"
    1722#include "TTextControl.h"
    1823
    1924
     
    5762}
    5863
    5964
     65void
     66TTextControl::MouseDown(BPoint mousePosition)
     67{
     68    if(VisibleLabelBounds().Contains(mousePosition))
     69        LoadLabels(Text());
     70    else
     71        BTextControl::MouseDown(mousePosition);
     72}
     73
     74
    6075bool
    6176TTextControl::Changed(void)
    6277{
     
    7893    fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1);
    7994    strcpy(fOriginal, Text());
    8095}
     96
     97
     98void
     99TTextControl::LoadLabels(const char *fLabel)
     100{
     101    BString argument(fLabel);
     102   
     103    if (BString(gFields[F_URL].name).Append(":") == Label()) {
     104       
     105        if (argument.IFindFirst ("www") == 0)
     106            argument.Prepend ("http://");
     107        else if (argument.IFindFirst ("ftp") == 0)
     108            argument.Prepend ("ftp://");
     109       
     110        const char *args[] = {argument.String(), 0};
     111
     112        if (argument.IFindFirst("http://") == 0
     113                || argument.IFindFirst("ftp://") == 0) {
     114            BString mimeType = B_URL_MIME;
     115            mimeType.Append(argument, argument.FindFirst(':'));
     116            if (!BMimeType::IsValid(mimeType.String()))
     117                return;
     118            be_roster->Launch(mimeType.String(), 1, const_cast<char **>(args));
     119        }
     120    }
     121   
     122    if (BString(gFields[F_EMAIL].name).Append(":") == Label()) {
     123       
     124        if (argument.IFindFirst ("mailto:") != 0 && argument != "")
     125            argument.Prepend("mailto:");
     126       
     127        if (argument != "") {
     128            const char *args[] = {argument.String(), 0};
     129            be_roster->Launch ("text/x-email", 1, const_cast<char **>(args));
     130        }
     131    }
     132   
     133}
     134
     135
     136BRect
     137TTextControl::VisibleLabelBounds() const
     138{
     139    BRect bounds(Bounds());
     140    bounds.right = Divider();
     141    bounds.left = bounds.right - StringWidth(Label());
     142    return bounds;
     143}