Macro/投稿/229

http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2F229


Top > Macro > 投稿 > 229

選択範囲内の数字をカウントアップ/ダウン(HTA版)

  • ページ: Macro/投稿
  • 作者: jj?
  • カテゴリー: js
  • 投稿日: 2014-05-31 (土) 23:41:00

メッセージ

選択範囲内の数字を増減(カウントアップ/ダウン)します。
HTA(mshta.exe)をダイアログ代わりに使っています。
とりあえず
      [+1]    [+5]    [+10]
      [-1]    [-5]    [-10]
      10進 / 16進
      他
のボタンを用意してみました。

なおマクロ実行中はキーボード操作が殆ど効かないので
範囲の選択し直しなどはマウス操作が主になります。
(要sakura:2.0.4.0以降)

fileNumberUpDownHta.js
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
/*<!-- ファイル先頭の "/*" はHTAドキュメントに表示されてしまうので初期化時に取り除く。 -->
<!DOCTYPE html>		<!-- ファイル先頭に記述していないので無効。 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	IE10では<hta:application>要素廃止(!)によりoHTA.commandLine=undefinedとなりエラー。 -->
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<!--
*/
 
/*
 [概要]
	選択範囲の数字の増減を行います。(HTAによるGUI)
		例:"123" を選択してマクロ実行
			→ [+1]クリックで "124"、[-1]クリックで "122"
	選択範囲内の数字はすべて別個に処理されます。
	範囲選択されていない場合、カーソル上の単語が選択されます。
	(対応:sakura:2.0.4.0以降)
	
	矩形範囲選択での注意点:
		文字数の増減により、選択していた数字が選択範囲から外れたり
		選択していない数字が選択範囲内に入ってしまう場合があるため、
		右側は多めに選択しておいた方が安全です。
		特に折り返し行では、矩形範囲選択は使わない方が無難です。
	HTAウィンドウの位置:
		sakura:2.0.6.0以降では、HTAウィンドウの位置を一時的に記憶します。
		文書を閉じるとデフォルト位置に戻ります。文書毎に記憶されます。
 [備考]
	マクロ本体(.js) と HTA(.hta) を1つのファイルにまとめています。
	WinVista以降のOSが望ましいです。(WinXP以前ではエクスプローラやIEが
	起動されていなければIEを起動するのでその分遅いです。)
 [変更履歴]
	2014/05/06	新規
*/
 
 
 
//==============================================================
//	マクロ本体(.js) (HTAの呼び出し側マクロ)
//==============================================================
 
// HTAウィンドウのデフォルト位置。
//		・座標指定:ウィンドウ(の左上)の座標を指定。(pixel単位)
//		・% 指定  :ウィンドウの中心位置を % で指定。(画面左上から%単位、0〜100%)
//		但し画面外に消えないように制限している。("9999" としても画面内に来る。)
//var sWINDOW_POS_X	= "200";	// 座標X [pixel]
//var sWINDOW_POS_Y	= "100";	// 座標Y [pixel]
var sWINDOW_POS_X    = "30%";    // 中心X [%]
var sWINDOW_POS_Y    = "30%";    // 中心Y [%]
 
// 各チェックボックスの初期値。
//		true=チェックオン / false=オフ
var bFULLWIDTH    = true;            // [全角数字も扱う]
var bMINUS        = false;        // [負数を扱う]
var bFRACTION    = false;        // [小数部は変更しない]
 
 
 
Main();
 
