It is currently Wed May 27, 2020 1:14 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Modul OwnGadget (PB5.2x)
PostPosted: Sun Jul 07, 2013 5:13 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5755
Location: Berlin - Germany
This Modul based of: viewtopic.php?p=140940

You can register your own gadget, for example API-Controls, Controls from ext. Libraries and so on.

The source uses the infos from the actual SDK.

In the moment only for windows!

Code:
;======================================================================
; Module:          OwnGadget.pbi
;
; Author:          Thomas (ts-soft) Schulz
; based on Code by edel (Hallodri)
; Date:            Jul 08, 2013
; Version:         0.8
; Target Compiler: PureBasic 5.2+
; Target OS:       in the moment only windows
; License:         Free, unrestricted, no warranty whatsoever
;                  Use at your own risk
;======================================================================

; History:
; 0.7
; removed GetGadgetParent() (UseGadgetList(0) do the same)
; put RegisterGadget() to public

; 0.8
; fixed RegisterGadget

DeclareModule OwnGadget
  Structure GadgetVT
    GadgetType.l   
    SizeOf.l       
    GadgetCallback.i
    FreeGadget.i
    GetGadgetState.i
    SetGadgetState.i
    GetGadgetText.i
    SetGadgetText.i
    AddGadgetItem2.i
    AddGadgetItem3.i
    RemoveGadgetItem.i
    ClearGadgetItemList.i
    ResizeGadget.i
    CountGadgetItems.i
    GetGadgetItemState.i
    SetGadgetItemState.i
    GetGadgetItemText.i
    SetGadgetItemText.i
    OpenGadgetList2.i
    GadgetX.i
    GadgetY.i
    GadgetWidth.i
    GadgetHeight.i
    HideGadget.i
    AddGadgetColumn.i
    RemoveGadgetColumn.i
    GetGadgetAttribute.i
    SetGadgetAttribute.i
    GetGadgetItemAttribute2.i
    SetGadgetItemAttribute2.i
    SetGadgetColor.i
    GetGadgetColor.i
    SetGadgetItemColor2.i
    GetGadgetItemColor2.i
    SetGadgetItemData.i
    GetGadgetItemData.i
    GetRequiredSize.i
    SetActiveGadget.i
    GetGadgetFont.i
    SetGadgetFont.i
    SetGadgetItemImage.i
  EndStructure

  Declare RegisterGadget(ID.i, hWnd.i, *vt.GadgetVT = 0)
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      Declare CreateGadget(ID.i, ClassName.s, Text.s, Style.l, x.i, y.i, w.i, h.i, ExStyle.l = 0, *vt.GadgetVT = 0)
  CompilerEndSelect
EndDeclareModule

