]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/stattext.mm
Fix horizontal mouse wheel scrolling in wxGTK.
[wxWidgets.git] / src / cocoa / stattext.mm
CommitLineData
fb896a32 1/////////////////////////////////////////////////////////////////////////////
ccdc11bb 2// Name: src/cocoa/stattext.mm
fb896a32
DE
3// Purpose: wxStaticText
4// Author: David Elliott
5// Modified by:
6// Created: 2003/02/15
fb896a32 7// Copyright: (c) 2003 David Elliott
526954c5 8// Licence: wxWindows licence
fb896a32
DE
9/////////////////////////////////////////////////////////////////////////////
10
449c5673 11#include "wx/wxprec.h"
ccdc11bb
WS
12
13#include "wx/stattext.h"
14
449c5673
DE
15#ifndef WX_PRECOMP
16 #include "wx/app.h"
b9d29922 17 #include "wx/log.h"
449c5673 18#endif //WX_PRECOMP
fb896a32 19
7fc77f30 20#include "wx/cocoa/autorelease.h"
b0c0a393 21#include "wx/cocoa/string.h"
b9d29922 22#include "wx/cocoa/log.h"
7fc77f30 23
fb896a32
DE
24#import <Foundation/NSString.h>
25#import <AppKit/NSTextField.h>
1c54c792 26#include <math.h>
fb896a32 27
fb896a32
DE
28BEGIN_EVENT_TABLE(wxStaticText, wxControl)
29END_EVENT_TABLE()
30WX_IMPLEMENT_COCOA_OWNER(wxStaticText,NSTextField,NSControl,NSView)
31
32bool wxStaticText::Create(wxWindow *parent, wxWindowID winid,
33 const wxString& label,
34 const wxPoint& pos,
35 const wxSize& size,
36 long style,
37 const wxString& name)
38{
7fc77f30 39 wxAutoNSAutoreleasePool pool;
fb896a32
DE
40 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
41 return false;
42 m_cocoaNSView = NULL;
8d656ea9 43 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
fb896a32 44 [m_cocoaNSView release];
5b70207e 45 [GetNSTextField() setStringValue:wxNSStringWithWxString(GetLabelText(label))];
fb896a32
DE
46// [GetNSTextField() setBordered: NO];
47 [GetNSTextField() setBezeled: NO];
48 [GetNSTextField() setEditable: NO];
49 [GetNSTextField() setDrawsBackground: NO];
1c54c792 50
c59112bb
DE
51 NSTextAlignment alignStyle;
52 if (style & wxALIGN_RIGHT)
53 alignStyle = NSRightTextAlignment;
54 else if (style & wxALIGN_CENTRE)
55 alignStyle = NSCenterTextAlignment;
56 else // default to wxALIGN_LEFT because it is 0 and can't be tested
57 alignStyle = NSLeftTextAlignment;
58 [GetNSControl() setAlignment:(NSTextAlignment)alignStyle];
59
fb896a32 60 [GetNSControl() sizeToFit];
1c54c792
DE
61 // Round-up to next integer size
62 NSRect nsrect = [m_cocoaNSView frame];
63 nsrect.size.width = ceil(nsrect.size.width);
64 [m_cocoaNSView setFrameSize: nsrect.size];
65
fb896a32
DE
66 if(m_parent)
67 m_parent->CocoaAddChild(this);
8d656ea9
DE
68 SetInitialFrameRect(pos,size);
69
fb896a32
DE
70 return true;
71}
72
73wxStaticText::~wxStaticText()
74{
911e17c6 75 DisassociateNSTextField(GetNSTextField());
fb896a32
DE
76}
77
78void wxStaticText::SetLabel(const wxString& label)
79{
5b70207e 80 [GetNSTextField() setStringValue:wxNSStringWithWxString(GetLabelText(label))];
b9d29922
DE
81 NSRect oldFrameRect = [GetNSTextField() frame];
82 NSView *superview = [GetNSTextField() superview];
e2b497f7
DE
83
84 if(!(GetWindowStyle() & wxST_NO_AUTORESIZE))
b9d29922 85 {
e2b497f7
DE
86 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel Old Position: (%d,%d)"), GetPosition().x, GetPosition().y);
87 [GetNSTextField() sizeToFit];
88 NSRect newFrameRect = [GetNSTextField() frame];
89 // Ensure new size is an integer so GetSize returns valid data
90 newFrameRect.size.height = ceil(newFrameRect.size.height);
91 newFrameRect.size.width = ceil(newFrameRect.size.width);
92 if(![superview isFlipped])
93 {
94 newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height;
95 }
96 [GetNSTextField() setFrame:newFrameRect];
97 // New origin (wx coords) should always match old origin
98 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel New Position: (%d,%d)"), GetPosition().x, GetPosition().y);
99 [superview setNeedsDisplayInRect:newFrameRect];
b9d29922 100 }
b9d29922 101
e2b497f7 102 [superview setNeedsDisplayInRect:oldFrameRect];
fb896a32
DE
103}
104
d174f457
VZ
105wxString wxStaticText::GetLabel() const
106{
107 wxAutoNSAutoreleasePool pool;
108 return wxStringWithNSString([GetNSTextField() stringValue]);
109}
110
fb896a32
DE
111void wxStaticText::Cocoa_didChangeText(void)
112{
113}