function Main()
{
    var WshShell        = new ActiveXObject("WScript.Shell");
    var oShellWindows    = (new ActiveXObject("Shell.Application")).Windows();
    var oSWItem;            // Progman/エクスプローラ/IE (ShellWindows.Item())
    var oIE;                // IEオブジェクト
    var sMacroPath;            // 本マクロのパス
    var sPropertyName;        // (=マクロファイル名)
    var Property        = { oEditor: Editor, sWindowPosX: "0", sWindowPosY: "0",
                            bFullWidth: false, bMinus: false, bFraction: false };
    var sCmd;
    
    
    sMacroPath = Editor.ExpandParameter("$M");
    if( (sMacroPath == "") && (typeof Plugin != "undefined") ){
        // プラグインではExpandParameter("$M")=""(空文字列)が返る。
        // (2014/05時点では "C[n]" キーは相対パス指定の仕様だが一応絶対パスも対応。)
        sMacroPath = Plugin.GetDef( "Command", "C[" + Plugin.GetCommandNo() + "]" );
        if( !sMacroPath.match( /^([A-Z]:|\\)/i ) ){        // 不一致なら相対パス(とみなす)。
            sMacroPath = Plugin.GetPluginDir() + "\\" + sMacroPath;
		}
		sMacroPath = (new ActiveXObject("Scripting.FileSystemObject")).GetAbsolutePathName( sMacroPath );
	}
	
	//==========================================================
	// HTAをダイアログ(GUI)として使用する。
	//
	
	// HTAへ渡す値。
	//		次のようだった。(VistaはWin7と同じ)
	//		ShellWindows.Item() (引数無し):
	//			Win7	:"Program Manager" Progman (ShellWindows.Count=0でもこれが返る)
	//			XP		:エクスプローラ、起動されていなければnull
	//		ShellWindows.Item(index) (引数あり):
	//			Win7/XP	:IE または エクスプローラ、どちらも起動されていなければnull
	// "Program Manager" Progman が利用可能なら、またはエクスプローラが起動されていれば利用。
	if( !(oSWItem = oShellWindows.Item()) ){			// Progman or エクスプローラ
		// IEが起動されていれば利用。
		if( !(oSWItem = oShellWindows.Item(0)) ){		// IE or エクスプローラ
			//if(WshShell.Popup("InternetExplorer.Application 起動します?",0,"",0x101) != 1) return;
			oIE = new ActiveXObject("InternetExplorer.Application");	// IEオブジェクト生成。
			oSWItem = oIE;								// oIE == oShellWindows.Item(0)
		}
	}
	sPropertyName = sMacroPath.replace( /^.*\\/, "" );		// ファイル名部分。
	Property.sWindowPosX	= sWINDOW_POS_X;
	Property.sWindowPosY	= sWINDOW_POS_Y;
	Property.bFullWidth		= bFULLWIDTH;
	Property.bMinus			= bMINUS;
	Property.bFraction		= bFRACTION;
	oSWItem.PutProperty( sPropertyName, Property );
	
	// HTA呼び出し。(mshta.exeの引数はフルパスが必要。)
	sCmd = 'mshta.exe "' + sMacroPath + '"';
	WshShell.Run( sCmd, 1, true );		// true:プログラムの終了を待機。
	
	// 取り敢えずundefinedに。(ログオフするか、エクスプローラ/IEが消えるまで残る?)
	oSWItem.PutProperty( sPropertyName, undefined );
	if( oIE ) oIE.Quit();	// IEオブジェクト解放。(Quit()しないとiexplore.exeプロセスが残る。)
}
 
 
 
