1///////////////////////////////////////////////////////////////////////////// 2// Name: src/cocoa/utils.cpp 3// Purpose: Various utilities 4// Author: AUTHOR 5// Modified by: 6// Created: 2003/??/?? 7// RCS-ID: $Id: utils.mm 48184 2007-08-19 19:22:09Z DE $ 8// Copyright: (c) AUTHOR 9// Licence: wxWindows licence 10///////////////////////////////////////////////////////////////////////////// 11 12#include "wx/wxprec.h" 13 14#include "wx/utils.h" 15 16#ifndef WX_PRECOMP 17 #include "wx/app.h" 18#endif // WX_PRECOMP 19 20#include "wx/apptrait.h" 21#include "wx/display.h" 22 23#include <ctype.h> 24 25#include <stdio.h> 26#include <stdlib.h> 27#include <string.h> 28#include <stdarg.h> 29 30#include "wx/cocoa/string.h" 31 32#import <Foundation/NSURL.h> 33#import <AppKit/NSWorkspace.h> 34 35void wxDisplaySize(int *width, int *height) 36{ 37 // TODO 38 if(width) 39 *width = 1024; 40 if(height) 41 *height = 768; 42} 43 44void wxDisplaySizeMM(int*,int*) 45{ 46 // TODO 47} 48 49void wxClientDisplayRect(int *x,int *y,int *width,int *height) 50{ 51 // TODO 52 if(x) 53 *x = 0; 54 if(y) 55 *y = 0; 56 if(width) 57 *width=1024; 58 if(height) 59 *height=768; 60} 61 62wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const 63{ 64 // We suppose that toolkit version is the same as OS version under Mac 65 wxGetOsVersion(verMaj, verMin); 66 67 return wxPORT_COCOA; 68} 69 70wxWindow* wxFindWindowAtPoint(const wxPoint& pt) 71{ 72 return wxGenericFindWindowAtPoint(pt); 73} 74 75// Return true if we have a colour display 76bool wxColourDisplay() 77{ 78 // TODO 79 return true; 80} 81 82void wxGetMousePosition( int* x, int* y ) 83{ 84 // TODO 85}; 86 87// Returns depth of screen 88int wxDisplayDepth() 89{ 90 // TODO 91 return 0; 92} 93 94// Emit a beeeeeep 95void wxBell() 96{ 97 // TODO 98} 99 100#include "wx/private/browserhack28.h" 101 102// Private helper method for wxLaunchDefaultBrowser 103static bool wxCocoaLaunchDefaultBrowser(const wxString& url, int flags) 104{ 105 // NOTE: We ignore the flags 106 return [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:wxNSStringWithWxString(url)]] != NO; 107} 108 109// For this to work the linker (particularly the static one) must link in this object file and the C++ 110// runtime must call the static initializer. It is basically guaranteed that the linker won't throw us 111// away because some of the wxGUIAppTraits virtual methods are implemented in this file. 112static class DoFixLaunchDefaultBrowser 113{ 114public: 115 DoFixLaunchDefaultBrowser() 116 { 117 // Tell the base library we can launch a default browser better. 118 wxSetLaunchDefaultBrowserImpl(&wxCocoaLaunchDefaultBrowser); 119 } 120} s_launchDefaultBrowserFixer; 121 122#if 0 123// DFE: These aren't even implemented by wxGTK, and no wxWidgets code calls 124// them. If someone needs them, then they'll get a link error 125 126// Consume all events until no more left 127void wxFlushEvents() 128{ 129} 130 131// Check whether this window wants to process messages, e.g. Stop button 132// in long calculations. 133bool wxCheckForInterrupt(wxWindow *wnd) 134{ 135 // TODO 136 return false; 137} 138 139#endif 140 141// Reading and writing resources (eg WIN.INI, .Xdefaults) 142#if wxUSE_RESOURCES 143bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) 144{ 145 // TODO 146 return false; 147} 148 149bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) 150{ 151 char buf[50]; 152 sprintf(buf, "%.4f", value); 153 return wxWriteResource(section, entry, buf, file); 154} 155 156bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) 157{ 158 char buf[50]; 159 sprintf(buf, "%ld", value); 160 return wxWriteResource(section, entry, buf, file); 161} 162 163bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) 164{ 165 char buf[50]; 166 sprintf(buf, "%d", value); 167 return wxWriteResource(section, entry, buf, file); 168} 169 170bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) 171{ 172 // TODO 173 return false; 174} 175 176bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) 177{ 178 char *s = NULL; 179 bool succ = wxGetResource(section, entry, (char **)&s, file); 180 if (succ) 181 { 182 *value = (float)strtod(s, NULL); 183 delete[] s; 184 return true; 185 } 186 else return false; 187} 188 189bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) 190{ 191 char *s = NULL; 192 bool succ = wxGetResource(section, entry, (char **)&s, file); 193 if (succ) 194 { 195 *value = strtol(s, NULL, 10); 196 delete[] s; 197 return true; 198 } 199 else return false; 200} 201 202bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) 203{ 204 char *s = NULL; 205 bool succ = wxGetResource(section, entry, (char **)&s, file); 206 if (succ) 207 { 208 *value = (int)strtol(s, NULL, 10); 209 delete[] s; 210 return true; 211 } 212 else return false; 213} 214#endif // wxUSE_RESOURCES 215