]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/stattext.mm
default implementations for Replace and Remove
[wxWidgets.git] / src / cocoa / stattext.mm
CommitLineData
fb896a32
DE
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
065e208e 9// Licence: wxWidgets licence
fb896a32
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673
DE
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/app.h"
15 #include "wx/stattext.h"
b9d29922 16 #include "wx/log.h"
449c5673 17#endif //WX_PRECOMP
fb896a32 18
7fc77f30 19#include "wx/cocoa/autorelease.h"
b0c0a393 20#include "wx/cocoa/string.h"
b9d29922 21#include "wx/cocoa/log.h"
7fc77f30 22
fb896a32
DE
23#import <Foundation/NSString.h>
24#import <AppKit/NSTextField.h>
1c54c792 25#include <math.h>
fb896a32
DE
26
27IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl)
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];
b0c0a393 45 [GetNSTextField() setStringValue:wxNSStringWithWxString(label)];
fb896a32
DE
46// [GetNSTextField() setBordered: NO];
47 [GetNSTextField() setBezeled: NO];
48 [GetNSTextField() setEditable: NO];
49 [GetNSTextField() setDrawsBackground: NO];
1c54c792 50
fb896a32 51 [GetNSControl() sizeToFit];
1c54c792
DE
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
fb896a32
DE
57 if(m_parent)
58 m_parent->CocoaAddChild(this);
8d656ea9
DE
59 SetInitialFrameRect(pos,size);
60
fb896a32
DE
61 return true;
62}
63
64wxStaticText::~wxStaticText()
65{
911e17c6 66 DisassociateNSTextField(GetNSTextField());
fb896a32
DE
67}
68
69void wxStaticText::SetLabel(const wxString& label)
70{
b9d29922
DE
71 [GetNSTextField() setStringValue:wxNSStringWithWxString(label)];
72 NSRect oldFrameRect = [GetNSTextField() frame];
73 NSView *superview = [GetNSTextField() superview];
2e11bb42 74 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel Old Position: (%d,%d)"), GetPosition().x, GetPosition().y);
b9d29922
DE
75 [GetNSTextField() sizeToFit];
76 NSRect newFrameRect = [GetNSTextField() frame];
e9247fda
DE
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);
b9d29922
DE
80 if(![superview isFlipped])
81 {
82 newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height;
b9d29922 83 }
e9247fda
DE
84 [GetNSTextField() setFrame:newFrameRect];
85 // New origin (wx coords) should always match old origin
2e11bb42 86 wxLogTrace(wxTRACE_COCOA_Window_Size, wxT("wxStaticText::SetLabel New Position: (%d,%d)"), GetPosition().x, GetPosition().y);
b9d29922
DE
87
88 [[GetNSTextField() superview] setNeedsDisplayInRect:oldFrameRect];
89 [[GetNSTextField() superview] setNeedsDisplayInRect:newFrameRect];
fb896a32
DE
90}
91
92void wxStaticText::Cocoa_didChangeText(void)
93{
94}
95