WidgetWin.cpp 3.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#include "config.h"
27
#include <windows.h>
28
29
30
31
32
#include "Widget.h"

#include "Cursor.h"
#include "GraphicsContext.h"
#include "FrameWin.h"
33
#include "IntRect.h"
34
35
36
37
38
39
40
#include "Font.h"

namespace WebCore {

class WidgetPrivate
{
public:
ggaren's avatar
ggaren committed
41
    HWND containingWindow;
42
    Font font;
43
    WidgetClient* client;
44
45
46
47
48
};

Widget::Widget()
    : data(new WidgetPrivate)
{
ggaren's avatar
ggaren committed
49
    data->containingWindow = 0;
50
    data->client = 0;
51
52
53
54
55
56
57
}

Widget::~Widget() 
{
    delete data;
}

ggaren's avatar
ggaren committed
58
HWND Widget::containingWindow() const
59
{
ggaren's avatar
ggaren committed
60
    return data->containingWindow;
61
62
}

ggaren's avatar
ggaren committed
63
void Widget::setContainingWindow(HWND hWnd)
64
{
ggaren's avatar
ggaren committed
65
    data->containingWindow = hWnd;
66
67
}

68
69
70
71
72
73
74
75
76
77
void Widget::setClient(WidgetClient* c)
{
    data->client = c;
}

WidgetClient* Widget::client() const
{
    return data->client;
}

78
79
80
IntRect Widget::frameGeometry() const
{
    RECT frame;
ggaren's avatar
ggaren committed
81
82
83
    if (GetWindowRect(data->containingWindow, &frame)) {
        if (HWND containingWindow = GetParent(data->containingWindow))
            MapWindowPoints(NULL, containingWindow, (LPPOINT)&frame, 2);
84
        return frame;
85
86
    }
    
87
88
89
90
91
    return IntRect();
}

bool Widget::hasFocus() const
{
ggaren's avatar
ggaren committed
92
    return (data->containingWindow == GetForegroundWindow());
93
94
95
96
}

void Widget::setFocus()
{
ggaren's avatar
ggaren committed
97
    SetFocus(data->containingWindow);
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
}

void Widget::clearFocus()
{
    FrameWin::clearDocumentFocus(this);
    SetFocus(0);
}

const Font& Widget::font() const
{
    return data->font;
}

void Widget::setFont(const Font& font)
{
    data->font = font;
}

void Widget::setCursor(const Cursor& cursor)
{
118
119
120
121
122
    // SetCursor only works until the next event is recieved.
    // However, we call this method on every mouse-moved,
    // so this should work well enough for our purposes.
    if (HCURSOR c = cursor.impl())
        SetCursor(c);
123
124
125
126
}

void Widget::show()
{
ggaren's avatar
ggaren committed
127
    ShowWindow(data->containingWindow, SW_SHOWNA);
128
129
130
131
}

void Widget::hide()
{
ggaren's avatar
ggaren committed
132
    ShowWindow(data->containingWindow, SW_HIDE);
133
134
135
136
}

void Widget::setFrameGeometry(const IntRect &rect)
{
ggaren's avatar
ggaren committed
137
    MoveWindow(data->containingWindow, rect.x(), rect.y(), rect.width(), rect.height(), false);
138
139
}

adele's avatar
adele committed
140
141
142
143
144
145
146
147
148
149
IntPoint Widget::convertToContainingWindow(const IntPoint& point) const
{
  return point;
}

IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const
{
  return point;
}

150
}