Commit fe7db65b9ef5ef7347943798b532486119bcc207
- Diff rendering mode:
- inline
- side by side
iPhone.txt
(12 / 0)
|   | |||
| 1 | For example if you are using the iPhone Simulator on Snow Leapord, it is necessary to copy the stdc++ file from one location to the simulator | ||
| 2 | this is needed to be copied as super user. | ||
| 3 | |||
| 4 | from /Developer/SDKs/MacOSX10.6.sdk/usr/lib/i686-apple-darwin10/4.2.1/libstdc++.dylib | ||
| 5 | to /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/lib/gcc/i686-apple-darwin9/4.2.1/libstdc++.dylib | ||
| 6 | |||
| 7 | It is also very important to initialize the qt-iphone library. To do the following to the beginning to main. This function will re-enter main. | ||
| 8 | #ifdef Q_WS_IPHONE | ||
| 9 | QiPhoneInit(argc, argv); | ||
| 10 | #endif | ||
| 11 | |||
| 12 | If the application is not terminating as expected add an exit(0); to the end of main. These are some of the current limitations to the library. |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qcolordialog_p.h" | ||
| 43 | #if !defined(QT_NO_COLORDIALOG) && defined(Q_WS_MAC) | ||
| 44 | #include <qapplication.h> | ||
| 45 | #include <qtimer.h> | ||
| 46 | #include <qdialogbuttonbox.h> | ||
| 47 | #include <qabstracteventdispatcher.h> | ||
| 48 | #include <private/qapplication_p.h> | ||
| 49 | #include <private/qt_iphone_p.h> | ||
| 50 | #include <qdebug.h> | ||
| 51 | |||
| 52 | #import <Foundation/Foundation.h> | ||
| 53 | |||
| 54 | //#if !CGFLOAT_DEFINED | ||
| 55 | //typedef float CGFloat; // Should only not be defined on 32-bit platforms | ||
| 56 | //#endif | ||
| 57 | // | ||
| 58 | // | ||
| 59 | //#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | ||
| 60 | //@protocol NSWindowDelegate <NSObject> | ||
| 61 | //- (void)windowDidResize:(NSNotification *)notification; | ||
| 62 | //- (BOOL)windowShouldClose:(id)window; | ||
| 63 | //@end | ||
| 64 | //#endif | ||
| 65 | |||
| 66 | QT_USE_NAMESPACE | ||
| 67 | |||
| 68 | //@class QCocoaColorPanelDelegate; | ||
| 69 | // | ||
| 70 | //@interface QCocoaColorPanelDelegate : NSObject<NSWindowDelegate> { | ||
| 71 | // NSColorPanel *mColorPanel; | ||
| 72 | // NSView *mStolenContentView; | ||
| 73 | // NSButton *mOkButton; | ||
| 74 | // NSButton *mCancelButton; | ||
| 75 | // QColorDialogPrivate *mPriv; | ||
| 76 | // QColor *mQtColor; | ||
| 77 | // CGFloat mMinWidth; // currently unused | ||
| 78 | // CGFloat mExtraHeight; // currently unused | ||
| 79 | // BOOL mHackedPanel; | ||
| 80 | // NSInteger mResultCode; | ||
| 81 | // BOOL mDialogIsExecuting; | ||
| 82 | //} | ||
| 83 | //- (id)initWithColorPanel:(NSColorPanel *)panel | ||
| 84 | // stolenContentView:(NSView *)stolenContentView | ||
| 85 | // okButton:(NSButton *)okButton | ||
| 86 | // cancelButton:(NSButton *)cancelButton | ||
| 87 | // priv:(QColorDialogPrivate *)priv; | ||
| 88 | //- (void)colorChanged:(NSNotification *)notification; | ||
| 89 | //- (void)relayout; | ||
| 90 | //- (void)onOkClicked; | ||
| 91 | //- (void)onCancelClicked; | ||
| 92 | //- (void)updateQtColor; | ||
| 93 | //- (NSColorPanel *)colorPanel; | ||
| 94 | //- (QColor)qtColor; | ||
| 95 | //- (void)finishOffWithCode:(NSInteger)result; | ||
| 96 | //- (void)showColorPanel; | ||
| 97 | //- (void)exec; | ||
| 98 | //@end | ||
| 99 | // | ||
| 100 | //@implementation QCocoaColorPanelDelegate | ||
| 101 | //- (id)initWithColorPanel:(NSColorPanel *)panel | ||
| 102 | // stolenContentView:(NSView *)stolenContentView | ||
| 103 | // okButton:(NSButton *)okButton | ||
| 104 | // cancelButton:(NSButton *)cancelButton | ||
| 105 | // priv:(QColorDialogPrivate *)priv | ||
| 106 | //{ | ||
| 107 | // self = [super init]; | ||
| 108 | // | ||
| 109 | // mColorPanel = panel; | ||
| 110 | // mStolenContentView = stolenContentView; | ||
| 111 | // mOkButton = okButton; | ||
| 112 | // mCancelButton = cancelButton; | ||
| 113 | // mPriv = priv; | ||
| 114 | // mMinWidth = 0.0; | ||
| 115 | // mExtraHeight = 0.0; | ||
| 116 | // mHackedPanel = (okButton != 0); | ||
| 117 | // mResultCode = NSCancelButton; | ||
| 118 | // mDialogIsExecuting = false; | ||
| 119 | // | ||
| 120 | // if (mHackedPanel) { | ||
| 121 | // [self relayout]; | ||
| 122 | // | ||
| 123 | // [okButton setAction:@selector(onOkClicked)]; | ||
| 124 | // [okButton setTarget:self]; | ||
| 125 | // | ||
| 126 | // [cancelButton setAction:@selector(onCancelClicked)]; | ||
| 127 | // [cancelButton setTarget:self]; | ||
| 128 | // } | ||
| 129 | // | ||
| 130 | // [[NSNotificationCenter defaultCenter] addObserver:self | ||
| 131 | // selector:@selector(colorChanged:) | ||
| 132 | // name:NSColorPanelColorDidChangeNotification | ||
| 133 | // object:mColorPanel]; | ||
| 134 | // | ||
| 135 | // mQtColor = new QColor(); | ||
| 136 | // return self; | ||
| 137 | //} | ||
| 138 | // | ||
| 139 | //- (void)dealloc | ||
| 140 | //{ | ||
| 141 | // QMacCocoaAutoReleasePool pool; | ||
| 142 | // if (mHackedPanel) { | ||
| 143 | // NSView *ourContentView = [mColorPanel contentView]; | ||
| 144 | // | ||
| 145 | // // return stolen stuff to its rightful owner | ||
| 146 | // [mStolenContentView removeFromSuperview]; | ||
| 147 | // [mColorPanel setContentView:mStolenContentView]; | ||
| 148 | // | ||
| 149 | // [mOkButton release]; | ||
| 150 | // [mCancelButton release]; | ||
| 151 | // [ourContentView release]; | ||
| 152 | // } | ||
| 153 | // [mColorPanel setDelegate:nil]; | ||
| 154 | // [[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
| 155 | // delete mQtColor; | ||
| 156 | // [super dealloc]; | ||
| 157 | //} | ||
| 158 | // | ||
| 159 | //- (BOOL)windowShouldClose:(id)window | ||
| 160 | //{ | ||
| 161 | // Q_UNUSED(window); | ||
| 162 | // if (mHackedPanel) { | ||
| 163 | // [self onCancelClicked]; | ||
| 164 | // } else { | ||
| 165 | // [self updateQtColor]; | ||
| 166 | // [self finishOffWithCode:NSCancelButton]; | ||
| 167 | // } | ||
| 168 | // return true; | ||
| 169 | //} | ||
| 170 | // | ||
| 171 | //- (void)windowDidResize:(NSNotification *)notification | ||
| 172 | //{ | ||
| 173 | // Q_UNUSED(notification); | ||
| 174 | // if (mHackedPanel) | ||
| 175 | // [self relayout]; | ||
| 176 | //} | ||
| 177 | // | ||
| 178 | //- (void)colorChanged:(NSNotification *)notification; | ||
| 179 | //{ | ||
| 180 | // Q_UNUSED(notification); | ||
| 181 | // [self updateQtColor]; | ||
| 182 | //} | ||
| 183 | // | ||
| 184 | //- (void)relayout | ||
| 185 | //{ | ||
| 186 | // Q_ASSERT(mHackedPanel); | ||
| 187 | // | ||
| 188 | // NSRect rect = [[mStolenContentView superview] frame]; | ||
| 189 | // | ||
| 190 | // // should a priori be kept in sync with qfontdialog_mac.mm | ||
| 191 | // const CGFloat ButtonMinWidth = 78.0; // 84.0 for Carbon | ||
| 192 | // const CGFloat ButtonMinHeight = 32.0; | ||
| 193 | // const CGFloat ButtonSpacing = 0.0; | ||
| 194 | // const CGFloat ButtonTopMargin = 0.0; | ||
| 195 | // const CGFloat ButtonBottomMargin = 7.0; | ||
| 196 | // const CGFloat ButtonSideMargin = 9.0; | ||
| 197 | // | ||
| 198 | // [mOkButton sizeToFit]; | ||
| 199 | // NSSize okSizeHint = [mOkButton frame].size; | ||
| 200 | // | ||
| 201 | // [mCancelButton sizeToFit]; | ||
| 202 | // NSSize cancelSizeHint = [mCancelButton frame].size; | ||
| 203 | // | ||
| 204 | // const CGFloat ButtonWidth = qMin(qMax(ButtonMinWidth, | ||
| 205 | // qMax(okSizeHint.width, cancelSizeHint.width)), | ||
| 206 | // CGFloat((rect.size.width - 2.0 * ButtonSideMargin - ButtonSpacing) * 0.5)); | ||
| 207 | // const CGFloat ButtonHeight = qMax(ButtonMinHeight, | ||
| 208 | // qMax(okSizeHint.height, cancelSizeHint.height)); | ||
| 209 | // | ||
| 210 | // NSRect okRect = { { rect.size.width - ButtonSideMargin - ButtonWidth, | ||
| 211 | // ButtonBottomMargin }, | ||
| 212 | // { ButtonWidth, ButtonHeight } }; | ||
| 213 | // [mOkButton setFrame:okRect]; | ||
| 214 | // [mOkButton setNeedsDisplay:YES]; | ||
| 215 | // | ||
| 216 | // NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - ButtonWidth, | ||
| 217 | // ButtonBottomMargin }, | ||
| 218 | // { ButtonWidth, ButtonHeight } }; | ||
| 219 | // [mCancelButton setFrame:cancelRect]; | ||
| 220 | // [mCancelButton setNeedsDisplay:YES]; | ||
| 221 | // | ||
| 222 | // const CGFloat Y = ButtonBottomMargin + ButtonHeight + ButtonTopMargin; | ||
| 223 | // NSRect stolenCVRect = { { 0.0, Y }, | ||
| 224 | // { rect.size.width, rect.size.height - Y } }; | ||
| 225 | // [mStolenContentView setFrame:stolenCVRect]; | ||
| 226 | // [mStolenContentView setNeedsDisplay:YES]; | ||
| 227 | // | ||
| 228 | // [[mStolenContentView superview] setNeedsDisplay:YES]; | ||
| 229 | // mMinWidth = 2 * ButtonSideMargin + ButtonSpacing + 2 * ButtonWidth; | ||
| 230 | // mExtraHeight = Y; | ||
| 231 | //} | ||
| 232 | // | ||
| 233 | //- (void)onOkClicked | ||
| 234 | //{ | ||
| 235 | // Q_ASSERT(mHackedPanel); | ||
| 236 | // [[mStolenContentView window] close]; | ||
| 237 | // [self updateQtColor]; | ||
| 238 | // [self finishOffWithCode:NSOKButton]; | ||
| 239 | //} | ||
| 240 | // | ||
| 241 | //- (void)onCancelClicked | ||
| 242 | //{ | ||
| 243 | // Q_ASSERT(mHackedPanel); | ||
| 244 | // [[mStolenContentView window] close]; | ||
| 245 | // delete mQtColor; | ||
| 246 | // mQtColor = new QColor(); | ||
| 247 | // [self finishOffWithCode:NSCancelButton]; | ||
| 248 | //} | ||
| 249 | // | ||
| 250 | //- (void)updateQtColor | ||
| 251 | //{ | ||
| 252 | // delete mQtColor; | ||
| 253 | // mQtColor = new QColor(); | ||
| 254 | // NSColor *color = [mColorPanel color]; | ||
| 255 | // NSString *colorSpaceName = [color colorSpaceName]; | ||
| 256 | // if (colorSpaceName == NSDeviceCMYKColorSpace) { | ||
| 257 | // CGFloat cyan = 0, magenta = 0, yellow = 0, black = 0, alpha = 0; | ||
| 258 | // [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; | ||
| 259 | // mQtColor->setCmykF(cyan, magenta, yellow, black, alpha); | ||
| 260 | // } else if (colorSpaceName == NSCalibratedRGBColorSpace || colorSpaceName == NSDeviceRGBColorSpace) { | ||
| 261 | // CGFloat red = 0, green = 0, blue = 0, alpha = 0; | ||
| 262 | // [color getRed:&red green:&green blue:&blue alpha:&alpha]; | ||
| 263 | // mQtColor->setRgbF(red, green, blue, alpha); | ||
| 264 | // } else if (colorSpaceName == NSNamedColorSpace) { | ||
| 265 | // NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | ||
| 266 | // CGFloat red = 0, green = 0, blue = 0, alpha = 0; | ||
| 267 | // [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; | ||
| 268 | // mQtColor->setRgbF(red, green, blue, alpha); | ||
| 269 | // } else { | ||
| 270 | // NSColorSpace *colorSpace = [color colorSpace]; | ||
| 271 | // if ([colorSpace colorSpaceModel] == NSCMYKColorSpaceModel && [color numberOfComponents] == 5){ | ||
| 272 | // CGFloat components[5]; | ||
| 273 | // [color getComponents:components]; | ||
| 274 | // mQtColor->setCmykF(components[0], components[1], components[2], components[3], components[4]); | ||
| 275 | // } else { | ||
| 276 | // NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | ||
| 277 | // CGFloat red = 0, green = 0, blue = 0, alpha = 0; | ||
| 278 | // [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; | ||
| 279 | // mQtColor->setRgbF(red, green, blue, alpha); | ||
| 280 | // } | ||
| 281 | // } | ||
| 282 | // | ||
| 283 | // mPriv->setCurrentQColor(*mQtColor); | ||
| 284 | //} | ||
| 285 | // | ||
| 286 | //- (NSColorPanel *)colorPanel | ||
| 287 | //{ | ||
| 288 | // return mColorPanel; | ||
| 289 | //} | ||
| 290 | // | ||
| 291 | //- (QColor)qtColor | ||
| 292 | //{ | ||
| 293 | // return *mQtColor; | ||
| 294 | //} | ||
| 295 | // | ||
| 296 | //- (void)finishOffWithCode:(NSInteger)code | ||
| 297 | //{ | ||
| 298 | // mResultCode = code; | ||
| 299 | // if (mDialogIsExecuting) { | ||
| 300 | // // We stop the current modal event loop. The control | ||
| 301 | // // will then return inside -(void)exec below. | ||
| 302 | // // It's important that the modal event loop is stopped before | ||
| 303 | // // we accept/reject QColorDialog, since QColorDialog has its | ||
| 304 | // // own event loop that needs to be stopped last. | ||
| 305 | // [NSApp stopModalWithCode:code]; | ||
| 306 | // } else { | ||
| 307 | // // Since we are not in a modal event loop, we can safely close | ||
| 308 | // // down QColorDialog | ||
| 309 | // if (mResultCode == NSCancelButton) | ||
| 310 | // mPriv->colorDialog()->reject(); | ||
| 311 | // else | ||
| 312 | // mPriv->colorDialog()->accept(); | ||
| 313 | // } | ||
| 314 | //} | ||
| 315 | // | ||
| 316 | //- (void)showColorPanel | ||
| 317 | //{ | ||
| 318 | // mDialogIsExecuting = false; | ||
| 319 | // [mColorPanel makeKeyAndOrderFront:mColorPanel]; | ||
| 320 | //} | ||
| 321 | // | ||
| 322 | //- (void)exec | ||
| 323 | //{ | ||
| 324 | // QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); | ||
| 325 | // QMacCocoaAutoReleasePool pool; | ||
| 326 | // mDialogIsExecuting = true; | ||
| 327 | // bool modalEnded = false; | ||
| 328 | // while (!modalEnded) { | ||
| 329 | // @try { | ||
| 330 | // [NSApp runModalForWindow:mColorPanel]; | ||
| 331 | // modalEnded = true; | ||
| 332 | // } @catch (NSException *) { | ||
| 333 | // // For some reason, NSColorPanel throws an exception when | ||
| 334 | // // clicking on 'SelectedMenuItemColor' from the 'Developer' | ||
| 335 | // // palette (tab three). | ||
| 336 | // } | ||
| 337 | // } | ||
| 338 | // | ||
| 339 | // if (mResultCode == NSCancelButton) | ||
| 340 | // mPriv->colorDialog()->reject(); | ||
| 341 | // else | ||
| 342 | // mPriv->colorDialog()->accept(); | ||
| 343 | //} | ||
| 344 | // | ||
| 345 | //@end | ||
| 346 | // | ||
| 347 | //QT_BEGIN_NAMESPACE | ||
| 348 | // | ||
| 349 | //extern void macStartInterceptNSPanelCtor(); | ||
| 350 | //extern void macStopInterceptNSPanelCtor(); | ||
| 351 | //extern NSButton *macCreateButton(const char *text, NSView *superview); | ||
| 352 | // | ||
| 353 | //void QColorDialogPrivate::openCocoaColorPanel(const QColor &initial, | ||
| 354 | // QWidget *parent, const QString &title, QColorDialog::ColorDialogOptions options) | ||
| 355 | //{ | ||
| 356 | // Q_UNUSED(parent); // we would use the parent if only NSColorPanel could be a sheet | ||
| 357 | // QMacCocoaAutoReleasePool pool; | ||
| 358 | // | ||
| 359 | // if (!delegate) { | ||
| 360 | // /* | ||
| 361 | // The standard Cocoa color panel has no OK or Cancel button and | ||
| 362 | // is created as a utility window, whereas we want something like | ||
| 363 | // the Carbon color panel. We need to take the following steps: | ||
| 364 | // | ||
| 365 | // 1. Intercept the color panel constructor to turn off the | ||
| 366 | // NSUtilityWindowMask flag. This is done by temporarily | ||
| 367 | // replacing initWithContentRect:styleMask:backing:defer: | ||
| 368 | // in NSPanel by our own method. | ||
| 369 | // | ||
| 370 | // 2. Modify the color panel so that its content view is part | ||
| 371 | // of a new content view that contains it as well as two | ||
| 372 | // buttons (OK and Cancel). | ||
| 373 | // | ||
| 374 | // 3. Lay out the original content view and the buttons when | ||
| 375 | // the color panel is shown and whenever it is resized. | ||
| 376 | // | ||
| 377 | // 4. Clean up after ourselves. | ||
| 378 | // */ | ||
| 379 | // | ||
| 380 | // bool hackColorPanel = !(options & QColorDialog::NoButtons); | ||
| 381 | // | ||
| 382 | // if (hackColorPanel) | ||
| 383 | // macStartInterceptNSPanelCtor(); | ||
| 384 | // NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel]; | ||
| 385 | // if (hackColorPanel) | ||
| 386 | // macStopInterceptNSPanelCtor(); | ||
| 387 | // | ||
| 388 | // [colorPanel setHidesOnDeactivate:false]; | ||
| 389 | // | ||
| 390 | // // set up the Cocoa color panel | ||
| 391 | // [colorPanel setShowsAlpha:options & QColorDialog::ShowAlphaChannel]; | ||
| 392 | // [colorPanel setTitle:(NSString*)(CFStringRef)QCFString(title)]; | ||
| 393 | // | ||
| 394 | // NSView *stolenContentView = 0; | ||
| 395 | // NSButton *okButton = 0; | ||
| 396 | // NSButton *cancelButton = 0; | ||
| 397 | // | ||
| 398 | // if (hackColorPanel) { | ||
| 399 | // // steal the color panel's contents view | ||
| 400 | // stolenContentView = [colorPanel contentView]; | ||
| 401 | // [stolenContentView retain]; | ||
| 402 | // [colorPanel setContentView:0]; | ||
| 403 | // | ||
| 404 | // // create a new content view and add the stolen one as a subview | ||
| 405 | // NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; | ||
| 406 | // NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; | ||
| 407 | // [ourContentView addSubview:stolenContentView]; | ||
| 408 | // | ||
| 409 | // // create OK and Cancel buttons and add these as subviews | ||
| 410 | // okButton = macCreateButton("&OK", ourContentView); | ||
| 411 | // cancelButton = macCreateButton("Cancel", ourContentView); | ||
| 412 | // | ||
| 413 | // [colorPanel setContentView:ourContentView]; | ||
| 414 | // [colorPanel setDefaultButtonCell:[okButton cell]]; | ||
| 415 | // } | ||
| 416 | // | ||
| 417 | // delegate = [[QCocoaColorPanelDelegate alloc] initWithColorPanel:colorPanel | ||
| 418 | // stolenContentView:stolenContentView | ||
| 419 | // okButton:okButton | ||
| 420 | // cancelButton:cancelButton | ||
| 421 | // priv:this]; | ||
| 422 | // [colorPanel setDelegate:static_cast<QCocoaColorPanelDelegate *>(delegate)]; | ||
| 423 | // } | ||
| 424 | // | ||
| 425 | // setCocoaPanelColor(initial); | ||
| 426 | // [static_cast<QCocoaColorPanelDelegate *>(delegate) showColorPanel]; | ||
| 427 | //} | ||
| 428 | // | ||
| 429 | //void QColorDialogPrivate::closeCocoaColorPanel() | ||
| 430 | //{ | ||
| 431 | // [static_cast<QCocoaColorPanelDelegate *>(delegate) onCancelClicked]; | ||
| 432 | //} | ||
| 433 | // | ||
| 434 | //void QColorDialogPrivate::releaseCocoaColorPanelDelegate() | ||
| 435 | //{ | ||
| 436 | // [static_cast<QCocoaColorPanelDelegate *>(delegate) release]; | ||
| 437 | //} | ||
| 438 | // | ||
| 439 | //void QColorDialogPrivate::mac_nativeDialogModalHelp() | ||
| 440 | //{ | ||
| 441 | // // Do a queued meta-call to open the native modal dialog so it opens after the new | ||
| 442 | // // event loop has started to execute (in QDialog::exec). Using a timer rather than | ||
| 443 | // // a queued meta call is intentional to ensure that the call is only delivered when | ||
| 444 | // // [NSApp run] runs (timers are handeled special in cocoa). If NSApp is not | ||
| 445 | // // running (which is the case if e.g a top-most QEventLoop has been | ||
| 446 | // // interrupted, and the second-most event loop has not yet been reactivated (regardless | ||
| 447 | // // if [NSApp run] is still on the stack)), showing a native modal dialog will fail. | ||
| 448 | // if (delegate){ | ||
| 449 | // Q_Q(QColorDialog); | ||
| 450 | // QTimer::singleShot(1, q, SLOT(_q_macRunNativeAppModalPanel())); | ||
| 451 | // } | ||
| 452 | //} | ||
| 453 | // | ||
| 454 | //void QColorDialogPrivate::_q_macRunNativeAppModalPanel() | ||
| 455 | //{ | ||
| 456 | // [static_cast<QCocoaColorPanelDelegate *>(delegate) exec]; | ||
| 457 | //} | ||
| 458 | // | ||
| 459 | //void QColorDialogPrivate::setCocoaPanelColor(const QColor &color) | ||
| 460 | //{ | ||
| 461 | // QMacCocoaAutoReleasePool pool; | ||
| 462 | // QCocoaColorPanelDelegate *theDelegate = static_cast<QCocoaColorPanelDelegate *>(delegate); | ||
| 463 | // NSColor *nsColor; | ||
| 464 | // const QColor::Spec spec = color.spec(); | ||
| 465 | // if (spec == QColor::Cmyk) { | ||
| 466 | // nsColor = [NSColor colorWithDeviceCyan:color.cyanF() | ||
| 467 | // magenta:color.magentaF() | ||
| 468 | // yellow:color.yellowF() | ||
| 469 | // black:color.blackF() | ||
| 470 | // alpha:color.alphaF()]; | ||
| 471 | // } else { | ||
| 472 | // nsColor = [NSColor colorWithCalibratedRed:color.redF() | ||
| 473 | // green:color.greenF() | ||
| 474 | // blue:color.blueF() | ||
| 475 | // alpha:color.alphaF()]; | ||
| 476 | // } | ||
| 477 | // [[theDelegate colorPanel] setColor:nsColor]; | ||
| 478 | //} | ||
| 479 | |||
| 480 | QT_END_NAMESPACE | ||
| 481 | |||
| 482 | #endif |
src/gui/dialogs/qfiledialog_iphone.mm
(1110 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qfiledialog.h" | ||
| 43 | |||
| 44 | #ifndef QT_NO_FILEDIALOG | ||
| 45 | |||
| 46 | /***************************************************************************** | ||
| 47 | QFileDialog debug facilities | ||
| 48 | *****************************************************************************/ | ||
| 49 | //#define DEBUG_FILEDIALOG_FILTERS | ||
| 50 | |||
| 51 | #include <qapplication.h> | ||
| 52 | #include <private/qapplication_p.h> | ||
| 53 | #include <private/qfiledialog_p.h> | ||
| 54 | #include <private/qt_iphone_p.h> | ||
| 55 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 56 | #include <qregexp.h> | ||
| 57 | #include <qbuffer.h> | ||
| 58 | #include <qdebug.h> | ||
| 59 | #include <qstringlist.h> | ||
| 60 | #include <qaction.h> | ||
| 61 | #include <qtextcodec.h> | ||
| 62 | #include <qvarlengtharray.h> | ||
| 63 | #include <qdesktopwidget.h> | ||
| 64 | #include <stdlib.h> | ||
| 65 | #include <qabstracteventdispatcher.h> | ||
| 66 | #include "ui_qfiledialog.h" | ||
| 67 | |||
| 68 | QT_BEGIN_NAMESPACE | ||
| 69 | |||
| 70 | //extern QStringList qt_make_filter_list(const QString &filter); // qfiledialog.cpp | ||
| 71 | //extern QStringList qt_clean_filter_list(const QString &filter); // qfiledialog.cpp | ||
| 72 | //extern const char *qt_file_dialog_filter_reg_exp; // qfiledialog.cpp | ||
| 73 | //extern bool qt_mac_is_macsheet(const QWidget *w); // qwidget_mac.mm | ||
| 74 | // | ||
| 75 | //QT_END_NAMESPACE | ||
| 76 | // | ||
| 77 | //QT_FORWARD_DECLARE_CLASS(QFileDialogPrivate) | ||
| 78 | //QT_FORWARD_DECLARE_CLASS(QString) | ||
| 79 | //QT_FORWARD_DECLARE_CLASS(QStringList) | ||
| 80 | //QT_FORWARD_DECLARE_CLASS(QWidget) | ||
| 81 | //QT_FORWARD_DECLARE_CLASS(QAction) | ||
| 82 | //QT_FORWARD_DECLARE_CLASS(QFileInfo) | ||
| 83 | //QT_USE_NAMESPACE | ||
| 84 | // | ||
| 85 | //@class QNSOpenSavePanelDelegate; | ||
| 86 | // | ||
| 87 | //@interface QNSOpenSavePanelDelegate : NSObject { | ||
| 88 | // @public | ||
| 89 | // NSOpenPanel *mOpenPanel; | ||
| 90 | // NSSavePanel *mSavePanel; | ||
| 91 | // NSView *mAccessoryView; | ||
| 92 | // NSPopUpButton *mPopUpButton; | ||
| 93 | // NSTextField *mTextField; | ||
| 94 | // QFileDialogPrivate *mPriv; | ||
| 95 | // NSString *mCurrentDir; | ||
| 96 | // bool mConfirmOverwrite; | ||
| 97 | // int mReturnCode; | ||
| 98 | // | ||
| 99 | // QT_PREPEND_NAMESPACE(QFileDialog::AcceptMode) mAcceptMode; | ||
| 100 | // QT_PREPEND_NAMESPACE(QDir::Filters) *mQDirFilter; | ||
| 101 | // QT_PREPEND_NAMESPACE(QFileDialog::FileMode) mFileMode; | ||
| 102 | // QT_PREPEND_NAMESPACE(QFileDialog::Options) *mFileOptions; | ||
| 103 | // | ||
| 104 | // QString *mLastFilterCheckPath; | ||
| 105 | // QString *mCurrentSelection; | ||
| 106 | // QStringList *mQDirFilterEntryList; | ||
| 107 | // QStringList *mNameFilterDropDownList; | ||
| 108 | // QStringList *mSelectedNameFilter; | ||
| 109 | //} | ||
| 110 | // | ||
| 111 | //- (NSString *)strip:(const QString &)label; | ||
| 112 | //- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename; | ||
| 113 | //- (void)filterChanged:(id)sender; | ||
| 114 | //- (void)showModelessPanel; | ||
| 115 | //- (BOOL)runApplicationModalPanel; | ||
| 116 | //- (void)showWindowModalSheet:(QWidget *)docWidget; | ||
| 117 | //- (void)updateProperties; | ||
| 118 | //- (QStringList)acceptableExtensionsForSave; | ||
| 119 | //- (QString)removeExtensions:(const QString &)filter; | ||
| 120 | //- (void)createTextField; | ||
| 121 | //- (void)createPopUpButton:(const QString &)selectedFilter hideDetails:(BOOL)hideDetails; | ||
| 122 | //- (void)createAccessory; | ||
| 123 | // | ||
| 124 | //@end | ||
| 125 | // | ||
| 126 | //@implementation QNSOpenSavePanelDelegate | ||
| 127 | // | ||
| 128 | //- (id)initWithAcceptMode:(QT_PREPEND_NAMESPACE(QFileDialog::AcceptMode))acceptMode | ||
| 129 | // title:(const QString &)title | ||
| 130 | // nameFilters:(const QStringList &)nameFilters | ||
| 131 | // selectedNameFilter:(const QString &)selectedNameFilter | ||
| 132 | // hideNameFilterDetails:(bool)hideNameFilterDetails | ||
| 133 | // qDirFilter:(QT_PREPEND_NAMESPACE(QDir::Filters))qDirFilter | ||
| 134 | // fileOptions:(QT_PREPEND_NAMESPACE(QFileDialog::Options))fileOptions | ||
| 135 | // fileMode:(QT_PREPEND_NAMESPACE(QFileDialog::FileMode))fileMode | ||
| 136 | // selectFile:(const QString &)selectFile | ||
| 137 | // confirmOverwrite:(bool)confirm | ||
| 138 | // priv:(QFileDialogPrivate *)priv | ||
| 139 | //{ | ||
| 140 | // self = [super init]; | ||
| 141 | // | ||
| 142 | // mAcceptMode = acceptMode; | ||
| 143 | // if (mAcceptMode == QT_PREPEND_NAMESPACE(QFileDialog::AcceptOpen)){ | ||
| 144 | // mOpenPanel = [NSOpenPanel openPanel]; | ||
| 145 | // mSavePanel = mOpenPanel; | ||
| 146 | // } else { | ||
| 147 | // mSavePanel = [NSSavePanel savePanel]; | ||
| 148 | // mOpenPanel = 0; | ||
| 149 | // } | ||
| 150 | // | ||
| 151 | // [mSavePanel setLevel:NSModalPanelWindowLevel]; | ||
| 152 | // [mSavePanel setDelegate:self]; | ||
| 153 | // mQDirFilter = new QT_PREPEND_NAMESPACE(QDir::Filters)(qDirFilter); | ||
| 154 | // mFileOptions = new QT_PREPEND_NAMESPACE(QFileDialog::Options)(fileOptions); | ||
| 155 | // mFileMode = fileMode; | ||
| 156 | // mConfirmOverwrite = confirm; | ||
| 157 | // mReturnCode = -1; | ||
| 158 | // mPriv = priv; | ||
| 159 | // mLastFilterCheckPath = new QString; | ||
| 160 | // mQDirFilterEntryList = new QStringList; | ||
| 161 | // mNameFilterDropDownList = new QStringList(nameFilters); | ||
| 162 | // mSelectedNameFilter = new QStringList(qt_clean_filter_list(selectedNameFilter)); | ||
| 163 | // QFileInfo sel(selectFile); | ||
| 164 | // if (sel.isDir()){ | ||
| 165 | // mCurrentDir = [qt_mac_QStringToNSString(sel.absoluteFilePath()) retain]; | ||
| 166 | // mCurrentSelection = new QString; | ||
| 167 | // } else { | ||
| 168 | // mCurrentDir = [qt_mac_QStringToNSString(sel.absolutePath()) retain]; | ||
| 169 | // mCurrentSelection = new QString(sel.absoluteFilePath()); | ||
| 170 | // } | ||
| 171 | // [mSavePanel setTitle:qt_mac_QStringToNSString(title)]; | ||
| 172 | // [self createPopUpButton:selectedNameFilter hideDetails:hideNameFilterDetails]; | ||
| 173 | // [self createTextField]; | ||
| 174 | // [self createAccessory]; | ||
| 175 | // [mSavePanel setAccessoryView:mNameFilterDropDownList->size() > 1 ? mAccessoryView : nil]; | ||
| 176 | // | ||
| 177 | // if (mPriv){ | ||
| 178 | // [mSavePanel setPrompt:[self strip:mPriv->acceptLabel]]; | ||
| 179 | // if (mPriv->fileNameLabelExplicitlySat) | ||
| 180 | // [mSavePanel setNameFieldLabel:[self strip:mPriv->qFileDialogUi->fileNameLabel->text()]]; | ||
| 181 | // } | ||
| 182 | // | ||
| 183 | // [self updateProperties]; | ||
| 184 | // [mSavePanel retain]; | ||
| 185 | // return self; | ||
| 186 | //} | ||
| 187 | // | ||
| 188 | //- (void)dealloc | ||
| 189 | //{ | ||
| 190 | // delete mQDirFilter; | ||
| 191 | // delete mFileOptions; | ||
| 192 | // delete mLastFilterCheckPath; | ||
| 193 | // delete mQDirFilterEntryList; | ||
| 194 | // delete mNameFilterDropDownList; | ||
| 195 | // delete mSelectedNameFilter; | ||
| 196 | // delete mCurrentSelection; | ||
| 197 | // | ||
| 198 | // [mSavePanel orderOut:mSavePanel]; | ||
| 199 | // [mSavePanel setAccessoryView:nil]; | ||
| 200 | // [mPopUpButton release]; | ||
| 201 | // [mTextField release]; | ||
| 202 | // [mAccessoryView release]; | ||
| 203 | // [mSavePanel setDelegate:nil]; | ||
| 204 | // [mSavePanel release]; | ||
| 205 | // [mCurrentDir release]; | ||
| 206 | // [super dealloc]; | ||
| 207 | //} | ||
| 208 | // | ||
| 209 | //- (NSString *)strip:(const QString &)label | ||
| 210 | //{ | ||
| 211 | // QAction a(label, 0); | ||
| 212 | // return qt_mac_QStringToNSString(a.iconText()); | ||
| 213 | //} | ||
| 214 | // | ||
| 215 | //- (void)closePanel | ||
| 216 | //{ | ||
| 217 | // *mCurrentSelection = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)([mSavePanel filename]); | ||
| 218 | // [mSavePanel close]; | ||
| 219 | //} | ||
| 220 | // | ||
| 221 | //- (void)showModelessPanel | ||
| 222 | //{ | ||
| 223 | // if (mOpenPanel){ | ||
| 224 | // QFileInfo info(*mCurrentSelection); | ||
| 225 | // NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName()); | ||
| 226 | // NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath()); | ||
| 227 | // bool selectable = (mAcceptMode == QFileDialog::AcceptSave) | ||
| 228 | // || [self panel:nil shouldShowFilename:filepath]; | ||
| 229 | // [mOpenPanel | ||
| 230 | // beginForDirectory:mCurrentDir | ||
| 231 | // file:selectable ? filename : nil | ||
| 232 | // types:nil | ||
| 233 | // modelessDelegate:self | ||
| 234 | // didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) | ||
| 235 | // contextInfo:nil]; | ||
| 236 | // } | ||
| 237 | //} | ||
| 238 | // | ||
| 239 | //- (BOOL)runApplicationModalPanel | ||
| 240 | //{ | ||
| 241 | // QFileInfo info(*mCurrentSelection); | ||
| 242 | // NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName()); | ||
| 243 | // NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath()); | ||
| 244 | // bool selectable = (mAcceptMode == QFileDialog::AcceptSave) | ||
| 245 | // || [self panel:nil shouldShowFilename:filepath]; | ||
| 246 | // mReturnCode = [mSavePanel | ||
| 247 | // runModalForDirectory:mCurrentDir | ||
| 248 | // file:selectable ? filename : @"untitled"]; | ||
| 249 | // | ||
| 250 | // QAbstractEventDispatcher::instance()->interrupt(); | ||
| 251 | // return (mReturnCode == NSOKButton); | ||
| 252 | //} | ||
| 253 | // | ||
| 254 | //- (QT_PREPEND_NAMESPACE(QDialog::DialogCode))dialogResultCode | ||
| 255 | //{ | ||
| 256 | // return (mReturnCode == NSOKButton) ? QT_PREPEND_NAMESPACE(QDialog::Accepted) : QT_PREPEND_NAMESPACE(QDialog::Rejected); | ||
| 257 | //} | ||
| 258 | // | ||
| 259 | //- (void)showWindowModalSheet:(QWidget *)docWidget | ||
| 260 | //{ | ||
| 261 | // Q_UNUSED(docWidget); | ||
| 262 | // QFileInfo info(*mCurrentSelection); | ||
| 263 | // NSString *filename = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.fileName()); | ||
| 264 | // NSString *filepath = QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(info.filePath()); | ||
| 265 | // bool selectable = (mAcceptMode == QFileDialog::AcceptSave) | ||
| 266 | // || [self panel:nil shouldShowFilename:filepath]; | ||
| 267 | // [mSavePanel | ||
| 268 | // beginSheetForDirectory:mCurrentDir | ||
| 269 | // file:selectable ? filename : nil | ||
| 270 | //#ifdef QT_MAC_USE_COCOA | ||
| 271 | // modalForWindow:QT_PREPEND_NAMESPACE(qt_mac_window_for)(docWidget) | ||
| 272 | //#else | ||
| 273 | // modalForWindow:nil | ||
| 274 | //#endif | ||
| 275 | // modalDelegate:self | ||
| 276 | // didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) | ||
| 277 | // contextInfo:nil]; | ||
| 278 | //} | ||
| 279 | // | ||
| 280 | //- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename | ||
| 281 | //{ | ||
| 282 | // Q_UNUSED(sender); | ||
| 283 | // | ||
| 284 | // if ([filename length] == 0) | ||
| 285 | // return NO; | ||
| 286 | // | ||
| 287 | // QString qtFileName = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)(filename); | ||
| 288 | // QFileInfo info(qtFileName.normalized(QT_PREPEND_NAMESPACE(QString::NormalizationForm_C))); | ||
| 289 | // QString path = info.absolutePath(); | ||
| 290 | // if (path != *mLastFilterCheckPath){ | ||
| 291 | // *mLastFilterCheckPath = path; | ||
| 292 | // *mQDirFilterEntryList = info.dir().entryList(*mQDirFilter); | ||
| 293 | // } | ||
| 294 | // // Check if the QDir filter accepts the file: | ||
| 295 | // if (!mQDirFilterEntryList->contains(info.fileName())) | ||
| 296 | // return NO; | ||
| 297 | // | ||
| 298 | // // Always accept directories regardless of their names: | ||
| 299 | // BOOL isDir; | ||
| 300 | // if ([[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&isDir] && isDir) | ||
| 301 | // return YES; | ||
| 302 | // | ||
| 303 | // // No filter means accept everything | ||
| 304 | // if (mSelectedNameFilter->isEmpty()) | ||
| 305 | // return YES; | ||
| 306 | // // Check if the current file name filter accepts the file: | ||
| 307 | // for (int i=0; i<mSelectedNameFilter->size(); ++i) { | ||
| 308 | // if (QDir::match(mSelectedNameFilter->at(i), qtFileName)) | ||
| 309 | // return YES; | ||
| 310 | // } | ||
| 311 | // return NO; | ||
| 312 | //} | ||
| 313 | // | ||
| 314 | //- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag | ||
| 315 | //{ | ||
| 316 | // Q_UNUSED(sender); | ||
| 317 | // if (!okFlag) | ||
| 318 | // return filename; | ||
| 319 | // if (mConfirmOverwrite) | ||
| 320 | // return filename; | ||
| 321 | // | ||
| 322 | // // User has clicked save, and no overwrite confirmation should occur. | ||
| 323 | // // To get the latter, we need to change the name we return (hence the prefix): | ||
| 324 | // return [@"___qt_very_unlikely_prefix_" stringByAppendingString:filename]; | ||
| 325 | //} | ||
| 326 | // | ||
| 327 | //- (void)setNameFilters:(const QStringList &)filters hideDetails:(BOOL)hideDetails | ||
| 328 | //{ | ||
| 329 | // [mPopUpButton removeAllItems]; | ||
| 330 | // *mNameFilterDropDownList = filters; | ||
| 331 | // if (filters.size() > 0){ | ||
| 332 | // for (int i=0; i<filters.size(); ++i) { | ||
| 333 | // QString filter = hideDetails ? [self removeExtensions:filters.at(i)] : filters.at(i); | ||
| 334 | // [mPopUpButton addItemWithTitle:QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(filter)]; | ||
| 335 | // } | ||
| 336 | // [mPopUpButton selectItemAtIndex:0]; | ||
| 337 | // [mSavePanel setAccessoryView:mAccessoryView]; | ||
| 338 | // } else | ||
| 339 | // [mSavePanel setAccessoryView:nil]; | ||
| 340 | // | ||
| 341 | // [self filterChanged:self]; | ||
| 342 | //} | ||
| 343 | // | ||
| 344 | //- (void)filterChanged:(id)sender | ||
| 345 | //{ | ||
| 346 | // // This mDelegate function is called when the _name_ filter changes. | ||
| 347 | // Q_UNUSED(sender); | ||
| 348 | // QString selection = mNameFilterDropDownList->value([mPopUpButton indexOfSelectedItem]); | ||
| 349 | // *mSelectedNameFilter = QT_PREPEND_NAMESPACE(qt_clean_filter_list)(selection); | ||
| 350 | // [mSavePanel validateVisibleColumns]; | ||
| 351 | // [self updateProperties]; | ||
| 352 | // if (mPriv) | ||
| 353 | // mPriv->QNSOpenSavePanelDelegate_filterSelected([mPopUpButton indexOfSelectedItem]); | ||
| 354 | //} | ||
| 355 | // | ||
| 356 | //- (QString)currentNameFilter | ||
| 357 | //{ | ||
| 358 | // return mNameFilterDropDownList->value([mPopUpButton indexOfSelectedItem]); | ||
| 359 | //} | ||
| 360 | // | ||
| 361 | //- (QStringList)selectedFiles | ||
| 362 | //{ | ||
| 363 | // if (mOpenPanel) | ||
| 364 | // return QT_PREPEND_NAMESPACE(qt_mac_NSArrayToQStringList)([mOpenPanel filenames]); | ||
| 365 | // else{ | ||
| 366 | // QStringList result; | ||
| 367 | // QString filename = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)([mSavePanel filename]); | ||
| 368 | // result << filename.remove(QLatin1String("___qt_very_unlikely_prefix_")); | ||
| 369 | // return result; | ||
| 370 | // } | ||
| 371 | //} | ||
| 372 | // | ||
| 373 | //- (void)updateProperties | ||
| 374 | //{ | ||
| 375 | // // Call this functions if mFileMode, mFileOptions, | ||
| 376 | // // mNameFilterDropDownList or mQDirFilter changes. | ||
| 377 | // // The savepanel does not contain the neccessary functions for this. | ||
| 378 | // bool chooseFilesOnly = mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFile) | ||
| 379 | // || mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFiles); | ||
| 380 | // bool chooseDirsOnly = mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::Directory) | ||
| 381 | // || mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::DirectoryOnly) | ||
| 382 | // || *mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::ShowDirsOnly); | ||
| 383 | // | ||
| 384 | // [mOpenPanel setCanChooseFiles:!chooseDirsOnly]; | ||
| 385 | // [mOpenPanel setCanChooseDirectories:!chooseFilesOnly]; | ||
| 386 | // [mSavePanel setCanCreateDirectories:!(*mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::ReadOnly))]; | ||
| 387 | // [mOpenPanel setAllowsMultipleSelection:(mFileMode == QT_PREPEND_NAMESPACE(QFileDialog::ExistingFiles))]; | ||
| 388 | // [mOpenPanel setResolvesAliases:!(*mFileOptions & QT_PREPEND_NAMESPACE(QFileDialog::DontResolveSymlinks))]; | ||
| 389 | // | ||
| 390 | // QStringList ext = [self acceptableExtensionsForSave]; | ||
| 391 | // if (mPriv && !ext.isEmpty() && !mPriv->defaultSuffix.isEmpty()) | ||
| 392 | // ext.prepend(mPriv->defaultSuffix); | ||
| 393 | // [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : QT_PREPEND_NAMESPACE(qt_mac_QStringListToNSMutableArray(ext))]; | ||
| 394 | // | ||
| 395 | // if ([mSavePanel isVisible]) | ||
| 396 | // [mOpenPanel validateVisibleColumns]; | ||
| 397 | //} | ||
| 398 | // | ||
| 399 | //- (void)panelSelectionDidChange:(id)sender | ||
| 400 | //{ | ||
| 401 | // Q_UNUSED(sender); | ||
| 402 | // if (mPriv) { | ||
| 403 | // QString selection = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString([mSavePanel filename])); | ||
| 404 | // if (selection != mCurrentSelection) { | ||
| 405 | // *mCurrentSelection = selection; | ||
| 406 | // mPriv->QNSOpenSavePanelDelegate_selectionChanged(selection); | ||
| 407 | // } | ||
| 408 | // } | ||
| 409 | //} | ||
| 410 | // | ||
| 411 | //- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo | ||
| 412 | //{ | ||
| 413 | // Q_UNUSED(panel); | ||
| 414 | // Q_UNUSED(contextInfo); | ||
| 415 | // mReturnCode = returnCode; | ||
| 416 | // if (mPriv) | ||
| 417 | // mPriv->QNSOpenSavePanelDelegate_panelClosed(returnCode == NSOKButton); | ||
| 418 | //} | ||
| 419 | // | ||
| 420 | //- (void)panel:(id)sender directoryDidChange:(NSString *)path | ||
| 421 | //{ | ||
| 422 | // Q_UNUSED(sender); | ||
| 423 | // if (!mPriv) | ||
| 424 | // return; | ||
| 425 | // if ([path isEqualToString:mCurrentDir]) | ||
| 426 | // return; | ||
| 427 | // | ||
| 428 | // [mCurrentDir release]; | ||
| 429 | // mCurrentDir = [path retain]; | ||
| 430 | // mPriv->QNSOpenSavePanelDelegate_directoryEntered(QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString(mCurrentDir))); | ||
| 431 | //} | ||
| 432 | // | ||
| 433 | ///* | ||
| 434 | // Returns a list of extensions (e.g. "png", "jpg", "gif") | ||
| 435 | // for the current name filter. If a filter do not conform | ||
| 436 | // to the format *.xyz or * or *.*, an empty list | ||
| 437 | // is returned meaning accept everything. | ||
| 438 | //*/ | ||
| 439 | //- (QStringList)acceptableExtensionsForSave | ||
| 440 | //{ | ||
| 441 | // QStringList result; | ||
| 442 | // for (int i=0; i<mSelectedNameFilter->count(); ++i) { | ||
| 443 | // const QString &filter = mSelectedNameFilter->at(i); | ||
| 444 | // if (filter.startsWith(QLatin1String("*.")) | ||
| 445 | // && !filter.contains(QLatin1Char('?')) | ||
| 446 | // && filter.count(QLatin1Char('*')) == 1) { | ||
| 447 | // result += filter.mid(2); | ||
| 448 | // } else { | ||
| 449 | // return QStringList(); // Accept everything | ||
| 450 | // } | ||
| 451 | // } | ||
| 452 | // return result; | ||
| 453 | //} | ||
| 454 | // | ||
| 455 | //- (QString)removeExtensions:(const QString &)filter | ||
| 456 | //{ | ||
| 457 | // QRegExp regExp(QT_PREPEND_NAMESPACE(QString::fromLatin1)(QT_PREPEND_NAMESPACE(qt_file_dialog_filter_reg_exp))); | ||
| 458 | // if (regExp.indexIn(filter) != -1) | ||
| 459 | // return regExp.cap(1).trimmed(); | ||
| 460 | // return filter; | ||
| 461 | //} | ||
| 462 | // | ||
| 463 | //- (void)createTextField | ||
| 464 | //{ | ||
| 465 | // NSRect textRect = { { 0.0, 3.0 }, { 100.0, 25.0 } }; | ||
| 466 | // mTextField = [[NSTextField alloc] initWithFrame:textRect]; | ||
| 467 | // [[mTextField cell] setFont:[NSFont systemFontOfSize: | ||
| 468 | // [NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; | ||
| 469 | // [mTextField setAlignment:NSRightTextAlignment]; | ||
| 470 | // [mTextField setEditable:false]; | ||
| 471 | // [mTextField setSelectable:false]; | ||
| 472 | // [mTextField setBordered:false]; | ||
| 473 | // [mTextField setDrawsBackground:false]; | ||
| 474 | // if (mPriv){ | ||
| 475 | // [mTextField setStringValue:[self strip:mPriv->qFileDialogUi->fileTypeLabel->text()]]; | ||
| 476 | // } else | ||
| 477 | // [mTextField setStringValue:QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(QT_PREPEND_NAMESPACE(QFileDialog::tr)("Files of type:"))]; | ||
| 478 | //} | ||
| 479 | // | ||
| 480 | //- (void)createPopUpButton:(const QString &)selectedFilter hideDetails:(BOOL)hideDetails | ||
| 481 | //{ | ||
| 482 | // NSRect popUpRect = { { 100.0, 5.0 }, { 250.0, 25.0 } }; | ||
| 483 | // mPopUpButton = [[NSPopUpButton alloc] initWithFrame:popUpRect pullsDown:NO]; | ||
| 484 | // [mPopUpButton setTarget:self]; | ||
| 485 | // [mPopUpButton setAction:@selector(filterChanged:)]; | ||
| 486 | // | ||
| 487 | // QStringList *filters = mNameFilterDropDownList; | ||
| 488 | // if (filters->size() > 0){ | ||
| 489 | // for (int i=0; i<mNameFilterDropDownList->size(); ++i) { | ||
| 490 | // QString filter = hideDetails ? [self removeExtensions:filters->at(i)] : filters->at(i); | ||
| 491 | // [mPopUpButton addItemWithTitle:QT_PREPEND_NAMESPACE(qt_mac_QStringToNSString)(filter)]; | ||
| 492 | // if (filters->at(i) == selectedFilter) | ||
| 493 | // [mPopUpButton selectItemAtIndex:i]; | ||
| 494 | // } | ||
| 495 | // } | ||
| 496 | //} | ||
| 497 | // | ||
| 498 | //- (void)createAccessory | ||
| 499 | //{ | ||
| 500 | // NSRect accessoryRect = { { 0.0, 0.0 }, { 450.0, 33.0 } }; | ||
| 501 | // mAccessoryView = [[NSView alloc] initWithFrame:accessoryRect]; | ||
| 502 | // [mAccessoryView addSubview:mTextField]; | ||
| 503 | // [mAccessoryView addSubview:mPopUpButton]; | ||
| 504 | //} | ||
| 505 | // | ||
| 506 | //@end | ||
| 507 | // | ||
| 508 | //QT_BEGIN_NAMESPACE | ||
| 509 | // | ||
| 510 | //void QFileDialogPrivate::QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath) | ||
| 511 | //{ | ||
| 512 | // emit q_func()->currentChanged(newPath); | ||
| 513 | //} | ||
| 514 | // | ||
| 515 | //void QFileDialogPrivate::QNSOpenSavePanelDelegate_panelClosed(bool accepted) | ||
| 516 | //{ | ||
| 517 | // if (accepted) | ||
| 518 | // q_func()->accept(); | ||
| 519 | // else | ||
| 520 | // q_func()->reject(); | ||
| 521 | //} | ||
| 522 | // | ||
| 523 | //void QFileDialogPrivate::QNSOpenSavePanelDelegate_directoryEntered(const QString &newDir) | ||
| 524 | //{ | ||
| 525 | // setLastVisitedDirectory(newDir); | ||
| 526 | // emit q_func()->directoryEntered(newDir); | ||
| 527 | //} | ||
| 528 | // | ||
| 529 | //void QFileDialogPrivate::QNSOpenSavePanelDelegate_filterSelected(int menuIndex) | ||
| 530 | //{ | ||
| 531 | // emit q_func()->filterSelected(nameFilters.at(menuIndex)); | ||
| 532 | //} | ||
| 533 | // | ||
| 534 | //extern OSErr qt_mac_create_fsref(const QString &, FSRef *); // qglobal.cpp | ||
| 535 | //extern void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1); // qglobal.cpp | ||
| 536 | // | ||
| 537 | //void QFileDialogPrivate::setDirectory_sys(const QString &directory) | ||
| 538 | //{ | ||
| 539 | //#ifndef QT_MAC_USE_COCOA | ||
| 540 | // if (directory == mCurrentLocation) | ||
| 541 | // return; | ||
| 542 | // mCurrentLocation = directory; | ||
| 543 | // emit q_func()->directoryEntered(mCurrentLocation); | ||
| 544 | // | ||
| 545 | // FSRef fsRef; | ||
| 546 | // if (qt_mac_create_fsref(directory, &fsRef) == noErr) { | ||
| 547 | // AEDesc desc; | ||
| 548 | // if (AECreateDesc(typeFSRef, &fsRef, sizeof(FSRef), &desc) == noErr) | ||
| 549 | // NavCustomControl(mDialog, kNavCtlSetLocation, (void*)&desc); | ||
| 550 | // } | ||
| 551 | //#else | ||
| 552 | // QMacCocoaAutoReleasePool pool; | ||
| 553 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 554 | // [delegate->mSavePanel setDirectory:qt_mac_QStringToNSString(directory)]; | ||
| 555 | //#endif | ||
| 556 | //} | ||
| 557 | // | ||
| 558 | //QString QFileDialogPrivate::directory_sys() const | ||
| 559 | //{ | ||
| 560 | //#ifndef QT_MAC_USE_COCOA | ||
| 561 | // return mCurrentLocation; | ||
| 562 | //#else | ||
| 563 | // QMacCocoaAutoReleasePool pool; | ||
| 564 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 565 | // return qt_mac_NSStringToQString([delegate->mSavePanel directory]); | ||
| 566 | //#endif | ||
| 567 | //} | ||
| 568 | // | ||
| 569 | //void QFileDialogPrivate::selectFile_sys(const QString &filename) | ||
| 570 | //{ | ||
| 571 | // QString filePath = filename; | ||
| 572 | // if (QDir::isRelativePath(filePath)) | ||
| 573 | // filePath = QFileInfo(directory_sys(), filePath).filePath(); | ||
| 574 | // | ||
| 575 | //#ifndef QT_MAC_USE_COCOA | ||
| 576 | // // Update the selection list immidiatly, so | ||
| 577 | // // subsequent calls to selectedFiles() gets correct: | ||
| 578 | // mCurrentSelectionList.clear(); | ||
| 579 | // mCurrentSelectionList << filename; | ||
| 580 | // if (mCurrentSelection != filename){ | ||
| 581 | // mCurrentSelection = filename; | ||
| 582 | // emit q_func()->currentChanged(mCurrentSelection); | ||
| 583 | // } | ||
| 584 | // | ||
| 585 | // AEDescList descList; | ||
| 586 | // if (AECreateList(0, 0, false, &descList) != noErr) | ||
| 587 | // return; | ||
| 588 | // | ||
| 589 | // FSRef fsRef; | ||
| 590 | // if (qt_mac_create_fsref(filePath, &fsRef) == noErr) { | ||
| 591 | // AEDesc desc; | ||
| 592 | // if (AECreateDesc(typeFSRef, &fsRef, sizeof(FSRef), &desc) == noErr){ | ||
| 593 | // if (AEPutDesc(&descList, 0, &desc) == noErr) | ||
| 594 | // NavCustomControl(mDialog, kNavCtlSetSelection, (void*)&descList); | ||
| 595 | // } | ||
| 596 | // } | ||
| 597 | // | ||
| 598 | // // Type the file name into the save dialog's text field: | ||
| 599 | // UInt8 *strBuffer = (UInt8 *)malloc(1024); | ||
| 600 | // qt_mac_to_pascal_string(QFileInfo(filename).fileName(), strBuffer); | ||
| 601 | // NavCustomControl(mDialog, kNavCtlSetEditFileName, strBuffer); | ||
| 602 | // free(strBuffer); | ||
| 603 | //#else | ||
| 604 | // // There seems to no way to select a file once the dialog is running. | ||
| 605 | // // So do the next best thing, set the file's directory: | ||
| 606 | // setDirectory_sys(QFileInfo(filePath).absolutePath()); | ||
| 607 | //#endif | ||
| 608 | //} | ||
| 609 | // | ||
| 610 | //QStringList QFileDialogPrivate::selectedFiles_sys() const | ||
| 611 | //{ | ||
| 612 | //#ifndef QT_MAC_USE_COCOA | ||
| 613 | // if (q_func()->acceptMode() == QFileDialog::AcceptOpen){ | ||
| 614 | // return mCurrentSelectionList; | ||
| 615 | // } else { | ||
| 616 | // return QStringList() << mCurrentLocation + QLatin1Char('/') | ||
| 617 | // + QCFString::toQString(NavDialogGetSaveFileName(mDialog)); | ||
| 618 | // } | ||
| 619 | //#else | ||
| 620 | // QMacCocoaAutoReleasePool pool; | ||
| 621 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 622 | // return [delegate selectedFiles]; | ||
| 623 | //#endif | ||
| 624 | //} | ||
| 625 | // | ||
| 626 | //void QFileDialogPrivate::setNameFilters_sys(const QStringList &filters) | ||
| 627 | //{ | ||
| 628 | //#ifndef QT_MAC_USE_COCOA | ||
| 629 | // Q_UNUSED(filters); | ||
| 630 | //#else | ||
| 631 | // QMacCocoaAutoReleasePool pool; | ||
| 632 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 633 | // bool hideDetails = q_func()->testOption(QFileDialog::HideNameFilterDetails); | ||
| 634 | // [delegate setNameFilters:filters hideDetails:hideDetails]; | ||
| 635 | //#endif | ||
| 636 | //} | ||
| 637 | // | ||
| 638 | //void QFileDialogPrivate::setFilter_sys() | ||
| 639 | //{ | ||
| 640 | //#ifndef QT_MAC_USE_COCOA | ||
| 641 | //#else | ||
| 642 | // QMacCocoaAutoReleasePool pool; | ||
| 643 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 644 | // *(delegate->mQDirFilter) = model->filter(); | ||
| 645 | // [delegate updateProperties]; | ||
| 646 | //#endif | ||
| 647 | //} | ||
| 648 | // | ||
| 649 | //void QFileDialogPrivate::selectNameFilter_sys(const QString &filter) | ||
| 650 | //{ | ||
| 651 | // int index = nameFilters.indexOf(filter); | ||
| 652 | // if (index != -1) { | ||
| 653 | //#ifndef QT_MAC_USE_COCOA | ||
| 654 | // NavMenuItemSpec navSpec; | ||
| 655 | // bzero(&navSpec, sizeof(NavMenuItemSpec)); | ||
| 656 | // navSpec.menuType = index; | ||
| 657 | // NavCustomControl(mDialog, kNavCtlSelectCustomType, &navSpec); | ||
| 658 | //#else | ||
| 659 | // QMacCocoaAutoReleasePool pool; | ||
| 660 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 661 | // [delegate->mPopUpButton selectItemAtIndex:index]; | ||
| 662 | // [delegate filterChanged:nil]; | ||
| 663 | //#endif | ||
| 664 | // } | ||
| 665 | //} | ||
| 666 | // | ||
| 667 | //QString QFileDialogPrivate::selectedNameFilter_sys() const | ||
| 668 | //{ | ||
| 669 | //#ifndef QT_MAC_USE_COCOA | ||
| 670 | // int index = filterInfo.currentSelection; | ||
| 671 | //#else | ||
| 672 | // QMacCocoaAutoReleasePool pool; | ||
| 673 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 674 | // int index = [delegate->mPopUpButton indexOfSelectedItem]; | ||
| 675 | //#endif | ||
| 676 | // return index != -1 ? nameFilters.at(index) : QString(); | ||
| 677 | //} | ||
| 678 | // | ||
| 679 | //void QFileDialogPrivate::deleteNativeDialog_sys() | ||
| 680 | //{ | ||
| 681 | //#ifndef QT_MAC_USE_COCOA | ||
| 682 | // if (mDialog) | ||
| 683 | // NavDialogDispose(mDialog); | ||
| 684 | // mDialog = 0; | ||
| 685 | // mDialogStarted = false; | ||
| 686 | //#else | ||
| 687 | // QMacCocoaAutoReleasePool pool; | ||
| 688 | // [reinterpret_cast<QNSOpenSavePanelDelegate *>(mDelegate) release]; | ||
| 689 | // mDelegate = 0; | ||
| 690 | //#endif | ||
| 691 | // nativeDialogInUse = false; | ||
| 692 | //} | ||
| 693 | // | ||
| 694 | //bool QFileDialogPrivate::setVisible_sys(bool visible) | ||
| 695 | //{ | ||
| 696 | // Q_Q(QFileDialog); | ||
| 697 | // if (!visible == q->isHidden()) | ||
| 698 | // return false; | ||
| 699 | // | ||
| 700 | //#ifndef QT_MAC_USE_COCOA | ||
| 701 | // return visible ? showCarbonNavServicesDialog() : hideCarbonNavServicesDialog(); | ||
| 702 | //#else | ||
| 703 | // return visible ? showCocoaFilePanel() : hideCocoaFilePanel(); | ||
| 704 | //#endif | ||
| 705 | //} | ||
| 706 | // | ||
| 707 | //#ifndef QT_MAC_USE_COCOA | ||
| 708 | //Boolean QFileDialogPrivate::qt_mac_filedialog_filter_proc(AEDesc *theItem, void *info, | ||
| 709 | // void *data, NavFilterModes) | ||
| 710 | //{ | ||
| 711 | // QFileDialogPrivate *fileDialogPrivate = static_cast<QFileDialogPrivate *>(data); | ||
| 712 | // | ||
| 713 | // if (!fileDialogPrivate || fileDialogPrivate->filterInfo.filters.isEmpty() | ||
| 714 | // || (fileDialogPrivate->filterInfo.currentSelection < 0 | ||
| 715 | // && fileDialogPrivate->filterInfo.currentSelection | ||
| 716 | // >= fileDialogPrivate->filterInfo.filters.size())) | ||
| 717 | // return true; | ||
| 718 | // | ||
| 719 | // NavFileOrFolderInfo *theInfo = static_cast<NavFileOrFolderInfo *>(info); | ||
| 720 | // QString file; | ||
| 721 | // const QtMacFilterName &fn | ||
| 722 | // = fileDialogPrivate->filterInfo.filters.at(fileDialogPrivate->filterInfo.currentSelection); | ||
| 723 | // if (theItem->descriptorType == typeFSRef) { | ||
| 724 | // FSRef ref; | ||
| 725 | // AEGetDescData(theItem, &ref, sizeof(ref)); | ||
| 726 | // UInt8 str_buffer[1024]; | ||
| 727 | // FSRefMakePath(&ref, str_buffer, 1024); | ||
| 728 | // file = QString::fromUtf8(reinterpret_cast<const char *>(str_buffer)); | ||
| 729 | // int slsh = file.lastIndexOf(QLatin1Char('/')); | ||
| 730 | // if (slsh != -1) | ||
| 731 | // file = file.right(file.length() - slsh - 1); | ||
| 732 | // } | ||
| 733 | // QStringList reg = fn.regexp.split(QLatin1String(";")); | ||
| 734 | // for (QStringList::const_iterator it = reg.constBegin(); it != reg.constEnd(); ++it) { | ||
| 735 | // QRegExp rg(*it, Qt::CaseInsensitive, QRegExp::Wildcard); | ||
| 736 | //#ifdef DEBUG_FILEDIALOG_FILTERS | ||
| 737 | // qDebug("QFileDialogPrivate::qt_mac_filedialog_filter_proc:%d, asked to filter.. %s (%s)", __LINE__, | ||
| 738 | // qPrintable(file), qPrintable(*it)); | ||
| 739 | //#endif | ||
| 740 | // if (rg.exactMatch(file)) | ||
| 741 | // return true; | ||
| 742 | // } | ||
| 743 | // return (theInfo->isFolder && !file.endsWith(QLatin1String(".app"))); | ||
| 744 | //} | ||
| 745 | // | ||
| 746 | //void QFileDialogPrivate::qt_mac_filedialog_event_proc(const NavEventCallbackMessage msg, | ||
| 747 | // NavCBRecPtr p, NavCallBackUserData data) | ||
| 748 | //{ | ||
| 749 | // QFileDialogPrivate *fileDialogPrivate = static_cast<QFileDialogPrivate *>(data); | ||
| 750 | // | ||
| 751 | // switch(msg) { | ||
| 752 | // case kNavCBPopupMenuSelect: { | ||
| 753 | // NavMenuItemSpec *s = static_cast<NavMenuItemSpec *>(p->eventData.eventDataParms.param); | ||
| 754 | // if (int(s->menuType) != fileDialogPrivate->filterInfo.currentSelection) { | ||
| 755 | // fileDialogPrivate->filterInfo.currentSelection = s->menuType; | ||
| 756 | // emit fileDialogPrivate->q_func()->filterSelected(fileDialogPrivate->nameFilters.at(s->menuType)); | ||
| 757 | // } | ||
| 758 | // if (fileDialogPrivate->acceptMode == QFileDialog::AcceptSave) { | ||
| 759 | // QString base = QCFString::toQString(NavDialogGetSaveFileName(p->context)); | ||
| 760 | // QFileInfo fi(base); | ||
| 761 | // base = fi.completeBaseName(); | ||
| 762 | // const QtMacFilterName &fn = fileDialogPrivate->filterInfo.filters.at( | ||
| 763 | // fileDialogPrivate->filterInfo.currentSelection); | ||
| 764 | // QStringList reg = fn.regexp.split(QLatin1String(";"), QString::SkipEmptyParts); | ||
| 765 | // QString r = reg.first(); | ||
| 766 | // r = r.right(r.length()-1); // Strip the * | ||
| 767 | // base += r; //"." + QString::number(s->menuType); | ||
| 768 | // NavDialogSetSaveFileName(p->context, QCFString::toCFStringRef(base)); | ||
| 769 | // } | ||
| 770 | //#ifdef DEBUG_FILEDIALOG_FILTERS | ||
| 771 | // qDebug("QFileDialogPrivate::qt_mac_filedialog_event_proc:%d - Selected a filter: %ld", __LINE__, s->menuType); | ||
| 772 | //#endif | ||
| 773 | // break; } | ||
| 774 | // case kNavCBStart:{ | ||
| 775 | // fileDialogPrivate->mDialogStarted = true; | ||
| 776 | // // Set selected file: | ||
| 777 | // QModelIndexList indexes = fileDialogPrivate->qFileDialogUi->listView->selectionModel()->selectedRows(); | ||
| 778 | // QString selected; | ||
| 779 | // if (!indexes.isEmpty()) | ||
| 780 | // selected = indexes.at(0).data(QFileSystemModel::FilePathRole).toString(); | ||
| 781 | // else | ||
| 782 | // selected = fileDialogPrivate->typedFiles().value(0); | ||
| 783 | // fileDialogPrivate->selectFile_sys(selected); | ||
| 784 | // fileDialogPrivate->selectNameFilter_sys(fileDialogPrivate->qFileDialogUi->fileTypeCombo->currentText()); | ||
| 785 | // break; } | ||
| 786 | // case kNavCBSelectEntry:{ | ||
| 787 | // // Event: Current selection has changed. | ||
| 788 | // QStringList prevSelectionList = fileDialogPrivate->mCurrentSelectionList; | ||
| 789 | // fileDialogPrivate->mCurrentSelectionList.clear(); | ||
| 790 | // QString fileNameToEmit; | ||
| 791 | // | ||
| 792 | // AEDescList *descList = (AEDescList *)p->eventData.eventDataParms.param; | ||
| 793 | // // Get the number of files selected: | ||
| 794 | // UInt8 strBuffer[1024]; | ||
| 795 | // long count; | ||
| 796 | // OSErr err = AECountItems(descList, &count); | ||
| 797 | // if (err != noErr || !count) | ||
| 798 | // break; | ||
| 799 | // | ||
| 800 | // for (long index=1; index<=count; ++index) { | ||
| 801 | // FSRef ref; | ||
| 802 | // err = AEGetNthPtr(descList, index, typeFSRef, 0, 0, &ref, sizeof(ref), 0); | ||
| 803 | // if (err != noErr) | ||
| 804 | // break; | ||
| 805 | // FSRefMakePath(&ref, strBuffer, 1024); | ||
| 806 | // QString selected = QString::fromUtf8((const char *)strBuffer); | ||
| 807 | // fileDialogPrivate->mCurrentSelectionList << selected; | ||
| 808 | // if (!prevSelectionList.contains(selected)) | ||
| 809 | // fileNameToEmit = selected; | ||
| 810 | // } | ||
| 811 | // | ||
| 812 | // if (!fileNameToEmit.isEmpty() && fileNameToEmit != fileDialogPrivate->mCurrentSelection) | ||
| 813 | // emit fileDialogPrivate->q_func()->currentChanged(fileNameToEmit); | ||
| 814 | // fileDialogPrivate->mCurrentSelection = fileNameToEmit; | ||
| 815 | // break; } | ||
| 816 | // case kNavCBShowDesktop: | ||
| 817 | // case kNavCBNewLocation:{ | ||
| 818 | // // Event: Current directory has changed. | ||
| 819 | // AEDesc *desc = (AEDesc *)p->eventData.eventDataParms.param; | ||
| 820 | // FSRef ref; | ||
| 821 | // AEGetDescData(desc, &ref, sizeof(ref)); | ||
| 822 | // UInt8 *strBuffer = (UInt8 *)malloc(1024); | ||
| 823 | // FSRefMakePath(&ref, strBuffer, 1024); | ||
| 824 | // QString newLocation = QString::fromUtf8((const char *)strBuffer); | ||
| 825 | // free(strBuffer); | ||
| 826 | // if (fileDialogPrivate->mCurrentLocation != newLocation){ | ||
| 827 | // fileDialogPrivate->mCurrentLocation = newLocation; | ||
| 828 | // QFileDialog::FileMode mode = fileDialogPrivate->fileMode; | ||
| 829 | // if (mode == QFileDialog::AnyFile || mode == QFileDialog::ExistingFile | ||
| 830 | // || mode == QFileDialog::ExistingFiles){ | ||
| 831 | // // When changing directory, the current selection is cleared if | ||
| 832 | // // we are supposed to be selecting files only: | ||
| 833 | // if (!fileDialogPrivate->mCurrentSelection.isEmpty()){ | ||
| 834 | // fileDialogPrivate->mCurrentSelectionList.clear(); | ||
| 835 | // fileDialogPrivate->mCurrentSelection.clear(); | ||
| 836 | // emit fileDialogPrivate->q_func()->currentChanged(fileDialogPrivate->mCurrentSelection); | ||
| 837 | // } | ||
| 838 | // } | ||
| 839 | // fileDialogPrivate->setLastVisitedDirectory(newLocation); | ||
| 840 | // emit fileDialogPrivate->q_func()->directoryEntered(newLocation); | ||
| 841 | // } | ||
| 842 | // break; } | ||
| 843 | // case kNavCBAccept: | ||
| 844 | // fileDialogPrivate->mDialogClosed = true; | ||
| 845 | // fileDialogPrivate->q_func()->accept(); | ||
| 846 | // break; | ||
| 847 | // case kNavCBCancel: | ||
| 848 | // fileDialogPrivate->mDialogClosed = true; | ||
| 849 | // fileDialogPrivate->q_func()->reject(); | ||
| 850 | // break; | ||
| 851 | // } | ||
| 852 | //} | ||
| 853 | // | ||
| 854 | //static QFileDialogPrivate::QtMacFilterName qt_mac_extract_filter(const QString &rawFilter, bool showDetails) | ||
| 855 | //{ | ||
| 856 | // QFileDialogPrivate::QtMacFilterName ret; | ||
| 857 | // ret.filter = rawFilter; | ||
| 858 | // QString result = rawFilter; | ||
| 859 | // QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); | ||
| 860 | // int index = r.indexIn(result); | ||
| 861 | // if (index >= 0) | ||
| 862 | // result = r.cap(2); | ||
| 863 | // | ||
| 864 | // if (showDetails) { | ||
| 865 | // ret.description = rawFilter; | ||
| 866 | // } else { | ||
| 867 | // if (index >= 0) | ||
| 868 | // ret.description = r.cap(1).trimmed(); | ||
| 869 | // if (ret.description.isEmpty()) | ||
| 870 | // ret.description = result; | ||
| 871 | // } | ||
| 872 | // ret.regexp = result.replace(QLatin1Char(' '), QLatin1Char(';')); | ||
| 873 | // return ret; | ||
| 874 | //} | ||
| 875 | // | ||
| 876 | //static QList<QFileDialogPrivate::QtMacFilterName> qt_mac_make_filters_list(const QString &filter, bool showDetails) | ||
| 877 | //{ | ||
| 878 | //#ifdef DEBUG_FILEDIALOG_FILTERS | ||
| 879 | // qDebug("QFileDialog:%d - Got filter (%s)", __LINE__, filter.latin1()); | ||
| 880 | //#endif | ||
| 881 | // | ||
| 882 | // QList<QFileDialogPrivate::QtMacFilterName> ret; | ||
| 883 | // QString f(filter); | ||
| 884 | // if (f.isEmpty()) | ||
| 885 | // f = QFileDialog::tr("All Files (*)"); | ||
| 886 | // if (f.isEmpty()) | ||
| 887 | // return ret; | ||
| 888 | // QStringList filts = qt_make_filter_list(f); | ||
| 889 | // for (QStringList::const_iterator it = filts.constBegin(); it != filts.constEnd(); ++it) { | ||
| 890 | // QFileDialogPrivate::QtMacFilterName filter = qt_mac_extract_filter(*it, showDetails); | ||
| 891 | //#ifdef DEBUG_FILEDIALOG_FILTERS | ||
| 892 | // qDebug("QFileDialog:%d Split out filter (%d) '%s' '%s' [%s]", __LINE__, ret.count(), | ||
| 893 | // filter->regxp.latin1(), filter->description.latin1(), (*it).latin1()); | ||
| 894 | //#endif | ||
| 895 | // ret.append(filter); | ||
| 896 | // } | ||
| 897 | // return ret; | ||
| 898 | //} | ||
| 899 | // | ||
| 900 | //void QFileDialogPrivate::createNavServicesDialog() | ||
| 901 | //{ | ||
| 902 | // Q_Q(QFileDialog); | ||
| 903 | // if (mDialog) | ||
| 904 | // deleteNativeDialog_sys(); | ||
| 905 | // | ||
| 906 | // NavDialogCreationOptions navOptions; | ||
| 907 | // NavGetDefaultDialogCreationOptions(&navOptions); | ||
| 908 | // | ||
| 909 | // // Translate QFileDialog settings into NavDialog options: | ||
| 910 | // if (qt_mac_is_macsheet(q)) { | ||
| 911 | // navOptions.modality = kWindowModalityWindowModal; | ||
| 912 | // navOptions.parentWindow = qt_mac_window_for(q->parentWidget()); | ||
| 913 | // } else if (q->windowModality() == Qt::ApplicationModal) | ||
| 914 | // navOptions.modality = kWindowModalityAppModal; | ||
| 915 | // else | ||
| 916 | // navOptions.modality = kWindowModalityNone; | ||
| 917 | // navOptions.optionFlags |= kNavSupportPackages; | ||
| 918 | // if (q->testOption(QFileDialog::DontConfirmOverwrite)) | ||
| 919 | // navOptions.optionFlags |= kNavDontConfirmReplacement; | ||
| 920 | // if (fileMode != QFileDialog::ExistingFiles) | ||
| 921 | // navOptions.optionFlags &= ~kNavAllowMultipleFiles; | ||
| 922 | // | ||
| 923 | // navOptions.windowTitle = QCFString::toCFStringRef(q->windowTitle()); | ||
| 924 | // | ||
| 925 | // navOptions.location.h = -1; | ||
| 926 | // navOptions.location.v = -1; | ||
| 927 | // | ||
| 928 | // QWidget *parent = q->parentWidget(); | ||
| 929 | // if (parent && parent->isVisible()) { | ||
| 930 | // WindowClass wclass; | ||
| 931 | // GetWindowClass(qt_mac_window_for(parent), &wclass); | ||
| 932 | // parent = parent->window(); | ||
| 933 | // QString s = parent->windowTitle(); | ||
| 934 | // navOptions.clientName = QCFString::toCFStringRef(s); | ||
| 935 | // } | ||
| 936 | // | ||
| 937 | // filterInfo.currentSelection = 0; | ||
| 938 | // filterInfo.filters = qt_mac_make_filters_list(nameFilters.join(QLatin1String(";;")), q->isNameFilterDetailsVisible()); | ||
| 939 | // QCFType<CFArrayRef> filterArray; | ||
| 940 | // if (filterInfo.filters.size() > 1) { | ||
| 941 | // int i = 0; | ||
| 942 | // CFStringRef *cfstringArray = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef) | ||
| 943 | // * filterInfo.filters.size())); | ||
| 944 | // for (i = 0; i < filterInfo.filters.size(); ++i) { | ||
| 945 | // cfstringArray[i] = QCFString::toCFStringRef(filterInfo.filters.at(i).description); | ||
| 946 | // } | ||
| 947 | // filterArray = CFArrayCreate(kCFAllocatorDefault, | ||
| 948 | // reinterpret_cast<const void **>(cfstringArray), filterInfo.filters.size(), | ||
| 949 | // &kCFTypeArrayCallBacks); | ||
| 950 | // navOptions.popupExtension = filterArray; | ||
| 951 | // free(cfstringArray); | ||
| 952 | // } | ||
| 953 | // | ||
| 954 | // if (q->acceptMode() == QFileDialog::AcceptSave) { | ||
| 955 | // if (NavCreatePutFileDialog(&navOptions, 'cute', kNavGenericSignature, | ||
| 956 | // QFileDialogPrivate::qt_mac_filedialog_event_proc, this, &mDialog)) { | ||
| 957 | // qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); | ||
| 958 | // return; | ||
| 959 | // } | ||
| 960 | // } else if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory) { | ||
| 961 | // if (NavCreateChooseFolderDialog(&navOptions, | ||
| 962 | // QFileDialogPrivate::qt_mac_filedialog_event_proc, 0, this, &mDialog)) { | ||
| 963 | // qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); | ||
| 964 | // return; | ||
| 965 | // } | ||
| 966 | // } else { | ||
| 967 | // if (NavCreateGetFileDialog(&navOptions, 0, | ||
| 968 | // QFileDialogPrivate::qt_mac_filedialog_event_proc, 0, | ||
| 969 | // QFileDialogPrivate::qt_mac_filedialog_filter_proc, this, &mDialog)) { | ||
| 970 | // qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__); | ||
| 971 | // return; | ||
| 972 | // } | ||
| 973 | // } | ||
| 974 | // | ||
| 975 | // // Set start-up directory: | ||
| 976 | // if (mCurrentLocation.isEmpty()) | ||
| 977 | // mCurrentLocation = rootPath(); | ||
| 978 | // FSRef fsRef; | ||
| 979 | // if (qt_mac_create_fsref(mCurrentLocation, &fsRef) == noErr) { | ||
| 980 | // AEDesc desc; | ||
| 981 | // if (AECreateDesc(typeFSRef, &fsRef, sizeof(FSRef), &desc) == noErr) | ||
| 982 | // NavCustomControl(mDialog, kNavCtlSetLocation, (void*)&desc); | ||
| 983 | // } | ||
| 984 | //} | ||
| 985 | // | ||
| 986 | //bool QFileDialogPrivate::showCarbonNavServicesDialog() | ||
| 987 | //{ | ||
| 988 | // Q_Q(QFileDialog); | ||
| 989 | // if (q->acceptMode() == QFileDialog::AcceptSave && q->windowModality() == Qt::NonModal) | ||
| 990 | // return false; // cannot do native no-modal save dialogs. | ||
| 991 | // createNavServicesDialog(); | ||
| 992 | // mDialogClosed = false; | ||
| 993 | // if (q->windowModality() != Qt::ApplicationModal) | ||
| 994 | // NavDialogRun(mDialog); | ||
| 995 | // return true; | ||
| 996 | //} | ||
| 997 | // | ||
| 998 | //bool QFileDialogPrivate::hideCarbonNavServicesDialog() | ||
| 999 | //{ | ||
| 1000 | // if (!mDialogClosed){ | ||
| 1001 | // mDialogClosed = true; | ||
| 1002 | // NavCustomControl(mDialog, kNavCtlCancel, 0); | ||
| 1003 | // } | ||
| 1004 | // return true; | ||
| 1005 | //} | ||
| 1006 | // | ||
| 1007 | //#else // Cocoa | ||
| 1008 | // | ||
| 1009 | //void QFileDialogPrivate::createNSOpenSavePanelDelegate() | ||
| 1010 | //{ | ||
| 1011 | // Q_Q(QFileDialog); | ||
| 1012 | // if (mDelegate) | ||
| 1013 | // return; | ||
| 1014 | // | ||
| 1015 | // bool selectDir = q->selectedFiles().isEmpty(); | ||
| 1016 | // QString selection(selectDir ? q->directory().absolutePath() : q->selectedFiles().value(0)); | ||
| 1017 | // QNSOpenSavePanelDelegate *delegate = [[QNSOpenSavePanelDelegate alloc] | ||
| 1018 | // initWithAcceptMode:acceptMode | ||
| 1019 | // title:q->windowTitle() | ||
| 1020 | // nameFilters:q->nameFilters() | ||
| 1021 | // selectedNameFilter:q->selectedNameFilter() | ||
| 1022 | // hideNameFilterDetails:q->testOption(QFileDialog::HideNameFilterDetails) | ||
| 1023 | // qDirFilter:model->filter() | ||
| 1024 | // fileOptions:opts | ||
| 1025 | // fileMode:fileMode | ||
| 1026 | // selectFile:selection | ||
| 1027 | // confirmOverwrite:!q->testOption(QFileDialog::DontConfirmOverwrite) | ||
| 1028 | // priv:this]; | ||
| 1029 | // | ||
| 1030 | // mDelegate = delegate; | ||
| 1031 | //} | ||
| 1032 | // | ||
| 1033 | //bool QFileDialogPrivate::showCocoaFilePanel() | ||
| 1034 | //{ | ||
| 1035 | // Q_Q(QFileDialog); | ||
| 1036 | // QMacCocoaAutoReleasePool pool; | ||
| 1037 | // createNSOpenSavePanelDelegate(); | ||
| 1038 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 1039 | // if (qt_mac_is_macsheet(q)) | ||
| 1040 | // [delegate showWindowModalSheet:q->parentWidget()]; | ||
| 1041 | // else | ||
| 1042 | // [delegate showModelessPanel]; | ||
| 1043 | // return true; | ||
| 1044 | //} | ||
| 1045 | // | ||
| 1046 | //bool QFileDialogPrivate::hideCocoaFilePanel() | ||
| 1047 | //{ | ||
| 1048 | // if (!mDelegate){ | ||
| 1049 | // // Nothing to do. We return false to leave the question | ||
| 1050 | // // open regarding whether or not to go native: | ||
| 1051 | // return false; | ||
| 1052 | // } else { | ||
| 1053 | // QMacCocoaAutoReleasePool pool; | ||
| 1054 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 1055 | // [delegate closePanel]; | ||
| 1056 | // // Even when we hide it, we are still using a | ||
| 1057 | // // native dialog, so return true: | ||
| 1058 | // return true; | ||
| 1059 | // } | ||
| 1060 | //} | ||
| 1061 | // | ||
| 1062 | //#endif | ||
| 1063 | // | ||
| 1064 | //void QFileDialogPrivate::mac_nativeDialogModalHelp() | ||
| 1065 | //{ | ||
| 1066 | // // Do a queued meta-call to open the native modal dialog so it opens after the new | ||
| 1067 | // // event loop has started to execute (in QDialog::exec). Using a timer rather than | ||
| 1068 | // // a queued meta call is intentional to ensure that the call is only delivered when | ||
| 1069 | // // [NSApp run] runs (timers are handeled special in cocoa). If NSApp is not | ||
| 1070 | // // running (which is the case if e.g a top-most QEventLoop has been | ||
| 1071 | // // interrupted, and the second-most event loop has not yet been reactivated (regardless | ||
| 1072 | // // if [NSApp run] is still on the stack)), showing a native modal dialog will fail. | ||
| 1073 | // if (nativeDialogInUse){ | ||
| 1074 | // Q_Q(QFileDialog); | ||
| 1075 | // QTimer::singleShot(1, q, SLOT(_q_macRunNativeAppModalPanel())); | ||
| 1076 | // } | ||
| 1077 | //} | ||
| 1078 | // | ||
| 1079 | //void QFileDialogPrivate::_q_macRunNativeAppModalPanel() | ||
| 1080 | //{ | ||
| 1081 | // QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); | ||
| 1082 | //#ifndef QT_MAC_USE_COCOA | ||
| 1083 | // NavDialogRun(mDialog); | ||
| 1084 | //#else | ||
| 1085 | // Q_Q(QFileDialog); | ||
| 1086 | // QMacCocoaAutoReleasePool pool; | ||
| 1087 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 1088 | // [delegate runApplicationModalPanel]; | ||
| 1089 | // dialogResultCode_sys() == QDialog::Accepted ? q->accept() : q->reject(); | ||
| 1090 | //#endif | ||
| 1091 | //} | ||
| 1092 | // | ||
| 1093 | //QDialog::DialogCode QFileDialogPrivate::dialogResultCode_sys() | ||
| 1094 | //{ | ||
| 1095 | //#ifndef QT_MAC_USE_COCOA | ||
| 1096 | // NavUserAction result = NavDialogGetUserAction(mDialog); | ||
| 1097 | // if (result == kNavUserActionCancel || result == kNavUserActionNone) | ||
| 1098 | // return QDialog::Rejected; | ||
| 1099 | // else | ||
| 1100 | // return QDialog::Accepted; | ||
| 1101 | //#else | ||
| 1102 | // QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); | ||
| 1103 | // return [delegate dialogResultCode]; | ||
| 1104 | //#endif | ||
| 1105 | //} | ||
| 1106 | |||
| 1107 | |||
| 1108 | QT_END_NAMESPACE | ||
| 1109 | |||
| 1110 | #endif // QT_NO_FILEDIALOG |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qfontdialog_p.h" | ||
| 43 | #if !defined(QT_NO_FONTDIALOG) && defined(Q_WS_MAC) | ||
| 44 | #include <qapplication.h> | ||
| 45 | #include <qdialogbuttonbox.h> | ||
| 46 | #include <qlineedit.h> | ||
| 47 | #include <private/qapplication_p.h> | ||
| 48 | #include <private/qfont_p.h> | ||
| 49 | #include <private/qfontengine_p.h> | ||
| 50 | #include <private/qt_cocoa_helpers_mac_p.h> | ||
| 51 | #include <private/qt_mac_p.h> | ||
| 52 | #include <qdebug.h> | ||
| 53 | #import <AppKit/AppKit.h> | ||
| 54 | #import <Foundation/Foundation.h> | ||
| 55 | |||
| 56 | #if !CGFLOAT_DEFINED | ||
| 57 | typedef float CGFloat; // Should only not be defined on 32-bit platforms | ||
| 58 | #endif | ||
| 59 | |||
| 60 | QT_USE_NAMESPACE | ||
| 61 | |||
| 62 | // should a priori be kept in sync with qcolordialog_mac.mm | ||
| 63 | //const CGFloat ButtonMinWidth = 78.0; | ||
| 64 | //const CGFloat ButtonMinHeight = 32.0; | ||
| 65 | //const CGFloat ButtonSpacing = 0.0; | ||
| 66 | //const CGFloat ButtonTopMargin = 0.0; | ||
| 67 | //const CGFloat ButtonBottomMargin = 7.0; | ||
| 68 | //const CGFloat ButtonSideMargin = 9.0; | ||
| 69 | |||
| 70 | // looks better with some margins | ||
| 71 | //const CGFloat DialogTopMargin = 7.0; | ||
| 72 | //const CGFloat DialogSideMargin = 9.0; | ||
| 73 | // | ||
| 74 | //const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; | ||
| 75 | // | ||
| 76 | //@class QCocoaFontPanelDelegate; | ||
| 77 | |||
| 78 | |||
| 79 | //#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | ||
| 80 | |||
| 81 | //@protocol NSWindowDelegate <NSObject> | ||
| 82 | //- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; | ||
| 83 | //@end | ||
| 84 | // | ||
| 85 | //#endif | ||
| 86 | // | ||
| 87 | //@interface QCocoaFontPanelDelegate : NSObject <NSWindowDelegate> { | ||
| 88 | // NSFontPanel *mFontPanel; | ||
| 89 | // NSView *mStolenContentView; | ||
| 90 | // NSButton *mOkButton; | ||
| 91 | // NSButton *mCancelButton; | ||
| 92 | // QFontDialogPrivate *mPriv; | ||
| 93 | // QFont *mQtFont; | ||
| 94 | // BOOL mPanelHackedWithButtons; | ||
| 95 | // CGFloat mDialogExtraWidth; | ||
| 96 | // CGFloat mDialogExtraHeight; | ||
| 97 | // NSModalSession mModalSession; | ||
| 98 | //} | ||
| 99 | //- (id)initWithFontPanel:(NSFontPanel *)panel | ||
| 100 | // stolenContentView:(NSView *)stolenContentView | ||
| 101 | // okButton:(NSButton *)okButton | ||
| 102 | // cancelButton:(NSButton *)cancelButton | ||
| 103 | // priv:(QFontDialogPrivate *)priv | ||
| 104 | // extraWidth:(CGFloat)extraWidth | ||
| 105 | // extraHeight:(CGFloat)extraHeight; | ||
| 106 | //- (void)changeFont:(id)sender; | ||
| 107 | //- (void)changeAttributes:(id)sender; | ||
| 108 | //- (void)setModalSession:(NSModalSession)session; | ||
| 109 | //- (BOOL)windowShouldClose:(id)window; | ||
| 110 | //- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; | ||
| 111 | //- (void)relayout; | ||
| 112 | //- (void)relayoutToContentSize:(NSSize)frameSize; | ||
| 113 | //- (void)onOkClicked; | ||
| 114 | //- (void)onCancelClicked; | ||
| 115 | //- (NSFontPanel *)fontPanel; | ||
| 116 | //- (NSWindow *)actualPanel; | ||
| 117 | //- (NSSize)dialogExtraSize; | ||
| 118 | //- (void)setQtFont:(const QFont &)newFont; | ||
| 119 | //- (QFont)qtFont; | ||
| 120 | //- (void)finishOffWithCode:(NSInteger)result; | ||
| 121 | //- (void)cleanUpAfterMyself; | ||
| 122 | //@end | ||
| 123 | // | ||
| 124 | //static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) | ||
| 125 | //{ | ||
| 126 | // QFont newFont; | ||
| 127 | // if (cocoaFont) { | ||
| 128 | // int pSize = qRound([cocoaFont pointSize]); | ||
| 129 | // QString family(qt_mac_NSStringToQString([cocoaFont familyName])); | ||
| 130 | // QString typeface(qt_mac_NSStringToQString([cocoaFont fontName])); | ||
| 131 | // | ||
| 132 | // int hyphenPos = typeface.indexOf(QLatin1Char('-')); | ||
| 133 | // if (hyphenPos != -1) { | ||
| 134 | // typeface.remove(0, hyphenPos + 1); | ||
| 135 | // } else { | ||
| 136 | // typeface = QLatin1String("Normal"); | ||
| 137 | // } | ||
| 138 | // | ||
| 139 | // newFont = QFontDatabase().font(family, typeface, pSize); | ||
| 140 | // newFont.setUnderline(resolveFont.underline()); | ||
| 141 | // newFont.setStrikeOut(resolveFont.strikeOut()); | ||
| 142 | // | ||
| 143 | // } | ||
| 144 | // return newFont; | ||
| 145 | //} | ||
| 146 | // | ||
| 147 | //@implementation QCocoaFontPanelDelegate | ||
| 148 | //- (id)initWithFontPanel:(NSFontPanel *)panel | ||
| 149 | // stolenContentView:(NSView *)stolenContentView | ||
| 150 | // okButton:(NSButton *)okButton | ||
| 151 | // cancelButton:(NSButton *)cancelButton | ||
| 152 | // priv:(QFontDialogPrivate *)priv | ||
| 153 | // extraWidth:(CGFloat)extraWidth | ||
| 154 | // extraHeight:(CGFloat)extraHeight | ||
| 155 | //{ | ||
| 156 | // self = [super init]; | ||
| 157 | // mFontPanel = panel; | ||
| 158 | // mStolenContentView = stolenContentView; | ||
| 159 | // mOkButton = okButton; | ||
| 160 | // mCancelButton = cancelButton; | ||
| 161 | // mPriv = priv; | ||
| 162 | // mPanelHackedWithButtons = (okButton != 0); | ||
| 163 | // mDialogExtraWidth = extraWidth; | ||
| 164 | // mDialogExtraHeight = extraHeight; | ||
| 165 | // mModalSession = 0; | ||
| 166 | // | ||
| 167 | // if (mPanelHackedWithButtons) { | ||
| 168 | // [self relayout]; | ||
| 169 | // | ||
| 170 | // [okButton setAction:@selector(onOkClicked)]; | ||
| 171 | // [okButton setTarget:self]; | ||
| 172 | // | ||
| 173 | // [cancelButton setAction:@selector(onCancelClicked)]; | ||
| 174 | // [cancelButton setTarget:self]; | ||
| 175 | // } | ||
| 176 | // mQtFont = new QFont(); | ||
| 177 | // return self; | ||
| 178 | //} | ||
| 179 | // | ||
| 180 | //- (void)dealloc | ||
| 181 | //{ | ||
| 182 | // delete mQtFont; | ||
| 183 | // [super dealloc]; | ||
| 184 | //} | ||
| 185 | // | ||
| 186 | //- (void)changeFont:(id)sender | ||
| 187 | //{ | ||
| 188 | // NSFont *dummyFont = [NSFont userFontOfSize:12.0]; | ||
| 189 | // [self setQtFont:qfontForCocoaFont([sender convertFont:dummyFont], *mQtFont)]; | ||
| 190 | // if (mPriv) | ||
| 191 | // mPriv->updateSampleFont(*mQtFont); | ||
| 192 | //} | ||
| 193 | // | ||
| 194 | //- (void)changeAttributes:(id)sender | ||
| 195 | //{ | ||
| 196 | // NSDictionary *dummyAttribs = [NSDictionary dictionary]; | ||
| 197 | // NSDictionary *attribs = [sender convertAttributes:dummyAttribs]; | ||
| 198 | // | ||
| 199 | //#ifdef QT_MAC_USE_COCOA | ||
| 200 | // for (id key in attribs) { | ||
| 201 | //#else | ||
| 202 | // NSEnumerator *enumerator = [attribs keyEnumerator]; | ||
| 203 | // id key; | ||
| 204 | // while((key = [enumerator nextObject])) { | ||
| 205 | //#endif | ||
| 206 | // NSNumber *number = static_cast<NSNumber *>([attribs objectForKey:key]); | ||
| 207 | // if ([key isEqual:NSUnderlineStyleAttributeName]) { | ||
| 208 | // mQtFont->setUnderline([number intValue] != NSUnderlineStyleNone); | ||
| 209 | // } else if ([key isEqual:NSStrikethroughStyleAttributeName]) { | ||
| 210 | // mQtFont->setStrikeOut([number intValue] != NSUnderlineStyleNone); | ||
| 211 | // } | ||
| 212 | // } | ||
| 213 | // | ||
| 214 | // if (mPriv) | ||
| 215 | // mPriv->updateSampleFont(*mQtFont); | ||
| 216 | //} | ||
| 217 | // | ||
| 218 | //- (void)setModalSession:(NSModalSession)session | ||
| 219 | //{ | ||
| 220 | // Q_ASSERT(!mModalSession); | ||
| 221 | // mModalSession = session; | ||
| 222 | //} | ||
| 223 | // | ||
| 224 | //- (BOOL)windowShouldClose:(id)window | ||
| 225 | //{ | ||
| 226 | // Q_UNUSED(window); | ||
| 227 | // if (mPanelHackedWithButtons) { | ||
| 228 | // [self onCancelClicked]; | ||
| 229 | // } else { | ||
| 230 | // [self finishOffWithCode:NSCancelButton]; | ||
| 231 | // } | ||
| 232 | // return true; | ||
| 233 | //} | ||
| 234 | // | ||
| 235 | //- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize | ||
| 236 | //{ | ||
| 237 | // if (mFontPanel == window) { | ||
| 238 | // proposedFrameSize = [static_cast<id <NSWindowDelegate> >(mFontPanel) windowWillResize:mFontPanel toSize:proposedFrameSize]; | ||
| 239 | // } else { | ||
| 240 | // /* | ||
| 241 | // Ugly hack: NSFontPanel rearranges the layout of its main | ||
| 242 | // component in windowWillResize:toSize:. So we temporarily | ||
| 243 | // restore the stolen content view to its rightful owner, | ||
| 244 | // call windowWillResize:toSize:, and steal the content view | ||
| 245 | // again. | ||
| 246 | // */ | ||
| 247 | // [mStolenContentView removeFromSuperview]; | ||
| 248 | // [mFontPanel setContentView:mStolenContentView]; | ||
| 249 | // NSSize extraSize = [self dialogExtraSize]; | ||
| 250 | // proposedFrameSize.width -= extraSize.width; | ||
| 251 | // proposedFrameSize.height -= extraSize.height; | ||
| 252 | // proposedFrameSize = [static_cast<id <NSWindowDelegate> >(mFontPanel) windowWillResize:mFontPanel toSize:proposedFrameSize]; | ||
| 253 | // NSRect frameRect = { { 0.0, 0.0 }, proposedFrameSize }; | ||
| 254 | // [mFontPanel setFrame:frameRect display:NO]; | ||
| 255 | // [mFontPanel setContentView:0]; | ||
| 256 | // [[window contentView] addSubview:mStolenContentView]; | ||
| 257 | // proposedFrameSize.width += extraSize.width; | ||
| 258 | // proposedFrameSize.height += extraSize.height; | ||
| 259 | // } | ||
| 260 | // if (mPanelHackedWithButtons) { | ||
| 261 | // NSRect frameRect = { { 0.0, 0.0 }, proposedFrameSize }; | ||
| 262 | // NSRect contentRect = [NSWindow contentRectForFrameRect:frameRect styleMask:[window styleMask]]; | ||
| 263 | // [self relayoutToContentSize:contentRect.size]; | ||
| 264 | // } | ||
| 265 | // return proposedFrameSize; | ||
| 266 | //} | ||
| 267 | // | ||
| 268 | //- (void)relayout | ||
| 269 | //{ | ||
| 270 | // [self relayoutToContentSize:[[mStolenContentView superview] frame].size]; | ||
| 271 | //} | ||
| 272 | // | ||
| 273 | //- (void)relayoutToContentSize:(NSSize)frameSize; | ||
| 274 | //{ | ||
| 275 | // Q_ASSERT(mPanelHackedWithButtons); | ||
| 276 | // | ||
| 277 | // [mOkButton sizeToFit]; | ||
| 278 | // NSSize okSizeHint = [mOkButton frame].size; | ||
| 279 | // | ||
| 280 | // [mCancelButton sizeToFit]; | ||
| 281 | // NSSize cancelSizeHint = [mCancelButton frame].size; | ||
| 282 | // | ||
| 283 | // const CGFloat ButtonWidth = qMin(qMax(ButtonMinWidth, | ||
| 284 | // qMax(okSizeHint.width, cancelSizeHint.width)), | ||
| 285 | // CGFloat((frameSize.width - 2.0 * ButtonSideMargin | ||
| 286 | // - ButtonSpacing) * 0.5)); | ||
| 287 | // const CGFloat ButtonHeight = qMax(ButtonMinHeight, | ||
| 288 | // qMax(okSizeHint.height, cancelSizeHint.height)); | ||
| 289 | // | ||
| 290 | // const CGFloat X = DialogSideMargin; | ||
| 291 | // const CGFloat Y = ButtonBottomMargin + ButtonHeight + ButtonTopMargin; | ||
| 292 | // | ||
| 293 | // NSRect okRect = { { frameSize.width - ButtonSideMargin - ButtonWidth, | ||
| 294 | // ButtonBottomMargin }, | ||
| 295 | // { ButtonWidth, ButtonHeight } }; | ||
| 296 | // [mOkButton setFrame:okRect]; | ||
| 297 | // [mOkButton setNeedsDisplay:YES]; | ||
| 298 | // | ||
| 299 | // NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - ButtonWidth, | ||
| 300 | // ButtonBottomMargin }, | ||
| 301 | // { ButtonWidth, ButtonHeight } }; | ||
| 302 | // [mCancelButton setFrame:cancelRect]; | ||
| 303 | // [mCancelButton setNeedsDisplay:YES]; | ||
| 304 | // | ||
| 305 | // NSRect stolenCVRect = { { X, Y }, | ||
| 306 | // { frameSize.width - X - X, frameSize.height - Y - DialogTopMargin } }; | ||
| 307 | // [mStolenContentView setFrame:stolenCVRect]; | ||
| 308 | // [mStolenContentView setNeedsDisplay:YES]; | ||
| 309 | // | ||
| 310 | // [[mStolenContentView superview] setNeedsDisplay:YES]; | ||
| 311 | //} | ||
| 312 | // | ||
| 313 | //- (void)onOkClicked | ||
| 314 | //{ | ||
| 315 | // Q_ASSERT(mPanelHackedWithButtons); | ||
| 316 | // NSFontManager *fontManager = [NSFontManager sharedFontManager]; | ||
| 317 | // [self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]], | ||
| 318 | // *mQtFont)]; | ||
| 319 | // [[mStolenContentView window] close]; | ||
| 320 | // [self finishOffWithCode:NSOKButton]; | ||
| 321 | //} | ||
| 322 | // | ||
| 323 | //- (void)onCancelClicked | ||
| 324 | //{ | ||
| 325 | // Q_ASSERT(mPanelHackedWithButtons); | ||
| 326 | // [[mStolenContentView window] close]; | ||
| 327 | // [self finishOffWithCode:NSCancelButton]; | ||
| 328 | //} | ||
| 329 | // | ||
| 330 | //- (NSFontPanel *)fontPanel | ||
| 331 | //{ | ||
| 332 | // return mFontPanel; | ||
| 333 | //} | ||
| 334 | // | ||
| 335 | //- (NSWindow *)actualPanel | ||
| 336 | //{ | ||
| 337 | // return [mStolenContentView window]; | ||
| 338 | //} | ||
| 339 | // | ||
| 340 | //- (NSSize)dialogExtraSize | ||
| 341 | //{ | ||
| 342 | // // this must be recomputed each time, because sometimes the | ||
| 343 | // // NSFontPanel has the NSDocModalWindowMask flag set, and sometimes | ||
| 344 | // // not -- which affects the frame rect vs. content rect measurements | ||
| 345 | // | ||
| 346 | // // take the different frame rectangles into account for dialogExtra{Width,Height} | ||
| 347 | // NSRect someRect = { { 0.0, 0.0 }, { 100000.0, 100000.0 } }; | ||
| 348 | // NSRect sharedFontPanelContentRect = [mFontPanel contentRectForFrameRect:someRect]; | ||
| 349 | // NSRect ourPanelContentRect = [NSWindow contentRectForFrameRect:someRect styleMask:StyleMask]; | ||
| 350 | // | ||
| 351 | // NSSize result = { mDialogExtraWidth, mDialogExtraHeight }; | ||
| 352 | // result.width -= ourPanelContentRect.size.width - sharedFontPanelContentRect.size.width; | ||
| 353 | // result.height -= ourPanelContentRect.size.height - sharedFontPanelContentRect.size.height; | ||
| 354 | // return result; | ||
| 355 | //} | ||
| 356 | // | ||
| 357 | //- (void)setQtFont:(const QFont &)newFont | ||
| 358 | //{ | ||
| 359 | // delete mQtFont; | ||
| 360 | // mQtFont = new QFont(newFont); | ||
| 361 | //} | ||
| 362 | // | ||
| 363 | //- (QFont)qtFont | ||
| 364 | //{ | ||
| 365 | // return *mQtFont; | ||
| 366 | //} | ||
| 367 | // | ||
| 368 | //- (void)finishOffWithCode:(NSInteger)code | ||
| 369 | //{ | ||
| 370 | // if (mPriv) { | ||
| 371 | // if (mModalSession) { | ||
| 372 | // [NSApp endModalSession:mModalSession]; | ||
| 373 | // mModalSession = 0; | ||
| 374 | // } | ||
| 375 | // | ||
| 376 | // mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); | ||
| 377 | // } else { | ||
| 378 | // [NSApp stopModalWithCode:code]; | ||
| 379 | // } | ||
| 380 | //} | ||
| 381 | // | ||
| 382 | //- (void)cleanUpAfterMyself | ||
| 383 | //{ | ||
| 384 | // if (mPanelHackedWithButtons) { | ||
| 385 | // NSView *ourContentView = [mFontPanel contentView]; | ||
| 386 | // | ||
| 387 | // // return stolen stuff to its rightful owner | ||
| 388 | // [mStolenContentView removeFromSuperview]; | ||
| 389 | // [mFontPanel setContentView:mStolenContentView]; | ||
| 390 | // | ||
| 391 | // [mOkButton release]; | ||
| 392 | // [mCancelButton release]; | ||
| 393 | // [ourContentView release]; | ||
| 394 | // } | ||
| 395 | // [mFontPanel setDelegate:nil]; | ||
| 396 | // [[NSFontManager sharedFontManager] setDelegate:nil]; | ||
| 397 | // [[NSFontManager sharedFontManager] setTarget:nil]; | ||
| 398 | //} | ||
| 399 | //@end | ||
| 400 | // | ||
| 401 | //QT_BEGIN_NAMESPACE | ||
| 402 | // | ||
| 403 | //extern void macStartInterceptNSPanelCtor(); | ||
| 404 | //extern void macStopInterceptNSPanelCtor(); | ||
| 405 | //extern NSButton *macCreateButton(const char *text, NSView *superview); | ||
| 406 | // | ||
| 407 | //void *QFontDialogPrivate::openCocoaFontPanel(const QFont &initial, | ||
| 408 | // QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options, | ||
| 409 | // QFontDialogPrivate *priv) | ||
| 410 | //{ | ||
| 411 | // Q_UNUSED(parent); // we would use the parent if only NSFontPanel could be a sheet | ||
| 412 | // QMacCocoaAutoReleasePool pool; | ||
| 413 | // | ||
| 414 | // /* | ||
| 415 | // The standard Cocoa font panel has no OK or Cancel button and | ||
| 416 | // is created as a utility window. For strange reasons (which seem | ||
| 417 | // to stem from the fact that the font panel is based on a NIB | ||
| 418 | // file), the approach we use for the color panel doesn't work for | ||
| 419 | // the font panel (and, inversely, the approach we use here doesn't | ||
| 420 | // quite work for color panel, and crashed last time I tried). So | ||
| 421 | // instead, we take the following steps: | ||
| 422 | // | ||
| 423 | // 1. Constructs a plain NSPanel that looks the way we want it | ||
| 424 | // to look. Specifically, if the NoButtons option is off, we | ||
| 425 | // construct a panel without the NSUtilityWindowMask flag | ||
| 426 | // and with buttons (OK and Cancel). | ||
| 427 | // | ||
| 428 | // 2. Steal the content view from the shared NSFontPanel and | ||
| 429 | // put it inside our new NSPanel's content view, together | ||
| 430 | // with the OK and Cancel buttons. | ||
| 431 | // | ||
| 432 | // 3. Lay out the original content view and the buttons when | ||
| 433 | // the font panel is shown and whenever it is resized. | ||
| 434 | // | ||
| 435 | // 4. Clean up after ourselves. | ||
| 436 | // | ||
| 437 | // PS. Some customization is also done in QCocoaApplication | ||
| 438 | // validModesForFontPanel:. | ||
| 439 | // */ | ||
| 440 | // | ||
| 441 | // Qt::WindowModality modality = Qt::ApplicationModal; | ||
| 442 | // if (priv) | ||
| 443 | // modality = priv->fontDialog()->windowModality(); | ||
| 444 | // | ||
| 445 | // bool needButtons = !(options & QFontDialog::NoButtons); | ||
| 446 | // // don't need our own panel if the title bar isn't visible anyway (in a sheet) | ||
| 447 | // bool needOwnPanel = (needButtons && modality != Qt::WindowModal); | ||
| 448 | // | ||
| 449 | // bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; | ||
| 450 | // NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; | ||
| 451 | // [sharedFontPanel setHidesOnDeactivate:false]; | ||
| 452 | // | ||
| 453 | // // hack to ensure that QCocoaApplication's validModesForFontPanel: | ||
| 454 | // // implementation is honored | ||
| 455 | // if (!sharedFontPanelExisted && needOwnPanel) { | ||
| 456 | // [sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; | ||
| 457 | // [sharedFontPanel close]; | ||
| 458 | // } | ||
| 459 | // | ||
| 460 | // NSPanel *ourPanel = 0; | ||
| 461 | // NSView *stolenContentView = 0; | ||
| 462 | // NSButton *okButton = 0; | ||
| 463 | // NSButton *cancelButton = 0; | ||
| 464 | // | ||
| 465 | // CGFloat dialogExtraWidth = 0.0; | ||
| 466 | // CGFloat dialogExtraHeight = 0.0; | ||
| 467 | // | ||
| 468 | // if (!needOwnPanel) { | ||
| 469 | // // we can reuse the NSFontPanel unchanged | ||
| 470 | // ourPanel = sharedFontPanel; | ||
| 471 | // } else { | ||
| 472 | // // compute dialogExtra{Width,Height} | ||
| 473 | // dialogExtraWidth = 2.0 * DialogSideMargin; | ||
| 474 | // dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight | ||
| 475 | // + ButtonBottomMargin; | ||
| 476 | // | ||
| 477 | // // compute initial contents rectangle | ||
| 478 | // NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; | ||
| 479 | // contentRect.size.width += dialogExtraWidth; | ||
| 480 | // contentRect.size.height += dialogExtraHeight; | ||
| 481 | // | ||
| 482 | // // create the new panel | ||
| 483 | // ourPanel = [[NSPanel alloc] initWithContentRect:contentRect | ||
| 484 | // styleMask:StyleMask | ||
| 485 | // backing:NSBackingStoreBuffered | ||
| 486 | // defer:YES]; | ||
| 487 | // [ourPanel setReleasedWhenClosed:YES]; | ||
| 488 | // } | ||
| 489 | // | ||
| 490 | // stolenContentView = [sharedFontPanel contentView]; | ||
| 491 | // | ||
| 492 | // if (needButtons) { | ||
| 493 | // // steal the font panel's contents view | ||
| 494 | // [stolenContentView retain]; | ||
| 495 | // [sharedFontPanel setContentView:0]; | ||
| 496 | // | ||
| 497 | // // create a new content view and add the stolen one as a subview | ||
| 498 | // NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; | ||
| 499 | // NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; | ||
| 500 | // [ourContentView addSubview:stolenContentView]; | ||
| 501 | // | ||
| 502 | // // create OK and Cancel buttons and add these as subviews | ||
| 503 | // okButton = macCreateButton("&OK", ourContentView); | ||
| 504 | // cancelButton = macCreateButton("Cancel", ourContentView); | ||
| 505 | // | ||
| 506 | // [ourPanel setContentView:ourContentView]; | ||
| 507 | // [ourPanel setDefaultButtonCell:[okButton cell]]; | ||
| 508 | // } | ||
| 509 | // | ||
| 510 | // // create a delegate and set it | ||
| 511 | // QCocoaFontPanelDelegate *delegate = | ||
| 512 | // [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel | ||
| 513 | // stolenContentView:stolenContentView | ||
| 514 | // okButton:okButton | ||
| 515 | // cancelButton:cancelButton | ||
| 516 | // priv:priv | ||
| 517 | // extraWidth:dialogExtraWidth | ||
| 518 | // extraHeight:dialogExtraHeight]; | ||
| 519 | // [ourPanel setDelegate:delegate]; | ||
| 520 | // [[NSFontManager sharedFontManager] setDelegate:delegate]; | ||
| 521 | // [[NSFontManager sharedFontManager] setTarget:delegate]; | ||
| 522 | // setFont(delegate, initial); | ||
| 523 | // | ||
| 524 | // // hack to get correct initial layout | ||
| 525 | // NSRect frameRect = [ourPanel frame]; | ||
| 526 | // frameRect.size.width += 1.0; | ||
| 527 | // [ourPanel setFrame:frameRect display:NO]; | ||
| 528 | // frameRect.size.width -= 1.0; | ||
| 529 | // frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; | ||
| 530 | // [ourPanel setFrame:frameRect display:NO]; | ||
| 531 | // [ourPanel center]; | ||
| 532 | // | ||
| 533 | // [ourPanel setTitle:(NSString*)(CFStringRef)QCFString(title)]; | ||
| 534 | // | ||
| 535 | // if (priv) { | ||
| 536 | // switch (modality) { | ||
| 537 | // case Qt::WindowModal: | ||
| 538 | // if (parent) { | ||
| 539 | //#ifndef QT_MAC_USE_COCOA | ||
| 540 | // WindowRef hiwindowRef = qt_mac_window_for(parent); | ||
| 541 | // NSWindow *window = | ||
| 542 | // [[NSWindow alloc] initWithWindowRef:hiwindowRef]; | ||
| 543 | // // Cocoa docs say I should retain the Carbon ref. | ||
| 544 | // CFRetain(hiwindowRef); | ||
| 545 | //#else | ||
| 546 | // NSWindow *window = qt_mac_window_for(parent); | ||
| 547 | //#endif | ||
| 548 | // [NSApp beginSheet:ourPanel | ||
| 549 | // modalForWindow:window | ||
| 550 | // modalDelegate:0 | ||
| 551 | // didEndSelector:0 | ||
| 552 | // contextInfo:0]; | ||
| 553 | //#ifndef QT_MAC_USE_COCOA | ||
| 554 | // [window release]; | ||
| 555 | //#endif | ||
| 556 | // break; | ||
| 557 | // } | ||
| 558 | // // fallthrough | ||
| 559 | // case Qt::ApplicationModal: | ||
| 560 | // [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; | ||
| 561 | // break; | ||
| 562 | // default: | ||
| 563 | // [ourPanel makeKeyAndOrderFront:ourPanel]; | ||
| 564 | // } | ||
| 565 | // } | ||
| 566 | // | ||
| 567 | // return delegate; | ||
| 568 | //} | ||
| 569 | // | ||
| 570 | //void QFontDialogPrivate::closeCocoaFontPanel(void *delegate) | ||
| 571 | //{ | ||
| 572 | // QMacCocoaAutoReleasePool pool; | ||
| 573 | // QCocoaFontPanelDelegate *theDelegate = static_cast<QCocoaFontPanelDelegate *>(delegate); | ||
| 574 | // NSWindow *ourPanel = [theDelegate actualPanel]; | ||
| 575 | // [ourPanel close]; | ||
| 576 | // [theDelegate cleanUpAfterMyself]; | ||
| 577 | // [theDelegate autorelease]; | ||
| 578 | //} | ||
| 579 | // | ||
| 580 | //QFont QFontDialogPrivate::execCocoaFontPanel(bool *ok, const QFont &initial, | ||
| 581 | // QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options) | ||
| 582 | //{ | ||
| 583 | // QMacCocoaAutoReleasePool pool; | ||
| 584 | // QCocoaFontPanelDelegate *delegate = | ||
| 585 | // static_cast<QCocoaFontPanelDelegate *>( | ||
| 586 | // openCocoaFontPanel(initial, parent, title, options)); | ||
| 587 | // NSWindow *ourPanel = [delegate actualPanel]; | ||
| 588 | // [ourPanel retain]; | ||
| 589 | // int rval = [NSApp runModalForWindow:ourPanel]; | ||
| 590 | // QFont font([delegate qtFont]); | ||
| 591 | // [ourPanel release]; | ||
| 592 | // [delegate cleanUpAfterMyself]; | ||
| 593 | // [delegate release]; | ||
| 594 | // bool isOk = ((options & QFontDialog::NoButtons) || rval == NSOKButton); | ||
| 595 | // if (ok) | ||
| 596 | // *ok = isOk; | ||
| 597 | // if (isOk) { | ||
| 598 | // return font; | ||
| 599 | // } else { | ||
| 600 | // return initial; | ||
| 601 | // } | ||
| 602 | //} | ||
| 603 | // | ||
| 604 | //void QFontDialogPrivate::setFont(void *delegate, const QFont &font) | ||
| 605 | //{ | ||
| 606 | // QMacCocoaAutoReleasePool pool; | ||
| 607 | // QFontEngine *fe = font.d->engineForScript(QUnicodeTables::Common); | ||
| 608 | // NSFontManager *mgr = [NSFontManager sharedFontManager]; | ||
| 609 | // NSFont *nsFont = 0; | ||
| 610 | // | ||
| 611 | //#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | ||
| 612 | // if (qstrcmp(fe->name(), "CoreText") == 0) { | ||
| 613 | // nsFont = reinterpret_cast<const NSFont *>(static_cast<QCoreTextFontEngineMulti *>(fe)->ctfont); | ||
| 614 | // } else | ||
| 615 | //#endif | ||
| 616 | // { | ||
| 617 | // int weight = 5; | ||
| 618 | // NSFontTraitMask mask = 0; | ||
| 619 | // if (font.style() == QFont::StyleItalic) { | ||
| 620 | // mask |= NSItalicFontMask; | ||
| 621 | // } | ||
| 622 | // if (font.weight() == QFont::Bold) { | ||
| 623 | // weight = 9; | ||
| 624 | // mask |= NSBoldFontMask; | ||
| 625 | // } | ||
| 626 | // | ||
| 627 | // NSFontManager *mgr = [NSFontManager sharedFontManager]; | ||
| 628 | // nsFont = [mgr fontWithFamily:qt_mac_QStringToNSString(font.family()) | ||
| 629 | // traits:mask | ||
| 630 | // weight:weight | ||
| 631 | // size:QFontInfo(font).pointSize()]; | ||
| 632 | // } | ||
| 633 | // | ||
| 634 | // [mgr setSelectedFont:nsFont isMultiple:NO]; | ||
| 635 | // [static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font]; | ||
| 636 | //} | ||
| 637 | |||
| 638 | QT_END_NAMESPACE | ||
| 639 | |||
| 640 | #endif |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include <qdialogbuttonbox.h> | ||
| 43 | #if defined(Q_WS_MAC) | ||
| 44 | #include <private/qt_mac_p.h> | ||
| 45 | #import <AppKit/AppKit.h> | ||
| 46 | #import <Foundation/Foundation.h> | ||
| 47 | #import <objc/objc-class.h> | ||
| 48 | |||
| 49 | QT_BEGIN_NAMESPACE | ||
| 50 | static QWidget *currentWindow = 0; | ||
| 51 | QT_END_NAMESPACE | ||
| 52 | |||
| 53 | QT_USE_NAMESPACE | ||
| 54 | // | ||
| 55 | //@class QNSPanelProxy; | ||
| 56 | // | ||
| 57 | //@interface QNSPanelProxy : NSWindow { | ||
| 58 | //} | ||
| 59 | //- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 60 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation; | ||
| 61 | //- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 62 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen; | ||
| 63 | //- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 64 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation; | ||
| 65 | //- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 66 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen; | ||
| 67 | //@end | ||
| 68 | // | ||
| 69 | //@implementation QNSPanelProxy | ||
| 70 | //- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 71 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation | ||
| 72 | //{ | ||
| 73 | // // remove evil flag | ||
| 74 | // windowStyle &= ~NSUtilityWindowMask; | ||
| 75 | // self = [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle | ||
| 76 | // backing:bufferingType defer:deferCreation]; | ||
| 77 | // return self; | ||
| 78 | //} | ||
| 79 | // | ||
| 80 | //- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 81 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen | ||
| 82 | //{ | ||
| 83 | // // remove evil flag | ||
| 84 | // windowStyle &= ~NSUtilityWindowMask; | ||
| 85 | // return [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle | ||
| 86 | // backing:bufferingType defer:deferCreation screen:screen]; | ||
| 87 | //} | ||
| 88 | // | ||
| 89 | //- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 90 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation | ||
| 91 | //{ | ||
| 92 | // Q_UNUSED(contentRect); | ||
| 93 | // Q_UNUSED(windowStyle); | ||
| 94 | // Q_UNUSED(bufferingType); | ||
| 95 | // Q_UNUSED(deferCreation); | ||
| 96 | // return nil; | ||
| 97 | //} | ||
| 98 | // | ||
| 99 | //- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle | ||
| 100 | // backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen | ||
| 101 | //{ | ||
| 102 | // Q_UNUSED(contentRect); | ||
| 103 | // Q_UNUSED(windowStyle); | ||
| 104 | // Q_UNUSED(bufferingType); | ||
| 105 | // Q_UNUSED(deferCreation); | ||
| 106 | // Q_UNUSED(screen); | ||
| 107 | // return nil; | ||
| 108 | //} | ||
| 109 | //@end | ||
| 110 | // | ||
| 111 | //@class QNSWindowProxy; | ||
| 112 | // | ||
| 113 | //@interface QNSWindowProxy : NSWindow { | ||
| 114 | //} | ||
| 115 | //- (void)setTitle:(NSString *)title; | ||
| 116 | //- (void)qt_fakeSetTitle:(NSString *)title; | ||
| 117 | //@end | ||
| 118 | // | ||
| 119 | //@implementation QNSWindowProxy | ||
| 120 | //- (void)setTitle:(NSString *)title | ||
| 121 | //{ | ||
| 122 | // QCFString cftitle(currentWindow->windowTitle()); | ||
| 123 | // | ||
| 124 | // // evil reverse engineering | ||
| 125 | // if ([title isEqualToString:@"Print"] | ||
| 126 | // || [title isEqualToString:@"Page Setup"] | ||
| 127 | // || [[self className] isEqualToString:@"PMPrintingWindow"]) | ||
| 128 | // title = (NSString *)(static_cast<CFStringRef>(cftitle)); | ||
| 129 | // return [self qt_fakeSetTitle:title]; | ||
| 130 | //} | ||
| 131 | // | ||
| 132 | //- (void)qt_fakeSetTitle:(NSString *)title | ||
| 133 | //{ | ||
| 134 | // Q_UNUSED(title); | ||
| 135 | //} | ||
| 136 | //@end | ||
| 137 | // | ||
| 138 | //QT_BEGIN_NAMESPACE | ||
| 139 | // | ||
| 140 | //void macStartIntercept(SEL originalSel, SEL fakeSel, Class baseClass, Class proxyClass) | ||
| 141 | //{ | ||
| 142 | //#ifndef QT_MAC_USE_COCOA | ||
| 143 | // if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) | ||
| 144 | //#endif | ||
| 145 | // { | ||
| 146 | //#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | ||
| 147 | // // The following code replaces the _implementation_ for the selector we want to hack | ||
| 148 | // // (originalSel) with the implementation found in proxyClass. Then it creates | ||
| 149 | // // a new 'backup' method inside baseClass containing the old, original, | ||
| 150 | // // implementation (fakeSel). You can let the proxy implementation of originalSel | ||
| 151 | // // call fakeSel if needed (similar approach to calling a super class implementation). | ||
| 152 | // // fakeSel must also be implemented in proxyClass, as the signature is used | ||
| 153 | // // as template for the method one we add into baseClass. | ||
| 154 | // // NB: You will typically never create any instances of proxyClass; we use it | ||
| 155 | // // only for stealing its contents and put it into baseClass. | ||
| 156 | // Method originalMethod = class_getInstanceMethod(baseClass, originalSel); | ||
| 157 | // Method newMethod = class_getInstanceMethod(proxyClass, originalSel); | ||
| 158 | // Method fakeMethod = class_getInstanceMethod(proxyClass, fakeSel); | ||
| 159 | // | ||
| 160 | // IMP originalImp = method_setImplementation(originalMethod, method_getImplementation(newMethod)); | ||
| 161 | // class_addMethod(baseClass, fakeSel, originalImp, method_getTypeEncoding(fakeMethod)); | ||
| 162 | //#endif | ||
| 163 | // } | ||
| 164 | //} | ||
| 165 | // | ||
| 166 | //void macStopIntercept(SEL originalSel, SEL fakeSel, Class baseClass, Class /* proxyClass */) | ||
| 167 | //{ | ||
| 168 | //#ifndef QT_MAC_USE_COCOA | ||
| 169 | // if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) | ||
| 170 | //#endif | ||
| 171 | // { | ||
| 172 | //#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | ||
| 173 | // Method originalMethod = class_getInstanceMethod(baseClass, originalSel); | ||
| 174 | // Method fakeMethodInBaseClass = class_getInstanceMethod(baseClass, fakeSel); | ||
| 175 | // method_setImplementation(originalMethod, method_getImplementation(fakeMethodInBaseClass)); | ||
| 176 | //#endif | ||
| 177 | // } | ||
| 178 | //} | ||
| 179 | // | ||
| 180 | ///* | ||
| 181 | // Intercept the NSColorPanel constructor if the shared | ||
| 182 | // color panel doesn't exist yet. What's going on here is | ||
| 183 | // quite wacky, because we want to override the NSPanel | ||
| 184 | // constructor and at the same time call the old NSPanel | ||
| 185 | // constructor. So what we do is we effectively rename the | ||
| 186 | // old NSPanel constructor qt_fakeInitWithContentRect:... | ||
| 187 | // and have the new one call the old one. | ||
| 188 | //*/ | ||
| 189 | //void macStartInterceptNSPanelCtor() | ||
| 190 | //{ | ||
| 191 | // macStartIntercept(@selector(initWithContentRect:styleMask:backing:defer:), | ||
| 192 | // @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:), | ||
| 193 | // [NSPanel class], [QNSPanelProxy class]); | ||
| 194 | // macStartIntercept(@selector(initWithContentRect:styleMask:backing:defer:screen:), | ||
| 195 | // @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:), | ||
| 196 | // [NSPanel class], [QNSPanelProxy class]); | ||
| 197 | //} | ||
| 198 | // | ||
| 199 | ///* | ||
| 200 | // Restore things as they were. | ||
| 201 | //*/ | ||
| 202 | //void macStopInterceptNSPanelCtor() | ||
| 203 | //{ | ||
| 204 | // macStopIntercept(@selector(initWithContentRect:styleMask:backing:defer:screen:), | ||
| 205 | // @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:), | ||
| 206 | // [NSPanel class], [QNSPanelProxy class]); | ||
| 207 | // macStopIntercept(@selector(initWithContentRect:styleMask:backing:defer:), | ||
| 208 | // @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:), | ||
| 209 | // [NSPanel class], [QNSPanelProxy class]); | ||
| 210 | //} | ||
| 211 | // | ||
| 212 | ///* | ||
| 213 | // Intercept the NSPrintPanel and NSPageLayout setTitle: calls. The | ||
| 214 | // hack is similar as for NSColorPanel above. | ||
| 215 | //*/ | ||
| 216 | //void macStartInterceptWindowTitle(QWidget *window) | ||
| 217 | //{ | ||
| 218 | // currentWindow = window; | ||
| 219 | // macStartIntercept(@selector(setTitle:), @selector(qt_fakeSetTitle:), | ||
| 220 | // [NSWindow class], [QNSWindowProxy class]); | ||
| 221 | //} | ||
| 222 | // | ||
| 223 | ///* | ||
| 224 | // Restore things as they were. | ||
| 225 | //*/ | ||
| 226 | //void macStopInterceptWindowTitle() | ||
| 227 | //{ | ||
| 228 | // currentWindow = 0; | ||
| 229 | // macStopIntercept(@selector(setTitle:), @selector(qt_fakeSetTitle:), | ||
| 230 | // [NSWindow class], [QNSWindowProxy class]); | ||
| 231 | //} | ||
| 232 | // | ||
| 233 | ///* | ||
| 234 | // Doesn't really belong in here. | ||
| 235 | //*/ | ||
| 236 | //NSButton *macCreateButton(const char *text, NSView *superview) | ||
| 237 | //{ | ||
| 238 | // static const NSRect buttonFrameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; | ||
| 239 | // | ||
| 240 | // NSButton *button = [[NSButton alloc] initWithFrame:buttonFrameRect]; | ||
| 241 | // [button setButtonType:NSMomentaryLightButton]; | ||
| 242 | // [button setBezelStyle:NSRoundedBezelStyle]; | ||
| 243 | // [button setTitle:(NSString*)(CFStringRef)QCFString(QDialogButtonBox::tr(text) | ||
| 244 | // .remove(QLatin1Char('&')))]; | ||
| 245 | // [[button cell] setFont:[NSFont systemFontOfSize: | ||
| 246 | // [NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; | ||
| 247 | // [superview addSubview:button]; | ||
| 248 | // return button; | ||
| 249 | //} | ||
| 250 | |||
| 251 | QT_END_NAMESPACE | ||
| 252 | |||
| 253 | #endif |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qpagesetupdialog.h" | ||
| 43 | |||
| 44 | #include <qhash.h> | ||
| 45 | #include <private/qapplication_p.h> | ||
| 46 | #include <private/qprintengine_iphone_p.h> | ||
| 47 | #include <private/qabstractpagesetupdialog_p.h> | ||
| 48 | |||
| 49 | #ifndef QT_NO_PRINTDIALOG | ||
| 50 | |||
| 51 | QT_USE_NAMESPACE | ||
| 52 | // | ||
| 53 | //@class QCocoaPageLayoutDelegate; | ||
| 54 | // | ||
| 55 | //@interface QCocoaPageLayoutDelegate : NSObject { | ||
| 56 | // QMacPrintEnginePrivate *pe; | ||
| 57 | //} | ||
| 58 | //- (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine; | ||
| 59 | //- (void)pageLayoutDidEnd:(NSPageLayout *)pageLayout | ||
| 60 | // returnCode:(int)returnCode contextInfo:(void *)contextInfo; | ||
| 61 | //@end | ||
| 62 | // | ||
| 63 | //@implementation QCocoaPageLayoutDelegate | ||
| 64 | //- (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine; | ||
| 65 | //{ | ||
| 66 | // self = [super init]; | ||
| 67 | // if (self) { | ||
| 68 | // pe = printEngine; | ||
| 69 | // } | ||
| 70 | // return self; | ||
| 71 | // | ||
| 72 | //} | ||
| 73 | //- (void)pageLayoutDidEnd:(NSPageLayout *)pageLayout | ||
| 74 | // returnCode:(int)returnCode contextInfo:(void *)contextInfo | ||
| 75 | //{ | ||
| 76 | // Q_UNUSED(pageLayout); | ||
| 77 | // QPageSetupDialog *dialog = static_cast<QPageSetupDialog *>(contextInfo); | ||
| 78 | // if (returnCode == NSOKButton) { | ||
| 79 | // PMRect paperRect; | ||
| 80 | // PMGetUnadjustedPaperRect(pe->format, &paperRect); | ||
| 81 | // pe->customSize = QSizeF(paperRect.right - paperRect.left, | ||
| 82 | // paperRect.bottom - paperRect.top); | ||
| 83 | // } | ||
| 84 | // dialog->done((returnCode == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); | ||
| 85 | //} | ||
| 86 | //@end | ||
| 87 | // | ||
| 88 | //QT_BEGIN_NAMESPACE | ||
| 89 | // | ||
| 90 | //extern void macStartInterceptWindowTitle(QWidget *window); | ||
| 91 | //extern void macStopInterceptWindowTitle(); | ||
| 92 | |||
| 93 | class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate | ||
| 94 | { | ||
| 95 | Q_DECLARE_PUBLIC(QPageSetupDialog) | ||
| 96 | |||
| 97 | public: | ||
| 98 | // QPageSetupDialogPrivate() : ep(0) | ||
| 99 | //#ifndef QT_MAC_USE_COCOA | ||
| 100 | // ,upp(0) | ||
| 101 | //#else | ||
| 102 | // ,pageLayout(0) | ||
| 103 | //#endif | ||
| 104 | // {} | ||
| 105 | // | ||
| 106 | // ~QPageSetupDialogPrivate() { | ||
| 107 | //#ifndef QT_MAC_USE_COCOA | ||
| 108 | // if (upp) { | ||
| 109 | // DisposePMSheetDoneUPP(upp); | ||
| 110 | // upp = 0; | ||
| 111 | // } | ||
| 112 | // QHash<PMPrintSession, QPageSetupDialogPrivate *>::iterator it = sheetCallbackMap.begin(); | ||
| 113 | // while (it != sheetCallbackMap.end()) { | ||
| 114 | // if (it.value() == this) { | ||
| 115 | // it = sheetCallbackMap.erase(it); | ||
| 116 | // } else { | ||
| 117 | // ++it; | ||
| 118 | // } | ||
| 119 | // } | ||
| 120 | //#endif | ||
| 121 | // } | ||
| 122 | // | ||
| 123 | //#ifndef QT_MAC_USE_COCOA | ||
| 124 | // void openCarbonPageLayout(Qt::WindowModality modality); | ||
| 125 | // void closeCarbonPageLayout(); | ||
| 126 | // static void pageSetupDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) { | ||
| 127 | // QPageSetupDialogPrivate *priv = sheetCallbackMap.value(printSession); | ||
| 128 | // if (!priv) { | ||
| 129 | // qWarning("%s:%d: QPageSetupDialog::exec: Could not retrieve data structure, " | ||
| 130 | // "you most likely now have an infinite modal loop", __FILE__, __LINE__); | ||
| 131 | // return; | ||
| 132 | // } | ||
| 133 | // priv->q_func()->done(accepted ? QDialog::Accepted : QDialog::Rejected); | ||
| 134 | // } | ||
| 135 | //#else | ||
| 136 | // void openCocoaPageLayout(Qt::WindowModality modality); | ||
| 137 | // void closeCocoaPageLayout(); | ||
| 138 | //#endif | ||
| 139 | // | ||
| 140 | // QMacPrintEnginePrivate *ep; | ||
| 141 | //#ifndef QT_MAC_USE_COCOA | ||
| 142 | // PMSheetDoneUPP upp; | ||
| 143 | // static QHash<PMPrintSession, QPageSetupDialogPrivate*> sheetCallbackMap; | ||
| 144 | //#else | ||
| 145 | // NSPageLayout *pageLayout; | ||
| 146 | //#endif | ||
| 147 | }; | ||
| 148 | |||
| 149 | //#ifndef QT_MAC_USE_COCOA | ||
| 150 | //QHash<PMPrintSession, QPageSetupDialogPrivate*> QPageSetupDialogPrivate::sheetCallbackMap; | ||
| 151 | //void QPageSetupDialogPrivate::openCarbonPageLayout(Qt::WindowModality modality) | ||
| 152 | //{ | ||
| 153 | // Q_Q(QPageSetupDialog); | ||
| 154 | // // If someone is reusing a QPrinter object, the end released all our old | ||
| 155 | // // information. In this case, we must reinitialize. | ||
| 156 | // if (ep->session == 0) | ||
| 157 | // ep->initialize(); | ||
| 158 | // | ||
| 159 | // sheetCallbackMap.insert(ep->session, this); | ||
| 160 | // if (modality == Qt::ApplicationModal) { | ||
| 161 | // QWidget modal_widg(0, Qt::Window); | ||
| 162 | // modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg")); | ||
| 163 | // modal_widg.createWinId(); | ||
| 164 | // QApplicationPrivate::enterModal(&modal_widg); | ||
| 165 | // QApplicationPrivate::native_modal_dialog_active = true; | ||
| 166 | // Boolean accepted; | ||
| 167 | // PMSessionPageSetupDialog(ep->session, ep->format, &accepted); | ||
| 168 | // QApplicationPrivate::leaveModal(&modal_widg); | ||
| 169 | // QApplicationPrivate::native_modal_dialog_active = false; | ||
| 170 | // pageSetupDialogSheetDoneCallback(ep->session, 0, accepted); | ||
| 171 | // } else { | ||
| 172 | // // Window Modal means that we use a sheet at the moment, there's no other way to do it correctly. | ||
| 173 | // if (!upp) | ||
| 174 | // upp = NewPMSheetDoneUPP(QPageSetupDialogPrivate::pageSetupDialogSheetDoneCallback); | ||
| 175 | // PMSessionUseSheets(ep->session, qt_mac_window_for(q->parentWidget()), upp); | ||
| 176 | // Boolean unused; | ||
| 177 | // PMSessionPageSetupDialog(ep->session, ep->format, &unused); | ||
| 178 | // } | ||
| 179 | //} | ||
| 180 | // | ||
| 181 | //void QPageSetupDialogPrivate::closeCarbonPageLayout() | ||
| 182 | //{ | ||
| 183 | // // if the margins have changed, we have to use the margins from the new | ||
| 184 | // // PMFormat object | ||
| 185 | // if (q_func()->result() == QDialog::Accepted) { | ||
| 186 | // PMPaper paper; | ||
| 187 | // PMPaperMargins margins; | ||
| 188 | // PMGetPageFormatPaper(ep->format, &paper); | ||
| 189 | // PMPaperGetMargins(paper, &margins); | ||
| 190 | // ep->leftMargin = margins.left; | ||
| 191 | // ep->topMargin = margins.top; | ||
| 192 | // ep->rightMargin = margins.right; | ||
| 193 | // ep->bottomMargin = margins.bottom; | ||
| 194 | // | ||
| 195 | // PMRect paperRect; | ||
| 196 | // PMGetUnadjustedPaperRect(ep->format, &paperRect); | ||
| 197 | // ep->customSize = QSizeF(paperRect.right - paperRect.left, | ||
| 198 | // paperRect.bottom - paperRect.top); | ||
| 199 | // } | ||
| 200 | // sheetCallbackMap.remove(ep->session); | ||
| 201 | //} | ||
| 202 | //#else | ||
| 203 | //void QPageSetupDialogPrivate::openCocoaPageLayout(Qt::WindowModality modality) | ||
| 204 | //{ | ||
| 205 | // Q_Q(QPageSetupDialog); | ||
| 206 | // | ||
| 207 | // // If someone is reusing a QPrinter object, the end released all our old | ||
| 208 | // // information. In this case, we must reinitialize. | ||
| 209 | // if (ep->session == 0) | ||
| 210 | // ep->initialize(); | ||
| 211 | // | ||
| 212 | // macStartInterceptWindowTitle(q); | ||
| 213 | // pageLayout = [NSPageLayout pageLayout]; | ||
| 214 | // // Keep a copy to this since we plan on using it for a bit. | ||
| 215 | // [pageLayout retain]; | ||
| 216 | // QCocoaPageLayoutDelegate *delegate = [[QCocoaPageLayoutDelegate alloc] initWithMacPrintEngine:ep]; | ||
| 217 | // | ||
| 218 | // if (modality == Qt::ApplicationModal) { | ||
| 219 | // int rval = [pageLayout runModalWithPrintInfo:ep->printInfo]; | ||
| 220 | // [delegate pageLayoutDidEnd:pageLayout returnCode:rval contextInfo:q]; | ||
| 221 | // } else { | ||
| 222 | // Q_ASSERT(q->parentWidget()); | ||
| 223 | // [pageLayout beginSheetWithPrintInfo:ep->printInfo | ||
| 224 | // modalForWindow:qt_mac_window_for(q->parentWidget()) | ||
| 225 | // delegate:delegate | ||
| 226 | // didEndSelector:@selector(pageLayoutDidEnd:returnCode:contextInfo:) | ||
| 227 | // contextInfo:q]; | ||
| 228 | // } | ||
| 229 | // | ||
| 230 | // macStopInterceptWindowTitle(); | ||
| 231 | //} | ||
| 232 | // | ||
| 233 | //void QPageSetupDialogPrivate::closeCocoaPageLayout() | ||
| 234 | //{ | ||
| 235 | // [pageLayout release]; | ||
| 236 | // pageLayout = 0; | ||
| 237 | //} | ||
| 238 | //#endif | ||
| 239 | |||
| 240 | QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent) | ||
| 241 | : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent) | ||
| 242 | { | ||
| 243 | // Q_D(QPageSetupDialog); | ||
| 244 | // d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func(); | ||
| 245 | } | ||
| 246 | |||
| 247 | QPageSetupDialog::QPageSetupDialog(QWidget *parent) | ||
| 248 | : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), 0, parent) | ||
| 249 | { | ||
| 250 | // Q_D(QPageSetupDialog); | ||
| 251 | // d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func(); | ||
| 252 | } | ||
| 253 | |||
| 254 | //void QPageSetupDialog::setVisible(bool visible) | ||
| 255 | //{ | ||
| 256 | // Q_D(QPageSetupDialog); | ||
| 257 | // | ||
| 258 | // if (d->printer->outputFormat() != QPrinter::NativeFormat) | ||
| 259 | // return; | ||
| 260 | // | ||
| 261 | //#ifndef QT_MAC_USE_COCOA | ||
| 262 | // bool isCurrentlyVisible = d->sheetCallbackMap.contains(d->ep->session); | ||
| 263 | //#else | ||
| 264 | // bool isCurrentlyVisible = (d->pageLayout != 0); | ||
| 265 | //#endif | ||
| 266 | // if (!visible == !isCurrentlyVisible) | ||
| 267 | // return; | ||
| 268 | // | ||
| 269 | // if (visible) { | ||
| 270 | //#ifndef QT_MAC_USE_COCOA | ||
| 271 | // d->openCarbonPageLayout(parentWidget() ? Qt::WindowModal | ||
| 272 | // : Qt::ApplicationModal); | ||
| 273 | //#else | ||
| 274 | // d->openCocoaPageLayout(parentWidget() ? Qt::WindowModal | ||
| 275 | // : Qt::ApplicationModal); | ||
| 276 | //#endif | ||
| 277 | // return; | ||
| 278 | // } else { | ||
| 279 | //#ifndef QT_MAC_USE_COCOA | ||
| 280 | // d->closeCarbonPageLayout(); | ||
| 281 | //#else | ||
| 282 | // if (d->pageLayout) { | ||
| 283 | // d->closeCocoaPageLayout(); | ||
| 284 | // return; | ||
| 285 | // } | ||
| 286 | //#endif | ||
| 287 | // } | ||
| 288 | //} | ||
| 289 | |||
| 290 | int QPageSetupDialog::exec() | ||
| 291 | { | ||
| 292 | Q_D(QPageSetupDialog); | ||
| 293 | |||
| 294 | // if (d->printer->outputFormat() != QPrinter::NativeFormat) | ||
| 295 | // return Rejected; | ||
| 296 | // | ||
| 297 | //#ifndef QT_MAC_USE_COCOA | ||
| 298 | // d->openCarbonPageLayout(Qt::ApplicationModal); | ||
| 299 | // d->closeCarbonPageLayout(); | ||
| 300 | //#else | ||
| 301 | // QMacCocoaAutoReleasePool pool; | ||
| 302 | // d->openCocoaPageLayout(Qt::ApplicationModal); | ||
| 303 | // d->closeCocoaPageLayout(); | ||
| 304 | //#endif | ||
| 305 | // return result(); | ||
| 306 | return 0; | ||
| 307 | } | ||
| 308 | |||
| 309 | QT_END_NAMESPACE | ||
| 310 | |||
| 311 | #endif QT_NO_PRINTDIALOG |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #ifndef QT_NO_PRINTDIALOG | ||
| 43 | |||
| 44 | #include <private/qt_iphone_p.h> | ||
| 45 | |||
| 46 | #include <qhash.h> | ||
| 47 | #include <qprintdialog.h> | ||
| 48 | #include <private/qapplication_p.h> | ||
| 49 | #include <private/qabstractprintdialog_p.h> | ||
| 50 | #include <private/qprintengine_iphone_p.h> | ||
| 51 | |||
| 52 | QT_BEGIN_NAMESPACE | ||
| 53 | |||
| 54 | class QPrintDialogPrivate : public QAbstractPrintDialogPrivate | ||
| 55 | { | ||
| 56 | Q_DECLARE_PUBLIC(QPrintDialog) | ||
| 57 | |||
| 58 | public: | ||
| 59 | QPrintDialogPrivate() // : ep(0), printPanel(0) | ||
| 60 | //#ifndef QT_MAC_USE_COCOA | ||
| 61 | // ,upp(0) | ||
| 62 | //#endif | ||
| 63 | {} | ||
| 64 | //#ifndef QT_MAC_USE_COCOA | ||
| 65 | // ~QPrintDialogPrivate() { | ||
| 66 | // if (upp) { | ||
| 67 | // DisposePMSheetDoneUPP(upp); | ||
| 68 | // upp = 0; | ||
| 69 | // } | ||
| 70 | // QHash<PMPrintSession, QPrintDialogPrivate *>::iterator it = sheetCallbackMap.begin(); | ||
| 71 | // while (it != sheetCallbackMap.end()) { | ||
| 72 | // if (it.value() == this) { | ||
| 73 | // it = sheetCallbackMap.erase(it); | ||
| 74 | // } else { | ||
| 75 | // ++it; | ||
| 76 | // } | ||
| 77 | // } | ||
| 78 | // } | ||
| 79 | //#endif | ||
| 80 | // | ||
| 81 | //#ifndef QT_MAC_USE_COCOA | ||
| 82 | // void openCarbonPrintPanel(Qt::WindowModality modality); | ||
| 83 | // void closeCarbonPrintPanel(); | ||
| 84 | // static void printDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) { | ||
| 85 | // QPrintDialogPrivate *priv = sheetCallbackMap.value(printSession); | ||
| 86 | // if (!priv) { | ||
| 87 | // qWarning("%s:%d: QPrintDialog::exec: Could not retrieve data structure, " | ||
| 88 | // "you most likely now have an infinite loop", __FILE__, __LINE__); | ||
| 89 | // return; | ||
| 90 | // } | ||
| 91 | // priv->q_func()->done(accepted ? QDialog::Accepted : QDialog::Rejected); | ||
| 92 | // priv->closeCarbonPrintPanel(); | ||
| 93 | // } | ||
| 94 | //#else | ||
| 95 | // void openCocoaPrintPanel(Qt::WindowModality modality); | ||
| 96 | // void closeCocoaPrintPanel(); | ||
| 97 | //#endif | ||
| 98 | void initBeforeRun(); | ||
| 99 | |||
| 100 | inline QPrintDialog *printDialog() { return q_func(); } | ||
| 101 | |||
| 102 | inline void _q_printToFileChanged(int) {} | ||
| 103 | inline void _q_rbPrintRangeToggled(bool) {} | ||
| 104 | inline void _q_printerChanged(int) {} | ||
| 105 | #ifndef QT_NO_MESSAGEBOX | ||
| 106 | inline void _q_checkFields() {} | ||
| 107 | #endif | ||
| 108 | inline void _q_chbPrintLastFirstToggled(bool) {} | ||
| 109 | inline void _q_paperSizeChanged(int) {} | ||
| 110 | inline void _q_btnBrowseClicked() {} | ||
| 111 | inline void _q_btnPropertiesClicked() {} | ||
| 112 | |||
| 113 | // QMacPrintEnginePrivate *ep; | ||
| 114 | // NSPrintPanel *printPanel; | ||
| 115 | //#ifndef QT_MAC_USE_COCOA | ||
| 116 | // PMSheetDoneUPP upp; | ||
| 117 | // static QHash<PMPrintSession, QPrintDialogPrivate *> sheetCallbackMap; | ||
| 118 | //#endif | ||
| 119 | }; | ||
| 120 | |||
| 121 | QT_END_NAMESPACE | ||
| 122 | |||
| 123 | QT_USE_NAMESPACE | ||
| 124 | |||
| 125 | //#ifdef QT_MAC_USE_COCOA | ||
| 126 | // | ||
| 127 | //@class QCocoaPrintPanelDelegate; | ||
| 128 | // | ||
| 129 | //@interface QCocoaPrintPanelDelegate : NSObject { | ||
| 130 | //} | ||
| 131 | //- (void)printPanelDidEnd:(NSPrintPanel *)printPanel | ||
| 132 | // returnCode:(int)returnCode contextInfo:(void *)contextInfo; | ||
| 133 | //@end | ||
| 134 | // | ||
| 135 | //@implementation QCocoaPrintPanelDelegate | ||
| 136 | //- (void)printPanelDidEnd:(NSPrintPanel *)printPanel | ||
| 137 | // returnCode:(int)returnCode contextInfo:(void *)contextInfo | ||
| 138 | //{ | ||
| 139 | // Q_UNUSED(printPanel); | ||
| 140 | // | ||
| 141 | // QPrintDialogPrivate *d = static_cast<QPrintDialogPrivate *>(contextInfo); | ||
| 142 | // QPrintDialog *dialog = d->printDialog(); | ||
| 143 | // // temporary hack to work around bug in deleteLater() in Qt/Mac Cocoa | ||
| 144 | //#if 1 | ||
| 145 | // bool deleteDialog = dialog->testAttribute(Qt::WA_DeleteOnClose); | ||
| 146 | // dialog->setAttribute(Qt::WA_DeleteOnClose, false); | ||
| 147 | //#endif | ||
| 148 | // | ||
| 149 | // if (returnCode == NSOKButton) { | ||
| 150 | // UInt32 frompage, topage; | ||
| 151 | // PMGetFirstPage(d->ep->settings, &frompage); | ||
| 152 | // PMGetLastPage(d->ep->settings, &topage); | ||
| 153 | // topage = qMin(UInt32(INT_MAX), topage); | ||
| 154 | // dialog->setFromTo(frompage, topage); | ||
| 155 | // | ||
| 156 | // // OK, I need to map these values back let's see | ||
| 157 | // // If from is 1 and to is INT_MAX, then print it all | ||
| 158 | // // (Apologies to the folks with more than INT_MAX pages) | ||
| 159 | // if (dialog->fromPage() == 1 && dialog->toPage() == INT_MAX) { | ||
| 160 | // dialog->setPrintRange(QPrintDialog::AllPages); | ||
| 161 | // dialog->setFromTo(0, 0); | ||
| 162 | // } else { | ||
| 163 | // dialog->setPrintRange(QPrintDialog::PageRange); // In a way a lie, but it shouldn't hurt. | ||
| 164 | // // Carbon hands us back a very large number here even for ALL, set it to max | ||
| 165 | // // in that case to follow the behavior of the other print dialogs. | ||
| 166 | // if (dialog->maxPage() < dialog->toPage()) | ||
| 167 | // dialog->setFromTo(dialog->fromPage(), dialog->maxPage()); | ||
| 168 | // } | ||
| 169 | // // Keep us in sync with file output | ||
| 170 | // PMDestinationType dest; | ||
| 171 | // | ||
| 172 | // // If the user selected print to file, the session has been | ||
| 173 | // // changed behind our back and our d->ep->session object is a | ||
| 174 | // // dangling pointer. Update it based on the "current" session | ||
| 175 | // d->ep->session = static_cast<PMPrintSession>([d->ep->printInfo PMPrintSession]); | ||
| 176 | // | ||
| 177 | // PMSessionGetDestinationType(d->ep->session, d->ep->settings, &dest); | ||
| 178 | // if (dest == kPMDestinationFile) { | ||
| 179 | // QCFType<CFURLRef> file; | ||
| 180 | // PMSessionCopyDestinationLocation(d->ep->session, d->ep->settings, &file); | ||
| 181 | // UInt8 localFile[2048]; // Assuming there's a POSIX file system here. | ||
| 182 | // CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile)); | ||
| 183 | // d->ep->outputFilename | ||
| 184 | // = QString::fromUtf8(reinterpret_cast<const char *>(localFile)); | ||
| 185 | // } else { | ||
| 186 | // // Keep output format. | ||
| 187 | // QPrinter::OutputFormat format; | ||
| 188 | // format = d->printer->outputFormat(); | ||
| 189 | // d->printer->setOutputFileName(QString()); | ||
| 190 | // d->printer->setOutputFormat(format); | ||
| 191 | // } | ||
| 192 | // } | ||
| 193 | // | ||
| 194 | // dialog->done((returnCode == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); | ||
| 195 | //#if 1 | ||
| 196 | // if (deleteDialog) | ||
| 197 | // delete dialog; | ||
| 198 | //#endif | ||
| 199 | //} | ||
| 200 | //@end | ||
| 201 | // | ||
| 202 | //#endif | ||
| 203 | // | ||
| 204 | //QT_BEGIN_NAMESPACE | ||
| 205 | // | ||
| 206 | //extern void macStartInterceptWindowTitle(QWidget *window); | ||
| 207 | //extern void macStopInterceptWindowTitle(); | ||
| 208 | // | ||
| 209 | // | ||
| 210 | //void QPrintDialogPrivate::initBeforeRun() | ||
| 211 | //{ | ||
| 212 | // Q_Q(QPrintDialog); | ||
| 213 | // // If someone is reusing a QPrinter object, the end released all our old | ||
| 214 | // // information. In this case, we must reinitialize. | ||
| 215 | // if (ep->session == 0) | ||
| 216 | // ep->initialize(); | ||
| 217 | // | ||
| 218 | // | ||
| 219 | // // It seems the only way that PM lets you use all is if the minimum | ||
| 220 | // // for the page range is 1. This _kind of_ makes sense if you think about | ||
| 221 | // // it. However, calling PMSetFirstPage() or PMSetLastPage() always enforces | ||
| 222 | // // the range. | ||
| 223 | // PMSetPageRange(ep->settings, q->minPage(), q->maxPage()); | ||
| 224 | // if (q->printRange() == QAbstractPrintDialog::PageRange) { | ||
| 225 | // PMSetFirstPage(ep->settings, q->fromPage(), false); | ||
| 226 | // PMSetLastPage(ep->settings, q->toPage(), false); | ||
| 227 | // } | ||
| 228 | //} | ||
| 229 | // | ||
| 230 | //#ifndef QT_MAC_USE_COCOA | ||
| 231 | //QHash<PMPrintSession, QPrintDialogPrivate *> QPrintDialogPrivate::sheetCallbackMap; | ||
| 232 | //void QPrintDialogPrivate::openCarbonPrintPanel(Qt::WindowModality modality) | ||
| 233 | //{ | ||
| 234 | // Q_Q(QPrintDialog); | ||
| 235 | // initBeforeRun(); | ||
| 236 | // sheetCallbackMap.insert(ep->session, this); | ||
| 237 | // if (modality == Qt::ApplicationModal) { | ||
| 238 | // QWidget modal_widg(0, Qt::Window); | ||
| 239 | // modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg")); | ||
| 240 | // modal_widg.createWinId(); | ||
| 241 | // QApplicationPrivate::enterModal(&modal_widg); | ||
| 242 | // QApplicationPrivate::native_modal_dialog_active = true; | ||
| 243 | // Boolean acceptStatus; | ||
| 244 | // PMSessionPrintDialog(ep->session, ep->settings, ep->format, &acceptStatus); | ||
| 245 | // QApplicationPrivate::leaveModal(&modal_widg); | ||
| 246 | // QApplicationPrivate::native_modal_dialog_active = false; | ||
| 247 | // printDialogSheetDoneCallback(ep->session, 0, acceptStatus); | ||
| 248 | // } else { | ||
| 249 | // // Window Modal means that we use a sheet at the moment, there's no other way to do it correctly. | ||
| 250 | // if (!upp) | ||
| 251 | // upp = NewPMSheetDoneUPP(QPrintDialogPrivate::printDialogSheetDoneCallback); | ||
| 252 | // PMSessionUseSheets(ep->session, qt_mac_window_for(q->parentWidget()), upp); | ||
| 253 | // QApplicationPrivate::native_modal_dialog_active = true; | ||
| 254 | // Boolean unused; | ||
| 255 | // PMSessionPrintDialog(ep->session, ep->settings, ep->format, &unused); | ||
| 256 | // } | ||
| 257 | //} | ||
| 258 | // | ||
| 259 | //void QPrintDialogPrivate::closeCarbonPrintPanel() | ||
| 260 | //{ | ||
| 261 | // Q_Q(QPrintDialog); | ||
| 262 | // QApplicationPrivate::native_modal_dialog_active = false; | ||
| 263 | // if (q->result() == QDialog::Accepted) { | ||
| 264 | // UInt32 frompage, topage; | ||
| 265 | // PMGetFirstPage(ep->settings, &frompage); | ||
| 266 | // PMGetLastPage(ep->settings, &topage); | ||
| 267 | // topage = qMin(UInt32(INT_MAX), topage); | ||
| 268 | // q->setFromTo(frompage, topage); | ||
| 269 | // | ||
| 270 | // // OK, I need to map these values back let's see | ||
| 271 | // // If from is 1 and to is INT_MAX, then print it all | ||
| 272 | // // (Apologies to the folks with more than INT_MAX pages) | ||
| 273 | // // ...that's a joke. | ||
| 274 | // if (q->fromPage() == 1 && q->toPage() == INT_MAX) { | ||
| 275 | // q->setPrintRange(QAbstractPrintDialog::AllPages); | ||
| 276 | // q->setFromTo(0,0); | ||
| 277 | // } else { | ||
| 278 | // q->setPrintRange(QAbstractPrintDialog::PageRange); // In a way a lie, but it shouldn't hurt. | ||
| 279 | // // Carbon hands us back a very large number here even for ALL, set it to max | ||
| 280 | // // in that case to follow the behavior of the other print dialogs. | ||
| 281 | // if (q->maxPage() < q->toPage()) | ||
| 282 | // q->setFromTo(q->fromPage(), q->maxPage()); | ||
| 283 | // } | ||
| 284 | // // Keep us in sync with file output | ||
| 285 | // PMDestinationType dest; | ||
| 286 | // PMSessionGetDestinationType(ep->session, ep->settings, &dest); | ||
| 287 | // if (dest == kPMDestinationFile) { | ||
| 288 | // QCFType<CFURLRef> file; | ||
| 289 | // PMSessionCopyDestinationLocation(ep->session, ep->settings, &file); | ||
| 290 | // UInt8 localFile[2048]; // Assuming there's a POSIX file system here. | ||
| 291 | // CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile)); | ||
| 292 | // ep->outputFilename = QString::fromUtf8(reinterpret_cast<const char *>(localFile)); | ||
| 293 | // } else { | ||
| 294 | // ep->outputFilename = QString(); | ||
| 295 | // } | ||
| 296 | // } | ||
| 297 | // sheetCallbackMap.remove(ep->session); | ||
| 298 | //} | ||
| 299 | //#else | ||
| 300 | //void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality) | ||
| 301 | //{ | ||
| 302 | // Q_Q(QPrintDialog); | ||
| 303 | // | ||
| 304 | // initBeforeRun(); | ||
| 305 | // | ||
| 306 | // QPrintDialog::PrintDialogOptions qtOptions = q->options(); | ||
| 307 | // NSPrintPanelOptions macOptions = NSPrintPanelShowsCopies; | ||
| 308 | // if (qtOptions & QPrintDialog::PrintPageRange) | ||
| 309 | // macOptions |= NSPrintPanelShowsPageRange; | ||
| 310 | // if (qtOptions & QPrintDialog::PrintShowPageSize) | ||
| 311 | // macOptions |= NSPrintPanelShowsPaperSize | NSPrintPanelShowsPageSetupAccessory | ||
| 312 | // | NSPrintPanelShowsOrientation; | ||
| 313 | // | ||
| 314 | // macStartInterceptWindowTitle(q); | ||
| 315 | // printPanel = [NSPrintPanel printPanel]; | ||
| 316 | // QCocoaPrintPanelDelegate *delegate = [[QCocoaPrintPanelDelegate alloc] init]; | ||
| 317 | // [printPanel setOptions:macOptions]; | ||
| 318 | // | ||
| 319 | // if (modality == Qt::ApplicationModal) { | ||
| 320 | // int rval = [printPanel runModalWithPrintInfo:ep->printInfo]; | ||
| 321 | // [delegate printPanelDidEnd:printPanel returnCode:rval contextInfo:this]; | ||
| 322 | // } else { | ||
| 323 | // Q_ASSERT(q->parentWidget()); | ||
| 324 | // NSWindow *windowRef = qt_mac_window_for(q->parentWidget()); | ||
| 325 | // [printPanel beginSheetWithPrintInfo:ep->printInfo | ||
| 326 | // modalForWindow:windowRef | ||
| 327 | // delegate:delegate | ||
| 328 | // didEndSelector:@selector(printPanelDidEnd:returnCode:contextInfo:) | ||
| 329 | // contextInfo:this]; | ||
| 330 | // } | ||
| 331 | // | ||
| 332 | // macStopInterceptWindowTitle(); | ||
| 333 | //} | ||
| 334 | // | ||
| 335 | //void QPrintDialogPrivate::closeCocoaPrintPanel() | ||
| 336 | //{ | ||
| 337 | // // ### | ||
| 338 | //} | ||
| 339 | //#endif | ||
| 340 | // | ||
| 341 | //static bool warnIfNotNative(QPrinter *printer) | ||
| 342 | //{ | ||
| 343 | // if (printer->outputFormat() != QPrinter::NativeFormat) { | ||
| 344 | // qWarning("QPrintDialog: Cannot be used on non-native printers"); | ||
| 345 | // return false; | ||
| 346 | // } | ||
| 347 | // return true; | ||
| 348 | //} | ||
| 349 | |||
| 350 | QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent) | ||
| 351 | : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent) | ||
| 352 | { | ||
| 353 | Q_D(QPrintDialog); | ||
| 354 | // if (!warnIfNotNative(d->printer)) | ||
| 355 | // return; | ||
| 356 | // d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func(); | ||
| 357 | } | ||
| 358 | |||
| 359 | QPrintDialog::QPrintDialog(QWidget *parent) | ||
| 360 | : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent) | ||
| 361 | { | ||
| 362 | Q_D(QPrintDialog); | ||
| 363 | // if (!warnIfNotNative(d->printer)) | ||
| 364 | // return; | ||
| 365 | // d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func(); | ||
| 366 | } | ||
| 367 | |||
| 368 | QPrintDialog::~QPrintDialog() | ||
| 369 | { | ||
| 370 | } | ||
| 371 | |||
| 372 | int QPrintDialog::exec() | ||
| 373 | { | ||
| 374 | Q_D(QPrintDialog); | ||
| 375 | // if (!warnIfNotNative(d->printer)) | ||
| 376 | // return QDialog::Rejected; | ||
| 377 | // | ||
| 378 | //#ifndef QT_MAC_USE_COCOA | ||
| 379 | // d->openCarbonPrintPanel(Qt::ApplicationModal); | ||
| 380 | //#else | ||
| 381 | // QMacCocoaAutoReleasePool pool; | ||
| 382 | // | ||
| 383 | // d->openCocoaPrintPanel(Qt::ApplicationModal); | ||
| 384 | // d->closeCocoaPrintPanel(); | ||
| 385 | //#endif | ||
| 386 | // return result(); | ||
| 387 | return 0; | ||
| 388 | } | ||
| 389 | |||
| 390 | //#ifdef QT3_SUPPORT | ||
| 391 | //QPrinter *QPrintDialog::printer() const | ||
| 392 | //{ | ||
| 393 | // Q_D(const QPrintDialog); | ||
| 394 | // return d->printer; | ||
| 395 | //} | ||
| 396 | //#endif | ||
| 397 | |||
| 398 | /*! | ||
| 399 | \reimp | ||
| 400 | */ | ||
| 401 | void QPrintDialog::setVisible(bool visible) | ||
| 402 | { | ||
| 403 | Q_D(QPrintDialog); | ||
| 404 | |||
| 405 | // bool isCurrentlyVisible = (d->printPanel != 0); | ||
| 406 | // | ||
| 407 | // if (!visible == !isCurrentlyVisible) | ||
| 408 | // return; | ||
| 409 | // | ||
| 410 | // if (d->printer->outputFormat() != QPrinter::NativeFormat) | ||
| 411 | // return; | ||
| 412 | // | ||
| 413 | // if (visible) { | ||
| 414 | //#ifndef QT_MAC_USE_COCOA | ||
| 415 | // d->openCarbonPrintPanel(parentWidget() ? Qt::WindowModal | ||
| 416 | // : Qt::ApplicationModal); | ||
| 417 | //#else | ||
| 418 | // d->openCocoaPrintPanel(parentWidget() ? Qt::WindowModal | ||
| 419 | // : Qt::ApplicationModal); | ||
| 420 | //#endif | ||
| 421 | // return; | ||
| 422 | // } else { | ||
| 423 | // if (d->printPanel) { | ||
| 424 | //#ifndef QT_MAC_USE_COCOA | ||
| 425 | // d->closeCarbonPrintPanel(); | ||
| 426 | //#else | ||
| 427 | // d->closeCocoaPrintPanel(); | ||
| 428 | //#endif | ||
| 429 | // return; | ||
| 430 | // } | ||
| 431 | // } | ||
| 432 | } | ||
| 433 | |||
| 434 | void QPrintDialog::accept() | ||
| 435 | { | ||
| 436 | } | ||
| 437 | |||
| 438 | QT_END_NAMESPACE | ||
| 439 | |||
| 440 | #include "moc_qprintdialog.cpp" | ||
| 441 | |||
| 442 | #endif // QT_NO_PRINTDIALOG |
src/gui/image/qpixmap.h
(21 / 0)
|   | |||
| 50 | 50 | #include <QtGui/qimage.h> | |
| 51 | 51 | #include <QtGui/qtransform.h> | |
| 52 | 52 | ||
| 53 | #ifdef Q_WS_IPHONE | ||
| 54 | #import <CoreGraphics/CoreGraphics.h> | ||
| 55 | #endif | ||
| 56 | |||
| 53 | 57 | QT_BEGIN_HEADER | |
| 54 | 58 | ||
| 55 | 59 | #if defined(Q_OS_SYMBIAN) | |
| … | … | ||
| 164 | 164 | static QPixmap fromMacCGImageRef(CGImageRef image); | |
| 165 | 165 | #endif | |
| 166 | 166 | ||
| 167 | #if defined(Q_WS_IPHONE) | ||
| 168 | CGImageRef toiPhoneCGImageRef() const; | ||
| 169 | static QPixmap fromiPhoneCGImageRef(CGImageRef image); | ||
| 170 | #endif | ||
| 171 | |||
| 167 | 172 | #if defined(Q_OS_SYMBIAN) | |
| 168 | 173 | CFbsBitmap *toSymbianCFbsBitmap() const; | |
| 169 | 174 | static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap); | |
| … | … | ||
| 202 | 202 | Qt::HANDLE macQDHandle() const; | |
| 203 | 203 | Qt::HANDLE macQDAlphaHandle() const; | |
| 204 | 204 | Qt::HANDLE macCGHandle() const; | |
| 205 | #elif defined(Q_WS_IPHONE) | ||
| 206 | Qt::HANDLE iphoneQDHandle() const; | ||
| 207 | Qt::HANDLE iphoneQDAlphaHandle() const; | ||
| 208 | Qt::HANDLE iphoneCGHandle() const; | ||
| 205 | 209 | #elif defined(Q_WS_X11) | |
| 206 | 210 | enum ShareMode { ImplicitlyShared, ExplicitlyShared }; | |
| 207 | 211 | ||
| … | … | ||
| 273 | 273 | friend quint32 *qt_mac_pixmap_get_base(const QPixmap*); | |
| 274 | 274 | friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*); | |
| 275 | 275 | #endif | |
| 276 | #ifdef Q_WS_IPHONE | ||
| 277 | friend CGContextRef qt_iphone_cg_context(const QPaintDevice*); | ||
| 278 | friend CGImageRef qt_iphone_create_imagemask(const QPixmap&, const QRectF&); | ||
| 279 | //friend IconRef qt_iphone_create_iconref(const QPixmap&); | ||
| 280 | friend quint32 *qt_iphone_pixmap_get_base(const QPixmap*); | ||
| 281 | friend int qt_iphone_pixmap_get_bytes_per_line(const QPixmap*); | ||
| 282 | #endif | ||
| 283 | |||
| 276 | 284 | friend class QPixmapData; | |
| 277 | 285 | friend class QX11PixmapData; | |
| 278 | 286 | friend class QMacPixmapData; |
src/gui/image/qpixmap_iphone.mm
(1194 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qpixmap.h" | ||
| 43 | #include "qimage.h" | ||
| 44 | #include "qapplication.h" | ||
| 45 | #include "qbitmap.h" | ||
| 46 | #include "qmatrix.h" | ||
| 47 | #include "qtransform.h" | ||
| 48 | #include "qlibrary.h" | ||
| 49 | #include "qvarlengtharray.h" | ||
| 50 | #include "qdebug.h" | ||
| 51 | #include <private/qdrawhelper_p.h> | ||
| 52 | #include <private/qpixmap_iphone_p.h> | ||
| 53 | #include <private/qpixmap_raster_p.h> | ||
| 54 | #include <private/qpaintengine_iphone_p.h> | ||
| 55 | #include <private/qt_iphone_p.h> | ||
| 56 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 57 | |||
| 58 | #include <limits.h> | ||
| 59 | #include <string.h> | ||
| 60 | |||
| 61 | #warning qpixmap_iphone_p not completed. | ||
| 62 | |||
| 63 | QT_BEGIN_NAMESPACE | ||
| 64 | |||
| 65 | /***************************************************************************** | ||
| 66 | Externals | ||
| 67 | *****************************************************************************/ | ||
| 68 | extern const uchar *qt_get_bitflip_array(); //qimage.cpp | ||
| 69 | //extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev); //qpaintdevice_mac.cpp | ||
| 70 | //extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp | ||
| 71 | //extern void qt_mac_dispose_rgn(RgnHandle r); //qregion_mac.cpp | ||
| 72 | //extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp | ||
| 73 | |||
| 74 | //static int qt_pixmap_serial = 0; | ||
| 75 | |||
| 76 | //Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix) | ||
| 77 | //{ | ||
| 78 | // return static_cast<QMacPixmapData*>(pix->data.data())->pixels; | ||
| 79 | //} | ||
| 80 | |||
| 81 | //Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix) | ||
| 82 | //{ | ||
| 83 | // return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow; | ||
| 84 | //} | ||
| 85 | |||
| 86 | //void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t) | ||
| 87 | //{ | ||
| 88 | // QMacPixmapData *pmdata = static_cast<QMacPixmapData *>(info); | ||
| 89 | // if (!pmdata) { | ||
| 90 | // free(const_cast<void *>(memoryToFree)); | ||
| 91 | // } else { | ||
| 92 | // if (QMacPixmapData::validDataPointers.contains(pmdata) == false) { | ||
| 93 | // free(const_cast<void *>(memoryToFree)); | ||
| 94 | // return; | ||
| 95 | // } | ||
| 96 | // if (pmdata->pixels == pmdata->pixelsToFree) { | ||
| 97 | // // something we aren't expecting, just free it. | ||
| 98 | // Q_ASSERT(memoryToFree != pmdata->pixelsToFree); | ||
| 99 | // free(const_cast<void *>(memoryToFree)); | ||
| 100 | // } else { | ||
| 101 | // free(pmdata->pixelsToFree); | ||
| 102 | // pmdata->pixelsToFree = static_cast<quint32 *>(const_cast<void *>(memoryToFree)); | ||
| 103 | // } | ||
| 104 | // pmdata->cg_dataBeingReleased = 0; | ||
| 105 | // } | ||
| 106 | //} | ||
| 107 | |||
| 108 | //CGImageRef qt_mac_image_to_cgimage(const QImage &image) | ||
| 109 | //{ | ||
| 110 | // int bitsPerColor = 8; | ||
| 111 | // int bitsPerPixel = 32; | ||
| 112 | // if (image.depth() == 1) { | ||
| 113 | // bitsPerColor = 1; | ||
| 114 | // bitsPerPixel = 1; | ||
| 115 | // } | ||
| 116 | // QCFType<CGDataProviderRef> provider = | ||
| 117 | // CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(), | ||
| 118 | // 0); | ||
| 119 | // | ||
| 120 | // uint cgflags = kCGImageAlphaPremultipliedFirst; | ||
| 121 | //#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version | ||
| 122 | // cgflags |= kCGBitmapByteOrder32Host; | ||
| 123 | //#endif | ||
| 124 | // | ||
| 125 | // CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel, | ||
| 126 | // image.bytesPerLine(), | ||
| 127 | // QCoreGraphicsPaintEngine::macGenericColorSpace(), | ||
| 128 | // cgflags, provider, | ||
| 129 | // 0, | ||
| 130 | // 0, | ||
| 131 | // kCGRenderingIntentDefault); | ||
| 132 | // | ||
| 133 | // return cgImage; | ||
| 134 | //} | ||
| 135 | |||
| 136 | /***************************************************************************** | ||
| 137 | QPixmap member functions | ||
| 138 | *****************************************************************************/ | ||
| 139 | |||
| 140 | //static inline QRgb qt_conv16ToRgb(ushort c) { | ||
| 141 | // static const int qt_rbits = (565/100); | ||
| 142 | // static const int qt_gbits = (565/10%10); | ||
| 143 | // static const int qt_bbits = (565%10); | ||
| 144 | // static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits); | ||
| 145 | // static const int qt_green_shift = qt_bbits-(8-qt_gbits); | ||
| 146 | // static const int qt_neg_blue_shift = 8-qt_bbits; | ||
| 147 | // static const int qt_blue_mask = (1<<qt_bbits)-1; | ||
| 148 | // static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-((1<<qt_bbits)-1); | ||
| 149 | // static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits)); | ||
| 150 | // | ||
| 151 | // const int r=(c & qt_red_mask); | ||
| 152 | // const int g=(c & qt_green_mask); | ||
| 153 | // const int b=(c & qt_blue_mask); | ||
| 154 | // const int tr = r >> qt_red_shift; | ||
| 155 | // const int tg = g >> qt_green_shift; | ||
| 156 | // const int tb = b << qt_neg_blue_shift; | ||
| 157 | // | ||
| 158 | // return qRgb(tr,tg,tb); | ||
| 159 | //} | ||
| 160 | |||
| 161 | //QSet<QMacPixmapData*> QMacPixmapData::validDataPointers; | ||
| 162 | |||
| 163 | QIPhonePixmapData::QIPhonePixmapData(PixelType type) | ||
| 164 | : QPixmapData(type, MacClass) //, has_alpha(0), has_mask(0), | ||
| 165 | // uninit(true), pixels(0), pixelsSize(0), pixelsToFree(0), | ||
| 166 | // bytesPerRow(0), cg_data(0), cg_dataBeingReleased(0), cg_mask(0), | ||
| 167 | // pengine(0) | ||
| 168 | { | ||
| 169 | } | ||
| 170 | |||
| 171 | //QPixmapData *QMacPixmapData::createCompatiblePixmapData() const | ||
| 172 | //{ | ||
| 173 | // return new QMacPixmapData(pixelType()); | ||
| 174 | //} | ||
| 175 | |||
| 176 | //#define BEST_BYTE_ALIGNMENT 16 | ||
| 177 | //#define COMPTUE_BEST_BYTES_PER_ROW(bpr) \ | ||
| 178 | // (((bpr) + (BEST_BYTE_ALIGNMENT - 1)) & ~(BEST_BYTE_ALIGNMENT - 1)) | ||
| 179 | // | ||
| 180 | void QIPhonePixmapData::resize(int width, int height) | ||
| 181 | { | ||
| 182 | // setSerialNumber(++qt_pixmap_serial); | ||
| 183 | // | ||
| 184 | // w = width; | ||
| 185 | // h = height; | ||
| 186 | // is_null = (w <= 0 || h <= 0); | ||
| 187 | // d = (pixelType() == BitmapType ? 1 : 32); | ||
| 188 | // bool make_null = w <= 0 || h <= 0; // create null pixmap | ||
| 189 | // if (make_null || d == 0) { | ||
| 190 | // w = 0; | ||
| 191 | // h = 0; | ||
| 192 | // is_null = true; | ||
| 193 | // d = 0; | ||
| 194 | // if (!make_null) | ||
| 195 | // qWarning("Qt: QPixmap: Invalid pixmap parameters"); | ||
| 196 | // return; | ||
| 197 | // } | ||
| 198 | // | ||
| 199 | // if (w < 1 || h < 1) | ||
| 200 | // return; | ||
| 201 | // | ||
| 202 | // //create the pixels | ||
| 203 | // bytesPerRow = w * sizeof(quint32); // Minimum bytes per row. | ||
| 204 | // | ||
| 205 | // // Quartz2D likes things as a multple of 16 (for now). | ||
| 206 | // bytesPerRow = COMPTUE_BEST_BYTES_PER_ROW(bytesPerRow); | ||
| 207 | // macCreatePixels(); | ||
| 208 | } | ||
| 209 | |||
| 210 | //#undef COMPUTE_BEST_BYTES_PER_ROW | ||
| 211 | |||
| 212 | void QIPhonePixmapData::fromImage(const QImage &img, | ||
| 213 | Qt::ImageConversionFlags flags) | ||
| 214 | { | ||
| 215 | // setSerialNumber(++qt_pixmap_serial); | ||
| 216 | // | ||
| 217 | // // the conversion code only handles format >= | ||
| 218 | // // Format_ARGB32_Premultiplied at the moment.. | ||
| 219 | // if (img.format() > QImage::Format_ARGB32_Premultiplied) { | ||
| 220 | // QImage image; | ||
| 221 | // if (img.hasAlphaChannel()) | ||
| 222 | // image = img.convertToFormat(QImage::Format_ARGB32_Premultiplied); | ||
| 223 | // else | ||
| 224 | // image = img.convertToFormat(QImage::Format_RGB32); | ||
| 225 | // fromImage(image, flags); | ||
| 226 | // return; | ||
| 227 | // } | ||
| 228 | // | ||
| 229 | // w = img.width(); | ||
| 230 | // h = img.height(); | ||
| 231 | // is_null = (w <= 0 || h <= 0); | ||
| 232 | // d = (pixelType() == BitmapType ? 1 : img.depth()); | ||
| 233 | // | ||
| 234 | // QImage image = img; | ||
| 235 | // int dd = QPixmap::defaultDepth(); | ||
| 236 | // bool force_mono = (dd == 1 || | ||
| 237 | // (flags & Qt::ColorMode_Mask)==Qt::MonoOnly); | ||
| 238 | // if (force_mono) { // must be monochrome | ||
| 239 | // if (d != 1) { | ||
| 240 | // image = image.convertToFormat(QImage::Format_MonoLSB, flags); // dither | ||
| 241 | // d = 1; | ||
| 242 | // } | ||
| 243 | // } else { // can be both | ||
| 244 | // bool conv8 = false; | ||
| 245 | // if(d > 8 && dd <= 8) { // convert to 8 bit | ||
| 246 | // if ((flags & Qt::DitherMode_Mask) == Qt::AutoDither) | ||
| 247 | // flags = (flags & ~Qt::DitherMode_Mask) | ||
| 248 | // | Qt::PreferDither; | ||
| 249 | // conv8 = true; | ||
| 250 | // } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) { | ||
| 251 | // conv8 = d == 1; // native depth wanted | ||
| 252 | // } else if (d == 1) { | ||
| 253 | // if (image.colorCount() == 2) { | ||
| 254 | // QRgb c0 = image.color(0); // Auto: convert to best | ||
| 255 | // QRgb c1 = image.color(1); | ||
| 256 | // conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255); | ||
| 257 | // } else { | ||
| 258 | // // eg. 1-color monochrome images (they do exist). | ||
| 259 | // conv8 = true; | ||
| 260 | // } | ||
| 261 | // } | ||
| 262 | // if (conv8) { | ||
| 263 | // image = image.convertToFormat(QImage::Format_Indexed8, flags); | ||
| 264 | // d = 8; | ||
| 265 | // } | ||
| 266 | // } | ||
| 267 | // | ||
| 268 | // if (image.depth()==1) { | ||
| 269 | // image.setColor(0, QColor(Qt::color0).rgba()); | ||
| 270 | // image.setColor(1, QColor(Qt::color1).rgba()); | ||
| 271 | // } | ||
| 272 | // | ||
| 273 | // if (d == 16 || d == 24) { | ||
| 274 | // image = image.convertToFormat(QImage::Format_RGB32, flags); | ||
| 275 | // fromImage(image, flags); | ||
| 276 | // return; | ||
| 277 | // } | ||
| 278 | // | ||
| 279 | // // different size or depth, make a new pixmap | ||
| 280 | // resize(w, h); | ||
| 281 | // | ||
| 282 | // quint32 *dptr = pixels, *drow; | ||
| 283 | // const uint dbpr = bytesPerRow; | ||
| 284 | // | ||
| 285 | // const QImage::Format sfmt = image.format(); | ||
| 286 | // const unsigned short sbpr = image.bytesPerLine(); | ||
| 287 | // | ||
| 288 | // // use const_cast to prevent a detach | ||
| 289 | // const uchar *sptr = const_cast<const QImage &>(image).bits(), *srow; | ||
| 290 | // | ||
| 291 | // for (int y = 0; y < h; ++y) { | ||
| 292 | // drow = dptr + (y * (dbpr / 4)); | ||
| 293 | // srow = sptr + (y * sbpr); | ||
| 294 | // switch(sfmt) { | ||
| 295 | // case QImage::Format_MonoLSB: | ||
| 296 | // case QImage::Format_Mono:{ | ||
| 297 | // for (int x = 0; x < w; ++x) { | ||
| 298 | // char one_bit = *(srow + (x / 8)); | ||
| 299 | // if (sfmt == QImage::Format_Mono) | ||
| 300 | // one_bit = one_bit >> (7 - (x % 8)); | ||
| 301 | // else | ||
| 302 | // one_bit = one_bit >> (x % 8); | ||
| 303 | // if ((one_bit & 0x01)) | ||
| 304 | // *(drow+x) = 0xFF000000; | ||
| 305 | // else | ||
| 306 | // *(drow+x) = 0xFFFFFFFF; | ||
| 307 | // } | ||
| 308 | // break; | ||
| 309 | // } | ||
| 310 | // case QImage::Format_Indexed8: { | ||
| 311 | // int numColors = image.numColors(); | ||
| 312 | // if (numColors > 0) { | ||
| 313 | // for (int x = 0; x < w; ++x) { | ||
| 314 | // int index = *(srow + x); | ||
| 315 | // *(drow+x) = PREMUL(image.color(qMin(index, numColors))); | ||
| 316 | // } | ||
| 317 | // } | ||
| 318 | // } break; | ||
| 319 | // case QImage::Format_RGB32: | ||
| 320 | // for (int x = 0; x < w; ++x) | ||
| 321 | // *(drow+x) = *(((quint32*)srow) + x) | 0xFF000000; | ||
| 322 | // break; | ||
| 323 | // case QImage::Format_ARGB32: | ||
| 324 | // case QImage::Format_ARGB32_Premultiplied: | ||
| 325 | // for (int x = 0; x < w; ++x) { | ||
| 326 | // if(sfmt == QImage::Format_RGB32) | ||
| 327 | // *(drow+x) = 0xFF000000 | (*(((quint32*)srow) + x) & 0x00FFFFFF); | ||
| 328 | // else if(sfmt == QImage::Format_ARGB32_Premultiplied) | ||
| 329 | // *(drow+x) = *(((quint32*)srow) + x); | ||
| 330 | // else | ||
| 331 | // *(drow+x) = PREMUL(*(((quint32*)srow) + x)); | ||
| 332 | // } | ||
| 333 | // break; | ||
| 334 | // default: | ||
| 335 | // qWarning("Qt: internal: Oops: Forgot a format [%d] %s:%d", sfmt, | ||
| 336 | // __FILE__, __LINE__); | ||
| 337 | // break; | ||
| 338 | // } | ||
| 339 | // } | ||
| 340 | // if (sfmt != QImage::Format_RGB32) { //setup the alpha | ||
| 341 | // bool alphamap = image.depth() == 32; | ||
| 342 | // if (sfmt == QImage::Format_Indexed8) { | ||
| 343 | // const QVector<QRgb> rgb = image.colorTable(); | ||
| 344 | // for (int i = 0, count = image.colorCount(); i < count; ++i) { | ||
| 345 | // const int alpha = qAlpha(rgb[i]); | ||
| 346 | // if (alpha != 0xff) { | ||
| 347 | // alphamap = true; | ||
| 348 | // break; | ||
| 349 | // } | ||
| 350 | // } | ||
| 351 | // } | ||
| 352 | // macSetHasAlpha(alphamap); | ||
| 353 | // } | ||
| 354 | // uninit = false; | ||
| 355 | } | ||
| 356 | |||
| 357 | //int get_index(QImage * qi,QRgb mycol) | ||
| 358 | //{ | ||
| 359 | // int loopc; | ||
| 360 | // for(loopc=0;loopc<qi->colorCount();loopc++) { | ||
| 361 | // if(qi->color(loopc)==mycol) | ||
| 362 | // return loopc; | ||
| 363 | // } | ||
| 364 | // qi->setColorCount(qi->colorCount()+1); | ||
| 365 | // qi->setColor(qi->colorCount(),mycol); | ||
| 366 | // return qi->colorCount(); | ||
| 367 | //} | ||
| 368 | |||
| 369 | QImage QIPhonePixmapData::toImage() const | ||
| 370 | { | ||
| 371 | // QImage::Format format = QImage::Format_MonoLSB; | ||
| 372 | // if (d != 1) //Doesn't support index color modes | ||
| 373 | // format = (has_alpha ? QImage::Format_ARGB32_Premultiplied : | ||
| 374 | // QImage::Format_RGB32); | ||
| 375 | // | ||
| 376 | // QImage image(w, h, format); | ||
| 377 | // quint32 *sptr = pixels, *srow; | ||
| 378 | // const uint sbpr = bytesPerRow; | ||
| 379 | // if (format == QImage::Format_MonoLSB) { | ||
| 380 | // image.fill(0); | ||
| 381 | // image.setColorCount(2); | ||
| 382 | // image.setColor(0, QColor(Qt::color0).rgba()); | ||
| 383 | // image.setColor(1, QColor(Qt::color1).rgba()); | ||
| 384 | // for (int y = 0; y < h; ++y) { | ||
| 385 | // uchar *scanLine = image.scanLine(y); | ||
| 386 | // srow = sptr + (y * (sbpr/4)); | ||
| 387 | // for (int x = 0; x < w; ++x) { | ||
| 388 | // if (!(*(srow + x) & RGB_MASK)) | ||
| 389 | // scanLine[x >> 3] |= (1 << (x & 7)); | ||
| 390 | // } | ||
| 391 | // } | ||
| 392 | // } else { | ||
| 393 | // for (int y = 0; y < h; ++y) { | ||
| 394 | // srow = sptr + (y * (sbpr / 4)); | ||
| 395 | // memcpy(image.scanLine(y), srow, w * 4); | ||
| 396 | // } | ||
| 397 | // | ||
| 398 | // } | ||
| 399 | // | ||
| 400 | // return image; | ||
| 401 | #warning toImage() | ||
| 402 | return QImage(); | ||
| 403 | } | ||
| 404 | |||
| 405 | void QIPhonePixmapData::fill(const QColor &fillColor) | ||
| 406 | { | ||
| 407 | // { //we don't know what backend to use so we cannot paint here | ||
| 408 | // quint32 *dptr = pixels; | ||
| 409 | // Q_ASSERT_X(dptr, "QPixmap::fill", "No dptr"); | ||
| 410 | // const quint32 colr = PREMUL(fillColor.rgba()); | ||
| 411 | // const int nbytes = bytesPerRow * h; | ||
| 412 | // if (!colr) { | ||
| 413 | // memset(dptr, 0, nbytes); | ||
| 414 | // } else { | ||
| 415 | // for (uint i = 0; i < nbytes / sizeof(quint32); ++i) | ||
| 416 | // *(dptr + i) = colr; | ||
| 417 | // } | ||
| 418 | // } | ||
| 419 | // macSetHasAlpha(fillColor.alpha() != 255); | ||
| 420 | } | ||
| 421 | |||
| 422 | //QPixmap QMacPixmapData::alphaChannel() const | ||
| 423 | //{ | ||
| 424 | // if (!has_alpha) | ||
| 425 | // return QPixmap(); | ||
| 426 | // | ||
| 427 | // QMacPixmapData *alpha = new QMacPixmapData(PixmapType); | ||
| 428 | // alpha->resize(w, h); | ||
| 429 | // macGetAlphaChannel(alpha, false); | ||
| 430 | // return QPixmap(alpha); | ||
| 431 | //} | ||
| 432 | // | ||
| 433 | //void QMacPixmapData::setAlphaChannel(const QPixmap &alpha) | ||
| 434 | //{ | ||
| 435 | // has_mask = true; | ||
| 436 | // QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data()); | ||
| 437 | // macSetAlphaChannel(alphaData, false); | ||
| 438 | //} | ||
| 439 | |||
| 440 | //QBitmap QMacPixmapData::mask() const | ||
| 441 | //{ | ||
| 442 | // if (!has_mask && !has_alpha) | ||
| 443 | // return QBitmap(); | ||
| 444 | // | ||
| 445 | // QMacPixmapData *mask = new QMacPixmapData(BitmapType); | ||
| 446 | // mask->resize(w, h); | ||
| 447 | // macGetAlphaChannel(mask, true); | ||
| 448 | // return QPixmap(mask); | ||
| 449 | //} | ||
| 450 | |||
| 451 | //void QMacPixmapData::setMask(const QBitmap &mask) | ||
| 452 | //{ | ||
| 453 | // if (mask.isNull()) { | ||
| 454 | // QMacPixmapData opaque(PixmapType); | ||
| 455 | // opaque.resize(w, h); | ||
| 456 | // opaque.fill(QColor(255, 255, 255, 255)); | ||
| 457 | // macSetAlphaChannel(&opaque, true); | ||
| 458 | // has_alpha = has_mask = false; | ||
| 459 | // return; | ||
| 460 | // } | ||
| 461 | // | ||
| 462 | // has_alpha = false; | ||
| 463 | // has_mask = true; | ||
| 464 | // QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data()); | ||
| 465 | // macSetAlphaChannel(maskData, true); | ||
| 466 | //} | ||
| 467 | |||
| 468 | int QIPhonePixmapData::metric(QPaintDevice::PaintDeviceMetric theMetric) const | ||
| 469 | { | ||
| 470 | // switch (theMetric) { | ||
| 471 | // case QPaintDevice::PdmWidth: | ||
| 472 | // return w; | ||
| 473 | // case QPaintDevice::PdmHeight: | ||
| 474 | // return h; | ||
| 475 | // case QPaintDevice::PdmWidthMM: | ||
| 476 | // return qRound(metric(QPaintDevice::PdmWidth) * 25.4 / qreal(metric(QPaintDevice::PdmDpiX))); | ||
| 477 | // case QPaintDevice::PdmHeightMM: | ||
| 478 | // return qRound(metric(QPaintDevice::PdmHeight) * 25.4 / qreal(metric(QPaintDevice::PdmDpiY))); | ||
| 479 | // case QPaintDevice::PdmNumColors: | ||
| 480 | // return 1 << d; | ||
| 481 | // case QPaintDevice::PdmDpiX: | ||
| 482 | // case QPaintDevice::PdmPhysicalDpiX: { | ||
| 483 | // extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp | ||
| 484 | // return int(qt_mac_defaultDpi_x()); | ||
| 485 | // } | ||
| 486 | // case QPaintDevice::PdmDpiY: | ||
| 487 | // case QPaintDevice::PdmPhysicalDpiY: { | ||
| 488 | // extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp | ||
| 489 | // return int(qt_mac_defaultDpi_y()); | ||
| 490 | // } | ||
| 491 | // case QPaintDevice::PdmDepth: | ||
| 492 | // return d; | ||
| 493 | // default: | ||
| 494 | // qWarning("QPixmap::metric: Invalid metric command"); | ||
| 495 | // } | ||
| 496 | return 0; | ||
| 497 | } | ||
| 498 | |||
| 499 | QIPhonePixmapData::~QIPhonePixmapData() | ||
| 500 | { | ||
| 501 | // validDataPointers.remove(this); | ||
| 502 | // if (cg_mask) { | ||
| 503 | // CGImageRelease(cg_mask); | ||
| 504 | // cg_mask = 0; | ||
| 505 | // } | ||
| 506 | // | ||
| 507 | // delete pengine; // Make sure we aren't drawing on the context anymore. | ||
| 508 | // if (cg_data) { | ||
| 509 | // CGImageRelease(cg_data); | ||
| 510 | // } else if (!cg_dataBeingReleased && pixels != pixelsToFree) { | ||
| 511 | // free(pixels); | ||
| 512 | // } | ||
| 513 | // free(pixelsToFree); | ||
| 514 | } | ||
| 515 | |||
| 516 | //void QMacPixmapData::macSetAlphaChannel(const QMacPixmapData *pix, bool asMask) | ||
| 517 | //{ | ||
| 518 | // if (!pixels || !h || !w || pix->w != w || pix->h != h) | ||
| 519 | // return; | ||
| 520 | // | ||
| 521 | // quint32 *dptr = pixels, *drow; | ||
| 522 | // const uint dbpr = bytesPerRow; | ||
| 523 | // const unsigned short sbpr = pix->bytesPerRow; | ||
| 524 | // quint32 *sptr = pix->pixels, *srow; | ||
| 525 | // for (int y=0; y < h; ++y) { | ||
| 526 | // drow = dptr + (y * (dbpr/4)); | ||
| 527 | // srow = sptr + (y * (sbpr/4)); | ||
| 528 | // if(d == 1) { | ||
| 529 | // for (int x=0; x < w; ++x) { | ||
| 530 | // if((*(srow+x) & RGB_MASK)) | ||
| 531 | // *(drow+x) = 0xFFFFFFFF; | ||
| 532 | // } | ||
| 533 | // } else if(d == 8) { | ||
| 534 | // for (int x=0; x < w; ++x) | ||
| 535 | // *(drow+x) = (*(drow+x) & RGB_MASK) | (*(srow+x) << 24); | ||
| 536 | // } else if(asMask) { | ||
| 537 | // for (int x=0; x < w; ++x) { | ||
| 538 | // if(*(srow+x) & RGB_MASK) | ||
| 539 | // *(drow+x) = (*(drow+x) & RGB_MASK); | ||
| 540 | // else | ||
| 541 | // *(drow+x) = (*(drow+x) & RGB_MASK) | 0xFF000000; | ||
| 542 | // *(drow+x) = PREMUL(*(drow+x)); | ||
| 543 | // } | ||
| 544 | // } else { | ||
| 545 | // for (int x=0; x < w; ++x) { | ||
| 546 | // const uchar alpha = qGray(qRed(*(srow+x)), qGreen(*(srow+x)), qBlue(*(srow+x))); | ||
| 547 | // const uchar destAlpha = qt_div_255(alpha * qAlpha(*(drow+x))); | ||
| 548 | //#if 1 | ||
| 549 | // *(drow+x) = (*(drow+x) & RGB_MASK) | (destAlpha << 24); | ||
| 550 | //#else | ||
| 551 | // *(drow+x) = qRgba(qt_div_255(qRed(*(drow+x) * alpha)), | ||
| 552 | // qt_div_255(qGreen(*(drow+x) * alpha)), | ||
| 553 | // qt_div_255(qBlue(*(drow+x) * alpha)), destAlpha); | ||
| 554 | //#endif | ||
| 555 | // *(drow+x) = PREMUL(*(drow+x)); | ||
| 556 | // } | ||
| 557 | // } | ||
| 558 | // } | ||
| 559 | // macSetHasAlpha(true); | ||
| 560 | //} | ||
| 561 | |||
| 562 | //void QMacPixmapData::macGetAlphaChannel(QMacPixmapData *pix, bool asMask) const | ||
| 563 | //{ | ||
| 564 | // quint32 *dptr = pix->pixels, *drow; | ||
| 565 | // const uint dbpr = pix->bytesPerRow; | ||
| 566 | // const unsigned short sbpr = bytesPerRow; | ||
| 567 | // quint32 *sptr = pixels, *srow; | ||
| 568 | // for(int y=0; y < h; ++y) { | ||
| 569 | // drow = dptr + (y * (dbpr/4)); | ||
| 570 | // srow = sptr + (y * (sbpr/4)); | ||
| 571 | // if(asMask) { | ||
| 572 | // for (int x = 0; x < w; ++x) { | ||
| 573 | // if (*(srow + x) & qRgba(0, 0, 0, 255)) | ||
| 574 | // *(drow + x) = 0x00000000; | ||
| 575 | // else | ||
| 576 | // *(drow + x) = 0xFFFFFFFF; | ||
| 577 | // } | ||
| 578 | // } else { | ||
| 579 | // for (int x = 0; x < w; ++x) { | ||
| 580 | // const int alpha = qAlpha(*(srow + x)); | ||
| 581 | // *(drow + x) = qRgb(alpha, alpha, alpha); | ||
| 582 | // } | ||
| 583 | // } | ||
| 584 | // } | ||
| 585 | //} | ||
| 586 | |||
| 587 | //void QMacPixmapData::macSetHasAlpha(bool b) | ||
| 588 | //{ | ||
| 589 | // has_alpha = b; | ||
| 590 | // macReleaseCGImageRef(); | ||
| 591 | //} | ||
| 592 | |||
| 593 | //void QMacPixmapData::macCreateCGImageRef() | ||
| 594 | //{ | ||
| 595 | // Q_ASSERT(cg_data == 0); | ||
| 596 | // //create the cg data | ||
| 597 | // CGColorSpaceRef colorspace = QCoreGraphicsPaintEngine::macDisplayColorSpace(); | ||
| 598 | // QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(this, | ||
| 599 | // pixels, bytesPerRow * h, | ||
| 600 | // qt_mac_cgimage_data_free); | ||
| 601 | // validDataPointers.insert(this); | ||
| 602 | // uint cgflags = kCGImageAlphaPremultipliedFirst; | ||
| 603 | //#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version | ||
| 604 | // cgflags |= kCGBitmapByteOrder32Host; | ||
| 605 | //#endif | ||
| 606 | // cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace, | ||
| 607 | // cgflags, provider, 0, 0, kCGRenderingIntentDefault); | ||
| 608 | //} | ||
| 609 | |||
| 610 | //void QMacPixmapData::macReleaseCGImageRef() | ||
| 611 | //{ | ||
| 612 | // if (!cg_data) | ||
| 613 | // return; // There's nothing we need to do | ||
| 614 | // | ||
| 615 | // cg_dataBeingReleased = cg_data; | ||
| 616 | // CGImageRelease(cg_data); | ||
| 617 | // cg_data = 0; | ||
| 618 | // | ||
| 619 | // if (pixels != pixelsToFree) { | ||
| 620 | // macCreatePixels(); | ||
| 621 | // } else { | ||
| 622 | // pixelsToFree = 0; | ||
| 623 | // } | ||
| 624 | //} | ||
| 625 | |||
| 626 | // We create our space in memory to paint on here. If we already have existing pixels | ||
| 627 | // copy them over. This is to preserve the fact that CGImageRef's are immutable. | ||
| 628 | //void QMacPixmapData::macCreatePixels() | ||
| 629 | //{ | ||
| 630 | // const int numBytes = bytesPerRow * h; | ||
| 631 | // quint32 *base_pixels; | ||
| 632 | // if (pixelsToFree && pixelsToFree != pixels) { | ||
| 633 | // // Reuse unused block of memory lying around from a previous callback. | ||
| 634 | // base_pixels = pixelsToFree; | ||
| 635 | // pixelsToFree = 0; | ||
| 636 | // } else { | ||
| 637 | // // We need a block of memory to do stuff with. | ||
| 638 | // base_pixels = static_cast<quint32 *>(malloc(numBytes)); | ||
| 639 | // } | ||
| 640 | // | ||
| 641 | // if (pixels) | ||
| 642 | // memcpy(base_pixels, pixels, pixelsSize); | ||
| 643 | // pixels = base_pixels; | ||
| 644 | // pixelsSize = numBytes; | ||
| 645 | //} | ||
| 646 | |||
| 647 | //#if 0 | ||
| 648 | //QPixmap QMacPixmapData::transformed(const QTransform &transform, | ||
| 649 | // Qt::TransformationMode mode) const | ||
| 650 | //{ | ||
| 651 | // int w, h; // size of target pixmap | ||
| 652 | // const int ws = width(); | ||
| 653 | // const int hs = height(); | ||
| 654 | // | ||
| 655 | // QTransform mat(transform.m11(), transform.m12(), | ||
| 656 | // transform.m21(), transform.m22(), 0., 0.); | ||
| 657 | // if (transform.m12() == 0.0F && transform.m21() == 0.0F && | ||
| 658 | // transform.m11() >= 0.0F && transform.m22() >= 0.0F) | ||
| 659 | // { | ||
| 660 | // h = int(qAbs(mat.m22()) * hs + 0.9999); | ||
| 661 | // w = int(qAbs(mat.m11()) * ws + 0.9999); | ||
| 662 | // h = qAbs(h); | ||
| 663 | // w = qAbs(w); | ||
| 664 | // } else { // rotation or shearing | ||
| 665 | // QPolygonF a(QRectF(0,0,ws+1,hs+1)); | ||
| 666 | // a = mat.map(a); | ||
| 667 | // QRectF r = a.boundingRect().normalized(); | ||
| 668 | // w = int(r.width() + 0.9999); | ||
| 669 | // h = int(r.height() + 0.9999); | ||
| 670 | // } | ||
| 671 | // mat = QPixmap::trueMatrix(mat, ws, hs); | ||
| 672 | // if (!h || !w) | ||
| 673 | // return QPixmap(); | ||
| 674 | // | ||
| 675 | // // create destination | ||
| 676 | // QMacPixmapData *pm = new QMacPixmapData(pixelType(), w, h); | ||
| 677 | // const quint32 *sptr = pixels; | ||
| 678 | // quint32 *dptr = pm->pixels; | ||
| 679 | // memset(dptr, 0, (pm->bytesPerRow * pm->h)); | ||
| 680 | // | ||
| 681 | // // do the transform | ||
| 682 | // if (mode == Qt::SmoothTransformation) { | ||
| 683 | //#warning QMacPixmapData::transformed not properly implemented | ||
| 684 | // qWarning("QMacPixmapData::transformed not properly implemented"); | ||
| 685 | //#if 0 | ||
| 686 | // QPainter p(&pm); | ||
| 687 | // p.setRenderHint(QPainter::Antialiasing); | ||
| 688 | // p.setRenderHint(QPainter::SmoothPixmapTransform); | ||
| 689 | // p.setTransform(mat); | ||
| 690 | // p.drawPixmap(0, 0, *this); | ||
| 691 | //#endif | ||
| 692 | // } else { | ||
| 693 | // bool invertible; | ||
| 694 | // mat = mat.inverted(&invertible); | ||
| 695 | // if (!invertible) | ||
| 696 | // return QPixmap(); | ||
| 697 | // | ||
| 698 | // const int bpp = 32; | ||
| 699 | // const int xbpl = (w * bpp) / 8; | ||
| 700 | // if (!qt_xForm_helper(mat, 0, QT_XFORM_TYPE_MSBFIRST, bpp, | ||
| 701 | // (uchar*)dptr, xbpl, (pm->bytesPerRow) - xbpl, | ||
| 702 | // h, (uchar*)sptr, (bytesPerRow), ws, hs)) { | ||
| 703 | // qWarning("QMacPixmapData::transform(): failure"); | ||
| 704 | // return QPixmap(); | ||
| 705 | // } | ||
| 706 | // } | ||
| 707 | // | ||
| 708 | // // update the alpha | ||
| 709 | // pm->macSetHasAlpha(true); | ||
| 710 | // return QPixmap(pm); | ||
| 711 | //} | ||
| 712 | //#endif | ||
| 713 | |||
| 714 | QT_BEGIN_INCLUDE_NAMESPACE | ||
| 715 | //#include <OpenGL/OpenGL.h> | ||
| 716 | //#include <OpenGL/gl.h> | ||
| 717 | QT_END_INCLUDE_NAMESPACE | ||
| 718 | |||
| 719 | // Load and resolve the symbols we need from OpenGL manually so QtGui doesn't have to link against the OpenGL framework. | ||
| 720 | //typedef CGLError (*PtrCGLChoosePixelFormat)(const CGLPixelFormatAttribute *, CGLPixelFormatObj *, long *); | ||
| 721 | //typedef CGLError (*PtrCGLClearDrawable)(CGLContextObj); | ||
| 722 | //typedef CGLError (*PtrCGLCreateContext)(CGLPixelFormatObj, CGLContextObj, CGLContextObj *); | ||
| 723 | //typedef CGLError (*PtrCGLDestroyContext)(CGLContextObj); | ||
| 724 | //typedef CGLError (*PtrCGLDestroyPixelFormat)(CGLPixelFormatObj); | ||
| 725 | //typedef CGLError (*PtrCGLSetCurrentContext)(CGLContextObj); | ||
| 726 | //typedef CGLError (*PtrCGLSetFullScreen)(CGLContextObj); | ||
| 727 | //typedef void (*PtrglFinish)(); | ||
| 728 | //typedef void (*PtrglPixelStorei)(GLenum, GLint); | ||
| 729 | //typedef void (*PtrglReadBuffer)(GLenum); | ||
| 730 | //typedef void (*PtrglReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *); | ||
| 731 | |||
| 732 | //static PtrCGLChoosePixelFormat ptrCGLChoosePixelFormat = 0; | ||
| 733 | //static PtrCGLClearDrawable ptrCGLClearDrawable = 0; | ||
| 734 | //static PtrCGLCreateContext ptrCGLCreateContext = 0; | ||
| 735 | //static PtrCGLDestroyContext ptrCGLDestroyContext = 0; | ||
| 736 | //static PtrCGLDestroyPixelFormat ptrCGLDestroyPixelFormat = 0; | ||
| 737 | //static PtrCGLSetCurrentContext ptrCGLSetCurrentContext = 0; | ||
| 738 | //static PtrCGLSetFullScreen ptrCGLSetFullScreen = 0; | ||
| 739 | //static PtrglFinish ptrglFinish = 0; | ||
| 740 | //static PtrglPixelStorei ptrglPixelStorei = 0; | ||
| 741 | //static PtrglReadBuffer ptrglReadBuffer = 0; | ||
| 742 | //static PtrglReadPixels ptrglReadPixels = 0; | ||
| 743 | |||
| 744 | //static bool resolveOpenGLSymbols() | ||
| 745 | //{ | ||
| 746 | // if (ptrCGLChoosePixelFormat == 0) { | ||
| 747 | // QLibrary library(QLatin1String("/System/Library/Frameworks/OpenGL.framework/OpenGL")); | ||
| 748 | // ptrCGLChoosePixelFormat = (PtrCGLChoosePixelFormat)(library.resolve("CGLChoosePixelFormat")); | ||
| 749 | // ptrCGLClearDrawable = (PtrCGLClearDrawable)(library.resolve("CGLClearDrawable")); | ||
| 750 | // ptrCGLCreateContext = (PtrCGLCreateContext)(library.resolve("CGLCreateContext")); | ||
| 751 | // ptrCGLDestroyContext = (PtrCGLDestroyContext)(library.resolve("CGLDestroyContext")); | ||
| 752 | // ptrCGLDestroyPixelFormat = (PtrCGLDestroyPixelFormat)(library.resolve("CGLDestroyPixelFormat")); | ||
| 753 | // ptrCGLSetCurrentContext = (PtrCGLSetCurrentContext)(library.resolve("CGLSetCurrentContext")); | ||
| 754 | // ptrCGLSetFullScreen = (PtrCGLSetFullScreen)(library.resolve("CGLSetFullScreen")); | ||
| 755 | // ptrglFinish = (PtrglFinish)(library.resolve("glFinish")); | ||
| 756 | // ptrglPixelStorei = (PtrglPixelStorei)(library.resolve("glPixelStorei")); | ||
| 757 | // ptrglReadBuffer = (PtrglReadBuffer)(library.resolve("glReadBuffer")); | ||
| 758 | // ptrglReadPixels = (PtrglReadPixels)(library.resolve("glReadPixels")); | ||
| 759 | // } | ||
| 760 | // return ptrCGLChoosePixelFormat && ptrCGLClearDrawable && ptrCGLCreateContext | ||
| 761 | // && ptrCGLDestroyContext && ptrCGLDestroyPixelFormat && ptrCGLSetCurrentContext | ||
| 762 | // && ptrCGLSetFullScreen && ptrglFinish && ptrglPixelStorei | ||
| 763 | // && ptrglReadBuffer && ptrglReadPixels; | ||
| 764 | //} | ||
| 765 | |||
| 766 | // Inverts the given pixmap in the y direction. | ||
| 767 | //static void qt_mac_flipPixmap(void *data, int rowBytes, int height) | ||
| 768 | //{ | ||
| 769 | // int bottom = height - 1; | ||
| 770 | // void *base = data; | ||
| 771 | // void *buffer = malloc(rowBytes); | ||
| 772 | // | ||
| 773 | // int top = 0; | ||
| 774 | // while ( top < bottom ) | ||
| 775 | // { | ||
| 776 | // void *topP = (void *)((top * rowBytes) + (intptr_t)base); | ||
| 777 | // void *bottomP = (void *)((bottom * rowBytes) + (intptr_t)base); | ||
| 778 | // | ||
| 779 | // bcopy( topP, buffer, rowBytes ); | ||
| 780 | // bcopy( bottomP, topP, rowBytes ); | ||
| 781 | // bcopy( buffer, bottomP, rowBytes ); | ||
| 782 | // | ||
| 783 | // ++top; | ||
| 784 | // --bottom; | ||
| 785 | // } | ||
| 786 | // free(buffer); | ||
| 787 | //} | ||
| 788 | |||
| 789 | // Grabs displayRect from display and places it into buffer. | ||
| 790 | //static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displayRect, void *buffer) | ||
| 791 | //{ | ||
| 792 | // if (display == kCGNullDirectDisplay) | ||
| 793 | // return; | ||
| 794 | // | ||
| 795 | // CGLPixelFormatAttribute attribs[] = { | ||
| 796 | // kCGLPFAFullScreen, | ||
| 797 | // kCGLPFADisplayMask, | ||
| 798 | // (CGLPixelFormatAttribute)0, /* Display mask bit goes here */ | ||
| 799 | // (CGLPixelFormatAttribute)0 | ||
| 800 | // }; | ||
| 801 | // | ||
| 802 | // attribs[2] = (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display); | ||
| 803 | // | ||
| 804 | // // Build a full-screen GL context | ||
| 805 | // CGLPixelFormatObj pixelFormatObj; | ||
| 806 | // long numPixelFormats; | ||
| 807 | // | ||
| 808 | // ptrCGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats ); | ||
| 809 | // | ||
| 810 | // if (!pixelFormatObj) // No full screen context support | ||
| 811 | // return; | ||
| 812 | // | ||
| 813 | // CGLContextObj glContextObj; | ||
| 814 | // ptrCGLCreateContext(pixelFormatObj, 0, &glContextObj); | ||
| 815 | // ptrCGLDestroyPixelFormat(pixelFormatObj) ; | ||
| 816 | // if (!glContextObj) | ||
| 817 | // return; | ||
| 818 | // | ||
| 819 | // ptrCGLSetCurrentContext(glContextObj); | ||
| 820 | // ptrCGLSetFullScreen(glContextObj) ; | ||
| 821 | // | ||
| 822 | // ptrglReadBuffer(GL_FRONT); | ||
| 823 | // | ||
| 824 | // ptrglFinish(); // Finish all OpenGL commands | ||
| 825 | // ptrglPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment | ||
| 826 | // ptrglPixelStorei(GL_PACK_ROW_LENGTH, 0); | ||
| 827 | // ptrglPixelStorei(GL_PACK_SKIP_ROWS, 0); | ||
| 828 | // ptrglPixelStorei(GL_PACK_SKIP_PIXELS, 0); | ||
| 829 | // | ||
| 830 | // // Fetch the data in XRGB format, matching the bitmap context. | ||
| 831 | // ptrglReadPixels(GLint(displayRect.x()), GLint(displayRect.y()), | ||
| 832 | // GLint(displayRect.width()), GLint(displayRect.height()), | ||
| 833 | //#ifdef __BIG_ENDIAN__ | ||
| 834 | // GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer | ||
| 835 | //#else | ||
| 836 | // GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, buffer | ||
| 837 | //#endif | ||
| 838 | // ); | ||
| 839 | // | ||
| 840 | // ptrCGLSetCurrentContext(0); | ||
| 841 | // ptrCGLClearDrawable(glContextObj); // disassociate from full screen | ||
| 842 | // ptrCGLDestroyContext(glContextObj); // and destroy the context | ||
| 843 | //} | ||
| 844 | |||
| 845 | // Returns a pixmap containing the screen contents at rect. | ||
| 846 | //static QPixmap qt_mac_grabScreenRect(const QRect &rect) | ||
| 847 | //{ | ||
| 848 | // if (!resolveOpenGLSymbols()) | ||
| 849 | // return QPixmap(); | ||
| 850 | // | ||
| 851 | // const int maxDisplays = 128; // 128 displays should be enough for everyone. | ||
| 852 | // CGDirectDisplayID displays[maxDisplays]; | ||
| 853 | // CGDisplayCount displayCount; | ||
| 854 | // const CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()); | ||
| 855 | // const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount); | ||
| 856 | // | ||
| 857 | // if (err && displayCount == 0) | ||
| 858 | // return QPixmap(); | ||
| 859 | // | ||
| 860 | // long bytewidth = rect.width() * 4; // Assume 4 bytes/pixel for now | ||
| 861 | // bytewidth = (bytewidth + 3) & ~3; // Align to 4 bytes | ||
| 862 | // QVarLengthArray<char> buffer(rect.height() * bytewidth); | ||
| 863 | // | ||
| 864 | // for (uint i = 0; i < displayCount; ++i) { | ||
| 865 | // const CGRect bounds = CGDisplayBounds(displays[i]); | ||
| 866 | // // Translate to display-local coordinates | ||
| 867 | // QRect displayRect = rect.translated(qRound(-bounds.origin.x), qRound(-bounds.origin.y)); | ||
| 868 | // // Adjust for inverted y axis. | ||
| 869 | // displayRect.moveTop(qRound(bounds.size.height) - displayRect.y() - rect.height()); | ||
| 870 | // qt_mac_grabDisplayRect(displays[i], displayRect, buffer.data()); | ||
| 871 | // } | ||
| 872 | // | ||
| 873 | // qt_mac_flipPixmap(buffer.data(), bytewidth, rect.height()); | ||
| 874 | // QCFType<CGContextRef> bitmap = CGBitmapContextCreate(buffer.data(), rect.width(), | ||
| 875 | // rect.height(), 8, bytewidth, | ||
| 876 | // QCoreGraphicsPaintEngine::macGenericColorSpace(), | ||
| 877 | // kCGImageAlphaNoneSkipFirst); | ||
| 878 | // QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap); | ||
| 879 | // return QPixmap::fromMacCGImageRef(image); | ||
| 880 | //} | ||
| 881 | |||
| 882 | //#ifndef QT_MAC_USE_COCOA // no QuickDraw in 64-bit mode | ||
| 883 | //static QPixmap qt_mac_grabScreenRect_10_3(int x, int y, int w, int h, QWidget *widget) | ||
| 884 | //{ | ||
| 885 | // QPixmap pm = QPixmap(w, h); | ||
| 886 | // extern WindowPtr qt_mac_window_for(const QWidget *); // qwidget_mac.cpp | ||
| 887 | // const BitMap *windowPort = 0; | ||
| 888 | // if((widget->windowType() == Qt::Desktop)) { | ||
| 889 | // GDHandle gdh; | ||
| 890 | // if(!(gdh=GetMainDevice())) | ||
| 891 | // qDebug("Qt: internal: Unexpected condition reached: %s:%d", __FILE__, __LINE__); | ||
| 892 | // windowPort = (BitMap*)(*(*gdh)->gdPMap); | ||
| 893 | // } else { | ||
| 894 | // windowPort = GetPortBitMapForCopyBits(GetWindowPort(qt_mac_window_for(widget))); | ||
| 895 | // } | ||
| 896 | // const BitMap *pixmapPort = GetPortBitMapForCopyBits(static_cast<GWorldPtr>(pm.macQDHandle())); | ||
| 897 | // Rect macSrcRect, macDstRect; | ||
| 898 | // SetRect(&macSrcRect, x, y, x + w, y + h); | ||
| 899 | // SetRect(&macDstRect, 0, 0, w, h); | ||
| 900 | // CopyBits(windowPort, pixmapPort, &macSrcRect, &macDstRect, srcCopy, 0); | ||
| 901 | // return pm; | ||
| 902 | //} | ||
| 903 | |||
| 904 | QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) | ||
| 905 | { | ||
| 906 | // QWidget *widget = QWidget::find(window); | ||
| 907 | // if (widget == 0) | ||
| 908 | // return QPixmap(); | ||
| 909 | // | ||
| 910 | // if(w == -1) | ||
| 911 | // w = widget->width() - x; | ||
| 912 | // if(h == -1) | ||
| 913 | // h = widget->height() - y; | ||
| 914 | // | ||
| 915 | // QPoint globalCoord(0, 0); | ||
| 916 | // globalCoord = widget->mapToGlobal(globalCoord); | ||
| 917 | // QRect rect(globalCoord.x() + x, globalCoord.y() + y, w, h); | ||
| 918 | // | ||
| 919 | //#ifdef QT_MAC_USE_COCOA | ||
| 920 | // return qt_mac_grabScreenRect(rect); | ||
| 921 | //#else | ||
| 922 | //#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) | ||
| 923 | // if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { | ||
| 924 | // return qt_mac_grabScreenRect(rect); | ||
| 925 | // } else | ||
| 926 | //#endif | ||
| 927 | // { | ||
| 928 | // return qt_mac_grabScreenRect_10_3(x, y, w, h, widget); | ||
| 929 | // } | ||
| 930 | //#endif // ifdef Q_WS_MAC64 | ||
| 931 | #warning grabWindow(); | ||
| 932 | return QPixmap(); | ||
| 933 | } | ||
| 934 | |||
| 935 | /*! \internal | ||
| 936 | |||
| 937 | Returns the QuickDraw CGrafPtr of the pixmap. 0 is returned if it can't | ||
| 938 | be obtained. Do not hold the pointer around for long as it can be | ||
| 939 | relocated. | ||
| 940 | |||
| 941 | \warning This function is only available on Mac OS X. | ||
| 942 | \warning As of Qt 4.6, this function \e{always} returns zero. | ||
| 943 | */ | ||
| 944 | |||
| 945 | //Qt::HANDLE QPixmap::macQDHandle() const | ||
| 946 | //{ | ||
| 947 | // return 0; | ||
| 948 | //} | ||
| 949 | |||
| 950 | /*! \internal | ||
| 951 | |||
| 952 | Returns the QuickDraw CGrafPtr of the pixmap's alpha channel. 0 is | ||
| 953 | returned if it can't be obtained. Do not hold the pointer around for | ||
| 954 | long as it can be relocated. | ||
| 955 | |||
| 956 | \warning This function is only available on Mac OS X. | ||
| 957 | \warning As of Qt 4.6, this function \e{always} returns zero. | ||
| 958 | */ | ||
| 959 | |||
| 960 | //Qt::HANDLE QPixmap::macQDAlphaHandle() const | ||
| 961 | //{ | ||
| 962 | // return 0; | ||
| 963 | //} | ||
| 964 | |||
| 965 | /*! \internal | ||
| 966 | |||
| 967 | Returns the CoreGraphics CGContextRef of the pixmap. 0 is returned if | ||
| 968 | it can't be obtained. It is the caller's responsiblity to | ||
| 969 | CGContextRelease the context when finished using it. | ||
| 970 | |||
| 971 | \warning This function is only available on Mac OS X. | ||
| 972 | */ | ||
| 973 | |||
| 974 | //Qt::HANDLE QPixmap::macCGHandle() const | ||
| 975 | //{ | ||
| 976 | // if (isNull()) | ||
| 977 | // return 0; | ||
| 978 | // | ||
| 979 | // if (data->classId() == QPixmapData::MacClass) { | ||
| 980 | // QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data()); | ||
| 981 | // if (!d->cg_data) | ||
| 982 | // d->macCreateCGImageRef(); | ||
| 983 | // CGImageRef ret = d->cg_data; | ||
| 984 | // CGImageRetain(ret); | ||
| 985 | // return ret; | ||
| 986 | // } else if (data->classId() == QPixmapData::RasterClass) { | ||
| 987 | // return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data.data())->image); | ||
| 988 | // } | ||
| 989 | // return 0; | ||
| 990 | //} | ||
| 991 | |||
| 992 | bool QIPhonePixmapData::hasAlphaChannel() const | ||
| 993 | { | ||
| 994 | #warning hasAlphaChannel() | ||
| 995 | return false; | ||
| 996 | // return has_alpha; | ||
| 997 | } | ||
| 998 | |||
| 999 | //CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr) | ||
| 1000 | //{ | ||
| 1001 | // QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data()); | ||
| 1002 | // if (px->cg_mask) { | ||
| 1003 | // if (px->cg_mask_rect == sr) { | ||
| 1004 | // CGImageRetain(px->cg_mask); //reference for the caller | ||
| 1005 | // return px->cg_mask; | ||
| 1006 | // } | ||
| 1007 | // CGImageRelease(px->cg_mask); | ||
| 1008 | // px->cg_mask = 0; | ||
| 1009 | // } | ||
| 1010 | // | ||
| 1011 | // const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height()); | ||
| 1012 | // const int sbpr = px->bytesPerRow; | ||
| 1013 | // const uint nbytes = sw * sh; | ||
| 1014 | // // alpha is always 255 for bitmaps, ignore it in this case. | ||
| 1015 | // const quint32 mask = px->depth() == 1 ? 0x00ffffff : 0xffffffff; | ||
| 1016 | // quint8 *dptr = static_cast<quint8 *>(malloc(nbytes)); | ||
| 1017 | // quint32 *sptr = px->pixels, *srow; | ||
| 1018 | // for(int y = sy, offset=0; y < sh; ++y) { | ||
| 1019 | // srow = sptr + (y * (sbpr / 4)); | ||
| 1020 | // for(int x = sx; x < sw; ++x) | ||
| 1021 | // *(dptr+(offset++)) = (*(srow+x) & mask) ? 255 : 0; | ||
| 1022 | // } | ||
| 1023 | // QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, dptr, nbytes, qt_mac_cgimage_data_free); | ||
| 1024 | // px->cg_mask = CGImageMaskCreate(sw, sh, 8, 8, nbytes / sh, provider, 0, 0); | ||
| 1025 | // px->cg_mask_rect = sr; | ||
| 1026 | // CGImageRetain(px->cg_mask); //reference for the caller | ||
| 1027 | // return px->cg_mask; | ||
| 1028 | //} | ||
| 1029 | |||
| 1030 | //IconRef qt_mac_create_iconref(const QPixmap &px) | ||
| 1031 | //{ | ||
| 1032 | // if (px.isNull()) | ||
| 1033 | // return 0; | ||
| 1034 | // | ||
| 1035 | // //create icon | ||
| 1036 | // IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0)); | ||
| 1037 | // //create data | ||
| 1038 | // { | ||
| 1039 | // struct { | ||
| 1040 | // OSType mac_type; | ||
| 1041 | // int width, height, depth; | ||
| 1042 | // bool mask; | ||
| 1043 | // } images[] = { | ||
| 1044 | // { kThumbnail32BitData, 128, 128, 32, false }, | ||
| 1045 | // { kThumbnail8BitMask, 128, 128, 8, true }, | ||
| 1046 | // { 0, 0, 0, 0, false } //end marker | ||
| 1047 | // }; | ||
| 1048 | // for(int i = 0; images[i].mac_type; i++) { | ||
| 1049 | // //get QPixmap data | ||
| 1050 | // QImage scaled_px = px.toImage().scaled(images[i].width, images[i].height); | ||
| 1051 | // | ||
| 1052 | // quint32 *sptr = (quint32 *) scaled_px.bits(); | ||
| 1053 | // quint32 *srow; | ||
| 1054 | // uint sbpr = scaled_px.bytesPerLine(); | ||
| 1055 | // | ||
| 1056 | // //get Handle data | ||
| 1057 | // const int dbpr = images[i].width * (images[i].depth/8); | ||
| 1058 | // Handle hdl = NewHandle(dbpr*images[i].height); | ||
| 1059 | // if(!sptr) { //handle null pixmap | ||
| 1060 | // memset((*hdl), '\0', dbpr*images[i].height); | ||
| 1061 | // } else if(images[i].mask) { | ||
| 1062 | // if(images[i].mac_type == kThumbnail8BitMask) { | ||
| 1063 | // for(int y = 0, hindex = 0; y < images[i].height; ++y) { | ||
| 1064 | // srow = sptr + (y * (sbpr/4)); | ||
| 1065 | // for(int x = 0; x < images[i].width; ++x) | ||
| 1066 | // *((*hdl)+(hindex++)) = qAlpha(*(srow+x)); | ||
| 1067 | // } | ||
| 1068 | // } | ||
| 1069 | // } else { | ||
| 1070 | // char *dest = (*hdl); | ||
| 1071 | //#if defined(__i386__) | ||
| 1072 | // if(images[i].depth == 32) { | ||
| 1073 | // for(int y = 0; y < images[i].height; ++y) { | ||
| 1074 | // uint *source = (uint*)((const uchar*)sptr+(sbpr*y)); | ||
| 1075 | // for(int x = 0; x < images[i].width; ++x, dest += 4) | ||
| 1076 | // *((uint*)dest) = CFSwapInt32(*(source + x)); | ||
| 1077 | // } | ||
| 1078 | // } else | ||
| 1079 | //#endif | ||
| 1080 | // { | ||
| 1081 | // for(int y = 0; y < images[i].height; ++y) | ||
| 1082 | // memcpy(dest+(y*dbpr), ((const uchar*)sptr+(sbpr*y)), dbpr); | ||
| 1083 | // } | ||
| 1084 | // } | ||
| 1085 | // | ||
| 1086 | // //set the family data to the Handle | ||
| 1087 | // OSStatus set = SetIconFamilyData(iconFamily, images[i].mac_type, hdl); | ||
| 1088 | // if(set != noErr) | ||
| 1089 | // qWarning("%s: %d -- Unable to create icon data[%d]!! %ld", | ||
| 1090 | // __FILE__, __LINE__, i, long(set)); | ||
| 1091 | // DisposeHandle(hdl); | ||
| 1092 | // } | ||
| 1093 | // } | ||
| 1094 | // | ||
| 1095 | // //acquire and cleanup | ||
| 1096 | // IconRef ret; | ||
| 1097 | // static int counter = 0; | ||
| 1098 | // const OSType kQtCreator = 'CUTE'; | ||
| 1099 | // RegisterIconRefFromIconFamily(kQtCreator, (OSType)counter, iconFamily, &ret); | ||
| 1100 | // AcquireIconRef(ret); | ||
| 1101 | // UnregisterIconRef(kQtCreator, (OSType)counter); | ||
| 1102 | // DisposeHandle(reinterpret_cast<Handle>(iconFamily)); | ||
| 1103 | // counter++; | ||
| 1104 | // return ret; | ||
| 1105 | // | ||
| 1106 | //} | ||
| 1107 | |||
| 1108 | /*! \internal */ | ||
| 1109 | QPaintEngine* QIPhonePixmapData::paintEngine() const | ||
| 1110 | { | ||
| 1111 | // if (!pengine) { | ||
| 1112 | // QMacPixmapData *that = const_cast<QMacPixmapData*>(this); | ||
| 1113 | // that->pengine = new QCoreGraphicsPaintEngine(); | ||
| 1114 | // } | ||
| 1115 | // return pengine; | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | //void QMacPixmapData::copy(const QPixmapData *data, const QRect &rect) | ||
| 1119 | //{ | ||
| 1120 | // if (data->pixelType() == BitmapType) { | ||
| 1121 | // QBitmap::fromImage(toImage().copy(rect)); | ||
| 1122 | // return; | ||
| 1123 | // } | ||
| 1124 | // | ||
| 1125 | // const QMacPixmapData *macData = static_cast<const QMacPixmapData*>(data); | ||
| 1126 | // | ||
| 1127 | // resize(rect.width(), rect.height()); | ||
| 1128 | // | ||
| 1129 | // has_alpha = macData->has_alpha; | ||
| 1130 | // has_mask = macData->has_mask; | ||
| 1131 | // uninit = false; | ||
| 1132 | // | ||
| 1133 | // const int x = rect.x(); | ||
| 1134 | // const int y = rect.y(); | ||
| 1135 | // char *dest = reinterpret_cast<char*>(pixels); | ||
| 1136 | // const char *src = reinterpret_cast<const char*>(macData->pixels + x) + y * macData->bytesPerRow; | ||
| 1137 | // for (int i = 0; i < h; ++i) { | ||
| 1138 | // memcpy(dest, src, w * 4); | ||
| 1139 | // dest += bytesPerRow; | ||
| 1140 | // src += macData->bytesPerRow; | ||
| 1141 | // } | ||
| 1142 | // | ||
| 1143 | // has_alpha = macData->has_alpha; | ||
| 1144 | // has_mask = macData->has_mask; | ||
| 1145 | //} | ||
| 1146 | |||
| 1147 | //bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect) | ||
| 1148 | //{ | ||
| 1149 | // Q_UNUSED(dx); | ||
| 1150 | // Q_UNUSED(dy); | ||
| 1151 | // Q_UNUSED(rect); | ||
| 1152 | // return false; | ||
| 1153 | //} | ||
| 1154 | |||
| 1155 | /*! | ||
| 1156 | \since 4.2 | ||
| 1157 | |||
| 1158 | Creates a \c CGImageRef equivalent to the QPixmap. Returns the \c CGImageRef handle. | ||
| 1159 | |||
| 1160 | It is the caller's responsibility to release the \c CGImageRef data | ||
| 1161 | after use. | ||
| 1162 | |||
| 1163 | \warning This function is only available on Mac OS X. | ||
| 1164 | |||
| 1165 | \sa fromMacCGImageRef() | ||
| 1166 | */ | ||
| 1167 | //CGImageRef QPixmap::toMacCGImageRef() const | ||
| 1168 | //{ | ||
| 1169 | // return (CGImageRef)macCGHandle(); | ||
| 1170 | //} | ||
| 1171 | |||
| 1172 | /*! | ||
| 1173 | \since 4.2 | ||
| 1174 | |||
| 1175 | Returns a QPixmap that is equivalent to the given \a image. | ||
| 1176 | |||
| 1177 | \warning This function is only available on Mac OS X. | ||
| 1178 | |||
| 1179 | \sa toMacCGImageRef(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} | ||
| 1180 | */ | ||
| 1181 | //QPixmap QPixmap::fromMacCGImageRef(CGImageRef image) | ||
| 1182 | //{ | ||
| 1183 | // const size_t w = CGImageGetWidth(image), | ||
| 1184 | // h = CGImageGetHeight(image); | ||
| 1185 | // QPixmap ret(w, h); | ||
| 1186 | // ret.fill(Qt::transparent); | ||
| 1187 | // CGRect rect = CGRectMake(0, 0, w, h); | ||
| 1188 | // CGContextRef ctx = qt_mac_cg_context(&ret); | ||
| 1189 | // qt_mac_drawCGImage(ctx, &rect, image); | ||
| 1190 | // CGContextRelease(ctx); | ||
| 1191 | // return ret; | ||
| 1192 | //} | ||
| 1193 | |||
| 1194 | QT_END_NAMESPACE |
src/gui/image/qpixmap_iphone_p.h
(134 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #ifndef QPIXMAP_IPHONE_P_H | ||
| 43 | #define QPIXMAP_IPHONE_P_H | ||
| 44 | |||
| 45 | // | ||
| 46 | // W A R N I N G | ||
| 47 | // ------------- | ||
| 48 | // | ||
| 49 | // This file is not part of the Qt API. It exists purely as an | ||
| 50 | // implementation detail. This header file may change from version to | ||
| 51 | // version without notice, or even be removed. | ||
| 52 | // | ||
| 53 | // We mean it. | ||
| 54 | // | ||
| 55 | |||
| 56 | #include <QtGui/private/qpixmapdata_p.h> | ||
| 57 | #include <QtGui/private/qpixmapdatafactory_p.h> | ||
| 58 | #include <QtGui/private/qt_iphone_p.h> | ||
| 59 | |||
| 60 | QT_BEGIN_NAMESPACE | ||
| 61 | |||
| 62 | class QIPhonePixmapData : public QPixmapData | ||
| 63 | { | ||
| 64 | public: | ||
| 65 | QIPhonePixmapData(PixelType type); | ||
| 66 | ~QIPhonePixmapData(); | ||
| 67 | |||
| 68 | // QPixmapData *createCompatiblePixmapData() const; | ||
| 69 | |||
| 70 | void resize(int width, int height); | ||
| 71 | void fromImage(const QImage &image, Qt::ImageConversionFlags flags); | ||
| 72 | // void copy(const QPixmapData *data, const QRect &rect); | ||
| 73 | // bool scroll(int dx, int dy, const QRect &rect); | ||
| 74 | |||
| 75 | int metric(QPaintDevice::PaintDeviceMetric metric) const; | ||
| 76 | void fill(const QColor &color); | ||
| 77 | // QBitmap mask() const; | ||
| 78 | // void setMask(const QBitmap &mask); | ||
| 79 | bool hasAlphaChannel() const; | ||
| 80 | //// QPixmap transformed(const QTransform &matrix, | ||
| 81 | //// Qt::TransformationMode mode) const; | ||
| 82 | // void setAlphaChannel(const QPixmap &alphaChannel); | ||
| 83 | // QPixmap alphaChannel() const; | ||
| 84 | QImage toImage() const; | ||
| 85 | QPaintEngine* paintEngine() const; | ||
| 86 | |||
| 87 | private: | ||
| 88 | |||
| 89 | // uint has_alpha : 1, has_mask : 1, uninit : 1; | ||
| 90 | |||
| 91 | // void macSetHasAlpha(bool b); | ||
| 92 | // void macGetAlphaChannel(QMacPixmapData *, bool asMask) const; | ||
| 93 | // void macSetAlphaChannel(const QMacPixmapData *, bool asMask); | ||
| 94 | // void macCreateCGImageRef(); | ||
| 95 | // void macCreatePixels(); | ||
| 96 | // void macReleaseCGImageRef(); | ||
| 97 | /* | ||
| 98 | pixels stores the pixmap data. pixelsToFree is either 0 or some memory | ||
| 99 | block that was bound to a CGImageRef and released, and for which the | ||
| 100 | release callback has been called. There are two uses to pixelsToFree: | ||
| 101 | |||
| 102 | 1. If pixels == pixelsToFree, then we know that the CGImageRef is done\ | ||
| 103 | with the data and we can modify pixels without breaking CGImageRef's | ||
| 104 | mutability invariant. | ||
| 105 | |||
| 106 | 2. If pixels != pixelsToFree and pixelsToFree != 0, then we can reuse | ||
| 107 | pixelsToFree later on instead of malloc'ing memory. | ||
| 108 | */ | ||
| 109 | // quint32 *pixels; | ||
| 110 | // uint pixelsSize; | ||
| 111 | // quint32 *pixelsToFree; | ||
| 112 | // uint bytesPerRow; | ||
| 113 | // QRectF cg_mask_rect; | ||
| 114 | // CGImageRef cg_data, cg_dataBeingReleased, cg_mask; | ||
| 115 | // static QSet<QMacPixmapData*> validDataPointers; | ||
| 116 | |||
| 117 | // QPaintEngine *pengine; | ||
| 118 | |||
| 119 | // friend class QPixmap; | ||
| 120 | // friend class QRasterBuffer; | ||
| 121 | // friend class QRasterPaintEngine; | ||
| 122 | // friend class QCoreGraphicsPaintEngine; | ||
| 123 | // friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&); | ||
| 124 | // friend quint32 *qt_mac_pixmap_get_base(const QPixmap*); | ||
| 125 | // friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*); | ||
| 126 | // friend void qt_mac_cgimage_data_free(void *, const void*, size_t); | ||
| 127 | // friend IconRef qt_mac_create_iconref(const QPixmap&); | ||
| 128 | // friend CGContextRef qt_mac_cg_context(const QPaintDevice*); | ||
| 129 | // friend QColor qcolorForThemeTextColor(ThemeTextColor themeColor); | ||
| 130 | }; | ||
| 131 | |||
| 132 | QT_END_NAMESPACE | ||
| 133 | |||
| 134 | #endif // QPIXMAP_IPHONE_P_H |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include <qvarlengtharray.h> | ||
| 43 | #include <qwidget.h> | ||
| 44 | #include <private/qiphoneinputcontext_p.h> | ||
| 45 | #include "qtextformat.h" | ||
| 46 | #include <qdebug.h> | ||
| 47 | #include <private/qapplication_p.h> | ||
| 48 | #include <private/qkeymapper_p.h> | ||
| 49 | |||
| 50 | QT_BEGIN_NAMESPACE | ||
| 51 | |||
| 52 | //extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); | ||
| 53 | // | ||
| 54 | //#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) | ||
| 55 | //# define typeRefCon typeSInt32 | ||
| 56 | //# define typeByteCount typeSInt32 | ||
| 57 | //#endif | ||
| 58 | // | ||
| 59 | //QMacInputContext::QMacInputContext(QObject *parent) | ||
| 60 | // : QInputContext(parent), composing(false), recursionGuard(false), textDocument(0), | ||
| 61 | // keydownEvent(0) | ||
| 62 | //{ | ||
| 63 | //// createTextDocument(); | ||
| 64 | //} | ||
| 65 | // | ||
| 66 | //QMacInputContext::~QMacInputContext() | ||
| 67 | //{ | ||
| 68 | //#ifndef QT_MAC_USE_COCOA | ||
| 69 | // if(textDocument) | ||
| 70 | // DeleteTSMDocument(textDocument); | ||
| 71 | //#endif | ||
| 72 | //} | ||
| 73 | // | ||
| 74 | //void | ||
| 75 | //QMacInputContext::createTextDocument() | ||
| 76 | //{ | ||
| 77 | //#ifndef QT_MAC_USE_COCOA | ||
| 78 | // if(!textDocument) { | ||
| 79 | // InterfaceTypeList itl = { kUnicodeDocument }; | ||
| 80 | // NewTSMDocument(1, itl, &textDocument, SRefCon(this)); | ||
| 81 | // } | ||
| 82 | //#endif | ||
| 83 | //} | ||
| 84 | // | ||
| 85 | // | ||
| 86 | //QString QMacInputContext::language() | ||
| 87 | //{ | ||
| 88 | // return QString(); | ||
| 89 | //} | ||
| 90 | // | ||
| 91 | // | ||
| 92 | //void QMacInputContext::mouseHandler(int pos, QMouseEvent *e) | ||
| 93 | //{ | ||
| 94 | //#ifndef QT_MAC_USE_COCOA | ||
| 95 | // if(e->type() != QEvent::MouseButtonPress) | ||
| 96 | // return; | ||
| 97 | // | ||
| 98 | // if (!composing) | ||
| 99 | // return; | ||
| 100 | // if (pos < 0 || pos > currentText.length()) | ||
| 101 | // reset(); | ||
| 102 | // // ##### handle mouse position | ||
| 103 | //#else | ||
| 104 | // Q_UNUSED(pos); | ||
| 105 | // Q_UNUSED(e); | ||
| 106 | //#endif | ||
| 107 | //} | ||
| 108 | // | ||
| 109 | //#if !defined QT_MAC_USE_COCOA | ||
| 110 | // | ||
| 111 | //static QTextFormat qt_mac_compose_format() | ||
| 112 | //{ | ||
| 113 | // QTextCharFormat ret; | ||
| 114 | // ret.setFontUnderline(true); | ||
| 115 | // return ret; | ||
| 116 | //} | ||
| 117 | // | ||
| 118 | //void QMacInputContext::reset() | ||
| 119 | //{ | ||
| 120 | // if (recursionGuard) | ||
| 121 | // return; | ||
| 122 | // if (!currentText.isEmpty()){ | ||
| 123 | // QInputMethodEvent e; | ||
| 124 | // e.setCommitString(currentText); | ||
| 125 | // qt_sendSpontaneousEvent(focusWidget(), &e); | ||
| 126 | // currentText = QString(); | ||
| 127 | // } | ||
| 128 | // recursionGuard = true; | ||
| 129 | // createTextDocument(); | ||
| 130 | // composing = false; | ||
| 131 | // ActivateTSMDocument(textDocument); | ||
| 132 | // FixTSMDocument(textDocument); | ||
| 133 | // recursionGuard = false; | ||
| 134 | //} | ||
| 135 | // | ||
| 136 | //bool QMacInputContext::isComposing() const | ||
| 137 | //{ | ||
| 138 | // return composing; | ||
| 139 | //} | ||
| 140 | //#endif | ||
| 141 | // | ||
| 142 | //void QMacInputContext::setFocusWidget(QWidget *w) | ||
| 143 | //{ | ||
| 144 | // createTextDocument(); | ||
| 145 | //#ifndef QT_MAC_USE_COCOA | ||
| 146 | // if(w) | ||
| 147 | // ActivateTSMDocument(textDocument); | ||
| 148 | // else | ||
| 149 | // DeactivateTSMDocument(textDocument); | ||
| 150 | //#endif | ||
| 151 | // QInputContext::setFocusWidget(w); | ||
| 152 | //} | ||
| 153 | // | ||
| 154 | // | ||
| 155 | //#ifndef QT_MAC_USE_COCOA | ||
| 156 | //static EventTypeSpec input_events[] = { | ||
| 157 | // { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, | ||
| 158 | // { kEventClassTextInput, kEventTextInputOffsetToPos }, | ||
| 159 | // { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } | ||
| 160 | //}; | ||
| 161 | //static EventHandlerUPP input_proc_handlerUPP = 0; | ||
| 162 | //static EventHandlerRef input_proc_handler = 0; | ||
| 163 | //#endif | ||
| 164 | // | ||
| 165 | //void | ||
| 166 | //QMacInputContext::initialize() | ||
| 167 | //{ | ||
| 168 | //#ifndef QT_MAC_USE_COCOA | ||
| 169 | // if(!input_proc_handler) { | ||
| 170 | // input_proc_handlerUPP = NewEventHandlerUPP(QMacInputContext::globalEventProcessor); | ||
| 171 | // InstallEventHandler(GetApplicationEventTarget(), input_proc_handlerUPP, | ||
| 172 | // GetEventTypeCount(input_events), input_events, | ||
| 173 | // 0, &input_proc_handler); | ||
| 174 | // } | ||
| 175 | //#endif | ||
| 176 | //} | ||
| 177 | // | ||
| 178 | //void | ||
| 179 | //QMacInputContext::cleanup() | ||
| 180 | //{ | ||
| 181 | //#ifndef QT_MAC_USE_COCOA | ||
| 182 | // if(input_proc_handler) { | ||
| 183 | // RemoveEventHandler(input_proc_handler); | ||
| 184 | // input_proc_handler = 0; | ||
| 185 | // } | ||
| 186 | // if(input_proc_handlerUPP) { | ||
| 187 | // DisposeEventHandlerUPP(input_proc_handlerUPP); | ||
| 188 | // input_proc_handlerUPP = 0; | ||
| 189 | // } | ||
| 190 | //#endif | ||
| 191 | //} | ||
| 192 | // | ||
| 193 | //void QMacInputContext::setLastKeydownEvent(EventRef event) | ||
| 194 | //{ | ||
| 195 | // EventRef tmpEvent = keydownEvent; | ||
| 196 | // keydownEvent = event; | ||
| 197 | // if (keydownEvent) | ||
| 198 | // RetainEvent(keydownEvent); | ||
| 199 | // if (tmpEvent) | ||
| 200 | // ReleaseEvent(tmpEvent); | ||
| 201 | //} | ||
| 202 | // | ||
| 203 | //OSStatus | ||
| 204 | //QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void *) | ||
| 205 | //{ | ||
| 206 | //#ifndef QT_MAC_USE_COCOA | ||
| 207 | // QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData); | ||
| 208 | // | ||
| 209 | // SRefCon refcon = 0; | ||
| 210 | // GetEventParameter(event, kEventParamTextInputSendRefCon, typeRefCon, 0, | ||
| 211 | // sizeof(refcon), 0, &refcon); | ||
| 212 | // QMacInputContext *context = reinterpret_cast<QMacInputContext*>(refcon); | ||
| 213 | // | ||
| 214 | // bool handled_event=true; | ||
| 215 | // UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); | ||
| 216 | // switch(eclass) { | ||
| 217 | // case kEventClassTextInput: { | ||
| 218 | // handled_event = false; | ||
| 219 | // QWidget *widget = QApplicationPrivate::focus_widget; | ||
| 220 | // bool canCompose = widget && (!context || widget->inputContext() == context) | ||
| 221 | // && !(widget->inputMethodHints() & Qt::ImhDigitsOnly | ||
| 222 | // || widget->inputMethodHints() & Qt::ImhFormattedNumbersOnly | ||
| 223 | // || widget->inputMethodHints() & Qt::ImhHiddenText); | ||
| 224 | // if(!canCompose) { | ||
| 225 | // handled_event = false; | ||
| 226 | // } else if(ekind == kEventTextInputOffsetToPos) { | ||
| 227 | // if(!widget->testAttribute(Qt::WA_InputMethodEnabled)) { | ||
| 228 | // handled_event = false; | ||
| 229 | // break; | ||
| 230 | // } | ||
| 231 | // | ||
| 232 | // QRect mr(widget->inputMethodQuery(Qt::ImMicroFocus).toRect()); | ||
| 233 | // QPoint mp(widget->mapToGlobal(QPoint(mr.topLeft()))); | ||
| 234 | // Point pt; | ||
| 235 | // pt.h = mp.x(); | ||
| 236 | // pt.v = mp.y() + mr.height(); | ||
| 237 | // SetEventParameter(event, kEventParamTextInputReplyPoint, typeQDPoint, | ||
| 238 | // sizeof(pt), &pt); | ||
| 239 | // handled_event = true; | ||
| 240 | // } else if(ekind == kEventTextInputUpdateActiveInputArea) { | ||
| 241 | // if(!widget->testAttribute(Qt::WA_InputMethodEnabled)) { | ||
| 242 | // handled_event = false; | ||
| 243 | // break; | ||
| 244 | // } | ||
| 245 | // | ||
| 246 | // if (context->recursionGuard) | ||
| 247 | // break; | ||
| 248 | // | ||
| 249 | // ByteCount unilen = 0; | ||
| 250 | // GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, | ||
| 251 | // 0, 0, &unilen, 0); | ||
| 252 | // UniChar *unicode = (UniChar*)NewPtr(unilen); | ||
| 253 | // GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, | ||
| 254 | // 0, unilen, 0, unicode); | ||
| 255 | // QString text((QChar*)unicode, unilen / sizeof(UniChar)); | ||
| 256 | // DisposePtr((char*)unicode); | ||
| 257 | // | ||
| 258 | // ByteCount fixed_length = 0; | ||
| 259 | // GetEventParameter(event, kEventParamTextInputSendFixLen, typeByteCount, 0, | ||
| 260 | // sizeof(fixed_length), 0, &fixed_length); | ||
| 261 | // if(fixed_length == ULONG_MAX || fixed_length == unilen) { | ||
| 262 | // QInputMethodEvent e; | ||
| 263 | // e.setCommitString(text); | ||
| 264 | // context->currentText = QString(); | ||
| 265 | // qt_sendSpontaneousEvent(context->focusWidget(), &e); | ||
| 266 | // handled_event = true; | ||
| 267 | // context->reset(); | ||
| 268 | // } else { | ||
| 269 | // ByteCount rngSize = 0; | ||
| 270 | // OSStatus err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, 0, | ||
| 271 | // 0, &rngSize, 0); | ||
| 272 | // QVarLengthArray<TextRangeArray> highlight(rngSize); | ||
| 273 | // if (noErr == err) { | ||
| 274 | // err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, 0, | ||
| 275 | // rngSize, &rngSize, highlight.data()); | ||
| 276 | // } | ||
| 277 | // context->composing = true; | ||
| 278 | // if(fixed_length > 0) { | ||
| 279 | // const int qFixedLength = fixed_length / sizeof(UniChar); | ||
| 280 | // QList<QInputMethodEvent::Attribute> attrs; | ||
| 281 | // attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, | ||
| 282 | // qFixedLength, text.length()-qFixedLength, | ||
| 283 | // qt_mac_compose_format()); | ||
| 284 | // QInputMethodEvent e(text, attrs); | ||
| 285 | // context->currentText = text; | ||
| 286 | // e.setCommitString(text.left(qFixedLength), 0, qFixedLength); | ||
| 287 | // qt_sendSpontaneousEvent(widget, &e); | ||
| 288 | // handled_event = true; | ||
| 289 | // } else { | ||
| 290 | // /* Apple's enums that they have removed from Tiger :( | ||
| 291 | // enum { | ||
| 292 | // kCaretPosition = 1, | ||
| 293 | // kRawText = 2, | ||
| 294 | // kSelectedRawText = 3, | ||
| 295 | // kConvertedText = 4, | ||
| 296 | // kSelectedConvertedText = 5, | ||
| 297 | // kBlockFillText = 6, | ||
| 298 | // kOutlineText = 7, | ||
| 299 | // kSelectedText = 8 | ||
| 300 | // }; | ||
| 301 | // */ | ||
| 302 | //#ifndef kConvertedText | ||
| 303 | //#define kConvertedText 4 | ||
| 304 | //#endif | ||
| 305 | //#ifndef kCaretPosition | ||
| 306 | //#define kCaretPosition 1 | ||
| 307 | //#endif | ||
| 308 | // QList<QInputMethodEvent::Attribute> attrs; | ||
| 309 | // if (!highlight.isEmpty()) { | ||
| 310 | // TextRangeArray *data = highlight.data(); | ||
| 311 | // for (int i = 0; i < data->fNumOfRanges; ++i) { | ||
| 312 | // int start = data->fRange[i].fStart / sizeof(UniChar); | ||
| 313 | // int len = (data->fRange[i].fEnd - data->fRange[i].fStart) / sizeof(UniChar); | ||
| 314 | // if (data->fRange[i].fHiliteStyle == kCaretPosition) { | ||
| 315 | // attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, start, 0, QVariant()); | ||
| 316 | // continue; | ||
| 317 | // } | ||
| 318 | // QTextCharFormat format; | ||
| 319 | // format.setFontUnderline(true); | ||
| 320 | // if (data->fRange[i].fHiliteStyle == kConvertedText) | ||
| 321 | // format.setUnderlineColor(Qt::gray); | ||
| 322 | // else | ||
| 323 | // format.setUnderlineColor(Qt::black); | ||
| 324 | // attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, len, format); | ||
| 325 | // } | ||
| 326 | // } else { | ||
| 327 | // attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, | ||
| 328 | // 0, text.length(), qt_mac_compose_format()); | ||
| 329 | // } | ||
| 330 | // context->currentText = text; | ||
| 331 | // QInputMethodEvent e(text, attrs); | ||
| 332 | // qt_sendSpontaneousEvent(widget, &e); | ||
| 333 | // handled_event = true; | ||
| 334 | // } | ||
| 335 | // } | ||
| 336 | //#if 0 | ||
| 337 | // if(!context->composing) | ||
| 338 | // handled_event = false; | ||
| 339 | //#endif | ||
| 340 | // | ||
| 341 | // extern bool qt_mac_eat_unicode_key; //qapplication_mac.cpp | ||
| 342 | // qt_mac_eat_unicode_key = handled_event; | ||
| 343 | // } else if(ekind == kEventTextInputUnicodeForKeyEvent) { | ||
| 344 | // EventRef key_ev = 0; | ||
| 345 | // GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, 0, | ||
| 346 | // sizeof(key_ev), 0, &key_ev); | ||
| 347 | // QString text; | ||
| 348 | // ByteCount unilen = 0; | ||
| 349 | // if(GetEventParameter(key_ev, kEventParamKeyUnicodes, typeUnicodeText, 0, 0, &unilen, 0) == noErr) { | ||
| 350 | // UniChar *unicode = (UniChar*)NewPtr(unilen); | ||
| 351 | // GetEventParameter(key_ev, kEventParamKeyUnicodes, typeUnicodeText, 0, unilen, 0, unicode); | ||
| 352 | // text = QString((QChar*)unicode, unilen / sizeof(UniChar)); | ||
| 353 | // DisposePtr((char*)unicode); | ||
| 354 | // } | ||
| 355 | // unsigned char chr = 0; | ||
| 356 | // GetEventParameter(key_ev, kEventParamKeyMacCharCodes, typeChar, 0, sizeof(chr), 0, &chr); | ||
| 357 | // if(!chr || chr >= 128 || (text.length() > 0 && (text.length() > 1 || text.at(0) != QLatin1Char(chr)))) | ||
| 358 | // handled_event = !widget->testAttribute(Qt::WA_InputMethodEnabled); | ||
| 359 | // QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext()); | ||
| 360 | // if (context && context->lastKeydownEvent()) { | ||
| 361 | // qt_keymapper_private()->translateKeyEvent(widget, 0, context->lastKeydownEvent(), | ||
| 362 | // 0, false); | ||
| 363 | // context->setLastKeydownEvent(0); | ||
| 364 | // } | ||
| 365 | // } | ||
| 366 | // break; } | ||
| 367 | // default: | ||
| 368 | // break; | ||
| 369 | // } | ||
| 370 | // if(!handled_event) //let the event go through | ||
| 371 | // return eventNotHandledErr; | ||
| 372 | //#else | ||
| 373 | // Q_UNUSED(event); | ||
| 374 | //#endif | ||
| 375 | // return noErr; //we eat the event | ||
| 376 | //} | ||
| 377 | |||
| 378 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #ifndef QMACINPUTCONTEXT_P_H | ||
| 43 | #define QMACINPUTCONTEXT_P_H | ||
| 44 | |||
| 45 | // | ||
| 46 | // W A R N I N G | ||
| 47 | // ------------- | ||
| 48 | // | ||
| 49 | // This file is not part of the Qt API. It exists purely as an | ||
| 50 | // implementation detail. This header file may change from version to | ||
| 51 | // version without notice, or even be removed. | ||
| 52 | // | ||
| 53 | // We mean it. | ||
| 54 | // | ||
| 55 | |||
| 56 | #include "QtGui/qinputcontext.h" | ||
| 57 | #include "private/qt_iphone_p.h" | ||
| 58 | |||
| 59 | QT_BEGIN_NAMESPACE | ||
| 60 | |||
| 61 | class Q_GUI_EXPORT QMacInputContext : public QInputContext | ||
| 62 | { | ||
| 63 | Q_OBJECT | ||
| 64 | // //Q_DECLARE_PRIVATE(QMacInputContext) | ||
| 65 | // void createTextDocument(); | ||
| 66 | //public: | ||
| 67 | // explicit QMacInputContext(QObject* parent = 0); | ||
| 68 | // virtual ~QMacInputContext(); | ||
| 69 | // | ||
| 70 | // virtual void setFocusWidget(QWidget *w); | ||
| 71 | // virtual QString identifierName() { return QLatin1String("mac"); } | ||
| 72 | // virtual QString language(); | ||
| 73 | // | ||
| 74 | // virtual void reset(); | ||
| 75 | // | ||
| 76 | // virtual bool isComposing() const; | ||
| 77 | // | ||
| 78 | // static OSStatus globalEventProcessor(EventHandlerCallRef, EventRef, void *); | ||
| 79 | // static void initialize(); | ||
| 80 | // static void cleanup(); | ||
| 81 | // | ||
| 82 | // EventRef lastKeydownEvent() { return keydownEvent; } | ||
| 83 | // void setLastKeydownEvent(EventRef); | ||
| 84 | // | ||
| 85 | //protected: | ||
| 86 | // void mouseHandler(int pos, QMouseEvent *); | ||
| 87 | //private: | ||
| 88 | // bool composing; | ||
| 89 | // bool recursionGuard; | ||
| 90 | // TSMDocumentID textDocument; | ||
| 91 | // QString currentText; | ||
| 92 | // EventRef keydownEvent; | ||
| 93 | }; | ||
| 94 | |||
| 95 | QT_END_NAMESPACE | ||
| 96 | |||
| 97 | #endif // QMACINPUTCONTEXT_P_H |
src/gui/kernel/iphone.pri
(1 / 1)
|   | |||
| 1 | 1 | !x11:!embedded:iphone { | |
| 2 | LIBS_PRIVATE += -framework CoreFoundation -lz | ||
| 2 | LIBS_PRIVATE += -framework CoreFoundation -framework Foundation -framework UIKit -lobjc -lz | ||
| 3 | 3 | } |
src/gui/kernel/kernel.pri
(4 / 6)
|   | |||
| 195 | 195 | ||
| 196 | 196 | iphone { | |
| 197 | 197 | ||
| 198 | SOURCES += \ | ||
| 199 | kernel/qclipboard_iphone.cpp \ | ||
| 200 | kernel/qmime_iphone.cpp \ | ||
| 201 | kernel/qt_iphone.cpp \ | ||
| 202 | kernel/qkeymapper_iphone.cpp | ||
| 203 | |||
| 204 | 198 | OBJECTIVE_HEADERS += \ | |
| 205 | 199 | kernel/qcocoawindow_iphone_p.h \ | |
| 206 | 200 | kernel/qcocoawindowdelegate_iphone_p.h \ | |
| … | … | ||
| 205 | 205 | kernel/qmultitouch_iphone_p.h | |
| 206 | 206 | ||
| 207 | 207 | OBJECTIVE_SOURCES += \ | |
| 208 | kernel/qclipboard_iphone.mm \ | ||
| 209 | kernel/qmime_iphone.mm \ | ||
| 210 | kernel/qt_iphone.mm \ | ||
| 211 | kernel/qkeymapper_iphone.mm \ | ||
| 208 | 212 | kernel/qcursor_iphone.mm \ | |
| 209 | 213 | kernel/qdnd_iphone.mm \ | |
| 210 | 214 | kernel/qsound_iphone.mm \ |
|   | |||
| 69 | 69 | ||
| 70 | 70 | QT_MODULE(Gui) | |
| 71 | 71 | ||
| 72 | #if defined(Q_WS_IPHONE) | ||
| 73 | Q_GUI_EXPORT int QiPhoneInit(int argc, char **argv); | ||
| 74 | #endif | ||
| 75 | |||
| 72 | 76 | class QSessionManager; | |
| 73 | 77 | class QDesktopWidget; | |
| 74 | 78 | class QStyle; |
src/gui/kernel/qapplication_iphone.mm
(3088 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | // must bring in some defines for CocoaTouch | ||
| 77 | #include "qglobal.h" | ||
| 78 | #import <Foundation/Foundation.h> | ||
| 79 | #import <UIKit/UIKit.h> | ||
| 80 | |||
| 81 | #include "qapplication.h" | ||
| 82 | #include "qbitarray.h" | ||
| 83 | #include "qclipboard.h" | ||
| 84 | #include "qcursor.h" | ||
| 85 | #include "qdatastream.h" | ||
| 86 | #include "qdatetime.h" | ||
| 87 | #include "qdesktopwidget.h" | ||
| 88 | #include "qdockwidget.h" | ||
| 89 | #include "qevent.h" | ||
| 90 | #include "qhash.h" | ||
| 91 | #include "qlayout.h" | ||
| 92 | #include "qmenubar.h" | ||
| 93 | #include "qmessagebox.h" | ||
| 94 | #include "qmime.h" | ||
| 95 | #include "qpixmapcache.h" | ||
| 96 | #include "qpointer.h" | ||
| 97 | #include "qsessionmanager.h" | ||
| 98 | #include "qsettings.h" | ||
| 99 | #include "qsocketnotifier.h" | ||
| 100 | #include "qstyle.h" | ||
| 101 | #include "qstylefactory.h" | ||
| 102 | #include "qtextcodec.h" | ||
| 103 | #include "qtoolbar.h" | ||
| 104 | #include "qvariant.h" | ||
| 105 | #include "qwidget.h" | ||
| 106 | #include "qcolormap.h" | ||
| 107 | #include "qdir.h" | ||
| 108 | #include "qdebug.h" | ||
| 109 | #include "qtimer.h" | ||
| 110 | #include "qurl.h" | ||
| 111 | #include "private/qiphoneinputcontext_p.h" | ||
| 112 | #include "private/qpaintengine_iphone_p.h" | ||
| 113 | #include "private/qcursor_p.h" | ||
| 114 | #include "private/qapplication_p.h" | ||
| 115 | #include "private/qcolor_p.h" | ||
| 116 | #include "private/qwidget_p.h" | ||
| 117 | #include "private/qkeymapper_p.h" | ||
| 118 | #include "private/qeventdispatcher_iphone_p.h" | ||
| 119 | #include "private/qeventdispatcher_unix_p.h" | ||
| 120 | #include <private/qcocoamenuloader_iphone_p.h> | ||
| 121 | #include <private/qcocoaapplication_iphone_p.h> | ||
| 122 | #include <private/qcocoaapplicationdelegate_iphone_p.h> | ||
| 123 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 124 | #include <private/qcocoawindow_iphone_p.h> | ||
| 125 | #include <private/qpixmap_iphone_p.h> | ||
| 126 | #include <private/qdesktopwidget_iphone_p.h> | ||
| 127 | #include <private/qeventdispatcher_iphone_p.h> | ||
| 128 | #include <qvarlengtharray.h> | ||
| 129 | |||
| 130 | #ifndef QT_NO_ACCESSIBILITY | ||
| 131 | # include "qaccessible.h" | ||
| 132 | #endif | ||
| 133 | |||
| 134 | #ifndef QT_NO_THREAD | ||
| 135 | # include "qmutex.h" | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #include <unistd.h> | ||
| 139 | #include <string.h> | ||
| 140 | #include <sys/time.h> | ||
| 141 | #include <sys/select.h> | ||
| 142 | |||
| 143 | /***************************************************************************** | ||
| 144 | QApplication debug facilities | ||
| 145 | *****************************************************************************/ | ||
| 146 | //#define DEBUG_EVENTS //like EventDebug but more specific to Qt | ||
| 147 | //#define DEBUG_DROPPED_EVENTS | ||
| 148 | //#define DEBUG_MOUSE_MAPS | ||
| 149 | //#define DEBUG_MODAL_EVENTS | ||
| 150 | //#define DEBUG_PLATFORM_SETTINGS | ||
| 151 | |||
| 152 | //#define QMAC_SPEAK_TO_ME | ||
| 153 | //#ifdef QMAC_SPEAK_TO_ME | ||
| 154 | //#include "qregexp.h" | ||
| 155 | //#endif | ||
| 156 | |||
| 157 | //#ifndef kThemeBrushAlternatePrimaryHighlightColor | ||
| 158 | //#define kThemeBrushAlternatePrimaryHighlightColor -5 | ||
| 159 | //#endif | ||
| 160 | |||
| 161 | //#define kCMDeviceUnregisteredNotification CFSTR("CMDeviceUnregisteredNotification") | ||
| 162 | //#define kCMDefaultDeviceNotification CFSTR("CMDefaultDeviceNotification") | ||
| 163 | //#define kCMDeviceProfilesNotification CFSTR("CMDeviceProfilesNotification") | ||
| 164 | //#define kCMDefaultDeviceProfileNotification CFSTR("CMDefaultDeviceProfileNotification") | ||
| 165 | |||
| 166 | QT_BEGIN_NAMESPACE | ||
| 167 | |||
| 168 | //for qt_mac.h | ||
| 169 | //QPaintDevice *qt_mac_safe_pdev = 0; | ||
| 170 | //QList<QMacWindowChangeEvent*> *QMacWindowChangeEvent::change_events = 0; | ||
| 171 | |||
| 172 | /***************************************************************************** | ||
| 173 | Internal variables and functions | ||
| 174 | *****************************************************************************/ | ||
| 175 | |||
| 176 | //static struct { | ||
| 177 | // bool use_qt_time_limit; | ||
| 178 | // QPointer<QWidget> last_widget; | ||
| 179 | // int last_x, last_y; | ||
| 180 | // int last_modifiers, last_button; | ||
| 181 | // EventTime last_time; | ||
| 182 | //} qt_mac_dblclick = { false, 0, -1, -1, 0, 0, -2 }; | ||
| 183 | |||
| 184 | //static bool app_do_modal = false; // modal mode | ||
| 185 | //extern QWidgetList *qt_modal_stack; // stack of modal widgets | ||
| 186 | //extern bool qt_tab_all_widgets; // from qapplication.cpp | ||
| 187 | //bool qt_mac_app_fullscreen = false; | ||
| 188 | //bool qt_scrollbar_jump_to_pos = false; | ||
| 189 | //static bool qt_mac_collapse_on_dblclick = true; | ||
| 190 | //extern int qt_antialiasing_threshold; // from qapplication.cpp | ||
| 191 | QPointer<QWidget> qt_button_down; // widget got last button-down | ||
| 192 | //#ifndef QT_MAC_USE_COCOA | ||
| 193 | //static bool qt_button_down_in_content; // whether the button_down was in the content area. | ||
| 194 | //static bool qt_mac_previous_press_in_popup_mode = false; | ||
| 195 | //static bool qt_mac_no_click_through_mode = false; | ||
| 196 | //static int tablet_button_state = 0; | ||
| 197 | //#endif | ||
| 198 | //QPointer<QWidget> qt_mouseover; | ||
| 199 | //#if defined(QT_DEBUG) | ||
| 200 | //static bool appNoGrab = false; // mouse/keyboard grabbing | ||
| 201 | //#endif | ||
| 202 | //#ifndef QT_MAC_USE_COCOA | ||
| 203 | //static EventHandlerRef app_proc_handler = 0; | ||
| 204 | //static EventHandlerUPP app_proc_handlerUPP = 0; | ||
| 205 | //#endif | ||
| 206 | //static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL; | ||
| 207 | //static EventHandlerRef tablet_proximity_handler = 0; | ||
| 208 | //static EventHandlerUPP tablet_proximity_UPP = 0; | ||
| 209 | //bool QApplicationPrivate::native_modal_dialog_active; | ||
| 210 | Q_GUI_EXPORT int qt_argc = 0; | ||
| 211 | Q_GUI_EXPORT char** qt_argv = 0; | ||
| 212 | |||
| 213 | Q_GUI_EXPORT bool qt_applefontsmoothing_enabled; | ||
| 214 | |||
| 215 | /***************************************************************************** | ||
| 216 | External functions | ||
| 217 | *****************************************************************************/ | ||
| 218 | //extern void qt_mac_beep(); //qsound_mac.mm | ||
| 219 | //extern Qt::KeyboardModifiers qt_mac_get_modifiers(int keys); //qkeymapper_mac.cpp | ||
| 220 | //extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp | ||
| 221 | //extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp | ||
| 222 | //extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.cpp | ||
| 223 | //extern QWidget *qt_mac_find_window(OSWindowRef); //qwidget_mac.cpp | ||
| 224 | //extern void qt_mac_set_cursor(const QCursor *, const QPoint &); //qcursor_mac.cpp | ||
| 225 | //extern bool qt_mac_is_macsheet(const QWidget *); //qwidget_mac.cpp | ||
| 226 | //extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp | ||
| 227 | //extern void qt_mac_command_set_enabled(MenuRef, UInt32, bool); //qmenu_mac.cpp | ||
| 228 | //extern bool qt_sendSpontaneousEvent(QObject *obj, QEvent *event); // qapplication.cpp | ||
| 229 | |||
| 230 | // Forward Decls | ||
| 231 | //void onApplicationWindowChangedActivation( QWidget*widget, bool activated ); | ||
| 232 | //void onApplicationChangedActivation( bool activated ); | ||
| 233 | |||
| 234 | //static void qt_mac_read_fontsmoothing_settings() | ||
| 235 | //{ | ||
| 236 | // NSInteger appleFontSmoothing = [[NSUserDefaults standardUserDefaults] integerForKey:@"AppleFontSmoothing"]; | ||
| 237 | // qt_applefontsmoothing_enabled = (appleFontSmoothing > 0); | ||
| 238 | //} | ||
| 239 | |||
| 240 | //Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) { | ||
| 241 | // OSStatus err; | ||
| 242 | // AEDesc scriptTextDesc; | ||
| 243 | // ComponentInstance theComponent = 0; | ||
| 244 | // OSAID scriptID = kOSANullScript, resultID = kOSANullScript; | ||
| 245 | // | ||
| 246 | // // set up locals to a known state | ||
| 247 | // AECreateDesc(typeNull, 0, 0, &scriptTextDesc); | ||
| 248 | // scriptID = kOSANullScript; | ||
| 249 | // resultID = kOSANullScript; | ||
| 250 | // | ||
| 251 | // // open the scripting component | ||
| 252 | // theComponent = OpenDefaultComponent(kOSAComponentType, typeAppleScript); | ||
| 253 | // if (!theComponent) { | ||
| 254 | // err = paramErr; | ||
| 255 | // goto bail; | ||
| 256 | // } | ||
| 257 | // | ||
| 258 | // // put the script text into an aedesc | ||
| 259 | // err = AECreateDesc(typeUTF8Text, script, script_len, &scriptTextDesc); | ||
| 260 | // if (err != noErr) | ||
| 261 | // goto bail; | ||
| 262 | // | ||
| 263 | // // compile the script | ||
| 264 | // err = OSACompile(theComponent, &scriptTextDesc, kOSAModeNull, &scriptID); | ||
| 265 | // if (err != noErr) | ||
| 266 | // goto bail; | ||
| 267 | // | ||
| 268 | // // run the script | ||
| 269 | // err = OSAExecute(theComponent, scriptID, kOSANullScript, kOSAModeNull, &resultID); | ||
| 270 | // | ||
| 271 | // // collect the results - if any | ||
| 272 | // if (ret) { | ||
| 273 | // AECreateDesc(typeNull, 0, 0, ret); | ||
| 274 | // if (err == errOSAScriptError) | ||
| 275 | // OSAScriptError(theComponent, kOSAErrorMessage, typeChar, ret); | ||
| 276 | // else if (err == noErr && resultID != kOSANullScript) | ||
| 277 | // OSADisplay(theComponent, resultID, typeChar, kOSAModeNull, ret); | ||
| 278 | // } | ||
| 279 | //bail: | ||
| 280 | // AEDisposeDesc(&scriptTextDesc); | ||
| 281 | // if (scriptID != kOSANullScript) | ||
| 282 | // OSADispose(theComponent, scriptID); | ||
| 283 | // if (resultID != kOSANullScript) | ||
| 284 | // OSADispose(theComponent, resultID); | ||
| 285 | // if (theComponent) | ||
| 286 | // CloseComponent(theComponent); | ||
| 287 | // return err == noErr; | ||
| 288 | //} | ||
| 289 | |||
| 290 | //Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, AEDesc *ret) | ||
| 291 | //{ | ||
| 292 | // return qt_mac_execute_apple_script(script, qstrlen(script), ret); | ||
| 293 | //} | ||
| 294 | |||
| 295 | //Q_GUI_EXPORT bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret) | ||
| 296 | //{ | ||
| 297 | // const QByteArray l = script.toUtf8(); return qt_mac_execute_apple_script(l.constData(), l.size(), ret); | ||
| 298 | //} | ||
| 299 | |||
| 300 | /* Resolution change magic */ | ||
| 301 | //void qt_mac_display_change_callbk(CGDirectDisplayID, CGDisplayChangeSummaryFlags flags, void *) | ||
| 302 | //{ | ||
| 303 | //#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) | ||
| 304 | // const bool resized = flags & kCGDisplayDesktopShapeChangedFlag; | ||
| 305 | //#else | ||
| 306 | // Q_UNUSED(flags); | ||
| 307 | // const bool resized = true; | ||
| 308 | //#endif | ||
| 309 | // if (resized && qApp) { | ||
| 310 | // if (QDesktopWidget *dw = qApp->desktop()) { | ||
| 311 | // QResizeEvent *re = new QResizeEvent(dw->size(), dw->size()); | ||
| 312 | // QApplication::postEvent(dw, re); | ||
| 313 | // QCoreGraphicsPaintEngine::cleanUpMacColorSpaces(); | ||
| 314 | // } | ||
| 315 | // } | ||
| 316 | //} | ||
| 317 | |||
| 318 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 319 | //static void qt_mac_debug_palette(const QPalette &pal, const QPalette &pal2, const QString &where) | ||
| 320 | //{ | ||
| 321 | // const char *const groups[] = {"Active", "Disabled", "Inactive" }; | ||
| 322 | // const char *const roles[] = { "WindowText", "Button", "Light", "Midlight", "Dark", "Mid", | ||
| 323 | // "Text", "BrightText", "ButtonText", "Base", "Window", "Shadow", | ||
| 324 | // "Highlight", "HighlightedText", "Link", "LinkVisited" }; | ||
| 325 | // if (!where.isNull()) | ||
| 326 | // qDebug("qt-internal: %s", where.toLatin1().constData()); | ||
| 327 | // for(int grp = 0; grp < QPalette::NColorGroups; grp++) { | ||
| 328 | // for(int role = 0; role < QPalette::NColorRoles; role++) { | ||
| 329 | // QBrush b = pal.brush((QPalette::ColorGroup)grp, (QPalette::ColorRole)role); | ||
| 330 | // QPixmap pm = b.texture(); | ||
| 331 | // qDebug(" %s::%s %d::%d::%d [%p]%s", groups[grp], roles[role], b.color().red(), | ||
| 332 | // b.color().green(), b.color().blue(), pm.isNull() ? 0 : &pm, | ||
| 333 | // pal2.brush((QPalette::ColorGroup)grp, (QPalette::ColorRole)role) != b ? " (*)" : ""); | ||
| 334 | // } | ||
| 335 | // } | ||
| 336 | // | ||
| 337 | //} | ||
| 338 | //#else | ||
| 339 | //#define qt_mac_debug_palette(x, y, z) | ||
| 340 | //#endif | ||
| 341 | |||
| 342 | //raise a notification | ||
| 343 | //#ifndef QT_MAC_USE_COCOA | ||
| 344 | //static NMRec qt_mac_notification = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
| 345 | //#endif | ||
| 346 | //void qt_mac_send_notification() | ||
| 347 | //{ | ||
| 348 | //#ifndef QT_MAC_USE_COCOA | ||
| 349 | // //send it | ||
| 350 | // qt_mac_notification.nmMark = 1; //non-zero magic number | ||
| 351 | // qt_mac_notification.qType = nmType; | ||
| 352 | // NMInstall(&qt_mac_notification); | ||
| 353 | //#else | ||
| 354 | // QMacCocoaAutoReleasePool pool; | ||
| 355 | // [[NSApplication sharedApplication] requestUserAttention:NSInformationalRequest]; | ||
| 356 | //#endif | ||
| 357 | //} | ||
| 358 | |||
| 359 | //void qt_mac_cancel_notification() | ||
| 360 | //{ | ||
| 361 | //#ifndef QT_MAC_USE_COCOA | ||
| 362 | // NMRemove(&qt_mac_notification); | ||
| 363 | //#else | ||
| 364 | // QMacCocoaAutoReleasePool pool; | ||
| 365 | // [[NSApplication sharedApplication] cancelUserAttentionRequest:NSInformationalRequest]; | ||
| 366 | //#endif | ||
| 367 | //} | ||
| 368 | |||
| 369 | //#ifndef QT_MAC_USE_COCOA | ||
| 370 | ////find widget (and part) at a given point | ||
| 371 | //static short qt_mac_window_at(int x, int y, QWidget **w=0) | ||
| 372 | //{ | ||
| 373 | // Point p; | ||
| 374 | // p.h = x; | ||
| 375 | // p.v = y; | ||
| 376 | // OSWindowRef wp; | ||
| 377 | // WindowPartCode wpc; | ||
| 378 | // OSStatus err = FindWindowOfClass(&p, kAllWindowClasses, &wp, &wpc); | ||
| 379 | // if(err != noErr) { | ||
| 380 | // if(w) | ||
| 381 | // (*w) = 0; | ||
| 382 | // return wpc; | ||
| 383 | // } | ||
| 384 | // if(w) { | ||
| 385 | // if(wp) { | ||
| 386 | // *w = qt_mac_find_window(wp); | ||
| 387 | //#if 0 | ||
| 388 | // if(!*w) | ||
| 389 | // qWarning("QApplication: qt_mac_window_at: Couldn't find %d",(int)wp); | ||
| 390 | //#endif | ||
| 391 | // } else { | ||
| 392 | // *w = 0; | ||
| 393 | // } | ||
| 394 | // } | ||
| 395 | // return wpc; | ||
| 396 | //} | ||
| 397 | |||
| 398 | //#endif | ||
| 399 | |||
| 400 | //void qt_mac_set_app_icon(const QPixmap &pixmap) | ||
| 401 | //{ | ||
| 402 | //#ifndef QT_MAC_USE_COCOA | ||
| 403 | // if(pixmap.isNull()) { | ||
| 404 | // RestoreApplicationDockTileImage(); | ||
| 405 | // } else { | ||
| 406 | // CGImageRef img = (CGImageRef)pixmap.macCGHandle(); | ||
| 407 | // SetApplicationDockTileImage(img); | ||
| 408 | // CGImageRelease(img); | ||
| 409 | // } | ||
| 410 | //#else | ||
| 411 | // QMacCocoaAutoReleasePool pool; | ||
| 412 | // NSImage *image = NULL; | ||
| 413 | // if (pixmap.isNull()) { | ||
| 414 | // // Get Application icon from bundle | ||
| 415 | // image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; // released below | ||
| 416 | // } else { | ||
| 417 | // image = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); | ||
| 418 | // } | ||
| 419 | // | ||
| 420 | // [NSApp setApplicationIconImage:image]; | ||
| 421 | // [image release]; | ||
| 422 | //#endif | ||
| 423 | //} | ||
| 424 | |||
| 425 | //Q_GUI_EXPORT void qt_mac_set_press_and_hold_context(bool b) | ||
| 426 | //{ | ||
| 427 | // Q_UNUSED(b); | ||
| 428 | // qWarning("qt_mac_set_press_and_hold_context: This functionality is no longer available"); | ||
| 429 | //} | ||
| 430 | |||
| 431 | //bool qt_nograb() // application no-grab option | ||
| 432 | //{ | ||
| 433 | //#if defined(QT_DEBUG) | ||
| 434 | // return appNoGrab; | ||
| 435 | //#else | ||
| 436 | // return false; | ||
| 437 | //#endif | ||
| 438 | //} | ||
| 439 | |||
| 440 | //void qt_mac_update_os_settings() | ||
| 441 | //{ | ||
| 442 | // if (!qApp) | ||
| 443 | // return; | ||
| 444 | // if (!QApplication::startingUp()) { | ||
| 445 | // static bool needToPolish = true; | ||
| 446 | // if (needToPolish) { | ||
| 447 | // QApplication::style()->polish(qApp); | ||
| 448 | // needToPolish = false; | ||
| 449 | // } | ||
| 450 | // } | ||
| 451 | // //focus mode | ||
| 452 | // /* First worked as of 10.2.3 */ | ||
| 453 | // QSettings appleSettings(QLatin1String("apple.com")); | ||
| 454 | // QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0); | ||
| 455 | // qt_tab_all_widgets = (appleValue.toInt() & 0x2); | ||
| 456 | // //paging mode | ||
| 457 | // /* First worked as of 10.2.3 */ | ||
| 458 | // appleValue = appleSettings.value(QLatin1String("AppleScrollerPagingBehavior"), false); | ||
| 459 | // qt_scrollbar_jump_to_pos = appleValue.toBool(); | ||
| 460 | // //collapse | ||
| 461 | // /* First worked as of 10.3.3 */ | ||
| 462 | // appleValue = appleSettings.value(QLatin1String("AppleMiniaturizeOnDoubleClick"), true); | ||
| 463 | // qt_mac_collapse_on_dblclick = appleValue.toBool(); | ||
| 464 | // | ||
| 465 | // // Anti-aliasing threshold | ||
| 466 | // appleValue = appleSettings.value(QLatin1String("AppleAntiAliasingThreshold")); | ||
| 467 | // if (appleValue.isValid()) | ||
| 468 | // qt_antialiasing_threshold = appleValue.toInt(); | ||
| 469 | // | ||
| 470 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 471 | // qDebug("qt_mac_update_os_settings *********************************************************************"); | ||
| 472 | //#endif | ||
| 473 | // { // setup the global palette | ||
| 474 | // QColor qc; | ||
| 475 | // (void) QApplication::style(); // trigger creation of application style and system palettes | ||
| 476 | // QPalette pal = *QApplicationPrivate::sys_pal; | ||
| 477 | // | ||
| 478 | // pal.setBrush( QPalette::Active, QPalette::Highlight, qcolorForTheme(kThemeBrushPrimaryHighlightColor) ); | ||
| 479 | // pal.setBrush( QPalette::Inactive, QPalette::Highlight, qcolorForTheme(kThemeBrushSecondaryHighlightColor) ); | ||
| 480 | // | ||
| 481 | // pal.setBrush( QPalette::Disabled, QPalette::Highlight, qcolorForTheme(kThemeBrushSecondaryHighlightColor) ); | ||
| 482 | // pal.setBrush( QPalette::Active, QPalette::Shadow, qcolorForTheme(kThemeBrushButtonActiveDarkShadow) ); | ||
| 483 | // | ||
| 484 | // pal.setBrush( QPalette::Inactive, QPalette::Shadow, qcolorForTheme(kThemeBrushButtonInactiveDarkShadow) ); | ||
| 485 | // pal.setBrush( QPalette::Disabled, QPalette::Shadow, qcolorForTheme(kThemeBrushButtonInactiveDarkShadow) ); | ||
| 486 | // | ||
| 487 | // qc = qcolorForThemeTextColor(kThemeTextColorDialogActive); | ||
| 488 | // pal.setColor(QPalette::Active, QPalette::Text, qc); | ||
| 489 | // pal.setColor(QPalette::Active, QPalette::WindowText, qc); | ||
| 490 | // pal.setColor(QPalette::Active, QPalette::HighlightedText, qc); | ||
| 491 | // | ||
| 492 | // qc = qcolorForThemeTextColor(kThemeTextColorDialogInactive); | ||
| 493 | // pal.setColor(QPalette::Inactive, QPalette::Text, qc); | ||
| 494 | // pal.setColor(QPalette::Inactive, QPalette::WindowText, qc); | ||
| 495 | // pal.setColor(QPalette::Inactive, QPalette::HighlightedText, qc); | ||
| 496 | // pal.setColor(QPalette::Disabled, QPalette::Text, qc); | ||
| 497 | // pal.setColor(QPalette::Disabled, QPalette::WindowText, qc); | ||
| 498 | // pal.setColor(QPalette::Disabled, QPalette::HighlightedText, qc); | ||
| 499 | // pal.setBrush(QPalette::ToolTipBase, QColor(255, 255, 199)); | ||
| 500 | // | ||
| 501 | // if (!QApplicationPrivate::sys_pal || *QApplicationPrivate::sys_pal != pal) { | ||
| 502 | // QApplicationPrivate::setSystemPalette(pal); | ||
| 503 | // QApplication::setPalette(pal); | ||
| 504 | // } | ||
| 505 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 506 | // qt_mac_debug_palette(pal, QApplication::palette(), "Global Palette"); | ||
| 507 | //#endif | ||
| 508 | // } | ||
| 509 | // | ||
| 510 | // QFont fnt = qfontForThemeFont(kThemeApplicationFont); | ||
| 511 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 512 | // qDebug("qt-internal: Font for Application [%s::%d::%d::%d]", | ||
| 513 | // fnt.family().toLatin1().constData(), fnt.pointSize(), fnt.bold(), fnt.italic()); | ||
| 514 | //#endif | ||
| 515 | // if (!QApplicationPrivate::sys_font || *QApplicationPrivate::sys_font != fnt) | ||
| 516 | // QApplicationPrivate::setSystemFont(fnt); | ||
| 517 | // | ||
| 518 | // { //setup the fonts | ||
| 519 | // struct FontMap { | ||
| 520 | // FontMap(const char *qc, short fk) : qt_class(qc), font_key(fk) { } | ||
| 521 | // const char *const qt_class; | ||
| 522 | // short font_key; | ||
| 523 | // } mac_widget_fonts[] = { | ||
| 524 | // FontMap("QPushButton", kThemePushButtonFont), | ||
| 525 | // FontMap("QListView", kThemeViewsFont), | ||
| 526 | // FontMap("QListBox", kThemeViewsFont), | ||
| 527 | // FontMap("QTitleBar", kThemeWindowTitleFont), | ||
| 528 | // FontMap("QMenuBar", kThemeMenuTitleFont), | ||
| 529 | // FontMap("QMenu", kThemeMenuItemFont), | ||
| 530 | // FontMap("QComboMenuItem", kThemeSystemFont), | ||
| 531 | // FontMap("QHeaderView", kThemeSmallSystemFont), | ||
| 532 | // FontMap("Q3Header", kThemeSmallSystemFont), | ||
| 533 | // FontMap("QTipLabel", kThemeSmallSystemFont), | ||
| 534 | // FontMap("QLabel", kThemeSystemFont), | ||
| 535 | // FontMap("QToolButton", kThemeSmallSystemFont), | ||
| 536 | // FontMap("QMenuItem", kThemeMenuItemCmdKeyFont), // It doesn't exist, but its unique. | ||
| 537 | // FontMap("QComboLineEdit", kThemeViewsFont), // It doesn't exist, but its unique. | ||
| 538 | // FontMap("QSmallFont", kThemeSmallSystemFont), // It doesn't exist, but its unique. | ||
| 539 | // FontMap("QMiniFont", kThemeMiniSystemFont), // It doesn't exist, but its unique. | ||
| 540 | // FontMap(0, 0) }; | ||
| 541 | // for(int i = 0; mac_widget_fonts[i].qt_class; i++) { | ||
| 542 | // QFont fnt = qfontForThemeFont(mac_widget_fonts[i].font_key); | ||
| 543 | // bool set_font = true; | ||
| 544 | // FontHash *hash = qt_app_fonts_hash(); | ||
| 545 | // if (!hash->isEmpty()) { | ||
| 546 | // FontHash::const_iterator it | ||
| 547 | // = hash->constFind(mac_widget_fonts[i].qt_class); | ||
| 548 | // if (it != hash->constEnd()) | ||
| 549 | // set_font = (fnt != *it); | ||
| 550 | // } | ||
| 551 | // if (set_font) { | ||
| 552 | // QApplication::setFont(fnt, mac_widget_fonts[i].qt_class); | ||
| 553 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 554 | // qDebug("qt-internal: Font for %s [%s::%d::%d::%d]", mac_widget_fonts[i].qt_class, | ||
| 555 | // fnt.family().toLatin1().constData(), fnt.pointSize(), fnt.bold(), fnt.italic()); | ||
| 556 | //#endif | ||
| 557 | // } | ||
| 558 | // } | ||
| 559 | // } | ||
| 560 | // QApplicationPrivate::initializeWidgetPaletteHash(); | ||
| 561 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 562 | // qDebug("qt_mac_update_os_settings END !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | ||
| 563 | //#endif | ||
| 564 | //} | ||
| 565 | |||
| 566 | void QApplicationPrivate::initializeWidgetPaletteHash() | ||
| 567 | { | ||
| 568 | qDebug("QApplicationPrivate::initializeWidgetPaletteHash()"); | ||
| 569 | // { //setup the palette | ||
| 570 | // struct PaletteMap { | ||
| 571 | // inline PaletteMap(const char *qc, ThemeBrush a, ThemeBrush i) : | ||
| 572 | // qt_class(qc), active(a), inactive(i) { } | ||
| 573 | // const char *const qt_class; | ||
| 574 | // ThemeBrush active, inactive; | ||
| 575 | // } mac_widget_colors[] = { | ||
| 576 | // PaletteMap("QToolButton", kThemeTextColorBevelButtonActive, kThemeTextColorBevelButtonInactive), | ||
| 577 | // PaletteMap("QAbstractButton", kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), | ||
| 578 | // PaletteMap("QHeaderView", kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), | ||
| 579 | // PaletteMap("Q3Header", kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive), | ||
| 580 | // PaletteMap("QComboBox", kThemeTextColorPopupButtonActive, kThemeTextColorPopupButtonInactive), | ||
| 581 | // PaletteMap("QAbstractItemView", kThemeTextColorListView, kThemeTextColorDialogInactive), | ||
| 582 | // PaletteMap("QMessageBoxLabel", kThemeTextColorAlertActive, kThemeTextColorAlertInactive), | ||
| 583 | // PaletteMap("QTabBar", kThemeTextColorTabFrontActive, kThemeTextColorTabFrontInactive), | ||
| 584 | // PaletteMap("QLabel", kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive), | ||
| 585 | // PaletteMap("QGroupBox", kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive), | ||
| 586 | // PaletteMap("QMenu", kThemeTextColorPopupLabelActive, kThemeTextColorPopupLabelInactive), | ||
| 587 | // PaletteMap("QTextEdit", 0, 0), | ||
| 588 | // PaletteMap("QTextControl", 0, 0), | ||
| 589 | // PaletteMap("QLineEdit", 0, 0), | ||
| 590 | // PaletteMap(0, 0, 0) }; | ||
| 591 | // QColor qc; | ||
| 592 | // for(int i = 0; mac_widget_colors[i].qt_class; i++) { | ||
| 593 | // QPalette pal; | ||
| 594 | // if (mac_widget_colors[i].active != 0) { | ||
| 595 | // qc = qcolorForThemeTextColor(mac_widget_colors[i].active); | ||
| 596 | // pal.setColor(QPalette::Active, QPalette::Text, qc); | ||
| 597 | // pal.setColor(QPalette::Active, QPalette::WindowText, qc); | ||
| 598 | // pal.setColor(QPalette::Active, QPalette::HighlightedText, qc); | ||
| 599 | // qc = qcolorForThemeTextColor(mac_widget_colors[i].inactive); | ||
| 600 | // pal.setColor(QPalette::Inactive, QPalette::Text, qc); | ||
| 601 | // pal.setColor(QPalette::Disabled, QPalette::Text, qc); | ||
| 602 | // pal.setColor(QPalette::Inactive, QPalette::WindowText, qc); | ||
| 603 | // pal.setColor(QPalette::Disabled, QPalette::WindowText, qc); | ||
| 604 | // pal.setColor(QPalette::Inactive, QPalette::HighlightedText, qc); | ||
| 605 | // pal.setColor(QPalette::Disabled, QPalette::HighlightedText, qc); | ||
| 606 | // } | ||
| 607 | // if (!strcmp(mac_widget_colors[i].qt_class, "QMenu")) { | ||
| 608 | // qc = qcolorForThemeTextColor(kThemeTextColorMenuItemActive); | ||
| 609 | // pal.setBrush(QPalette::ButtonText, qc); | ||
| 610 | // qc = qcolorForThemeTextColor(kThemeTextColorMenuItemSelected); | ||
| 611 | // pal.setBrush(QPalette::HighlightedText, qc); | ||
| 612 | // qc = qcolorForThemeTextColor(kThemeTextColorMenuItemDisabled); | ||
| 613 | // pal.setBrush(QPalette::Disabled, QPalette::Text, qc); | ||
| 614 | // } else if (!strcmp(mac_widget_colors[i].qt_class, "QAbstractButton") | ||
| 615 | // || !strcmp(mac_widget_colors[i].qt_class, "QHeaderView") | ||
| 616 | // || !strcmp(mac_widget_colors[i].qt_class, "Q3Header")) { //special | ||
| 617 | // pal.setColor(QPalette::Disabled, QPalette::ButtonText, | ||
| 618 | // pal.color(QPalette::Disabled, QPalette::Text)); | ||
| 619 | // pal.setColor(QPalette::Inactive, QPalette::ButtonText, | ||
| 620 | // pal.color(QPalette::Inactive, QPalette::Text)); | ||
| 621 | // pal.setColor(QPalette::Active, QPalette::ButtonText, | ||
| 622 | // pal.color(QPalette::Active, QPalette::Text)); | ||
| 623 | // } else if (!strcmp(mac_widget_colors[i].qt_class, "QAbstractItemView")) { | ||
| 624 | // pal.setBrush(QPalette::Active, QPalette::Highlight, | ||
| 625 | // qcolorForTheme(kThemeBrushAlternatePrimaryHighlightColor)); | ||
| 626 | // qc = qcolorForThemeTextColor(kThemeTextColorMenuItemSelected); | ||
| 627 | // pal.setBrush(QPalette::Active, QPalette::HighlightedText, qc); | ||
| 628 | //#if 1 | ||
| 629 | // pal.setBrush(QPalette::Inactive, QPalette::Text, | ||
| 630 | // pal.brush(QPalette::Active, QPalette::Text)); | ||
| 631 | // pal.setBrush(QPalette::Inactive, QPalette::HighlightedText, | ||
| 632 | // pal.brush(QPalette::Active, QPalette::Text)); | ||
| 633 | //#endif | ||
| 634 | // } else if (!strcmp(mac_widget_colors[i].qt_class, "QTextEdit") | ||
| 635 | // || !strcmp(mac_widget_colors[i].qt_class, "QTextControl")) { | ||
| 636 | // pal.setBrush(QPalette::Inactive, QPalette::Text, | ||
| 637 | // pal.brush(QPalette::Active, QPalette::Text)); | ||
| 638 | // pal.setBrush(QPalette::Inactive, QPalette::HighlightedText, | ||
| 639 | // pal.brush(QPalette::Active, QPalette::Text)); | ||
| 640 | // } else if (!strcmp(mac_widget_colors[i].qt_class, "QLineEdit")) { | ||
| 641 | // pal.setBrush(QPalette::Disabled, QPalette::Base, | ||
| 642 | // pal.brush(QPalette::Active, QPalette::Base)); | ||
| 643 | // } | ||
| 644 | // | ||
| 645 | // bool set_palette = true; | ||
| 646 | // PaletteHash *phash = qt_app_palettes_hash(); | ||
| 647 | // if (!phash->isEmpty()) { | ||
| 648 | // PaletteHash::const_iterator it | ||
| 649 | // = phash->constFind(mac_widget_colors[i].qt_class); | ||
| 650 | // if (it != phash->constEnd()) | ||
| 651 | // set_palette = (pal != *it); | ||
| 652 | // } | ||
| 653 | // if (set_palette) { | ||
| 654 | // QApplication::setPalette(pal, mac_widget_colors[i].qt_class); | ||
| 655 | //#ifdef DEBUG_PLATFORM_SETTINGS | ||
| 656 | // qt_mac_debug_palette(pal, QApplication::palette(), QLatin1String("Palette for ") + QString::fromLatin1(mac_widget_colors[i].qt_class)); | ||
| 657 | //#endif | ||
| 658 | // } | ||
| 659 | // } | ||
| 660 | // } | ||
| 661 | } | ||
| 662 | |||
| 663 | //static void qt_mac_event_release(EventRef &event) | ||
| 664 | //{ | ||
| 665 | // ReleaseEvent(event); | ||
| 666 | // event = 0; | ||
| 667 | //} | ||
| 668 | //#ifndef QT_MAC_USE_COCOA | ||
| 669 | //static void qt_mac_event_release(QWidget *w, EventRef &event) | ||
| 670 | //{ | ||
| 671 | // if (event) { | ||
| 672 | // QWidget *widget = 0; | ||
| 673 | // if (GetEventParameter(event, kEventParamQWidget, typeQWidget, 0, sizeof(widget), 0, &widget) == noErr | ||
| 674 | // && w == widget) { | ||
| 675 | // if (IsEventInQueue(GetMainEventQueue(), event)) | ||
| 676 | // RemoveEventFromQueue(GetMainEventQueue(), event); | ||
| 677 | // qt_mac_event_release(event); | ||
| 678 | // } | ||
| 679 | // } | ||
| 680 | //} | ||
| 681 | |||
| 682 | //static bool qt_mac_event_remove(EventRef &event) | ||
| 683 | //{ | ||
| 684 | // if (event) { | ||
| 685 | // if (IsEventInQueue(GetMainEventQueue(), event)) | ||
| 686 | // RemoveEventFromQueue(GetMainEventQueue(), event); | ||
| 687 | // qt_mac_event_release(event); | ||
| 688 | // return true; | ||
| 689 | // } | ||
| 690 | // return false; | ||
| 691 | //} | ||
| 692 | //#endif | ||
| 693 | |||
| 694 | /* sheets */ | ||
| 695 | //#ifndef QT_MAC_USE_COCOA | ||
| 696 | //static EventRef request_showsheet_pending = 0; | ||
| 697 | //#endif | ||
| 698 | //void qt_event_request_showsheet(QWidget *w) | ||
| 699 | //{ | ||
| 700 | // Q_ASSERT(qt_mac_is_macsheet(w)); | ||
| 701 | //#ifdef QT_MAC_USE_COCOA | ||
| 702 | // [NSApp beginSheet:qt_mac_window_for(w) modalForWindow:qt_mac_window_for(w->parentWidget()) | ||
| 703 | // modalDelegate:nil didEndSelector:nil contextInfo:0]; | ||
| 704 | //#else | ||
| 705 | // qt_mac_event_remove(request_showsheet_pending); | ||
| 706 | // CreateEvent(0, kEventClassQt, kEventQtRequestShowSheet, GetCurrentEventTime(), | ||
| 707 | // kEventAttributeUserEvent, &request_showsheet_pending); | ||
| 708 | // SetEventParameter(request_showsheet_pending, kEventParamQWidget, typeQWidget, sizeof(w), &w); | ||
| 709 | // PostEventToQueue(GetMainEventQueue(), request_showsheet_pending, kEventPriorityStandard); | ||
| 710 | //#endif | ||
| 711 | //} | ||
| 712 | |||
| 713 | //static void qt_post_window_change_event(QWidget *widget) | ||
| 714 | //{ | ||
| 715 | // qt_widget_private(widget)->needWindowChange = true; | ||
| 716 | // QEvent *glWindowChangeEvent = new QEvent(QEvent::MacGLWindowChange); | ||
| 717 | // QApplication::postEvent(widget, glWindowChangeEvent); | ||
| 718 | //} | ||
| 719 | |||
| 720 | /* | ||
| 721 | Posts updates to all child and grandchild OpenGL widgets for the given widget. | ||
| 722 | */ | ||
| 723 | //static void qt_mac_update_child_gl_widgets(QWidget *widget) | ||
| 724 | //{ | ||
| 725 | // if (widget->isWindow()) | ||
| 726 | // return; | ||
| 727 | // | ||
| 728 | // // Update all OpenGL child widgets for the given widget. | ||
| 729 | // QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget)->glWidgets; | ||
| 730 | // QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end(); | ||
| 731 | // QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin(); | ||
| 732 | // | ||
| 733 | // for (;it != end; ++it) { | ||
| 734 | // qt_post_window_change_event(it->widget); | ||
| 735 | // } | ||
| 736 | //} | ||
| 737 | |||
| 738 | /* | ||
| 739 | Sends updates to all child and grandchild gl widgets that have updates pending. | ||
| 740 | */ | ||
| 741 | //void qt_mac_send_posted_gl_updates(QWidget *widget) | ||
| 742 | //{ | ||
| 743 | // QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget)->glWidgets; | ||
| 744 | // QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end(); | ||
| 745 | // QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin(); | ||
| 746 | // | ||
| 747 | // for (;it != end; ++it) { | ||
| 748 | // QWidget *glWidget = it->widget; | ||
| 749 | // if (qt_widget_private(glWidget)->needWindowChange) { | ||
| 750 | // QEvent glChangeEvent(QEvent::MacGLWindowChange); | ||
| 751 | // QApplication::sendEvent(glWidget, &glChangeEvent); | ||
| 752 | // } | ||
| 753 | // } | ||
| 754 | //} | ||
| 755 | |||
| 756 | /* | ||
| 757 | Posts updates to all OpenGL widgets within the window that the given widget intersects. | ||
| 758 | */ | ||
| 759 | //static void qt_mac_update_intersected_gl_widgets(QWidget *widget) | ||
| 760 | //{ | ||
| 761 | //#ifndef QT_MAC_USE_COCOA | ||
| 762 | // QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget->window())->glWidgets; | ||
| 763 | // if (glWidgets.isEmpty()) | ||
| 764 | // return; | ||
| 765 | // | ||
| 766 | // // Exit if the window has not been created yet (mapToGlobal/size will force create it) | ||
| 767 | // if (widget->testAttribute(Qt::WA_WState_Created) == false || HIViewGetWindow(qt_mac_nativeview_for(widget)) == 0) | ||
| 768 | // return; | ||
| 769 | // | ||
| 770 | // const QRect globalWidgetRect = QRect(widget->mapToGlobal(QPoint(0, 0)), widget->size()); | ||
| 771 | // | ||
| 772 | // QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end(); | ||
| 773 | // QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin(); | ||
| 774 | // | ||
| 775 | // for (;it != end; ++it){ | ||
| 776 | // QWidget *glWidget = it->widget; | ||
| 777 | // const QRect globalGlWidgetRect = QRect(glWidget->mapToGlobal(QPoint(0, 0)), glWidget->size()); | ||
| 778 | // if (globalWidgetRect.intersects(globalGlWidgetRect)) { | ||
| 779 | // qt_post_window_change_event(glWidget); | ||
| 780 | // it->lastUpdateWidget = widget; | ||
| 781 | // } else if (it->lastUpdateWidget == widget) { | ||
| 782 | // // Update the gl wigets that the widget intersected the last time around, | ||
| 783 | // // and that we are not intersecting now. This prevents paint errors when the | ||
| 784 | // // intersecting widget leaves a gl widget. | ||
| 785 | // qt_post_window_change_event(glWidget); | ||
| 786 | // it->lastUpdateWidget = 0; | ||
| 787 | // } | ||
| 788 | // } | ||
| 789 | //#else | ||
| 790 | // Q_UNUSED(widget); | ||
| 791 | //#endif | ||
| 792 | //} | ||
| 793 | |||
| 794 | /* | ||
| 795 | Posts a kEventQtRequestWindowChange event to the main Carbon event queue. | ||
| 796 | */ | ||
| 797 | //static EventRef request_window_change_pending = 0; | ||
| 798 | //Q_GUI_EXPORT void qt_event_request_window_change() | ||
| 799 | //{ | ||
| 800 | // if(request_window_change_pending) | ||
| 801 | // return; | ||
| 802 | // | ||
| 803 | // CreateEvent(0, kEventClassQt, kEventQtRequestWindowChange, GetCurrentEventTime(), | ||
| 804 | // kEventAttributeUserEvent, &request_window_change_pending); | ||
| 805 | // PostEventToQueue(GetMainEventQueue(), request_window_change_pending, kEventPriorityHigh); | ||
| 806 | //} | ||
| 807 | |||
| 808 | /* window changing. This is a hack around Apple's missing functionality, pending the toolbox | ||
| 809 | team fix. --Sam */ | ||
| 810 | //Q_GUI_EXPORT void qt_event_request_window_change(QWidget *widget) | ||
| 811 | //{ | ||
| 812 | // if (!widget) | ||
| 813 | // return; | ||
| 814 | // | ||
| 815 | // // Post a kEventQtRequestWindowChange event. This event is semi-public, | ||
| 816 | // // don't remove this line! | ||
| 817 | // qt_event_request_window_change(); | ||
| 818 | // | ||
| 819 | // // Post update request on gl widgets unconditionally. | ||
| 820 | // if (qt_widget_private(widget)->isGLWidget == true) { | ||
| 821 | // qt_post_window_change_event(widget); | ||
| 822 | // return; | ||
| 823 | // } | ||
| 824 | // | ||
| 825 | // qt_mac_update_child_gl_widgets(widget); | ||
| 826 | // qt_mac_update_intersected_gl_widgets(widget); | ||
| 827 | //} | ||
| 828 | |||
| 829 | /* activation */ | ||
| 830 | //static struct { | ||
| 831 | // QPointer<QWidget> widget; | ||
| 832 | // EventRef event; | ||
| 833 | // EventLoopTimerRef timer; | ||
| 834 | // EventLoopTimerUPP timerUPP; | ||
| 835 | //} request_activate_pending = { 0, 0, 0, 0 }; | ||
| 836 | //bool qt_event_remove_activate() | ||
| 837 | //{ | ||
| 838 | // if (request_activate_pending.timer) { | ||
| 839 | // RemoveEventLoopTimer(request_activate_pending.timer); | ||
| 840 | // request_activate_pending.timer = 0; | ||
| 841 | // } | ||
| 842 | // if (request_activate_pending.event) | ||
| 843 | // qt_mac_event_release(request_activate_pending.event); | ||
| 844 | // return true; | ||
| 845 | //} | ||
| 846 | |||
| 847 | //void qt_event_activate_timer_callbk(EventLoopTimerRef r, void *) | ||
| 848 | //{ | ||
| 849 | // EventLoopTimerRef otc = request_activate_pending.timer; | ||
| 850 | // qt_event_remove_activate(); | ||
| 851 | // if (r == otc && !request_activate_pending.widget.isNull()) { | ||
| 852 | // const QWidget *tlw = request_activate_pending.widget->window(); | ||
| 853 | // Qt::WindowType wt = tlw->windowType(); | ||
| 854 | // if (tlw->isVisible() | ||
| 855 | // && ((wt != Qt::Desktop && wt != Qt::Popup && wt != Qt::Tool) || tlw->isModal())) { | ||
| 856 | // CreateEvent(0, kEventClassQt, kEventQtRequestActivate, GetCurrentEventTime(), | ||
| 857 | // kEventAttributeUserEvent, &request_activate_pending.event); | ||
| 858 | // PostEventToQueue(GetMainEventQueue(), request_activate_pending.event, kEventPriorityHigh); | ||
| 859 | // } | ||
| 860 | // } | ||
| 861 | //} | ||
| 862 | |||
| 863 | //void qt_event_request_activate(QWidget *w) | ||
| 864 | //{ | ||
| 865 | // if (w == request_activate_pending.widget) | ||
| 866 | // return; | ||
| 867 | // | ||
| 868 | // /* We put these into a timer because due to order of events being sent we need to be sure this | ||
| 869 | // comes from inside of the event loop */ | ||
| 870 | // qt_event_remove_activate(); | ||
| 871 | // if (!request_activate_pending.timerUPP) | ||
| 872 | // request_activate_pending.timerUPP = NewEventLoopTimerUPP(qt_event_activate_timer_callbk); | ||
| 873 | // request_activate_pending.widget = w; | ||
| 874 | // InstallEventLoopTimer(GetMainEventLoop(), 0, 0, request_activate_pending.timerUPP, 0, &request_activate_pending.timer); | ||
| 875 | //} | ||
| 876 | |||
| 877 | |||
| 878 | /* menubars */ | ||
| 879 | //#ifndef QT_MAC_USE_COCOA | ||
| 880 | //static EventRef request_menubarupdate_pending = 0; | ||
| 881 | //#endif | ||
| 882 | //void qt_event_request_menubarupdate() | ||
| 883 | //{ | ||
| 884 | //#ifndef QT_MAC_USE_COCOA | ||
| 885 | // if (request_menubarupdate_pending) { | ||
| 886 | // if (IsEventInQueue(GetMainEventQueue(), request_menubarupdate_pending)) | ||
| 887 | // return; | ||
| 888 | //#ifdef DEBUG_DROPPED_EVENTS | ||
| 889 | // qDebug("%s:%d Whoa, we dropped an event on the floor!", __FILE__, __LINE__); | ||
| 890 | //#endif | ||
| 891 | // } | ||
| 892 | // | ||
| 893 | // CreateEvent(0, kEventClassQt, kEventQtRequestMenubarUpdate, GetCurrentEventTime(), | ||
| 894 | // kEventAttributeUserEvent, &request_menubarupdate_pending); | ||
| 895 | // PostEventToQueue(GetMainEventQueue(), request_menubarupdate_pending, kEventPriorityHigh); | ||
| 896 | //#else | ||
| 897 | // // Just call this. The request has the benefit that we don't call this multiple times, but | ||
| 898 | // // we can optimize this. | ||
| 899 | // QMenuBar::macUpdateMenuBar(); | ||
| 900 | //#endif | ||
| 901 | //} | ||
| 902 | |||
| 903 | ////context menu | ||
| 904 | //static EventRef request_context_pending = 0; | ||
| 905 | //static void qt_event_request_context(QWidget *w=0, EventRef *where=0) | ||
| 906 | //{ | ||
| 907 | // if (!where) | ||
| 908 | // where = &request_context_pending; | ||
| 909 | // if (*where) | ||
| 910 | // return; | ||
| 911 | // CreateEvent(0, kEventClassQt, kEventQtRequestContext, GetCurrentEventTime(), | ||
| 912 | // kEventAttributeUserEvent, where); | ||
| 913 | // if (w) | ||
| 914 | // SetEventParameter(*where, kEventParamQWidget, typeQWidget, sizeof(w), &w); | ||
| 915 | // PostEventToQueue(GetMainEventQueue(), *where, kEventPriorityStandard); | ||
| 916 | //} | ||
| 917 | //#endif | ||
| 918 | |||
| 919 | void QApplicationPrivate::createEventDispatcher() | ||
| 920 | { | ||
| 921 | Q_Q(QApplication); | ||
| 922 | if (q->type() != QApplication::Tty) | ||
| 923 | eventDispatcher = new QEventDispatcherIPhone(q); | ||
| 924 | else | ||
| 925 | eventDispatcher = new QEventDispatcherUNIX(q); | ||
| 926 | } | ||
| 927 | |||
| 928 | /* clipboard */ | ||
| 929 | //void qt_event_send_clipboard_changed() | ||
| 930 | //{ | ||
| 931 | //#ifndef QT_MAC_USE_COCOA | ||
| 932 | // AppleEvent ae; | ||
| 933 | // if (AECreateAppleEvent(kEventClassQt, typeAEClipboardChanged, 0, kAutoGenerateReturnID, kAnyTransactionID, &ae) != noErr) | ||
| 934 | // qDebug("Can't happen!!"); | ||
| 935 | // AppleEvent reply; | ||
| 936 | // AESend(&ae, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, 0, 0); | ||
| 937 | //#endif | ||
| 938 | //} | ||
| 939 | |||
| 940 | /* app menu */ | ||
| 941 | //static QMenu *qt_mac_dock_menu = 0; | ||
| 942 | //Q_GUI_EXPORT void qt_mac_set_dock_menu(QMenu *menu) | ||
| 943 | //{ | ||
| 944 | // qt_mac_dock_menu = menu; | ||
| 945 | //#ifdef QT_MAC_USE_COCOA | ||
| 946 | // [NSApp setDockMenu:menu->macMenu()]; | ||
| 947 | //#else | ||
| 948 | // SetApplicationDockTileMenu(menu->macMenu()); | ||
| 949 | //#endif | ||
| 950 | //} | ||
| 951 | |||
| 952 | /* events that hold pointers to widgets, must be cleaned up like this */ | ||
| 953 | //void qt_mac_event_release(QWidget *w) | ||
| 954 | //{ | ||
| 955 | // if (w) { | ||
| 956 | //#ifndef QT_MAC_USE_COCOA | ||
| 957 | // qt_mac_event_release(w, request_showsheet_pending); | ||
| 958 | // qt_mac_event_release(w, request_context_pending); | ||
| 959 | //#endif | ||
| 960 | // if (w == qt_mac_dock_menu) { | ||
| 961 | // qt_mac_dock_menu = 0; | ||
| 962 | //#ifndef QT_MAC_USE_COCOA | ||
| 963 | // SetApplicationDockTileMenu(0); | ||
| 964 | //#else | ||
| 965 | // [NSApp setDockMenu:0]; | ||
| 966 | //#endif | ||
| 967 | // } | ||
| 968 | // } | ||
| 969 | //} | ||
| 970 | |||
| 971 | //struct QMacAppleEventTypeSpec { | ||
| 972 | // AEEventClass mac_class; | ||
| 973 | // AEEventID mac_id; | ||
| 974 | //} app_apple_events[] = { | ||
| 975 | // { kCoreEventClass, kAEQuitApplication }, | ||
| 976 | // { kCoreEventClass, kAEOpenDocuments }, | ||
| 977 | // { kInternetEventClass, kAEGetURL }, | ||
| 978 | //}; | ||
| 979 | |||
| 980 | //#ifndef QT_MAC_USE_COCOA | ||
| 981 | |||
| 982 | //#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) | ||
| 983 | //enum | ||
| 984 | //{ | ||
| 985 | // kEventMouseScroll = 11, | ||
| 986 | // kEventParamMouseWheelSmoothVerticalDelta = 'saxy', | ||
| 987 | // kEventParamMouseWheelSmoothHorizontalDelta = 'saxx', | ||
| 988 | //}; | ||
| 989 | //#endif | ||
| 990 | |||
| 991 | /* watched events */ | ||
| 992 | //static EventTypeSpec app_events[] = { | ||
| 993 | // { kEventClassQt, kEventQtRequestWindowChange }, | ||
| 994 | // { kEventClassQt, kEventQtRequestShowSheet }, | ||
| 995 | // { kEventClassQt, kEventQtRequestContext }, | ||
| 996 | // { kEventClassQt, kEventQtRequestActivate }, | ||
| 997 | // { kEventClassQt, kEventQtRequestMenubarUpdate }, | ||
| 998 | // | ||
| 999 | // { kEventClassWindow, kEventWindowActivated }, | ||
| 1000 | // { kEventClassWindow, kEventWindowDeactivated }, | ||
| 1001 | // | ||
| 1002 | // { kEventClassMouse, kEventMouseScroll }, | ||
| 1003 | // { kEventClassMouse, kEventMouseWheelMoved }, | ||
| 1004 | // { kEventClassMouse, kEventMouseDown }, | ||
| 1005 | // { kEventClassMouse, kEventMouseUp }, | ||
| 1006 | // { kEventClassMouse, kEventMouseDragged }, | ||
| 1007 | // { kEventClassMouse, kEventMouseMoved }, | ||
| 1008 | // | ||
| 1009 | // { kEventClassTablet, kEventTabletProximity }, | ||
| 1010 | // | ||
| 1011 | // { kEventClassApplication, kEventAppActivated }, | ||
| 1012 | // { kEventClassApplication, kEventAppDeactivated }, | ||
| 1013 | // { kEventClassApplication, kEventAppAvailableWindowBoundsChanged }, | ||
| 1014 | // | ||
| 1015 | // // { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, | ||
| 1016 | // { kEventClassKeyboard, kEventRawKeyModifiersChanged }, | ||
| 1017 | // { kEventClassKeyboard, kEventRawKeyRepeat }, | ||
| 1018 | // { kEventClassKeyboard, kEventRawKeyUp }, | ||
| 1019 | // { kEventClassKeyboard, kEventRawKeyDown }, | ||
| 1020 | // | ||
| 1021 | // { kEventClassCommand, kEventCommandProcess }, | ||
| 1022 | // | ||
| 1023 | // { kEventClassAppleEvent, kEventAppleEvent }, | ||
| 1024 | // | ||
| 1025 | // { kAppearanceEventClass, kAEAppearanceChanged } | ||
| 1026 | //}; | ||
| 1027 | |||
| 1028 | //void qt_init_app_proc_handler() | ||
| 1029 | //{ | ||
| 1030 | // InstallEventHandler(GetApplicationEventTarget(), app_proc_handlerUPP, | ||
| 1031 | // GetEventTypeCount(app_events), app_events, (void *)qApp, | ||
| 1032 | // &app_proc_handler); | ||
| 1033 | //} | ||
| 1034 | |||
| 1035 | //static void qt_init_tablet_proximity_handler() | ||
| 1036 | //{ | ||
| 1037 | // EventTypeSpec tabletProximityEvent = { kEventClassTablet, kEventTabletProximity }; | ||
| 1038 | // InstallEventHandler(GetEventMonitorTarget(), tablet_proximity_UPP, | ||
| 1039 | // 1, &tabletProximityEvent, qApp, &tablet_proximity_handler); | ||
| 1040 | //} | ||
| 1041 | |||
| 1042 | //static void qt_release_tablet_proximity_handler() | ||
| 1043 | //{ | ||
| 1044 | // RemoveEventHandler(tablet_proximity_handler); | ||
| 1045 | //} | ||
| 1046 | |||
| 1047 | QString QApplicationPrivate::appName() const | ||
| 1048 | { | ||
| 1049 | qDebug("QApplicationPrivate::appName()"); | ||
| 1050 | // static QString applName; | ||
| 1051 | // if (applName.isEmpty()) { | ||
| 1052 | // applName = QCoreApplicationPrivate::macMenuBarName(); | ||
| 1053 | // ProcessSerialNumber psn; | ||
| 1054 | // if (applName.isEmpty() && qt_is_gui_used && GetCurrentProcess(&psn) == noErr) { | ||
| 1055 | // QCFString cfstr; | ||
| 1056 | // CopyProcessName(&psn, &cfstr); | ||
| 1057 | // applName = cfstr; | ||
| 1058 | // } | ||
| 1059 | // } | ||
| 1060 | // return applName; | ||
| 1061 | return "Beta"; | ||
| 1062 | } | ||
| 1063 | |||
| 1064 | //void qt_release_app_proc_handler() | ||
| 1065 | //{ | ||
| 1066 | //#ifndef QT_MAC_USE_COCOA | ||
| 1067 | // if (app_proc_handler) { | ||
| 1068 | // RemoveEventHandler(app_proc_handler); | ||
| 1069 | // app_proc_handler = 0; | ||
| 1070 | // } | ||
| 1071 | //#endif | ||
| 1072 | //} | ||
| 1073 | |||
| 1074 | //void qt_color_profile_changed(CFNotificationCenterRef, void *, CFStringRef, const void *, | ||
| 1075 | // CFDictionaryRef) | ||
| 1076 | //{ | ||
| 1077 | // QCoreGraphicsPaintEngine::cleanUpMacColorSpaces(); | ||
| 1078 | //} | ||
| 1079 | |||
| 1080 | /* platform specific implementations */ | ||
| 1081 | void qt_init(QApplicationPrivate *priv, int) | ||
| 1082 | { | ||
| 1083 | // if (qt_is_gui_used) { | ||
| 1084 | // CGDisplayRegisterReconfigurationCallback(qt_mac_display_change_callbk, 0); | ||
| 1085 | // CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter(); | ||
| 1086 | // CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed, | ||
| 1087 | // kCMDeviceUnregisteredNotification, 0, | ||
| 1088 | // CFNotificationSuspensionBehaviorDeliverImmediately); | ||
| 1089 | // CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed, | ||
| 1090 | // kCMDefaultDeviceNotification, 0, | ||
| 1091 | // CFNotificationSuspensionBehaviorDeliverImmediately); | ||
| 1092 | // CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed, | ||
| 1093 | // kCMDeviceProfilesNotification, 0, | ||
| 1094 | // CFNotificationSuspensionBehaviorDeliverImmediately); | ||
| 1095 | // CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed, | ||
| 1096 | // kCMDefaultDeviceProfileNotification, 0, | ||
| 1097 | // CFNotificationSuspensionBehaviorDeliverImmediately); | ||
| 1098 | // ProcessSerialNumber psn; | ||
| 1099 | // if (GetCurrentProcess(&psn) == noErr) { | ||
| 1100 | // // Jambi needs to transform itself since most people aren't "used" | ||
| 1101 | // // to putting things in bundles, but other people may actually not | ||
| 1102 | // // want to tranform the process (running as a helper or something) | ||
| 1103 | // // so don't do that for them. This means checking both LSUIElement | ||
| 1104 | // // and LSBackgroundOnly. If you set them both... well, you | ||
| 1105 | // // shouldn't do that. | ||
| 1106 | // | ||
| 1107 | // bool forceTransform = true; | ||
| 1108 | // CFTypeRef value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), | ||
| 1109 | // CFSTR("LSUIElement")); | ||
| 1110 | // if (value) { | ||
| 1111 | // CFTypeID valueType = CFGetTypeID(value); | ||
| 1112 | // // Officially it's supposed to be a string, a boolean makes sense, so we'll check. | ||
| 1113 | // // A number less so, but OK. | ||
| 1114 | // if (valueType == CFStringGetTypeID()) | ||
| 1115 | // forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt()); | ||
| 1116 | // else if (valueType == CFBooleanGetTypeID()) | ||
| 1117 | // forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value)); | ||
| 1118 | // else if (valueType == CFNumberGetTypeID()) { | ||
| 1119 | // int valueAsInt; | ||
| 1120 | // CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt); | ||
| 1121 | // forceTransform = !valueAsInt; | ||
| 1122 | // } | ||
| 1123 | // } | ||
| 1124 | // | ||
| 1125 | // if (forceTransform) { | ||
| 1126 | // value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), | ||
| 1127 | // CFSTR("LSBackgroundOnly")); | ||
| 1128 | // if (value) { | ||
| 1129 | // CFTypeID valueType = CFGetTypeID(value); | ||
| 1130 | // if (valueType == CFBooleanGetTypeID()) | ||
| 1131 | // forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value)); | ||
| 1132 | // else if (valueType == CFStringGetTypeID()) | ||
| 1133 | // forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt()); | ||
| 1134 | // else if (valueType == CFNumberGetTypeID()) { | ||
| 1135 | // int valueAsInt; | ||
| 1136 | // CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt); | ||
| 1137 | // forceTransform = !valueAsInt; | ||
| 1138 | // } | ||
| 1139 | // } | ||
| 1140 | // } | ||
| 1141 | // | ||
| 1142 | // | ||
| 1143 | // if (forceTransform) { | ||
| 1144 | // TransformProcessType(&psn, kProcessTransformToForegroundApplication); | ||
| 1145 | // } | ||
| 1146 | // } | ||
| 1147 | // } | ||
| 1148 | // | ||
| 1149 | // char **argv = priv->argv; | ||
| 1150 | // | ||
| 1151 | // // Get command line params | ||
| 1152 | // if (int argc = priv->argc) { | ||
| 1153 | // int i, j = 1; | ||
| 1154 | // QString passed_psn; | ||
| 1155 | // for(i=1; i < argc; i++) { | ||
| 1156 | // if (argv[i] && *argv[i] != '-') { | ||
| 1157 | // argv[j++] = argv[i]; | ||
| 1158 | // continue; | ||
| 1159 | // } | ||
| 1160 | // QByteArray arg(argv[i]); | ||
| 1161 | //#if defined(QT_DEBUG) | ||
| 1162 | // if (arg == "-nograb") | ||
| 1163 | // appNoGrab = !appNoGrab; | ||
| 1164 | // else | ||
| 1165 | //#endif // QT_DEBUG | ||
| 1166 | // if (arg.left(5) == "-psn_") { | ||
| 1167 | // passed_psn = QString::fromLatin1(arg.mid(6)); | ||
| 1168 | // } else { | ||
| 1169 | // argv[j++] = argv[i]; | ||
| 1170 | // } | ||
| 1171 | // } | ||
| 1172 | // if (j < priv->argc) { | ||
| 1173 | // priv->argv[j] = 0; | ||
| 1174 | // priv->argc = j; | ||
| 1175 | // } | ||
| 1176 | // | ||
| 1177 | // //special hack to change working directory (for an app bundle) when running from finder | ||
| 1178 | // if (!passed_psn.isNull() && QDir::currentPath() == QLatin1String("/")) { | ||
| 1179 | // QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle())); | ||
| 1180 | // QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL, | ||
| 1181 | // kCFURLPOSIXPathStyle)); | ||
| 1182 | // if (qbundlePath.endsWith(QLatin1String(".app"))) | ||
| 1183 | // QDir::setCurrent(qbundlePath.section(QLatin1Char('/'), 0, -2)); | ||
| 1184 | // } | ||
| 1185 | // } | ||
| 1186 | // | ||
| 1187 | // QMacPasteboardMime::initialize(); | ||
| 1188 | // | ||
| 1189 | // qApp->setObjectName(priv->appName()); | ||
| 1190 | // if (qt_is_gui_used) { | ||
| 1191 | // QColormap::initialize(); | ||
| 1192 | // QFont::initialize(); | ||
| 1193 | // QCursorData::initialize(); | ||
| 1194 | // QCoreGraphicsPaintEngine::initialize(); | ||
| 1195 | //#ifndef QT_NO_ACCESSIBILITY | ||
| 1196 | // QAccessible::initialize(); | ||
| 1197 | //#endif | ||
| 1198 | // QMacInputContext::initialize(); | ||
| 1199 | // QApplicationPrivate::inputContext = new QMacInputContext; | ||
| 1200 | // | ||
| 1201 | // if (QApplication::desktopSettingsAware()) | ||
| 1202 | // qt_mac_update_os_settings(); | ||
| 1203 | //#ifndef QT_MAC_USE_COCOA | ||
| 1204 | // if (!app_proc_handler) { | ||
| 1205 | // app_proc_handlerUPP = NewEventHandlerUPP(QApplicationPrivate::globalEventProcessor); | ||
| 1206 | // qt_init_app_proc_handler(); | ||
| 1207 | // } | ||
| 1208 | // | ||
| 1209 | //#endif | ||
| 1210 | // if (!app_proc_ae_handlerUPP) { | ||
| 1211 | // app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor); | ||
| 1212 | // for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) | ||
| 1213 | // AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, | ||
| 1214 | // app_proc_ae_handlerUPP, SRefCon(qApp), false); | ||
| 1215 | // } | ||
| 1216 | // | ||
| 1217 | // if (QApplicationPrivate::app_style) { | ||
| 1218 | // QEvent ev(QEvent::Style); | ||
| 1219 | // qt_sendSpontaneousEvent(QApplicationPrivate::app_style, &ev); | ||
| 1220 | // } | ||
| 1221 | // } | ||
| 1222 | // if (QApplication::desktopSettingsAware()) | ||
| 1223 | // QApplicationPrivate::qt_mac_apply_settings(); | ||
| 1224 | // | ||
| 1225 | // qt_mac_read_fontsmoothing_settings(); | ||
| 1226 | // | ||
| 1227 | // // Cocoa application delegate | ||
| 1228 | //#ifdef QT_MAC_USE_COCOA | ||
| 1229 | // NSApplication *cocoaApp = [NSApplication sharedApplication]; | ||
| 1230 | // QMacCocoaAutoReleasePool pool; | ||
| 1231 | // NSObject *oldDelegate = [cocoaApp delegate]; | ||
| 1232 | // QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]; | ||
| 1233 | // Q_ASSERT(newDelegate); | ||
| 1234 | // [newDelegate setQtPrivate:priv]; | ||
| 1235 | // // Only do things that make sense to do once, otherwise we crash. | ||
| 1236 | // if (oldDelegate != newDelegate && !QApplication::testAttribute(Qt::AA_MacPluginApplication)) { | ||
| 1237 | // [newDelegate setReflectionDelegate:oldDelegate]; | ||
| 1238 | // [cocoaApp setDelegate:newDelegate]; | ||
| 1239 | // | ||
| 1240 | // QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) alloc] init]; | ||
| 1241 | // if ([NSBundle loadNibNamed:@"qt_menu" owner:qtMenuLoader] == false) { | ||
| 1242 | // qFatal("Qt internal error: qt_menu.nib could not be loaded. The .nib file" | ||
| 1243 | // " should be placed in QtGui.framework/Versions/Current/Resources/ " | ||
| 1244 | // " or in the resources directory of your application bundle."); | ||
| 1245 | // } | ||
| 1246 | // | ||
| 1247 | // [cocoaApp setMenu:[qtMenuLoader menu]]; | ||
| 1248 | // [newDelegate setMenuLoader:qtMenuLoader]; | ||
| 1249 | // [qtMenuLoader release]; | ||
| 1250 | // | ||
| 1251 | // NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; | ||
| 1252 | // [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:) | ||
| 1253 | // forEventClass:kInternetEventClass andEventID:kAEGetURL]; | ||
| 1254 | // } | ||
| 1255 | //#endif | ||
| 1256 | // // Register for Carbon tablet proximity events on the event monitor target. | ||
| 1257 | // // This means that we should receive proximity events even when we aren't the active application. | ||
| 1258 | // if (!tablet_proximity_handler) { | ||
| 1259 | // tablet_proximity_UPP = NewEventHandlerUPP(QApplicationPrivate::tabletProximityCallback); | ||
| 1260 | // qt_init_tablet_proximity_handler(); | ||
| 1261 | // } | ||
| 1262 | // priv->native_modal_dialog_active = false; | ||
| 1263 | // | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | //void qt_release_apple_event_handler() | ||
| 1267 | //{ | ||
| 1268 | // if(app_proc_ae_handlerUPP) { | ||
| 1269 | // for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) | ||
| 1270 | // AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, | ||
| 1271 | // app_proc_ae_handlerUPP, true); | ||
| 1272 | // DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP); | ||
| 1273 | // app_proc_ae_handlerUPP = 0; | ||
| 1274 | // } | ||
| 1275 | //} | ||
| 1276 | |||
| 1277 | /***************************************************************************** | ||
| 1278 | qt_cleanup() - cleans up when the application is finished | ||
| 1279 | *****************************************************************************/ | ||
| 1280 | void qt_cleanup() | ||
| 1281 | { | ||
| 1282 | // CGDisplayRemoveReconfigurationCallback(qt_mac_display_change_callbk, 0); | ||
| 1283 | // CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter(); | ||
| 1284 | // CFNotificationCenterRemoveObserver(center, qApp, kCMDeviceUnregisteredNotification, 0); | ||
| 1285 | // CFNotificationCenterRemoveObserver(center, qApp, kCMDefaultDeviceNotification, 0); | ||
| 1286 | // CFNotificationCenterRemoveObserver(center, qApp, kCMDeviceProfilesNotification, 0); | ||
| 1287 | // CFNotificationCenterRemoveObserver(center, qApp, kCMDefaultDeviceProfileNotification, 0); | ||
| 1288 | // | ||
| 1289 | //#ifndef QT_MAC_USE_COCOA | ||
| 1290 | // qt_release_app_proc_handler(); | ||
| 1291 | // if (app_proc_handlerUPP) { | ||
| 1292 | // DisposeEventHandlerUPP(app_proc_handlerUPP); | ||
| 1293 | // app_proc_handlerUPP = 0; | ||
| 1294 | // } | ||
| 1295 | //#endif | ||
| 1296 | // qt_release_apple_event_handler(); | ||
| 1297 | // qt_release_tablet_proximity_handler(); | ||
| 1298 | // if (tablet_proximity_UPP) | ||
| 1299 | // DisposeEventHandlerUPP(tablet_proximity_UPP); | ||
| 1300 | // | ||
| 1301 | // QPixmapCache::clear(); | ||
| 1302 | // if (qt_is_gui_used) { | ||
| 1303 | //#ifndef QT_NO_ACCESSIBILITY | ||
| 1304 | // QAccessible::cleanup(); | ||
| 1305 | //#endif | ||
| 1306 | // QMacInputContext::cleanup(); | ||
| 1307 | // QCursorData::cleanup(); | ||
| 1308 | // QFont::cleanup(); | ||
| 1309 | // QColormap::cleanup(); | ||
| 1310 | // if (qt_mac_safe_pdev) { | ||
| 1311 | // delete qt_mac_safe_pdev; | ||
| 1312 | // qt_mac_safe_pdev = 0; | ||
| 1313 | // } | ||
| 1314 | // extern void qt_mac_unregister_widget(); // qapplication_mac.cpp | ||
| 1315 | // qt_mac_unregister_widget(); | ||
| 1316 | // } | ||
| 1317 | } | ||
| 1318 | |||
| 1319 | /***************************************************************************** | ||
| 1320 | Platform specific global and internal functions | ||
| 1321 | *****************************************************************************/ | ||
| 1322 | //void qt_updated_rootinfo() | ||
| 1323 | //{ | ||
| 1324 | //} | ||
| 1325 | |||
| 1326 | //bool qt_wstate_iconified(WId) | ||
| 1327 | //{ | ||
| 1328 | // return false; | ||
| 1329 | //} | ||
| 1330 | |||
| 1331 | /***************************************************************************** | ||
| 1332 | Platform specific QApplication members | ||
| 1333 | *****************************************************************************/ | ||
| 1334 | //extern QWidget * mac_mouse_grabber; | ||
| 1335 | //extern QWidget * mac_keyboard_grabber; | ||
| 1336 | |||
| 1337 | #ifdef QT3_SUPPORT | ||
| 1338 | void QApplication::setMainWidget(QWidget *mainWidget) | ||
| 1339 | { | ||
| 1340 | qDebug("QApplication::setMainWidget(QWidget *mainWidget)"); | ||
| 1341 | // QApplicationPrivate::main_widget = mainWidget; | ||
| 1342 | // if (QApplicationPrivate::main_widget && windowIcon().isNull() | ||
| 1343 | // && QApplicationPrivate::main_widget->testAttribute(Qt::WA_SetWindowIcon)) | ||
| 1344 | // setWindowIcon(QApplicationPrivate::main_widget->windowIcon()); | ||
| 1345 | } | ||
| 1346 | #endif | ||
| 1347 | |||
| 1348 | #ifndef QT_NO_CURSO | ||
| 1349 | ///***************************************************************************** | ||
| 1350 | // QApplication cursor stack | ||
| 1351 | // *****************************************************************************/ | ||
| 1352 | void QApplication::setOverrideCursor(const QCursor &cursor) | ||
| 1353 | { | ||
| 1354 | qDebug("QApplication::setOverrideCursor(const QCursor &cursor)"); | ||
| 1355 | // qApp->d_func()->cursor_list.prepend(cursor); | ||
| 1356 | // | ||
| 1357 | //#ifdef QT_MAC_USE_COCOA | ||
| 1358 | // [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) push]; | ||
| 1359 | //#else | ||
| 1360 | // if (qApp && qApp->activeWindow()) | ||
| 1361 | // qt_mac_set_cursor(&qApp->d_func()->cursor_list.first(), QCursor::pos()); | ||
| 1362 | //#endif | ||
| 1363 | } | ||
| 1364 | |||
| 1365 | void QApplication::restoreOverrideCursor() | ||
| 1366 | { | ||
| 1367 | qDebug("QApplication::restoreOverrideCursor()"); | ||
| 1368 | // if (qApp->d_func()->cursor_list.isEmpty()) | ||
| 1369 | // return; | ||
| 1370 | // qApp->d_func()->cursor_list.removeFirst(); | ||
| 1371 | // | ||
| 1372 | //#ifdef QT_MAC_USE_COCOA | ||
| 1373 | // [NSCursor pop]; | ||
| 1374 | //#else | ||
| 1375 | // if (qApp && qApp->activeWindow()) { | ||
| 1376 | // const QCursor def(Qt::ArrowCursor); | ||
| 1377 | // qt_mac_set_cursor(qApp->d_func()->cursor_list.isEmpty() ? &def : &qApp->d_func()->cursor_list.first(), QCursor::pos()); | ||
| 1378 | // } | ||
| 1379 | //#endif | ||
| 1380 | } | ||
| 1381 | #endif // QT_NO_CURSOR | ||
| 1382 | |||
| 1383 | QWidget *QApplication::topLevelAt(const QPoint &p) | ||
| 1384 | { | ||
| 1385 | qDebug("QApplication::topLevelAt(const QPoint &p)"); | ||
| 1386 | //#ifndef QT_MAC_USE_COCOA | ||
| 1387 | // QWidget *widget; | ||
| 1388 | // qt_mac_window_at(p.x(), p.y(), &widget); | ||
| 1389 | // return widget; | ||
| 1390 | //#else | ||
| 1391 | // NSInteger windowCount; | ||
| 1392 | // NSCountWindows(&windowCount); | ||
| 1393 | // if (windowCount <= 0) | ||
| 1394 | // return 0; // There's no window to find! | ||
| 1395 | // QMacCocoaAutoReleasePool pool; | ||
| 1396 | // NSPoint cocoaPoint = flipPoint(p); | ||
| 1397 | // QVarLengthArray<NSInteger> windowList(windowCount); | ||
| 1398 | // NSWindowList(windowCount, windowList.data()); | ||
| 1399 | // for (int i = 0; i < windowCount; ++i) { | ||
| 1400 | // NSWindow *window = [NSApp windowWithWindowNumber:windowList[i]]; | ||
| 1401 | // if (window && NSPointInRect(cocoaPoint, [window frame])) { | ||
| 1402 | // QWidget *candidateWindow = [window QT_MANGLE_NAMESPACE(qt_qwidget)]; | ||
| 1403 | // // Check to see if there's a hole in the window where the mask is. | ||
| 1404 | // // If there is, we should just continue to see if there is a window below. | ||
| 1405 | // if (candidateWindow && !candidateWindow->mask().isEmpty()) { | ||
| 1406 | // QPoint localPoint = candidateWindow->mapFromGlobal(p); | ||
| 1407 | // if (!candidateWindow->mask().contains(localPoint)) { | ||
| 1408 | // continue; | ||
| 1409 | // } | ||
| 1410 | // } | ||
| 1411 | // return candidateWindow; | ||
| 1412 | // } | ||
| 1413 | // } | ||
| 1414 | // return 0; // Couldn't find a window at this point | ||
| 1415 | //#endif | ||
| 1416 | return 0; | ||
| 1417 | } | ||
| 1418 | |||
| 1419 | /***************************************************************************** | ||
| 1420 | Main event loop | ||
| 1421 | *****************************************************************************/ | ||
| 1422 | |||
| 1423 | bool QApplicationPrivate::modalState() | ||
| 1424 | { | ||
| 1425 | qDebug("QApplicationPrivate::modalState()"); | ||
| 1426 | // return app_do_modal; | ||
| 1427 | return false; | ||
| 1428 | } | ||
| 1429 | |||
| 1430 | //#ifdef QT_MAC_USE_COCOA | ||
| 1431 | //#endif | ||
| 1432 | |||
| 1433 | void QApplicationPrivate::enterModal_sys(QWidget *widget) | ||
| 1434 | { | ||
| 1435 | qDebug("QApplicationPrivate::enterModal_sys(QWidget *widget)"); | ||
| 1436 | //#ifdef DEBUG_MODAL_EVENTS | ||
| 1437 | // Q_ASSERT(widget); | ||
| 1438 | // qDebug("Entering modal state with %s::%s::%p (%d)", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(), | ||
| 1439 | // widget, qt_modal_stack ? (int)qt_modal_stack->count() : -1); | ||
| 1440 | //#endif | ||
| 1441 | // if (!qt_modal_stack) | ||
| 1442 | // qt_modal_stack = new QWidgetList; | ||
| 1443 | // | ||
| 1444 | // dispatchEnterLeave(0, qt_mouseover); | ||
| 1445 | // qt_mouseover = 0; | ||
| 1446 | // | ||
| 1447 | // qt_modal_stack->insert(0, widget); | ||
| 1448 | // if (!app_do_modal) | ||
| 1449 | // qt_event_request_menubarupdate(); | ||
| 1450 | // app_do_modal = true; | ||
| 1451 | // qt_button_down = 0; | ||
| 1452 | // | ||
| 1453 | //#ifdef QT_MAC_USE_COCOA | ||
| 1454 | // if (!qt_mac_is_macsheet(widget)) | ||
| 1455 | // QEventDispatcherMacPrivate::beginModalSession(widget); | ||
| 1456 | //#endif | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | void QApplicationPrivate::leaveModal_sys(QWidget *widget) | ||
| 1460 | { | ||
| 1461 | qDebug(" QApplicationPrivate::leaveModal_sys(QWidget *widget)"); | ||
| 1462 | // if (qt_modal_stack && qt_modal_stack->removeAll(widget)) { | ||
| 1463 | //#ifdef DEBUG_MODAL_EVENTS | ||
| 1464 | // qDebug("Leaving modal state with %s::%s::%p (%d)", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(), | ||
| 1465 | // widget, qt_modal_stack->count()); | ||
| 1466 | //#endif | ||
| 1467 | // if (qt_modal_stack->isEmpty()) { | ||
| 1468 | // delete qt_modal_stack; | ||
| 1469 | // qt_modal_stack = 0; | ||
| 1470 | // QPoint p(QCursor::pos()); | ||
| 1471 | // app_do_modal = false; | ||
| 1472 | // QWidget* w = 0; | ||
| 1473 | // if (QWidget *grabber = QWidget::mouseGrabber()) | ||
| 1474 | // w = grabber; | ||
| 1475 | // else | ||
| 1476 | // w = QApplication::widgetAt(p.x(), p.y()); | ||
| 1477 | // dispatchEnterLeave(w, qt_mouseover); // send synthetic enter event | ||
| 1478 | // qt_mouseover = w; | ||
| 1479 | // } | ||
| 1480 | //#ifdef QT_MAC_USE_COCOA | ||
| 1481 | // if (!qt_mac_is_macsheet(widget)) | ||
| 1482 | // QEventDispatcherMacPrivate::endModalSession(widget); | ||
| 1483 | //#endif | ||
| 1484 | // } | ||
| 1485 | //#ifdef DEBUG_MODAL_EVENTS | ||
| 1486 | // else qDebug("Failure to remove %s::%s::%p -- %p", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(), widget, qt_modal_stack); | ||
| 1487 | //#endif | ||
| 1488 | // app_do_modal = (qt_modal_stack != 0); | ||
| 1489 | // if (!app_do_modal) | ||
| 1490 | // qt_event_request_menubarupdate(); | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | //QWidget *QApplicationPrivate::tryModalHelper_sys(QWidget *top) | ||
| 1494 | //{ | ||
| 1495 | //#ifndef QT_MAC_USE_COCOA | ||
| 1496 | // if(top && qt_mac_is_macsheet(top) && !IsWindowVisible(qt_mac_window_for(top))) { | ||
| 1497 | // if(OSWindowRef wp = GetFrontWindowOfClass(kSheetWindowClass, true)) { | ||
| 1498 | // if(QWidget *sheet = qt_mac_find_window(wp)) | ||
| 1499 | // top = sheet; | ||
| 1500 | // } | ||
| 1501 | // } | ||
| 1502 | //#endif | ||
| 1503 | // return top; | ||
| 1504 | //} | ||
| 1505 | |||
| 1506 | //#ifndef QT_MAC_USE_COCOA | ||
| 1507 | //static bool qt_try_modal(QWidget *widget, EventRef event) | ||
| 1508 | //{ | ||
| 1509 | // QWidget * top = 0; | ||
| 1510 | // | ||
| 1511 | // if (QApplicationPrivate::tryModalHelper(widget, &top)) | ||
| 1512 | // return true; | ||
| 1513 | // | ||
| 1514 | // // INVARIANT: widget is modally shaddowed within its | ||
| 1515 | // // window, and should therefore not handle the event. | ||
| 1516 | // // However, if the window is not active, the event | ||
| 1517 | // // might suggest that we should bring it to front: | ||
| 1518 | // | ||
| 1519 | // bool block_event = false; | ||
| 1520 | // | ||
| 1521 | // if (event) { | ||
| 1522 | // switch (GetEventClass(event)) { | ||
| 1523 | // case kEventClassMouse: | ||
| 1524 | // case kEventClassKeyboard: | ||
| 1525 | // block_event = true; | ||
| 1526 | // break; | ||
| 1527 | // } | ||
| 1528 | // } | ||
| 1529 | // | ||
| 1530 | // QWidget *activeWidget = QApplication::activeWindow(); | ||
| 1531 | // if ((!activeWidget || QApplicationPrivate::isBlockedByModal(activeWidget)) && | ||
| 1532 | // top->isWindow() && block_event && !QApplicationPrivate::native_modal_dialog_active) | ||
| 1533 | // top->raise(); | ||
| 1534 | // | ||
| 1535 | //#ifdef DEBUG_MODAL_EVENTS | ||
| 1536 | // qDebug("%s:%d -- final decision! (%s)", __FILE__, __LINE__, block_event ? "false" : "true"); | ||
| 1537 | //#endif | ||
| 1538 | // return !block_event; | ||
| 1539 | //} | ||
| 1540 | //#endif | ||
| 1541 | |||
| 1542 | //OSStatus QApplicationPrivate::tabletProximityCallback(EventHandlerCallRef, EventRef carbonEvent, | ||
| 1543 | // void *) | ||
| 1544 | //{ | ||
| 1545 | // OSType eventClass = GetEventClass(carbonEvent); | ||
| 1546 | // UInt32 eventKind = GetEventKind(carbonEvent); | ||
| 1547 | // if (eventClass != kEventClassTablet || eventKind != kEventTabletProximity) | ||
| 1548 | // return eventNotHandledErr; | ||
| 1549 | // | ||
| 1550 | // // Get the current point of the device and its unique ID. | ||
| 1551 | // ::TabletProximityRec proxRec; | ||
| 1552 | // GetEventParameter(carbonEvent, kEventParamTabletProximityRec, typeTabletProximityRec, 0, | ||
| 1553 | // sizeof(proxRec), 0, &proxRec); | ||
| 1554 | // qt_dispatchTabletProximityEvent(proxRec); | ||
| 1555 | // return noErr; | ||
| 1556 | //} | ||
| 1557 | |||
| 1558 | //OSStatus | ||
| 1559 | //QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event, void *data) | ||
| 1560 | //{ | ||
| 1561 | //#ifndef QT_MAC_USE_COCOA | ||
| 1562 | // QApplication *app = (QApplication *)data; | ||
| 1563 | // QScopedLoopLevelCounter loopLevelCounter(app->d_func()->threadData); | ||
| 1564 | // long result; | ||
| 1565 | // if (app->filterEvent(&event, &result)) | ||
| 1566 | // return result; | ||
| 1567 | // if(app->macEventFilter(er, event)) //someone else ate it | ||
| 1568 | // return noErr; | ||
| 1569 | // QPointer<QWidget> widget; | ||
| 1570 | // | ||
| 1571 | // /*We assume all events are handled and in | ||
| 1572 | // the code below we set it to false when we know we didn't handle it, this | ||
| 1573 | // will let rogue events through (shouldn't really happen, but better safe | ||
| 1574 | // than sorry) */ | ||
| 1575 | // bool handled_event=true; | ||
| 1576 | // UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); | ||
| 1577 | // switch(eclass) | ||
| 1578 | // { | ||
| 1579 | // case kEventClassQt: | ||
| 1580 | // if(ekind == kEventQtRequestShowSheet) { | ||
| 1581 | // request_showsheet_pending = 0; | ||
| 1582 | // QWidget *widget = 0; | ||
| 1583 | // GetEventParameter(event, kEventParamQWidget, typeQWidget, 0, | ||
| 1584 | // sizeof(widget), 0, &widget); | ||
| 1585 | // if(widget) { | ||
| 1586 | // if (widget->macEvent(er, event)) | ||
| 1587 | // return noErr; | ||
| 1588 | // WindowPtr window = qt_mac_window_for(widget); | ||
| 1589 | // bool just_show = !qt_mac_is_macsheet(widget); | ||
| 1590 | // if(!just_show) { | ||
| 1591 | // OSStatus err = ShowSheetWindow(window, qt_mac_window_for(widget->parentWidget())); | ||
| 1592 | // if(err != noErr) | ||
| 1593 | // qWarning("Qt: QWidget: Unable to show as sheet %s::%s [%ld]", widget->metaObject()->className(), | ||
| 1594 | // widget->objectName().toLocal8Bit().constData(), long(err)); | ||
| 1595 | // just_show = true; | ||
| 1596 | // } | ||
| 1597 | // if(just_show) //at least the window will be visible, but the sheet flag doesn't work sadly (probalby too many sheets) | ||
| 1598 | // ShowHide(window, true); | ||
| 1599 | // } | ||
| 1600 | // } else if(ekind == kEventQtRequestWindowChange) { | ||
| 1601 | // qt_mac_event_release(request_window_change_pending); | ||
| 1602 | // } else if(ekind == kEventQtRequestMenubarUpdate) { | ||
| 1603 | // qt_mac_event_release(request_menubarupdate_pending); | ||
| 1604 | // QMenuBar::macUpdateMenuBar(); | ||
| 1605 | // } else if(ekind == kEventQtRequestActivate) { | ||
| 1606 | // qt_mac_event_release(request_activate_pending.event); | ||
| 1607 | // if(request_activate_pending.widget) { | ||
| 1608 | // QWidget *tlw = request_activate_pending.widget->window(); | ||
| 1609 | // if (tlw->macEvent(er, event)) | ||
| 1610 | // return noErr; | ||
| 1611 | // request_activate_pending.widget = 0; | ||
| 1612 | // tlw->activateWindow(); | ||
| 1613 | // SelectWindow(qt_mac_window_for(tlw)); | ||
| 1614 | // } | ||
| 1615 | // } else if(ekind == kEventQtRequestContext) { | ||
| 1616 | // bool send = false; | ||
| 1617 | // if ((send = (event == request_context_pending))) | ||
| 1618 | // qt_mac_event_release(request_context_pending); | ||
| 1619 | // if(send) { | ||
| 1620 | // //figure out which widget to send it to | ||
| 1621 | // QPoint where = QCursor::pos(); | ||
| 1622 | // QWidget *widget = 0; | ||
| 1623 | // GetEventParameter(event, kEventParamQWidget, typeQWidget, 0, | ||
| 1624 | // sizeof(widget), 0, &widget); | ||
| 1625 | // if(!widget) { | ||
| 1626 | // if(qt_button_down) | ||
| 1627 | // widget = qt_button_down; | ||
| 1628 | // else | ||
| 1629 | // widget = QApplication::widgetAt(where.x(), where.y()); | ||
| 1630 | // } | ||
| 1631 | // if(widget && !isBlockedByModal(widget)) { | ||
| 1632 | // if (widget->macEvent(er, event)) | ||
| 1633 | // return noErr; | ||
| 1634 | // QPoint plocal(widget->mapFromGlobal(where)); | ||
| 1635 | // const Qt::KeyboardModifiers keyboardModifiers = qt_mac_get_modifiers(GetCurrentEventKeyModifiers()); | ||
| 1636 | // QContextMenuEvent qme(QContextMenuEvent::Mouse, plocal, where, keyboardModifiers); | ||
| 1637 | // QApplication::sendEvent(widget, &qme); | ||
| 1638 | // if(qme.isAccepted()) { //once this happens the events before are pitched | ||
| 1639 | // qt_button_down = 0; | ||
| 1640 | // qt_mac_dblclick.last_widget = 0; | ||
| 1641 | // } | ||
| 1642 | // } else { | ||
| 1643 | // handled_event = false; | ||
| 1644 | // } | ||
| 1645 | // } | ||
| 1646 | // } else { | ||
| 1647 | // handled_event = false; | ||
| 1648 | // } | ||
| 1649 | // break; | ||
| 1650 | // case kEventClassTablet: | ||
| 1651 | // switch (ekind) { | ||
| 1652 | // case kEventTabletProximity: | ||
| 1653 | // // Get the current point of the device and its unique ID. | ||
| 1654 | // ::TabletProximityRec proxRec; | ||
| 1655 | // GetEventParameter(event, kEventParamTabletProximityRec, typeTabletProximityRec, 0, | ||
| 1656 | // sizeof(proxRec), 0, &proxRec); | ||
| 1657 | // qt_dispatchTabletProximityEvent(proxRec); | ||
| 1658 | // } | ||
| 1659 | // break; | ||
| 1660 | // case kEventClassMouse: | ||
| 1661 | // { | ||
| 1662 | // static const int kEventParamQAppSeenMouseEvent = 'QASM'; | ||
| 1663 | // // Check if we've seen the event, if we have we shouldn't process | ||
| 1664 | // // it again as it may lead to spurious "double events" | ||
| 1665 | // bool seenEvent; | ||
| 1666 | // if (GetEventParameter(event, kEventParamQAppSeenMouseEvent, | ||
| 1667 | // typeBoolean, 0, sizeof(bool), 0, &seenEvent) == noErr) { | ||
| 1668 | // if (seenEvent) | ||
| 1669 | // return eventNotHandledErr; | ||
| 1670 | // } | ||
| 1671 | // seenEvent = true; | ||
| 1672 | // SetEventParameter(event, kEventParamQAppSeenMouseEvent, typeBoolean, | ||
| 1673 | // sizeof(bool), &seenEvent); | ||
| 1674 | // | ||
| 1675 | // Point where; | ||
| 1676 | // bool inNonClientArea = false; | ||
| 1677 | // GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, | ||
| 1678 | // sizeof(where), 0, &where); | ||
| 1679 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 1680 | // const char *edesc = 0; | ||
| 1681 | // switch(ekind) { | ||
| 1682 | // case kEventMouseDown: edesc = "MouseButtonPress"; break; | ||
| 1683 | // case kEventMouseUp: edesc = "MouseButtonRelease"; break; | ||
| 1684 | // case kEventMouseDragged: case kEventMouseMoved: edesc = "MouseMove"; break; | ||
| 1685 | // case kEventMouseScroll: edesc = "MouseWheelScroll"; break; | ||
| 1686 | // case kEventMouseWheelMoved: edesc = "MouseWheelMove"; break; | ||
| 1687 | // } | ||
| 1688 | // if(ekind == kEventMouseDown || ekind == kEventMouseUp) | ||
| 1689 | // qDebug("Handling mouse: %s", edesc); | ||
| 1690 | //#endif | ||
| 1691 | // QEvent::Type etype = QEvent::None; | ||
| 1692 | // Qt::KeyboardModifiers modifiers; | ||
| 1693 | // { | ||
| 1694 | // UInt32 mac_modifiers = 0; | ||
| 1695 | // GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0, | ||
| 1696 | // sizeof(mac_modifiers), 0, &mac_modifiers); | ||
| 1697 | // modifiers = qt_mac_get_modifiers(mac_modifiers); | ||
| 1698 | // } | ||
| 1699 | // Qt::MouseButtons buttons; | ||
| 1700 | // { | ||
| 1701 | // UInt32 mac_buttons = 0; | ||
| 1702 | // GetEventParameter(event, kEventParamMouseChord, typeUInt32, 0, | ||
| 1703 | // sizeof(mac_buttons), 0, &mac_buttons); | ||
| 1704 | // buttons = qt_mac_get_buttons(mac_buttons); | ||
| 1705 | // } | ||
| 1706 | // | ||
| 1707 | // int wheel_deltaX = 0; | ||
| 1708 | // int wheel_deltaY = 0; | ||
| 1709 | // static EventRef compatibilityEvent = 0; | ||
| 1710 | // | ||
| 1711 | // if (ekind == kEventMouseScroll) { | ||
| 1712 | // // kEventMouseScroll is the new way of dealing with mouse wheel | ||
| 1713 | // // events (kEventMouseWheelMoved was the old). kEventMouseScroll results | ||
| 1714 | // // in much smoother scrolling when using Mighty Mouse or TrackPad. For | ||
| 1715 | // // compatibility with older applications, carbon will also send us | ||
| 1716 | // // kEventMouseWheelMoved events if we dont eat this event | ||
| 1717 | // // (actually two events; one for horizontal and one for vertical). | ||
| 1718 | // // As a results of this, and to make sure we dont't receive duplicate events, | ||
| 1719 | // // we try to detect when this happend by checking the 'compatibilityEvent'. | ||
| 1720 | // SInt32 mdelt = 0; | ||
| 1721 | // GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0, | ||
| 1722 | // sizeof(mdelt), 0, &mdelt); | ||
| 1723 | // wheel_deltaX = mdelt; | ||
| 1724 | // mdelt = 0; | ||
| 1725 | // GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0, | ||
| 1726 | // sizeof(mdelt), 0, &mdelt); | ||
| 1727 | // wheel_deltaY = mdelt; | ||
| 1728 | // GetEventParameter(event, kEventParamEventRef, typeEventRef, 0, | ||
| 1729 | // sizeof(compatibilityEvent), 0, &compatibilityEvent); | ||
| 1730 | // } else if (ekind == kEventMouseWheelMoved) { | ||
| 1731 | // if (event != compatibilityEvent) { | ||
| 1732 | // compatibilityEvent = 0; | ||
| 1733 | // int mdelt = 0; | ||
| 1734 | // GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0, | ||
| 1735 | // sizeof(mdelt), 0, &mdelt); | ||
| 1736 | // EventMouseWheelAxis axis; | ||
| 1737 | // GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, 0, | ||
| 1738 | // sizeof(axis), 0, &axis); | ||
| 1739 | // | ||
| 1740 | // // Remove acceleration, and use either -120 or 120 as delta: | ||
| 1741 | // if (axis == kEventMouseWheelAxisX) | ||
| 1742 | // wheel_deltaX = qBound(-120, int(mdelt * 10000), 120); | ||
| 1743 | // else | ||
| 1744 | // wheel_deltaY = qBound(-120, int(mdelt * 10000), 120); | ||
| 1745 | // } | ||
| 1746 | // } | ||
| 1747 | // | ||
| 1748 | // Qt::MouseButton button = Qt::NoButton; | ||
| 1749 | // if(ekind == kEventMouseDown || ekind == kEventMouseUp) { | ||
| 1750 | // EventMouseButton mac_button = 0; | ||
| 1751 | // GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0, | ||
| 1752 | // sizeof(mac_button), 0, &mac_button); | ||
| 1753 | // button = qt_mac_get_button(mac_button); | ||
| 1754 | // } | ||
| 1755 | // | ||
| 1756 | // switch(ekind) { | ||
| 1757 | // case kEventMouseDown: | ||
| 1758 | // etype = QEvent::MouseButtonPress; | ||
| 1759 | // break; | ||
| 1760 | // case kEventMouseUp: | ||
| 1761 | // etype = QEvent::MouseButtonRelease; | ||
| 1762 | // break; | ||
| 1763 | // case kEventMouseDragged: | ||
| 1764 | // case kEventMouseMoved: | ||
| 1765 | // etype = QEvent::MouseMove; | ||
| 1766 | // break; | ||
| 1767 | // } | ||
| 1768 | // | ||
| 1769 | // const bool inPopupMode = app->d_func()->inPopupMode(); | ||
| 1770 | // | ||
| 1771 | // // A click outside a popup closes the popup. Make sure | ||
| 1772 | // // that no events are generated for the release part of that click. | ||
| 1773 | // // (The press goes to the popup and closes it.) | ||
| 1774 | // if (etype == QEvent::MouseButtonPress) { | ||
| 1775 | // qt_mac_previous_press_in_popup_mode = inPopupMode; | ||
| 1776 | // } else if (qt_mac_previous_press_in_popup_mode && !inPopupMode && etype == QEvent::MouseButtonRelease) { | ||
| 1777 | // qt_mac_previous_press_in_popup_mode = false; | ||
| 1778 | // handled_event = true; | ||
| 1779 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 1780 | // qDebug("Bail out early due to qt_mac_previous_press_in_popup_mode"); | ||
| 1781 | //#endif | ||
| 1782 | // break; // break from case kEventClassMouse | ||
| 1783 | // } | ||
| 1784 | // | ||
| 1785 | // //figure out which widget to send it to | ||
| 1786 | // if(inPopupMode) { | ||
| 1787 | // QWidget *popup = qApp->activePopupWidget(); | ||
| 1788 | // if (qt_button_down && qt_button_down->window() == popup) { | ||
| 1789 | // widget = qt_button_down; | ||
| 1790 | // } else { | ||
| 1791 | // QPoint pos = popup->mapFromGlobal(QPoint(where.h, where.v)); | ||
| 1792 | // widget = popup->childAt(pos); | ||
| 1793 | // } | ||
| 1794 | // if(!widget) | ||
| 1795 | // widget = popup; | ||
| 1796 | // } else { | ||
| 1797 | // if(mac_mouse_grabber) { | ||
| 1798 | // widget = mac_mouse_grabber; | ||
| 1799 | // } else if (qt_button_down) { | ||
| 1800 | // widget = qt_button_down; | ||
| 1801 | // } else { | ||
| 1802 | // { | ||
| 1803 | // WindowPtr window = 0; | ||
| 1804 | // if(GetEventParameter(event, kEventParamWindowRef, typeWindowRef, 0, | ||
| 1805 | // sizeof(window), 0, &window) != noErr) | ||
| 1806 | // FindWindowOfClass(&where, kAllWindowClasses, &window, 0); | ||
| 1807 | // if(window) { | ||
| 1808 | // HIViewRef hiview; | ||
| 1809 | // if(HIViewGetViewForMouseEvent(HIViewGetRoot(window), event, &hiview) == noErr) { | ||
| 1810 | // widget = QWidget::find((WId)hiview); | ||
| 1811 | // if (widget) { | ||
| 1812 | // // Make sure we didn't pass over a widget with a "fake hole" in it. | ||
| 1813 | // QWidget *otherWidget = QApplication::widgetAt(where.h, where.v); | ||
| 1814 | // if (otherWidget && otherWidget->testAttribute(Qt::WA_MouseNoMask)) | ||
| 1815 | // widget = otherWidget; | ||
| 1816 | // } | ||
| 1817 | // } | ||
| 1818 | // } | ||
| 1819 | // } | ||
| 1820 | // if(!widget) //fallback | ||
| 1821 | // widget = QApplication::widgetAt(where.h, where.v); | ||
| 1822 | // if(ekind == kEventMouseUp && widget) { | ||
| 1823 | // short part = qt_mac_window_at(where.h, where.v); | ||
| 1824 | // if(part == inDrag) { | ||
| 1825 | // UInt32 count = 0; | ||
| 1826 | // GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL, | ||
| 1827 | // sizeof(count), NULL, &count); | ||
| 1828 | // if(count == 2 && qt_mac_collapse_on_dblclick) { | ||
| 1829 | // if (widget->macEvent(er, event)) | ||
| 1830 | // return noErr; | ||
| 1831 | // widget->setWindowState(widget->windowState() | Qt::WindowMinimized); | ||
| 1832 | // //we send a hide to be like X11/Windows | ||
| 1833 | // QEvent e(QEvent::Hide); | ||
| 1834 | // QApplication::sendSpontaneousEvent(widget, &e); | ||
| 1835 | // break; | ||
| 1836 | // } | ||
| 1837 | // } | ||
| 1838 | // } | ||
| 1839 | // } | ||
| 1840 | // } | ||
| 1841 | // if (widget && widget->macEvent(er, event)) | ||
| 1842 | // return noErr; | ||
| 1843 | // WindowPartCode wpc = qt_mac_window_at(where.h, where.v, 0); | ||
| 1844 | // if (wpc == inProxyIcon && modifiers == Qt::ControlModifier && buttons != Qt::NoButton) { | ||
| 1845 | // QIconDragEvent e; | ||
| 1846 | // QApplication::sendSpontaneousEvent(widget, &e); | ||
| 1847 | // if (e.isAccepted()) { | ||
| 1848 | // return noErr; // IconDrag ate it. | ||
| 1849 | // } | ||
| 1850 | // } | ||
| 1851 | // if (inPopupMode == false | ||
| 1852 | // && (qt_button_down == 0 || qt_button_down_in_content == false) | ||
| 1853 | // && (wpc != inContent && wpc != inStructure)) { | ||
| 1854 | // inNonClientArea = true; | ||
| 1855 | // switch (etype) { | ||
| 1856 | // case QEvent::MouseButtonPress: { | ||
| 1857 | // UInt32 count = 0; | ||
| 1858 | // GetEventParameter(event, kEventParamClickCount, typeUInt32, 0, | ||
| 1859 | // sizeof(count), 0, &count); | ||
| 1860 | // if(count % 2 || count == 0) { | ||
| 1861 | // etype = QEvent::NonClientAreaMouseButtonPress; | ||
| 1862 | // } else { | ||
| 1863 | // etype = QEvent::NonClientAreaMouseButtonDblClick; | ||
| 1864 | // }} break; | ||
| 1865 | // case QEvent::MouseButtonRelease: | ||
| 1866 | // etype = QEvent::NonClientAreaMouseButtonRelease; | ||
| 1867 | // break; | ||
| 1868 | // case QEvent::MouseMove: | ||
| 1869 | // if (widget == 0 || widget->hasMouseTracking()) | ||
| 1870 | // etype = QEvent::NonClientAreaMouseMove; | ||
| 1871 | // break; | ||
| 1872 | // default: | ||
| 1873 | // break; | ||
| 1874 | // } | ||
| 1875 | // } | ||
| 1876 | // | ||
| 1877 | // if(qt_mac_find_window((FrontWindow()))) { //set the cursor up | ||
| 1878 | // QCursor cursor(Qt::ArrowCursor); | ||
| 1879 | // QWidget *cursor_widget = widget; | ||
| 1880 | // if(cursor_widget && cursor_widget == qt_button_down && ekind == kEventMouseUp) | ||
| 1881 | // cursor_widget = QApplication::widgetAt(where.h, where.v); | ||
| 1882 | // if(cursor_widget) { //only over the app, do we set a cursor.. | ||
| 1883 | // if(!qApp->d_func()->cursor_list.isEmpty()) { | ||
| 1884 | // cursor = qApp->d_func()->cursor_list.first(); | ||
| 1885 | // } else { | ||
| 1886 | // for(; cursor_widget; cursor_widget = cursor_widget->parentWidget()) { | ||
| 1887 | // QWExtra *extra = cursor_widget->d_func()->extraData(); | ||
| 1888 | // if(extra && extra->curs && cursor_widget->isEnabled()) { | ||
| 1889 | // cursor = *extra->curs; | ||
| 1890 | // break; | ||
| 1891 | // } | ||
| 1892 | // } | ||
| 1893 | // } | ||
| 1894 | // } | ||
| 1895 | // qt_mac_set_cursor(&cursor, QPoint(where.h, where.v)); | ||
| 1896 | // } | ||
| 1897 | // | ||
| 1898 | // //This mouse button state stuff looks like this on purpose | ||
| 1899 | // //although it looks hacky it is VERY intentional.. | ||
| 1900 | // if(widget && app_do_modal && !qt_try_modal(widget, event)) { | ||
| 1901 | // if(ekind == kEventMouseDown && qt_mac_is_macsheet(QApplication::activeModalWidget())) | ||
| 1902 | // QApplication::activeModalWidget()->parentWidget()->activateWindow(); //sheets have a parent | ||
| 1903 | // handled_event = false; | ||
| 1904 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 1905 | // qDebug("Bail out early due to qt_try_modal"); | ||
| 1906 | //#endif | ||
| 1907 | // break; | ||
| 1908 | // } | ||
| 1909 | // | ||
| 1910 | // UInt32 tabletEventType = 0; | ||
| 1911 | // GetEventParameter(event, kEventParamTabletEventType, typeUInt32, 0, | ||
| 1912 | // sizeof(tabletEventType), 0, &tabletEventType); | ||
| 1913 | // if (tabletEventType == kEventTabletPoint) { | ||
| 1914 | // TabletPointRec tabletPointRec; | ||
| 1915 | // GetEventParameter(event, kEventParamTabletPointRec, typeTabletPointRec, 0, | ||
| 1916 | // sizeof(tabletPointRec), 0, &tabletPointRec); | ||
| 1917 | // QEvent::Type t = QEvent::TabletMove; //default | ||
| 1918 | // int new_tablet_button_state = tabletPointRec.buttons ? 1 : 0; | ||
| 1919 | // if (new_tablet_button_state != tablet_button_state) | ||
| 1920 | // if (new_tablet_button_state) | ||
| 1921 | // t = QEvent::TabletPress; | ||
| 1922 | // else | ||
| 1923 | // t = QEvent::TabletRelease; | ||
| 1924 | // tablet_button_state = new_tablet_button_state; | ||
| 1925 | // | ||
| 1926 | // QMacTabletHash *tabletHash = qt_mac_tablet_hash(); | ||
| 1927 | // if (!tabletHash->contains(tabletPointRec.deviceID) && t != QEvent::TabletRelease) { | ||
| 1928 | // // Never discard TabletRelease events as they may be delivered *after* TabletLeaveProximity events | ||
| 1929 | // qWarning("handleTabletEvent: This tablet device is unknown" | ||
| 1930 | // " (received no proximity event for it). Discarding event."); | ||
| 1931 | // return false; | ||
| 1932 | // } | ||
| 1933 | // QTabletDeviceData &deviceData = tabletHash->operator[](tabletPointRec.deviceID); | ||
| 1934 | // if (t == QEvent::TabletPress) { | ||
| 1935 | // deviceData.widgetToGetPress = widget; | ||
| 1936 | // } else if (t == QEvent::TabletRelease && deviceData.widgetToGetPress) { | ||
| 1937 | // widget = deviceData.widgetToGetPress; | ||
| 1938 | // deviceData.widgetToGetPress = 0; | ||
| 1939 | // } | ||
| 1940 | // | ||
| 1941 | // if (widget) { | ||
| 1942 | // int tiltX = ((int)tabletPointRec.tiltX)/(32767/64); // 32K -> 60 | ||
| 1943 | // int tiltY = ((int)tabletPointRec.tiltY)/(-32767/64); // 32K -> 60 | ||
| 1944 | // HIPoint hiPoint; | ||
| 1945 | // GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0, sizeof(HIPoint), 0, &hiPoint); | ||
| 1946 | // QPointF hiRes(hiPoint.x, hiPoint.y); | ||
| 1947 | // QPoint global(where.h, where.v); | ||
| 1948 | // | ||
| 1949 | // | ||
| 1950 | // | ||
| 1951 | // QPoint local(widget->mapFromGlobal(global)); | ||
| 1952 | // int z = 0; | ||
| 1953 | // qreal rotation = 0.0; | ||
| 1954 | // qreal tp = 0.0; | ||
| 1955 | // // Again from the Wacom.h header | ||
| 1956 | // | ||
| 1957 | // if (deviceData.capabilityMask & 0x0200) // Z-axis | ||
| 1958 | // z = tabletPointRec.absZ; | ||
| 1959 | // | ||
| 1960 | // if (deviceData.capabilityMask & 0x0800) // Tangential pressure | ||
| 1961 | // tp = tabletPointRec.tangentialPressure / 32767.0; | ||
| 1962 | // | ||
| 1963 | // if (deviceData.capabilityMask & 0x2000) // Rotation | ||
| 1964 | // rotation = qreal(tabletPointRec.rotation) / 64.0; | ||
| 1965 | // | ||
| 1966 | // QTabletEvent e(t, local, global, hiRes, deviceData.tabletDeviceType, | ||
| 1967 | // deviceData.tabletPointerType, | ||
| 1968 | // qreal(tabletPointRec.pressure / qreal(0xffff)), tiltX, tiltY, | ||
| 1969 | // tp, rotation, z, modifiers, deviceData.tabletUniqueID); | ||
| 1970 | // QApplication::sendSpontaneousEvent(widget, &e); | ||
| 1971 | // if (e.isAccepted()) { | ||
| 1972 | // if (t == QEvent::TabletPress) { | ||
| 1973 | // qt_button_down = widget; | ||
| 1974 | // } else if (t == QEvent::TabletRelease) { | ||
| 1975 | // qt_button_down = 0; | ||
| 1976 | // } | ||
| 1977 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 1978 | // qDebug("Bail out early due to tablet acceptance"); | ||
| 1979 | //#endif | ||
| 1980 | // break; | ||
| 1981 | // } | ||
| 1982 | // } | ||
| 1983 | // } | ||
| 1984 | // | ||
| 1985 | // if(ekind == kEventMouseDown) { | ||
| 1986 | // qt_mac_no_click_through_mode = false; | ||
| 1987 | // const short windowPart = qt_mac_window_at(where.h, where.v, 0); | ||
| 1988 | // // Menubar almost always wins. | ||
| 1989 | // if (!inPopupMode && windowPart == inMenuBar) { | ||
| 1990 | // MenuSelect(where); //allow menu tracking | ||
| 1991 | // return noErr; | ||
| 1992 | // } | ||
| 1993 | // | ||
| 1994 | // if (widget && !(GetCurrentKeyModifiers() & cmdKey)) { | ||
| 1995 | // extern bool qt_isGenuineQWidget(const QWidget *); // qwidget_mac.cpp | ||
| 1996 | // QWidget *window = widget->window(); | ||
| 1997 | // bool genuineQtWidget = qt_isGenuineQWidget(widget); // the widget, not the window. | ||
| 1998 | // window->raise(); | ||
| 1999 | // | ||
| 2000 | // bool needActivate = (window->windowType() != Qt::Desktop) | ||
| 2001 | // && (window->windowType() != Qt::Popup) | ||
| 2002 | // && !qt_mac_is_macsheet(window); | ||
| 2003 | // if (needActivate && (!window->isModal() && qobject_cast<QDockWidget *>(window))) | ||
| 2004 | // needActivate = false; | ||
| 2005 | // | ||
| 2006 | // if (genuineQtWidget && needActivate) | ||
| 2007 | // needActivate = !window->isActiveWindow() | ||
| 2008 | // || !IsWindowActive(qt_mac_window_for(window)); | ||
| 2009 | // | ||
| 2010 | // if (needActivate) { | ||
| 2011 | // window->activateWindow(); | ||
| 2012 | // if (!qt_mac_can_clickThrough(widget)) { | ||
| 2013 | // qt_mac_no_click_through_mode = true; | ||
| 2014 | // handled_event = false; | ||
| 2015 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 2016 | // qDebug("Bail out early due to qt_mac_canClickThrough %s::%s", widget->metaObject()->className(), | ||
| 2017 | // widget->objectName().toLocal8Bit().constData()); | ||
| 2018 | //#endif | ||
| 2019 | // break; | ||
| 2020 | // } | ||
| 2021 | // } | ||
| 2022 | // } | ||
| 2023 | // | ||
| 2024 | // if(qt_mac_dblclick.last_widget && | ||
| 2025 | // qt_mac_dblclick.last_x != -1 && qt_mac_dblclick.last_y != -1 && | ||
| 2026 | // QRect(qt_mac_dblclick.last_x-2, qt_mac_dblclick.last_y-2, 4, 4).contains(QPoint(where.h, where.v))) { | ||
| 2027 | // if(qt_mac_dblclick.use_qt_time_limit) { | ||
| 2028 | // EventTime now = GetEventTime(event); | ||
| 2029 | // if(qt_mac_dblclick.last_time != -2 && qt_mac_dblclick.last_widget == widget && | ||
| 2030 | // now - qt_mac_dblclick.last_time <= ((double)QApplicationPrivate::mouse_double_click_time)/1000 && | ||
| 2031 | // qt_mac_dblclick.last_button == button) | ||
| 2032 | // etype = QEvent::MouseButtonDblClick; | ||
| 2033 | // } else { | ||
| 2034 | // UInt32 count = 0; | ||
| 2035 | // GetEventParameter(event, kEventParamClickCount, typeUInt32, 0, | ||
| 2036 | // sizeof(count), 0, &count); | ||
| 2037 | // if(!(count % 2) && qt_mac_dblclick.last_modifiers == modifiers && | ||
| 2038 | // qt_mac_dblclick.last_widget == widget && qt_mac_dblclick.last_button == button) | ||
| 2039 | // etype = QEvent::MouseButtonDblClick; | ||
| 2040 | // } | ||
| 2041 | // if(etype == QEvent::MouseButtonDblClick) | ||
| 2042 | // qt_mac_dblclick.last_widget = 0; | ||
| 2043 | // } | ||
| 2044 | // if(etype != QEvent::MouseButtonDblClick) { | ||
| 2045 | // qt_mac_dblclick.last_x = where.h; | ||
| 2046 | // qt_mac_dblclick.last_y = where.v; | ||
| 2047 | // } else { | ||
| 2048 | // qt_mac_dblclick.last_x = qt_mac_dblclick.last_y = -1; | ||
| 2049 | // } | ||
| 2050 | // } else if(qt_mac_no_click_through_mode) { | ||
| 2051 | // if(ekind == kEventMouseUp) | ||
| 2052 | // qt_mac_no_click_through_mode = false; | ||
| 2053 | // handled_event = false; | ||
| 2054 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 2055 | // qDebug("Bail out early due to qt_mac_no_click_through_mode"); | ||
| 2056 | //#endif | ||
| 2057 | // break; | ||
| 2058 | // } | ||
| 2059 | // | ||
| 2060 | // QPointer<QWidget> leaveAfterRelease = 0; | ||
| 2061 | // switch(ekind) { | ||
| 2062 | // case kEventMouseUp: | ||
| 2063 | // if (!buttons) { | ||
| 2064 | // if (!inPopupMode && !QWidget::mouseGrabber()) | ||
| 2065 | // leaveAfterRelease = qt_button_down; | ||
| 2066 | // qt_button_down = 0; | ||
| 2067 | // } | ||
| 2068 | // break; | ||
| 2069 | // case kEventMouseDown: { | ||
| 2070 | // if (!qt_button_down) | ||
| 2071 | // qt_button_down = widget; | ||
| 2072 | // WindowPartCode wpc = qt_mac_window_at(where.h, where.v, 0); | ||
| 2073 | // qt_button_down_in_content = (wpc == inContent || wpc == inStructure); | ||
| 2074 | // break; } | ||
| 2075 | // } | ||
| 2076 | // | ||
| 2077 | // // Check if we should send enter/leave events: | ||
| 2078 | // switch(ekind) { | ||
| 2079 | // case kEventMouseDragged: | ||
| 2080 | // case kEventMouseMoved: | ||
| 2081 | // case kEventMouseUp: | ||
| 2082 | // case kEventMouseDown: { | ||
| 2083 | // // If we are in popup mode, widget will point to the current popup no matter | ||
| 2084 | // // where the mouse cursor is. In that case find out if the mouse cursor is | ||
| 2085 | // // really over the popup in order to send correct enter / leave envents. | ||
| 2086 | // QWidget * const enterLeaveWidget = (inPopupMode || ekind == kEventMouseUp) ? | ||
| 2087 | // QApplication::widgetAt(where.h, where.v) : static_cast<QWidget*>(widget); | ||
| 2088 | // | ||
| 2089 | // if ((QWidget *) qt_mouseover != enterLeaveWidget || inNonClientArea) { | ||
| 2090 | //#ifdef DEBUG_MOUSE_MAPS | ||
| 2091 | // qDebug("Entering: %p - %s (%s), Leaving %s (%s)", (QWidget*)enterLeaveWidget, | ||
| 2092 | // enterLeaveWidget ? enterLeaveWidget->metaObject()->className() : "none", | ||
| 2093 | // enterLeaveWidget ? enterLeaveWidget->objectName().toLocal8Bit().constData() : "", | ||
| 2094 | // qt_mouseover ? qt_mouseover->metaObject()->className() : "none", | ||
| 2095 | // qt_mouseover ? qt_mouseover->objectName().toLocal8Bit().constData() : ""); | ||
| 2096 | //#endif | ||
| 2097 | // | ||
| 2098 | // QWidget * const mouseGrabber = QWidget::mouseGrabber(); | ||
| 2099 | // | ||
| 2100 | // if (inPopupMode) { | ||
| 2101 | // QWidget *enter = enterLeaveWidget; | ||
| 2102 | // QWidget *leave = qt_mouseover; | ||
| 2103 | // if (mouseGrabber) { | ||
| 2104 | // QWidget * const popupWidget = qApp->activePopupWidget(); | ||
| 2105 | // if (leave == popupWidget) | ||
| 2106 | // enter = mouseGrabber; | ||
| 2107 | // if (enter == popupWidget) | ||
| 2108 | // leave = mouseGrabber; | ||
| 2109 | // if ((enter == mouseGrabber && leave == popupWidget) | ||
| 2110 | // || (leave == mouseGrabber && enter == popupWidget)) { | ||
| 2111 | // QApplicationPrivate::dispatchEnterLeave(enter, leave); | ||
| 2112 | // qt_mouseover = enter; | ||
| 2113 | // } | ||
| 2114 | // } else { | ||
| 2115 | // QApplicationPrivate::dispatchEnterLeave(enter, leave); | ||
| 2116 | // qt_mouseover = enter; | ||
| 2117 | // } | ||
| 2118 | // } else if ((!qt_button_down || !qt_mouseover) && !mouseGrabber && !leaveAfterRelease) { | ||
| 2119 | // QApplicationPrivate::dispatchEnterLeave(enterLeaveWidget, qt_mouseover); | ||
| 2120 | // qt_mouseover = enterLeaveWidget; | ||
| 2121 | // } | ||
| 2122 | // } | ||
| 2123 | // break; } | ||
| 2124 | // } | ||
| 2125 | // | ||
| 2126 | // if(widget) { | ||
| 2127 | // QPoint p(where.h, where.v); | ||
| 2128 | // QPoint plocal(widget->mapFromGlobal(p)); | ||
| 2129 | // if(etype == QEvent::MouseButtonPress) { | ||
| 2130 | // qt_mac_dblclick.last_widget = widget; | ||
| 2131 | // qt_mac_dblclick.last_modifiers = modifiers; | ||
| 2132 | // qt_mac_dblclick.last_button = button; | ||
| 2133 | // qt_mac_dblclick.last_time = GetEventTime(event); | ||
| 2134 | // } | ||
| 2135 | // | ||
| 2136 | // if (wheel_deltaX || wheel_deltaY) { | ||
| 2137 | // if (wheel_deltaX) { | ||
| 2138 | // QWheelEvent qwe(plocal, p, wheel_deltaX, buttons, modifiers, Qt::Horizontal); | ||
| 2139 | // QApplication::sendSpontaneousEvent(widget, &qwe); | ||
| 2140 | // if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) { | ||
| 2141 | // QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p, | ||
| 2142 | // wheel_deltaX, buttons, modifiers, Qt::Horizontal); | ||
| 2143 | // QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); | ||
| 2144 | // if (!qwe2.isAccepted()) | ||
| 2145 | // handled_event = false; | ||
| 2146 | // } | ||
| 2147 | // } | ||
| 2148 | // if (wheel_deltaY) { | ||
| 2149 | // QWheelEvent qwe(plocal, p, wheel_deltaY, buttons, modifiers, Qt::Vertical); | ||
| 2150 | // QApplication::sendSpontaneousEvent(widget, &qwe); | ||
| 2151 | // if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) { | ||
| 2152 | // QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p, | ||
| 2153 | // wheel_deltaY, buttons, modifiers, Qt::Vertical); | ||
| 2154 | // QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); | ||
| 2155 | // if (!qwe2.isAccepted()) | ||
| 2156 | // handled_event = false; | ||
| 2157 | // } | ||
| 2158 | // } | ||
| 2159 | // } else { | ||
| 2160 | //#ifdef QMAC_SPEAK_TO_ME | ||
| 2161 | // const int speak_keys = Qt::AltModifier | Qt::ShiftModifier; | ||
| 2162 | // if(etype == QMouseEvent::MouseButtonDblClick && ((modifiers & speak_keys) == speak_keys)) { | ||
| 2163 | // QVariant v = widget->property("displayText"); | ||
| 2164 | // if(!v.isValid()) v = widget->property("text"); | ||
| 2165 | // if(!v.isValid()) v = widget->property("windowTitle"); | ||
| 2166 | // if(v.isValid()) { | ||
| 2167 | // QString s = v.toString(); | ||
| 2168 | // s.replace(QRegExp(QString::fromLatin1("(\\&|\\<[^\\>]*\\>)")), QLatin1String("")); | ||
| 2169 | // SpeechChannel ch; | ||
| 2170 | // NewSpeechChannel(0, &ch); | ||
| 2171 | // SpeakText(ch, s.toLatin1().constData(), s.length()); | ||
| 2172 | // DisposeSpeechChannel(ch); | ||
| 2173 | // } | ||
| 2174 | // } | ||
| 2175 | //#endif | ||
| 2176 | // Qt::MouseButton buttonToSend = button; | ||
| 2177 | // static bool lastButtonTranslated = false; | ||
| 2178 | // if(ekind == kEventMouseDown && | ||
| 2179 | // button == Qt::LeftButton && (modifiers & Qt::MetaModifier)) { | ||
| 2180 | // buttonToSend = Qt::RightButton; | ||
| 2181 | // lastButtonTranslated = true; | ||
| 2182 | // } else if(ekind == kEventMouseUp && lastButtonTranslated) { | ||
| 2183 | // buttonToSend = Qt::RightButton; | ||
| 2184 | // lastButtonTranslated = false; | ||
| 2185 | // } | ||
| 2186 | // QMouseEvent qme(etype, plocal, p, buttonToSend, buttons, modifiers); | ||
| 2187 | // QApplication::sendSpontaneousEvent(widget, &qme); | ||
| 2188 | // if(!qme.isAccepted() || inNonClientArea) | ||
| 2189 | // handled_event = false; | ||
| 2190 | // } | ||
| 2191 | // | ||
| 2192 | // if (leaveAfterRelease) { | ||
| 2193 | // QWidget *enter = QApplication::widgetAt(where.h, where.v); | ||
| 2194 | // QApplicationPrivate::dispatchEnterLeave(enter, leaveAfterRelease); | ||
| 2195 | // qt_mouseover = enter; | ||
| 2196 | // leaveAfterRelease = 0; | ||
| 2197 | // } | ||
| 2198 | // | ||
| 2199 | // if(ekind == kEventMouseDown && | ||
| 2200 | // ((button == Qt::RightButton) || | ||
| 2201 | // (button == Qt::LeftButton && (modifiers & Qt::MetaModifier)))) | ||
| 2202 | // qt_event_request_context(); | ||
| 2203 | // | ||
| 2204 | //#ifdef DEBUG_MOUSE_MAPS | ||
| 2205 | // const char *event_desc = edesc; | ||
| 2206 | // if(etype == QEvent::MouseButtonDblClick) | ||
| 2207 | // event_desc = "Double Click"; | ||
| 2208 | // else if(etype == QEvent::NonClientAreaMouseButtonPress) | ||
| 2209 | // event_desc = "NonClientMousePress"; | ||
| 2210 | // else if(etype == QEvent::NonClientAreaMouseButtonRelease) | ||
| 2211 | // event_desc = "NonClientMouseRelease"; | ||
| 2212 | // else if(etype == QEvent::NonClientAreaMouseMove) | ||
| 2213 | // event_desc = "NonClientMouseMove"; | ||
| 2214 | // else if(etype == QEvent::NonClientAreaMouseButtonDblClick) | ||
| 2215 | // event_desc = "NonClientMouseDblClick"; | ||
| 2216 | // qDebug("%d %d (%d %d) - Would send (%s) event to %p %s %s (%d 0x%08x 0x%08x %d)", p.x(), p.y(), | ||
| 2217 | // plocal.x(), plocal.y(), event_desc, (QWidget*)widget, | ||
| 2218 | // widget ? widget->objectName().toLocal8Bit().constData() : "*Unknown*", | ||
| 2219 | // widget ? widget->metaObject()->className() : "*Unknown*", | ||
| 2220 | // button, (int)buttons, (int)modifiers, wheel_deltaX); | ||
| 2221 | //#endif | ||
| 2222 | // } else { | ||
| 2223 | // handled_event = false; | ||
| 2224 | // } | ||
| 2225 | // break; | ||
| 2226 | // } | ||
| 2227 | // case kEventClassTextInput: | ||
| 2228 | // case kEventClassKeyboard: { | ||
| 2229 | // EventRef key_event = event; | ||
| 2230 | // if(eclass == kEventClassTextInput) { | ||
| 2231 | // Q_ASSERT(ekind == kEventTextInputUnicodeForKeyEvent); | ||
| 2232 | // OSStatus err = GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, 0, | ||
| 2233 | // sizeof(key_event), 0, &key_event); | ||
| 2234 | // Q_ASSERT(err == noErr); | ||
| 2235 | // Q_UNUSED(err); | ||
| 2236 | // } | ||
| 2237 | // const UInt32 key_ekind = GetEventKind(key_event); | ||
| 2238 | // Q_ASSERT(GetEventClass(key_event) == kEventClassKeyboard); | ||
| 2239 | // | ||
| 2240 | // if(key_ekind == kEventRawKeyDown) | ||
| 2241 | // qt_keymapper_private()->updateKeyMap(er, key_event, data); | ||
| 2242 | // if(mac_keyboard_grabber) | ||
| 2243 | // widget = mac_keyboard_grabber; | ||
| 2244 | // else if (app->activePopupWidget()) | ||
| 2245 | // widget = (app->activePopupWidget()->focusWidget() ? | ||
| 2246 | // app->activePopupWidget()->focusWidget() : app->activePopupWidget()); | ||
| 2247 | // else if(QApplication::focusWidget()) | ||
| 2248 | // widget = QApplication::focusWidget(); | ||
| 2249 | // else | ||
| 2250 | // widget = app->activeWindow(); | ||
| 2251 | // | ||
| 2252 | // if (widget) { | ||
| 2253 | // if (widget->macEvent(er, event)) | ||
| 2254 | // return noErr; | ||
| 2255 | // } else { | ||
| 2256 | // // Darn, I need to update tho modifier state, even though | ||
| 2257 | // // Qt itself isn't getting them, otherwise the keyboard state get inconsistent. | ||
| 2258 | // if (key_ekind == kEventRawKeyModifiersChanged) { | ||
| 2259 | // UInt32 modifiers = 0; | ||
| 2260 | // GetEventParameter(key_event, kEventParamKeyModifiers, typeUInt32, 0, | ||
| 2261 | // sizeof(modifiers), 0, &modifiers); | ||
| 2262 | // extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object); // qkeymapper_mac.cpp | ||
| 2263 | // // Just send it to the qApp for the time being. | ||
| 2264 | // qt_mac_send_modifiers_changed(modifiers, qApp); | ||
| 2265 | // } | ||
| 2266 | // handled_event = false; | ||
| 2267 | // break; | ||
| 2268 | // } | ||
| 2269 | // | ||
| 2270 | // if(app_do_modal && !qt_try_modal(widget, key_event)) | ||
| 2271 | // break; | ||
| 2272 | // if (eclass == kEventClassTextInput) { | ||
| 2273 | // handled_event = false; | ||
| 2274 | // } else { | ||
| 2275 | // handled_event = qt_keymapper_private()->translateKeyEvent(widget, er, key_event, data, | ||
| 2276 | // widget == mac_keyboard_grabber); | ||
| 2277 | // } | ||
| 2278 | // break; } | ||
| 2279 | // case kEventClassWindow: { | ||
| 2280 | // WindowRef wid = 0; | ||
| 2281 | // GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, | ||
| 2282 | // sizeof(WindowRef), 0, &wid); | ||
| 2283 | // widget = qt_mac_find_window(wid); | ||
| 2284 | // if (widget && widget->macEvent(er, event)) | ||
| 2285 | // return noErr; | ||
| 2286 | // if(ekind == kEventWindowActivated) { | ||
| 2287 | // if(QApplicationPrivate::app_style) { | ||
| 2288 | // QEvent ev(QEvent::Style); | ||
| 2289 | // QApplication::sendSpontaneousEvent(QApplicationPrivate::app_style, &ev); | ||
| 2290 | // } | ||
| 2291 | // | ||
| 2292 | // if(widget && app_do_modal && !qt_try_modal(widget, event)) | ||
| 2293 | // break; | ||
| 2294 | // | ||
| 2295 | // if(widget && widget->window()->isVisible()) { | ||
| 2296 | // QWidget *tlw = widget->window(); | ||
| 2297 | // if(tlw->isWindow() && !(tlw->windowType() == Qt::Popup) | ||
| 2298 | // && !qt_mac_is_macdrawer(tlw) | ||
| 2299 | // && (!tlw->parentWidget() || tlw->isModal() | ||
| 2300 | // || !(tlw->windowType() == Qt::Tool))) { | ||
| 2301 | // bool just_send_event = false; | ||
| 2302 | // { | ||
| 2303 | // WindowActivationScope scope; | ||
| 2304 | // if(GetWindowActivationScope((WindowRef)wid, &scope) == noErr && | ||
| 2305 | // scope == kWindowActivationScopeIndependent) { | ||
| 2306 | // if(GetFrontWindowOfClass(kAllWindowClasses, true) != wid) | ||
| 2307 | // just_send_event = true; | ||
| 2308 | // } | ||
| 2309 | // } | ||
| 2310 | // if(just_send_event) { | ||
| 2311 | // QEvent e(QEvent::WindowActivate); | ||
| 2312 | // QApplication::sendSpontaneousEvent(widget, &e); | ||
| 2313 | // } else { | ||
| 2314 | // app->setActiveWindow(tlw); | ||
| 2315 | // } | ||
| 2316 | // } | ||
| 2317 | // QMenuBar::macUpdateMenuBar(); | ||
| 2318 | // } | ||
| 2319 | // } else if(ekind == kEventWindowDeactivated) { | ||
| 2320 | // if(widget && QApplicationPrivate::active_window == widget) | ||
| 2321 | // app->setActiveWindow(0); | ||
| 2322 | // } else { | ||
| 2323 | // handled_event = false; | ||
| 2324 | // } | ||
| 2325 | // break; } | ||
| 2326 | // case kEventClassApplication: | ||
| 2327 | // if(ekind == kEventAppActivated) { | ||
| 2328 | // if(QApplication::desktopSettingsAware()) | ||
| 2329 | // qt_mac_update_os_settings(); | ||
| 2330 | // if(qt_clipboard) { //manufacture an event so the clipboard can see if it has changed | ||
| 2331 | // QEvent ev(QEvent::Clipboard); | ||
| 2332 | // QApplication::sendSpontaneousEvent(qt_clipboard, &ev); | ||
| 2333 | // } | ||
| 2334 | // if(app) { | ||
| 2335 | // QEvent ev(QEvent::ApplicationActivate); | ||
| 2336 | // QApplication::sendSpontaneousEvent(app, &ev); | ||
| 2337 | // } | ||
| 2338 | // if(!app->activeWindow()) { | ||
| 2339 | // WindowPtr wp = ActiveNonFloatingWindow(); | ||
| 2340 | // if(QWidget *tmp_w = qt_mac_find_window(wp)) | ||
| 2341 | // app->setActiveWindow(tmp_w); | ||
| 2342 | // } | ||
| 2343 | // QMenuBar::macUpdateMenuBar(); | ||
| 2344 | // } else if(ekind == kEventAppDeactivated) { | ||
| 2345 | // //qt_mac_no_click_through_mode = false; | ||
| 2346 | // while(app->d_func()->inPopupMode()) | ||
| 2347 | // app->activePopupWidget()->close(); | ||
| 2348 | // if(app) { | ||
| 2349 | // QEvent ev(QEvent::ApplicationDeactivate); | ||
| 2350 | // QApplication::sendSpontaneousEvent(app, &ev); | ||
| 2351 | // } | ||
| 2352 | // app->setActiveWindow(0); | ||
| 2353 | // } else if(ekind == kEventAppAvailableWindowBoundsChanged) { | ||
| 2354 | // QDesktopWidgetImplementation::instance()->onResize(); | ||
| 2355 | // } else { | ||
| 2356 | // handled_event = false; | ||
| 2357 | // } | ||
| 2358 | // break; | ||
| 2359 | // case kAppearanceEventClass: | ||
| 2360 | // if(ekind == kAEAppearanceChanged) { | ||
| 2361 | // if(QApplication::desktopSettingsAware()) | ||
| 2362 | // qt_mac_update_os_settings(); | ||
| 2363 | // if(QApplicationPrivate::app_style) { | ||
| 2364 | // QEvent ev(QEvent::Style); | ||
| 2365 | // QApplication::sendSpontaneousEvent(QApplicationPrivate::app_style, &ev); | ||
| 2366 | // } | ||
| 2367 | // } else { | ||
| 2368 | // handled_event = false; | ||
| 2369 | // } | ||
| 2370 | // break; | ||
| 2371 | // case kEventClassAppleEvent: | ||
| 2372 | // if(ekind == kEventAppleEvent) { | ||
| 2373 | // EventRecord erec; | ||
| 2374 | // if(!ConvertEventRefToEventRecord(event, &erec)) | ||
| 2375 | // qDebug("Qt: internal: WH0A, unexpected condition reached. %s:%d", __FILE__, __LINE__); | ||
| 2376 | // else if(AEProcessAppleEvent(&erec) != noErr) | ||
| 2377 | // handled_event = false; | ||
| 2378 | // } else { | ||
| 2379 | // handled_event = false; | ||
| 2380 | // } | ||
| 2381 | // break; | ||
| 2382 | // case kEventClassCommand: | ||
| 2383 | // if(ekind == kEventCommandProcess) { | ||
| 2384 | // HICommand cmd; | ||
| 2385 | // GetEventParameter(event, kEventParamDirectObject, typeHICommand, | ||
| 2386 | // 0, sizeof(cmd), 0, &cmd); | ||
| 2387 | // handled_event = false; | ||
| 2388 | // if(!cmd.menu.menuRef && GetApplicationDockTileMenu()) { | ||
| 2389 | // EventRef copy = CopyEvent(event); | ||
| 2390 | // HICommand copy_cmd; | ||
| 2391 | // GetEventParameter(event, kEventParamDirectObject, typeHICommand, | ||
| 2392 | // 0, sizeof(copy_cmd), 0, ©_cmd); | ||
| 2393 | // copy_cmd.menu.menuRef = GetApplicationDockTileMenu(); | ||
| 2394 | // SetEventParameter(copy, kEventParamDirectObject, typeHICommand, sizeof(copy_cmd), ©_cmd); | ||
| 2395 | // if(SendEventToMenu(copy, copy_cmd.menu.menuRef) == noErr) | ||
| 2396 | // handled_event = true; | ||
| 2397 | // } | ||
| 2398 | // if(!handled_event) { | ||
| 2399 | // if(cmd.commandID == kHICommandQuit) { | ||
| 2400 | // handled_event = true; | ||
| 2401 | // HiliteMenu(0); | ||
| 2402 | // bool handle_quit = true; | ||
| 2403 | // if(QApplicationPrivate::modalState()) { | ||
| 2404 | // int visible = 0; | ||
| 2405 | // const QWidgetList tlws = QApplication::topLevelWidgets(); | ||
| 2406 | // for(int i = 0; i < tlws.size(); ++i) { | ||
| 2407 | // if(tlws.at(i)->isVisible()) | ||
| 2408 | // ++visible; | ||
| 2409 | // } | ||
| 2410 | // handle_quit = (visible <= 1); | ||
| 2411 | // } | ||
| 2412 | // if(handle_quit) { | ||
| 2413 | // QCloseEvent ev; | ||
| 2414 | // QApplication::sendSpontaneousEvent(app, &ev); | ||
| 2415 | // if(ev.isAccepted()) | ||
| 2416 | // app->quit(); | ||
| 2417 | // } else { | ||
| 2418 | // QApplication::beep(); | ||
| 2419 | // } | ||
| 2420 | // } else if(cmd.commandID == kHICommandSelectWindow) { | ||
| 2421 | // if((GetCurrentKeyModifiers() & cmdKey)) | ||
| 2422 | // handled_event = true; | ||
| 2423 | // } else if(cmd.commandID == kHICommandAbout) { | ||
| 2424 | // QMessageBox::aboutQt(0); | ||
| 2425 | // HiliteMenu(0); | ||
| 2426 | // handled_event = true; | ||
| 2427 | // } | ||
| 2428 | // } | ||
| 2429 | // } | ||
| 2430 | // break; | ||
| 2431 | // } | ||
| 2432 | // | ||
| 2433 | //#ifdef DEBUG_EVENTS | ||
| 2434 | // qDebug("%shandled event %c%c%c%c %d", handled_event ? "(*) " : "", | ||
| 2435 | // char(eclass >> 24), char((eclass >> 16) & 255), char((eclass >> 8) & 255), | ||
| 2436 | // char(eclass & 255), (int)ekind); | ||
| 2437 | //#endif | ||
| 2438 | // if(!handled_event) //let the event go through | ||
| 2439 | // return eventNotHandledErr; | ||
| 2440 | // return noErr; //we eat the event | ||
| 2441 | //#else | ||
| 2442 | // Q_UNUSED(er); | ||
| 2443 | // Q_UNUSED(event); | ||
| 2444 | // Q_UNUSED(data); | ||
| 2445 | // return eventNotHandledErr; | ||
| 2446 | //#endif | ||
| 2447 | //} | ||
| 2448 | |||
| 2449 | // In Carbon this is your one stop for apple events. | ||
| 2450 | // In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists | ||
| 2451 | // for the time between instantiating the NSApplication, but before the | ||
| 2452 | // NSApplication has installed it's OWN Apple Event handler. When Cocoa has | ||
| 2453 | // that set up, we remove this. So, if you are debugging problems, you likely | ||
| 2454 | // want to check out QCocoaApplicationDelegate instead. | ||
| 2455 | //OSStatus QApplicationPrivate::globalAppleEventProcessor(const AppleEvent *ae, AppleEvent *, long handlerRefcon) | ||
| 2456 | //{ | ||
| 2457 | // QApplication *app = (QApplication *)handlerRefcon; | ||
| 2458 | // bool handled_event=false; | ||
| 2459 | // OSType aeID=typeWildCard, aeClass=typeWildCard; | ||
| 2460 | // AEGetAttributePtr(ae, keyEventClassAttr, typeType, 0, &aeClass, sizeof(aeClass), 0); | ||
| 2461 | // AEGetAttributePtr(ae, keyEventIDAttr, typeType, 0, &aeID, sizeof(aeID), 0); | ||
| 2462 | // if(aeClass == kCoreEventClass) { | ||
| 2463 | // switch(aeID) { | ||
| 2464 | // case kAEQuitApplication: { | ||
| 2465 | // extern bool qt_mac_quit_menu_item_enabled; // qmenu_mac.cpp | ||
| 2466 | // if (qt_mac_quit_menu_item_enabled) { | ||
| 2467 | // QCloseEvent ev; | ||
| 2468 | // QApplication::sendSpontaneousEvent(app, &ev); | ||
| 2469 | // if(ev.isAccepted()) { | ||
| 2470 | // handled_event = true; | ||
| 2471 | // app->quit(); | ||
| 2472 | // } | ||
| 2473 | // } else { | ||
| 2474 | // QApplication::beep(); // Sorry, you can't quit right now. | ||
| 2475 | // } | ||
| 2476 | // break; } | ||
| 2477 | // case kAEOpenDocuments: { | ||
| 2478 | // AEDescList docs; | ||
| 2479 | // if(AEGetParamDesc(ae, keyDirectObject, typeAEList, &docs) == noErr) { | ||
| 2480 | // long cnt = 0; | ||
| 2481 | // AECountItems(&docs, &cnt); | ||
| 2482 | // UInt8 *str_buffer = NULL; | ||
| 2483 | // for(int i = 0; i < cnt; i++) { | ||
| 2484 | // FSRef ref; | ||
| 2485 | // if(AEGetNthPtr(&docs, i+1, typeFSRef, 0, 0, &ref, sizeof(ref), 0) != noErr) | ||
| 2486 | // continue; | ||
| 2487 | // if(!str_buffer) | ||
| 2488 | // str_buffer = (UInt8 *)malloc(1024); | ||
| 2489 | // FSRefMakePath(&ref, str_buffer, 1024); | ||
| 2490 | // QFileOpenEvent ev(QString::fromUtf8((const char *)str_buffer)); | ||
| 2491 | // QApplication::sendSpontaneousEvent(app, &ev); | ||
| 2492 | // } | ||
| 2493 | // if(str_buffer) | ||
| 2494 | // free(str_buffer); | ||
| 2495 | // } | ||
| 2496 | // break; } | ||
| 2497 | // default: | ||
| 2498 | // break; | ||
| 2499 | // } | ||
| 2500 | // } else if (aeClass == kInternetEventClass) { | ||
| 2501 | // switch (aeID) { | ||
| 2502 | // case kAEGetURL: { | ||
| 2503 | // char urlData[1024]; | ||
| 2504 | // Size actualSize; | ||
| 2505 | // if (AEGetParamPtr(ae, keyDirectObject, typeChar, 0, urlData, | ||
| 2506 | // sizeof(urlData) - 1, &actualSize) == noErr) { | ||
| 2507 | // urlData[actualSize] = 0; | ||
| 2508 | // QFileOpenEvent ev(QUrl(QString::fromUtf8(urlData))); | ||
| 2509 | // QApplication::sendSpontaneousEvent(app, &ev); | ||
| 2510 | // } | ||
| 2511 | // break; | ||
| 2512 | // } | ||
| 2513 | // default: | ||
| 2514 | // break; | ||
| 2515 | // } | ||
| 2516 | // } | ||
| 2517 | //#ifdef DEBUG_EVENTS | ||
| 2518 | // qDebug("Qt: internal: %shandled Apple event! %c%c%c%c %c%c%c%c", handled_event ? "(*)" : "", | ||
| 2519 | // char(aeID >> 24), char((aeID >> 16) & 255), char((aeID >> 8) & 255),char(aeID & 255), | ||
| 2520 | // char(aeClass >> 24), char((aeClass >> 16) & 255), char((aeClass >> 8) & 255),char(aeClass & 255)); | ||
| 2521 | //#else | ||
| 2522 | // if(!handled_event) //let the event go through | ||
| 2523 | // return eventNotHandledErr; | ||
| 2524 | // return noErr; //we eat the event | ||
| 2525 | //#endif | ||
| 2526 | //} | ||
| 2527 | |||
| 2528 | /*! | ||
| 2529 | \fn bool QApplication::macEventFilter(EventHandlerCallRef caller, EventRef event) | ||
| 2530 | |||
| 2531 | \warning This virtual function is only implemented under Mac OS X when against Carbon. | ||
| 2532 | |||
| 2533 | If you create an application that inherits QApplication and reimplement | ||
| 2534 | this function, you get direct access to all Carbon Events that Qt registers | ||
| 2535 | for from Mac OS X with this function being called with the \a caller and | ||
| 2536 | the \a event. | ||
| 2537 | |||
| 2538 | Return true if you want to stop the event from being processed. | ||
| 2539 | Return false for normal event dispatching. The default | ||
| 2540 | implementation returns false. | ||
| 2541 | |||
| 2542 | Cocoa uses a different event system which means this function is NOT CALLED | ||
| 2543 | when building Qt against Cocoa. If you want similar functionality subclass | ||
| 2544 | NSApplication and reimplement the sendEvent: message to handle all the | ||
| 2545 | NSEvents. You also will need to to instantiate your custom NSApplication | ||
| 2546 | before creating a QApplication. See \l | ||
| 2547 | {http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html}{Apple's | ||
| 2548 | NSApplication Reference} for more information. | ||
| 2549 | |||
| 2550 | */ | ||
| 2551 | //bool QApplication::macEventFilter(EventHandlerCallRef, EventRef) | ||
| 2552 | //{ | ||
| 2553 | // return false; | ||
| 2554 | //} | ||
| 2555 | |||
| 2556 | /*! | ||
| 2557 | \internal | ||
| 2558 | */ | ||
| 2559 | void QApplicationPrivate::openPopup(QWidget *popup) | ||
| 2560 | { | ||
| 2561 | qDebug("QApplicationPrivate::openPopup(QWidget *popup)"); | ||
| 2562 | // if (!QApplicationPrivate::popupWidgets) // create list | ||
| 2563 | // QApplicationPrivate::popupWidgets = new QWidgetList; | ||
| 2564 | // QApplicationPrivate::popupWidgets->append(popup); // add to end of list | ||
| 2565 | // | ||
| 2566 | // // popups are not focus-handled by the window system (the first | ||
| 2567 | // // popup grabbed the keyboard), so we have to do that manually: A | ||
| 2568 | // // new popup gets the focus | ||
| 2569 | // if (popup->focusWidget()) { | ||
| 2570 | // popup->focusWidget()->setFocus(Qt::PopupFocusReason); | ||
| 2571 | // } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup | ||
| 2572 | // popup->setFocus(Qt::PopupFocusReason); | ||
| 2573 | // } | ||
| 2574 | } | ||
| 2575 | |||
| 2576 | /*! | ||
| 2577 | \internal | ||
| 2578 | */ | ||
| 2579 | void QApplicationPrivate::closePopup(QWidget *popup) | ||
| 2580 | { | ||
| 2581 | qDebug("QApplicationPrivate::closePopup(QWidget *popup)"); | ||
| 2582 | Q_Q(QApplication); | ||
| 2583 | // if (!QApplicationPrivate::popupWidgets) | ||
| 2584 | // return; | ||
| 2585 | // | ||
| 2586 | // QApplicationPrivate::popupWidgets->removeAll(popup); | ||
| 2587 | // if (popup == qt_button_down) | ||
| 2588 | // qt_button_down = 0; | ||
| 2589 | // if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup | ||
| 2590 | // delete QApplicationPrivate::popupWidgets; | ||
| 2591 | // QApplicationPrivate::popupWidgets = 0; | ||
| 2592 | // | ||
| 2593 | // // Special case for Tool windows: since they are activated and deactived together | ||
| 2594 | // // with a normal window they never become the QApplicationPrivate::active_window. | ||
| 2595 | // QWidget *appFocusWidget = QApplication::focusWidget(); | ||
| 2596 | // if (appFocusWidget && appFocusWidget->window()->windowType() == Qt::Tool) { | ||
| 2597 | // appFocusWidget->setFocus(Qt::PopupFocusReason); | ||
| 2598 | // } else if (QApplicationPrivate::active_window) { | ||
| 2599 | // if (QWidget *fw = QApplicationPrivate::active_window->focusWidget()) { | ||
| 2600 | // if (fw != QApplication::focusWidget()) { | ||
| 2601 | // fw->setFocus(Qt::PopupFocusReason); | ||
| 2602 | // } else { | ||
| 2603 | // QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason); | ||
| 2604 | // q->sendEvent(fw, &e); | ||
| 2605 | // } | ||
| 2606 | // } | ||
| 2607 | // } | ||
| 2608 | // } else { | ||
| 2609 | // // popups are not focus-handled by the window system (the | ||
| 2610 | // // first popup grabbed the keyboard), so we have to do that | ||
| 2611 | // // manually: A popup was closed, so the previous popup gets | ||
| 2612 | // // the focus. | ||
| 2613 | // QWidget* aw = QApplicationPrivate::popupWidgets->last(); | ||
| 2614 | // if (QWidget *fw = aw->focusWidget()) | ||
| 2615 | // fw->setFocus(Qt::PopupFocusReason); | ||
| 2616 | // } | ||
| 2617 | } | ||
| 2618 | |||
| 2619 | void QApplication::beep() | ||
| 2620 | { | ||
| 2621 | qDebug("QApplication::beep()"); | ||
| 2622 | // qt_mac_beep(); | ||
| 2623 | } | ||
| 2624 | |||
| 2625 | void QApplication::alert(QWidget *widget, int duration) | ||
| 2626 | { | ||
| 2627 | // A do nothing for iphone / embeded | ||
| 2628 | // qDebug("QApplication::alert(QWidget *widget, int duration)"); | ||
| 2629 | // if (!QApplicationPrivate::checkInstance("alert")) | ||
| 2630 | // return; | ||
| 2631 | // | ||
| 2632 | // QWidgetList windowsToMark; | ||
| 2633 | // if (!widget) | ||
| 2634 | // windowsToMark += topLevelWidgets(); | ||
| 2635 | // else | ||
| 2636 | // windowsToMark.append(widget->window()); | ||
| 2637 | // | ||
| 2638 | // bool needNotification = false; | ||
| 2639 | // for (int i = 0; i < windowsToMark.size(); ++i) { | ||
| 2640 | // QWidget *window = windowsToMark.at(i); | ||
| 2641 | // if (!window->isActiveWindow() && window->isVisible()) { | ||
| 2642 | // needNotification = true; // yeah, we may set it multiple times, but that's OK. | ||
| 2643 | // if (duration != 0) { | ||
| 2644 | // QTimer *timer = new QTimer(qApp); | ||
| 2645 | // timer->setSingleShot(true); | ||
| 2646 | // connect(timer, SIGNAL(timeout()), qApp, SLOT(_q_alertTimeOut())); | ||
| 2647 | // if (QTimer *oldTimer = qApp->d_func()->alertTimerHash.value(widget)) { | ||
| 2648 | // qApp->d_func()->alertTimerHash.remove(widget); | ||
| 2649 | // delete oldTimer; | ||
| 2650 | // } | ||
| 2651 | // qApp->d_func()->alertTimerHash.insert(widget, timer); | ||
| 2652 | // timer->start(duration); | ||
| 2653 | // } | ||
| 2654 | // } | ||
| 2655 | // } | ||
| 2656 | // if (needNotification) | ||
| 2657 | // qt_mac_send_notification(); | ||
| 2658 | } | ||
| 2659 | |||
| 2660 | //void QApplicationPrivate::_q_alertTimeOut() | ||
| 2661 | //{ | ||
| 2662 | // qDebug("QApplicationPrivate::_q_alertTimeOut()"); | ||
| 2663 | // if (QTimer *timer = qobject_cast<QTimer *>(q_func()->sender())) { | ||
| 2664 | // QHash<QWidget *, QTimer *>::iterator it = alertTimerHash.begin(); | ||
| 2665 | // while (it != alertTimerHash.end()) { | ||
| 2666 | // if (it.value() == timer) { | ||
| 2667 | // alertTimerHash.erase(it); | ||
| 2668 | // timer->deleteLater(); | ||
| 2669 | // break; | ||
| 2670 | // } | ||
| 2671 | // ++it; | ||
| 2672 | // } | ||
| 2673 | // if (alertTimerHash.isEmpty()) { | ||
| 2674 | // qt_mac_cancel_notification(); | ||
| 2675 | // } | ||
| 2676 | // } | ||
| 2677 | //} | ||
| 2678 | |||
| 2679 | void QApplication::setCursorFlashTime(int msecs) | ||
| 2680 | { | ||
| 2681 | QApplicationPrivate::cursor_flash_time = msecs; | ||
| 2682 | } | ||
| 2683 | |||
| 2684 | int QApplication::cursorFlashTime() | ||
| 2685 | { | ||
| 2686 | return QApplicationPrivate::cursor_flash_time; | ||
| 2687 | } | ||
| 2688 | |||
| 2689 | void QApplication::setDoubleClickInterval(int ms) | ||
| 2690 | { | ||
| 2691 | qDebug(" QApplication::setDoubleClickInterval(int ms)"); | ||
| 2692 | // iPhone dont use varable interval. | ||
| 2693 | // qt_mac_dblclick.use_qt_time_limit = true; | ||
| 2694 | QApplicationPrivate::mouse_double_click_time = ms; | ||
| 2695 | } | ||
| 2696 | |||
| 2697 | int QApplication::doubleClickInterval() | ||
| 2698 | { | ||
| 2699 | qDebug("QApplication::doubleClickInterval()"); | ||
| 2700 | // if (!qt_mac_dblclick.use_qt_time_limit) { //get it from the system | ||
| 2701 | // QSettings appleSettings(QLatin1String("apple.com")); | ||
| 2702 | // /* First worked as of 10.3.3 */ | ||
| 2703 | // double dci = appleSettings.value(QLatin1String("com/apple/mouse/doubleClickThreshold"), 0.5).toDouble(); | ||
| 2704 | // return int(dci * 1000); | ||
| 2705 | // } | ||
| 2706 | return QApplicationPrivate::mouse_double_click_time; | ||
| 2707 | } | ||
| 2708 | |||
| 2709 | void QApplication::setKeyboardInputInterval(int ms) | ||
| 2710 | { | ||
| 2711 | QApplicationPrivate::keyboard_input_time = ms; | ||
| 2712 | } | ||
| 2713 | |||
| 2714 | int QApplication::keyboardInputInterval() | ||
| 2715 | { | ||
| 2716 | // FIXME: get from the system | ||
| 2717 | return QApplicationPrivate::keyboard_input_time; | ||
| 2718 | return 0; | ||
| 2719 | } | ||
| 2720 | |||
| 2721 | void QApplication::setWheelScrollLines(int n) | ||
| 2722 | { | ||
| 2723 | QApplicationPrivate::wheel_scroll_lines = n; | ||
| 2724 | } | ||
| 2725 | |||
| 2726 | int QApplication::wheelScrollLines() | ||
| 2727 | { | ||
| 2728 | return QApplicationPrivate::wheel_scroll_lines; | ||
| 2729 | } | ||
| 2730 | |||
| 2731 | void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) | ||
| 2732 | { | ||
| 2733 | qDebug("QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)"); | ||
| 2734 | // switch (effect) { | ||
| 2735 | // case Qt::UI_FadeMenu: | ||
| 2736 | // QApplicationPrivate::fade_menu = enable; | ||
| 2737 | // break; | ||
| 2738 | // case Qt::UI_AnimateMenu: | ||
| 2739 | // QApplicationPrivate::animate_menu = enable; | ||
| 2740 | // break; | ||
| 2741 | // case Qt::UI_FadeTooltip: | ||
| 2742 | // QApplicationPrivate::fade_tooltip = enable; | ||
| 2743 | // break; | ||
| 2744 | // case Qt::UI_AnimateTooltip: | ||
| 2745 | // QApplicationPrivate::animate_tooltip = enable; | ||
| 2746 | // break; | ||
| 2747 | // case Qt::UI_AnimateCombo: | ||
| 2748 | // QApplicationPrivate::animate_combo = enable; | ||
| 2749 | // break; | ||
| 2750 | // case Qt::UI_AnimateToolBox: | ||
| 2751 | // QApplicationPrivate::animate_toolbox = enable; | ||
| 2752 | // break; | ||
| 2753 | // case Qt::UI_General: | ||
| 2754 | // QApplicationPrivate::fade_tooltip = true; | ||
| 2755 | // break; | ||
| 2756 | // default: | ||
| 2757 | // QApplicationPrivate::animate_ui = enable; | ||
| 2758 | // break; | ||
| 2759 | // } | ||
| 2760 | // | ||
| 2761 | // if (enable) | ||
| 2762 | // QApplicationPrivate::animate_ui = true; | ||
| 2763 | } | ||
| 2764 | |||
| 2765 | bool QApplication::isEffectEnabled(Qt::UIEffect effect) | ||
| 2766 | { | ||
| 2767 | qDebug("QApplication::isEffectEnabled(Qt::UIEffect effect)"); | ||
| 2768 | // if (QColormap::instance().depth() < 16 || !QApplicationPrivate::animate_ui) | ||
| 2769 | // return false; | ||
| 2770 | // | ||
| 2771 | // switch(effect) { | ||
| 2772 | // case Qt::UI_AnimateMenu: | ||
| 2773 | // return QApplicationPrivate::animate_menu; | ||
| 2774 | // case Qt::UI_FadeMenu: | ||
| 2775 | // return QApplicationPrivate::fade_menu; | ||
| 2776 | // case Qt::UI_AnimateCombo: | ||
| 2777 | // return QApplicationPrivate::animate_combo; | ||
| 2778 | // case Qt::UI_AnimateTooltip: | ||
| 2779 | // return QApplicationPrivate::animate_tooltip; | ||
| 2780 | // case Qt::UI_FadeTooltip: | ||
| 2781 | // return QApplicationPrivate::fade_tooltip; | ||
| 2782 | // case Qt::UI_AnimateToolBox: | ||
| 2783 | // return QApplicationPrivate::animate_toolbox; | ||
| 2784 | // default: | ||
| 2785 | // break; | ||
| 2786 | // } | ||
| 2787 | // return QApplicationPrivate::animate_ui; | ||
| 2788 | return false; | ||
| 2789 | } | ||
| 2790 | |||
| 2791 | /*! | ||
| 2792 | \internal | ||
| 2793 | */ | ||
| 2794 | //bool QApplicationPrivate::qt_mac_apply_settings() | ||
| 2795 | //{ | ||
| 2796 | // QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); | ||
| 2797 | // settings.beginGroup(QLatin1String("Qt")); | ||
| 2798 | // | ||
| 2799 | // /* | ||
| 2800 | // Qt settings. This is how they are written into the datastream. | ||
| 2801 | // Palette/ * - QPalette | ||
| 2802 | // font - QFont | ||
| 2803 | // libraryPath - QStringList | ||
| 2804 | // style - QString | ||
| 2805 | // doubleClickInterval - int | ||
| 2806 | // cursorFlashTime - int | ||
| 2807 | // wheelScrollLines - int | ||
| 2808 | // colorSpec - QString | ||
| 2809 | // defaultCodec - QString | ||
| 2810 | // globalStrut/width - int | ||
| 2811 | // globalStrut/height - int | ||
| 2812 | // GUIEffects - QStringList | ||
| 2813 | // Font Substitutions/ * - QStringList | ||
| 2814 | // Font Substitutions/... - QStringList | ||
| 2815 | // */ | ||
| 2816 | // | ||
| 2817 | // // read library (ie. plugin) path list | ||
| 2818 | // QString libpathkey = | ||
| 2819 | // QString::fromLatin1("%1.%2/libraryPath") | ||
| 2820 | // .arg(QT_VERSION >> 16) | ||
| 2821 | // .arg((QT_VERSION & 0xff00) >> 8); | ||
| 2822 | // QStringList pathlist = settings.value(libpathkey).toString().split(QLatin1Char(':')); | ||
| 2823 | // if (!pathlist.isEmpty()) { | ||
| 2824 | // QStringList::ConstIterator it = pathlist.begin(); | ||
| 2825 | // while(it != pathlist.end()) | ||
| 2826 | // QApplication::addLibraryPath(*it++); | ||
| 2827 | // } | ||
| 2828 | // | ||
| 2829 | // QString defaultcodec = settings.value(QLatin1String("defaultCodec"), QVariant(QLatin1String("none"))).toString(); | ||
| 2830 | // if (defaultcodec != QLatin1String("none")) { | ||
| 2831 | // QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1().constData()); | ||
| 2832 | // if (codec) | ||
| 2833 | // QTextCodec::setCodecForTr(codec); | ||
| 2834 | // } | ||
| 2835 | // | ||
| 2836 | // if (qt_is_gui_used) { | ||
| 2837 | // QString str; | ||
| 2838 | // QStringList strlist; | ||
| 2839 | // int num; | ||
| 2840 | // | ||
| 2841 | // // read new palette | ||
| 2842 | // int i; | ||
| 2843 | // QPalette pal(QApplication::palette()); | ||
| 2844 | // strlist = settings.value(QLatin1String("Palette/active")).toStringList(); | ||
| 2845 | // if (strlist.count() == QPalette::NColorRoles) { | ||
| 2846 | // for (i = 0; i < QPalette::NColorRoles; i++) | ||
| 2847 | // pal.setColor(QPalette::Active, (QPalette::ColorRole) i, | ||
| 2848 | // QColor(strlist[i])); | ||
| 2849 | // } | ||
| 2850 | // strlist = settings.value(QLatin1String("Palette/inactive")).toStringList(); | ||
| 2851 | // if (strlist.count() == QPalette::NColorRoles) { | ||
| 2852 | // for (i = 0; i < QPalette::NColorRoles; i++) | ||
| 2853 | // pal.setColor(QPalette::Inactive, (QPalette::ColorRole) i, | ||
| 2854 | // QColor(strlist[i])); | ||
| 2855 | // } | ||
| 2856 | // strlist = settings.value(QLatin1String("Palette/disabled")).toStringList(); | ||
| 2857 | // if (strlist.count() == QPalette::NColorRoles) { | ||
| 2858 | // for (i = 0; i < QPalette::NColorRoles; i++) | ||
| 2859 | // pal.setColor(QPalette::Disabled, (QPalette::ColorRole) i, | ||
| 2860 | // QColor(strlist[i])); | ||
| 2861 | // } | ||
| 2862 | // | ||
| 2863 | // if (pal != QApplication::palette()) | ||
| 2864 | // QApplication::setPalette(pal); | ||
| 2865 | // | ||
| 2866 | // // read new font | ||
| 2867 | // QFont font(QApplication::font()); | ||
| 2868 | // str = settings.value(QLatin1String("font")).toString(); | ||
| 2869 | // if (!str.isEmpty()) { | ||
| 2870 | // font.fromString(str); | ||
| 2871 | // if (font != QApplication::font()) | ||
| 2872 | // QApplication::setFont(font); | ||
| 2873 | // } | ||
| 2874 | // | ||
| 2875 | // // read new QStyle | ||
| 2876 | // QString stylename = settings.value(QLatin1String("style")).toString(); | ||
| 2877 | // if (! stylename.isNull() && ! stylename.isEmpty()) { | ||
| 2878 | // QStyle *style = QStyleFactory::create(stylename); | ||
| 2879 | // if (style) | ||
| 2880 | // QApplication::setStyle(style); | ||
| 2881 | // else | ||
| 2882 | // stylename = QLatin1String("default"); | ||
| 2883 | // } else { | ||
| 2884 | // stylename = QLatin1String("default"); | ||
| 2885 | // } | ||
| 2886 | // | ||
| 2887 | // num = settings.value(QLatin1String("doubleClickInterval"), | ||
| 2888 | // QApplication::doubleClickInterval()).toInt(); | ||
| 2889 | // QApplication::setDoubleClickInterval(num); | ||
| 2890 | // | ||
| 2891 | // num = settings.value(QLatin1String("cursorFlashTime"), | ||
| 2892 | // QApplication::cursorFlashTime()).toInt(); | ||
| 2893 | // QApplication::setCursorFlashTime(num); | ||
| 2894 | // | ||
| 2895 | // num = settings.value(QLatin1String("wheelScrollLines"), | ||
| 2896 | // QApplication::wheelScrollLines()).toInt(); | ||
| 2897 | // QApplication::setWheelScrollLines(num); | ||
| 2898 | // | ||
| 2899 | // QString colorspec = settings.value(QLatin1String("colorSpec"), | ||
| 2900 | // QVariant(QLatin1String("default"))).toString(); | ||
| 2901 | // if (colorspec == QLatin1String("normal")) | ||
| 2902 | // QApplication::setColorSpec(QApplication::NormalColor); | ||
| 2903 | // else if (colorspec == QLatin1String("custom")) | ||
| 2904 | // QApplication::setColorSpec(QApplication::CustomColor); | ||
| 2905 | // else if (colorspec == QLatin1String("many")) | ||
| 2906 | // QApplication::setColorSpec(QApplication::ManyColor); | ||
| 2907 | // else if (colorspec != QLatin1String("default")) | ||
| 2908 | // colorspec = QLatin1String("default"); | ||
| 2909 | // | ||
| 2910 | // int w = settings.value(QLatin1String("globalStrut/width")).toInt(); | ||
| 2911 | // int h = settings.value(QLatin1String("globalStrut/height")).toInt(); | ||
| 2912 | // QSize strut(w, h); | ||
| 2913 | // if (strut.isValid()) | ||
| 2914 | // QApplication::setGlobalStrut(strut); | ||
| 2915 | // | ||
| 2916 | // QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList(); | ||
| 2917 | // if (!effects.isEmpty()) { | ||
| 2918 | // if (effects.contains(QLatin1String("none"))) | ||
| 2919 | // QApplication::setEffectEnabled(Qt::UI_General, false); | ||
| 2920 | // if (effects.contains(QLatin1String("general"))) | ||
| 2921 | // QApplication::setEffectEnabled(Qt::UI_General, true); | ||
| 2922 | // if (effects.contains(QLatin1String("animatemenu"))) | ||
| 2923 | // QApplication::setEffectEnabled(Qt::UI_AnimateMenu, true); | ||
| 2924 | // if (effects.contains(QLatin1String("fademenu"))) | ||
| 2925 | // QApplication::setEffectEnabled(Qt::UI_FadeMenu, true); | ||
| 2926 | // if (effects.contains(QLatin1String("animatecombo"))) | ||
| 2927 | // QApplication::setEffectEnabled(Qt::UI_AnimateCombo, true); | ||
| 2928 | // if (effects.contains(QLatin1String("animatetooltip"))) | ||
| 2929 | // QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, true); | ||
| 2930 | // if (effects.contains(QLatin1String("fadetooltip"))) | ||
| 2931 | // QApplication::setEffectEnabled(Qt::UI_FadeTooltip, true); | ||
| 2932 | // if (effects.contains(QLatin1String("animatetoolbox"))) | ||
| 2933 | // QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, true); | ||
| 2934 | // } else { | ||
| 2935 | // QApplication::setEffectEnabled(Qt::UI_General, true); | ||
| 2936 | // } | ||
| 2937 | // | ||
| 2938 | // settings.beginGroup(QLatin1String("Font Substitutions")); | ||
| 2939 | // QStringList fontsubs = settings.childKeys(); | ||
| 2940 | // if (!fontsubs.isEmpty()) { | ||
| 2941 | // QStringList::Iterator it = fontsubs.begin(); | ||
| 2942 | // for (; it != fontsubs.end(); ++it) { | ||
| 2943 | // QString fam = QString::fromLatin1((*it).toLatin1().constData()); | ||
| 2944 | // QStringList subs = settings.value(fam).toStringList(); | ||
| 2945 | // QFont::insertSubstitutions(fam, subs); | ||
| 2946 | // } | ||
| 2947 | // } | ||
| 2948 | // settings.endGroup(); | ||
| 2949 | // } | ||
| 2950 | // | ||
| 2951 | // settings.endGroup(); | ||
| 2952 | // return true; | ||
| 2953 | //} | ||
| 2954 | |||
| 2955 | // DRSWAT | ||
| 2956 | |||
| 2957 | //bool QApplicationPrivate::canQuit() | ||
| 2958 | //{ | ||
| 2959 | //#ifndef QT_MAC_USE_COCOA | ||
| 2960 | // return true; | ||
| 2961 | //#else | ||
| 2962 | // Q_Q(QApplication); | ||
| 2963 | //#ifdef QT_MAC_USE_COCOA | ||
| 2964 | // [[NSApp mainMenu] cancelTracking]; | ||
| 2965 | //#else | ||
| 2966 | // HiliteMenu(0); | ||
| 2967 | //#endif | ||
| 2968 | // | ||
| 2969 | // bool handle_quit = true; | ||
| 2970 | // if (QApplicationPrivate::modalState() && [[[[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] | ||
| 2971 | // menuLoader] quitMenuItem] isEnabled]) { | ||
| 2972 | // int visible = 0; | ||
| 2973 | // const QWidgetList tlws = QApplication::topLevelWidgets(); | ||
| 2974 | // for(int i = 0; i < tlws.size(); ++i) { | ||
| 2975 | // if (tlws.at(i)->isVisible()) | ||
| 2976 | // ++visible; | ||
| 2977 | // } | ||
| 2978 | // handle_quit = (visible <= 1); | ||
| 2979 | // } | ||
| 2980 | // if (handle_quit) { | ||
| 2981 | // QCloseEvent ev; | ||
| 2982 | // QApplication::sendSpontaneousEvent(q, &ev); | ||
| 2983 | // if (ev.isAccepted()) { | ||
| 2984 | // return true; | ||
| 2985 | // } | ||
| 2986 | // } | ||
| 2987 | // return false; | ||
| 2988 | //#endif | ||
| 2989 | //} | ||
| 2990 | |||
| 2991 | //void onApplicationWindowChangedActivation(QWidget *widget, bool activated) | ||
| 2992 | //{ | ||
| 2993 | //#if QT_MAC_USE_COCOA | ||
| 2994 | // if (!widget) | ||
| 2995 | // return; | ||
| 2996 | // | ||
| 2997 | // if (activated) { | ||
| 2998 | // if (QApplicationPrivate::app_style) { | ||
| 2999 | // QEvent ev(QEvent::Style); | ||
| 3000 | // qt_sendSpontaneousEvent(QApplicationPrivate::app_style, &ev); | ||
| 3001 | // } | ||
| 3002 | // qApp->setActiveWindow(widget); | ||
| 3003 | // } else { // deactivated | ||
| 3004 | // if (QApplicationPrivate::active_window == widget) | ||
| 3005 | // qApp->setActiveWindow(0); | ||
| 3006 | // } | ||
| 3007 | // | ||
| 3008 | // QMenuBar::macUpdateMenuBar(); | ||
| 3009 | // | ||
| 3010 | //#else | ||
| 3011 | // Q_UNUSED(widget); | ||
| 3012 | // Q_UNUSED(activated); | ||
| 3013 | //#endif | ||
| 3014 | //} | ||
| 3015 | |||
| 3016 | |||
| 3017 | //void onApplicationChangedActivation( bool activated ) | ||
| 3018 | //{ | ||
| 3019 | //#if QT_MAC_USE_COCOA | ||
| 3020 | // QApplication *app = qApp; | ||
| 3021 | // | ||
| 3022 | ////NSLog(@"App Changed Activation\n"); | ||
| 3023 | // | ||
| 3024 | // if ( activated ) { | ||
| 3025 | // if (QApplication::desktopSettingsAware()) | ||
| 3026 | // qt_mac_update_os_settings(); | ||
| 3027 | // | ||
| 3028 | // if (qt_clipboard) { //manufacture an event so the clipboard can see if it has changed | ||
| 3029 | // QEvent ev(QEvent::Clipboard); | ||
| 3030 | // qt_sendSpontaneousEvent(qt_clipboard, &ev); | ||
| 3031 | // } | ||
| 3032 | // | ||
| 3033 | // if (app) { | ||
| 3034 | // QEvent ev(QEvent::ApplicationActivate); | ||
| 3035 | // qt_sendSpontaneousEvent(app, &ev); | ||
| 3036 | // } | ||
| 3037 | // | ||
| 3038 | // if (!app->activeWindow()) { | ||
| 3039 | //#if QT_MAC_USE_COCOA | ||
| 3040 | // OSWindowRef wp = [NSApp keyWindow]; | ||
| 3041 | //#else | ||
| 3042 | // OSWindowRef wp = ActiveNonFloatingWindow(); | ||
| 3043 | //#endif | ||
| 3044 | // if (QWidget *tmp_w = qt_mac_find_window(wp)) | ||
| 3045 | // app->setActiveWindow(tmp_w); | ||
| 3046 | // } | ||
| 3047 | // QMenuBar::macUpdateMenuBar(); | ||
| 3048 | // } else { // de-activated | ||
| 3049 | // QApplicationPrivate *priv = [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] qAppPrivate]; | ||
| 3050 | // while (priv->inPopupMode()) | ||
| 3051 | // app->activePopupWidget()->close(); | ||
| 3052 | // if (app) { | ||
| 3053 | // QEvent ev(QEvent::ApplicationDeactivate); | ||
| 3054 | // qt_sendSpontaneousEvent(app, &ev); | ||
| 3055 | // } | ||
| 3056 | // app->setActiveWindow(0); | ||
| 3057 | // } | ||
| 3058 | //#else | ||
| 3059 | // Q_UNUSED(activated); | ||
| 3060 | //#endif | ||
| 3061 | //} | ||
| 3062 | |||
| 3063 | void QApplicationPrivate::initializeMultitouch_sys() | ||
| 3064 | { | ||
| 3065 | } | ||
| 3066 | |||
| 3067 | void QApplicationPrivate::cleanupMultitouch_sys() | ||
| 3068 | { | ||
| 3069 | } | ||
| 3070 | |||
| 3071 | int QiPhoneInit(int argc, char **argv) | ||
| 3072 | { | ||
| 3073 | // This should only be ran once | ||
| 3074 | if (qt_argc == 0) { | ||
| 3075 | qt_argc = argc; | ||
| 3076 | qt_argv = argv; | ||
| 3077 | |||
| 3078 | // UIApplication never actually retruns from this. | ||
| 3079 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | ||
| 3080 | QCocoaApplicationDelegate* temp = [[QCocoaApplicationDelegate alloc] init]; | ||
| 3081 | int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"QCocoaApplicationDelegate"); | ||
| 3082 | [pool release]; | ||
| 3083 | return retVal; | ||
| 3084 | } | ||
| 3085 | return 0; | ||
| 3086 | } | ||
| 3087 | |||
| 3088 | QT_END_NAMESPACE |
|   | |||
| 481 | 481 | static Qt::NavigationMode navigationMode; | |
| 482 | 482 | #endif | |
| 483 | 483 | ||
| 484 | #if defined(Q_WS_MAC) || defined(Q_WS_IPHONE) || defined(Q_WS_X11) | ||
| 484 | #if defined(Q_WS_MAC) || defined(Q_WS_X11) | ||
| 485 | 485 | void _q_alertTimeOut(); | |
| 486 | 486 | QHash<QWidget *, QTimer *> alertTimerHash; | |
| 487 | 487 | #endif |
src/gui/kernel/qclipboard_iphone.mm
(625 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qclipboard.h" | ||
| 43 | #include "qapplication.h" | ||
| 44 | #include "qbitmap.h" | ||
| 45 | #include "qdatetime.h" | ||
| 46 | #include "qdebug.h" | ||
| 47 | #include "qapplication_p.h" | ||
| 48 | #include <private/qt_iphone_p.h> | ||
| 49 | #include "qevent.h" | ||
| 50 | #include "qurl.h" | ||
| 51 | #include <stdlib.h> | ||
| 52 | #include <string.h> | ||
| 53 | #include "qt_cocoa_helpers_iphone_p.h" | ||
| 54 | |||
| 55 | QT_BEGIN_NAMESPACE | ||
| 56 | |||
| 57 | QT_USE_NAMESPACE | ||
| 58 | |||
| 59 | /***************************************************************************** | ||
| 60 | QClipboard debug facilities | ||
| 61 | *****************************************************************************/ | ||
| 62 | //#define DEBUG_PASTEBOARD | ||
| 63 | |||
| 64 | #ifndef QT_NO_CLIPBOARD | ||
| 65 | |||
| 66 | /***************************************************************************** | ||
| 67 | QClipboard member functions for mac. | ||
| 68 | *****************************************************************************/ | ||
| 69 | |||
| 70 | //static QIPhonePasteboard *qt_mac_pasteboards[2] = {0, 0}; | ||
| 71 | |||
| 72 | //static inline QMacPasteboard *qt_mac_pasteboard(QClipboard::Mode mode) | ||
| 73 | //{ | ||
| 74 | // Q_ASSERT(mode == QClipboard::Clipboard || mode == QClipboard::FindBuffer); | ||
| 75 | // if (mode == QClipboard::Clipboard) | ||
| 76 | // return qt_mac_pasteboards[0]; | ||
| 77 | // else | ||
| 78 | // return qt_mac_pasteboards[1]; | ||
| 79 | //} | ||
| 80 | // | ||
| 81 | //static void qt_mac_cleanupPasteboard() { | ||
| 82 | // delete qt_mac_pasteboards[0]; | ||
| 83 | // delete qt_mac_pasteboards[1]; | ||
| 84 | // qt_mac_pasteboards[0] = 0; | ||
| 85 | // qt_mac_pasteboards[1] = 0; | ||
| 86 | //} | ||
| 87 | // | ||
| 88 | //static bool qt_mac_updateScrap(QClipboard::Mode mode) | ||
| 89 | //{ | ||
| 90 | //// if(!qt_mac_pasteboards[0]) { | ||
| 91 | //// qt_mac_pasteboards[0] = new QMacPasteboard(kPasteboardClipboard, QMacPasteboardMime::MIME_CLIP); | ||
| 92 | //// qt_mac_pasteboards[1] = new QMacPasteboard(kPasteboardFind, QMacPasteboardMime::MIME_CLIP); | ||
| 93 | //// qAddPostRoutine(qt_mac_cleanupPasteboard); | ||
| 94 | //// return true; | ||
| 95 | //// } | ||
| 96 | // return qt_mac_pasteboard(mode)->sync(); | ||
| 97 | //} | ||
| 98 | |||
| 99 | void QClipboard::clear(Mode mode) | ||
| 100 | { | ||
| 101 | // if (!supportsMode(mode)) | ||
| 102 | // return; | ||
| 103 | // qt_mac_updateScrap(mode); | ||
| 104 | // qt_mac_pasteboard(mode)->clear(); | ||
| 105 | // setMimeData(0, mode); | ||
| 106 | } | ||
| 107 | |||
| 108 | void QClipboard::ownerDestroyed() | ||
| 109 | { | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | void QClipboard::connectNotify(const char *signal) | ||
| 114 | { | ||
| 115 | Q_UNUSED(signal); | ||
| 116 | } | ||
| 117 | |||
| 118 | bool QClipboard::event(QEvent *e) | ||
| 119 | { | ||
| 120 | // if(e->type() != QEvent::Clipboard) | ||
| 121 | // return QObject::event(e); | ||
| 122 | // | ||
| 123 | // if (qt_mac_updateScrap(QClipboard::Clipboard)) { | ||
| 124 | // emitChanged(QClipboard::Clipboard); | ||
| 125 | // } | ||
| 126 | // | ||
| 127 | // if (qt_mac_updateScrap(QClipboard::FindBuffer)) { | ||
| 128 | // emitChanged(QClipboard::FindBuffer); | ||
| 129 | // } | ||
| 130 | // | ||
| 131 | // return QObject::event(e); | ||
| 132 | } | ||
| 133 | |||
| 134 | const QMimeData *QClipboard::mimeData(Mode mode) const | ||
| 135 | { | ||
| 136 | // if (!supportsMode(mode)) | ||
| 137 | return 0; | ||
| 138 | // qt_mac_updateScrap(mode); | ||
| 139 | // return qt_mac_pasteboard(mode)->mimeData(); | ||
| 140 | } | ||
| 141 | |||
| 142 | void QClipboard::setMimeData(QMimeData *src, Mode mode) | ||
| 143 | { | ||
| 144 | // if (!supportsMode(mode)) | ||
| 145 | // return; | ||
| 146 | // qt_mac_updateScrap(mode); | ||
| 147 | // qt_mac_pasteboard(mode)->setMimeData(src); | ||
| 148 | // emitChanged(mode); | ||
| 149 | } | ||
| 150 | |||
| 151 | bool QClipboard::supportsMode(Mode mode) const | ||
| 152 | { | ||
| 153 | #warning supportsMode() | ||
| 154 | // return (mode == Clipboard || mode == FindBuffer); | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | bool QClipboard::ownsMode(Mode mode) const | ||
| 159 | { | ||
| 160 | Q_UNUSED(mode); | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | |||
| 164 | #endif // QT_NO_CLIPBOARD | ||
| 165 | |||
| 166 | ///***************************************************************************** | ||
| 167 | // QMacPasteboard code | ||
| 168 | //*****************************************************************************/ | ||
| 169 | // | ||
| 170 | //QMacPasteboard::QMacPasteboard(PasteboardRef p, uchar mt) | ||
| 171 | //{ | ||
| 172 | //// mac_mime_source = false; | ||
| 173 | //// mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL); | ||
| 174 | //// paste = p; | ||
| 175 | //// CFRetain(paste); | ||
| 176 | //} | ||
| 177 | // | ||
| 178 | //QMacPasteboard::QMacPasteboard(uchar mt) | ||
| 179 | //{ | ||
| 180 | //// mac_mime_source = false; | ||
| 181 | //// mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL); | ||
| 182 | //// paste = 0; | ||
| 183 | //// OSStatus err = PasteboardCreate(0, &paste); | ||
| 184 | //// if(err == noErr) { | ||
| 185 | //// PasteboardSetPromiseKeeper(paste, promiseKeeper, this); | ||
| 186 | //// } else { | ||
| 187 | //// qDebug("PasteBoard: Error creating pasteboard: [%d]", (int)err); | ||
| 188 | //// } | ||
| 189 | //} | ||
| 190 | // | ||
| 191 | //QMacPasteboard::QMacPasteboard(CFStringRef name, uchar mt) | ||
| 192 | //{ | ||
| 193 | //// mac_mime_source = false; | ||
| 194 | //// mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL); | ||
| 195 | //// paste = 0; | ||
| 196 | //// OSStatus err = PasteboardCreate(name, &paste); | ||
| 197 | //// if(err == noErr) { | ||
| 198 | //// PasteboardSetPromiseKeeper(paste, promiseKeeper, this); | ||
| 199 | //// } else { | ||
| 200 | //// qDebug("PasteBoard: Error creating pasteboard: %s [%d]", QCFString::toQString(name).toLatin1().constData(), (int)err); | ||
| 201 | //// } | ||
| 202 | //} | ||
| 203 | // | ||
| 204 | //QMacPasteboard::~QMacPasteboard() | ||
| 205 | //{ | ||
| 206 | //// // commit all promises for paste after exit close | ||
| 207 | //// for (int i = 0; i < promises.count(); ++i) { | ||
| 208 | //// const Promise &promise = promises.at(i); | ||
| 209 | //// QCFString flavor = QCFString(promise.convertor->flavorFor(promise.mime)); | ||
| 210 | //// promiseKeeper(paste, (PasteboardItemID)promise.itemId, flavor, this); | ||
| 211 | //// } | ||
| 212 | //// | ||
| 213 | //// if(paste) | ||
| 214 | //// CFRelease(paste); | ||
| 215 | //} | ||
| 216 | // | ||
| 217 | //PasteboardRef | ||
| 218 | //QMacPasteboard::pasteBoard() const | ||
| 219 | //{ | ||
| 220 | // return paste; | ||
| 221 | //} | ||
| 222 | // | ||
| 223 | //OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, CFStringRef flavor, void *_qpaste) | ||
| 224 | //{ | ||
| 225 | // QMacPasteboard *qpaste = (QMacPasteboard*)_qpaste; | ||
| 226 | // const long promise_id = (long)id; | ||
| 227 | // | ||
| 228 | // // Find the kept promise | ||
| 229 | // const QString flavorAsQString = QCFString::toQString(flavor); | ||
| 230 | // QMacPasteboard::Promise promise; | ||
| 231 | // for (int i = 0; i < qpaste->promises.size(); i++){ | ||
| 232 | // QMacPasteboard::Promise tmp = qpaste->promises[i]; | ||
| 233 | // if (tmp.itemId == promise_id && tmp.convertor->canConvert(tmp.mime, flavorAsQString)){ | ||
| 234 | // promise = tmp; | ||
| 235 | // break; | ||
| 236 | // } | ||
| 237 | // } | ||
| 238 | // | ||
| 239 | // if (!promise.itemId && flavorAsQString == QLatin1String("com.trolltech.qt.MimeTypeName")) { | ||
| 240 | // // we have promised this data, but wont be able to convert, so return null data. | ||
| 241 | // // This helps in making the application/x-qt-mime-type-name hidden from normal use. | ||
| 242 | // QByteArray ba; | ||
| 243 | // QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size()); | ||
| 244 | // PasteboardPutItemFlavor(paste, id, flavor, data, kPasteboardFlavorNoFlags); | ||
| 245 | // return noErr; | ||
| 246 | // } | ||
| 247 | // | ||
| 248 | // if (!promise.itemId) { | ||
| 249 | // // There was no promise that could deliver data for the | ||
| 250 | // // given id and flavor. This should not happend. | ||
| 251 | // qDebug("Pasteboard: %d: Request for %ld, %s, but no promise found!", __LINE__, promise_id, qPrintable(flavorAsQString)); | ||
| 252 | // return cantGetFlavorErr; | ||
| 253 | // } | ||
| 254 | // | ||
| 255 | //#ifdef DEBUG_PASTEBOARD | ||
| 256 | // qDebug("PasteBoard: Calling in promise for %s[%ld] [%s] (%s) [%d]", qPrintable(promise.mime), promise_id, | ||
| 257 | // qPrintable(flavorAsQString), qPrintable(promise.convertor->convertorName()), promise.offset); | ||
| 258 | //#endif | ||
| 259 | // | ||
| 260 | // QList<QByteArray> md = promise.convertor->convertFromMime(promise.mime, promise.data, flavorAsQString); | ||
| 261 | // if (md.size() <= promise.offset) | ||
| 262 | // return cantGetFlavorErr; | ||
| 263 | // const QByteArray &ba = md[promise.offset]; | ||
| 264 | // QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size()); | ||
| 265 | // PasteboardPutItemFlavor(paste, id, flavor, data, kPasteboardFlavorNoFlags); | ||
| 266 | // return noErr; | ||
| 267 | //} | ||
| 268 | // | ||
| 269 | //bool | ||
| 270 | //QMacPasteboard::hasOSType(int c_flavor) const | ||
| 271 | //{ | ||
| 272 | //// if (!paste) | ||
| 273 | //// return false; | ||
| 274 | //// | ||
| 275 | //// sync(); | ||
| 276 | //// | ||
| 277 | //// ItemCount cnt = 0; | ||
| 278 | //// if(PasteboardGetItemCount(paste, &cnt) || !cnt) | ||
| 279 | //// return false; | ||
| 280 | //// | ||
| 281 | ////#ifdef DEBUG_PASTEBOARD | ||
| 282 | //// qDebug("PasteBoard: hasOSType [%c%c%c%c]", (c_flavor>>24)&0xFF, (c_flavor>>16)&0xFF, | ||
| 283 | //// (c_flavor>>8)&0xFF, (c_flavor>>0)&0xFF); | ||
| 284 | ////#endif | ||
| 285 | //// for(uint index = 1; index <= cnt; ++index) { | ||
| 286 | //// | ||
| 287 | //// PasteboardItemID id; | ||
| 288 | //// if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) | ||
| 289 | //// return false; | ||
| 290 | //// | ||
| 291 | //// QCFType<CFArrayRef> types; | ||
| 292 | //// if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr) | ||
| 293 | //// return false; | ||
| 294 | //// | ||
| 295 | //// const int type_count = CFArrayGetCount(types); | ||
| 296 | //// for(int i = 0; i < type_count; ++i) { | ||
| 297 | //// CFStringRef flavor = (CFStringRef)CFArrayGetValueAtIndex(types, i); | ||
| 298 | //// const int os_flavor = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(flavor, kUTTagClassOSType)); | ||
| 299 | //// if(os_flavor == c_flavor) { | ||
| 300 | ////#ifdef DEBUG_PASTEBOARD | ||
| 301 | //// qDebug(" - Found!"); | ||
| 302 | ////#endif | ||
| 303 | //// return true; | ||
| 304 | //// } | ||
| 305 | //// } | ||
| 306 | //// } | ||
| 307 | ////#ifdef DEBUG_PASTEBOARD | ||
| 308 | //// qDebug(" - NotFound!"); | ||
| 309 | ////#endif | ||
| 310 | // return false; | ||
| 311 | //} | ||
| 312 | // | ||
| 313 | //bool | ||
| 314 | //QMacPasteboard::hasFlavor(QString c_flavor) const | ||
| 315 | //{ | ||
| 316 | //// if (!paste) | ||
| 317 | //// return false; | ||
| 318 | //// | ||
| 319 | //// sync(); | ||
| 320 | //// | ||
| 321 | //// ItemCount cnt = 0; | ||
| 322 | //// if(PasteboardGetItemCount(paste, &cnt) || !cnt) | ||
| 323 | //// return false; | ||
| 324 | //// | ||
| 325 | ////#ifdef DEBUG_PASTEBOARD | ||
| 326 | //// qDebug("PasteBoard: hasFlavor [%s]", qPrintable(c_flavor)); | ||
| 327 | ////#endif | ||
| 328 | //// for(uint index = 1; index <= cnt; ++index) { | ||
| 329 | //// | ||
| 330 | //// PasteboardItemID id; | ||
| 331 | //// if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) | ||
| 332 | //// return false; | ||
| 333 | //// | ||
| 334 | //// PasteboardFlavorFlags flags; | ||
| 335 | //// if(PasteboardGetItemFlavorFlags(paste, id, QCFString(c_flavor), &flags) == noErr) { | ||
| 336 | ////#ifdef DEBUG_PASTEBOARD | ||
| 337 | //// qDebug(" - Found!"); | ||
| 338 | ////#endif | ||
| 339 | //// return true; | ||
| 340 | //// } | ||
| 341 | //// } | ||
| 342 | ////#ifdef DEBUG_PASTEBOARD | ||
| 343 | //// qDebug(" - NotFound!"); | ||
| 344 | ////#endif | ||
| 345 | // return false; | ||
| 346 | //} | ||
| 347 | // | ||
| 348 | //class QMacPasteboardMimeSource : public QMimeData { | ||
| 349 | //// const QMacPasteboard *paste; | ||
| 350 | ////public: | ||
| 351 | //// QMacPasteboardMimeSource(const QMacPasteboard *p) : QMimeData(), paste(p) { } | ||
| 352 | //// ~QMacPasteboardMimeSource() { } | ||
| 353 | //// virtual QStringList formats() const { return paste->formats(); } | ||
| 354 | //// virtual QVariant retrieveData(const QString &format, QVariant::Type type) const { return paste->retrieveData(format, type); } | ||
| 355 | //}; | ||
| 356 | // | ||
| 357 | //QMimeData | ||
| 358 | //*QMacPasteboard::mimeData() const | ||
| 359 | //{ | ||
| 360 | //// if(!mime) { | ||
| 361 | //// mac_mime_source = true; | ||
| 362 | //// mime = new QMacPasteboardMimeSource(this); | ||
| 363 | //// | ||
| 364 | //// } | ||
| 365 | // return mime; | ||
| 366 | //} | ||
| 367 | // | ||
| 368 | //class QMacMimeData : public QMimeData | ||
| 369 | //{ | ||
| 370 | //public: | ||
| 371 | // QVariant variantData(const QString &mime) { return retrieveData(mime, QVariant::Invalid); } | ||
| 372 | //private: | ||
| 373 | // QMacMimeData(); | ||
| 374 | //}; | ||
| 375 | // | ||
| 376 | //void | ||
| 377 | //QMacPasteboard::setMimeData(QMimeData *mime_src) | ||
| 378 | //{ | ||
| 379 | //// if (!paste) | ||
| 380 | //// return; | ||
| 381 | //// | ||
| 382 | //// if (mime == mime_src || (!mime_src && mime && mac_mime_source)) | ||
| 383 | //// return; | ||
| 384 | //// mac_mime_source = false; | ||
| 385 | //// delete mime; | ||
| 386 | //// mime = mime_src; | ||
| 387 | //// | ||
| 388 | //// QList<QMacPasteboardMime*> availableConverters = QMacPasteboardMime::all(mime_type); | ||
| 389 | //// if (mime != 0) { | ||
| 390 | //// clear_helper(); | ||
| 391 | //// QStringList formats = mime_src->formats(); | ||
| 392 | //// | ||
| 393 | //// for(int f = 0; f < formats.size(); ++f) { | ||
| 394 | //// QString mimeType = formats.at(f); | ||
| 395 | //// for (QList<QMacPasteboardMime *>::Iterator it = availableConverters.begin(); it != availableConverters.end(); ++it) { | ||
| 396 | //// QMacPasteboardMime *c = (*it); | ||
| 397 | //// QString flavor(c->flavorFor(mimeType)); | ||
| 398 | //// if(!flavor.isEmpty()) { | ||
| 399 | //// QVariant mimeData = static_cast<QMacMimeData*>(mime_src)->variantData(mimeType); | ||
| 400 | ////#if 0 | ||
| 401 | //// //### Grrr, why didn't I put in a virtual int QMacPasteboardMime::count()? --Sam | ||
| 402 | //// const int numItems = c->convertFromMime(mimeType, mimeData, flavor).size(); | ||
| 403 | ////#else | ||
| 404 | //// int numItems = 1; //this is a hack but it is much faster than allowing conversion above | ||
| 405 | //// if(c->convertorName() == QLatin1String("FileURL")) | ||
| 406 | //// numItems = mime_src->urls().count(); | ||
| 407 | ////#endif | ||
| 408 | //// for(int item = 0; item < numItems; ++item) { | ||
| 409 | //// const int itemID = item+1; //id starts at 1 | ||
| 410 | //// promises.append(QMacPasteboard::Promise(itemID, c, mimeType, mimeData, item)); | ||
| 411 | //// PasteboardPutItemFlavor(paste, (PasteboardItemID)itemID, QCFString(flavor), 0, kPasteboardFlavorNoFlags); | ||
| 412 | ////#ifdef DEBUG_PASTEBOARD | ||
| 413 | //// qDebug(" - adding %d %s [%s] <%s> [%d]", | ||
| 414 | //// itemID, qPrintable(mimeType), qPrintable(flavor), qPrintable(c->convertorName()), item); | ||
| 415 | ////#endif | ||
| 416 | //// } | ||
| 417 | //// } | ||
| 418 | //// } | ||
| 419 | //// } | ||
| 420 | //// } | ||
| 421 | //} | ||
| 422 | // | ||
| 423 | //QStringList | ||
| 424 | //QMacPasteboard::formats() const | ||
| 425 | //{ | ||
| 426 | //// if (!paste) | ||
| 427 | //// return QStringList(); | ||
| 428 | //// | ||
| 429 | //// sync(); | ||
| 430 | //// | ||
| 431 | //// QStringList ret; | ||
| 432 | //// ItemCount cnt = 0; | ||
| 433 | //// if(PasteboardGetItemCount(paste, &cnt) || !cnt) | ||
| 434 | //// return ret; | ||
| 435 | //// | ||
| 436 | ////#ifdef DEBUG_PASTEBOARD | ||
| 437 | //// qDebug("PasteBoard: Formats [%d]", (int)cnt); | ||
| 438 | ////#endif | ||
| 439 | //// for(uint index = 1; index <= cnt; ++index) { | ||
| 440 | //// | ||
| 441 | //// PasteboardItemID id; | ||
| 442 | //// if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) | ||
| 443 | //// continue; | ||
| 444 | //// | ||
| 445 | //// QCFType<CFArrayRef> types; | ||
| 446 | //// if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr) | ||
| 447 | //// continue; | ||
| 448 | //// | ||
| 449 | //// const int type_count = CFArrayGetCount(types); | ||
| 450 | //// for(int i = 0; i < type_count; ++i) { | ||
| 451 | //// const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i)); | ||
| 452 | ////#ifdef DEBUG_PASTEBOARD | ||
| 453 | //// qDebug(" -%s", qPrintable(QString(flavor))); | ||
| 454 | ////#endif | ||
| 455 | //// QString mimeType = QMacPasteboardMime::flavorToMime(mime_type, flavor); | ||
| 456 | //// if(!mimeType.isEmpty() && !ret.contains(mimeType)) { | ||
| 457 | ////#ifdef DEBUG_PASTEBOARD | ||
| 458 | //// qDebug(" -<%d> %s [%s]", ret.size(), qPrintable(mimeType), qPrintable(QString(flavor))); | ||
| 459 | ////#endif | ||
| 460 | //// ret << mimeType; | ||
| 461 | //// } | ||
| 462 | //// } | ||
| 463 | //// } | ||
| 464 | //// return ret; | ||
| 465 | // return QStringList(); | ||
| 466 | //} | ||
| 467 | // | ||
| 468 | //bool | ||
| 469 | //QMacPasteboard::hasFormat(const QString &format) const | ||
| 470 | //{ | ||
| 471 | //// if (!paste) | ||
| 472 | //// return false; | ||
| 473 | //// | ||
| 474 | //// sync(); | ||
| 475 | //// | ||
| 476 | //// ItemCount cnt = 0; | ||
| 477 | //// if(PasteboardGetItemCount(paste, &cnt) || !cnt) | ||
| 478 | //// return false; | ||
| 479 | //// | ||
| 480 | ////#ifdef DEBUG_PASTEBOARD | ||
| 481 | //// qDebug("PasteBoard: hasFormat [%s]", qPrintable(format)); | ||
| 482 | ////#endif | ||
| 483 | //// for(uint index = 1; index <= cnt; ++index) { | ||
| 484 | //// | ||
| 485 | //// PasteboardItemID id; | ||
| 486 | //// if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) | ||
| 487 | //// continue; | ||
| 488 | //// | ||
| 489 | //// QCFType<CFArrayRef> types; | ||
| 490 | //// if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr) | ||
| 491 | //// continue; | ||
| 492 | //// | ||
| 493 | //// const int type_count = CFArrayGetCount(types); | ||
| 494 | //// for(int i = 0; i < type_count; ++i) { | ||
| 495 | //// const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i)); | ||
| 496 | ////#ifdef DEBUG_PASTEBOARD | ||
| 497 | //// qDebug(" -%s [0x%x]", qPrintable(QString(flavor)), mime_type); | ||
| 498 | ////#endif | ||
| 499 | //// QString mimeType = QMacPasteboardMime::flavorToMime(mime_type, flavor); | ||
| 500 | ////#ifdef DEBUG_PASTEBOARD | ||
| 501 | //// if(!mimeType.isEmpty()) | ||
| 502 | //// qDebug(" - %s", qPrintable(mimeType)); | ||
| 503 | ////#endif | ||
| 504 | //// if(mimeType == format) | ||
| 505 | //// return true; | ||
| 506 | //// } | ||
| 507 | //// } | ||
| 508 | // return false; | ||
| 509 | //} | ||
| 510 | // | ||
| 511 | //QVariant | ||
| 512 | //QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const | ||
| 513 | //{ | ||
| 514 | //// if (!paste) | ||
| 515 | //// return QVariant(); | ||
| 516 | //// | ||
| 517 | //// sync(); | ||
| 518 | //// | ||
| 519 | //// ItemCount cnt = 0; | ||
| 520 | //// if(PasteboardGetItemCount(paste, &cnt) || !cnt) | ||
| 521 | //// return QByteArray(); | ||
| 522 | //// | ||
| 523 | ////#ifdef DEBUG_PASTEBOARD | ||
| 524 | //// qDebug("Pasteboard: retrieveData [%s]", qPrintable(format)); | ||
| 525 | ////#endif | ||
| 526 | //// const QList<QMacPasteboardMime *> mimes = QMacPasteboardMime::all(mime_type); | ||
| 527 | //// for(int mime = 0; mime < mimes.size(); ++mime) { | ||
| 528 | //// QMacPasteboardMime *c = mimes.at(mime); | ||
| 529 | //// QString c_flavor = c->flavorFor(format); | ||
| 530 | //// if(!c_flavor.isEmpty()) { | ||
| 531 | //// // Handle text/plain a little differently. Try handling Unicode first. | ||
| 532 | //// bool checkForUtf16 = (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text") | ||
| 533 | //// || c_flavor == QLatin1String("public.utf8-plain-text")); | ||
| 534 | //// if (checkForUtf16 || c_flavor == QLatin1String("public.utf16-plain-text")) { | ||
| 535 | //// // Try to get the NSStringPboardType from NSPasteboard, newlines are mapped | ||
| 536 | //// // correctly (as '\n') in this data. The 'public.utf16-plain-text' type | ||
| 537 | //// // usually maps newlines to '\r' instead. | ||
| 538 | //// QString str = qt_mac_get_pasteboardString(paste); | ||
| 539 | //// if (!str.isEmpty()) | ||
| 540 | //// return str; | ||
| 541 | //// } | ||
| 542 | //// if (checkForUtf16 && hasFlavor(QLatin1String("public.utf16-plain-text"))) | ||
| 543 | //// c_flavor = QLatin1String("public.utf16-plain-text"); | ||
| 544 | //// | ||
| 545 | //// QVariant ret; | ||
| 546 | //// QList<QByteArray> retList; | ||
| 547 | //// for(uint index = 1; index <= cnt; ++index) { | ||
| 548 | //// PasteboardItemID id; | ||
| 549 | //// if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) | ||
| 550 | //// continue; | ||
| 551 | //// | ||
| 552 | //// QCFType<CFArrayRef> types; | ||
| 553 | //// if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr) | ||
| 554 | //// continue; | ||
| 555 | //// | ||
| 556 | //// const int type_count = CFArrayGetCount(types); | ||
| 557 | //// for(int i = 0; i < type_count; ++i) { | ||
| 558 | //// CFStringRef flavor = static_cast<CFStringRef>(CFArrayGetValueAtIndex(types, i)); | ||
| 559 | //// if(c_flavor == QCFString::toQString(flavor)) { | ||
| 560 | //// QCFType<CFDataRef> macBuffer; | ||
| 561 | //// if(PasteboardCopyItemFlavorData(paste, id, flavor, &macBuffer) == noErr) { | ||
| 562 | //// QByteArray buffer((const char *)CFDataGetBytePtr(macBuffer), CFDataGetLength(macBuffer)); | ||
| 563 | //// if(!buffer.isEmpty()) { | ||
| 564 | ////#ifdef DEBUG_PASTEBOARD | ||
| 565 | //// qDebug(" - %s [%s] (%s)", qPrintable(format), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName())); | ||
| 566 | ////#endif | ||
| 567 | //// buffer.detach(); //detach since we release the macBuffer | ||
| 568 | //// retList.append(buffer); | ||
| 569 | //// break; //skip to next element | ||
| 570 | //// } | ||
| 571 | //// } | ||
| 572 | //// } else { | ||
| 573 | ////#ifdef DEBUG_PASTEBOARD | ||
| 574 | //// qDebug(" - NoMatch %s [%s] (%s)", qPrintable(c_flavor), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName())); | ||
| 575 | ////#endif | ||
| 576 | //// } | ||
| 577 | //// } | ||
| 578 | //// } | ||
| 579 | //// | ||
| 580 | //// if (!retList.isEmpty()) { | ||
| 581 | //// ret = c->convertToMime(format, retList, c_flavor); | ||
| 582 | //// return ret; | ||
| 583 | //// } | ||
| 584 | //// } | ||
| 585 | //// } | ||
| 586 | // return QVariant(); | ||
| 587 | //} | ||
| 588 | // | ||
| 589 | //void QMacPasteboard::clear_helper() | ||
| 590 | //{ | ||
| 591 | //// if (paste) | ||
| 592 | //// PasteboardClear(paste); | ||
| 593 | //// promises.clear(); | ||
| 594 | //} | ||
| 595 | // | ||
| 596 | //void | ||
| 597 | //QMacPasteboard::clear() | ||
| 598 | //{ | ||
| 599 | //#ifdef DEBUG_PASTEBOARD | ||
| 600 | // qDebug("PasteBoard: clear!"); | ||
| 601 | //#endif | ||
| 602 | // clear_helper(); | ||
| 603 | //} | ||
| 604 | // | ||
| 605 | //bool | ||
| 606 | //QMacPasteboard::sync() const | ||
| 607 | //{ | ||
| 608 | //// if (!paste) | ||
| 609 | //// return false; | ||
| 610 | //// const bool fromGlobal = PasteboardSynchronize(paste) & kPasteboardModified; | ||
| 611 | //// | ||
| 612 | //// if (fromGlobal) | ||
| 613 | //// const_cast<QMacPasteboard *>(this)->setMimeData(0); | ||
| 614 | //// | ||
| 615 | ////#ifdef DEBUG_PASTEBOARD | ||
| 616 | //// if(fromGlobal) | ||
| 617 | //// qDebug("Pasteboard: Syncronize!"); | ||
| 618 | ////#endif | ||
| 619 | //// return fromGlobal; | ||
| 620 | //} | ||
| 621 | // | ||
| 622 | // | ||
| 623 | |||
| 624 | |||
| 625 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #include <qglobal.h> | ||
| 77 | #include <private/qcocoaapplication_iphone_p.h> | ||
| 78 | #include <private/qcocoaapplicationdelegate_iphone_p.h> | ||
| 79 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 80 | |||
| 81 | //@implementation UIApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration)) | ||
| 82 | |||
| 83 | //+ (void) load | ||
| 84 | //{ | ||
| 85 | // NSLog(@"UIApplication is loaded"); | ||
| 86 | //} | ||
| 87 | |||
| 88 | //- (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu | ||
| 89 | //{ | ||
| 90 | // [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] setDockMenu:newMenu]; | ||
| 91 | //} | ||
| 92 | // | ||
| 93 | //- (QApplicationPrivate *)QT_MANGLE_NAMESPACE(qt_qappPrivate) | ||
| 94 | //{ | ||
| 95 | // return [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] qAppPrivate]; | ||
| 96 | //} | ||
| 97 | // | ||
| 98 | //- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader) | ||
| 99 | //{ | ||
| 100 | // return [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] menuLoader]; | ||
| 101 | //} | ||
| 102 | // | ||
| 103 | //- (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel | ||
| 104 | //{ | ||
| 105 | // Q_UNUSED(fontPanel); | ||
| 106 | // // only display those things that QFont can handle | ||
| 107 | // return NSFontPanelFaceModeMask | ||
| 108 | // | NSFontPanelSizeModeMask | ||
| 109 | // | NSFontPanelCollectionModeMask | ||
| 110 | // | NSFontPanelUnderlineEffectModeMask | ||
| 111 | // | NSFontPanelStrikethroughEffectModeMask; | ||
| 112 | //} | ||
| 113 | |||
| 114 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | // | ||
| 77 | // W A R N I N G | ||
| 78 | // ------------- | ||
| 79 | // | ||
| 80 | // This file is not part of the Qt API. It exists for the convenience | ||
| 81 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 82 | // and many other. This header file may change from version to version | ||
| 83 | // without notice, or even be removed. | ||
| 84 | // | ||
| 85 | // We mean it. | ||
| 86 | // | ||
| 87 | |||
| 88 | /* | ||
| 89 | Cocoa Application Categories | ||
| 90 | */ | ||
| 91 | #include "qmacdefines_iphone.h" | ||
| 92 | #import <UIKit/UIKit.h> | ||
| 93 | |||
| 94 | //QT_FORWARD_DECLARE_CLASS(QApplicationPrivate) | ||
| 95 | //@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader); | ||
| 96 | |||
| 97 | //@interface UIApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration)) | ||
| 98 | //+ (void) load; | ||
| 99 | //- (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu; | ||
| 100 | //- (QApplicationPrivate *)QT_MANGLE_NAMESPACE(qt_qappPrivate); | ||
| 101 | //- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader); | ||
| 102 | //- (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel; | ||
| 103 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #include "qmacdefines_iphone.h" | ||
| 77 | |||
| 78 | #import <private/qcocoaapplicationdelegate_iphone_p.h> | ||
| 79 | #import <private/qcocoamenuloader_iphone_p.h> | ||
| 80 | #include <private/qapplication_p.h> | ||
| 81 | #include <private/qt_iphone_p.h> | ||
| 82 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 83 | #include <private/qdesktopwidget_iphone_p.h> | ||
| 84 | #include <qevent.h> | ||
| 85 | #include <qurl.h> | ||
| 86 | #include <qapplication.h> | ||
| 87 | #include <qdebug.h> | ||
| 88 | |||
| 89 | extern int qt_argc; | ||
| 90 | extern char** qt_argv; | ||
| 91 | int main(int argc, char** argv); | ||
| 92 | |||
| 93 | QT_BEGIN_NAMESPACE | ||
| 94 | //extern void onApplicationChangedActivation(bool); // qapplication_mac.mm | ||
| 95 | //extern void qt_release_apple_event_handler(); //qapplication_mac.mm | ||
| 96 | QT_END_NAMESPACE | ||
| 97 | // | ||
| 98 | //QT_FORWARD_DECLARE_CLASS(QDesktopWidgetImplementation) | ||
| 99 | QT_USE_NAMESPACE | ||
| 100 | // | ||
| 101 | //static QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *sharedCocoaApplicationDelegate = nil; | ||
| 102 | // | ||
| 103 | //static void cleanupCocoaApplicationDelegate() | ||
| 104 | //{ | ||
| 105 | // [sharedCocoaApplicationDelegate release]; | ||
| 106 | //} | ||
| 107 | // | ||
| 108 | @implementation QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) | ||
| 109 | |||
| 110 | //- (id)init | ||
| 111 | //{ | ||
| 112 | // self = [super init]; | ||
| 113 | // if (self) | ||
| 114 | // inLaunch = true; | ||
| 115 | // return self; | ||
| 116 | //} | ||
| 117 | // | ||
| 118 | //- (void)dealloc | ||
| 119 | //{ | ||
| 120 | // sharedCocoaApplicationDelegate = nil; | ||
| 121 | // [dockMenu release]; | ||
| 122 | // [qtMenuLoader release]; | ||
| 123 | // if (reflectionDelegate) { | ||
| 124 | // [NSApp setDelegate:reflectionDelegate]; | ||
| 125 | // [reflectionDelegate release]; | ||
| 126 | // } | ||
| 127 | // [super dealloc]; | ||
| 128 | //} | ||
| 129 | // | ||
| 130 | //+ (id)allocWithZone:(NSZone *)zone | ||
| 131 | //{ | ||
| 132 | // @synchronized(self) { | ||
| 133 | // if (sharedCocoaApplicationDelegate == nil) { | ||
| 134 | // sharedCocoaApplicationDelegate = [super allocWithZone:zone]; | ||
| 135 | // return sharedCocoaApplicationDelegate; | ||
| 136 | // qAddPostRoutine(cleanupCocoaApplicationDelegate); | ||
| 137 | // } | ||
| 138 | // } | ||
| 139 | // return nil; | ||
| 140 | //} | ||
| 141 | |||
| 142 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
| 143 | { | ||
| 144 | main(qt_argc, qt_argv); | ||
| 145 | return true; | ||
| 146 | } | ||
| 147 | |||
| 148 | // | ||
| 149 | //+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate | ||
| 150 | //{ | ||
| 151 | // @synchronized(self) { | ||
| 152 | // if (sharedCocoaApplicationDelegate == nil) | ||
| 153 | // [[self alloc] init]; | ||
| 154 | // } | ||
| 155 | // return [[sharedCocoaApplicationDelegate retain] autorelease]; | ||
| 156 | //} | ||
| 157 | // | ||
| 158 | //- (void)setDockMenu:(NSMenu*)newMenu | ||
| 159 | //{ | ||
| 160 | // [newMenu retain]; | ||
| 161 | // [dockMenu release]; | ||
| 162 | // dockMenu = newMenu; | ||
| 163 | //} | ||
| 164 | // | ||
| 165 | //- (NSMenu *)applicationDockMenu | ||
| 166 | //{ | ||
| 167 | // return [[dockMenu retain] autorelease]; | ||
| 168 | //} | ||
| 169 | // | ||
| 170 | //- (QApplicationPrivate *)qAppPrivate | ||
| 171 | //{ | ||
| 172 | // return qtPrivate; | ||
| 173 | //} | ||
| 174 | // | ||
| 175 | //- (void)setQtPrivate:(QApplicationPrivate *)value | ||
| 176 | //{ | ||
| 177 | // qtPrivate = value; | ||
| 178 | //} | ||
| 179 | // | ||
| 180 | //- (void)setMenuLoader:(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader | ||
| 181 | //{ | ||
| 182 | // [menuLoader retain]; | ||
| 183 | // [qtMenuLoader release]; | ||
| 184 | // qtMenuLoader = menuLoader; | ||
| 185 | //} | ||
| 186 | // | ||
| 187 | //- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader; | ||
| 188 | //{ | ||
| 189 | // return [[qtMenuLoader retain] autorelease]; | ||
| 190 | //} | ||
| 191 | // | ||
| 192 | //// This function will only be called when NSApp is actually running. Before | ||
| 193 | //// that, the kAEQuitApplication apple event will be sendt to | ||
| 194 | //// QApplicationPrivate::globalAppleEventProcessor in qapplication_mac.mm | ||
| 195 | //- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender | ||
| 196 | //{ | ||
| 197 | // Q_UNUSED(sender); | ||
| 198 | // // The reflection delegate gets precedence | ||
| 199 | // if (reflectionDelegate | ||
| 200 | // && [reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) { | ||
| 201 | // return [reflectionDelegate applicationShouldTerminate:sender]; | ||
| 202 | // } | ||
| 203 | // | ||
| 204 | // if (qtPrivate->canQuit()) { | ||
| 205 | // if (!startedQuit) { | ||
| 206 | // startedQuit = true; | ||
| 207 | // qAppInstance()->quit(); | ||
| 208 | // startedQuit = false; | ||
| 209 | // } | ||
| 210 | // } | ||
| 211 | // | ||
| 212 | // if (qtPrivate->threadData->eventLoops.size() == 0) { | ||
| 213 | // // INVARIANT: No event loop is executing. This probably | ||
| 214 | // // means that Qt is used as a plugin, or as a part of a native | ||
| 215 | // // Cocoa application. In any case it should be fine to | ||
| 216 | // // terminate now: | ||
| 217 | // return NSTerminateNow; | ||
| 218 | // } else { | ||
| 219 | // // Prevent Cocoa from terminating the application, since this simply | ||
| 220 | // // exits the program whithout allowing QApplication::exec() to return. | ||
| 221 | // // The call to QApplication::quit() above will instead quit the | ||
| 222 | // // application from the Qt side. | ||
| 223 | // return NSTerminateCancel; | ||
| 224 | // } | ||
| 225 | //} | ||
| 226 | // | ||
| 227 | //- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | ||
| 228 | //{ | ||
| 229 | // Q_UNUSED(aNotification); | ||
| 230 | // inLaunch = false; | ||
| 231 | // qt_release_apple_event_handler(); | ||
| 232 | //} | ||
| 233 | // | ||
| 234 | //- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames | ||
| 235 | //{ | ||
| 236 | // for (NSString *fileName in filenames) { | ||
| 237 | // QString qtFileName = qt_mac_NSStringToQString(fileName); | ||
| 238 | // if (inLaunch) { | ||
| 239 | // // We need to be careful because Cocoa will be nice enough to take | ||
| 240 | // // command line arguments and send them to us as events. Given the history | ||
| 241 | // // of Qt Applications, this will result in behavior people don't want, as | ||
| 242 | // // they might be doing the opening themselves with the command line parsing. | ||
| 243 | // if (qApp->arguments().contains(qtFileName)) | ||
| 244 | // continue; | ||
| 245 | // } | ||
| 246 | // QFileOpenEvent foe(qtFileName); | ||
| 247 | // qt_sendSpontaneousEvent(qAppInstance(), &foe); | ||
| 248 | // } | ||
| 249 | // | ||
| 250 | // if (reflectionDelegate && | ||
| 251 | // [reflectionDelegate respondsToSelector:@selector(application:openFiles:)]) | ||
| 252 | // [reflectionDelegate application:sender openFiles:filenames]; | ||
| 253 | //} | ||
| 254 | // | ||
| 255 | //- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender | ||
| 256 | //{ | ||
| 257 | // // If we have a reflection delegate, that will get to call the shots. | ||
| 258 | // if (reflectionDelegate | ||
| 259 | // && [reflectionDelegate respondsToSelector: | ||
| 260 | // @selector(applicationShouldTerminateAfterLastWindowClosed:)]) | ||
| 261 | // return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender]; | ||
| 262 | // return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together. | ||
| 263 | //} | ||
| 264 | // | ||
| 265 | // | ||
| 266 | //- (void)applicationDidBecomeActive:(NSNotification *)notification | ||
| 267 | //{ | ||
| 268 | // if (reflectionDelegate | ||
| 269 | // && [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)]) | ||
| 270 | // [reflectionDelegate applicationDidBecomeActive:notification]; | ||
| 271 | // onApplicationChangedActivation(true); | ||
| 272 | //} | ||
| 273 | // | ||
| 274 | //- (void)applicationDidResignActive:(NSNotification *)notification; | ||
| 275 | //{ | ||
| 276 | // if (reflectionDelegate | ||
| 277 | // && [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)]) | ||
| 278 | // [reflectionDelegate applicationDidResignActive:notification]; | ||
| 279 | // onApplicationChangedActivation(false); | ||
| 280 | //} | ||
| 281 | // | ||
| 282 | //- (void)applicationDidChangeScreenParameters:(NSNotification *)notification | ||
| 283 | //{ | ||
| 284 | // Q_UNUSED(notification); | ||
| 285 | // QDesktopWidgetImplementation::instance()->onResize(); | ||
| 286 | //} | ||
| 287 | // | ||
| 288 | //- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate | ||
| 289 | //{ | ||
| 290 | // [oldDelegate retain]; | ||
| 291 | // [reflectionDelegate release]; | ||
| 292 | // reflectionDelegate = oldDelegate; | ||
| 293 | //} | ||
| 294 | // | ||
| 295 | //- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector | ||
| 296 | //{ | ||
| 297 | // NSMethodSignature *result = [super methodSignatureForSelector:aSelector]; | ||
| 298 | // if (!result && reflectionDelegate) { | ||
| 299 | // result = [reflectionDelegate methodSignatureForSelector:aSelector]; | ||
| 300 | // } | ||
| 301 | // return result; | ||
| 302 | //} | ||
| 303 | // | ||
| 304 | //- (BOOL)respondsToSelector:(SEL)aSelector | ||
| 305 | //{ | ||
| 306 | // BOOL result = [super respondsToSelector:aSelector]; | ||
| 307 | // if (!result && reflectionDelegate) | ||
| 308 | // result = [reflectionDelegate respondsToSelector:aSelector]; | ||
| 309 | // return result; | ||
| 310 | //} | ||
| 311 | // | ||
| 312 | //- (void)forwardInvocation:(NSInvocation *)invocation | ||
| 313 | //{ | ||
| 314 | // SEL invocationSelector = [invocation selector]; | ||
| 315 | // if (reflectionDelegate && [reflectionDelegate respondsToSelector:invocationSelector]) | ||
| 316 | // [invocation invokeWithTarget:reflectionDelegate]; | ||
| 317 | // else | ||
| 318 | // [self doesNotRecognizeSelector:invocationSelector]; | ||
| 319 | //} | ||
| 320 | // | ||
| 321 | //- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent | ||
| 322 | //{ | ||
| 323 | // Q_UNUSED(replyEvent); | ||
| 324 | // | ||
| 325 | // NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; | ||
| 326 | // QUrl url(qt_mac_NSStringToQString(urlString)); | ||
| 327 | // QFileOpenEvent qtEvent(url); | ||
| 328 | // qt_sendSpontaneousEvent(qAppInstance(), &qtEvent); | ||
| 329 | //} | ||
| 330 | |||
| 331 | @end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | |||
| 43 | /**************************************************************************** | ||
| 44 | ** | ||
| 45 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 46 | ** | ||
| 47 | ** All rights reserved. | ||
| 48 | ** | ||
| 49 | ** Redistribution and use in source and binary forms, with or without | ||
| 50 | ** modification, are permitted provided that the following conditions are met: | ||
| 51 | ** | ||
| 52 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 53 | ** this list of conditions and the following disclaimer. | ||
| 54 | ** | ||
| 55 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 56 | ** this list of conditions and the following disclaimer in the documentation | ||
| 57 | ** and/or other materials provided with the distribution. | ||
| 58 | ** | ||
| 59 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 60 | ** may be used to endorse or promote products derived from this software | ||
| 61 | ** without specific prior written permission. | ||
| 62 | ** | ||
| 63 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 64 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 65 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 66 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 67 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 68 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 69 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 70 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 71 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 72 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 73 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 74 | ** | ||
| 75 | ****************************************************************************/ | ||
| 76 | |||
| 77 | // | ||
| 78 | // W A R N I N G | ||
| 79 | // ------------- | ||
| 80 | // | ||
| 81 | // This file is not part of the Qt API. It exists for the convenience | ||
| 82 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 83 | // and many other. This header file may change from version to version | ||
| 84 | // without notice, or even be removed. | ||
| 85 | // | ||
| 86 | // We mean it. | ||
| 87 | // | ||
| 88 | |||
| 89 | #import <UIKit/UIKit.h> | ||
| 90 | |||
| 91 | QT_FORWARD_DECLARE_CLASS(QApplicationPrivate); | ||
| 92 | |||
| 93 | //@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader); | ||
| 94 | // | ||
| 95 | //#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | ||
| 96 | // | ||
| 97 | //@protocol NSApplicationDelegate <NSObject> | ||
| 98 | //- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; | ||
| 99 | //- (void)applicationDidFinishLaunching:(NSNotification *)aNotification; | ||
| 100 | //- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames; | ||
| 101 | //- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender; | ||
| 102 | //- (void)applicationDidBecomeActive:(NSNotification *)notification; | ||
| 103 | //- (void)applicationDidResignActive:(NSNotification *)notification; | ||
| 104 | //@end | ||
| 105 | // | ||
| 106 | //#endif | ||
| 107 | |||
| 108 | @interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject <UIApplicationDelegate> { | ||
| 109 | // bool startedQuit; | ||
| 110 | // QApplicationPrivate *qtPrivate; | ||
| 111 | // NSMenu *dockMenu; | ||
| 112 | // QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader; | ||
| 113 | // NSObject <NSApplicationDelegate> *reflectionDelegate; | ||
| 114 | // bool inLaunch; | ||
| 115 | } | ||
| 116 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; | ||
| 117 | //+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate; | ||
| 118 | //- (void)setDockMenu:(NSMenu *)newMenu; | ||
| 119 | //- (void)setQtPrivate:(QApplicationPrivate *)value; | ||
| 120 | //- (QApplicationPrivate *)qAppPrivate; | ||
| 121 | //- (void)setMenuLoader:(QT_MANGLE_NAMESPACE(QCocoaMenuLoader)*)menuLoader; | ||
| 122 | //- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader; | ||
| 123 | //- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate; | ||
| 124 | //- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; | ||
| 125 | @end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qmacdefines_iphone.h" | ||
| 43 | #warning qcocoamenuloader_iphone not finished. | ||
| 44 | //#ifdef QT_MAC_USE_COCOA | ||
| 45 | //#include <qaction.h> | ||
| 46 | //#include <qcoreapplication.h> | ||
| 47 | //#include <private/qcocoamenuloader_mac_p.h> | ||
| 48 | //#include <private/qapplication_p.h> | ||
| 49 | //#include <private/qt_mac_p.h> | ||
| 50 | //#include <qmenubar.h> | ||
| 51 | // | ||
| 52 | //QT_FORWARD_DECLARE_CLASS(QCFString) | ||
| 53 | //QT_FORWARD_DECLARE_CLASS(QString) | ||
| 54 | // | ||
| 55 | //QT_USE_NAMESPACE | ||
| 56 | // | ||
| 57 | //@implementation QT_MANGLE_NAMESPACE(QCocoaMenuLoader) | ||
| 58 | // | ||
| 59 | //- (void)awakeFromNib | ||
| 60 | //{ | ||
| 61 | // // Get the names in the nib to match the app name set by Qt. | ||
| 62 | // NSString *appName = reinterpret_cast<const NSString*>(QCFString::toCFStringRef(qAppName())); | ||
| 63 | // [quitItem setTitle:[[quitItem title] stringByReplacingOccurrencesOfString:@"NewApplication" | ||
| 64 | // withString:appName]]; | ||
| 65 | // [hideItem setTitle:[[hideItem title] stringByReplacingOccurrencesOfString:@"NewApplication" | ||
| 66 | // withString:appName]]; | ||
| 67 | // [aboutItem setTitle:[[aboutItem title] stringByReplacingOccurrencesOfString:@"NewApplication" | ||
| 68 | // withString:appName]]; | ||
| 69 | // [appName release]; | ||
| 70 | // // Disable the items that don't do anything. If someone associates a QAction with them | ||
| 71 | // // They should get synced back in. | ||
| 72 | // [preferencesItem setEnabled:NO]; | ||
| 73 | // [preferencesItem setHidden:YES]; | ||
| 74 | // [aboutItem setEnabled:NO]; | ||
| 75 | // [aboutItem setHidden:YES]; | ||
| 76 | //} | ||
| 77 | // | ||
| 78 | //- (void)ensureAppMenuInMenu:(NSMenu *)menu | ||
| 79 | //{ | ||
| 80 | // // The application menu is the menu in the menu bar that contains the | ||
| 81 | // // 'Quit' item. When changing menu bar (e.g when swithing between | ||
| 82 | // // windows with different menu bars), we never recreate this menu, but | ||
| 83 | // // instead pull it out the current menu bar and place into the new one: | ||
| 84 | // NSMenu *mainMenu = [NSApp mainMenu]; | ||
| 85 | // if ([NSApp mainMenu] == menu) | ||
| 86 | // return; // nothing to do (menu is the current menu bar)! | ||
| 87 | // | ||
| 88 | //#ifndef QT_NAMESPACE | ||
| 89 | // Q_ASSERT(mainMenu); | ||
| 90 | //#endif | ||
| 91 | // // Grab the app menu out of the current menu. | ||
| 92 | // int numItems = [mainMenu numberOfItems]; | ||
| 93 | // NSMenuItem *oldAppMenuItem = 0; | ||
| 94 | // for (int i = 0; i < numItems; ++i) { | ||
| 95 | // NSMenuItem *item = [mainMenu itemAtIndex:i]; | ||
| 96 | // if ([item submenu] == appMenu) { | ||
| 97 | // oldAppMenuItem = item; | ||
| 98 | // [oldAppMenuItem retain]; | ||
| 99 | // [mainMenu removeItemAtIndex:i]; | ||
| 100 | // break; | ||
| 101 | // } | ||
| 102 | // } | ||
| 103 | // | ||
| 104 | // if (oldAppMenuItem) { | ||
| 105 | // [oldAppMenuItem setSubmenu:nil]; | ||
| 106 | // [oldAppMenuItem release]; | ||
| 107 | // NSMenuItem *appMenuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" | ||
| 108 | // action:nil keyEquivalent:@""]; | ||
| 109 | // [appMenuItem setSubmenu:appMenu]; | ||
| 110 | // [menu insertItem:appMenuItem atIndex:0]; | ||
| 111 | // } | ||
| 112 | //} | ||
| 113 | // | ||
| 114 | //- (void)dealloc | ||
| 115 | //{ | ||
| 116 | // [lastAppSpecificItem release]; | ||
| 117 | // [theMenu release]; | ||
| 118 | // [appMenu release]; | ||
| 119 | // [super dealloc]; | ||
| 120 | //} | ||
| 121 | // | ||
| 122 | //- (NSMenu *)menu | ||
| 123 | //{ | ||
| 124 | // return [[theMenu retain] autorelease]; | ||
| 125 | //} | ||
| 126 | // | ||
| 127 | //- (NSMenu *)applicationMenu | ||
| 128 | //{ | ||
| 129 | // return [[appMenu retain] autorelease]; | ||
| 130 | //} | ||
| 131 | // | ||
| 132 | //- (NSMenuItem *)quitMenuItem | ||
| 133 | //{ | ||
| 134 | // return [[quitItem retain] autorelease]; | ||
| 135 | //} | ||
| 136 | // | ||
| 137 | //- (NSMenuItem *)preferencesMenuItem | ||
| 138 | //{ | ||
| 139 | // return [[preferencesItem retain] autorelease]; | ||
| 140 | //} | ||
| 141 | // | ||
| 142 | //- (NSMenuItem *)aboutMenuItem | ||
| 143 | //{ | ||
| 144 | // return [[aboutItem retain] autorelease]; | ||
| 145 | //} | ||
| 146 | // | ||
| 147 | //- (NSMenuItem *)aboutQtMenuItem | ||
| 148 | //{ | ||
| 149 | // return [[aboutQtItem retain] autorelease]; | ||
| 150 | //} | ||
| 151 | // | ||
| 152 | //- (NSMenuItem *)hideMenuItem; | ||
| 153 | //{ | ||
| 154 | // return [[hideItem retain] autorelease]; | ||
| 155 | //} | ||
| 156 | // | ||
| 157 | //- (NSMenuItem *)appSpecificMenuItem; | ||
| 158 | //{ | ||
| 159 | // // Create an App-Specific menu item, insert it into the menu and return | ||
| 160 | // // it as an autorelease item. | ||
| 161 | // NSMenuItem *item = [[NSMenuItem alloc] init]; | ||
| 162 | // | ||
| 163 | // NSInteger location; | ||
| 164 | // if (lastAppSpecificItem == nil) { | ||
| 165 | // location = [appMenu indexOfItem:aboutQtItem]; | ||
| 166 | // } else { | ||
| 167 | // location = [appMenu indexOfItem:lastAppSpecificItem]; | ||
| 168 | // [lastAppSpecificItem release]; | ||
| 169 | // } | ||
| 170 | // lastAppSpecificItem = item; // Keep track of this for later (i.e., don't release it) | ||
| 171 | // [appMenu insertItem:item atIndex:location + 1]; | ||
| 172 | // | ||
| 173 | // return [[item retain] autorelease]; | ||
| 174 | //} | ||
| 175 | // | ||
| 176 | //- (BOOL) acceptsFirstResponder | ||
| 177 | //{ | ||
| 178 | // return YES; | ||
| 179 | //} | ||
| 180 | // | ||
| 181 | //- (void)terminate:(id)sender | ||
| 182 | //{ | ||
| 183 | // [NSApp terminate:sender]; | ||
| 184 | //} | ||
| 185 | // | ||
| 186 | //- (void)orderFrontStandardAboutPanel:(id)sender | ||
| 187 | //{ | ||
| 188 | // [NSApp orderFrontStandardAboutPanel:sender]; | ||
| 189 | //} | ||
| 190 | // | ||
| 191 | //- (void)hideOtherApplications:(id)sender | ||
| 192 | //{ | ||
| 193 | // [NSApp hideOtherApplications:sender]; | ||
| 194 | //} | ||
| 195 | // | ||
| 196 | //- (void)unhideAllApplications:(id)sender | ||
| 197 | //{ | ||
| 198 | // [NSApp unhideAllApplications:sender]; | ||
| 199 | //} | ||
| 200 | // | ||
| 201 | //- (void)hide:(id)sender | ||
| 202 | //{ | ||
| 203 | // [NSApp hide:sender]; | ||
| 204 | //} | ||
| 205 | // | ||
| 206 | //- (IBAction)qtDispatcherToQAction:(id)sender | ||
| 207 | //{ | ||
| 208 | // QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData); | ||
| 209 | // NSMenuItem *item = static_cast<NSMenuItem *>(sender); | ||
| 210 | // if (QAction *action = reinterpret_cast<QAction *>([item tag])) { | ||
| 211 | // action->trigger(); | ||
| 212 | // } else if (item == quitItem) { | ||
| 213 | // // We got here because someone was once the quitItem, but it has been | ||
| 214 | // // abandoned (e.g., the menubar was deleted). In the meantime, just do | ||
| 215 | // // normal QApplication::quit(). | ||
| 216 | // qApp->quit(); | ||
| 217 | // } | ||
| 218 | //} | ||
| 219 | //@end | ||
| 220 | //#endif // QT_MAC_USE_COCOA |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #ifndef QCOCOAMENULOADER_P_H | ||
| 43 | #define QCOCOAMENULOADER_P_H | ||
| 44 | |||
| 45 | // | ||
| 46 | // W A R N I N G | ||
| 47 | // ------------- | ||
| 48 | // | ||
| 49 | // This file is not part of the Qt API. It exists for the convenience | ||
| 50 | // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header | ||
| 51 | // file may change from version to version without notice, or even be removed. | ||
| 52 | // | ||
| 53 | // We mean it. | ||
| 54 | // | ||
| 55 | |||
| 56 | #include "qmacdefines_iphone.h" | ||
| 57 | |||
| 58 | //@interface QT_MANGLE_NAMESPACE(QCocoaMenuLoader) : NSResponder | ||
| 59 | //{ | ||
| 60 | // IBOutlet NSMenu *theMenu; | ||
| 61 | // IBOutlet NSMenu *appMenu; | ||
| 62 | // IBOutlet NSMenuItem *quitItem; | ||
| 63 | // IBOutlet NSMenuItem *preferencesItem; | ||
| 64 | // IBOutlet NSMenuItem *aboutItem; | ||
| 65 | // IBOutlet NSMenuItem *aboutQtItem; | ||
| 66 | // IBOutlet NSMenuItem *hideItem; | ||
| 67 | // NSMenuItem *lastAppSpecificItem; | ||
| 68 | // | ||
| 69 | //} | ||
| 70 | //- (void)ensureAppMenuInMenu:(NSMenu *)menu; | ||
| 71 | //- (NSMenu *)applicationMenu; | ||
| 72 | //- (NSMenu *)menu; | ||
| 73 | //- (NSMenuItem *)quitMenuItem; | ||
| 74 | //- (NSMenuItem *)preferencesMenuItem; | ||
| 75 | //- (NSMenuItem *)aboutMenuItem; | ||
| 76 | //- (NSMenuItem *)aboutQtMenuItem; | ||
| 77 | //- (NSMenuItem *)hideMenuItem; | ||
| 78 | //- (NSMenuItem *)appSpecificMenuItem; | ||
| 79 | //- (IBAction)terminate:(id)sender; | ||
| 80 | //- (IBAction)orderFrontStandardAboutPanel:(id)sender; | ||
| 81 | //- (IBAction)hideOtherApplications:(id)sender; | ||
| 82 | //- (IBAction)unhideAllApplications:(id)sender; | ||
| 83 | //- (IBAction)hide:(id)sender; | ||
| 84 | //- (IBAction)qtDispatcherToQAction:(id)sender; | ||
| 85 | //@end | ||
| 86 | |||
| 87 | #endif // QCOCOAMENULOADER_P_H |
src/gui/kernel/qcocoapanel_iphone.mm
(201 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #import <private/qcocoapanel_iphone_p.h> | ||
| 43 | #ifdef QT_MAC_USE_COCOA | ||
| 44 | #import <private/qt_cocoa_helpers_iphone_p.h> | ||
| 45 | #import <private/qcocoawindow_iphone_p.h> | ||
| 46 | #import <private/qcocoawindowdelegate_iphone_p.h> | ||
| 47 | #import <private/qcocoaview_iphone_p.h> | ||
| 48 | #import <private/qcocoawindowcustomthemeframe_iphone_p.h> | ||
| 49 | |||
| 50 | #include <QtGui/QWidget> | ||
| 51 | |||
| 52 | QT_FORWARD_DECLARE_CLASS(QWidget); | ||
| 53 | QT_BEGIN_NAMESPACE | ||
| 54 | extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm | ||
| 55 | QT_END_NAMESPACE | ||
| 56 | QT_USE_NAMESPACE | ||
| 57 | |||
| 58 | |||
| 59 | @interface NSWindow (QtCoverForHackWithCategory) | ||
| 60 | + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; | ||
| 61 | @end | ||
| 62 | |||
| 63 | |||
| 64 | @implementation QT_MANGLE_NAMESPACE(QCocoaPanel) | ||
| 65 | |||
| 66 | - (BOOL)canBecomeKeyWindow | ||
| 67 | { | ||
| 68 | QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)]; | ||
| 69 | |||
| 70 | bool isToolTip = (widget->windowType() == Qt::ToolTip); | ||
| 71 | bool isPopup = (widget->windowType() == Qt::Popup); | ||
| 72 | return !(isPopup || isToolTip); | ||
| 73 | } | ||
| 74 | |||
| 75 | /*********************************************************************** | ||
| 76 | BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel | ||
| 77 | This is a bit unfortunate, but thanks to the dynamic dispatch we | ||
| 78 | have to duplicate this code or resort to really silly forwarding methods | ||
| 79 | **************************************************************************/ | ||
| 80 | |||
| 81 | /* | ||
| 82 | The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever | ||
| 83 | get hit. We automatically say we can be first responder if we are a window. | ||
| 84 | So, the handling should get handled by the view. This is here more as a | ||
| 85 | last resort (i.e., this is code that can potentially be removed). | ||
| 86 | */ | ||
| 87 | |||
| 88 | - (void)toggleToolbarShown:(id)sender | ||
| 89 | { | ||
| 90 | macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 91 | [super toggleToolbarShown:sender]; | ||
| 92 | } | ||
| 93 | |||
| 94 | - (void)keyDown:(NSEvent *)theEvent | ||
| 95 | { | ||
| 96 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 97 | if (!keyOK) | ||
| 98 | [super keyDown:theEvent]; | ||
| 99 | } | ||
| 100 | |||
| 101 | - (void)keyUp:(NSEvent *)theEvent | ||
| 102 | { | ||
| 103 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 104 | if (!keyOK) | ||
| 105 | [super keyUp:theEvent]; | ||
| 106 | } | ||
| 107 | |||
| 108 | - (void)flagsChanged:(NSEvent *)theEvent | ||
| 109 | { | ||
| 110 | qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 111 | [super flagsChanged:theEvent]; | ||
| 112 | } | ||
| 113 | |||
| 114 | |||
| 115 | - (void)tabletProximity:(NSEvent *)tabletEvent | ||
| 116 | { | ||
| 117 | qt_dispatchTabletProximityEvent(tabletEvent); | ||
| 118 | } | ||
| 119 | |||
| 120 | - (void)sendEvent:(NSEvent *)event | ||
| 121 | { | ||
| 122 | QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; | ||
| 123 | |||
| 124 | // Cocoa can hold onto the window after we've disavowed its knowledge. So, | ||
| 125 | // if we get sent an event afterwards just have it go through the super's | ||
| 126 | // version and don't do any stuff with Qt. | ||
| 127 | if (!widget) { | ||
| 128 | [super sendEvent:event]; | ||
| 129 | return; | ||
| 130 | } | ||
| 131 | [self retain]; | ||
| 132 | QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget)); | ||
| 133 | Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]); | ||
| 134 | |||
| 135 | // sometimes need to redirect mouse events to the popup. | ||
| 136 | QWidget *popup = qAppInstance()->activePopupWidget(); | ||
| 137 | if (popup && popup != widget) { | ||
| 138 | switch([event type]) | ||
| 139 | { | ||
| 140 | case NSLeftMouseDown: | ||
| 141 | qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton); | ||
| 142 | // Don't call super here. This prevents us from getting the mouseUp event, | ||
| 143 | // which we need to send even if the mouseDown event was not accepted. | ||
| 144 | // (this is standard Qt behavior.) | ||
| 145 | break; | ||
| 146 | case NSRightMouseDown: | ||
| 147 | case NSOtherMouseDown: | ||
| 148 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton)) | ||
| 149 | [super sendEvent:event]; | ||
| 150 | break; | ||
| 151 | case NSLeftMouseUp: | ||
| 152 | case NSRightMouseUp: | ||
| 153 | case NSOtherMouseUp: | ||
| 154 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton)) | ||
| 155 | [super sendEvent:event]; | ||
| 156 | break; | ||
| 157 | case NSMouseMoved: | ||
| 158 | qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton); | ||
| 159 | break; | ||
| 160 | case NSLeftMouseDragged: | ||
| 161 | case NSRightMouseDragged: | ||
| 162 | case NSOtherMouseDragged: | ||
| 163 | [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view; | ||
| 164 | [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event; | ||
| 165 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton)) | ||
| 166 | [super sendEvent:event]; | ||
| 167 | break; | ||
| 168 | default: | ||
| 169 | [super sendEvent:event]; | ||
| 170 | break; | ||
| 171 | } | ||
| 172 | } else { | ||
| 173 | [super sendEvent:event]; | ||
| 174 | } | ||
| 175 | qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton); | ||
| 176 | |||
| 177 | |||
| 178 | [self release]; | ||
| 179 | } | ||
| 180 | |||
| 181 | - (BOOL)makeFirstResponder:(NSResponder *)responder | ||
| 182 | { | ||
| 183 | // For some reason Cocoa wants to flip the first responder | ||
| 184 | // when Qt doesn't want to, sorry, but "No" :-) | ||
| 185 | if (responder == nil && qApp->focusWidget()) | ||
| 186 | return NO; | ||
| 187 | return [super makeFirstResponder:responder]; | ||
| 188 | } | ||
| 189 | |||
| 190 | /*********************************************************************** | ||
| 191 | END Copy and Paste between QCocoaWindow and QCocoaPanel | ||
| 192 | ***********************************************************************/ | ||
| 193 | + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask | ||
| 194 | { | ||
| 195 | if (styleMask & QtMacCustomizeWindow) | ||
| 196 | return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class]; | ||
| 197 | return [super frameViewClassForStyleMask:styleMask]; | ||
| 198 | } | ||
| 199 | |||
| 200 | @end | ||
| 201 | #endif |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists purely as an | ||
| 47 | // implementation detail. This header file may change from version to | ||
| 48 | // version without notice, or even be removed. | ||
| 49 | // | ||
| 50 | // We mean it. | ||
| 51 | // | ||
| 52 | |||
| 53 | #include "qmacdefines_iphone.h" | ||
| 54 | //#ifdef QT_MAC_USE_COCOA | ||
| 55 | //#import <Cocoa/Cocoa.h> | ||
| 56 | // | ||
| 57 | // | ||
| 58 | //@interface QT_MANGLE_NAMESPACE(QCocoaPanel) : NSPanel { | ||
| 59 | // bool leftButtonIsRightButton; | ||
| 60 | //} | ||
| 61 | // | ||
| 62 | //+ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; | ||
| 63 | // | ||
| 64 | //@end | ||
| 65 | //#endif |
src/gui/kernel/qcocoaview_iphone.mm
(1474 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #import <private/qcocoaview_mac_p.h> | ||
| 43 | #ifdef QT_MAC_USE_COCOA | ||
| 44 | |||
| 45 | #include <private/qwidget_p.h> | ||
| 46 | #include <private/qt_mac_p.h> | ||
| 47 | #include <private/qapplication_p.h> | ||
| 48 | #include <private/qabstractscrollarea_p.h> | ||
| 49 | #include <private/qt_cocoa_helpers_mac_p.h> | ||
| 50 | #include <private/qdnd_p.h> | ||
| 51 | #include <private/qmacinputcontext_p.h> | ||
| 52 | #include <private/qmultitouch_mac_p.h> | ||
| 53 | #include <private/qevent_p.h> | ||
| 54 | #include <private/qbackingstore_p.h> | ||
| 55 | |||
| 56 | #include <qscrollarea.h> | ||
| 57 | #include <qhash.h> | ||
| 58 | #include <qtextformat.h> | ||
| 59 | #include <qpaintengine.h> | ||
| 60 | #include <QUrl> | ||
| 61 | #include <QAccessible> | ||
| 62 | #include <QFileInfo> | ||
| 63 | #include <QFile> | ||
| 64 | |||
| 65 | #include <qdebug.h> | ||
| 66 | |||
| 67 | @interface NSEvent (Qt_Compile_Leopard_DeviceDelta) | ||
| 68 | - (CGFloat)deviceDeltaX; | ||
| 69 | - (CGFloat)deviceDeltaY; | ||
| 70 | - (CGFloat)deviceDeltaZ; | ||
| 71 | @end | ||
| 72 | |||
| 73 | @interface NSEvent (Qt_Compile_Leopard_Gestures) | ||
| 74 | - (CGFloat)magnification; | ||
| 75 | @end | ||
| 76 | |||
| 77 | QT_BEGIN_NAMESPACE | ||
| 78 | |||
| 79 | Q_GLOBAL_STATIC(DnDParams, qMacDnDParams); | ||
| 80 | |||
| 81 | extern void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos); // qcursor_mac.mm | ||
| 82 | extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp | ||
| 83 | extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm | ||
| 84 | extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp | ||
| 85 | extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm | ||
| 86 | extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp | ||
| 87 | |||
| 88 | Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) | ||
| 89 | { | ||
| 90 | if (buttonNum == 0) | ||
| 91 | return Qt::LeftButton; | ||
| 92 | if (buttonNum == 1) | ||
| 93 | return Qt::RightButton; | ||
| 94 | if (buttonNum == 2) | ||
| 95 | return Qt::MidButton; | ||
| 96 | if (buttonNum == 3) | ||
| 97 | return Qt::XButton1; | ||
| 98 | if (buttonNum == 4) | ||
| 99 | return Qt::XButton2; | ||
| 100 | return Qt::NoButton; | ||
| 101 | } | ||
| 102 | |||
| 103 | struct dndenum_mapper | ||
| 104 | { | ||
| 105 | NSDragOperation mac_code; | ||
| 106 | Qt::DropAction qt_code; | ||
| 107 | bool Qt2Mac; | ||
| 108 | }; | ||
| 109 | |||
| 110 | static dndenum_mapper dnd_enums[] = { | ||
| 111 | { NSDragOperationLink, Qt::LinkAction, true }, | ||
| 112 | { NSDragOperationMove, Qt::MoveAction, true }, | ||
| 113 | { NSDragOperationCopy, Qt::CopyAction, true }, | ||
| 114 | { NSDragOperationGeneric, Qt::CopyAction, false }, | ||
| 115 | { NSDragOperationEvery, Qt::ActionMask, false }, | ||
| 116 | { NSDragOperationNone, Qt::IgnoreAction, false } | ||
| 117 | }; | ||
| 118 | |||
| 119 | static NSDragOperation qt_mac_mapDropAction(Qt::DropAction action) | ||
| 120 | { | ||
| 121 | for (int i=0; dnd_enums[i].qt_code; i++) { | ||
| 122 | if (dnd_enums[i].Qt2Mac && (action & dnd_enums[i].qt_code)) { | ||
| 123 | return dnd_enums[i].mac_code; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | return NSDragOperationNone; | ||
| 127 | } | ||
| 128 | |||
| 129 | static NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions) | ||
| 130 | { | ||
| 131 | NSDragOperation nsActions = NSDragOperationNone; | ||
| 132 | for (int i=0; dnd_enums[i].qt_code; i++) { | ||
| 133 | if (dnd_enums[i].Qt2Mac && (actions & dnd_enums[i].qt_code)) | ||
| 134 | nsActions |= dnd_enums[i].mac_code; | ||
| 135 | } | ||
| 136 | return nsActions; | ||
| 137 | } | ||
| 138 | |||
| 139 | static Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions) | ||
| 140 | { | ||
| 141 | Qt::DropAction action = Qt::IgnoreAction; | ||
| 142 | for (int i=0; dnd_enums[i].mac_code; i++) { | ||
| 143 | if (nsActions & dnd_enums[i].mac_code) | ||
| 144 | return dnd_enums[i].qt_code; | ||
| 145 | } | ||
| 146 | return action; | ||
| 147 | } | ||
| 148 | |||
| 149 | static Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions) | ||
| 150 | { | ||
| 151 | Qt::DropActions actions = Qt::IgnoreAction; | ||
| 152 | for (int i=0; dnd_enums[i].mac_code; i++) { | ||
| 153 | if (nsActions & dnd_enums[i].mac_code) | ||
| 154 | actions |= dnd_enums[i].qt_code; | ||
| 155 | } | ||
| 156 | return actions; | ||
| 157 | } | ||
| 158 | |||
| 159 | static QColor colorFrom(NSColor *color) | ||
| 160 | { | ||
| 161 | QColor qtColor; | ||
| 162 | NSString *colorSpace = [color colorSpaceName]; | ||
| 163 | if (colorSpace == NSDeviceCMYKColorSpace) { | ||
| 164 | CGFloat cyan, magenta, yellow, black, alpha; | ||
| 165 | [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; | ||
| 166 | qtColor.setCmykF(cyan, magenta, yellow, black, alpha); | ||
| 167 | } else { | ||
| 168 | NSColor *tmpColor; | ||
| 169 | tmpColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; | ||
| 170 | CGFloat red, green, blue, alpha; | ||
| 171 | [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; | ||
| 172 | qtColor.setRgbF(red, green, blue, alpha); | ||
| 173 | } | ||
| 174 | return qtColor; | ||
| 175 | } | ||
| 176 | |||
| 177 | QT_END_NAMESPACE | ||
| 178 | |||
| 179 | QT_FORWARD_DECLARE_CLASS(QMacCocoaAutoReleasePool) | ||
| 180 | QT_FORWARD_DECLARE_CLASS(QCFString) | ||
| 181 | QT_FORWARD_DECLARE_CLASS(QDragManager) | ||
| 182 | QT_FORWARD_DECLARE_CLASS(QMimeData) | ||
| 183 | QT_FORWARD_DECLARE_CLASS(QPoint) | ||
| 184 | QT_FORWARD_DECLARE_CLASS(QApplication) | ||
| 185 | QT_FORWARD_DECLARE_CLASS(QApplicationPrivate) | ||
| 186 | QT_FORWARD_DECLARE_CLASS(QDragEnterEvent) | ||
| 187 | QT_FORWARD_DECLARE_CLASS(QDragMoveEvent) | ||
| 188 | QT_FORWARD_DECLARE_CLASS(QStringList) | ||
| 189 | QT_FORWARD_DECLARE_CLASS(QString) | ||
| 190 | QT_FORWARD_DECLARE_CLASS(QRect) | ||
| 191 | QT_FORWARD_DECLARE_CLASS(QRegion) | ||
| 192 | QT_FORWARD_DECLARE_CLASS(QAbstractScrollArea) | ||
| 193 | QT_FORWARD_DECLARE_CLASS(QAbstractScrollAreaPrivate) | ||
| 194 | QT_FORWARD_DECLARE_CLASS(QPaintEvent) | ||
| 195 | QT_FORWARD_DECLARE_CLASS(QPainter) | ||
| 196 | QT_FORWARD_DECLARE_CLASS(QHoverEvent) | ||
| 197 | QT_FORWARD_DECLARE_CLASS(QCursor) | ||
| 198 | QT_USE_NAMESPACE | ||
| 199 | extern "C" { | ||
| 200 | extern NSString *NSTextInputReplacementRangeAttributeName; | ||
| 201 | } | ||
| 202 | |||
| 203 | |||
| 204 | @implementation QT_MANGLE_NAMESPACE(QCocoaView) | ||
| 205 | |||
| 206 | - (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate | ||
| 207 | { | ||
| 208 | self = [super init]; | ||
| 209 | if (self) { | ||
| 210 | [self finishInitWithQWidget:widget widgetPrivate:widgetprivate]; | ||
| 211 | } | ||
| 212 | composingText = new QString(); | ||
| 213 | composing = false; | ||
| 214 | sendKeyEvents = true; | ||
| 215 | currentCustomTypes = 0; | ||
| 216 | [self setHidden:YES]; | ||
| 217 | return self; | ||
| 218 | } | ||
| 219 | |||
| 220 | - (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate | ||
| 221 | { | ||
| 222 | qwidget = widget; | ||
| 223 | qwidgetprivate = widgetprivate; | ||
| 224 | [[NSNotificationCenter defaultCenter] addObserver:self | ||
| 225 | selector:@selector(frameDidChange:) | ||
| 226 | name:@"NSViewFrameDidChangeNotification" | ||
| 227 | object:self]; | ||
| 228 | } | ||
| 229 | |||
| 230 | -(void)registerDragTypes | ||
| 231 | { | ||
| 232 | QMacCocoaAutoReleasePool pool; | ||
| 233 | // Calling registerForDraggedTypes is slow, so only do it once for each widget | ||
| 234 | // or when the custom types change. | ||
| 235 | const QStringList& customTypes = qEnabledDraggedTypes(); | ||
| 236 | if (currentCustomTypes == 0 || *currentCustomTypes != customTypes) { | ||
| 237 | if (currentCustomTypes == 0) | ||
| 238 | currentCustomTypes = new QStringList(); | ||
| 239 | *currentCustomTypes = customTypes; | ||
| 240 | const NSString* mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName"; | ||
| 241 | NSMutableArray *supportedTypes = [NSMutableArray arrayWithObjects:NSColorPboardType, | ||
| 242 | NSFilenamesPboardType, NSStringPboardType, | ||
| 243 | NSFilenamesPboardType, NSPostScriptPboardType, NSTIFFPboardType, | ||
| 244 | NSRTFPboardType, NSTabularTextPboardType, NSFontPboardType, | ||
| 245 | NSRulerPboardType, NSFileContentsPboardType, NSColorPboardType, | ||
| 246 | NSRTFDPboardType, NSHTMLPboardType, NSPICTPboardType, | ||
| 247 | NSURLPboardType, NSPDFPboardType, NSVCardPboardType, | ||
| 248 | NSFilesPromisePboardType, NSInkTextPboardType, | ||
| 249 | NSMultipleTextSelectionPboardType, mimeTypeGeneric, nil]; | ||
| 250 | // Add custom types supported by the application. | ||
| 251 | for (int i = 0; i < customTypes.size(); i++) { | ||
| 252 | [supportedTypes addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(customTypes[i]))]; | ||
| 253 | } | ||
| 254 | [self registerForDraggedTypes:supportedTypes]; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | - (void)resetCursorRects | ||
| 259 | { | ||
| 260 | QWidget *cursorWidget = qwidget; | ||
| 261 | |||
| 262 | if (cursorWidget->testAttribute(Qt::WA_TransparentForMouseEvents)) | ||
| 263 | cursorWidget = QApplication::widgetAt(qwidget->mapToGlobal(qwidget->rect().center())); | ||
| 264 | |||
| 265 | if (cursorWidget == 0) | ||
| 266 | return; | ||
| 267 | |||
| 268 | if (!cursorWidget->testAttribute(Qt::WA_SetCursor)) { | ||
| 269 | [super resetCursorRects]; | ||
| 270 | return; | ||
| 271 | } | ||
| 272 | |||
| 273 | QRegion mask = qt_widget_private(cursorWidget)->extra->mask; | ||
| 274 | NSCursor *nscursor = static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursorWidget->cursor())); | ||
| 275 | if (mask.isEmpty()) { | ||
| 276 | [self addCursorRect:[qt_mac_nativeview_for(cursorWidget) visibleRect] cursor:nscursor]; | ||
| 277 | } else { | ||
| 278 | const QVector<QRect> &rects = mask.rects(); | ||
| 279 | for (int i = 0; i < rects.size(); ++i) { | ||
| 280 | const QRect &rect = rects.at(i); | ||
| 281 | [self addCursorRect:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()) cursor:nscursor]; | ||
| 282 | } | ||
| 283 | } | ||
| 284 | } | ||
| 285 | |||
| 286 | - (void)removeDropData | ||
| 287 | { | ||
| 288 | if (dropData) { | ||
| 289 | delete dropData; | ||
| 290 | dropData = 0; | ||
| 291 | } | ||
| 292 | } | ||
| 293 | |||
| 294 | - (void)addDropData:(id <NSDraggingInfo>)sender | ||
| 295 | { | ||
| 296 | [self removeDropData]; | ||
| 297 | CFStringRef dropPasteboard = (CFStringRef) [[sender draggingPasteboard] name]; | ||
| 298 | dropData = new QCocoaDropData(dropPasteboard); | ||
| 299 | } | ||
| 300 | |||
| 301 | - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender | ||
| 302 | { | ||
| 303 | if (qwidget->testAttribute(Qt::WA_DropSiteRegistered) == false) | ||
| 304 | return NSDragOperationNone; | ||
| 305 | NSPoint windowPoint = [sender draggingLocation]; | ||
| 306 | if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { | ||
| 307 | // pass the drag enter event to the view underneath. | ||
| 308 | NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; | ||
| 309 | if (candidateView && candidateView != self) | ||
| 310 | return [candidateView draggingEntered:sender]; | ||
| 311 | } | ||
| 312 | dragEnterSequence = [sender draggingSequenceNumber]; | ||
| 313 | [self addDropData:sender]; | ||
| 314 | QMimeData *mimeData = dropData; | ||
| 315 | if (QDragManager::self()->source()) | ||
| 316 | mimeData = QDragManager::self()->dragPrivate()->data; | ||
| 317 | NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; | ||
| 318 | NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; | ||
| 319 | QPoint posDrag(localPoint.x, localPoint.y); | ||
| 320 | NSDragOperation nsActions = [sender draggingSourceOperationMask]; | ||
| 321 | Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions); | ||
| 322 | QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions; | ||
| 323 | Qt::KeyboardModifiers modifiers = Qt::NoModifier; | ||
| 324 | if ([sender draggingSource] != nil) { | ||
| 325 | // modifier flags might have changed, update it here since we don't send any input events. | ||
| 326 | QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]); | ||
| 327 | modifiers = QApplication::keyboardModifiers(); | ||
| 328 | } else { | ||
| 329 | // when the source is from another application the above technique will not work. | ||
| 330 | modifiers = qt_cocoaDragOperation2QtModifiers(nsActions); | ||
| 331 | } | ||
| 332 | // send the drag enter event to the widget. | ||
| 333 | QDragEnterEvent qDEEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); | ||
| 334 | QApplication::sendEvent(qwidget, &qDEEvent); | ||
| 335 | if (!qDEEvent.isAccepted()) { | ||
| 336 | // widget is not interested in this drag, so ignore this drop data. | ||
| 337 | [self removeDropData]; | ||
| 338 | return NSDragOperationNone; | ||
| 339 | } else { | ||
| 340 | // save the mouse position, used by draggingExited handler. | ||
| 341 | DnDParams *dndParams = [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]; | ||
| 342 | dndParams->activeDragEnterPos = windowPoint; | ||
| 343 | // send a drag move event immediately after a drag enter event (as per documentation). | ||
| 344 | QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); | ||
| 345 | qDMEvent.setDropAction(qDEEvent.dropAction()); | ||
| 346 | qDMEvent.accept(); // accept by default, since enter event was accepted. | ||
| 347 | QApplication::sendEvent(qwidget, &qDMEvent); | ||
| 348 | if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) { | ||
| 349 | // since we accepted the drag enter event, the widget expects | ||
| 350 | // future drage move events. | ||
| 351 | // ### check if we need to treat this like the drag enter event. | ||
| 352 | nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDEEvent.dropAction()); | ||
| 353 | } else { | ||
| 354 | nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDMEvent.dropAction()); | ||
| 355 | } | ||
| 356 | QT_PREPEND_NAMESPACE(qt_mac_copy_answer_rect)(qDMEvent); | ||
| 357 | return nsActions; | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 361 | - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender | ||
| 362 | { | ||
| 363 | NSPoint windowPoint = [sender draggingLocation]; | ||
| 364 | if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { | ||
| 365 | // pass the drag move event to the view underneath. | ||
| 366 | NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; | ||
| 367 | if (candidateView && candidateView != self) | ||
| 368 | return [candidateView draggingUpdated:sender]; | ||
| 369 | } | ||
| 370 | // in cases like QFocusFrame, the view under the mouse might | ||
| 371 | // not have received the drag enter. Generate a synthetic | ||
| 372 | // drag enter event for that view. | ||
| 373 | if (dragEnterSequence != [sender draggingSequenceNumber]) | ||
| 374 | [self draggingEntered:sender]; | ||
| 375 | // drag enter event was rejected, so ignore the move event. | ||
| 376 | if (dropData == 0) | ||
| 377 | return NSDragOperationNone; | ||
| 378 | // return last value, if we are still in the answerRect. | ||
| 379 | NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; | ||
| 380 | NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; | ||
| 381 | NSDragOperation nsActions = [sender draggingSourceOperationMask]; | ||
| 382 | QPoint posDrag(localPoint.x, localPoint.y); | ||
| 383 | if (qt_mac_mouse_inside_answer_rect(posDrag) | ||
| 384 | && QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) == nsActions) | ||
| 385 | return QT_PREPEND_NAMESPACE(qt_mac_mapDropActions)(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastAction)); | ||
| 386 | // send drag move event to the widget | ||
| 387 | QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions; | ||
| 388 | Qt::DropActions qtAllowed = QT_PREPEND_NAMESPACE(qt_mac_mapNSDragOperations)(nsActions); | ||
| 389 | Qt::KeyboardModifiers modifiers = Qt::NoModifier; | ||
| 390 | if ([sender draggingSource] != nil) { | ||
| 391 | // modifier flags might have changed, update it here since we don't send any input events. | ||
| 392 | QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]); | ||
| 393 | modifiers = QApplication::keyboardModifiers(); | ||
| 394 | } else { | ||
| 395 | // when the source is from another application the above technique will not work. | ||
| 396 | modifiers = qt_cocoaDragOperation2QtModifiers(nsActions); | ||
| 397 | } | ||
| 398 | QMimeData *mimeData = dropData; | ||
| 399 | if (QDragManager::self()->source()) | ||
| 400 | mimeData = QDragManager::self()->dragPrivate()->data; | ||
| 401 | QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); | ||
| 402 | qDMEvent.setDropAction(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction); | ||
| 403 | qDMEvent.accept(); | ||
| 404 | QApplication::sendEvent(qwidget, &qDMEvent); | ||
| 405 | qt_mac_copy_answer_rect(qDMEvent); | ||
| 406 | |||
| 407 | NSDragOperation operation = qt_mac_mapDropAction(qDMEvent.dropAction()); | ||
| 408 | if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) { | ||
| 409 | // ignore this event (we will still receive further notifications) | ||
| 410 | operation = NSDragOperationNone; | ||
| 411 | } | ||
| 412 | return operation; | ||
| 413 | } | ||
| 414 | |||
| 415 | - (void)draggingExited:(id < NSDraggingInfo >)sender | ||
| 416 | { | ||
| 417 | dragEnterSequence = -1; | ||
| 418 | if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { | ||
| 419 | // try sending the leave event to the last view which accepted drag enter. | ||
| 420 | DnDParams *dndParams = [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]; | ||
| 421 | NSView *candidateView = [[[self window] contentView] hitTest:dndParams->activeDragEnterPos]; | ||
| 422 | if (candidateView && candidateView != self) | ||
| 423 | return [candidateView draggingExited:sender]; | ||
| 424 | } | ||
| 425 | // drag enter event was rejected, so ignore the move event. | ||
| 426 | if (dropData) { | ||
| 427 | QDragLeaveEvent de; | ||
| 428 | QApplication::sendEvent(qwidget, &de); | ||
| 429 | [self removeDropData]; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender | ||
| 434 | { | ||
| 435 | NSPoint windowPoint = [sender draggingLocation]; | ||
| 436 | dragEnterSequence = -1; | ||
| 437 | if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) { | ||
| 438 | // pass the drop event to the view underneath. | ||
| 439 | NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; | ||
| 440 | if (candidateView && candidateView != self) | ||
| 441 | return [candidateView performDragOperation:sender]; | ||
| 442 | } | ||
| 443 | [self addDropData:sender]; | ||
| 444 | |||
| 445 | NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; | ||
| 446 | NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; | ||
| 447 | QPoint posDrop(localPoint.x, localPoint.y); | ||
| 448 | |||
| 449 | NSDragOperation nsActions = [sender draggingSourceOperationMask]; | ||
| 450 | Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions); | ||
| 451 | QMimeData *mimeData = dropData; | ||
| 452 | if (QDragManager::self()->source()) | ||
| 453 | mimeData = QDragManager::self()->dragPrivate()->data; | ||
| 454 | // send the drop event to the widget. | ||
| 455 | QDropEvent de(posDrop, qtAllowed, mimeData, | ||
| 456 | QApplication::mouseButtons(), QApplication::keyboardModifiers()); | ||
| 457 | if (QDragManager::self()->object) | ||
| 458 | QDragManager::self()->dragPrivate()->target = qwidget; | ||
| 459 | QApplication::sendEvent(qwidget, &de); | ||
| 460 | if (QDragManager::self()->object) | ||
| 461 | QDragManager::self()->dragPrivate()->executed_action = de.dropAction(); | ||
| 462 | if (!de.isAccepted()) | ||
| 463 | return NO; | ||
| 464 | else | ||
| 465 | return YES; | ||
| 466 | } | ||
| 467 | |||
| 468 | - (void)dealloc | ||
| 469 | { | ||
| 470 | delete composingText; | ||
| 471 | [[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
| 472 | delete currentCustomTypes; | ||
| 473 | [self unregisterDraggedTypes]; | ||
| 474 | [super dealloc]; | ||
| 475 | } | ||
| 476 | |||
| 477 | - (BOOL)isOpaque; | ||
| 478 | { | ||
| 479 | return qwidgetprivate->isOpaque; | ||
| 480 | } | ||
| 481 | |||
| 482 | - (BOOL)isFlipped; | ||
| 483 | { | ||
| 484 | return YES; | ||
| 485 | } | ||
| 486 | |||
| 487 | - (BOOL) preservesContentDuringLiveResize; | ||
| 488 | { | ||
| 489 | return qwidget->testAttribute(Qt::WA_StaticContents); | ||
| 490 | } | ||
| 491 | |||
| 492 | - (void) setFrameSize:(NSSize)newSize | ||
| 493 | { | ||
| 494 | [super setFrameSize:newSize]; | ||
| 495 | |||
| 496 | // A change in size has required the view to be invalidated. | ||
| 497 | if ([self inLiveResize]) { | ||
| 498 | NSRect rects[4]; | ||
| 499 | NSInteger count; | ||
| 500 | [self getRectsExposedDuringLiveResize:rects count:&count]; | ||
| 501 | while (count-- > 0) | ||
| 502 | { | ||
| 503 | [self setNeedsDisplayInRect:rects[count]]; | ||
| 504 | } | ||
| 505 | } else { | ||
| 506 | [self setNeedsDisplay:YES]; | ||
| 507 | } | ||
| 508 | } | ||
| 509 | |||
| 510 | - (void)drawRect:(NSRect)aRect | ||
| 511 | { | ||
| 512 | if (QApplicationPrivate::graphicsSystem() != 0) { | ||
| 513 | if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore()) | ||
| 514 | bs->markDirty(qwidget->rect(), qwidget); | ||
| 515 | qwidgetprivate->syncBackingStore(qwidget->rect()); | ||
| 516 | return; | ||
| 517 | } | ||
| 518 | CGContextRef cg = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | ||
| 519 | qwidgetprivate->hd = cg; | ||
| 520 | CGContextSaveGState(cg); | ||
| 521 | |||
| 522 | if (qwidget->isVisible() && qwidget->updatesEnabled()) { //process the actual paint event. | ||
| 523 | if (qwidget->testAttribute(Qt::WA_WState_InPaintEvent)) | ||
| 524 | qWarning("QWidget::repaint: Recursive repaint detected"); | ||
| 525 | |||
| 526 | const QRect qrect = QRect(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height); | ||
| 527 | QRegion qrgn(qrect); | ||
| 528 | |||
| 529 | if (!qwidget->isWindow() && !qobject_cast<QAbstractScrollArea *>(qwidget->parent())) { | ||
| 530 | const QRegion &parentMask = qwidget->window()->mask(); | ||
| 531 | if (!parentMask.isEmpty()) { | ||
| 532 | const QPoint mappedPoint = qwidget->mapTo(qwidget->window(), qrect.topLeft()); | ||
| 533 | qrgn.translate(mappedPoint); | ||
| 534 | qrgn &= parentMask; | ||
| 535 | qrgn.translate(-mappedPoint.x(), -mappedPoint.y()); | ||
| 536 | } | ||
| 537 | } | ||
| 538 | |||
| 539 | QPoint redirectionOffset(0, 0); | ||
| 540 | //setup the context | ||
| 541 | qwidget->setAttribute(Qt::WA_WState_InPaintEvent); | ||
| 542 | QPaintEngine *engine = qwidget->paintEngine(); | ||
| 543 | if (engine) | ||
| 544 | engine->setSystemClip(qrgn); | ||
| 545 | if (qwidgetprivate->extra && qwidgetprivate->extra->hasMask) { | ||
| 546 | CGRect widgetRect = CGRectMake(0, 0, qwidget->width(), qwidget->height()); | ||
| 547 | CGContextTranslateCTM (cg, 0, widgetRect.size.height); | ||
| 548 | CGContextScaleCTM(cg, 1, -1); | ||
| 549 | if (qwidget->isWindow()) | ||
| 550 | CGContextClearRect(cg, widgetRect); | ||
| 551 | CGContextClipToMask(cg, widgetRect, qwidgetprivate->extra->imageMask); | ||
| 552 | CGContextScaleCTM(cg, 1, -1); | ||
| 553 | CGContextTranslateCTM (cg, 0, -widgetRect.size.height); | ||
| 554 | } | ||
| 555 | |||
| 556 | if (qwidget->isWindow() && !qwidgetprivate->isOpaque | ||
| 557 | && !qwidget->testAttribute(Qt::WA_MacBrushedMetal)) { | ||
| 558 | CGContextClearRect(cg, NSRectToCGRect(aRect)); | ||
| 559 | } | ||
| 560 | |||
| 561 | if (engine && !qwidget->testAttribute(Qt::WA_NoSystemBackground) | ||
| 562 | && (qwidget->isWindow() || qwidget->autoFillBackground()) | ||
| 563 | || qwidget->testAttribute(Qt::WA_TintedBackground) | ||
| 564 | || qwidget->testAttribute(Qt::WA_StyledBackground)) { | ||
| 565 | #ifdef DEBUG_WIDGET_PAINT | ||
| 566 | if(doDebug) | ||
| 567 | qDebug(" Handling erase for [%s::%s]", qwidget->metaObject()->className(), | ||
| 568 | qwidget->objectName().local8Bit().data()); | ||
| 569 | #endif | ||
| 570 | QPainter p(qwidget); | ||
| 571 | qwidgetprivate->paintBackground(&p, qrgn, | ||
| 572 | qwidget->isWindow() ? QWidgetPrivate::DrawAsRoot : 0); | ||
| 573 | p.end(); | ||
| 574 | } | ||
| 575 | QPaintEvent e(qrgn); | ||
| 576 | #ifdef QT3_SUPPORT | ||
| 577 | e.setErased(true); | ||
| 578 | #endif | ||
| 579 | qt_sendSpontaneousEvent(qwidget, &e); | ||
| 580 | if (!redirectionOffset.isNull()) | ||
| 581 | QPainter::restoreRedirected(qwidget); | ||
| 582 | if (engine) | ||
| 583 | engine->setSystemClip(QRegion()); | ||
| 584 | qwidget->setAttribute(Qt::WA_WState_InPaintEvent, false); | ||
| 585 | if(!qwidget->testAttribute(Qt::WA_PaintOutsidePaintEvent) && qwidget->paintingActive()) | ||
| 586 | qWarning("QWidget: It is dangerous to leave painters active on a" | ||
| 587 | " widget outside of the PaintEvent"); | ||
| 588 | } | ||
| 589 | qwidgetprivate->hd = 0; | ||
| 590 | CGContextRestoreGState(cg); | ||
| 591 | } | ||
| 592 | |||
| 593 | - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent | ||
| 594 | { | ||
| 595 | Q_UNUSED(theEvent); | ||
| 596 | return !qwidget->testAttribute(Qt::WA_MacNoClickThrough); | ||
| 597 | } | ||
| 598 | |||
| 599 | - (NSView *)hitTest:(NSPoint)aPoint | ||
| 600 | { | ||
| 601 | if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) | ||
| 602 | return nil; // You cannot hit a transparent for mouse event widget. | ||
| 603 | return [super hitTest:aPoint]; | ||
| 604 | } | ||
| 605 | |||
| 606 | - (void)updateTrackingAreas | ||
| 607 | { | ||
| 608 | QMacCocoaAutoReleasePool pool; | ||
| 609 | if (NSArray *trackingArray = [self trackingAreas]) { | ||
| 610 | NSUInteger size = [trackingArray count]; | ||
| 611 | for (NSUInteger i = 0; i < size; ++i) { | ||
| 612 | NSTrackingArea *t = [trackingArray objectAtIndex:i]; | ||
| 613 | [self removeTrackingArea:t]; | ||
| 614 | } | ||
| 615 | } | ||
| 616 | |||
| 617 | // Ideally, we shouldn't have NSTrackingMouseMoved events included below, it should | ||
| 618 | // only be turned on if mouseTracking, hover is on or a tool tip is set. | ||
| 619 | // Unfortunately, Qt will send "tooltip" events on mouse moves, so we need to | ||
| 620 | // turn it on in ALL case. That means EVERY QCocoaView gets to pay the cost of | ||
| 621 | // mouse moves delivered to it (Apple recommends keeping it OFF because there | ||
| 622 | // is a performance hit). So it goes. | ||
| 623 | NSUInteger trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp | ||
| 624 | | NSTrackingInVisibleRect | NSTrackingMouseMoved; | ||
| 625 | NSTrackingArea *ta = [[NSTrackingArea alloc] initWithRect:NSMakeRect(0, 0, | ||
| 626 | qwidget->width(), | ||
| 627 | qwidget->height()) | ||
| 628 | options:trackingOptions | ||
| 629 | owner:self | ||
| 630 | userInfo:nil]; | ||
| 631 | [self addTrackingArea:ta]; | ||
| 632 | [ta release]; | ||
| 633 | } | ||
| 634 | |||
| 635 | - (void)mouseEntered:(NSEvent *)event | ||
| 636 | { | ||
| 637 | QEvent enterEvent(QEvent::Enter); | ||
| 638 | NSPoint windowPoint = [event locationInWindow]; | ||
| 639 | NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; | ||
| 640 | NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil]; | ||
| 641 | if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) { | ||
| 642 | QApplication::sendEvent(qwidget, &enterEvent); | ||
| 643 | qt_mouseover = qwidget; | ||
| 644 | |||
| 645 | // Update cursor and dispatch hover events. | ||
| 646 | qt_mac_update_cursor_at_global_pos(flipPoint(globalPoint).toPoint()); | ||
| 647 | if (qwidget->testAttribute(Qt::WA_Hover) && | ||
| 648 | (!qAppInstance()->activePopupWidget() || qAppInstance()->activePopupWidget() == qwidget->window())) { | ||
| 649 | QHoverEvent he(QEvent::HoverEnter, QPoint(viewPoint.x, viewPoint.y), QPoint(-1, -1)); | ||
| 650 | QApplicationPrivate::instance()->notify_helper(qwidget, &he); | ||
| 651 | } | ||
| 652 | } | ||
| 653 | } | ||
| 654 | |||
| 655 | - (void)mouseExited:(NSEvent *)event | ||
| 656 | { | ||
| 657 | QEvent leaveEvent(QEvent::Leave); | ||
| 658 | NSPoint globalPoint = [[event window] convertBaseToScreen:[event locationInWindow]]; | ||
| 659 | if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) { | ||
| 660 | QApplication::sendEvent(qwidget, &leaveEvent); | ||
| 661 | |||
| 662 | // ### Think about if it is necessary to update the cursor, should only be for a few cases. | ||
| 663 | qt_mac_update_cursor_at_global_pos(flipPoint(globalPoint).toPoint()); | ||
| 664 | if (qwidget->testAttribute(Qt::WA_Hover) | ||
| 665 | && (!qAppInstance()->activePopupWidget() || qAppInstance()->activePopupWidget() == qwidget->window())) { | ||
| 666 | QHoverEvent he(QEvent::HoverLeave, QPoint(-1, -1), | ||
| 667 | qwidget->mapFromGlobal(QApplicationPrivate::instance()->hoverGlobalPos)); | ||
| 668 | QApplicationPrivate::instance()->notify_helper(qwidget, &he); | ||
| 669 | } | ||
| 670 | } | ||
| 671 | } | ||
| 672 | |||
| 673 | - (void)flagsChanged:(NSEvent *)theEvent | ||
| 674 | { | ||
| 675 | QWidget *widgetToGetKey = qwidget; | ||
| 676 | |||
| 677 | QWidget *popup = qAppInstance()->activePopupWidget(); | ||
| 678 | if (popup && popup != qwidget->window()) | ||
| 679 | widgetToGetKey = popup->focusWidget() ? popup->focusWidget() : popup; | ||
| 680 | qt_dispatchModifiersChanged(theEvent, widgetToGetKey); | ||
| 681 | [super flagsChanged:theEvent]; | ||
| 682 | } | ||
| 683 | |||
| 684 | - (void)mouseMoved:(NSEvent *)theEvent | ||
| 685 | { | ||
| 686 | // We always enable mouse tracking for all QCocoaView-s. In cases where we have | ||
| 687 | // child views, we will receive mouseMoved for both parent & the child (if | ||
| 688 | // mouse is over the child). We need to ignore the parent mouseMoved in such | ||
| 689 | // cases. | ||
| 690 | NSPoint windowPoint = [theEvent locationInWindow]; | ||
| 691 | NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; | ||
| 692 | if (candidateView && candidateView == self) { | ||
| 693 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); | ||
| 694 | } | ||
| 695 | } | ||
| 696 | |||
| 697 | - (void)mouseDown:(NSEvent *)theEvent | ||
| 698 | { | ||
| 699 | if (!qt_button_down) | ||
| 700 | qt_button_down = qwidget; | ||
| 701 | |||
| 702 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::LeftButton); | ||
| 703 | // Don't call super here. This prevents us from getting the mouseUp event, | ||
| 704 | // which we need to send even if the mouseDown event was not accepted. | ||
| 705 | // (this is standard Qt behavior.) | ||
| 706 | } | ||
| 707 | |||
| 708 | |||
| 709 | - (void)mouseUp:(NSEvent *)theEvent | ||
| 710 | { | ||
| 711 | qt_button_down = 0; | ||
| 712 | |||
| 713 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::LeftButton); | ||
| 714 | } | ||
| 715 | |||
| 716 | - (void)rightMouseDown:(NSEvent *)theEvent | ||
| 717 | { | ||
| 718 | if (!qt_button_down) | ||
| 719 | qt_button_down = qwidget; | ||
| 720 | |||
| 721 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::RightButton); | ||
| 722 | } | ||
| 723 | |||
| 724 | - (void)rightMouseUp:(NSEvent *)theEvent | ||
| 725 | { | ||
| 726 | qt_button_down = 0; | ||
| 727 | |||
| 728 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::RightButton); | ||
| 729 | } | ||
| 730 | |||
| 731 | - (void)otherMouseDown:(NSEvent *)theEvent | ||
| 732 | { | ||
| 733 | if (!qt_button_down) | ||
| 734 | qt_button_down = qwidget; | ||
| 735 | |||
| 736 | Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); | ||
| 737 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, mouseButton); | ||
| 738 | } | ||
| 739 | |||
| 740 | - (void)otherMouseUp:(NSEvent *)theEvent | ||
| 741 | { | ||
| 742 | qt_button_down = 0; | ||
| 743 | |||
| 744 | Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); | ||
| 745 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, mouseButton); | ||
| 746 | } | ||
| 747 | |||
| 748 | - (void)mouseDragged:(NSEvent *)theEvent | ||
| 749 | { | ||
| 750 | qMacDnDParams()->view = self; | ||
| 751 | qMacDnDParams()->theEvent = theEvent; | ||
| 752 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); | ||
| 753 | } | ||
| 754 | |||
| 755 | - (void)rightMouseDragged:(NSEvent *)theEvent | ||
| 756 | { | ||
| 757 | qMacDnDParams()->view = self; | ||
| 758 | qMacDnDParams()->theEvent = theEvent; | ||
| 759 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); | ||
| 760 | } | ||
| 761 | |||
| 762 | - (void)otherMouseDragged:(NSEvent *)theEvent | ||
| 763 | { | ||
| 764 | qMacDnDParams()->view = self; | ||
| 765 | qMacDnDParams()->theEvent = theEvent; | ||
| 766 | qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); | ||
| 767 | } | ||
| 768 | |||
| 769 | - (void)scrollWheel:(NSEvent *)theEvent | ||
| 770 | { | ||
| 771 | // Give the Input Manager a chance to process the wheel event. | ||
| 772 | NSInputManager *currentIManager = [NSInputManager currentInputManager]; | ||
| 773 | if (currentIManager && [currentIManager wantsToHandleMouseEvents]) { | ||
| 774 | [currentIManager handleMouseEvent:theEvent]; | ||
| 775 | } | ||
| 776 | |||
| 777 | NSPoint windowPoint = [theEvent locationInWindow]; | ||
| 778 | NSPoint globalPoint = [[theEvent window] convertBaseToScreen:windowPoint]; | ||
| 779 | NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; | ||
| 780 | QPoint qlocal = QPoint(localPoint.x, localPoint.y); | ||
| 781 | QPoint qglobal = QPoint(globalPoint.x, globalPoint.y); | ||
| 782 | Qt::MouseButton buttons = cocoaButton2QtButton([theEvent buttonNumber]); | ||
| 783 | bool wheelOK = false; | ||
| 784 | Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([theEvent modifierFlags]); | ||
| 785 | QWidget *widgetToGetMouse = qwidget; | ||
| 786 | int deltaX = 0; | ||
| 787 | int deltaY = 0; | ||
| 788 | int deltaZ = 0; | ||
| 789 | |||
| 790 | const EventRef carbonEvent = (EventRef)[theEvent eventRef]; | ||
| 791 | const UInt32 carbonEventKind = carbonEvent ? ::GetEventKind(carbonEvent) : 0; | ||
| 792 | const bool scrollEvent = carbonEventKind == kEventMouseScroll; | ||
| 793 | |||
| 794 | if (scrollEvent) { | ||
| 795 | // The mouse device containts pixel scroll wheel support (Mighty Mouse, Trackpad). | ||
| 796 | // Since deviceDelta is delivered as pixels rather than degrees, we need to | ||
| 797 | // convert from pixels to degrees in a sensible manner. | ||
| 798 | // It looks like four degrees per pixel behaves most native. | ||
| 799 | // Qt expects the unit for delta to be 1/8 of a degree: | ||
| 800 | deltaX = [theEvent deviceDeltaX]; | ||
| 801 | deltaY = [theEvent deviceDeltaY]; | ||
| 802 | deltaZ = [theEvent deviceDeltaZ]; | ||
| 803 | } else { | ||
| 804 | // carbonEventKind == kEventMouseWheelMoved | ||
| 805 | // Remove acceleration, and use either -120 or 120 as delta: | ||
| 806 | deltaX = qBound(-120, int([theEvent deltaX] * 10000), 120); | ||
| 807 | deltaY = qBound(-120, int([theEvent deltaY] * 10000), 120); | ||
| 808 | deltaZ = qBound(-120, int([theEvent deltaZ] * 10000), 120); | ||
| 809 | } | ||
| 810 | |||
| 811 | if (deltaX != 0) { | ||
| 812 | QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal); | ||
| 813 | qt_sendSpontaneousEvent(widgetToGetMouse, &qwe); | ||
| 814 | wheelOK = qwe.isAccepted(); | ||
| 815 | if (!wheelOK && QApplicationPrivate::focus_widget | ||
| 816 | && QApplicationPrivate::focus_widget != widgetToGetMouse) { | ||
| 817 | QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, | ||
| 818 | deltaX, buttons, keyMods, Qt::Horizontal); | ||
| 819 | qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); | ||
| 820 | wheelOK = qwe2.isAccepted(); | ||
| 821 | } | ||
| 822 | } | ||
| 823 | |||
| 824 | if (deltaY) { | ||
| 825 | QWheelEvent qwe(qlocal, qglobal, deltaY, buttons, keyMods, Qt::Vertical); | ||
| 826 | qt_sendSpontaneousEvent(widgetToGetMouse, &qwe); | ||
| 827 | wheelOK = qwe.isAccepted(); | ||
| 828 | if (!wheelOK && QApplicationPrivate::focus_widget | ||
| 829 | && QApplicationPrivate::focus_widget != widgetToGetMouse) { | ||
| 830 | QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, | ||
| 831 | deltaY, buttons, keyMods, Qt::Vertical); | ||
| 832 | qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); | ||
| 833 | wheelOK = qwe2.isAccepted(); | ||
| 834 | } | ||
| 835 | } | ||
| 836 | |||
| 837 | if (deltaZ) { | ||
| 838 | // Qt doesn't explicitly support wheels with a Z component. In a misguided attempt to | ||
| 839 | // try to be ahead of the pack, I'm adding this extra value. | ||
| 840 | QWheelEvent qwe(qlocal, qglobal, deltaZ, buttons, keyMods, (Qt::Orientation)3); | ||
| 841 | qt_sendSpontaneousEvent(widgetToGetMouse, &qwe); | ||
| 842 | wheelOK = qwe.isAccepted(); | ||
| 843 | if (!wheelOK && QApplicationPrivate::focus_widget | ||
| 844 | && QApplicationPrivate::focus_widget != widgetToGetMouse) { | ||
| 845 | QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, | ||
| 846 | deltaZ, buttons, keyMods, (Qt::Orientation)3); | ||
| 847 | qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); | ||
| 848 | wheelOK = qwe2.isAccepted(); | ||
| 849 | } | ||
| 850 | } | ||
| 851 | if (!wheelOK) { | ||
| 852 | return [super scrollWheel:theEvent]; | ||
| 853 | } | ||
| 854 | } | ||
| 855 | |||
| 856 | - (void)tabletProximity:(NSEvent *)tabletEvent | ||
| 857 | { | ||
| 858 | qt_dispatchTabletProximityEvent(tabletEvent); | ||
| 859 | } | ||
| 860 | |||
| 861 | - (void)tabletPoint:(NSEvent *)tabletEvent | ||
| 862 | { | ||
| 863 | if (!qt_mac_handleTabletEvent(self, tabletEvent)) | ||
| 864 | [super tabletPoint:tabletEvent]; | ||
| 865 | } | ||
| 866 | |||
| 867 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 868 | - (void)touchesBeganWithEvent:(NSEvent *)event; | ||
| 869 | { | ||
| 870 | bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); | ||
| 871 | qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); | ||
| 872 | } | ||
| 873 | |||
| 874 | - (void)touchesMovedWithEvent:(NSEvent *)event; | ||
| 875 | { | ||
| 876 | bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); | ||
| 877 | qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); | ||
| 878 | } | ||
| 879 | |||
| 880 | - (void)touchesEndedWithEvent:(NSEvent *)event; | ||
| 881 | { | ||
| 882 | bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); | ||
| 883 | qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); | ||
| 884 | } | ||
| 885 | |||
| 886 | - (void)touchesCancelledWithEvent:(NSEvent *)event; | ||
| 887 | { | ||
| 888 | bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); | ||
| 889 | qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); | ||
| 890 | } | ||
| 891 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 892 | |||
| 893 | - (void)magnifyWithEvent:(NSEvent *)event; | ||
| 894 | { | ||
| 895 | if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) | ||
| 896 | return; | ||
| 897 | |||
| 898 | QNativeGestureEvent qNGEvent; | ||
| 899 | qNGEvent.gestureType = QNativeGestureEvent::Zoom; | ||
| 900 | NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; | ||
| 901 | qNGEvent.position = flipPoint(p).toPoint(); | ||
| 902 | qNGEvent.percentage = [event magnification]; | ||
| 903 | qt_sendSpontaneousEvent(qwidget, &qNGEvent); | ||
| 904 | } | ||
| 905 | |||
| 906 | - (void)rotateWithEvent:(NSEvent *)event; | ||
| 907 | { | ||
| 908 | if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) | ||
| 909 | return; | ||
| 910 | |||
| 911 | QNativeGestureEvent qNGEvent; | ||
| 912 | qNGEvent.gestureType = QNativeGestureEvent::Rotate; | ||
| 913 | NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; | ||
| 914 | qNGEvent.position = flipPoint(p).toPoint(); | ||
| 915 | qNGEvent.percentage = -[event rotation]; | ||
| 916 | qt_sendSpontaneousEvent(qwidget, &qNGEvent); | ||
| 917 | } | ||
| 918 | |||
| 919 | - (void)swipeWithEvent:(NSEvent *)event; | ||
| 920 | { | ||
| 921 | if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) | ||
| 922 | return; | ||
| 923 | |||
| 924 | QNativeGestureEvent qNGEvent; | ||
| 925 | qNGEvent.gestureType = QNativeGestureEvent::Swipe; | ||
| 926 | NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; | ||
| 927 | qNGEvent.position = flipPoint(p).toPoint(); | ||
| 928 | if ([event deltaX] == 1) | ||
| 929 | qNGEvent.angle = 180.0f; | ||
| 930 | else if ([event deltaX] == -1) | ||
| 931 | qNGEvent.angle = 0.0f; | ||
| 932 | else if ([event deltaY] == 1) | ||
| 933 | qNGEvent.angle = 90.0f; | ||
| 934 | else if ([event deltaY] == -1) | ||
| 935 | qNGEvent.angle = 270.0f; | ||
| 936 | qt_sendSpontaneousEvent(qwidget, &qNGEvent); | ||
| 937 | } | ||
| 938 | |||
| 939 | - (void)beginGestureWithEvent:(NSEvent *)event; | ||
| 940 | { | ||
| 941 | if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) | ||
| 942 | return; | ||
| 943 | |||
| 944 | QNativeGestureEvent qNGEvent; | ||
| 945 | qNGEvent.gestureType = QNativeGestureEvent::GestureBegin; | ||
| 946 | NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; | ||
| 947 | qNGEvent.position = flipPoint(p).toPoint(); | ||
| 948 | qt_sendSpontaneousEvent(qwidget, &qNGEvent); | ||
| 949 | } | ||
| 950 | |||
| 951 | - (void)endGestureWithEvent:(NSEvent *)event; | ||
| 952 | { | ||
| 953 | if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) | ||
| 954 | return; | ||
| 955 | |||
| 956 | QNativeGestureEvent qNGEvent; | ||
| 957 | qNGEvent.gestureType = QNativeGestureEvent::GestureEnd; | ||
| 958 | NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; | ||
| 959 | qNGEvent.position = flipPoint(p).toPoint(); | ||
| 960 | qt_sendSpontaneousEvent(qwidget, &qNGEvent); | ||
| 961 | } | ||
| 962 | |||
| 963 | - (void)frameDidChange:(NSNotification *)note | ||
| 964 | { | ||
| 965 | Q_UNUSED(note); | ||
| 966 | if (qwidget->isWindow()) | ||
| 967 | return; | ||
| 968 | NSRect newFrame = [self frame]; | ||
| 969 | QRect newGeo(newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height); | ||
| 970 | bool moved = qwidget->testAttribute(Qt::WA_Moved); | ||
| 971 | bool resized = qwidget->testAttribute(Qt::WA_Resized); | ||
| 972 | qwidget->setGeometry(newGeo); | ||
| 973 | qwidget->setAttribute(Qt::WA_Moved, moved); | ||
| 974 | qwidget->setAttribute(Qt::WA_Resized, resized); | ||
| 975 | qwidgetprivate->syncCocoaMask(); | ||
| 976 | } | ||
| 977 | |||
| 978 | - (BOOL)isEnabled | ||
| 979 | { | ||
| 980 | if (!qwidget) | ||
| 981 | return [super isEnabled]; | ||
| 982 | return [super isEnabled] && qwidget->isEnabled(); | ||
| 983 | } | ||
| 984 | |||
| 985 | - (void)setEnabled:(BOOL)flag | ||
| 986 | { | ||
| 987 | QMacCocoaAutoReleasePool pool; | ||
| 988 | [super setEnabled:flag]; | ||
| 989 | if (qwidget->isEnabled() != flag) | ||
| 990 | qwidget->setEnabled(flag); | ||
| 991 | } | ||
| 992 | |||
| 993 | + (Class)cellClass | ||
| 994 | { | ||
| 995 | return [NSActionCell class]; | ||
| 996 | } | ||
| 997 | |||
| 998 | - (BOOL)acceptsFirstResponder | ||
| 999 | { | ||
| 1000 | if (qwidget->isWindow()) | ||
| 1001 | return YES; // Always do it, so that windows can accept key press events. | ||
| 1002 | return qwidget->focusPolicy() != Qt::NoFocus; | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | - (BOOL)resignFirstResponder | ||
| 1006 | { | ||
| 1007 | // Seems like the following test only triggers if this | ||
| 1008 | // view is inside a QMacNativeWidget: | ||
| 1009 | if (qwidget == QApplication::focusWidget()) | ||
| 1010 | QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason); | ||
| 1011 | return YES; | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal | ||
| 1015 | { | ||
| 1016 | Q_UNUSED(isLocal); | ||
| 1017 | return supportedActions; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | - (void)setSupportedActions:(NSDragOperation)actions | ||
| 1021 | { | ||
| 1022 | supportedActions = actions; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | - (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation | ||
| 1026 | { | ||
| 1027 | Q_UNUSED(anImage); | ||
| 1028 | Q_UNUSED(aPoint); | ||
| 1029 | qMacDnDParams()->performedAction = operation; | ||
| 1030 | if (QDragManager::self()->object | ||
| 1031 | && QDragManager::self()->dragPrivate()->executed_action != Qt::ActionMask) { | ||
| 1032 | qMacDnDParams()->performedAction = | ||
| 1033 | qt_mac_mapDropAction(QDragManager::self()->dragPrivate()->executed_action); | ||
| 1034 | } | ||
| 1035 | } | ||
| 1036 | |||
| 1037 | - (QWidget *)qt_qwidget | ||
| 1038 | { | ||
| 1039 | return qwidget; | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | - (BOOL)qt_leftButtonIsRightButton | ||
| 1043 | { | ||
| 1044 | return leftButtonIsRightButton; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | - (void)qt_setLeftButtonIsRightButton:(BOOL)isSwapped | ||
| 1048 | { | ||
| 1049 | leftButtonIsRightButton = isSwapped; | ||
| 1050 | } | ||
| 1051 | |||
| 1052 | + (DnDParams*)currentMouseEvent | ||
| 1053 | { | ||
| 1054 | return qMacDnDParams(); | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | - (void)keyDown:(NSEvent *)theEvent | ||
| 1058 | { | ||
| 1059 | sendKeyEvents = true; | ||
| 1060 | |||
| 1061 | QWidget *widgetToGetKey = qwidget; | ||
| 1062 | |||
| 1063 | QWidget *popup = qAppInstance()->activePopupWidget(); | ||
| 1064 | bool sendToPopup = false; | ||
| 1065 | if (popup && popup != qwidget->window()) { | ||
| 1066 | widgetToGetKey = popup->focusWidget() ? popup->focusWidget() : popup; | ||
| 1067 | sendToPopup = true; | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | if (widgetToGetKey->testAttribute(Qt::WA_InputMethodEnabled) | ||
| 1071 | && !(widgetToGetKey->inputMethodHints() & Qt::ImhDigitsOnly | ||
| 1072 | || widgetToGetKey->inputMethodHints() & Qt::ImhFormattedNumbersOnly | ||
| 1073 | || widgetToGetKey->inputMethodHints() & Qt::ImhHiddenText)) { | ||
| 1074 | [qt_mac_nativeview_for(widgetToGetKey) interpretKeyEvents:[NSArray arrayWithObject: theEvent]]; | ||
| 1075 | } | ||
| 1076 | if (sendKeyEvents && !composing) { | ||
| 1077 | bool keyOK = qt_dispatchKeyEvent(theEvent, widgetToGetKey); | ||
| 1078 | if (!keyOK && !sendToPopup) | ||
| 1079 | [super keyDown:theEvent]; | ||
| 1080 | } | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | |||
| 1084 | - (void)keyUp:(NSEvent *)theEvent | ||
| 1085 | { | ||
| 1086 | if (sendKeyEvents) { | ||
| 1087 | bool keyOK = qt_dispatchKeyEvent(theEvent, qwidget); | ||
| 1088 | if (!keyOK) | ||
| 1089 | [super keyUp:theEvent]; | ||
| 1090 | } | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | - (void)viewWillMoveToWindow:(NSWindow *)window | ||
| 1094 | { | ||
| 1095 | if (qwidget->windowFlags() & Qt::MSWindowsOwnDC | ||
| 1096 | && (window != [self window])) { // OpenGL Widget | ||
| 1097 | // Create a stupid ClearDrawable Event | ||
| 1098 | QEvent event(QEvent::MacGLClearDrawable); | ||
| 1099 | qApp->sendEvent(qwidget, &event); | ||
| 1100 | } | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | - (void)viewDidMoveToWindow | ||
| 1104 | { | ||
| 1105 | if (qwidget->windowFlags() & Qt::MSWindowsOwnDC && [self window]) { | ||
| 1106 | // call update paint event | ||
| 1107 | qwidgetprivate->needWindowChange = true; | ||
| 1108 | QEvent event(QEvent::MacGLWindowChange); | ||
| 1109 | qApp->sendEvent(qwidget, &event); | ||
| 1110 | } | ||
| 1111 | } | ||
| 1112 | |||
| 1113 | |||
| 1114 | // NSTextInput Protocol implementation | ||
| 1115 | |||
| 1116 | - (void) insertText:(id)aString | ||
| 1117 | { | ||
| 1118 | QString commitText; | ||
| 1119 | if ([aString length]) { | ||
| 1120 | if ([aString isKindOfClass:[NSAttributedString class]]) { | ||
| 1121 | commitText = QCFString::toQString(reinterpret_cast<CFStringRef>([aString string])); | ||
| 1122 | } else { | ||
| 1123 | commitText = QCFString::toQString(reinterpret_cast<CFStringRef>(aString)); | ||
| 1124 | }; | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | if ([aString length] && composing) { | ||
| 1128 | // Send the commit string to the widget. | ||
| 1129 | composing = false; | ||
| 1130 | sendKeyEvents = false; | ||
| 1131 | QInputMethodEvent e; | ||
| 1132 | e.setCommitString(commitText); | ||
| 1133 | qt_sendSpontaneousEvent(qwidget, &e); | ||
| 1134 | } else { | ||
| 1135 | // The key sequence "`q" on a French Keyboard will generate two calls to insertText before | ||
| 1136 | // it returns from interpretKeyEvents. The first call will turn off 'composing' and accept | ||
| 1137 | // the "`" key. The last keyDown event needs to be processed by the widget to get the | ||
| 1138 | // character "q". The string parameter is ignored for the second call. | ||
| 1139 | sendKeyEvents = true; | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | composingText->clear(); | ||
| 1143 | } | ||
| 1144 | |||
| 1145 | - (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange | ||
| 1146 | { | ||
| 1147 | // Generate the QInputMethodEvent with preedit string and the attributes | ||
| 1148 | // for rendering it. The attributes handled here are 'underline', | ||
| 1149 | // 'underline color' and 'cursor position'. | ||
| 1150 | sendKeyEvents = false; | ||
| 1151 | composing = true; | ||
| 1152 | QString qtText; | ||
| 1153 | // Cursor position is retrived from the range. | ||
| 1154 | QList<QInputMethodEvent::Attribute> attrs; | ||
| 1155 | attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, selRange.location, 1, QVariant()); | ||
| 1156 | if ([aString isKindOfClass:[NSAttributedString class]]) { | ||
| 1157 | qtText = QCFString::toQString(reinterpret_cast<CFStringRef>([aString string])); | ||
| 1158 | composingLength = qtText.length(); | ||
| 1159 | int index = 0; | ||
| 1160 | // Create attributes for individual sections of preedit text | ||
| 1161 | while (index < composingLength) { | ||
| 1162 | NSRange effectiveRange; | ||
| 1163 | NSRange range = NSMakeRange(index, composingLength-index); | ||
| 1164 | NSDictionary *attributes = [aString attributesAtIndex:index | ||
| 1165 | longestEffectiveRange:&effectiveRange | ||
| 1166 | inRange:range]; | ||
| 1167 | NSNumber *underlineStyle = [attributes objectForKey:NSUnderlineStyleAttributeName]; | ||
| 1168 | if (underlineStyle) { | ||
| 1169 | QColor clr (Qt::black); | ||
| 1170 | NSColor *color = [attributes objectForKey:NSUnderlineColorAttributeName]; | ||
| 1171 | if (color) { | ||
| 1172 | clr = colorFrom(color); | ||
| 1173 | } | ||
| 1174 | QTextCharFormat format; | ||
| 1175 | format.setFontUnderline(true); | ||
| 1176 | format.setUnderlineColor(clr); | ||
| 1177 | attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, | ||
| 1178 | effectiveRange.location, | ||
| 1179 | effectiveRange.length, | ||
| 1180 | format); | ||
| 1181 | } | ||
| 1182 | index = effectiveRange.location + effectiveRange.length; | ||
| 1183 | } | ||
| 1184 | } else { | ||
| 1185 | // No attributes specified, take only the preedit text. | ||
| 1186 | qtText = QCFString::toQString(reinterpret_cast<CFStringRef>(aString)); | ||
| 1187 | composingLength = qtText.length(); | ||
| 1188 | } | ||
| 1189 | // Make sure that we have at least one text format. | ||
| 1190 | if (attrs.size() <= 1) { | ||
| 1191 | QTextCharFormat format; | ||
| 1192 | format.setFontUnderline(true); | ||
| 1193 | attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, | ||
| 1194 | 0, composingLength, format); | ||
| 1195 | } | ||
| 1196 | *composingText = qtText; | ||
| 1197 | QInputMethodEvent e(qtText, attrs); | ||
| 1198 | qt_sendSpontaneousEvent(qwidget, &e); | ||
| 1199 | if (!composingLength) | ||
| 1200 | composing = false; | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | - (void) unmarkText | ||
| 1204 | { | ||
| 1205 | if (composing) { | ||
| 1206 | QInputMethodEvent e; | ||
| 1207 | e.setCommitString(*composingText); | ||
| 1208 | qt_sendSpontaneousEvent(qwidget, &e); | ||
| 1209 | } | ||
| 1210 | composingText->clear(); | ||
| 1211 | composing = false; | ||
| 1212 | } | ||
| 1213 | |||
| 1214 | - (BOOL) hasMarkedText | ||
| 1215 | { | ||
| 1216 | return (composing ? YES: NO); | ||
| 1217 | } | ||
| 1218 | |||
| 1219 | - (void) doCommandBySelector:(SEL)aSelector | ||
| 1220 | { | ||
| 1221 | Q_UNUSED(aSelector); | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | - (BOOL)isComposing | ||
| 1225 | { | ||
| 1226 | return composing; | ||
| 1227 | } | ||
| 1228 | |||
| 1229 | - (NSInteger) conversationIdentifier | ||
| 1230 | { | ||
| 1231 | // Return a unique identifier fot this ime conversation | ||
| 1232 | return (NSInteger)self; | ||
| 1233 | } | ||
| 1234 | |||
| 1235 | - (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange | ||
| 1236 | { | ||
| 1237 | QString selectedText(qwidget->inputMethodQuery(Qt::ImCurrentSelection).toString()); | ||
| 1238 | if (!selectedText.isEmpty()) { | ||
| 1239 | QCFString string(selectedText.mid(theRange.location, theRange.length)); | ||
| 1240 | const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string); | ||
| 1241 | return [[[NSAttributedString alloc] initWithString:tmpString] autorelease]; | ||
| 1242 | } else { | ||
| 1243 | return nil; | ||
| 1244 | } | ||
| 1245 | } | ||
| 1246 | |||
| 1247 | - (NSRange) markedRange | ||
| 1248 | { | ||
| 1249 | NSRange range; | ||
| 1250 | if (composing) { | ||
| 1251 | range.location = 0; | ||
| 1252 | range.length = composingLength; | ||
| 1253 | } else { | ||
| 1254 | range.location = NSNotFound; | ||
| 1255 | range.length = 0; | ||
| 1256 | } | ||
| 1257 | return range; | ||
| 1258 | } | ||
| 1259 | |||
| 1260 | - (NSRange) selectedRange | ||
| 1261 | { | ||
| 1262 | NSRange selRange; | ||
| 1263 | QString selectedText(qwidget->inputMethodQuery(Qt::ImCurrentSelection).toString()); | ||
| 1264 | if (!selectedText.isEmpty()) { | ||
| 1265 | // Consider only the selected text. | ||
| 1266 | selRange.location = 0; | ||
| 1267 | selRange.length = selectedText.length(); | ||
| 1268 | } else { | ||
| 1269 | // No selected text. | ||
| 1270 | selRange.location = NSNotFound; | ||
| 1271 | selRange.length = 0; | ||
| 1272 | } | ||
| 1273 | return selRange; | ||
| 1274 | |||
| 1275 | } | ||
| 1276 | |||
| 1277 | - (NSRect) firstRectForCharacterRange:(NSRange)theRange | ||
| 1278 | { | ||
| 1279 | Q_UNUSED(theRange); | ||
| 1280 | // The returned rect is always based on the internal cursor. | ||
| 1281 | QRect mr(qwidget->inputMethodQuery(Qt::ImMicroFocus).toRect()); | ||
| 1282 | QPoint mp(qwidget->mapToGlobal(QPoint(mr.bottomLeft()))); | ||
| 1283 | NSRect rect ; | ||
| 1284 | rect.origin.x = mp.x(); | ||
| 1285 | rect.origin.y = flipYCoordinate(mp.y()); | ||
| 1286 | rect.size.width = mr.width(); | ||
| 1287 | rect.size.height = mr.height(); | ||
| 1288 | return rect; | ||
| 1289 | } | ||
| 1290 | |||
| 1291 | - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint | ||
| 1292 | { | ||
| 1293 | // We dont support cursor movements using mouse while composing. | ||
| 1294 | Q_UNUSED(thePoint); | ||
| 1295 | return NSNotFound; | ||
| 1296 | } | ||
| 1297 | |||
| 1298 | - (NSArray*) validAttributesForMarkedText | ||
| 1299 | { | ||
| 1300 | if (!qwidget->testAttribute(Qt::WA_InputMethodEnabled)) | ||
| 1301 | return nil; // Not sure if that's correct, but it's saves a malloc. | ||
| 1302 | |||
| 1303 | // Support only underline color/style. | ||
| 1304 | return [NSArray arrayWithObjects:NSUnderlineColorAttributeName, | ||
| 1305 | NSUnderlineStyleAttributeName, nil]; | ||
| 1306 | } | ||
| 1307 | @end | ||
| 1308 | |||
| 1309 | QT_BEGIN_NAMESPACE | ||
| 1310 | void QMacInputContext::reset() | ||
| 1311 | { | ||
| 1312 | QWidget *w = QInputContext::focusWidget(); | ||
| 1313 | if (w) { | ||
| 1314 | NSView *view = qt_mac_nativeview_for(w); | ||
| 1315 | if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { | ||
| 1316 | QMacCocoaAutoReleasePool pool; | ||
| 1317 | QT_MANGLE_NAMESPACE(QCocoaView) *qc = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view); | ||
| 1318 | NSInputManager *currentIManager = [NSInputManager currentInputManager]; | ||
| 1319 | if (currentIManager) { | ||
| 1320 | [currentIManager markedTextAbandoned:view]; | ||
| 1321 | [qc unmarkText]; | ||
| 1322 | } | ||
| 1323 | } | ||
| 1324 | } | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | bool QMacInputContext::isComposing() const | ||
| 1328 | { | ||
| 1329 | QWidget *w = QInputContext::focusWidget(); | ||
| 1330 | if (w) { | ||
| 1331 | NSView *view = qt_mac_nativeview_for(w); | ||
| 1332 | if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { | ||
| 1333 | return [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) isComposing]; | ||
| 1334 | } | ||
| 1335 | } | ||
| 1336 | return false; | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | extern bool qt_mac_in_drag; | ||
| 1340 | void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm); | ||
| 1341 | static const int default_pm_hotx = -2; | ||
| 1342 | static const int default_pm_hoty = -16; | ||
| 1343 | static const char* default_pm[] = { | ||
| 1344 | "13 9 3 1", | ||
| 1345 | ". c None", | ||
| 1346 | " c #000000", | ||
| 1347 | "X c #FFFFFF", | ||
| 1348 | "X X X X X X X", | ||
| 1349 | " X X X X X X ", | ||
| 1350 | "X ......... X", | ||
| 1351 | " X.........X ", | ||
| 1352 | "X ......... X", | ||
| 1353 | " X.........X ", | ||
| 1354 | "X ......... X", | ||
| 1355 | " X X X X X X ", | ||
| 1356 | "X X X X X X X", | ||
| 1357 | }; | ||
| 1358 | |||
| 1359 | Qt::DropAction QDragManager::drag(QDrag *o) | ||
| 1360 | { | ||
| 1361 | if(qt_mac_in_drag) { //just make sure.. | ||
| 1362 | qWarning("Qt: Internal error: WH0A, unexpected condition reached"); | ||
| 1363 | return Qt::IgnoreAction; | ||
| 1364 | } | ||
| 1365 | if(object == o) | ||
| 1366 | return Qt::IgnoreAction; | ||
| 1367 | /* At the moment it seems clear that Mac OS X does not want to drag with a non-left button | ||
| 1368 | so we just bail early to prevent it */ | ||
| 1369 | if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary)) | ||
| 1370 | return Qt::IgnoreAction; | ||
| 1371 | |||
| 1372 | if(object) { | ||
| 1373 | dragPrivate()->source->removeEventFilter(this); | ||
| 1374 | cancel(); | ||
| 1375 | beingCancelled = false; | ||
| 1376 | } | ||
| 1377 | |||
| 1378 | object = o; | ||
| 1379 | dragPrivate()->target = 0; | ||
| 1380 | |||
| 1381 | #ifndef QT_NO_ACCESSIBILITY | ||
| 1382 | QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart); | ||
| 1383 | #endif | ||
| 1384 | |||
| 1385 | // setup the data | ||
| 1386 | QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacPasteboardMime::MIME_DND); | ||
| 1387 | dragPrivate()->data->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray()); | ||
| 1388 | dragBoard.setMimeData(dragPrivate()->data); | ||
| 1389 | |||
| 1390 | // create the image | ||
| 1391 | QPoint hotspot; | ||
| 1392 | QPixmap pix = dragPrivate()->pixmap; | ||
| 1393 | if(pix.isNull()) { | ||
| 1394 | if(dragPrivate()->data->hasText() || dragPrivate()->data->hasUrls()) { | ||
| 1395 | // get the string | ||
| 1396 | QString s = dragPrivate()->data->hasText() ? dragPrivate()->data->text() | ||
| 1397 | : dragPrivate()->data->urls().first().toString(); | ||
| 1398 | if(s.length() > 26) | ||
| 1399 | s = s.left(23) + QChar(0x2026); | ||
| 1400 | if(!s.isEmpty()) { | ||
| 1401 | // draw it | ||
| 1402 | QFont f(qApp->font()); | ||
| 1403 | f.setPointSize(12); | ||
| 1404 | QFontMetrics fm(f); | ||
| 1405 | QPixmap tmp(fm.width(s), fm.height()); | ||
| 1406 | if(!tmp.isNull()) { | ||
| 1407 | QPainter p(&tmp); | ||
| 1408 | p.fillRect(0, 0, tmp.width(), tmp.height(), Qt::color0); | ||
| 1409 | p.setPen(Qt::color1); | ||
| 1410 | p.setFont(f); | ||
| 1411 | p.drawText(0, fm.ascent(), s); | ||
| 1412 | // save it | ||
| 1413 | pix = tmp; | ||
| 1414 | hotspot = QPoint(tmp.width() / 2, tmp.height() / 2); | ||
| 1415 | } | ||
| 1416 | } | ||
| 1417 | } else { | ||
| 1418 | pix = QPixmap(default_pm); | ||
| 1419 | hotspot = QPoint(default_pm_hotx, default_pm_hoty); | ||
| 1420 | } | ||
| 1421 | } else { | ||
| 1422 | hotspot = dragPrivate()->hotspot; | ||
| 1423 | } | ||
| 1424 | // convert the image to NSImage. | ||
| 1425 | NSImage *image = (NSImage *)qt_mac_create_nsimage(pix); | ||
| 1426 | [image retain]; | ||
| 1427 | DnDParams dndParams = *[QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]; | ||
| 1428 | // save supported actions | ||
| 1429 | [dndParams.view setSupportedActions: qt_mac_mapDropActions(dragPrivate()->possible_actions)]; | ||
| 1430 | NSPoint imageLoc = {dndParams.localPoint.x - hotspot.x(), | ||
| 1431 | dndParams.localPoint.y + pix.height() - hotspot.y()}; | ||
| 1432 | NSSize mouseOffset = {0.0, 0.0}; | ||
| 1433 | NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; | ||
| 1434 | NSPoint windowPoint = [dndParams.theEvent locationInWindow]; | ||
| 1435 | dragPrivate()->executed_action = Qt::ActionMask; | ||
| 1436 | // do the drag | ||
| 1437 | [dndParams.view retain]; | ||
| 1438 | [dndParams.view dragImage:image | ||
| 1439 | at:imageLoc | ||
| 1440 | offset:mouseOffset | ||
| 1441 | event:dndParams.theEvent | ||
| 1442 | pasteboard:pboard | ||
| 1443 | source:dndParams.view | ||
| 1444 | slideBack:YES]; | ||
| 1445 | [dndParams.view release]; | ||
| 1446 | [image release]; | ||
| 1447 | dragPrivate()->executed_action = Qt::IgnoreAction; | ||
| 1448 | object = 0; | ||
| 1449 | Qt::DropAction performedAction(qt_mac_mapNSDragOperation(qMacDnDParams()->performedAction)); | ||
| 1450 | // do post drag processing, if required. | ||
| 1451 | if(performedAction != Qt::IgnoreAction) { | ||
| 1452 | // check if the receiver points us to a file location. | ||
| 1453 | // if so, we need to do the file copy/move ourselves. | ||
| 1454 | QCFType<CFURLRef> pasteLocation = 0; | ||
| 1455 | PasteboardCopyPasteLocation(dragBoard.pasteBoard(), &pasteLocation); | ||
| 1456 | if (pasteLocation) { | ||
| 1457 | QList<QUrl> urls = o->mimeData()->urls(); | ||
| 1458 | for (int i = 0; i < urls.size(); ++i) { | ||
| 1459 | QUrl fromUrl = urls.at(i); | ||
| 1460 | QString filename = QFileInfo(fromUrl.path()).fileName(); | ||
| 1461 | QUrl toUrl(QCFString::toQString(CFURLGetString(pasteLocation)) + filename); | ||
| 1462 | if (performedAction == Qt::MoveAction) | ||
| 1463 | QFile::rename(fromUrl.path(), toUrl.path()); | ||
| 1464 | else if (performedAction == Qt::CopyAction) | ||
| 1465 | QFile::copy(fromUrl.path(), toUrl.path()); | ||
| 1466 | } | ||
| 1467 | } | ||
| 1468 | } | ||
| 1469 | return performedAction; | ||
| 1470 | } | ||
| 1471 | |||
| 1472 | QT_END_NAMESPACE | ||
| 1473 | |||
| 1474 | #endif // QT_MAC_USE_COCOA |
src/gui/kernel/qcocoaview_iphone_p.h
(111 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists purely as an | ||
| 47 | // implementation detail. This header file may change from version to | ||
| 48 | // version without notice, or even be removed. | ||
| 49 | // | ||
| 50 | // We mean it. | ||
| 51 | // | ||
| 52 | |||
| 53 | #include <qevent.h> | ||
| 54 | |||
| 55 | //@class QT_MANGLE_NAMESPACE(QCocoaView); | ||
| 56 | //QT_FORWARD_DECLARE_CLASS(QWidgetPrivate); | ||
| 57 | //QT_FORWARD_DECLARE_CLASS(QWidget); | ||
| 58 | //QT_FORWARD_DECLARE_CLASS(QEvent); | ||
| 59 | //QT_FORWARD_DECLARE_CLASS(QCocoaDropData); | ||
| 60 | //QT_FORWARD_DECLARE_CLASS(QString); | ||
| 61 | //QT_FORWARD_DECLARE_CLASS(QStringList); | ||
| 62 | // | ||
| 63 | //QT_BEGIN_NAMESPACE | ||
| 64 | //struct DnDParams | ||
| 65 | //{ | ||
| 66 | // QT_MANGLE_NAMESPACE(QCocoaView) *view; | ||
| 67 | // NSEvent *theEvent; | ||
| 68 | // NSPoint localPoint; | ||
| 69 | // NSDragOperation performedAction; | ||
| 70 | // NSPoint activeDragEnterPos; | ||
| 71 | //}; | ||
| 72 | |||
| 73 | QT_END_NAMESPACE | ||
| 74 | |||
| 75 | //QT_FORWARD_DECLARE_STRUCT(DnDParams); | ||
| 76 | |||
| 77 | //Q_GUI_EXPORT | ||
| 78 | //@interface QT_MANGLE_NAMESPACE(QCocoaView) : NSControl <NSTextInput> { | ||
| 79 | // QWidget *qwidget; | ||
| 80 | // QWidgetPrivate *qwidgetprivate; | ||
| 81 | // bool leftButtonIsRightButton; | ||
| 82 | // QCocoaDropData *dropData; | ||
| 83 | // NSDragOperation supportedActions; | ||
| 84 | // bool composing; | ||
| 85 | // int composingLength; | ||
| 86 | // bool sendKeyEvents; | ||
| 87 | // QString *composingText; | ||
| 88 | // QStringList *currentCustomTypes; | ||
| 89 | // NSInteger dragEnterSequence; | ||
| 90 | //} | ||
| 91 | //- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; | ||
| 92 | //- (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; | ||
| 93 | //- (void)frameDidChange:(NSNotification *)note; | ||
| 94 | //- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender; | ||
| 95 | //- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender; | ||
| 96 | //- (void)draggingExited:(id < NSDraggingInfo >)sender; | ||
| 97 | //- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender; | ||
| 98 | //- (void)registerDragTypes; | ||
| 99 | //- (void)removeDropData; | ||
| 100 | //- (void)addDropData:(id <NSDraggingInfo>)sender; | ||
| 101 | //- (void)setSupportedActions:(NSDragOperation)actions; | ||
| 102 | //- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal; | ||
| 103 | //- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation; | ||
| 104 | //- (BOOL)isComposing; | ||
| 105 | //- (QWidget *)qt_qwidget; | ||
| 106 | //- (BOOL)qt_leftButtonIsRightButton; | ||
| 107 | //- (void)qt_setLeftButtonIsRightButton:(BOOL)isSwapped; | ||
| 108 | //+ (DnDParams*)currentMouseEvent; | ||
| 109 | |||
| 110 | //@end | ||
| 111 | //#endif |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qmacdefines_iphone.h" | ||
| 43 | #ifdef QT_MAC_USE_COCOA | ||
| 44 | #import <private/qcocoawindow_iphone_p.h> | ||
| 45 | #import <private/qcocoawindowdelegate_iphone_p.h> | ||
| 46 | #import <private/qcocoaview_iphone_p.h> | ||
| 47 | #import <private/qt_cocoa_helpers_iphone_p.h> | ||
| 48 | #import <private/qcocoawindowcustomthemeframe_iphone_p.h> | ||
| 49 | |||
| 50 | #include <QtGui/QWidget> | ||
| 51 | |||
| 52 | QT_FORWARD_DECLARE_CLASS(QWidget); | ||
| 53 | QT_BEGIN_NAMESPACE | ||
| 54 | extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm | ||
| 55 | QT_END_NAMESPACE | ||
| 56 | QT_USE_NAMESPACE | ||
| 57 | |||
| 58 | @interface NSWindow (QtCoverForHackWithCategory) | ||
| 59 | + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; | ||
| 60 | @end | ||
| 61 | |||
| 62 | @implementation NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration)) | ||
| 63 | |||
| 64 | - (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget*)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask; | ||
| 65 | { | ||
| 66 | self = [self initWithContentRect:rect styleMask:mask backing:NSBackingStoreBuffered defer:YES]; | ||
| 67 | if (self) { | ||
| 68 | [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] becomeDelegteForWindow:self widget:widget]; | ||
| 69 | [self setReleasedWhenClosed:NO]; | ||
| 70 | } | ||
| 71 | return self; | ||
| 72 | } | ||
| 73 | |||
| 74 | - (QWidget *)QT_MANGLE_NAMESPACE(qt_qwidget) | ||
| 75 | { | ||
| 76 | QWidget *widget = 0; | ||
| 77 | if ([self delegate] == [QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate]) | ||
| 78 | widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; | ||
| 79 | return widget; | ||
| 80 | } | ||
| 81 | |||
| 82 | @end | ||
| 83 | |||
| 84 | @implementation QT_MANGLE_NAMESPACE(QCocoaWindow) | ||
| 85 | |||
| 86 | - (BOOL)canBecomeKeyWindow | ||
| 87 | { | ||
| 88 | return YES; | ||
| 89 | } | ||
| 90 | |||
| 91 | /*********************************************************************** | ||
| 92 | BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel | ||
| 93 | This is a bit unfortunate, but thanks to the dynamic dispatch we | ||
| 94 | have to duplicate this code or resort to really silly forwarding methods | ||
| 95 | **************************************************************************/ | ||
| 96 | |||
| 97 | /* | ||
| 98 | The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever | ||
| 99 | get hit. We automatically say we can be first responder if we are a window. | ||
| 100 | So, the handling should get handled by the view. This is here more as a | ||
| 101 | last resort (i.e., this is code that can potentially be removed). | ||
| 102 | */ | ||
| 103 | |||
| 104 | - (void)toggleToolbarShown:(id)sender | ||
| 105 | { | ||
| 106 | macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 107 | [super toggleToolbarShown:sender]; | ||
| 108 | } | ||
| 109 | |||
| 110 | - (void)keyDown:(NSEvent *)theEvent | ||
| 111 | { | ||
| 112 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 113 | if (!keyOK) | ||
| 114 | [super keyDown:theEvent]; | ||
| 115 | } | ||
| 116 | |||
| 117 | - (void)keyUp:(NSEvent *)theEvent | ||
| 118 | { | ||
| 119 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 120 | if (!keyOK) | ||
| 121 | [super keyUp:theEvent]; | ||
| 122 | } | ||
| 123 | |||
| 124 | - (void)flagsChanged:(NSEvent *)theEvent | ||
| 125 | { | ||
| 126 | qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 127 | [super flagsChanged:theEvent]; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | - (void)tabletProximity:(NSEvent *)tabletEvent | ||
| 132 | { | ||
| 133 | qt_dispatchTabletProximityEvent(tabletEvent); | ||
| 134 | } | ||
| 135 | |||
| 136 | - (void)sendEvent:(NSEvent *)event | ||
| 137 | { | ||
| 138 | QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; | ||
| 139 | |||
| 140 | // Cocoa can hold onto the window after we've disavowed its knowledge. So, | ||
| 141 | // if we get sent an event afterwards just have it go through the super's | ||
| 142 | // version and don't do any stuff with Qt. | ||
| 143 | if (!widget) { | ||
| 144 | [super sendEvent:event]; | ||
| 145 | return; | ||
| 146 | } | ||
| 147 | |||
| 148 | [self retain]; | ||
| 149 | QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget)); | ||
| 150 | Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]); | ||
| 151 | // sometimes need to redirect mouse events to the popup. | ||
| 152 | QWidget *popup = qAppInstance()->activePopupWidget(); | ||
| 153 | if (popup && popup != widget) { | ||
| 154 | switch([event type]) | ||
| 155 | { | ||
| 156 | case NSLeftMouseDown: | ||
| 157 | qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton); | ||
| 158 | // Don't call super here. This prevents us from getting the mouseUp event, | ||
| 159 | // which we need to send even if the mouseDown event was not accepted. | ||
| 160 | // (this is standard Qt behavior.) | ||
| 161 | break; | ||
| 162 | case NSRightMouseDown: | ||
| 163 | case NSOtherMouseDown: | ||
| 164 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton)) | ||
| 165 | [super sendEvent:event]; | ||
| 166 | break; | ||
| 167 | case NSLeftMouseUp: | ||
| 168 | case NSRightMouseUp: | ||
| 169 | case NSOtherMouseUp: | ||
| 170 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton)) | ||
| 171 | [super sendEvent:event]; | ||
| 172 | break; | ||
| 173 | case NSMouseMoved: | ||
| 174 | qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton); | ||
| 175 | break; | ||
| 176 | case NSLeftMouseDragged: | ||
| 177 | case NSRightMouseDragged: | ||
| 178 | case NSOtherMouseDragged: | ||
| 179 | [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view; | ||
| 180 | [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event; | ||
| 181 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton)) | ||
| 182 | [super sendEvent:event]; | ||
| 183 | break; | ||
| 184 | default: | ||
| 185 | [super sendEvent:event]; | ||
| 186 | break; | ||
| 187 | } | ||
| 188 | } else { | ||
| 189 | [super sendEvent:event]; | ||
| 190 | } | ||
| 191 | qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton); | ||
| 192 | |||
| 193 | |||
| 194 | [self release]; | ||
| 195 | } | ||
| 196 | |||
| 197 | |||
| 198 | - (BOOL)makeFirstResponder:(NSResponder *)responder | ||
| 199 | { | ||
| 200 | // For some reason Cocoa wants to flip the first responder | ||
| 201 | // when Qt doesn't want to, sorry, but "No" :-) | ||
| 202 | if (responder == nil && qApp->focusWidget()) | ||
| 203 | return NO; | ||
| 204 | return [super makeFirstResponder:responder]; | ||
| 205 | } | ||
| 206 | |||
| 207 | /*********************************************************************** | ||
| 208 | END Copy and Paste between QCocoaWindow and QCocoaPanel | ||
| 209 | ***********************************************************************/ | ||
| 210 | |||
| 211 | + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask | ||
| 212 | { | ||
| 213 | if (styleMask & QtMacCustomizeWindow) | ||
| 214 | return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class]; | ||
| 215 | return [super frameViewClassForStyleMask:styleMask]; | ||
| 216 | } | ||
| 217 | |||
| 218 | @end | ||
| 219 | |||
| 220 | #endif |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists purely as an | ||
| 47 | // implementation detail. This header file may change from version to | ||
| 48 | // version without notice, or even be removed. | ||
| 49 | // | ||
| 50 | // We mean it. | ||
| 51 | // | ||
| 52 | |||
| 53 | #include "qmacdefines_iphone.h" | ||
| 54 | |||
| 55 | //enum { QtMacCustomizeWindow = 1 << 21 }; // This will one day be run over by | ||
| 56 | |||
| 57 | //QT_FORWARD_DECLARE_CLASS(QWidget); | ||
| 58 | // | ||
| 59 | //@interface NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration)) | ||
| 60 | //- (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget *)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask; | ||
| 61 | //- (QWidget *)QT_MANGLE_NAMESPACE(qt_qwidget); | ||
| 62 | //@end | ||
| 63 | // | ||
| 64 | //@interface QT_MANGLE_NAMESPACE(QCocoaWindow) : NSWindow { | ||
| 65 | // bool leftButtonIsRightButton; | ||
| 66 | //} | ||
| 67 | // | ||
| 68 | //+ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; | ||
| 69 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qmacdefines_iphone.h" | ||
| 43 | |||
| 44 | #import "private/qcocoawindowcustomthemeframe_iphone_p.h" | ||
| 45 | //#import "private/qcocoawindow_iphone_p.h" | ||
| 46 | //#include "private/qt_cocoa_helpers_iphone_p.h" | ||
| 47 | //#include "qwidget.h" | ||
| 48 | |||
| 49 | #warning qcocoawindowcustomthemeframe_iphone_p not finished. | ||
| 50 | |||
| 51 | //@implementation QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) | ||
| 52 | // | ||
| 53 | //- (void)_updateButtons | ||
| 54 | //{ | ||
| 55 | // [super _updateButtons]; | ||
| 56 | // NSWindow *window = [self window]; | ||
| 57 | // qt_syncCocoaTitleBarButtons(window, [window QT_MANGLE_NAMESPACE(qt_qwidget)]); | ||
| 58 | //} | ||
| 59 | // | ||
| 60 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists for the convenience | ||
| 47 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 48 | // and many other. This header file may change from version to version | ||
| 49 | // without notice, or even be removed. | ||
| 50 | // | ||
| 51 | // We mean it. | ||
| 52 | // | ||
| 53 | |||
| 54 | #include "qmacdefines_iphone.h" | ||
| 55 | #import "qnsthemeframe_iphone_p.h" | ||
| 56 | |||
| 57 | //@interface QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) : NSThemeFrame | ||
| 58 | //{ | ||
| 59 | //} | ||
| 60 | // | ||
| 61 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #import "private/qcocoawindowdelegate_iphone_p.h" | ||
| 43 | #warning qcocoawindowdelegate_iphone_p not finsihed | ||
| 44 | //#ifdef QT_MAC_USE_COCOA | ||
| 45 | //#include <private/qwidget_p.h> | ||
| 46 | //#include <private/qapplication_p.h> | ||
| 47 | //#include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 48 | //#include <qevent.h> | ||
| 49 | //#include <qlayout.h> | ||
| 50 | //#include <qcoreapplication.h> | ||
| 51 | //#include <qmenubar.h> | ||
| 52 | |||
| 53 | //QT_BEGIN_NAMESPACE | ||
| 54 | //extern QWidgetData *qt_qwidget_data(QWidget *); // qwidget.cpp | ||
| 55 | //extern void onApplicationWindowChangedActivation(QWidget *, bool); //qapplication_mac.mm | ||
| 56 | //extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp | ||
| 57 | //QT_END_NAMESPACE | ||
| 58 | // | ||
| 59 | //QT_USE_NAMESPACE | ||
| 60 | // | ||
| 61 | //static QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) *sharedCocoaWindowDelegate = nil; | ||
| 62 | // | ||
| 63 | //// This is a singleton, but unlike most Cocoa singletons, it lives in a library and could be | ||
| 64 | //// pontentially loaded and unloaded. This means we should at least attempt to do the | ||
| 65 | //// memory management correctly. | ||
| 66 | // | ||
| 67 | //static void cleanupCocoaWindowDelegate() | ||
| 68 | //{ | ||
| 69 | // [sharedCocoaWindowDelegate release]; | ||
| 70 | //} | ||
| 71 | // | ||
| 72 | //@implementation QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) | ||
| 73 | // | ||
| 74 | //- (id)init | ||
| 75 | //{ | ||
| 76 | // self = [super init]; | ||
| 77 | // if (self != nil) { | ||
| 78 | // m_windowHash = new QHash<NSWindow *, QWidget *>(); | ||
| 79 | // m_drawerHash = new QHash<NSDrawer *, QWidget *>(); | ||
| 80 | // } | ||
| 81 | // return self; | ||
| 82 | //} | ||
| 83 | // | ||
| 84 | //- (void)dealloc | ||
| 85 | //{ | ||
| 86 | // sharedCocoaWindowDelegate = nil; | ||
| 87 | // QHash<NSWindow *, QWidget *>::const_iterator windowIt = m_windowHash->constBegin(); | ||
| 88 | // while (windowIt != m_windowHash->constEnd()) { | ||
| 89 | // [windowIt.key() setDelegate:nil]; | ||
| 90 | // ++windowIt; | ||
| 91 | // } | ||
| 92 | // delete m_windowHash; | ||
| 93 | // QHash<NSDrawer *, QWidget *>::const_iterator drawerIt = m_drawerHash->constBegin(); | ||
| 94 | // while (drawerIt != m_drawerHash->constEnd()) { | ||
| 95 | // [drawerIt.key() setDelegate:nil]; | ||
| 96 | // ++drawerIt; | ||
| 97 | // } | ||
| 98 | // delete m_drawerHash; | ||
| 99 | // [super dealloc]; | ||
| 100 | //} | ||
| 101 | // | ||
| 102 | //+ (id)allocWithZone:(NSZone *)zone | ||
| 103 | //{ | ||
| 104 | // @synchronized(self) { | ||
| 105 | // if (sharedCocoaWindowDelegate == nil) { | ||
| 106 | // sharedCocoaWindowDelegate = [super allocWithZone:zone]; | ||
| 107 | // return sharedCocoaWindowDelegate; | ||
| 108 | // qAddPostRoutine(cleanupCocoaWindowDelegate); | ||
| 109 | // } | ||
| 110 | // } | ||
| 111 | // return nil; | ||
| 112 | //} | ||
| 113 | // | ||
| 114 | //+ (QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)*)sharedDelegate | ||
| 115 | //{ | ||
| 116 | // @synchronized(self) { | ||
| 117 | // if (sharedCocoaWindowDelegate == nil) | ||
| 118 | // [[self alloc] init]; | ||
| 119 | // } | ||
| 120 | // return [[sharedCocoaWindowDelegate retain] autorelease]; | ||
| 121 | //} | ||
| 122 | // | ||
| 123 | //-(void)syncSizeForWidget:(QWidget *)qwidget toSize:(const QSize &)newSize fromSize:(const QSize &)oldSize | ||
| 124 | //{ | ||
| 125 | // qt_qwidget_data(qwidget)->crect.setSize(newSize); | ||
| 126 | // // ### static contents optimization needs to go here | ||
| 127 | // const OSViewRef view = qt_mac_nativeview_for(qwidget); | ||
| 128 | // [view setFrameSize:NSMakeSize(newSize.width(), newSize.height())]; | ||
| 129 | // if (!qwidget->isVisible()) { | ||
| 130 | // qwidget->setAttribute(Qt::WA_PendingResizeEvent, true); | ||
| 131 | // } else { | ||
| 132 | // QResizeEvent qre(newSize, oldSize); | ||
| 133 | // if (qwidget->testAttribute(Qt::WA_PendingResizeEvent)) { | ||
| 134 | // qwidget->setAttribute(Qt::WA_PendingResizeEvent, false); | ||
| 135 | // QApplication::sendEvent(qwidget, &qre); | ||
| 136 | // } else { | ||
| 137 | // qt_sendSpontaneousEvent(qwidget, &qre); | ||
| 138 | // } | ||
| 139 | // } | ||
| 140 | //} | ||
| 141 | // | ||
| 142 | //- (void)dumpMaximizedStateforWidget:(QWidget*)qwidget window:(NSWindow *)window; | ||
| 143 | //{ | ||
| 144 | // if (!window) | ||
| 145 | // return; // Nothing to do. | ||
| 146 | // QWidgetData *widgetData = qt_qwidget_data(qwidget); | ||
| 147 | // if ((widgetData->window_state & Qt::WindowMaximized) && ![window isZoomed]) { | ||
| 148 | // widgetData->window_state &= ~Qt::WindowMaximized; | ||
| 149 | // QWindowStateChangeEvent e(Qt::WindowState(widgetData->window_state | Qt::WindowMaximized)); | ||
| 150 | // qt_sendSpontaneousEvent(qwidget, &e); | ||
| 151 | // } | ||
| 152 | //} | ||
| 153 | // | ||
| 154 | //- (NSSize)closestAcceptableSizeForWidget:(QWidget *)qwidget window:(NSWindow *)window | ||
| 155 | // withNewSize:(NSSize)proposedSize | ||
| 156 | //{ | ||
| 157 | // [self dumpMaximizedStateforWidget:qwidget window:window]; | ||
| 158 | // QSize newSize = QLayout::closestAcceptableSize(qwidget, | ||
| 159 | // QSize(proposedSize.width, proposedSize.height)); | ||
| 160 | // return [NSWindow frameRectForContentRect: | ||
| 161 | // NSMakeRect(0., 0., newSize.width(), newSize.height()) | ||
| 162 | // styleMask:[window styleMask]].size; | ||
| 163 | //} | ||
| 164 | // | ||
| 165 | //- (NSSize)windowWillResize:(NSWindow *)windowToResize toSize:(NSSize)proposedFrameSize | ||
| 166 | //{ | ||
| 167 | // QWidget *qwidget = m_windowHash->value(windowToResize); | ||
| 168 | // return [self closestAcceptableSizeForWidget:qwidget window:windowToResize | ||
| 169 | // withNewSize:[NSWindow contentRectForFrameRect: | ||
| 170 | // NSMakeRect(0, 0, | ||
| 171 | // proposedFrameSize.width, | ||
| 172 | // proposedFrameSize.height) | ||
| 173 | // styleMask:[windowToResize styleMask]].size]; | ||
| 174 | //} | ||
| 175 | // | ||
| 176 | //- (NSSize)drawerWillResizeContents:(NSDrawer *)sender toSize:(NSSize)contentSize | ||
| 177 | //{ | ||
| 178 | // QWidget *qwidget = m_drawerHash->value(sender); | ||
| 179 | // return [self closestAcceptableSizeForWidget:qwidget window:nil withNewSize:contentSize]; | ||
| 180 | //} | ||
| 181 | // | ||
| 182 | //-(void)windowDidMiniaturize:(NSNotification*)notification | ||
| 183 | //{ | ||
| 184 | // QWidget *qwidget = m_windowHash->value([notification object]); | ||
| 185 | // if (!qwidget->isMinimized()) { | ||
| 186 | // QWidgetData *widgetData = qt_qwidget_data(qwidget); | ||
| 187 | // widgetData->window_state = widgetData->window_state | Qt::WindowMinimized; | ||
| 188 | // QWindowStateChangeEvent e(Qt::WindowStates(widgetData->window_state & ~Qt::WindowMinimized)); | ||
| 189 | // qt_sendSpontaneousEvent(qwidget, &e); | ||
| 190 | // } | ||
| 191 | // // Send hide to match Qt on X11 and Windows | ||
| 192 | // QEvent e(QEvent::Hide); | ||
| 193 | // qt_sendSpontaneousEvent(qwidget, &e); | ||
| 194 | //} | ||
| 195 | // | ||
| 196 | //- (void)windowDidResize:(NSNotification *)notification | ||
| 197 | //{ | ||
| 198 | // NSWindow *window = [notification object]; | ||
| 199 | // QWidget *qwidget = m_windowHash->value(window); | ||
| 200 | // QWidgetData *widgetData = qt_qwidget_data(qwidget); | ||
| 201 | // if (!(qwidget->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) && [window isZoomed]) { | ||
| 202 | // widgetData->window_state = widgetData->window_state | Qt::WindowMaximized; | ||
| 203 | // QWindowStateChangeEvent e(Qt::WindowStates(widgetData->window_state | ||
| 204 | // & ~Qt::WindowMaximized)); | ||
| 205 | // qt_sendSpontaneousEvent(qwidget, &e); | ||
| 206 | // } | ||
| 207 | // NSRect rect = [[window contentView] frame]; | ||
| 208 | // const QSize newSize(rect.size.width, rect.size.height); | ||
| 209 | // const QSize &oldSize = widgetData->crect.size(); | ||
| 210 | // if (newSize != oldSize) { | ||
| 211 | // QWidgetPrivate::qt_mac_update_sizer(qwidget); | ||
| 212 | // [self syncSizeForWidget:qwidget toSize:newSize fromSize:oldSize]; | ||
| 213 | // } | ||
| 214 | //} | ||
| 215 | // | ||
| 216 | //- (void)windowDidMove:(NSNotification *)notification | ||
| 217 | //{ | ||
| 218 | // // The code underneath needs to translate the window location | ||
| 219 | // // from bottom left (which is the origin used by Cocoa) to | ||
| 220 | // // upper left (which is the origin used by Qt): | ||
| 221 | // NSWindow *window = [notification object]; | ||
| 222 | // NSRect newRect = [window frame]; | ||
| 223 | // QWidget *qwidget = m_windowHash->value(window); | ||
| 224 | // QPoint qtPoint = flipPoint(NSMakePoint(newRect.origin.x, | ||
| 225 | // newRect.origin.y + newRect.size.height)).toPoint(); | ||
| 226 | // const QRect &oldRect = qwidget->frameGeometry(); | ||
| 227 | // | ||
| 228 | // if (qtPoint.x() != oldRect.x() || qtPoint.y() != oldRect.y()) { | ||
| 229 | // QWidgetData *widgetData = qt_qwidget_data(qwidget); | ||
| 230 | // QRect oldCRect = widgetData->crect; | ||
| 231 | // QWidgetPrivate *widgetPrivate = qt_widget_private(qwidget); | ||
| 232 | // const QRect &fStrut = widgetPrivate->frameStrut(); | ||
| 233 | // widgetData->crect.moveTo(qtPoint.x() + fStrut.left(), qtPoint.y() + fStrut.top()); | ||
| 234 | // if (!qwidget->isVisible()) { | ||
| 235 | // qwidget->setAttribute(Qt::WA_PendingMoveEvent, true); | ||
| 236 | // } else { | ||
| 237 | // QMoveEvent qme(qtPoint, oldRect.topLeft()); | ||
| 238 | // qt_sendSpontaneousEvent(qwidget, &qme); | ||
| 239 | // } | ||
| 240 | // } | ||
| 241 | //} | ||
| 242 | // | ||
| 243 | //-(BOOL)windowShouldClose:(id)windowThatWantsToClose | ||
| 244 | //{ | ||
| 245 | // QWidget *qwidget = m_windowHash->value(windowThatWantsToClose); | ||
| 246 | // QScopedLoopLevelCounter counter(qt_widget_private(qwidget)->threadData); | ||
| 247 | // return qt_widget_private(qwidget)->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); | ||
| 248 | //} | ||
| 249 | // | ||
| 250 | //-(void)windowDidDeminiaturize:(NSNotification *)notification | ||
| 251 | //{ | ||
| 252 | // QWidget *qwidget = m_windowHash->value([notification object]); | ||
| 253 | // QWidgetData *widgetData = qt_qwidget_data(qwidget); | ||
| 254 | // Qt::WindowStates currState = Qt::WindowStates(widgetData->window_state); | ||
| 255 | // Qt::WindowStates newState = currState; | ||
| 256 | // if (currState & Qt::WindowMinimized) | ||
| 257 | // newState &= ~Qt::WindowMinimized; | ||
| 258 | // if (!(currState & Qt::WindowActive)) | ||
| 259 | // newState |= Qt::WindowActive; | ||
| 260 | // if (newState != currState) { | ||
| 261 | // widgetData->window_state = newState; | ||
| 262 | // QWindowStateChangeEvent e(currState); | ||
| 263 | // qt_sendSpontaneousEvent(qwidget, &e); | ||
| 264 | // } | ||
| 265 | // QShowEvent qse; | ||
| 266 | // qt_sendSpontaneousEvent(qwidget, &qse); | ||
| 267 | //} | ||
| 268 | // | ||
| 269 | //-(void)windowDidBecomeMain:(NSNotification*)notification | ||
| 270 | //{ | ||
| 271 | // QWidget *qwidget = m_windowHash->value([notification object]); | ||
| 272 | // Q_ASSERT(qwidget); | ||
| 273 | // if (qwidget->isActiveWindow()) | ||
| 274 | // return; // Widget is already active, no need to go through re-activation. | ||
| 275 | // | ||
| 276 | // onApplicationWindowChangedActivation(qwidget, true); | ||
| 277 | //} | ||
| 278 | // | ||
| 279 | //-(void)windowDidResignMain:(NSNotification*)notification | ||
| 280 | //{ | ||
| 281 | // QWidget *qwidget = m_windowHash->value([notification object]); | ||
| 282 | // Q_ASSERT(qwidget); | ||
| 283 | // onApplicationWindowChangedActivation(qwidget, false); | ||
| 284 | //} | ||
| 285 | // | ||
| 286 | //// These are the same as main, but they are probably better to keep separate since there is a | ||
| 287 | //// tiny difference between main and key windows. | ||
| 288 | //-(void)windowDidBecomeKey:(NSNotification*)notification | ||
| 289 | //{ | ||
| 290 | // QWidget *qwidget = m_windowHash->value([notification object]); | ||
| 291 | // Q_ASSERT(qwidget); | ||
| 292 | // if (qwidget->isActiveWindow()) | ||
| 293 | // return; // Widget is already active, no need to go through re-activation | ||
| 294 | // | ||
| 295 | // | ||
| 296 | // onApplicationWindowChangedActivation(qwidget, true); | ||
| 297 | //} | ||
| 298 | // | ||
| 299 | //-(void)windowDidResignKey:(NSNotification*)notification | ||
| 300 | //{ | ||
| 301 | // QWidget *qwidget = m_windowHash->value([notification object]); | ||
| 302 | // Q_ASSERT(qwidget); | ||
| 303 | // onApplicationWindowChangedActivation(qwidget, false); | ||
| 304 | //} | ||
| 305 | // | ||
| 306 | //-(QWidget *)qt_qwidgetForWindow:(NSWindow *)window | ||
| 307 | //{ | ||
| 308 | // return m_windowHash->value(window); | ||
| 309 | //} | ||
| 310 | // | ||
| 311 | //- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame | ||
| 312 | //{ | ||
| 313 | // Q_UNUSED(newFrame); | ||
| 314 | // // saving the current window geometry before the window is maximized | ||
| 315 | // QWidget *qwidget = m_windowHash->value(window); | ||
| 316 | // if (qwidget->isWindow() && !(qwidget->windowState() & Qt::WindowMaximized)) { | ||
| 317 | // QWidgetPrivate *widgetPrivate = qt_widget_private(qwidget); | ||
| 318 | // widgetPrivate->topData()->normalGeometry = qwidget->geometry(); | ||
| 319 | // } | ||
| 320 | // return YES; | ||
| 321 | //} | ||
| 322 | // | ||
| 323 | //- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame | ||
| 324 | //{ | ||
| 325 | // NSRect frameToReturn = defaultFrame; | ||
| 326 | // QWidget *qwidget = m_windowHash->value(window); | ||
| 327 | // QSizeF size = qwidget->maximumSize(); | ||
| 328 | // NSRect windowFrameRect = [window frame]; | ||
| 329 | // NSRect viewFrameRect = [[window contentView] frame]; | ||
| 330 | // // consider additional size required for titlebar & frame | ||
| 331 | // frameToReturn.size.width = qMin<CGFloat>(frameToReturn.size.width, | ||
| 332 | // size.width()+(windowFrameRect.size.width - viewFrameRect.size.width)); | ||
| 333 | // frameToReturn.size.height = qMin<CGFloat>(frameToReturn.size.height, | ||
| 334 | // size.height()+(windowFrameRect.size.height - viewFrameRect.size.height)); | ||
| 335 | // return frameToReturn; | ||
| 336 | //} | ||
| 337 | // | ||
| 338 | //- (void)becomeDelegteForWindow:(NSWindow *)window widget:(QWidget *)widget | ||
| 339 | //{ | ||
| 340 | // m_windowHash->insert(window, widget); | ||
| 341 | // [window setDelegate:self]; | ||
| 342 | //} | ||
| 343 | // | ||
| 344 | //- (void)resignDelegateForWindow:(NSWindow *)window | ||
| 345 | //{ | ||
| 346 | // [window setDelegate:nil]; | ||
| 347 | // m_windowHash->remove(window); | ||
| 348 | //} | ||
| 349 | // | ||
| 350 | //- (void)becomeDelegateForDrawer:(NSDrawer *)drawer widget:(QWidget *)widget | ||
| 351 | //{ | ||
| 352 | // m_drawerHash->insert(drawer, widget); | ||
| 353 | // [drawer setDelegate:self]; | ||
| 354 | // NSWindow *window = [[drawer contentView] window]; | ||
| 355 | // [self becomeDelegteForWindow:window widget:widget]; | ||
| 356 | //} | ||
| 357 | // | ||
| 358 | //- (void)resignDelegateForDrawer:(NSDrawer *)drawer | ||
| 359 | //{ | ||
| 360 | // QWidget *widget = m_drawerHash->value(drawer); | ||
| 361 | // [drawer setDelegate:nil]; | ||
| 362 | // if (widget) | ||
| 363 | // [self resignDelegateForWindow:[[drawer contentView] window]]; | ||
| 364 | // m_drawerHash->remove(drawer); | ||
| 365 | //} | ||
| 366 | // | ||
| 367 | //- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu | ||
| 368 | //{ | ||
| 369 | // Q_UNUSED(menu); | ||
| 370 | // QWidget *qwidget = m_windowHash->value(window); | ||
| 371 | // if (qwidget && !qwidget->windowFilePath().isEmpty()) { | ||
| 372 | // return YES; | ||
| 373 | // } | ||
| 374 | // return NO; | ||
| 375 | //} | ||
| 376 | // | ||
| 377 | //- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event | ||
| 378 | // from:(NSPoint)dragImageLocation | ||
| 379 | // withPasteboard:(NSPasteboard *)pasteboard | ||
| 380 | //{ | ||
| 381 | // Q_UNUSED(event); | ||
| 382 | // Q_UNUSED(dragImageLocation); | ||
| 383 | // Q_UNUSED(pasteboard); | ||
| 384 | // QWidget *qwidget = m_windowHash->value(window); | ||
| 385 | // if (qwidget && !qwidget->windowFilePath().isEmpty()) { | ||
| 386 | // return YES; | ||
| 387 | // } | ||
| 388 | // return NO; | ||
| 389 | //} | ||
| 390 | //@end | ||
| 391 | //#endif// QT_MAC_USE_COCOA |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists purely as an | ||
| 47 | // implementation detail. This header file may change from version to | ||
| 48 | // version without notice, or even be removed. | ||
| 49 | // | ||
| 50 | // We mean it. | ||
| 51 | // | ||
| 52 | |||
| 53 | #include "qmacdefines_iphone.h" | ||
| 54 | // | ||
| 55 | //#ifdef QT_MAC_USE_COCOA | ||
| 56 | //#import <Cocoa/Cocoa.h> | ||
| 57 | // | ||
| 58 | //QT_BEGIN_NAMESPACE | ||
| 59 | //template <class Key, class T> class QHash; | ||
| 60 | //QT_END_NAMESPACE | ||
| 61 | //using QT_PREPEND_NAMESPACE(QHash); | ||
| 62 | //QT_FORWARD_DECLARE_CLASS(QWidget) | ||
| 63 | //QT_FORWARD_DECLARE_CLASS(QSize) | ||
| 64 | //QT_FORWARD_DECLARE_CLASS(QWidgetData) | ||
| 65 | // | ||
| 66 | //#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | ||
| 67 | //@protocol NSWindowDelegate <NSObject> | ||
| 68 | //- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; | ||
| 69 | //- (void)windowDidMiniaturize:(NSNotification*)notification; | ||
| 70 | //- (void)windowDidResize:(NSNotification *)notification; | ||
| 71 | //- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame; | ||
| 72 | //- (void)windowDidMove:(NSNotification *)notification; | ||
| 73 | //- (BOOL)windowShouldClose:(id)window; | ||
| 74 | //- (void)windowDidDeminiaturize:(NSNotification *)notification; | ||
| 75 | //- (void)windowDidBecomeMain:(NSNotification*)notification; | ||
| 76 | //- (void)windowDidResignMain:(NSNotification*)notification; | ||
| 77 | //- (void)windowDidBecomeKey:(NSNotification*)notification; | ||
| 78 | //- (void)windowDidResignKey:(NSNotification*)notification; | ||
| 79 | //- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu; | ||
| 80 | //- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard; | ||
| 81 | //- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; | ||
| 82 | //@end | ||
| 83 | // | ||
| 84 | //@protocol NSDrawerDelegate <NSObject> | ||
| 85 | //- (NSSize)drawerWillResizeContents:(NSDrawer *)sender toSize:(NSSize)contentSize; | ||
| 86 | //@end | ||
| 87 | // | ||
| 88 | //#endif | ||
| 89 | // | ||
| 90 | // | ||
| 91 | // | ||
| 92 | //@interface QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) : NSObject<NSWindowDelegate, NSDrawerDelegate> { | ||
| 93 | // QHash<NSWindow *, QWidget *> *m_windowHash; | ||
| 94 | // QHash<NSDrawer *, QWidget *> *m_drawerHash; | ||
| 95 | //} | ||
| 96 | //+ (QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)*)sharedDelegate; | ||
| 97 | //- (void)becomeDelegteForWindow:(NSWindow *)window widget:(QWidget *)widget; | ||
| 98 | //- (void)resignDelegateForWindow:(NSWindow *)window; | ||
| 99 | //- (void)becomeDelegateForDrawer:(NSDrawer *)drawer widget:(QWidget *)widget; | ||
| 100 | //- (void)resignDelegateForDrawer:(NSDrawer *)drawer; | ||
| 101 | //- (void)dumpMaximizedStateforWidget:(QWidget*)qwidget window:(NSWindow *)window; | ||
| 102 | //- (void)syncSizeForWidget:(QWidget *)qwidget | ||
| 103 | // toSize:(const QSize &)newSize | ||
| 104 | // fromSize:(const QSize &)oldSize; | ||
| 105 | //- (NSSize)closestAcceptableSizeForWidget:(QWidget *)qwidget | ||
| 106 | // window:(NSWindow *)window withNewSize:(NSSize)proposedSize; | ||
| 107 | //- (QWidget *)qt_qwidgetForWindow:(NSWindow *)window; | ||
| 108 | //@end | ||
| 109 | //#endif |
src/gui/kernel/qcursor_iphone.mm
(574 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include <private/qcursor_p.h> | ||
| 43 | //#include <private/qpixmap_iphone_p.h> | ||
| 44 | #include <qapplication.h> | ||
| 45 | #include <qbitmap.h> | ||
| 46 | #include <qcursor.h> | ||
| 47 | #include <qevent.h> | ||
| 48 | #include <string.h> | ||
| 49 | #include <unistd.h> | ||
| 50 | //#include <AppKit/NSCursor.h> | ||
| 51 | #include <qpainter.h> | ||
| 52 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 53 | |||
| 54 | QT_BEGIN_NAMESPACE | ||
| 55 | #warning qcursor_iphone.mm not completed. | ||
| 56 | |||
| 57 | /***************************************************************************** | ||
| 58 | Externals | ||
| 59 | *****************************************************************************/ | ||
| 60 | //extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; | ||
| 61 | //extern OSWindowRef qt_mac_window_for(const QWidget *); //qwidget_mac.cpp | ||
| 62 | //extern GrafPtr qt_mac_qd_context(const QPaintDevice *); //qpaintdevice_mac.cpp | ||
| 63 | //extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_mac.cpp | ||
| 64 | |||
| 65 | /***************************************************************************** | ||
| 66 | Internal QCursorData class | ||
| 67 | *****************************************************************************/ | ||
| 68 | |||
| 69 | //class QMacAnimateCursor : public QObject | ||
| 70 | //{ | ||
| 71 | // int timerId, step; | ||
| 72 | // ThemeCursor curs; | ||
| 73 | //public: | ||
| 74 | // QMacAnimateCursor() : QObject(), timerId(-1) { } | ||
| 75 | // void start(ThemeCursor c) { | ||
| 76 | // step = 1; | ||
| 77 | // if(timerId != -1) | ||
| 78 | // killTimer(timerId); | ||
| 79 | // timerId = startTimer(300); | ||
| 80 | // curs = c; | ||
| 81 | // } | ||
| 82 | // void stop() { | ||
| 83 | // if(timerId != -1) { | ||
| 84 | // killTimer(timerId); | ||
| 85 | // timerId = -1; | ||
| 86 | // } | ||
| 87 | // } | ||
| 88 | //protected: | ||
| 89 | // void timerEvent(QTimerEvent *e) { | ||
| 90 | // if(e->timerId() == timerId) { | ||
| 91 | // /* | ||
| 92 | // if(SetAnimatedThemeCursor(curs, step++) == themeBadCursorIndexErr) | ||
| 93 | // stop(); | ||
| 94 | // */ | ||
| 95 | // } | ||
| 96 | // } | ||
| 97 | //}; | ||
| 98 | // | ||
| 99 | //void *qt_mac_nsCursorForQCursor(const QCursor &c) | ||
| 100 | //{ | ||
| 101 | // c.d->update(); | ||
| 102 | // return [[static_cast<NSCursor *>(c.d->curs.cp.nscursor) retain] autorelease]; | ||
| 103 | //} | ||
| 104 | // | ||
| 105 | //static QCursorData *currentCursor = 0; //current cursor | ||
| 106 | //void qt_mac_set_cursor(const QCursor *c, const QPoint &) | ||
| 107 | //{ | ||
| 108 | //#ifdef QT_MAC_USE_COCOA | ||
| 109 | // Q_UNUSED(c); | ||
| 110 | // return; | ||
| 111 | //#else | ||
| 112 | // if (!c) { | ||
| 113 | // currentCursor = 0; | ||
| 114 | // return; | ||
| 115 | // } | ||
| 116 | // c->handle(); //force the cursor to get loaded, if it's not | ||
| 117 | // | ||
| 118 | // if(1 || currentCursor != c->d) { | ||
| 119 | // if(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor | ||
| 120 | // && currentCursor->curs.tc.anim) | ||
| 121 | // currentCursor->curs.tc.anim->stop(); | ||
| 122 | // QMacCocoaAutoReleasePool pool; | ||
| 123 | // if(c->d->type == QCursorData::TYPE_ImageCursor) { | ||
| 124 | // [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set]; | ||
| 125 | // } else if(c->d->type == QCursorData::TYPE_ThemeCursor) { | ||
| 126 | //#ifdef QT_MAC_USE_COCOA | ||
| 127 | // if (c->d->curs.cp.nscursor == 0) | ||
| 128 | // [[NSCursor arrowCursor] set]; | ||
| 129 | // [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set]; | ||
| 130 | //#else | ||
| 131 | // if(SetAnimatedThemeCursor(c->d->curs.tc.curs, 0) == themeBadCursorIndexErr) { | ||
| 132 | // SetThemeCursor(c->d->curs.tc.curs); | ||
| 133 | // } else { | ||
| 134 | // if(!c->d->curs.tc.anim) | ||
| 135 | // c->d->curs.tc.anim = new QMacAnimateCursor; | ||
| 136 | // c->d->curs.tc.anim->start(c->d->curs.tc.curs); | ||
| 137 | // } | ||
| 138 | //#endif | ||
| 139 | // } | ||
| 140 | // } | ||
| 141 | // currentCursor = c->d; | ||
| 142 | //#endif | ||
| 143 | //} | ||
| 144 | // | ||
| 145 | //void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos) | ||
| 146 | //{ | ||
| 147 | //#ifdef QT_MAC_USE_COCOA | ||
| 148 | // Q_UNUSED(globalPos); | ||
| 149 | // return; | ||
| 150 | //#else | ||
| 151 | // QCursor cursor(Qt::ArrowCursor); | ||
| 152 | // if (QApplication::overrideCursor()) { | ||
| 153 | // cursor = *QApplication::overrideCursor(); | ||
| 154 | // } else { | ||
| 155 | // for(QWidget *w = QApplication::widgetAt(globalPos); w; w = w->parentWidget()) { | ||
| 156 | // if(w->testAttribute(Qt::WA_SetCursor)) { | ||
| 157 | // cursor = w->cursor(); | ||
| 158 | // break; | ||
| 159 | // } | ||
| 160 | // } | ||
| 161 | // } | ||
| 162 | // qt_mac_set_cursor(&cursor, globalPos); | ||
| 163 | //#endif | ||
| 164 | //} | ||
| 165 | // | ||
| 166 | //void qt_mac_update_cursor() | ||
| 167 | //{ | ||
| 168 | // qt_mac_update_cursor_at_global_pos(QCursor::pos()); | ||
| 169 | //} | ||
| 170 | // | ||
| 171 | //static int nextCursorId = Qt::BitmapCursor; | ||
| 172 | |||
| 173 | QCursorData::QCursorData(Qt::CursorShape s) | ||
| 174 | // : cshape(s), bm(0), bmm(0), hx(-1), hy(-1), mId(s), type(TYPE_None) | ||
| 175 | { | ||
| 176 | // ref = 1; | ||
| 177 | // memset(&curs, '\0', sizeof(curs)); | ||
| 178 | } | ||
| 179 | |||
| 180 | QCursorData::~QCursorData() | ||
| 181 | { | ||
| 182 | // if (type == TYPE_ImageCursor) { | ||
| 183 | // if (curs.cp.my_cursor) { | ||
| 184 | // QMacCocoaAutoReleasePool pool; | ||
| 185 | // [static_cast<NSCursor *>(curs.cp.nscursor) release]; | ||
| 186 | // } | ||
| 187 | // } else if(type == TYPE_ThemeCursor) { | ||
| 188 | // delete curs.tc.anim; | ||
| 189 | // } | ||
| 190 | // type = TYPE_None; | ||
| 191 | // | ||
| 192 | // delete bm; | ||
| 193 | // delete bmm; | ||
| 194 | // if(currentCursor == this) | ||
| 195 | // currentCursor = 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY) | ||
| 199 | { | ||
| 200 | // if (!QCursorData::initialized) | ||
| 201 | // QCursorData::initialize(); | ||
| 202 | // if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) { | ||
| 203 | // qWarning("Qt: QCursor: Cannot create bitmap cursor; invalid bitmap(s)"); | ||
| 204 | // QCursorData *c = qt_cursorTable[0]; | ||
| 205 | // c->ref.ref(); | ||
| 206 | // return c; | ||
| 207 | // } | ||
| 208 | // // This is silly, but this is apparently called outside the constructor, so we have | ||
| 209 | // // to be ready for that case. | ||
| 210 | // QCursorData *x = new QCursorData; | ||
| 211 | // x->ref = 1; | ||
| 212 | // x->mId = ++nextCursorId; | ||
| 213 | // x->bm = new QBitmap(bitmap); | ||
| 214 | // x->bmm = new QBitmap(mask); | ||
| 215 | // x->cshape = Qt::BitmapCursor; | ||
| 216 | // x->hx = hotX >= 0 ? hotX : bitmap.width() / 2; | ||
| 217 | // x->hy = hotY >= 0 ? hotY : bitmap.height() / 2; | ||
| 218 | // return x; | ||
| 219 | } | ||
| 220 | |||
| 221 | //Qt::HANDLE QCursor::handle() const | ||
| 222 | //{ | ||
| 223 | // if(!QCursorData::initialized) | ||
| 224 | // QCursorData::initialize(); | ||
| 225 | // if(d->type == QCursorData::TYPE_None) | ||
| 226 | // d->update(); | ||
| 227 | // return (Qt::HANDLE)d->mId; | ||
| 228 | //} | ||
| 229 | |||
| 230 | QPoint QCursor::pos() | ||
| 231 | { | ||
| 232 | // return flipPoint([NSEvent mouseLocation]).toPoint(); | ||
| 233 | return QPoint(); | ||
| 234 | } | ||
| 235 | |||
| 236 | void QCursor::setPos(int x, int y) | ||
| 237 | { | ||
| 238 | // CGWarpMouseCursorPosition(CGPointMake(x, y)); | ||
| 239 | // | ||
| 240 | // /* I'm not too keen on doing this, but this makes it a lot easier, so I just | ||
| 241 | // send the event back through the event system and let it get propagated correctly | ||
| 242 | // ideally this would not really need to be faked --Sam | ||
| 243 | // */ | ||
| 244 | // QWidget *widget = 0; | ||
| 245 | // if(QWidget *grb = QWidget::mouseGrabber()) | ||
| 246 | // widget = grb; | ||
| 247 | // else | ||
| 248 | // widget = QApplication::widgetAt(QPoint(x, y)); | ||
| 249 | // if(widget) { | ||
| 250 | // QMouseEvent me(QMouseEvent::MouseMove, widget->mapFromGlobal(QPoint(x, y)), Qt::NoButton, | ||
| 251 | // QApplication::mouseButtons(), QApplication::keyboardModifiers()); | ||
| 252 | // qt_sendSpontaneousEvent(widget, &me); | ||
| 253 | // } | ||
| 254 | } | ||
| 255 | |||
| 256 | //void QCursorData::initCursorFromBitmap() | ||
| 257 | //{ | ||
| 258 | // NSImage *nsimage; | ||
| 259 | // QImage finalCursor(bm->size(), QImage::Format_ARGB32); | ||
| 260 | // QImage bmi = bm->toImage().convertToFormat(QImage::Format_RGB32); | ||
| 261 | // QImage bmmi = bmm->toImage().convertToFormat(QImage::Format_RGB32); | ||
| 262 | // for (int row = 0; row < finalCursor.height(); ++row) { | ||
| 263 | // QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row)); | ||
| 264 | // QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row)); | ||
| 265 | // QRgb *finalData = reinterpret_cast<QRgb *>(finalCursor.scanLine(row)); | ||
| 266 | // for (int col = 0; col < finalCursor.width(); ++col) { | ||
| 267 | // if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) { | ||
| 268 | // finalData[col] = 0xffffffff; | ||
| 269 | // } else if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) { | ||
| 270 | // finalData[col] = 0x7f000000; | ||
| 271 | // } else if (bmmData[col] == 0xffffffff && bmData[col] == 0xffffffff) { | ||
| 272 | // finalData[col] = 0x00000000; | ||
| 273 | // } else { | ||
| 274 | // finalData[col] = 0xff000000; | ||
| 275 | // } | ||
| 276 | // } | ||
| 277 | // } | ||
| 278 | // type = QCursorData::TYPE_ImageCursor; | ||
| 279 | // curs.cp.my_cursor = true; | ||
| 280 | // QPixmap bmCopy = QPixmap::fromImage(finalCursor); | ||
| 281 | // NSPoint hotSpot = { hx, hy }; | ||
| 282 | // nsimage = static_cast<NSImage*>(qt_mac_create_nsimage(bmCopy)); | ||
| 283 | // curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; | ||
| 284 | // [nsimage release]; | ||
| 285 | //} | ||
| 286 | |||
| 287 | //void QCursorData::initCursorFromPixmap() | ||
| 288 | //{ | ||
| 289 | // type = QCursorData::TYPE_ImageCursor; | ||
| 290 | // curs.cp.my_cursor = true; | ||
| 291 | // NSPoint hotSpot = { hx, hy }; | ||
| 292 | // NSImage *nsimage; | ||
| 293 | // nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); | ||
| 294 | // curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; | ||
| 295 | // [nsimage release]; | ||
| 296 | //} | ||
| 297 | |||
| 298 | void QCursorData::update() | ||
| 299 | { | ||
| 300 | // if(!QCursorData::initialized) | ||
| 301 | // QCursorData::initialize(); | ||
| 302 | // if(type != QCursorData::TYPE_None) | ||
| 303 | // return; | ||
| 304 | // | ||
| 305 | // /* Note to self... *** | ||
| 306 | // * mask x data | ||
| 307 | // * 0xFF x 0x00 == fully opaque white | ||
| 308 | // * 0x00 x 0xFF == xor'd black | ||
| 309 | // * 0xFF x 0xFF == fully opaque black | ||
| 310 | // * 0x00 x 0x00 == fully transparent | ||
| 311 | // */ | ||
| 312 | // | ||
| 313 | // if (hx < 0) | ||
| 314 | // hx = 0; | ||
| 315 | // if (hy < 0) | ||
| 316 | // hy = 0; | ||
| 317 | // | ||
| 318 | //#define QT_USE_APPROXIMATE_CURSORS | ||
| 319 | //#ifdef QT_USE_APPROXIMATE_CURSORS | ||
| 320 | // static const uchar cur_ver_bits[] = { | ||
| 321 | // 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, | ||
| 322 | // 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x0f, 0xf0, | ||
| 323 | // 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00 }; | ||
| 324 | // static const uchar mcur_ver_bits[] = { | ||
| 325 | // 0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0xf8, | ||
| 326 | // 0x7f, 0xfc, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x7f, 0xfc, 0x3f, 0xf8, | ||
| 327 | // 0x1f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80 }; | ||
| 328 | // | ||
| 329 | // static const uchar cur_hor_bits[] = { | ||
| 330 | // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x18, 0x30, | ||
| 331 | // 0x38, 0x38, 0x7f, 0xfc, 0x7f, 0xfc, 0x38, 0x38, 0x18, 0x30, 0x08, 0x20, | ||
| 332 | // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
| 333 | // static const uchar mcur_hor_bits[] = { | ||
| 334 | // 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x0c, 0x60, 0x1c, 0x70, 0x3c, 0x78, | ||
| 335 | // 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x3c, 0x78, | ||
| 336 | // 0x1c, 0x70, 0x0c, 0x60, 0x04, 0x40, 0x00, 0x00 }; | ||
| 337 | // | ||
| 338 | // static const uchar cur_fdiag_bits[] = { | ||
| 339 | // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0x78, | ||
| 340 | // 0x00, 0xf8, 0x01, 0xd8, 0x23, 0x88, 0x37, 0x00, 0x3e, 0x00, 0x3c, 0x00, | ||
| 341 | // 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
| 342 | // static const uchar mcur_fdiag_bits[] = { | ||
| 343 | // 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0xfc, | ||
| 344 | // 0x41, 0xfc, 0x63, 0xfc, 0x77, 0xdc, 0x7f, 0x8c, 0x7f, 0x04, 0x7e, 0x00, | ||
| 345 | // 0x7f, 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x00, 0x00 }; | ||
| 346 | // | ||
| 347 | // static const uchar cur_bdiag_bits[] = { | ||
| 348 | // 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e, 0x00, | ||
| 349 | // 0x37, 0x00, 0x23, 0x88, 0x01, 0xd8, 0x00, 0xf8, 0x00, 0x78, 0x00, 0xf8, | ||
| 350 | // 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
| 351 | // static const uchar mcur_bdiag_bits[] = { | ||
| 352 | // 0x00, 0x00, 0x7f, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7e, 0x00, 0x7f, 0x04, | ||
| 353 | // 0x7f, 0x8c, 0x77, 0xdc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01, 0xfc, | ||
| 354 | // 0x03, 0xfc, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00 }; | ||
| 355 | // | ||
| 356 | // static const unsigned char cur_up_arrow_bits[] = { | ||
| 357 | // 0x00, 0x80, 0x01, 0x40, 0x01, 0x40, 0x02, 0x20, 0x02, 0x20, 0x04, 0x10, | ||
| 358 | // 0x04, 0x10, 0x08, 0x08, 0x0f, 0x78, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, | ||
| 359 | // 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0 }; | ||
| 360 | // static const unsigned char mcur_up_arrow_bits[] = { | ||
| 361 | // 0x00, 0x80, 0x01, 0xc0, 0x01, 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0, | ||
| 362 | // 0x07, 0xf0, 0x0f, 0xf8, 0x0f, 0xf8, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, | ||
| 363 | // 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0 }; | ||
| 364 | //#endif | ||
| 365 | // const uchar *cursorData = 0; | ||
| 366 | // const uchar *cursorMaskData = 0; | ||
| 367 | //#ifdef QT_MAC_USE_COCOA | ||
| 368 | // switch (cshape) { // map Q cursor to MAC cursor | ||
| 369 | // case Qt::BitmapCursor: { | ||
| 370 | // if (pixmap.isNull()) | ||
| 371 | // initCursorFromBitmap(); | ||
| 372 | // else | ||
| 373 | // initCursorFromPixmap(); | ||
| 374 | // break; } | ||
| 375 | // case Qt::BlankCursor: { | ||
| 376 | // pixmap = QPixmap(16, 16); | ||
| 377 | // pixmap.fill(Qt::transparent); | ||
| 378 | // initCursorFromPixmap(); | ||
| 379 | // break; } | ||
| 380 | // case Qt::ArrowCursor: { | ||
| 381 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 382 | // curs.cp.nscursor = [NSCursor arrowCursor]; | ||
| 383 | // break; } | ||
| 384 | // case Qt::CrossCursor: { | ||
| 385 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 386 | // curs.cp.nscursor = [NSCursor crosshairCursor]; | ||
| 387 | // break; } | ||
| 388 | // case Qt::WaitCursor: { | ||
| 389 | // pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/spincursor.png")); | ||
| 390 | // initCursorFromPixmap(); | ||
| 391 | // break; } | ||
| 392 | // case Qt::IBeamCursor: { | ||
| 393 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 394 | // curs.cp.nscursor = [NSCursor IBeamCursor]; | ||
| 395 | // break; } | ||
| 396 | // case Qt::SizeAllCursor: { | ||
| 397 | // pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/pluscursor.png")); | ||
| 398 | // initCursorFromPixmap(); | ||
| 399 | // break; } | ||
| 400 | // case Qt::WhatsThisCursor: { //for now just use the pointing hand | ||
| 401 | // case Qt::PointingHandCursor: | ||
| 402 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 403 | // curs.cp.nscursor = [NSCursor pointingHandCursor]; | ||
| 404 | // break; } | ||
| 405 | // case Qt::BusyCursor: { | ||
| 406 | // pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/waitcursor.png")); | ||
| 407 | // initCursorFromPixmap(); | ||
| 408 | // break; } | ||
| 409 | // case Qt::SplitVCursor: { | ||
| 410 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 411 | // curs.cp.nscursor = [NSCursor resizeUpDownCursor]; | ||
| 412 | // break; } | ||
| 413 | // case Qt::SplitHCursor: { | ||
| 414 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 415 | // curs.cp.nscursor = [NSCursor resizeLeftRightCursor]; | ||
| 416 | // break; } | ||
| 417 | // case Qt::ForbiddenCursor: { | ||
| 418 | // pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/forbiddencursor.png")); | ||
| 419 | // initCursorFromPixmap(); | ||
| 420 | // break; } | ||
| 421 | // case Qt::OpenHandCursor: | ||
| 422 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 423 | // curs.cp.nscursor = [NSCursor openHandCursor]; | ||
| 424 | // break; | ||
| 425 | // case Qt::ClosedHandCursor: | ||
| 426 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 427 | // curs.cp.nscursor = [NSCursor closedHandCursor]; | ||
| 428 | // break; | ||
| 429 | //#define QT_USE_APPROXIMATE_CURSORS | ||
| 430 | //#ifdef QT_USE_APPROXIMATE_CURSORS | ||
| 431 | // case Qt::SizeVerCursor: | ||
| 432 | // cursorData = cur_ver_bits; | ||
| 433 | // cursorMaskData = mcur_ver_bits; | ||
| 434 | // hx = hy = 8; | ||
| 435 | // break; | ||
| 436 | // case Qt::SizeHorCursor: | ||
| 437 | // cursorData = cur_hor_bits; | ||
| 438 | // cursorMaskData = mcur_hor_bits; | ||
| 439 | // hx = hy = 8; | ||
| 440 | // break; | ||
| 441 | // case Qt::SizeBDiagCursor: | ||
| 442 | // cursorData = cur_fdiag_bits; | ||
| 443 | // cursorMaskData = mcur_fdiag_bits; | ||
| 444 | // hx = hy = 8; | ||
| 445 | // break; | ||
| 446 | // case Qt::SizeFDiagCursor: | ||
| 447 | // cursorData = cur_bdiag_bits; | ||
| 448 | // cursorMaskData = mcur_bdiag_bits; | ||
| 449 | // hx = hy = 8; | ||
| 450 | // break; | ||
| 451 | // case Qt::UpArrowCursor: | ||
| 452 | // cursorData = cur_up_arrow_bits; | ||
| 453 | // cursorMaskData = mcur_up_arrow_bits; | ||
| 454 | // hx = 8; | ||
| 455 | // break; | ||
| 456 | //#endif | ||
| 457 | // default: | ||
| 458 | // qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape); | ||
| 459 | // return; | ||
| 460 | // } | ||
| 461 | //#else | ||
| 462 | // // Carbon | ||
| 463 | // switch (cshape) { // map Q cursor to MAC cursor | ||
| 464 | // case Qt::BitmapCursor: { | ||
| 465 | // if (pixmap.isNull()) | ||
| 466 | // initCursorFromBitmap(); | ||
| 467 | // else | ||
| 468 | // initCursorFromPixmap(); | ||
| 469 | // break; } | ||
| 470 | // case Qt::BlankCursor: { | ||
| 471 | // pixmap = QPixmap(16, 16); | ||
| 472 | // pixmap.fill(Qt::transparent); | ||
| 473 | // initCursorFromPixmap(); | ||
| 474 | // break; } | ||
| 475 | // case Qt::ArrowCursor: { | ||
| 476 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 477 | // curs.tc.curs = kThemeArrowCursor; | ||
| 478 | // break; } | ||
| 479 | // case Qt::CrossCursor: { | ||
| 480 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 481 | // curs.tc.curs = kThemeCrossCursor; | ||
| 482 | // break; } | ||
| 483 | // case Qt::WaitCursor: { | ||
| 484 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 485 | // curs.tc.curs = kThemeWatchCursor; | ||
| 486 | // break; } | ||
| 487 | // case Qt::IBeamCursor: { | ||
| 488 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 489 | // curs.tc.curs = kThemeIBeamCursor; | ||
| 490 | // break; } | ||
| 491 | // case Qt::SizeAllCursor: { | ||
| 492 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 493 | // curs.tc.curs = kThemePlusCursor; | ||
| 494 | // break; } | ||
| 495 | // case Qt::WhatsThisCursor: { //for now just use the pointing hand | ||
| 496 | // case Qt::PointingHandCursor: | ||
| 497 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 498 | // curs.tc.curs = kThemePointingHandCursor; | ||
| 499 | // break; } | ||
| 500 | // case Qt::BusyCursor: { | ||
| 501 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 502 | // curs.tc.curs = kThemeSpinningCursor; | ||
| 503 | // break; } | ||
| 504 | // case Qt::SplitVCursor: { | ||
| 505 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 506 | // curs.tc.curs = kThemeResizeUpDownCursor; | ||
| 507 | // break; } | ||
| 508 | // case Qt::SplitHCursor: { | ||
| 509 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 510 | // curs.tc.curs = kThemeResizeLeftRightCursor; | ||
| 511 | // break; } | ||
| 512 | // case Qt::ForbiddenCursor: { | ||
| 513 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 514 | // curs.tc.curs = kThemeNotAllowedCursor; | ||
| 515 | // break; } | ||
| 516 | // case Qt::OpenHandCursor: | ||
| 517 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 518 | // curs.tc.curs = kThemeOpenHandCursor; | ||
| 519 | // break; | ||
| 520 | // case Qt::ClosedHandCursor: | ||
| 521 | // type = QCursorData::TYPE_ThemeCursor; | ||
| 522 | // curs.tc.curs = kThemeClosedHandCursor; | ||
| 523 | // break; | ||
| 524 | //#define QT_USE_APPROXIMATE_CURSORS | ||
| 525 | //#ifdef QT_USE_APPROXIMATE_CURSORS | ||
| 526 | // case Qt::SizeVerCursor: | ||
| 527 | // cursorData = cur_ver_bits; | ||
| 528 | // cursorMaskData = mcur_ver_bits; | ||
| 529 | // hx = hy = 8; | ||
| 530 | // break; | ||
| 531 | // case Qt::SizeHorCursor: | ||
| 532 | // cursorData = cur_hor_bits; | ||
| 533 | // cursorMaskData = mcur_hor_bits; | ||
| 534 | // hx = hy = 8; | ||
| 535 | // break; | ||
| 536 | // case Qt::SizeBDiagCursor: | ||
| 537 | // cursorData = cur_fdiag_bits; | ||
| 538 | // cursorMaskData = mcur_fdiag_bits; | ||
| 539 | // hx = hy = 8; | ||
| 540 | // break; | ||
| 541 | // case Qt::SizeFDiagCursor: | ||
| 542 | // cursorData = cur_bdiag_bits; | ||
| 543 | // cursorMaskData = mcur_bdiag_bits; | ||
| 544 | // hx = hy = 8; | ||
| 545 | // break; | ||
| 546 | // case Qt::UpArrowCursor: | ||
| 547 | // cursorData = cur_up_arrow_bits; | ||
| 548 | // cursorMaskData = mcur_up_arrow_bits; | ||
| 549 | // hx = 8; | ||
| 550 | // break; | ||
| 551 | //#endif | ||
| 552 | // default: | ||
| 553 | // qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape); | ||
| 554 | // return; | ||
| 555 | // } | ||
| 556 | //#endif | ||
| 557 | // | ||
| 558 | // if (cursorData) { | ||
| 559 | // bm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorData, | ||
| 560 | // QImage::Format_Mono)); | ||
| 561 | // bmm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorMaskData, | ||
| 562 | // QImage::Format_Mono)); | ||
| 563 | // initCursorFromBitmap(); | ||
| 564 | // } | ||
| 565 | // | ||
| 566 | //#if 0 | ||
| 567 | // if(type == QCursorData::TYPE_CursPtr && curs.cp.hcurs && curs.cp.my_cursor) { | ||
| 568 | // curs.cp.hcurs->hotSpot.h = hx >= 0 ? hx : 8; | ||
| 569 | // curs.cp.hcurs->hotSpot.v = hy >= 0 ? hy : 8; | ||
| 570 | // } | ||
| 571 | //#endif | ||
| 572 | } | ||
| 573 | |||
| 574 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #include "qapplication.h" | ||
| 77 | #include "qdesktopwidget.h" | ||
| 78 | #include <private/qt_iphone_p.h> | ||
| 79 | #include "qwidget_p.h" | ||
| 80 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 81 | #include <private/qdesktopwidget_iphone_p.h> | ||
| 82 | |||
| 83 | QT_BEGIN_NAMESPACE | ||
| 84 | |||
| 85 | QT_USE_NAMESPACE | ||
| 86 | |||
| 87 | /***************************************************************************** | ||
| 88 | Externals | ||
| 89 | *****************************************************************************/ | ||
| 90 | |||
| 91 | /***************************************************************************** | ||
| 92 | QDesktopWidget member functions | ||
| 93 | *****************************************************************************/ | ||
| 94 | // | ||
| 95 | //Q_GLOBAL_STATIC(QDesktopWidgetImplementation, qdesktopWidgetImplementation) | ||
| 96 | // | ||
| 97 | //QDesktopWidgetImplementation::QDesktopWidgetImplementation() | ||
| 98 | // : appScreen(0) | ||
| 99 | //{ | ||
| 100 | // onResize(); | ||
| 101 | //} | ||
| 102 | // | ||
| 103 | //QDesktopWidgetImplementation::~QDesktopWidgetImplementation() | ||
| 104 | //{ | ||
| 105 | //} | ||
| 106 | // | ||
| 107 | //QDesktopWidgetImplementation *QDesktopWidgetImplementation::instance() | ||
| 108 | //{ | ||
| 109 | // return qdesktopWidgetImplementation(); | ||
| 110 | //} | ||
| 111 | // | ||
| 112 | //QRect QDesktopWidgetImplementation::availableRect(int screenIndex) const | ||
| 113 | //{ | ||
| 114 | // if (screenIndex < 0 || screenIndex >= screenCount) | ||
| 115 | // screenIndex = appScreen; | ||
| 116 | // | ||
| 117 | // return availableRects[screenIndex].toRect(); | ||
| 118 | //} | ||
| 119 | // | ||
| 120 | //QRect QDesktopWidgetImplementation::screenRect(int screenIndex) const | ||
| 121 | //{ | ||
| 122 | // if (screenIndex < 0 || screenIndex >= screenCount) | ||
| 123 | // screenIndex = appScreen; | ||
| 124 | // | ||
| 125 | // return screenRects[screenIndex].toRect(); | ||
| 126 | //} | ||
| 127 | // | ||
| 128 | //void QDesktopWidgetImplementation::onResize() | ||
| 129 | //{ | ||
| 130 | // QMacCocoaAutoReleasePool pool; | ||
| 131 | // NSArray *displays = [NSScreen screens]; | ||
| 132 | // screenCount = [displays count]; | ||
| 133 | // | ||
| 134 | // screenRects.clear(); | ||
| 135 | // availableRects.clear(); | ||
| 136 | // NSRect primaryRect = [[displays objectAtIndex:0] frame]; | ||
| 137 | // for (int i = 0; i<screenCount; i++) { | ||
| 138 | // NSRect r = [[displays objectAtIndex:i] frame]; | ||
| 139 | // int flippedY = - r.origin.y + // account for position offset and | ||
| 140 | // primaryRect.size.height - r.size.height; // height difference. | ||
| 141 | // screenRects.append(QRectF(r.origin.x, flippedY, | ||
| 142 | // r.size.width, r.size.height)); | ||
| 143 | // | ||
| 144 | // r = [[displays objectAtIndex:i] visibleFrame]; | ||
| 145 | // flippedY = - r.origin.y + // account for position offset and | ||
| 146 | // primaryRect.size.height - r.size.height; // height difference. | ||
| 147 | // availableRects.append(QRectF(r.origin.x, flippedY, | ||
| 148 | // r.size.width, r.size.height)); | ||
| 149 | // } | ||
| 150 | //} | ||
| 151 | |||
| 152 | |||
| 153 | |||
| 154 | QDesktopWidget::QDesktopWidget() | ||
| 155 | : QWidget(0, Qt::Desktop) | ||
| 156 | { | ||
| 157 | // setObjectName(QLatin1String("desktop")); | ||
| 158 | // setAttribute(Qt::WA_WState_Visible); | ||
| 159 | } | ||
| 160 | |||
| 161 | QDesktopWidget::~QDesktopWidget() | ||
| 162 | { | ||
| 163 | } | ||
| 164 | |||
| 165 | bool QDesktopWidget::isVirtualDesktop() const | ||
| 166 | { | ||
| 167 | return true; | ||
| 168 | } | ||
| 169 | |||
| 170 | int QDesktopWidget::primaryScreen() const | ||
| 171 | { | ||
| 172 | return 0; | ||
| 173 | // return qdesktopWidgetImplementation()->appScreen; | ||
| 174 | } | ||
| 175 | |||
| 176 | int QDesktopWidget::numScreens() const | ||
| 177 | { | ||
| 178 | // return qdesktopWidgetImplementation()->screenCount; | ||
| 179 | return 1; | ||
| 180 | } | ||
| 181 | |||
| 182 | QWidget *QDesktopWidget::screen(int) | ||
| 183 | { | ||
| 184 | return this; | ||
| 185 | } | ||
| 186 | |||
| 187 | const QRect QDesktopWidget::availableGeometry(int screen) const | ||
| 188 | { | ||
| 189 | #warning availableGeometry(<#int screen#>) | ||
| 190 | // return qdesktopWidgetImplementation()->availableRect(screen); | ||
| 191 | return QRect(); | ||
| 192 | } | ||
| 193 | |||
| 194 | const QRect QDesktopWidget::screenGeometry(int screen) const | ||
| 195 | { | ||
| 196 | #warning screenGeometry() | ||
| 197 | // return qdesktopWidgetImplementation()->screenRect(screen); | ||
| 198 | return QRect(); | ||
| 199 | } | ||
| 200 | |||
| 201 | int QDesktopWidget::screenNumber(const QWidget *widget) const | ||
| 202 | { | ||
| 203 | // QDesktopWidgetImplementation *d = qdesktopWidgetImplementation(); | ||
| 204 | // if (!widget) | ||
| 205 | // return d->appScreen; | ||
| 206 | // QRect frame = widget->frameGeometry(); | ||
| 207 | // if (!widget->isWindow()) | ||
| 208 | // frame.moveTopLeft(widget->mapToGlobal(QPoint(0,0))); | ||
| 209 | // int maxSize = -1, maxScreen = -1; | ||
| 210 | // for (int i = 0; i < d->screenCount; ++i) { | ||
| 211 | // QRect rr = d->screenRect(i); | ||
| 212 | // QRect sect = rr.intersected(frame); | ||
| 213 | // int size = sect.width() * sect.height(); | ||
| 214 | // if (size > maxSize && sect.width() > 0 && sect.height() > 0) { | ||
| 215 | // maxSize = size; | ||
| 216 | // maxScreen = i; | ||
| 217 | // } | ||
| 218 | // } | ||
| 219 | // return maxScreen; | ||
| 220 | return 1; | ||
| 221 | } | ||
| 222 | |||
| 223 | int QDesktopWidget::screenNumber(const QPoint &point) const | ||
| 224 | { | ||
| 225 | // QDesktopWidgetImplementation *d = qdesktopWidgetImplementation(); | ||
| 226 | // int closestScreen = -1; | ||
| 227 | // int shortestDistance = INT_MAX; | ||
| 228 | // for (int i = 0; i < d->screenCount; ++i) { | ||
| 229 | // QRect rr = d->screenRect(i); | ||
| 230 | // int thisDistance = QWidgetPrivate::pointToRect(point, rr); | ||
| 231 | // if (thisDistance < shortestDistance) { | ||
| 232 | // shortestDistance = thisDistance; | ||
| 233 | // closestScreen = i; | ||
| 234 | // } | ||
| 235 | // } | ||
| 236 | // return closestScreen; | ||
| 237 | return 1; | ||
| 238 | } | ||
| 239 | |||
| 240 | void QDesktopWidget::resizeEvent(QResizeEvent *) | ||
| 241 | { | ||
| 242 | // QDesktopWidgetImplementation *d = qdesktopWidgetImplementation(); | ||
| 243 | // | ||
| 244 | // const int oldScreenCount = d->screenCount; | ||
| 245 | // const QVector<QRectF> oldRects(d->screenRects); | ||
| 246 | // const QVector<QRectF> oldWorks(d->availableRects); | ||
| 247 | // | ||
| 248 | // d->onResize(); | ||
| 249 | // | ||
| 250 | // for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) { | ||
| 251 | // if (oldRects.at(i) != d->screenRects.at(i)) | ||
| 252 | // emit resized(i); | ||
| 253 | // } | ||
| 254 | // for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) { | ||
| 255 | // if (oldWorks.at(i) != d->availableRects.at(i)) | ||
| 256 | // emit workAreaResized(i); | ||
| 257 | // } | ||
| 258 | // | ||
| 259 | // if (oldScreenCount != d->screenCount) | ||
| 260 | // emit screenCountChanged(d->screenCount); | ||
| 261 | } | ||
| 262 | |||
| 263 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists purely as an | ||
| 47 | // implementation detail. This header file may change from version to | ||
| 48 | // version without notice, or even be removed. | ||
| 49 | // | ||
| 50 | // We mean it. | ||
| 51 | // | ||
| 52 | |||
| 53 | #include <qrect.h> | ||
| 54 | |||
| 55 | QT_BEGIN_NAMESPACE | ||
| 56 | |||
| 57 | class QDesktopWidgetImplementation | ||
| 58 | { | ||
| 59 | public: | ||
| 60 | QDesktopWidgetImplementation(); | ||
| 61 | ~QDesktopWidgetImplementation(); | ||
| 62 | static QDesktopWidgetImplementation *instance(); | ||
| 63 | |||
| 64 | int appScreen; | ||
| 65 | int screenCount; | ||
| 66 | |||
| 67 | QVector<QRectF> availableRects; | ||
| 68 | QVector<QRectF> screenRects; | ||
| 69 | |||
| 70 | QRect availableRect(int screenIndex) const; | ||
| 71 | QRect screenRect(int screenIndex) const; | ||
| 72 | void onResize(); | ||
| 73 | }; | ||
| 74 | |||
| 75 | QT_END_NAMESPACE |
src/gui/kernel/qdnd_iphone.mm
(720 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qapplication.h" | ||
| 43 | #ifndef QT_NO_DRAGANDDROP | ||
| 44 | #include "qbitmap.h" | ||
| 45 | #include "qcursor.h" | ||
| 46 | #include "qevent.h" | ||
| 47 | #include "qpainter.h" | ||
| 48 | #include "qurl.h" | ||
| 49 | #include "qwidget.h" | ||
| 50 | #include "qfile.h" | ||
| 51 | #include "qfileinfo.h" | ||
| 52 | #include <stdlib.h> | ||
| 53 | #include <string.h> | ||
| 54 | #ifndef QT_NO_ACCESSIBILITY | ||
| 55 | # include "qaccessible.h" | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #include <private/qapplication_p.h> | ||
| 59 | #include <private/qwidget_p.h> | ||
| 60 | #include <private/qdnd_p.h> | ||
| 61 | #include <private/qt_iphone_p.h> | ||
| 62 | |||
| 63 | QT_BEGIN_NAMESPACE | ||
| 64 | |||
| 65 | QT_USE_NAMESPACE | ||
| 66 | |||
| 67 | //QMacDndAnswerRecord qt_mac_dnd_answer_rec; | ||
| 68 | // | ||
| 69 | ///***************************************************************************** | ||
| 70 | // QDnD debug facilities | ||
| 71 | // *****************************************************************************/ | ||
| 72 | ////#define DEBUG_DRAG_EVENTS | ||
| 73 | ////#define DEBUG_DRAG_PROMISES | ||
| 74 | // | ||
| 75 | ///***************************************************************************** | ||
| 76 | // QDnD globals | ||
| 77 | // *****************************************************************************/ | ||
| 78 | //bool qt_mac_in_drag = false; | ||
| 79 | //#ifndef QT_MAC_USE_COCOA | ||
| 80 | //static DragReference qt_mac_current_dragRef = 0; | ||
| 81 | //#endif | ||
| 82 | // | ||
| 83 | ///***************************************************************************** | ||
| 84 | // Externals | ||
| 85 | // *****************************************************************************/ | ||
| 86 | //extern void qt_mac_send_modifiers_changed(quint32, QObject *); //qapplication_mac.cpp | ||
| 87 | //extern uint qGlobalPostedEventsCount(); //qapplication.cpp | ||
| 88 | //extern RgnHandle qt_mac_get_rgn(); // qregion_mac.cpp | ||
| 89 | //extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp | ||
| 90 | ///***************************************************************************** | ||
| 91 | // QDnD utility functions | ||
| 92 | // *****************************************************************************/ | ||
| 93 | // | ||
| 94 | ////default pixmap | ||
| 95 | //static const int default_pm_hotx = -2; | ||
| 96 | //static const int default_pm_hoty = -16; | ||
| 97 | //#ifndef QT_MAC_USE_COCOA | ||
| 98 | //static const char * const default_pm[] = { | ||
| 99 | // "13 9 3 1", | ||
| 100 | // ". c None", | ||
| 101 | // " c #000000", | ||
| 102 | // "X c #FFFFFF", | ||
| 103 | // "X X X X X X X", | ||
| 104 | // " X X X X X X ", | ||
| 105 | // "X ......... X", | ||
| 106 | // " X.........X ", | ||
| 107 | // "X ......... X", | ||
| 108 | // " X.........X ", | ||
| 109 | // "X ......... X", | ||
| 110 | // " X X X X X X ", | ||
| 111 | // "X X X X X X X", | ||
| 112 | //}; | ||
| 113 | //#endif | ||
| 114 | // | ||
| 115 | ////action management | ||
| 116 | //#ifdef DEBUG_DRAG_EVENTS | ||
| 117 | //# define MAP_MAC_ENUM(x) x, #x | ||
| 118 | //#else | ||
| 119 | //# define MAP_MAC_ENUM(x) x | ||
| 120 | //#endif | ||
| 121 | //struct mac_enum_mapper | ||
| 122 | //{ | ||
| 123 | // int mac_code; | ||
| 124 | // int qt_code; | ||
| 125 | //#ifdef DEBUG_DRAG_EVENTS | ||
| 126 | // char *qt_desc; | ||
| 127 | //#endif | ||
| 128 | //}; | ||
| 129 | //#ifndef QT_MAC_USE_COCOA | ||
| 130 | //static mac_enum_mapper dnd_action_symbols[] = { | ||
| 131 | // { kDragActionAlias, MAP_MAC_ENUM(Qt::LinkAction) }, | ||
| 132 | // { kDragActionMove, MAP_MAC_ENUM(Qt::MoveAction) }, | ||
| 133 | // { kDragActionGeneric, MAP_MAC_ENUM(Qt::CopyAction) }, | ||
| 134 | // { kDragActionCopy, MAP_MAC_ENUM(Qt::CopyAction) }, | ||
| 135 | // { 0, MAP_MAC_ENUM(0) } | ||
| 136 | //}; | ||
| 137 | //static DragActions qt_mac_dnd_map_qt_actions(Qt::DropActions qActions) | ||
| 138 | //{ | ||
| 139 | // DragActions ret = kDragActionNothing; | ||
| 140 | // for(int i = 0; dnd_action_symbols[i].qt_code; ++i) { | ||
| 141 | // if(qActions & dnd_action_symbols[i].qt_code) | ||
| 142 | // ret |= dnd_action_symbols[i].mac_code; | ||
| 143 | // } | ||
| 144 | // return ret; | ||
| 145 | //} | ||
| 146 | //static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions) | ||
| 147 | //{ | ||
| 148 | //#ifdef DEBUG_DRAG_EVENTS | ||
| 149 | // qDebug("Converting DND ActionList: 0x%lx", macActions); | ||
| 150 | //#endif | ||
| 151 | // Qt::DropActions ret = Qt::IgnoreAction; | ||
| 152 | // for(int i = 0; dnd_action_symbols[i].qt_code; ++i) { | ||
| 153 | //#ifdef DEBUG_DRAG_EVENTS | ||
| 154 | // qDebug(" %d) [%s] : %s", i, dnd_action_symbols[i].qt_desc, | ||
| 155 | // (macActions & dnd_action_symbols[i].mac_code) ? "true" : "false"); | ||
| 156 | //#endif | ||
| 157 | // if(macActions & dnd_action_symbols[i].mac_code) | ||
| 158 | // ret |= Qt::DropAction(dnd_action_symbols[i].qt_code); | ||
| 159 | // } | ||
| 160 | // return ret; | ||
| 161 | //} | ||
| 162 | //static Qt::DropAction qt_mac_dnd_map_mac_default_action(DragActions macActions) | ||
| 163 | //{ | ||
| 164 | // static Qt::DropAction preferred_actions[] = { Qt::CopyAction, Qt::LinkAction, //in order | ||
| 165 | // Qt::MoveAction, Qt::IgnoreAction }; | ||
| 166 | // Qt::DropAction ret = Qt::IgnoreAction; | ||
| 167 | // const Qt::DropActions qtActions = qt_mac_dnd_map_mac_actions(macActions); | ||
| 168 | // for(int i = 0; preferred_actions[i] != Qt::IgnoreAction; ++i) { | ||
| 169 | // if(qtActions & preferred_actions[i]) { | ||
| 170 | // ret = preferred_actions[i]; | ||
| 171 | // break; | ||
| 172 | // } | ||
| 173 | // } | ||
| 174 | //#ifdef DEBUG_DRAG_EVENTS | ||
| 175 | // for(int i = 0; dnd_action_symbols[i].qt_code; ++i) { | ||
| 176 | // if(dnd_action_symbols[i].qt_code == ret) { | ||
| 177 | // qDebug("Got default action: %s [0x%lx]", dnd_action_symbols[i].qt_desc, macActions); | ||
| 178 | // break; | ||
| 179 | // } | ||
| 180 | // } | ||
| 181 | //#endif | ||
| 182 | // return ret; | ||
| 183 | //} | ||
| 184 | //static void qt_mac_dnd_update_action(DragReference dragRef) { | ||
| 185 | // SInt16 modifiers; | ||
| 186 | // GetDragModifiers(dragRef, &modifiers, 0, 0); | ||
| 187 | // qt_mac_send_modifiers_changed(modifiers, qApp); | ||
| 188 | // | ||
| 189 | // Qt::DropAction qtAction = Qt::IgnoreAction; | ||
| 190 | // { | ||
| 191 | // DragActions macAllowed = kDragActionNothing; | ||
| 192 | // GetDragDropAction(dragRef, &macAllowed); | ||
| 193 | // Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(macAllowed); | ||
| 194 | // qtAction = QDragManager::self()->defaultAction(qtAllowed, QApplication::keyboardModifiers()); | ||
| 195 | //#if 1 | ||
| 196 | // if(!(qtAllowed & qtAction)) | ||
| 197 | // qtAction = qt_mac_dnd_map_mac_default_action(macAllowed); | ||
| 198 | //#endif | ||
| 199 | // } | ||
| 200 | // DragActions macAction = qt_mac_dnd_map_qt_actions(qtAction); | ||
| 201 | // | ||
| 202 | // DragActions currentActions; | ||
| 203 | // GetDragDropAction(dragRef, ¤tActions); | ||
| 204 | // if(currentActions != macAction) { | ||
| 205 | // SetDragDropAction(dragRef, macAction); | ||
| 206 | // QDragManager::self()->emitActionChanged(qtAction); | ||
| 207 | // } | ||
| 208 | //} | ||
| 209 | //#endif // !QT_MAC_USE_COCOA | ||
| 210 | |||
| 211 | /***************************************************************************** | ||
| 212 | DnD functions | ||
| 213 | *****************************************************************************/ | ||
| 214 | bool QDropData::hasFormat_sys(const QString &mime) const | ||
| 215 | { | ||
| 216 | Q_UNUSED(mime); | ||
| 217 | return false; | ||
| 218 | } | ||
| 219 | |||
| 220 | QVariant QDropData::retrieveData_sys(const QString &mime, QVariant::Type type) const | ||
| 221 | { | ||
| 222 | Q_UNUSED(mime); | ||
| 223 | Q_UNUSED(type); | ||
| 224 | return QVariant(); | ||
| 225 | } | ||
| 226 | |||
| 227 | QStringList QDropData::formats_sys() const | ||
| 228 | { | ||
| 229 | return QStringList(); | ||
| 230 | } | ||
| 231 | |||
| 232 | void QDragManager::timerEvent(QTimerEvent*) | ||
| 233 | { | ||
| 234 | } | ||
| 235 | |||
| 236 | bool QDragManager::eventFilter(QObject *, QEvent *) | ||
| 237 | { | ||
| 238 | return false; | ||
| 239 | } | ||
| 240 | |||
| 241 | void QDragManager::updateCursor() | ||
| 242 | { | ||
| 243 | } | ||
| 244 | |||
| 245 | void QDragManager::cancel(bool) | ||
| 246 | { | ||
| 247 | // if(object) { | ||
| 248 | // beingCancelled = true; | ||
| 249 | // object = 0; | ||
| 250 | // } | ||
| 251 | //#ifndef QT_NO_ACCESSIBILITY | ||
| 252 | // QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd); | ||
| 253 | //#endif | ||
| 254 | } | ||
| 255 | |||
| 256 | void QDragManager::move(const QPoint &) | ||
| 257 | { | ||
| 258 | } | ||
| 259 | |||
| 260 | void QDragManager::drop() | ||
| 261 | { | ||
| 262 | } | ||
| 263 | |||
| 264 | /** | ||
| 265 | If a drop action is already set on the carbon event | ||
| 266 | (from e.g. an earlier enter event), we insert the same | ||
| 267 | action on the new Qt event that has yet to be sendt. | ||
| 268 | */ | ||
| 269 | //static inline bool qt_mac_set_existing_drop_action(const DragRef &dragRef, QDropEvent &event) | ||
| 270 | //{ | ||
| 271 | //#ifndef QT_MAC_USE_COCOA | ||
| 272 | // DragActions currentAction = kDragActionNothing; | ||
| 273 | // OSStatus err = GetDragDropAction(dragRef, ¤tAction); | ||
| 274 | // if (err == noErr && currentAction != kDragActionNothing) { | ||
| 275 | // // This looks a bit evil, but we only ever set one action, so it's OK. | ||
| 276 | // event.setDropAction(Qt::DropAction(int(qt_mac_dnd_map_mac_actions(currentAction)))); | ||
| 277 | // return true; | ||
| 278 | // } | ||
| 279 | //#else | ||
| 280 | // Q_UNUSED(dragRef); | ||
| 281 | // Q_UNUSED(event); | ||
| 282 | //#endif | ||
| 283 | // return false; | ||
| 284 | //} | ||
| 285 | // | ||
| 286 | ///** | ||
| 287 | // If an answer rect has been set on the event (after being sent | ||
| 288 | // to the global event processor), we store that rect so we can | ||
| 289 | // check if the mouse is in the same area upon next drag move event. | ||
| 290 | //*/ | ||
| 291 | //void qt_mac_copy_answer_rect(const QDragMoveEvent &event) | ||
| 292 | //{ | ||
| 293 | // if (!event.answerRect().isEmpty()) { | ||
| 294 | // qt_mac_dnd_answer_rec.rect = event.answerRect(); | ||
| 295 | // qt_mac_dnd_answer_rec.buttons = event.mouseButtons(); | ||
| 296 | // qt_mac_dnd_answer_rec.modifiers = event.keyboardModifiers(); | ||
| 297 | // qt_mac_dnd_answer_rec.lastAction = event.dropAction(); | ||
| 298 | // } | ||
| 299 | //} | ||
| 300 | // | ||
| 301 | //bool qt_mac_mouse_inside_answer_rect(QPoint mouse) | ||
| 302 | //{ | ||
| 303 | // if (!qt_mac_dnd_answer_rec.rect.isEmpty() | ||
| 304 | // && qt_mac_dnd_answer_rec.rect.contains(mouse) | ||
| 305 | // && QApplication::mouseButtons() == qt_mac_dnd_answer_rec.buttons | ||
| 306 | // && QApplication::keyboardModifiers() == qt_mac_dnd_answer_rec.modifiers) | ||
| 307 | // return true; | ||
| 308 | // else | ||
| 309 | // return false; | ||
| 310 | //} | ||
| 311 | // | ||
| 312 | //bool QWidgetPrivate::qt_mac_dnd_event(uint kind, DragRef dragRef) | ||
| 313 | //{ | ||
| 314 | //#ifndef QT_MAC_USE_COCOA | ||
| 315 | // Q_Q(QWidget); | ||
| 316 | // qt_mac_current_dragRef = dragRef; | ||
| 317 | // if (kind != kEventControlDragLeave) | ||
| 318 | // qt_mac_dnd_update_action(dragRef); | ||
| 319 | // | ||
| 320 | // Point mouse; | ||
| 321 | // GetDragMouse(dragRef, &mouse, 0L); | ||
| 322 | // if(!mouse.h && !mouse.v) | ||
| 323 | // GetGlobalMouse(&mouse); | ||
| 324 | // | ||
| 325 | // if(QApplicationPrivate::modalState()) { | ||
| 326 | // for(QWidget *modal = q; modal; modal = modal->parentWidget()) { | ||
| 327 | // if(modal->isWindow()) { | ||
| 328 | // if(modal != QApplication::activeModalWidget()) | ||
| 329 | // return noErr; | ||
| 330 | // break; | ||
| 331 | // } | ||
| 332 | // } | ||
| 333 | // } | ||
| 334 | // | ||
| 335 | // //lookup the possible actions | ||
| 336 | // DragActions allowed = kDragActionNothing; | ||
| 337 | // GetDragAllowableActions(dragRef, &allowed); | ||
| 338 | // Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(allowed); | ||
| 339 | // | ||
| 340 | // //lookup the source dragAccepted | ||
| 341 | // QMimeData *dropdata = QDragManager::self()->dropData; | ||
| 342 | // if(QDragManager::self()->source()) | ||
| 343 | // dropdata = QDragManager::self()->dragPrivate()->data; | ||
| 344 | // | ||
| 345 | // // 'interrestedInDrag' should end up being 'true' if a later drop | ||
| 346 | // // will be accepted by the widget for the current mouse position | ||
| 347 | // bool interrestedInDrag = true; | ||
| 348 | // | ||
| 349 | // //Dispatch events | ||
| 350 | // if (kind == kEventControlDragWithin) { | ||
| 351 | // if (qt_mac_mouse_inside_answer_rect(q->mapFromGlobal(QPoint(mouse.h, mouse.v)))) | ||
| 352 | // return qt_mac_dnd_answer_rec.lastAction == Qt::IgnoreAction; | ||
| 353 | // else | ||
| 354 | // qt_mac_dnd_answer_rec.clear(); | ||
| 355 | // | ||
| 356 | // QDragMoveEvent qDMEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata, | ||
| 357 | // QApplication::mouseButtons(), QApplication::keyboardModifiers()); | ||
| 358 | // | ||
| 359 | // // Accept the event by default if a | ||
| 360 | // // drag action exists on the carbon event | ||
| 361 | // if (qt_mac_set_existing_drop_action(dragRef, qDMEvent)) | ||
| 362 | // qDMEvent.accept(); | ||
| 363 | // | ||
| 364 | // QApplication::sendEvent(q, &qDMEvent); | ||
| 365 | // if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) | ||
| 366 | // interrestedInDrag = false; | ||
| 367 | // | ||
| 368 | // qt_mac_copy_answer_rect(qDMEvent); | ||
| 369 | // SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDMEvent.dropAction())); | ||
| 370 | // | ||
| 371 | // } else if (kind == kEventControlDragEnter) { | ||
| 372 | // qt_mac_dnd_answer_rec.clear(); | ||
| 373 | // | ||
| 374 | // QDragEnterEvent qDEEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata, | ||
| 375 | // QApplication::mouseButtons(), QApplication::keyboardModifiers()); | ||
| 376 | // qt_mac_set_existing_drop_action(dragRef, qDEEvent); | ||
| 377 | // QApplication::sendEvent(q, &qDEEvent); | ||
| 378 | // SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDEEvent.dropAction())); | ||
| 379 | // | ||
| 380 | // if (!qDEEvent.isAccepted()) | ||
| 381 | // // The widget is simply not interested in this | ||
| 382 | // // drag. So tell carbon this by returning 'false'. We will then | ||
| 383 | // // not receive any further move, drop or leave events for this widget. | ||
| 384 | // return false; | ||
| 385 | // else { | ||
| 386 | // // Documentation states that a drag move event is sent immediately after | ||
| 387 | // // a drag enter event. So we do that. This will honor widgets overriding | ||
| 388 | // // 'dragMoveEvent' only, and not 'dragEnterEvent' | ||
| 389 | // QDragMoveEvent qDMEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata, | ||
| 390 | // QApplication::mouseButtons(), QApplication::keyboardModifiers()); | ||
| 391 | // qDMEvent.accept(); // accept by default, since enter event was accepted. | ||
| 392 | // qDMEvent.setDropAction(qDEEvent.dropAction()); | ||
| 393 | // QApplication::sendEvent(q, &qDMEvent); | ||
| 394 | // if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) | ||
| 395 | // interrestedInDrag = false; | ||
| 396 | // | ||
| 397 | // qt_mac_copy_answer_rect(qDMEvent); | ||
| 398 | // SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDMEvent.dropAction())); | ||
| 399 | // } | ||
| 400 | // | ||
| 401 | // } else if(kind == kEventControlDragLeave) { | ||
| 402 | // QDragLeaveEvent de; | ||
| 403 | // QApplication::sendEvent(q, &de); | ||
| 404 | // } else if(kind == kEventControlDragReceive) { | ||
| 405 | // QDropEvent de(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata, | ||
| 406 | // QApplication::mouseButtons(), QApplication::keyboardModifiers()); | ||
| 407 | // if(QDragManager::self()->object) | ||
| 408 | // QDragManager::self()->dragPrivate()->target = q; | ||
| 409 | // QApplication::sendEvent(q, &de); | ||
| 410 | // if(!de.isAccepted()) { | ||
| 411 | // interrestedInDrag = false; | ||
| 412 | // SetDragDropAction(dragRef, kDragActionNothing); | ||
| 413 | // } else { | ||
| 414 | // if(QDragManager::self()->object) | ||
| 415 | // QDragManager::self()->dragPrivate()->executed_action = de.dropAction(); | ||
| 416 | // SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(de.dropAction())); | ||
| 417 | // } | ||
| 418 | // } | ||
| 419 | // | ||
| 420 | //#ifdef DEBUG_DRAG_EVENTS | ||
| 421 | // { | ||
| 422 | // const char *desc = 0; | ||
| 423 | // switch(kind) { | ||
| 424 | // case kEventControlDragWithin: desc = "DragMove"; break; | ||
| 425 | // case kEventControlDragEnter: desc = "DragEnter"; break; | ||
| 426 | // case kEventControlDragLeave: desc = "DragLeave"; break; | ||
| 427 | // case kEventControlDragReceive: desc = "DragDrop"; break; | ||
| 428 | // } | ||
| 429 | // if(desc) { | ||
| 430 | // QPoint pos(q->mapFromGlobal(QPoint(mouse.h, mouse.v))); | ||
| 431 | // qDebug("Sending <%s>(%d, %d) event to %p(%s::%s) [%d] (%p)", | ||
| 432 | // desc, pos.x(), pos.y(), q, q->metaObject()->className(), | ||
| 433 | // q->objectName().toLocal8Bit().constData(), ret, dragRef); | ||
| 434 | // } | ||
| 435 | // } | ||
| 436 | //#endif | ||
| 437 | // | ||
| 438 | // //set the cursor | ||
| 439 | // bool found_cursor = false; | ||
| 440 | // if(kind == kEventControlDragWithin || kind == kEventControlDragEnter) { | ||
| 441 | // ThemeCursor cursor = kThemeNotAllowedCursor; | ||
| 442 | // found_cursor = true; | ||
| 443 | // if (interrestedInDrag) { | ||
| 444 | // DragActions action = kDragActionNothing; | ||
| 445 | // GetDragDropAction(dragRef, &action); | ||
| 446 | // switch(qt_mac_dnd_map_mac_default_action(action)) { | ||
| 447 | // case Qt::IgnoreAction: | ||
| 448 | // cursor = kThemeNotAllowedCursor; | ||
| 449 | // break; | ||
| 450 | // case Qt::MoveAction: | ||
| 451 | // cursor = kThemeArrowCursor; | ||
| 452 | // break; | ||
| 453 | // case Qt::CopyAction: | ||
| 454 | // cursor = kThemeCopyArrowCursor; | ||
| 455 | // break; | ||
| 456 | // case Qt::LinkAction: | ||
| 457 | // cursor = kThemeAliasArrowCursor; | ||
| 458 | // break; | ||
| 459 | // default: | ||
| 460 | // cursor = kThemeNotAllowedCursor; | ||
| 461 | // break; | ||
| 462 | // } | ||
| 463 | // } | ||
| 464 | // SetThemeCursor(cursor); | ||
| 465 | // } | ||
| 466 | // if(found_cursor) { | ||
| 467 | // qt_mac_set_cursor(0, QPoint()); //just use our's | ||
| 468 | // } else { | ||
| 469 | // QCursor cursor(Qt::ArrowCursor); | ||
| 470 | // if(qApp && qApp->overrideCursor()) { | ||
| 471 | // cursor = *qApp->overrideCursor(); | ||
| 472 | // } else if(q) { | ||
| 473 | // for(QWidget *p = q; p; p = p->parentWidget()) { | ||
| 474 | // if(p->isEnabled() && p->testAttribute(Qt::WA_SetCursor)) { | ||
| 475 | // cursor = p->cursor(); | ||
| 476 | // break; | ||
| 477 | // } | ||
| 478 | // } | ||
| 479 | // } | ||
| 480 | // qt_mac_set_cursor(&cursor, QPoint(mouse.h, mouse.v)); | ||
| 481 | // } | ||
| 482 | // | ||
| 483 | // //idle things | ||
| 484 | // if(qGlobalPostedEventsCount()) { | ||
| 485 | // QApplication::sendPostedEvents(); | ||
| 486 | // QApplication::flush(); | ||
| 487 | // } | ||
| 488 | // | ||
| 489 | // // If this was not a drop, tell carbon that we will be interresed in receiving more | ||
| 490 | // // events for the current drag. We do that by returning true. | ||
| 491 | // if (kind == kEventControlDragReceive) | ||
| 492 | // return interrestedInDrag; | ||
| 493 | // else | ||
| 494 | // return true; | ||
| 495 | //#else | ||
| 496 | // Q_UNUSED(kind); | ||
| 497 | // Q_UNUSED(dragRef); | ||
| 498 | // return false; | ||
| 499 | //#endif // !QT_MAC_USE_COCOA | ||
| 500 | //} | ||
| 501 | |||
| 502 | Qt::DropAction QDragManager::drag(QDrag *o) | ||
| 503 | { | ||
| 504 | // | ||
| 505 | // if(qt_mac_in_drag) { //just make sure.. | ||
| 506 | // qWarning("Qt: Internal error: WH0A, unexpected condition reached"); | ||
| 507 | // return Qt::IgnoreAction; | ||
| 508 | // } | ||
| 509 | // if(object == o) | ||
| 510 | // return Qt::IgnoreAction; | ||
| 511 | // /* At the moment it seems clear that Mac OS X does not want to drag with a non-left button | ||
| 512 | // so we just bail early to prevent it */ | ||
| 513 | // if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary)) | ||
| 514 | // return Qt::IgnoreAction; | ||
| 515 | // | ||
| 516 | // if(object) { | ||
| 517 | // dragPrivate()->source->removeEventFilter(this); | ||
| 518 | // cancel(); | ||
| 519 | // beingCancelled = false; | ||
| 520 | // } | ||
| 521 | // | ||
| 522 | // object = o; | ||
| 523 | // dragPrivate()->target = 0; | ||
| 524 | // | ||
| 525 | //#ifndef QT_NO_ACCESSIBILITY | ||
| 526 | // QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart); | ||
| 527 | //#endif | ||
| 528 | // | ||
| 529 | // //setup the data | ||
| 530 | // QMacPasteboard dragBoard(QMacPasteboardMime::MIME_DND); | ||
| 531 | // dragBoard.setMimeData(dragPrivate()->data); | ||
| 532 | // | ||
| 533 | // //create the drag | ||
| 534 | // OSErr result; | ||
| 535 | // DragRef dragRef; | ||
| 536 | // if((result = NewDragWithPasteboard(dragBoard.pasteBoard(), &dragRef))) | ||
| 537 | // return Qt::IgnoreAction; | ||
| 538 | // //setup the actions | ||
| 539 | // DragActions possibleActions = qt_mac_dnd_map_qt_actions(dragPrivate()->possible_actions); | ||
| 540 | // SetDragAllowableActions(dragRef, //local | ||
| 541 | // possibleActions, | ||
| 542 | // true); | ||
| 543 | // SetDragAllowableActions(dragRef, //remote (same as local) | ||
| 544 | // possibleActions, | ||
| 545 | // false); | ||
| 546 | // | ||
| 547 | // | ||
| 548 | // QPoint hotspot; | ||
| 549 | // QPixmap pix = dragPrivate()->pixmap; | ||
| 550 | // if(pix.isNull()) { | ||
| 551 | // if(dragPrivate()->data->hasText() || dragPrivate()->data->hasUrls()) { | ||
| 552 | // //get the string | ||
| 553 | // QString s = dragPrivate()->data->hasText() ? dragPrivate()->data->text() | ||
| 554 | // : dragPrivate()->data->urls().first().toString(); | ||
| 555 | // if(s.length() > 26) | ||
| 556 | // s = s.left(23) + QChar(0x2026); | ||
| 557 | // if(!s.isEmpty()) { | ||
| 558 | // //draw it | ||
| 559 | // QFont f(qApp->font()); | ||
| 560 | // f.setPointSize(12); | ||
| 561 | // QFontMetrics fm(f); | ||
| 562 | // const int width = fm.width(s); | ||
| 563 | // const int height = fm.height(); | ||
| 564 | // if(width > 0 && height > 0) { | ||
| 565 | // QPixmap tmp(width, height); | ||
| 566 | // QPainter p(&tmp); | ||
| 567 | // p.fillRect(0, 0, tmp.width(), tmp.height(), Qt::color0); | ||
| 568 | // p.setPen(Qt::color1); | ||
| 569 | // p.setFont(f); | ||
| 570 | // p.drawText(0, fm.ascent(), s); | ||
| 571 | // p.end(); | ||
| 572 | // //save it | ||
| 573 | // pix = tmp; | ||
| 574 | // hotspot = QPoint(tmp.width() / 2, tmp.height() / 2); | ||
| 575 | // } | ||
| 576 | // } | ||
| 577 | // } else { | ||
| 578 | // pix = QPixmap(default_pm); | ||
| 579 | // hotspot = QPoint(default_pm_hotx, default_pm_hoty); | ||
| 580 | // } | ||
| 581 | // } else { | ||
| 582 | // hotspot = dragPrivate()->hotspot; | ||
| 583 | // } | ||
| 584 | // | ||
| 585 | // //so we must fake an event | ||
| 586 | // EventRecord fakeEvent; | ||
| 587 | // GetGlobalMouse(&(fakeEvent.where)); | ||
| 588 | // fakeEvent.message = 0; | ||
| 589 | // fakeEvent.what = mouseDown; | ||
| 590 | // fakeEvent.when = EventTimeToTicks(GetCurrentEventTime()); | ||
| 591 | // fakeEvent.modifiers = GetCurrentKeyModifiers(); | ||
| 592 | // if(GetCurrentEventButtonState() & 2) | ||
| 593 | // fakeEvent.modifiers |= controlKey; | ||
| 594 | // | ||
| 595 | // //find the hotspot in relation to the pixmap | ||
| 596 | // Point boundsPoint; | ||
| 597 | // boundsPoint.h = fakeEvent.where.h - hotspot.x(); | ||
| 598 | // boundsPoint.v = fakeEvent.where.v - hotspot.y(); | ||
| 599 | // Rect boundsRect; | ||
| 600 | // SetRect(&boundsRect, boundsPoint.h, boundsPoint.v, boundsPoint.h + pix.width(), boundsPoint.v + pix.height()); | ||
| 601 | // | ||
| 602 | // //set the drag image | ||
| 603 | // QRegion dragRegion(boundsPoint.h, boundsPoint.v, pix.width(), pix.height()), pixRegion; | ||
| 604 | // if(!pix.isNull()) { | ||
| 605 | // HIPoint hipoint = { -hotspot.x(), -hotspot.y() }; | ||
| 606 | // CGImageRef img = (CGImageRef)pix.macCGHandle(); | ||
| 607 | // SetDragImageWithCGImage(dragRef, img, &hipoint, 0); | ||
| 608 | // CGImageRelease(img); | ||
| 609 | // } | ||
| 610 | // | ||
| 611 | // SetDragItemBounds(dragRef, (ItemReference)1 , &boundsRect); | ||
| 612 | // { //do the drag | ||
| 613 | // qt_mac_in_drag = true; | ||
| 614 | // qt_mac_dnd_update_action(dragRef); | ||
| 615 | // result = TrackDrag(dragRef, &fakeEvent, QMacSmartQuickDrawRegion(dragRegion.toQDRgn())); | ||
| 616 | // qt_mac_in_drag = false; | ||
| 617 | // } | ||
| 618 | // object = 0; | ||
| 619 | // if(result == noErr) { | ||
| 620 | // // Check if the receiver points us to | ||
| 621 | // // a file location. If so, we need to do | ||
| 622 | // // the file copy/move ourselves: | ||
| 623 | // QCFType<CFURLRef> pasteLocation = 0; | ||
| 624 | // PasteboardCopyPasteLocation(dragBoard.pasteBoard(), &pasteLocation); | ||
| 625 | // if (pasteLocation){ | ||
| 626 | // Qt::DropAction action = o->d_func()->defaultDropAction; | ||
| 627 | // if (action == Qt::IgnoreAction){ | ||
| 628 | // if (o->d_func()->possible_actions & Qt::MoveAction) | ||
| 629 | // action = Qt::MoveAction; | ||
| 630 | // else if (o->d_func()->possible_actions & Qt::CopyAction) | ||
| 631 | // action = Qt::CopyAction; | ||
| 632 | // | ||
| 633 | // } | ||
| 634 | // bool atleastOne = false; | ||
| 635 | // QList<QUrl> urls = o->mimeData()->urls(); | ||
| 636 | // for (int i = 0; i < urls.size(); ++i){ | ||
| 637 | // QUrl fromUrl = urls.at(i); | ||
| 638 | // QString filename = QFileInfo(fromUrl.path()).fileName(); | ||
| 639 | // QUrl toUrl(QCFString::toQString(CFURLGetString(pasteLocation)) + filename); | ||
| 640 | // if (action == Qt::MoveAction){ | ||
| 641 | // if (QFile::rename(fromUrl.path(), toUrl.path())) | ||
| 642 | // atleastOne = true; | ||
| 643 | // } else if (action == Qt::CopyAction){ | ||
| 644 | // if (QFile::copy(fromUrl.path(), toUrl.path())) | ||
| 645 | // atleastOne = true; | ||
| 646 | // } | ||
| 647 | // } | ||
| 648 | // if (atleastOne){ | ||
| 649 | // DisposeDrag(dragRef); | ||
| 650 | // return action; | ||
| 651 | // } | ||
| 652 | // } | ||
| 653 | // | ||
| 654 | // DragActions ret = kDragActionNothing; | ||
| 655 | // GetDragDropAction(dragRef, &ret); | ||
| 656 | // DisposeDrag(dragRef); //cleanup | ||
| 657 | // return qt_mac_dnd_map_mac_default_action(ret); | ||
| 658 | // } | ||
| 659 | // DisposeDrag(dragRef); //cleanup | ||
| 660 | return Qt::IgnoreAction; | ||
| 661 | } | ||
| 662 | |||
| 663 | void QDragManager::updatePixmap() | ||
| 664 | { | ||
| 665 | } | ||
| 666 | |||
| 667 | //QCocoaDropData::QCocoaDropData(CFStringRef pasteboard) | ||
| 668 | // : QInternalMimeData() | ||
| 669 | //{ | ||
| 670 | // NSString* pasteboardName = (NSString*)pasteboard; | ||
| 671 | // [pasteboardName retain]; | ||
| 672 | // dropPasteboard = pasteboard; | ||
| 673 | //} | ||
| 674 | // | ||
| 675 | //QCocoaDropData::~QCocoaDropData() | ||
| 676 | //{ | ||
| 677 | // NSString* pasteboardName = (NSString*)dropPasteboard; | ||
| 678 | // [pasteboardName release]; | ||
| 679 | //} | ||
| 680 | // | ||
| 681 | //QStringList QCocoaDropData::formats_sys() const | ||
| 682 | //{ | ||
| 683 | // QStringList formats; | ||
| 684 | // OSPasteboardRef board; | ||
| 685 | // if (PasteboardCreate(dropPasteboard, &board) != noErr) { | ||
| 686 | // qDebug("DnD: Cannot get PasteBoard!"); | ||
| 687 | // return formats; | ||
| 688 | // } | ||
| 689 | // formats = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).formats(); | ||
| 690 | // return formats; | ||
| 691 | //} | ||
| 692 | // | ||
| 693 | //QVariant QCocoaDropData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const | ||
| 694 | //{ | ||
| 695 | // QVariant data; | ||
| 696 | // OSPasteboardRef board; | ||
| 697 | // if (PasteboardCreate(dropPasteboard, &board) != noErr) { | ||
| 698 | // qDebug("DnD: Cannot get PasteBoard!"); | ||
| 699 | // return data; | ||
| 700 | // } | ||
| 701 | // data = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).retrieveData(mimeType, type); | ||
| 702 | // CFRelease(board); | ||
| 703 | // return data; | ||
| 704 | //} | ||
| 705 | // | ||
| 706 | //bool QCocoaDropData::hasFormat_sys(const QString &mimeType) const | ||
| 707 | //{ | ||
| 708 | // bool has = false; | ||
| 709 | // OSPasteboardRef board; | ||
| 710 | // if (PasteboardCreate(dropPasteboard, &board) != noErr) { | ||
| 711 | // qDebug("DnD: Cannot get PasteBoard!"); | ||
| 712 | // return has; | ||
| 713 | // } | ||
| 714 | // has = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mimeType); | ||
| 715 | // CFRelease(board); | ||
| 716 | // return has; | ||
| 717 | //} | ||
| 718 | |||
| 719 | #endif // QT_NO_DRAGANDDROP | ||
| 720 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #include "qplatformdefs.h" | ||
| 77 | #include "private/qt_iphone_p.h" | ||
| 78 | #include "qeventdispatcher_iphone_p.h" | ||
| 79 | #include "qapplication.h" | ||
| 80 | #include "qevent.h" | ||
| 81 | #include "qdialog.h" | ||
| 82 | #include "qhash.h" | ||
| 83 | #include "qsocketnotifier.h" | ||
| 84 | #include "private/qwidget_p.h" | ||
| 85 | #include "private/qthread_p.h" | ||
| 86 | #include "private/qapplication_p.h" | ||
| 87 | |||
| 88 | #include <private/qcocoaapplication_iphone_p.h> | ||
| 89 | #include "private/qt_cocoa_helpers_iphone_p.h" | ||
| 90 | |||
| 91 | #include <UiKit/UiKit.h> | ||
| 92 | |||
| 93 | #ifndef QT_NO_THREAD | ||
| 94 | # include "qmutex.h" | ||
| 95 | |||
| 96 | #include "qdebug.h" | ||
| 97 | |||
| 98 | QT_BEGIN_NAMESPACE | ||
| 99 | |||
| 100 | QT_USE_NAMESPACE | ||
| 101 | #endif | ||
| 102 | |||
| 103 | /***************************************************************************** | ||
| 104 | Externals | ||
| 105 | *****************************************************************************/ | ||
| 106 | extern void qt_event_request_timer(IPhoneTimerInfo *); //qapplication_IPhone.cpp | ||
| 107 | //extern IPhoneTimerInfo *qt_event_get_timer(EventRef); //qapplication_IPhone.cpp | ||
| 108 | extern void qt_event_request_select(QEventDispatcherIPhone *); //qapplication_IPhone.cpp | ||
| 109 | extern void qt_event_request_updates(); //qapplication_IPhone.cpp | ||
| 110 | //extern OSWindowRef qt_IPhone_window_for(const QWidget *); //qwidget_IPhone.cpp | ||
| 111 | extern bool qt_is_gui_used; //qapplication.cpp | ||
| 112 | extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp | ||
| 113 | extern bool qt_IPhone_is_IPhonesheet(const QWidget *); //qwidget_IPhone.cpp | ||
| 114 | |||
| 115 | static IPhoneTimerHash iPhoneTimerHash; | ||
| 116 | |||
| 117 | static inline CFRunLoopRef mainRunLoop() | ||
| 118 | { | ||
| 119 | return [[NSRunLoop mainRunLoop] getCFRunLoop]; | ||
| 120 | } | ||
| 121 | |||
| 122 | /***************************************************************************** | ||
| 123 | Timers stuff | ||
| 124 | *****************************************************************************/ | ||
| 125 | |||
| 126 | /* timer call back */ | ||
| 127 | void QEventDispatcherIPhonePrivate::activateTimer(CFRunLoopTimerRef, void *info) | ||
| 128 | { | ||
| 129 | int timerID = | ||
| 130 | int(info); | ||
| 131 | |||
| 132 | IPhoneTimerInfo *tmr; | ||
| 133 | tmr = iPhoneTimerHash.value(timerID); | ||
| 134 | if (tmr == 0 || tmr->pending == true) | ||
| 135 | return; // Can't send another timer event if it's pending. | ||
| 136 | |||
| 137 | |||
| 138 | // if (blockSendPostedEvents) { | ||
| 139 | // QCoreApplication::postEvent(tmr->obj, new QTimerEvent(tmr->id)); | ||
| 140 | // } else { | ||
| 141 | tmr->pending = true; | ||
| 142 | QTimerEvent e(tmr->id); | ||
| 143 | qt_sendSpontaneousEvent(tmr->obj, &e); | ||
| 144 | // Get the value again in case the timer gets unregistered during the sendEvent. | ||
| 145 | tmr = iPhoneTimerHash.value(timerID); | ||
| 146 | if (tmr != 0) | ||
| 147 | tmr->pending = false; | ||
| 148 | // } | ||
| 149 | // | ||
| 150 | } | ||
| 151 | |||
| 152 | void QEventDispatcherIPhone::registerTimer(int timerId, int interval, QObject *obj) | ||
| 153 | { | ||
| 154 | #ifndef QT_NO_DEBUG | ||
| 155 | if (timerId < 1 || interval < 0 || !obj) { | ||
| 156 | qWarning("QEventDispatcherIPhone::registerTimer: invalid arguments"); | ||
| 157 | return; | ||
| 158 | } else if (obj->thread() != thread() || thread() != QThread::currentThread()) { | ||
| 159 | qWarning("QObject::startTimer: timers cannot be started from another thread"); | ||
| 160 | return; | ||
| 161 | } | ||
| 162 | #endif | ||
| 163 | |||
| 164 | IPhoneTimerInfo *t = new IPhoneTimerInfo(); | ||
| 165 | t->id = timerId; | ||
| 166 | t->interval = interval; | ||
| 167 | t->obj = obj; | ||
| 168 | t->runLoopTimer = 0; | ||
| 169 | t->pending = false; | ||
| 170 | |||
| 171 | CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent(); | ||
| 172 | CFTimeInterval cfinterval = qMax(CFTimeInterval(interval) / 1000, 0.0000001); | ||
| 173 | fireDate += cfinterval; | ||
| 174 | iPhoneTimerHash.insert(timerId, t); | ||
| 175 | CFRunLoopTimerContext info = { 0, (void *)timerId, 0, 0, 0 }; | ||
| 176 | t->runLoopTimer = CFRunLoopTimerCreate(0, fireDate, cfinterval, 0, 0, | ||
| 177 | QEventDispatcherIPhonePrivate::activateTimer, &info); | ||
| 178 | if (t->runLoopTimer == 0) { | ||
| 179 | qFatal("QEventDispatcherIPhone::registerTimer: Cannot create timer"); | ||
| 180 | } | ||
| 181 | CFRunLoopAddTimer(mainRunLoop(), t->runLoopTimer, kCFRunLoopCommonModes); | ||
| 182 | } | ||
| 183 | |||
| 184 | bool QEventDispatcherIPhone::unregisterTimer(int identifier) | ||
| 185 | { | ||
| 186 | qDebug("bool QEventDispatcherIPhone::unregisterTimer(int identifier)"); | ||
| 187 | #ifndef QT_NO_DEBUG | ||
| 188 | if (identifier < 1) { | ||
| 189 | qWarning("QEventDispatcherIPhone::unregisterTimer: invalid argument"); | ||
| 190 | return false; | ||
| 191 | } else if (thread() != QThread::currentThread()) { | ||
| 192 | qWarning("QObject::killTimer: timers cannot be stopped from another thread"); | ||
| 193 | return false; | ||
| 194 | } | ||
| 195 | #endif | ||
| 196 | if (identifier <= 0) | ||
| 197 | return false; // not init'd or invalid timer | ||
| 198 | |||
| 199 | IPhoneTimerInfo *timerInfo = iPhoneTimerHash.take(identifier); | ||
| 200 | if (timerInfo == 0) | ||
| 201 | return false; | ||
| 202 | |||
| 203 | if (!QObjectPrivate::get(timerInfo->obj)->inThreadChangeEvent) | ||
| 204 | QAbstractEventDispatcherPrivate::releaseTimerId(identifier); | ||
| 205 | CFRunLoopTimerInvalidate(timerInfo->runLoopTimer); | ||
| 206 | CFRelease(timerInfo->runLoopTimer); | ||
| 207 | delete timerInfo; | ||
| 208 | |||
| 209 | return true; | ||
| 210 | } | ||
| 211 | |||
| 212 | bool QEventDispatcherIPhone::unregisterTimers(QObject *obj) | ||
| 213 | { | ||
| 214 | qDebug("bool QEventDispatcherIPhone::unregisterTimers(QObject *obj)"); | ||
| 215 | #ifndef QT_NO_DEBUG | ||
| 216 | if (!obj) { | ||
| 217 | qWarning("QEventDispatcherIPhone::unregisterTimers: invalid argument"); | ||
| 218 | return false; | ||
| 219 | } else if (obj->thread() != thread() || thread() != QThread::currentThread()) { | ||
| 220 | qWarning("QObject::killTimers: timers cannot be stopped from another thread"); | ||
| 221 | return false; | ||
| 222 | } | ||
| 223 | #endif | ||
| 224 | |||
| 225 | IPhoneTimerHash::iterator it = iPhoneTimerHash.begin(); | ||
| 226 | while (it != iPhoneTimerHash.end()) { | ||
| 227 | IPhoneTimerInfo *timerInfo = it.value(); | ||
| 228 | if (timerInfo->obj != obj) { | ||
| 229 | ++it; | ||
| 230 | } else { | ||
| 231 | if (!QObjectPrivate::get(timerInfo->obj)->inThreadChangeEvent) | ||
| 232 | QAbstractEventDispatcherPrivate::releaseTimerId(timerInfo->id); | ||
| 233 | CFRunLoopTimerInvalidate(timerInfo->runLoopTimer); | ||
| 234 | CFRelease(timerInfo->runLoopTimer); | ||
| 235 | delete timerInfo; | ||
| 236 | it = iPhoneTimerHash.erase(it); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | return true; | ||
| 240 | } | ||
| 241 | |||
| 242 | QList<QEventDispatcherIPhone::TimerInfo> | ||
| 243 | QEventDispatcherIPhone::registeredTimers(QObject *object) const | ||
| 244 | { | ||
| 245 | qDebug("QEventDispatcherIPhone::registeredTimers(QObject *object) const"); | ||
| 246 | if (!object) { | ||
| 247 | qWarning("QEventDispatcherIPhone:registeredTimers: invalid argument"); | ||
| 248 | return QList<TimerInfo>(); | ||
| 249 | } | ||
| 250 | |||
| 251 | QList<TimerInfo> list; | ||
| 252 | |||
| 253 | IPhoneTimerHash::const_iterator it = iPhoneTimerHash.constBegin(); | ||
| 254 | while (it != iPhoneTimerHash.constEnd()) { | ||
| 255 | IPhoneTimerInfo *t = it.value(); | ||
| 256 | if (t->obj == object) | ||
| 257 | list << TimerInfo(t->id, t->interval); | ||
| 258 | ++it; | ||
| 259 | } | ||
| 260 | return list; | ||
| 261 | } | ||
| 262 | |||
| 263 | /************************************************************************** | ||
| 264 | Socket Notifiers | ||
| 265 | *************************************************************************/ | ||
| 266 | void qt_IPhone_socket_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef, | ||
| 267 | const void *, void *info) { | ||
| 268 | QEventDispatcherIPhonePrivate *const eventDispatcher | ||
| 269 | = static_cast<QEventDispatcherIPhonePrivate *>(info); | ||
| 270 | int nativeSocket = CFSocketGetNative(s); | ||
| 271 | IPhoneSocketInfo *socketInfo = eventDispatcher->IPhoneSockets.value(nativeSocket); | ||
| 272 | QEvent notifierEvent(QEvent::SockAct); | ||
| 273 | |||
| 274 | // There is a race condition that happen where we disable the notifier and | ||
| 275 | // the kernel still has a notification to pass on. We then get this | ||
| 276 | // notification after we've successfully disabled the CFSocket, but our Qt | ||
| 277 | // notifier is now gone. The upshot is we have to check the notifier | ||
| 278 | // everytime. | ||
| 279 | if (callbackType == kCFSocketReadCallBack) { | ||
| 280 | if (socketInfo->readNotifier) | ||
| 281 | QApplication::sendEvent(socketInfo->readNotifier, ¬ifierEvent); | ||
| 282 | } else if (callbackType == kCFSocketWriteCallBack) { | ||
| 283 | if (socketInfo->writeNotifier) | ||
| 284 | QApplication::sendEvent(socketInfo->writeNotifier, ¬ifierEvent); | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | /* | ||
| 289 | Adds a loop source for the given socket to the current run loop. | ||
| 290 | */ | ||
| 291 | CFRunLoopSourceRef qt_IPhone_add_socket_to_runloop(const CFSocketRef socket) | ||
| 292 | { | ||
| 293 | CFRunLoopSourceRef loopSource = CFSocketCreateRunLoopSource(kCFAllocatorDefault, socket, 0); | ||
| 294 | if (!loopSource) | ||
| 295 | return 0; | ||
| 296 | |||
| 297 | CFRunLoopAddSource(mainRunLoop(), loopSource, kCFRunLoopCommonModes); | ||
| 298 | return loopSource; | ||
| 299 | } | ||
| 300 | |||
| 301 | /* | ||
| 302 | Removes the loop source for the given socket from the current run loop. | ||
| 303 | */ | ||
| 304 | void qt_IPhone_remove_socket_from_runloop(const CFSocketRef socket, CFRunLoopSourceRef runloop) | ||
| 305 | { | ||
| 306 | Q_ASSERT(runloop); | ||
| 307 | CFRunLoopRemoveSource(mainRunLoop(), runloop, kCFRunLoopCommonModes); | ||
| 308 | CFSocketDisableCallBacks(socket, kCFSocketReadCallBack); | ||
| 309 | CFSocketDisableCallBacks(socket, kCFSocketWriteCallBack); | ||
| 310 | CFRunLoopSourceInvalidate(runloop); | ||
| 311 | } | ||
| 312 | |||
| 313 | /* | ||
| 314 | Register a QSocketNotifier with the IPhone event system by creating a CFSocket with | ||
| 315 | with a read/write callback. | ||
| 316 | |||
| 317 | Qt has separate socket notifiers for reading and writing, but on the IPhone there is | ||
| 318 | a limitation of one CFSocket object for each native socket. | ||
| 319 | */ | ||
| 320 | void QEventDispatcherIPhone::registerSocketNotifier(QSocketNotifier *notifier) | ||
| 321 | { | ||
| 322 | qDebug("QEventDispatcherIPhone::registerSocketNotifier"); | ||
| 323 | Q_ASSERT(notifier); | ||
| 324 | int nativeSocket = notifier->socket(); | ||
| 325 | int type = notifier->type(); | ||
| 326 | #ifndef QT_NO_DEBUG | ||
| 327 | if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) { | ||
| 328 | qWarning("QSocketNotifier: Internal error"); | ||
| 329 | return; | ||
| 330 | } else if (notifier->thread() != thread() | ||
| 331 | || thread() != QThread::currentThread()) { | ||
| 332 | qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); | ||
| 333 | return; | ||
| 334 | } | ||
| 335 | #endif | ||
| 336 | |||
| 337 | Q_D(QEventDispatcherIPhone); | ||
| 338 | |||
| 339 | if (type == QSocketNotifier::Exception) { | ||
| 340 | qWarning("QSocketNotifier::Exception is not supported on IPhone OS X"); | ||
| 341 | return; | ||
| 342 | } | ||
| 343 | |||
| 344 | // Check if we have a CFSocket for the native socket, create one if not. | ||
| 345 | IPhoneSocketInfo *socketInfo = d->IPhoneSockets.value(nativeSocket); | ||
| 346 | if (!socketInfo) { | ||
| 347 | socketInfo = new IPhoneSocketInfo(); | ||
| 348 | |||
| 349 | // Create CFSocket, specify that we want both read and write callbacks (the callbacks | ||
| 350 | // are enabled/disabled later on). | ||
| 351 | const int callbackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack; | ||
| 352 | CFSocketContext context = {0, d, 0, 0, 0}; | ||
| 353 | socketInfo->socket = CFSocketCreateWithNative(kCFAllocatorDefault, nativeSocket, callbackTypes, qt_IPhone_socket_callback, &context); | ||
| 354 | if (CFSocketIsValid(socketInfo->socket) == false) { | ||
| 355 | qWarning("QEventDispatcherIPhone::registerSocketNotifier: Failed to create CFSocket"); | ||
| 356 | return; | ||
| 357 | } | ||
| 358 | |||
| 359 | CFOptionFlags flags = CFSocketGetSocketFlags(socketInfo->socket); | ||
| 360 | flags |= kCFSocketAutomaticallyReenableWriteCallBack; //QSocketNotifier stays enabled after a write | ||
| 361 | flags &= ~kCFSocketCloseOnInvalidate; //QSocketNotifier doesn't close the socket upon destruction/invalidation | ||
| 362 | CFSocketSetSocketFlags(socketInfo->socket, flags); | ||
| 363 | |||
| 364 | // Add CFSocket to runloop. | ||
| 365 | if(!(socketInfo->runloop = qt_IPhone_add_socket_to_runloop(socketInfo->socket))) { | ||
| 366 | qWarning("QEventDispatcherIPhone::registerSocketNotifier: Failed to add CFSocket to runloop"); | ||
| 367 | CFSocketInvalidate(socketInfo->socket); | ||
| 368 | CFRelease(socketInfo->socket); | ||
| 369 | return; | ||
| 370 | } | ||
| 371 | |||
| 372 | // Disable both callback types by default. This must be done after | ||
| 373 | // we add the CFSocket to the runloop, or else these calls will have | ||
| 374 | // no effect. | ||
| 375 | CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack); | ||
| 376 | CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); | ||
| 377 | |||
| 378 | d->IPhoneSockets.insert(nativeSocket, socketInfo); | ||
| 379 | } | ||
| 380 | |||
| 381 | // Increment read/write counters and select enable callbacks if necessary. | ||
| 382 | if (type == QSocketNotifier::Read) { | ||
| 383 | Q_ASSERT(socketInfo->readNotifier == 0); | ||
| 384 | socketInfo->readNotifier = notifier; | ||
| 385 | CFSocketEnableCallBacks(socketInfo->socket, kCFSocketReadCallBack); | ||
| 386 | } else if (type == QSocketNotifier::Write) { | ||
| 387 | Q_ASSERT(socketInfo->writeNotifier == 0); | ||
| 388 | socketInfo->writeNotifier = notifier; | ||
| 389 | CFSocketEnableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); | ||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | /* | ||
| 394 | Unregister QSocketNotifer. The CFSocket correspoding to this notifier is | ||
| 395 | removed from the runloop of this is the last notifier that users | ||
| 396 | that CFSocket. | ||
| 397 | */ | ||
| 398 | void QEventDispatcherIPhone::unregisterSocketNotifier(QSocketNotifier *notifier) | ||
| 399 | { | ||
| 400 | qDebug("QEventDispatcherIPhone::unregisterSocketNotifier"); | ||
| 401 | Q_ASSERT(notifier); | ||
| 402 | int nativeSocket = notifier->socket(); | ||
| 403 | int type = notifier->type(); | ||
| 404 | #ifndef QT_NO_DEBUG | ||
| 405 | if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) { | ||
| 406 | qWarning("QSocketNotifier: Internal error"); | ||
| 407 | return; | ||
| 408 | } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) { | ||
| 409 | qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); | ||
| 410 | return; | ||
| 411 | } | ||
| 412 | #endif | ||
| 413 | |||
| 414 | Q_D(QEventDispatcherIPhone); | ||
| 415 | |||
| 416 | if (type == QSocketNotifier::Exception) { | ||
| 417 | qWarning("QSocketNotifier::Exception is not supported on IPhone OS X"); | ||
| 418 | return; | ||
| 419 | } | ||
| 420 | IPhoneSocketInfo *socketInfo = d->IPhoneSockets.value(nativeSocket); | ||
| 421 | if (!socketInfo) { | ||
| 422 | qWarning("QEventDispatcherIPhone::unregisterSocketNotifier: Tried to unregister a not registered notifier"); | ||
| 423 | return; | ||
| 424 | } | ||
| 425 | |||
| 426 | // Decrement read/write counters and disable callbacks if necessary. | ||
| 427 | if (type == QSocketNotifier::Read) { | ||
| 428 | Q_ASSERT(notifier == socketInfo->readNotifier); | ||
| 429 | socketInfo->readNotifier = 0; | ||
| 430 | CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack); | ||
| 431 | } else if (type == QSocketNotifier::Write) { | ||
| 432 | Q_ASSERT(notifier == socketInfo->writeNotifier); | ||
| 433 | socketInfo->writeNotifier = 0; | ||
| 434 | CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack); | ||
| 435 | } | ||
| 436 | |||
| 437 | // Remove CFSocket from runloop if this was the last QSocketNotifier. | ||
| 438 | if (socketInfo->readNotifier == 0 && socketInfo->writeNotifier == 0) { | ||
| 439 | if (CFSocketIsValid(socketInfo->socket)) | ||
| 440 | qt_IPhone_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop); | ||
| 441 | CFRunLoopSourceInvalidate(socketInfo->runloop); | ||
| 442 | CFRelease(socketInfo->runloop); | ||
| 443 | CFSocketInvalidate(socketInfo->socket); | ||
| 444 | CFRelease(socketInfo->socket); | ||
| 445 | delete socketInfo; | ||
| 446 | d->IPhoneSockets.remove(nativeSocket); | ||
| 447 | } | ||
| 448 | } | ||
| 449 | |||
| 450 | bool QEventDispatcherIPhone::hasPendingEvents() | ||
| 451 | { | ||
| 452 | qDebug("QEventDispatcherIPhone::hasPendingEvents"); | ||
| 453 | extern uint qGlobalPostedEventsCount(); | ||
| 454 | return qGlobalPostedEventsCount(); //|| (qt_is_gui_used && GetNumEventsInQueue(GetMainEventQueue())); | ||
| 455 | } | ||
| 456 | |||
| 457 | static bool qt_IPhone_send_event(QEventLoop::ProcessEventsFlags, UIEvent *event, UIWindow *pt) | ||
| 458 | { | ||
| 459 | if (pt) | ||
| 460 | [pt sendEvent:event]; | ||
| 461 | else | ||
| 462 | [[UIApplication sharedApplication] sendEvent:event]; | ||
| 463 | return true; | ||
| 464 | } | ||
| 465 | |||
| 466 | //static bool IsMouseOrKeyEvent( UIEvent* event ) | ||
| 467 | //{ | ||
| 468 | // bool result = false; | ||
| 469 | // | ||
| 470 | // switch( [event type] ) | ||
| 471 | // { | ||
| 472 | // case UIEventTypeTouches: | ||
| 473 | // result = true; | ||
| 474 | // break; | ||
| 475 | // | ||
| 476 | // default: | ||
| 477 | // break; | ||
| 478 | // } | ||
| 479 | // return result; | ||
| 480 | //} | ||
| 481 | |||
| 482 | static inline void qt_IPhone_waitForMoreEvents() | ||
| 483 | { | ||
| 484 | ////#ifndef QT_IPhone_USE_COCOA | ||
| 485 | while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, true) == kCFRunLoopRunTimedOut) ; | ||
| 486 | ////#else | ||
| 487 | // // If no event exist in the cocoa event que, wait | ||
| 488 | // // (and free up cpu time) until at least one event occur. | ||
| 489 | // // This implementation is a bit on the edge, but seems to | ||
| 490 | // // work fine: | ||
| 491 | // NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask | ||
| 492 | // untilDate:[NSDate distantFuture] | ||
| 493 | // inMode:NSDefaultRunLoopMode | ||
| 494 | // dequeue:YES]; | ||
| 495 | // if (event) | ||
| 496 | // [NSApp postEvent:event atStart:YES]; | ||
| 497 | ////#endif | ||
| 498 | } | ||
| 499 | |||
| 500 | bool QEventDispatcherIPhone::processEvents(QEventLoop::ProcessEventsFlags flags) | ||
| 501 | { | ||
| 502 | Q_D(QEventDispatcherIPhone); | ||
| 503 | d->interrupt = false; | ||
| 504 | // In case we end up recursing while we now process events, make sure | ||
| 505 | // that we send remaining posted Qt events before this call returns: | ||
| 506 | wakeUp(); | ||
| 507 | emit awake(); | ||
| 508 | |||
| 509 | bool retVal = false; | ||
| 510 | |||
| 511 | forever { | ||
| 512 | if (d->interrupt) | ||
| 513 | break; | ||
| 514 | |||
| 515 | UIEvent* event = 0; | ||
| 516 | |||
| 517 | // If Qt is used as a plugin, or just added into a native cocoa | ||
| 518 | // application, we should not run or stop NSApplication; | ||
| 519 | // This will be done from outside Qt. | ||
| 520 | // And if processEvents is called manually (rather than from QEventLoop), we | ||
| 521 | // cannot enter a tight loop and block the call, but instead return after one flush: | ||
| 522 | //bool canExec_3rdParty = d->nsAppRunCalledByQt; //|| ![NSApp isRunning]; | ||
| 523 | bool canExec_Qt = false; //= flags & QEventLoop::DialogExec || flags & QEventLoop::EventLoopExec; | ||
| 524 | |||
| 525 | if (canExec_Qt) { | ||
| 526 | // We can use exec-mode, meaning that we can stay in a tight loop until | ||
| 527 | // interrupted. This is mostly an optimization, but it also allow us | ||
| 528 | // to use [NSApp run], which is the recommended way of running applications | ||
| 529 | // in cocoa. [NSApp run] should be called at least once for any cocoa app. | ||
| 530 | // d->nsAppRunCalledByQt = true; | ||
| 531 | // QBoolBlocker execGuard(d->currentExecIsNSAppRun, true); | ||
| 532 | [[NSRunLoop currentRunLoop] run]; | ||
| 533 | retVal = true; | ||
| 534 | } else do { | ||
| 535 | // INVARIANT: We cannot block the thread (and run in a tight loop). | ||
| 536 | // Instead we will process all current pending events and return. | ||
| 537 | bool mustRelease = false; | ||
| 538 | |||
| 539 | if (!(flags & QEventLoop::ExcludeUserInputEvents) && !d->queuedUserInputEvents.isEmpty()) { | ||
| 540 | // Process a pending user input event | ||
| 541 | mustRelease = true; | ||
| 542 | event = static_cast<UIEvent *>(d->queuedUserInputEvents.takeFirst()); | ||
| 543 | qDebug("PreProcess Events"); | ||
| 544 | } else { | ||
| 545 | [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]]; | ||
| 546 | // event = [NSApp nextEventMatchingMask:NSAnyEventMask | ||
| 547 | // untilDate:nil | ||
| 548 | // inMode:NSDefaultRunLoopMode | ||
| 549 | // dequeue: YES]; | ||
| 550 | // | ||
| 551 | // if (event != nil) { | ||
| 552 | // if (flags & QEventLoop::ExcludeUserInputEvents) { | ||
| 553 | // if (IsMouseOrKeyEvent(event)) { | ||
| 554 | // // retain event here? | ||
| 555 | // [event retain]; | ||
| 556 | // d->queuedUserInputEvents.append(event); | ||
| 557 | // continue; | ||
| 558 | // } | ||
| 559 | // } | ||
| 560 | // } | ||
| 561 | } | ||
| 562 | if (event) { | ||
| 563 | qDebug("Sending Events"); | ||
| 564 | if (!filterEvent(event) && qt_IPhone_send_event(flags, event, 0)) | ||
| 565 | retVal = true; | ||
| 566 | if (mustRelease) | ||
| 567 | [event release]; | ||
| 568 | } | ||
| 569 | } while(!d->interrupt && event != nil); | ||
| 570 | |||
| 571 | bool canWait = (d->threadData->canWait | ||
| 572 | && !retVal | ||
| 573 | && !d->interrupt | ||
| 574 | && (flags & QEventLoop::WaitForMoreEvents)); | ||
| 575 | if (canWait) { | ||
| 576 | // INVARIANT: We haven't processed any events yet. And we're told | ||
| 577 | // to stay inside this function until at least one event is processed. | ||
| 578 | qt_IPhone_waitForMoreEvents(); | ||
| 579 | flags &= ~QEventLoop::WaitForMoreEvents; | ||
| 580 | } else { | ||
| 581 | // Done with event processing for now. | ||
| 582 | // Leave the function: | ||
| 583 | break; | ||
| 584 | } | ||
| 585 | } | ||
| 586 | |||
| 587 | // In case we _now_ process events using [NSApp run], we need to stop it to | ||
| 588 | // ensure that: | ||
| 589 | // 1. the QEventLoop that called us is still executing, or | ||
| 590 | // 2. we have a modal session that needs to be spun instead. | ||
| 591 | // In case this is a plain call to processEvents (perhaps from a loop) | ||
| 592 | // from the application (rather than from a QEventLoop), we delay the | ||
| 593 | // interrupting until we/ actually enter a lower loop level (hence the | ||
| 594 | // deffered delete of the object below): | ||
| 595 | QtIPhoneInterruptDispatcherHelp::interruptLater(); | ||
| 596 | |||
| 597 | if (d->interrupt) { | ||
| 598 | // We should continue to leave all recursion to processEvents until | ||
| 599 | // processEvents is called again (e.g. from a QEventLoop that | ||
| 600 | // was not yet told to quit: | ||
| 601 | interrupt(); | ||
| 602 | } | ||
| 603 | |||
| 604 | return retVal; | ||
| 605 | } | ||
| 606 | |||
| 607 | void QEventDispatcherIPhone::wakeUp() | ||
| 608 | { | ||
| 609 | Q_D(QEventDispatcherIPhone); | ||
| 610 | d->serialNumber.ref(); | ||
| 611 | CFRunLoopSourceSignal(d->postedEventsSource); | ||
| 612 | CFRunLoopWakeUp(mainRunLoop()); | ||
| 613 | } | ||
| 614 | |||
| 615 | void QEventDispatcherIPhone::flush() | ||
| 616 | { | ||
| 617 | qDebug("void QEventDispatcherIPhone::flush()"); | ||
| 618 | // if(qApp) { | ||
| 619 | // QWidgetList tlws = QApplication::topLevelWidgets(); | ||
| 620 | // for(int i = 0; i < tlws.size(); i++) { | ||
| 621 | // QWidget *tlw = tlws.at(i); | ||
| 622 | // if(tlw->isVisible()) | ||
| 623 | // iPhoneWindowFlush(qt_IPhone_window_for(tlw)); | ||
| 624 | // } | ||
| 625 | // } | ||
| 626 | } | ||
| 627 | |||
| 628 | QEventDispatcherIPhonePrivate::QEventDispatcherIPhonePrivate() | ||
| 629 | : interrupt(false) | ||
| 630 | { | ||
| 631 | } | ||
| 632 | |||
| 633 | QEventDispatcherIPhone::QEventDispatcherIPhone(QObject *parent) | ||
| 634 | : QAbstractEventDispatcher(*new QEventDispatcherIPhonePrivate, parent) | ||
| 635 | { | ||
| 636 | Q_D(QEventDispatcherIPhone); | ||
| 637 | CFRunLoopSourceContext context; | ||
| 638 | bzero(&context, sizeof(CFRunLoopSourceContext)); | ||
| 639 | context.info = d; | ||
| 640 | context.equal = QEventDispatcherIPhonePrivate::postedEventSourceEqualCallback; | ||
| 641 | context.perform = QEventDispatcherIPhonePrivate::postedEventsSourcePerformCallback; | ||
| 642 | d->postedEventsSource = CFRunLoopSourceCreate(0, 0, &context); | ||
| 643 | Q_ASSERT(d->postedEventsSource); | ||
| 644 | CFRunLoopAddSource(mainRunLoop(), d->postedEventsSource, kCFRunLoopCommonModes); | ||
| 645 | |||
| 646 | CFRunLoopObserverContext observerContext; | ||
| 647 | bzero(&observerContext, sizeof(CFRunLoopObserverContext)); | ||
| 648 | observerContext.info = this; | ||
| 649 | d->waitingObserver = CFRunLoopObserverCreate(kCFAllocatorDefault, | ||
| 650 | kCFRunLoopBeforeWaiting | kCFRunLoopAfterWaiting, | ||
| 651 | true, 0, | ||
| 652 | QEventDispatcherIPhonePrivate::waitingObserverCallback, | ||
| 653 | &observerContext); | ||
| 654 | CFRunLoopAddObserver(mainRunLoop(), d->waitingObserver, kCFRunLoopCommonModes); | ||
| 655 | |||
| 656 | /* The first cycle in the loop adds the source and the events of the source | ||
| 657 | are not processed. | ||
| 658 | We use an observer to process the posted events for the first | ||
| 659 | execution of the loop. */ | ||
| 660 | CFRunLoopObserverContext firstTimeObserverContext; | ||
| 661 | bzero(&firstTimeObserverContext, sizeof(CFRunLoopObserverContext)); | ||
| 662 | firstTimeObserverContext.info = d; | ||
| 663 | d->firstTimeObserver = CFRunLoopObserverCreate(kCFAllocatorDefault, | ||
| 664 | kCFRunLoopEntry, | ||
| 665 | /* repeats = */ false, | ||
| 666 | 0, | ||
| 667 | QEventDispatcherIPhonePrivate::firstLoopEntry, | ||
| 668 | &firstTimeObserverContext); | ||
| 669 | CFRunLoopAddObserver(mainRunLoop(), d->firstTimeObserver, kCFRunLoopCommonModes); | ||
| 670 | } | ||
| 671 | |||
| 672 | void QEventDispatcherIPhonePrivate::waitingObserverCallback(CFRunLoopObserverRef, | ||
| 673 | CFRunLoopActivity activity, void *info) | ||
| 674 | { | ||
| 675 | if (activity == kCFRunLoopBeforeWaiting) | ||
| 676 | emit static_cast<QEventDispatcherIPhone*>(info)->aboutToBlock(); | ||
| 677 | else | ||
| 678 | emit static_cast<QEventDispatcherIPhone*>(info)->awake(); | ||
| 679 | } | ||
| 680 | |||
| 681 | Boolean QEventDispatcherIPhonePrivate::postedEventSourceEqualCallback(const void *info1, const void *info2) | ||
| 682 | { | ||
| 683 | return info1 == info2; | ||
| 684 | } | ||
| 685 | |||
| 686 | inline static void processPostedEvents(QEventDispatcherIPhonePrivate *const d) | ||
| 687 | { | ||
| 688 | if (d->interrupt) { | ||
| 689 | CFRunLoopSourceSignal(d->postedEventsSource); | ||
| 690 | } else { | ||
| 691 | if (!d->threadData->canWait || (d->serialNumber != d->lastSerial)) { | ||
| 692 | d->lastSerial = d->serialNumber; | ||
| 693 | QApplicationPrivate::sendPostedEvents(0, 0, d->threadData); | ||
| 694 | } | ||
| 695 | } | ||
| 696 | } | ||
| 697 | |||
| 698 | void QEventDispatcherIPhonePrivate::firstLoopEntry(CFRunLoopObserverRef ref, | ||
| 699 | CFRunLoopActivity activity, | ||
| 700 | void *info) | ||
| 701 | { | ||
| 702 | Q_UNUSED(ref); | ||
| 703 | Q_UNUSED(activity); | ||
| 704 | processPostedEvents(static_cast<QEventDispatcherIPhonePrivate *>(info)); | ||
| 705 | } | ||
| 706 | |||
| 707 | void QEventDispatcherIPhonePrivate::postedEventsSourcePerformCallback(void *info) | ||
| 708 | { | ||
| 709 | processPostedEvents(static_cast<QEventDispatcherIPhonePrivate *>(info)); | ||
| 710 | } | ||
| 711 | |||
| 712 | void QEventDispatcherIPhone::interrupt() | ||
| 713 | { | ||
| 714 | Q_D(QEventDispatcherIPhone); | ||
| 715 | d->interrupt = true; | ||
| 716 | wakeUp(); | ||
| 717 | |||
| 718 | CFRunLoopStop(mainRunLoop()); | ||
| 719 | } | ||
| 720 | |||
| 721 | QEventDispatcherIPhone::~QEventDispatcherIPhone() | ||
| 722 | { | ||
| 723 | Q_D(QEventDispatcherIPhone); | ||
| 724 | //timer cleanup | ||
| 725 | IPhoneTimerHash::iterator it = iPhoneTimerHash.begin(); | ||
| 726 | while (it != iPhoneTimerHash.end()) { | ||
| 727 | IPhoneTimerInfo *t = it.value(); | ||
| 728 | if (t->runLoopTimer) { | ||
| 729 | CFRunLoopTimerInvalidate(t->runLoopTimer); | ||
| 730 | CFRelease(t->runLoopTimer); | ||
| 731 | } | ||
| 732 | delete t; | ||
| 733 | ++it; | ||
| 734 | } | ||
| 735 | iPhoneTimerHash.clear(); | ||
| 736 | |||
| 737 | // Remove CFSockets from the runloop. | ||
| 738 | for (IPhoneSocketHash::ConstIterator it = d->IPhoneSockets.constBegin(); it != d->IPhoneSockets.constEnd(); ++it) { | ||
| 739 | IPhoneSocketInfo *socketInfo = (*it); | ||
| 740 | if (CFSocketIsValid(socketInfo->socket)) { | ||
| 741 | qt_IPhone_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop); | ||
| 742 | CFRunLoopSourceInvalidate(socketInfo->runloop); | ||
| 743 | CFRelease(socketInfo->runloop); | ||
| 744 | CFSocketInvalidate(socketInfo->socket); | ||
| 745 | CFRelease(socketInfo->socket); | ||
| 746 | } | ||
| 747 | } | ||
| 748 | CFRunLoopRemoveSource(mainRunLoop(), d->postedEventsSource, kCFRunLoopCommonModes); | ||
| 749 | CFRelease(d->postedEventsSource); | ||
| 750 | |||
| 751 | CFRunLoopObserverInvalidate(d->waitingObserver); | ||
| 752 | CFRelease(d->waitingObserver); | ||
| 753 | |||
| 754 | CFRunLoopObserverInvalidate(d->firstTimeObserver); | ||
| 755 | CFRelease(d->firstTimeObserver); | ||
| 756 | } | ||
| 757 | |||
| 758 | /////////////////////////////////////////////////////////////////////////////// | ||
| 759 | |||
| 760 | QtIPhoneInterruptDispatcherHelp* QtIPhoneInterruptDispatcherHelp::instance = 0; | ||
| 761 | |||
| 762 | QtIPhoneInterruptDispatcherHelp::QtIPhoneInterruptDispatcherHelp() : cancelled(false) | ||
| 763 | { | ||
| 764 | // This is the whole point of encapsulation this code | ||
| 765 | // inside a class; we can make the code (inside destructor) | ||
| 766 | // execute on lower loop level: | ||
| 767 | deleteLater(); | ||
| 768 | } | ||
| 769 | |||
| 770 | QtIPhoneInterruptDispatcherHelp::~QtIPhoneInterruptDispatcherHelp() | ||
| 771 | { | ||
| 772 | if (cancelled) | ||
| 773 | return; | ||
| 774 | |||
| 775 | instance = 0; | ||
| 776 | |||
| 777 | // if (QEventDispatcherIPhonePrivate::currentExecIsNSAppRun) { | ||
| 778 | // int activeCount = QEventDispatcherIPhonePrivate::activeModalSessionCount(); | ||
| 779 | // if (activeCount > 0) { | ||
| 780 | // // The problem we now have hit: [NSApp stop] will not stop NSApp | ||
| 781 | // // if a session is active; it will stop the session instead. | ||
| 782 | // // So to stop NSApp, we need to temporarily stop all the | ||
| 783 | // // sessions, then stop NSApp, then restart the session on top again. | ||
| 784 | // // We need to do this to ensure that we're not stuck inside | ||
| 785 | // // [NSApp run] when we really should be running a modal session: | ||
| 786 | // QEventDispatcherIPhonePrivate::temporarilyStopAllModalSessions(); | ||
| 787 | // } | ||
| 788 | // } | ||
| 789 | // Always interrupt once more in case the modal session stack changed | ||
| 790 | // while processEvents was called manually from within the application: | ||
| 791 | QEventDispatcherIPhone::instance()->interrupt(); | ||
| 792 | } | ||
| 793 | |||
| 794 | void QtIPhoneInterruptDispatcherHelp::interruptLater() { | ||
| 795 | if (instance) { | ||
| 796 | instance->cancelled = true; | ||
| 797 | delete instance; | ||
| 798 | } | ||
| 799 | instance = new QtIPhoneInterruptDispatcherHelp; | ||
| 800 | } | ||
| 801 | |||
| 802 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #ifndef QEVENTDISPATCHER_MAC_P_H | ||
| 77 | #define QEVENTDISPATCHER_MAC_P_H | ||
| 78 | |||
| 79 | // | ||
| 80 | // W A R N I N G | ||
| 81 | // ------------- | ||
| 82 | // | ||
| 83 | // This file is not part of the Qt API. It exists purely as an | ||
| 84 | // implementation detail. This header file may change from version to | ||
| 85 | // version without notice, or even be removed. | ||
| 86 | // | ||
| 87 | // We mean it. | ||
| 88 | // | ||
| 89 | |||
| 90 | #include <QtGui/qwindowdefs.h> | ||
| 91 | #include <QtCore/qhash.h> | ||
| 92 | #include <QtCore/qstack.h> | ||
| 93 | #include "private/qabstracteventdispatcher_p.h" | ||
| 94 | #include "private/qt_iphone_p.h" | ||
| 95 | |||
| 96 | QT_BEGIN_NAMESPACE | ||
| 97 | |||
| 98 | //typedef struct _NSModalSession *NSModalSession; | ||
| 99 | //typedef struct _QCocoaModalSessionInfo { | ||
| 100 | // QPointer<QWidget> widget; | ||
| 101 | // NSModalSession session; | ||
| 102 | //} QCocoaModalSessionInfo; | ||
| 103 | |||
| 104 | class QEventDispatcherIPhonePrivate; | ||
| 105 | |||
| 106 | class QEventDispatcherIPhone : public QAbstractEventDispatcher | ||
| 107 | { | ||
| 108 | Q_OBJECT | ||
| 109 | Q_DECLARE_PRIVATE(QEventDispatcherIPhone) | ||
| 110 | |||
| 111 | public: | ||
| 112 | explicit QEventDispatcherIPhone(QObject *parent = 0); | ||
| 113 | ~QEventDispatcherIPhone(); | ||
| 114 | |||
| 115 | bool processEvents(QEventLoop::ProcessEventsFlags flags); | ||
| 116 | bool hasPendingEvents(); | ||
| 117 | |||
| 118 | void registerSocketNotifier(QSocketNotifier *notifier); | ||
| 119 | void unregisterSocketNotifier(QSocketNotifier *notifier); | ||
| 120 | |||
| 121 | void registerTimer(int timerId, int interval, QObject *object); | ||
| 122 | bool unregisterTimer(int timerId); | ||
| 123 | bool unregisterTimers(QObject *object); | ||
| 124 | QList<TimerInfo> registeredTimers(QObject *object) const; | ||
| 125 | |||
| 126 | void wakeUp(); | ||
| 127 | void flush(); | ||
| 128 | void interrupt(); | ||
| 129 | |||
| 130 | private: | ||
| 131 | // friend void qt_mac_select_timer_callbk(__EventLoopTimer*, void*); | ||
| 132 | friend class QApplicationPrivate; | ||
| 133 | }; | ||
| 134 | |||
| 135 | struct IPhoneTimerInfo { | ||
| 136 | int id; | ||
| 137 | int interval; | ||
| 138 | QObject *obj; | ||
| 139 | bool pending; | ||
| 140 | CFRunLoopTimerRef runLoopTimer; | ||
| 141 | bool operator==(const IPhoneTimerInfo &other) | ||
| 142 | { | ||
| 143 | return (id == other.id); | ||
| 144 | } | ||
| 145 | }; | ||
| 146 | typedef QHash<int, IPhoneTimerInfo *> IPhoneTimerHash; | ||
| 147 | |||
| 148 | struct IPhoneSocketInfo { | ||
| 149 | IPhoneSocketInfo() : socket(0), runloop(0), readNotifier(0), writeNotifier(0) {} | ||
| 150 | CFSocketRef socket; | ||
| 151 | CFRunLoopSourceRef runloop; | ||
| 152 | QObject *readNotifier; | ||
| 153 | QObject *writeNotifier; | ||
| 154 | }; | ||
| 155 | typedef QHash<int, IPhoneSocketInfo *> IPhoneSocketHash; | ||
| 156 | |||
| 157 | class QEventDispatcherIPhonePrivate : public QAbstractEventDispatcherPrivate | ||
| 158 | { | ||
| 159 | Q_DECLARE_PUBLIC(QEventDispatcherIPhone) | ||
| 160 | |||
| 161 | public: | ||
| 162 | QEventDispatcherIPhonePrivate(); | ||
| 163 | protected: | ||
| 164 | //static IPhoneTimerHash iPhoneTimerHash; | ||
| 165 | // Set 'blockSendPostedEvents' to true if you _really_ need | ||
| 166 | // to make sure that qt events are not posted while calling | ||
| 167 | // low-level cocoa functions (like beginModalForWindow). And | ||
| 168 | // use a QBoolBlocker to be safe: | ||
| 169 | //static bool blockSendPostedEvents; | ||
| 170 | // The following variables help organizing modal sessions: | ||
| 171 | //static QStack<QCocoaModalSessionInfo> cocoaModalSessionStack; | ||
| 172 | //static bool currentExecIsNSAppRun; | ||
| 173 | //static bool nsAppRunCalledByQt; | ||
| 174 | //static NSModalSession currentModalSessionCached; | ||
| 175 | //static void updateChildrenWorksWhenModal(); | ||
| 176 | //static NSModalSession currentModalSession(); | ||
| 177 | //static int activeModalSessionCount(); | ||
| 178 | //static void temporarilyStopAllModalSessions(); | ||
| 179 | //static void beginModalSession(QWidget *widget); | ||
| 180 | //static void endModalSession(QWidget *widget); | ||
| 181 | |||
| 182 | public: | ||
| 183 | IPhoneSocketHash IPhoneSockets; | ||
| 184 | QList<void *> queuedUserInputEvents; // List of EventRef in Carbon, and NSEvent * in Cocoa | ||
| 185 | CFRunLoopSourceRef postedEventsSource; | ||
| 186 | CFRunLoopObserverRef waitingObserver; | ||
| 187 | CFRunLoopObserverRef firstTimeObserver; | ||
| 188 | QAtomicInt serialNumber; | ||
| 189 | int lastSerial; | ||
| 190 | bool interrupt; | ||
| 191 | private: | ||
| 192 | static Boolean postedEventSourceEqualCallback(const void *info1, const void *info2); | ||
| 193 | static void postedEventsSourcePerformCallback(void *info); | ||
| 194 | static void activateTimer(CFRunLoopTimerRef, void *info); | ||
| 195 | static void waitingObserverCallback(CFRunLoopObserverRef observer, | ||
| 196 | CFRunLoopActivity activity, void *info); | ||
| 197 | static void firstLoopEntry(CFRunLoopObserverRef ref, CFRunLoopActivity activity, void *info); | ||
| 198 | }; | ||
| 199 | |||
| 200 | class QtIPhoneInterruptDispatcherHelp : public QObject | ||
| 201 | { | ||
| 202 | static QtIPhoneInterruptDispatcherHelp *instance; | ||
| 203 | bool cancelled; | ||
| 204 | |||
| 205 | QtIPhoneInterruptDispatcherHelp(); | ||
| 206 | ~QtIPhoneInterruptDispatcherHelp(); | ||
| 207 | |||
| 208 | public: | ||
| 209 | static void interruptLater(); | ||
| 210 | }; | ||
| 211 | |||
| 212 | QT_END_NAMESPACE | ||
| 213 | |||
| 214 | #endif // QEVENTDISPATCHER_MAC_P_H |
src/gui/kernel/qkeymapper_iphone.mm
(963 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include <private/qt_iphone_p.h> | ||
| 43 | #include <qdebug.h> | ||
| 44 | #include <qevent.h> | ||
| 45 | #include <private/qevent_p.h> | ||
| 46 | #include <qtextcodec.h> | ||
| 47 | #include <qapplication.h> | ||
| 48 | #include <qinputcontext.h> | ||
| 49 | #include <private/qkeymapper_p.h> | ||
| 50 | #include <private/qapplication_p.h> | ||
| 51 | #include <private/qiphoneinputcontext_p.h> | ||
| 52 | |||
| 53 | QT_BEGIN_NAMESPACE | ||
| 54 | |||
| 55 | QT_USE_NAMESPACE | ||
| 56 | |||
| 57 | /***************************************************************************** | ||
| 58 | QKeyMapper debug facilities | ||
| 59 | *****************************************************************************/ | ||
| 60 | //#define DEBUG_KEY_BINDINGS | ||
| 61 | //#define DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 62 | //#define DEBUG_KEY_MAPS | ||
| 63 | |||
| 64 | /***************************************************************************** | ||
| 65 | Internal variables and functions | ||
| 66 | *****************************************************************************/ | ||
| 67 | //bool qt_mac_eat_unicode_key = false; | ||
| 68 | //extern bool qt_sendSpontaneousEvent(QObject *obj, QEvent *event); //qapplication_mac.cpp | ||
| 69 | |||
| 70 | //Q_GUI_EXPORT void qt_mac_secure_keyboard(bool b) | ||
| 71 | //{ | ||
| 72 | // static bool secure = false; | ||
| 73 | // if (b != secure){ | ||
| 74 | // b ? EnableSecureEventInput() : DisableSecureEventInput(); | ||
| 75 | // secure = b; | ||
| 76 | // } | ||
| 77 | //} | ||
| 78 | |||
| 79 | /* | ||
| 80 | \internal | ||
| 81 | A Mac KeyboardLayoutItem has 8 possible states: | ||
| 82 | 1. Unmodified | ||
| 83 | 2. Shift | ||
| 84 | 3. Control | ||
| 85 | 4. Control + Shift | ||
| 86 | 5. Alt | ||
| 87 | 6. Alt + Shift | ||
| 88 | 7. Alt + Control | ||
| 89 | 8. Alt + Control + Shift | ||
| 90 | 9. Meta | ||
| 91 | 10. Meta + Shift | ||
| 92 | 11. Meta + Control | ||
| 93 | 12. Meta + Control + Shift | ||
| 94 | 13. Meta + Alt | ||
| 95 | 14. Meta + Alt + Shift | ||
| 96 | 15. Meta + Alt + Control | ||
| 97 | 16. Meta + Alt + Control + Shift | ||
| 98 | */ | ||
| 99 | //struct KeyboardLayoutItem { | ||
| 100 | // bool dirty; | ||
| 101 | // quint32 qtKey[16]; // Can by any Qt::Key_<foo>, or unicode character | ||
| 102 | //}; | ||
| 103 | |||
| 104 | // Possible modifier states. | ||
| 105 | // NOTE: The order of these states match the order in QKeyMapperPrivate::updatePossibleKeyCodes()! | ||
| 106 | //static const Qt::KeyboardModifiers ModsTbl[] = { | ||
| 107 | // Qt::NoModifier, // 0 | ||
| 108 | // Qt::ShiftModifier, // 1 | ||
| 109 | // Qt::ControlModifier, // 2 | ||
| 110 | // Qt::ControlModifier | Qt::ShiftModifier, // 3 | ||
| 111 | // Qt::AltModifier, // 4 | ||
| 112 | // Qt::AltModifier | Qt::ShiftModifier, // 5 | ||
| 113 | // Qt::AltModifier | Qt::ControlModifier, // 6 | ||
| 114 | // Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 7 | ||
| 115 | // Qt::MetaModifier, // 8 | ||
| 116 | // Qt::MetaModifier | Qt::ShiftModifier, // 9 | ||
| 117 | // Qt::MetaModifier | Qt::ControlModifier, // 10 | ||
| 118 | // Qt::MetaModifier | Qt::ControlModifier | Qt::ShiftModifier,// 11 | ||
| 119 | // Qt::MetaModifier | Qt::AltModifier, // 12 | ||
| 120 | // Qt::MetaModifier | Qt::AltModifier | Qt::ShiftModifier, // 13 | ||
| 121 | // Qt::MetaModifier | Qt::AltModifier | Qt::ControlModifier, // 14 | ||
| 122 | // Qt::MetaModifier | Qt::AltModifier | Qt::ShiftModifier | Qt::ControlModifier, // 15 | ||
| 123 | //}; | ||
| 124 | |||
| 125 | /* key maps */ | ||
| 126 | //struct qt_mac_enum_mapper | ||
| 127 | //{ | ||
| 128 | // int mac_code; | ||
| 129 | // int qt_code; | ||
| 130 | //#if defined(DEBUG_KEY_BINDINGS) | ||
| 131 | //# define QT_MAC_MAP_ENUM(x) x, #x | ||
| 132 | // const char *desc; | ||
| 133 | //#else | ||
| 134 | //# define QT_MAC_MAP_ENUM(x) x | ||
| 135 | //#endif | ||
| 136 | //}; | ||
| 137 | |||
| 138 | //modifiers | ||
| 139 | //static qt_mac_enum_mapper qt_mac_modifier_symbols[] = { | ||
| 140 | // { shiftKey, QT_MAC_MAP_ENUM(Qt::ShiftModifier) }, | ||
| 141 | // { rightShiftKey, QT_MAC_MAP_ENUM(Qt::ShiftModifier) }, | ||
| 142 | // { controlKey, QT_MAC_MAP_ENUM(Qt::MetaModifier) }, | ||
| 143 | // { rightControlKey, QT_MAC_MAP_ENUM(Qt::MetaModifier) }, | ||
| 144 | // { cmdKey, QT_MAC_MAP_ENUM(Qt::ControlModifier) }, | ||
| 145 | // { optionKey, QT_MAC_MAP_ENUM(Qt::AltModifier) }, | ||
| 146 | // { rightOptionKey, QT_MAC_MAP_ENUM(Qt::AltModifier) }, | ||
| 147 | // { kEventKeyModifierNumLockMask, QT_MAC_MAP_ENUM(Qt::KeypadModifier) }, | ||
| 148 | // { 0, QT_MAC_MAP_ENUM(0) } | ||
| 149 | //}; | ||
| 150 | //Qt::KeyboardModifiers qt_mac_get_modifiers(int keys) | ||
| 151 | //{ | ||
| 152 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 153 | // qDebug("Qt: internal: **Mapping modifiers: %d (0x%04x)", keys, keys); | ||
| 154 | //#endif | ||
| 155 | // Qt::KeyboardModifiers ret = Qt::NoModifier; | ||
| 156 | // for (int i = 0; qt_mac_modifier_symbols[i].qt_code; i++) { | ||
| 157 | // if (keys & qt_mac_modifier_symbols[i].mac_code) { | ||
| 158 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 159 | // qDebug("Qt: internal: got modifier: %s", qt_mac_modifier_symbols[i].desc); | ||
| 160 | //#endif | ||
| 161 | // ret |= Qt::KeyboardModifier(qt_mac_modifier_symbols[i].qt_code); | ||
| 162 | // } | ||
| 163 | // } | ||
| 164 | // if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) { | ||
| 165 | // Qt::KeyboardModifiers oldModifiers = ret; | ||
| 166 | // ret &= ~(Qt::MetaModifier | Qt::ControlModifier); | ||
| 167 | // if (oldModifiers & Qt::ControlModifier) | ||
| 168 | // ret |= Qt::MetaModifier; | ||
| 169 | // if (oldModifiers & Qt::MetaModifier) | ||
| 170 | // ret |= Qt::ControlModifier; | ||
| 171 | // } | ||
| 172 | // return ret; | ||
| 173 | //} | ||
| 174 | //static int qt_mac_get_mac_modifiers(Qt::KeyboardModifiers keys) | ||
| 175 | //{ | ||
| 176 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 177 | // qDebug("Qt: internal: **Mapping modifiers: %d (0x%04x)", (int)keys, (int)keys); | ||
| 178 | //#endif | ||
| 179 | // int ret = 0; | ||
| 180 | // for (int i = 0; qt_mac_modifier_symbols[i].qt_code; i++) { | ||
| 181 | // if (keys & qt_mac_modifier_symbols[i].qt_code) { | ||
| 182 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 183 | // qDebug("Qt: internal: got modifier: %s", qt_mac_modifier_symbols[i].desc); | ||
| 184 | //#endif | ||
| 185 | // ret |= qt_mac_modifier_symbols[i].mac_code; | ||
| 186 | // } | ||
| 187 | // } | ||
| 188 | // | ||
| 189 | // if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) { | ||
| 190 | // int oldModifiers = ret; | ||
| 191 | // ret &= ~(controlKeyBit | cmdKeyBit); | ||
| 192 | // if (oldModifiers & controlKeyBit) | ||
| 193 | // ret |= cmdKeyBit; | ||
| 194 | // if (oldModifiers & cmdKeyBit) | ||
| 195 | // ret |= controlKeyBit; | ||
| 196 | // } | ||
| 197 | // return ret; | ||
| 198 | //} | ||
| 199 | //void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object) | ||
| 200 | //{ | ||
| 201 | // static quint32 cachedModifiers = 0; | ||
| 202 | // quint32 lastModifiers = cachedModifiers, | ||
| 203 | // changedModifiers = lastModifiers ^ modifiers; | ||
| 204 | // cachedModifiers = modifiers; | ||
| 205 | // | ||
| 206 | // //check the bits | ||
| 207 | // static qt_mac_enum_mapper modifier_key_symbols[] = { | ||
| 208 | // { shiftKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Shift) }, | ||
| 209 | // { rightShiftKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Shift) }, //??? | ||
| 210 | // { controlKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Meta) }, | ||
| 211 | // { rightControlKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Meta) }, //??? | ||
| 212 | // { cmdKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Control) }, | ||
| 213 | // { optionKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Alt) }, | ||
| 214 | // { rightOptionKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Alt) }, //??? | ||
| 215 | // { alphaLockBit, QT_MAC_MAP_ENUM(Qt::Key_CapsLock) }, | ||
| 216 | // { kEventKeyModifierNumLockBit, QT_MAC_MAP_ENUM(Qt::Key_NumLock) }, | ||
| 217 | // { 0, QT_MAC_MAP_ENUM(0) } }; | ||
| 218 | // for (int i = 0; i <= 32; i++) { //just check each bit | ||
| 219 | // if (!(changedModifiers & (1 << i))) | ||
| 220 | // continue; | ||
| 221 | // QEvent::Type etype = QEvent::KeyPress; | ||
| 222 | // if (lastModifiers & (1 << i)) | ||
| 223 | // etype = QEvent::KeyRelease; | ||
| 224 | // int key = 0; | ||
| 225 | // for (uint x = 0; modifier_key_symbols[x].mac_code; x++) { | ||
| 226 | // if (modifier_key_symbols[x].mac_code == i) { | ||
| 227 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 228 | // qDebug("got modifier changed: %s", modifier_key_symbols[x].desc); | ||
| 229 | //#endif | ||
| 230 | // key = modifier_key_symbols[x].qt_code; | ||
| 231 | // break; | ||
| 232 | // } | ||
| 233 | // } | ||
| 234 | // if (!key) { | ||
| 235 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 236 | // qDebug("could not get modifier changed: %d", i); | ||
| 237 | //#endif | ||
| 238 | // continue; | ||
| 239 | // } | ||
| 240 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 241 | // qDebug("KeyEvent (modif): Sending %s to %s::%s: %d - 0x%08x", | ||
| 242 | // etype == QEvent::KeyRelease ? "KeyRelease" : "KeyPress", | ||
| 243 | // object ? object->metaObject()->className() : "none", | ||
| 244 | // object ? object->objectName().toLatin1().constData() : "", | ||
| 245 | // key, (int)modifiers); | ||
| 246 | //#endif | ||
| 247 | // QKeyEvent ke(etype, key, qt_mac_get_modifiers(modifiers ^ (1 << i)), QLatin1String("")); | ||
| 248 | // qt_sendSpontaneousEvent(object, &ke); | ||
| 249 | // } | ||
| 250 | //} | ||
| 251 | // | ||
| 252 | ////keyboard keys (non-modifiers) | ||
| 253 | //static qt_mac_enum_mapper qt_mac_keyboard_symbols[] = { | ||
| 254 | // { kHomeCharCode, QT_MAC_MAP_ENUM(Qt::Key_Home) }, | ||
| 255 | // { kEnterCharCode, QT_MAC_MAP_ENUM(Qt::Key_Enter) }, | ||
| 256 | // { kEndCharCode, QT_MAC_MAP_ENUM(Qt::Key_End) }, | ||
| 257 | // { kBackspaceCharCode, QT_MAC_MAP_ENUM(Qt::Key_Backspace) }, | ||
| 258 | // { kTabCharCode, QT_MAC_MAP_ENUM(Qt::Key_Tab) }, | ||
| 259 | // { kPageUpCharCode, QT_MAC_MAP_ENUM(Qt::Key_PageUp) }, | ||
| 260 | // { kPageDownCharCode, QT_MAC_MAP_ENUM(Qt::Key_PageDown) }, | ||
| 261 | // { kReturnCharCode, QT_MAC_MAP_ENUM(Qt::Key_Return) }, | ||
| 262 | // { kEscapeCharCode, QT_MAC_MAP_ENUM(Qt::Key_Escape) }, | ||
| 263 | // { kLeftArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Left) }, | ||
| 264 | // { kRightArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Right) }, | ||
| 265 | // { kUpArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Up) }, | ||
| 266 | // { kDownArrowCharCode, QT_MAC_MAP_ENUM(Qt::Key_Down) }, | ||
| 267 | // { kHelpCharCode, QT_MAC_MAP_ENUM(Qt::Key_Help) }, | ||
| 268 | // { kDeleteCharCode, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, | ||
| 269 | ////ascii maps, for debug | ||
| 270 | // { ':', QT_MAC_MAP_ENUM(Qt::Key_Colon) }, | ||
| 271 | // { ';', QT_MAC_MAP_ENUM(Qt::Key_Semicolon) }, | ||
| 272 | // { '<', QT_MAC_MAP_ENUM(Qt::Key_Less) }, | ||
| 273 | // { '=', QT_MAC_MAP_ENUM(Qt::Key_Equal) }, | ||
| 274 | // { '>', QT_MAC_MAP_ENUM(Qt::Key_Greater) }, | ||
| 275 | // { '?', QT_MAC_MAP_ENUM(Qt::Key_Question) }, | ||
| 276 | // { '@', QT_MAC_MAP_ENUM(Qt::Key_At) }, | ||
| 277 | // { ' ', QT_MAC_MAP_ENUM(Qt::Key_Space) }, | ||
| 278 | // { '!', QT_MAC_MAP_ENUM(Qt::Key_Exclam) }, | ||
| 279 | // { '"', QT_MAC_MAP_ENUM(Qt::Key_QuoteDbl) }, | ||
| 280 | // { '#', QT_MAC_MAP_ENUM(Qt::Key_NumberSign) }, | ||
| 281 | // { '$', QT_MAC_MAP_ENUM(Qt::Key_Dollar) }, | ||
| 282 | // { '%', QT_MAC_MAP_ENUM(Qt::Key_Percent) }, | ||
| 283 | // { '&', QT_MAC_MAP_ENUM(Qt::Key_Ampersand) }, | ||
| 284 | // { '\'', QT_MAC_MAP_ENUM(Qt::Key_Apostrophe) }, | ||
| 285 | // { '(', QT_MAC_MAP_ENUM(Qt::Key_ParenLeft) }, | ||
| 286 | // { ')', QT_MAC_MAP_ENUM(Qt::Key_ParenRight) }, | ||
| 287 | // { '*', QT_MAC_MAP_ENUM(Qt::Key_Asterisk) }, | ||
| 288 | // { '+', QT_MAC_MAP_ENUM(Qt::Key_Plus) }, | ||
| 289 | // { ',', QT_MAC_MAP_ENUM(Qt::Key_Comma) }, | ||
| 290 | // { '-', QT_MAC_MAP_ENUM(Qt::Key_Minus) }, | ||
| 291 | // { '.', QT_MAC_MAP_ENUM(Qt::Key_Period) }, | ||
| 292 | // { '/', QT_MAC_MAP_ENUM(Qt::Key_Slash) }, | ||
| 293 | // { '[', QT_MAC_MAP_ENUM(Qt::Key_BracketLeft) }, | ||
| 294 | // { ']', QT_MAC_MAP_ENUM(Qt::Key_BracketRight) }, | ||
| 295 | // { '\\', QT_MAC_MAP_ENUM(Qt::Key_Backslash) }, | ||
| 296 | // { '_', QT_MAC_MAP_ENUM(Qt::Key_Underscore) }, | ||
| 297 | // { '`', QT_MAC_MAP_ENUM(Qt::Key_QuoteLeft) }, | ||
| 298 | // { '{', QT_MAC_MAP_ENUM(Qt::Key_BraceLeft) }, | ||
| 299 | // { '}', QT_MAC_MAP_ENUM(Qt::Key_BraceRight) }, | ||
| 300 | // { '|', QT_MAC_MAP_ENUM(Qt::Key_Bar) }, | ||
| 301 | // { '~', QT_MAC_MAP_ENUM(Qt::Key_AsciiTilde) }, | ||
| 302 | // { '^', QT_MAC_MAP_ENUM(Qt::Key_AsciiCircum) }, | ||
| 303 | // { 0, QT_MAC_MAP_ENUM(0) } | ||
| 304 | //}; | ||
| 305 | // | ||
| 306 | //static qt_mac_enum_mapper qt_mac_keyvkey_symbols[] = { //real scan codes | ||
| 307 | // { 122, QT_MAC_MAP_ENUM(Qt::Key_F1) }, | ||
| 308 | // { 120, QT_MAC_MAP_ENUM(Qt::Key_F2) }, | ||
| 309 | // { 99, QT_MAC_MAP_ENUM(Qt::Key_F3) }, | ||
| 310 | // { 118, QT_MAC_MAP_ENUM(Qt::Key_F4) }, | ||
| 311 | // { 96, QT_MAC_MAP_ENUM(Qt::Key_F5) }, | ||
| 312 | // { 97, QT_MAC_MAP_ENUM(Qt::Key_F6) }, | ||
| 313 | // { 98, QT_MAC_MAP_ENUM(Qt::Key_F7) }, | ||
| 314 | // { 100, QT_MAC_MAP_ENUM(Qt::Key_F8) }, | ||
| 315 | // { 101, QT_MAC_MAP_ENUM(Qt::Key_F9) }, | ||
| 316 | // { 109, QT_MAC_MAP_ENUM(Qt::Key_F10) }, | ||
| 317 | // { 103, QT_MAC_MAP_ENUM(Qt::Key_F11) }, | ||
| 318 | // { 111, QT_MAC_MAP_ENUM(Qt::Key_F12) }, | ||
| 319 | // { 105, QT_MAC_MAP_ENUM(Qt::Key_F13) }, | ||
| 320 | // { 107, QT_MAC_MAP_ENUM(Qt::Key_F14) }, | ||
| 321 | // { 113, QT_MAC_MAP_ENUM(Qt::Key_F15) }, | ||
| 322 | // { 106, QT_MAC_MAP_ENUM(Qt::Key_F16) }, | ||
| 323 | // { 0, QT_MAC_MAP_ENUM(0) } | ||
| 324 | //}; | ||
| 325 | // | ||
| 326 | //static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) | ||
| 327 | //{ | ||
| 328 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 329 | // qDebug("**Mapping key: %d (0x%04x) - %d (0x%04x)", key.unicode(), key.unicode(), virtualKey, virtualKey); | ||
| 330 | //#endif | ||
| 331 | // | ||
| 332 | // if (key == kClearCharCode && virtualKey == 0x47) | ||
| 333 | // return Qt::Key_Clear; | ||
| 334 | // | ||
| 335 | // if (key.isDigit()) { | ||
| 336 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 337 | // qDebug("%d: got key: %d", __LINE__, key.digitValue()); | ||
| 338 | //#endif | ||
| 339 | // return key.digitValue() + Qt::Key_0; | ||
| 340 | // } | ||
| 341 | // | ||
| 342 | // if (key.isLetter()) { | ||
| 343 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 344 | // qDebug("%d: got key: %d", __LINE__, (key.toUpper().unicode() - 'A')); | ||
| 345 | //#endif | ||
| 346 | // return (key.toUpper().unicode() - 'A') + Qt::Key_A; | ||
| 347 | // } | ||
| 348 | // if (key.isSymbol()) { | ||
| 349 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 350 | // qDebug("%d: got key: %d", __LINE__, (key.unicode())); | ||
| 351 | //#endif | ||
| 352 | // return key.unicode(); | ||
| 353 | // } | ||
| 354 | // | ||
| 355 | // for (int i = 0; qt_mac_keyboard_symbols[i].qt_code; i++) { | ||
| 356 | // if (qt_mac_keyboard_symbols[i].mac_code == key) { | ||
| 357 | // /* To work like Qt for X11 we issue Backtab when Shift + Tab are pressed */ | ||
| 358 | // if (qt_mac_keyboard_symbols[i].qt_code == Qt::Key_Tab && (modif & Qt::ShiftModifier)) { | ||
| 359 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 360 | // qDebug("%d: got key: Qt::Key_Backtab", __LINE__); | ||
| 361 | //#endif | ||
| 362 | // return Qt::Key_Backtab; | ||
| 363 | // } | ||
| 364 | // | ||
| 365 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 366 | // qDebug("%d: got key: %s", __LINE__, qt_mac_keyboard_symbols[i].desc); | ||
| 367 | //#endif | ||
| 368 | // return qt_mac_keyboard_symbols[i].qt_code; | ||
| 369 | // } | ||
| 370 | // } | ||
| 371 | // | ||
| 372 | // //last ditch try to match the scan code | ||
| 373 | // for (int i = 0; qt_mac_keyvkey_symbols[i].qt_code; i++) { | ||
| 374 | // if (qt_mac_keyvkey_symbols[i].mac_code == virtualKey) { | ||
| 375 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 376 | // qDebug("%d: got key: %s", __LINE__, qt_mac_keyvkey_symbols[i].desc); | ||
| 377 | //#endif | ||
| 378 | // return qt_mac_keyvkey_symbols[i].qt_code; | ||
| 379 | // } | ||
| 380 | // } | ||
| 381 | // | ||
| 382 | // //oh well | ||
| 383 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 384 | // qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); | ||
| 385 | //#endif | ||
| 386 | // return Qt::Key_unknown; | ||
| 387 | //} | ||
| 388 | // | ||
| 389 | //static Boolean qt_KeyEventComparatorProc(EventRef inEvent, void *data) | ||
| 390 | //{ | ||
| 391 | // UInt32 ekind = GetEventKind(inEvent), | ||
| 392 | // eclass = GetEventClass(inEvent); | ||
| 393 | // return (eclass == kEventClassKeyboard && (void *)ekind == data); | ||
| 394 | //} | ||
| 395 | // | ||
| 396 | //static bool translateKeyEventInternal(EventHandlerCallRef er, EventRef keyEvent, int *qtKey, | ||
| 397 | // QChar *outChar, Qt::KeyboardModifiers *outModifiers, bool *outHandled) | ||
| 398 | //{ | ||
| 399 | //#if !defined(QT_MAC_USE_COCOA) || defined(Q_OS_MAC64) | ||
| 400 | // Q_UNUSED(er); | ||
| 401 | // Q_UNUSED(outHandled); | ||
| 402 | //#endif | ||
| 403 | // const UInt32 ekind = GetEventKind(keyEvent); | ||
| 404 | // { | ||
| 405 | // UInt32 mac_modifiers = 0; | ||
| 406 | // GetEventParameter(keyEvent, kEventParamKeyModifiers, typeUInt32, 0, | ||
| 407 | // sizeof(mac_modifiers), 0, &mac_modifiers); | ||
| 408 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 409 | // qDebug("************ Mapping modifiers and key ***********"); | ||
| 410 | //#endif | ||
| 411 | // *outModifiers = qt_mac_get_modifiers(mac_modifiers); | ||
| 412 | //#ifdef DEBUG_KEY_BINDINGS_MODIFIERS | ||
| 413 | // qDebug("------------ Mapping modifiers and key -----------"); | ||
| 414 | //#endif | ||
| 415 | // } | ||
| 416 | // | ||
| 417 | // //get keycode | ||
| 418 | // UInt32 keyCode = 0; | ||
| 419 | // GetEventParameter(keyEvent, kEventParamKeyCode, typeUInt32, 0, sizeof(keyCode), 0, &keyCode); | ||
| 420 | // | ||
| 421 | // //get mac mapping | ||
| 422 | // static UInt32 tmp_unused_state = 0L; | ||
| 423 | // const UCKeyboardLayout *uchrData = 0; | ||
| 424 | //#if defined(Q_OS_MAC32) | ||
| 425 | // KeyboardLayoutRef keyLayoutRef = 0; | ||
| 426 | // KLGetCurrentKeyboardLayout(&keyLayoutRef); | ||
| 427 | // OSStatus err; | ||
| 428 | // if (keyLayoutRef != 0) { | ||
| 429 | // err = KLGetKeyboardLayoutProperty(keyLayoutRef, kKLuchrData, | ||
| 430 | // (reinterpret_cast<const void **>(&uchrData))); | ||
| 431 | // if (err != noErr) { | ||
| 432 | // qWarning("Qt::internal::unable to get keyboardlayout %ld %s:%d", | ||
| 433 | // long(err), __FILE__, __LINE__); | ||
| 434 | // } | ||
| 435 | // } | ||
| 436 | //#else | ||
| 437 | // QCFType<TISInputSourceRef> inputSource = TISCopyCurrentKeyboardInputSource(); | ||
| 438 | // Q_ASSERT(inputSource != 0); | ||
| 439 | // CFDataRef data = static_cast<CFDataRef>(TISGetInputSourceProperty(inputSource, | ||
| 440 | // kTISPropertyUnicodeKeyLayoutData)); | ||
| 441 | // uchrData = data ? reinterpret_cast<const UCKeyboardLayout *>(CFDataGetBytePtr(data)) : 0; | ||
| 442 | //#endif | ||
| 443 | // *qtKey = Qt::Key_unknown; | ||
| 444 | // if (uchrData) { | ||
| 445 | // // The easy stuff; use the unicode stuff! | ||
| 446 | // UniChar string[4]; | ||
| 447 | // UniCharCount actualLength; | ||
| 448 | // UInt32 currentModifiers = GetCurrentEventKeyModifiers(); | ||
| 449 | // UInt32 currentModifiersWOAltOrControl = currentModifiers & ~(controlKey | optionKey); | ||
| 450 | // int keyAction; | ||
| 451 | // switch (ekind) { | ||
| 452 | // default: | ||
| 453 | // case kEventRawKeyDown: | ||
| 454 | // keyAction = kUCKeyActionDown; | ||
| 455 | // break; | ||
| 456 | // case kEventRawKeyUp: | ||
| 457 | // keyAction = kUCKeyActionUp; | ||
| 458 | // break; | ||
| 459 | // case kEventRawKeyRepeat: | ||
| 460 | // keyAction = kUCKeyActionAutoKey; | ||
| 461 | // break; | ||
| 462 | // } | ||
| 463 | // OSStatus err = UCKeyTranslate(uchrData, keyCode, keyAction, | ||
| 464 | // ((currentModifiersWOAltOrControl >> 8) & 0xff), LMGetKbdType(), | ||
| 465 | // kUCKeyTranslateNoDeadKeysMask, &tmp_unused_state, 4, &actualLength, | ||
| 466 | // string); | ||
| 467 | // if (err == noErr) { | ||
| 468 | // *outChar = QChar(string[0]); | ||
| 469 | // *qtKey = qt_mac_get_key(*outModifiers, *outChar, keyCode); | ||
| 470 | // if (currentModifiersWOAltOrControl != currentModifiers) { | ||
| 471 | // // Now get the real char. | ||
| 472 | // err = UCKeyTranslate(uchrData, keyCode, keyAction, | ||
| 473 | // ((currentModifiers >> 8) & 0xff), LMGetKbdType(), | ||
| 474 | // kUCKeyTranslateNoDeadKeysMask, &tmp_unused_state, 4, &actualLength, | ||
| 475 | // string); | ||
| 476 | // if (err == noErr) | ||
| 477 | // *outChar = QChar(string[0]); | ||
| 478 | // } | ||
| 479 | // } else { | ||
| 480 | // qWarning("Qt::internal::UCKeyTranslate is returnining %ld %s:%d", | ||
| 481 | // long(err), __FILE__, __LINE__); | ||
| 482 | // } | ||
| 483 | // } | ||
| 484 | //#ifdef Q_OS_MAC32 | ||
| 485 | // else { | ||
| 486 | // // The road less travelled; use KeyTranslate | ||
| 487 | // const void *keyboard_layout; | ||
| 488 | // KeyboardLayoutRef keyLayoutRef = 0; | ||
| 489 | // KLGetCurrentKeyboardLayout(&keyLayoutRef); | ||
| 490 | // err = KLGetKeyboardLayoutProperty(keyLayoutRef, kKLKCHRData, | ||
| 491 | // reinterpret_cast<const void **>(&keyboard_layout)); | ||
| 492 | // | ||
| 493 | // int translatedChar = KeyTranslate(keyboard_layout, (GetCurrentEventKeyModifiers() & | ||
| 494 | // (kEventKeyModifierNumLockMask|shiftKey|cmdKey| | ||
| 495 | // rightShiftKey|alphaLock)) | keyCode, | ||
| 496 | // &tmp_unused_state); | ||
| 497 | // if (!translatedChar) { | ||
| 498 | //#ifdef QT_MAC_USE_COCOA | ||
| 499 | // if (outHandled) { | ||
| 500 | // qt_mac_eat_unicode_key = false; | ||
| 501 | // if (er) | ||
| 502 | // CallNextEventHandler(er, keyEvent); | ||
| 503 | // *outHandled = qt_mac_eat_unicode_key; | ||
| 504 | // } | ||
| 505 | //#endif | ||
| 506 | // return false; | ||
| 507 | // } | ||
| 508 | // | ||
| 509 | // //map it into qt keys | ||
| 510 | // *qtKey = qt_mac_get_key(*outModifiers, QChar(translatedChar), keyCode); | ||
| 511 | // if (*outModifiers & (Qt::AltModifier | Qt::ControlModifier)) { | ||
| 512 | // if (translatedChar & (1 << 7)) //high ascii | ||
| 513 | // translatedChar = 0; | ||
| 514 | // } else { //now get the real ascii value | ||
| 515 | // UInt32 tmp_mod = 0L; | ||
| 516 | // static UInt32 tmp_state = 0L; | ||
| 517 | // if (*outModifiers & Qt::ShiftModifier) | ||
| 518 | // tmp_mod |= shiftKey; | ||
| 519 | // if (*outModifiers & Qt::MetaModifier) | ||
| 520 | // tmp_mod |= controlKey; | ||
| 521 | // if (*outModifiers & Qt::ControlModifier) | ||
| 522 | // tmp_mod |= cmdKey; | ||
| 523 | // if (GetCurrentEventKeyModifiers() & alphaLock) //no Qt mapper | ||
| 524 | // tmp_mod |= alphaLock; | ||
| 525 | // if (*outModifiers & Qt::AltModifier) | ||
| 526 | // tmp_mod |= optionKey; | ||
| 527 | // if (*outModifiers & Qt::KeypadModifier) | ||
| 528 | // tmp_mod |= kEventKeyModifierNumLockMask; | ||
| 529 | // translatedChar = KeyTranslate(keyboard_layout, tmp_mod | keyCode, &tmp_state); | ||
| 530 | // } | ||
| 531 | // { | ||
| 532 | // ByteCount unilen = 0; | ||
| 533 | // if (GetEventParameter(keyEvent, kEventParamKeyUnicodes, typeUnicodeText, 0, 0, &unilen, 0) | ||
| 534 | // == noErr && unilen == 2) { | ||
| 535 | // GetEventParameter(keyEvent, kEventParamKeyUnicodes, typeUnicodeText, 0, unilen, 0, outChar); | ||
| 536 | // } else if (translatedChar) { | ||
| 537 | // static QTextCodec *c = 0; | ||
| 538 | // if (!c) | ||
| 539 | // c = QTextCodec::codecForName("Apple Roman"); | ||
| 540 | // char tmpChar = (char)translatedChar; // **sigh** | ||
| 541 | // *outChar = c->toUnicode(&tmpChar, 1).at(0); | ||
| 542 | // } else { | ||
| 543 | // *qtKey = qt_mac_get_key(*outModifiers, QChar(translatedChar), keyCode); | ||
| 544 | // } | ||
| 545 | // } | ||
| 546 | // } | ||
| 547 | //#endif | ||
| 548 | // if (*qtKey == Qt::Key_unknown) | ||
| 549 | // *qtKey = qt_mac_get_key(*outModifiers, *outChar, keyCode); | ||
| 550 | // return true; | ||
| 551 | //} | ||
| 552 | |||
| 553 | QKeyMapperPrivate::QKeyMapperPrivate() | ||
| 554 | { | ||
| 555 | // memset(keyLayout, 0, sizeof(keyLayout)); | ||
| 556 | // keyboard_layout_format.unicode = 0; | ||
| 557 | //#ifdef Q_OS_MAC32 | ||
| 558 | // keyboard_mode = NullMode; | ||
| 559 | //#else | ||
| 560 | // currentInputSource = 0; | ||
| 561 | //#endif | ||
| 562 | } | ||
| 563 | |||
| 564 | QKeyMapperPrivate::~QKeyMapperPrivate() | ||
| 565 | { | ||
| 566 | // deleteLayouts(); | ||
| 567 | } | ||
| 568 | |||
| 569 | //bool | ||
| 570 | //QKeyMapperPrivate::updateKeyboard() | ||
| 571 | //{ | ||
| 572 | // const UCKeyboardLayout *uchrData = 0; | ||
| 573 | //#ifdef Q_OS_MAC32 | ||
| 574 | // KeyboardLayoutRef keyLayoutRef = 0; | ||
| 575 | // KLGetCurrentKeyboardLayout(&keyLayoutRef); | ||
| 576 | // | ||
| 577 | // if (keyboard_mode != NullMode && currentKeyboardLayout == keyLayoutRef) | ||
| 578 | // return false; | ||
| 579 | // | ||
| 580 | // OSStatus err; | ||
| 581 | // if (keyLayoutRef != 0) { | ||
| 582 | // err = KLGetKeyboardLayoutProperty(keyLayoutRef, kKLuchrData, | ||
| 583 | // const_cast<const void **>(reinterpret_cast<const void **>(&uchrData))); | ||
| 584 | // if (err != noErr) { | ||
| 585 | // qWarning("Qt::internal::unable to get unicode keyboardlayout %ld %s:%d", | ||
| 586 | // long(err), __FILE__, __LINE__); | ||
| 587 | // } | ||
| 588 | // } | ||
| 589 | //#else | ||
| 590 | // QCFType<TISInputSourceRef> source = TISCopyCurrentKeyboardInputSource(); | ||
| 591 | // if (keyboard_mode != NullMode && source == currentInputSource) { | ||
| 592 | // return false; | ||
| 593 | // } | ||
| 594 | // Q_ASSERT(source != 0); | ||
| 595 | // CFDataRef data = static_cast<CFDataRef>(TISGetInputSourceProperty(source, | ||
| 596 | // kTISPropertyUnicodeKeyLayoutData)); | ||
| 597 | // uchrData = data ? reinterpret_cast<const UCKeyboardLayout *>(CFDataGetBytePtr(data)) : 0; | ||
| 598 | //#endif | ||
| 599 | // | ||
| 600 | // keyboard_kind = LMGetKbdType(); | ||
| 601 | // if (uchrData) { | ||
| 602 | // keyboard_layout_format.unicode = uchrData; | ||
| 603 | // keyboard_mode = UnicodeMode; | ||
| 604 | // } | ||
| 605 | //#ifdef Q_OS_MAC32 | ||
| 606 | // else { | ||
| 607 | // void *happy; | ||
| 608 | // err = KLGetKeyboardLayoutProperty(keyLayoutRef, kKLKCHRData, | ||
| 609 | // const_cast<const void **>(reinterpret_cast<void **>(&happy))); | ||
| 610 | // if (err != noErr) { | ||
| 611 | // qFatal("Qt::internal::unable to get non-unicode layout, cannot procede %ld %s:%d", | ||
| 612 | // long(err), __FILE__, __LINE__); | ||
| 613 | // } | ||
| 614 | // keyboard_layout_format.other = happy; | ||
| 615 | // keyboard_mode = OtherMode; | ||
| 616 | // } | ||
| 617 | // | ||
| 618 | // currentKeyboardLayout = keyLayoutRef; | ||
| 619 | //#else | ||
| 620 | // currentInputSource = source; | ||
| 621 | //#endif | ||
| 622 | // keyboard_dead = 0; | ||
| 623 | // CFStringRef iso639Code; | ||
| 624 | //#ifdef Q_OS_MAC32 | ||
| 625 | //# ifndef kKLLanguageCode | ||
| 626 | //# define kKLLanguageCode 9 | ||
| 627 | //# endif | ||
| 628 | // KLGetKeyboardLayoutProperty(currentKeyboardLayout, kKLLanguageCode, | ||
| 629 | // reinterpret_cast<const void **>(&iso639Code)); | ||
| 630 | //#else | ||
| 631 | // CFArrayRef array = static_cast<CFArrayRef>(TISGetInputSourceProperty(currentInputSource, kTISPropertyInputSourceLanguages)); | ||
| 632 | // iso639Code = static_cast<CFStringRef>(CFArrayGetValueAtIndex(array, 0)); // Actually a RFC3066bis, but it's close enough | ||
| 633 | //#endif | ||
| 634 | // if (iso639Code) { | ||
| 635 | // keyboardInputLocale = QLocale(QCFString::toQString(iso639Code)); | ||
| 636 | // QString monday = keyboardInputLocale.dayName(1); | ||
| 637 | // bool rtl = false; | ||
| 638 | // for (int i = 0; i < monday.length(); ++i) { | ||
| 639 | // switch (monday.at(i).direction()) { | ||
| 640 | // default: | ||
| 641 | // break; | ||
| 642 | // case QChar::DirR: | ||
| 643 | // case QChar::DirAL: | ||
| 644 | // case QChar::DirRLE: | ||
| 645 | // case QChar::DirRLO: | ||
| 646 | // rtl = true; | ||
| 647 | // break; | ||
| 648 | // } | ||
| 649 | // if (rtl) | ||
| 650 | // break; | ||
| 651 | // } | ||
| 652 | // keyboardInputDirection = rtl ? Qt::RightToLeft : Qt::LeftToRight; | ||
| 653 | // } else { | ||
| 654 | // keyboardInputLocale = QLocale::c(); | ||
| 655 | // keyboardInputDirection = Qt::LeftToRight; | ||
| 656 | // } | ||
| 657 | // return true; | ||
| 658 | //} | ||
| 659 | // | ||
| 660 | //void | ||
| 661 | //QKeyMapperPrivate::deleteLayouts() | ||
| 662 | //{ | ||
| 663 | // keyboard_mode = NullMode; | ||
| 664 | // for (int i = 0; i < 255; ++i) { | ||
| 665 | // if (keyLayout[i]) { | ||
| 666 | // delete keyLayout[i]; | ||
| 667 | // keyLayout[i] = 0; | ||
| 668 | // } | ||
| 669 | // } | ||
| 670 | //} | ||
| 671 | |||
| 672 | void QKeyMapperPrivate::clearMappings() | ||
| 673 | { | ||
| 674 | // deleteLayouts(); | ||
| 675 | // updateKeyboard(); | ||
| 676 | } | ||
| 677 | |||
| 678 | QList<int> QKeyMapperPrivate::possibleKeys(QKeyEvent *e) | ||
| 679 | { | ||
| 680 | // QList<int> ret; | ||
| 681 | // | ||
| 682 | // KeyboardLayoutItem *kbItem = keyLayout[e->nativeVirtualKey()]; | ||
| 683 | // if (!kbItem) // Key is not in any keyboard layout (e.g. eisu-key on Japanese keyboard) | ||
| 684 | // return ret; | ||
| 685 | // | ||
| 686 | // int baseKey = kbItem->qtKey[0]; | ||
| 687 | // Qt::KeyboardModifiers keyMods = e->modifiers(); | ||
| 688 | // ret << int(baseKey + keyMods); // The base key is _always_ valid, of course | ||
| 689 | // | ||
| 690 | // for (int i = 1; i < 8; ++i) { | ||
| 691 | // Qt::KeyboardModifiers neededMods = ModsTbl[i]; | ||
| 692 | // int key = kbItem->qtKey[i]; | ||
| 693 | // if (key && key != baseKey && ((keyMods & neededMods) == neededMods)) | ||
| 694 | // ret << int(key + (keyMods & ~neededMods)); | ||
| 695 | // } | ||
| 696 | // | ||
| 697 | // return ret; | ||
| 698 | } | ||
| 699 | |||
| 700 | //bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef er, EventRef event, | ||
| 701 | // void *info, bool grab) | ||
| 702 | //{ | ||
| 703 | // Q_ASSERT(GetEventClass(event) == kEventClassKeyboard); | ||
| 704 | // bool handled_event=true; | ||
| 705 | // UInt32 ekind = GetEventKind(event); | ||
| 706 | // | ||
| 707 | // // unfortunately modifiers changed event looks quite different, so I have a separate | ||
| 708 | // // code path | ||
| 709 | // if (ekind == kEventRawKeyModifiersChanged) { | ||
| 710 | // //figure out changed modifiers, wish Apple would just send a delta | ||
| 711 | // UInt32 modifiers = 0; | ||
| 712 | // GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0, | ||
| 713 | // sizeof(modifiers), 0, &modifiers); | ||
| 714 | // qt_mac_send_modifiers_changed(modifiers, widget); | ||
| 715 | // return true; | ||
| 716 | // } | ||
| 717 | // | ||
| 718 | // if (qApp->inputContext() && qApp->inputContext()->isComposing()) { | ||
| 719 | // if (ekind == kEventRawKeyDown) { | ||
| 720 | // QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext()); | ||
| 721 | // if (context) | ||
| 722 | // context->setLastKeydownEvent(event); | ||
| 723 | // } | ||
| 724 | // return false; | ||
| 725 | // } | ||
| 726 | // //get modifiers | ||
| 727 | // Qt::KeyboardModifiers modifiers; | ||
| 728 | // int qtKey; | ||
| 729 | // QChar ourChar; | ||
| 730 | // if (translateKeyEventInternal(er, event, &qtKey, &ourChar, &modifiers, | ||
| 731 | // &handled_event) == false) | ||
| 732 | // return handled_event; | ||
| 733 | // QString text(ourChar); | ||
| 734 | // /* This is actually wrong - but unfortunatly it is the best that can be | ||
| 735 | // done for now because of the Control/Meta mapping problems */ | ||
| 736 | // if (modifiers & (Qt::ControlModifier | Qt::MetaModifier) | ||
| 737 | // && !qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) { | ||
| 738 | // text = QString(); | ||
| 739 | // } | ||
| 740 | // | ||
| 741 | // | ||
| 742 | // if (widget) { | ||
| 743 | //#ifndef QT_MAC_USE_COCOA | ||
| 744 | // Q_UNUSED(info); | ||
| 745 | // // Try not to call "other" event handlers if we have a popup, | ||
| 746 | // // However, if the key has text | ||
| 747 | // // then we should pass it along because otherwise then people | ||
| 748 | // // can use input method stuff. | ||
| 749 | // if (!qApp->activePopupWidget() | ||
| 750 | // || (qApp->activePopupWidget() && !text.isEmpty())) { | ||
| 751 | // //Find out if someone else wants the event, namely | ||
| 752 | // //is it of use to text services? If so we won't bother | ||
| 753 | // //with a QKeyEvent. | ||
| 754 | // qt_mac_eat_unicode_key = false; | ||
| 755 | // if (er) | ||
| 756 | // CallNextEventHandler(er, event); | ||
| 757 | // extern bool qt_mac_menubar_is_open(); | ||
| 758 | // if (qt_mac_eat_unicode_key || qt_mac_menubar_is_open()) { | ||
| 759 | // return true; | ||
| 760 | // } | ||
| 761 | // } | ||
| 762 | //#endif | ||
| 763 | // // Try to compress key events. | ||
| 764 | // if (!text.isEmpty() && widget->testAttribute(Qt::WA_KeyCompression)) { | ||
| 765 | // EventTime lastTime = GetEventTime(event); | ||
| 766 | // for (;;) { | ||
| 767 | // EventRef releaseEvent = FindSpecificEventInQueue(GetMainEventQueue(), | ||
| 768 | // qt_KeyEventComparatorProc, | ||
| 769 | // (void*)kEventRawKeyUp); | ||
| 770 | // if (!releaseEvent) | ||
| 771 | // break; | ||
| 772 | // const EventTime releaseTime = GetEventTime(releaseEvent); | ||
| 773 | // if (releaseTime < lastTime) | ||
| 774 | // break; | ||
| 775 | // lastTime = releaseTime; | ||
| 776 | // | ||
| 777 | // EventRef pressEvent = FindSpecificEventInQueue(GetMainEventQueue(), | ||
| 778 | // qt_KeyEventComparatorProc, | ||
| 779 | // (void*)kEventRawKeyDown); | ||
| 780 | // if (!pressEvent) | ||
| 781 | // break; | ||
| 782 | // const EventTime pressTime = GetEventTime(pressEvent); | ||
| 783 | // if (pressTime < lastTime) | ||
| 784 | // break; | ||
| 785 | // lastTime = pressTime; | ||
| 786 | // | ||
| 787 | // Qt::KeyboardModifiers compressMod; | ||
| 788 | // int compressQtKey = 0; | ||
| 789 | // QChar compressChar; | ||
| 790 | // if (translateKeyEventInternal(er, pressEvent, | ||
| 791 | // &compressQtKey, &compressChar, &compressMod, 0) | ||
| 792 | // == false) { | ||
| 793 | // break; | ||
| 794 | // } | ||
| 795 | // // Copied from qapplication_x11.cpp (change both). | ||
| 796 | // | ||
| 797 | // bool stopCompression = | ||
| 798 | // // 1) misc keys | ||
| 799 | // (compressQtKey >= Qt::Key_Escape && compressQtKey <= Qt::Key_SysReq) | ||
| 800 | // // 2) cursor movement | ||
| 801 | // || (compressQtKey >= Qt::Key_Home && compressQtKey <= Qt::Key_PageDown) | ||
| 802 | // // 3) extra keys | ||
| 803 | // || (compressQtKey >= Qt::Key_Super_L && compressQtKey <= Qt::Key_Direction_R) | ||
| 804 | // // 4) something that a) doesn't translate to text or b) translates | ||
| 805 | // // to newline text | ||
| 806 | // || (compressQtKey == 0) | ||
| 807 | // || (compressChar == QLatin1Char('\n')) | ||
| 808 | // || (compressQtKey == Qt::Key_unknown); | ||
| 809 | // | ||
| 810 | // if (compressMod == modifiers && !compressChar.isNull() && !stopCompression) { | ||
| 811 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 812 | // qDebug("compressing away %c", compressChar.toLatin1()); | ||
| 813 | //#endif | ||
| 814 | // text += compressChar; | ||
| 815 | // // Clean up | ||
| 816 | // RemoveEventFromQueue(GetMainEventQueue(), releaseEvent); | ||
| 817 | // RemoveEventFromQueue(GetMainEventQueue(), pressEvent); | ||
| 818 | // } else { | ||
| 819 | //#ifdef DEBUG_KEY_BINDINGS | ||
| 820 | // qDebug("stoping compression.."); | ||
| 821 | //#endif | ||
| 822 | // break; | ||
| 823 | // } | ||
| 824 | // } | ||
| 825 | // } | ||
| 826 | // | ||
| 827 | // // There is no way to get the scan code from carbon. But we cannot use the value 0, since | ||
| 828 | // // it indicates that the event originates from somewhere else than the keyboard | ||
| 829 | // UInt32 macScanCode = 1; | ||
| 830 | // UInt32 macVirtualKey = 0; | ||
| 831 | // GetEventParameter(event, kEventParamKeyCode, typeUInt32, 0, sizeof(macVirtualKey), 0, &macVirtualKey); | ||
| 832 | // UInt32 macModifiers = 0; | ||
| 833 | // GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0, | ||
| 834 | // sizeof(macModifiers), 0, &macModifiers); | ||
| 835 | // handled_event = QKeyMapper::sendKeyEvent(widget, grab, | ||
| 836 | // (ekind == kEventRawKeyUp) ? QEvent::KeyRelease : QEvent::KeyPress, | ||
| 837 | // qtKey, modifiers, text, ekind == kEventRawKeyRepeat, 0, | ||
| 838 | // macScanCode, macVirtualKey, macModifiers | ||
| 839 | //#ifdef QT_MAC_USE_COCOA | ||
| 840 | // ,static_cast<bool *>(info) | ||
| 841 | //#endif | ||
| 842 | // ); | ||
| 843 | // } | ||
| 844 | // return handled_event; | ||
| 845 | //} | ||
| 846 | // | ||
| 847 | //void | ||
| 848 | //QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *) | ||
| 849 | //{ | ||
| 850 | // UInt32 macVirtualKey = 0; | ||
| 851 | // GetEventParameter(event, kEventParamKeyCode, typeUInt32, 0, sizeof(macVirtualKey), 0, &macVirtualKey); | ||
| 852 | // if (updateKeyboard()) | ||
| 853 | // QKeyMapper::changeKeyboard(); | ||
| 854 | // else if (keyLayout[macVirtualKey]) | ||
| 855 | // return; | ||
| 856 | // | ||
| 857 | // UniCharCount buffer_size = 10; | ||
| 858 | // UniChar buffer[buffer_size]; | ||
| 859 | // keyLayout[macVirtualKey] = new KeyboardLayoutItem; | ||
| 860 | // for (int i = 0; i < 16; ++i) { | ||
| 861 | // UniCharCount out_buffer_size = 0; | ||
| 862 | // keyLayout[macVirtualKey]->qtKey[i] = 0; | ||
| 863 | //#ifdef Q_WS_MAC32 | ||
| 864 | // if (keyboard_mode == UnicodeMode) { | ||
| 865 | //#endif | ||
| 866 | // const UInt32 keyModifier = ((qt_mac_get_mac_modifiers(ModsTbl[i]) >> 8) & 0xFF); | ||
| 867 | // OSStatus err = UCKeyTranslate(keyboard_layout_format.unicode, macVirtualKey, kUCKeyActionDown, keyModifier, | ||
| 868 | // keyboard_kind, 0, &keyboard_dead, buffer_size, &out_buffer_size, buffer); | ||
| 869 | // if (err == noErr && out_buffer_size) { | ||
| 870 | // const QChar unicode(buffer[0]); | ||
| 871 | // int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); | ||
| 872 | // if (qtkey == Qt::Key_unknown) | ||
| 873 | // qtkey = unicode.unicode(); | ||
| 874 | // keyLayout[macVirtualKey]->qtKey[i] = qtkey; | ||
| 875 | // } | ||
| 876 | //#ifdef Q_WS_MAC32 | ||
| 877 | // } else { | ||
| 878 | // const UInt32 keyModifier = (qt_mac_get_mac_modifiers(ModsTbl[i])); | ||
| 879 | // | ||
| 880 | // uchar translatedChar = KeyTranslate(keyboard_layout_format.other, keyModifier | macVirtualKey, &keyboard_dead); | ||
| 881 | // if (translatedChar) { | ||
| 882 | // static QTextCodec *c = 0; | ||
| 883 | // if (!c) | ||
| 884 | // c = QTextCodec::codecForName("Apple Roman"); | ||
| 885 | // const QChar unicode(c->toUnicode((const char *)&translatedChar, 1).at(0)); | ||
| 886 | // int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); | ||
| 887 | // if (qtkey == Qt::Key_unknown) | ||
| 888 | // qtkey = unicode.unicode(); | ||
| 889 | // keyLayout[macVirtualKey]->qtKey[i] = qtkey; | ||
| 890 | // } | ||
| 891 | // } | ||
| 892 | //#endif | ||
| 893 | // } | ||
| 894 | //#ifdef DEBUG_KEY_MAPS | ||
| 895 | // qDebug("updateKeyMap for virtual key = 0x%02x!", (uint)macVirtualKey); | ||
| 896 | // for (int i = 0; i < 16; ++i) { | ||
| 897 | // qDebug(" [%d] (%d,0x%02x,'%c')", i, | ||
| 898 | // keyLayout[macVirtualKey]->qtKey[i], | ||
| 899 | // keyLayout[macVirtualKey]->qtKey[i], | ||
| 900 | // keyLayout[macVirtualKey]->qtKey[i]); | ||
| 901 | // } | ||
| 902 | //#endif | ||
| 903 | //} | ||
| 904 | // | ||
| 905 | //bool | ||
| 906 | //QKeyMapper::sendKeyEvent(QWidget *widget, bool grab, | ||
| 907 | // QEvent::Type type, int code, Qt::KeyboardModifiers modifiers, | ||
| 908 | // const QString &text, bool autorepeat, int count, | ||
| 909 | // quint32 nativeScanCode, quint32 nativeVirtualKey, | ||
| 910 | // quint32 nativeModifiers, bool *isAccepted) | ||
| 911 | //{ | ||
| 912 | // Q_UNUSED(count); | ||
| 913 | // if (widget && widget->isEnabled()) { | ||
| 914 | // bool key_event = true; | ||
| 915 | //#if defined(QT3_SUPPORT) && !defined(QT_NO_SHORTCUT) | ||
| 916 | // if (type == QEvent::KeyPress && !grab | ||
| 917 | // && QApplicationPrivate::instance()->use_compat()) { | ||
| 918 | // QKeyEventEx accel_ev(type, code, modifiers, | ||
| 919 | // text, autorepeat, qMax(1, int(text.length())), | ||
| 920 | // nativeScanCode, nativeVirtualKey, nativeModifiers); | ||
| 921 | // if (QApplicationPrivate::instance()->qt_tryAccelEvent(widget, &accel_ev)) { | ||
| 922 | //#if defined(DEBUG_KEY_BINDINGS) || defined(DEBUG_KEY_BINDINGS_MODIFIERS) | ||
| 923 | // qDebug("KeyEvent: %s::%s consumed Accel: %s", | ||
| 924 | // widget ? widget->metaObject()->className() : "none", | ||
| 925 | // widget ? widget->objectName().toLatin1().constData() : "", | ||
| 926 | // text.toLatin1().constData()); | ||
| 927 | //#endif | ||
| 928 | // key_event = false; | ||
| 929 | // } else { | ||
| 930 | // if (accel_ev.isAccepted()) { | ||
| 931 | //#if defined(DEBUG_KEY_BINDINGS) || defined(DEBUG_KEY_BINDINGS_MODIFIERS) | ||
| 932 | // qDebug("KeyEvent: %s::%s overrode Accel: %s", | ||
| 933 | // widget ? widget->metaObject()->className() : "none", | ||
| 934 | // widget ? widget->objectName().toLatin1().constData() : "", | ||
| 935 | // text.toLatin1().constData()); | ||
| 936 | //#endif | ||
| 937 | // } | ||
| 938 | // } | ||
| 939 | // } | ||
| 940 | //#else | ||
| 941 | //Q_UNUSED(grab); | ||
| 942 | //#endif // QT3_SUPPORT && !QT_NO_SHORTCUT | ||
| 943 | // if (key_event) { | ||
| 944 | //#if defined(DEBUG_KEY_BINDINGS) || defined(DEBUG_KEY_BINDINGS_MODIFIERS) | ||
| 945 | // qDebug("KeyEvent: Sending %s to %s::%s: %s 0x%08x%s", | ||
| 946 | // type == QEvent::KeyRelease ? "KeyRelease" : "KeyPress", | ||
| 947 | // widget ? widget->metaObject()->className() : "none", | ||
| 948 | // widget ? widget->objectName().toLatin1().constData() : "", | ||
| 949 | // text.toLatin1().constData(), int(modifiers), | ||
| 950 | // autorepeat ? " Repeat" : ""); | ||
| 951 | //#endif | ||
| 952 | // QKeyEventEx ke(type, code, modifiers, text, autorepeat, qMax(1, text.length()), | ||
| 953 | // nativeScanCode, nativeVirtualKey, nativeModifiers); | ||
| 954 | // bool retMe = qt_sendSpontaneousEvent(widget,&ke); | ||
| 955 | // if (isAccepted) | ||
| 956 | // *isAccepted = ke.isAccepted(); | ||
| 957 | // return retMe; | ||
| 958 | // } | ||
| 959 | // } | ||
| 960 | // return false; | ||
| 961 | //} | ||
| 962 | |||
| 963 | QT_END_NAMESPACE |
src/gui/kernel/qmacdefines_iphone.h
(170 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | /* | ||
| 77 | * qmacdefines_mac_p.h | ||
| 78 | * All the defines you'll ever need for Qt/Mac :-) | ||
| 79 | */ | ||
| 80 | |||
| 81 | /* This is just many defines. Therefore it doesn't need things like: | ||
| 82 | QT_BEGIN_HEADER | ||
| 83 | |||
| 84 | QT_BEGIN_NAMESPACE | ||
| 85 | |||
| 86 | QT_MODULE(Gui) | ||
| 87 | |||
| 88 | QT_END_NAMESPACE | ||
| 89 | |||
| 90 | QT_END_HEADER | ||
| 91 | |||
| 92 | Yes, it is an informative comment ;-) | ||
| 93 | */ | ||
| 94 | |||
| 95 | #include <QtCore/qglobal.h> | ||
| 96 | |||
| 97 | #undef OLD_DEBUG | ||
| 98 | #ifdef DEBUG | ||
| 99 | # define OLD_DEBUG DEBUG | ||
| 100 | # undef DEBUG | ||
| 101 | #endif | ||
| 102 | #define DEBUG 0 | ||
| 103 | #ifdef qDebug | ||
| 104 | # define old_qDebug qDebug | ||
| 105 | # undef qDebug | ||
| 106 | #endif | ||
| 107 | |||
| 108 | //#ifdef __LP64__ | ||
| 109 | //typedef signed int OSStatus; | ||
| 110 | //#else | ||
| 111 | //typedef signed long OSStatus; | ||
| 112 | //#endif | ||
| 113 | |||
| 114 | #ifdef __OBJC__ | ||
| 115 | # ifdef slots | ||
| 116 | # define old_slots slots | ||
| 117 | # undef slots | ||
| 118 | # endif | ||
| 119 | #include <UiKit/UIKit.h> | ||
| 120 | # ifdef old_slots | ||
| 121 | # undef slots | ||
| 122 | # define slots | ||
| 123 | # undef old_slots | ||
| 124 | # endif | ||
| 125 | #endif | ||
| 126 | // typedef struct OpaqueEventHandlerCallRef * EventHandlerCallRef; | ||
| 127 | // typedef struct OpaqueEventRef * EventRef; | ||
| 128 | // typedef struct OpaqueMenuRef * MenuRef; | ||
| 129 | // typedef struct OpaquePasteboardRef* PasteboardRef; | ||
| 130 | // typedef struct OpaqueRgnHandle * RgnHandle; | ||
| 131 | // typedef const struct __HIShape *HIShapeRef; | ||
| 132 | // typedef struct __HIShape *HIMutableShapeRef; | ||
| 133 | // typedef struct CGRect CGRect; | ||
| 134 | // typedef struct CGImage *CGImageRef; | ||
| 135 | // typedef struct CGContext *CGContextRef; | ||
| 136 | // typedef struct GDevice * GDPtr; | ||
| 137 | // typedef GDPtr * GDHandle; | ||
| 138 | // typedef struct OpaqueIconRef * IconRef; | ||
| 139 | //# ifdef __OBJC__ | ||
| 140 | // typedef NSWindow* OSWindowRef; | ||
| 141 | // typedef NSView *OSViewRef; | ||
| 142 | // typedef NSMenu *OSMenuRef; | ||
| 143 | // typedef NSEvent *OSEventRef; | ||
| 144 | //# else | ||
| 145 | // typedef void *OSWindowRef; | ||
| 146 | // typedef void *OSViewRef; | ||
| 147 | // typedef void *OSMenuRef; | ||
| 148 | // typedef void *OSEventRef; | ||
| 149 | //# endif | ||
| 150 | |||
| 151 | //typedef PasteboardRef OSPasteboardRef; | ||
| 152 | //typedef struct AEDesc AEDescList; | ||
| 153 | //typedef AEDescList AERecord; | ||
| 154 | //typedef AERecord AppleEvent; | ||
| 155 | |||
| 156 | #ifdef check | ||
| 157 | #undef check | ||
| 158 | #endif | ||
| 159 | |||
| 160 | #undef DEBUG | ||
| 161 | #ifdef OLD_DEBUG | ||
| 162 | # define DEBUG OLD_DEBUG | ||
| 163 | # undef OLD_DEBUG | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifdef old_qDebug | ||
| 167 | # undef qDebug | ||
| 168 | # define qDebug QT_NO_QDEBUG_MACRO | ||
| 169 | # undef old_qDebug | ||
| 170 | #endif |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | //#include "qmacgesturerecognizer_mac_p.h" | ||
| 43 | //#include "qgesture.h" | ||
| 44 | //#include "qgesture_p.h" | ||
| 45 | //#include "qevent.h" | ||
| 46 | //#include "qevent_p.h" | ||
| 47 | //#include "qwidget.h" | ||
| 48 | //#include "qdebug.h" | ||
| 49 | // | ||
| 50 | //QT_BEGIN_NAMESPACE | ||
| 51 | // | ||
| 52 | //QMacSwipeGestureRecognizer::QMacSwipeGestureRecognizer() | ||
| 53 | //{ | ||
| 54 | //} | ||
| 55 | // | ||
| 56 | //QGesture *QMacSwipeGestureRecognizer::create(QObject * /*target*/) | ||
| 57 | //{ | ||
| 58 | // return new QSwipeGesture; | ||
| 59 | //} | ||
| 60 | // | ||
| 61 | //QGestureRecognizer::Result | ||
| 62 | //QMacSwipeGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) | ||
| 63 | //{ | ||
| 64 | // if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { | ||
| 65 | // QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); | ||
| 66 | // switch (ev->gestureType) { | ||
| 67 | // case QNativeGestureEvent::Swipe: { | ||
| 68 | // QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture); | ||
| 69 | // g->setSwipeAngle(ev->angle); | ||
| 70 | // return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; | ||
| 71 | // break; } | ||
| 72 | // default: | ||
| 73 | // break; | ||
| 74 | // } | ||
| 75 | // } | ||
| 76 | // | ||
| 77 | // return QGestureRecognizer::Ignore; | ||
| 78 | //} | ||
| 79 | // | ||
| 80 | //void QMacSwipeGestureRecognizer::reset(QGesture *gesture) | ||
| 81 | //{ | ||
| 82 | // QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture); | ||
| 83 | // g->setSwipeAngle(0); | ||
| 84 | // QGestureRecognizer::reset(gesture); | ||
| 85 | //} | ||
| 86 | // | ||
| 87 | ////////////////////////////////////////////////////////////////////////// | ||
| 88 | // | ||
| 89 | //QMacPinchGestureRecognizer::QMacPinchGestureRecognizer() | ||
| 90 | //{ | ||
| 91 | //} | ||
| 92 | // | ||
| 93 | //QGesture *QMacPinchGestureRecognizer::create(QObject * /*target*/) | ||
| 94 | //{ | ||
| 95 | // return new QPinchGesture; | ||
| 96 | //} | ||
| 97 | // | ||
| 98 | //QGestureRecognizer::Result | ||
| 99 | //QMacPinchGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) | ||
| 100 | //{ | ||
| 101 | // if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { | ||
| 102 | // QPinchGesture *g = static_cast<QPinchGesture *>(gesture); | ||
| 103 | // QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event); | ||
| 104 | // switch(ev->gestureType) { | ||
| 105 | // case QNativeGestureEvent::GestureBegin: | ||
| 106 | // reset(gesture); | ||
| 107 | // g->setStartCenterPoint(static_cast<QWidget*>(obj)->mapFromGlobal(ev->position)); | ||
| 108 | // g->setCenterPoint(g->startCenterPoint()); | ||
| 109 | // g->setChangeFlags(QPinchGesture::CenterPointChanged); | ||
| 110 | // g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); | ||
| 111 | // return QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint; | ||
| 112 | // case QNativeGestureEvent::Rotate: { | ||
| 113 | // g->setLastScaleFactor(g->scaleFactor()); | ||
| 114 | // g->setLastRotationAngle(g->rotationAngle()); | ||
| 115 | // g->setRotationAngle(g->rotationAngle() + ev->percentage); | ||
| 116 | // g->setChangeFlags(QPinchGesture::RotationAngleChanged); | ||
| 117 | // g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); | ||
| 118 | // return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; | ||
| 119 | // } | ||
| 120 | // case QNativeGestureEvent::Zoom: | ||
| 121 | // g->setLastScaleFactor(g->scaleFactor()); | ||
| 122 | // g->setLastRotationAngle(g->rotationAngle()); | ||
| 123 | // g->setScaleFactor(g->scaleFactor() * (1 + ev->percentage)); | ||
| 124 | // g->setChangeFlags(QPinchGesture::ScaleFactorChanged); | ||
| 125 | // g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); | ||
| 126 | // return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; | ||
| 127 | // case QNativeGestureEvent::GestureEnd: | ||
| 128 | // return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; | ||
| 129 | // default: | ||
| 130 | // break; | ||
| 131 | // } | ||
| 132 | // } | ||
| 133 | // | ||
| 134 | // return QGestureRecognizer::Ignore; | ||
| 135 | //} | ||
| 136 | // | ||
| 137 | //void QMacPinchGestureRecognizer::reset(QGesture *gesture) | ||
| 138 | //{ | ||
| 139 | // QPinchGesture *g = static_cast<QPinchGesture *>(gesture); | ||
| 140 | // g->setChangeFlags(0); | ||
| 141 | // g->setTotalChangeFlags(0); | ||
| 142 | // g->setScaleFactor(1.0f); | ||
| 143 | // g->setTotalScaleFactor(1.0f); | ||
| 144 | // g->setLastScaleFactor(1.0f); | ||
| 145 | // g->setRotationAngle(0.0f); | ||
| 146 | // g->setTotalRotationAngle(0.0f); | ||
| 147 | // g->setLastRotationAngle(0.0f); | ||
| 148 | // g->setCenterPoint(QPointF()); | ||
| 149 | // g->setStartCenterPoint(QPointF()); | ||
| 150 | // g->setLastCenterPoint(QPointF()); | ||
| 151 | // QGestureRecognizer::reset(gesture); | ||
| 152 | //} | ||
| 153 | // | ||
| 154 | ////////////////////////////////////////////////////////////////////////// | ||
| 155 | // | ||
| 156 | //#if defined(QT_MAC_USE_COCOA) | ||
| 157 | // | ||
| 158 | //QMacPanGestureRecognizer::QMacPanGestureRecognizer() : _panCanceled(true) | ||
| 159 | //{ | ||
| 160 | //} | ||
| 161 | // | ||
| 162 | //QGesture *QMacPanGestureRecognizer::create(QObject *target) | ||
| 163 | //{ | ||
| 164 | // if (!target) | ||
| 165 | // return new QPanGesture; | ||
| 166 | // | ||
| 167 | // if (QWidget *w = qobject_cast<QWidget *>(target)) { | ||
| 168 | // w->setAttribute(Qt::WA_AcceptTouchEvents); | ||
| 169 | // w->setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); | ||
| 170 | // return new QPanGesture; | ||
| 171 | // } | ||
| 172 | // return 0; | ||
| 173 | //} | ||
| 174 | // | ||
| 175 | //QGestureRecognizer::Result | ||
| 176 | //QMacPanGestureRecognizer::recognize(QGesture *gesture, QObject *target, QEvent *event) | ||
| 177 | //{ | ||
| 178 | // const int panBeginDelay = 300; | ||
| 179 | // const int panBeginRadius = 3; | ||
| 180 | // | ||
| 181 | // QPanGesture *g = static_cast<QPanGesture *>(gesture); | ||
| 182 | // | ||
| 183 | // switch (event->type()) { | ||
| 184 | // case QEvent::TouchBegin: { | ||
| 185 | // const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); | ||
| 186 | // if (ev->touchPoints().size() == 1) { | ||
| 187 | // reset(gesture); | ||
| 188 | // _startPos = QCursor::pos(); | ||
| 189 | // _panTimer.start(panBeginDelay, target); | ||
| 190 | // _panCanceled = false; | ||
| 191 | // return QGestureRecognizer::MayBeGesture; | ||
| 192 | // } | ||
| 193 | // break;} | ||
| 194 | // case QEvent::TouchEnd: { | ||
| 195 | // if (_panCanceled) | ||
| 196 | // break; | ||
| 197 | // | ||
| 198 | // const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); | ||
| 199 | // if (ev->touchPoints().size() == 1) | ||
| 200 | // return QGestureRecognizer::FinishGesture; | ||
| 201 | // break;} | ||
| 202 | // case QEvent::TouchUpdate: { | ||
| 203 | // if (_panCanceled) | ||
| 204 | // break; | ||
| 205 | // | ||
| 206 | // const QTouchEvent *ev = static_cast<const QTouchEvent*>(event); | ||
| 207 | // if (ev->touchPoints().size() == 1) { | ||
| 208 | // if (_panTimer.isActive()) { | ||
| 209 | // // INVARIANT: Still in maybeGesture. Check if the user | ||
| 210 | // // moved his finger so much that it makes sense to cancel the pan: | ||
| 211 | // const QPointF p = QCursor::pos(); | ||
| 212 | // if ((p - _startPos).manhattanLength() > panBeginRadius) { | ||
| 213 | // _panCanceled = true; | ||
| 214 | // _panTimer.stop(); | ||
| 215 | // return QGestureRecognizer::CancelGesture; | ||
| 216 | // } | ||
| 217 | // } else { | ||
| 218 | // const QPointF p = QCursor::pos(); | ||
| 219 | // const QPointF posOffset = p - _startPos; | ||
| 220 | // g->setLastOffset(g->offset()); | ||
| 221 | // g->setOffset(QPointF(posOffset.x(), posOffset.y())); | ||
| 222 | // return QGestureRecognizer::TriggerGesture; | ||
| 223 | // } | ||
| 224 | // } else if (_panTimer.isActive()) { | ||
| 225 | // // I only want to cancel the pan if the user is pressing | ||
| 226 | // // more than one finger, and the pan hasn't started yet: | ||
| 227 | // _panCanceled = true; | ||
| 228 | // _panTimer.stop(); | ||
| 229 | // return QGestureRecognizer::CancelGesture; | ||
| 230 | // } | ||
| 231 | // break;} | ||
| 232 | // case QEvent::Timer: { | ||
| 233 | // QTimerEvent *ev = static_cast<QTimerEvent *>(event); | ||
| 234 | // if (ev->timerId() == _panTimer.timerId()) { | ||
| 235 | // _panTimer.stop(); | ||
| 236 | // if (_panCanceled) | ||
| 237 | // break; | ||
| 238 | // // Begin new pan session! | ||
| 239 | // _startPos = QCursor::pos(); | ||
| 240 | // return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; | ||
| 241 | // } | ||
| 242 | // break; } | ||
| 243 | // default: | ||
| 244 | // break; | ||
| 245 | // } | ||
| 246 | // | ||
| 247 | // return QGestureRecognizer::Ignore; | ||
| 248 | //} | ||
| 249 | // | ||
| 250 | //void QMacPanGestureRecognizer::reset(QGesture *gesture) | ||
| 251 | //{ | ||
| 252 | // QPanGesture *g = static_cast<QPanGesture *>(gesture); | ||
| 253 | // _startPos = QPointF(); | ||
| 254 | // _panCanceled = true; | ||
| 255 | // g->setOffset(QPointF(0, 0)); | ||
| 256 | // g->setLastOffset(QPointF(0, 0)); | ||
| 257 | // g->setAcceleration(qreal(1)); | ||
| 258 | // QGestureRecognizer::reset(gesture); | ||
| 259 | //} | ||
| 260 | //#endif // QT_MAC_USE_COCOA | ||
| 261 | // | ||
| 262 | //QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | //#ifndef QMACSWIPEGESTURERECOGNIZER_MAC_P_H | ||
| 43 | //#define QMACSWIPEGESTURERECOGNIZER_MAC_P_H | ||
| 44 | |||
| 45 | // | ||
| 46 | // W A R N I N G | ||
| 47 | // ------------- | ||
| 48 | // | ||
| 49 | // This file is not part of the Qt API. It exists for the convenience | ||
| 50 | // of other Qt classes. This header file may change from version to | ||
| 51 | // version without notice, or even be removed. | ||
| 52 | // | ||
| 53 | // We mean it. | ||
| 54 | // | ||
| 55 | // | ||
| 56 | //#include "qtimer.h" | ||
| 57 | //#include "qpoint.h" | ||
| 58 | //#include "qgesturerecognizer.h" | ||
| 59 | // | ||
| 60 | //QT_BEGIN_NAMESPACE | ||
| 61 | // | ||
| 62 | //class QMacSwipeGestureRecognizer : public QGestureRecognizer | ||
| 63 | //{ | ||
| 64 | //public: | ||
| 65 | // QMacSwipeGestureRecognizer(); | ||
| 66 | // | ||
| 67 | // QGesture *create(QObject *target); | ||
| 68 | // QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); | ||
| 69 | // void reset(QGesture *gesture); | ||
| 70 | //}; | ||
| 71 | // | ||
| 72 | //class QMacPinchGestureRecognizer : public QGestureRecognizer | ||
| 73 | //{ | ||
| 74 | //public: | ||
| 75 | // QMacPinchGestureRecognizer(); | ||
| 76 | // | ||
| 77 | // QGesture *create(QObject *target); | ||
| 78 | // QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); | ||
| 79 | // void reset(QGesture *gesture); | ||
| 80 | //}; | ||
| 81 | // | ||
| 82 | //#if defined(QT_MAC_USE_COCOA) | ||
| 83 | // | ||
| 84 | //class QMacPanGestureRecognizer : public QObject, public QGestureRecognizer | ||
| 85 | //{ | ||
| 86 | //public: | ||
| 87 | // QMacPanGestureRecognizer(); | ||
| 88 | // | ||
| 89 | // QGesture *create(QObject *target); | ||
| 90 | // QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); | ||
| 91 | // void reset(QGesture *gesture); | ||
| 92 | //private: | ||
| 93 | // QPointF _startPos; | ||
| 94 | // QBasicTimer _panTimer; | ||
| 95 | // bool _panCanceled; | ||
| 96 | //}; | ||
| 97 | // | ||
| 98 | //#endif | ||
| 99 | // | ||
| 100 | //QT_END_NAMESPACE | ||
| 101 | // | ||
| 102 | //#endif // QMACSWIPEGESTURERECOGNIZER_MAC_P_H |
src/gui/kernel/qmime_iphone.mm
(1255 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include "qmime.h" | ||
| 43 | |||
| 44 | #warning qmime_iphone not completed | ||
| 45 | |||
| 46 | //#define USE_INTERNET_CONFIG | ||
| 47 | |||
| 48 | #ifndef USE_INTERNET_CONFIG | ||
| 49 | # include "qfile.h" | ||
| 50 | # include "qfileinfo.h" | ||
| 51 | # include "qtextstream.h" | ||
| 52 | # include "qdir.h" | ||
| 53 | # include <unistd.h> | ||
| 54 | # include <sys/types.h> | ||
| 55 | # include <sys/stat.h> | ||
| 56 | # include <sys/fcntl.h> | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #include "qdebug.h" | ||
| 60 | #include "qpixmap.h" | ||
| 61 | #include "qimagewriter.h" | ||
| 62 | #include "qimagereader.h" | ||
| 63 | #include "qdatastream.h" | ||
| 64 | #include "qbuffer.h" | ||
| 65 | #include "qdatetime.h" | ||
| 66 | #include "qapplication_p.h" | ||
| 67 | #include "qtextcodec.h" | ||
| 68 | #include "qregexp.h" | ||
| 69 | #include "qurl.h" | ||
| 70 | #include "qmap.h" | ||
| 71 | #include <private/qt_iphone_p.h> | ||
| 72 | |||
| 73 | |||
| 74 | #ifdef Q_WS_MAC32 | ||
| 75 | #include <QuickTime/QuickTime.h> | ||
| 76 | #include <qlibrary.h> | ||
| 77 | #endif | ||
| 78 | |||
| 79 | QT_BEGIN_NAMESPACE | ||
| 80 | |||
| 81 | //extern CGImageRef qt_mac_createCGImageFromQImage(const QImage &img, const QImage **imagePtr = 0); // qpaintengine_mac.cpp | ||
| 82 | // | ||
| 83 | //typedef QList<QMacPasteboardMime*> MimeList; | ||
| 84 | //Q_GLOBAL_STATIC(MimeList, globalMimeList) | ||
| 85 | // | ||
| 86 | //static void cleanup_mimes() | ||
| 87 | //{ | ||
| 88 | // MimeList *mimes = globalMimeList(); | ||
| 89 | // while (!mimes->isEmpty()) | ||
| 90 | // delete mimes->takeFirst(); | ||
| 91 | //} | ||
| 92 | // | ||
| 93 | //Q_GLOBAL_STATIC(QStringList, globalDraggedTypesList) | ||
| 94 | // | ||
| 95 | ///*! | ||
| 96 | // \fn void qRegisterDraggedTypes(const QStringList &types) | ||
| 97 | // \relates QMacPasteboardMime | ||
| 98 | // | ||
| 99 | // Registers the given \a types as custom pasteboard types. | ||
| 100 | // | ||
| 101 | // This function should be called to enable the Drag and Drop events | ||
| 102 | // for custom pasteboard types on Cocoa implementations. This is required | ||
| 103 | // in addition to a QMacPasteboardMime subclass implementation. By default | ||
| 104 | // drag and drop is enabled for all standard pasteboard types. | ||
| 105 | // | ||
| 106 | // \sa QMacPasteboardMime | ||
| 107 | //*/ | ||
| 108 | //Q_GUI_EXPORT void qRegisterDraggedTypes(const QStringList &types) | ||
| 109 | //{ | ||
| 110 | // (*globalDraggedTypesList()) += types; | ||
| 111 | //} | ||
| 112 | // | ||
| 113 | //const QStringList& qEnabledDraggedTypes() | ||
| 114 | //{ | ||
| 115 | // return (*globalDraggedTypesList()); | ||
| 116 | //} | ||
| 117 | // | ||
| 118 | // | ||
| 119 | ///***************************************************************************** | ||
| 120 | // QDnD debug facilities | ||
| 121 | // *****************************************************************************/ | ||
| 122 | ////#define DEBUG_MIME_MAPS | ||
| 123 | // | ||
| 124 | ////functions | ||
| 125 | //extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp | ||
| 126 | //extern void qt_mac_from_pascal_string(QString, Str255, TextEncoding encoding=0, int len=-1); //qglobal.cpp | ||
| 127 | // | ||
| 128 | //ScrapFlavorType qt_mac_mime_type = 'CUTE'; | ||
| 129 | //CFStringRef qt_mac_mime_typeUTI = CFSTR("com.pasteboard.trolltech.marker"); | ||
| 130 | // | ||
| 131 | ///*! | ||
| 132 | // \class QMacPasteboardMime | ||
| 133 | // \brief The QMacPasteboardMime class converts between a MIME type and a | ||
| 134 | // \l{http://developer.apple.com/macosx/uniformtypeidentifiers.html}{Uniform | ||
| 135 | // Type Identifier (UTI)} format. | ||
| 136 | // \since 4.2 | ||
| 137 | // | ||
| 138 | // \ingroup draganddrop | ||
| 139 | // | ||
| 140 | // Qt's drag and drop and clipboard facilities use the MIME | ||
| 141 | // standard. On X11, this maps trivially to the Xdnd protocol. On | ||
| 142 | // Mac, although some applications use MIME to describe clipboard | ||
| 143 | // contents, it is more common to use Apple's UTI format. | ||
| 144 | // | ||
| 145 | // QMacPasteboardMime's role is to bridge the gap between MIME and UTI; | ||
| 146 | // By subclasses this class, one can extend Qt's drag and drop | ||
| 147 | // and clipboard handling to convert to and from unsupported, or proprietary, UTI formats. | ||
| 148 | // | ||
| 149 | // A subclass of QMacPasteboardMime will automatically be registered, and active, upon instantiation. | ||
| 150 | // | ||
| 151 | // Qt has predefined support for the following UTIs: | ||
| 152 | // \list | ||
| 153 | // \i public.utf8-plain-text - converts to "text/plain" | ||
| 154 | // \i public.utf16-plain-text - converts to "text/plain" | ||
| 155 | // \i public.html - converts to "text/html" | ||
| 156 | // \i public.url - converts to "text/uri-list" | ||
| 157 | // \i public.file-url - converts to "text/uri-list" | ||
| 158 | // \i public.tiff - converts to "application/x-qt-image" | ||
| 159 | // \i com.apple.traditional-mac-plain-text - converts to "text/plain" | ||
| 160 | // \i com.apple.pict - converts to "application/x-qt-image" | ||
| 161 | // \endlist | ||
| 162 | // | ||
| 163 | // When working with MIME data, Qt will interate through all instances of QMacPasteboardMime to | ||
| 164 | // find an instance that can convert to, or from, a specific MIME type. It will do this by calling | ||
| 165 | // canConvert() on each instance, starting with (and choosing) the last created instance first. | ||
| 166 | // The actual conversions will be done by using convertToMime() and convertFromMime(). | ||
| 167 | // | ||
| 168 | // \note The API uses the term "flavor" in some cases. This is for backwards | ||
| 169 | // compatibility reasons, and should now be understood as UTIs. | ||
| 170 | //*/ | ||
| 171 | // | ||
| 172 | ///*! \enum QMacPasteboardMime::QMacPasteboardMimeType | ||
| 173 | // \internal | ||
| 174 | //*/ | ||
| 175 | // | ||
| 176 | ///*! | ||
| 177 | // Constructs a new conversion object of type \a t, adding it to the | ||
| 178 | // globally accessed list of available convertors. | ||
| 179 | //*/ | ||
| 180 | //QMacPasteboardMime::QMacPasteboardMime(char t) : type(t) | ||
| 181 | //{ | ||
| 182 | // globalMimeList()->append(this); | ||
| 183 | //} | ||
| 184 | // | ||
| 185 | ///*! | ||
| 186 | // Destroys a conversion object, removing it from the global | ||
| 187 | // list of available convertors. | ||
| 188 | //*/ | ||
| 189 | //QMacPasteboardMime::~QMacPasteboardMime() | ||
| 190 | //{ | ||
| 191 | // if(!QApplication::closingDown()) | ||
| 192 | // globalMimeList()->removeAll(this); | ||
| 193 | //} | ||
| 194 | // | ||
| 195 | //class QMacPasteboardMimeAny : public QMacPasteboardMime { | ||
| 196 | //private: | ||
| 197 | // | ||
| 198 | //public: | ||
| 199 | // QMacPasteboardMimeAny() : QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL) { | ||
| 200 | // } | ||
| 201 | // ~QMacPasteboardMimeAny() { | ||
| 202 | // } | ||
| 203 | // QString convertorName(); | ||
| 204 | // | ||
| 205 | // QString flavorFor(const QString &mime); | ||
| 206 | // QString mimeFor(QString flav); | ||
| 207 | // bool canConvert(const QString &mime, QString flav); | ||
| 208 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 209 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 210 | //}; | ||
| 211 | // | ||
| 212 | //QString QMacPasteboardMimeAny::convertorName() | ||
| 213 | //{ | ||
| 214 | // return QLatin1String("Any-Mime"); | ||
| 215 | //} | ||
| 216 | // | ||
| 217 | //QString QMacPasteboardMimeAny::flavorFor(const QString &mime) | ||
| 218 | //{ | ||
| 219 | // // do not handle the mime type name in the drag pasteboard | ||
| 220 | // if(mime == QLatin1String("application/x-qt-mime-type-name")) | ||
| 221 | // return QString(); | ||
| 222 | // QString ret = QLatin1String("com.trolltech.anymime.") + mime; | ||
| 223 | // return ret.replace(QLatin1Char('/'), QLatin1String("--")); | ||
| 224 | //} | ||
| 225 | // | ||
| 226 | //QString QMacPasteboardMimeAny::mimeFor(QString flav) | ||
| 227 | //{ | ||
| 228 | // const QString any_prefix = QLatin1String("com.trolltech.anymime."); | ||
| 229 | // if(flav.size() > any_prefix.length() && flav.startsWith(any_prefix)) | ||
| 230 | // return flav.mid(any_prefix.length()).replace(QLatin1String("--"), QLatin1String("/")); | ||
| 231 | // return QString(); | ||
| 232 | //} | ||
| 233 | // | ||
| 234 | //bool QMacPasteboardMimeAny::canConvert(const QString &mime, QString flav) | ||
| 235 | //{ | ||
| 236 | // return mimeFor(flav) == mime; | ||
| 237 | //} | ||
| 238 | // | ||
| 239 | //QVariant QMacPasteboardMimeAny::convertToMime(const QString &mime, QList<QByteArray> data, QString) | ||
| 240 | //{ | ||
| 241 | // if(data.count() > 1) | ||
| 242 | // qWarning("QMacPasteboardMimeAny: Cannot handle multiple member data"); | ||
| 243 | // QVariant ret; | ||
| 244 | // if (mime == QLatin1String("text/plain")) | ||
| 245 | // ret = QString::fromUtf8(data.first()); | ||
| 246 | // else | ||
| 247 | // ret = data.first(); | ||
| 248 | // return ret; | ||
| 249 | //} | ||
| 250 | // | ||
| 251 | //QList<QByteArray> QMacPasteboardMimeAny::convertFromMime(const QString &mime, QVariant data, QString) | ||
| 252 | //{ | ||
| 253 | // QList<QByteArray> ret; | ||
| 254 | // if (mime == QLatin1String("text/plain")) | ||
| 255 | // ret.append(data.toString().toUtf8()); | ||
| 256 | // else | ||
| 257 | // ret.append(data.toByteArray()); | ||
| 258 | // return ret; | ||
| 259 | //} | ||
| 260 | // | ||
| 261 | //class QMacPasteboardMimeTypeName : public QMacPasteboardMime { | ||
| 262 | //private: | ||
| 263 | // | ||
| 264 | //public: | ||
| 265 | // QMacPasteboardMimeTypeName() : QMacPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL) { | ||
| 266 | // } | ||
| 267 | // ~QMacPasteboardMimeTypeName() { | ||
| 268 | // } | ||
| 269 | // QString convertorName(); | ||
| 270 | // | ||
| 271 | // QString flavorFor(const QString &mime); | ||
| 272 | // QString mimeFor(QString flav); | ||
| 273 | // bool canConvert(const QString &mime, QString flav); | ||
| 274 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 275 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 276 | //}; | ||
| 277 | // | ||
| 278 | //QString QMacPasteboardMimeTypeName::convertorName() | ||
| 279 | //{ | ||
| 280 | // return QLatin1String("Qt-Mime-Type"); | ||
| 281 | //} | ||
| 282 | // | ||
| 283 | //QString QMacPasteboardMimeTypeName::flavorFor(const QString &mime) | ||
| 284 | //{ | ||
| 285 | // if(mime == QLatin1String("application/x-qt-mime-type-name")) | ||
| 286 | // return QLatin1String("com.trolltech.qt.MimeTypeName"); | ||
| 287 | // return QString(); | ||
| 288 | //} | ||
| 289 | // | ||
| 290 | //QString QMacPasteboardMimeTypeName::mimeFor(QString) | ||
| 291 | //{ | ||
| 292 | // return QString(); | ||
| 293 | //} | ||
| 294 | // | ||
| 295 | //bool QMacPasteboardMimeTypeName::canConvert(const QString &, QString) | ||
| 296 | //{ | ||
| 297 | // return false; | ||
| 298 | //} | ||
| 299 | // | ||
| 300 | //QVariant QMacPasteboardMimeTypeName::convertToMime(const QString &, QList<QByteArray>, QString) | ||
| 301 | //{ | ||
| 302 | // QVariant ret; | ||
| 303 | // return ret; | ||
| 304 | //} | ||
| 305 | // | ||
| 306 | //QList<QByteArray> QMacPasteboardMimeTypeName::convertFromMime(const QString &, QVariant, QString) | ||
| 307 | //{ | ||
| 308 | // QList<QByteArray> ret; | ||
| 309 | // ret.append(QString("x-qt-mime-type-name").toUtf8()); | ||
| 310 | // return ret; | ||
| 311 | //} | ||
| 312 | // | ||
| 313 | //class QMacPasteboardMimePlainText : public QMacPasteboardMime { | ||
| 314 | //public: | ||
| 315 | // QMacPasteboardMimePlainText() : QMacPasteboardMime(MIME_ALL) { } | ||
| 316 | // QString convertorName(); | ||
| 317 | // | ||
| 318 | // QString flavorFor(const QString &mime); | ||
| 319 | // QString mimeFor(QString flav); | ||
| 320 | // bool canConvert(const QString &mime, QString flav); | ||
| 321 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 322 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 323 | //}; | ||
| 324 | // | ||
| 325 | //QString QMacPasteboardMimePlainText::convertorName() | ||
| 326 | //{ | ||
| 327 | // return QLatin1String("PlainText"); | ||
| 328 | //} | ||
| 329 | // | ||
| 330 | //QString QMacPasteboardMimePlainText::flavorFor(const QString &mime) | ||
| 331 | //{ | ||
| 332 | // if (mime == QLatin1String("text/plain")) | ||
| 333 | // return QLatin1String("com.apple.traditional-mac-plain-text"); | ||
| 334 | // return QString(); | ||
| 335 | //} | ||
| 336 | // | ||
| 337 | //QString QMacPasteboardMimePlainText::mimeFor(QString flav) | ||
| 338 | //{ | ||
| 339 | // if (flav == QLatin1String("com.apple.traditional-mac-plain-text")) | ||
| 340 | // return QLatin1String("text/plain"); | ||
| 341 | // return QString(); | ||
| 342 | //} | ||
| 343 | // | ||
| 344 | //bool QMacPasteboardMimePlainText::canConvert(const QString &mime, QString flav) | ||
| 345 | //{ | ||
| 346 | // return flavorFor(mime) == flav; | ||
| 347 | //} | ||
| 348 | // | ||
| 349 | //QVariant QMacPasteboardMimePlainText::convertToMime(const QString &mimetype, QList<QByteArray> data, QString flavor) | ||
| 350 | //{ | ||
| 351 | // if(data.count() > 1) | ||
| 352 | // qWarning("QMacPasteboardMimePlainText: Cannot handle multiple member data"); | ||
| 353 | // const QByteArray &firstData = data.first(); | ||
| 354 | // QVariant ret; | ||
| 355 | // if(flavor == QCFString(QLatin1String("com.apple.traditional-mac-plain-text"))) { | ||
| 356 | // QCFString str(CFStringCreateWithBytes(kCFAllocatorDefault, | ||
| 357 | // reinterpret_cast<const UInt8 *>(firstData.constData()), | ||
| 358 | // firstData.size(), CFStringGetSystemEncoding(), false)); | ||
| 359 | // ret = QString(str); | ||
| 360 | // } else { | ||
| 361 | // qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mimetype)); | ||
| 362 | // } | ||
| 363 | // return ret; | ||
| 364 | //} | ||
| 365 | // | ||
| 366 | //QList<QByteArray> QMacPasteboardMimePlainText::convertFromMime(const QString &, QVariant data, QString flavor) | ||
| 367 | //{ | ||
| 368 | // QList<QByteArray> ret; | ||
| 369 | // QString string = data.toString(); | ||
| 370 | // if(flavor == QCFString(QLatin1String("com.apple.traditional-mac-plain-text"))) | ||
| 371 | // ret.append(string.toLatin1()); | ||
| 372 | // return ret; | ||
| 373 | //} | ||
| 374 | // | ||
| 375 | //class QMacPasteboardMimeUnicodeText : public QMacPasteboardMime { | ||
| 376 | //public: | ||
| 377 | // QMacPasteboardMimeUnicodeText() : QMacPasteboardMime(MIME_ALL) { } | ||
| 378 | // QString convertorName(); | ||
| 379 | // | ||
| 380 | // QString flavorFor(const QString &mime); | ||
| 381 | // QString mimeFor(QString flav); | ||
| 382 | // bool canConvert(const QString &mime, QString flav); | ||
| 383 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 384 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 385 | //}; | ||
| 386 | // | ||
| 387 | //QString QMacPasteboardMimeUnicodeText::convertorName() | ||
| 388 | //{ | ||
| 389 | // return QLatin1String("UnicodeText"); | ||
| 390 | //} | ||
| 391 | // | ||
| 392 | //QString QMacPasteboardMimeUnicodeText::flavorFor(const QString &mime) | ||
| 393 | //{ | ||
| 394 | // if (mime == QLatin1String("text/plain")) | ||
| 395 | // return QLatin1String("public.utf16-plain-text"); | ||
| 396 | // int i = mime.indexOf(QLatin1String("charset=")); | ||
| 397 | // if (i >= 0) { | ||
| 398 | // QString cs(mime.mid(i+8).toLower()); | ||
| 399 | // i = cs.indexOf(QLatin1Char(';')); | ||
| 400 | // if (i>=0) | ||
| 401 | // cs = cs.left(i); | ||
| 402 | // if (cs == QLatin1String("system")) | ||
| 403 | // return QLatin1String("public.utf8-plain-text"); | ||
| 404 | // else if (cs == QLatin1String("iso-10646-ucs-2") | ||
| 405 | // || cs == QLatin1String("utf16")) | ||
| 406 | // return QLatin1String("public.utf16-plain-text"); | ||
| 407 | // } | ||
| 408 | // return QString(); | ||
| 409 | //} | ||
| 410 | // | ||
| 411 | //QString QMacPasteboardMimeUnicodeText::mimeFor(QString flav) | ||
| 412 | //{ | ||
| 413 | // if (flav == QLatin1String("public.utf16-plain-text") || flav == QLatin1String("public.utf8-plain-text")) | ||
| 414 | // return QLatin1String("text/plain"); | ||
| 415 | // return QString(); | ||
| 416 | //} | ||
| 417 | // | ||
| 418 | //bool QMacPasteboardMimeUnicodeText::canConvert(const QString &mime, QString flav) | ||
| 419 | //{ | ||
| 420 | // return flavorFor(mime) == flav; | ||
| 421 | //} | ||
| 422 | // | ||
| 423 | //QVariant QMacPasteboardMimeUnicodeText::convertToMime(const QString &mimetype, QList<QByteArray> data, QString flavor) | ||
| 424 | //{ | ||
| 425 | // if(data.count() > 1) | ||
| 426 | // qWarning("QMacPasteboardMimeUnicodeText: Cannot handle multiple member data"); | ||
| 427 | // const QByteArray &firstData = data.first(); | ||
| 428 | // // I can only handle two types (system and unicode) so deal with them that way | ||
| 429 | // QVariant ret; | ||
| 430 | // if(flavor == QLatin1String("public.utf8-plain-text")) { | ||
| 431 | // QCFString str(CFStringCreateWithBytes(kCFAllocatorDefault, | ||
| 432 | // reinterpret_cast<const UInt8 *>(firstData.constData()), | ||
| 433 | // firstData.size(), CFStringGetSystemEncoding(), false)); | ||
| 434 | // ret = QString(str); | ||
| 435 | // } else if (flavor == QLatin1String("public.utf16-plain-text")) { | ||
| 436 | // ret = QString::fromUtf16(reinterpret_cast<const ushort *>(firstData.constData()), | ||
| 437 | // firstData.size() / sizeof(ushort)); | ||
| 438 | // } else { | ||
| 439 | // qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mimetype)); | ||
| 440 | // } | ||
| 441 | // return ret; | ||
| 442 | //} | ||
| 443 | // | ||
| 444 | //QList<QByteArray> QMacPasteboardMimeUnicodeText::convertFromMime(const QString &, QVariant data, QString flavor) | ||
| 445 | //{ | ||
| 446 | // QList<QByteArray> ret; | ||
| 447 | // QString string = data.toString(); | ||
| 448 | // if(flavor == QLatin1String("public.utf8-plain-text")) | ||
| 449 | // ret.append(string.toUtf8()); | ||
| 450 | // else if (flavor == QLatin1String("public.utf16-plain-text")) | ||
| 451 | // ret.append(QByteArray((char*)string.utf16(), string.length()*2)); | ||
| 452 | // return ret; | ||
| 453 | //} | ||
| 454 | // | ||
| 455 | //class QMacPasteboardMimeHTMLText : public QMacPasteboardMime { | ||
| 456 | //public: | ||
| 457 | // QMacPasteboardMimeHTMLText() : QMacPasteboardMime(MIME_ALL) { } | ||
| 458 | // QString convertorName(); | ||
| 459 | // | ||
| 460 | // QString flavorFor(const QString &mime); | ||
| 461 | // QString mimeFor(QString flav); | ||
| 462 | // bool canConvert(const QString &mime, QString flav); | ||
| 463 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 464 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 465 | //}; | ||
| 466 | // | ||
| 467 | //QString QMacPasteboardMimeHTMLText::convertorName() | ||
| 468 | //{ | ||
| 469 | // return QLatin1String("HTML"); | ||
| 470 | //} | ||
| 471 | // | ||
| 472 | //QString QMacPasteboardMimeHTMLText::flavorFor(const QString &mime) | ||
| 473 | //{ | ||
| 474 | // if (mime == QLatin1String("text/html")) | ||
| 475 | // return QLatin1String("public.html"); | ||
| 476 | // return QString(); | ||
| 477 | //} | ||
| 478 | // | ||
| 479 | //QString QMacPasteboardMimeHTMLText::mimeFor(QString flav) | ||
| 480 | //{ | ||
| 481 | // if (flav == QLatin1String("public.html")) | ||
| 482 | // return QLatin1String("text/html"); | ||
| 483 | // return QString(); | ||
| 484 | //} | ||
| 485 | // | ||
| 486 | //bool QMacPasteboardMimeHTMLText::canConvert(const QString &mime, QString flav) | ||
| 487 | //{ | ||
| 488 | // return flavorFor(mime) == flav; | ||
| 489 | //} | ||
| 490 | // | ||
| 491 | //QVariant QMacPasteboardMimeHTMLText::convertToMime(const QString &mimeType, QList<QByteArray> data, QString flavor) | ||
| 492 | //{ | ||
| 493 | // if (!canConvert(mimeType, flavor)) | ||
| 494 | // return QVariant(); | ||
| 495 | // if (data.count() > 1) | ||
| 496 | // qWarning("QMacPasteboardMimeHTMLText: Cannot handle multiple member data"); | ||
| 497 | // return data.first(); | ||
| 498 | //} | ||
| 499 | // | ||
| 500 | //QList<QByteArray> QMacPasteboardMimeHTMLText::convertFromMime(const QString &mime, QVariant data, QString flavor) | ||
| 501 | //{ | ||
| 502 | // QList<QByteArray> ret; | ||
| 503 | // if (!canConvert(mime, flavor)) | ||
| 504 | // return ret; | ||
| 505 | // ret.append(data.toByteArray()); | ||
| 506 | // return ret; | ||
| 507 | //} | ||
| 508 | // | ||
| 509 | // | ||
| 510 | //#ifdef Q_WS_MAC32 | ||
| 511 | // | ||
| 512 | //// This can be removed once 10.6 is the minimum (or we have to require 64-bit) whichever comes first. | ||
| 513 | // | ||
| 514 | //typedef ComponentResult (*PtrGraphicsImportSetDataHandle)(GraphicsImportComponent, Handle); | ||
| 515 | //typedef ComponentResult (*PtrGraphicsImportCreateCGImage)(GraphicsImportComponent, CGImageRef*, UInt32); | ||
| 516 | //typedef ComponentResult (*PtrGraphicsExportSetInputCGImage)(GraphicsExportComponent, CGImageRef); | ||
| 517 | //typedef ComponentResult (*PtrGraphicsExportSetOutputHandle)(GraphicsExportComponent, Handle); | ||
| 518 | //typedef ComponentResult (*PtrGraphicsExportDoExport)(GraphicsExportComponent, unsigned long *); | ||
| 519 | // | ||
| 520 | //static PtrGraphicsImportSetDataHandle ptrGraphicsImportSetDataHandle = 0; | ||
| 521 | //static PtrGraphicsImportCreateCGImage ptrGraphicsImportCreateCGImage = 0; | ||
| 522 | //static PtrGraphicsExportSetInputCGImage ptrGraphicsExportSetInputCGImage = 0; | ||
| 523 | //static PtrGraphicsExportSetOutputHandle ptrGraphicsExportSetOutputHandle = 0; | ||
| 524 | //static PtrGraphicsExportDoExport ptrGraphicsExportDoExport = 0; | ||
| 525 | // | ||
| 526 | //static bool resolveMimeQuickTimeSymbols() | ||
| 527 | //{ | ||
| 528 | // if (ptrGraphicsImportSetDataHandle == 0) { | ||
| 529 | // QLibrary library(QLatin1String("/System/Library/Frameworks/QuickTime.framework/QuickTime")); | ||
| 530 | // ptrGraphicsImportSetDataHandle = reinterpret_cast<PtrGraphicsImportSetDataHandle>(library.resolve("GraphicsImportSetDataHandle")); | ||
| 531 | // ptrGraphicsImportCreateCGImage = reinterpret_cast<PtrGraphicsImportCreateCGImage>(library.resolve("GraphicsImportCreateCGImage")); | ||
| 532 | // ptrGraphicsExportSetInputCGImage = reinterpret_cast<PtrGraphicsExportSetInputCGImage>(library.resolve("GraphicsExportSetInputCGImage")); | ||
| 533 | // ptrGraphicsExportSetOutputHandle = reinterpret_cast<PtrGraphicsExportSetOutputHandle>(library.resolve("GraphicsExportSetOutputHandle")); | ||
| 534 | // ptrGraphicsExportDoExport = reinterpret_cast<PtrGraphicsExportDoExport>(library.resolve("GraphicsExportDoExport")); | ||
| 535 | // } | ||
| 536 | // | ||
| 537 | // return ptrGraphicsImportSetDataHandle != 0 | ||
| 538 | // && ptrGraphicsImportCreateCGImage != 0 && ptrGraphicsExportSetInputCGImage != 0 | ||
| 539 | // && ptrGraphicsExportSetOutputHandle != 0 && ptrGraphicsExportDoExport != 0; | ||
| 540 | //} | ||
| 541 | // | ||
| 542 | //class QMacPasteboardMimePict : public QMacPasteboardMime { | ||
| 543 | //public: | ||
| 544 | // QMacPasteboardMimePict() : QMacPasteboardMime(MIME_ALL) { } | ||
| 545 | // QString convertorName(); | ||
| 546 | // | ||
| 547 | // QString flavorFor(const QString &mime); | ||
| 548 | // QString mimeFor(QString flav); | ||
| 549 | // bool canConvert(const QString &mime, QString flav); | ||
| 550 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 551 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 552 | //}; | ||
| 553 | // | ||
| 554 | //QString QMacPasteboardMimePict::convertorName() | ||
| 555 | //{ | ||
| 556 | // return QLatin1String("Pict"); | ||
| 557 | //} | ||
| 558 | // | ||
| 559 | //QString QMacPasteboardMimePict::flavorFor(const QString &mime) | ||
| 560 | //{ | ||
| 561 | // if(mime.startsWith(QLatin1String("application/x-qt-image"))) | ||
| 562 | // return QLatin1String("com.apple.pict"); | ||
| 563 | // return QString(); | ||
| 564 | //} | ||
| 565 | // | ||
| 566 | //QString QMacPasteboardMimePict::mimeFor(QString flav) | ||
| 567 | //{ | ||
| 568 | // if(flav == QLatin1String("com.apple.pict")) | ||
| 569 | // return QLatin1String("application/x-qt-image"); | ||
| 570 | // return QString(); | ||
| 571 | //} | ||
| 572 | // | ||
| 573 | //bool QMacPasteboardMimePict::canConvert(const QString &mime, QString flav) | ||
| 574 | //{ | ||
| 575 | // return flav == QLatin1String("com.apple.pict") | ||
| 576 | // && mime == QLatin1String("application/x-qt-image"); | ||
| 577 | //} | ||
| 578 | // | ||
| 579 | // | ||
| 580 | //QVariant QMacPasteboardMimePict::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) | ||
| 581 | //{ | ||
| 582 | // if(data.count() > 1) | ||
| 583 | // qWarning("QMacPasteboardMimePict: Cannot handle multiple member data"); | ||
| 584 | // QVariant ret; | ||
| 585 | // if (!resolveMimeQuickTimeSymbols()) | ||
| 586 | // return ret; | ||
| 587 | // | ||
| 588 | // if(!canConvert(mime, flav)) | ||
| 589 | // return ret; | ||
| 590 | // const QByteArray &a = data.first(); | ||
| 591 | // | ||
| 592 | // // This function expects the 512 header (just to skip it, so create the extra space for it). | ||
| 593 | // Handle pic = NewHandle(a.size() + 512); | ||
| 594 | // memcpy(*pic + 512, a.constData(), a.size()); | ||
| 595 | // | ||
| 596 | // GraphicsImportComponent graphicsImporter; | ||
| 597 | // ComponentResult result = OpenADefaultComponent(GraphicsImporterComponentType, | ||
| 598 | // kQTFileTypePicture, &graphicsImporter); | ||
| 599 | // QCFType<CGImageRef> cgImage; | ||
| 600 | // if (!result) | ||
| 601 | // result = ptrGraphicsImportSetDataHandle(graphicsImporter, pic); | ||
| 602 | // if (!result) | ||
| 603 | // result = ptrGraphicsImportCreateCGImage(graphicsImporter, &cgImage, | ||
| 604 | // kGraphicsImportCreateCGImageUsingCurrentSettings); | ||
| 605 | // if (!result) | ||
| 606 | // ret = QVariant(QPixmap::fromMacCGImageRef(cgImage).toImage()); | ||
| 607 | // CloseComponent(graphicsImporter); | ||
| 608 | // DisposeHandle(pic); | ||
| 609 | // return ret; | ||
| 610 | //} | ||
| 611 | // | ||
| 612 | //QList<QByteArray> QMacPasteboardMimePict::convertFromMime(const QString &mime, QVariant variant, | ||
| 613 | // QString flav) | ||
| 614 | //{ | ||
| 615 | // QList<QByteArray> ret; | ||
| 616 | // if (!resolveMimeQuickTimeSymbols()) | ||
| 617 | // return ret; | ||
| 618 | // | ||
| 619 | // if (!canConvert(mime, flav)) | ||
| 620 | // return ret; | ||
| 621 | // QCFType<CGImageRef> cgimage = qt_mac_createCGImageFromQImage(qvariant_cast<QImage>(variant)); | ||
| 622 | // Handle pic = NewHandle(0); | ||
| 623 | // GraphicsExportComponent graphicsExporter; | ||
| 624 | // ComponentResult result = OpenADefaultComponent(GraphicsExporterComponentType, | ||
| 625 | // kQTFileTypePicture, &graphicsExporter); | ||
| 626 | // if (!result) { | ||
| 627 | // unsigned long sizeWritten; | ||
| 628 | // result = ptrGraphicsExportSetInputCGImage(graphicsExporter, cgimage); | ||
| 629 | // if (!result) | ||
| 630 | // result = ptrGraphicsExportSetOutputHandle(graphicsExporter, pic); | ||
| 631 | // if (!result) | ||
| 632 | // result = ptrGraphicsExportDoExport(graphicsExporter, &sizeWritten); | ||
| 633 | // | ||
| 634 | // CloseComponent(graphicsExporter); | ||
| 635 | // } | ||
| 636 | // | ||
| 637 | // int size = GetHandleSize((Handle)pic); | ||
| 638 | // // Skip the Picture File header (512 bytes) and feed the raw data | ||
| 639 | // QByteArray ar(reinterpret_cast<char *>(*pic + 512), size - 512); | ||
| 640 | // ret.append(ar); | ||
| 641 | // DisposeHandle(pic); | ||
| 642 | // return ret; | ||
| 643 | //} | ||
| 644 | // | ||
| 645 | // | ||
| 646 | //#endif //Q_WS_MAC32 | ||
| 647 | // | ||
| 648 | //class QMacPasteboardMimeTiff : public QMacPasteboardMime { | ||
| 649 | //public: | ||
| 650 | // QMacPasteboardMimeTiff() : QMacPasteboardMime(MIME_ALL) { } | ||
| 651 | // QString convertorName(); | ||
| 652 | // | ||
| 653 | // QString flavorFor(const QString &mime); | ||
| 654 | // QString mimeFor(QString flav); | ||
| 655 | // bool canConvert(const QString &mime, QString flav); | ||
| 656 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 657 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 658 | //}; | ||
| 659 | // | ||
| 660 | //QString QMacPasteboardMimeTiff::convertorName() | ||
| 661 | //{ | ||
| 662 | // return QLatin1String("Tiff"); | ||
| 663 | //} | ||
| 664 | // | ||
| 665 | //QString QMacPasteboardMimeTiff::flavorFor(const QString &mime) | ||
| 666 | //{ | ||
| 667 | // if(mime.startsWith(QLatin1String("application/x-qt-image"))) | ||
| 668 | // return QLatin1String("public.tiff"); | ||
| 669 | // return QString(); | ||
| 670 | //} | ||
| 671 | // | ||
| 672 | //QString QMacPasteboardMimeTiff::mimeFor(QString flav) | ||
| 673 | //{ | ||
| 674 | // if(flav == QLatin1String("public.tiff")) | ||
| 675 | // return QLatin1String("application/x-qt-image"); | ||
| 676 | // return QString(); | ||
| 677 | //} | ||
| 678 | // | ||
| 679 | //bool QMacPasteboardMimeTiff::canConvert(const QString &mime, QString flav) | ||
| 680 | //{ | ||
| 681 | // return flav == QLatin1String("public.tiff") && mime == QLatin1String("application/x-qt-image"); | ||
| 682 | //} | ||
| 683 | // | ||
| 684 | //QVariant QMacPasteboardMimeTiff::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) | ||
| 685 | //{ | ||
| 686 | // if(data.count() > 1) | ||
| 687 | // qWarning("QMacPasteboardMimeTiff: Cannot handle multiple member data"); | ||
| 688 | // QVariant ret; | ||
| 689 | // if (!canConvert(mime, flav)) | ||
| 690 | // return ret; | ||
| 691 | // const QByteArray &a = data.first(); | ||
| 692 | // QCFType<CGImageRef> image; | ||
| 693 | // QCFType<CFDataRef> tiffData = CFDataCreateWithBytesNoCopy(0, | ||
| 694 | // reinterpret_cast<const UInt8 *>(a.constData()), | ||
| 695 | // a.size(), kCFAllocatorNull); | ||
| 696 | // QCFType<CGImageSourceRef> imageSource = CGImageSourceCreateWithData(tiffData, 0); | ||
| 697 | // image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0); | ||
| 698 | // | ||
| 699 | // if (image != 0) | ||
| 700 | // ret = QVariant(QPixmap::fromMacCGImageRef(image).toImage()); | ||
| 701 | // return ret; | ||
| 702 | //} | ||
| 703 | // | ||
| 704 | //QList<QByteArray> QMacPasteboardMimeTiff::convertFromMime(const QString &mime, QVariant variant, QString flav) | ||
| 705 | //{ | ||
| 706 | // QList<QByteArray> ret; | ||
| 707 | // if (!canConvert(mime, flav)) | ||
| 708 | // return ret; | ||
| 709 | // | ||
| 710 | // QImage img = qvariant_cast<QImage>(variant); | ||
| 711 | // QCFType<CGImageRef> cgimage = qt_mac_createCGImageFromQImage(img); | ||
| 712 | //#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) | ||
| 713 | // if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { | ||
| 714 | // QCFType<CFMutableDataRef> data = CFDataCreateMutable(0, 0); | ||
| 715 | // QCFType<CGImageDestinationRef> imageDestination = CGImageDestinationCreateWithData(data, kUTTypeTIFF, 1, 0); | ||
| 716 | // if (imageDestination != 0) { | ||
| 717 | // CFTypeRef keys[2]; | ||
| 718 | // QCFType<CFTypeRef> values[2]; | ||
| 719 | // QCFType<CFDictionaryRef> options; | ||
| 720 | // keys[0] = kCGImagePropertyPixelWidth; | ||
| 721 | // keys[1] = kCGImagePropertyPixelHeight; | ||
| 722 | // int width = img.width(); | ||
| 723 | // int height = img.height(); | ||
| 724 | // values[0] = CFNumberCreate(0, kCFNumberIntType, &width); | ||
| 725 | // values[1] = CFNumberCreate(0, kCFNumberIntType, &height); | ||
| 726 | // options = CFDictionaryCreate(0, reinterpret_cast<const void **>(keys), | ||
| 727 | // reinterpret_cast<const void **>(values), 2, | ||
| 728 | // &kCFTypeDictionaryKeyCallBacks, | ||
| 729 | // &kCFTypeDictionaryValueCallBacks); | ||
| 730 | // CGImageDestinationAddImage(imageDestination, cgimage, options); | ||
| 731 | // CGImageDestinationFinalize(imageDestination); | ||
| 732 | // } | ||
| 733 | // QByteArray ar(CFDataGetLength(data), 0); | ||
| 734 | // CFDataGetBytes(data, | ||
| 735 | // CFRangeMake(0, ar.size()), | ||
| 736 | // reinterpret_cast<UInt8 *>(ar.data())); | ||
| 737 | // ret.append(ar); | ||
| 738 | // } else | ||
| 739 | //#endif | ||
| 740 | // { | ||
| 741 | //#ifdef Q_WS_MAC32 | ||
| 742 | // Handle tiff = NewHandle(0); | ||
| 743 | // if (resolveMimeQuickTimeSymbols()) { | ||
| 744 | // GraphicsExportComponent graphicsExporter; | ||
| 745 | // ComponentResult result = OpenADefaultComponent(GraphicsExporterComponentType, | ||
| 746 | // kQTFileTypeTIFF, &graphicsExporter); | ||
| 747 | // if (!result) { | ||
| 748 | // unsigned long sizeWritten; | ||
| 749 | // result = ptrGraphicsExportSetInputCGImage(graphicsExporter, cgimage); | ||
| 750 | // if (!result) | ||
| 751 | // result = ptrGraphicsExportSetOutputHandle(graphicsExporter, tiff); | ||
| 752 | // if (!result) | ||
| 753 | // result = ptrGraphicsExportDoExport(graphicsExporter, &sizeWritten); | ||
| 754 | // | ||
| 755 | // CloseComponent(graphicsExporter); | ||
| 756 | // } | ||
| 757 | // } | ||
| 758 | // int size = GetHandleSize((Handle)tiff); | ||
| 759 | // QByteArray ar(reinterpret_cast<char *>(*tiff), size); | ||
| 760 | // ret.append(ar); | ||
| 761 | // DisposeHandle(tiff); | ||
| 762 | //#endif | ||
| 763 | // } | ||
| 764 | // return ret; | ||
| 765 | //} | ||
| 766 | // | ||
| 767 | // | ||
| 768 | //class QMacPasteboardMimeFileUri : public QMacPasteboardMime { | ||
| 769 | //public: | ||
| 770 | // QMacPasteboardMimeFileUri() : QMacPasteboardMime(MIME_ALL) { } | ||
| 771 | // QString convertorName(); | ||
| 772 | // | ||
| 773 | // QString flavorFor(const QString &mime); | ||
| 774 | // QString mimeFor(QString flav); | ||
| 775 | // bool canConvert(const QString &mime, QString flav); | ||
| 776 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 777 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 778 | //}; | ||
| 779 | // | ||
| 780 | //QString QMacPasteboardMimeFileUri::convertorName() | ||
| 781 | //{ | ||
| 782 | // return QLatin1String("FileURL"); | ||
| 783 | //} | ||
| 784 | // | ||
| 785 | //QString QMacPasteboardMimeFileUri::flavorFor(const QString &mime) | ||
| 786 | //{ | ||
| 787 | // if (mime == QLatin1String("text/uri-list")) | ||
| 788 | // return QCFString(UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, CFSTR("furl"), 0)); | ||
| 789 | // return QString(); | ||
| 790 | //} | ||
| 791 | // | ||
| 792 | //QString QMacPasteboardMimeFileUri::mimeFor(QString flav) | ||
| 793 | //{ | ||
| 794 | // if (flav == QCFString(UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, CFSTR("furl"), 0))) | ||
| 795 | // return QLatin1String("text/uri-list"); | ||
| 796 | // return QString(); | ||
| 797 | //} | ||
| 798 | // | ||
| 799 | //bool QMacPasteboardMimeFileUri::canConvert(const QString &mime, QString flav) | ||
| 800 | //{ | ||
| 801 | // return mime == QLatin1String("text/uri-list") | ||
| 802 | // && flav == QCFString(UTTypeCreatePreferredIdentifierForTag(kUTTagClassOSType, CFSTR("furl"), 0)); | ||
| 803 | //} | ||
| 804 | // | ||
| 805 | //QVariant QMacPasteboardMimeFileUri::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) | ||
| 806 | //{ | ||
| 807 | // if(!canConvert(mime, flav)) | ||
| 808 | // return QVariant(); | ||
| 809 | // QList<QVariant> ret; | ||
| 810 | // for(int i = 0; i < data.size(); ++i) { | ||
| 811 | // QUrl url = QUrl::fromEncoded(data.at(i)); | ||
| 812 | // if (url.host().toLower() == QLatin1String("localhost")) | ||
| 813 | // url.setHost(QString()); | ||
| 814 | // url.setPath(url.path().normalized(QString::NormalizationForm_C)); | ||
| 815 | // ret.append(url); | ||
| 816 | // } | ||
| 817 | // return QVariant(ret); | ||
| 818 | //} | ||
| 819 | // | ||
| 820 | //QList<QByteArray> QMacPasteboardMimeFileUri::convertFromMime(const QString &mime, QVariant data, QString flav) | ||
| 821 | //{ | ||
| 822 | // QList<QByteArray> ret; | ||
| 823 | // if (!canConvert(mime, flav)) | ||
| 824 | // return ret; | ||
| 825 | // QList<QVariant> urls = data.toList(); | ||
| 826 | // for(int i = 0; i < urls.size(); ++i) { | ||
| 827 | // QUrl url = urls.at(i).toUrl(); | ||
| 828 | // if (url.scheme().isEmpty()) | ||
| 829 | // url.setScheme(QLatin1String("file")); | ||
| 830 | // if (url.scheme().toLower() == QLatin1String("file")) { | ||
| 831 | // if (url.host().isEmpty()) | ||
| 832 | // url.setHost(QLatin1String("localhost")); | ||
| 833 | // url.setPath(url.path().normalized(QString::NormalizationForm_D)); | ||
| 834 | // } | ||
| 835 | // ret.append(url.toEncoded()); | ||
| 836 | // } | ||
| 837 | // return ret; | ||
| 838 | //} | ||
| 839 | // | ||
| 840 | //class QMacPasteboardMimeUrl : public QMacPasteboardMime { | ||
| 841 | //public: | ||
| 842 | // QMacPasteboardMimeUrl() : QMacPasteboardMime(MIME_ALL) { } | ||
| 843 | // QString convertorName(); | ||
| 844 | // | ||
| 845 | // QString flavorFor(const QString &mime); | ||
| 846 | // QString mimeFor(QString flav); | ||
| 847 | // bool canConvert(const QString &mime, QString flav); | ||
| 848 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 849 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 850 | //}; | ||
| 851 | // | ||
| 852 | //QString QMacPasteboardMimeUrl::convertorName() | ||
| 853 | //{ | ||
| 854 | // return QLatin1String("URL"); | ||
| 855 | //} | ||
| 856 | // | ||
| 857 | //QString QMacPasteboardMimeUrl::flavorFor(const QString &mime) | ||
| 858 | //{ | ||
| 859 | // if(mime.startsWith(QLatin1String("text/uri-list"))) | ||
| 860 | // return QLatin1String("public.url"); | ||
| 861 | // return QString(); | ||
| 862 | //} | ||
| 863 | // | ||
| 864 | //QString QMacPasteboardMimeUrl::mimeFor(QString flav) | ||
| 865 | //{ | ||
| 866 | // if(flav == QLatin1String("public.url")) | ||
| 867 | // return QLatin1String("text/uri-list"); | ||
| 868 | // return QString(); | ||
| 869 | //} | ||
| 870 | // | ||
| 871 | //bool QMacPasteboardMimeUrl::canConvert(const QString &mime, QString flav) | ||
| 872 | //{ | ||
| 873 | // return flav == QLatin1String("public.url") | ||
| 874 | // && mime == QLatin1String("text/uri-list"); | ||
| 875 | //} | ||
| 876 | // | ||
| 877 | //QVariant QMacPasteboardMimeUrl::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) | ||
| 878 | //{ | ||
| 879 | // if(!canConvert(mime, flav)) | ||
| 880 | // return QVariant(); | ||
| 881 | // | ||
| 882 | // QList<QVariant> ret; | ||
| 883 | // for (int i=0; i<data.size(); ++i) { | ||
| 884 | // QUrl url = QUrl::fromEncoded(data.at(i)); | ||
| 885 | // if (url.host().toLower() == QLatin1String("localhost")) | ||
| 886 | // url.setHost(QString()); | ||
| 887 | // url.setPath(url.path().normalized(QString::NormalizationForm_C)); | ||
| 888 | // ret.append(url); | ||
| 889 | // } | ||
| 890 | // return QVariant(ret); | ||
| 891 | //} | ||
| 892 | // | ||
| 893 | //QList<QByteArray> QMacPasteboardMimeUrl::convertFromMime(const QString &mime, QVariant data, QString flav) | ||
| 894 | //{ | ||
| 895 | // QList<QByteArray> ret; | ||
| 896 | // if (!canConvert(mime, flav)) | ||
| 897 | // return ret; | ||
| 898 | // | ||
| 899 | // QList<QVariant> urls = data.toList(); | ||
| 900 | // for(int i=0; i<urls.size(); ++i) { | ||
| 901 | // QUrl url = urls.at(i).toUrl(); | ||
| 902 | // if (url.scheme().isEmpty()) | ||
| 903 | // url.setScheme(QLatin1String("file")); | ||
| 904 | // if (url.scheme().toLower() == QLatin1String("file")) { | ||
| 905 | // if (url.host().isEmpty()) | ||
| 906 | // url.setHost(QLatin1String("localhost")); | ||
| 907 | // url.setPath(url.path().normalized(QString::NormalizationForm_D)); | ||
| 908 | // } | ||
| 909 | // ret.append(url.toEncoded()); | ||
| 910 | // } | ||
| 911 | // return ret; | ||
| 912 | //} | ||
| 913 | // | ||
| 914 | //#ifdef QT3_SUPPORT | ||
| 915 | //class QMacPasteboardMimeQt3Any : public QMacPasteboardMime { | ||
| 916 | //private: | ||
| 917 | // int current_max; | ||
| 918 | // QFile library_file; | ||
| 919 | // QDateTime mime_registry_loaded; | ||
| 920 | // QMap<QString, int> mime_registry; | ||
| 921 | // int registerMimeType(const QString &mime); | ||
| 922 | // bool loadMimeRegistry(); | ||
| 923 | // | ||
| 924 | //public: | ||
| 925 | // QMacPasteboardMimeQt3Any() : QMacPasteboardMime(MIME_QT3_CONVERTOR) { | ||
| 926 | // current_max = 'QT00'; | ||
| 927 | // } | ||
| 928 | // ~QMacPasteboardMimeQt3Any() { | ||
| 929 | // } | ||
| 930 | // QString convertorName(); | ||
| 931 | // | ||
| 932 | // QString flavorFor(const QString &mime); | ||
| 933 | // QString mimeFor(QString flav); | ||
| 934 | // bool canConvert(const QString &mime, QString flav); | ||
| 935 | // QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav); | ||
| 936 | // QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav); | ||
| 937 | //}; | ||
| 938 | // | ||
| 939 | //static bool qt_mac_openMimeRegistry(bool global, QIODevice::OpenMode mode, QFile &file) | ||
| 940 | //{ | ||
| 941 | // QString dir = QLatin1String("/Library/Qt"); | ||
| 942 | // if(!global) | ||
| 943 | // dir.prepend(QDir::homePath()); | ||
| 944 | // file.setFileName(dir + QLatin1String("/.mime_types")); | ||
| 945 | // if(mode != QIODevice::ReadOnly) { | ||
| 946 | // if(!QFile::exists(dir)) { | ||
| 947 | // // Do it with a system call as I don't see much worth in | ||
| 948 | // // doing it with QDir since we have to chmod anyway. | ||
| 949 | // bool success = ::mkdir(dir.toLocal8Bit().constData(), S_IRUSR | S_IWUSR | S_IXUSR) == 0; | ||
| 950 | // if (success) | ||
| 951 | // success = ::chmod(dir.toLocal8Bit().constData(), S_IRUSR | S_IWUSR | S_IXUSR | ||
| 952 | // | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH) == 0; | ||
| 953 | // if (!success) | ||
| 954 | // return false; | ||
| 955 | // } | ||
| 956 | // if (!file.exists()) { | ||
| 957 | // // Create the file and chmod it so that everyone can write to it. | ||
| 958 | // int fd = ::open(file.fileName().toLocal8Bit().constData(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); | ||
| 959 | // bool success = fd != -1; | ||
| 960 | // if (success) | ||
| 961 | // success = ::fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == 0; | ||
| 962 | // if (fd != -1) | ||
| 963 | // ::close(fd); | ||
| 964 | // if(!success) | ||
| 965 | // return false; | ||
| 966 | // } | ||
| 967 | // } | ||
| 968 | // return file.open(mode); | ||
| 969 | //} | ||
| 970 | // | ||
| 971 | //static void qt_mac_loadMimeRegistry(QFile &file, QMap<QString, int> ®istry, int &max) | ||
| 972 | //{ | ||
| 973 | // file.reset(); | ||
| 974 | // QTextStream stream(&file); | ||
| 975 | // while(!stream.atEnd()) { | ||
| 976 | // QString mime = stream.readLine(); | ||
| 977 | // int mactype = stream.readLine().toInt(); | ||
| 978 | // if(mactype > max) | ||
| 979 | // max = mactype; | ||
| 980 | // registry.insert(mime, mactype); | ||
| 981 | // } | ||
| 982 | //} | ||
| 983 | // | ||
| 984 | //bool QMacPasteboardMimeQt3Any::loadMimeRegistry() | ||
| 985 | //{ | ||
| 986 | // if(!library_file.isOpen()) { | ||
| 987 | // if(!qt_mac_openMimeRegistry(true, QIODevice::ReadWrite, library_file)) { | ||
| 988 | // QFile global; | ||
| 989 | // if(qt_mac_openMimeRegistry(true, QIODevice::ReadOnly, global)) { | ||
| 990 | // qt_mac_loadMimeRegistry(global, mime_registry, current_max); | ||
| 991 | // global.close(); | ||
| 992 | // } | ||
| 993 | // if(!qt_mac_openMimeRegistry(false, QIODevice::ReadWrite, library_file)) { | ||
| 994 | // qWarning("QMacPasteboardMimeAnyQt3Mime: Failure to open mime resources %s -- %s", library_file.fileName().toLatin1().constData(), | ||
| 995 | // library_file.errorString().toLatin1().constData()); | ||
| 996 | // return false; | ||
| 997 | // } | ||
| 998 | // } | ||
| 999 | // } | ||
| 1000 | // | ||
| 1001 | // QFileInfo fi(library_file); | ||
| 1002 | // if(!mime_registry_loaded.isNull() && mime_registry_loaded == fi.lastModified()) | ||
| 1003 | // return true; | ||
| 1004 | // mime_registry_loaded = fi.lastModified(); | ||
| 1005 | // qt_mac_loadMimeRegistry(library_file, mime_registry, current_max); | ||
| 1006 | // return true; | ||
| 1007 | //} | ||
| 1008 | // | ||
| 1009 | //int QMacPasteboardMimeQt3Any::registerMimeType(const QString &mime) | ||
| 1010 | //{ | ||
| 1011 | // if(!mime_registry.contains(mime)) { | ||
| 1012 | // if(!loadMimeRegistry()) { | ||
| 1013 | // qWarning("QMacPasteboardMimeAnyQt3Mime: Internal error"); | ||
| 1014 | // return 0; | ||
| 1015 | // } | ||
| 1016 | // if(!mime_registry.contains(mime)) { | ||
| 1017 | // if(!library_file.isOpen()) { | ||
| 1018 | // if(!library_file.open(QIODevice::WriteOnly)) { | ||
| 1019 | // qWarning("QMacPasteboardMimeAnyQt3Mime: Failure to open %s -- %s", library_file.fileName().toLatin1().constData(), | ||
| 1020 | // library_file.errorString().toLatin1().constData()); | ||
| 1021 | // return false; | ||
| 1022 | // } | ||
| 1023 | // } | ||
| 1024 | // int ret = ++current_max; | ||
| 1025 | // mime_registry_loaded = QFileInfo(library_file).lastModified(); | ||
| 1026 | // QTextStream stream(&library_file); | ||
| 1027 | // stream << mime << endl; | ||
| 1028 | // stream << ret << endl; | ||
| 1029 | // mime_registry.insert(mime, ret); | ||
| 1030 | // library_file.flush(); //flush and set mtime | ||
| 1031 | // return ret; | ||
| 1032 | // } | ||
| 1033 | // } | ||
| 1034 | // return mime_registry[mime]; | ||
| 1035 | //} | ||
| 1036 | // | ||
| 1037 | //QString QMacPasteboardMimeQt3Any::convertorName() | ||
| 1038 | //{ | ||
| 1039 | // return QLatin1String("Qt3-Any-Mime"); | ||
| 1040 | //} | ||
| 1041 | // | ||
| 1042 | //QString QMacPasteboardMimeQt3Any::flavorFor(const QString &mime) | ||
| 1043 | //{ | ||
| 1044 | // const int os_flav = registerMimeType(mime); | ||
| 1045 | // QCFType<CFArrayRef> ids = UTTypeCreateAllIdentifiersForTag(0, kUTTagClassOSType, | ||
| 1046 | // QCFString(UTCreateStringForOSType(os_flav))); | ||
| 1047 | // if(ids) { | ||
| 1048 | // const int type_count = CFArrayGetCount(ids); | ||
| 1049 | // if(type_count) { | ||
| 1050 | // if(type_count > 1) | ||
| 1051 | // qDebug("Can't happen!"); | ||
| 1052 | // return QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(ids, 0)); | ||
| 1053 | // } | ||
| 1054 | // } | ||
| 1055 | // return QString(); | ||
| 1056 | //} | ||
| 1057 | // | ||
| 1058 | //QString QMacPasteboardMimeQt3Any::mimeFor(QString flav) | ||
| 1059 | //{ | ||
| 1060 | // loadMimeRegistry(); | ||
| 1061 | // const int os_flav = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(QCFString(flav), kUTTagClassOSType)); | ||
| 1062 | // for(QMap<QString, int>::const_iterator it = mime_registry.constBegin(); | ||
| 1063 | // it != mime_registry.constEnd(); ++it) { | ||
| 1064 | // if(it.value() == os_flav) | ||
| 1065 | // return QString::fromLatin1(it.key().toLatin1()); | ||
| 1066 | // } | ||
| 1067 | // return QString(); | ||
| 1068 | //} | ||
| 1069 | // | ||
| 1070 | //bool QMacPasteboardMimeQt3Any::canConvert(const QString &mime, QString flav) | ||
| 1071 | //{ | ||
| 1072 | // loadMimeRegistry(); | ||
| 1073 | // const int os_flav = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(QCFString(flav), kUTTagClassOSType)); | ||
| 1074 | // if(mime_registry.contains(mime) && mime_registry[mime] == os_flav) | ||
| 1075 | // return true; | ||
| 1076 | // return false; | ||
| 1077 | //} | ||
| 1078 | // | ||
| 1079 | //QVariant QMacPasteboardMimeQt3Any::convertToMime(const QString &, QList<QByteArray>, QString) | ||
| 1080 | //{ | ||
| 1081 | // qWarning("QMacPasteboardMimeAnyQt3Mime: Cannot write anything!"); | ||
| 1082 | // return QVariant(); | ||
| 1083 | //} | ||
| 1084 | // | ||
| 1085 | //QList<QByteArray> QMacPasteboardMimeQt3Any::convertFromMime(const QString &mime, QVariant data, QString) | ||
| 1086 | //{ | ||
| 1087 | // QList<QByteArray> ret; | ||
| 1088 | // if (mime == QLatin1String("text/plain")) { | ||
| 1089 | // ret.append(data.toString().toUtf8()); | ||
| 1090 | // } else { | ||
| 1091 | // ret.append(data.toByteArray()); | ||
| 1092 | // } | ||
| 1093 | // return ret; | ||
| 1094 | //} | ||
| 1095 | //#endif | ||
| 1096 | // | ||
| 1097 | ///*! | ||
| 1098 | // \internal | ||
| 1099 | // | ||
| 1100 | // This is an internal function. | ||
| 1101 | //*/ | ||
| 1102 | //void QMacPasteboardMime::initialize() | ||
| 1103 | //{ | ||
| 1104 | // if(globalMimeList()->isEmpty()) { | ||
| 1105 | // qAddPostRoutine(cleanup_mimes); | ||
| 1106 | // | ||
| 1107 | // //standard types that we wrap | ||
| 1108 | // new QMacPasteboardMimeTiff; | ||
| 1109 | //#ifdef Q_WS_MAC32 | ||
| 1110 | // // 10.6 does automatic synthesis to and from PICT to standard image types (like TIFF), | ||
| 1111 | // // so don't bother doing it ourselves, especially since it's not available in 64-bit. | ||
| 1112 | // if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6) | ||
| 1113 | // new QMacPasteboardMimePict; | ||
| 1114 | //#endif | ||
| 1115 | // new QMacPasteboardMimeUnicodeText; | ||
| 1116 | // new QMacPasteboardMimePlainText; | ||
| 1117 | // new QMacPasteboardMimeHTMLText; | ||
| 1118 | // new QMacPasteboardMimeFileUri; | ||
| 1119 | // new QMacPasteboardMimeUrl; | ||
| 1120 | // new QMacPasteboardMimeTypeName; | ||
| 1121 | // //make sure our "non-standard" types are always last! --Sam | ||
| 1122 | // new QMacPasteboardMimeAny; | ||
| 1123 | //#ifdef QT3_SUPPORT | ||
| 1124 | // new QMacPasteboardMimeQt3Any; | ||
| 1125 | //#endif | ||
| 1126 | // } | ||
| 1127 | //} | ||
| 1128 | // | ||
| 1129 | ///*! | ||
| 1130 | // Returns the most-recently created QMacPasteboardMime of type \a t that can convert | ||
| 1131 | // between the \a mime and \a flav formats. Returns 0 if no such convertor | ||
| 1132 | // exists. | ||
| 1133 | //*/ | ||
| 1134 | //QMacPasteboardMime* | ||
| 1135 | //QMacPasteboardMime::convertor(uchar t, const QString &mime, QString flav) | ||
| 1136 | //{ | ||
| 1137 | // MimeList *mimes = globalMimeList(); | ||
| 1138 | // for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) { | ||
| 1139 | //#ifdef DEBUG_MIME_MAPS | ||
| 1140 | // qDebug("QMacPasteboardMime::convertor: seeing if %s (%d) can convert %s to %d[%c%c%c%c] [%d]", | ||
| 1141 | // (*it)->convertorName().toLatin1().constData(), | ||
| 1142 | // (*it)->type & t, mime.toLatin1().constData(), | ||
| 1143 | // flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF, | ||
| 1144 | // (*it)->canConvert(mime,flav)); | ||
| 1145 | // for(int i = 0; i < (*it)->countFlavors(); ++i) { | ||
| 1146 | // int f = (*it)->flavor(i); | ||
| 1147 | // qDebug(" %d) %d[%c%c%c%c] [%s]", i, f, | ||
| 1148 | // (f >> 24) & 0xFF, (f >> 16) & 0xFF, (f >> 8) & 0xFF, (f) & 0xFF, | ||
| 1149 | // (*it)->convertorName().toLatin1().constData()); | ||
| 1150 | // } | ||
| 1151 | //#endif | ||
| 1152 | // if(((*it)->type & t) && (*it)->canConvert(mime, flav)) | ||
| 1153 | // return (*it); | ||
| 1154 | // } | ||
| 1155 | // return 0; | ||
| 1156 | //} | ||
| 1157 | ///*! | ||
| 1158 | // Returns a MIME type of type \a t for \a flav, or 0 if none exists. | ||
| 1159 | //*/ | ||
| 1160 | //QString QMacPasteboardMime::flavorToMime(uchar t, QString flav) | ||
| 1161 | //{ | ||
| 1162 | // MimeList *mimes = globalMimeList(); | ||
| 1163 | // for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) { | ||
| 1164 | //#ifdef DEBUG_MIME_MAPS | ||
| 1165 | // qDebug("QMacMIme::flavorToMime: attempting %s (%d) for flavor %d[%c%c%c%c] [%s]", | ||
| 1166 | // (*it)->convertorName().toLatin1().constData(), | ||
| 1167 | // (*it)->type & t, flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF, | ||
| 1168 | // (*it)->mimeFor(flav).toLatin1().constData()); | ||
| 1169 | // | ||
| 1170 | //#endif | ||
| 1171 | // if((*it)->type & t) { | ||
| 1172 | // QString mimeType = (*it)->mimeFor(flav); | ||
| 1173 | // if(!mimeType.isNull()) | ||
| 1174 | // return mimeType; | ||
| 1175 | // } | ||
| 1176 | // } | ||
| 1177 | // return QString(); | ||
| 1178 | //} | ||
| 1179 | // | ||
| 1180 | ///*! | ||
| 1181 | // Returns a list of all currently defined QMacPasteboardMime objects of type \a t. | ||
| 1182 | //*/ | ||
| 1183 | //QList<QMacPasteboardMime*> QMacPasteboardMime::all(uchar t) | ||
| 1184 | //{ | ||
| 1185 | // MimeList ret; | ||
| 1186 | // MimeList *mimes = globalMimeList(); | ||
| 1187 | // for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) { | ||
| 1188 | // if((*it)->type & t) | ||
| 1189 | // ret.append((*it)); | ||
| 1190 | // } | ||
| 1191 | // return ret; | ||
| 1192 | //} | ||
| 1193 | // | ||
| 1194 | |||
| 1195 | /*! | ||
| 1196 | \fn QString QMacPasteboardMime::convertorName() | ||
| 1197 | |||
| 1198 | Returns a name for the convertor. | ||
| 1199 | |||
| 1200 | All subclasses must reimplement this pure virtual function. | ||
| 1201 | */ | ||
| 1202 | |||
| 1203 | /*! | ||
| 1204 | \fn bool QMacPasteboardMime::canConvert(const QString &mime, QString flav) | ||
| 1205 | |||
| 1206 | Returns true if the convertor can convert (both ways) between | ||
| 1207 | \a mime and \a flav; otherwise returns false. | ||
| 1208 | |||
| 1209 | All subclasses must reimplement this pure virtual function. | ||
| 1210 | */ | ||
| 1211 | |||
| 1212 | /*! | ||
| 1213 | \fn QString QMacPasteboardMime::mimeFor(QString flav) | ||
| 1214 | |||
| 1215 | Returns the MIME UTI used for Mac flavor \a flav, or 0 if this | ||
| 1216 | convertor does not support \a flav. | ||
| 1217 | |||
| 1218 | All subclasses must reimplement this pure virtual function. | ||
| 1219 | */ | ||
| 1220 | |||
| 1221 | /*! | ||
| 1222 | \fn QString QMacPasteboardMime::flavorFor(const QString &mime) | ||
| 1223 | |||
| 1224 | Returns the Mac UTI used for MIME type \a mime, or 0 if this | ||
| 1225 | convertor does not support \a mime. | ||
| 1226 | |||
| 1227 | All subclasses must reimplement this pure virtual function. | ||
| 1228 | */ | ||
| 1229 | |||
| 1230 | /*! | ||
| 1231 | \fn QVariant QMacPasteboardMime::convertToMime(const QString &mime, QList<QByteArray> data, QString flav) | ||
| 1232 | |||
| 1233 | Returns \a data converted from Mac UTI \a flav to MIME type \a | ||
| 1234 | mime. | ||
| 1235 | |||
| 1236 | Note that Mac flavors must all be self-terminating. The input \a | ||
| 1237 | data may contain trailing data. | ||
| 1238 | |||
| 1239 | All subclasses must reimplement this pure virtual function. | ||
| 1240 | */ | ||
| 1241 | |||
| 1242 | /*! | ||
| 1243 | \fn QList<QByteArray> QMacPasteboardMime::convertFromMime(const QString &mime, QVariant data, QString flav) | ||
| 1244 | |||
| 1245 | Returns \a data converted from MIME type \a mime | ||
| 1246 | to Mac UTI \a flav. | ||
| 1247 | |||
| 1248 | Note that Mac flavors must all be self-terminating. The return | ||
| 1249 | value may contain trailing data. | ||
| 1250 | |||
| 1251 | All subclasses must reimplement this pure virtual function. | ||
| 1252 | */ | ||
| 1253 | |||
| 1254 | |||
| 1255 | QT_END_NAMESPACE |
src/gui/kernel/qmultitouch_iphone.mm
(219 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include <private/qmultitouch_mac_p.h> | ||
| 43 | #include <qcursor.h> | ||
| 44 | |||
| 45 | #warning qmulit-touch-iphone not finished. | ||
| 46 | |||
| 47 | //#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 48 | // | ||
| 49 | //QT_BEGIN_NAMESPACE | ||
| 50 | // | ||
| 51 | //#ifdef QT_MAC_USE_COCOA | ||
| 52 | // | ||
| 53 | //QHash<qint64, QCocoaTouch*> QCocoaTouch::_currentTouches; | ||
| 54 | //QPointF QCocoaTouch::_screenReferencePos; | ||
| 55 | //QPointF QCocoaTouch::_trackpadReferencePos; | ||
| 56 | //int QCocoaTouch::_idAssignmentCount = 0; | ||
| 57 | //int QCocoaTouch::_touchCount = 0; | ||
| 58 | //bool QCocoaTouch::_updateInternalStateOnly = true; | ||
| 59 | // | ||
| 60 | //QCocoaTouch::QCocoaTouch(NSTouch *nstouch) | ||
| 61 | //{ | ||
| 62 | // if (_currentTouches.size() == 0) | ||
| 63 | // _idAssignmentCount = 0; | ||
| 64 | // | ||
| 65 | // _touchPoint.setId(_idAssignmentCount++); | ||
| 66 | // _touchPoint.setPressure(1.0); | ||
| 67 | // _identity = qint64([nstouch identity]); | ||
| 68 | // _currentTouches.insert(_identity, this); | ||
| 69 | // updateTouchData(nstouch, NSTouchPhaseBegan); | ||
| 70 | //} | ||
| 71 | // | ||
| 72 | //QCocoaTouch::~QCocoaTouch() | ||
| 73 | //{ | ||
| 74 | // _currentTouches.remove(_identity); | ||
| 75 | //} | ||
| 76 | // | ||
| 77 | //void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase) | ||
| 78 | //{ | ||
| 79 | // if (_touchCount == 1) | ||
| 80 | // _touchPoint.setState(toTouchPointState(phase) | Qt::TouchPointPrimary); | ||
| 81 | // else | ||
| 82 | // _touchPoint.setState(toTouchPointState(phase)); | ||
| 83 | // | ||
| 84 | // // From the normalized position on the trackpad, calculate | ||
| 85 | // // where on screen the touchpoint should be according to the | ||
| 86 | // // reference position: | ||
| 87 | // NSPoint npos = [nstouch normalizedPosition]; | ||
| 88 | // QPointF qnpos = QPointF(npos.x, 1 - npos.y); | ||
| 89 | // _touchPoint.setNormalizedPos(qnpos); | ||
| 90 | // | ||
| 91 | // if (_touchPoint.id() == 0 && phase == NSTouchPhaseBegan) { | ||
| 92 | // _trackpadReferencePos = qnpos; | ||
| 93 | // _screenReferencePos = QCursor::pos(); | ||
| 94 | // } | ||
| 95 | // | ||
| 96 | // NSSize dsize = [nstouch deviceSize]; | ||
| 97 | // float ppiX = (qnpos.x() - _trackpadReferencePos.x()) * dsize.width; | ||
| 98 | // float ppiY = (qnpos.y() - _trackpadReferencePos.y()) * dsize.height; | ||
| 99 | // QPointF relativePos = _trackpadReferencePos - QPointF(ppiX, ppiY); | ||
| 100 | // _touchPoint.setScreenPos(_screenReferencePos - relativePos); | ||
| 101 | //} | ||
| 102 | // | ||
| 103 | //QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch) | ||
| 104 | //{ | ||
| 105 | // qint64 identity = qint64([nstouch identity]); | ||
| 106 | // if (_currentTouches.contains(identity)) | ||
| 107 | // return _currentTouches.value(identity); | ||
| 108 | // return 0; | ||
| 109 | //} | ||
| 110 | // | ||
| 111 | //Qt::TouchPointState QCocoaTouch::toTouchPointState(NSTouchPhase nsState) | ||
| 112 | //{ | ||
| 113 | // Qt::TouchPointState qtState = Qt::TouchPointReleased; | ||
| 114 | // switch (nsState) { | ||
| 115 | // case NSTouchPhaseBegan: | ||
| 116 | // qtState = Qt::TouchPointPressed; | ||
| 117 | // break; | ||
| 118 | // case NSTouchPhaseMoved: | ||
| 119 | // qtState = Qt::TouchPointMoved; | ||
| 120 | // break; | ||
| 121 | // case NSTouchPhaseStationary: | ||
| 122 | // qtState = Qt::TouchPointStationary; | ||
| 123 | // break; | ||
| 124 | // case NSTouchPhaseEnded: | ||
| 125 | // case NSTouchPhaseCancelled: | ||
| 126 | // qtState = Qt::TouchPointReleased; | ||
| 127 | // break; | ||
| 128 | // default: | ||
| 129 | // break; | ||
| 130 | // } | ||
| 131 | // return qtState; | ||
| 132 | //} | ||
| 133 | // | ||
| 134 | //QList<QTouchEvent::TouchPoint> | ||
| 135 | //QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) | ||
| 136 | //{ | ||
| 137 | // QMap<int, QTouchEvent::TouchPoint> touchPoints; | ||
| 138 | // NSSet *ended = [event touchesMatchingPhase:NSTouchPhaseEnded | NSTouchPhaseCancelled inView:nil]; | ||
| 139 | // NSSet *active = [event | ||
| 140 | // touchesMatchingPhase:NSTouchPhaseBegan | NSTouchPhaseMoved | NSTouchPhaseStationary | ||
| 141 | // inView:nil]; | ||
| 142 | // _touchCount = [active count]; | ||
| 143 | // | ||
| 144 | // // First: remove touches that were ended by the user. If we are | ||
| 145 | // // currently not accepting single touches, a corresponding 'begin' | ||
| 146 | // // has never been send to the app for these events. | ||
| 147 | // // So should therefore not send the following removes either. | ||
| 148 | // | ||
| 149 | // for (int i=0; i<int([ended count]); ++i) { | ||
| 150 | // NSTouch *touch = [[ended allObjects] objectAtIndex:i]; | ||
| 151 | // QCocoaTouch *qcocoaTouch = findQCocoaTouch(touch); | ||
| 152 | // if (qcocoaTouch) { | ||
| 153 | // qcocoaTouch->updateTouchData(touch, [touch phase]); | ||
| 154 | // if (!_updateInternalStateOnly) | ||
| 155 | // touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); | ||
| 156 | // delete qcocoaTouch; | ||
| 157 | // } | ||
| 158 | // } | ||
| 159 | // | ||
| 160 | // bool wasUpdateInternalStateOnly = _updateInternalStateOnly; | ||
| 161 | // _updateInternalStateOnly = !acceptSingleTouch && _touchCount < 2; | ||
| 162 | // | ||
| 163 | // // Next: update, or create, existing touches. | ||
| 164 | // // We always keep track of all touch points, even | ||
| 165 | // // when not accepting single touches. | ||
| 166 | // | ||
| 167 | // for (int i=0; i<int([active count]); ++i) { | ||
| 168 | // NSTouch *touch = [[active allObjects] objectAtIndex:i]; | ||
| 169 | // QCocoaTouch *qcocoaTouch = findQCocoaTouch(touch); | ||
| 170 | // if (!qcocoaTouch) | ||
| 171 | // qcocoaTouch = new QCocoaTouch(touch); | ||
| 172 | // else | ||
| 173 | // qcocoaTouch->updateTouchData(touch, wasUpdateInternalStateOnly ? NSTouchPhaseBegan : [touch phase]); | ||
| 174 | // if (!_updateInternalStateOnly) | ||
| 175 | // touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); | ||
| 176 | // } | ||
| 177 | // | ||
| 178 | // // Next: sadly, we need to check that our touch hash is in | ||
| 179 | // // sync with cocoa. This is typically not the case after a system | ||
| 180 | // // gesture happend (like a four-finger-swipe to show expose). | ||
| 181 | // | ||
| 182 | // if (_touchCount != _currentTouches.size()) { | ||
| 183 | // // Remove all instances, and basically start from scratch: | ||
| 184 | // touchPoints.clear(); | ||
| 185 | // foreach (QCocoaTouch *qcocoaTouch, _currentTouches.values()) { | ||
| 186 | // if (!_updateInternalStateOnly) { | ||
| 187 | // qcocoaTouch->_touchPoint.setState(Qt::TouchPointReleased); | ||
| 188 | // touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); | ||
| 189 | // } | ||
| 190 | // delete qcocoaTouch; | ||
| 191 | // } | ||
| 192 | // _currentTouches.clear(); | ||
| 193 | // _updateInternalStateOnly = !acceptSingleTouch; | ||
| 194 | // return touchPoints.values(); | ||
| 195 | // } | ||
| 196 | // | ||
| 197 | // // Finally: If this call _started_ to reject single | ||
| 198 | // // touches, we need to fake a relase for the remaining | ||
| 199 | // // touch now (and refake a begin for it later, if needed). | ||
| 200 | // | ||
| 201 | // if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.isEmpty()) { | ||
| 202 | // QCocoaTouch *qcocoaTouch = _currentTouches.values().first(); | ||
| 203 | // qcocoaTouch->_touchPoint.setState(Qt::TouchPointReleased); | ||
| 204 | // touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint); | ||
| 205 | // // Since this last touch also will end up beeing the first | ||
| 206 | // // touch (if the user adds a second finger without lifting | ||
| 207 | // // the first), we promote it to be the primary touch: | ||
| 208 | // qcocoaTouch->_touchPoint.setId(0); | ||
| 209 | // _idAssignmentCount = 1; | ||
| 210 | // } | ||
| 211 | // | ||
| 212 | // return touchPoints.values(); | ||
| 213 | //} | ||
| 214 | // | ||
| 215 | //#endif | ||
| 216 | // | ||
| 217 | //QT_END_NAMESPACE | ||
| 218 | // | ||
| 219 | //#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists for the convenience | ||
| 47 | // of other Qt classes. This header file may change from version to | ||
| 48 | // version without notice, or even be removed. | ||
| 49 | // | ||
| 50 | // We mean it. | ||
| 51 | // | ||
| 52 | |||
| 53 | #ifndef QMULTITOUCH_MAC_P_H | ||
| 54 | #define QMULTITOUCH_MAC_P_H | ||
| 55 | |||
| 56 | //#ifdef QT_MAC_USE_COCOA | ||
| 57 | //#import <Cocoa/Cocoa.h> | ||
| 58 | //#endif | ||
| 59 | |||
| 60 | #include <qevent.h> | ||
| 61 | #include <qhash.h> | ||
| 62 | #include <QtCore> | ||
| 63 | |||
| 64 | //#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 65 | // | ||
| 66 | //QT_BEGIN_NAMESPACE | ||
| 67 | // | ||
| 68 | //#ifdef QT_MAC_USE_COCOA | ||
| 69 | // | ||
| 70 | //class QCocoaTouch | ||
| 71 | //{ | ||
| 72 | // public: | ||
| 73 | // static QList<QTouchEvent::TouchPoint> getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch); | ||
| 74 | // static void setMouseInDraggingState(bool inDraggingState); | ||
| 75 | // | ||
| 76 | // private: | ||
| 77 | // static QHash<qint64, QCocoaTouch*> _currentTouches; | ||
| 78 | // static QPointF _screenReferencePos; | ||
| 79 | // static QPointF _trackpadReferencePos; | ||
| 80 | // static int _idAssignmentCount; | ||
| 81 | // static int _touchCount; | ||
| 82 | // static bool _updateInternalStateOnly; | ||
| 83 | // | ||
| 84 | // QTouchEvent::TouchPoint _touchPoint; | ||
| 85 | // qint64 _identity; | ||
| 86 | // | ||
| 87 | // QCocoaTouch(NSTouch *nstouch); | ||
| 88 | // ~QCocoaTouch(); | ||
| 89 | // | ||
| 90 | // void updateTouchData(NSTouch *nstouch, NSTouchPhase phase); | ||
| 91 | // static QCocoaTouch *findQCocoaTouch(NSTouch *nstouch); | ||
| 92 | // static Qt::TouchPointState toTouchPointState(NSTouchPhase nsState); | ||
| 93 | //}; | ||
| 94 | // | ||
| 95 | //#endif // QT_MAC_USE_COCOA | ||
| 96 | // | ||
| 97 | //QT_END_NAMESPACE | ||
| 98 | // | ||
| 99 | //#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 | ||
| 100 | // | ||
| 101 | //#endif // QMULTITOUCH_MAC_P_H | ||
| 102 | // |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists for the convenience | ||
| 47 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 48 | // and many other. This header file may change from version to version | ||
| 49 | // without notice, or even be removed. | ||
| 50 | // | ||
| 51 | // We mean it. | ||
| 52 | // | ||
| 53 | |||
| 54 | // Private AppKit class (dumped from classdump). | ||
| 55 | |||
| 56 | #warning qNSFramWindow_iphone not implemented. | ||
| 57 | // | ||
| 58 | //#import <Cocoa/Cocoa.h> | ||
| 59 | // | ||
| 60 | //@interface NSFrameView : NSView | ||
| 61 | //{ | ||
| 62 | // unsigned int styleMask; | ||
| 63 | // NSString *_title; | ||
| 64 | // NSCell *titleCell; | ||
| 65 | // NSButton *closeButton; | ||
| 66 | // NSButton *zoomButton; | ||
| 67 | // NSButton *minimizeButton; | ||
| 68 | // char resizeByIncrement; | ||
| 69 | // char frameNeedsDisplay; | ||
| 70 | // unsigned char tabViewCount; | ||
| 71 | // NSSize resizeParameter; | ||
| 72 | // int shadowState; | ||
| 73 | //} | ||
| 74 | // | ||
| 75 | //+ (void)initialize; | ||
| 76 | //+ (void)initTitleCell:fp8 styleMask:(unsigned int)fp12; | ||
| 77 | //+ (struct _NSRect)frameRectForContentRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 78 | //+ (struct _NSRect)contentRectForFrameRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 79 | //+ (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16; | ||
| 80 | //+ (struct _NSSize)minContentSizeForMinFrameSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16; | ||
| 81 | //+ (float)minFrameWidthWithTitle:fp8 styleMask:(unsigned int)fp12; | ||
| 82 | //+ (unsigned int)_validateStyleMask:(unsigned int)fp8; | ||
| 83 | //- initWithFrame:(struct _NSRect)fp8 styleMask:(unsigned int)fp24 owner:fp28; | ||
| 84 | //- initWithFrame:(struct _NSRect)fp8; | ||
| 85 | //- (void)dealloc; | ||
| 86 | //- (void)shapeWindow; | ||
| 87 | //- (void)tileAndSetWindowShape:(char)fp8; | ||
| 88 | //- (void)tile; | ||
| 89 | //- (void)drawRect:(struct _NSRect)fp8; | ||
| 90 | //- (void)_drawFrameRects:(struct _NSRect)fp8; | ||
| 91 | //- (void)drawFrame:(struct _NSRect)fp8; | ||
| 92 | //- (void)drawThemeContentFill:(struct _NSRect)fp8 inView:fp24; | ||
| 93 | //- (void)drawWindowBackgroundRect:(struct _NSRect)fp8; | ||
| 94 | //- (void)drawWindowBackgroundRegion:(void *)fp8; | ||
| 95 | //- (float)contentAlpha; | ||
| 96 | //- (void)_windowChangedKeyState; | ||
| 97 | //- (void)_updateButtonState; | ||
| 98 | //- (char)_isSheet; | ||
| 99 | //- (char)_isUtility; | ||
| 100 | //- (void)setShadowState:(int)fp8; | ||
| 101 | //- (int)shadowState; | ||
| 102 | //- (char)_canHaveToolbar; | ||
| 103 | //- (char)_toolbarIsInTransition; | ||
| 104 | //- (char)_toolbarIsShown; | ||
| 105 | //- (char)_toolbarIsHidden; | ||
| 106 | //- (void)_showToolbarWithAnimation:(char)fp8; | ||
| 107 | //- (void)_hideToolbarWithAnimation:(char)fp8; | ||
| 108 | //- (float)_distanceFromToolbarBaseToTitlebar; | ||
| 109 | //- (int)_shadowType; | ||
| 110 | //- (unsigned int)_shadowFlags; | ||
| 111 | //- (void)_setShadowParameters; | ||
| 112 | //- (void)_drawFrameShadowAndFlushContext:fp8; | ||
| 113 | //- (void)setUpGState; | ||
| 114 | //- (void)adjustHalftonePhase; | ||
| 115 | //- (void)systemColorsDidChange:fp8; | ||
| 116 | //- frameColor; | ||
| 117 | //- contentFill; | ||
| 118 | //- (void)tabViewAdded; | ||
| 119 | //- (void)tabViewRemoved; | ||
| 120 | //- title; | ||
| 121 | //- (void)setTitle:fp8; | ||
| 122 | //- titleCell; | ||
| 123 | //- (void)initTitleCell:fp8; | ||
| 124 | //- (void)setResizeIncrements:(struct _NSSize)fp8; | ||
| 125 | //- (struct _NSSize)resizeIncrements; | ||
| 126 | //- (void)setAspectRatio:(struct _NSSize)fp8; | ||
| 127 | //- (struct _NSSize)aspectRatio; | ||
| 128 | //- (unsigned int)styleMask; | ||
| 129 | //- representedFilename; | ||
| 130 | //- (void)setRepresentedFilename:fp8; | ||
| 131 | //- (void)setDocumentEdited:(char)fp8; | ||
| 132 | //- (void)_setFrameNeedsDisplay:(char)fp8; | ||
| 133 | //- (char)frameNeedsDisplay; | ||
| 134 | //- titleFont; | ||
| 135 | //- (struct _NSRect)_maxTitlebarTitleRect; | ||
| 136 | //- (struct _NSRect)titlebarRect; | ||
| 137 | //- (void)_setUtilityWindow:(char)fp8; | ||
| 138 | //- (void)_setNonactivatingPanel:(char)fp8; | ||
| 139 | //- (void)setIsClosable:(char)fp8; | ||
| 140 | //- (void)setIsResizable:(char)fp8; | ||
| 141 | //- closeButton; | ||
| 142 | //- minimizeButton; | ||
| 143 | //- zoomButton; | ||
| 144 | //- (struct _NSSize)miniaturizedSize; | ||
| 145 | //- (void)_clearDragMargins; | ||
| 146 | //- (void)_resetDragMargins; | ||
| 147 | //- (void)setTitle:fp8 andDefeatWrap:(char)fp12; | ||
| 148 | //- (struct _NSRect)frameRectForContentRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 149 | //- (struct _NSRect)contentRectForFrameRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 150 | //- (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16; | ||
| 151 | //- (struct _NSRect)dragRectForFrameRect:(struct _NSRect)fp8; | ||
| 152 | //- (struct _NSRect)contentRect; | ||
| 153 | //- (struct _NSSize)minFrameSize; | ||
| 154 | //- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(struct _NSRect)fp8 isVisibleRect:(char)fp24 rectIsVisibleRectForView:fp28 topView:(char)fp32; | ||
| 155 | // | ||
| 156 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists for the convenience | ||
| 47 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 48 | // and many other. This header file may change from version to version | ||
| 49 | // without notice, or even be removed. | ||
| 50 | // | ||
| 51 | // We mean it. | ||
| 52 | // | ||
| 53 | |||
| 54 | // Private AppKit class (dumped from classdump). | ||
| 55 | |||
| 56 | //#import <Cocoa/Cocoa.h> | ||
| 57 | #import "qnstitledframe_iphone_p.h" | ||
| 58 | #warning qnsthemeframe_iphone_p.h not implemented. | ||
| 59 | //@interface NSThemeFrame : NSTitledFrame | ||
| 60 | //{ | ||
| 61 | // NSButton *toolbarButton; | ||
| 62 | // int toolbarVisibleStatus; | ||
| 63 | // NSImage *showToolbarTransitionImage; | ||
| 64 | // NSSize showToolbarPreWindowSize; | ||
| 65 | // NSButton *modeButton; | ||
| 66 | // int leftGroupTrackingTagNum; | ||
| 67 | // int rightGroupTrackingTagNum; | ||
| 68 | // char mouseInsideLeftGroup; | ||
| 69 | // char mouseInsideRightGroup; | ||
| 70 | // int widgetState; | ||
| 71 | // NSString *displayName; | ||
| 72 | //} | ||
| 73 | // | ||
| 74 | //+ (void)initialize; | ||
| 75 | //+ (float)_windowBorderThickness:(unsigned int)fp8; | ||
| 76 | //+ (float)_minXWindowBorderWidth:(unsigned int)fp8; | ||
| 77 | //+ (float)_maxXWindowBorderWidth:(unsigned int)fp8; | ||
| 78 | //+ (float)_minYWindowBorderHeight:(unsigned int)fp8; | ||
| 79 | //+ (float)_windowTitlebarButtonSpacingWidth:(unsigned int)fp8; | ||
| 80 | //+ (float)_windowFileButtonSpacingWidth:(unsigned int)fp8; | ||
| 81 | //+ (float)_minXTitlebarWidgetInset:(unsigned int)fp8; | ||
| 82 | //+ (float)_maxXTitlebarWidgetInset:(unsigned int)fp8; | ||
| 83 | //+ (float)minFrameWidthWithTitle:fp8 styleMask:(unsigned int)fp12; | ||
| 84 | //+ (float)_windowSideTitlebarTitleMinWidth:(unsigned int)fp8; | ||
| 85 | //+ (float)_windowTitlebarTitleMinHeight:(unsigned int)fp8; | ||
| 86 | //+ (float)_sideTitlebarWidth:(unsigned int)fp8; | ||
| 87 | //+ (float)_titlebarHeight:(unsigned int)fp8; | ||
| 88 | //+ (float)_resizeHeight:(unsigned int)fp8; | ||
| 89 | //+ (char)_resizeFromEdge; | ||
| 90 | //+ (struct _NSSize)sizeOfTitlebarButtons:(unsigned int)fp8; | ||
| 91 | //+ (float)_contentToFrameMinXWidth:(unsigned int)fp8; | ||
| 92 | //+ (float)_contentToFrameMaxXWidth:(unsigned int)fp8; | ||
| 93 | //+ (float)_contentToFrameMinYHeight:(unsigned int)fp8; | ||
| 94 | //+ (float)_contentToFrameMaxYHeight:(unsigned int)fp8; | ||
| 95 | //+ (unsigned int)_validateStyleMask:(unsigned int)fp8; | ||
| 96 | //- (struct _NSSize)_topCornerSize; | ||
| 97 | //- (struct _NSSize)_bottomCornerSize; | ||
| 98 | //- (void *)_createWindowOpaqueShape; | ||
| 99 | //- (void)shapeWindow; | ||
| 100 | //- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)fp8 isVisibleRect:(char)fp24 rectIsVisibleRectForView:fp28 topView:(char)fp32; | ||
| 101 | //- (void *)_regionForOpaqueDescendants:(NSRect)fp8 forMove:(char)fp24; | ||
| 102 | //- (void)_drawFrameInterior:(NSRect *)fp8 clip:(NSRect)fp12; | ||
| 103 | //- (void)_setTextShadow:(char)fp8; | ||
| 104 | //- (void)_drawTitleBar:(NSRect)fp8; | ||
| 105 | //- (void)_drawResizeIndicators:(NSRect)fp8; | ||
| 106 | //- (void)_drawFrameRects:(NSRect)fp8; | ||
| 107 | //- (void)drawFrame:(NSRect)fp8; | ||
| 108 | //- contentFill; | ||
| 109 | //- (void)viewDidEndLiveResize; | ||
| 110 | //- (float)contentAlpha; | ||
| 111 | //- (void)setThemeFrameWidgetState:(int)fp8; | ||
| 112 | //- (char)constrainResizeEdge:(int *)fp8 withDelta:(struct _NSSize)fp12 elapsedTime:(float)fp20; | ||
| 113 | //- (void)addFileButton:fp8; | ||
| 114 | //- (void)_updateButtons; | ||
| 115 | //- (void)_updateButtonState; | ||
| 116 | //- newCloseButton; | ||
| 117 | //- newZoomButton; | ||
| 118 | //- newMiniaturizeButton; | ||
| 119 | //- newToolbarButton; | ||
| 120 | //- newFileButton; | ||
| 121 | //- (void)_resetTitleBarButtons; | ||
| 122 | //- (void)setDocumentEdited:(char)fp8; | ||
| 123 | //- toolbarButton; | ||
| 124 | //- modeButton; | ||
| 125 | //- initWithFrame:(NSRect)fp8 styleMask:(unsigned int)fp24 owner:fp28; | ||
| 126 | //- (void)dealloc; | ||
| 127 | //- (void)setFrameSize:(struct _NSSize)fp8; | ||
| 128 | //- (char)_canHaveToolbar; | ||
| 129 | //- (char)_toolbarIsInTransition; | ||
| 130 | //- (char)_toolbarIsShown; | ||
| 131 | //- (char)_toolbarIsHidden; | ||
| 132 | //- _toolbarView; | ||
| 133 | //- _toolbar; | ||
| 134 | //- (float)_distanceFromToolbarBaseToTitlebar; | ||
| 135 | //- (unsigned int)_shadowFlags; | ||
| 136 | //- (NSRect)frameRectForContentRect:(NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 137 | //- (NSRect)contentRectForFrameRect:(NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 138 | //- (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16; | ||
| 139 | //- (NSRect)contentRect; | ||
| 140 | //- (NSRect)_contentRectExcludingToolbar; | ||
| 141 | //- (NSRect)_contentRectIncludingToolbarAtHome; | ||
| 142 | //- (void)_setToolbarShowHideResizeWeightingOptimizationOn:(char)fp8; | ||
| 143 | //- (char)_usingToolbarShowHideWeightingOptimization; | ||
| 144 | //- (void)handleSetFrameCommonRedisplay; | ||
| 145 | //- (void)_startLiveResizeAsTopLevel; | ||
| 146 | //- (void)_endLiveResizeAsTopLevel; | ||
| 147 | //- (void)_growContentReshapeContentAndToolbarView:(int)fp8 animate:(char)fp12; | ||
| 148 | //- (char)_growWindowReshapeContentAndToolbarView:(int)fp8 animate:(char)fp12; | ||
| 149 | //- (void)_reshapeContentAndToolbarView:(int)fp8 resizeWindow:(char)fp12 animate:(char)fp16; | ||
| 150 | //- (void)_toolbarFrameSizeChanged:fp8 oldSize:(struct _NSSize)fp12; | ||
| 151 | //- (void)_syncToolbarPosition; | ||
| 152 | //- (void)_showHideToolbar:(int)fp8 resizeWindow:(char)fp12 animate:(char)fp16; | ||
| 153 | //- (void)_showToolbarWithAnimation:(char)fp8; | ||
| 154 | //- (void)_hideToolbarWithAnimation:(char)fp8; | ||
| 155 | //- (void)_drawToolbarTransitionIfNecessary; | ||
| 156 | //- (void)drawRect:(NSRect)fp8; | ||
| 157 | //- (void)resetCursorRects; | ||
| 158 | //- (char)shouldBeTreatedAsInkEvent:fp8; | ||
| 159 | //- (char)_shouldBeTreatedAsInkEventInInactiveWindow:fp8; | ||
| 160 | //- hitTest:(struct _NSPoint)fp8; | ||
| 161 | //- (NSRect)_leftGroupRect; | ||
| 162 | //- (NSRect)_rightGroupRect; | ||
| 163 | //- (void)_updateWidgets; | ||
| 164 | //- (void)_updateMouseTracking; | ||
| 165 | //- (void)mouseEntered:fp8; | ||
| 166 | //- (void)mouseExited:fp8; | ||
| 167 | //- (void)_setMouseEnteredGroup:(char)fp8 entered:(char)fp12; | ||
| 168 | //- (char)_mouseInGroup:fp8; | ||
| 169 | //- (struct _NSSize)miniaturizedSize; | ||
| 170 | //- (float)_minXTitlebarDecorationMinWidth; | ||
| 171 | //- (float)_maxXTitlebarDecorationMinWidth; | ||
| 172 | //- (struct _NSSize)minFrameSize; | ||
| 173 | //- (float)_windowBorderThickness; | ||
| 174 | //- (float)_windowTitlebarXResizeBorderThickness; | ||
| 175 | //- (float)_windowTitlebarYResizeBorderThickness; | ||
| 176 | //- (float)_windowResizeBorderThickness; | ||
| 177 | //- (float)_minXWindowBorderWidth; | ||
| 178 | //- (float)_maxXWindowBorderWidth; | ||
| 179 | //- (float)_minYWindowBorderHeight; | ||
| 180 | //- (float)_maxYWindowBorderHeight; | ||
| 181 | //- (float)_minYTitlebarButtonsOffset; | ||
| 182 | //- (float)_minYTitlebarTitleOffset; | ||
| 183 | //- (float)_sideTitlebarWidth; | ||
| 184 | //- (float)_titlebarHeight; | ||
| 185 | //- (NSRect)_titlebarTitleRect; | ||
| 186 | //- (NSRect)titlebarRect; | ||
| 187 | //- (float)_windowTitlebarTitleMinHeight; | ||
| 188 | //- (struct _NSSize)_sizeOfTitlebarFileButton; | ||
| 189 | //- (struct _NSSize)sizeOfTitlebarToolbarButton; | ||
| 190 | //- (float)_windowTitlebarButtonSpacingWidth; | ||
| 191 | //- (float)_windowFileButtonSpacingWidth; | ||
| 192 | //- (float)_minXTitlebarWidgetInset; | ||
| 193 | //- (float)_maxXTitlebarWidgetInset; | ||
| 194 | //- (float)_minXTitlebarButtonsWidth; | ||
| 195 | //- (float)_maxXTitlebarButtonsWidth; | ||
| 196 | //- (struct _NSPoint)_closeButtonOrigin; | ||
| 197 | //- (struct _NSPoint)_zoomButtonOrigin; | ||
| 198 | //- (struct _NSPoint)_collapseButtonOrigin; | ||
| 199 | //- (struct _NSPoint)_toolbarButtonOrigin; | ||
| 200 | //- (struct _NSPoint)_fileButtonOrigin; | ||
| 201 | //- (void)_tileTitlebar; | ||
| 202 | //- (NSRect)_commandPopupRect; | ||
| 203 | //- (void)_resetDragMargins; | ||
| 204 | //- (float)_maxYTitlebarDragHeight; | ||
| 205 | //- (float)_minXTitlebarDragWidth; | ||
| 206 | //- (float)_maxXTitlebarDragWidth; | ||
| 207 | //- (float)_contentToFrameMinXWidth; | ||
| 208 | //- (float)_contentToFrameMaxXWidth; | ||
| 209 | //- (float)_contentToFrameMinYHeight; | ||
| 210 | //- (float)_contentToFrameMaxYHeight; | ||
| 211 | //- (float)_windowResizeCornerThickness; | ||
| 212 | //- (NSRect)_minYResizeRect; | ||
| 213 | //- (NSRect)_minYminXResizeRect; | ||
| 214 | //- (NSRect)_minYmaxXResizeRect; | ||
| 215 | //- (NSRect)_minXResizeRect; | ||
| 216 | //- (NSRect)_minXminYResizeRect; | ||
| 217 | //- (NSRect)_minXmaxYResizeRect; | ||
| 218 | //- (NSRect)_maxYResizeRect; | ||
| 219 | //- (NSRect)_maxYminXResizeRect; | ||
| 220 | //- (NSRect)_maxYmaxXResizeRect; | ||
| 221 | //- (NSRect)_maxXResizeRect; | ||
| 222 | //- (NSRect)_maxXminYResizeRect; | ||
| 223 | //- (NSRect)_maxXmaxYResizeRect; | ||
| 224 | //- (NSRect)_minXTitlebarResizeRect; | ||
| 225 | //- (NSRect)_maxXTitlebarResizeRect; | ||
| 226 | //- (NSRect)_minXBorderRect; | ||
| 227 | //- (NSRect)_maxXBorderRect; | ||
| 228 | //- (NSRect)_maxYBorderRect; | ||
| 229 | //- (NSRect)_minYBorderRect; | ||
| 230 | //- (void)_setUtilityWindow:(char)fp8; | ||
| 231 | //- (char)_isUtility; | ||
| 232 | //- (float)_sheetHeightAdjustment; | ||
| 233 | //- (void)_setSheet:(char)fp8; | ||
| 234 | //- (char)_isSheet; | ||
| 235 | //- (char)_isResizable; | ||
| 236 | //- (char)_isClosable; | ||
| 237 | //- (char)_isMiniaturizable; | ||
| 238 | //- (char)_hasToolbar; | ||
| 239 | //- (NSRect)_growBoxRect; | ||
| 240 | //- (void)_drawGrowBoxWithClip:(NSRect)fp8; | ||
| 241 | //- (char)_inactiveButtonsNeedMask; | ||
| 242 | //- (void)mouseDown:fp8; | ||
| 243 | //- _displayName; | ||
| 244 | //- (void)_setDisplayName:fp8; | ||
| 245 | // | ||
| 246 | //@end |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | // | ||
| 43 | // W A R N I N G | ||
| 44 | // ------------- | ||
| 45 | // | ||
| 46 | // This file is not part of the Qt API. It exists for the convenience | ||
| 47 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 48 | // and many other. This header file may change from version to version | ||
| 49 | // without notice, or even be removed. | ||
| 50 | // | ||
| 51 | // We mean it. | ||
| 52 | // | ||
| 53 | |||
| 54 | // Private AppKit class (dumped from classdump). | ||
| 55 | |||
| 56 | //#import <Cocoa/Cocoa.h> | ||
| 57 | #import "qnsframeview_iphone_p.h" | ||
| 58 | #warning qnstitledframe_iphone_p.h not implemented. | ||
| 59 | |||
| 60 | //@interface NSTitledFrame : NSFrameView | ||
| 61 | //{ | ||
| 62 | // int resizeFlags; | ||
| 63 | // id fileButton; /* NSDocumentDragButton* */ | ||
| 64 | // NSSize titleCellSize; | ||
| 65 | //} | ||
| 66 | // | ||
| 67 | //+ (float)_windowBorderThickness:(unsigned int)fp8; | ||
| 68 | //+ (float)_minXWindowBorderWidth:(unsigned int)fp8; | ||
| 69 | //+ (float)_maxXWindowBorderWidth:(unsigned int)fp8; | ||
| 70 | //+ (float)_minYWindowBorderHeight:(unsigned int)fp8; | ||
| 71 | //+ (char)_resizeFromEdge; | ||
| 72 | //+ (NSRect)frameRectForContentRect:(NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 73 | //+ (NSRect)contentRectForFrameRect:(NSRect)fp8 styleMask:(unsigned int)fp24; | ||
| 74 | //+ (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16; | ||
| 75 | //+ (struct _NSSize)minContentSizeForMinFrameSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16; | ||
| 76 | //+ (float)minFrameWidthWithTitle:fp8 styleMask:(unsigned int)fp12; | ||
| 77 | //+ (struct _NSSize)_titleCellSizeForTitle:fp8 styleMask:(unsigned int)fp12; | ||
| 78 | //+ (float)_titleCellHeight:(unsigned int)fp8; | ||
| 79 | //+ (float)_windowTitlebarTitleMinHeight:(unsigned int)fp8; | ||
| 80 | //+ (float)_titlebarHeight:(unsigned int)fp8; | ||
| 81 | //+ (struct _NSSize)sizeOfTitlebarButtons:(unsigned int)fp8; | ||
| 82 | //+ (float)windowTitlebarLinesSpacingWidth:(unsigned int)fp8; | ||
| 83 | //+ (float)windowTitlebarTitleLinesSpacingWidth:(unsigned int)fp8; | ||
| 84 | //+ (float)_contentToFrameMinXWidth:(unsigned int)fp8; | ||
| 85 | //+ (float)_contentToFrameMaxXWidth:(unsigned int)fp8; | ||
| 86 | //+ (float)_contentToFrameMinYHeight:(unsigned int)fp8; | ||
| 87 | //+ (float)_contentToFrameMaxYHeight:(unsigned int)fp8; | ||
| 88 | //- initWithFrame:(NSRect)fp8 styleMask:(unsigned int)fp24 owner:fp28; | ||
| 89 | //- (void)dealloc; | ||
| 90 | //- (void)setIsClosable:(char)fp8; | ||
| 91 | //- (void)setIsResizable:(char)fp8; | ||
| 92 | //- (void)_resetTitleFont; | ||
| 93 | //- (void)_setUtilityWindow:(char)fp8; | ||
| 94 | //- (char)isOpaque; | ||
| 95 | //- (char)worksWhenModal; | ||
| 96 | //- (void)propagateFrameDirtyRects:(NSRect)fp8; | ||
| 97 | //- (void)_showDrawRect:(NSRect)fp8; | ||
| 98 | //- (void)_drawFrameInterior:(NSRect *)fp8 clip:(NSRect)fp12; | ||
| 99 | //- (void)drawFrame:(NSRect)fp8; | ||
| 100 | //- (void)_drawFrameRects:(NSRect)fp8; | ||
| 101 | //- (void)_drawTitlebar:(NSRect)fp8; | ||
| 102 | //- (void)_drawTitlebarPattern:(int)fp8 inRect:(NSRect)fp12 clippedByRect:(NSRect)fp28 forKey:(char)fp44 alignment:(int)fp48; | ||
| 103 | //- (void)_drawTitlebarLines:(int)fp8 inRect:(NSRect)fp12 clippedByRect:(NSRect)fp28; | ||
| 104 | //- frameHighlightColor; | ||
| 105 | //- frameShadowColor; | ||
| 106 | //- (void)setFrameSize:(struct _NSSize)fp8; | ||
| 107 | //- (void)setFrameOrigin:(struct _NSPoint)fp8; | ||
| 108 | //- (void)tileAndSetWindowShape:(char)fp8; | ||
| 109 | //- (void)tile; | ||
| 110 | //- (void)_tileTitlebar; | ||
| 111 | //- (void)setTitle:fp8; | ||
| 112 | //- (char)_shouldRepresentFilename; | ||
| 113 | //- (void)setRepresentedFilename:fp8; | ||
| 114 | //- (void)_drawTitleStringIn:(NSRect)fp8 withColor:fp24; | ||
| 115 | //- titleFont; | ||
| 116 | //- (void)_drawResizeIndicators:(NSRect)fp8; | ||
| 117 | //- titleButtonOfClass:(Class)fp8; | ||
| 118 | //- initTitleButton:fp8; | ||
| 119 | //- newCloseButton; | ||
| 120 | //- newZoomButton; | ||
| 121 | //- newMiniaturizeButton; | ||
| 122 | //- newFileButton; | ||
| 123 | //- fileButton; | ||
| 124 | //- (void)_removeButtons; | ||
| 125 | //- (void)_updateButtons; | ||
| 126 | //- (char)_eventInTitlebar:fp8; | ||
| 127 | //- (char)acceptsFirstMouse:fp8; | ||
| 128 | //- (void)mouseDown:fp8; | ||
| 129 | //- (void)mouseUp:fp8; | ||
| 130 | //- (void)rightMouseDown:fp8; | ||
| 131 | //- (void)rightMouseUp:fp8; | ||
| 132 | //- (int)resizeEdgeForEvent:fp8; | ||
| 133 | //- (struct _NSSize)_resizeDeltaFromPoint:(struct _NSPoint)fp8 toEvent:fp16; | ||
| 134 | //- (NSRect)_validFrameForResizeFrame:(NSRect)fp8 fromResizeEdge:(int)fp24; | ||
| 135 | //- (NSRect)frame:(NSRect)fp8 resizedFromEdge:(int)fp24 withDelta:(struct _NSSize)fp28; | ||
| 136 | //- (char)constrainResizeEdge:(int *)fp8 withDelta:(struct _NSSize)fp12 elapsedTime:(float)fp20; | ||
| 137 | //- (void)resizeWithEvent:fp8; | ||
| 138 | //- (int)resizeFlags; | ||
| 139 | //- (void)resetCursorRects; | ||
| 140 | //- (void)setDocumentEdited:(char)fp8; | ||
| 141 | //- (struct _NSSize)miniaturizedSize; | ||
| 142 | //- (struct _NSSize)minFrameSize; | ||
| 143 | //- (float)_windowBorderThickness; | ||
| 144 | //- (float)_windowTitlebarXResizeBorderThickness; | ||
| 145 | //- (float)_windowTitlebarYResizeBorderThickness; | ||
| 146 | //- (float)_windowResizeBorderThickness; | ||
| 147 | //- (float)_minXWindowBorderWidth; | ||
| 148 | //- (float)_maxXWindowBorderWidth; | ||
| 149 | //- (float)_minYWindowBorderHeight; | ||
| 150 | //- (void)_invalidateTitleCellSize; | ||
| 151 | //- (void)_invalidateTitleCellWidth; | ||
| 152 | //- (float)_titleCellHeight; | ||
| 153 | //- (struct _NSSize)_titleCellSize; | ||
| 154 | //- (float)_titlebarHeight; | ||
| 155 | //- (NSRect)titlebarRect; | ||
| 156 | //- (NSRect)_maxTitlebarTitleRect; | ||
| 157 | //- (NSRect)_titlebarTitleRect; | ||
| 158 | //- (float)_windowTitlebarTitleMinHeight; | ||
| 159 | //- (NSRect)dragRectForFrameRect:(NSRect)fp8; | ||
| 160 | //- (struct _NSSize)sizeOfTitlebarButtons; | ||
| 161 | //- (struct _NSSize)_sizeOfTitlebarFileButton; | ||
| 162 | //- (float)_windowTitlebarButtonSpacingWidth; | ||
| 163 | //- (float)_minXTitlebarButtonsWidth; | ||
| 164 | //- (float)_maxXTitlebarButtonsWidth; | ||
| 165 | //- (int)_numberOfTitlebarLines; | ||
| 166 | //- (float)windowTitlebarLinesSpacingWidth; | ||
| 167 | //- (float)windowTitlebarTitleLinesSpacingWidth; | ||
| 168 | //- (float)_minLinesWidthWithSpace; | ||
| 169 | //- (NSRect)_minXTitlebarLinesRectWithTitleCellRect:(NSRect)fp8; | ||
| 170 | //- (NSRect)_maxXTitlebarLinesRectWithTitleCellRect:(NSRect)fp8; | ||
| 171 | //- (float)_minXTitlebarDecorationMinWidth; | ||
| 172 | //- (float)_maxXTitlebarDecorationMinWidth; | ||
| 173 | //- (struct _NSPoint)_closeButtonOrigin; | ||
| 174 | //- (struct _NSPoint)_zoomButtonOrigin; | ||
| 175 | //- (struct _NSPoint)_collapseButtonOrigin; | ||
| 176 | //- (struct _NSPoint)_fileButtonOrigin; | ||
| 177 | //- (float)_maxYTitlebarDragHeight; | ||
| 178 | //- (float)_minXTitlebarDragWidth; | ||
| 179 | //- (float)_maxXTitlebarDragWidth; | ||
| 180 | //- (float)_contentToFrameMinXWidth; | ||
| 181 | //- (float)_contentToFrameMaxXWidth; | ||
| 182 | //- (float)_contentToFrameMinYHeight; | ||
| 183 | //- (float)_contentToFrameMaxYHeight; | ||
| 184 | //- (NSRect)contentRect; | ||
| 185 | //- (float)_windowResizeCornerThickness; | ||
| 186 | //- (NSRect)_minYResizeRect; | ||
| 187 | //- (NSRect)_minYminXResizeRect; | ||
| 188 | //- (NSRect)_minYmaxXResizeRect; | ||
| 189 | //- (NSRect)_minXResizeRect; | ||
| 190 | //- (NSRect)_minXminYResizeRect; | ||
| 191 | //- (NSRect)_minXmaxYResizeRect; | ||
| 192 | //- (NSRect)_maxYResizeRect; | ||
| 193 | //- (NSRect)_maxYminXResizeRect; | ||
| 194 | //- (NSRect)_maxYmaxXResizeRect; | ||
| 195 | //- (NSRect)_maxXResizeRect; | ||
| 196 | //- (NSRect)_maxXminYResizeRect; | ||
| 197 | //- (NSRect)_maxXmaxYResizeRect; | ||
| 198 | //- (NSRect)_minXTitlebarResizeRect; | ||
| 199 | //- (NSRect)_maxXTitlebarResizeRect; | ||
| 200 | //- (NSRect)_minXBorderRect; | ||
| 201 | //- (NSRect)_maxXBorderRect; | ||
| 202 | //- (NSRect)_maxYBorderRect; | ||
| 203 | //- (NSRect)_minYBorderRect; | ||
| 204 | // | ||
| 205 | //@end |
src/gui/kernel/qsound_iphone.mm
(189 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | #include <qapplication.h> | ||
| 42 | #include "qsound.h" | ||
| 43 | #include "qsound_p.h" | ||
| 44 | #include <private/qt_iphone_p.h> | ||
| 45 | #include <qhash.h> | ||
| 46 | #include <qdebug.h> | ||
| 47 | //#import <AppKit/AppKit.h> | ||
| 48 | |||
| 49 | //#include <AppKit/NSSound.h> | ||
| 50 | |||
| 51 | QT_BEGIN_NAMESPACE | ||
| 52 | |||
| 53 | //void qt_mac_beep() | ||
| 54 | //{ | ||
| 55 | //// NSBeep(); | ||
| 56 | //} | ||
| 57 | |||
| 58 | QT_END_NAMESPACE | ||
| 59 | |||
| 60 | #ifndef QT_NO_SOUND | ||
| 61 | |||
| 62 | QT_BEGIN_NAMESPACE | ||
| 63 | |||
| 64 | //typedef QHash<QSound *, NSSound const *> Sounds; | ||
| 65 | //static Sounds sounds; | ||
| 66 | // | ||
| 67 | //class QAuServerMac : public QAuServer | ||
| 68 | //{ | ||
| 69 | // Q_OBJECT | ||
| 70 | //public: | ||
| 71 | // QAuServerMac(QObject* parent) : QAuServer(parent) { } | ||
| 72 | // void play(const QString& filename); | ||
| 73 | // void play(QSound *s); | ||
| 74 | // void stop(QSound*); | ||
| 75 | // bool okay() { return true; } | ||
| 76 | // using QAuServer::decLoop; // promote to public. | ||
| 77 | //protected: | ||
| 78 | // NSSound *createNSSound(const QString &filename, QSound *qSound); | ||
| 79 | //}; | ||
| 80 | // | ||
| 81 | //QT_END_NAMESPACE | ||
| 82 | // | ||
| 83 | //#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | ||
| 84 | //@protocol NSSoundDelegate <NSObject> | ||
| 85 | //-(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)aBool; | ||
| 86 | //@end | ||
| 87 | //#endif | ||
| 88 | // | ||
| 89 | //QT_USE_NAMESPACE | ||
| 90 | // | ||
| 91 | //@interface QMacSoundDelegate : NSObject<NSSoundDelegate> { | ||
| 92 | // QSound *qSound; // may be null. | ||
| 93 | // QAuServerMac* server; | ||
| 94 | //} | ||
| 95 | //-(id)initWithQSound:(QSound*)sound:(QAuServerMac*)server; | ||
| 96 | //@end | ||
| 97 | // | ||
| 98 | //@implementation QMacSoundDelegate | ||
| 99 | //-(id)initWithQSound:(QSound*)s:(QAuServerMac*)serv { | ||
| 100 | // self = [super init]; | ||
| 101 | // if(self) { | ||
| 102 | // qSound = s; | ||
| 103 | // server = serv; | ||
| 104 | // } | ||
| 105 | // return self; | ||
| 106 | //} | ||
| 107 | // | ||
| 108 | //// Delegate function that gets called each time a sound finishes. | ||
| 109 | //-(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedOk | ||
| 110 | //{ | ||
| 111 | // // qSound is null if this sound was started by play(QString), | ||
| 112 | // // in which case there is no corresponding QSound object. | ||
| 113 | // if (qSound == 0) { | ||
| 114 | // [sound release]; | ||
| 115 | // [self release]; | ||
| 116 | // return; | ||
| 117 | // } | ||
| 118 | // | ||
| 119 | // // finishedOk is false if the sound cold not be played or | ||
| 120 | // // if it was interrupted by stop(). | ||
| 121 | // if (finishedOk == false) { | ||
| 122 | // sounds.remove(qSound); | ||
| 123 | // [sound release]; | ||
| 124 | // [self release]; | ||
| 125 | // return; | ||
| 126 | // } | ||
| 127 | // | ||
| 128 | // // Check if the sound should loop "forever" (until stop). | ||
| 129 | // if (qSound->loops() == -1) { | ||
| 130 | // [sound play]; | ||
| 131 | // return; | ||
| 132 | // } | ||
| 133 | // | ||
| 134 | // const int remainingIterations = server->decLoop(qSound); | ||
| 135 | // if (remainingIterations > 0) { | ||
| 136 | // [sound play]; | ||
| 137 | // } else { | ||
| 138 | // sounds.remove(qSound); | ||
| 139 | // [sound release]; | ||
| 140 | // [self release]; | ||
| 141 | // } | ||
| 142 | //} | ||
| 143 | //@end | ||
| 144 | |||
| 145 | QT_BEGIN_NAMESPACE | ||
| 146 | |||
| 147 | //void QAuServerMac::play(const QString &fileName) | ||
| 148 | //{ | ||
| 149 | // QMacCocoaAutoReleasePool pool; | ||
| 150 | // NSSound * const nsSound = createNSSound(fileName, 0); | ||
| 151 | // [nsSound play]; | ||
| 152 | //} | ||
| 153 | // | ||
| 154 | //void QAuServerMac::play(QSound *qSound) | ||
| 155 | //{ | ||
| 156 | // QMacCocoaAutoReleasePool pool; | ||
| 157 | // NSSound * const nsSound = createNSSound(qSound->fileName(), qSound); | ||
| 158 | // [nsSound play]; | ||
| 159 | // // Keep track of the nsSound object so we can find it again in stop(). | ||
| 160 | // sounds[qSound] = nsSound; | ||
| 161 | //} | ||
| 162 | // | ||
| 163 | //void QAuServerMac::stop(QSound *qSound) | ||
| 164 | //{ | ||
| 165 | // Sounds::const_iterator it = sounds.constFind(qSound); | ||
| 166 | // if (it != sounds.constEnd()) | ||
| 167 | // [*it stop]; | ||
| 168 | //} | ||
| 169 | // | ||
| 170 | //// Creates an NSSound object and installs a "sound finished" callack delegate on it. | ||
| 171 | //NSSound *QAuServerMac::createNSSound(const QString &fileName, QSound *qSound) | ||
| 172 | //{ | ||
| 173 | // NSString *nsFileName = const_cast<NSString *>(reinterpret_cast<const NSString *>(QCFString::toCFStringRef(fileName))); | ||
| 174 | // NSSound * const nsSound = [[NSSound alloc] initWithContentsOfFile: nsFileName byReference:YES]; | ||
| 175 | // QMacSoundDelegate * const delegate = [[QMacSoundDelegate alloc] initWithQSound:qSound:this]; | ||
| 176 | // [nsSound setDelegate:delegate]; | ||
| 177 | // return nsSound; | ||
| 178 | //} | ||
| 179 | |||
| 180 | QAuServer* qt_new_audio_server() | ||
| 181 | { | ||
| 182 | // return new QAuServerMac(qApp); | ||
| 183 | } | ||
| 184 | |||
| 185 | QT_END_NAMESPACE | ||
| 186 | |||
| 187 | //#include "qsound_mac.moc" | ||
| 188 | |||
| 189 | #endif // QT_NO_SOUND |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #include <private/qcore_mac_p.h> | ||
| 77 | #include <qaction.h> | ||
| 78 | #include <qwidget.h> | ||
| 79 | #include <qdesktopwidget.h> | ||
| 80 | #include <qevent.h> | ||
| 81 | #include <qpixmapcache.h> | ||
| 82 | #include <private/qevent_p.h> | ||
| 83 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 84 | #include <private/qt_iphone_p.h> | ||
| 85 | #include <private/qapplication_p.h> | ||
| 86 | #include <private/qcocoawindow_iphone_p.h> | ||
| 87 | #include <private/qcocoaview_iphone_p.h> | ||
| 88 | #include <private/qkeymapper_p.h> | ||
| 89 | #include <private/qwidget_p.h> | ||
| 90 | |||
| 91 | QT_BEGIN_NAMESPACE | ||
| 92 | |||
| 93 | //Q_GLOBAL_STATIC(QMacWindowFader, macwindowFader); | ||
| 94 | // | ||
| 95 | //QMacWindowFader::QMacWindowFader() | ||
| 96 | // : m_duration(0.250) | ||
| 97 | //{ | ||
| 98 | //} | ||
| 99 | // | ||
| 100 | //QMacWindowFader *QMacWindowFader::currentFader() | ||
| 101 | //{ | ||
| 102 | // return macwindowFader(); | ||
| 103 | //} | ||
| 104 | // | ||
| 105 | //void QMacWindowFader::registerWindowToFade(QWidget *window) | ||
| 106 | //{ | ||
| 107 | // m_windowsToFade.append(window); | ||
| 108 | //} | ||
| 109 | // | ||
| 110 | //void QMacWindowFader::performFade() | ||
| 111 | //{ | ||
| 112 | // const QWidgetList myWidgetsToFade = m_windowsToFade; | ||
| 113 | // const int widgetCount = myWidgetsToFade.count(); | ||
| 114 | //#if QT_MAC_USE_COCOA | ||
| 115 | // QMacCocoaAutoReleasePool pool; | ||
| 116 | // [NSAnimationContext beginGrouping]; | ||
| 117 | // [[NSAnimationContext currentContext] setDuration:NSTimeInterval(m_duration)]; | ||
| 118 | //#endif | ||
| 119 | // | ||
| 120 | // for (int i = 0; i < widgetCount; ++i) { | ||
| 121 | // QWidget *widget = m_windowsToFade.at(i); | ||
| 122 | // OSWindowRef window = qt_mac_window_for(widget); | ||
| 123 | //#if QT_MAC_USE_COCOA | ||
| 124 | // [[window animator] setAlphaValue:0.0]; | ||
| 125 | // QTimer::singleShot(qRound(m_duration * 1000), widget, SLOT(hide())); | ||
| 126 | //#else | ||
| 127 | // TransitionWindowOptions options = {0, m_duration, 0, 0}; | ||
| 128 | // TransitionWindowWithOptions(window, kWindowFadeTransitionEffect, kWindowHideTransitionAction, | ||
| 129 | // 0, 1, &options); | ||
| 130 | //#endif | ||
| 131 | // } | ||
| 132 | //#if QT_MAC_USE_COCOA | ||
| 133 | // [NSAnimationContext endGrouping]; | ||
| 134 | //#endif | ||
| 135 | // m_duration = 0.250; | ||
| 136 | // m_windowsToFade.clear(); | ||
| 137 | //} | ||
| 138 | // | ||
| 139 | //extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // qapplication.cpp; | ||
| 140 | //extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm | ||
| 141 | //extern QWidget * mac_mouse_grabber; | ||
| 142 | // | ||
| 143 | //void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds) | ||
| 144 | //{ | ||
| 145 | // OSWindowRef wnd = static_cast<OSWindowRef>(window); | ||
| 146 | // if (wnd) { | ||
| 147 | // QWidget *widget; | ||
| 148 | //#if QT_MAC_USE_COCOA | ||
| 149 | // widget = [wnd QT_MANGLE_NAMESPACE(qt_qwidget)]; | ||
| 150 | //#else | ||
| 151 | // const UInt32 kWidgetCreatorQt = kEventClassQt; | ||
| 152 | // enum { | ||
| 153 | // kWidgetPropertyQWidget = 'QWId' //QWidget * | ||
| 154 | // }; | ||
| 155 | // if (GetWindowProperty(static_cast<WindowRef>(window), kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(widget), 0, &widget) != noErr) | ||
| 156 | // widget = 0; | ||
| 157 | //#endif | ||
| 158 | // if (widget) { | ||
| 159 | // QMacWindowFader::currentFader()->setFadeDuration(durationSeconds); | ||
| 160 | // QMacWindowFader::currentFader()->registerWindowToFade(widget); | ||
| 161 | // QMacWindowFader::currentFader()->performFade(); | ||
| 162 | // } | ||
| 163 | // } | ||
| 164 | //} | ||
| 165 | // | ||
| 166 | //bool macWindowIsTextured( void * /*OSWindowRef*/ window ) | ||
| 167 | //{ | ||
| 168 | // OSWindowRef wnd = static_cast<OSWindowRef>(window); | ||
| 169 | //#if QT_MAC_USE_COCOA | ||
| 170 | // return ( [wnd styleMask] & NSTexturedBackgroundWindowMask ) ? true : false; | ||
| 171 | //#else | ||
| 172 | // WindowAttributes currentAttributes; | ||
| 173 | // GetWindowAttributes(wnd, ¤tAttributes); | ||
| 174 | // return (currentAttributes & kWindowMetalAttribute) ? true : false; | ||
| 175 | //#endif | ||
| 176 | //} | ||
| 177 | // | ||
| 178 | //void macWindowToolbarShow(const QWidget *widget, bool show ) | ||
| 179 | //{ | ||
| 180 | // OSWindowRef wnd = qt_mac_window_for(widget); | ||
| 181 | //#if QT_MAC_USE_COCOA | ||
| 182 | // if (NSToolbar *toolbar = [wnd toolbar]) { | ||
| 183 | // QMacCocoaAutoReleasePool pool; | ||
| 184 | // if (show != [toolbar isVisible]) { | ||
| 185 | // [toolbar setVisible:show]; | ||
| 186 | // } else { | ||
| 187 | // // The toolbar may be in sync, but we are not, update our framestrut. | ||
| 188 | // qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut(); | ||
| 189 | // } | ||
| 190 | // } | ||
| 191 | //#else | ||
| 192 | // ShowHideWindowToolbar(wnd, show, false); | ||
| 193 | //#endif | ||
| 194 | //} | ||
| 195 | // | ||
| 196 | // | ||
| 197 | //void macWindowToolbarSet( void * /*OSWindowRef*/ window, void *toolbarRef ) | ||
| 198 | //{ | ||
| 199 | // OSWindowRef wnd = static_cast<OSWindowRef>(window); | ||
| 200 | //#if QT_MAC_USE_COCOA | ||
| 201 | // [wnd setToolbar:static_cast<NSToolbar *>(toolbarRef)]; | ||
| 202 | //#else | ||
| 203 | // SetWindowToolbar(wnd, static_cast<HIToolbarRef>(toolbarRef)); | ||
| 204 | //#endif | ||
| 205 | //} | ||
| 206 | // | ||
| 207 | //bool macWindowToolbarIsVisible( void * /*OSWindowRef*/ window ) | ||
| 208 | //{ | ||
| 209 | // OSWindowRef wnd = static_cast<OSWindowRef>(window); | ||
| 210 | //#if QT_MAC_USE_COCOA | ||
| 211 | // if (NSToolbar *toolbar = [wnd toolbar]) | ||
| 212 | // return [toolbar isVisible]; | ||
| 213 | // return false; | ||
| 214 | //#else | ||
| 215 | // return IsWindowToolbarVisible(wnd); | ||
| 216 | //#endif | ||
| 217 | //} | ||
| 218 | // | ||
| 219 | //void macWindowSetHasShadow( void * /*OSWindowRef*/ window, bool hasShadow ) | ||
| 220 | //{ | ||
| 221 | // OSWindowRef wnd = static_cast<OSWindowRef>(window); | ||
| 222 | //#if QT_MAC_USE_COCOA | ||
| 223 | // [wnd setHasShadow:BOOL(hasShadow)]; | ||
| 224 | //#else | ||
| 225 | // if (hasShadow) | ||
| 226 | // ChangeWindowAttributes(wnd, 0, kWindowNoShadowAttribute); | ||
| 227 | // else | ||
| 228 | // ChangeWindowAttributes(wnd, kWindowNoShadowAttribute, 0); | ||
| 229 | //#endif | ||
| 230 | //} | ||
| 231 | // | ||
| 232 | //void macWindowFlush(void * /*OSWindowRef*/ window) | ||
| 233 | //{ | ||
| 234 | // OSWindowRef wnd = static_cast<OSWindowRef>(window); | ||
| 235 | //#if QT_MAC_USE_COCOA | ||
| 236 | // [wnd flushWindowIfNeeded]; | ||
| 237 | //#else | ||
| 238 | // HIWindowFlush(wnd); | ||
| 239 | //#endif | ||
| 240 | //} | ||
| 241 | // | ||
| 242 | //void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm) | ||
| 243 | //{ | ||
| 244 | // QMacCocoaAutoReleasePool pool; | ||
| 245 | // if(QCFType<CGImageRef> image = pm.toMacCGImageRef()) { | ||
| 246 | // NSImage *newImage = 0; | ||
| 247 | // NSRect imageRect = NSMakeRect(0.0, 0.0, CGImageGetWidth(image), CGImageGetHeight(image)); | ||
| 248 | // newImage = [[NSImage alloc] initWithSize:imageRect.size]; | ||
| 249 | // [newImage lockFocus]; | ||
| 250 | // { | ||
| 251 | // CGContextRef imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; | ||
| 252 | // CGContextDrawImage(imageContext, *(CGRect*)&imageRect, image); | ||
| 253 | // } | ||
| 254 | // [newImage unlockFocus]; | ||
| 255 | // return newImage; | ||
| 256 | // } | ||
| 257 | // return 0; | ||
| 258 | //} | ||
| 259 | // | ||
| 260 | //void qt_mac_update_mouseTracking(QWidget *widget) | ||
| 261 | //{ | ||
| 262 | //#ifdef QT_MAC_USE_COCOA | ||
| 263 | // [qt_mac_nativeview_for(widget) updateTrackingAreas]; | ||
| 264 | //#else | ||
| 265 | // Q_UNUSED(widget); | ||
| 266 | //#endif | ||
| 267 | //} | ||
| 268 | |||
| 269 | int qt_iphone_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage) | ||
| 270 | { | ||
| 271 | // Verbatim copy if HIViewDrawCGImage (as shown on Carbon-Dev) | ||
| 272 | OSStatus err = noErr; | ||
| 273 | |||
| 274 | if (inContext == NULL) return -1; | ||
| 275 | if (inBounds == NULL) return -1; | ||
| 276 | if (inImage == NULL) return -1; | ||
| 277 | |||
| 278 | CGContextSaveGState( inContext ); | ||
| 279 | CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds)); | ||
| 280 | CGContextScaleCTM(inContext, 1, -1); | ||
| 281 | |||
| 282 | CGContextDrawImage(inContext, *inBounds, inImage); | ||
| 283 | |||
| 284 | CGContextRestoreGState(inContext); | ||
| 285 | return err; | ||
| 286 | } | ||
| 287 | |||
| 288 | //bool qt_mac_checkForNativeSizeGrip(const QWidget *widget) | ||
| 289 | //{ | ||
| 290 | //#ifndef QT_MAC_USE_COCOA | ||
| 291 | // OSViewRef nativeSizeGrip = 0; | ||
| 292 | // HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(widget->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip); | ||
| 293 | // return (nativeSizeGrip != 0); | ||
| 294 | //#else | ||
| 295 | // return [[reinterpret_cast<NSView *>(widget->winId()) window] showsResizeIndicator]; | ||
| 296 | //#endif | ||
| 297 | //} | ||
| 298 | //struct qt_mac_enum_mapper | ||
| 299 | //{ | ||
| 300 | // int mac_code; | ||
| 301 | // int qt_code; | ||
| 302 | //#if defined(DEBUG_MOUSE_MAPS) | ||
| 303 | //# define QT_MAC_MAP_ENUM(x) x, #x | ||
| 304 | // const char *desc; | ||
| 305 | //#else | ||
| 306 | //# define QT_MAC_MAP_ENUM(x) x | ||
| 307 | //#endif | ||
| 308 | //}; | ||
| 309 | // | ||
| 310 | ////mouse buttons | ||
| 311 | //static qt_mac_enum_mapper qt_mac_mouse_symbols[] = { | ||
| 312 | //{ kEventMouseButtonPrimary, QT_MAC_MAP_ENUM(Qt::LeftButton) }, | ||
| 313 | //{ kEventMouseButtonSecondary, QT_MAC_MAP_ENUM(Qt::RightButton) }, | ||
| 314 | //{ kEventMouseButtonTertiary, QT_MAC_MAP_ENUM(Qt::MidButton) }, | ||
| 315 | //{ 4, QT_MAC_MAP_ENUM(Qt::XButton1) }, | ||
| 316 | //{ 5, QT_MAC_MAP_ENUM(Qt::XButton2) }, | ||
| 317 | //{ 0, QT_MAC_MAP_ENUM(0) } | ||
| 318 | //}; | ||
| 319 | //Qt::MouseButtons qt_mac_get_buttons(int buttons) | ||
| 320 | //{ | ||
| 321 | //#ifdef DEBUG_MOUSE_MAPS | ||
| 322 | // qDebug("Qt: internal: **Mapping buttons: %d (0x%04x)", buttons, buttons); | ||
| 323 | //#endif | ||
| 324 | // Qt::MouseButtons ret = Qt::NoButton; | ||
| 325 | // for(int i = 0; qt_mac_mouse_symbols[i].qt_code; i++) { | ||
| 326 | // if (buttons & (0x01<<(qt_mac_mouse_symbols[i].mac_code-1))) { | ||
| 327 | //#ifdef DEBUG_MOUSE_MAPS | ||
| 328 | // qDebug("Qt: internal: got button: %s", qt_mac_mouse_symbols[i].desc); | ||
| 329 | //#endif | ||
| 330 | // ret |= Qt::MouseButtons(qt_mac_mouse_symbols[i].qt_code); | ||
| 331 | // } | ||
| 332 | // } | ||
| 333 | // return ret; | ||
| 334 | //} | ||
| 335 | //Qt::MouseButton qt_mac_get_button(EventMouseButton button) | ||
| 336 | //{ | ||
| 337 | //#ifdef DEBUG_MOUSE_MAPS | ||
| 338 | // qDebug("Qt: internal: **Mapping button: %d (0x%04x)", button, button); | ||
| 339 | //#endif | ||
| 340 | // Qt::MouseButtons ret = 0; | ||
| 341 | // for(int i = 0; qt_mac_mouse_symbols[i].qt_code; i++) { | ||
| 342 | // if (button == qt_mac_mouse_symbols[i].mac_code) { | ||
| 343 | //#ifdef DEBUG_MOUSE_MAPS | ||
| 344 | // qDebug("Qt: internal: got button: %s", qt_mac_mouse_symbols[i].desc); | ||
| 345 | //#endif | ||
| 346 | // return Qt::MouseButton(qt_mac_mouse_symbols[i].qt_code); | ||
| 347 | // } | ||
| 348 | // } | ||
| 349 | // return Qt::NoButton; | ||
| 350 | //} | ||
| 351 | // | ||
| 352 | //void macSendToolbarChangeEvent(QWidget *widget) | ||
| 353 | //{ | ||
| 354 | // QToolBarChangeEvent ev(!(GetCurrentKeyModifiers() & cmdKey)); | ||
| 355 | // qt_sendSpontaneousEvent(widget, &ev); | ||
| 356 | //} | ||
| 357 | // | ||
| 358 | //Q_GLOBAL_STATIC(QMacTabletHash, tablet_hash) | ||
| 359 | //QMacTabletHash *qt_mac_tablet_hash() | ||
| 360 | //{ | ||
| 361 | // return tablet_hash(); | ||
| 362 | //} | ||
| 363 | // | ||
| 364 | //#ifdef QT_MAC_USE_COCOA | ||
| 365 | //void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent) | ||
| 366 | //{ | ||
| 367 | // NSEvent *proximityEvent = static_cast<NSEvent *>(tabletEvent); | ||
| 368 | // // simply construct a Carbon proximity record and handle it all in one spot. | ||
| 369 | // TabletProximityRec carbonProximityRec = { [proximityEvent vendorID], | ||
| 370 | // [proximityEvent tabletID], | ||
| 371 | // [proximityEvent pointingDeviceID], | ||
| 372 | // [proximityEvent deviceID], | ||
| 373 | // [proximityEvent systemTabletID], | ||
| 374 | // [proximityEvent vendorPointingDeviceType], | ||
| 375 | // [proximityEvent pointingDeviceSerialNumber], | ||
| 376 | // [proximityEvent uniqueID], | ||
| 377 | // [proximityEvent capabilityMask], | ||
| 378 | // [proximityEvent pointingDeviceType], | ||
| 379 | // [proximityEvent isEnteringProximity] }; | ||
| 380 | // qt_dispatchTabletProximityEvent(carbonProximityRec); | ||
| 381 | //} | ||
| 382 | //#endif // QT_MAC_USE_COCOA | ||
| 383 | // | ||
| 384 | //void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec) | ||
| 385 | //{ | ||
| 386 | // QTabletDeviceData proximityDevice; | ||
| 387 | // proximityDevice.tabletUniqueID = proxRec.uniqueID; | ||
| 388 | // proximityDevice.capabilityMask = proxRec.capabilityMask; | ||
| 389 | // | ||
| 390 | // switch (proxRec.pointerType) { | ||
| 391 | // case NSUnknownPointingDevice: | ||
| 392 | // default: | ||
| 393 | // proximityDevice.tabletPointerType = QTabletEvent::UnknownPointer; | ||
| 394 | // break; | ||
| 395 | // case NSPenPointingDevice: | ||
| 396 | // proximityDevice.tabletPointerType = QTabletEvent::Pen; | ||
| 397 | // break; | ||
| 398 | // case NSCursorPointingDevice: | ||
| 399 | // proximityDevice.tabletPointerType = QTabletEvent::Cursor; | ||
| 400 | // break; | ||
| 401 | // case NSEraserPointingDevice: | ||
| 402 | // proximityDevice.tabletPointerType = QTabletEvent::Eraser; | ||
| 403 | // break; | ||
| 404 | // } | ||
| 405 | // uint bits = proxRec.vendorPointerType; | ||
| 406 | // if (bits == 0 && proximityDevice.tabletUniqueID != 0) { | ||
| 407 | // // Fallback. It seems that the driver doesn't always include all the information. | ||
| 408 | // // High-End Wacom devices store their "type" in the uper bits of the Unique ID. | ||
| 409 | // // I'm not sure how to handle it for consumer devices, but I'll test that in a bit. | ||
| 410 | // bits = proximityDevice.tabletUniqueID >> 32; | ||
| 411 | // } | ||
| 412 | // // Defined in the "EN0056-NxtGenImpGuideX" | ||
| 413 | // // on Wacom's Developer Website (www.wacomeng.com) | ||
| 414 | // if (((bits & 0x0006) == 0x0002) && ((bits & 0x0F06) != 0x0902)) { | ||
| 415 | // proximityDevice.tabletDeviceType = QTabletEvent::Stylus; | ||
| 416 | // } else { | ||
| 417 | // switch (bits & 0x0F06) { | ||
| 418 | // case 0x0802: | ||
| 419 | // proximityDevice.tabletDeviceType = QTabletEvent::Stylus; | ||
| 420 | // break; | ||
| 421 | // case 0x0902: | ||
| 422 | // proximityDevice.tabletDeviceType = QTabletEvent::Airbrush; | ||
| 423 | // break; | ||
| 424 | // case 0x0004: | ||
| 425 | // proximityDevice.tabletDeviceType = QTabletEvent::FourDMouse; | ||
| 426 | // break; | ||
| 427 | // case 0x0006: | ||
| 428 | // proximityDevice.tabletDeviceType = QTabletEvent::Puck; | ||
| 429 | // break; | ||
| 430 | // case 0x0804: | ||
| 431 | // proximityDevice.tabletDeviceType = QTabletEvent::RotationStylus; | ||
| 432 | // break; | ||
| 433 | // default: | ||
| 434 | // proximityDevice.tabletDeviceType = QTabletEvent::NoDevice; | ||
| 435 | // } | ||
| 436 | // } | ||
| 437 | // // The deviceID is "unique" while in the proximity, it's a key that we can use for | ||
| 438 | // // linking up TabletDeviceData to an event (especially if there are two devices in action). | ||
| 439 | // bool entering = proxRec.enterProximity; | ||
| 440 | // if (entering) { | ||
| 441 | // qt_mac_tablet_hash()->insert(proxRec.deviceID, proximityDevice); | ||
| 442 | // } else { | ||
| 443 | // qt_mac_tablet_hash()->remove(proxRec.deviceID); | ||
| 444 | // } | ||
| 445 | // | ||
| 446 | // QTabletEvent qtabletProximity(entering ? QEvent::TabletEnterProximity | ||
| 447 | // : QEvent::TabletLeaveProximity, | ||
| 448 | // QPoint(), QPoint(), QPointF(), proximityDevice.tabletDeviceType, | ||
| 449 | // proximityDevice.tabletPointerType, 0., 0, 0, 0., 0., 0, 0, | ||
| 450 | // proximityDevice.tabletUniqueID); | ||
| 451 | // | ||
| 452 | // qt_sendSpontaneousEvent(qApp, &qtabletProximity); | ||
| 453 | //} | ||
| 454 | // | ||
| 455 | //#ifdef QT_MAC_USE_COCOA | ||
| 456 | //// Use this method to keep all the information in the TextSegment. As long as it is ordered | ||
| 457 | //// we are in OK shape, and we can influence that ourselves. | ||
| 458 | //struct KeyPair | ||
| 459 | //{ | ||
| 460 | // QChar cocoaKey; | ||
| 461 | // Qt::Key qtKey; | ||
| 462 | //}; | ||
| 463 | // | ||
| 464 | //bool operator==(const KeyPair &entry, QChar qchar) | ||
| 465 | //{ | ||
| 466 | // return entry.cocoaKey == qchar; | ||
| 467 | //} | ||
| 468 | // | ||
| 469 | //bool operator<(const KeyPair &entry, QChar qchar) | ||
| 470 | //{ | ||
| 471 | // return entry.cocoaKey < qchar; | ||
| 472 | //} | ||
| 473 | // | ||
| 474 | //bool operator<(QChar qchar, const KeyPair &entry) | ||
| 475 | //{ | ||
| 476 | // return qchar < entry.cocoaKey; | ||
| 477 | //} | ||
| 478 | // | ||
| 479 | //static Qt::Key cocoaKey2QtKey(QChar keyCode) | ||
| 480 | //{ | ||
| 481 | // static const int NumEntries = 57; | ||
| 482 | // static const KeyPair entries[NumEntries] = { | ||
| 483 | // { NSEnterCharacter, Qt::Key_Enter }, | ||
| 484 | // { NSTabCharacter, Qt::Key_Tab }, | ||
| 485 | // { NSCarriageReturnCharacter, Qt::Key_Return }, | ||
| 486 | // { NSBackTabCharacter, Qt::Key_Backtab }, | ||
| 487 | // { kEscapeCharCode, Qt::Key_Escape }, | ||
| 488 | // { NSDeleteCharacter, Qt::Key_Backspace }, | ||
| 489 | // { NSUpArrowFunctionKey, Qt::Key_Up }, | ||
| 490 | // { NSDownArrowFunctionKey, Qt::Key_Down }, | ||
| 491 | // { NSLeftArrowFunctionKey, Qt::Key_Left }, | ||
| 492 | // { NSRightArrowFunctionKey, Qt::Key_Right }, | ||
| 493 | // { NSF1FunctionKey, Qt::Key_F1 }, | ||
| 494 | // { NSF2FunctionKey, Qt::Key_F2 }, | ||
| 495 | // { NSF3FunctionKey, Qt::Key_F3 }, | ||
| 496 | // { NSF4FunctionKey, Qt::Key_F4 }, | ||
| 497 | // { NSF5FunctionKey, Qt::Key_F5 }, | ||
| 498 | // { NSF6FunctionKey, Qt::Key_F6 }, | ||
| 499 | // { NSF7FunctionKey, Qt::Key_F7 }, | ||
| 500 | // { NSF8FunctionKey, Qt::Key_F8 }, | ||
| 501 | // { NSF9FunctionKey, Qt::Key_F8 }, | ||
| 502 | // { NSF10FunctionKey, Qt::Key_F10 }, | ||
| 503 | // { NSF11FunctionKey, Qt::Key_F11 }, | ||
| 504 | // { NSF12FunctionKey, Qt::Key_F12 }, | ||
| 505 | // { NSF13FunctionKey, Qt::Key_F13 }, | ||
| 506 | // { NSF14FunctionKey, Qt::Key_F14 }, | ||
| 507 | // { NSF15FunctionKey, Qt::Key_F15 }, | ||
| 508 | // { NSF16FunctionKey, Qt::Key_F16 }, | ||
| 509 | // { NSF17FunctionKey, Qt::Key_F17 }, | ||
| 510 | // { NSF18FunctionKey, Qt::Key_F18 }, | ||
| 511 | // { NSF19FunctionKey, Qt::Key_F19 }, | ||
| 512 | // { NSF20FunctionKey, Qt::Key_F20 }, | ||
| 513 | // { NSF21FunctionKey, Qt::Key_F21 }, | ||
| 514 | // { NSF22FunctionKey, Qt::Key_F22 }, | ||
| 515 | // { NSF23FunctionKey, Qt::Key_F23 }, | ||
| 516 | // { NSF24FunctionKey, Qt::Key_F24 }, | ||
| 517 | // { NSF25FunctionKey, Qt::Key_F25 }, | ||
| 518 | // { NSF26FunctionKey, Qt::Key_F26 }, | ||
| 519 | // { NSF27FunctionKey, Qt::Key_F27 }, | ||
| 520 | // { NSF28FunctionKey, Qt::Key_F28 }, | ||
| 521 | // { NSF29FunctionKey, Qt::Key_F29 }, | ||
| 522 | // { NSF30FunctionKey, Qt::Key_F30 }, | ||
| 523 | // { NSF31FunctionKey, Qt::Key_F31 }, | ||
| 524 | // { NSF32FunctionKey, Qt::Key_F32 }, | ||
| 525 | // { NSF33FunctionKey, Qt::Key_F33 }, | ||
| 526 | // { NSF34FunctionKey, Qt::Key_F34 }, | ||
| 527 | // { NSF35FunctionKey, Qt::Key_F35 }, | ||
| 528 | // { NSInsertFunctionKey, Qt::Key_Insert }, | ||
| 529 | // { NSDeleteFunctionKey, Qt::Key_Delete }, | ||
| 530 | // { NSHomeFunctionKey, Qt::Key_Home }, | ||
| 531 | // { NSEndFunctionKey, Qt::Key_End }, | ||
| 532 | // { NSPageUpFunctionKey, Qt::Key_PageUp }, | ||
| 533 | // { NSPageDownFunctionKey, Qt::Key_PageDown }, | ||
| 534 | // { NSPrintScreenFunctionKey, Qt::Key_Print }, | ||
| 535 | // { NSScrollLockFunctionKey, Qt::Key_ScrollLock }, | ||
| 536 | // { NSPauseFunctionKey, Qt::Key_Pause }, | ||
| 537 | // { NSSysReqFunctionKey, Qt::Key_SysReq }, | ||
| 538 | // { NSMenuFunctionKey, Qt::Key_Menu }, | ||
| 539 | // { NSHelpFunctionKey, Qt::Key_Help }, | ||
| 540 | // }; | ||
| 541 | // static const KeyPair * const end = entries + NumEntries; | ||
| 542 | // const KeyPair *i = qBinaryFind(entries, end, keyCode); | ||
| 543 | // if (i == end) | ||
| 544 | // return Qt::Key(keyCode.unicode()); | ||
| 545 | // return i->qtKey; | ||
| 546 | //} | ||
| 547 | // | ||
| 548 | //Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags) | ||
| 549 | //{ | ||
| 550 | // Qt::KeyboardModifiers qtMods =Qt::NoModifier; | ||
| 551 | // if (modifierFlags & NSShiftKeyMask) | ||
| 552 | // qtMods |= Qt::ShiftModifier; | ||
| 553 | // if (modifierFlags & NSControlKeyMask) | ||
| 554 | // qtMods |= Qt::MetaModifier; | ||
| 555 | // if (modifierFlags & NSAlternateKeyMask) | ||
| 556 | // qtMods |= Qt::AltModifier; | ||
| 557 | // if (modifierFlags & NSCommandKeyMask) | ||
| 558 | // qtMods |= Qt::ControlModifier; | ||
| 559 | // if (modifierFlags & NSNumericPadKeyMask) | ||
| 560 | // qtMods |= Qt::KeypadModifier; | ||
| 561 | // return qtMods; | ||
| 562 | //} | ||
| 563 | // | ||
| 564 | //Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations) | ||
| 565 | //{ | ||
| 566 | // Qt::KeyboardModifiers qtMods =Qt::NoModifier; | ||
| 567 | // if (dragOperations & NSDragOperationLink) | ||
| 568 | // qtMods |= Qt::MetaModifier; | ||
| 569 | // if (dragOperations & NSDragOperationGeneric) | ||
| 570 | // qtMods |= Qt::ControlModifier; | ||
| 571 | // if (dragOperations & NSDragOperationCopy) | ||
| 572 | // qtMods |= Qt::AltModifier; | ||
| 573 | // return qtMods; | ||
| 574 | //} | ||
| 575 | // | ||
| 576 | //static inline QEvent::Type cocoaEvent2QtEvent(NSUInteger eventType) | ||
| 577 | //{ | ||
| 578 | // // Handle the trivial cases that can be determined from the type. | ||
| 579 | // switch (eventType) { | ||
| 580 | // case NSKeyDown: | ||
| 581 | // return QEvent::KeyPress; | ||
| 582 | // case NSKeyUp: | ||
| 583 | // return QEvent::KeyRelease; | ||
| 584 | // case NSLeftMouseDown: | ||
| 585 | // case NSRightMouseDown: | ||
| 586 | // case NSOtherMouseDown: | ||
| 587 | // return QEvent::MouseButtonPress; | ||
| 588 | // case NSLeftMouseUp: | ||
| 589 | // case NSRightMouseUp: | ||
| 590 | // case NSOtherMouseUp: | ||
| 591 | // return QEvent::MouseButtonRelease; | ||
| 592 | // case NSMouseMoved: | ||
| 593 | // case NSLeftMouseDragged: | ||
| 594 | // case NSRightMouseDragged: | ||
| 595 | // case NSOtherMouseDragged: | ||
| 596 | // return QEvent::MouseMove; | ||
| 597 | // case NSScrollWheel: | ||
| 598 | // return QEvent::Wheel; | ||
| 599 | // } | ||
| 600 | // return QEvent::None; | ||
| 601 | //} | ||
| 602 | // | ||
| 603 | //static bool mustUseCocoaKeyEvent() | ||
| 604 | //{ | ||
| 605 | // QCFType<TISInputSourceRef> source = TISCopyCurrentKeyboardInputSource(); | ||
| 606 | // return TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData) == 0; | ||
| 607 | //} | ||
| 608 | // | ||
| 609 | //bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent) | ||
| 610 | //{ | ||
| 611 | // NSEvent *event = static_cast<NSEvent *>(keyEvent); | ||
| 612 | // NSString *keyChars = [event charactersIgnoringModifiers]; | ||
| 613 | // int keyLength = [keyChars length]; | ||
| 614 | // if (keyLength == 0) | ||
| 615 | // return false; // Dead Key, nothing to do! | ||
| 616 | // bool ignoreText = false; | ||
| 617 | // Qt::Key qtKey = Qt::Key_unknown; | ||
| 618 | // if (keyLength == 1) { | ||
| 619 | // QChar ch([keyChars characterAtIndex:0]); | ||
| 620 | // if (ch.isLower()) | ||
| 621 | // ch = ch.toUpper(); | ||
| 622 | // qtKey = cocoaKey2QtKey(ch); | ||
| 623 | // // Do not set the text for Function-Key Unicodes characters (0xF700–0xF8FF). | ||
| 624 | // ignoreText = (ch.unicode() >= 0xF700 && ch.unicode() <= 0xF8FF); | ||
| 625 | // } | ||
| 626 | // Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([event modifierFlags]); | ||
| 627 | // QString text; | ||
| 628 | // | ||
| 629 | // // To quote from the Carbon port: This is actually wrong--but it is the best that | ||
| 630 | // // can be done for now because of the Control/Meta mapping issues | ||
| 631 | // // (we always get text on the Mac) | ||
| 632 | // if (!ignoreText && !(keyMods & (Qt::ControlModifier | Qt::MetaModifier))) | ||
| 633 | // text = QCFString::toQString(reinterpret_cast<CFStringRef>(keyChars)); | ||
| 634 | // | ||
| 635 | // UInt32 macScanCode = 1; | ||
| 636 | // QKeyEventEx ke(cocoaEvent2QtEvent([event type]), qtKey, keyMods, text, [event isARepeat], qMax(1, keyLength), | ||
| 637 | // macScanCode, [event keyCode], [event modifierFlags]); | ||
| 638 | // qt_sendSpontaneousEvent(widgetToGetEvent, &ke); | ||
| 639 | // return ke.isAccepted(); | ||
| 640 | //} | ||
| 641 | //#endif | ||
| 642 | // | ||
| 643 | //// Helper to share code between QCocoaWindow and QCocoaView | ||
| 644 | //bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent) | ||
| 645 | //{ | ||
| 646 | //#ifndef QT_MAC_USE_COCOA | ||
| 647 | // Q_UNUSED(keyEvent); | ||
| 648 | // Q_UNUSED(widgetToGetEvent); | ||
| 649 | // return false; | ||
| 650 | //#else | ||
| 651 | // NSEvent *event = static_cast<NSEvent *>(keyEvent); | ||
| 652 | // EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef])); | ||
| 653 | // Q_ASSERT(key_event); | ||
| 654 | // if ([event type] == NSKeyDown) { | ||
| 655 | // qt_keymapper_private()->updateKeyMap(0, key_event, 0); | ||
| 656 | // } | ||
| 657 | // if (widgetToGetEvent == 0) | ||
| 658 | // return false; | ||
| 659 | // | ||
| 660 | // if (qt_mac_sendMacEventToWidget(widgetToGetEvent, key_event)) | ||
| 661 | // return true; | ||
| 662 | // | ||
| 663 | // if (mustUseCocoaKeyEvent()) | ||
| 664 | // return qt_dispatchKeyEventWithCocoa(keyEvent, widgetToGetEvent); | ||
| 665 | // bool isAccepted; | ||
| 666 | // qt_keymapper_private()->translateKeyEvent(widgetToGetEvent, 0, key_event, &isAccepted, true); | ||
| 667 | // return isAccepted; | ||
| 668 | //#endif | ||
| 669 | //} | ||
| 670 | // | ||
| 671 | //void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent) | ||
| 672 | //{ | ||
| 673 | //#ifndef QT_MAC_USE_COCOA | ||
| 674 | // Q_UNUSED(flagsChangedEvent); | ||
| 675 | // Q_UNUSED(widgetToGetEvent); | ||
| 676 | //#else | ||
| 677 | // UInt32 modifiers = 0; | ||
| 678 | // // Sync modifiers with Qt | ||
| 679 | // NSEvent *event = static_cast<NSEvent *>(flagsChangedEvent); | ||
| 680 | // EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef])); | ||
| 681 | // Q_ASSERT(key_event); | ||
| 682 | // GetEventParameter(key_event, kEventParamKeyModifiers, typeUInt32, 0, | ||
| 683 | // sizeof(modifiers), 0, &modifiers); | ||
| 684 | // extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object); | ||
| 685 | // qt_mac_send_modifiers_changed(modifiers, widgetToGetEvent); | ||
| 686 | //#endif | ||
| 687 | //} | ||
| 688 | // | ||
| 689 | // | ||
| 690 | //QPointF flipPoint(const NSPoint &p) | ||
| 691 | //{ | ||
| 692 | // return QPointF(p.x, flipYCoordinate(p.y)); | ||
| 693 | //} | ||
| 694 | // | ||
| 695 | //NSPoint flipPoint(const QPoint &p) | ||
| 696 | //{ | ||
| 697 | // return NSMakePoint(p.x(), flipYCoordinate(p.y())); | ||
| 698 | //} | ||
| 699 | // | ||
| 700 | //NSPoint flipPoint(const QPointF &p) | ||
| 701 | //{ | ||
| 702 | // return NSMakePoint(p.x(), flipYCoordinate(p.y())); | ||
| 703 | //} | ||
| 704 | // | ||
| 705 | //void qt_mac_dispatchNCMouseMessage(void * /* NSWindow* */eventWindow, void * /* NSEvent* */mouseEvent, | ||
| 706 | // QWidget *widgetToGetEvent, bool &leftButtonIsRightButton) | ||
| 707 | //{ | ||
| 708 | //#ifndef QT_MAC_USE_COCOA | ||
| 709 | // Q_UNUSED(eventWindow); | ||
| 710 | // Q_UNUSED(mouseEvent); | ||
| 711 | // Q_UNUSED(widgetToGetEvent); | ||
| 712 | // Q_UNUSED(leftButtonIsRightButton); | ||
| 713 | //#else | ||
| 714 | // if (widgetToGetEvent == 0) | ||
| 715 | // return; | ||
| 716 | // NSWindow *window = static_cast<NSWindow *>(eventWindow); | ||
| 717 | // NSEvent *event = static_cast<NSEvent *>(mouseEvent); | ||
| 718 | // NSEventType evtType = [event type]; | ||
| 719 | // | ||
| 720 | // QPoint qlocalPoint; | ||
| 721 | // QPoint qglobalPoint; | ||
| 722 | // bool processThisEvent = false; | ||
| 723 | // bool fakeNCEvents = false; | ||
| 724 | // bool fakeMouseEvents = false; | ||
| 725 | // | ||
| 726 | // // Check if this is a mouse event. | ||
| 727 | // if (evtType == NSLeftMouseDown || evtType == NSLeftMouseUp | ||
| 728 | // || evtType == NSRightMouseDown || evtType == NSRightMouseUp | ||
| 729 | // || evtType == NSOtherMouseDown || evtType == NSOtherMouseUp | ||
| 730 | // || evtType == NSMouseMoved || evtType == NSLeftMouseDragged | ||
| 731 | // || evtType == NSRightMouseDragged || evtType == NSOtherMouseDragged) { | ||
| 732 | // // Check if we want to pass this message to another window | ||
| 733 | // if (mac_mouse_grabber && mac_mouse_grabber != widgetToGetEvent) { | ||
| 734 | // NSWindow *grabWindow = static_cast<NSWindow *>(qt_mac_window_for(mac_mouse_grabber)); | ||
| 735 | // if (window != grabWindow) { | ||
| 736 | // window = grabWindow; | ||
| 737 | // widgetToGetEvent = mac_mouse_grabber; | ||
| 738 | // fakeNCEvents = true; | ||
| 739 | // } | ||
| 740 | // } | ||
| 741 | // // Dont generate normal NC mouse events for Left Button dragged | ||
| 742 | // if(evtType != NSLeftMouseDragged || fakeNCEvents) { | ||
| 743 | // NSPoint windowPoint = [event locationInWindow]; | ||
| 744 | // NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; | ||
| 745 | // NSRect frameRect = [window frame]; | ||
| 746 | // if (fakeNCEvents || NSMouseInRect(globalPoint, frameRect, NO)) { | ||
| 747 | // NSRect contentRect = [window contentRectForFrameRect:frameRect]; | ||
| 748 | // if (fakeNCEvents || !NSMouseInRect(globalPoint, contentRect, NO)) { | ||
| 749 | // qglobalPoint = QPoint(flipPoint(globalPoint).toPoint()); | ||
| 750 | // qlocalPoint = widgetToGetEvent->mapFromGlobal(qglobalPoint); | ||
| 751 | // processThisEvent = true; | ||
| 752 | // } | ||
| 753 | // } | ||
| 754 | // } | ||
| 755 | // } | ||
| 756 | // // This is not an NC area mouse message. | ||
| 757 | // if (!processThisEvent) | ||
| 758 | // return; | ||
| 759 | // // If the window is frame less, generate fake mouse events instead. (floating QToolBar) | ||
| 760 | // if (fakeNCEvents && (widgetToGetEvent->window()->windowFlags() & Qt::FramelessWindowHint)) | ||
| 761 | // fakeMouseEvents = true; | ||
| 762 | // | ||
| 763 | // Qt::MouseButton button; | ||
| 764 | // QEvent::Type eventType; | ||
| 765 | // // Convert to Qt::Event type | ||
| 766 | // switch (evtType) { | ||
| 767 | // case NSLeftMouseDown: | ||
| 768 | // button = Qt::LeftButton; | ||
| 769 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonPress | ||
| 770 | // : QEvent::MouseButtonPress; | ||
| 771 | // break; | ||
| 772 | // case NSLeftMouseUp: | ||
| 773 | // button = Qt::LeftButton; | ||
| 774 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonRelease | ||
| 775 | // : QEvent::MouseButtonRelease; | ||
| 776 | // break; | ||
| 777 | // case NSRightMouseDown: | ||
| 778 | // button = Qt::RightButton; | ||
| 779 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonPress | ||
| 780 | // : QEvent::MouseButtonPress; | ||
| 781 | // break; | ||
| 782 | // case NSRightMouseUp: | ||
| 783 | // button = Qt::RightButton; | ||
| 784 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonRelease | ||
| 785 | // : QEvent::MouseButtonRelease; | ||
| 786 | // break; | ||
| 787 | // case NSOtherMouseDown: | ||
| 788 | // button = cocoaButton2QtButton([event buttonNumber]); | ||
| 789 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonPress | ||
| 790 | // : QEvent::MouseButtonPress; | ||
| 791 | // break; | ||
| 792 | // case NSOtherMouseUp: | ||
| 793 | // button = cocoaButton2QtButton([event buttonNumber]); | ||
| 794 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonRelease | ||
| 795 | // : QEvent::MouseButtonRelease; | ||
| 796 | // break; | ||
| 797 | // case NSMouseMoved: | ||
| 798 | // button = Qt::NoButton; | ||
| 799 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove | ||
| 800 | // : QEvent::MouseMove; | ||
| 801 | // break; | ||
| 802 | // case NSLeftMouseDragged: | ||
| 803 | // button = Qt::LeftButton; | ||
| 804 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove | ||
| 805 | // : QEvent::MouseMove; | ||
| 806 | // break; | ||
| 807 | // case NSRightMouseDragged: | ||
| 808 | // button = Qt::RightButton; | ||
| 809 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove | ||
| 810 | // : QEvent::MouseMove; | ||
| 811 | // break; | ||
| 812 | // case NSOtherMouseDragged: | ||
| 813 | // button = cocoaButton2QtButton([event buttonNumber]); | ||
| 814 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove | ||
| 815 | // : QEvent::MouseMove; | ||
| 816 | // break; | ||
| 817 | // default: | ||
| 818 | // qWarning("not handled! Non client area mouse message"); | ||
| 819 | // return; | ||
| 820 | // } | ||
| 821 | // | ||
| 822 | // Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([event modifierFlags]); | ||
| 823 | // if (eventType == QEvent::NonClientAreaMouseButtonPress || eventType == QEvent::MouseButtonPress) { | ||
| 824 | // NSInteger clickCount = [event clickCount]; | ||
| 825 | // if (clickCount % 2 == 0) | ||
| 826 | // eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonDblClick | ||
| 827 | // : QEvent::MouseButtonDblClick; | ||
| 828 | // if (button == Qt::LeftButton && (keyMods & Qt::MetaModifier)) { | ||
| 829 | // button = Qt::RightButton; | ||
| 830 | // leftButtonIsRightButton = true; | ||
| 831 | // } | ||
| 832 | // } else if (eventType == QEvent::NonClientAreaMouseButtonRelease || eventType == QEvent::MouseButtonRelease) { | ||
| 833 | // if (button == Qt::LeftButton && leftButtonIsRightButton) { | ||
| 834 | // button = Qt::RightButton; | ||
| 835 | // leftButtonIsRightButton = false; | ||
| 836 | // } | ||
| 837 | // } | ||
| 838 | // QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, button, keyMods); | ||
| 839 | // qt_sendSpontaneousEvent(widgetToGetEvent, &qme); | ||
| 840 | //#endif | ||
| 841 | //} | ||
| 842 | // | ||
| 843 | //bool qt_mac_handleMouseEvent(void * /* NSView * */view, void * /* NSEvent * */event, QEvent::Type eventType, Qt::MouseButton button) | ||
| 844 | //{ | ||
| 845 | //#ifndef QT_MAC_USE_COCOA | ||
| 846 | // Q_UNUSED(view); | ||
| 847 | // Q_UNUSED(event); | ||
| 848 | // Q_UNUSED(eventType); | ||
| 849 | // Q_UNUSED(button); | ||
| 850 | // return false; | ||
| 851 | //#else | ||
| 852 | // QT_MANGLE_NAMESPACE(QCocoaView) *theView = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view); | ||
| 853 | // NSEvent *theEvent = static_cast<NSEvent *>(event); | ||
| 854 | // | ||
| 855 | // // Give the Input Manager a chance to process the mouse events. | ||
| 856 | // NSInputManager *currentIManager = [NSInputManager currentInputManager]; | ||
| 857 | // if (currentIManager && [currentIManager wantsToHandleMouseEvents]) { | ||
| 858 | // [currentIManager handleMouseEvent:theEvent]; | ||
| 859 | // } | ||
| 860 | // | ||
| 861 | // // Handle tablet events (if any) first. | ||
| 862 | // if (qt_mac_handleTabletEvent(theView, theEvent)) { | ||
| 863 | // // Tablet event was handled. In Qt we aren't supposed to send the mouse event. | ||
| 864 | // return true; | ||
| 865 | // } | ||
| 866 | // | ||
| 867 | // NSPoint windowPoint = [theEvent locationInWindow]; | ||
| 868 | // NSPoint globalPoint = [[theEvent window] convertBaseToScreen:windowPoint]; | ||
| 869 | // | ||
| 870 | // // Find the widget that *should* get the event (e.g., maybe it was a pop-up, | ||
| 871 | // // they always get the mouse event). | ||
| 872 | // QWidget *qwidget = [theView qt_qwidget]; | ||
| 873 | // QWidget *widgetToGetMouse = qwidget; | ||
| 874 | // QWidget *popup = qAppInstance()->activePopupWidget(); | ||
| 875 | // NSView *tmpView = theView; | ||
| 876 | // if (mac_mouse_grabber && mac_mouse_grabber != widgetToGetMouse) { | ||
| 877 | // widgetToGetMouse = mac_mouse_grabber; | ||
| 878 | // tmpView = qt_mac_nativeview_for(widgetToGetMouse); | ||
| 879 | // } | ||
| 880 | // | ||
| 881 | // if (popup && popup != qwidget->window()) { | ||
| 882 | // widgetToGetMouse = popup; | ||
| 883 | // tmpView = qt_mac_nativeview_for(popup); | ||
| 884 | // windowPoint = [[tmpView window] convertScreenToBase:globalPoint]; | ||
| 885 | // | ||
| 886 | // QPoint qWindowPoint(windowPoint.x, windowPoint.y); | ||
| 887 | // if (widgetToGetMouse->rect().contains(qWindowPoint)) { | ||
| 888 | // // Keeping the mouse pressed on a combobox button will make | ||
| 889 | // // the popup pop in front of the mouse. But all mouse events | ||
| 890 | // // will be sendt to the button. Since we want mouse events | ||
| 891 | // // to be sendt to widgets inside the popup, we search for the | ||
| 892 | // // widget in front of the mouse: | ||
| 893 | // tmpView = [tmpView hitTest:windowPoint]; | ||
| 894 | // if (!tmpView) | ||
| 895 | // return false; | ||
| 896 | // widgetToGetMouse = | ||
| 897 | // [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget]; | ||
| 898 | // } | ||
| 899 | // } else { | ||
| 900 | // extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp | ||
| 901 | // if (!mac_mouse_grabber && qt_button_down) { | ||
| 902 | // // if there is no explicit grabber, and the mouse was grabbed | ||
| 903 | // // implicitely (i.e. a mousebutton was pressed) | ||
| 904 | // widgetToGetMouse = qt_button_down; | ||
| 905 | // tmpView = qt_mac_nativeview_for(widgetToGetMouse); | ||
| 906 | // } | ||
| 907 | // } | ||
| 908 | // | ||
| 909 | // NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil]; | ||
| 910 | // QPoint qlocalPoint(localPoint.x, localPoint.y); | ||
| 911 | // | ||
| 912 | // EventRef carbonEvent = static_cast<EventRef>(const_cast<void *>([theEvent eventRef])); | ||
| 913 | // if (qt_mac_sendMacEventToWidget(widgetToGetMouse, carbonEvent)) | ||
| 914 | // return true; | ||
| 915 | // | ||
| 916 | // // Yay! All the special cases are handled, it really is just a normal mouse event. | ||
| 917 | // Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([theEvent modifierFlags]); | ||
| 918 | // NSInteger clickCount = [theEvent clickCount]; | ||
| 919 | // Qt::MouseButtons buttons = 0; | ||
| 920 | // { | ||
| 921 | // UInt32 mac_buttons; | ||
| 922 | // if (GetEventParameter(carbonEvent, kEventParamMouseChord, typeUInt32, 0, | ||
| 923 | // sizeof(mac_buttons), 0, &mac_buttons) == noErr) | ||
| 924 | // buttons = qt_mac_get_buttons(mac_buttons); | ||
| 925 | // } | ||
| 926 | // switch (eventType) { | ||
| 927 | // default: | ||
| 928 | // qWarning("not handled! %d", eventType); | ||
| 929 | // break; | ||
| 930 | // case QEvent::MouseMove: | ||
| 931 | // break; | ||
| 932 | // case QEvent::MouseButtonPress: | ||
| 933 | // [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = theView; | ||
| 934 | // [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = theEvent; | ||
| 935 | //#ifndef QT_NAMESPACE | ||
| 936 | // Q_ASSERT(clickCount > 0); | ||
| 937 | //#endif | ||
| 938 | // if (clickCount % 2 == 0) | ||
| 939 | // eventType = QEvent::MouseButtonDblClick; | ||
| 940 | // if (button == Qt::LeftButton && (keyMods & Qt::MetaModifier)) { | ||
| 941 | // button = Qt::RightButton; | ||
| 942 | // [theView qt_setLeftButtonIsRightButton: true]; | ||
| 943 | // } | ||
| 944 | // break; | ||
| 945 | // case QEvent::MouseButtonRelease: | ||
| 946 | // if (button == Qt::LeftButton && [theView qt_leftButtonIsRightButton]) { | ||
| 947 | // button = Qt::RightButton; | ||
| 948 | // [theView qt_setLeftButtonIsRightButton: false]; | ||
| 949 | // } | ||
| 950 | // break; | ||
| 951 | // } | ||
| 952 | // [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->localPoint = localPoint; | ||
| 953 | // QPoint qglobalPoint(flipPoint(globalPoint).toPoint()); | ||
| 954 | // QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods); | ||
| 955 | // qt_sendSpontaneousEvent(widgetToGetMouse, &qme); | ||
| 956 | // if (eventType == QEvent::MouseButtonPress && button == Qt::RightButton) { | ||
| 957 | // QContextMenuEvent qcme(QContextMenuEvent::Mouse, qlocalPoint, qglobalPoint, keyMods); | ||
| 958 | // qt_sendSpontaneousEvent(widgetToGetMouse, &qcme); | ||
| 959 | // } | ||
| 960 | // return qme.isAccepted(); | ||
| 961 | //#endif | ||
| 962 | //} | ||
| 963 | // | ||
| 964 | //bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */tabletEvent) | ||
| 965 | //{ | ||
| 966 | //#ifndef QT_MAC_USE_COCOA | ||
| 967 | // Q_UNUSED(view); | ||
| 968 | // Q_UNUSED(tabletEvent); | ||
| 969 | // return false; | ||
| 970 | //#else | ||
| 971 | // QT_MANGLE_NAMESPACE(QCocoaView) *theView = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view); | ||
| 972 | // NSView *theNSView = static_cast<NSView *>(view); | ||
| 973 | // NSEvent *theTabletEvent = static_cast<NSEvent *>(tabletEvent); | ||
| 974 | // | ||
| 975 | // NSEventType eventType = [theTabletEvent type]; | ||
| 976 | // if (eventType != NSTabletPoint && [theTabletEvent subtype] != NSTabletPointEventSubtype) | ||
| 977 | // return false; // Not a tablet event. | ||
| 978 | // | ||
| 979 | // NSPoint windowPoint = [theTabletEvent locationInWindow]; | ||
| 980 | // NSPoint globalPoint = [[theTabletEvent window] convertBaseToScreen:windowPoint]; | ||
| 981 | // | ||
| 982 | // QWidget *qwidget = [theView qt_qwidget]; | ||
| 983 | // QWidget *widgetToGetMouse = qwidget; | ||
| 984 | // QWidget *popup = qAppInstance()->activePopupWidget(); | ||
| 985 | // if (popup && popup != qwidget->window()) | ||
| 986 | // widgetToGetMouse = popup; | ||
| 987 | // | ||
| 988 | // if (qt_mac_sendMacEventToWidget(widgetToGetMouse, | ||
| 989 | // static_cast<EventRef>(const_cast<void *>([theTabletEvent eventRef])))) | ||
| 990 | // return true; | ||
| 991 | // if (widgetToGetMouse != qwidget) { | ||
| 992 | // theNSView = qt_mac_nativeview_for(widgetToGetMouse); | ||
| 993 | // windowPoint = [[theNSView window] convertScreenToBase:globalPoint]; | ||
| 994 | // } | ||
| 995 | // NSPoint localPoint = [theNSView convertPoint:windowPoint fromView:nil]; | ||
| 996 | // // Tablet events do not handle WA_TransparentForMouseEvents ATM | ||
| 997 | // // In theory, people who set the WA_TransparentForMouseEvents attribute won't handle | ||
| 998 | // // tablet events either in which case they will fall into the mouse event case and get | ||
| 999 | // // them passed on. This will NOT handle the raw events, but that might not be a big problem. | ||
| 1000 | // | ||
| 1001 | // const QMacTabletHash *tabletHash = qt_mac_tablet_hash(); | ||
| 1002 | // if (!tabletHash->contains([theTabletEvent deviceID])) { | ||
| 1003 | // qWarning("QCocoaView handleTabletEvent: This tablet device is unknown" | ||
| 1004 | // " (received no proximity event for it). Discarding event."); | ||
| 1005 | // return false; | ||
| 1006 | // } | ||
| 1007 | // const QTabletDeviceData &deviceData = tabletHash->value([theTabletEvent deviceID]); | ||
| 1008 | // | ||
| 1009 | // | ||
| 1010 | // QEvent::Type qType; | ||
| 1011 | // switch (eventType) { | ||
| 1012 | // case NSLeftMouseDown: | ||
| 1013 | // case NSRightMouseDown: | ||
| 1014 | // qType = QEvent::TabletPress; | ||
| 1015 | // break; | ||
| 1016 | // case NSLeftMouseUp: | ||
| 1017 | // case NSRightMouseUp: | ||
| 1018 | // qType = QEvent::TabletRelease; | ||
| 1019 | // break; | ||
| 1020 | // case NSMouseMoved: | ||
| 1021 | // case NSTabletPoint: | ||
| 1022 | // case NSLeftMouseDragged: | ||
| 1023 | // case NSRightMouseDragged: | ||
| 1024 | // default: | ||
| 1025 | // qType = QEvent::TabletMove; | ||
| 1026 | // break; | ||
| 1027 | // } | ||
| 1028 | // | ||
| 1029 | // qreal pressure; | ||
| 1030 | // if (eventType != NSMouseMoved) { | ||
| 1031 | // pressure = [theTabletEvent pressure]; | ||
| 1032 | // } else { | ||
| 1033 | // pressure = 0.0; | ||
| 1034 | // } | ||
| 1035 | // | ||
| 1036 | // NSPoint tilt = [theTabletEvent tilt]; | ||
| 1037 | // int xTilt = qRound(tilt.x * 60.0); | ||
| 1038 | // int yTilt = qRound(tilt.y * -60.0); | ||
| 1039 | // qreal tangentialPressure = 0; | ||
| 1040 | // qreal rotation = 0; | ||
| 1041 | // int z = 0; | ||
| 1042 | // if (deviceData.capabilityMask & 0x0200) | ||
| 1043 | // z = [theTabletEvent absoluteZ]; | ||
| 1044 | // | ||
| 1045 | // if (deviceData.capabilityMask & 0x0800) | ||
| 1046 | // tangentialPressure = [theTabletEvent tangentialPressure]; | ||
| 1047 | // | ||
| 1048 | // rotation = [theTabletEvent rotation]; | ||
| 1049 | // QPointF hiRes = flipPoint(globalPoint); | ||
| 1050 | // QTabletEvent qtabletEvent(qType, QPoint(localPoint.x, localPoint.y), | ||
| 1051 | // hiRes.toPoint(), hiRes, | ||
| 1052 | // deviceData.tabletDeviceType, deviceData.tabletPointerType, | ||
| 1053 | // pressure, xTilt, yTilt, tangentialPressure, rotation, z, | ||
| 1054 | // qt_cocoaModifiers2QtModifiers([theTabletEvent modifierFlags]), | ||
| 1055 | // deviceData.tabletUniqueID); | ||
| 1056 | // | ||
| 1057 | // qt_sendSpontaneousEvent(widgetToGetMouse, &qtabletEvent); | ||
| 1058 | // return qtabletEvent.isAccepted(); | ||
| 1059 | //#endif | ||
| 1060 | //} | ||
| 1061 | // | ||
| 1062 | //void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::HIContentBorderMetrics &metrics) | ||
| 1063 | //{ | ||
| 1064 | // OSWindowRef theWindow = static_cast<OSWindowRef>(window); | ||
| 1065 | //#if !defined(QT_MAC_USE_COCOA) | ||
| 1066 | //# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 | ||
| 1067 | // if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { | ||
| 1068 | // ::HIWindowSetContentBorderThickness(theWindow, &metrics); | ||
| 1069 | // } | ||
| 1070 | //# else | ||
| 1071 | // Q_UNUSED(window); | ||
| 1072 | // Q_UNUSED(metrics); | ||
| 1073 | //# endif | ||
| 1074 | //#else | ||
| 1075 | // if ([theWindow styleMask] & NSTexturedBackgroundWindowMask) | ||
| 1076 | // [theWindow setContentBorderThickness:metrics.top forEdge:NSMaxYEdge]; | ||
| 1077 | // [theWindow setContentBorderThickness:metrics.bottom forEdge:NSMinYEdge]; | ||
| 1078 | //#endif | ||
| 1079 | //} | ||
| 1080 | // | ||
| 1081 | //void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show) | ||
| 1082 | //{ | ||
| 1083 | //#if QT_MAC_USE_COCOA | ||
| 1084 | // QMacCocoaAutoReleasePool pool; | ||
| 1085 | // OSWindowRef theWindow = static_cast<OSWindowRef>(window); | ||
| 1086 | // NSToolbar *macToolbar = [theWindow toolbar]; | ||
| 1087 | // if (macToolbar) | ||
| 1088 | // [macToolbar setShowsBaselineSeparator: show]; | ||
| 1089 | //#endif | ||
| 1090 | //} | ||
| 1091 | // | ||
| 1092 | //QStringList qt_mac_NSArrayToQStringList(void *nsarray) | ||
| 1093 | //{ | ||
| 1094 | // QStringList result; | ||
| 1095 | // NSArray *array = static_cast<NSArray *>(nsarray); | ||
| 1096 | // for (NSUInteger i=0; i<[array count]; ++i) | ||
| 1097 | // result << qt_mac_NSStringToQString([array objectAtIndex:i]); | ||
| 1098 | // return result; | ||
| 1099 | //} | ||
| 1100 | // | ||
| 1101 | //void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list) | ||
| 1102 | //{ | ||
| 1103 | // NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()]; | ||
| 1104 | // for (int i=0; i<list.size(); ++i){ | ||
| 1105 | // [result addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(list[i]))]; | ||
| 1106 | // } | ||
| 1107 | // return result; | ||
| 1108 | //} | ||
| 1109 | // | ||
| 1110 | //void qt_syncCocoaTitleBarButtons(OSWindowRef window, QWidget *widgetForWindow) | ||
| 1111 | //{ | ||
| 1112 | // if (!widgetForWindow) | ||
| 1113 | // return; | ||
| 1114 | // | ||
| 1115 | // Qt::WindowFlags flags = widgetForWindow->windowFlags(); | ||
| 1116 | // bool customize = flags & Qt::CustomizeWindowHint; | ||
| 1117 | // | ||
| 1118 | // NSButton *btn = [window standardWindowButton:NSWindowZoomButton]; | ||
| 1119 | // // BOOL is not an int, so the bitwise AND doesn't work. | ||
| 1120 | // bool go = uint(customize && !(flags & Qt::WindowMaximizeButtonHint)) == 0; | ||
| 1121 | // [btn setEnabled:go]; | ||
| 1122 | // | ||
| 1123 | // btn = [window standardWindowButton:NSWindowMiniaturizeButton]; | ||
| 1124 | // go = uint(customize && !(flags & Qt::WindowMinimizeButtonHint)) == 0; | ||
| 1125 | // [btn setEnabled:go]; | ||
| 1126 | // | ||
| 1127 | // btn = [window standardWindowButton:NSWindowCloseButton]; | ||
| 1128 | // go = uint(customize && !(flags & Qt::WindowSystemMenuHint | ||
| 1129 | // || flags & Qt::WindowCloseButtonHint)) == 0; | ||
| 1130 | // [btn setEnabled:go]; | ||
| 1131 | // | ||
| 1132 | // [window setShowsToolbarButton:uint(flags & Qt::MacWindowToolBarButtonHint) != 0]; | ||
| 1133 | //} | ||
| 1134 | // | ||
| 1135 | //// Carbon: Make sure you call QDEndContext on the context when done with it. | ||
| 1136 | //CGContextRef qt_mac_graphicsContextFor(QWidget *widget) | ||
| 1137 | //{ | ||
| 1138 | // if (!widget) | ||
| 1139 | // return 0; | ||
| 1140 | // | ||
| 1141 | //#ifndef QT_MAC_USE_COCOA | ||
| 1142 | // CGContextRef context; | ||
| 1143 | // CGrafPtr port = GetWindowPort(qt_mac_window_for(widget)); | ||
| 1144 | // QDBeginCGContext(port, &context); | ||
| 1145 | //#else | ||
| 1146 | // CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithWindow:qt_mac_window_for(widget)] graphicsPort]; | ||
| 1147 | //#endif | ||
| 1148 | // return context; | ||
| 1149 | //} | ||
| 1150 | |||
| 1151 | CGFloat qt_iphone_get_scalefactor() | ||
| 1152 | { | ||
| 1153 | //#ifndef QT_MAC_USE_COCOA | ||
| 1154 | // return HIGetScaleFactor(); | ||
| 1155 | //#else | ||
| 1156 | // return [[NSScreen mainScreen] userSpaceScaleFactor]; | ||
| 1157 | //#endif | ||
| 1158 | return 1; | ||
| 1159 | } | ||
| 1160 | |||
| 1161 | //QString qt_mac_get_pasteboardString(OSPasteboardRef paste) | ||
| 1162 | //{ | ||
| 1163 | // QMacCocoaAutoReleasePool pool; | ||
| 1164 | // NSPasteboard *pb = nil; | ||
| 1165 | // CFStringRef pbname; | ||
| 1166 | // if (PasteboardCopyName (paste, &pbname)) { | ||
| 1167 | // pb = [NSPasteboard generalPasteboard]; | ||
| 1168 | // } else { | ||
| 1169 | // pb = [NSPasteboard pasteboardWithName:reinterpret_cast<const NSString *>(pbname)]; | ||
| 1170 | // CFRelease (pbname); | ||
| 1171 | // } | ||
| 1172 | // if (pb) { | ||
| 1173 | // NSString *text = [pb stringForType:NSStringPboardType]; | ||
| 1174 | // if (text) | ||
| 1175 | // return qt_mac_NSStringToQString(text); | ||
| 1176 | // } | ||
| 1177 | // return QString(); | ||
| 1178 | //} | ||
| 1179 | // | ||
| 1180 | //QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height) | ||
| 1181 | //{ | ||
| 1182 | // QPixmap ret(width, height); | ||
| 1183 | // ret.fill(QColor(0, 0, 0, 0)); | ||
| 1184 | // | ||
| 1185 | // CGRect rect = CGRectMake(0, 0, width, height); | ||
| 1186 | // | ||
| 1187 | // CGContextRef ctx = qt_mac_cg_context(&ret); | ||
| 1188 | // CGAffineTransform old_xform = CGContextGetCTM(ctx); | ||
| 1189 | // CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform)); | ||
| 1190 | // CGContextConcatCTM(ctx, CGAffineTransformIdentity); | ||
| 1191 | // | ||
| 1192 | // ::RGBColor b; | ||
| 1193 | // b.blue = b.green = b.red = 255*255; | ||
| 1194 | // PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon); | ||
| 1195 | // CGContextRelease(ctx); | ||
| 1196 | // return ret; | ||
| 1197 | //} | ||
| 1198 | // | ||
| 1199 | //void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon) | ||
| 1200 | //{ | ||
| 1201 | // int size = 16; | ||
| 1202 | // while (size <= 128) { | ||
| 1203 | // | ||
| 1204 | // const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size); | ||
| 1205 | // QPixmap mainIcon; | ||
| 1206 | // if (standardIcon >= QStyle::SP_CustomBase) { | ||
| 1207 | // mainIcon = qt_mac_convert_iconref(icon, size, size); | ||
| 1208 | // } else if (QPixmapCache::find(cacheKey, mainIcon) == false) { | ||
| 1209 | // mainIcon = qt_mac_convert_iconref(icon, size, size); | ||
| 1210 | // QPixmapCache::insert(cacheKey, mainIcon); | ||
| 1211 | // } | ||
| 1212 | // | ||
| 1213 | // if (overlayIcon) { | ||
| 1214 | // int littleSize = size / 2; | ||
| 1215 | // QPixmap overlayPix = qt_mac_convert_iconref(overlayIcon, littleSize, littleSize); | ||
| 1216 | // QPainter painter(&mainIcon); | ||
| 1217 | // painter.drawPixmap(size - littleSize, size - littleSize, overlayPix); | ||
| 1218 | // } | ||
| 1219 | // | ||
| 1220 | // retIcon->addPixmap(mainIcon); | ||
| 1221 | // size += size; // 16 -> 32 -> 64 -> 128 | ||
| 1222 | // } | ||
| 1223 | //} | ||
| 1224 | // | ||
| 1225 | //void qt_mac_menu_collapseSeparators(void */*NSMenu **/ theMenu, bool collapse) | ||
| 1226 | //{ | ||
| 1227 | // OSMenuRef menu = static_cast<OSMenuRef>(theMenu); | ||
| 1228 | // if (collapse) { | ||
| 1229 | // bool previousIsSeparator = true; // setting to true kills all the separators placed at the top. | ||
| 1230 | // NSMenuItem *previousItem = nil; | ||
| 1231 | // | ||
| 1232 | // NSArray *itemArray = [menu itemArray]; | ||
| 1233 | // for (unsigned int i = 0; i < [itemArray count]; ++i) { | ||
| 1234 | // NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]); | ||
| 1235 | // if ([item isSeparatorItem]) { | ||
| 1236 | // [item setHidden:previousIsSeparator]; | ||
| 1237 | // } | ||
| 1238 | // | ||
| 1239 | // if (![item isHidden]) { | ||
| 1240 | // previousItem = item; | ||
| 1241 | // previousIsSeparator = ([previousItem isSeparatorItem]); | ||
| 1242 | // } | ||
| 1243 | // } | ||
| 1244 | // | ||
| 1245 | // // We now need to check the final item since we don't want any separators at the end of the list. | ||
| 1246 | // if (previousItem && previousIsSeparator) | ||
| 1247 | // [previousItem setHidden:YES]; | ||
| 1248 | // } else { | ||
| 1249 | // NSArray *itemArray = [menu itemArray]; | ||
| 1250 | // for (unsigned int i = 0; i < [itemArray count]; ++i) { | ||
| 1251 | // NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]); | ||
| 1252 | // if (QAction *action = reinterpret_cast<QAction *>([item tag])) | ||
| 1253 | // [item setHidden:!action->isVisible()]; | ||
| 1254 | // } | ||
| 1255 | // } | ||
| 1256 | //} | ||
| 1257 | // | ||
| 1258 | //#ifdef QT_MAC_USE_COCOA | ||
| 1259 | //void qt_cocoaChangeOverrideCursor(const QCursor &cursor) | ||
| 1260 | //{ | ||
| 1261 | // QMacCocoaAutoReleasePool pool; | ||
| 1262 | // [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) set]; | ||
| 1263 | //} | ||
| 1264 | //#endif | ||
| 1265 | |||
| 1266 | QT_END_NAMESPACE |
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | // | ||
| 77 | // W A R N I N G | ||
| 78 | // ------------- | ||
| 79 | // | ||
| 80 | // This file is not part of the Qt API. It exists for the convenience | ||
| 81 | // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp | ||
| 82 | // and many other. This header file may change from version to version | ||
| 83 | // without notice, or even be removed. | ||
| 84 | // | ||
| 85 | // We mean it. | ||
| 86 | // | ||
| 87 | |||
| 88 | #include <private/qt_iphone_p.h> | ||
| 89 | |||
| 90 | #include <qapplication.h> | ||
| 91 | #include <qdesktopwidget.h> | ||
| 92 | #include <qwidget.h> | ||
| 93 | #include <qevent.h> | ||
| 94 | #include <qhash.h> | ||
| 95 | #include <qlabel.h> | ||
| 96 | #include <qpointer.h> | ||
| 97 | #include <qstyle.h> | ||
| 98 | #include <qstyleoption.h> | ||
| 99 | #include <qstylepainter.h> | ||
| 100 | #include <qtimer.h> | ||
| 101 | #include <qtooltip.h> | ||
| 102 | #include <private/qeffects_p.h> | ||
| 103 | #include <qtextdocument.h> | ||
| 104 | #include <qdebug.h> | ||
| 105 | #include <qpoint.h> | ||
| 106 | #include "private/qt_iphone_p.h" | ||
| 107 | |||
| 108 | //struct HIContentBorderMetrics; | ||
| 109 | // | ||
| 110 | //#ifdef Q_WS_MAC32 | ||
| 111 | //typedef struct _NSPoint NSPoint; // Just redefine here so I don't have to pull in all of Cocoa. | ||
| 112 | //#else | ||
| 113 | //typedef struct CGPoint NSPoint; | ||
| 114 | //#endif | ||
| 115 | // | ||
| 116 | //QT_BEGIN_NAMESPACE | ||
| 117 | //Qt::MouseButtons qt_mac_get_buttons(int buttons); | ||
| 118 | //#ifndef Q_WS_IPHONE | ||
| 119 | //Qt::MouseButton qt_mac_get_button(EventMouseButton button); | ||
| 120 | //#endif | ||
| 121 | //void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds = 0.15); | ||
| 122 | //bool macWindowIsTextured(void * /*OSWindowRef*/ window); | ||
| 123 | //void macWindowToolbarShow(const QWidget *widget, bool show ); | ||
| 124 | //void macWindowToolbarSet( void * /*OSWindowRef*/ window, void* toolbarRef ); | ||
| 125 | //bool macWindowToolbarIsVisible( void * /*OSWindowRef*/ window ); | ||
| 126 | //void macWindowSetHasShadow( void * /*OSWindowRef*/ window, bool hasShadow ); | ||
| 127 | //void macWindowFlush(void * /*OSWindowRef*/ window); | ||
| 128 | //void macSendToolbarChangeEvent(QWidget *widget); | ||
| 129 | //void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::HIContentBorderMetrics &metrics); | ||
| 130 | //void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show); | ||
| 131 | //void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm); | ||
| 132 | //void qt_mac_update_mouseTracking(QWidget *widget); | ||
| 133 | int qt_iphone_drawCGImage(CGContextRef cg, const CGRect *inbounds, CGImageRef); | ||
| 134 | //bool qt_mac_checkForNativeSizeGrip(const QWidget *widget); | ||
| 135 | //void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent); | ||
| 136 | //#ifdef QT_MAC_USE_COCOA | ||
| 137 | //bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent); | ||
| 138 | //void qt_cocoaChangeOverrideCursor(const QCursor &cursor); | ||
| 139 | //#endif | ||
| 140 | //void qt_mac_menu_collapseSeparators(void * /*NSMenu */ menu, bool collapse); | ||
| 141 | //bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent); | ||
| 142 | //void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent); | ||
| 143 | //void qt_mac_dispatchNCMouseMessage(void */* NSWindow* */eventWindow, void */* NSEvent* */mouseEvent, | ||
| 144 | // QWidget *widgetToGetEvent, bool &leftButtonIsRightButton); | ||
| 145 | //bool qt_mac_handleMouseEvent(void * /*QCocoaView * */view, void * /*NSEvent * */event, QEvent::Type eventType, Qt::MouseButton button); | ||
| 146 | //bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */event); | ||
| 147 | //inline QApplication *qAppInstance() { return static_cast<QApplication *>(QCoreApplication::instance()); } | ||
| 148 | //#ifndef Q_WS_IPHONE | ||
| 149 | //struct ::TabletProximityRec; | ||
| 150 | //void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec); | ||
| 151 | //#endif | ||
| 152 | //Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags); | ||
| 153 | //Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations); | ||
| 154 | //QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height); | ||
| 155 | //void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, | ||
| 156 | // QStyle::StandardPixmap standardIcon = QStyle::SP_CustomBase); | ||
| 157 | //inline int flipYCoordinate(int y) | ||
| 158 | //{ | ||
| 159 | // return QApplication::desktop()->screenGeometry(0).height() - y; | ||
| 160 | //} | ||
| 161 | // | ||
| 162 | //inline qreal flipYCoordinate(qreal y) | ||
| 163 | //{ | ||
| 164 | // return QApplication::desktop()->screenGeometry(0).height() - y; | ||
| 165 | //} | ||
| 166 | // | ||
| 167 | //QPointF flipPoint(const NSPoint &p); | ||
| 168 | //NSPoint flipPoint(const QPoint &p); | ||
| 169 | //NSPoint flipPoint(const QPointF &p); | ||
| 170 | // | ||
| 171 | //QStringList qt_mac_NSArrayToQStringList(void *nsarray); | ||
| 172 | //void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list); | ||
| 173 | // | ||
| 174 | //void qt_syncCocoaTitleBarButtons(OSWindowRef window, QWidget *widgetForWindow); | ||
| 175 | |||
| 176 | CGFloat qt_iphone_get_scalefactor(); | ||
| 177 | //QString qt_mac_get_pasteboardString(OSPasteboardRef paste); | ||
| 178 | |||
| 179 | //#ifdef __OBJC__ | ||
| 180 | //inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qstrlist) | ||
| 181 | //{ return reinterpret_cast<NSMutableArray *>(qt_mac_QStringListToNSMutableArrayVoid(qstrlist)); } | ||
| 182 | // | ||
| 183 | //inline QString qt_mac_NSStringToQString(const NSString *nsstr) | ||
| 184 | //{ return QCFString::toQString(reinterpret_cast<const CFStringRef>(nsstr)); } | ||
| 185 | // | ||
| 186 | //inline NSString *qt_mac_QStringToNSString(const QString &qstr) | ||
| 187 | //{ return [reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)) autorelease]; } | ||
| 188 | //#endif | ||
| 189 | |||
| 190 | QT_END_NAMESPACE |
src/gui/kernel/qt_iphone.mm
(175 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #include <private/qt_iphone_p.h> | ||
| 43 | #include <private/qpixmap_iphone_p.h> | ||
| 44 | #include <private/qnativeimage_p.h> | ||
| 45 | #include <qdebug.h> | ||
| 46 | |||
| 47 | QT_BEGIN_NAMESPACE | ||
| 48 | |||
| 49 | //#ifdef QT_MAC_USE_COCOA | ||
| 50 | //static CTFontRef CopyCTThemeFont(ThemeFontID themeID) | ||
| 51 | //{ | ||
| 52 | // CTFontUIFontType ctID = HIThemeGetUIFontType(themeID); | ||
| 53 | // return CTFontCreateUIFontForLanguage(ctID, 0, 0); | ||
| 54 | //} | ||
| 55 | //#endif | ||
| 56 | // | ||
| 57 | //QFont qfontForThemeFont(ThemeFontID themeID) | ||
| 58 | //{ | ||
| 59 | //#ifndef QT_MAC_USE_COCOA | ||
| 60 | // static const ScriptCode Script = smRoman; | ||
| 61 | // Str255 f_name; | ||
| 62 | // SInt16 f_size; | ||
| 63 | // Style f_style; | ||
| 64 | // GetThemeFont(themeID, Script, f_name, &f_size, &f_style); | ||
| 65 | // extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp | ||
| 66 | // return QFont(qt_mac_from_pascal_string(f_name), f_size, | ||
| 67 | // (f_style & ::bold) ? QFont::Bold : QFont::Normal, | ||
| 68 | // (bool)(f_style & ::italic)); | ||
| 69 | //#else | ||
| 70 | // QCFType<CTFontRef> ctfont = CopyCTThemeFont(themeID); | ||
| 71 | // QString familyName = QCFString(CTFontCopyFamilyName(ctfont)); | ||
| 72 | // QCFType<CFDictionaryRef> dict = CTFontCopyTraits(ctfont); | ||
| 73 | // CFNumberRef num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontWeightTrait)); | ||
| 74 | // float fW; | ||
| 75 | // CFNumberGetValue(num, kCFNumberFloat32Type, &fW); | ||
| 76 | // QFont::Weight wght = fW > 0. ? QFont::Bold : QFont::Normal; | ||
| 77 | // num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontSlantTrait)); | ||
| 78 | // CFNumberGetValue(num, kCFNumberFloatType, &fW); | ||
| 79 | // bool italic = (fW != 0.0); | ||
| 80 | // return QFont(familyName, CTFontGetSize(ctfont), wght, italic); | ||
| 81 | //#endif | ||
| 82 | //} | ||
| 83 | // | ||
| 84 | //#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) | ||
| 85 | //static QColor qcolorFromCGColor(CGColorRef cgcolor) | ||
| 86 | //{ | ||
| 87 | // QColor pc; | ||
| 88 | // CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgcolor)); | ||
| 89 | // const CGFloat *components = CGColorGetComponents(cgcolor); | ||
| 90 | // if (model == kCGColorSpaceModelRGB) { | ||
| 91 | // pc.setRgbF(components[0], components[1], components[2], components[3]); | ||
| 92 | // } else if (model == kCGColorSpaceModelCMYK) { | ||
| 93 | // pc.setCmykF(components[0], components[1], components[2], components[3]); | ||
| 94 | // } else if (model == kCGColorSpaceModelMonochrome) { | ||
| 95 | // pc.setRgbF(components[0], components[0], components[0], components[1]); | ||
| 96 | // } else { | ||
| 97 | // // Colorspace we can't deal with. | ||
| 98 | // qWarning("Qt: qcolorFromCGColor: cannot convert from colorspace model: %d", model); | ||
| 99 | // Q_ASSERT(false); | ||
| 100 | // } | ||
| 101 | // return pc; | ||
| 102 | //} | ||
| 103 | // | ||
| 104 | //static inline QColor leopardBrush(ThemeBrush brush) | ||
| 105 | //{ | ||
| 106 | // QCFType<CGColorRef> cgClr = 0; | ||
| 107 | // HIThemeBrushCreateCGColor(brush, &cgClr); | ||
| 108 | // return qcolorFromCGColor(cgClr); | ||
| 109 | //} | ||
| 110 | //#endif | ||
| 111 | |||
| 112 | //QColor qcolorForTheme(ThemeBrush brush) | ||
| 113 | //{ | ||
| 114 | //#ifndef QT_MAC_USE_COCOA | ||
| 115 | //# if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) | ||
| 116 | // if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { | ||
| 117 | // return leopardBrush(brush); | ||
| 118 | // } else | ||
| 119 | //# endif | ||
| 120 | // { | ||
| 121 | // RGBColor rgbcolor; | ||
| 122 | // GetThemeBrushAsColor(brush, 32, true, &rgbcolor); | ||
| 123 | // return QColor(rgbcolor.red / 256, rgbcolor.green / 256, rgbcolor.blue / 256); | ||
| 124 | // } | ||
| 125 | //#else | ||
| 126 | // return leopardBrush(brush); | ||
| 127 | //#endif | ||
| 128 | //} | ||
| 129 | |||
| 130 | //QColor qcolorForThemeTextColor(ThemeTextColor themeColor) | ||
| 131 | //{ | ||
| 132 | //#ifdef Q_OS_MAC32 | ||
| 133 | // RGBColor c; | ||
| 134 | // GetThemeTextColor(themeColor, 32, true, &c); | ||
| 135 | // QColor color = QColor(c.red / 256, c.green / 256, c.blue / 256); | ||
| 136 | // return color; | ||
| 137 | //#else | ||
| 138 | // // There is no equivalent to GetThemeTextColor in 64-bit and it was rather bad that | ||
| 139 | // // I didn't file a request to implement this for Snow Leopard. So, in the meantime | ||
| 140 | // // I've encoded the values from the GetThemeTextColor. This is not exactly ideal | ||
| 141 | // // as if someone really wants to mess with themeing, these colors will be wrong. | ||
| 142 | // // It also means that we need to make sure the values for differences between | ||
| 143 | // // OS releases (and it will be likely that we are a step behind.) | ||
| 144 | // switch (themeColor) { | ||
| 145 | // case kThemeTextColorAlertActive: | ||
| 146 | // case kThemeTextColorTabFrontActive: | ||
| 147 | // case kThemeTextColorBevelButtonActive: | ||
| 148 | // case kThemeTextColorListView: | ||
| 149 | // case kThemeTextColorPlacardActive: | ||
| 150 | // case kThemeTextColorPopupButtonActive: | ||
| 151 | // case kThemeTextColorPopupLabelActive: | ||
| 152 | // case kThemeTextColorPushButtonActive: | ||
| 153 | // return Qt::black; | ||
| 154 | // case kThemeTextColorAlertInactive: | ||
| 155 | // case kThemeTextColorDialogInactive: | ||
| 156 | // case kThemeTextColorPlacardInactive: | ||
| 157 | // return QColor(69, 69, 69, 255); | ||
| 158 | // case kThemeTextColorPopupButtonInactive: | ||
| 159 | // case kThemeTextColorPopupLabelInactive: | ||
| 160 | // case kThemeTextColorPushButtonInactive: | ||
| 161 | // case kThemeTextColorTabFrontInactive: | ||
| 162 | // case kThemeTextColorBevelButtonInactive: | ||
| 163 | // return QColor(127, 127, 127, 255); | ||
| 164 | // default: { | ||
| 165 | // QNativeImage nativeImage(16,16, QNativeImage::systemFormat()); | ||
| 166 | // CGRect cgrect = CGRectMake(0, 0, 16, 16); | ||
| 167 | // HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal); | ||
| 168 | // CGContextFillRect(nativeImage.cg, cgrect); | ||
| 169 | // QColor color = nativeImage.image.pixel(0,0); | ||
| 170 | // return QColor(nativeImage.image.pixel(0 , 0)); | ||
| 171 | // } | ||
| 172 | // } | ||
| 173 | //#endif | ||
| 174 | //} | ||
| 175 | QT_END_NAMESPACE |
src/gui/kernel/qt_iphone_p.h
(284 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | #ifndef QT_IPHONE_P_H | ||
| 43 | #define QT_IPHONE_P_H | ||
| 44 | |||
| 45 | // | ||
| 46 | // W A R N I N G | ||
| 47 | // ------------- | ||
| 48 | // | ||
| 49 | // This file is not part of the Qt API. It exists purely as an | ||
| 50 | // implementation detail. This header file may change from version to | ||
| 51 | // version without notice, or even be removed. | ||
| 52 | // | ||
| 53 | // We mean it. | ||
| 54 | // | ||
| 55 | |||
| 56 | #include "qmacdefines_iphone.h" | ||
| 57 | |||
| 58 | #ifdef __OBJC__ | ||
| 59 | #include <UIKit/UIKit.h> | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #include "QtCore/qglobal.h" | ||
| 63 | #include "QtCore/qvariant.h" | ||
| 64 | #include "QtCore/qmimedata.h" | ||
| 65 | #include "QtCore/qpointer.h" | ||
| 66 | |||
| 67 | // For the QtCore we rely on darwin, which is mac platform | ||
| 68 | #include "private/qcore_mac_p.h" | ||
| 69 | |||
| 70 | #include "QtGui/qpainter.h" | ||
| 71 | |||
| 72 | QT_BEGIN_NAMESPACE | ||
| 73 | class QWidget; | ||
| 74 | class QDragMoveEvent; | ||
| 75 | |||
| 76 | /* Event masks */ | ||
| 77 | // internal Qt types | ||
| 78 | |||
| 79 | // Event class for our own Carbon events. | ||
| 80 | //#if defined(QT_NAMESPACE) && defined(QT_NAMESPACE_MAC_CRC) | ||
| 81 | // Take the CRC we generated at configure time. This *may* result in a | ||
| 82 | // collision with another value If that is the case, please change the value | ||
| 83 | // here to something other than 'Cute'. | ||
| 84 | //const UInt32 kEventClassQt = QT_NAMESPACE_MAC_CRC; | ||
| 85 | //#else | ||
| 86 | //const UInt32 kEventClassQt = 'Cute'; | ||
| 87 | //#endif | ||
| 88 | |||
| 89 | //enum { | ||
| 90 | // //AE types | ||
| 91 | // typeAEClipboardChanged = 1, | ||
| 92 | // //types | ||
| 93 | // typeQWidget = 1, /* QWidget * */ | ||
| 94 | // //params | ||
| 95 | // kEventParamQWidget = 'qwid', /* typeQWidget */ | ||
| 96 | // //events | ||
| 97 | // kEventQtRequestContext = 13, | ||
| 98 | // kEventQtRequestMenubarUpdate = 14, | ||
| 99 | // kEventQtRequestShowSheet = 17, | ||
| 100 | // kEventQtRequestActivate = 18, | ||
| 101 | // kEventQtRequestWindowChange = 20 | ||
| 102 | //}; | ||
| 103 | |||
| 104 | // Simple class to manage short-lived regions | ||
| 105 | //class QMacSmartQuickDrawRegion | ||
| 106 | //{ | ||
| 107 | // RgnHandle qdRgn; | ||
| 108 | // Q_DISABLE_COPY(QMacSmartQuickDrawRegion) | ||
| 109 | //public: | ||
| 110 | // explicit QMacSmartQuickDrawRegion(RgnHandle rgn) : qdRgn(rgn) {} | ||
| 111 | // ~QMacSmartQuickDrawRegion() { | ||
| 112 | // extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp | ||
| 113 | // qt_mac_dispose_rgn(qdRgn); | ||
| 114 | // } | ||
| 115 | // operator RgnHandle() { | ||
| 116 | // return qdRgn; | ||
| 117 | // } | ||
| 118 | //}; | ||
| 119 | |||
| 120 | // Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading. | ||
| 121 | //class QMacWindowFader | ||
| 122 | //{ | ||
| 123 | // QWidgetList m_windowsToFade; | ||
| 124 | // float m_duration; | ||
| 125 | // Q_DISABLE_COPY(QMacWindowFader) | ||
| 126 | //public: | ||
| 127 | // QMacWindowFader(); // PLEASE DON'T CALL THIS. | ||
| 128 | // static QMacWindowFader *currentFader(); | ||
| 129 | // void registerWindowToFade(QWidget *window); | ||
| 130 | // void setFadeDuration(float durationInSecs) { m_duration = durationInSecs; } | ||
| 131 | // float fadeDuration() const { return m_duration; } | ||
| 132 | // void performFade(); | ||
| 133 | //}; | ||
| 134 | |||
| 135 | //class Q_GUI_EXPORT QMacCocoaAutoReleasePool | ||
| 136 | //{ | ||
| 137 | //private: | ||
| 138 | // void *pool; | ||
| 139 | //public: | ||
| 140 | // QMacCocoaAutoReleasePool(); | ||
| 141 | // ~QMacCocoaAutoReleasePool(); | ||
| 142 | // | ||
| 143 | // inline void *handle() const { return pool; } | ||
| 144 | //}; | ||
| 145 | |||
| 146 | |||
| 147 | //QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp | ||
| 148 | // | ||
| 149 | //class Q_GUI_EXPORT QMacWindowChangeEvent | ||
| 150 | //{ | ||
| 151 | //private: | ||
| 152 | // static QList<QMacWindowChangeEvent*> *change_events; | ||
| 153 | //public: | ||
| 154 | // QMacWindowChangeEvent() { | ||
| 155 | // } | ||
| 156 | // virtual ~QMacWindowChangeEvent() { | ||
| 157 | // } | ||
| 158 | // static inline void exec(bool ) { | ||
| 159 | // } | ||
| 160 | //protected: | ||
| 161 | // virtual void windowChanged() = 0; | ||
| 162 | // virtual void flushWindowChanged() = 0; | ||
| 163 | //}; | ||
| 164 | |||
| 165 | class QIPhoneCGContext | ||
| 166 | { | ||
| 167 | CGContextRef context; | ||
| 168 | public: | ||
| 169 | QIPhoneCGContext(QPainter *p); //qpaintengine_mac.cpp | ||
| 170 | inline QIPhoneCGContext() { context = 0; } | ||
| 171 | inline QIPhoneCGContext(const QPaintDevice *pdev) { | ||
| 172 | extern CGContextRef qt_mac_cg_context(const QPaintDevice *); | ||
| 173 | context = qt_mac_cg_context(pdev); | ||
| 174 | } | ||
| 175 | inline QIPhoneCGContext(CGContextRef cg, bool takeOwnership=false) { | ||
| 176 | context = cg; | ||
| 177 | if(!takeOwnership) | ||
| 178 | CGContextRetain(context); | ||
| 179 | } | ||
| 180 | inline QIPhoneCGContext(const QIPhoneCGContext ©) : context(0) { *this = copy; } | ||
| 181 | inline ~QIPhoneCGContext() { | ||
| 182 | if(context) | ||
| 183 | CGContextRelease(context); | ||
| 184 | } | ||
| 185 | inline bool isNull() const { return context; } | ||
| 186 | inline operator CGContextRef() { return context; } | ||
| 187 | inline QIPhoneCGContext &operator=(const QIPhoneCGContext ©) { | ||
| 188 | if(context) | ||
| 189 | CGContextRelease(context); | ||
| 190 | context = copy.context; | ||
| 191 | CGContextRetain(context); | ||
| 192 | return *this; | ||
| 193 | } | ||
| 194 | inline QIPhoneCGContext &operator=(CGContextRef cg) { | ||
| 195 | if(context) | ||
| 196 | CGContextRelease(context); | ||
| 197 | context = cg; | ||
| 198 | CGContextRetain(context); //we do not take ownership | ||
| 199 | return *this; | ||
| 200 | } | ||
| 201 | }; | ||
| 202 | |||
| 203 | class QIPhonePasteboardMime; | ||
| 204 | class QMimeData; | ||
| 205 | |||
| 206 | //class QMacPasteboard | ||
| 207 | //{ | ||
| 208 | // struct Promise { | ||
| 209 | // Promise() : itemId(0), convertor(0) { } | ||
| 210 | // Promise(int itemId, QMacPasteboardMime *c, QString m, QVariant d, int o=0) : itemId(itemId), offset(o), convertor(c), mime(m), data(d) { } | ||
| 211 | // int itemId, offset; | ||
| 212 | // QMacPasteboardMime *convertor; | ||
| 213 | // QString mime; | ||
| 214 | // QVariant data; | ||
| 215 | // }; | ||
| 216 | // QList<Promise> promises; | ||
| 217 | // | ||
| 218 | // OSPasteboardRef paste; | ||
| 219 | // uchar mime_type; | ||
| 220 | // mutable QPointer<QMimeData> mime; | ||
| 221 | // mutable bool mac_mime_source; | ||
| 222 | //#ifndef Q_WS_IPHONE | ||
| 223 | // static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *); | ||
| 224 | //#endif | ||
| 225 | // void clear_helper(); | ||
| 226 | //public: | ||
| 227 | // QMacPasteboard(OSPasteboardRef p, uchar mime_type=0); | ||
| 228 | // QMacPasteboard(uchar mime_type); | ||
| 229 | // QMacPasteboard(CFStringRef name=0, uchar mime_type=0); | ||
| 230 | // ~QMacPasteboard(); | ||
| 231 | // | ||
| 232 | // bool hasFlavor(QString flavor) const; | ||
| 233 | // bool hasOSType(int c_flavor) const; | ||
| 234 | // | ||
| 235 | // OSPasteboardRef pasteBoard() const; | ||
| 236 | // QMimeData *mimeData() const; | ||
| 237 | // void setMimeData(QMimeData *mime); | ||
| 238 | // | ||
| 239 | // QStringList formats() const; | ||
| 240 | // bool hasFormat(const QString &format) const; | ||
| 241 | // QVariant retrieveData(const QString &format, QVariant::Type) const; | ||
| 242 | // | ||
| 243 | // void clear(); | ||
| 244 | // bool sync() const; | ||
| 245 | //}; | ||
| 246 | |||
| 247 | //extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp | ||
| 248 | |||
| 249 | //extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm | ||
| 250 | //extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm | ||
| 251 | //extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm | ||
| 252 | |||
| 253 | //#ifdef check | ||
| 254 | //# undef check | ||
| 255 | //#endif | ||
| 256 | |||
| 257 | //QFont qfontForThemeFont(ThemeFontID themeID); | ||
| 258 | |||
| 259 | //QColor qcolorForTheme(ThemeBrush brush); | ||
| 260 | |||
| 261 | //QColor qcolorForThemeTextColor(ThemeTextColor themeColor); | ||
| 262 | |||
| 263 | //struct QMacDndAnswerRecord { | ||
| 264 | // QRect rect; | ||
| 265 | // Qt::KeyboardModifiers modifiers; | ||
| 266 | // Qt::MouseButtons buttons; | ||
| 267 | // Qt::DropAction lastAction; | ||
| 268 | // unsigned int lastOperation; | ||
| 269 | // void clear() { | ||
| 270 | // rect = QRect(); | ||
| 271 | // modifiers = Qt::NoModifier; | ||
| 272 | // buttons = Qt::NoButton; | ||
| 273 | // lastAction = Qt::IgnoreAction; | ||
| 274 | // lastOperation = 0; | ||
| 275 | // } | ||
| 276 | //}; | ||
| 277 | |||
| 278 | //extern QMacDndAnswerRecord qt_mac_dnd_answer_rec; | ||
| 279 | //void qt_mac_copy_answer_rect(const QDragMoveEvent &event); | ||
| 280 | //bool qt_mac_mouse_inside_answer_rect(QPoint mouse); | ||
| 281 | |||
| 282 | QT_END_NAMESPACE | ||
| 283 | |||
| 284 | #endif // QT_IPHONE_P_H |
src/gui/kernel/qwidget_iphone.mm
(5012 / 0)
|   | |||
| 1 | /**************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | ||
| 4 | ** All rights reserved. | ||
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | ||
| 6 | ** | ||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | ||
| 8 | ** | ||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | ||
| 10 | ** No Commercial Usage | ||
| 11 | ** This file contains pre-release code and may not be distributed. | ||
| 12 | ** You may use this file in accordance with the terms and conditions | ||
| 13 | ** contained in the Technology Preview License Agreement accompanying | ||
| 14 | ** this package. | ||
| 15 | ** | ||
| 16 | ** GNU Lesser General Public License Usage | ||
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
| 18 | ** General Public License version 2.1 as published by the Free Software | ||
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | ||
| 20 | ** packaging of this file. Please review the following information to | ||
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | ||
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
| 23 | ** | ||
| 24 | ** In addition, as a special exception, Nokia gives you certain additional | ||
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception | ||
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
| 27 | ** | ||
| 28 | ** If you have questions regarding the use of this file, please contact | ||
| 29 | ** Nokia at qt-info@nokia.com. | ||
| 30 | ** | ||
| 31 | ** | ||
| 32 | ** | ||
| 33 | ** | ||
| 34 | ** | ||
| 35 | ** | ||
| 36 | ** | ||
| 37 | ** | ||
| 38 | ** $QT_END_LICENSE$ | ||
| 39 | ** | ||
| 40 | ****************************************************************************/ | ||
| 41 | |||
| 42 | /**************************************************************************** | ||
| 43 | ** | ||
| 44 | ** Copyright (c) 2007-2008, Apple, Inc. | ||
| 45 | ** | ||
| 46 | ** All rights reserved. | ||
| 47 | ** | ||
| 48 | ** Redistribution and use in source and binary forms, with or without | ||
| 49 | ** modification, are permitted provided that the following conditions are met: | ||
| 50 | ** | ||
| 51 | ** * Redistributions of source code must retain the above copyright notice, | ||
| 52 | ** this list of conditions and the following disclaimer. | ||
| 53 | ** | ||
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice, | ||
| 55 | ** this list of conditions and the following disclaimer in the documentation | ||
| 56 | ** and/or other materials provided with the distribution. | ||
| 57 | ** | ||
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors | ||
| 59 | ** may be used to endorse or promote products derived from this software | ||
| 60 | ** without specific prior written permission. | ||
| 61 | ** | ||
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 73 | ** | ||
| 74 | ****************************************************************************/ | ||
| 75 | |||
| 76 | #include <private/qt_iphone_p.h> | ||
| 77 | #include <private/qeventdispatcher_iphone_p.h> | ||
| 78 | |||
| 79 | #include "qapplication.h" | ||
| 80 | #include "qapplication_p.h" | ||
| 81 | #include "qbitmap.h" | ||
| 82 | #include "qcursor.h" | ||
| 83 | #include "qdesktopwidget.h" | ||
| 84 | #include "qevent.h" | ||
| 85 | #include "qfileinfo.h" | ||
| 86 | #include "qimage.h" | ||
| 87 | #include "qlayout.h" | ||
| 88 | #include "qmenubar.h" | ||
| 89 | #include <private/qbackingstore_p.h> | ||
| 90 | #include <private/qwindowsurface_iphone_p.h> | ||
| 91 | #include <private/qpaintengine_iphone_p.h> | ||
| 92 | #include "qpainter.h" | ||
| 93 | #include "qstyle.h" | ||
| 94 | #include "qtimer.h" | ||
| 95 | #include "qfocusframe.h" | ||
| 96 | #include "qdebug.h" | ||
| 97 | #include <private/qmainwindowlayout_p.h> | ||
| 98 | |||
| 99 | #warning qwidget_iphone incomplete. | ||
| 100 | #include <UiKit/UiKit.h> | ||
| 101 | |||
| 102 | #include <private/qabstractscrollarea_p.h> | ||
| 103 | #include <qabstractscrollarea.h> | ||
| 104 | #include <limits.h> | ||
| 105 | #include <private/qt_cocoa_helpers_iphone_p.h> | ||
| 106 | #include <private/qcocoaview_iphone_p.h> | ||
| 107 | #include <private/qcocoawindow_iphone_p.h> | ||
| 108 | #include <private/qcocoawindowdelegate_iphone_p.h> | ||
| 109 | #include <private/qcocoapanel_iphone_p.h> | ||
| 110 | |||
| 111 | #include "qwidget_p.h" | ||
| 112 | #include "qevent_p.h" | ||
| 113 | #include "qdnd_p.h" | ||
| 114 | #include <QtGui/qgraphicsproxywidget.h> | ||
| 115 | |||
| 116 | QT_BEGIN_NAMESPACE | ||
| 117 | |||
| 118 | //#define XCOORD_MAX 16383 | ||
| 119 | //#define WRECT_MAX 8191 | ||
| 120 | // | ||
| 121 | //#ifndef QT_MAC_USE_COCOA | ||
| 122 | // | ||
| 123 | //extern "C" { | ||
| 124 | // extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat, | ||
| 125 | // OptionBits) __attribute__ ((weak)); | ||
| 126 | //} | ||
| 127 | //#define kHIViewScrollRectAdjustInvalid 1 | ||
| 128 | //#define kHIViewScrollRectDontInvalidateRevealedArea 2 | ||
| 129 | //#endif | ||
| 130 | |||
| 131 | |||
| 132 | /***************************************************************************** | ||
| 133 | QWidget debug facilities | ||
| 134 | *****************************************************************************/ | ||
| 135 | //#define DEBUG_WINDOW_RGNS | ||
| 136 | //#define DEBUG_WINDOW_CREATE | ||
| 137 | //#define DEBUG_WINDOW_STATE | ||
| 138 | //#define DEBUG_WIDGET_PAINT | ||
| 139 | |||
| 140 | /***************************************************************************** | ||
| 141 | QWidget globals | ||
| 142 | *****************************************************************************/ | ||
| 143 | //#ifndef QT_MAC_USE_COCOA | ||
| 144 | //typedef QHash<Qt::WindowFlags, WindowGroupRef> WindowGroupHash; | ||
| 145 | //Q_GLOBAL_STATIC(WindowGroupHash, qt_mac_window_groups) | ||
| 146 | //const UInt32 kWidgetCreatorQt = kEventClassQt; | ||
| 147 | //enum { | ||
| 148 | // kWidgetPropertyQWidget = 'QWId' //QWidget * | ||
| 149 | //}; | ||
| 150 | //#endif | ||
| 151 | |||
| 152 | //static bool qt_mac_raise_process = true; | ||
| 153 | //static OSWindowRef qt_root_win = 0; | ||
| 154 | //QWidget *mac_mouse_grabber = 0; | ||
| 155 | //QWidget *mac_keyboard_grabber = 0; | ||
| 156 | |||
| 157 | //#ifndef QT_MAC_USE_COCOA | ||
| 158 | //#ifdef QT_NAMESPACE | ||
| 159 | // | ||
| 160 | //// produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE. | ||
| 161 | //#define SS(x) #x | ||
| 162 | //#define S0(x) SS(x) | ||
| 163 | //#define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".widget" | ||
| 164 | // | ||
| 165 | //static CFStringRef kObjectQWidget = CFSTR(S); | ||
| 166 | // | ||
| 167 | //#undef SS | ||
| 168 | //#undef S0 | ||
| 169 | //#undef S | ||
| 170 | // | ||
| 171 | //#else | ||
| 172 | //static CFStringRef kObjectQWidget = CFSTR("com.trolltech.qt.widget"); | ||
| 173 | //#endif // QT_NAMESPACE | ||
| 174 | //#endif // QT_MAC_USE_COCOA | ||
| 175 | |||
| 176 | /***************************************************************************** | ||
| 177 | Externals | ||
| 178 | *****************************************************************************/ | ||
| 179 | //extern QWidget *qt_mac_modal_blocked(QWidget *); //qapplication_mac.mm | ||
| 180 | //extern void qt_event_request_activate(QWidget *); //qapplication_mac.mm | ||
| 181 | //extern bool qt_event_remove_activate(); //qapplication_mac.mm | ||
| 182 | //extern void qt_mac_event_release(QWidget *w); //qapplication_mac.mm | ||
| 183 | //extern void qt_event_request_showsheet(QWidget *); //qapplication_mac.mm | ||
| 184 | //extern void qt_event_request_window_change(QWidget *); //qapplication_mac.mm | ||
| 185 | //extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm | ||
| 186 | //extern IconRef qt_mac_create_iconref(const QPixmap &); //qpixmap_mac.cpp | ||
| 187 | //extern void qt_mac_set_cursor(const QCursor *, const QPoint &); //qcursor_mac.mm | ||
| 188 | //extern void qt_mac_update_cursor(); //qcursor_mac.mm | ||
| 189 | //extern bool qt_nograb(); | ||
| 190 | //extern CGImageRef qt_mac_create_cgimage(const QPixmap &, bool); //qpixmap_mac.cpp | ||
| 191 | //extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp | ||
| 192 | //extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp | ||
| 193 | |||
| 194 | /***************************************************************************** | ||
| 195 | QWidget utility functions | ||
| 196 | *****************************************************************************/ | ||
| 197 | //void Q_GUI_EXPORT qt_mac_set_raise_process(bool b) { qt_mac_raise_process = b; } | ||
| 198 | //static QSize qt_mac_desktopSize() | ||
| 199 | //{ | ||
| 200 | //#warning qt_mac_set_raise_process NOT finished | ||
| 201 | // int w = 0, h = 0; | ||
| 202 | //// CGDisplayCount cg_count; | ||
| 203 | //// CGGetActiveDisplayList(0, 0, &cg_count); | ||
| 204 | //// QVector<CGDirectDisplayID> displays(cg_count); | ||
| 205 | //// CGGetActiveDisplayList(cg_count, displays.data(), &cg_count); | ||
| 206 | //// Q_ASSERT(cg_count == (CGDisplayCount)displays.size()); | ||
| 207 | //// for(int i = 0; i < (int)cg_count; ++i) { | ||
| 208 | //// CGRect r = CGDisplayBounds(displays.at(i)); | ||
| 209 | //// w = qMax<int>(w, qRound(r.origin.x + r.size.width)); | ||
| 210 | //// h = qMax<int>(h, qRound(r.origin.y + r.size.height)); | ||
| 211 | //// } | ||
| 212 | // return QSize(w, h); | ||
| 213 | //} | ||
| 214 | |||
| 215 | //#ifdef QT_MAC_USE_COCOA | ||
| 216 | ////static NSDrawer *qt_mac_drawer_for(const QWidget *widget) | ||
| 217 | ////{ | ||
| 218 | //// // This only goes one level below the content view so start with the window. | ||
| 219 | //// // This works fine for straight Qt stuff, but runs into problems if we are | ||
| 220 | //// // embedding, but if that's the case, they probably want to be using | ||
| 221 | //// // NSDrawer directly. | ||
| 222 | ////#warning qt_mac_drawer_for NOT finished | ||
| 223 | ////// NSView *widgetView = reinterpret_cast<NSView *>(widget->window()->winId()); | ||
| 224 | ////// NSArray *windows = [NSApp windows]; | ||
| 225 | ////// for (NSWindow *window in windows) { | ||
| 226 | ////// NSArray *drawers = [window drawers]; | ||
| 227 | ////// for (NSDrawer *drawer in drawers) { | ||
| 228 | ////// NSArray *views = [[drawer contentView] subviews]; | ||
| 229 | ////// for (NSView *view in views) { | ||
| 230 | ////// if (view == widgetView) | ||
| 231 | ////// return drawer; | ||
| 232 | ////// } | ||
