Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGCocoa.mm
Go to the documentation of this file.
1// @(#)root/graf2d:$Id$
2// Author: Timur Pocheptsov 22/11/2011
3
4/*************************************************************************
5 * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//#define NDEBUG
13
14#include "TGCocoa.h"
15
16#include "ROOTOpenGLView.h"
17#include "CocoaConstants.h"
18#include "TMacOSXSystem.h"
19#include "CocoaPrivate.h"
20#include "QuartzWindow.h"
21#include "QuartzPixmap.h"
22#include "QuartzUtils.h"
23#include "X11Drawable.h"
24#include "QuartzText.h"
25#include "CocoaUtils.h"
26#include "MenuLoader.h"
27#include "TVirtualGL.h"
28#include "X11Events.h"
29#include "X11Buffer.h"
30#include "X11Atoms.h"
31#include "TGClient.h"
32#include "TGWindow.h"
33#include "TSystem.h"
34#include "TGFrame.h"
35#include "TError.h"
36#include "TColor.h"
37#include "TROOT.h"
38#include "TEnv.h"
39#include "TVirtualMutex.h"
40
41#include <ApplicationServices/ApplicationServices.h>
42#include <OpenGL/OpenGL.h>
43#include <OpenGL/gl.h>
44#include <Cocoa/Cocoa.h>
45
46#include <algorithm>
47#include <stdexcept>
48#include <cassert>
49#include <cstring>
50#include <cstddef>
51#include <limits>
52#include <memory>
53
54//Style notes: I'm using a lot of asserts to check pre-conditions - mainly function parameters.
55//In asserts, expression always looks like 'p != 0' for "C++ pointer" (either object of built-in type
56//or C++ class), and 'p != nil' for object from Objective-C. There is no difference, this is to make
57//asserts more explicit. In conditional statement, it'll always be 'if (p)' or 'if (!p)' for both
58//C++ and Objective-C pointers/code.
59
60//I never use const qualifier for pointers to Objective-C objects since they are useless:
61//there are no cv-qualified methods (member-functions in C++) in Objective-C, and I do not use
62//'->' operator to access instance variables (data-members in C++) of Objective-C's object.
63//I also declare pointer as a const, if it's const:
64//NSWindow * const topLevelWindow = ... (and note, not pointer to const - no use with Obj-C).
65
66//Asserts on drawables ids usually only check, that it's not a 'root' window id (unless operation
67//is permitted on a 'root' window):
68//a) assert(!fPimpl->IsRootWindow(windowID)) and later I also check that windowID != 0 (kNone).
69//b) assert(drawableID > fPimpl->GetRootWindowID()) so drawableID can not be kNone and
70// can not be a 'root' window.
71
72//ROOT window has id 1. So if id > 1 (id > fPimpl->GetRootWindowID())
73//id is considered as valid (if it's out of range and > maximum valid id, this will be
74//caught by CocoaPrivate.
75
77namespace Util = ROOT::MacOSX::Util;
78namespace X11 = ROOT::MacOSX::X11;
79namespace Quartz = ROOT::Quartz;
81
82namespace {
83
84#pragma mark - Display configuration management.
85
86//______________________________________________________________________________
87void DisplayReconfigurationCallback(CGDirectDisplayID /*display*/, CGDisplayChangeSummaryFlags flags, void * /*userInfo*/)
88{
89 if (flags & kCGDisplayBeginConfigurationFlag)
90 return;
91
92 if (flags & kCGDisplayDesktopShapeChangedFlag) {
93 assert(dynamic_cast<TGCocoa *>(gVirtualX) != 0 && "DisplayReconfigurationCallback, gVirtualX"
94 " is either null or has a wrong type");
95 TGCocoa * const gCocoa = static_cast<TGCocoa *>(gVirtualX);
96 gCocoa->ReconfigureDisplay();
97 }
98}
99
100#pragma mark - Aux. functions called from GUI-rendering part.
101
102//______________________________________________________________________________
103void SetStrokeForegroundColorFromX11Context(CGContextRef ctx, const GCValues_t &gcVals)
104{
105 assert(ctx != 0 && "SetStrokeForegroundColorFromX11Context, parameter 'ctx' is null");
106
107 CGFloat rgb[3] = {};
108 if (gcVals.fMask & kGCForeground)
109 X11::PixelToRGB(gcVals.fForeground, rgb);
110 else
111 ::Warning("SetStrokeForegroundColorFromX11Context",
112 "x11 context does not have line color information");
113
114 CGContextSetRGBStrokeColor(ctx, rgb[0], rgb[1], rgb[2], 1.);
115}
116
117//______________________________________________________________________________
118void SetStrokeDashFromX11Context(CGContextRef ctx, const GCValues_t &gcVals)
119{
120 //Set line dash pattern (X11's LineOnOffDash line style).
121 assert(ctx != 0 && "SetStrokeDashFromX11Context, ctx parameter is null");
122
123 SetStrokeForegroundColorFromX11Context(ctx, gcVals);
124
125 static const std::size_t maxLength = sizeof gcVals.fDashes / sizeof gcVals.fDashes[0];
126 assert(maxLength >= std::size_t(gcVals.fDashLen) &&
127 "SetStrokeDashFromX11Context, x11 context has bad dash length > sizeof(fDashes)");
128
129 CGFloat dashes[maxLength] = {};
130 for (Int_t i = 0; i < gcVals.fDashLen; ++i)
131 dashes[i] = gcVals.fDashes[i];
132
133 CGContextSetLineDash(ctx, gcVals.fDashOffset, dashes, gcVals.fDashLen);
134}
135
136//______________________________________________________________________________
137void SetStrokeDoubleDashFromX11Context(CGContextRef /*ctx*/, const GCValues_t & /*gcVals*/)
138{
139 //assert(ctx != 0 && "SetStrokeDoubleDashFromX11Context, ctx parameter is null");
140 ::Warning("SetStrokeDoubleDashFromX11Context", "Not implemented yet, kick tpochep!");
141}
142
143//______________________________________________________________________________
144void SetStrokeParametersFromX11Context(CGContextRef ctx, const GCValues_t &gcVals)
145{
146 //Set line width and color from GCValues_t object.
147 //(GUI rendering).
148 assert(ctx != 0 && "SetStrokeParametersFromX11Context, parameter 'ctx' is null");
149
150 const Mask_t mask = gcVals.fMask;
151 if ((mask & kGCLineWidth) && gcVals.fLineWidth > 1)
152 CGContextSetLineWidth(ctx, gcVals.fLineWidth);
153 else
154 CGContextSetLineWidth(ctx, 1.);
155
156 CGContextSetLineDash(ctx, 0., 0, 0);
157
158 if (mask & kGCLineStyle) {
159 if (gcVals.fLineStyle == kLineSolid)
160 SetStrokeForegroundColorFromX11Context(ctx, gcVals);
161 else if (gcVals.fLineStyle == kLineOnOffDash)
162 SetStrokeDashFromX11Context(ctx, gcVals);
163 else if (gcVals.fLineStyle == kLineDoubleDash)
164 SetStrokeDoubleDashFromX11Context(ctx ,gcVals);
165 else {
166 ::Warning("SetStrokeParametersFromX11Context", "line style bit is set,"
167 " but line style is unknown");
168 SetStrokeForegroundColorFromX11Context(ctx, gcVals);
169 }
170 } else
171 SetStrokeForegroundColorFromX11Context(ctx, gcVals);
172}
173
174//______________________________________________________________________________
175void SetFilledAreaColorFromX11Context(CGContextRef ctx, const GCValues_t &gcVals)
176{
177 //Set fill color from "foreground" pixel color.
178 //(GUI rendering).
179 assert(ctx != 0 && "SetFilledAreaColorFromX11Context, parameter 'ctx' is null");
180
181 CGFloat rgb[3] = {};
182 if (gcVals.fMask & kGCForeground)
183 X11::PixelToRGB(gcVals.fForeground, rgb);
184 else
185 ::Warning("SetFilledAreaColorFromX11Context", "no fill color found in x11 context");
186
187 CGContextSetRGBFillColor(ctx, rgb[0], rgb[1], rgb[2], 1.);
188}
189
190struct PatternContext {
191 PatternContext(Mask_t mask = {}, Int_t fillStyle = {}, Int_t foreground = 0, Int_t background = 0,
192 NSObject<X11Drawable> *image = nil, CGSize phase = {})
193 : fMask(mask), fFillStyle(fillStyle), fForeground(foreground), fBackground(background), fPhase(phase)
194 {
195 fImage = [image retain];
196 }
197 ~PatternContext()
198 {
199 [fImage release];
200 }
201
202 PatternContext(const PatternContext &) = delete;
203 PatternContext(PatternContext &&) = delete;
204 PatternContext &operator = (const PatternContext &) = delete;
205 PatternContext &operator = (PatternContext &&) = delete;
206
207 void SetImage(NSObject<X11Drawable> *image)
208 {
209 if (image != fImage) {
210 [fImage release];
211 fImage = [image retain];
212 }
213 }
214
215 Mask_t fMask = {};
216 Int_t fFillStyle = 0;
217 ULong_t fForeground = 0;
218 ULong_t fBackground = 0;
219 NSObject<X11Drawable> *fImage = nil;//Either stipple or tile image.
220 CGSize fPhase = {};
221};
222
223
224//______________________________________________________________________________
225bool HasFillTiledStyle(Mask_t mask, Int_t fillStyle)
226{
227 return (mask & kGCFillStyle) && (fillStyle == kFillTiled);
228}
229
230//______________________________________________________________________________
231bool HasFillTiledStyle(const GCValues_t &gcVals)
232{
233 return HasFillTiledStyle(gcVals.fMask, gcVals.fFillStyle);
234}
235
236//______________________________________________________________________________
237bool HasFillStippledStyle(Mask_t mask, Int_t fillStyle)
238{
239 return (mask & kGCFillStyle) && (fillStyle == kFillStippled);
240}
241
242//______________________________________________________________________________
243bool HasFillStippledStyle(const GCValues_t &gcVals)
244{
245 return HasFillStippledStyle(gcVals.fMask, gcVals.fFillStyle);
246}
247
248//______________________________________________________________________________
249bool HasFillOpaqueStippledStyle(Mask_t mask, Int_t fillStyle)
250{
251 return (mask & kGCFillStyle) && (fillStyle == kFillOpaqueStippled);
252}
253
254//______________________________________________________________________________
255bool HasFillOpaqueStippledStyle(const GCValues_t &gcVals)
256{
257 return HasFillOpaqueStippledStyle(gcVals.fMask, gcVals.fFillStyle);
258}
259
260//______________________________________________________________________________
261void DrawTile(NSObject<X11Drawable> *patternImage, CGContextRef ctx)
262{
263 assert(patternImage != nil && "DrawTile, parameter 'patternImage' is nil");
264 assert(ctx != 0 && "DrawTile, ctx parameter is null");
265
266 const CGRect patternRect = CGRectMake(0, 0, patternImage.fWidth, patternImage.fHeight);
267 if ([patternImage isKindOfClass : [QuartzImage class]]) {
268 CGContextDrawImage(ctx, patternRect, ((QuartzImage *)patternImage).fImage);
269 } else if ([patternImage isKindOfClass : [QuartzPixmap class]]){
270 const Util::CFScopeGuard<CGImageRef> imageFromPixmap([((QuartzPixmap *)patternImage) createImageFromPixmap]);
271 assert(imageFromPixmap.Get() != 0 && "DrawTile, createImageFromPixmap failed");
272 CGContextDrawImage(ctx, patternRect, imageFromPixmap.Get());
273 } else
274 assert(0 && "DrawTile, pattern is neither a QuartzImage, nor a QuartzPixmap");
275}
276
277//______________________________________________________________________________
278void DrawPattern(void *info, CGContextRef ctx)
279{
280 //Pattern callback, either use foreground (and background, if any)
281 //color and stipple mask to draw a pattern, or use pixmap
282 //as a pattern image.
283 //(GUI rendering).
284 assert(info != 0 && "DrawPattern, parameter 'info' is null");
285 assert(ctx != 0 && "DrawPattern, parameter 'ctx' is null");
286
287 const PatternContext * const patternContext = (PatternContext *)info;
288 const Mask_t mask = patternContext->fMask;
289 const Int_t fillStyle = patternContext->fFillStyle;
290
291 NSObject<X11Drawable> * const patternImage = patternContext->fImage;
292 assert(patternImage != nil && "DrawPattern, pattern (stipple) image is nil");
293 const CGRect patternRect = CGRectMake(0, 0, patternImage.fWidth, patternImage.fHeight);
294
295 if (HasFillTiledStyle(mask, fillStyle)) {
296 DrawTile(patternImage, ctx);
297 } else if (HasFillStippledStyle(mask, fillStyle) || HasFillOpaqueStippledStyle(mask, fillStyle)) {
298 assert([patternImage isKindOfClass : [QuartzImage class]] &&
299 "DrawPattern, stipple must be a QuartzImage object");
300 QuartzImage * const image = (QuartzImage *)patternImage;
301 assert(image.fIsStippleMask == YES && "DrawPattern, image is not a stipple mask");
302
303 CGFloat rgb[3] = {};
304
305 if (HasFillOpaqueStippledStyle(mask,fillStyle)) {
306 //Fill background first.
307 assert((mask & kGCBackground) &&
308 "DrawPattern, fill style is FillOpaqueStippled, but background color is not set in a context");
309 X11::PixelToRGB(patternContext->fBackground, rgb);
310 CGContextSetRGBFillColor(ctx, rgb[0], rgb[1], rgb[2], 1.);
311 CGContextFillRect(ctx, patternRect);
312 }
313
314 //Fill rectangle with foreground colour, using stipple mask.
315 assert((mask & kGCForeground) && "DrawPattern, foreground color is not set");
316 X11::PixelToRGB(patternContext->fForeground, rgb);
317 CGContextSetRGBFillColor(ctx, rgb[0], rgb[1], rgb[2], 1.);
318 CGContextClipToMask(ctx, patternRect, image.fImage);
319 CGContextFillRect(ctx, patternRect);
320 } else {
321 //This can be a window background pixmap
322 DrawTile(patternImage, ctx);
323 }
324}
325
326//______________________________________________________________________________
327void PatternRelease(void *info)
328{
329 delete static_cast<PatternContext *>(info);
330}
331
332//______________________________________________________________________________
333void SetFillPattern(CGContextRef ctx, const PatternContext *patternContext)
334{
335 //Create CGPatternRef to fill GUI elements with pattern.
336 //Pattern is a QuartzImage object, it can be either a mask,
337 //or pattern image itself.
338 //(GUI-rendering).
339 assert(ctx != 0 && "SetFillPattern, parameter 'ctx' is null");
340 assert(patternContext != 0 && "SetFillPattern, parameter 'patternContext' is null");
341 assert(patternContext->fImage != nil && "SetFillPattern, pattern image is nil");
342
343 const Util::CFScopeGuard<CGColorSpaceRef> patternColorSpace(CGColorSpaceCreatePattern(0));
344 CGContextSetFillColorSpace(ctx, patternColorSpace.Get());
345
346 CGPatternCallbacks callbacks = {};
347 callbacks.drawPattern = DrawPattern;
348 callbacks.releaseInfo = PatternRelease;
349 const CGRect patternRect = CGRectMake(0, 0, patternContext->fImage.fWidth, patternContext->fImage.fHeight);
350 const Util::CFScopeGuard<CGPatternRef> pattern(CGPatternCreate((void *)patternContext, patternRect, CGAffineTransformIdentity,
351 patternContext->fImage.fWidth, patternContext->fImage.fHeight,
352 kCGPatternTilingNoDistortion, true, &callbacks));
353 const CGFloat alpha = 1.;
354 CGContextSetFillPattern(ctx, pattern.Get(), &alpha);
355 CGContextSetPatternPhase(ctx, patternContext->fPhase);
356}
357
358//______________________________________________________________________________
359bool ParentRendersToChild(NSView<X11Window> *child)
360{
361 assert(child != nil && "ParentRendersToChild, parameter 'child' is nil");
363}
364
365class ViewFixer final {
366public:
367 ViewFixer(QuartzView *&viewToFix, Drawable_t &widToFix)
368 {
369 if (ParentRendersToChild(viewToFix) && [viewToFix.fParentView isKindOfClass:[QuartzView class]]) {
370 const auto origin = viewToFix.frame.origin;
371 viewToFix = viewToFix.fParentView;
372 widToFix = viewToFix.fID;
373 if ((context = viewToFix.fContext)) {
374 CGContextSaveGState(context);
375 CGContextTranslateCTM(context, origin.x, origin.y);
376 }
377 }
378 }
379 ~ViewFixer()
380 {
381 if (context)
382 CGContextRestoreGState(context);
383 }
384 ViewFixer(const ViewFixer &rhs) = delete;
385 ViewFixer &operator = (const ViewFixer &) = delete;
386
387private:
388 CGContextRef context = nullptr;
389};
390
391//______________________________________________________________________________
392bool IsNonPrintableAsciiCharacter(UniChar c)
393{
394 if (c == 9 || (c >= 32 && c < 127))
395 return false;
396
397 return true;
398}
399
400//______________________________________________________________________________
401void FixAscii(std::vector<UniChar> &text)
402{
403 //GUI text is essentially ASCII. Our GUI
404 //calculates text metrix 'per-symbol', this means,
405 //it never asks about 'Text' metrics, but 'T', 'e', 'x', 't'.
406 //Obviously, text does not fit any widget because of
407 //this and I have to place all glyphs manually.
408 //And here I have another problem from our GUI - it
409 //can easily feed TGCocoa with non-printable symbols
410 //(this is a bug). Obviously, I do not have glyphs for, say, form feed
411 //or 'data link escape'. So I have to fix ascii text before
412 //manual glyph rendering: DLE symbol - replaced by space (this
413 //is done in TGText, but due to a bug it fails to replace them all)
414 //Other non-printable symbols simply removed (and thus ignored).
415
416 //Replace remaining ^P symbols with whitespaces, I have not idea why
417 //TGTextView replaces only part of them and not all of them.
418 std::replace(text.begin(), text.end(), UniChar(16), UniChar(' '));
419
420 //Now, remove remaining non-printable characters (no glyphs exist for them).
421 text.erase(std::remove_if(text.begin(), text.end(), IsNonPrintableAsciiCharacter), text.end());
422}
423
424}
425
426
428
429//______________________________________________________________________________
431 : fSelectedDrawable(0),
432 fCocoaDraw(0),
433 fDrawMode(kCopy),
434 fDirectDraw(false),
435 fForegroundProcess(false),
436 fSetApp(true),
437 fDisplayShapeChanged(true)
438{
439 assert(dynamic_cast<TMacOSXSystem *>(gSystem) != nullptr &&
440 "TGCocoa, gSystem is eihter null or has a wrong type");
441 TMacOSXSystem * const system = (TMacOSXSystem *)gSystem;
442
443 if (!system->CocoaInitialized())
444 system->InitializeCocoa();
445
446 fPimpl.reset(new Details::CocoaPrivate);
447
449 fgDeleteWindowAtom = FindAtom("WM_DELETE_WINDOW", true);
450
451 CGDisplayRegisterReconfigurationCallback (DisplayReconfigurationCallback, 0);
452}
453
454//______________________________________________________________________________
455TGCocoa::TGCocoa(const char *name, const char *title)
456 : TVirtualX(name, title),
457 fSelectedDrawable(0),
458 fCocoaDraw(0),
459 fDrawMode(kCopy),
460 fDirectDraw(false),
461 fForegroundProcess(false),
462 fSetApp(true),
463 fDisplayShapeChanged(true)
464{
465 assert(dynamic_cast<TMacOSXSystem *>(gSystem) != nullptr &&
466 "TGCocoa, gSystem is eihter null or has a wrong type");
467 TMacOSXSystem * const system = (TMacOSXSystem *)gSystem;
468
469 if (!system->CocoaInitialized())
470 system->InitializeCocoa();
471
472 fPimpl.reset(new Details::CocoaPrivate);
473
475 fgDeleteWindowAtom = FindAtom("WM_DELETE_WINDOW", true);
476
477 CGDisplayRegisterReconfigurationCallback (DisplayReconfigurationCallback, 0);
478}
479
480//______________________________________________________________________________
482{
483 //
484 CGDisplayRemoveReconfigurationCallback (DisplayReconfigurationCallback, 0);
485}
486
487//General part (empty, since it's not an X server.
488
489//______________________________________________________________________________
490Bool_t TGCocoa::Init(void * /*display*/)
491{
492 //Nothing to initialize here, return true to make
493 //a caller happy.
494 return kTRUE;
495}
496
497
498//______________________________________________________________________________
499Int_t TGCocoa::OpenDisplay(const char * /*dpyName*/)
500{
501 // return <0 in case of "error". The only error we have is: no interactive
502 // session, i.e no windows message handler etc.
503 if (CGMainDisplayID() == kCGNullDirectDisplay)
504 return -1;
505
507
508 return 0;
509}
510
511//______________________________________________________________________________
512const char *TGCocoa::DisplayName(const char *)
513{
514 //Noop.
515 return "dummy";
516}
517
518//______________________________________________________________________________
520{
521 //No, thank you, I'm not supporting any of X11 extensions!
522 return -1;
523}
524
525//______________________________________________________________________________
527{
528 //Noop.
529}
530
531//______________________________________________________________________________
533{
534 //Noop.
535 return 0;
536}
537
538//______________________________________________________________________________
540{
541 //Noop.
542 return 0;
543}
544
545//______________________________________________________________________________
547{
548 //Noop.
549 return 0;
550}
551
552//______________________________________________________________________________
554{
555 //Comment from TVirtualX:
556 // Returns the width of the screen in millimeters.
557 //End of comment.
558
559 return CGDisplayScreenSize(CGMainDisplayID()).width;
560}
561
562//______________________________________________________________________________
564{
565 //Comment from TVirtualX:
566 // Returns depth of screen (number of bit planes).
567 // Equivalent to GetPlanes().
568 //End of comment.
569
570 NSArray * const screens = [NSScreen screens];
571 assert(screens != nil && "screens array is nil");
572
573 NSScreen * const mainScreen = [screens objectAtIndex : 0];
574 assert(mainScreen != nil && "screen with index 0 is nil");
575
576 return NSBitsPerPixelFromDepth([mainScreen depth]);
577}
578
579//______________________________________________________________________________
581{
583
584 if (mode == 2) {
585 // with none-virtualX displays like qt6canv gClient not created at all
586 // while graphics libraries can be loaded by different ways prvent crash when client not present
587 // before not defined gClient was triggering assert here
588 if (gClient)
589 gClient->DoRedraw();//Call DoRedraw for all widgets, who need to be updated.
590 } else if (mode > 0) {
591 //Execute buffered commands.
592 fPimpl->fX11CommandBuffer.Flush(fPimpl.get());
593 }
594
595 if (fDirectDraw && mode != 2) {
596 // here was flushing of XOR operation
597 // now XOR operations collected directly by correspondent view and
598 // updated asynchronousely by calling view.setNeedsDisplay(YES)
599 // so there is no need for central instance
600 }
601}
602
603//______________________________________________________________________________
608
609//______________________________________________________________________________
611{
613 NSArray * const screens = [NSScreen screens];
614 assert(screens != nil && screens.count != 0 && "GetDisplayGeometry, no screens found");
615
616 NSRect frame = [(NSScreen *)[screens objectAtIndex : 0] frame];
617 CGFloat xMin = frame.origin.x, xMax = xMin + frame.size.width;
618 CGFloat yMin = frame.origin.y, yMax = yMin + frame.size.height;
619
620 for (NSUInteger i = 1, e = screens.count; i < e; ++i) {
621 frame = [(NSScreen *)[screens objectAtIndex : i] frame];
622 xMin = std::min(xMin, frame.origin.x);
623 xMax = std::max(xMax, frame.origin.x + frame.size.width);
624 yMin = std::min(yMin, frame.origin.y);
625 yMax = std::max(yMax, frame.origin.y + frame.size.height);
626 }
627
628 fDisplayRect.fX = int(xMin);
629 fDisplayRect.fY = int(yMin);
630 fDisplayRect.fWidth = unsigned(xMax - xMin);
631 fDisplayRect.fHeight = unsigned(yMax - yMin);
632
633 fDisplayShapeChanged = false;
634 }
635
636 return fDisplayRect;
637}
638
639#pragma mark - Window management part.
640
641//______________________________________________________________________________
643{
644 //Index, fixed and used only by 'root' window.
645 return fPimpl->GetRootWindowID();
646}
647
648//______________________________________________________________________________
650{
651 //InitWindow is a bad name, since this function
652 //creates a window, but this name comes from the TVirtualX interface.
653 //Actually, there is no special need in this function,
654 //it's a kind of simplified CreateWindow (with only
655 //one parameter). This function is called by TRootCanvas,
656 //to create a special window inside TGCanvas (thus parentID must be a valid window ID).
657 //TGX11/TGWin32 have internal array of such special windows,
658 //they return index into this array, instead of drawable's ids.
659 //I simply re-use CreateWindow and return a drawable's id.
660
661 assert(parentID != 0 && "InitWindow, parameter 'parentID' is 0");
662
663 //Use parent's attributes (as it's done in TGX11).
665 if (fPimpl->IsRootWindow(parentID))
667 else
668 [fPimpl->GetWindow(parentID) getAttributes : &attr];
669
670 return CreateWindow(parentID, 0, 0, attr.fWidth, attr.fHeight, 0, attr.fDepth, attr.fClass, 0, 0, 0);
671}
672
673//______________________________________________________________________________
675{
676 //In case of TGX11/TGWin32, there is a mixture of
677 //casted X11 ids (Window_t) and indices in some internal array, which
678 //contains such an id. On Mac I always have indices. Yes, I'm smart.
679 return windowID;
680}
681
682//______________________________________________________________________________
684{
685 //This function can be called from pad/canvas, both for window and for pixmap.
686 fSelectedDrawable = windowID;
687}
688
689//______________________________________________________________________________
691{
692 if (wid <= 0)
693 return (WinContext_t) 0;
694 auto drawable = fPimpl->GetDrawable(wid);
695 return (WinContext_t) drawable;
696}
697
698//______________________________________________________________________________
703
704//______________________________________________________________________________
706{
707 auto drawable = (NSObject<X11Drawable> *) wctxt;
708
709 // here XOR window and XOR operations can be removed if necessary
710 [drawable setDrawMode : mode];
711}
712
713//______________________________________________________________________________
715{
716 auto drawable = (NSObject<X11Drawable> *) wctxt;
717
718 return [drawable getDrawMode];
719}
720
721//______________________________________________________________________________
723{
724 auto drawable = (NSObject<X11Drawable> * const) wctxt;
725
726 if (drawable.fIsPixmap) {
727 //Pixmaps are white by default.
728 //This is bad - we can not have transparent sub-pads (in TCanvas)
729 //because of this. But there is no way how gVirtualX can
730 //obtain real pad's color and check for its transparency.
731 CGContextRef pixmapCtx = drawable.fContext;
732 assert(pixmapCtx != 0 && "ClearWindow, pixmap's context is null");
733 //const Quartz::CGStateGuard ctxGuard(pixmapCtx);
734 //CGContextSetRGBFillColor(pixmapCtx, 1., 1., 1., 1.);
735 //CGContextFillRect(pixmapCtx, CGRectMake(0, 0, drawable.fWidth, drawable.fHeight));
736 //Now we really clear!
737 CGContextClearRect(pixmapCtx, CGRectMake(0, 0, drawable.fWidth, drawable.fHeight));
738 } else {
739 //For a window ClearArea with w == 0 and h == 0 means the whole window.
740 ClearArea(drawable.fID, 0, 0, 0, 0);
741 }
742}
743
744//______________________________________________________________________________
746{
747 auto window = (NSObject<X11Window> * const) wctxt;
748
749 //Have no idea, why this can happen with ROOT - done by TGDNDManager :(
750 if (window.fIsPixmap == YES)
751 return;
752
753 if (QuartzPixmap * const pixmap = window.fBackBuffer) {
754 assert([window.fContentView isKindOfClass : [QuartzView class]] && "UpdateWindow, content view is not a QuartzView");
755 QuartzView *dstView = (QuartzView *)window.fContentView;
756
757 if (dstView.fIsOverlapped)
758 return;
759
760 if (dstView.fContext) {
761 //We can draw directly.
762 const X11::Rectangle copyArea(0, 0, pixmap.fWidth, pixmap.fHeight);
763 [dstView copy : pixmap area : copyArea withMask : nil clipOrigin : X11::Point() toPoint : X11::Point()];
764 } else {
765 //Have to wait.
766 fPimpl->fX11CommandBuffer.AddUpdateWindow(dstView);
767 Update(1);
768 }
769 }
770}
771
772
773
774//______________________________________________________________________________
776{
777 //Clear the selected drawable OR pixmap (the name - from TVirtualX interface - is bad).
778 assert(fSelectedDrawable > fPimpl->GetRootWindowID() &&
779 "ClearWindow, fSelectedDrawable is invalid");
780
782}
783
784//______________________________________________________________________________
786{
787 //In TGX11, GetGeometry works with special windows, created by InitWindow
788 //(thus this function is called from TCanvas/TGCanvas/TRootCanvas).
789
790 //IMPORTANT: this function also translates x and y
791 //from parent's coordinates into screen coordinates - so, again, name "GetGeometry"
792 //from the TVirtualX interface is bad and misleading.
793
794 if (windowID < 0 || fPimpl->IsRootWindow(windowID)) {
795 //Comment in TVirtualX suggests, that wid can be < 0.
796 //This will be a screen's geometry.
799 x = attr.fX;
800 y = attr.fY;
801 w = attr.fWidth;
802 h = attr.fHeight;
803 } else {
804 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(windowID);
805 x = drawable.fX;
806 y = drawable.fY;
807 w = drawable.fWidth;
808 h = drawable.fHeight;
809
810 if (!drawable.fIsPixmap) {
811 NSObject<X11Window> * const window = (NSObject<X11Window> *)drawable;
812 NSPoint srcPoint = {};
813 srcPoint.x = x;
814 srcPoint.y = y;
815 NSView<X11Window> * const view = window.fContentView.fParentView ? window.fContentView.fParentView : window.fContentView;
816 //View parameter for TranslateToScreen call must
817 //be parent view, since x and y are in parent's
818 //coordinate system.
819 const NSPoint dstPoint = X11::TranslateToScreen(view, srcPoint);
820 x = dstPoint.x;
821 y = dstPoint.y;
822 }
823 }
824}
825
826//______________________________________________________________________________
828{
829 //windowID is either kNone or a valid window id.
830 //x and y are coordinates of a top-left corner relative to the parent's coordinate system.
831
832 assert(!fPimpl->IsRootWindow(windowID) && "MoveWindow, called for root window");
833
834 if (!windowID)//From TGX11.
835 return;
836
837 [fPimpl->GetWindow(windowID) setX : x Y : y];
838}
839
840//______________________________________________________________________________
841void TGCocoa::RescaleWindow(Int_t /*wid*/, UInt_t /*w*/, UInt_t /*h*/)
842{
843 //This function is for TRootCanvas and related stuff, never gets
844 //called/used from/by any our GUI class.
845 //Noop.
846}
847
848//______________________________________________________________________________
850{
851 //This function does not resize window (it was done already by layout management?),
852 //it resizes "back buffer" if any.
853
854 if (!windowID)//From TGX11.
855 return;
856
857 assert(!fPimpl->IsRootWindow(windowID) &&
858 "ResizeWindow, parameter 'windowID' is a root window's id");
859
860 const Util::AutoreleasePool pool;
861
862 NSObject<X11Window> * const window = fPimpl->GetWindow(windowID);
863 if (window.fBackBuffer) {
864 const Drawable_t currentDrawable = fSelectedDrawable;
865 fSelectedDrawable = windowID;
867 fSelectedDrawable = currentDrawable;
868 }
869}
870
871//______________________________________________________________________________
873{
874 //This function is used by TCanvas/TPad:
875 //draw "back buffer" image into the view.
876 //fContentView (destination) MUST be a QuartzView.
877
878 //Basic es-guarantee: X11Buffer::AddUpdateWindow modifies vector with commands,
879 //if the following call to TGCocoa::Update will produce an exception dusing X11Buffer::Flush,
880 //initial state of X11Buffer can not be restored, but it still must be in some valid state.
881
882 assert(fSelectedDrawable > fPimpl->GetRootWindowID() &&
883 "UpdateWindow, fSelectedDrawable is not a valid window id");
884
885 //Have no idea, why this can happen with ROOT - done by TGDNDManager :(
886 if (fPimpl->GetDrawable(fSelectedDrawable).fIsPixmap == YES)
887 return;
888
890}
891
892//______________________________________________________________________________
894{
895 //Window selected by SelectWindow.
896 return fSelectedDrawable;
897}
898
899//______________________________________________________________________________
901{
902 //Deletes selected window.
903}
904
905//______________________________________________________________________________
907{
908 //Should register a window created by Qt as a ROOT window,
909 //but since Qt-ROOT does not work on Mac and will never work,
910 //especially with version 4.8 - this implementation will always
911 //be empty.
912 return 0;
913}
914
915//______________________________________________________________________________
917{
918 //Remove window, created by Qt.
919}
920
921//______________________________________________________________________________
923 UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype)
924{
925 //Create new window (top-level == QuartzWindow + QuartzView, or child == QuartzView)
926
927 //Strong es-guarantee - exception can be only during registration, class state will remain
928 //unchanged, no leaks (scope guards).
929
930 const Util::AutoreleasePool pool;
931
932 if (fPimpl->IsRootWindow(parentID)) {//parent == root window.
933 //Can throw:
934 QuartzWindow * const newWindow = X11::CreateTopLevelWindow(x, y, w, h, border,
935 depth, clss, visual, attr, wtype);
936 //Something like unique_ptr would perfectly solve the problem with raw pointer + a separate
937 //guard for this pointer, but it requires move semantics.
938 const Util::NSScopeGuard<QuartzWindow> winGuard(newWindow);
939 const Window_t result = fPimpl->RegisterDrawable(newWindow);//Can throw.
940 newWindow.fID = result;
941 [newWindow setAcceptsMouseMovedEvents : YES];
942
943 return result;
944 } else {
945 NSObject<X11Window> * const parentWin = fPimpl->GetWindow(parentID);
946 //OpenGL view can not have children.
947 assert([parentWin.fContentView isKindOfClass : [QuartzView class]] &&
948 "CreateWindow, parent view must be QuartzView");
949
950 //Can throw:
951 QuartzView * const childView = X11::CreateChildView((QuartzView *)parentWin.fContentView,
952 x, y, w, h, border, depth, clss, visual, attr, wtype);
953 const Util::NSScopeGuard<QuartzView> viewGuard(childView);
954 const Window_t result = fPimpl->RegisterDrawable(childView);//Can throw.
955 childView.fID = result;
956 [parentWin addChild : childView];
957
958 return result;
959 }
960}
961
962//______________________________________________________________________________
964{
965 //The XDestroyWindow function destroys the specified window as well as all of its subwindows
966 //and causes the X server to generate a DestroyNotify event for each window. The window
967 //should never be referenced again. If the window specified by the w argument is mapped,
968 //it is unmapped automatically. The ordering of the
969 //DestroyNotify events is such that for any given window being destroyed, DestroyNotify is generated
970 //on any inferiors of the window before being generated on the window itself. The ordering
971 //among siblings and across subhierarchies is not otherwise constrained.
972 //If the window you specified is a root window, no windows are destroyed. Destroying a mapped window
973 //will generate Expose events on other windows that were obscured by the window being destroyed.
974
975 //No-throw guarantee???
976
977 //I have NO idea why ROOT's GUI calls DestroyWindow with illegal
978 //window id, but it does.
979
980 if (!wid)
981 return;
982
983 if (fPimpl->IsRootWindow(wid))
984 return;
985
986 BOOL needFocusChange = NO;
987
988 {//Block to force autoreleasepool to drain.
989 const Util::AutoreleasePool pool;
990
991 fPimpl->fX11EventTranslator.CheckUnmappedView(wid);
992
993 assert(fPimpl->GetDrawable(wid).fIsPixmap == NO &&
994 "DestroyWindow, can not be called for QuartzPixmap or QuartzImage object");
995
996 NSObject<X11Window> * const window = fPimpl->GetWindow(wid);
997 if (fPimpl->fX11CommandBuffer.BufferSize())
998 fPimpl->fX11CommandBuffer.RemoveOperationsForDrawable(wid);
999
1000 //TEST: "fix" a keyboard focus.
1001 if ((needFocusChange = window == window.fQuartzWindow && window.fQuartzWindow.fHasFocus))
1002 window.fHasFocus = NO;//If any.
1003
1005 if (window.fEventMask & kStructureNotifyMask)
1006 fPimpl->fX11EventTranslator.GenerateDestroyNotify(wid);
1007
1008 //Interrupt modal loop (TGClient::WaitFor).
1009 if (gClient->GetWaitForEvent() == kDestroyNotify && wid == gClient->GetWaitForWindow())
1010 gClient->SetWaitForWindow(kNone);
1011
1012 fPimpl->DeleteDrawable(wid);
1013 }
1014
1015 //"Fix" a keyboard focus.
1016 if (needFocusChange)
1018}
1019
1020//______________________________________________________________________________
1022{
1023 // The DestroySubwindows function destroys all inferior windows of the
1024 // specified window, in bottom-to-top stacking order.
1025
1026 //No-throw guarantee??
1027
1028 //From TGX11:
1029 if (!wid)
1030 return;
1031
1032 if (fPimpl->IsRootWindow(wid))
1033 return;
1034
1035 const Util::AutoreleasePool pool;
1036
1037 assert(fPimpl->GetDrawable(wid).fIsPixmap == NO &&
1038 "DestroySubwindows, can not be called for QuartzPixmap or QuartzImage object");
1039
1040 NSObject<X11Window> *window = fPimpl->GetWindow(wid);
1041
1042 //I can not iterate on subviews array directly, since it'll be modified
1043 //during this iteration - create a copy (and it'll also increase references,
1044 //which will be decreased by guard's dtor).
1045 const Util::NSScopeGuard<NSArray> children([[window.fContentView subviews] copy]);
1046
1047 for (NSView<X11Window> *child in children.Get())
1048 DestroyWindow(child.fID);
1049}
1050
1051//______________________________________________________________________________
1053{
1054 //No-throw guarantee.
1055
1056 if (!wid)//X11's None?
1057 return;
1058
1059 if (fPimpl->IsRootWindow(wid))
1061 else
1062 [fPimpl->GetWindow(wid) getAttributes : &attr];
1063}
1064
1065//______________________________________________________________________________
1067{
1068 //No-throw guarantee.
1069
1070 if (!wid)//From TGX11
1071 return;
1072
1073 const Util::AutoreleasePool pool;
1074
1075 assert(!fPimpl->IsRootWindow(wid) && "ChangeWindowAttributes, called for root window");
1076 assert(attr != 0 && "ChangeWindowAttributes, parameter 'attr' is null");
1077
1078 [fPimpl->GetWindow(wid) setAttributes : attr];
1079}
1080
1081//______________________________________________________________________________
1082void TGCocoa::SelectInput(Window_t windowID, UInt_t eventMask)
1083{
1084 //No-throw guarantee.
1085
1086 // Defines which input events the window is interested in. By default
1087 // events are propageted up the window stack. This mask can also be
1088 // set at window creation time via the SetWindowAttributes_t::fEventMask
1089 // attribute.
1090
1091 //TGuiBldDragManager selects input on a 'root' window.
1092 //TGWin32 has a check on windowID == 0.
1093 if (windowID <= fPimpl->GetRootWindowID())
1094 return;
1095
1096 NSObject<X11Window> * const window = fPimpl->GetWindow(windowID);
1097 //XSelectInput overrides a previous mask.
1098 window.fEventMask = eventMask;
1099}
1100
1101//______________________________________________________________________________
1103{
1104 //Reparent view.
1105 using namespace Details;
1106
1107 assert(!fPimpl->IsRootWindow(wid) && "ReparentChild, can not re-parent root window");
1108
1109 const Util::AutoreleasePool pool;
1110
1111 NSView<X11Window> * const view = fPimpl->GetWindow(wid).fContentView;
1112 if (fPimpl->IsRootWindow(pid)) {
1113 //Make a top-level view from a child view.
1114 [view retain];
1115 [view removeFromSuperview];
1116 view.fParentView = nil;
1117
1118 NSRect frame = view.frame;
1119 frame.origin = NSPoint();
1120
1121 NSUInteger styleMask = kClosableWindowMask | kMiniaturizableWindowMask | kResizableWindowMask;
1122 if (!view.fOverrideRedirect)
1123 styleMask |= kTitledWindowMask;
1124
1125 QuartzWindow * const newTopLevel = [[QuartzWindow alloc] initWithContentRect : frame
1126 styleMask : styleMask
1127 backing : NSBackingStoreBuffered
1128 defer : NO];
1129 [view setX : x Y : y];
1130 [newTopLevel addChild : view];
1131
1132 fPimpl->ReplaceDrawable(wid, newTopLevel);
1133
1134 [view release];
1135 [newTopLevel release];
1136 } else {
1137 [view retain];
1138 [view removeFromSuperview];
1139 //
1140 NSObject<X11Window> * const newParent = fPimpl->GetWindow(pid);
1141 assert(newParent.fIsPixmap == NO && "ReparentChild, pixmap can not be a new parent");
1142 [view setX : x Y : y];
1143 [newParent addChild : view];//It'll also update view's level, no need to call updateLevel.
1144 [view release];
1145 }
1146}
1147
1148//______________________________________________________________________________
1150{
1151 //Reparent top-level window.
1152 //I have to delete QuartzWindow here and place in its slot content view +
1153 //reparent this view into pid.
1154 if (fPimpl->IsRootWindow(pid))//Nothing to do, wid is already a top-level window.
1155 return;
1156
1157 const Util::AutoreleasePool pool;
1158
1159 NSView<X11Window> * const contentView = fPimpl->GetWindow(wid).fContentView;
1160 QuartzWindow * const topLevel = (QuartzWindow *)[contentView window];
1161 [contentView retain];
1162 [contentView removeFromSuperview];
1163 [topLevel setContentView : nil];
1164 fPimpl->ReplaceDrawable(wid, contentView);
1165 [contentView setX : x Y : y];
1166 [fPimpl->GetWindow(pid) addChild : contentView];//Will also replace view's level.
1167 [contentView release];
1168}
1169
1170//______________________________________________________________________________
1172{
1173 //Change window's parent (possibly creating new top-level window or destroying top-level window).
1174
1175 if (!wid) //From TGX11.
1176 return;
1177
1178 assert(!fPimpl->IsRootWindow(wid) && "ReparentWindow, can not re-parent root window");
1179
1180 NSView<X11Window> * const view = fPimpl->GetWindow(wid).fContentView;
1181 if (view.fParentView)
1182 ReparentChild(wid, pid, x, y);
1183 else
1184 //wid is a top-level window (or content view of such a window).
1185 ReparentTopLevel(wid, pid, x, y);
1186}
1187
1188//______________________________________________________________________________
1190{
1191 // Maps the window "wid" and all of its subwindows that have had map
1192 // requests. This function has no effect if the window is already mapped.
1193
1194 assert(!fPimpl->IsRootWindow(wid) && "MapWindow, called for root window");
1195
1196 const Util::AutoreleasePool pool;
1197
1199 [fPimpl->GetWindow(wid) mapWindow];
1200
1201 if (fSetApp) {
1204 fSetApp = false;
1205 }
1206}
1207
1208//______________________________________________________________________________
1210{
1211 // Maps all subwindows for the specified window "wid" in top-to-bottom
1212 // stacking order.
1213
1214 assert(!fPimpl->IsRootWindow(wid) && "MapSubwindows, called for 'root' window");
1215
1216 const Util::AutoreleasePool pool;
1217
1219 [fPimpl->GetWindow(wid) mapSubwindows];
1220}
1221
1222//______________________________________________________________________________
1224{
1225 // Maps the window "wid" and all of its subwindows that have had map
1226 // requests on the screen and put this window on the top of of the
1227 // stack of all windows.
1228
1229 assert(!fPimpl->IsRootWindow(wid) && "MapRaised, called for root window");
1230
1231 const Util::AutoreleasePool pool;
1232
1234 [fPimpl->GetWindow(wid) mapRaised];
1235
1236 if (fSetApp) {
1239 fSetApp = false;
1240 }
1241}
1242
1243//______________________________________________________________________________
1245{
1246 // Unmaps the specified window "wid". If the specified window is already
1247 // unmapped, this function has no effect. Any child window will no longer
1248 // be visible (but they are still mapped) until another map call is made
1249 // on the parent.
1250 assert(!fPimpl->IsRootWindow(wid) && "UnmapWindow, called for root window");
1251
1252 const Util::AutoreleasePool pool;
1253
1254 //If this window is a grab window or a parent of a grab window.
1255 fPimpl->fX11EventTranslator.CheckUnmappedView(wid);
1256
1257 NSObject<X11Window> * const win = fPimpl->GetWindow(wid);
1258 [win unmapWindow];
1259
1260 if (win == win.fQuartzWindow && win.fQuartzWindow.fHasFocus)
1262
1263 win.fHasFocus = NO;
1264
1265 //if (window.fEventMask & kStructureNotifyMask)
1266 // fPimpl->fX11EventTranslator.GenerateUnmapNotify(wid);
1267
1268 //Interrupt modal loop (TGClient::WaitForUnmap).
1269 if (gClient->GetWaitForEvent() == kUnmapNotify && gClient->GetWaitForWindow() == wid)
1270 gClient->SetWaitForWindow(kNone);
1271}
1272
1273//______________________________________________________________________________
1275{
1276 // Raises the specified window to the top of the stack so that no
1277 // sibling window obscures it.
1278
1279 if (!wid)//From TGX11.
1280 return;
1281
1282 assert(!fPimpl->IsRootWindow(wid) && "RaiseWindow, called for root window");
1283
1284 if (!fPimpl->GetWindow(wid).fParentView)
1285 return;
1286
1287 [fPimpl->GetWindow(wid) raiseWindow];
1288}
1289
1290//______________________________________________________________________________
1292{
1293 // Lowers the specified window "wid" to the bottom of the stack so
1294 // that it does not obscure any sibling windows.
1295
1296 if (!wid)//From TGX11.
1297 return;
1298
1299 assert(!fPimpl->IsRootWindow(wid) && "LowerWindow, called for root window");
1300
1301 if (!fPimpl->GetWindow(wid).fParentView)
1302 return;
1303
1304 [fPimpl->GetWindow(wid) lowerWindow];
1305}
1306
1307//______________________________________________________________________________
1309{
1310 // Moves the specified window to the specified x and y coordinates.
1311 // It does not change the window's size, raise the window, or change
1312 // the mapping state of the window.
1313 //
1314 // x, y - coordinates, which define the new position of the window
1315 // relative to its parent.
1316
1317 if (!wid)//From TGX11.
1318 return;
1319
1320 assert(!fPimpl->IsRootWindow(wid) && "MoveWindow, called for root window");
1321 const Util::AutoreleasePool pool;
1322 [fPimpl->GetWindow(wid) setX : x Y : y];
1323}
1324
1325//______________________________________________________________________________
1327{
1328 // Changes the size and location of the specified window "wid" without
1329 // raising it.
1330 //
1331 // x, y - coordinates, which define the new position of the window
1332 // relative to its parent.
1333 // w, h - the width and height, which define the interior size of
1334 // the window
1335
1336 if (!wid)//From TGX11.
1337 return;
1338
1339 assert(!fPimpl->IsRootWindow(wid) && "MoveResizeWindow, called for 'root' window");
1340
1341 const Util::AutoreleasePool pool;
1342 [fPimpl->GetWindow(wid) setX : x Y : y width : w height : h];
1343}
1344
1345//______________________________________________________________________________
1347{
1348 if (!wid)//From TGX11.
1349 return;
1350
1351 assert(!fPimpl->IsRootWindow(wid) && "ResizeWindow, called for 'root' window");
1352
1353 const Util::AutoreleasePool pool;
1354
1355 //We can have this unfortunately.
1356 const UInt_t siMax = std::numeric_limits<Int_t>::max();
1357 if (w > siMax || h > siMax)
1358 return;
1359
1360 NSSize newSize = {};
1361 newSize.width = w;
1362 newSize.height = h;
1363
1364 [fPimpl->GetWindow(wid) setDrawableSize : newSize];
1365}
1366
1367//______________________________________________________________________________
1369{
1370 // Iconifies the window "wid".
1371 if (!wid)
1372 return;
1373
1374 assert(!fPimpl->IsRootWindow(wid) && "IconifyWindow, can not iconify the root window");
1375 assert(fPimpl->GetWindow(wid).fIsPixmap == NO && "IconifyWindow, invalid window id");
1376
1377 NSObject<X11Window> * const win = fPimpl->GetWindow(wid);
1378 assert(win.fQuartzWindow == win && "IconifyWindow, can be called only for a top level window");
1379
1380 fPimpl->fX11EventTranslator.CheckUnmappedView(wid);
1381
1382 NSObject<X11Window> * const window = fPimpl->GetWindow(wid);
1383 if (fPimpl->fX11CommandBuffer.BufferSize())
1384 fPimpl->fX11CommandBuffer.RemoveOperationsForDrawable(wid);
1385
1386 if (window.fQuartzWindow.fHasFocus) {
1388 window.fQuartzWindow.fHasFocus = NO;
1389 }
1390
1391 [win.fQuartzWindow miniaturize : win.fQuartzWindow];
1392}
1393
1394//______________________________________________________________________________
1395void TGCocoa::TranslateCoordinates(Window_t srcWin, Window_t dstWin, Int_t srcX, Int_t srcY, Int_t &dstX, Int_t &dstY, Window_t &child)
1396{
1397 // Translates coordinates in one window to the coordinate space of another
1398 // window. It takes the "src_x" and "src_y" coordinates relative to the
1399 // source window's origin and returns these coordinates to "dest_x" and
1400 // "dest_y" relative to the destination window's origin.
1401
1402 // child - returns the child of "dest" if the coordinates
1403 // are contained in a mapped child of the destination
1404 // window; otherwise, child is set to 0
1405 child = 0;
1406 if (!srcWin || !dstWin)//This is from TGX11, looks like this can happen.
1407 return;
1408
1409 const bool srcIsRoot = fPimpl->IsRootWindow(srcWin);
1410 const bool dstIsRoot = fPimpl->IsRootWindow(dstWin);
1411
1412 if (srcIsRoot && dstIsRoot) {
1413 //This can happen with ROOT's GUI. Set dstX/Y equal to srcX/Y.
1414 //From man for XTranslateCoordinates it's not clear, what should be in child.
1415 dstX = srcX;
1416 dstY = srcY;
1417
1418 if (QuartzWindow * const qw = X11::FindWindowInPoint(srcX, srcY))
1419 child = qw.fID;
1420
1421 return;
1422 }
1423
1424 NSPoint srcPoint = {};
1425 srcPoint.x = srcX;
1426 srcPoint.y = srcY;
1427
1428 NSPoint dstPoint = {};
1429
1430
1431 if (dstIsRoot) {
1432 NSView<X11Window> * const srcView = fPimpl->GetWindow(srcWin).fContentView;
1433 dstPoint = X11::TranslateToScreen(srcView, srcPoint);
1434 } else if (srcIsRoot) {
1435 NSView<X11Window> * const dstView = fPimpl->GetWindow(dstWin).fContentView;
1436 dstPoint = X11::TranslateFromScreen(srcPoint, dstView);
1437
1438 if ([dstView superview]) {
1439 //hitTest requires a point in a superview's coordinate system.
1440 //Even contentView of QuartzWindow has a superview (NSThemeFrame),
1441 //so this should always work.
1442 dstPoint = [[dstView superview] convertPoint : dstPoint fromView : dstView];
1443 if (NSView<X11Window> * const view = (NSView<X11Window> *)[dstView hitTest : dstPoint]) {
1444 if (view != dstView && view.fMapState == kIsViewable)
1445 child = view.fID;
1446 }
1447 }
1448 } else {
1449 NSView<X11Window> * const srcView = fPimpl->GetWindow(srcWin).fContentView;
1450 NSView<X11Window> * const dstView = fPimpl->GetWindow(dstWin).fContentView;
1451
1452 dstPoint = X11::TranslateCoordinates(srcView, dstView, srcPoint);
1453 if ([dstView superview]) {
1454 //hitTest requires a point in a view's superview coordinate system.
1455 //Even contentView of QuartzWindow has a superview (NSThemeFrame),
1456 //so this should always work.
1457 const NSPoint pt = [[dstView superview] convertPoint : dstPoint fromView : dstView];
1458 if (NSView<X11Window> * const view = (NSView<X11Window> *)[dstView hitTest : pt]) {
1459 if (view != dstView && view.fMapState == kIsViewable)
1460 child = view.fID;
1461 }
1462 }
1463 }
1464
1465 dstX = dstPoint.x;
1466 dstY = dstPoint.y;
1467}
1468
1469//______________________________________________________________________________
1471{
1472 // Returns the location and the size of window "wid"
1473 //
1474 // x, y - coordinates of the upper-left outer corner relative to the
1475 // parent window's origin
1476 // w, h - the size of the window, not including the border.
1477
1478 //From GX11Gui.cxx:
1479 if (!wid)
1480 return;
1481
1482 if (fPimpl->IsRootWindow(wid)) {
1485 x = attr.fX;
1486 y = attr.fY;
1487 w = attr.fWidth;
1488 h = attr.fHeight;
1489 } else {
1490 NSObject<X11Drawable> *window = fPimpl->GetDrawable(wid);
1491 //ROOT can ask window size for ... non-window drawable.
1492 if (!window.fIsPixmap) {
1493 x = window.fX;
1494 y = window.fY;
1495 } else {
1496 x = 0;
1497 y = 0;
1498 }
1499
1500 w = window.fWidth;
1501 h = window.fHeight;
1502 }
1503}
1504
1505//______________________________________________________________________________
1507{
1508 //From TGX11:
1509 if (!wid)
1510 return;
1511
1512 assert(!fPimpl->IsRootWindow(wid) && "SetWindowBackground, can not set color for root window");
1513
1514 fPimpl->GetWindow(wid).fBackgroundPixel = color;
1515}
1516
1517//______________________________________________________________________________
1519{
1520 // Sets the background pixmap of the window "wid" to the specified
1521 // pixmap "pxm".
1522
1523 //From TGX11/TGWin32:
1524 if (!windowID)
1525 return;
1526
1527 assert(!fPimpl->IsRootWindow(windowID) &&
1528 "SetWindowBackgroundPixmap, can not set background for a root window");
1529 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
1530 "SetWindowBackgroundPixmap, invalid window id");
1531
1532 NSObject<X11Window> * const window = fPimpl->GetWindow(windowID);
1533 if (pixmapID == kNone) {
1534 window.fBackgroundPixmap = nil;
1535 return;
1536 }
1537
1538 assert(pixmapID > fPimpl->GetRootWindowID() &&
1539 "SetWindowBackgroundPixmap, parameter 'pixmapID' is not a valid pixmap id");
1540 assert(fPimpl->GetDrawable(pixmapID).fIsPixmap == YES &&
1541 "SetWindowBackgroundPixmap, bad drawable");
1542
1543 NSObject<X11Drawable> * const pixmapOrImage = fPimpl->GetDrawable(pixmapID);
1544 //X11 doc says, that pixmap can be freed immediately after call
1545 //XSetWindowBackgroundPixmap, so I have to copy a pixmap.
1546 Util::NSScopeGuard<QuartzImage> backgroundImage;
1547
1548 if ([pixmapOrImage isKindOfClass : [QuartzPixmap class]]) {
1549 backgroundImage.Reset([[QuartzImage alloc] initFromPixmap : (QuartzPixmap *)pixmapOrImage]);
1550 if (backgroundImage.Get())
1551 window.fBackgroundPixmap = backgroundImage.Get();//the window is retaining the image.
1552 } else {
1553 backgroundImage.Reset([[QuartzImage alloc] initFromImage : (QuartzImage *)pixmapOrImage]);
1554 if (backgroundImage.Get())
1555 window.fBackgroundPixmap = backgroundImage.Get();//the window is retaining the image.
1556 }
1557
1558 if (!backgroundImage.Get())
1559 //Detailed error message was issued by QuartzImage at this point.
1560 Error("SetWindowBackgroundPixmap", "QuartzImage initialization failed");
1561}
1562
1563//______________________________________________________________________________
1565{
1566 // Returns the parent of the window "windowID".
1567
1568 //0 or root (checked in TGX11):
1569 if (windowID <= fPimpl->GetRootWindowID())
1570 return windowID;
1571
1572 NSView<X11Window> *view = fPimpl->GetWindow(windowID).fContentView;
1573 return view.fParentView ? view.fParentView.fID : fPimpl->GetRootWindowID();
1574}
1575
1576//______________________________________________________________________________
1578{
1579 if (!wid || !name)//From TGX11.
1580 return;
1581
1582 const Util::AutoreleasePool pool;
1583
1584 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1585
1586 if ([(NSObject *)drawable isKindOfClass : [NSWindow class]]) {
1587 NSString * const windowTitle = [NSString stringWithCString : name encoding : NSASCIIStringEncoding];
1588 [(NSWindow *)drawable setTitle : windowTitle];
1589 }
1590}
1591
1592//______________________________________________________________________________
1593void TGCocoa::SetIconName(Window_t /*wid*/, char * /*name*/)
1594{
1595 //Noop.
1596}
1597
1598//______________________________________________________________________________
1600{
1601 //Noop.
1602}
1603
1604//______________________________________________________________________________
1605void TGCocoa::SetClassHints(Window_t /*wid*/, char * /*className*/, char * /*resourceName*/)
1606{
1607 //Noop.
1608}
1609
1610//______________________________________________________________________________
1611void TGCocoa::ShapeCombineMask(Window_t windowID, Int_t /*x*/, Int_t /*y*/, Pixmap_t pixmapID)
1612{
1613 //Comment from TVirtualX:
1614 // The Nonrectangular Window Shape Extension adds nonrectangular
1615 // windows to the System.
1616 // This allows for making shaped (partially transparent) windows
1617
1618 assert(!fPimpl->IsRootWindow(windowID) &&
1619 "ShapeCombineMask, windowID parameter is a 'root' window");
1620 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
1621 "ShapeCombineMask, windowID parameter is a bad window id");
1622 assert([fPimpl->GetDrawable(pixmapID) isKindOfClass : [QuartzImage class]] &&
1623 "ShapeCombineMask, pixmapID parameter must point to QuartzImage object");
1624
1625 if (fPimpl->GetWindow(windowID).fContentView.fParentView)
1626 return;
1627
1628 QuartzImage * const srcImage = (QuartzImage *)fPimpl->GetDrawable(pixmapID);
1629 assert(srcImage.fIsStippleMask == YES && "ShapeCombineMask, source image is not a stipple mask");
1630
1631 // There is some kind of problems with shape masks and
1632 // flipped views, I have to do an image flip here.
1633 const Util::NSScopeGuard<QuartzImage> image([[QuartzImage alloc] initFromImageFlipped : srcImage]);
1634 if (image.Get()) {
1635 QuartzWindow * const qw = fPimpl->GetWindow(windowID).fQuartzWindow;
1636 qw.fShapeCombineMask = image.Get();
1637 [qw setOpaque : NO];
1638 [qw setBackgroundColor : [NSColor clearColor]];
1639 }
1640}
1641
1642#pragma mark - "Window manager hints" set of functions.
1643
1644//______________________________________________________________________________
1646{
1647 // Sets decoration style.
1648 using namespace Details;
1649
1650 assert(!fPimpl->IsRootWindow(wid) && "SetMWMHints, called for 'root' window");
1651
1652 QuartzWindow * const qw = fPimpl->GetWindow(wid).fQuartzWindow;
1653 NSUInteger newMask = 0;
1654
1655 if ([qw styleMask] & kTitledWindowMask) {//Do not modify this.
1656 newMask |= kTitledWindowMask;
1657 newMask |= kClosableWindowMask;
1658 }
1659
1660 if (value & kMWMFuncAll) {
1661 newMask |= kMiniaturizableWindowMask | kResizableWindowMask;
1662 } else {
1664 newMask |= kMiniaturizableWindowMask;
1665 if (funcs & kMWMFuncResize)
1666 newMask |= kResizableWindowMask;
1667 }
1668
1669 [qw setStyleMask : newMask];
1670
1671 if (funcs & kMWMDecorAll) {
1672 if (!qw.fMainWindow) {//Do not touch buttons for transient window.
1673 [[qw standardWindowButton : NSWindowZoomButton] setEnabled : YES];
1674 [[qw standardWindowButton : NSWindowMiniaturizeButton] setEnabled : YES];
1675 }
1676 } else {
1677 if (!qw.fMainWindow) {//Do not touch transient window's titlebar.
1678 [[qw standardWindowButton : NSWindowZoomButton] setEnabled : funcs & kMWMDecorMaximize];
1679 [[qw standardWindowButton : NSWindowMiniaturizeButton] setEnabled : funcs & kMWMDecorMinimize];
1680 }
1681 }
1682}
1683
1684//______________________________________________________________________________
1685void TGCocoa::SetWMPosition(Window_t /*wid*/, Int_t /*x*/, Int_t /*y*/)
1686{
1687 //Noop.
1688}
1689
1690//______________________________________________________________________________
1691void TGCocoa::SetWMSize(Window_t /*wid*/, UInt_t /*w*/, UInt_t /*h*/)
1692{
1693 //Noop.
1694}
1695
1696//______________________________________________________________________________
1697void TGCocoa::SetWMSizeHints(Window_t wid, UInt_t wMin, UInt_t hMin, UInt_t wMax, UInt_t hMax, UInt_t /*wInc*/, UInt_t /*hInc*/)
1698{
1699 using namespace Details;
1700
1701 assert(!fPimpl->IsRootWindow(wid) && "SetWMSizeHints, called for root window");
1702
1703 const NSUInteger styleMask = kTitledWindowMask | kClosableWindowMask | kMiniaturizableWindowMask | kResizableWindowMask;
1704 const NSRect minRect = [NSWindow frameRectForContentRect : NSMakeRect(0., 0., wMin, hMin) styleMask : styleMask];
1705 const NSRect maxRect = [NSWindow frameRectForContentRect : NSMakeRect(0., 0., wMax, hMax) styleMask : styleMask];
1706
1707 QuartzWindow * const qw = fPimpl->GetWindow(wid).fQuartzWindow;
1708 [qw setMinSize : minRect.size];
1709 [qw setMaxSize : maxRect.size];
1710}
1711
1712//______________________________________________________________________________
1714{
1715 //Noop.
1716}
1717
1718//______________________________________________________________________________
1720{
1721 //Comment from TVirtualX:
1722 // Tells window manager that the window "wid" is a transient window
1723 // of the window "main_id". A window manager may decide not to decorate
1724 // a transient window or may treat it differently in other ways.
1725 //End of TVirtualX's comment.
1726
1727 //TGTransientFrame uses this hint to attach a window to some "main" window,
1728 //so that transient window is alway above the main window. This is used for
1729 //dialogs and dockable panels.
1730 assert(wid > fPimpl->GetRootWindowID() && "SetWMTransientHint, wid parameter is not a valid window id");
1731
1732 if (fPimpl->IsRootWindow(mainWid))
1733 return;
1734
1735 QuartzWindow * const mainWindow = fPimpl->GetWindow(mainWid).fQuartzWindow;
1736
1737 if (![mainWindow isVisible])
1738 return;
1739
1740 QuartzWindow * const transientWindow = fPimpl->GetWindow(wid).fQuartzWindow;
1741
1742 if (mainWindow != transientWindow) {
1743 if (transientWindow.fMainWindow) {
1744 if (transientWindow.fMainWindow != mainWindow)
1745 Error("SetWMTransientHint", "window is already transient for other window");
1746 } else {
1747 [[transientWindow standardWindowButton : NSWindowZoomButton] setEnabled : NO];
1748 [mainWindow addTransientWindow : transientWindow];
1749 }
1750 } else
1751 Warning("SetWMTransientHint", "transient and main windows are the same window");
1752}
1753
1754#pragma mark - GUI-rendering part.
1755
1756//______________________________________________________________________________
1758{
1759 //Can be called directly of when flushing command buffer.
1760 assert(!fPimpl->IsRootWindow(wid) && "DrawLineAux, called for root window");
1761
1762 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1763 CGContextRef ctx = drawable.fContext;
1764 assert(ctx != 0 && "DrawLineAux, context is null");
1765
1766 const Quartz::CGStateGuard ctxGuard(ctx);//Will restore state back.
1767 //Draw a line.
1768 //This draw line is a special GUI method, it's used not by ROOT's graphics, but
1769 //widgets. The problem is:
1770 //-I have to switch off anti-aliasing, since if anti-aliasing is on,
1771 //the line is thick and has different color.
1772 //-As soon as I switch-off anti-aliasing, and line is precise, I can not
1773 //draw a line [0, 0, -> w, 0].
1774 //I use a small translation, after all, this is ONLY gui method and it
1775 //will not affect anything except GUI.
1776
1777 CGContextSetAllowsAntialiasing(ctx, false);//Smoothed line is of wrong color and in a wrong position - this is bad for GUI.
1778
1779 if (!drawable.fIsPixmap)
1780 CGContextTranslateCTM(ctx, 0.5, 0.5);
1781 else {
1782 //Pixmap uses native Cocoa's left-low-corner system.
1783 y1 = Int_t(X11::LocalYROOTToCocoa(drawable, y1));
1784 y2 = Int_t(X11::LocalYROOTToCocoa(drawable, y2));
1785 }
1786
1787 SetStrokeParametersFromX11Context(ctx, gcVals);
1788 CGContextBeginPath(ctx);
1789 CGContextMoveToPoint(ctx, x1, y1);
1790 CGContextAddLineToPoint(ctx, x2, y2);
1791 CGContextStrokePath(ctx);
1792
1793 CGContextSetAllowsAntialiasing(ctx, true);//Somehow, it's not saved/restored, this affects ... window's titlebar.
1794}
1795
1796//______________________________________________________________________________
1798{
1799 //This function can be called:
1800 //a)'normal' way - from view's drawRect method.
1801 //b) for 'direct rendering' - operation was initiated by ROOT's GUI, not by
1802 // drawRect.
1803
1804 //From TGX11:
1805 if (!wid)
1806 return;
1807
1808 assert(!fPimpl->IsRootWindow(wid) && "DrawLine, called for root window");
1809 assert(gc > 0 && gc <= fX11Contexts.size() && "DrawLine, invalid context index");
1810
1811 const GCValues_t &gcVals = fX11Contexts[gc - 1];
1812
1813 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1814 if (!drawable.fIsPixmap) {
1815 NSObject<X11Window> * const window = (NSObject<X11Window> *)drawable;
1816 QuartzView *view = (QuartzView *)window.fContentView;
1817 const ViewFixer fixer(view, wid);
1818 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
1819 if (!view.fContext)
1820 fPimpl->fX11CommandBuffer.AddDrawLine(wid, gcVals, x1, y1, x2, y2);
1821 else
1822 DrawLineAux(wid, gcVals, x1, y1, x2, y2);
1823 }
1824 } else {
1825 if (!IsCocoaDraw()) {
1826 fPimpl->fX11CommandBuffer.AddDrawLine(wid, gcVals, x1, y1, x2, y2);
1827 } else {
1828 DrawLineAux(wid, gcVals, x1, y1, x2, y2);
1829 }
1830 }
1831}
1832
1833//______________________________________________________________________________
1834void TGCocoa::DrawSegmentsAux(Drawable_t wid, const GCValues_t &gcVals, const Segment_t *segments, Int_t nSegments)
1835{
1836 assert(!fPimpl->IsRootWindow(wid) && "DrawSegmentsAux, called for root window");
1837 assert(segments != 0 && "DrawSegmentsAux, segments parameter is null");
1838 assert(nSegments > 0 && "DrawSegmentsAux, nSegments <= 0");
1839
1840 for (Int_t i = 0; i < nSegments; ++i)
1841 DrawLineAux(wid, gcVals, segments[i].fX1, segments[i].fY1 - 3, segments[i].fX2, segments[i].fY2 - 3);
1842}
1843
1844//______________________________________________________________________________
1846{
1847 //Draw multiple line segments. Each line is specified by a pair of points.
1848
1849 //From TGX11:
1850 if (!wid)
1851 return;
1852
1853 assert(!fPimpl->IsRootWindow(wid) && "DrawSegments, called for root window");
1854 assert(gc > 0 && gc <= fX11Contexts.size() && "DrawSegments, invalid context index");
1855 assert(segments != 0 && "DrawSegments, parameter 'segments' is null");
1856 assert(nSegments > 0 && "DrawSegments, number of segments <= 0");
1857
1858 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1859 const GCValues_t &gcVals = fX11Contexts[gc - 1];
1860
1861 if (!drawable.fIsPixmap) {
1862 QuartzView *view = (QuartzView *)fPimpl->GetWindow(wid).fContentView;
1863 const ViewFixer fixer(view, wid);
1864
1865 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
1866 if (!view.fContext)
1867 fPimpl->fX11CommandBuffer.AddDrawSegments(wid, gcVals, segments, nSegments);
1868 else
1869 DrawSegmentsAux(wid, gcVals, segments, nSegments);
1870 }
1871 } else {
1872 if (!IsCocoaDraw())
1873 fPimpl->fX11CommandBuffer.AddDrawSegments(wid, gcVals, segments, nSegments);
1874 else
1875 DrawSegmentsAux(wid, gcVals, segments, nSegments);
1876 }
1877}
1878
1879//______________________________________________________________________________
1881{
1882 //Can be called directly or during flushing command buffer.
1883 assert(!fPimpl->IsRootWindow(wid) && "DrawRectangleAux, called for root window");
1884
1885 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1886
1887 if (!drawable.fIsPixmap) {
1888 //I can not draw a line at y == 0, shift the rectangle to 1 pixel (and reduce its height).
1889 if (!y) {
1890 y = 1;
1891 if (h)
1892 h -= 1;
1893 }
1894 } else {
1895 //Pixmap has native Cocoa's low-left-corner system.
1896 y = Int_t(X11::LocalYROOTToCocoa(drawable, y + h));
1897 }
1898
1899 CGContextRef ctx = fPimpl->GetDrawable(wid).fContext;
1900 assert(ctx && "DrawRectangleAux, context is null");
1901 const Quartz::CGStateGuard ctxGuard(ctx);//Will restore context state.
1902
1903 CGContextSetAllowsAntialiasing(ctx, false);
1904 //Line color from X11 context.
1905 SetStrokeParametersFromX11Context(ctx, gcVals);
1906
1907 const CGRect rect = CGRectMake(x, y, w, h);
1908 CGContextStrokeRect(ctx, rect);
1909
1910 CGContextSetAllowsAntialiasing(ctx, true);
1911}
1912
1913//______________________________________________________________________________
1915{
1916 //Can be called in a 'normal way' - from drawRect method (QuartzView)
1917 //or directly by ROOT.
1918
1919 if (!wid)//From TGX11.
1920 return;
1921
1922 assert(!fPimpl->IsRootWindow(wid) && "DrawRectangle, called for root window");
1923 assert(gc > 0 && gc <= fX11Contexts.size() && "DrawRectangle, invalid context index");
1924
1925 const GCValues_t &gcVals = fX11Contexts[gc - 1];
1926
1927 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1928
1929 if (!drawable.fIsPixmap) {
1930 NSObject<X11Window> * const window = (NSObject<X11Window> *)drawable;
1931 QuartzView *view = (QuartzView *)window.fContentView;
1932 const ViewFixer fixer(view, wid);
1933
1934 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
1935 if (!view.fContext)
1936 fPimpl->fX11CommandBuffer.AddDrawRectangle(wid, gcVals, x, y, w, h);
1937 else
1938 DrawRectangleAux(wid, gcVals, x, y, w, h);
1939 }
1940 } else {
1941 if (!IsCocoaDraw())
1942 fPimpl->fX11CommandBuffer.AddDrawRectangle(wid, gcVals, x, y, w, h);
1943 else
1944 DrawRectangleAux(wid, gcVals, x, y, w, h);
1945 }
1946}
1947
1948//______________________________________________________________________________
1950{
1951 //Can be called directly or when flushing command buffer.
1952 //Can be called directly or when flushing command buffer.
1953
1954 //From TGX11:
1955 if (!wid)
1956 return;
1957
1958 assert(!fPimpl->IsRootWindow(wid) && "FillRectangleAux, called for root window");
1959
1960 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
1961 CGContextRef ctx = drawable.fContext;
1962 CGSize patternPhase = {};
1963
1964 if (drawable.fIsPixmap) {
1965 //Pixmap has low-left-corner based system.
1966 y = Int_t(X11::LocalYROOTToCocoa(drawable, y + h));
1967 }
1968
1969 const CGRect fillRect = CGRectMake(x, y, w, h);
1970
1971 if (!drawable.fIsPixmap) {
1972 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(wid).fContentView;
1973 if (view.fParentView) {
1974 const NSPoint origin = [view.fParentView convertPoint : view.frame.origin toView : nil];
1975 patternPhase.width = origin.x;
1976 patternPhase.height = origin.y;
1977 }
1978 }
1979
1980 const Quartz::CGStateGuard ctxGuard(ctx);//Will restore context state.
1981
1982 if (HasFillStippledStyle(gcVals) || HasFillOpaqueStippledStyle(gcVals) || HasFillTiledStyle(gcVals)) {
1983 std::unique_ptr<PatternContext> patternContext(new PatternContext(gcVals.fMask, gcVals.fFillStyle,
1984 0, 0, nil, patternPhase));
1985 if (HasFillStippledStyle(gcVals) || HasFillOpaqueStippledStyle(gcVals)) {
1986 assert(gcVals.fStipple != kNone &&
1987 "FillRectangleAux, fill_style is FillStippled/FillOpaqueStippled,"
1988 " but no stipple is set in a context");
1989
1990 patternContext->fForeground = gcVals.fForeground;
1991 patternContext->SetImage(fPimpl->GetDrawable(gcVals.fStipple));
1992
1993 if (HasFillOpaqueStippledStyle(gcVals))
1994 patternContext->fBackground = gcVals.fBackground;
1995 } else {
1996 assert(gcVals.fTile != kNone &&
1997 "FillRectangleAux, fill_style is FillTiled, but not tile is set in a context");
1998
1999 patternContext->SetImage(fPimpl->GetDrawable(gcVals.fTile));
2000 }
2001
2002 SetFillPattern(ctx, patternContext.get());
2003 patternContext.release();
2004 CGContextFillRect(ctx, fillRect);
2005
2006 return;
2007 }
2008
2009 SetFilledAreaColorFromX11Context(ctx, gcVals);
2010 CGContextFillRect(ctx, fillRect);
2011}
2012
2013//______________________________________________________________________________
2015{
2016 //Can be called in a 'normal way' - from drawRect method (QuartzView)
2017 //or directly by ROOT.
2018
2019 //From TGX11:
2020 if (!wid)
2021 return;
2022
2023 assert(!fPimpl->IsRootWindow(wid) && "FillRectangle, called for root window");
2024 assert(gc > 0 && gc <= fX11Contexts.size() && "FillRectangle, invalid context index");
2025
2026 const GCValues_t &gcVals = fX11Contexts[gc - 1];
2027 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2028
2029 if (!drawable.fIsPixmap) {
2030 NSObject<X11Window> * const window = (NSObject<X11Window> *)drawable;
2031 QuartzView *view = (QuartzView *)window.fContentView;
2032 const ViewFixer fixer(view, wid);
2033 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
2034 if (!view.fContext)
2035 fPimpl->fX11CommandBuffer.AddFillRectangle(wid, gcVals, x, y, w, h);
2036 else
2037 FillRectangleAux(wid, gcVals, x, y, w, h);
2038 }
2039 } else
2040 FillRectangleAux(wid, gcVals, x, y, w, h);
2041}
2042
2043//______________________________________________________________________________
2044void TGCocoa::FillPolygonAux(Window_t wid, const GCValues_t &gcVals, const Point_t *polygon, Int_t nPoints)
2045{
2046 //Can be called directly or when flushing command buffer.
2047
2048 //From TGX11:
2049 if (!wid)
2050 return;
2051
2052 assert(!fPimpl->IsRootWindow(wid) && "FillPolygonAux, called for root window");
2053 assert(polygon != 0 && "FillPolygonAux, parameter 'polygon' is null");
2054 assert(nPoints > 0 && "FillPolygonAux, number of points must be positive");
2055
2056 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2057 CGContextRef ctx = drawable.fContext;
2058
2059 CGSize patternPhase = {};
2060
2061 if (!drawable.fIsPixmap) {
2062 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(wid).fContentView;
2063 const NSPoint origin = [view convertPoint : view.frame.origin toView : nil];
2064 patternPhase.width = origin.x;
2065 patternPhase.height = origin.y;
2066 }
2067
2068 const Quartz::CGStateGuard ctxGuard(ctx);//Will restore context state.
2069
2070 CGContextSetAllowsAntialiasing(ctx, false);
2071
2072 if (HasFillStippledStyle(gcVals) || HasFillOpaqueStippledStyle(gcVals) || HasFillTiledStyle(gcVals)) {
2073 std::unique_ptr<PatternContext> patternContext(new PatternContext(gcVals.fMask, gcVals.fFillStyle, 0, 0, nil, patternPhase));
2074
2075 if (HasFillStippledStyle(gcVals) || HasFillOpaqueStippledStyle(gcVals)) {
2076 assert(gcVals.fStipple != kNone &&
2077 "FillRectangleAux, fill style is FillStippled/FillOpaqueStippled,"
2078 " but no stipple is set in a context");
2079
2080 patternContext->fForeground = gcVals.fForeground;
2081 patternContext->SetImage(fPimpl->GetDrawable(gcVals.fStipple));
2082
2083 if (HasFillOpaqueStippledStyle(gcVals))
2084 patternContext->fBackground = gcVals.fBackground;
2085 } else {
2086 assert(gcVals.fTile != kNone &&
2087 "FillRectangleAux, fill_style is FillTiled, but not tile is set in a context");
2088
2089 patternContext->SetImage(fPimpl->GetDrawable(gcVals.fTile));
2090 }
2091
2092 SetFillPattern(ctx, patternContext.get());
2093 patternContext.release();
2094 } else
2095 SetFilledAreaColorFromX11Context(ctx, gcVals);
2096
2097 //This +2 -2 shit is the result of ROOT's GUI producing strange coordinates out of ....
2098 // - first noticed on checkmarks in a menu - they were all shifted.
2099
2100 CGContextBeginPath(ctx);
2101 if (!drawable.fIsPixmap) {
2102 CGContextMoveToPoint(ctx, polygon[0].fX, polygon[0].fY - 2);
2103 for (Int_t i = 1; i < nPoints; ++i)
2104 CGContextAddLineToPoint(ctx, polygon[i].fX, polygon[i].fY - 2);
2105 } else {
2106 CGContextMoveToPoint(ctx, polygon[0].fX, X11::LocalYROOTToCocoa(drawable, polygon[0].fY + 2));
2107 for (Int_t i = 1; i < nPoints; ++i)
2108 CGContextAddLineToPoint(ctx, polygon[i].fX, X11::LocalYROOTToCocoa(drawable, polygon[i].fY + 2));
2109 }
2110
2111 CGContextFillPath(ctx);
2112 CGContextSetAllowsAntialiasing(ctx, true);
2113}
2114
2115//______________________________________________________________________________
2117{
2118 // Fills the region closed by the specified path. The path is closed
2119 // automatically if the last point in the list does not coincide with the
2120 // first point.
2121 //
2122 // Point_t *points - specifies an array of points
2123 // Int_t npnt - specifies the number of points in the array
2124 //
2125 // GC components in use: function, plane-mask, fill-style, fill-rule,
2126 // subwindow-mode, clip-x-origin, clip-y-origin, and clip-mask. GC
2127 // mode-dependent components: foreground, background, tile, stipple,
2128 // tile-stipple-x-origin, and tile-stipple-y-origin.
2129 // (see also the GCValues_t structure)
2130
2131 //From TGX11:
2132 if (!wid)
2133 return;
2134
2135 assert(polygon != 0 && "FillPolygon, parameter 'polygon' is null");
2136 assert(nPoints > 0 && "FillPolygon, number of points must be positive");
2137 assert(gc > 0 && gc <= fX11Contexts.size() && "FillPolygon, invalid context index");
2138
2139 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2140 const GCValues_t &gcVals = fX11Contexts[gc - 1];
2141
2142 if (!drawable.fIsPixmap) {
2143 QuartzView *view = (QuartzView *)fPimpl->GetWindow(wid).fContentView;
2144 const ViewFixer fixer(view, wid);
2145
2146 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
2147 if (!view.fContext)
2148 fPimpl->fX11CommandBuffer.AddFillPolygon(wid, gcVals, polygon, nPoints);
2149 else
2150 FillPolygonAux(wid, gcVals, polygon, nPoints);
2151 }
2152 } else {
2153 if (!IsCocoaDraw())
2154 fPimpl->fX11CommandBuffer.AddFillPolygon(wid, gcVals, polygon, nPoints);
2155 else
2156 FillPolygonAux(wid, gcVals, polygon, nPoints);
2157 }
2158}
2159
2160//______________________________________________________________________________
2162 UInt_t width, UInt_t height, Int_t dstX, Int_t dstY)
2163{
2164 //Called directly or when flushing command buffer.
2165 if (!src || !dst)//Can this happen? From TGX11.
2166 return;
2167
2168 assert(!fPimpl->IsRootWindow(src) && "CopyAreaAux, src parameter is root window");
2169 assert(!fPimpl->IsRootWindow(dst) && "CopyAreaAux, dst parameter is root window");
2170
2171 //Some copy operations create autoreleased cocoa objects,
2172 //I do not want them to wait till run loop's iteration end to die.
2173 const Util::AutoreleasePool pool;
2174
2175 NSObject<X11Drawable> * const srcDrawable = fPimpl->GetDrawable(src);
2176 NSObject<X11Drawable> * const dstDrawable = fPimpl->GetDrawable(dst);
2177
2178 const X11::Point dstPoint(dstX, dstY);
2179 const X11::Rectangle copyArea(srcX, srcY, width, height);
2180
2181 QuartzImage *mask = nil;
2182 if ((gcVals.fMask & kGCClipMask) && gcVals.fClipMask) {
2183 assert(fPimpl->GetDrawable(gcVals.fClipMask).fIsPixmap == YES &&
2184 "CopyArea, mask is not a pixmap");
2185 mask = (QuartzImage *)fPimpl->GetDrawable(gcVals.fClipMask);
2186 }
2187
2188 X11::Point clipOrigin;
2189 if (gcVals.fMask & kGCClipXOrigin)
2190 clipOrigin.fX = gcVals.fClipXOrigin;
2191 if (gcVals.fMask & kGCClipYOrigin)
2192 clipOrigin.fY = gcVals.fClipYOrigin;
2193
2194 [dstDrawable copy : srcDrawable area : copyArea withMask : mask clipOrigin : clipOrigin toPoint : dstPoint];
2195}
2196
2197//______________________________________________________________________________
2199 UInt_t width, UInt_t height, Int_t dstX, Int_t dstY)
2200{
2201 if (!src || !dst)//Can this happen? From TGX11.
2202 return;
2203
2204 assert(!fPimpl->IsRootWindow(src) && "CopyArea, src parameter is root window");
2205 assert(!fPimpl->IsRootWindow(dst) && "CopyArea, dst parameter is root window");
2206 assert(gc > 0 && gc <= fX11Contexts.size() && "CopyArea, invalid context index");
2207
2208 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(dst);
2209 const GCValues_t &gcVals = fX11Contexts[gc - 1];
2210
2211 if (!drawable.fIsPixmap) {
2212 QuartzView *view = (QuartzView *)fPimpl->GetWindow(dst).fContentView;
2213 const ViewFixer fixer(view, dst);
2214
2215 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
2216 if (!view.fContext)
2217 fPimpl->fX11CommandBuffer.AddCopyArea(src, dst, gcVals, srcX, srcY, width, height, dstX, dstY);
2218 else
2219 CopyAreaAux(src, dst, gcVals, srcX, srcY, width, height, dstX, dstY);
2220 }
2221 } else {
2222 if (fPimpl->GetDrawable(src).fIsPixmap) {
2223 //Both are pixmaps, nothing is buffered for src (???).
2224 CopyAreaAux(src, dst, gcVals, srcX, srcY, width, height, dstX, dstY);
2225 } else {
2226 if (!IsCocoaDraw())
2227 fPimpl->fX11CommandBuffer.AddCopyArea(src, dst, gcVals, srcX, srcY, width, height, dstX, dstY);
2228 else
2229 CopyAreaAux(src, dst, gcVals, srcX, srcY, width, height, dstX, dstY);
2230 }
2231 }
2232}
2233
2234//______________________________________________________________________________
2236{
2237 //Can be called by ROOT directly, or indirectly by AppKit.
2238 assert(!fPimpl->IsRootWindow(wid) && "DrawStringAux, called for root window");
2239
2240 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2241 CGContextRef ctx = drawable.fContext;
2242 assert(ctx != 0 && "DrawStringAux, context is null");
2243
2244 const Quartz::CGStateGuard ctxGuard(ctx);//Will reset parameters back.
2245
2246 CGContextSetTextMatrix(ctx, CGAffineTransformIdentity);
2247
2248 //View is flipped, I have to transform for text to work.
2249 if (!drawable.fIsPixmap) {
2250 CGContextTranslateCTM(ctx, 0., drawable.fHeight);
2251 CGContextScaleCTM(ctx, 1., -1.);
2252 }
2253
2254 //Text must be antialiased
2255 CGContextSetAllowsAntialiasing(ctx, true);
2256
2257 assert(gcVals.fMask & kGCFont && "DrawString, font is not set in a context");
2258
2259 if (len < 0)//Negative length can come from caller.
2260 len = std::strlen(text);
2261 //Text can be not black, for example, highlighted label.
2262 CGFloat textColor[4] = {0., 0., 0., 1.};//black by default.
2263 //I do not check the results here, it's ok to have a black text.
2264 if (gcVals.fMask & kGCForeground)
2265 X11::PixelToRGB(gcVals.fForeground, textColor);
2266
2267 CGContextSetRGBFillColor(ctx, textColor[0], textColor[1], textColor[2], textColor[3]);
2268
2269 //Do a simple text layout using CGGlyphs.
2270 //GUI uses non-ascii symbols, and does not care about signed/unsigned - just dump everything
2271 //into a char and be happy. I'm not.
2272 std::vector<UniChar> unichars((unsigned char *)text, (unsigned char *)text + len);
2273 FixAscii(unichars);
2274
2275 Quartz::DrawTextLineNoKerning(ctx, (CTFontRef)gcVals.fFont, unichars, x, X11::LocalYROOTToCocoa(drawable, y));
2276}
2277
2278//______________________________________________________________________________
2280{
2281 //Can be called by ROOT directly, or indirectly by AppKit.
2282 if (!wid)//from TGX11.
2283 return;
2284
2285 assert(!fPimpl->IsRootWindow(wid) && "DrawString, called for root window");
2286 assert(gc > 0 && gc <= fX11Contexts.size() && "DrawString, invalid context index");
2287
2288 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2289 const GCValues_t &gcVals = fX11Contexts[gc - 1];
2290 assert(gcVals.fMask & kGCFont && "DrawString, font is not set in a context");
2291
2292 if (!drawable.fIsPixmap) {
2293 QuartzView *view = (QuartzView *)fPimpl->GetWindow(wid).fContentView;
2294 const ViewFixer fixer(view, wid);
2295
2296 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
2297 if (!view.fContext)
2298 fPimpl->fX11CommandBuffer.AddDrawString(wid, gcVals, x, y, text, len);
2299 else
2300 DrawStringAux(wid, gcVals, x, y, text, len);
2301 }
2302
2303 } else {
2304 if (!IsCocoaDraw())
2305 fPimpl->fX11CommandBuffer.AddDrawString(wid, gcVals, x, y, text, len);
2306 else
2307 DrawStringAux(wid, gcVals, x, y, text, len);
2308 }
2309}
2310
2311//______________________________________________________________________________
2313{
2314 assert(!fPimpl->IsRootWindow(windowID) && "ClearAreaAux, called for root window");
2315
2316 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(windowID).fContentView;
2317 assert(view.fContext != 0 && "ClearAreaAux, view.fContext is null");
2318
2319 //w and h can be 0 (comment from TGX11) - clear the entire window.
2320 if (!w)
2321 w = view.fWidth;
2322 if (!h)
2323 h = view.fHeight;
2324
2325 if (!view.fBackgroundPixmap) {
2326 //Simple solid fill.
2327 CGFloat rgb[3] = {};
2329
2330 const Quartz::CGStateGuard ctxGuard(view.fContext);
2331 CGContextSetRGBFillColor(view.fContext, rgb[0], rgb[1], rgb[2], 1.);//alpha can be also used.
2332 CGContextFillRect(view.fContext, CGRectMake(x, y, w, h));
2333 } else {
2334 const CGRect fillRect = CGRectMake(x, y, w, h);
2335
2336 CGSize patternPhase = {};
2337 if (view.fParentView) {
2338 const NSPoint origin = [view.fParentView convertPoint : view.frame.origin toView : nil];
2339 patternPhase.width = origin.x;
2340 patternPhase.height = origin.y;
2341 }
2342 const Quartz::CGStateGuard ctxGuard(view.fContext);//Will restore context state.
2343
2344 std::unique_ptr<PatternContext> patternContext(new PatternContext({}, 0, 0, 0, view.fBackgroundPixmap, patternPhase));
2345 SetFillPattern(view.fContext, patternContext.get());
2346 patternContext.release();
2347 CGContextFillRect(view.fContext, fillRect);
2348 }
2349}
2350
2351//______________________________________________________________________________
2353{
2354 //Can be called from drawRect method and also by ROOT's GUI directly.
2355 //Should not be called for pixmap?
2356
2357 //From TGX11:
2358 if (!wid)
2359 return;
2360
2361 assert(!fPimpl->IsRootWindow(wid) && "ClearArea, called for root window");
2362
2363 //If wid is pixmap or image, this will crush.
2364 QuartzView *view = (QuartzView *)fPimpl->GetWindow(wid).fContentView;
2365 if (ParentRendersToChild(view))
2366 return;
2367
2368 if (!view.fIsOverlapped && view.fMapState == kIsViewable) {
2369 if (!view.fContext)
2370 fPimpl->fX11CommandBuffer.AddClearArea(wid, x, y, w, h);
2371 else
2372 ClearAreaAux(wid, x, y, w, h);
2373 }
2374}
2375
2376//______________________________________________________________________________
2378{
2379 //Clears the entire area in the specified window (comment from TGX11).
2380
2381 //From TGX11:
2382 if (!wid)
2383 return;
2384
2385 ClearArea(wid, 0, 0, 0, 0);
2386}
2387
2388#pragma mark - Pixmap management.
2389
2390//______________________________________________________________________________
2392{
2393 //Two stage creation.
2394 NSSize newSize = {};
2395 newSize.width = w;
2396 newSize.height = h;
2397
2398 Util::NSScopeGuard<QuartzPixmap> pixmap([[QuartzPixmap alloc] initWithW : w H : h
2399 scaleFactor : [[NSScreen mainScreen] backingScaleFactor]]);
2400 if (pixmap.Get()) {
2401 pixmap.Get().fID = fPimpl->RegisterDrawable(pixmap.Get());//Can throw.
2402 return (Int_t)pixmap.Get().fID;
2403 } else {
2404 //Detailed error message was issued by QuartzPixmap by this point:
2405 Error("OpenPixmap", "QuartzPixmap initialization failed");
2406 return -1;
2407 }
2408}
2409
2410//______________________________________________________________________________
2412{
2413 assert(!fPimpl->IsRootWindow(wid) && "ResizePixmap, called for root window");
2414
2415 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2416 assert(drawable.fIsPixmap == YES && "ResizePixmap, invalid drawable");
2417
2418 QuartzPixmap *pixmap = (QuartzPixmap *)drawable;
2419 if (w == pixmap.fWidth && h == pixmap.fHeight)
2420 return 1;
2421
2422 if ([pixmap resizeW : w H : h scaleFactor : [[NSScreen mainScreen] backingScaleFactor]])
2423 return 1;
2424
2425 return -1;
2426}
2427
2428//______________________________________________________________________________
2430{
2431 assert(pixmapID > (Int_t)fPimpl->GetRootWindowID() &&
2432 "SelectPixmap, parameter 'pixmapID' is not a valid id");
2433
2434 fSelectedDrawable = pixmapID;
2435}
2436
2437//______________________________________________________________________________
2439{
2440 assert(fSelectedDrawable > fPimpl->GetRootWindowID() &&
2441 "CopyPixmap, fSelectedDrawable is not a valid window id");
2442
2443 CopyPixmapW((WinContext_t) fPimpl->GetDrawable(fSelectedDrawable), pixmapID, x, y);
2444}
2445
2446//______________________________________________________________________________
2448{
2449 assert(pixmapID > (Int_t)fPimpl->GetRootWindowID() &&
2450 "CopyPixmapW, parameter 'pixmapID' is not a valid id");
2451
2452 NSObject<X11Drawable> * const source = fPimpl->GetDrawable(pixmapID);
2453 assert([source isKindOfClass : [QuartzPixmap class]] &&
2454 "CopyPixmap, source is not a pixmap");
2455 QuartzPixmap * const pixmap = (QuartzPixmap *)source;
2456
2457 auto drawable = (NSObject<X11Drawable> * const) wctxt;
2458 NSObject<X11Drawable> * destination = nil;
2459
2460 if (drawable.fIsPixmap) {
2461 destination = drawable;
2462 } else {
2463 NSObject<X11Window> * const window = (NSObject<X11Window> * const) drawable;
2464 if (window.fBackBuffer) {
2465 destination = window.fBackBuffer;
2466 } else {
2467 Warning("CopyPixmapW", "Operation skipped, since destination"
2468 " window is not double buffered");
2469 return;
2470 }
2471 }
2472
2473 const X11::Rectangle copyArea(0, 0, pixmap.fWidth, pixmap.fHeight);
2474 const X11::Point dstPoint(x, y);
2475
2476 [destination copy : pixmap area : copyArea withMask : nil clipOrigin : X11::Point() toPoint : dstPoint];
2477}
2478
2479//______________________________________________________________________________
2481{
2482 // Deletes current pixmap.
2483 assert(fSelectedDrawable > fPimpl->GetRootWindowID() && "ClosePixmap, no drawable selected");
2484 assert(fPimpl->GetDrawable(fSelectedDrawable).fIsPixmap == YES && "ClosePixmap, selected drawable is not a pixmap");
2485
2488}
2489
2490#pragma mark - Different functions to create pixmap from different data sources. Used by GUI.
2491#pragma mark - These functions implement TVirtualX interface, some of them dupilcate others.
2492
2493//______________________________________________________________________________
2495{
2496 //
2497 return OpenPixmap(w, h);
2498}
2499
2500//______________________________________________________________________________
2502 ULong_t foregroundPixel, ULong_t backgroundPixel, Int_t depth)
2503{
2504 //Create QuartzImage, using bitmap and foregroundPixel/backgroundPixel,
2505 //if depth is one - create an image mask instead.
2506
2507 assert(bitmap != 0 && "CreatePixmap, parameter 'bitmap' is null");
2508 assert(width > 0 && "CreatePixmap, parameter 'width' is 0");
2509 assert(height > 0 && "CreatePixmap, parameter 'height' is 0");
2510
2511 std::vector<unsigned char> imageData (depth > 1 ? width * height * 4 : width * height);
2512
2513 X11::FillPixmapBuffer((unsigned char*)bitmap, width, height, foregroundPixel,
2514 backgroundPixel, depth, &imageData[0]);
2515
2516 //Now we can create CGImageRef.
2518
2519 if (depth > 1)
2520 image.Reset([[QuartzImage alloc] initWithW : width H : height data: &imageData[0]]);
2521 else
2522 image.Reset([[QuartzImage alloc] initMaskWithW : width H : height bitmapMask : &imageData[0]]);
2523
2524 if (!image.Get()) {
2525 Error("CreatePixmap", "QuartzImage initialization failed");//More concrete message was issued by QuartzImage.
2526 return kNone;
2527 }
2528
2529 image.Get().fID = fPimpl->RegisterDrawable(image.Get());//This can throw.
2530 return image.Get().fID;
2531}
2532
2533//______________________________________________________________________________
2535{
2536 //Create QuartzImage, using "bits" (data in bgra format).
2537 assert(bits != 0 && "CreatePixmapFromData, data parameter is null");
2538 assert(width != 0 && "CreatePixmapFromData, width parameter is 0");
2539 assert(height != 0 && "CreatePixmapFromData, height parameter is 0");
2540
2541 //I'm not using vector here, since I have to pass this pointer to Obj-C code
2542 //(and Obj-C object will own this memory later).
2543 std::vector<unsigned char> imageData(bits, bits + width * height * 4);
2544
2545 //Convert bgra to rgba.
2546 unsigned char *p = &imageData[0];
2547 for (unsigned i = 0, e = width * height; i < e; ++i, p += 4)
2548 std::swap(p[0], p[2]);
2549
2550 //Now we can create CGImageRef.
2551 Util::NSScopeGuard<QuartzImage> image([[QuartzImage alloc] initWithW : width
2552 H : height data : &imageData[0]]);
2553
2554 if (!image.Get()) {
2555 //Detailed error message was issued by QuartzImage.
2556 Error("CreatePixmapFromData", "QuartzImage initialziation failed");
2557 return kNone;
2558 }
2559
2560 image.Get().fID = fPimpl->RegisterDrawable(image.Get());//This can throw.
2561 return image.Get().fID;
2562}
2563
2564//______________________________________________________________________________
2566{
2567 //Create QuartzImage with image mask.
2568 assert(std::numeric_limits<unsigned char>::digits == 8 && "CreateBitmap, ASImage requires octets");
2569
2570 //I'm not using vector here, since I have to pass this pointer to Obj-C code
2571 //(and Obj-C object will own this memory later).
2572
2573 //TASImage has a bug, it calculates size in pixels (making a with to multiple-of eight and
2574 //allocates memory as each bit occupies one byte, and later packs bits into bytes.
2575
2576 std::vector<unsigned char> imageData(width * height);
2577
2578 //TASImage assumes 8-bit bytes and packs mask bits.
2579 for (unsigned i = 0, j = 0, e = width / 8 * height; i < e; ++i) {
2580 for(unsigned bit = 0; bit < 8; ++bit, ++j) {
2581 if (bitmap[i] & (1 << bit))
2582 imageData[j] = 0;//Opaque.
2583 else
2584 imageData[j] = 255;//Masked out bit.
2585 }
2586 }
2587
2588 //Now we can create CGImageRef.
2589 Util::NSScopeGuard<QuartzImage> image([[QuartzImage alloc] initMaskWithW : width
2590 H : height bitmapMask : &imageData[0]]);
2591 if (!image.Get()) {
2592 //Detailed error message was issued by QuartzImage.
2593 Error("CreateBitmap", "QuartzImage initialization failed");
2594 return kNone;
2595 }
2596
2597 image.Get().fID = fPimpl->RegisterDrawable(image.Get());//This can throw.
2598 return image.Get().fID;
2599}
2600
2601//______________________________________________________________________________
2603{
2604 fPimpl->DeleteDrawable(pixmapID);
2605}
2606
2607//______________________________________________________________________________
2609{
2610 // Explicitely deletes the pixmap resource "pmap".
2611 assert(fPimpl->GetDrawable(pixmapID).fIsPixmap == YES && "DeletePixmap, object is not a pixmap");
2612 fPimpl->fX11CommandBuffer.AddDeletePixmap(pixmapID);
2613}
2614
2615//______________________________________________________________________________
2617{
2618 // Registers a pixmap created by TGLManager as a ROOT pixmap
2619 //
2620 // w, h - the width and height, which define the pixmap size
2621 return 0;
2622}
2623
2624//______________________________________________________________________________
2626{
2627 //Can be also in a window management part, since window is also drawable.
2628 if (fPimpl->IsRootWindow(wid)) {
2629 Warning("GetColorBits", "Called for root window");
2630 } else {
2631 assert(x >= 0 && "GetColorBits, parameter 'x' is negative");
2632 assert(y >= 0 && "GetColorBits, parameter 'y' is negative");
2633 assert(w != 0 && "GetColorBits, parameter 'w' is 0");
2634 assert(h != 0 && "GetColorBits, parameter 'h' is 0");
2635
2636 const X11::Rectangle area(x, y, w, h);
2637 return [fPimpl->GetDrawable(wid) readColorBits : area];//readColorBits can throw std::bad_alloc, no resource will leak.
2638 }
2639
2640 return 0;
2641}
2642
2643#pragma mark - XImage emulation.
2644
2645//______________________________________________________________________________
2647{
2648 // Allocates the memory needed for a drawable.
2649 //
2650 // width - the width of the image, in pixels
2651 // height - the height of the image, in pixels
2652 return OpenPixmap(width, height);
2653}
2654
2655//______________________________________________________________________________
2657{
2658 // Returns the width and height of the image wid
2659 assert(wid > fPimpl->GetRootWindowID() && "GetImageSize, parameter 'wid' is invalid");
2660
2661 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(wid);
2662 width = drawable.fWidth;
2663 height = drawable.fHeight;
2664}
2665
2666//______________________________________________________________________________
2668{
2669 // Overwrites the pixel in the image with the specified pixel value.
2670 // The image must contain the x and y coordinates.
2671 //
2672 // imageID - specifies the image
2673 // x, y - coordinates
2674 // pixel - the new pixel value
2675
2676 assert([fPimpl->GetDrawable(imageID) isKindOfClass : [QuartzPixmap class]] &&
2677 "PutPixel, parameter 'imageID' is a bad pixmap id");
2678 assert(x >= 0 && "PutPixel, parameter 'x' is negative");
2679 assert(y >= 0 && "PutPixel, parameter 'y' is negative");
2680
2681 QuartzPixmap * const pixmap = (QuartzPixmap *)fPimpl->GetDrawable(imageID);
2682
2683 unsigned char rgb[3] = {};
2684 X11::PixelToRGB(pixel, rgb);
2685 [pixmap putPixel : rgb X : x Y : y];
2686}
2687
2688//______________________________________________________________________________
2689void TGCocoa::PutImage(Drawable_t drawableID, GContext_t gc, Drawable_t imageID, Int_t dstX, Int_t dstY,
2690 Int_t srcX, Int_t srcY, UInt_t width, UInt_t height)
2691{
2692 //TGX11 uses ZPixmap in CreateImage ... so background/foreground
2693 //in gc can NEVER be used (and the depth is ALWAYS > 1).
2694 //This means .... I can call CopyArea!
2695
2696 CopyArea(imageID, drawableID, gc, srcX, srcY, width, height, dstX, dstY);
2697}
2698
2699//______________________________________________________________________________
2701{
2702 // Deallocates the memory associated with the image img
2703 assert([fPimpl->GetDrawable(imageID) isKindOfClass : [QuartzPixmap class]] &&
2704 "DeleteImage, imageID parameter is not a valid image id");
2705 DeletePixmap(imageID);
2706}
2707
2708#pragma mark - Mouse related code.
2709
2710//______________________________________________________________________________
2712 Window_t /*confine*/, Cursor_t /*cursor*/, Bool_t grab)
2713{
2714 //Emulate "passive grab" feature of X11 (similar to "implicit grab" in Cocoa
2715 //and implicit grab on X11, the difference is that "implicit grab" works as
2716 //if owner_events parameter for XGrabButton was False, but in ROOT
2717 //owner_events for XGrabButton is _always_ True.
2718 //Confine will never be used - no such feature on MacOSX and
2719 //I'm not going to emulate it..
2720 //This function also does ungrab.
2721
2722 //From TGWin32:
2723 if (!wid)
2724 return;
2725
2726 assert(!fPimpl->IsRootWindow(wid) && "GrabButton, called for 'root' window");
2727
2728 NSObject<X11Window> * const widget = fPimpl->GetWindow(wid);
2729
2730 if (grab) {
2731 widget.fPassiveGrabOwnerEvents = YES; //This is how TGX11 works.
2732 widget.fPassiveGrabButton = button;
2733 widget.fPassiveGrabEventMask = eventMask;
2734 widget.fPassiveGrabKeyModifiers = keyModifiers;
2735 //Set the cursor.
2736 } else {
2737 widget.fPassiveGrabOwnerEvents = NO;
2738 widget.fPassiveGrabButton = -1;//0 is kAnyButton.
2739 widget.fPassiveGrabEventMask = 0;
2740 widget.fPassiveGrabKeyModifiers = 0;
2741 }
2742}
2743
2744//______________________________________________________________________________
2745void TGCocoa::GrabPointer(Window_t wid, UInt_t eventMask, Window_t /*confine*/, Cursor_t /*cursor*/, Bool_t grab, Bool_t ownerEvents)
2746{
2747 //Emulate pointer grab from X11.
2748 //Confine will never be used - no such feature on MacOSX and
2749 //I'm not going to emulate it..
2750 //This function also does ungrab.
2751
2752 if (grab) {
2753 NSView<X11Window> * const view = fPimpl->GetWindow(wid).fContentView;
2754 assert(!fPimpl->IsRootWindow(wid) && "GrabPointer, called for 'root' window");
2755 //set the cursor.
2756 //set active grab.
2757 fPimpl->fX11EventTranslator.SetPointerGrab(view, eventMask, ownerEvents);
2758 } else {
2759 //unset cursor?
2760 //cancel grab.
2761 fPimpl->fX11EventTranslator.CancelPointerGrab();
2762 }
2763}
2764
2765//______________________________________________________________________________
2767{
2768 // Changes the specified dynamic parameters if the pointer is actively
2769 // grabbed by the client and if the specified time is no earlier than the
2770 // last-pointer-grab time and no later than the current X server time.
2771 //Noop.
2772}
2773
2774//______________________________________________________________________________
2776{
2777 // Turns key auto repeat on (kTRUE) or off (kFALSE).
2778 //Noop.
2779}
2780
2781//______________________________________________________________________________
2782void TGCocoa::GrabKey(Window_t wid, Int_t keyCode, UInt_t rootKeyModifiers, Bool_t grab)
2783{
2784 //Comment from TVirtualX:
2785 // Establishes a passive grab on the keyboard. In the future, the
2786 // keyboard is actively grabbed, the last-keyboard-grab time is set
2787 // to the time at which the key was pressed (as transmitted in the
2788 // KeyPress event), and the KeyPress event is reported if all of the
2789 // following conditions are true:
2790 // - the keyboard is not grabbed and the specified key (which can
2791 // itself be a modifier key) is logically pressed when the
2792 // specified modifier keys are logically down, and no other
2793 // modifier keys are logically down;
2794 // - either the grab window "id" is an ancestor of (or is) the focus
2795 // window, or "id" is a descendant of the focus window and contains
2796 // the pointer;
2797 // - a passive grab on the same key combination does not exist on any
2798 // ancestor of grab_window
2799 //
2800 // id - window id
2801 // keycode - specifies the KeyCode or AnyKey
2802 // modifier - specifies the set of keymasks or AnyModifier; the mask is
2803 // the bitwise inclusive OR of the valid keymask bits
2804 // grab - a switch between grab/ungrab key
2805 // grab = kTRUE grab the key and modifier
2806 // grab = kFALSE ungrab the key and modifier
2807 //End of comment.
2808
2809
2810 //Key code already must be Cocoa's key code, this is done by GUI classes,
2811 //they call KeySymToKeyCode.
2812 assert(!fPimpl->IsRootWindow(wid) && "GrabKey, called for root window");
2813
2814 NSView<X11Window> * const view = fPimpl->GetWindow(wid).fContentView;
2815 const NSUInteger cocoaKeyModifiers = X11::GetCocoaKeyModifiersFromROOTKeyModifiers(rootKeyModifiers);
2816
2817 if (grab)
2818 [view addPassiveKeyGrab : keyCode modifiers : cocoaKeyModifiers];
2819 else
2820 [view removePassiveKeyGrab : keyCode modifiers : cocoaKeyModifiers];
2821}
2822
2823//______________________________________________________________________________
2825{
2826 // Converts the "keysym" to the appropriate keycode. For example,
2827 // keysym is a letter and keycode is the matching keyboard key (which
2828 // is dependend on the current keyboard mapping). If the specified
2829 // "keysym" is not defined for any keycode, returns zero.
2830
2831 return X11::MapKeySymToKeyCode(keySym);
2832}
2833
2834//______________________________________________________________________________
2836{
2837 // Returns the window id of the window having the input focus.
2838
2839 return fPimpl->fX11EventTranslator.GetInputFocus();
2840}
2841
2842//______________________________________________________________________________
2844{
2845 // Changes the input focus to specified window "wid".
2846 assert(!fPimpl->IsRootWindow(wid) && "SetInputFocus, called for root window");
2847
2848 if (wid == kNone)
2849 fPimpl->fX11EventTranslator.SetInputFocus(nil);
2850 else
2851 fPimpl->fX11EventTranslator.SetInputFocus(fPimpl->GetWindow(wid).fContentView);
2852}
2853
2854//______________________________________________________________________________
2856{
2857 // Converts the keycode from the event structure to a key symbol (according
2858 // to the modifiers specified in the event structure and the current
2859 // keyboard mapping). In "buf" a null terminated ASCII string is returned
2860 // representing the string that is currently mapped to the key code.
2861 //
2862 // event - specifies the event structure to be used
2863 // buf - returns the translated characters
2864 // buflen - the length of the buffer
2865 // keysym - returns the "keysym" computed from the event
2866 // if this argument is not NULL
2867 assert(buf != 0 && "LookupString, parameter 'buf' is null");
2868 assert(length >= 2 && "LookupString, parameter 'length' - not enough memory to return null-terminated ASCII string");
2869
2870 X11::MapUnicharToKeySym(event->fCode, buf, length, keysym);
2871}
2872
2873#pragma mark - Font management.
2874
2875//______________________________________________________________________________
2877{
2878 //fontName is in XLFD format:
2879 //-foundry-family- ..... etc., some components can be omitted and replaced by *.
2880 assert(fontName != 0 && "LoadQueryFont, fontName is null");
2881
2882 X11::XLFDName xlfd;
2883 if (ParseXLFDName(fontName, xlfd)) {
2884 //Make names more flexible: fFamilyName can be empty or '*'.
2885 if (!xlfd.fFamilyName.length() || xlfd.fFamilyName == "*")
2886 xlfd.fFamilyName = "Courier";//Up to me, right?
2887 if (!xlfd.fPixelSize)
2888 xlfd.fPixelSize = 11;//Again, up to me.
2889 return fPimpl->fFontManager.LoadFont(xlfd);
2890 }
2891
2892 return FontStruct_t();
2893}
2894
2895//______________________________________________________________________________
2900
2901//______________________________________________________________________________
2903{
2904 fPimpl->fFontManager.UnloadFont(fs);
2905}
2906
2907//______________________________________________________________________________
2909{
2910 // Returns True when TrueType fonts are used
2911 return kTRUE;
2912}
2913
2914//______________________________________________________________________________
2916{
2917 // Return length of the string "s" in pixels. Size depends on font.
2918 return fPimpl->fFontManager.GetTextWidth(font, s, len);
2919}
2920
2921//______________________________________________________________________________
2922void TGCocoa::GetFontProperties(FontStruct_t font, Int_t &maxAscent, Int_t &maxDescent)
2923{
2924 // Returns the font properties.
2925 fPimpl->fFontManager.GetFontProperties(font, maxAscent, maxDescent);
2926}
2927
2928//______________________________________________________________________________
2930{
2931 // Retrieves the associated font structure of the font specified font
2932 // handle "fh".
2933 //
2934 // Free returned FontStruct_t using FreeFontStruct().
2935
2936 return (FontStruct_t)fh;
2937}
2938
2939//______________________________________________________________________________
2941{
2942 // Frees the font structure "fs". The font itself will be freed when
2943 // no other resource references it.
2944 //Noop.
2945}
2946
2947//______________________________________________________________________________
2948char **TGCocoa::ListFonts(const char *fontName, Int_t maxNames, Int_t &count)
2949{
2950 count = 0;
2951
2952 if (fontName && fontName[0]) {
2953 X11::XLFDName xlfd;
2954 if (X11::ParseXLFDName(fontName, xlfd))
2955 return fPimpl->fFontManager.ListFonts(xlfd, maxNames, count);
2956 }
2957
2958 return 0;
2959}
2960
2961//______________________________________________________________________________
2962void TGCocoa::FreeFontNames(char **fontList)
2963{
2964 // Frees the specified the array of strings "fontlist".
2965 if (!fontList)
2966 return;
2967
2968 fPimpl->fFontManager.FreeFontNames(fontList);
2969}
2970
2971#pragma mark - Color management.
2972
2973//______________________________________________________________________________
2974Bool_t TGCocoa::ParseColor(Colormap_t /*cmap*/, const char *colorName, ColorStruct_t &color)
2975{
2976 //"Color" passed as colorName, can be one of the names, defined in X11/rgb.txt,
2977 //or rgb triplet, which looks like: #rgb #rrggbb #rrrgggbbb #rrrrggggbbbb,
2978 //where r, g, and b - are hex digits.
2979 return fPimpl->fX11ColorParser.ParseColor(colorName, color);
2980}
2981
2982//______________________________________________________________________________
2984{
2985 const unsigned red = unsigned(double(color.fRed) / 0xFFFF * 0xFF);
2986 const unsigned green = unsigned(double(color.fGreen) / 0xFFFF * 0xFF);
2987 const unsigned blue = unsigned(double(color.fBlue) / 0xFFFF * 0xFF);
2988 color.fPixel = red << 16 | green << 8 | blue;
2989 return kTRUE;
2990}
2991
2992//______________________________________________________________________________
2994{
2995 // Returns the current RGB value for the pixel in the "color" structure
2996 color.fRed = (color.fPixel >> 16 & 0xFF) * 0xFFFF / 0xFF;
2997 color.fGreen = (color.fPixel >> 8 & 0xFF) * 0xFFFF / 0xFF;
2998 color.fBlue = (color.fPixel & 0xFF) * 0xFFFF / 0xFF;
2999}
3000
3001//______________________________________________________________________________
3002void TGCocoa::FreeColor(Colormap_t /*cmap*/, ULong_t /*pixel*/)
3003{
3004 // Frees color cell with specified pixel value.
3005}
3006
3007//______________________________________________________________________________
3009{
3010 ULong_t pixel = 0;
3011 if (const TColor * const color = gROOT->GetColor(rootColorIndex)) {
3012 Float_t red = 0.f, green = 0.f, blue = 0.f;
3013 color->GetRGB(red, green, blue);
3014 pixel = unsigned(red * 255) << 16;
3015 pixel |= unsigned(green * 255) << 8;
3016 pixel |= unsigned(blue * 255);
3017 }
3018
3019 return pixel;
3020}
3021
3022//______________________________________________________________________________
3024{
3025 //Implemented as NSBitsPerPixelFromDepth([mainScreen depth]);
3026 nPlanes = GetDepth();
3027}
3028
3029//______________________________________________________________________________
3030void TGCocoa::GetRGB(Int_t /*index*/, Float_t &/*r*/, Float_t &/*g*/, Float_t &/*b*/)
3031{
3032 // Returns RGB values for color "index".
3033}
3034
3035//______________________________________________________________________________
3036void TGCocoa::SetRGB(Int_t /*cindex*/, Float_t /*r*/, Float_t /*g*/, Float_t /*b*/)
3037{
3038 // Sets color intensities the specified color index "cindex".
3039 //
3040 // cindex - color index
3041 // r, g, b - the red, green, blue intensities between 0.0 and 1.0
3042}
3043
3044//______________________________________________________________________________
3046{
3047 return Colormap_t();
3048}
3049
3050#pragma mark - Graphical context management.
3051
3052//______________________________________________________________________________
3054{
3055 //Here I have to imitate graphics context that exists in X11.
3056 fX11Contexts.push_back(*gval);
3057 return fX11Contexts.size();
3058}
3059
3060//______________________________________________________________________________
3062{
3063 // Sets the foreground color for the specified GC (shortcut for ChangeGC
3064 // with only foreground mask set).
3065 //
3066 // gc - specifies the GC
3067 // foreground - the foreground you want to set
3068 // (see also the GCValues_t structure)
3069
3070 assert(gc <= fX11Contexts.size() && gc > 0 && "ChangeGC, invalid context id");
3071
3072 GCValues_t &x11Context = fX11Contexts[gc - 1];
3073 x11Context.fMask |= kGCForeground;
3074 x11Context.fForeground = foreground;
3075}
3076
3077//______________________________________________________________________________
3079{
3080 //
3081 assert(gc <= fX11Contexts.size() && gc > 0 && "ChangeGC, invalid context id");
3082 assert(gval != 0 && "ChangeGC, gval parameter is null");
3083
3084 GCValues_t &x11Context = fX11Contexts[gc - 1];
3085 const Mask_t &mask = gval->fMask;
3086 x11Context.fMask |= mask;
3087
3088 //Not all of GCValues_t members are used, but
3089 //all can be copied/set without any problem.
3090
3091 if (mask & kGCFunction)
3092 x11Context.fFunction = gval->fFunction;
3093 if (mask & kGCPlaneMask)
3094 x11Context.fPlaneMask = gval->fPlaneMask;
3095 if (mask & kGCForeground)
3096 x11Context.fForeground = gval->fForeground;
3097 if (mask & kGCBackground)
3098 x11Context.fBackground = gval->fBackground;
3099 if (mask & kGCLineWidth)
3100 x11Context.fLineWidth = gval->fLineWidth;
3101 if (mask & kGCLineStyle)
3102 x11Context.fLineStyle = gval->fLineStyle;
3103 if (mask & kGCCapStyle)//nobody uses
3104 x11Context.fCapStyle = gval->fCapStyle;
3105 if (mask & kGCJoinStyle)//nobody uses
3106 x11Context.fJoinStyle = gval->fJoinStyle;
3107 if (mask & kGCFillRule)//nobody uses
3108 x11Context.fFillRule = gval->fFillRule;
3109 if (mask & kGCArcMode)//nobody uses
3110 x11Context.fArcMode = gval->fArcMode;
3111 if (mask & kGCFillStyle)
3112 x11Context.fFillStyle = gval->fFillStyle;
3113 if (mask & kGCTile)
3114 x11Context.fTile = gval->fTile;
3115 if (mask & kGCStipple)
3116 x11Context.fStipple = gval->fStipple;
3118 x11Context.fTsXOrigin = gval->fTsXOrigin;
3120 x11Context.fTsYOrigin = gval->fTsYOrigin;
3121 if (mask & kGCFont)
3122 x11Context.fFont = gval->fFont;
3123 if (mask & kGCSubwindowMode)
3124 x11Context.fSubwindowMode = gval->fSubwindowMode;
3126 x11Context.fGraphicsExposures = gval->fGraphicsExposures;
3127 if (mask & kGCClipXOrigin)
3128 x11Context.fClipXOrigin = gval->fClipXOrigin;
3129 if (mask & kGCClipYOrigin)
3130 x11Context.fClipYOrigin = gval->fClipYOrigin;
3131 if (mask & kGCClipMask)
3132 x11Context.fClipMask = gval->fClipMask;
3133 if (mask & kGCDashOffset)
3134 x11Context.fDashOffset = gval->fDashOffset;
3135 if (mask & kGCDashList) {
3136 const unsigned nDashes = sizeof x11Context.fDashes / sizeof x11Context.fDashes[0];
3137 for (unsigned i = 0; i < nDashes; ++i)
3138 x11Context.fDashes[i] = gval->fDashes[i];
3139 x11Context.fDashLen = gval->fDashLen;
3140 }
3141}
3142
3143//______________________________________________________________________________
3145{
3146 assert(src <= fX11Contexts.size() && src > 0 && "CopyGC, bad source context");
3147 assert(dst <= fX11Contexts.size() && dst > 0 && "CopyGC, bad destination context");
3148
3149 GCValues_t srcContext = fX11Contexts[src - 1];
3150 srcContext.fMask = mask;
3151
3152 ChangeGC(dst, &srcContext);
3153}
3154
3155//______________________________________________________________________________
3157{
3158 // Returns the components specified by the mask in "gval" for the
3159 // specified GC "gc" (see also the GCValues_t structure)
3160 const GCValues_t &gcVal = fX11Contexts[gc - 1];
3161 gval = gcVal;
3162}
3163
3164//______________________________________________________________________________
3166{
3167 // Deletes the specified GC "gc".
3168}
3169
3170#pragma mark - Cursor management.
3171
3172//______________________________________________________________________________
3174{
3175 // Creates the specified cursor. (just return cursor from cursor pool).
3176 // The cursor can be:
3177 //
3178 // kBottomLeft, kBottomRight, kTopLeft, kTopRight,
3179 // kBottomSide, kLeftSide, kTopSide, kRightSide,
3180 // kMove, kCross, kArrowHor, kArrowVer,
3181 // kHand, kRotate, kPointer, kArrowRight,
3182 // kCaret, kWatch
3183
3184 return Cursor_t(cursor + 1);//HAHAHAHAHA!!! CREATED!!!
3185}
3186
3187//______________________________________________________________________________
3189{
3190 // The cursor "cursor" will be used when the pointer is in the
3191 // window "wid".
3192 assert(!fPimpl->IsRootWindow(wid) && "SetCursor, called for root window");
3193
3194 NSView<X11Window> * const view = fPimpl->GetWindow(wid).fContentView;
3195 view.fCurrentCursor = cursor;
3196}
3197
3198//______________________________________________________________________________
3200{
3201 // Sets the cursor "curid" to be used when the pointer is in the
3202 // window "wid".
3203 if (cursorID > 0)
3204 SetCursor(Int_t(wid), ECursor(cursorID - 1));
3205 else
3207}
3208
3209//______________________________________________________________________________
3211{
3212 // Returns the pointer position.
3213
3214 //I ignore fSelectedDrawable here. If you have any problems with this, hehe, you can ask me :)
3215 const NSPoint screenPoint = [NSEvent mouseLocation];
3216 x = X11::GlobalXCocoaToROOT(screenPoint.x);
3217 y = X11::GlobalYCocoaToROOT(screenPoint.y);
3218}
3219
3220//______________________________________________________________________________
3221void TGCocoa::QueryPointer(Window_t winID, Window_t &rootWinID, Window_t &childWinID,
3222 Int_t &rootX, Int_t &rootY, Int_t &winX, Int_t &winY, UInt_t &mask)
3223{
3224 //Emulate XQueryPointer.
3225
3226 //From TGX11/TGWin32:
3227 if (!winID)
3228 return;//Neither TGX11, nor TGWin32 set any of out parameters.
3229
3230 //We have only one root window.
3231 rootWinID = fPimpl->GetRootWindowID();
3232 //Find cursor position (screen coordinates).
3233 NSPoint screenPoint = [NSEvent mouseLocation];
3234 screenPoint.x = X11::GlobalXCocoaToROOT(screenPoint.x);
3235 screenPoint.y = X11::GlobalYCocoaToROOT(screenPoint.y);
3236 rootX = screenPoint.x;
3237 rootY = screenPoint.y;
3238
3239 //Convert a screen point to winID's coordinate system.
3240 if (winID > fPimpl->GetRootWindowID()) {
3241 NSObject<X11Window> * const window = fPimpl->GetWindow(winID);
3242 const NSPoint winPoint = X11::TranslateFromScreen(screenPoint, window.fContentView);
3243 winX = winPoint.x;
3244 winY = winPoint.y;
3245 } else {
3246 winX = screenPoint.x;
3247 winY = screenPoint.y;
3248 }
3249
3250 //Find child window in these coordinates (?).
3251 if (QuartzWindow * const childWin = X11::FindWindowInPoint(screenPoint.x, screenPoint.y)) {
3252 childWinID = childWin.fID;
3254 } else {
3255 childWinID = 0;
3256 mask = 0;
3257 }
3258}
3259
3260#pragma mark - OpenGL management.
3261
3262//______________________________________________________________________________
3264{
3265 //Scaling factor to let our OpenGL code know, that we probably
3266 //work on a retina display.
3267
3268 return [[NSScreen mainScreen] backingScaleFactor];
3269}
3270
3271//______________________________________________________________________________
3273 const std::vector<std::pair<UInt_t, Int_t> > &formatComponents)
3274{
3275 //ROOT never creates GL widgets with 'root' as a parent (so not top-level gl-windows).
3276 //If this change, assert must be deleted.
3277 typedef std::pair<UInt_t, Int_t> component_type;
3278 typedef std::vector<component_type>::size_type size_type;
3279
3280 //Convert pairs into Cocoa's GL attributes.
3281 std::vector<NSOpenGLPixelFormatAttribute> attribs;
3282 for (size_type i = 0, e = formatComponents.size(); i < e; ++i) {
3283 const component_type &comp = formatComponents[i];
3284
3285 if (comp.first == Rgl::kDoubleBuffer) {
3286 attribs.push_back(NSOpenGLPFADoubleBuffer);
3287 } else if (comp.first == Rgl::kDepth) {
3288 attribs.push_back(NSOpenGLPFADepthSize);
3289 attribs.push_back(comp.second > 0 ? comp.second : 32);
3290 } else if (comp.first == Rgl::kAccum) {
3291 attribs.push_back(NSOpenGLPFAAccumSize);
3292 attribs.push_back(comp.second > 0 ? comp.second : 1);
3293 } else if (comp.first == Rgl::kStencil) {
3294 attribs.push_back(NSOpenGLPFAStencilSize);
3295 attribs.push_back(comp.second > 0 ? comp.second : 8);
3296 } else if (comp.first == Rgl::kMultiSample) {
3297 attribs.push_back(NSOpenGLPFAMultisample);
3298 attribs.push_back(NSOpenGLPFASampleBuffers);
3299 attribs.push_back(1);
3300 attribs.push_back(NSOpenGLPFASamples);
3301 attribs.push_back(comp.second ? comp.second : 8);
3302 }
3303 }
3304
3305 attribs.push_back(0);
3306
3307 NSOpenGLPixelFormat * const pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes : &attribs[0]];
3308 const Util::NSScopeGuard<NSOpenGLPixelFormat> formatGuard(pixelFormat);
3309
3310 NSView<X11Window> *parentView = nil;
3311 if (!fPimpl->IsRootWindow(parentID)) {
3312 parentView = fPimpl->GetWindow(parentID).fContentView;
3313 assert([parentView isKindOfClass : [QuartzView class]] &&
3314 "CreateOpenGLWindow, parent view must be QuartzView");
3315 }
3316
3317 NSRect viewFrame = {};
3318 viewFrame.size.width = width;
3319 viewFrame.size.height = height;
3320
3321 ROOTOpenGLView * const glView = [[ROOTOpenGLView alloc] initWithFrame : viewFrame pixelFormat : pixelFormat];
3322 const Util::NSScopeGuard<ROOTOpenGLView> viewGuard(glView);
3323
3324 Window_t glID = kNone;
3325
3326 if (parentView) {
3327 [parentView addChild : glView];
3328 glID = fPimpl->RegisterDrawable(glView);
3329 glView.fID = glID;
3330 } else {
3331 //"top-level glview".
3332 //Create a window to be parent of this gl-view.
3333 QuartzWindow *parent = [[QuartzWindow alloc] initWithGLView : glView];
3334 const Util::NSScopeGuard<QuartzWindow> winGuard(parent);
3335
3336
3337 if (!parent) {
3338 Error("CreateOpenGLWindow", "QuartzWindow allocation/initialization"
3339 " failed for a top-level GL widget");
3340 return kNone;
3341 }
3342
3343 glID = fPimpl->RegisterDrawable(parent);
3344 parent.fID = glID;
3345 }
3346
3347 return glID;
3348}
3349
3350//______________________________________________________________________________
3352{
3353 assert(!fPimpl->IsRootWindow(windowID) &&
3354 "CreateOpenGLContext, parameter 'windowID' is a root window");
3355 assert([fPimpl->GetWindow(windowID).fContentView isKindOfClass : [ROOTOpenGLView class]] &&
3356 "CreateOpenGLContext, view is not an OpenGL view");
3357
3358 NSOpenGLContext * const sharedContext = fPimpl->GetGLContextForHandle(sharedID);
3359 ROOTOpenGLView * const glView = (ROOTOpenGLView *)fPimpl->GetWindow(windowID);
3360
3362 newContext([[NSOpenGLContext alloc] initWithFormat : glView.pixelFormat shareContext : sharedContext]);
3363 glView.fOpenGLContext = newContext.Get();
3364 const Handle_t ctxID = fPimpl->RegisterGLContext(newContext.Get());
3365
3366 return ctxID;
3367}
3368
3369//______________________________________________________________________________
3371{
3372 // Creates OpenGL context for window "wid"
3373}
3374
3375//______________________________________________________________________________
3377{
3378 using namespace Details;
3379
3380 assert(ctxID > 0 && "MakeOpenGLContextCurrent, invalid context id");
3381
3382 NSOpenGLContext * const glContext = fPimpl->GetGLContextForHandle(ctxID);
3383 if (!glContext) {
3384 Error("MakeOpenGLContextCurrent", "No OpenGL context found for id %d", int(ctxID));
3385
3386 return kFALSE;
3387 }
3388
3389 ROOTOpenGLView * const glView = (ROOTOpenGLView *)fPimpl->GetWindow(windowID).fContentView;
3390
3391 if (OpenGL::GLViewIsValidDrawable(glView)) {
3392 if ([glContext view] != glView)
3393 [glContext setView : glView];
3394
3395 if (glView.fUpdateContext) {
3396 [glContext update];
3397 glView.fUpdateContext = NO;
3398 }
3399
3400 glView.fOpenGLContext = glContext;
3401 [glContext makeCurrentContext];
3402
3403 return kTRUE;
3404 } else {
3405 //Oh, here's the real black magic.
3406 //Our brilliant GL code is sure that MakeCurrent always succeeds.
3407 //But it does not: if view is not visible, context can not be attached,
3408 //gl operations will fail.
3409 //Funny enough, but if you have invisible window with visible view,
3410 //this trick works.
3411
3412 NSView *fakeView = nil;
3413 QuartzWindow *fakeWindow = fPimpl->GetFakeGLWindow();
3414
3415 if (!fakeWindow) {
3416 //We did not find any window. Create a new one.
3418 //100 - is just a stupid hardcoded value:
3419 const UInt_t width = std::max(glView.frame.size.width, CGFloat(100));
3420 const UInt_t height = std::max(glView.frame.size.height, CGFloat(100));
3421
3422 NSRect viewFrame = {};
3423 viewFrame.size.width = width;
3424 viewFrame.size.height = height;
3425
3426 const NSUInteger styleMask = kTitledWindowMask | kClosableWindowMask |
3427 kMiniaturizableWindowMask | kResizableWindowMask;
3428
3429 //NOTE: defer parameter is 'NO', otherwise this trick will not help.
3430 fakeWindow = [[QuartzWindow alloc] initWithContentRect : viewFrame styleMask : styleMask
3431 backing : NSBackingStoreBuffered defer : NO windowAttributes : &attr];
3432 Util::NSScopeGuard<QuartzWindow> winGuard(fakeWindow);
3433
3434 fakeView = fakeWindow.fContentView;
3435 [fakeView setHidden : NO];//!
3436
3437 fPimpl->SetFakeGLWindow(fakeWindow);//Can throw.
3438 winGuard.Release();
3439 } else {
3440 fakeView = fakeWindow.fContentView;
3441 [fakeView setHidden : NO];
3442 }
3443
3444 glView.fOpenGLContext = nil;
3445 [glContext setView : fakeView];
3446 [glContext makeCurrentContext];
3447 }
3448
3449 return kTRUE;
3450}
3451
3452//______________________________________________________________________________
3454{
3455 NSOpenGLContext * const currentContext = [NSOpenGLContext currentContext];
3456 if (!currentContext) {
3457 Error("GetCurrentOpenGLContext", "The current OpenGL context is null");
3458 return kNone;
3459 }
3460
3461 const Handle_t contextID = fPimpl->GetHandleForGLContext(currentContext);
3462 if (!contextID)
3463 Error("GetCurrentOpenGLContext", "The current OpenGL context was"
3464 " not created/registered by TGCocoa");
3465
3466 return contextID;
3467}
3468
3469//______________________________________________________________________________
3471{
3472 assert(ctxID > 0 && "FlushOpenGLBuffer, invalid context id");
3473
3474 NSOpenGLContext * const glContext = fPimpl->GetGLContextForHandle(ctxID);
3475 assert(glContext != nil && "FlushOpenGLBuffer, bad context id");
3476
3477 if (glContext != [NSOpenGLContext currentContext])//???
3478 return;
3479
3480 glFlush();//???
3481 [glContext flushBuffer];
3482}
3483
3484//______________________________________________________________________________
3486{
3487 //Historically, DeleteOpenGLContext was accepting window id,
3488 //now it's a context id. DeleteOpenGLContext is not used in ROOT,
3489 //only in TGLContext for Cocoa.
3490 NSOpenGLContext * const glContext = fPimpl->GetGLContextForHandle(ctxID);
3491 if (NSView * const v = [glContext view]) {
3492 if ([v isKindOfClass : [ROOTOpenGLView class]])
3493 ((ROOTOpenGLView *)v).fOpenGLContext = nil;
3494
3495 [glContext clearDrawable];
3496 }
3497
3498 if (glContext == [NSOpenGLContext currentContext])
3499 [NSOpenGLContext clearCurrentContext];
3500
3501 fPimpl->DeleteGLContext(ctxID);
3502}
3503
3504#pragma mark - Off-screen rendering for TPad/TCanvas.
3505
3506//______________________________________________________________________________
3508{
3509 //In ROOT, canvas has a "double buffer" - pixmap attached to 'wid'.
3510 assert(windowID > (Int_t)fPimpl->GetRootWindowID() && "SetDoubleBuffer called for root window");
3511
3512 // only workaround for canvas which is closed but pixmap/window id remains
3513 // cocoa destroys them when widget is closed but ids remains set
3514 // FIXME: correctly reset canvas/pads ids in cocoa
3515 if (!fPimpl->HasDrawable(windowID))
3516 return;
3517
3518 if (windowID == 999) {//Comment in TVirtaulX suggests, that 999 means all windows.
3519 Warning("SetDoubleBuffer", "called with wid == 999");
3520 //Window with id 999 can not exists - this is checked in CocoaPrivate.
3521 } else {
3522 fSelectedDrawable = windowID;
3524 }
3525}
3526
3527//______________________________________________________________________________
3529{
3530 fDirectDraw = true;
3531
3532 assert(fSelectedDrawable > fPimpl->GetRootWindowID() &&
3533 "SetDoubleBufferON, called, but no correct window was selected before");
3534
3535 NSObject<X11Window> * const window = fPimpl->GetWindow(fSelectedDrawable);
3536 if (!window) return;
3537
3538 assert(window.fIsPixmap == NO &&
3539 "SetDoubleBufferON, selected drawable is a pixmap, can not attach pixmap to pixmap");
3540
3541 [window setDirectDraw : YES];
3542}
3543
3544//______________________________________________________________________________
3546{
3547 //Attach pixmap to the selected window (view).
3548 fDirectDraw = false;
3549
3550 assert(fSelectedDrawable > fPimpl->GetRootWindowID() &&
3551 "SetDoubleBufferON, called, but no correct window was selected before");
3552
3553 NSObject<X11Window> * const window = fPimpl->GetWindow(fSelectedDrawable);
3554 if (!window) return;
3555
3556 assert(window.fIsPixmap == NO &&
3557 "SetDoubleBufferON, selected drawable is a pixmap, can not attach pixmap to pixmap");
3558
3559 [window setDirectDraw : NO];
3560
3561 const unsigned currW = window.fWidth;
3562 const unsigned currH = window.fHeight;
3563
3564 if (QuartzPixmap *const currentPixmap = window.fBackBuffer) {
3565 if (currH == currentPixmap.fHeight && currW == currentPixmap.fWidth)
3566 return;
3567 }
3568
3569 Util::NSScopeGuard<QuartzPixmap> pixmap([[QuartzPixmap alloc] initWithW : currW
3570 H : currH scaleFactor : [[NSScreen mainScreen] backingScaleFactor]]);
3571 if (pixmap.Get())
3572 window.fBackBuffer = pixmap.Get();
3573 else
3574 //Detailed error message was issued by QuartzPixmap.
3575 Error("SetDoubleBufferON", "QuartzPixmap initialization failed");
3576}
3577
3578//______________________________________________________________________________
3580{
3581 // Sets the drawing mode for all windows.
3582 //
3583 auto windows = NSApplication.sharedApplication.windows;
3584 for (NSWindow *candidate : windows) {
3585 if ([candidate isKindOfClass:QuartzWindow.class])
3586 [(QuartzWindow *)candidate setDrawMode : mode];
3587 }
3588
3589 fDrawMode = mode;
3590}
3591
3592#pragma mark - Event management part.
3593
3594//______________________________________________________________________________
3596{
3597 if (fPimpl->IsRootWindow(wid))//ROOT's GUI can send events to root window.
3598 return;
3599
3600 //From TGX11:
3601 if (!wid || !event)
3602 return;
3603
3604 Event_t newEvent = *event;
3605 newEvent.fWindow = wid;
3606 fPimpl->fX11EventTranslator.fEventQueue.push_back(newEvent);
3607}
3608
3609//______________________________________________________________________________
3611{
3612 assert(fPimpl->fX11EventTranslator.fEventQueue.size() > 0 && "NextEvent, event queue is empty");
3613
3614 event = fPimpl->fX11EventTranslator.fEventQueue.front();
3615 fPimpl->fX11EventTranslator.fEventQueue.pop_front();
3616}
3617
3618//______________________________________________________________________________
3620{
3621 return (Int_t)fPimpl->fX11EventTranslator.fEventQueue.size();
3622}
3623
3624
3625//______________________________________________________________________________
3627{
3628 typedef X11::EventQueue_t::iterator iterator_type;
3629
3630 iterator_type it = fPimpl->fX11EventTranslator.fEventQueue.begin();
3631 iterator_type eIt = fPimpl->fX11EventTranslator.fEventQueue.end();
3632
3633 for (; it != eIt; ++it) {
3634 const Event_t &queuedEvent = *it;
3635 if (queuedEvent.fWindow == windowID && queuedEvent.fType == type) {
3636 event = queuedEvent;
3637 fPimpl->fX11EventTranslator.fEventQueue.erase(it);
3638 return kTRUE;
3639 }
3640 }
3641
3642 return kFALSE;
3643}
3644
3645//______________________________________________________________________________
3647{
3648 //I can not give an access to the native event,
3649 //it even, probably, does not exist already.
3650 return kNone;
3651}
3652
3653#pragma mark - "Drag and drop", "Copy and paste", X11 properties.
3654
3655//______________________________________________________________________________
3656Atom_t TGCocoa::InternAtom(const char *name, Bool_t onlyIfExist)
3657{
3658 //X11 properties emulation.
3659
3660 assert(name != 0 && "InternAtom, parameter 'name' is null");
3661 return FindAtom(name, !onlyIfExist);
3662}
3663
3664//______________________________________________________________________________
3666{
3667 //Comment from TVirtualX:
3668 // Makes the window "wid" the current owner of the primary selection.
3669 // That is the window in which, for example some text is selected.
3670 //End of comment.
3671
3672 //It's not clear, why SetPrimarySelectionOwner and SetSelectionOwner have different return types.
3673
3674 if (!windowID)//From TGWin32.
3675 return;
3676
3677 assert(!fPimpl->IsRootWindow(windowID) &&
3678 "SetPrimarySelectionOwner, windowID parameter is a 'root' window");
3679 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3680 "SetPrimarySelectionOwner, windowID parameter is not a valid window");
3681
3682 const Atom_t primarySelectionAtom = FindAtom("XA_PRIMARY", false);
3683 assert(primarySelectionAtom != kNone &&
3684 "SetPrimarySelectionOwner, predefined XA_PRIMARY atom was not found");
3685
3686 fSelectionOwners[primarySelectionAtom] = windowID;
3687 //No events will be send - I do not have different clients, so nobody to send SelectionClear.
3688}
3689
3690//______________________________________________________________________________
3692{
3693 //Comment from TVirtualX:
3694 // Changes the owner and last-change time for the specified selection.
3695 //End of comment.
3696
3697 //It's not clear, why SetPrimarySelectionOwner and SetSelectionOwner have different return types.
3698
3699 if (!windowID)
3700 return kFALSE;
3701
3702 assert(!fPimpl->IsRootWindow(windowID) &&
3703 "SetSelectionOwner, windowID parameter is a 'root' window'");
3704 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3705 "SetSelectionOwner, windowID parameter is not a valid window");
3706
3707 fSelectionOwners[selection] = windowID;
3708 //No messages, since I do not have different clients.
3709
3710 return kTRUE;
3711}
3712
3713//______________________________________________________________________________
3715{
3716 //Comment from TVirtualX:
3717 // Returns the window id of the current owner of the primary selection.
3718 // That is the window in which, for example some text is selected.
3719 //End of comment.
3720 const Atom_t primarySelectionAtom = FindAtom("XA_PRIMARY", false);
3721 assert(primarySelectionAtom != kNone &&
3722 "GetPrimarySelectionOwner, predefined XA_PRIMARY atom was not found");
3723
3724 return fSelectionOwners[primarySelectionAtom];
3725}
3726
3727//______________________________________________________________________________
3729{
3730 //Comment from TVirtualX:
3731 // Causes a SelectionRequest event to be sent to the current primary
3732 // selection owner. This event specifies the selection property
3733 // (primary selection), the format into which to convert that data before
3734 // storing it (target = XA_STRING), the property in which the owner will
3735 // place the information (sel_property), the window that wants the
3736 // information (id), and the time of the conversion request (when).
3737 // The selection owner responds by sending a SelectionNotify event, which
3738 // confirms the selected atom and type.
3739 //End of comment.
3740
3741 //From TGWin32:
3742 if (!windowID)
3743 return;
3744
3745 assert(!fPimpl->IsRootWindow(windowID) &&
3746 "ConvertPrimarySelection, parameter 'windowID' is root window");
3747 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3748 "ConvertPrimarySelection, parameter windowID parameter is not a window id");
3749
3750 Atom_t primarySelectionAtom = FindAtom("XA_PRIMARY", false);
3751 assert(primarySelectionAtom != kNone &&
3752 "ConvertPrimarySelection, XA_PRIMARY predefined atom not found");
3753
3754 Atom_t stringAtom = FindAtom("XA_STRING", false);
3755 assert(stringAtom != kNone &&
3756 "ConvertPrimarySelection, XA_STRING predefined atom not found");
3757
3758 ConvertSelection(windowID, primarySelectionAtom, stringAtom, clipboard, when);
3759}
3760
3761//______________________________________________________________________________
3763 Atom_t &property, Time_t &/*timeStamp*/)
3764{
3765 // Requests that the specified selection be converted to the specified
3766 // target type.
3767
3768 // Requests that the specified selection be converted to the specified
3769 // target type.
3770
3771 if (!windowID)
3772 return;
3773
3774 assert(!fPimpl->IsRootWindow(windowID) &&
3775 "ConvertSelection, parameter 'windowID' is root window'");
3776 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3777 "ConvertSelection, parameter 'windowID' is not a window id");
3778
3779 Event_t newEvent = {};
3780 selection_iterator selIter = fSelectionOwners.find(selection);
3781
3782 if (selIter != fSelectionOwners.end())
3783 newEvent.fType = kSelectionRequest;
3784 else
3785 newEvent.fType = kSelectionNotify;
3786
3787 newEvent.fWindow = windowID;
3788 newEvent.fUser[0] = windowID;//requestor
3789 newEvent.fUser[1] = selection;
3790 newEvent.fUser[2] = target;
3791 newEvent.fUser[3] = property;
3792
3793 SendEvent(windowID, &newEvent);
3794}
3795
3796//______________________________________________________________________________
3798 Atom_t *actualType, Int_t *actualFormat, ULong_t *nItems,
3799 ULong_t *bytesAfterReturn, unsigned char **propertyReturn)
3800{
3801 //Comment from TVirtualX:
3802 // Returns the actual type of the property; the actual format of the property;
3803 // the number of 8-bit, 16-bit, or 32-bit items transferred; the number of
3804 // bytes remaining to be read in the property; and a pointer to the data
3805 // actually returned.
3806 //End of comment.
3807
3808 if (fPimpl->IsRootWindow(windowID))
3809 return 0;
3810
3811 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3812 "GetProperty, parameter 'windowID' is not a valid window id");
3813 assert(propertyID > 0 && propertyID <= fAtomToName.size() &&
3814 "GetProperty, parameter 'propertyID' is not a valid atom");
3815 assert(actualType != 0 && "GetProperty, parameter 'actualType' is null");
3816 assert(actualFormat != 0 && "GetProperty, parameter 'actualFormat' is null");
3817 assert(bytesAfterReturn != 0 && "GetProperty, parameter 'bytesAfterReturn' is null");
3818 assert(propertyReturn != 0 && "GetProperty, parameter 'propertyReturn' is null");
3819
3820 const Util::AutoreleasePool pool;
3821
3822 *bytesAfterReturn = 0;//In TGWin32 the value set to .. nItems?
3823 *propertyReturn = 0;
3824 *nItems = 0;
3825
3826 const std::string &atomName = fAtomToName[propertyID - 1];
3827 NSObject<X11Window> *window = fPimpl->GetWindow(windowID);
3828
3829 if (![window hasProperty : atomName.c_str()]) {
3830 Error("GetProperty", "Unknown property %s requested", atomName.c_str());
3831 return 0;//actually, 0 is ... Success (X11)?
3832 }
3833
3834 unsigned tmpFormat = 0, tmpElements = 0;
3835 *propertyReturn = [window getProperty : atomName.c_str() returnType : actualType
3836 returnFormat : &tmpFormat nElements : &tmpElements];
3837 *actualFormat = (Int_t)tmpFormat;
3838 *nItems = tmpElements;
3839
3840 return *nItems;//Success (X11) is 0?
3841}
3842
3843//______________________________________________________________________________
3845 Int_t &nChars, Bool_t clearBuffer)
3846{
3847 //Comment from TVirtualX:
3848 // Gets contents of the paste buffer "atom" into the string "text".
3849 // (nchar = number of characters) If "del" is true deletes the paste
3850 // buffer afterwards.
3851 //End of comment.
3852
3853 //From TGX11:
3854 if (!windowID)
3855 return;
3856
3857 assert(!fPimpl->IsRootWindow(windowID) &&
3858 "GetPasteBuffer, parameter 'windowID' is root window");
3859 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3860 "GetPasteBuffer, parameter 'windowID' is not a valid window");
3861 assert(propertyID && propertyID <= fAtomToName.size() &&
3862 "GetPasteBuffer, parameter 'propertyID' is not a valid atom");
3863
3864 const Util::AutoreleasePool pool;
3865
3866 const std::string &atomString = fAtomToName[propertyID - 1];
3867 NSObject<X11Window> *window = fPimpl->GetWindow(windowID);
3868
3869 if (![window hasProperty : atomString.c_str()]) {
3870 Error("GetPasteBuffer", "No property %s on a window", atomString.c_str());
3871 return;
3872 }
3873
3874 Atom_t tmpType = 0;
3875 unsigned tmpFormat = 0, nElements = 0;
3876
3878 propertyData((char *)[window getProperty : atomString.c_str()
3879 returnType : &tmpType returnFormat : &tmpFormat
3880 nElements : &nElements]);
3881
3882 assert(tmpFormat == 8 && "GetPasteBuffer, property has wrong format");
3883
3884 text.Insert(0, propertyData.Get(), nElements);
3885 nChars = (Int_t)nElements;
3886
3887 if (clearBuffer) {
3888 //For the moment - just remove the property
3889 //(anyway, ChangeProperty/ChangeProperties will re-create it).
3890 [window removeProperty : atomString.c_str()];
3891 }
3892}
3893
3894//______________________________________________________________________________
3897{
3898 //Comment from TVirtualX:
3899 // Alters the property for the specified window and causes the X server
3900 // to generate a PropertyNotify event on that window.
3901 //
3902 // wid - the window whose property you want to change
3903 // property - specifies the property name
3904 // type - the type of the property; the X server does not
3905 // interpret the type but simply passes it back to
3906 // an application that might ask about the window
3907 // properties
3908 // data - the property data
3909 // len - the length of the specified data format
3910 //End of comment.
3911
3912 //TGX11 always calls XChangeProperty with PropModeReplace.
3913 //I simply reset the property (or create a new one).
3914
3915 if (!windowID) //From TGWin32.
3916 return;
3917
3918 if (!data || !len) //From TGWin32.
3919 return;
3920
3921 assert(!fPimpl->IsRootWindow(windowID) &&
3922 "ChangeProperty, parameter 'windowID' is root window");
3923 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3924 "ChangeProperty, parameter 'windowID' is not a valid window id");
3925 assert(propertyID && propertyID <= fAtomToName.size() &&
3926 "ChangeProperty, parameter 'propertyID' is not a valid atom");
3927
3928 const Util::AutoreleasePool pool;
3929
3930 const std::string &atomString = fAtomToName[propertyID - 1];
3931
3932 NSObject<X11Window> * const window = fPimpl->GetWindow(windowID);
3933 [window setProperty : atomString.c_str() data : data size : len forType : type format : 8];
3934 //ROOT ignores PropertyNotify events.
3935}
3936
3937//______________________________________________________________________________
3940{
3941 //Comment from TVirtualX:
3942 // Alters the property for the specified window and causes the X server
3943 // to generate a PropertyNotify event on that window.
3944 //End of comment.
3945
3946 //TGX11 always calls XChangeProperty with PropModeReplace.
3947 //I simply reset the property (or create a new one).
3948
3949 if (!windowID)//From TGWin32.
3950 return;
3951
3952 if (!data || !len)//From TGWin32.
3953 return;
3954
3955 assert(!fPimpl->IsRootWindow(windowID) &&
3956 "ChangeProperties, parameter 'windowID' is root window");
3957 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3958 "ChangeProperties, parameter 'windowID' is not a valid window id");
3959 assert(propertyID && propertyID <= fAtomToName.size() &&
3960 "ChangeProperties, parameter 'propertyID' is not a valid atom");
3961
3962 const Util::AutoreleasePool pool;
3963
3964 const std::string &atomName = fAtomToName[propertyID - 1];
3965
3966 NSObject<X11Window> * const window = fPimpl->GetWindow(windowID);
3967 [window setProperty : atomName.c_str() data : data
3968 size : len forType : type format : format];
3969 //No property notify, ROOT does not know about this.
3970}
3971
3972//______________________________________________________________________________
3973void TGCocoa::DeleteProperty(Window_t windowID, Atom_t &propertyID)
3974{
3975 //Comment from TVirtualX:
3976 // Deletes the specified property only if the property was defined on the
3977 // specified window and causes the X server to generate a PropertyNotify
3978 // event on the window unless the property does not exist.
3979 //End of comment.
3980
3981 if (!windowID)//Can this happen?
3982 return;
3983
3984 //Strange signature - why propertyID is a reference?
3985 assert(!fPimpl->IsRootWindow(windowID) &&
3986 "DeleteProperty, parameter 'windowID' is root window");
3987 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
3988 "DeleteProperty, parameter 'windowID' is not a valid window");
3989 assert(propertyID && propertyID <= fAtomToName.size() &&
3990 "DeleteProperty, parameter 'propertyID' is not a valid atom");
3991
3992 const std::string &atomString = fAtomToName[propertyID - 1];
3993 [fPimpl->GetWindow(windowID) removeProperty : atomString.c_str()];
3994}
3995
3996//______________________________________________________________________________
3997void TGCocoa::SetDNDAware(Window_t windowID, Atom_t *typeList)
3998{
3999 //Comment from TVirtaulX:
4000 // Add XdndAware property and the list of drag and drop types to the
4001 // Window win.
4002 //End of comment.
4003
4004
4005 //TGX11 first replaces XdndAware property for a windowID, and then appends atoms from a typelist.
4006 //I simply put all data for a property into a vector and set the property (either creating
4007 //a new property or replacing the existing).
4008
4009 assert(windowID > fPimpl->GetRootWindowID() &&
4010 "SetDNDAware, parameter 'windowID' is not a valid window id");
4011 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
4012 "SetDNDAware, parameter 'windowID' is not a window");
4013
4014 const Util::AutoreleasePool pool;
4015
4016 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(windowID).fContentView;
4017 NSArray * const supportedTypes = [NSArray arrayWithObjects : NSFilenamesPboardType, nil];//In a pool.
4018
4019 //Do this for Cocoa - to make it possible to drag something to a
4020 //ROOT's window (also this will change cursor shape while dragging).
4021 [view registerForDraggedTypes : supportedTypes];
4022 //Declared property - for convenience, not to check atoms/shmatoms or X11 properties.
4023 view.fIsDNDAware = YES;
4024
4025 FindAtom("XdndAware", true);//Add it, if not yet.
4026 const Atom_t xaAtomAtom = FindAtom("XA_ATOM", false);
4027
4028 assert(xaAtomAtom == 4 && "SetDNDAware, XA_ATOM is not defined");//This is a predefined atom.
4029
4030 //ROOT's GUI uses Atom_t, which is unsigned long, and it's 64-bit.
4031 //While calling XChangeProperty, it passes the address of this typelist
4032 //and format is ... 32. I have to pack data into unsigned and force the size:
4033 assert(sizeof(unsigned) == 4 && "SetDNDAware, sizeof(unsigned) must be 4");
4034
4035 std::vector<unsigned> propertyData;
4036 propertyData.push_back(4);//This '4' is from TGX11 (is it XA_ATOM???)
4037
4038 if (typeList) {
4039 for (unsigned i = 0; typeList[i]; ++i)
4040 propertyData.push_back(unsigned(typeList[i]));//hehe.
4041 }
4042
4043 [view setProperty : "XdndAware" data : (unsigned char *)&propertyData[0]
4044 size : propertyData.size() forType : xaAtomAtom format : 32];
4045}
4046
4047//______________________________________________________________________________
4049{
4050 //Checks if the Window is DND aware. typeList is ignored.
4051
4052 if (windowID <= fPimpl->GetRootWindowID())//kNone or root.
4053 return kFALSE;
4054
4055 assert(fPimpl->GetDrawable(windowID).fIsPixmap == NO &&
4056 "IsDNDAware, windowID parameter is not a window");
4057
4058 QuartzView * const view = (QuartzView *)fPimpl->GetWindow(windowID).fContentView;
4059 return view.fIsDNDAware;
4060}
4061
4062//______________________________________________________________________________
4064{
4065 // Add the list of drag and drop types to the Window win.
4066 //It's never called from GUI.
4067 ::Warning("SetTypeList", "Not implemented");
4068}
4069
4070//______________________________________________________________________________
4071Window_t TGCocoa::FindRWindow(Window_t winID, Window_t dragWinID, Window_t inputWinID, int x, int y, int maxDepth)
4072{
4073 //Comment from TVirtualX:
4074
4075 // Recursively search in the children of Window for a Window which is at
4076 // location x, y and is DND aware, with a maximum depth of maxd.
4077 // Ignore dragwin and input (???)
4078 //End of comment from TVirtualX.
4079
4080
4081 //Now my comments. The name of this function, as usually, says nothing about what it does.
4082 //It's searching for some window, probably child of winID, or may be winID itself(?) and
4083 //window must be DND aware. So the name should be FindDNDAwareWindowRecursively or something like this.
4084
4085 //This function is not documented, comments suck as soon as they are simply wrong - the
4086 //first return statement in X11 version contradicts with comments
4087 //about child. Since X11 version is more readable, I'm reproducing X11 version here,
4088 //and ... my code can't be wrong, since there is nothing right about this function.
4089
4091 fPimpl->IsRootWindow(winID) ? nil : fPimpl->GetWindow(winID).fContentView,
4092 dragWinID, inputWinID, x, y, maxDepth);
4093 if (testView)
4094 return testView.fID;
4095
4096 return kNone;
4097}
4098
4099#pragma mark - Noops.
4100
4101//______________________________________________________________________________
4102UInt_t TGCocoa::ExecCommand(TGWin32Command * /*code*/)
4103{
4104 // Executes the command "code" coming from the other threads (Win32)
4105 return 0;
4106}
4107
4108//______________________________________________________________________________
4110{
4111 // Queries the double buffer value for the window "wid".
4112 return 0;
4113}
4114
4115//______________________________________________________________________________
4117{
4118 // Returns character up vector.
4119 chupx = chupy = 0.f;
4120}
4121
4122//______________________________________________________________________________
4123Pixmap_t TGCocoa::ReadGIF(Int_t /*x0*/, Int_t /*y0*/, const char * /*file*/, Window_t /*id*/)
4124{
4125 // If id is NULL - loads the specified gif file at position [x0,y0] in the
4126 // current window. Otherwise creates pixmap from gif file
4127
4128 return kNone;
4129}
4130
4131//______________________________________________________________________________
4132Int_t TGCocoa::RequestLocator(Int_t /*mode*/, Int_t /*ctyp*/, Int_t &/*x*/, Int_t &/*y*/)
4133{
4134 // Requests Locator position.
4135 // x,y - cursor position at moment of button press (output)
4136 // ctyp - cursor type (input)
4137 // ctyp = 1 tracking cross
4138 // ctyp = 2 cross-hair
4139 // ctyp = 3 rubber circle
4140 // ctyp = 4 rubber band
4141 // ctyp = 5 rubber rectangle
4142 //
4143 // mode - input mode
4144 // mode = 0 request
4145 // mode = 1 sample
4146 //
4147 // The returned value is:
4148 // in request mode:
4149 // 1 = left is pressed
4150 // 2 = middle is pressed
4151 // 3 = right is pressed
4152 // in sample mode:
4153 // 11 = left is released
4154 // 12 = middle is released
4155 // 13 = right is released
4156 // -1 = nothing is pressed or released
4157 // -2 = leave the window
4158 // else = keycode (keyboard is pressed)
4159
4160 return 0;
4161}
4162
4163//______________________________________________________________________________
4164Int_t TGCocoa::RequestString(Int_t /*x*/, Int_t /*y*/, char * /*text*/)
4165{
4166 // Requests string: text is displayed and can be edited with Emacs-like
4167 // keybinding. Returns termination code (0 for ESC, 1 for RETURN)
4168 //
4169 // x,y - position where text is displayed
4170 // text - displayed text (as input), edited text (as output)
4171 return 0;
4172}
4173
4174//______________________________________________________________________________
4175void TGCocoa::SetCharacterUp(Float_t /*chupx*/, Float_t /*chupy*/)
4176{
4177 // Sets character up vector.
4178}
4179
4180//______________________________________________________________________________
4182{
4183 // Turns off the clipping for the window "wid".
4184}
4185
4186//______________________________________________________________________________
4187void TGCocoa::SetClipRegion(Int_t /*wid*/, Int_t /*x*/, Int_t /*y*/, UInt_t /*w*/, UInt_t /*h*/)
4188{
4189 // Sets clipping region for the window "wid".
4190 //
4191 // wid - window indentifier
4192 // x, y - origin of clipping rectangle
4193 // w, h - the clipping rectangle dimensions
4194
4195}
4196
4197//______________________________________________________________________________
4199{
4200 // Sets the current text magnification factor to "mgn"
4201}
4202
4203//______________________________________________________________________________
4204void TGCocoa::Sync(Int_t /*mode*/)
4205{
4206 // Set synchronisation on or off.
4207 // mode : synchronisation on/off
4208 // mode=1 on
4209 // mode<>0 off
4210}
4211
4212//______________________________________________________________________________
4214{
4215 // Sets the pointer position.
4216 // ix - new X coordinate of pointer
4217 // iy - new Y coordinate of pointer
4218 // Coordinates are relative to the origin of the window id
4219 // or to the origin of the current window if id == 0.
4220
4221 if (!winID)
4222 return;
4223
4224 NSPoint newCursorPosition = {};
4225 newCursorPosition.x = ix;
4226 newCursorPosition.y = iy;
4227
4228 if (fPimpl->GetRootWindowID() == winID) {
4229 //Suddenly .... top-left - based!
4230 newCursorPosition.x = X11::GlobalXROOTToCocoa(newCursorPosition.x);
4231 } else {
4232 assert(fPimpl->GetDrawable(winID).fIsPixmap == NO &&
4233 "Warp, drawable is not a window");
4234 newCursorPosition = X11::TranslateToScreen(fPimpl->GetWindow(winID).fContentView,
4235 newCursorPosition);
4236 }
4237
4238 CGWarpMouseCursorPosition(NSPointToCGPoint(newCursorPosition));
4239}
4240
4241//______________________________________________________________________________
4242Int_t TGCocoa::WriteGIF(char * /*name*/)
4243{
4244 // Writes the current window into GIF file.
4245 // Returns 1 in case of success, 0 otherwise.
4246
4247 return 0;
4248}
4249
4250//______________________________________________________________________________
4251void TGCocoa::WritePixmap(Int_t /*wid*/, UInt_t /*w*/, UInt_t /*h*/, char * /*pxname*/)
4252{
4253 // Writes the pixmap "wid" in the bitmap file "pxname".
4254 //
4255 // wid - the pixmap address
4256 // w, h - the width and height of the pixmap.
4257 // pxname - the file name
4258}
4259
4260//______________________________________________________________________________
4262{
4263 // Notify the low level GUI layer ROOT requires "tgwindow" to be
4264 // updated
4265 //
4266 // Returns kTRUE if the notification was desirable and it was sent
4267 //
4268 // At the moment only Qt4 layer needs that
4269 //
4270 // One needs explicitly cast the first parameter to TGWindow to make
4271 // it working in the implementation.
4272 //
4273 // One needs to process the notification to confine
4274 // all paint operations within "expose" / "paint" like low level event
4275 // or equivalent
4276
4277 return kFALSE;
4278}
4279
4280//______________________________________________________________________________
4282 const char * /*filename*/,
4283 Pixmap_t &/*pict*/,
4284 Pixmap_t &/*pict_mask*/,
4285 PictureAttributes_t &/*attr*/)
4286{
4287 // Creates a picture pict from data in file "filename". The picture
4288 // attributes "attr" are used for input and output. Returns kTRUE in
4289 // case of success, kFALSE otherwise. If the mask "pict_mask" does not
4290 // exist it is set to kNone.
4291
4292 return kFALSE;
4293}
4294
4295//______________________________________________________________________________
4297 Pixmap_t &/*pict*/,
4298 Pixmap_t &/*pict_mask*/,
4299 PictureAttributes_t & /*attr*/)
4300{
4301 // Creates a picture pict from data in bitmap format. The picture
4302 // attributes "attr" are used for input and output. Returns kTRUE in
4303 // case of success, kFALSE otherwise. If the mask "pict_mask" does not
4304 // exist it is set to kNone.
4305
4306 return kFALSE;
4307}
4308//______________________________________________________________________________
4309Bool_t TGCocoa::ReadPictureDataFromFile(const char * /*filename*/, char *** /*ret_data*/)
4310{
4311 // Reads picture data from file "filename" and store it in "ret_data".
4312 // Returns kTRUE in case of success, kFALSE otherwise.
4313
4314 return kFALSE;
4315}
4316
4317//______________________________________________________________________________
4318void TGCocoa::DeletePictureData(void * /*data*/)
4319{
4320 // Delete picture data created by the function ReadPictureDataFromFile.
4321}
4322
4323//______________________________________________________________________________
4324void TGCocoa::SetDashes(GContext_t /*gc*/, Int_t /*offset*/, const char * /*dash_list*/, Int_t /*n*/)
4325{
4326 // Sets the dash-offset and dash-list attributes for dashed line styles
4327 // in the specified GC. There must be at least one element in the
4328 // specified dash_list. The initial and alternating elements (second,
4329 // fourth, and so on) of the dash_list are the even dashes, and the
4330 // others are the odd dashes. Each element in the "dash_list" array
4331 // specifies the length (in pixels) of a segment of the pattern.
4332 //
4333 // gc - specifies the GC (see GCValues_t structure)
4334 // offset - the phase of the pattern for the dashed line-style you
4335 // want to set for the specified GC.
4336 // dash_list - the dash-list for the dashed line-style you want to set
4337 // for the specified GC
4338 // n - the number of elements in dash_list
4339 // (see also the GCValues_t structure)
4340}
4341
4342//______________________________________________________________________________
4343void TGCocoa::Bell(Int_t /*percent*/)
4344{
4345 // Sets the sound bell. Percent is loudness from -100% .. 100%.
4346}
4347
4348//______________________________________________________________________________
4350{
4351 // Tells WM to send message when window is closed via WM.
4352}
4353
4354//______________________________________________________________________________
4356 Rectangle_t * /*recs*/, Int_t /*n*/)
4357{
4358 // Sets clipping rectangles in graphics context. [x,y] specify the origin
4359 // of the rectangles. "recs" specifies an array of rectangles that define
4360 // the clipping mask and "n" is the number of rectangles.
4361 // (see also the GCValues_t structure)
4362}
4363
4364//______________________________________________________________________________
4366{
4367 // Creates a new empty region.
4368
4369 return 0;
4370}
4371
4372//______________________________________________________________________________
4374{
4375 // Destroys the region "reg".
4376}
4377
4378//______________________________________________________________________________
4380{
4381 // Updates the destination region from a union of the specified rectangle
4382 // and the specified source region.
4383 //
4384 // rect - specifies the rectangle
4385 // src - specifies the source region to be used
4386 // dest - returns the destination region
4387}
4388
4389//______________________________________________________________________________
4390Region_t TGCocoa::PolygonRegion(Point_t * /*points*/, Int_t /*np*/, Bool_t /*winding*/)
4391{
4392 // Returns a region for the polygon defined by the points array.
4393 //
4394 // points - specifies an array of points
4395 // np - specifies the number of points in the polygon
4396 // winding - specifies the winding-rule is set (kTRUE) or not(kFALSE)
4397
4398 return 0;
4399}
4400
4401//______________________________________________________________________________
4402void TGCocoa::UnionRegion(Region_t /*rega*/, Region_t /*regb*/, Region_t /*result*/)
4403{
4404 // Computes the union of two regions.
4405 //
4406 // rega, regb - specify the two regions with which you want to perform
4407 // the computation
4408 // result - returns the result of the computation
4409
4410}
4411
4412//______________________________________________________________________________
4413void TGCocoa::IntersectRegion(Region_t /*rega*/, Region_t /*regb*/, Region_t /*result*/)
4414{
4415 // Computes the intersection of two regions.
4416 //
4417 // rega, regb - specify the two regions with which you want to perform
4418 // the computation
4419 // result - returns the result of the computation
4420}
4421
4422//______________________________________________________________________________
4423void TGCocoa::SubtractRegion(Region_t /*rega*/, Region_t /*regb*/, Region_t /*result*/)
4424{
4425 // Subtracts regb from rega and stores the results in result.
4426}
4427
4428//______________________________________________________________________________
4429void TGCocoa::XorRegion(Region_t /*rega*/, Region_t /*regb*/, Region_t /*result*/)
4430{
4431 // Calculates the difference between the union and intersection of
4432 // two regions.
4433 //
4434 // rega, regb - specify the two regions with which you want to perform
4435 // the computation
4436 // result - returns the result of the computation
4437
4438}
4439
4440//______________________________________________________________________________
4442{
4443 // Returns kTRUE if the region reg is empty.
4444
4445 return kFALSE;
4446}
4447
4448//______________________________________________________________________________
4450{
4451 // Returns kTRUE if the point [x, y] is contained in the region reg.
4452
4453 return kFALSE;
4454}
4455
4456//______________________________________________________________________________
4458{
4459 // Returns kTRUE if the two regions have the same offset, size, and shape.
4460
4461 return kFALSE;
4462}
4463
4464//______________________________________________________________________________
4466{
4467 // Returns smallest enclosing rectangle.
4468}
4469
4470#pragma mark - Details and aux. functions.
4471
4472//______________________________________________________________________________
4474{
4475 return &fPimpl->fX11EventTranslator;
4476}
4477
4478//______________________________________________________________________________
4480{
4481 return &fPimpl->fX11CommandBuffer;
4482}
4483
4484//______________________________________________________________________________
4486{
4487 ++fCocoaDraw;
4488}
4489
4490//______________________________________________________________________________
4492{
4493 assert(fCocoaDraw > 0 && "CocoaDrawOFF, was already off");
4494 --fCocoaDraw;
4495}
4496
4497//______________________________________________________________________________
4499{
4500 return bool(fCocoaDraw);
4501}
4502
4503//______________________________________________________________________________
4505{
4506 NSObject<X11Drawable> * const drawable = fPimpl->GetDrawable(fSelectedDrawable);
4507 if (!drawable.fIsPixmap) {
4508 Error("GetCurrentContext", "TCanvas/TPad's internal error,"
4509 " selected drawable is not a pixmap!");
4510 return 0;
4511 }
4512
4513 return drawable.fContext;
4514}
4515
4516//______________________________________________________________________________
4518{
4519 //We start ROOT in a terminal window, so it's considered as a
4520 //background process. Background process has a lot of problems
4521 //if it tries to create and manage windows.
4522 //So, first time we convert process to foreground, next time
4523 //we make it front.
4524
4525 if (!fForegroundProcess) {
4526 ProcessSerialNumber psn = {0, kCurrentProcess};
4527
4528 const OSStatus res1 = TransformProcessType(&psn, kProcessTransformToForegroundApplication);
4529
4530 //When TGCocoa's functions are called from the python (Apple's system version),
4531 //TransformProcessType fails with paramErr (looks like process is _already_ foreground),
4532 //why is it a paramErr - I've no idea.
4533 if (res1 != noErr && res1 != paramErr) {
4534 Error("MakeProcessForeground", "TransformProcessType failed with code %d", int(res1));
4535 return false;
4536 }
4537#ifdef MAC_OS_X_VERSION_10_9
4538 //Instead of quite transparent Carbon calls we now have another black-box function.
4539 [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
4540#else
4541 const OSErr res2 = SetFrontProcess(&psn);
4542 if (res2 != noErr) {
4543 Error("MakeProcessForeground", "SetFrontProcess failed with code %d", res2);
4544 return false;
4545 }
4546#endif
4547
4548 fForegroundProcess = true;
4549 } else {
4550#ifdef MAC_OS_X_VERSION_10_9
4551 //Instead of quite transparent Carbon calls we now have another black-box function.
4552 [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
4553#else
4554 ProcessSerialNumber psn = {};
4555
4556 OSErr res = GetCurrentProcess(&psn);
4557 if (res != noErr) {
4558 Error("MakeProcessForeground", "GetCurrentProcess failed with code %d", res);
4559 return false;
4560 }
4561
4562 res = SetFrontProcess(&psn);
4563 if (res != noErr) {
4564 Error("MapProcessForeground", "SetFrontProcess failed with code %d", res);
4565 return false;
4566 }
4567#endif
4568 }
4569
4570 return true;
4571}
4572
4573//______________________________________________________________________________
4574Atom_t TGCocoa::FindAtom(const std::string &atomName, bool addIfNotFound)
4575{
4576 const std::map<std::string, Atom_t>::const_iterator it = fNameToAtom.find(atomName);
4577
4578 if (it != fNameToAtom.end())
4579 return it->second;
4580 else if (addIfNotFound) {
4581 //Create a new atom.
4582 fAtomToName.push_back(atomName);
4583 fNameToAtom[atomName] = Atom_t(fAtomToName.size());
4584
4585 return Atom_t(fAtomToName.size());
4586 }
4587
4588 return kNone;
4589}
4590
4591//______________________________________________________________________________
4593{
4594 if (gEnv) {
4595 const char * const iconDirectoryPath = gEnv->GetValue("Gui.IconPath",TROOT::GetIconPath());
4596 if (iconDirectoryPath) {
4597 const Util::ScopedArray<char> fileName(gSystem->Which(iconDirectoryPath, "Root6Icon.png", kReadPermission));
4598 if (fileName.Get()) {
4599 const Util::AutoreleasePool pool;
4600 //Aha, ASCII ;) do not install ROOT in ...
4601 NSString *cocoaStr = [NSString stringWithCString : fileName.Get() encoding : NSASCIIStringEncoding];
4602 NSImage *image = [[[NSImage alloc] initWithContentsOfFile : cocoaStr] autorelease];
4603 [NSApp setApplicationIconImage : image];
4604 }
4605 }
4606 }
4607}
Handle_t Atom_t
WM token.
Definition GuiTypes.h:38
Handle_t Region_t
Region handle.
Definition GuiTypes.h:33
const Mask_t kGCCapStyle
Definition GuiTypes.h:293
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
const Mask_t kGCArcMode
Definition GuiTypes.h:309
EGEventType
Definition GuiTypes.h:60
@ kUnmapNotify
Definition GuiTypes.h:63
@ kSelectionNotify
Definition GuiTypes.h:64
@ kDestroyNotify
Definition GuiTypes.h:63
@ kSelectionRequest
Definition GuiTypes.h:64
const Mask_t kGCDashOffset
Definition GuiTypes.h:307
const Mask_t kGCBackground
Definition GuiTypes.h:290
const Mask_t kGCForeground
Definition GuiTypes.h:289
const Mask_t kGCLineStyle
Definition GuiTypes.h:292
const Mask_t kGCSubwindowMode
Definition GuiTypes.h:302
const Mask_t kGCLineWidth
Definition GuiTypes.h:291
ECursor
Definition GuiTypes.h:373
@ kPointer
Definition GuiTypes.h:376
Handle_t Pixmap_t
Pixmap handle.
Definition GuiTypes.h:31
const Mask_t kGCTile
Definition GuiTypes.h:297
const Mask_t kGCClipXOrigin
Definition GuiTypes.h:304
Handle_t FontH_t
Font handle (as opposed to Font_t which is an index)
Definition GuiTypes.h:36
Handle_t Visual_t
Visual handle.
Definition GuiTypes.h:28
const Mask_t kGCDashList
Definition GuiTypes.h:308
const Mask_t kGCFillStyle
Definition GuiTypes.h:295
Handle_t Window_t
Window handle.
Definition GuiTypes.h:29
const Mask_t kGCJoinStyle
Definition GuiTypes.h:294
Handle_t Display_t
Display handle.
Definition GuiTypes.h:27
const Mask_t kGCFunction
Definition GuiTypes.h:287
ULong_t Time_t
Event time.
Definition GuiTypes.h:43
Handle_t GContext_t
Graphics context handle.
Definition GuiTypes.h:39
EInitialState
Initial window mapping state.
Definition GuiTypes.h:346
const Mask_t kGCTileStipXOrigin
Definition GuiTypes.h:299
Handle_t Drawable_t
Drawable handle.
Definition GuiTypes.h:32
const Mask_t kGCFont
Definition GuiTypes.h:301
Handle_t Cursor_t
Cursor handle.
Definition GuiTypes.h:35
const Handle_t kNone
Definition GuiTypes.h:89
const Mask_t kStructureNotifyMask
Definition GuiTypes.h:167
@ kIsViewable
Definition GuiTypes.h:47
@ kFillOpaqueStippled
Definition GuiTypes.h:52
@ kLineDoubleDash
Definition GuiTypes.h:49
@ kFillStippled
Definition GuiTypes.h:52
@ kLineSolid
Definition GuiTypes.h:49
@ kLineOnOffDash
Definition GuiTypes.h:49
@ kFillTiled
Definition GuiTypes.h:52
const Mask_t kGCFillRule
Definition GuiTypes.h:296
const Mask_t kGCPlaneMask
Definition GuiTypes.h:288
const Mask_t kGCStipple
Definition GuiTypes.h:298
const Mask_t kGCGraphicsExposures
Definition GuiTypes.h:303
const Mask_t kGCClipYOrigin
Definition GuiTypes.h:305
const Mask_t kGCClipMask
Definition GuiTypes.h:306
const Mask_t kGCTileStipYOrigin
Definition GuiTypes.h:300
EMouseButton
Button names.
Definition GuiTypes.h:215
Handle_t Colormap_t
Colormap handle.
Definition GuiTypes.h:34
ULongptr_t Handle_t
Generic resource handle.
Definition GuiTypes.h:26
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:40
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
cudaEvent_t event
double * dst
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Color_t
Color number (short)
Definition RtypesCore.h:100
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:53
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:70
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
#define X(type, name)
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
#define gClient
Definition TGClient.h:157
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorMaximize
Definition TGFrame.h:69
@ kMWMDecorMinimize
Definition TGFrame.h:68
@ kMWMDecorAll
Definition TGFrame.h:63
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void chupy
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void pixel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void clipboard
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize DestroySubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void chupx
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t CopyArea
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void foreground
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char bitmap
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void funcs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t win
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetCursor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t grab
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void when
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t gval
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t property
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list ConvertSelection
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:142
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:417
@ kReadPermission
Definition TSystem.h:55
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define R__LOCKGUARD(mutex)
#define gVirtualX
Definition TVirtualX.h:391
DerivedType * Get() const
Definition CocoaUtils.h:136
void Reset(NSObject *object)
Definition CocoaUtils.h:141
The color creation and management class.
Definition TColor.h:23
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1941
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
This class implements TVirtualX interface for MacOS X, using Cocoa and Quartz 2D.
Definition TGCocoa.h:57
void DeleteFont(FontStruct_t fs) override
Explicitly deletes the font structure "fs" obtained via LoadQueryFont().
Definition TGCocoa.mm:2902
Int_t WriteGIF(char *name) override
Writes the current window into GIF file.
Definition TGCocoa.mm:4242
void SetCharacterUp(Float_t chupx, Float_t chupy) override
Sets character up vector.
Definition TGCocoa.mm:4175
Bool_t IsDNDAware(Window_t win, Atom_t *typelist) override
Checks if the Window is DND aware, and knows any of the DND formats passed in argument.
Definition TGCocoa.mm:4048
Pixmap_t CreatePixmap(Drawable_t wid, UInt_t w, UInt_t h) override
Creates a pixmap of the specified width and height and returns a pixmap ID that identifies it.
Definition TGCocoa.mm:2494
void TranslateCoordinates(Window_t src, Window_t dest, Int_t src_x, Int_t src_y, Int_t &dest_x, Int_t &dest_y, Window_t &child) override
Translates coordinates in one window to the coordinate space of another window.
Definition TGCocoa.mm:1395
void GetRegionBox(Region_t reg, Rectangle_t *rect) override
Returns smallest enclosing rectangle.
Definition TGCocoa.mm:4465
Window_t GetParent(Window_t wid) const override
Returns the parent of the window "id".
Definition TGCocoa.mm:1564
Double_t GetOpenGLScalingFactor() override
On a HiDPI resolution it can be > 1., this means glViewport should use scaled width and height.
Definition TGCocoa.mm:3263
void GetCharacterUp(Float_t &chupx, Float_t &chupy) override
Returns character up vector.
Definition TGCocoa.mm:4116
UInt_t ScreenWidthMM() const override
Returns the width of the screen in millimeters.
Definition TGCocoa.mm:553
std::vector< GCValues_t > fX11Contexts
Definition TGCocoa.h:463
void GrabPointer(Window_t wid, UInt_t evmask, Window_t confine, Cursor_t cursor, Bool_t grab=kTRUE, Bool_t owner_events=kTRUE) override
Establishes an active pointer grab.
Definition TGCocoa.mm:2745
void DrawLineAux(Drawable_t wid, const GCValues_t &gcVals, Int_t x1, Int_t y1, Int_t x2, Int_t y2)
Definition TGCocoa.mm:1757
~TGCocoa() override
Definition TGCocoa.mm:481
EDrawMode GetDrawModeW(WinContext_t wctxt) override
Returns window draw mode.
Definition TGCocoa.mm:714
TGCocoa()
Definition TGCocoa.mm:430
Int_t GetProperty(Window_t, Atom_t, Long_t, Long_t, Bool_t, Atom_t, Atom_t *, Int_t *, ULong_t *, ULong_t *, unsigned char **) override
Returns the actual type of the property; the actual format of the property; the number of 8-bit,...
Definition TGCocoa.mm:3797
void ReparentTopLevel(Window_t wid, Window_t pid, Int_t x, Int_t y)
Definition TGCocoa.mm:1149
void SetDoubleBufferON() override
Turns double buffer mode on.
Definition TGCocoa.mm:3545
void PutPixel(Drawable_t wid, Int_t x, Int_t y, ULong_t pixel) override
Overwrites the pixel in the image with the specified pixel value.
Definition TGCocoa.mm:2667
Bool_t IsCocoaDraw() const
Definition TGCocoa.mm:4498
void GetWindowSize(Drawable_t wid, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override
Returns the location and the size of window "id".
Definition TGCocoa.mm:1470
void SetApplicationIcon()
Definition TGCocoa.mm:4592
void SetWindowBackgroundPixmap(Window_t wid, Pixmap_t pxm) override
Sets the background pixmap of the window "id" to the specified pixmap "pxm".
Definition TGCocoa.mm:1518
bool fDisplayShapeChanged
Definition TGCocoa.h:472
void DeleteOpenGLContext(Int_t ctxID) override
Deletes OpenGL context for window "wid".
Definition TGCocoa.mm:3485
Bool_t AllocColor(Colormap_t cmap, ColorStruct_t &color) override
Allocates a read-only colormap entry corresponding to the closest RGB value supported by the hardware...
Definition TGCocoa.mm:2983
Bool_t EqualRegion(Region_t rega, Region_t regb) override
Returns kTRUE if the two regions have the same offset, size, and shape.
Definition TGCocoa.mm:4457
void CopyPixmap(Int_t wid, Int_t xpos, Int_t ypos) override
Copies the pixmap "wid" at the position [xpos,ypos] in the current window.
Definition TGCocoa.mm:2438
void FreeFontStruct(FontStruct_t fs) override
Frees the font structure "fs".
Definition TGCocoa.mm:2940
void DestroySubwindows(Window_t wid) override
The DestroySubwindows function destroys all inferior windows of the specified window,...
Definition TGCocoa.mm:1021
Int_t OpenPixmap(UInt_t w, UInt_t h) override
Creates a pixmap of the width "w" and height "h" you specified.
Definition TGCocoa.mm:2391
Int_t TextWidth(FontStruct_t font, const char *s, Int_t len) override
Return length of the string "s" in pixels. Size depends on font.
Definition TGCocoa.mm:2915
void ResizeWindow(Int_t wid) override
Resizes the window "wid" if necessary.
Definition TGCocoa.mm:849
void UpdateWindowW(WinContext_t wctxt, Int_t mode) override
Update specified window.
Definition TGCocoa.mm:745
void FillRectangleAux(Drawable_t wid, const GCValues_t &gcVals, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition TGCocoa.mm:1949
Atom_t FindAtom(const std::string &atomName, bool addIfNotFound)
Definition TGCocoa.mm:4574
ROOT::MacOSX::X11::CommandBuffer * GetCommandBuffer() const
Definition TGCocoa.mm:4479
void ChangeGC(GContext_t gc, GCValues_t *gval) override
Changes the components specified by the mask in gval for the specified GC.
Definition TGCocoa.mm:3078
void CopyAreaAux(Drawable_t src, Drawable_t dst, const GCValues_t &gc, Int_t srcX, Int_t srcY, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY)
Definition TGCocoa.mm:2161
void SetDoubleBufferOFF() override
Turns double buffer mode off.
Definition TGCocoa.mm:3528
bool fForegroundProcess
Definition TGCocoa.h:462
void DrawRectangleAux(Drawable_t wid, const GCValues_t &gcVals, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition TGCocoa.mm:1880
void Bell(Int_t percent) override
Sets the sound bell. Percent is loudness from -100% to 100%.
Definition TGCocoa.mm:4343
void SetWMState(Window_t winID, EInitialState state) override
Sets the initial state of the window "id": either kNormalState or kIconicState.
Definition TGCocoa.mm:1713
Window_t GetWindowID(Int_t wid) override
Returns the X11 window identifier.
Definition TGCocoa.mm:674
void SetWMSizeHints(Window_t winID, UInt_t wMin, UInt_t hMin, UInt_t wMax, UInt_t hMax, UInt_t wInc, UInt_t hInc) override
Gives the window manager minimum and maximum size hints of the window "id".
Definition TGCocoa.mm:1697
void LookupString(Event_t *event, char *buf, Int_t buflen, UInt_t &keysym) override
Converts the keycode from the event structure to a key symbol (according to the modifiers specified i...
Definition TGCocoa.mm:2855
Cursor_t CreateCursor(ECursor cursor) override
Creates the specified cursor.
Definition TGCocoa.mm:3173
Window_t GetCurrentWindow() const override
pointer to the current internal window used in canvas graphics
Definition TGCocoa.mm:893
void IntersectRegion(Region_t rega, Region_t regb, Region_t result) override
Computes the intersection of two regions.
Definition TGCocoa.mm:4413
std::unique_ptr< ROOT::MacOSX::Details::CocoaPrivate > fPimpl
!
Definition TGCocoa.h:451
void SetWindowName(Window_t wid, char *name) override
Sets the window name.
Definition TGCocoa.mm:1577
void Warp(Int_t ix, Int_t iy, Window_t wid) override
Sets the pointer position.
Definition TGCocoa.mm:4213
void IconifyWindow(Window_t wid) override
Iconifies the window "id".
Definition TGCocoa.mm:1368
Int_t ResizePixmap(Int_t wid, UInt_t w, UInt_t h) override
Resizes the specified pixmap "wid".
Definition TGCocoa.mm:2411
void * GetCurrentContext()
Definition TGCocoa.mm:4504
Window_t GetInputFocus() override
Returns the window id of the window having the input focus.
Definition TGCocoa.mm:2835
Colormap_t GetColormap() const override
Returns handle to colormap.
Definition TGCocoa.mm:3045
void DrawRectangle(Drawable_t wid, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Draws rectangle outlines of [x,y] [x+w,y] [x+w,y+h] [x,y+h].
Definition TGCocoa.mm:1914
void FreeColor(Colormap_t cmap, ULong_t pixel) override
Frees color cell with specified pixel value.
Definition TGCocoa.mm:3002
Bool_t NeedRedraw(ULong_t tgwindow, Bool_t force) override
Notify the low level GUI layer ROOT requires "tgwindow" to be updated.
Definition TGCocoa.mm:4261
void DeleteGC(GContext_t gc) override
Deletes the specified GC "gc".
Definition TGCocoa.mm:3165
void ClearWindowW(WinContext_t wctxt) override
Clear specified window.
Definition TGCocoa.mm:722
EDrawMode fDrawMode
Definition TGCocoa.h:454
void SetDNDAware(Window_t, Atom_t *) override
Add XdndAware property and the list of drag and drop types to the Window win.
Definition TGCocoa.mm:3997
Int_t AddPixmap(ULong_t pixid, UInt_t w, UInt_t h) override
Registers a pixmap created by TGLManager as a ROOT pixmap.
Definition TGCocoa.mm:2616
void DestroyWindow(Window_t wid) override
Destroys the window "id" as well as all of its subwindows.
Definition TGCocoa.mm:963
void ShapeCombineMask(Window_t wid, Int_t x, Int_t y, Pixmap_t mask) override
The Non-rectangular Window Shape Extension adds non-rectangular windows to the System.
Definition TGCocoa.mm:1611
void GetPlanes(Int_t &nplanes) override
Returns the maximum number of planes.
Definition TGCocoa.mm:3023
void UpdateWindow(Int_t mode) override
Updates or synchronises client and server once (not permanent).
Definition TGCocoa.mm:872
void CocoaDrawOFF()
Definition TGCocoa.mm:4491
Int_t SupportsExtension(const char *extensionName) const override
Returns 1 if window system server supports extension given by the argument, returns 0 in case extensi...
Definition TGCocoa.mm:519
Int_t GetScreen() const override
Returns screen number.
Definition TGCocoa.mm:546
Bool_t HasTTFonts() const override
Returns True when TrueType fonts are used.
Definition TGCocoa.mm:2908
void SetWindowBackground(Window_t wid, ULong_t color) override
Sets the background of the window "id" to the specified color value "color".
Definition TGCocoa.mm:1506
Bool_t ReadPictureDataFromFile(const char *filename, char ***ret_data) override
Reads picture data from file "filename" and store it in "ret_data".
Definition TGCocoa.mm:4309
void DestroyRegion(Region_t reg) override
Destroys the region "reg".
Definition TGCocoa.mm:4373
void GetRGB(Int_t index, Float_t &r, Float_t &g, Float_t &b) override
Returns RGB values for color "index".
Definition TGCocoa.mm:3030
void CopyPixmapW(WinContext_t wctxt, Int_t wid, Int_t xpos, Int_t ypos) override
Copy pixmap to specified window.
Definition TGCocoa.mm:2447
unsigned char * GetColorBits(Drawable_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Returns an array of pixels created from a part of drawable (defined by x, y, w, h) in format:
Definition TGCocoa.mm:2625
void SendEvent(Window_t wid, Event_t *ev) override
Specifies the event "ev" is to be sent to the window "id".
Definition TGCocoa.mm:3595
Int_t KeysymToKeycode(UInt_t keysym) override
Converts the "keysym" to the appropriate keycode.
Definition TGCocoa.mm:2824
void QueryColor(Colormap_t cmap, ColorStruct_t &color) override
Returns the current RGB value for the pixel in the "color" structure.
Definition TGCocoa.mm:2993
void MoveWindow(Int_t wid, Int_t x, Int_t y) override
Moves the window "wid" to the specified x and y coordinates.
Definition TGCocoa.mm:827
void SelectInput(Window_t wid, UInt_t evmask) override
Defines which input events the window is interested in.
Definition TGCocoa.mm:1082
void ClearWindow() override
Clears the entire area of the current window.
Definition TGCocoa.mm:775
void SetClipRectangles(GContext_t gc, Int_t x, Int_t y, Rectangle_t *recs, Int_t n) override
Sets clipping rectangles in graphics context.
Definition TGCocoa.mm:4355
Bool_t CreatePictureFromData(Drawable_t wid, char **data, Pixmap_t &pict, Pixmap_t &pict_mask, PictureAttributes_t &attr) override
Creates a picture pict from data in bitmap format.
Definition TGCocoa.mm:4296
void DrawString(Drawable_t wid, GContext_t gc, Int_t x, Int_t y, const char *s, Int_t len) override
Each character image, as defined by the font in the GC, is treated as an additional mask for a fill o...
Definition TGCocoa.mm:2279
std::vector< std::string > fAtomToName
Definition TGCocoa.h:466
void XorRegion(Region_t rega, Region_t regb, Region_t result) override
Calculates the difference between the union and intersection of two regions.
Definition TGCocoa.mm:4429
void SetTextMagnitude(Float_t mgn) override
Sets the current text magnification factor to "mgn".
Definition TGCocoa.mm:4198
FontStruct_t GetFontStruct(FontH_t fh) override
Retrieves the associated font structure of the font specified font handle "fh".
Definition TGCocoa.mm:2929
void SetMWMHints(Window_t winID, UInt_t value, UInt_t decorators, UInt_t inputMode) override
Sets decoration style.
Definition TGCocoa.mm:1645
Handle_t GetCurrentOpenGLContext() override
Asks OpenGL subsystem about the current OpenGL context.
Definition TGCocoa.mm:3453
Bool_t MakeOpenGLContextCurrent(Handle_t ctx, Window_t windowID) override
Makes context ctx current OpenGL context.
Definition TGCocoa.mm:3376
void SetPrimarySelectionOwner(Window_t wid) override
Makes the window "id" the current owner of the primary selection.
Definition TGCocoa.mm:3665
void GetGCValues(GContext_t gc, GCValues_t &gval) override
Returns the components specified by the mask in "gval" for the specified GC "gc" (see also the GCValu...
Definition TGCocoa.mm:3156
void SetRGB(Int_t cindex, Float_t r, Float_t g, Float_t b) override
Sets color intensities the specified color index "cindex".
Definition TGCocoa.mm:3036
void MapRaised(Window_t wid) override
Maps the window "id" and all of its subwindows that have had map requests on the screen and put this ...
Definition TGCocoa.mm:1223
Pixmap_t CreatePixmapFromData(unsigned char *bits, UInt_t width, UInt_t height) override
create pixmap from RGB data.
Definition TGCocoa.mm:2534
void SetClipOFF(Int_t wid) override
Turns off the clipping for the window "wid".
Definition TGCocoa.mm:4181
void GetWindowAttributes(Window_t wid, WindowAttributes_t &attr) override
The WindowAttributes_t structure is set to default.
Definition TGCocoa.mm:1052
Int_t RequestString(Int_t x, Int_t y, char *text) override
Requests string: text is displayed and can be edited with Emacs-like keybinding.
Definition TGCocoa.mm:4164
void ChangeActivePointerGrab(Window_t, UInt_t, Cursor_t) override
Changes the specified dynamic parameters if the pointer is actively grabbed by the client and if the ...
Definition TGCocoa.mm:2766
Bool_t CheckEvent(Window_t wid, EGEventType type, Event_t &ev) override
Check if there is for window "id" an event of type "type".
Definition TGCocoa.mm:3626
Int_t OpenDisplay(const char *displayName) override
Opens connection to display server (if such a thing exist on the current platform).
Definition TGCocoa.mm:499
static Atom_t fgDeleteWindowAtom
Definition TGCocoa.h:476
void QueryPointer(Int_t &x, Int_t &y) override
Returns the pointer position.
Definition TGCocoa.mm:3210
void SetDrawMode(EDrawMode mode) override
Sets the drawing mode.
Definition TGCocoa.mm:3579
Bool_t ParseColor(Colormap_t cmap, const char *cname, ColorStruct_t &color) override
Looks up the string name of a color "cname" with respect to the screen associated with the specified ...
Definition TGCocoa.mm:2974
void GetImageSize(Drawable_t wid, UInt_t &width, UInt_t &height) override
Returns the width and height of the image id.
Definition TGCocoa.mm:2656
Int_t InitWindow(ULong_t window) override
Creates a new window and return window number.
Definition TGCocoa.mm:649
void CloseDisplay() override
Closes connection to display server and destroys all windows.
Definition TGCocoa.mm:526
void ClearArea(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Paints a rectangular area in the specified window "id" according to the specified dimensions with the...
Definition TGCocoa.mm:2352
void DeletePixmap(Pixmap_t pixmapID) override
Explicitly deletes the pixmap resource "pmap".
Definition TGCocoa.mm:2608
void MapSubwindows(Window_t wid) override
Maps all subwindows for the specified window "id" in top-to-bottom stacking order.
Definition TGCocoa.mm:1209
void ReparentWindow(Window_t wid, Window_t pid, Int_t x, Int_t y) override
If the specified window is mapped, ReparentWindow automatically performs an UnmapWindow request on it...
Definition TGCocoa.mm:1171
Window_t GetDefaultRootWindow() const override
Returns handle to the default root window created when calling XOpenDisplay().
Definition TGCocoa.mm:642
void SetDoubleBuffer(Int_t wid, Int_t mode) override
Sets the double buffer on/off on the window "wid".
Definition TGCocoa.mm:3507
void GetGeometry(Int_t wid, Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override
Returns position and size of window "wid".
Definition TGCocoa.mm:785
WinContext_t GetWindowContext(Int_t wid) override
Get window drawing context Should remain valid until window exists.
Definition TGCocoa.mm:690
void RemoveWindow(ULong_t qwid) override
Removes the created by Qt window "qwid".
Definition TGCocoa.mm:916
Bool_t CreatePictureFromFile(Drawable_t wid, const char *filename, Pixmap_t &pict, Pixmap_t &pict_mask, PictureAttributes_t &attr) override
Creates a picture pict from data in file "filename".
Definition TGCocoa.mm:4281
void DrawStringAux(Drawable_t wid, const GCValues_t &gc, Int_t x, Int_t y, const char *s, Int_t len)
Definition TGCocoa.mm:2235
void GetPasteBuffer(Window_t wid, Atom_t atom, TString &text, Int_t &nchar, Bool_t del) override
Gets contents of the paste buffer "atom" into the string "text".
Definition TGCocoa.mm:3844
Drawable_t CreateImage(UInt_t width, UInt_t height) override
Allocates the memory needed for an drawable.
Definition TGCocoa.mm:2646
void Update(Int_t mode) override
Flushes (mode = 0, default) or synchronizes (mode = 1) X output buffer.
Definition TGCocoa.mm:580
Atom_t InternAtom(const char *atom_name, Bool_t only_if_exist) override
Returns the atom identifier associated with the specified "atom_name" string.
Definition TGCocoa.mm:3656
Handle_t CreateOpenGLContext(Window_t windowID, Handle_t sharedContext) override
Creates OpenGL context for window "windowID".
Definition TGCocoa.mm:3351
void ChangeWindowAttributes(Window_t wid, SetWindowAttributes_t *attr) override
Changes the attributes of the specified window "id" according the values provided in "attr".
Definition TGCocoa.mm:1066
GContext_t CreateGC(Drawable_t wid, GCValues_t *gval) override
Creates a graphics context using the provided GCValues_t *gval structure.
Definition TGCocoa.mm:3053
Int_t AddWindow(ULong_t qwid, UInt_t w, UInt_t h) override
Registers a window created by Qt as a ROOT window.
Definition TGCocoa.mm:906
void UnmapWindow(Window_t wid) override
Unmaps the specified window "id".
Definition TGCocoa.mm:1244
void ClearAreaAux(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition TGCocoa.mm:2312
void GrabButton(Window_t wid, EMouseButton button, UInt_t modifier, UInt_t evmask, Window_t confine, Cursor_t cursor, Bool_t grab=kTRUE) override
Establishes a passive grab on a certain mouse button.
Definition TGCocoa.mm:2711
Bool_t EmptyRegion(Region_t reg) override
Returns kTRUE if the region reg is empty.
Definition TGCocoa.mm:4441
void ConvertSelection(Window_t, Atom_t &, Atom_t &, Atom_t &, Time_t &) override
Requests that the specified selection be converted to the specified target type.
Definition TGCocoa.mm:3762
void ReconfigureDisplay()
Definition TGCocoa.mm:604
void RaiseWindow(Window_t wid) override
Raises the specified window to the top of the stack so that no sibling window obscures it.
Definition TGCocoa.mm:1274
void DrawSegments(Drawable_t wid, GContext_t gc, Segment_t *segments, Int_t nSegments) override
Draws multiple line segments.
Definition TGCocoa.mm:1845
ROOT::MacOSX::X11::Rectangle GetDisplayGeometry() const
Definition TGCocoa.mm:610
void MapWindow(Window_t wid) override
Maps the window "id" and all of its subwindows that have had map requests.
Definition TGCocoa.mm:1189
void SetWMSize(Window_t winID, UInt_t w, UInt_t h) override
Tells window manager the desired size of window "id".
Definition TGCocoa.mm:1691
WinContext_t GetSelectedContext()
Definition TGCocoa.mm:699
void SetDashes(GContext_t gc, Int_t offset, const char *dash_list, Int_t n) override
Sets the dash-offset and dash-list attributes for dashed line styles in the specified GC.
Definition TGCocoa.mm:4324
void SetClipRegion(Int_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Sets clipping region for the window "wid".
Definition TGCocoa.mm:4187
Bool_t PointInRegion(Int_t x, Int_t y, Region_t reg) override
Returns kTRUE if the point [x, y] is contained in the region reg.
Definition TGCocoa.mm:4449
Window_t FindRWindow(Window_t win, Window_t dragwin, Window_t input, int x, int y, int maxd) override
Recursively search in the children of Window for a Window which is at location x, y and is DND aware,...
Definition TGCocoa.mm:4071
void RescaleWindow(Int_t wid, UInt_t w, UInt_t h) override
Rescales the window "wid".
Definition TGCocoa.mm:841
char ** ListFonts(const char *fontname, Int_t max, Int_t &count) override
Returns list of font names matching fontname regexp, like "-*-times-*".
Definition TGCocoa.mm:2948
void WritePixmap(Int_t wid, UInt_t w, UInt_t h, char *pxname) override
Writes the pixmap "wid" in the bitmap file "pxname".
Definition TGCocoa.mm:4251
void CopyGC(GContext_t org, GContext_t dest, Mask_t mask) override
Copies the specified components from the source GC "org" to the destination GC "dest".
Definition TGCocoa.mm:3144
ROOT::MacOSX::X11::EventTranslator * GetEventTranslator() const
Definition TGCocoa.mm:4473
void ReparentChild(Window_t wid, Window_t pid, Int_t x, Int_t y)
Definition TGCocoa.mm:1102
void DrawSegmentsAux(Drawable_t wid, const GCValues_t &gcVals, const Segment_t *segments, Int_t nSegments)
Definition TGCocoa.mm:1834
void GrabKey(Window_t wid, Int_t keycode, UInt_t modifier, Bool_t grab=kTRUE) override
Establishes a passive grab on the keyboard.
Definition TGCocoa.mm:2782
bool fDirectDraw
Definition TGCocoa.h:455
void DeletePictureData(void *data) override
Delete picture data created by the function ReadPictureDataFromFile.
Definition TGCocoa.mm:4318
Int_t EventsPending() override
Returns the number of events that have been received from the X server but have not been removed from...
Definition TGCocoa.mm:3619
void SelectWindow(Int_t wid) override
Selects the window "wid" to which subsequent output is directed.
Definition TGCocoa.mm:683
void UnionRectWithRegion(Rectangle_t *rect, Region_t src, Region_t dest) override
Updates the destination region from a union of the specified rectangle and the specified source regio...
Definition TGCocoa.mm:4379
Display_t GetDisplay() const override
Returns handle to display (might be useful in some cases where direct X11 manipulation outside of TVi...
Definition TGCocoa.mm:532
void FlushOpenGLBuffer(Handle_t ctxID) override
Flushes OpenGL buffer.
Definition TGCocoa.mm:3470
void NextEvent(Event_t &event) override
The "event" is set to default event.
Definition TGCocoa.mm:3610
void SetIconName(Window_t wid, char *name) override
Sets the window icon name.
Definition TGCocoa.mm:1593
Bool_t Init(void *display) override
Initializes the X system.
Definition TGCocoa.mm:490
void DeletePixmapAux(Pixmap_t pixmapID)
Definition TGCocoa.mm:2602
void ClosePixmap() override
Deletes current pixmap.
Definition TGCocoa.mm:2480
Pixmap_t CreateBitmap(Drawable_t wid, const char *bitmap, UInt_t width, UInt_t height) override
Creates a bitmap (i.e.
Definition TGCocoa.mm:2565
void SetKeyAutoRepeat(Bool_t on=kTRUE) override
Turns key auto repeat on (kTRUE) or off (kFALSE).
Definition TGCocoa.mm:2775
void FreeFontNames(char **fontlist) override
Frees the specified the array of strings "fontlist".
Definition TGCocoa.mm:2962
void UnionRegion(Region_t rega, Region_t regb, Region_t result) override
Computes the union of two regions.
Definition TGCocoa.mm:4402
Window_t GetPrimarySelectionOwner() override
Returns the window id of the current owner of the primary selection.
Definition TGCocoa.mm:3714
void SetWMPosition(Window_t winID, Int_t x, Int_t y) override
Tells the window manager the desired position [x,y] of window "id".
Definition TGCocoa.mm:1685
void SetWMTransientHint(Window_t winID, Window_t mainWinID) override
Tells window manager that the window "id" is a transient window of the window "main_id".
Definition TGCocoa.mm:1719
void CocoaDrawON()
Definition TGCocoa.mm:4485
void SetIconPixmap(Window_t wid, Pixmap_t pix) override
Sets the icon name pixmap.
Definition TGCocoa.mm:1599
Pixmap_t ReadGIF(Int_t x0, Int_t y0, const char *file, Window_t wid) override
If id is NULL - loads the specified gif file at position [x0,y0] in the current window.
Definition TGCocoa.mm:4123
void LowerWindow(Window_t wid) override
Lowers the specified window "id" to the bottom of the stack so that it does not obscure any sibling w...
Definition TGCocoa.mm:1291
Bool_t SetSelectionOwner(Window_t windowID, Atom_t &selectionID) override
Changes the owner and last-change time for the specified selection.
Definition TGCocoa.mm:3691
Handle_t GetNativeEvent() const override
Returns the current native event handle.
Definition TGCocoa.mm:3646
void SubtractRegion(Region_t rega, Region_t regb, Region_t result) override
Subtracts regb from rega and stores the results in result.
Definition TGCocoa.mm:4423
void FillRectangle(Drawable_t wid, GContext_t gc, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Fills the specified rectangle defined by [x,y] [x+w,y] [x+w,y+h] [x,y+h].
Definition TGCocoa.mm:2014
Region_t CreateRegion() override
Creates a new empty region.
Definition TGCocoa.mm:4365
Int_t fCocoaDraw
Definition TGCocoa.h:452
void SelectPixmap(Int_t qpixid) override
Selects the pixmap "qpixid".
Definition TGCocoa.mm:2429
void ConvertPrimarySelection(Window_t wid, Atom_t clipboard, Time_t when) override
Causes a SelectionRequest event to be sent to the current primary selection owner.
Definition TGCocoa.mm:3728
void GetFontProperties(FontStruct_t font, Int_t &max_ascent, Int_t &max_descent) override
Returns the font properties.
Definition TGCocoa.mm:2922
void DrawLine(Drawable_t wid, GContext_t gc, Int_t x1, Int_t y1, Int_t x2, Int_t y2) override
Uses the components of the specified GC to draw a line between the specified set of points (x1,...
Definition TGCocoa.mm:1797
void ChangeProperty(Window_t wid, Atom_t property, Atom_t type, UChar_t *data, Int_t len) override
Alters the property for the specified window and causes the X server to generate a PropertyNotify eve...
Definition TGCocoa.mm:3895
void SetTypeList(Window_t win, Atom_t prop, Atom_t *typelist) override
Add the list of drag and drop types to the Window win.
Definition TGCocoa.mm:4063
bool fSetApp
Definition TGCocoa.h:471
Region_t PolygonRegion(Point_t *points, Int_t np, Bool_t winding) override
Returns a region for the polygon defined by the points array.
Definition TGCocoa.mm:4390
Int_t GetDoubleBuffer(Int_t wid) override
Queries the double buffer value for the window "wid".
Definition TGCocoa.mm:4109
void SetClassHints(Window_t wid, char *className, char *resourceName) override
Sets the windows class and resource name.
Definition TGCocoa.mm:1605
Window_t CreateWindow(Window_t parent, Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth, UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype) override
Creates an unmapped subwindow for a specified parent window and returns the created window.
Definition TGCocoa.mm:922
Int_t RequestLocator(Int_t mode, Int_t ctyp, Int_t &x, Int_t &y) override
Requests Locator position.
Definition TGCocoa.mm:4132
void SetInputFocus(Window_t wid) override
Changes the input focus to specified window "id".
Definition TGCocoa.mm:2843
Visual_t GetVisual() const override
Returns handle to visual.
Definition TGCocoa.mm:539
void MoveResizeWindow(Window_t wid, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Changes the size and location of the specified window "id" without raising it.
Definition TGCocoa.mm:1326
void FillPolygonAux(Window_t wid, const GCValues_t &gcVals, const Point_t *polygon, Int_t nPoints)
Definition TGCocoa.mm:2044
Int_t GetDepth() const override
Returns depth of screen (number of bit planes).
Definition TGCocoa.mm:563
FontStruct_t LoadQueryFont(const char *font_name) override
Provides the most common way for accessing a font: opens (loads) the specified font and returns a poi...
Definition TGCocoa.mm:2876
bool MakeProcessForeground()
Definition TGCocoa.mm:4517
Window_t CreateOpenGLWindow(Window_t parentID, UInt_t width, UInt_t height, const std::vector< std::pair< UInt_t, Int_t > > &format) override
Create window with special pixel format. Noop everywhere except Cocoa.
Definition TGCocoa.mm:3272
std::map< Atom_t, Window_t > fSelectionOwners
Definition TGCocoa.h:468
void DeleteProperty(Window_t, Atom_t &) override
Deletes the specified property only if the property was defined on the specified window and causes th...
Definition TGCocoa.mm:3973
std::map< std::string, Atom_t > fNameToAtom
Definition TGCocoa.h:465
UInt_t ExecCommand(TGWin32Command *code) override
Executes the command "code" coming from the other threads (Win32)
Definition TGCocoa.mm:4102
void SetCursor(Window_t wid, Cursor_t curid) override
Sets the cursor "curid" to be used when the pointer is in the window "id".
Definition TGCocoa.mm:3199
void SetForeground(GContext_t gc, ULong_t foreground) override
Sets the foreground color for the specified GC (shortcut for ChangeGC with only foreground mask set).
Definition TGCocoa.mm:3061
FontH_t GetFontHandle(FontStruct_t fs) override
Returns the font handle of the specified font structure "fs".
Definition TGCocoa.mm:2896
void DeleteImage(Drawable_t img) override
Deallocates the memory associated with the image img.
Definition TGCocoa.mm:2700
Drawable_t fSelectedDrawable
Definition TGCocoa.h:449
void SetDrawModeW(WinContext_t wctxt, EDrawMode mode) override
Set window draw mode.
Definition TGCocoa.mm:705
void CloseWindow() override
Deletes current window.
Definition TGCocoa.mm:900
void FillPolygon(Window_t wid, GContext_t gc, Point_t *polygon, Int_t nPoints) override
Fills the region closed by the specified path.
Definition TGCocoa.mm:2116
ROOT::MacOSX::X11::Rectangle fDisplayRect
Definition TGCocoa.h:473
void WMDeleteNotify(Window_t wid) override
Tells WM to send message when window is closed via WM.
Definition TGCocoa.mm:4349
void PutImage(Drawable_t wid, GContext_t gc, Drawable_t img, Int_t dx, Int_t dy, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Combines an image with a rectangle of the specified drawable.
Definition TGCocoa.mm:2689
void CopyArea(Drawable_t src, Drawable_t dst, GContext_t gc, Int_t srcX, Int_t srcY, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY) override
Combines the specified rectangle of "src" with the specified rectangle of "dest" according to the "gc...
Definition TGCocoa.mm:2198
void Sync(Int_t mode) override
Set synchronisation on or off.
Definition TGCocoa.mm:4204
ULong_t GetPixel(Color_t cindex) override
Returns pixel value associated to specified ROOT color number "cindex".
Definition TGCocoa.mm:3008
std::map< Atom_t, Window_t >::iterator selection_iterator
Definition TGCocoa.h:469
const char * DisplayName(const char *) override
Returns hostname on which the display is opened.
Definition TGCocoa.mm:512
void ChangeProperties(Window_t wid, Atom_t property, Atom_t type, Int_t format, UChar_t *data, Int_t len) override
Alters the property for the specified window and causes the X server to generate a PropertyNotify eve...
Definition TGCocoa.mm:3938
bool CocoaInitialized() const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1082
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
static const TString & GetIconPath()
Get the icon path in the installation. Static utility function.
Definition TROOT.cxx:3502
Basic string class.
Definition TString.h:137
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
Definition TSystem.cxx:1571
Semi-Abstract base class defining a generic interface to the underlying, low level,...
Definition TVirtualX.h:47
static void ConfigureColorsHandler()
Protected method to configure handler when color is modified and need to be updated system dependent ...
TPaveText * pt
BOOL fIsStippleMask
ROOT::MacOSX::Util::CFScopeGuard< CGImageRef > fImage
unsigned fHeight
unsigned fWidth
CGContextRef fContext
unsigned fWidth()
QuartzView * fParentView
unsigned fID
QuartzImage * fBackgroundPixmap
BOOL fIsOverlapped
unsigned long fBackgroundPixel
unsigned fHeight()
NSView< X11Window > * fContentView
QuartzWindow * fMainWindow
QuartzView * fContentView
QuartzImage * fShapeCombineMask
NSOpenGLContext * fOpenGLContext
NSOpenGLPixelFormat * pixelFormat()
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
bool GLViewIsValidDrawable(ROOTOpenGLView *glView)
Int_t MapKeySymToKeyCode(Int_t keySym)
Definition X11Events.mm:178
bool ViewIsHtmlViewFrame(NSView< X11Window > *view, bool checkParent)
int GlobalYCocoaToROOT(CGFloat yCocoa)
void PixelToRGB(Pixel_t pixelColor, CGFloat *rgb)
Definition X11Colors.mm:920
void MapUnicharToKeySym(unichar key, char *buf, Int_t len, UInt_t &rootKeySym)
Definition X11Events.mm:98
void FillPixmapBuffer(const unsigned char *bitmap, unsigned width, unsigned height, ULong_t foregroundPixel, ULong_t backgroundPixel, unsigned depth, unsigned char *imageData)
NSPoint TranslateToScreen(NSView< X11Window > *from, NSPoint point)
NSView< X11Window > * FindDNDAwareViewInPoint(NSView *parentView, Window_t dragWinID, Window_t inputWinID, Int_t x, Int_t y, Int_t maxDepth)
QuartzWindow * FindWindowInPoint(Int_t x, Int_t y)
int GlobalXCocoaToROOT(CGFloat xCocoa)
void WindowLostFocus(Window_t winID)
int LocalYROOTToCocoa(NSView< X11Window > *parentView, CGFloat yROOT)
UInt_t GetModifiers()
Definition X11Events.mm:300
bool ParseXLFDName(const std::string &xlfdName, XLFDName &dst)
NSPoint TranslateCoordinates(NSView< X11Window > *fromView, NSView< X11Window > *toView, NSPoint sourcePoint)
QuartzWindow * CreateTopLevelWindow(Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth, UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t)
int GlobalXROOTToCocoa(CGFloat xROOT)
QuartzView * CreateChildView(QuartzView *parent, Int_t x, Int_t y, UInt_t w, UInt_t h, UInt_t border, Int_t depth, UInt_t clss, void *visual, SetWindowAttributes_t *attr, UInt_t wtype)
void GetRootWindowAttributes(WindowAttributes_t *attr)
void InitWithPredefinedAtoms(std::map< std::string, Atom_t > &nameToAtom, std::vector< std::string > &atomNames)
Definition X11Atoms.mm:83
bool ViewIsTextViewFrame(NSView< X11Window > *view, bool checkParent)
NSPoint TranslateFromScreen(NSPoint point, NSView< X11Window > *to)
NSUInteger GetCocoaKeyModifiersFromROOTKeyModifiers(UInt_t rootKeyModifiers)
Definition X11Events.mm:261
void DrawTextLineNoKerning(CGContextRef ctx, CTFontRef font, const std::vector< UniChar > &text, Int_t x, Int_t y)
void DrawPattern(void *data, CGContextRef ctx)
bool SetFillPattern(CGContextRef ctx, const unsigned *patternIndex, Color_t attrFillColor)
@ kDepth
Definition TVirtualGL.h:129
@ kMultiSample
Definition TVirtualGL.h:133
@ kStencil
Definition TVirtualGL.h:131
@ kDoubleBuffer
Definition TVirtualGL.h:128
@ kAccum
Definition TVirtualGL.h:130
unsigned fID
Definition X11Drawable.h:37
ULong_t fPixel
color pixel value (index in color table)
Definition GuiTypes.h:312
UShort_t fRed
red component (0..65535)
Definition GuiTypes.h:313
UShort_t fGreen
green component (0..65535)
Definition GuiTypes.h:314
UShort_t fBlue
blue component (0..65535)
Definition GuiTypes.h:315
Event structure.
Definition GuiTypes.h:175
EGEventType fType
of event (see EGEventType)
Definition GuiTypes.h:176
Window_t fWindow
window reported event is relative to
Definition GuiTypes.h:177
Longptr_t fUser[5]
5 longs can be used by client message events NOTE: only [0], [1] and [2] may be used.
Definition GuiTypes.h:188
Graphics context structure.
Definition GuiTypes.h:225
ULong_t fBackground
background pixel
Definition GuiTypes.h:229
Int_t fFillRule
kEvenOddRule, kWindingRule
Definition GuiTypes.h:237
Pixmap_t fClipMask
bitmap clipping; other calls for rects
Definition GuiTypes.h:248
Int_t fDashOffset
patterned/dashed line information
Definition GuiTypes.h:249
Int_t fClipYOrigin
Definition GuiTypes.h:247
Int_t fClipXOrigin
origin for clipping
Definition GuiTypes.h:246
Int_t fLineWidth
line width
Definition GuiTypes.h:230
Pixmap_t fStipple
stipple 1 plane pixmap for stippling
Definition GuiTypes.h:240
Mask_t fMask
bit mask specifying which fields are valid
Definition GuiTypes.h:252
Int_t fLineStyle
kLineSolid, kLineOnOffDash, kLineDoubleDash
Definition GuiTypes.h:231
Pixmap_t fTile
tile pixmap for tiling operations
Definition GuiTypes.h:239
Bool_t fGraphicsExposures
boolean, should exposures be generated
Definition GuiTypes.h:245
Int_t fJoinStyle
kJoinMiter, kJoinRound, kJoinBevel
Definition GuiTypes.h:234
Char_t fDashes[8]
dash pattern list (dash length per byte)
Definition GuiTypes.h:250
ULong_t fForeground
foreground pixel
Definition GuiTypes.h:228
ULong_t fPlaneMask
plane mask
Definition GuiTypes.h:227
Int_t fFillStyle
kFillSolid, kFillTiled, kFillStippled, kFillOpaeueStippled
Definition GuiTypes.h:235
FontH_t fFont
default text font for text operations
Definition GuiTypes.h:243
Int_t fTsXOrigin
offset for tile or stipple operations
Definition GuiTypes.h:241
EGraphicsFunction fFunction
logical operation
Definition GuiTypes.h:226
Int_t fDashLen
number of dashes in fDashes
Definition GuiTypes.h:251
Int_t fCapStyle
kCapNotLast, kCapButt, kCapRound, kCapProjecting
Definition GuiTypes.h:232
Int_t fArcMode
kArcChord, kArcPieSlice
Definition GuiTypes.h:238
Int_t fTsYOrigin
Definition GuiTypes.h:242
Int_t fSubwindowMode
kClipByChildren, kIncludeInferiors
Definition GuiTypes.h:244
Point structure (maps to the X11 XPoint structure)
Definition GuiTypes.h:357
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:362
Used for drawing line segments (maps to the X11 XSegments structure)
Definition GuiTypes.h:352
Attributes that can be used when creating or changing a window.
Definition GuiTypes.h:94
Window attributes that can be inquired.
Definition GuiTypes.h:115