Code: Alles auswählen
; Plugininterface JA!COMMANDER
; ListLoad is the same as for a TotalCommander ListerPlugin.
; ShowFlags is not supported (ignored in the moment)
Prototype.i ListLoad(ParentWin.i, FileToLoad.p-ascii, ShowFlags.l = 0)
; this is the same as above but not compatible to TotalCommander
; this functions is for Unicode DLLs
Prototype.i ListLoadW(ParentWin.i, FileToLoad.p-unicode, ShowFlags.l = 0)
; This is your cleanup function, the same as in TotalCommander
; This function is not required.
; If TC Or JA!COMMANDER doesn't found this function,
; the window becomes destroyed with DestroyWindow_(hWnd)
Prototype   ListCloseWindow(ListWin.i)
EnableExplicit
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
Global win, img, info, con, image, image_copy
Procedure.s ByteRechner(dSize.d)
	Protected Namen = $4B4D4754, i = 24, C.c, Result.s = "0"
	If dSize > 0.0
		While dSize > 1024 And i >= 0
			dSize / 1024
			C = (Namen >> i) & $FF
			i - 8
		Wend
		Result = StrD(dSize, 2) + " " + Chr(C) + "Byte"
	EndIf
	ProcedureReturn Result
EndProcedure
Procedure Win_CB(hWnd, uMsg, wParam, lParam)
	Protected File.s, pic, Result = #PB_ProcessPureBasicEvents
	Protected Pattern.s = "JPEG-Files (*.jpg, *.jpeg)|*.jpg;*.jpeg"
	Protected x, y, xf.f, yf.f
	Select uMsg
		Case #WM_SIZE
			ResizeGadget(img, #PB_Ignore, #PB_Ignore, GadgetWidth(con), GadgetHeight(con) - 100)
			ResizeGadget(info, #PB_Ignore, GadgetHeight(con) - 99, GadgetWidth(con), #PB_Ignore)
			If image
				xf         = ImageWidth(image) / ImageHeight(image)
				yf         = GadgetWidth(con) / (GadgetHeight(con) - 100)
				If IsImage(image_copy)
					FreeImage(image_copy)
				EndIf
				image_copy = CopyImage(image, #PB_Any)
				If xf > yf
					xf = GadgetWidth(con) / ImageWidth(image_copy)
					If xf > 2
						xf = 2
					EndIf
					ResizeImage(image_copy, ImageWidth(image_copy) * xf, ImageHeight(image_copy) * xf)
				Else
					xf = (GadgetHeight(con) - 100) / ImageHeight(image_copy)
					If xf > 2
						xf = 2
					EndIf
					ResizeImage(image_copy, ImageWidth(image_copy) * xf, ImageHeight(image_copy) * xf)
				EndIf
				SetGadgetState(img, ImageID(image_copy))
			EndIf
		Case #WM_COMMAND
			If wParam & $FFFF
				;Select GetDlgCtrlID_(lParam)
				;           Case btn
				;             File = OpenFileRequester("", path, Pattern, 0)
				;             If File
				;               pic = LoadImage(#PB_Any, File)
				;               ResizeImage(pic, GadgetWidth(img), GadgetHeight(img))
				;               SetGadgetState(img, ImageID(pic))
				;             EndIf
				;EndSelect
			EndIf
	EndSelect
	ProcedureReturn Result
EndProcedure
ProcedureDLL ListLoad(ParentWin, File.s, Flags)
	win = OpenWindow(#PB_Any, 0, 0, 322, 150, "PluginDemo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
	If win
		con   = ContainerGadget(#PB_Any, 0, 0, WindowWidth(win), WindowHeight(win), #PB_Container_BorderLess)
		img   = ImageGadget(#PB_Any, 0, 0, 0, 0, 0)
		info  = EditorGadget(#PB_Any, 0, 0, 320, 98, #PB_Editor_ReadOnly)
		image = LoadImage(#PB_Any, File)
		If image
			SetGadgetState(img, ImageID(image))
			AddGadgetItem(info, -1, "Name:" + #TAB$ + #TAB$ + GetFilePart(File))
			AddGadgetItem(info, -1, "Path:" + #TAB$ + #TAB$ + GetPathPart(File))
			AddGadgetItem(info, -1, "Dimension:" + #TAB$ + Str(ImageWidth(image)) + " x " + Str(ImageHeight(Image)) + " pixel")
			AddGadgetItem(info, -1, "Depth:" + #TAB$ + #TAB$ + Str(ImageDepth(image)) + " bit")
			AddGadgetItem(info, -1, "Size:" + #TAB$ + #TAB$ + ByteRechner(FileSize(File)))
		Else
			SetGadgetText(info, "unknown format")
		EndIf
		CloseGadgetList()
		SetWindowCallback(@Win_CB())
		If ParentWin
			SetParent_(GadgetID(con), ParentWin)
			ProcedureReturn GadgetID(con)
		Else
			; only for testing
			HideWindow(win, #False)
		EndIf
	EndIf
EndProcedure
ProcedureDLL ListCloseWindow(ListWin)
	If IsImage(image_copy)
		FreeImage(image_copy)
	EndIf
	If image
		FreeImage(image)
	EndIf
	FreeGadget(con)
	CloseWindow(win)
EndProcedure