Page 1 of 4

PureBasic 3.89 Beta 1 - Public release

Posted: Wed Mar 17, 2004 6:11 pm
by Fred
Hi folks,

Here we go, for the first public beta testing for the new forthcoming 3.90 version which include the new dynamic system for objects, to get ride of numbers when needed. It's was a big changes to almost each libs, so use this beta carefully. This brings some incompatibility with old codes, so sorry for this. I think it worth the little adaptation tough. Read the README.txt carefully and don't hesitate to post any bugs found in the bug report forum with [Beta] in the subject (be sure it's a beta related bug).

Here we go: http://www.purebasic.com/PureBasic_3_89_Beta_1.zip

And don't forget to play with the marvelous Fr34k's "MDI ImageViewer.pb" example or I will get shot ;)

Have fun !

Fred.

Posted: Wed Mar 17, 2004 6:20 pm
by Kale
8O *spills drink while trying to download as fast as possible!*

Posted: Wed Mar 17, 2004 7:22 pm
by Karbon
- Added: MDIGadget() by Fr34k
!@!$@#!$@#%@

I LOVE YOU, MAN!

Excellent work all!!!!

Posted: Wed Mar 17, 2004 7:36 pm
by The_Pharao
great :D

@Fred:
did you also solve the problem with memory leaks concerning lists/arrays that were reported in the german forum recently?

Re: PureBasic 3.89 Beta 1 - Public release

Posted: Wed Mar 17, 2004 7:54 pm
by freak
Fred wrote:And don't forget to play with the marvelous Fr34k's "MDI ImageViewer.pb" example or I will get shot ;)
LOL :mrgreen:


Ok, i want to give some additional info to the Readme.txt:
- Added: New size handler by Fr34k which allow realtime window sizing without callback !
In other words, this means, that the #PB_Event_SizeWindow event is
working properly now, and you can use that in the Eventloop again, to avoid the callback.
new MS SDK support
It works like this: If there is no 'Win32.hlp' file present, the editor looks
for the MS Platform SDK on your computer, so if you wish to use it
instead of the Win32.hlp, just remove that one.
SetGadgetAttribute(), GetGadgetAttribute(), SetGadgetItemAttribute(), GetGadgetItemAttribute()
There is no help for them yet, to see how they are used, just look at the MDI Imageviewer example.
Only MDIGadget() and ScrollAreaGadget() make use of them for now, but
others will use them in the future to allow more control over the gadget, too.


And finally, there is a new feature in the ExplorerListGadget(), that
isn't mentioned anywhere. You can add/remove columns now, and
also add custom ones.

Here is an example:

Code: Select all

