]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/stattext.mm
Replace deprecated wxNB_* flags with wxBK_* used in last commit.
[wxWidgets.git] / src / cocoa / stattext.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/stattext.mm
3 // Purpose: wxStaticText
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/02/15
7 // RCS-ID: $Id:
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13 #ifndef WX_PRECOMP
14 #include "wx/app.h"
15 #include "wx/stattext.h"
16 #include "wx/log.h"
17 #endif //WX_PRECOMP
18
19 #include "wx/cocoa/autorelease.h"
20 #include "wx/cocoa/string.h"
21 #include "wx/cocoa/log.h"
22
23 #import <Foundation/NSString.h>
24 #import <AppKit/NSTextField.h>
25 #include <math.h>
26
27 IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
28 BEGIN_EVENT_TABLE(wxStaticText, wxControl)
29 END_EVENT_TABLE()
30 WX_IMPLEMENT_COCOA_OWNER(wxStaticText,NSTextField,NSControl,NSView)
31
32 bool 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 {
39 wxAutoNSAutoreleasePool pool;
40 if(!CreateControl(parent,winid,pos,size,style,wxDefaultValidator,name))
41 return false;
42 m_cocoaNSView = NULL;
43 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
44 [m_cocoaNSView release];
45 [GetNSTextField() setStringValue:wxNSStringWithWxString(label)];
46 // [GetNSTextField() setBordered: NO];
47 [GetNSTextField() setBezeled: NO];
48 [GetNSTextField() setEditable: NO];
49 [GetNSTextField() setDrawsBackground: NO];
50
51 [GetNSControl() sizeToFit];
52 // Round-up to next integer size
53 NSRect nsrect = [m_cocoaNSView frame];
54 nsrect.size.width = ceil(nsrect.size.width);
55 [m_cocoaNSView setFrameSize: nsrect.size];
56
57 if(m_parent)
58 m_parent->CocoaAddChild(this);
59 SetInitialFrameRect(pos,size);
60
61 return true;
62 }
63
64 wxStaticText::~wxStaticText()
65 {
66 DisassociateNSTextField(GetNSTextField());
67 }
68
69 void wxStaticText::SetLabel(const wxString& label)
70 {
71 [GetNSTextField() setStringValue:wxNSStringWithWxString(label)];
72 NSRect oldFrameRect = [GetNSTextField() frame];
73 NSView *superview = [GetNSTextField() superview];
74 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel Old Position: (%d,%d)"), GetPosition().x, GetPosition().y);
75 [GetNSTextField() sizeToFit];
76 NSRect newFrameRect = [GetNSTextField() frame];
77 // Ensure new size is an integer so GetSize returns valid data
78 newFrameRect.size.height = ceil(newFrameRect.size.height);
79 newFrameRect.size.width = ceil(newFrameRect.size.width);
80 if(![superview isFlipped])
81 {
82 newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height;
83 }
84 [GetNSTextField() setFrame:newFrameRect];
85 // New origin (wx coords) should always match old origin
86 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel New Position: (%d,%d)"), GetPosition().x, GetPosition().y);
87
88 [[GetNSTextField() superview] setNeedsDisplayInRect:oldFrameRect];
89 [[GetNSTextField() superview] setNeedsDisplayInRect:newFrameRect];
90 }
91
92 void wxStaticText::Cocoa_didChangeText(void)
93 {
94 }
95