~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to src/tools/mac_dock/mac_dock.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2006-01-20 00:20:36 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060120002036-7nw6yo6totip0ee5
Tags: 0.10-2
* Added upstream changelog (Closes: Bug#327748)
* Mention --no-gpg and --no-gpg-agent in manpage (Closes: Bug#204416)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "mac_dock.h"
 
2
 
 
3
#include "ApplicationServices/ApplicationServices.h"
 
4
#include "Carbon/Carbon.h"
 
5
 
 
6
#define DOCK_FONT_NAME "LucidaGrande-Bold"
 
7
#define DOCK_FONT_SIZE 24
 
8
        
 
9
static NMRec bounceRec;
 
10
 
 
11
/*!
 
12
 * Converts a QString to a CoreFoundation string, preserving Unicode.
 
13
 *
 
14
 * \param s the string to be converted.
 
15
 * \return a reference to a CoreFoundation string.
 
16
 */
 
17
/*static CFStringRef qString2CFString(const QString& s)
 
18
{
 
19
        if (s.isNull())
 
20
                return 0;
 
21
        
 
22
        ushort* buffer = new ushort[s.length()];
 
23
        for (unsigned int i = 0; i < s.length(); ++i)
 
24
                buffer[i] = s[i].unicode();
 
25
        CFStringRef result = CFStringCreateWithBytes ( NULL, 
 
26
                (UInt8*) buffer, 
 
27
                s.length()*sizeof(ushort),
 
28
                kCFStringEncodingUnicode, false);
 
29
 
 
30
        delete buffer;
 
31
        return result;
 
32
}*/
 
33
 
 
34
void MacDock::startBounce()
 
35
{
 
36
        if (!isBouncing) {
 
37
                bounceRec.qType = nmType;
 
38
                bounceRec.nmMark = 1;
 
39
                NMInstall(&bounceRec);
 
40
                isBouncing = true;
 
41
        }
 
42
}
 
43
 
 
44
void MacDock::stopBounce()
 
45
{
 
46
        if(isBouncing) {
 
47
                NMRemove(&bounceRec);
 
48
                isBouncing = false;
 
49
        }
 
50
}
 
51
 
 
52
void MacDock::overlay(const QString& text)
 
53
{
 
54
        if (text.isEmpty()) {
 
55
                overlayed = false;
 
56
                RestoreApplicationDockTileImage();
 
57
                return;
 
58
        }
 
59
 
 
60
        // Create the context
 
61
        CGContextRef context = BeginCGContextForApplicationDockTile();
 
62
 
 
63
        if (!overlayed) {
 
64
                overlayed = true;
 
65
 
 
66
                // Add some subtle drop down shadow
 
67
                // FIXME: Disabled because 10.2 doesn't support it
 
68
                //CGSize s = { 2.0, -4.0 };
 
69
                //CGContextSetShadow(context,s,5.0);
 
70
        }
 
71
 
 
72
        // Draw a circle
 
73
        CGContextBeginPath(context);
 
74
        CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
 
75
        CGContextClosePath(context);
 
76
        CGContextSetRGBFillColor(context, 1, 0.0, 0.0, 1);
 
77
        CGContextFillPath(context);
 
78
 
 
79
        // Set the clipping path to the same circle
 
80
        CGContextBeginPath(context);
 
81
        CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
 
82
        CGContextClip(context);
 
83
 
 
84
        // Remove drop shadow
 
85
        // FIXME: Disabled because 10.2 doesn't support it
 
86
        //CGSize s = { 0.0, -0.0 };
 
87
        //CGContextSetShadowWithColor(context, s, 0, NULL);
 
88
 
 
89
        // Select the appropriate font
 
90
        CGContextSelectFont(context,DOCK_FONT_NAME, DOCK_FONT_SIZE, kCGEncodingMacRoman);
 
91
        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
 
92
 
 
93
        // Draw the text invisible
 
94
        CGPoint begin = CGContextGetTextPosition(context);
 
95
        CGContextSetTextDrawingMode(context, kCGTextInvisible); 
 
96
        CGContextShowTextAtPoint(context, begin.x, begin.y, text.latin1(), text.length());
 
97
        CGPoint end = CGContextGetTextPosition(context);
 
98
 
 
99
        // Draw the text
 
100
        CGContextSetTextDrawingMode(context, kCGTextFill);      
 
101
        CGContextShowTextAtPoint(context, 95 - (end.x - begin.x)/2, 95 - 8, text.latin1(), text.length());
 
102
        
 
103
        // Cleanup
 
104
        CGContextFlush(context);
 
105
        EndCGContextForApplicationDockTile(context);
 
106
}
 
107
 
 
108
bool MacDock::isBouncing = false;
 
109
bool MacDock::overlayed = false;