| 1 |
zmatsuo |
7507 |
/* |
| 2 |
|
|
* Copyright (C) 2008-2019 TeraTerm Project |
| 3 |
doda |
7089 |
* All rights reserved. |
| 4 |
|
|
* |
| 5 |
|
|
* Redistribution and use in source and binary forms, with or without |
| 6 |
|
|
* modification, are permitted provided that the following conditions |
| 7 |
|
|
* are met: |
| 8 |
|
|
* |
| 9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
| 10 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 12 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 13 |
|
|
* documentation and/or other materials provided with the distribution. |
| 14 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
| 15 |
|
|
* derived from this software without specific prior written permission. |
| 16 |
|
|
* |
| 17 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 18 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 |
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
|
*/ |
| 28 |
zmatsuo |
7507 |
/* original idea from PuTTY 0.60 windows/sizetip.c */ |
| 29 |
doda |
7089 |
|
| 30 |
|
|
#include "teraterm.h" |
| 31 |
|
|
#include "tttypes.h" |
| 32 |
|
|
#include "ttlib.h" |
| 33 |
|
|
#include "ttwinman.h" |
| 34 |
|
|
|
| 35 |
|
|
#include <windows.h> |
| 36 |
|
|
#include <stdio.h> |
| 37 |
zmatsuo |
7507 |
#include <tchar.h> |
| 38 |
doda |
7089 |
|
| 39 |
zmatsuo |
7507 |
#include "TipWin.h" |
| 40 |
|
|
|
| 41 |
|
|
static TipWin *SizeTip; |
| 42 |
doda |
7089 |
static int tip_enabled = 0; |
| 43 |
|
|
|
| 44 |
zmatsuo |
7507 |
/** |
| 45 |
|
|
* point を |
| 46 |
|
|
* スクリーンからはみ出している場合、入るように補正する |
| 47 |
|
|
* NearestMonitor が TRUE のとき、最も近いモニタ |
| 48 |
|
|
* FALSEのとき、マウスのあるモニタに移動させる |
| 49 |
|
|
* ディスプレイの端から FrameWidth(pixel) より離れるようにする |
| 50 |
|
|
*/ |
| 51 |
|
|
static void FixPosFromFrame(POINT *point, int FrameWidth, BOOL NearestMonitor) |
| 52 |
doda |
7089 |
{ |
| 53 |
zmatsuo |
7507 |
if (HasMultiMonitorSupport()) { |
| 54 |
|
|
// マルチモニタがサポートされている場合 |
| 55 |
|
|
HMONITOR hm; |
| 56 |
|
|
MONITORINFO mi; |
| 57 |
doda |
7089 |
|
| 58 |
zmatsuo |
7507 |
hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONULL); |
| 59 |
|
|
if (hm == NULL) { |
| 60 |
|
|
if (NearestMonitor) { |
| 61 |
|
|
// 最も近いモニタに表示する |
| 62 |
|
|
hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST); |
| 63 |
|
|
} else { |
| 64 |
|
|
// スクリーンからはみ出している場合はマウスのあるモニタに表示する |
| 65 |
|
|
GetCursorPos(point); |
| 66 |
|
|
hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST); |
| 67 |
doda |
7089 |
} |
| 68 |
zmatsuo |
7507 |
} |
| 69 |
doda |
7089 |
|
| 70 |
zmatsuo |
7507 |
mi.cbSize = sizeof(MONITORINFO); |
| 71 |
|
|
GetMonitorInfo(hm, &mi); |
| 72 |
|
|
if (point->x < mi.rcMonitor.left + FrameWidth) { |
| 73 |
|
|
point->x = mi.rcMonitor.left + FrameWidth; |
| 74 |
|
|
} |
| 75 |
|
|
if (point->y < mi.rcMonitor.top + FrameWidth) { |
| 76 |
|
|
point->y = mi.rcMonitor.top + FrameWidth; |
| 77 |
|
|
} |
| 78 |
doda |
7089 |
} |
| 79 |
zmatsuo |
7507 |
else |
| 80 |
|
|
{ |
| 81 |
|
|
// マルチモニタがサポートされていない場合 |
| 82 |
|
|
if (point->x < FrameWidth) { |
| 83 |
|
|
point->x = FrameWidth; |
| 84 |
|
|
} |
| 85 |
|
|
if (point->y < FrameWidth) { |
| 86 |
|
|
point->y = FrameWidth; |
| 87 |
|
|
} |
| 88 |
|
|
} |
| 89 |
doda |
7089 |
} |
| 90 |
|
|
|
| 91 |
|
|
void UpdateSizeTip(HWND src, int cx, int cy) |
| 92 |
|
|
{ |
| 93 |
|
|
TCHAR str[32]; |
| 94 |
|
|
|
| 95 |
|
|
if (!tip_enabled) |
| 96 |
|
|
return; |
| 97 |
|
|
|
| 98 |
|
|
/* Generate the tip text */ |
| 99 |
|
|
|
| 100 |
zmatsuo |
7507 |
_stprintf_s(str, _countof(str), _T("%dx%d"), cx, cy); |
| 101 |
doda |
7089 |
|
| 102 |
zmatsuo |
7507 |
if (SizeTip == NULL) { |
| 103 |
doda |
7089 |
RECT wr; |
| 104 |
zmatsuo |
7507 |
POINT point; |
| 105 |
|
|
// ウィンドウの位置を取得 |
| 106 |
doda |
7089 |
GetWindowRect(src, &wr); |
| 107 |
zmatsuo |
7507 |
// sizetipを出す位置は、ウィンドウ左上-(8,16) |
| 108 |
|
|
point.x = wr.left - 16; |
| 109 |
|
|
point.y = wr.top - 8; |
| 110 |
|
|
FixPosFromFrame(&point, 16, FALSE); |
| 111 |
|
|
cx = point.x; |
| 112 |
|
|
cy = point.y; |
| 113 |
|
|
SizeTip = TipWinCreate(src, cx, cy, str); |
| 114 |
doda |
7089 |
} else { |
| 115 |
|
|
/* Tip already exists, just set the text */ |
| 116 |
zmatsuo |
7507 |
TipWinSetText(SizeTip, str); |
| 117 |
|
|
//SetWindowText(tip_wnd, str); |
| 118 |
doda |
7089 |
} |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
void EnableSizeTip(int bEnable) |
| 122 |
|
|
{ |
| 123 |
zmatsuo |
7507 |
if (SizeTip && !bEnable) { |
| 124 |
|
|
TipWinDestroy(SizeTip); |
| 125 |
|
|
SizeTip = NULL; |
| 126 |
doda |
7089 |
} |
| 127 |
|
|
|
| 128 |
|
|
tip_enabled = bEnable; |
| 129 |
|
|
} |