// 生成所有 Unicode 字符，包括扩展字符。

try {
  var hMainWnd=AkelPad.GetMainWnd();
}
catch (oError) {
  WScript.Quit();
}

var d=new Date();
var t=d.getTime();

var sCaption =WScript.ScriptName;
var oSys     =AkelPad.SystemFunction();
var nAkelEdit=AkelPad.IsAkelEdit();
var hWndEdit =AkelPad.GetEditWnd();

SetRedraw(hWndEdit, false);

var vChar=[];

for (i=0x0020;i<=0x0FFF;i+=1) {
  x=i.toString(16);
  vChar.push(unescape("\%u" + "000".substr(0, 4-x.length)+x));
}

for (i=0x1000;i<=0xD7FF;i+=1) {
  vChar.push(unescape("\%u" + i.toString(16)));
}

for (i=0xE000;i<=0xFFFF;i+=1) {
  vChar.push(unescape("\%u" + i.toString(16)));
}

x=null;
i=null;
CollectGarbage();

// 下面语句生成扩展字符。
for (i=0xd800;i<=0xDBFF;i+=1) {
  x=i.toString(16);
  for (j=0xDC00;j<=0xDFFF;j+=1) {
    vChar.push(unescape("%u" + x + "%u" + j.toString(16)));
  }
}

x=null;
i=null;
j=null;

SetRedraw(hWndEdit, true);

AkelPad.ReplaceSel(vChar.join(" \n"));

vChar=null;
CollectGarbage();

// 显示耗时
var d=new Date();
t=(d.getTime()-t)/1000;
AkelPad.MessageBox(hMainWnd, "耗时 " + t.toString() + " 秒。", sCaption, 0 /*MB_OK*/);


function SetRedraw(hWnd, bRedraw) {
  if (nAkelEdit) {
    AkelPad.SendMessage(hWnd, 3185 /*AEM_LOCKSCROLL*/, 3 /*SB_BOTH*/, !bRedraw);
  }

  AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, bRedraw, 0);
  if (bRedraw) {
    oSys.Call("user32::InvalidateRect", hWnd, 0, true);
  }
}