Cleanup: use braces for GHOST Cocoa *.mm sources

This commit is contained in:
Campbell Barton
2023-09-17 09:16:09 +10:00
parent 5b9740c913
commit 75afef1372
2 changed files with 59 additions and 28 deletions

View File

@@ -840,8 +840,9 @@ GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(int32_t &x, int32_t &y) cons
GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(int32_t x, int32_t y)
{
GHOST_WindowCocoa *window = (GHOST_WindowCocoa *)m_windowManager->getActiveWindow();
if (!window)
if (!window) {
return GHOST_kFailure;
}
// Cursor and mouse dissociation placed here not to interfere with continuous grab
// (in cont. grab setMouseCursorPosition is directly called)
@@ -861,8 +862,9 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(int32_t x, int32_t y)
{
float xf = (float)x, yf = (float)y;
GHOST_WindowCocoa *window = (GHOST_WindowCocoa *)m_windowManager->getActiveWindow();
if (!window)
if (!window) {
return GHOST_kFailure;
}
@autoreleasepool {
NSScreen *windowScreen = window->getScreen();
@@ -993,7 +995,9 @@ bool GHOST_SystemCocoa::processEvents(bool /*waitForEvent*/)
// so, as a workaround we always handle these up events.
if ([event type] == NSEventTypeKeyUp &&
([event modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagOption)))
{
handleKeyEvent(event);
}
[NSApp sendEvent:event];
}
@@ -1003,8 +1007,9 @@ bool GHOST_SystemCocoa::processEvents(bool /*waitForEvent*/)
} while (waitForEvent && !anyProcessed); // Needed only for timer implementation
#endif
if (m_needDelayedApplicationBecomeActiveEventProcessing)
if (m_needDelayedApplicationBecomeActiveEventProcessing) {
handleApplicationBecomeActiveEvent();
}
if (m_outsideLoopEventProcessed) {
m_outsideLoopEventProcessed = false;
@@ -1035,8 +1040,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleApplicationBecomeActiveEvent()
m_needDelayedApplicationBecomeActiveEventProcessing = true;
return GHOST_kFailure;
}
else
else {
m_needDelayedApplicationBecomeActiveEventProcessing = false;
}
modifiers = [[[NSApplication sharedApplication] currentEvent] modifierFlags];
@@ -1186,16 +1192,18 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
GHOST_TEventDataPtr eventData;
int i;
if (!data)
if (!data) {
return GHOST_kFailure;
}
switch (draggedObjectType) {
case GHOST_kDragnDropTypeFilenames:
droppedArray = (NSArray *)data;
strArray = (GHOST_TStringArray *)malloc(sizeof(GHOST_TStringArray));
if (!strArray)
if (!strArray) {
return GHOST_kFailure;
}
strArray->count = [droppedArray count];
if (strArray->count == 0) {
@@ -1272,8 +1280,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
break;
}
}
if (bitmapImage == nil)
if (bitmapImage == nil) {
return GHOST_kFailure;
}
if (([bitmapImage bitsPerPixel] == 32) && (([bitmapImage bitmapFormat] & 0x5) == 0) &&
![bitmapImage isPlanar])
@@ -1401,8 +1410,9 @@ void GHOST_SystemCocoa::handleQuitRequest()
GHOST_Window *window = (GHOST_Window *)m_windowManager->getActiveWindow();
// Discard quit event if we are in cursor grab sequence
if (window && window->getCursorGrabModeIsWarp())
if (window && window->getCursorGrabModeIsWarp()) {
return;
}
// Push the event to Blender so it can open a dialog if needed
pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventQuitRequest, window));
@@ -1471,8 +1481,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventT
// workaround 2 cornercases:
// 1. if [event isEnteringProximity] was not triggered since program-start
// 2. device is not sending [event pointingDeviceType], due no eraser
if (ct.Active == GHOST_kTabletModeNone)
if (ct.Active == GHOST_kTabletModeNone) {
ct.Active = GHOST_kTabletModeStylus;
}
ct.Pressure = [event pressure];
ct.Xtilt = [event tilt].x;
@@ -1649,8 +1660,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
GHOST_Rect bounds, windowBounds, correctedBounds;
/* fallback to window bounds */
if (window->getCursorGrabBounds(bounds) == GHOST_kFailure)
if (window->getCursorGrabBounds(bounds) == GHOST_kFailure) {
window->getClientBounds(bounds);
}
/* Switch back to Cocoa coordinates orientation
* (y=0 at bottom, the same as blender internal BTW!), and to client coordinates. */
@@ -1723,8 +1735,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
* change from e.g. scrolling to zooming. this works around the
* issue by ignoring momentum scroll after a key press */
if (momentumPhase) {
if (m_ignoreMomentumScroll)
if (m_ignoreMomentumScroll) {
break;
}
}
else {
m_ignoreMomentumScroll = false;
@@ -1733,10 +1746,12 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
/* we assume phases are only set for gestures from trackpad or magic
* mouse events. note that using tablet at the same time may not work
* since this is a static variable */
if (phase == NSEventPhaseBegan && m_multitouchGestures)
if (phase == NSEventPhaseBegan && m_multitouchGestures) {
m_multiTouchScroll = true;
else if (phase == NSEventPhaseEnded)
}
else if (phase == NSEventPhaseEnded) {
m_multiTouchScroll = false;
}
/* Standard scroll-wheel case, if no swiping happened,
* and no momentum (kinetic scroll) works. */
@@ -1745,10 +1760,12 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
double deltaF = [event deltaY];
if (deltaF == 0.0)
if (deltaF == 0.0) {
deltaF = [event deltaX]; // make blender decide if it's horizontal scroll
if (deltaF == 0.0)
}
if (deltaF == 0.0) {
break; // discard trackpad delta=0 events
}
delta = deltaF > 0.0 ? 1 : -1;
pushEvent(new GHOST_EventWheel([event timestamp] * 1000, window, delta));
@@ -1872,15 +1889,18 @@ GHOST_TSuccess GHOST_SystemCocoa::handleKeyEvent(void *eventPtr)
}
/* F keys should not have utf8 */
if ((keyCode >= GHOST_kKeyF1) && (keyCode <= GHOST_kKeyF20))
if ((keyCode >= GHOST_kKeyF1) && (keyCode <= GHOST_kKeyF20)) {
utf8_buf[0] = '\0';
}
/* no text with command key pressed */
if (m_modifierMask & NSEventModifierFlagCommand)
if (m_modifierMask & NSEventModifierFlagCommand) {
utf8_buf[0] = '\0';
}
if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSEventModifierFlagCommand))
if ((keyCode == GHOST_kKeyQ) && (m_modifierMask & NSEventModifierFlagCommand)) {
break; // Cmd-Q is directly handled by Cocoa
}
if ([event type] == NSEventTypeKeyDown) {
pushEvent(new GHOST_EventKey([event timestamp] * 1000,
@@ -2004,8 +2024,9 @@ char *GHOST_SystemCocoa::getClipboard(bool /*selection*/) const
void GHOST_SystemCocoa::putClipboard(const char *buffer, bool selection) const
{
if (selection)
if (selection) {
return; // for copying the selection, used on X11
}
@autoreleasepool {

View File

@@ -175,14 +175,18 @@
NSPoint mouseLocation = [sender draggingLocation];
NSPasteboard *draggingPBoard = [sender draggingPasteboard];
if ([[draggingPBoard types] containsObject:NSPasteboardTypeTIFF])
if ([[draggingPBoard types] containsObject:NSPasteboardTypeTIFF]) {
m_draggedObjectType = GHOST_kDragnDropTypeBitmap;
else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType])
}
else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType]) {
m_draggedObjectType = GHOST_kDragnDropTypeFilenames;
else if ([[draggingPBoard types] containsObject:NSPasteboardTypeString])
}
else if ([[draggingPBoard types] containsObject:NSPasteboardTypeString]) {
m_draggedObjectType = GHOST_kDragnDropTypeString;
else
}
else {
return NSDragOperationNone;
}
associatedWindow->setAcceptDragOperation(TRUE); // Drag operation is accepted by default
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingEntered,
@@ -240,8 +244,10 @@
droppedImg = [[NSImage alloc] initWithPasteboard:draggingPBoard];
data = droppedImg; //[draggingPBoard dataForType:NSPasteboardTypeTIFF];
}
else
else {
return NO;
}
break;
case GHOST_kDragnDropTypeFilenames:
data = [draggingPBoard propertyListForType:NSFilenamesPboardType];
@@ -418,8 +424,9 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
}
if (state == GHOST_kWindowStateFullScreen)
if (state == GHOST_kWindowStateFullScreen) {
setState(GHOST_kWindowStateFullScreen);
}
setNativePixelSize();
@@ -783,10 +790,12 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
// Lion style fullscreen
[m_window toggleFullScreen:nil];
}
else if ([m_window isMiniaturized])
else if ([m_window isMiniaturized]) {
[m_window deminiaturize:nil];
else if ([m_window isZoomed])
}
else if ([m_window isZoomed]) {
[m_window zoom:nil];
}
[pool drain];
break;
}
@@ -920,8 +929,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setProgressBar(float progress)
GHOST_TSuccess GHOST_WindowCocoa::endProgressBar()
{
if (!m_progressBarVisible)
if (!m_progressBarVisible) {
return GHOST_kFailure;
}
m_progressBarVisible = false;
/* Reset application icon to remove the progress bar. */