1 #include <CtrlLib/CtrlLib.h>
2 
3 #include <SysInfo/SysInfo.h>
4 #include <DropGrid/DropGrid.h>
5 
6 using namespace Upp;
7 
8 #include "SysInfo_demo_gui.h"
9 
10 #define IMAGEFILE <SysInfo_demo_gui/SysInfo_demo_gui.iml>
11 #define IMAGECLASS Images
12 #include <Draw/iml.h>
13 #define LAYOUTFILE <SysInfo_demo_gui/SysInfo_demo_gui.lay>
14 
15 
16 GUI_APP_MAIN {
17 	SysInfoDemo program;
18 
19 	SetLanguage(LNGC_('E','N','U','S', CHARSET_UTF8));
20 
21 	program.Run();
22 }
23 
24 void SpecialFolders::Fill() {
25 	TextDesktop = GetDesktopFolder();
26 	TextPrograms = GetProgramsFolder();
27 	TextApplication = GetAppDataFolder();
28 	TextMusic = GetMusicFolder();
29 	TextPictures = GetPicturesFolder();
30 	TextVideo = GetVideoFolder();
31 	TextPersonal = GetPersonalFolder();
32 	TextTemplates = GetTemplatesFolder();
33 	TextDownload = GetDownloadFolder();
34 	TextTemp = GetTempFolder();
35 	TextOs = GetOsFolder();
36 	TextSystem = GetSystemFolder();
37 
38 	DefaultExes.Reset();
39 	DefaultExes.AddColumn("Extension", 5);
40 	DefaultExes.AddColumn("Program", 40);
41 	const char *ext[] = {".html", ".doc", ".png", ".pdf", ".txt", ".xyz", ""};
42 	for (int i = 0; *ext[i] != 0; ++i)
43 		DefaultExes.Add(ext[i], GetExtExecutable(ext[i]));
44 #if defined(PLATFORM_WIN32)
45 	ButInstalledSoftware.WhenPush = THISBACK(ButInstalledSoftware_Push);
46 #else
47 	SoftwareInstalled.Enable(false);
48 	ButInstalledSoftware.Enable(false);
49 #endif
50 }
51 
ButInstalledSoftware_Push()52 void SpecialFolders::ButInstalledSoftware_Push() {
53 #if defined(PLATFORM_WIN32)
54 	ButInstalledSoftware.SetLabel("Getting list ...");
55 	ButInstalledSoftware.ProcessEvents();
56 	SoftwareInstalled.Reset();
57 	SoftwareInstalled.AddColumn("Name", 60);
58 	SoftwareInstalled.AddColumn("Version", 15);
59 	SoftwareInstalled.AddColumn("Vendor", 30);
60 	SoftwareInstalled.AddColumn("Install Date", 15);
61 	SoftwareInstalled.AddColumn("Caption", 60);
62 	SoftwareInstalled.AddColumn("Description", 60);
63 	SoftwareInstalled.AddColumn("Install State", 10);
64 	Array <Value> name, version, vendor, caption, installDate, description, state;
65 	if (GetPackagesInfo(name, version, vendor, installDate, caption, description, state)) {
66 		for (int i = 0; i < name.GetCount(); ++i)
67 			SoftwareInstalled.Add(name[i], version[i], vendor[i], installDate[i], caption[i], description[i], state[i]);
68 	}
69 	ButInstalledSoftware.SetLabel("Get installed software list");
70 #endif
71 }
72 
Fill()73 void SystemInfo::Fill() {
74 	String manufacturer, productName, version, mbSerial;
75 	Date releaseDate;
76 	int numberOfProcessors;
77 	GetSystemInfo(manufacturer, productName, version, numberOfProcessors, mbSerial);
78 
79 	TextManufacturer = manufacturer;
80 	TextProductName = productName;
81 	TextVersion = version;
82 	TextNumber = FormatInt(numberOfProcessors);
83 	TextSpeed = Format("%.3f GHz", GetCpuSpeed()/1000.);
84 	TextTemperature = FormatDouble(GetCpuTemperature());
85 	bool discharging;
86 	int percentage, remainingMin;
87 	if (GetBatteryStatus(discharging, percentage, remainingMin)) {
88 		TextAC = discharging ? "Off" : "On";
89 		if (!IsNull(remainingMin))
90 			TextRemaining = FormatInt(remainingMin) + " min";
91 		else
92 			TextRemaining = "";
93 	}
94 	TextMotherboardSerial = mbSerial;
95 
96  	String biosVersion, biosSerial;
97  	Date biosReleaseDate;
98 	GetBiosInfo(biosVersion, biosReleaseDate, biosSerial);
99 	TextBiosVersion = biosVersion;
100 	TextBiosRelease = AsString(biosReleaseDate);
101 	TextBiosSerial = biosSerial;
102 
103 	String kernel, kerVersion, kerArchitecture, distro, distVersion, desktop, deskVersion;
104 	if (GetOsInfo(kernel, kerVersion, kerArchitecture, distro, distVersion, desktop, deskVersion)) {
105 		TextKernel = kernel;
106 		TextKerVersion = kerVersion;
107 		TextKerArchitecture = kerArchitecture;
108 		TextDistro = distro;
109 		TextDistVersion = distVersion;
110 		TextDesktop = desktop;
111 		TextDeskVersion = deskVersion;
112 	}
113 
114 	String nname, domain, ip4, ip6;
115 	if (GetNetworkInfo(nname, domain, ip4, ip6)) {
116 		Textnname = nname;
117 		TextDomain = domain;
118 		TextIp4 = ip4;
119 		TextIp6 = ip6;
120 	}
121 
122 	int memoryLoad;
123 	uint64 totalPhys, freePhys, totalPageFile, freePageFile, totalVirtual, freeVirtual;
124 	if (GetMemoryInfo(memoryLoad, totalPhys, freePhys, totalPageFile, freePageFile, totalVirtual, freeVirtual)) {
125 		TextMemPercentage = FormatInt(memoryLoad);
126 		TextMemTotPhysicalbytes = Format64(totalPhys);
127 		TextMemTotPhysical = BytesToString(totalPhys);
128 		TextMemFreePhysicalbytes = Format64(freePhys);
129 		TextMemFreePhysical = BytesToString(freePhys);
130 		TextMemTotPagingbytes = Format64(totalPageFile);
131 		TextMemTotPaging = BytesToString(totalPageFile);
132 		TextMemFreePagingbytes = Format64(freePageFile);
133 		TextMemFreePaging = BytesToString(freePageFile);
134 		TextMemTotVirtualbytes = Format64(totalVirtual);
135 		TextMemTotVirtual = BytesToString(totalVirtual);
136 		TextMemFreeVirtualbytes = Format64(freeVirtual);
137 		TextMemFreeVirtual = BytesToString(freeVirtual);
138 	}
139 	String compiler, mode;
140 	Time tim;
141 	int compilerVersion, bits;
142 	GetCompilerInfo(compiler, compilerVersion, tim, mode, bits);
143 	TextCompiler = compiler;
144 	TextCompilerVersion = FormatInt(compilerVersion);
145 	TextCompilationDate = Format(tim);
146 	TextCompilationMode = mode;
147 	TextCompilationBits = FormatInt(bits);
148 
149 	Processors.Reset();
150 	Processors.AddColumn("Processor", 6);
151 	Processors.AddColumn("Vendor", 12);
152 	Processors.AddColumn("Identifier", 40);
153 	Processors.AddColumn("Architecture", 30);
154 	Processors.AddColumn("Speed MHz", 10);
155 	String vendor, identifier, architecture;
156 	int speed;
157 	for (int i = 0; i < numberOfProcessors; ++i) {
158 		GetProcessorInfo(i, vendor, identifier, architecture, speed);
159 		Processors.Add(Format("#%d", i), vendor, identifier, architecture, FormatInt(speed));
160 	}
161 #if defined(PLATFORM_WIN32)
162 	Video.Reset();
163 	Video.AddColumn("Name", 10);
164 	Video.AddColumn("Description", 10);
165 	Video.AddColumn("Video Processor", 10);
166 	Video.AddColumn("Adapter RAM Mb", 6);
167 	Video.AddColumn("Video Mode Description", 10);
168 	Array <Value> name, description, videoProcessor, videoMode, ram;
169 	if (GetVideoInfo(name, description, videoProcessor, ram, videoMode)) {
170 		for (int i = 0; i < name.GetCount(); ++i)
171 			Video.Add(name[i], description[i], videoProcessor[i], ram[i], videoMode[i]);
172 	} else
173 		Video.Add("Video data not accesible");
174 #else
175 	Video.Enable(false);
176 #endif
177 	Drives.Reset();
178 	Drives.AddColumn("Path", 10);
179 	Drives.AddColumn("Type", 10);
180 	Drives.AddColumn("Volume", 10);
181 	Drives.AddColumn("Max name", 5);
182 	Drives.AddColumn("File System", 5);
183 	Drives.AddColumn("Total User bytes", 10);
184 	Drives.AddColumn("Total User", 6);
185 	Drives.AddColumn("Free User bytes", 10);
186 	Drives.AddColumn("Free User", 6);
187 	Drives.AddColumn("Total Free bytes", 10);
188 	Drives.AddColumn("Total Free", 6);
189 	Vector<String> drives;
190 	drives = GetDriveList();
191 	for (int i = 0; i < drives.GetCount(); ++i) {
192 		Vector <Value> row;
193 		row.Clear();
194 		row.Add(drives[i]);
195 		String type, volume, fileSystem;
196 		int maxName;
197 		bool mounted = GetDriveInformation(drives[i], type, volume, maxName, fileSystem);
198 		if (mounted) {
199 			row.Add(type);
200 			row.Add(volume);
201 			row.Add(maxName);
202 			row.Add(fileSystem);
203 			uint64 freeBytesUser, totalBytesUser, totalFreeBytes;
204 			if(!GetDriveSpace(drives[i], freeBytesUser, totalBytesUser, totalFreeBytes))
205 				row.Add("Installed but no access to drive");
206 			else {
207 				row.Add(Format64(totalBytesUser));
208 				row.Add(BytesToString(totalBytesUser));
209 				row.Add(Format64(freeBytesUser));
210 				row.Add(BytesToString(freeBytesUser));
211 				row.Add(Format64(totalFreeBytes));
212 				row.Add(BytesToString(totalFreeBytes));
213 			}
214 		} else
215 			row.Add("Not mounted");
216 
217 		Drives.Add(row);
218 	}
219 	Adapters.Reset();
220 	Adapters.AddColumn("Type", 10);
221 	Adapters.AddColumn("Description", 20);
222 	Adapters.AddColumn("Fullname", 20);
223 	Adapters.AddColumn("MAC", 10);
224 	Adapters.AddColumn("IP4", 10);
225 	Adapters.AddColumn("IP6", 10);
226 	Array <NetAdapter> adapters = GetAdapterInfo();
227 	for (int i = 0; i < adapters.GetCount(); ++i)
228 		Adapters.Add(adapters[i].type, adapters[i].description, adapters[i].fullname,
229 				   adapters[i].mac, adapters[i].ip4, adapters[i].ip6);
230 	ButUpdate.WhenPush = THISBACK(ButUpdate_Push);
231 }
232 
ButUpdate_Push()233 void SystemInfo::ButUpdate_Push() {
234 	Fill();
235 }
236 
237 
238 #if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
239 
240 #define SetBit(uIntFlagBuff, Bit)  		(uIntFlagBuff |= (Bit))
241 #define ClearBit(uIntFlagBuff, BitNum) 	(uIntFlagBuff  = ((uIntFlagBuff) | (BitNum)) ^ (BitNum) )
242 static const char   *styles[] 	 = {"WS_CAPTION","WS_BORDER","WS_TABSTOP","WS_CHILD","WS_THICKFRAME","WS_VISIBLE","WS_VSCROLL","WS_HSCROLL","WS_SYSMENU","WS_SIZEBOX","WS_POPUP","WS_MINIMIZE","WS_MAXIMIZE","WS_MINIMIZEBOX","WS_MAXIMIZEBOX","WS_GROUP","WS_DLGFRAME","WS_CLIPSIBLINGS","WS_CLIPCHILDREN","WS_CHILDWINDOW","WS_DISABLED"};
243 static const uint64 stylesbits[] = {WS_CAPTION,WS_BORDER,WS_TABSTOP,WS_CHILD,WS_THICKFRAME,WS_VISIBLE,WS_VSCROLL,WS_HSCROLL,WS_SYSMENU,WS_SIZEBOX,WS_POPUP,WS_MINIMIZE,WS_MAXIMIZE,WS_MINIMIZEBOX,WS_MAXIMIZEBOX,WS_GROUP,WS_DLGFRAME,WS_CLIPSIBLINGS,WS_CLIPCHILDREN,WS_CHILDWINDOW,WS_DISABLED};
244 static const char   *exstyles[]  = {"WS_EX_ACCEPTFILES","WS_EX_APPWINDOW","WS_EX_CLIENTEDGE","WS_EX_COMPOSITED","WS_EX_CONTROLPARENT","WS_EX_DLGMODALFRAME","WS_EX_LAYERED","WS_EX_LAYOUTRTL","WS_EX_LEFTSCROLLBAR","WS_EX_MDICHILD","WS_EX_NOACTIVATE","WS_EX_NOINHERITLAYOUT","WS_EX_NOPARENTNOTIFY"/*,"WS_EX_NOREDIRECTIONBITMAP"*/,"WS_EX_RIGHT","WS_EX_PALETTEWINDOW(WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_TOPMOST)","WS_EX_STATICEDGE","WS_EX_TOOLWINDOW","WS_EX_TOPMOST","WS_EX_TRANSPARENT","WS_EX_WINDOWEDGE"};
245 static const uint64 exstylesbits[] = {WS_EX_ACCEPTFILES,WS_EX_APPWINDOW,WS_EX_CLIENTEDGE,WS_EX_COMPOSITED,WS_EX_CONTROLPARENT,WS_EX_DLGMODALFRAME,WS_EX_LAYERED,WS_EX_LAYOUTRTL,WS_EX_LEFTSCROLLBAR,WS_EX_MDICHILD,WS_EX_NOACTIVATE,WS_EX_NOINHERITLAYOUT,WS_EX_NOPARENTNOTIFY/*,WS_EX_NOREDIRECTIONBITMAP*/,WS_EX_RIGHT,WS_EX_PALETTEWINDOW,WS_EX_STATICEDGE,WS_EX_TOOLWINDOW,WS_EX_TOPMOST,WS_EX_TRANSPARENT,WS_EX_WINDOWEDGE};
246 
247 struct SOptDropGrid: public DropGrid {
248 	int64 hwnd;
249 	ArrayOption option;
250 	typedef SOptDropGrid CLASSNAME;
251 
SOptDropGridSOptDropGrid252 	SOptDropGrid() {
253 		hwnd = 0;
254 		ClearButton();
255 		//AddPlus(THISBACK(action));
256 		AddColumn("Style", 60).Ctrls<Option>();
257 		AddColumn("Hexbit");
258 		AddColumn("Bit", 0).Hidden();
259 		Width(280);
260 	}
InitSOptDropGrid261 	void Init(int64 wnd) {
262 		hwnd = wnd;
263 		int row = 0;
264 		//SetData("-- Regular styles --");
265 		Ready(false);
266 		StaticText *st;
267 		Add(0, 0, 0);
268 		st = new StaticText;
269 		*st= "-- click me --";
270 		*st <<= THISBACK(Action);
271 		GetList().SetCtrl(0, 0, st);
272 		++row;
273 		Add(0, 0, 0);
274 		st = new StaticText;
275 		*st = "-- Regular styles --";
276 		GetList().SetCtrl(1, 0, st);
277 		++row;
278 		Option *po;
279 		for(int i = 0; i < sizeof(styles)/sizeof(styles[0]); ++i, row++) {
280 			po = new Option;
281 			po->Set((stylesbits[i]&GetWindowLong((HWND)hwnd, GWL_STYLE) ? true : false));
282 			po->SetLabel(styles[i]);
283 			*po <<= THISBACK(Action);
284 			Add(po->Get(), ::Format("0x%08x", (int64)stylesbits[i]), *(int64*)&stylesbits[i]);
285 			GetList().SetCtrl(row, 0, po);
286 		}
287 		Add(0, 0);
288 		st = new StaticText;
289 		*st = "** Extendes styles **";
290 		GetList().SetCtrl(row, 0, st);
291 		++row;
292 		for(int i = 0; i < sizeof(exstyles)/sizeof(exstyles[0]); row++, ++i){
293 			po = new Option;
294 			po->Set((stylesbits[i]&GetWindowLong((HWND)hwnd,GWL_EXSTYLE)) ? true : false);
295 			po->SetLabel(exstyles[i]);
296 			*po <<= THISBACK(Action);
297 			Add(po->Get(), ::Format("0x%08x", (int64)exstylesbits[i]), *(int64*)&exstylesbits[i]);
298 			GetList().SetCtrl(row, 0, po);
299 		}
300 		Ready(true);
301 		/*GetList().SetCursor(0);
302 		SetIndex(0);
303 		SetData("-- click me --");*/
304 	}
ActionSOptDropGrid305 	void Action() {
306 		int rowind = GetCurrentRow();
307 		uint64 bit = (int64)Get(2);
308 		if(bit == 0) {
309 			TopWindow tw;
310 			tw.Title("~~~~~");
311 			Image img = Images::hat;
312 			ImageCtrl ic;
313 			ic.SetImage(img).SetRect(0, 0, img.GetWidth(), img.GetHeight());
314 			tw.Add(ic);
315 			tw.SetRect(::GetMousePos().x - 20, GetMousePos().y - 20, img.GetWidth(), img.GetHeight());
316 			tw.RunAppModal();
317 			return;
318 		}
319 		bool on = ((Option*)GetList().GetCtrl(0))->Get() == 1;
320 		uint64 bits = GetWindowLong((HWND)hwnd, (rowind>3+sizeof(stylesbits)/sizeof(stylesbits[0])) ? GWL_EXSTYLE : GWL_STYLE);
321 		if(on)
322 			SetBit(bits, bit);
323 		else
324 			ClearBit(bits, bit);
325 		SetWindowLong((HWND)hwnd, (rowind > 3 + sizeof(stylesbits)/sizeof(stylesbits[0])) ? GWL_EXSTYLE : GWL_STYLE, (LONG)bits);
326 		RedrawWindow(GetDesktopWindow(), 0, 0, RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_FRAME|RDW_ERASE);
327 		RedrawWindow((HWND)hwnd, 0, 0, RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_FRAME|RDW_ERASE);
328 	}
329 };
330 
331 #endif
332 
Fill()333 void WindowsList_::Fill() {
334 	Windows.Reset();
335 	Windows.AddColumn("Title", 30);
336 	Windows.AddColumn("Window handle", 8);
337 	Windows.AddColumn("Process Id", 8);
338 	Windows.AddColumn("Name", 20);
339 	Windows.AddColumn("File name", 30);
340 #if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
341 	Windows.AddColumn("Window styles", 23).Ctrls<SOptDropGrid>();
342 	Windows.AddColumn("Window class", 23);
343 #endif
344 	Array<int64> widL, pidL;
345 	Array<String> name, fileName, caption;
346 	GetWindowsList(widL, pidL, name, fileName, caption);
347 	for (int i = 0; i < widL.GetCount(); ++i) {
348 #if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
349 		char classname[64];
350 		GetClassName(reinterpret_cast<HWND>(widL[i]), classname, 64);
351 		Windows.Add(caption[i], Format64(widL[i]), Format64(pidL[i]), name[i], fileName[i], "Text", classname);
352 		SOptDropGrid *dg = (SOptDropGrid*)Windows.GetCtrl(i, 5);
353 		dg->Init(widL[i]);
354 #else
355 		Windows.Add(caption[i], Format64(widL[i]), Format64(pidL[i]), name[i], fileName[i]);
356 #endif
357 	}
358 	Windows.SetEditable();
359 	ButUpdate.WhenPush = THISBACK(ButUpdate_Push);
360 	#if defined(PLATFORM_WIN32)
361 	ButTopmost.WhenPush = THISBACK(ButTopmost_Push);
362 	#else
363 	ButTopmost.Disable();
364 	#endif
365 	static MenuBar bar;
366 	//GetList().StdToolBar(bar); //bar(2).Remove();bar(1).Remove();
367 	//GetList().WhenToolBar=THISBACK(cb);
368 	Windows.WhenBar = THISBACK(MenuCallback);
369 }
370 
371 #if defined(PLATFORM_WIN32)
ButTopmost_Push()372 void WindowsList_::ButTopmost_Push() {
373 	int row = Windows.GetCursor();
374 	if (row < 0)
375 		return;
376 	int64 id = ScanInt64(String(Windows.Get(row, 1)));
377 	Window_TopMost(id);
378 }
379 #endif
380 
CbCopy()381 void WindowsList_::CbCopy() {
382 	String text;
383 	HeaderCtrl& header = Windows.HeaderObject();
384 	for(int i = 0; i < header.GetCount(); i++) {
385 		if(!header.IsTabVisible(i))
386 			continue;
387 		if(!text.IsEmpty())
388 			text << " | ";
389 		text << Windows.Get(i);
390 	}
391 	WriteClipboardText(text);
392 }
393 
MenuCallback(Bar & bar)394 void WindowsList_::MenuCallback(Bar &bar){
395 	//Windows.SetClipboard(true,false);
396 	bar.AddMenu(true, "Copy", CtrlImg::copy(), THISBACK(CbCopy));
397 }
398 
ButUpdate_Push()399 void WindowsList_::ButUpdate_Push() {
400 	Fill();
401 }
402 
Fill()403 void ProcessList::Fill() {
404 	Process.Reset();
405 	Process.AddColumn("Id", 6);
406 	Process.AddColumn("Priority", 6);
407 	Process.AddColumn("Program", 12);
408 	Array<int64> pidL;
409 	pidL.Clear();
410 	Array<String> pNames;
411 	if (!GetProcessList(pidL, pNames))
412 		Process.Add("Error getting process info");
413 	else {
414 		for (int i = 0; i < pidL.GetCount(); ++i) {
415 			int priority = GetProcessPriority(pidL[i]);
416 			Process.Add(Format64(pidL[i]), priority >= 0? FormatInt(priority): "Not accesible", pNames[i]);
417 		}
418 	}
419 	ButUpdate.WhenPush = THISBACK(ButUpdate_Push);
420 }
ButUpdate_Push()421 void ProcessList::ButUpdate_Push() {
422 	Fill();
423 }
424 
Fill()425 void ScreenGrabTab::Fill() {
426 	EditFileNameGrab <<= AppendFileName(GetDesktopFolder(), "ScreenGrab.avi");
427 	EditTime <<= 5;
428 	EditFrameRate <<= 1;
429 	OpGrabMouse <<= true;
430 	SwGrabMode.Add("Desktop");
431 	SwGrabMode.Add("Window");
432 	SwGrabMode.Add("Rectangle");
433 	SwGrabMode.MinCaseHeight(20);
434 	SwGrabMode.SetData(0);
435 	SwGrabMode.WhenAction = THISBACK(SwGrabMode_Action);
436 	SwGrabMode_Action();
437 	ButGrab.WhenPush = THISBACK(ButGrab_Push);
438 
439 	//ButGrab.Enable(false);
440 	//EditFileNameGrab.Enable(false);
441 	//EditTime.Enable(false);
442 	//EditFrameRate.Enable(false);
443 	//OpGrabMouse.Enable(false);
444 
445 	String extension = "jpg";
446 	EditFileNameSnap <<= AppendFileName(GetDesktopFolder(), "ScreenSnap." + extension);
447 	ButSnap.WhenPush = THISBACK(ButSnap_Push);
448 }
449 
SwGrabMode_Action()450 void ScreenGrabTab::SwGrabMode_Action() {
451 	switch(int(~SwGrabMode)) {
452 	case 0:
453 		EditLeft.Enable(false);
454 		EditTop.Enable(false);
455 		EditWidth.Enable(false);
456 		EditHeight.Enable(false);
457 		EditWindowTitle.Enable(false);
458 		break;
459 	case 1:
460 		EditLeft.Enable(false);
461 		EditTop.Enable(false);
462 		EditWidth.Enable(false);
463 		EditHeight.Enable(false);
464 		EditWindowTitle.Enable(true);
465 		break;
466 	case 2:
467 		EditLeft.Enable(true);
468 		EditTop.Enable(true);
469 		EditWidth.Enable(true);
470 		EditHeight.Enable(true);
471 		EditWindowTitle.Enable(false);
472 		break;
473 	}
474 }
475 
ButGrab_Push()476 void ScreenGrabTab::ButGrab_Push() {
477 #if defined(PLATFORM_WIN32)
478 	FileDelete(EditFileNameGrab.GetData().ToString());
479 
480 	bool ret;
481 	if (~SwGrabMode == 0)
482 		ret = Record_Desktop(~EditFileNameGrab, EditTime, EditFrameRate, OpGrabMouse);
483 	else if (~SwGrabMode == 1)
484 		ret = Record_Window(~EditFileNameGrab, EditTime, GetWindowIdFromCaption(~EditWindowTitle, false), EditFrameRate, OpGrabMouse);
485 	else if (~SwGrabMode == 2)
486 		ret = Record_DesktopRectangle(~EditFileNameGrab, EditTime, EditLeft, EditTop, EditWidth, EditHeight, EditFrameRate, OpGrabMouse);
487 	else
488 		throw Exc("Unexpected value");
489 	if (!ret)
490 		Exclamation("Error on grabbing");
491 #endif
492 }
493 
Fill()494 void MouseKeyboard::Fill() {
495 	OnTimer();
496 #ifndef flagNO_XTEST
497 	capsLock.WhenAction = THISBACK(OnButLock);
498 	numLock.WhenAction = THISBACK(OnButLock);
499 	scrollLock.WhenAction = THISBACK(OnButLock);
500 	butKey.WhenAction = THISBACK(OnButKey);
501 	butMouse.WhenAction = THISBACK(OnButMouse);
502 #else
503 	capsLock.Enable(false);
504 	numLock.Enable(false);
505 	scrollLock.Enable(false);
506 	butKey.Enable(false);
507 	butMouse.Enable(false);
508 #endif
509 	editAccents <<= "Århus Ørsted Ñandú\ncrème brûlée";
510 	editAccents.SetFont(Courier(12));
511 	OnRemoveAccents();
512 	butRemoveAccents.WhenAction = THISBACK(OnRemoveAccents);
513 }
514 
OnTimer()515 void MouseKeyboard::OnTimer() {
516 	bool caps, num, scroll;
517 
518 	GetKeyLockStatus(caps, num, scroll);
519 	capsLock <<= caps;
520 	numLock <<= num;
521 	scrollLock <<= scroll;
522 }
523 
OnRemoveAccents()524 void MouseKeyboard::OnRemoveAccents() {
525 	labNoAccents = RemoveAccents(~editAccents);
526 }
527 
528 #ifndef flagNO_XTEST
529 
OnButLock()530 void MouseKeyboard::OnButLock() {
531 	SetKeyLockStatus(~capsLock, ~numLock, ~scrollLock);
532 }
533 
OnButKey()534 void MouseKeyboard::OnButKey() {
535 	String fileTest = AppendFileName(GetDesktopFolder(), "test.txt");
536 	SaveFile(fileTest, "Please wait a second...");
537 	LaunchFile(fileTest);
538 	{
539 		TimeStop t;
540 		uint64 windowId;
541 		while(INT64_MAX == (windowId = GetWindowIdFromCaption("test.txt", false))) {
542 			if (t.Elapsed() > 10000)
543 				break;
544 		}
545 		if (windowId != -1) {
546 			Sleep(1000);
547 			Mouse_SetPos(200, 200, windowId);
548 			Mouse_LeftClick();
549     		Keyb_SendKeys("{HOME}This text is added by Keyb_SendKeys.\n");
550     		Keyb_SendKeys("Some chars just for test: \\/:;,.ºª^[]{}´?¿~#@!¡\n");
551     		Keyb_SendKeys("These are accented: äáéíóúñÄÁÉÍÓÚÑ\n");
552     		//Keyb_SendKeys("And these are not latin at all: 雅言 한국말 韓國말 조선어 朝鮮語\n");
553     		Keyb_SendKeys("And these are not latin at all: 韓于页\n");
554 		}
555 	}
556 }
557 
OnButMouse()558 void MouseKeyboard::OnButMouse()
559 {
560 	uint64 wnd = GetWindowIdFromCaption("SysInfo", true);
561 
562 	if (wnd == -1) {
563 		Exclamation("Window not found");
564 		return;
565 	}
566 	int left, top, right, bottom;
567 	Window_GetRect(wnd, left, top, right, bottom);
568 #ifdef PLATFORM_POSIX
569 	top -= 10;
570 #endif
571 	Mouse_SetPos(left+100, top+5, 0);
572 	Sleep(100);
573 	Mouse_LeftDown();
574 	Sleep(100);
575 	Mouse_SetPos(left+100, top+200, 0);
576 	Sleep(100);
577 	Mouse_LeftUp();
578 	Ctrl::ProcessEvents();
579 	Sleep(300);
580 	Mouse_LeftDown();
581 	Sleep(100);
582 	Mouse_SetPos(left+300, top+200, 0);
583 	Sleep(100);
584 	Mouse_LeftUp();
585 	Ctrl::ProcessEvents();
586 	Sleep(300);
587 	Mouse_LeftDown();
588 	Sleep(100);
589 	Mouse_SetPos(left+100, top+5, 0);
590 	Sleep(100);
591 	Mouse_LeftUp();
592 }
593 
594 #endif
595 
ButSnap_Push()596 void ScreenGrabTab::ButSnap_Push()
597 {
598 	FileDelete(EditFileNameSnap.GetData().ToString());
599 
600 	if (~SwGrabMode == 0)
601 		Snap_Desktop(~EditFileNameSnap);
602 	else if (~SwGrabMode == 1) {
603 		int64 wId = GetWindowIdFromCaption(~EditWindowTitle, true);
604 		if (wId == -1)
605 			Exclamation("No window found named " + String(~EditWindowTitle));
606 		else
607 			Snap_Window(~EditFileNameSnap, wId);
608 	} else if (~SwGrabMode == 2)
609 		Snap_DesktopRectangle(~EditFileNameSnap, ~EditLeft, ~EditTop, ~EditWidth, ~EditHeight);
610 	else
611 		throw Exc("Unexpected value");
612 }
613 
SysInfoDemo()614 SysInfoDemo::SysInfoDemo()
615 {
616 	Title("SysInfo");
617 	Icon(Images::Computer());
618 	LargeIcon(Images::Computer());
619 
620 	systemInfo.Fill();
621 	filesTab.Add(systemInfo.SizePos(), "System Info");
622 	windowsList.Fill();
623 	filesTab.Add(windowsList.SizePos(), "Windows list");
624 	processList.Fill();
625 	filesTab.Add(processList.SizePos(), "Process list");
626 	specialFolders.Fill();
627 	filesTab.Add(specialFolders.SizePos(), "Special Folders/Executables/Installed Software");
628 	screenGrab.Fill();
629 	filesTab.Add(screenGrab.SizePos(), "Screen Grab");
630 	mouseKeyboard.Fill();
631 	filesTab.Add(mouseKeyboard.SizePos(), "Mouse & Keyboard");
632 
633 	AddFrame(menu);
634 	AddFrame(TopSeparatorFrame());
635 	AddFrame(info);
636 	Add(filesTab.SizePos());
637 
638 	menu.Set(THISBACK(MainMenu));
639 	menu.WhenHelp = info;
640 
641 	timeCallback.Set(-500, THISBACK(TimerFun));
642 
643 	Sizeable().Zoomable();
644 }
645 
TimerFun()646 void SysInfoDemo::TimerFun() {
647 	mouseKeyboard.OnTimer();
648 }
649 
MainMenu(Bar & bar)650 void SysInfoDemo::MainMenu(Bar& bar) {
651 	menu.Add("Menu", THISBACK(FileMenu));
652 }
653 
FileMenu(Bar & bar)654 void SysInfoDemo::FileMenu(Bar& bar)
655 {
656 	bar.Add("About...", THISBACK(About)).Help("SysInfo demo gui: SysInfo package demo");
657 	bar.Separator();
658 	bar.Add("Exit", THISBACK(Exit)).Help("Leave the program");
659 }
660 
About()661 void SysInfoDemo::About()
662 {
663 	Prompt("SysInfo demo gui", Images::Computer(), DeQtf("SysInfo package demo"), "Close");
664 }
665 
Exit()666 void SysInfoDemo::Exit()
667 {
668 	Break();
669 }
670