/*
-->
 
<!--
================================================================
	HTA(.hta) (マクロから呼び出される)
================================================================
-->
 
<title>HTA</title>
 
<!-- style要素はscript要素の後ろに記述。(ここだとIE8以前で機能しない。) -->
 
<script>
{
	var oShellWindows	= (new ActiveXObject("Shell.Application")).Windows();
	var oSWItem;			// Progman/エクスプローラ/IE (ShellWindows.Item())
	var Editor;				// サクラエディタのオブジェクト Editor
	var sCOOKIESCOPE			= "window";
	var sCOOKIENAME_WINDOW_XY	= "NumberUpDownHta_WindowXY";
	var bCookieEnabled			= false;
	var OffsetWindowPos			= { x:0, y:0 };	// ウィンドウ位置(枠)からのbodyのオフセット位置
	var nWindowScreenHeight;					// window.screen.height
	
	
	// ファイル先頭の "/*" はHTAドキュメントに表示されてしまうので初期化時に取り除く。
	//document.body.innerHTML = '<br style="display:none;" />' + document.body.innerHTML.substring(2);
	document.body.innerHTML = document.body.innerHTML.substring(2);
	
	//==========================================================
	// ウィンドウサイズ、位置
	//		起動時、ウィンドウが表示されてからリサイズされるのを回避したい場合、
	//		<HTA:APPLICATION> タグより前にリサイズのコードを記述します。
	// 画面外に移動させて擬似的に非表示にする。(この手法はちょっと怖いが。)
	// サイズは [閉じる] ボタンの位置から自動調整する為、スクロールバーが現れない程度の大きさは必要。
	window.moveTo( -999, -999 );	// 画面外。
	window.resizeTo( 390, 340 );	// とりあえずのサイズ。
	
	//==========================================================
	// 初期化
	function init()
	{
		var sMacroFile;
		var sPropertyName;		// (=マクロファイル名)
		var Property			// = { oEditor: Editor, sWindowPosX: "nnn", sWindowPosY: "nnn",
								//		bFullWidth: bbb, bMinus: bbb, bFraction: bbb };
		var x, y;
		var nBodyWidth, nBodyHeight;	// bodyのサイズ。
		var xSize, ySize;				// ウィンドウサイズ。
		var xMin, xMax, yMin, yMax;
		
		// コマンドライン引数の処理。
		//		例:oHTA.commandLine=["C:\dir\file.hta" /opt]
		sMacroFile = oHTA.commandLine.match( /^".*\\(.*)"/ )[1];
		document.title = sMacroFile;						// ウィンドウ(上部の)タイトル。
		
		// マクロ本体からの値の取得。
		if( !(oSWItem = oShellWindows.Item()) ){			// Progman or エクスプローラ
			if( !(oSWItem = oShellWindows.Item(0)) ){		// IE or エクスプローラ
				window.alert( "IE または エクスプローラ が起動されていないため、実行できません。" );
				window.close();
			}
		}
		sPropertyName = sMacroFile;
		Property = oSWItem.GetProperty( sPropertyName );
		if( Property == undefined ){
			window.moveTo( 0, 0 );		// 画面内に。
			window.alert( "ERROR:\nHTA は マクロからオブジェクトを取得できませんでした。" );
			window.close();
			return;
		}
		Editor = Property.oEditor;
		checkboxFullWidth.checked	= Property.bFullWidth;
		checkboxMinus.checked		= Property.bMinus;
		checkboxFraction.checked	= Property.bFraction;
		
		bCookieEnabled = (Editor.CompareVersion( Editor.ExpandParameter("$V"), "2.0.6.0" ) >= 0);
		
		// ウィンドウサイズ、位置。(サイズは [閉じる] ボタンの位置から自動調整する。)
		
		// ウィンドウ枠(ウィンドウ位置)からのbodyのオフセット位置。
		//		window.screenLeft, window.screenTop はdocumentの(bodyの)領域。
		//		ウィンドウ上部のバーや左側のウィンドウ枠などは含まない。
		//		(開発環境ではウィンドウ位置x,yに対し、screenLeft=x+8, screenTop=y+30 だった。)
		x = y = -999;	window.moveTo( x, y );			// OffsetWindowPosを求める為のmoveTo()。
		OffsetWindowPos.x = window.screenLeft - x;		// (==左側のウィンドウ枠の横幅)
		OffsetWindowPos.y = window.screenTop  - y;		// (==上側のウィンドウ枠の縦幅)
		// bodyのマージン。
		document.body.topMargin		= "10";
		document.body.rightMargin	= "2";
		document.body.bottomMargin	= "2";
		document.body.leftMargin	= "10";
		// [閉じる] ボタンの位置の配置。(.style.position="absolute")
		buttonClose.style.left = spanButtonClosePositionOrigin.offsetLeft +40;	// 結果は"px"が付く。
		buttonClose.style.top  = spanButtonClosePositionOrigin.offsetTop;
		// bodyのサイズ。[閉じる] ボタンの位置を元にする。(-0:文字列→数値化)
		nBodyWidth  = (buttonClose.offsetLeft + buttonClose.offsetWidth ) + (document.body.rightMargin -0);
		nBodyHeight = (buttonClose.offsetTop  + buttonClose.offsetHeight) + (document.body.bottomMargin-0);
		if( document.body.offsetLeft > 0 ){
			// IE7だと.offsetLeft .offsetTopはbodyのマージンからの相対位置になる(ので正確には足すべき)。
			// また右側に縦スクロールバーが常に表示される。適当に調整する。
			nBodyWidth  += 14;
		}
		// ウィンドウサイズ。(= bodyのサイズ + 上下左右ウィンドウ枠のサイズ)
		//		右側・下側のウィンドウ枠の幅は、左側(=OffsetWindowPos.x)と同じと仮定。
		xSize = nBodyWidth  + (OffsetWindowPos.x) * 2;
		ySize = nBodyHeight + (OffsetWindowPos.y) + (OffsetWindowPos.x);
		// 余裕を追加。
		xSize += 16;
		ySize += 10;
		
		// ウィンドウのデフォルト位置。("nnn%" の場合、ウィンドウの中心位置 [%])
		Property.sWindowPosX.match( /([+-]?\d+)(%?)/ );
		x = RegExp.$1 -0;		//(-0:文字列→数値化)
		if( RegExp.$2 ) x = Math.round( (window.screen.availWidth  * x/100) - (xSize/2) );
		Property.sWindowPosY.match( /([+-]?\d+)(%?)/ );
		y = RegExp.$1 -0;		//(-0:文字列→数値化)
		if( RegExp.$2 ) y = Math.round( (window.screen.availHeight * y/100) - (ySize/2) );
		if( bCookieEnabled ){
			// "x,y" の形式で保存している。
			if( Editor.GetCookie( sCOOKIESCOPE, sCOOKIENAME_WINDOW_XY ).match( /([+-]?\d+),([+-]?\d+)/ ) ){
				x = RegExp.$1 -0;		//(-0:文字列→数値化)
				y = RegExp.$2 -0;
			}
		}
		// 画面内に収める。
		xMin = -10;		xMax = window.screen.availWidth  - xSize +10;
		yMin = -10;		yMax = window.screen.availHeight - ySize +10;
		x = Math.min( Math.max( x, xMin ), xMax );
		y = Math.min( Math.max( y, yMin ), yMax );
		
		window.resizeTo( xSize, ySize );
		window.moveTo( x, y );
		nWindowScreenHeight = window.screen.height;		// 終了時の処理で使用。
		
		buttonClose.focus();				// [閉じる] ボタンにフォーカスを持たせる。
		if( !Editor.IsTextSelected() ){		// 非選択状態の場合、カーソル上の単語を選択。
			Editor.SelectWord();
		}
	}
	
	//==========================================================
	// 終了時の処理
	window.onbeforeunload = function()
	{
		var nScreenLeft, nScreenTop, fZoomRatio;
		var x, y;
		// ウィンドウ位置の記憶。
		if( bCookieEnabled ){
			// Ctrl+マウスホイールで拡大・縮小していると、次回に位置がずれてしまう。
			// 拡大するとwindow.screenLeft等の値は小さく、縮小すると大きくなってしまう…。
			// (拡大率で割った値になる。200%なら1/2倍、50%なら2倍。screen.availWidthなども…。)
			// 対策としてwindow.screen.height等から拡大率を得る。(しかしIEの将来Verではどうなるか不明)
			nScreenLeft = window.screenLeft;
			nScreenTop  = window.screenTop;
			if( window.screen.height != nWindowScreenHeight ){
				//fZoomRatio = 1 / (window.screen.height / nWindowScreenHeight);
				fZoomRatio  = nWindowScreenHeight / window.screen.height;
				nScreenLeft = Math.round( nScreenLeft * fZoomRatio );
				nScreenTop  = Math.round( nScreenTop  * fZoomRatio );
			}
			x = nScreenLeft - OffsetWindowPos.x;
			y = nScreenTop  - OffsetWindowPos.y;
			// "x,y" の形式で保存。
			Editor.SetCookie( sCOOKIESCOPE, sCOOKIENAME_WINDOW_XY, x + "," + y );
		}
	}
	
	//==========================================================
	// その他 イベントハンドラ
	function body_onKeydown()
	{
		switch( window.event.keyCode ){
		case 0x1b:			// VK_ESCAPE
			window.close();							// Escキー=[閉じる] 動作。
			break;
		case 0x74:			// VK_F5
			window.event.returnValue = false;		// F5キー [更新] を無効化。
			break;
		case 0x50:			// 'P'
			if( window.event.ctrlKey )
				window.event.returnValue = false;	// Ctrl+P [印刷] を(一応)無効化。
			break;
		default:
			break;
		}
		// Ctrl + マウスホイール/+(プラス)/-(マイナス)/0(ゼロ)で拡大・縮小・リセット、は
		// 無効化しない方が便利そう。
	}
	
	function label_onMousedown()
	{
		// 右クリックでlabelのtitleを表示。(ツールチップはすぐに消えて読み取れない為。)
		var s;
		if( window.event.button != 2 ) return;		// 2=右クリック。
		if( (s = window.event.srcElement.title) == "" ){					// 発生元=label。
			if( (s = window.event.srcElement.parentElement.title) == "" ){	// 発生元=labelの子。
				return;
			}
		}
		divTips.innerText = s;
		divTips.style.visibility = "visible";
	}
	function label_onMouseout()
	{
		if( divTips.style.visibility != "hidden" ) divTips.style.visibility = "hidden";
	}
	
	function buttonPlusMinus_onClick( nStep )
	{
		var nMAX_LINES		= 1000;		// 選択範囲の最大行数制限
		var r1, c1, r2, c2;				// 選択範囲のレイアウト位置(折り返し単位)
		var y1, x1, y2, x2;				// 選択範囲のロジック位置(改行単位)
		var sSrc;						// 選択範囲の文字列
		var sDst;						// 処理後の文字列
		var bDec;				// true=10進数で扱う / false=16進数で扱う 
		var bFullWidth;			// true=全角数字を扱う / false=扱わない(半角数字のみ処理)
		var bFraction;			// true=小数部は変更しない / false=小数扱いせず("."前後は別々に処理)
		var bMinus;				// true=負数を扱う / false=扱わない(符号無視、最小値0)
		var reDecAry, reHexAry, re;
		var nRadix;
		var iZenkakuLoop, iZenkaku;
		var sPlusChar, sMinusChar, sPeriodChar, sZeroChar;
		var sSrcLastLine, sDstLastLine;
		
		// 非選択状態なら終了。(値域は0〜2だが一応1,2以外を除外。)
		if( (Editor.IsTextSelected() != 1) && (Editor.IsTextSelected() != 2) ) return;
		// ビューモードなら終了。("上書き禁止" は編集可・不可が判らず未対処。)
		if( Editor.ExpandParameter("${R?0$:1$:2$}") == 0 ) return;
		
		// 選択範囲の開始・終了位置。(選択範囲の復元で使用。)
		r1 = Editor.GetSelectLineFrom();
		c1 = Editor.GetSelectColmFrom();
		r2 = Editor.GetSelectLineTo();
		c2 = Editor.GetSelectColmTo();
		y1 = Editor.LayoutToLogicLineNum( r1 );
		x1 = Editor.LineColumnToIndex( r1, c1 );
		y2 = Editor.LayoutToLogicLineNum( r2 );
		x2 = Editor.LineColumnToIndex( r2, c2 );
		
		sSrc = Editor.GetSelectedString(0);		// 矩形選択では一行毎にCRLF(0D 0A)が付く。
		sDst = sSrc;
		
		// 選択範囲の最大行数制限。
		//		HTAにてEditor操作を行う場合、一度の編集操作がある行数を超えると
		//		「スクリプト エラー」が発生する。
		//		sakura:2.1.0.0では3000行を超えると発生。(sakura:2.0.x.xでは6000行(?)。)
		//		(「処理の実行中...」の進捗バーダイアログが表示されると発生。)
		//		選択範囲への入力(置き換え)は、削除1500行+挿入1500行=3000行の為、最大1500行。
		//		安全の為、最大行数は1500行より少なくする。
		//		(切りの良いところで1000行。しかしsakuraの将来Verではどうなるか不明。)
		if( sSrc.match( /[\r\n]/ ) != null ){
			if( sSrc.match( /\r\n|\r|\n/g ).length > nMAX_LINES ){
				window.alert( "選択範囲は最大 " + nMAX_LINES + " 行までです。\n" );
				return;
			}
		}
		
		// 10進数で処理。(bDec=true)
		//	・"123." や ".456" の小数形式も扱う。(bFraction=true)
		//	  	但し ".456" は、[+1]で "1.456" → [-1]で "0.456" の様に先頭に "0" が付く。
		//		"1.2.3.4" は、"1.2" ".3" ".4" の3個の数字が存在すると解釈される為、
		//		[+1]でそれぞれ "2.2" "1.3" "1.4" となり結果(奇妙だが) "2.21.31.4" となる。
		//		尚、小数の演算は行わない。"0.3" は、[-1] で "-1.3"となる。"-0.7" には
		//		ならない。小数部は処理せずに温存し、整数部のみを増減する。
		//	・負号があれば、負数で扱う。(bMinus=true)
		//		"0-1-2" は、"0" "-1" "-2" の3個の数字が存在すると解釈される為、
		//		[+1]ではそれぞれ "1"  "0"  "-1" で結果 "10-1"   となり、
		//		[-1]ではそれぞれ "-1" "-2" "-3" で結果 "-1-2-3" となる。
		//	・"0x89AB" は、[+1]で "1x90AB" の様に数字部分を別々に10進数として処理する。
		//		(16進数の自動判別には未対応。)
		//	・先頭に0(ゼロパディング)があれば、桁数を維持。
		//		但し増加の場合、桁上がりでゼロパディングが失われてしまう。
		//		"0"    → [+1]で "1"
		//		"000"  → [+1]で "001"	(桁数を維持)
		//		"099"  → [+1]で "100"	(zero-paddingは失われる)
		//		"100"  → [-1]で "99"
		//		"0100" → [-1]で "0099"	(桁数を維持)
		// 16進数で処理。(bDec=false)
		//	・アルファベット(A〜F)は、常に大文字で返すものとする。
		//		"89ab" は、[+1] で "89AC" となる。
		//	・負号があれば、負数で扱う。(bMinus=true)
		//		"A-B-C" は、"A" "-B" "-C" の3個のHEX数字が存在すると解釈される為、
		//		[+1]ではそれぞれ "B" "-A" "-B" で結果 "B-A-B" となり、
		//		[-1]ではそれぞれ "9" "-C" "-D" で結果 "9-C-D" となる。
		//	・桁数(ゼロパディング)を維持。但し増加の場合、桁上がりで1桁増えてしまう。
		//		"0000"  → [+1]で "0001"
		//		"FFFF"  → [+1]で "10000"	(桁上がりで1桁増える)
		//		"10000" → [-1]で "0FFFF"	(5桁のまま)
		//		"0001"  → [-1]で "0000"
		
		function ZenkakuNumToHankaku( str ){		// 全角数字→半角数字。
			// "0"=u+ff10, "A"=u+ff21, "a"=u+ff41  ("+"=u+ff0b, "−"=u+ff0d, "."=u+ff0e)
			return str.replace( /[0-9A-Fa-f]/g, function( $0 ){
				//var i="0123456789ABCDEFabcdef".indexOf($0);
				//return "0123456789ABCDEFabcdef".charAt(i);
				var c = $0.charCodeAt(0);
				c += (c>=0xff41) ? (-0xff41+0x61) : (c>=0xff21) ? (-0xff21+0x41) : (-0xff10+0x30);
				return String.fromCharCode( c ); } );
		}
		function HankakuNumToZenkaku( str ){		// 半角数字→全角数字。
			return str.replace( /[0-9A-Fa-f]/g, function( $0 ){
				var c = $0.charCodeAt(0);
				c += (c>=0x61) ? (-0x61+0xff41) : (c>=0x41) ? (-0x41+0xff21) : (-0x30+0xff10);
				return String.fromCharCode( c ); } );
		}
		
		// 増減処理。
		bDec		= radioDec.checked;
		bFullWidth	= checkboxFullWidth.checked;
		bFraction	= checkboxFraction.checked;
		bMinus		= checkboxMinus.checked;
		reDecAry = [		// (各条件をやや強引に統合したので使わない空の括弧がある。)
			[	/([+-]?)()(?:([0-9]+)()())/g,							// [0=半角][0=小数扱いせず]
				/([+-]?)()(?:([0-9]+)(\.[0-9]*)?|\.([0-9]+))/g			// [0=半角][1=小数部変更なし]
			],
			[	/([+−]?)()(?:([0-9]+)()())/g,						// [1=全角][0=小数扱いせず]
				/([+−]?)()(?:([0-9]+)(.[0-9]*)?|.([0-9]+))/g	// [1=全角][1=小数部変更なし]
			]
		];
		reHexAry = [		// [ 0=半角, 1=全角 ][ 0=小数扱いせず, 1=小数部変更なし ]
			[	/([+-]?)(0x)?(?:([0-9A-F]+)()())/ig,
				/([+-]?)(0x)?(?:([0-9A-F]+)(\.[0-9A-F]*)?|\.([0-9A-F]+))/ig
			],
			[	/([+−]?)(0x)?(?:([0-9A-F]+)()())/ig,
				/([+−]?)(0x)?(?:([0-9A-F]+)(.[0-9A-F]*)?|.([0-9A-F]+))/ig
			]
		];
		nRadix = (bDec) ? 10 : 16;		// parseInt(str,nRadix), toString(nRadix)
		iZenkakuLoop = (bFullWidth) ? 2 : 1;
		for(iZenkaku=0; iZenkaku < iZenkakuLoop; iZenkaku++){		// 0=半角処理、1=全角処理。
			sPlusChar	= [ "+", "+" ][ iZenkaku ];
			sMinusChar	= [ "-", "−" ][ iZenkaku ];
			sPeriodChar	= [ ".", "." ][ iZenkaku ];
			sZeroChar	= [ "0", "0" ][ iZenkaku ];
			re = ((bDec) ? reDecAry : reHexAry)[ iZenkaku ][ bFraction -0 ];	//(-0:ブール→数値化)
			sDst = sDst.replace( re, function( $0,$1,$2,$3,$4,$5 ){
				var n, s;
				// ($3及び$4) と ($6) とは背反。一方がマッチすればもう一方はundefined。
				// bFraction==false(小数扱いせず)の場合、常に ($3) のみマッチ。
				// ($n)の評価:$nが1文字以上でtrue、undefined(/空文字列/null)でfalse。
				n = (!$3) ? 0 : parseInt( (iZenkaku) ? ZenkakuNumToHankaku( $3 ) : $3, nRadix );
				if( (!bMinus) && (n == 0) && (nStep < 0) ) return $0;	// 最小値0のまま。
				if( (bMinus) && ($1 == sMinusChar) ) n = -n;
				n += nStep;
				if( (!bMinus) && (n < 0) ) n = 0;						// 負数を扱わない→最小値0。
				
				s = Math.abs( n ).toString( nRadix ).toUpperCase();
				if( iZenkaku ) s = HankakuNumToZenkaku( s );
				if( ($3) && (s.length < $3.length) && ((!bDec) || ($3.charAt(0) == sZeroChar)) ){
					//for(i=$3.length-s.length; i>0; i--) s = sZeroChar + s;
					s = (new Array($3.length - s.length +1)).join(sZeroChar) + s;	// 0埋め桁数維持。
				}
				if( $2 ) s = $2 + s;									// "0x"があれば温存(16進のみ)。
				if( (n >= 0) && ($1 == sPlusChar) ) s = $1 + s;			// "+"があれば温存。
				if( (n < 0) || ((!bMinus) && ($1 == sMinusChar)) ) s = sMinusChar + s;	// "-"付加/温存。
				if( bFraction ){
					if( $4 ) s += $4;									// 小数部を温存。
					else if( $5 ) s += sPeriodChar + $5;				// 小数部を温存。
				}
				return s;
			} );
		}
		if( sSrc == sDst ) return;		// 変更が無ければ何もせず終了。
		
		if( Editor.IsTextSelected() == 1 ){
			// 通常選択中。
			Editor.InsText( sDst );
			
			// 選択範囲の復元。
			//		最終行は、文字数の増減に合わせて選択範囲も増減させる。
			sSrcLastLine = sSrc.replace( /^(?:.|[\r\n])*[\r\n]/, "" );
			sDstLastLine = sDst.replace( /^(?:.|[\r\n])*[\r\n]/, "" );
			x2 += sDstLastLine.length - sSrcLastLine.length;
			Editor.MoveCursor( y1, x1, 0 );			// (0=未選択)
			Editor.MoveCursor( y2, x2, 1 );			// (1=通常選択)
		}else{
			// 矩形選択中。
			Editor.InsBoxText( sDst );
			
			// 選択範囲の復元。
			//		矩形選択時は、選択範囲の伸縮はせずそのままとする。
			// MoveCursor()は改行より右側へは移動しない。MoveCursorLayout()を使う。
			Editor.MoveCursorLayout( r1, c1, 0 );	// (0=未選択)
			Editor.MoveCursorLayout( r2, c2, 2 );	// (2=矩形選択)
		}
		Editor.ReDraw();
	}
}
</script>
 
<style>
	.clsButtonPlusMinus1	{ width: 3em; font-size: 150%; padding-top: 0.2em; }
	.clsButtonPlusMinus		{ width: 3em; font-size: 120%; }
</style>
 
<hta:application id="oHTA"
	applicationname="Hta"
	maximizebutton="no" minimizebutton="no" scroll="no" selection="no"
	後ろに隠れると不便な為割愛→showintaskbar="no"
/>
<!-- <HTA:APPLICATION ID="oMyApp"
	APPLICATIONNAME="appname"	VERSION="1.0"			SINGLEINSTANCE="no"	SHOWINTASKBAR="yes"
	NAVIGABLE="no"				WINDOWSTATE="normal"	BORDER="thick"		INNERBORDER="yes"
	BORDERSTYLE="normal"		CONTEXTMENU="yes"		SELECTION="yes"		SCROLL="yes"
	SCROLLFLAT="no"				CAPTION="yes"			ICON="explorer.exe"	SYSMENU="yes"
	MAXIMIZEBUTTON="yes"		MINIMIZEBUTTON="yes"	/>
-->
 
</head>
 
 
 
<body style="background-color: ButtonFace; font-size: 10pt;"
	onload="init();"
	onkeydown="body_onKeydown();">
 
<div id="divTips"
	style="position: absolute; left: 4px; top: 4px; z-index: 1; visibility: hidden;
		margin-right: 4px; padding: 5px 7px 9px 7px; border: solid thin; background-color: Window;">
</div>
<div>選択範囲の数字の増減を行います。</div>
<div style="margin: 1em 0 0 3em;">
	<input type="button" id="buttonPlus1" name="buttonPlus1" class="clsButtonPlusMinus1" value="+1"
		onclick="buttonPlusMinus_onClick( +1 );" />
	<input type="button" id="buttonPlus5" name="buttonPlus5" class="clsButtonPlusMinus" value="+5"
		onclick="buttonPlusMinus_onClick( +5 );" />
	<input type="button" id="buttonPlus10" name="buttonPlus10" class="clsButtonPlusMinus" value="+10"
		onclick="buttonPlusMinus_onClick( +10 );" />
</div>
<div style="margin: 1em 0 0 3em;">
	<input type="button" id="buttonMinus1" name="buttonMinus1" class="clsButtonPlusMinus1" value="-1"
		onclick="buttonPlusMinus_onClick( -1 );" />
	<input type="button" id="buttonMinus5" name="buttonMinus5" class="clsButtonPlusMinus" value="-5"
		onclick="buttonPlusMinus_onClick( -5 );" />
	<input type="button" id="buttonMinus10" name="buttonMinus10" class="clsButtonPlusMinus" value="-10"
		onclick="buttonPlusMinus_onClick( -10 );" />
</div>
<div style="margin: 2em 0 1em 0;">
	<label title='10進数で扱います。&#10;&#10;補足:&#10;"0x123" は、[+1]すると "1x124" になります。16進数では扱われず、"x" の前後の数字が別々に10進数として処理されます。'
	 	style="margin-left: 1em;"
		onmousedown="label_onMousedown();" onmouseout="label_onMouseout();"
	>
		<input type="radio" name="radioNotation" id="radioDec" value="DEC" accesskey="D" checked="checked" />10進(<u>D</u>)
	</label>
	<label title='16進数で扱います。&#10;&#10;補足:&#10;アルファベット(A〜F)は、常に大文字になります。'
		style="margin-left: 1em;"
		onmousedown="label_onMousedown();" onmouseout="label_onMouseout();"
	>
		<input type="radio" name="radioNotation" id="radioHex" value="HEX" accesskey="H" />16進(<u>H</u>)
	</label>
</div>
<div>
	<label title='全角数字も扱います。&#10;半角数字とは区別され、(混在していても)別々に処理されます。'
		onmousedown="label_onMousedown();" onmouseout="label_onMouseout();"
	>
		<input type="checkbox" id="checkboxFullWidth" name="checkboxFullWidth" accesskey="Z" />全角数字も扱う(<u>Z</u>)
	</label>
	<br />
	<label title='数字の前にマイナス符号 "-" があれば、負数として扱います。&#10;例: "1-5"&#10;  チェックオン: [+1]すると "2-4" 。&#10;  チェックオフ: [+1]すると "2-6" 。&#10;&#10;チェックオフの場合、"0" は[-1]しても "0" のままです。'
		onmousedown="label_onMousedown();" onmouseout="label_onMouseout();"
	>
		<input type="checkbox" id="checkboxMinus" name="checkboxMinus" accesskey="M" />負数を扱う(<u>M</u>)
	</label>
	<br />
	<label title='数字の前にピリオド "." があれば、ピリオド以降の数字は小数部とみなし、変更されません。&#10;チェックオフの場合、ピリオド前後の数字は別々に処理されます。&#10;例: "1.23"&#10;  チェックオン: [+1]すると "2.23" 。&#10;  チェックオフ: [+1]すると "2.24" 。'
		onmousedown="label_onMousedown();" onmouseout="label_onMouseout();"
	>
		<input type="checkbox" id="checkboxFraction" name="checkboxFraction" accesskey="F" />小数部は変更しない(<u>F</u>)
	</label>
	<span id="spanButtonClosePositionOrigin">&nbsp;</span>
</div>
<button type="button" id="buttonClose" name="buttonClose" accesskey="C"
	style="width: 8em; padding: 0.5em 0.5em;   position: absolute; left: 14em; top: 15em;"
	onclick="window.close();">
	閉じる(<u>C</u>)
</button>
 
</body>
</html>
 
<!--
*/
// -->


URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

添付ファイル: fileNumberUpDownHta.js 182件 [詳細]

リロード   新規 編集 凍結 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2014-05-31 (土) 23:43:24 (3579d)