#Explorer = 0
If OpenWindow(0, 0, 0, 600, 400, #PB_Window_Screencentered|#PB_Window_SystemMenu, "ExplorerListGadget() custom columns")
  If CreateGadgetList(WindowID())
  
    ExplorerListGadget(#Explorer, 5, 5, 590, 390, "C:")
    
    ; first, let's remove all standart columns, to customize the gadget:
    RemoveGadgetColumn(#Explorer, 3)
    RemoveGadgetColumn(#Explorer, 2)
    RemoveGadgetColumn(#Explorer, 1)
    RemoveGadgetColumn(#Explorer, 0)
    
    ; now, add new ones:
    
    ; create date column
    AddGadgetColumn(#Explorer, 0, #PB_Explorer_Created, 100) 
    
    ; custom column, must be filled after each change:    
    AddGadgetColumn(#Explorer, 1, "Extension", 100)   
    
    ; name column doesn't need to be the first one:
    AddGadgetColumn(#Explorer, 2, #PB_Explorer_Name, 280)
    
    ; Possible Values:
    ; #PB_Explorer_Name   
    ; #PB_Explorer_Size      
    ; #PB_Explorer_Type    
    ; #PB_Explorer_Attributes 
    ; #PB_Explorer_Created     
    ; #PB_Explorer_Modified
    ; #PB_Explorer_Accessed    
    ; or a custom string to add an empty column, that can be filles later.

    ; refresh the gadget content, to reflect the done changes:
    SetGadgetText(#Explorer, "C:")

    ; now we fill the custom column by looping through
    ; all displayed elements. this needs to be once after creating the gadget,
    ; and then each time a #PB_EventType_Change is detected.

    
    For element = 0 To CountGadgetItems(#Explorer)-1
      
      ; let's get the file name        
      name$ = GetGadgetItemText(#Explorer, element, 2) ; remember, we put the name column in column 2
      
      ; set the custom column field with the file extension:
      SetGadgetItemText(#Explorer, element, GetExtensionPart(name$), 1)
      
      ; Note: you can have any number of custom columns.
      ; you can also overwrite the other columns values with SetGadgetItemText(),
      ; if you wish to change something there.
    
    Next element
    
    
    ; event loop
    Repeat
      Event = WaitWindowEvent()
      
      ; detect, when the contents of the gadget changed:
      If Event = #PB_EventGadget And EventGadgetID() = #Explorer And EventType() = #PB_EventType_Change   
        
        ; set the custom column again:      
        For element = 0 To CountGadgetItems(#Explorer)-1       
          name$ = GetGadgetItemText(#Explorer, element, 2)
          SetGadgetItemText(#Explorer, element, GetExtensionPart(name$), 1)
        Next element
      
      EndIf
    
    Until Event = #PB_EventCloseWindow
        
  EndIf
EndIf

End

Allright, that's it for now... enjoy :D


Timo

Posted: Wed Mar 17, 2004 9:45 pm
by fsw
No #PB_Any for menues :?:

@Freak
your MDI gadget is cool.
In my MDI apps I had a function in there, where I was able to disable the 'Windows' MenuTitle if there are no MDI child Windows.
I will search for it, implement it in your example and maybe Fred likes to add it to the menu library :wink:

BTW: you got Ctrl-F6 to work... 8)

Posted: Wed Mar 17, 2004 9:47 pm
by THCM
Hey, nice additions!

But how do I use the new memory related stuff:

- Changed: no more #Memory ID and flag for AllocateMemory()
- Removed: UpdateStatusBar(), UseMemory()

Even the provided examples like PackerProgress.pb don't work. The fast syntax help doesn't work either!

Any hint?

Thanx in advance,

Posted: Wed Mar 17, 2004 10:33 pm
by benny
@THCM:
Maybe it works like this ... argh, didnt test it .... i am on the booze :oops: :

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Compressor example file
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;

; This procedure is a 'Callback'. This means there will be called
; automatically by the program at regular interval, so we could
; see the progress of the compression
; 
Procedure PackerProgress(SourcePosition, DestinationPosition)
  Shared FileLength 
  
  Result.f = (SourcePosition/FileLength)*100
  SetGadgetState(0, Round(Result,0))
  
  While (WindowEvent()) : Wend  ; Process all the window event befor quit
  
  ProcedureReturn 1
EndProcedure

If OpenWindow(0, 100, 200, 300, 40, #PB_Window_SystemMenu, "Packer - Progress Window")

  CreateGadgetList(WindowID())
    ProgressBarGadget(0, 10, 10, 280, 20, 0, 100)
    
  If ReadFile(0, OpenFileRequester("Choose a file to compress", "", "*.*", 0))
    FileLength = Lof()

    ; Allocate the 2 memory buffers needed for compression..
    ;
    *mem1 = AllocateMemory(FileLength)
    *mem2 = AllocateMemory(FileLength+8)
       
    If FileLength And *mem1 And *mem2
      ReadData(*mem1, FileLength) ; Read the whole file in the memory buffer
      
      
      PackerCallback(@PackerProgress())
      
      ; Compress our file, which is in memory (and use a timer to see the time spend by compression..)
      ;
      CompressedLength = PackMemory(*mem1, *mem2, FileLength, 0)
      If CompressedLength
        
        DecompressedLength = UnpackMemory(*mem2, *mem1)
        If DecompressedLength = FileLength
          MessageRequester("Info", "De/Compression succeded:"+Chr(10)+Chr(10)+"Old size: "+Str(FileLength)+Chr(10)+"New size:"+Str(CompressedLength), #MB_ICONINFORMATION)
        EndIf      
      Else
        MessageRequester("Error", "Can't compress the file", 0)
      EndIf 
    EndIf
  EndIf
EndIf

Posted: Wed Mar 17, 2004 10:42 pm
by THCM
Seems to work! Thank you mate!

Keep on!

Posted: Wed Mar 17, 2004 11:51 pm
by einander
Fred and all the team:
Excellent work! :mrgreen:

Posted: Thu Mar 18, 2004 12:09 am
by midebor
Thanx to all for yhe upgrade :D

Michel

Posted: Thu Mar 18, 2004 1:25 am
by fsw
fsw wrote:No #PB_Any for menues :?:

@Freak
your MDI gadget is cool.
In my MDI apps I had a function in there, where I was able to disable the 'Windows' MenuTitle if there are no MDI child Windows.
I will search for it, implement it in your example and maybe Fred likes to add it to the menu library :wink:

BTW: you got Ctrl-F6 to work... 8)
Here is the modified code:

BTW:
  • IMHO MenuTitles should have a parameter more for the TitleNumber (like MenuItems) than it's possible to do fancy things
    IMHO MenuTitles should return the handle instead of 0 or 1.
    IMHO MenuItems should return the handle instead of 0 or 1.
    IMHO a MenuID() command is missing.
    IMHO there is a DisableMenuItem why is there no DisableMenuTitle?
Fred, you can look at the following code, it's pretty simple to add this stuff.
Would be nice to see these commands added in 3v9 final....

Now here it comes...

Code: Select all

; MDI Example by Freak
; Modified by FSW

; Added: the 'Windows' Menu Title is now disabled if no MDI Child Window exists
; Added: Ctrl+F4 for closing MDI Child Windows ; this was very difficult  ;)

; *******************************************************************************
; MDIGadget() Description:
; *******************************************************************************

; Syntax:
; MDIGadget(#Gadget, x, y, Width, Height, SubMenu, MenuItem [, Flags])
;
; SubMenu: 0 based index of the window submenu (opened with MenuTitle() ), on which
;          to add the MDI window entrys. (Usually, this menu is called "Windows")
;          
; MenuItem: the MenuItem number for the first MDI child window in the menu
;           more MDI windows will get a number above that one, so numbers
;           above MenuItem should be reserved for MDI use.
;
; Note: a MDIGadget can only be put directly on a window, not on a PanelGadget or 
; ContainerGadget! The window MUST have a menu, and SubMenu and MenuItem must be set
; correctly, otherwise, there is no minimize button displayed when the user maximizes
; a window, which is pretty bad.
;
; There can only be one MDIGadget per window, as 2 would create a conflict with the
; menu. However, an application can have several MDIGadgets in different windows.

; Gadget flags:
; #PB_MDI_BorderLess     - no borders   
; #PB_MDI_AutoSize       - automatically resize the gadget to fit the window
; #PB_MDI_NoScrollBars   - MDI client area is not scrollable     


; SetGadgetState() - set active child window number, or one of the following:
; #PB_MDI_Cascade           - cascade child windows      
; #PB_MDI_TileVertically    - arrange child windows   
; #PB_MDI_TileHorizontally  
; #PB_MDI_Next              - focus on next window
; #PB_MDI_Previous          - focus on previous window
; #PB_MDI_Arrange           - arrange iconic windows

; GetGadgetState() get active child window

; Get/SetGadgetItemState() - get/set a combination of the following:
; #PB_MDI_Normal     - normal view (not minimized, not maximized)
; #PB_MDI_Maximize   - maximize the window
; #PB_MDI_Minimize   - minimize the window
; #PB_MDI_Hide       - hide the window
; #PB_MDI_Show       - show the window

; attribute types for Get/SetGadgetItemAttribute()
; #PB_MDI_ItemWidth  - get/set the height of the child window
; #PB_MDI_ItemHeight - get/set the width of the child window

; attribute type for GetGadgetAttribute(): returns the item after a #PB_Eventtype_SizeItem
; #PB_MDI_SizedItem 

; Get/SetGadgetItemText() - change child window titlebar

; RemoveGadgetItem() - close child window
; ClearGadgetItemList() - close all childs

; AddGadgetItem() - create new window
;   - Position: numeric identifier for the window
;   - Text: window title
;   - ImageID: Icon for the window 

; if the MDI gadget fires an event, it is one of those:
; #PB_EventType_Focus - the active child window has changed
; #PB_EventType_SizeItem 
;   the user has resized one of the child windows,
;   use GetGadgetState() To find out wich one.

; #PB_EventType_CloseItem 
;   same as #PB_EventCloseWindow, but For an MDI child
;   use GetGadgetState() to find out wich one.
  
                                 
; *******************************************************************************
; Example Code: a MDI ImageViewer:
; *******************************************************************************

; added....
 #MIIM_STATE = 1
 #MIIM_ID = 2
 #MIIM_SUBMENU = 4
 #MIIM_CHECKMARKS = 8
 #MIIM_TYPE = 16
 #MIIM_DATA = 32
 
Procedure FSW_DisableMenuTitle (hwnd, MenuTitleNumber, State)
  mii.MENUITEMINFO
  mii\cbSize = SizeOf(mii)
  mii\fMask = #MIIM_STATE
  If State = 1
    mii\fState = #MFS_GRAYED
  Else
    mii\fState = #MFS_ENABLED
  EndIf
  Result = SetMenuItemInfo_(hWnd, MenuTitleNumber, #FALSE, @mii)
  DrawMenuBar_(WindowID())
  ProcedureReturn = Result
EndProcedure

Procedure FSW_MenuTitle(hWnd, MenuTitleNumber, Title$)
  MenuTitle(Title$)
  ItemCount.l = GetMenuItemCount_(hWnd)-1
  mii.MENUITEMINFO
  mii\cbSize = SizeOf(mii)
  mii\fMask = #MIIM_ID
  mii\wID = MenuTitleNumber
  SetMenuItemInfo_(hWnd, ItemCount, #TRUE, @mii)
  ProcedureReturn GetSubMenu_(hWnd, ItemCount) ;returns handle of it
EndProcedure

Procedure FSW_CheckMDI(hWnd, MenuTitleNumber, MDIChild)
  If MDIChild = 0
    FSW_DisableMenuTitle (hWnd, MenuTitleNumber, 1)
  Else
    FSW_DisableMenuTitle (hWnd, MenuTitleNumber, 0)
  EndIf
EndProcedure

;---------------------

Structure MDIWindow
  ; info about the loaded image
  Image.l
  ImageWidth.l
  ImageHeight.l
  
  ; gadget numbers
  ScrollAreaGadget.l
  ImageGadget.l  
EndStructure

NewList MDIWindow.MDIWindow()

#WINDOW = 0
#TOOLBAR = 0
#MENU = 0

Enumeration 100
  #MENU_File
  #MENU_Open
  #MENU_Close
  #MENU_CloseAll
  #MENU_Quit
  
  #MENU_Windows
  #MENU_TileV
  #MENU_TileH
  #MENU_Cascade
  #MENU_Arrange
  #MENU_Previous
  #MENU_Next
  
  #MENU_FirstMDI
EndEnumeration

UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()

#GADGET_MDI = 0

#WindowFlags = #PB_Window_Screencentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget

If OpenWindow(#WINDOW, 0, 0, 800, 600, #WindowFlags, "MDI ImageViewer")
  MenuHWND = CreateMenu(#MENU, WindowID())
  If MenuHWND
    ;MenuTitle("File")
    FSW_MenuTitle(MenuHWND, #MENU_File, "File")  ; added
      MenuItem(#MENU_Open, "Open")
      MenuItem(#MENU_Close, "Close")
      MenuItem(#MENU_CloseAll, "Close All")
      MenuBar()
      MenuItem(#MENU_QUit, "Quit")  
    ;MenuTitle("Windows")    
    FSW_MenuTitle(MenuHWND, #MENU_Windows, "Windows")  ; added
      MenuItem(#MENU_TileV, "Tile vertically")
      MenuItem(#MENU_TileH, "Tile horizontally")
      MenuItem(#MENU_Cascade, "Cascade")
      MenuItem(#MENU_Previous, "Previous")
      MenuItem(#MENU_Next, "Next")
      ; MDI subwindows will get added here
      
    FSW_DisableMenuTitle (MenuHWND, #MENU_Windows, 1)  ; added

  EndIf
  
  If CreateToolBar(#TOOLBAR, WindowID())
    ToolBarStandardButton(#MENU_Open, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(#MENU_Close, #PB_ToolBarIcon_Delete)
    ToolBarSeparator()
    ToolBarStandardButton(#MENU_Previous, #PB_ToolBarIcon_Undo)
    ToolBarStandardButton(#MENU_Next, #PB_ToolBarIcon_Redo)
  EndIf
  
  If CreateGadgetList(WindowID())
    MDIGadget(#GADGET_MDI, 0, 0, 0, 0, 1, #MENU_FirstMDI, #PB_MDI_Autosize)
    AddKeyboardShortcut(#WINDOW, #PB_Shortcut_Control|#PB_Shortcut_F4, #MENU_Close)  ; added 
  EndIf
  

  Quit = 0
  Repeat
    Event = WaitWindowEvent()

    If Event = #PB_Event_CloseWindow
      Quit = 1   
    
    ElseIf Event = #PB_Event_Menu
      Select EventMenuID()
        Case #MENU_Open
          FileName$ = OpenFileRequester("Open Image", DefautFile$, "Image Files (*.bmp,*.jpg,*.tiff,*.png,*.tga)|*.bmp;*.jpg;*.tiff;*.png;*.tga|All Files (*.*)|*.*", 0, #PB_Requester_MultiSelection)
          While FileName$
            DefaultFile$ = FileName$
            
            Image = LoadImage(#PB_Any, FileName$)
            If Image
            
              LastElement(MDIWindow())
              AddElement(MDIWindow())
              
              Item = ListIndex(MDIWindow())
              
              MDIWindow()\Image       = Image            
              MDIWIndow()\ImageWidth  = ImageWidth()
              MDIWindow()\ImageHeight = ImageHeight()
              
              AddGadgetItem(#GADGET_MDI, Item, FileName$)              
              SetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemWidth, ImageWidth())
              SetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemHeight, ImageHeight())
              
              Width  = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemWidth)
              Height = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemHeight)
              
              MDIWindow()\ScrollAreaGadget = ScrollAreaGadget(#PB_Any, 0, 0, Width, Height, MDIWindow()\ImageWidth, MDIWindow()\ImageHeight, 10) 
              MDIWindow()\ImageGadget = ImageGadget(#PB_Any, 0, 0, MDIWindow()\ImageWidth, MDIWindow()\ImageHeight, ImageID())
              CloseGadgetList()
                          
            Else
              MessageRequester("Image Viewer","Could not load image: "+FileName$)
            EndIf            
            
            FileName$ = NextSelectedFileName()
          Wend

          FSW_MDIChild = CountList(MDIWindow())  ; added
          FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild)  ; added
        
        Case #MENU_Close
          Item = GetGadgetState(#GADGET_MDI)
          If Item <> -1          
            RemoveGadgetItem(#GADGET_MDI, Item)
          
            SelectElement(MDIWindow(), Item)
            FreeImage(MDIWindow()\Image)
            DeleteElement(MDIWindow())

            FSW_MDIChild = CountList(MDIWindow())  ; added
            FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild)  ; added

          EndIf
        
        Case #MENU_CloseAll
          ClearGadgetItemList(#GADGET_MDI)  
                  
          ForEach MDIWindow()
            FreeImage(MDIWindow()\Image)  
          Next MDIWindow()
          ClearList(MDIWindow())

          FSW_MDIChild = CountList(MDIWindow())  ; added
          FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild)  ; added
          
        Case #MENU_Quit
          Quit = 1     
  
        Case #MENU_TileV
          SetGadgetState(#GADGET_MDI, #PB_MDI_TileVertically)
          
        Case #MENU_TileH
          SetGadgetState(#GADGET_MDI, #PB_MDI_TileHorizontally)
                
        Case #MENU_Cascade
          SetGadgetState(#GADGET_MDI, #PB_MDI_Cascade)
        
        Case #MENU_Arrange
          SetGadgetState(#GADGET_MDI, #PB_MDI_Arrange)
        
        Case #MENU_Previous
          SetGadgetState(#GADGET_MDI, #PB_MDI_Previous)
        
        Case #MENU_Next
          SetGadgetState(#GADGET_MDI, #PB_MDI_Next)
        
      EndSelect
      
    ElseIf Event = #PB_Event_Gadget
      If EventGadgetID() = #GADGET_MDI
        
        Type = EventType()
        
        If Type = #PB_EventType_SizeItem          
          Item = GetGadgetAttribute(#GADGET_MDI, #PB_MDI_SizedItem)          
          Width  = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemWidth)
          Height = GetGadgetItemAttribute(#GADGET_MDI, Item, #PB_MDI_ItemHeight)          
          
          SelectElement(MDIWindow(), Item)
          ResizeGadget(MDIWindow()\ScrollAreaGadget, 0, 0, Width, Height)

        ElseIf Type = #PB_EventType_CloseItem
          Item = GetGadgetState(#GADGET_MDI)         
          RemoveGadgetItem(#GADGET_MDI, Item)
        
          SelectElement(MDIWindow(), Item)
          FreeImage(MDIWindow()\Image)
          DeleteElement(MDIWindow())         
          
          FSW_MDIChild = CountList(MDIWindow())  ; added
          FSW_CheckMDI(MenuHWND, #MENU_Windows, FSW_MDIChild)  ; added

        EndIf
        
      EndIf
    
    EndIf
      
  Until Quit = 1  
  
EndIf
Now this example looks pretty professional... :wink:

Posted: Thu Mar 18, 2004 12:59 pm
by PolyVector
I have to say this MDIGadget thing is amazing... and the other features are wonderful!....
#PB_Any... :)
*jumps for joy*
would it be possible to create a TabbedMDI window using this gadget? That would be awesome!
Anyways... Great work fred/freak/everyone!

Posted: Thu Mar 18, 2004 1:05 pm
by freak
PolyVector wrote:I have to say this MDIGadget thing is amazing... and the other features are wonderful!....
#PB_Any... :)
*jumps for joy*
would it be possible to create a TabbedMDI window using this gadget? That would be awesome!
Anyways... Great work fred/freak/everyone!
What exactly is a 'TabbedMDI' ?


fsw:
Is that Ctrl+F4 standart behaviour for MDI apps? if so, i will add it.

Timo

Posted: Thu Mar 18, 2004 1:13 pm
by PolyVector
Something like DeadAIM or JaPBe...or....
here's a pic of what I meant
http://www.codeguru.com/img/legacy/doc_view/24-14-1.gif