Module OwnGadget
  EnableExplicit
 
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Import ""
  CompilerElse
  ImportC ""
  CompilerEndIf
    PB_Object_GetOrAllocateID(Objects.i, ID.i)
    PB_Gadget_RegisterGadget(ID.i, *Gadget, hWnd.i, *GadgetVT)
    PB_Gadget_Objects.i
  EndImport
 
  Structure Gadget
    Gadget.i
    *vt.GadgetVT
    UserData.i
    OldCallback.i
    Daten.i[4]
  EndStructure
 
  Procedure RegisterGadget(ID.i, hWnd.i, *vt.GadgetVT = 0)
    Protected *Gadget.Gadget
    Protected *vttmp.GadgetVT = AllocateMemory(SizeOf(GadgetVT))

    If Not *vttmp : ProcedureReturn #False : EndIf
         
    If Not hWnd Or ID < -1
      ProcedureReturn #False
    EndIf

    If *vt
      CopyMemory(*vt, *vttmp, SizeOf(GadgetVT))
      *vttmp\SizeOf = SizeOf(GadgetVT)
    EndIf
         
    *Gadget = PB_Object_GetOrAllocateID(PB_Gadget_Objects, ID)
    ProcedureReturn PB_Gadget_RegisterGadget(ID, *Gadget, hWnd, *vttmp)
   
  EndProcedure
 
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
    Procedure CreateGadget(ID.i, ClassName.s, Text.s, Style.l, x.i, y.i, w.i, h.i, ExStyle.l = 0, *vt.GadgetVT = 0)
      Protected hWnd.i, Parent.i = UseGadgetList(0), hInstance.i = GetModuleHandle_(0)
     
      hWnd  = CreateWindowEx_(ExStyle, ClassName, Text, Style, x, y, w, h, Parent, 0, hInstance, 0)
      SendMessage_(hWnd, #WM_SETFONT, GetGadgetFont(#PB_Default), 1)
     
      If Not hWnd : ProcedureReturn #False : EndIf
     
      ProcedureReturn RegisterGadget(ID, hWnd, *vt)
    EndProcedure
  CompilerEndSelect
EndModule

CompilerIf #PB_Compiler_IsMainFile
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
   
      Enumeration
        #btn1
        #btn2
      EndEnumeration
     
      Procedure MyButton(Gadget, x, y, width, height, Text.s)
        ProcedureReturn OwnGadget::CreateGadget(Gadget, "Button", Text, #WS_CHILD | #WS_VISIBLE, x, y, width, height)
      EndProcedure
     
      Procedure btn1_event()
        Debug "Okay pressed"
      EndProcedure
     
      Procedure Btn3_event()
        End
      EndProcedure
     
      Define btn3
      OpenWindow(0, #PB_Ignore, #PB_Ignore, 190, 100, "example")
      MyButton(#btn1, 10, 10, 80, 25, "Okay")
      BindGadgetEvent(#btn1, @btn1_event())
      MyButton(#btn2, 100, 10, 80, 25, "")
      SetGadgetText(#btn2, "Cancel")
      btn3 = MyButton(#PB_Any, 60, 60, 80, 25, "End")
      GadgetToolTip(btn3, "Close Example!")
      BindGadgetEvent(btn3, @Btn3_event())
     
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow : Break
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #btn2
                Debug "Cancel pressed"
            EndSelect
        EndSelect
      ForEver
  CompilerEndSelect
CompilerEndIf


Greetings - Thomas

_________________
PureBasic 5.71 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 19.3 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Last edited by ts-soft on Tue Jul 09, 2013 7:50 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Sun Jul 07, 2013 9:27 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3698
Location: Italy
Pretty nice template :)

Thanks for sharing.

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Sun Jul 07, 2013 9:52 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3520
Location: New Zealand
Interesting as always, thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Mon Jul 08, 2013 9:55 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4678
Location: Lyon - France
Works great, thanks TsSoft 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Wed Jul 24, 2013 5:29 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
@TSoft
Hi,
First, thanks for your GadgetVT structure. It's the most recent one that I've found.

Is it possible to define a custom DisableGadget(...) method ?

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Last edited by eddy on Wed Jul 24, 2013 5:44 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Wed Jul 24, 2013 5:40 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5755
Location: Berlin - Germany
I can't see a entry in the vtTable, so i don't know!

_________________
PureBasic 5.71 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 19.3 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Sun Jul 28, 2013 8:13 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1118
eddy wrote:
@TSoft
Hi,
First, thanks for your GadgetVT structure. It's the most recent one that I've found.

Is it possible to define a custom DisableGadget(...) method ?


You can do it in the callback proc.

Like
Code:
  Case #WM_ENABLE
    If wParam = #True
      ; DisableGadget(Gadget, #True) was used
    Else
      ; DisableGadget(Gadget, #False) was used
    EndIf

_________________
PureBasic 5.71 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Wed Jun 24, 2015 7:57 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
Is there SDK for linux or mac in PB 5.30 ?

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Wed Jun 24, 2015 9:06 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2469
Location: Germany
No way.

Only an old Linux. For Mac no SDK for occupancy and construction of GadgetVT.
Already have all searched and inquired.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Tue Jul 21, 2015 2:53 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
mk-soft wrote:
No way.

Only an old Linux. For Mac no SDK for occupancy and construction of GadgetVT.
Already have all searched and inquired.


Such a pity. It would be cool to fully integrate custom gadgets into PB.
PB has now many canvas-based custom gadgets (tabbar, gauge, button, checkbox, splitter, color picker, etc...).

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Tue Jul 21, 2015 6:17 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2469
Location: Germany
I had also thought so that you can use the standard functions.
viewtopic.php?f=12&t=59057

Have it but not get MacOS to run.

Therefore, I now go the way to modules and interfaces
http://www.purebasic.fr/german/viewtopi ... =8&t=28903

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Tue Jul 21, 2015 6:49 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 14063
Location: France
I will add SDK stuff for OS X and Linux in the next release.


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Tue Jul 21, 2015 7:00 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
Fred wrote:
I will add SDK stuff for OS X and Linux in the next release.

Great! :D

mk-soft wrote:
I had also thought so that you can use the standard functions.
viewtopic.php?f=12&t=59057

Have it but not get MacOS to run.

Therefore, I now go the way to modules and interfaces
http://www.purebasic.fr/german/viewtopi ... =8&t=28903

Thanks.
I'll study your code.

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Tue Jul 21, 2015 8:51 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2469
Location: Germany
Very Great :D

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Modul OwnGadget (PB5.2x)
PostPosted: Thu Jul 23, 2015 7:29 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
Hi,
I took a quick look at PB SDK. There's no API to retrieve PB Window number of current parent window.

I tried UseGadgetList(0) but it returns PB WindowID value of current parent window.


Code:
PostEvent(#PB_Event_Gadget, Window, Gadget, #PB_EventType_Change)

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye