summaryrefslogtreecommitdiffstats
path: root/src/gui_w32.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-01-08 13:44:24 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-08 13:44:24 +0000
commit7f8b2559a30e2e2a443c35b28e94c6b45ba7ae04 (patch)
tree04c0145c1e3cf9777d58c91fa7b2ad231cfecf8d /src/gui_w32.c
parentdf8f9473596c8fb18ec893de677dba455e8925b3 (diff)
patch 9.0.1158: code is indented more than necessaryv9.0.1158
Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11787)
Diffstat (limited to 'src/gui_w32.c')
-rw-r--r--src/gui_w32.c437
1 files changed, 220 insertions, 217 deletions
diff --git a/src/gui_w32.c b/src/gui_w32.c
index dfbb661eb6..206645a4f1 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -434,12 +434,12 @@ directx_enabled(void)
static void
directx_binddc(void)
{
- if (s_textArea != NULL)
- {
- RECT rect;
- GetClientRect(s_textArea, &rect);
- DWriteContext_BindDC(s_dwc, s_hdc, &rect);
- }
+ if (s_textArea == NULL)
+ return;
+
+ RECT rect;
+ GetClientRect(s_textArea, &rect);
+ DWriteContext_BindDC(s_dwc, s_hdc, &rect);
}
#endif
@@ -663,14 +663,14 @@ gui_mswin_rm_blink_timer(void)
{
MSG msg;
- if (blink_timer != 0)
- {
- KillTimer(NULL, blink_timer);
- // Eat spurious WM_TIMER messages
- while (PeekMessageW(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
- ;
- blink_timer = 0;
- }
+ if (blink_timer == 0)
+ return;
+
+ KillTimer(NULL, blink_timer);
+ // Eat spurious WM_TIMER messages
+ while (PeekMessageW(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
+ ;
+ blink_timer = 0;
}
/*
@@ -888,7 +888,7 @@ _OnChar(
modifiers = get_active_modifiers();
ch = simplify_key(ch, &modifiers);
-
+
// Some keys need adjustment when the Ctrl modifier is used.
++no_reduce_keys;
ch = may_adjust_key_for_ctrl(modifiers, ch);
@@ -1034,63 +1034,64 @@ _OnMouseButtonDown(
else
button = MOUSE_LEFT;
}
- if (button >= 0)
- {
- repeated_click = ((int)(currentTime - s_prevTime) < p_mouset);
+ if (button < 0)
+ return;
+
+ repeated_click = ((int)(currentTime - s_prevTime) < p_mouset);
+
+ /*
+ * Holding down the left and right buttons simulates pushing the middle
+ * button.
+ */
+ if (repeated_click
+ && ((button == MOUSE_LEFT && s_button_pending == MOUSE_RIGHT)
+ || (button == MOUSE_RIGHT
+ && s_button_pending == MOUSE_LEFT)))
+ {
/*
- * Holding down the left and right buttons simulates pushing the middle
- * button.
+ * Hmm, gui.c will ignore more than one button down at a time, so
+ * pretend we let go of it first.
*/
- if (repeated_click
- && ((button == MOUSE_LEFT && s_button_pending == MOUSE_RIGHT)
- || (button == MOUSE_RIGHT
- && s_button_pending == MOUSE_LEFT)))
+ gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, 0x0);
+ button = MOUSE_MIDDLE;
+ repeated_click = FALSE;
+ s_button_pending = -1;
+ _OnMouseEvent(button, x, y, repeated_click, keyFlags);
+ }
+ else if ((repeated_click)
+ || (mouse_model_popup() && (button == MOUSE_RIGHT)))
+ {
+ if (s_button_pending > -1)
{
- /*
- * Hmm, gui.c will ignore more than one button down at a time, so
- * pretend we let go of it first.
- */
- gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, 0x0);
- button = MOUSE_MIDDLE;
- repeated_click = FALSE;
+ _OnMouseEvent(s_button_pending, x, y, FALSE, keyFlags);
s_button_pending = -1;
- _OnMouseEvent(button, x, y, repeated_click, keyFlags);
- }
- else if ((repeated_click)
- || (mouse_model_popup() && (button == MOUSE_RIGHT)))
- {
- if (s_button_pending > -1)
- {
- _OnMouseEvent(s_button_pending, x, y, FALSE, keyFlags);
- s_button_pending = -1;
- }
- // TRACE("Button down at x %d, y %d\n", x, y);
- _OnMouseEvent(button, x, y, repeated_click, keyFlags);
- }
- else
- {
- /*
- * If this is the first press (i.e. not a multiple click) don't
- * action immediately, but store and wait for:
- * i) button-up
- * ii) mouse move
- * iii) another button press
- * before using it.
- * This enables us to make left+right simulate middle button,
- * without left or right being actioned first. The side-effect is
- * that if you click and hold the mouse without dragging, the
- * cursor doesn't move until you release the button. In practice
- * this is hardly a problem.
- */
- s_button_pending = button;
- s_x_pending = x;
- s_y_pending = y;
- s_kFlags_pending = keyFlags;
}
-
- s_prevTime = currentTime;
+ // TRACE("Button down at x %d, y %d\n", x, y);
+ _OnMouseEvent(button, x, y, repeated_click, keyFlags);
+ }
+ else
+ {
+ /*
+ * If this is the first press (i.e. not a multiple click) don't
+ * action immediately, but store and wait for:
+ * i) button-up
+ * ii) mouse move
+ * iii) another button press
+ * before using it.
+ * This enables us to make left+right simulate middle button,
+ * without left or right being actioned first. The side-effect is
+ * that if you click and hold the mouse without dragging, the
+ * cursor doesn't move until you release the button. In practice
+ * this is hardly a problem.
+ */
+ s_button_pending = button;
+ s_x_pending = x;
+ s_y_pending = y;
+ s_kFlags_pending = keyFlags;
}
+
+ s_prevTime = currentTime;
}
static void
@@ -1233,23 +1234,23 @@ _OnFindRepl(void)
flags = FRD_REPLACEALL;
}
- if (flags != 0)
- {
- char_u *p, *q;
+ if (flags == 0)
+ return;
- // Call the generic GUI function to do the actual work.
- if (s_findrep_struct.Flags & FR_WHOLEWORD)
- flags |= FRD_WHOLE_WORD;
- if (s_findrep_struct.Flags & FR_MATCHCASE)
- flags |= FRD_MATCH_CASE;
- down = (s_findrep_struct.Flags & FR_DOWN) != 0;
- p = utf16_to_enc(s_findrep_struct.lpstrFindWhat, NULL);
- q = utf16_to_enc(s_findrep_struct.lpstrReplaceWith, NULL);
- if (p != NULL && q != NULL)
- gui_do_findrepl(flags, p, q, down);
- vim_free(p);
- vim_free(q);
- }
+ char_u *p, *q;
+
+ // Call the generic GUI function to do the actual work.
+ if (s_findrep_struct.Flags & FR_WHOLEWORD)
+ flags |= FRD_WHOLE_WORD;
+ if (s_findrep_struct.Flags & FR_MATCHCASE)
+ flags |= FRD_MATCH_CASE;
+ down = (s_findrep_struct.Flags & FR_DOWN) != 0;
+ p = utf16_to_enc(s_findrep_struct.lpstrFindWhat, NULL);
+ q = utf16_to_enc(s_findrep_struct.lpstrReplaceWith, NULL);
+ if (p != NULL && q != NULL)
+ gui_do_findrepl(flags, p, q, down);
+ vim_free(p);
+ vim_free(q);
}
#endif
@@ -2932,11 +2933,11 @@ gui_mch_replace_dialog(exarg_T *eap)
void
gui_mch_mousehide(int hide)
{
- if (hide != gui.pointer_hidden)
- {
- ShowCursor(!hide);
- gui.pointer_hidden = hide;
- }
+ if (hide == gui.pointer_hidden)
+ return;
+
+ ShowCursor(!hide);
+ gui.pointer_hidden = hide;
}
#ifdef FEAT_MENU
@@ -2993,33 +2994,33 @@ _OnDestroy(HWND hwnd)
_OnPaint(
HWND hwnd)
{
- if (!IsMinimized(hwnd))
- {
- PAINTSTRUCT ps;
+ if (IsMinimized(hwnd))
+ return;
- out_flush(); // make sure all output has been processed
- (void)BeginPaint(hwnd, &ps);
+ PAINTSTRUCT ps;
- // prevent multi-byte characters from misprinting on an invalid
- // rectangle
- if (has_mbyte)
- {
- RECT rect;
+ out_flush(); // make sure all output has been processed
+ (void)BeginPaint(hwnd, &ps);
- GetClientRect(hwnd, &rect);
- ps.rcPaint.left = rect.left;
- ps.rcPaint.right = rect.right;
- }
+ // prevent multi-byte characters from misprinting on an invalid
+ // rectangle
+ if (has_mbyte)
+ {
+ RECT rect;
- if (!IsRectEmpty(&ps.rcPaint))
- {
- gui_redraw(ps.rcPaint.left, ps.rcPaint.top,
- ps.rcPaint.right - ps.rcPaint.left + 1,
- ps.rcPaint.bottom - ps.rcPaint.top + 1);
- }
+ GetClientRect(hwnd, &rect);
+ ps.rcPaint.left = rect.left;
+ ps.rcPaint.right = rect.right;
+ }
- EndPaint(hwnd, &ps);
+ if (!IsRectEmpty(&ps.rcPaint))
+ {
+ gui_redraw(ps.rcPaint.left, ps.rcPaint.top,
+ ps.rcPaint.right - ps.rcPaint.left + 1,
+ ps.rcPaint.bottom - ps.rcPaint.top + 1);
}
+
+ EndPaint(hwnd, &ps);
}
static void
@@ -3904,21 +3905,21 @@ _OnDropFiles(
DragFinish(hDrop);
- if (fnames != NULL)
- {
- int kbd_modifiers = get_active_modifiers();
+ if (fnames == NULL)
+ return;
+
+ int kbd_modifiers = get_active_modifiers();
- if ((kbd_modifiers & MOD_MASK_SHIFT) != 0)
- modifiers |= MOUSE_SHIFT;
- if ((kbd_modifiers & MOD_MASK_CTRL) != 0)
- modifiers |= MOUSE_CTRL;
- if ((kbd_modifiers & MOD_MASK_ALT) != 0)
- modifiers |= MOUSE_ALT;
+ if ((kbd_modifiers & MOD_MASK_SHIFT) != 0)
+ modifiers |= MOUSE_SHIFT;
+ if ((kbd_modifiers & MOD_MASK_CTRL) != 0)
+ modifiers |= MOUSE_CTRL;
+ if ((kbd_modifiers & MOD_MASK_ALT) != 0)
+ modifiers |= MOUSE_ALT;
- gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles);
+ gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles);
- s_need_activate = TRUE;
- }
+ s_need_activate = TRUE;
}
static int
@@ -4461,11 +4462,11 @@ show_sizing_tip(int cols, int rows)
static void
destroy_sizing_tip(void)
{
- if (hwndTip != NULL)
- {
- DestroyWindow(hwndTip);
- hwndTip = NULL;
- }
+ if (hwndTip == NULL)
+ return;
+
+ DestroyWindow(hwndTip);
+ hwndTip = NULL;
}
static int
@@ -5844,64 +5845,64 @@ im_set_active(int active)
}
# endif
- if (pImmGetContext) // if NULL imm32.dll wasn't loaded (yet)
+ if (!pImmGetContext) // if NULL imm32.dll wasn't loaded (yet)
+ return;
+
+ if (p_imdisable)
{
- if (p_imdisable)
+ if (hImcOld == (HIMC)0)
{
- if (hImcOld == (HIMC)0)
- {
- hImcOld = pImmGetContext(s_hwnd);
- if (hImcOld)
- pImmAssociateContext(s_hwnd, (HIMC)0);
- }
- active = FALSE;
+ hImcOld = pImmGetContext(s_hwnd);
+ if (hImcOld)
+ pImmAssociateContext(s_hwnd, (HIMC)0);
}
- else if (hImcOld != (HIMC)0)
+ active = FALSE;
+ }
+ else if (hImcOld != (HIMC)0)
+ {
+ pImmAssociateContext(s_hwnd, hImcOld);
+ hImcOld = (HIMC)0;
+ }
+
+ hImc = pImmGetContext(s_hwnd);
+ if (!hImc)
+ return;
+
+ /*
+ * for Korean ime
+ */
+ HKL hKL = GetKeyboardLayout(0);
+
+ if (LOWORD(hKL) == MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN))
+ {
+ static DWORD dwConversionSaved = 0, dwSentenceSaved = 0;
+ static BOOL bSaved = FALSE;
+
+ if (active)
{
- pImmAssociateContext(s_hwnd, hImcOld);
- hImcOld = (HIMC)0;
+ // if we have a saved conversion status, restore it
+ if (bSaved)
+ pImmSetConversionStatus(hImc, dwConversionSaved,
+ dwSentenceSaved);
+ bSaved = FALSE;
}
-
- hImc = pImmGetContext(s_hwnd);
- if (hImc)
+ else
{
- /*
- * for Korean ime
- */
- HKL hKL = GetKeyboardLayout(0);
-
- if (LOWORD(hKL) == MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN))
+ // save conversion status and disable korean
+ if (pImmGetConversionStatus(hImc, &dwConversionSaved,
+ &dwSentenceSaved))
{
- static DWORD dwConversionSaved = 0, dwSentenceSaved = 0;
- static BOOL bSaved = FALSE;
-
- if (active)
- {
- // if we have a saved conversion status, restore it
- if (bSaved)
- pImmSetConversionStatus(hImc, dwConversionSaved,
- dwSentenceSaved);
- bSaved = FALSE;
- }
- else
- {
- // save conversion status and disable korean
- if (pImmGetConversionStatus(hImc, &dwConversionSaved,
- &dwSentenceSaved))
- {
- bSaved = TRUE;
- pImmSetConversionStatus(hImc,
- dwConversionSaved & ~(IME_CMODE_NATIVE
- | IME_CMODE_FULLSHAPE),
- dwSentenceSaved);
- }
- }
+ bSaved = TRUE;
+ pImmSetConversionStatus(hImc,
+ dwConversionSaved & ~(IME_CMODE_NATIVE
+ | IME_CMODE_FULLSHAPE),
+ dwSentenceSaved);
}
-
- pImmSetOpenStatus(hImc, active);
- pImmReleaseContext(s_hwnd, hImc);
}
}
+
+ pImmSetOpenStatus(hImc, active);
+ pImmReleaseContext(s_hwnd, hImc);
}
/*
@@ -6459,28 +6460,28 @@ gui_make_popup(char_u *path_name, int mouse_pos)
{
vimmenu_T *menu = gui_find_menu(path_name);
- if (menu != NULL)
- {
- POINT p;
+ if (menu == NULL)
+ return;
- // Find the position of the current cursor
- GetDCOrgEx(s_hdc, &p);
- if (mouse_pos)
- {
- int mx, my;
+ POINT p;
- gui_mch_getmouse(&mx, &my);
- p.x += mx;
- p.y += my;
- }
- else if (curwin != NULL)
- {
- p.x += TEXT_X(curwin->w_wincol + curwin->w_wcol + 1);
- p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1);
- }
- msg_scroll = FALSE;
- gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y);
+ // Find the position of the current cursor
+ GetDCOrgEx(s_hdc, &p);
+ if (mouse_pos)
+ {
+ int mx, my;
+
+ gui_mch_getmouse(&mx, &my);
+ p.x += mx;
+ p.y += my;
}
+ else if (curwin != NULL)
+ {
+ p.x += TEXT_X(curwin->w_wincol + curwin->w_wcol + 1);
+ p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1);
+ }
+ msg_scroll = FALSE;
+ gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y);
}
# if defined(FEAT_TEAROFF) || defined(PROTO)
@@ -8274,25 +8275,27 @@ gui_mch_drawsign(int row, int col, int typenr)
static void
close_signicon_image(signicon_t *sign)
{
- if (sign)
- switch (sign->uType)
- {
- case IMAGE_BITMAP:
- DeleteObject((HGDIOBJ)sign->hImage);
- break;
- case IMAGE_CURSOR:
- DestroyCursor((HCURSOR)sign->hImage);
- break;
- case IMAGE_ICON:
- DestroyIcon((HICON)sign->hImage);
- break;
+ if (sign == NULL)
+ return;
+
+ switch (sign->uType)
+ {
+ case IMAGE_BITMAP:
+ DeleteObject((HGDIOBJ)sign->hImage);
+ break;
+ case IMAGE_CURSOR:
+ DestroyCursor((HCURSOR)sign->hImage);
+ break;
+ case IMAGE_ICON:
+ DestroyIcon((HICON)sign->hImage);
+ break;
# ifdef FEAT_XPM_W32
- case IMAGE_XPM:
- DeleteObject((HBITMAP)sign->hImage);
- DeleteObject((HBITMAP)sign->hShape);
- break;
+ case IMAGE_XPM:
+ DeleteObject((HBITMAP)sign->hImage);
+ DeleteObject((HBITMAP)sign->hShape);
+ break;
# endif
- }
+ }
}
void *
@@ -8347,11 +8350,11 @@ gui_mch_register_sign(char_u *signfile)
void
gui_mch_destroy_sign(void *sign)
{
- if (sign)
- {
- close_signicon_image((signicon_t *)sign);
- vim_free(sign);
- }
+ if (sign == NULL)
+ return;
+
+ close_signicon_image((signicon_t *)sign);
+ vim_free(sign);
}
#endif
@@ -8561,10 +8564,11 @@ Handle_WM_Notify(HWND hwnd UNUSED, LPNMHDR pnmh)
if (pnmh->idFrom != ID_BEVAL_TOOLTIP) // it is not our tooltip
return;
- if (cur_beval != NULL)
+ if (cur_beval == NULL)
+ return;
+
+ switch (pnmh->code)
{
- switch (pnmh->code)
- {
case TTN_SHOW:
break;
case TTN_POP: // Before tooltip disappear
@@ -8589,7 +8593,6 @@ Handle_WM_Notify(HWND hwnd UNUSED, LPNMHDR pnmh)
info->uFlags |= TTF_DI_SETITEM;
}
break;
- }
}
}