Known Limits in PB 3.94 Mac

Mac OSX specific forum
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Okay SEO.
On Windows with the little modification in the code i posted, you can open and close any window you like except for the main window of course.

It's a Mac thing, so i can't help here sorry.
SEO wrote: IncludeFile: I hope that is an Compiler Directive and only used to include the code when compiling the code...

//SEO
Yes and it works on window. :) but i have just never seen it used that way, but then again, what i have seen doesn't count.. :twisted:

Best Henrik
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

Hi again Henrik!

Yes I understand why it works Win but NOT in Mac.
If you asigned an menu to a window, the menu is not destroyed in the time you have the window opened. But in my case, the window is distroyed because I only have one menu (main menu)...

So as I can see this NOT works on Mac.

Have a nice time!
/SEO
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

Hi SEO,

I've tested an modified your last testcode. I think, that is near what you want.

Code: Select all

;
; Mac Window Rwsr Application Version 0.0.1
;

#Main_Window = 0
#Wnd1_Window = 1
#Wnd2_Window = 2
#Wnd3_Window = 3

Procedure Main_Menu(MenuID)
If CreateMenu(MenuID,WindowID(MenuID))
 MenuTitle("Window "+Str(MenuID))
 MenuItem(1, "Window 1")
  MenuItem(2, "Window 2")
   MenuItem(3, "Window 3")
   EndIf
   
UseWindow(MenuID)   ; <--#########
ActivateWindow()

EndProcedure

Procedure Window1_show()
If OpenWindow(#Wnd1_Window, 60,60,290, 215, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "Window 1")
   Main_Menu(#Wnd1_Window)
EndIf
EndProcedure

Procedure Window2_show()
If OpenWindow(#Wnd2_Window, 60,90,290, 215, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "Window 2")
   Main_Menu(#Wnd2_Window)
EndIf
EndProcedure

Procedure Window3_show()
If OpenWindow(#Wnd3_Window, 60,120,290, 215, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "Window 3")
   Main_Menu(#Wnd3_Window)
EndIf
EndProcedure

If OpenWindow(#Main_Window, 260,360,290, 215, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "Window0")

Main_menu(#Main_Window)

Repeat
  Main_EventID = WaitWindowEvent()
  Event_WindowID = EventWindowID()
  Event_TypeID = EventType()
  Event_GadgetID = EventGadgetID()
  
  Select Main_EventID
  Case #PB_Event_Menu
  Main_MenuItem = EventMenuID()
  Select Main_MenuItem

   Case 1
      If IsWindow(#wnd1_window)
         UseWindow(#Wnd1_Window)
         ActivateWindow()
         Main_Menu(#Wnd1_window)
      Else
         Window1_Show()
      EndIf
  Case 2
        If IsWindow(#wnd2_window)
         UseWindow(#Wnd2_Window)
         ActivateWindow()
         Main_Menu(#Wnd2_window)
      Else
         Window2_Show()
      EndIf
  Case 3
        If IsWindow(#wnd3_window)
         UseWindow(#Wnd3_Window)
         ActivateWindow()
         Main_Menu(#Wnd2_window)
      Else
         Window3_Show()
      EndIf
  EndSelect ; Main_MenuItem
  EndSelect ; Main_EventID
  

  Select EventWindowID()   ;Event_WindowID
  
  Case #Main_Window
   Select Main_EventID
   Case #PB_Event_CloseWindow : Quit = 1
   EndSelect 
  
  Case #Wnd1_Window
    Select WaitWindowEvent()  ;Main_EventID
    Case #PB_Event_CloseWindow : CloseWindow(#Wnd1_Window)
    Main_Menu(#Main_Window) ; <-- #######
    EndSelect
  
  Case #Wnd2_Window
    Select Main_EventID
    Case #PB_Event_CloseWindow : CloseWindow(#Wnd2_Window)
      Main_Menu(#Wnd1_Window) ; <-- #######
    EndSelect
    
  Case #Wnd3_Window
    Select Main_EventID
    Case #PB_Event_CloseWindow : CloseWindow(#Wnd3_Window)
    Main_Menu(#Wnd2_Window) ; <-- #######
    
    EndSelect

 Debug "IsWindow: "+Str(IsWindow(WindowID()))
 
  
EndSelect ; Event_WindowID

Until Quit = 1
End ; Terminate Application
EndIf ; OpenWindow(Main_Window) 
It's not perfect :wink:
The menu is active, if the window is active :!:

I will send you the code via mail too.

Regards
michel51
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi SEO & michel51
@michel51, if what you did work on Mac. then windows and Mac works in the same way cus. what you did is the same as what i did, just that you reused the windows constants where i created new ones.

And thats a good thing. The "Mac = Win" thing..

**Edit** SEO did you try the code i posted or for that matter michel51 posted, cus the same fault happens on win too if you reuse the same menuID constant when creating a new menu..

Best Henrik
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

here's another windows vs. messages example... it's windows but should work on the mac as well

Code: Select all

; purebasic survival guide - pb3.94
; mainloop_1.pb - 30.12.2005 ejn (blueznl)
; http://www.xs4all.nl/~bluez/datatalk/purebasic.htm
;
; - basic framework
; - menus
; - event loop
; - gadgets
; - multi window handling
; - gadget and window resizing
;

Declare init()
Declare main()
init()
main()

Procedure init()
  ;
  ; *** all global declarations, enumeration stuff etc. ***
  ;
  ; enumeration is your best friend... i use it here to identify...
  ; - all functions of the program (actions taken)
  ; - all windows
  ; - all menus
  ; - all gadgets
  ;
  Enumeration
    ;
    ; functions - either real menu entries or logical functions
    ;
    #f_exit
    #f_show_child
    #f_close_child
    #f_toggle_child
    ;
    ; windows
    ;
    #w_main_nr
    #w_child_nr
    ;
    ; menus
    ;
    #m_main_nr
    ;
    ; gadgets main
    ;
    #g_main_exit
    #g_main_sample_listview
    #g_main_toggle_child
    ;
    ; gadgets child
    ;
    #g_child_close
    ;
  EndEnumeration
  ;
  ; add other global stuff
  ;
EndProcedure

Procedure reflect_settings()
  Global show_child.l
  ;
  ; *** show current settings in gadgets ***
  ;
  SetMenuItemState(#m_main_nr,#f_toggle_child,show_child)
  ;
EndProcedure

Procedure draw()
  Protected w.l, h.l
  Global w_main_h.l, w_child_h.l, show_child.l
  ;
  ; *** all draw, redraw, and resize routines ***
  ;
  ; this is the main drawing procedure, all setting up of windows, creation of gadgets
  ; and so on take place in here, this is also the place where you could store resizing
  ; code, this procedure does not update the status of gadgets or menus, for that
  ; reflect_settings() has to be called seperately
  ;
  ;
  ; *** main window ***
  ;
  If IsWindow(#w_main_nr)                        ; redraw or resize
    ;
    UseWindow(#w_main_nr)
    w = WindowWidth()
    h = WindowHeight()
    h = h-MenuHeight()-32
    ResizeGadget(#g_main_sample_listview,2,2,w-4,h-4)
    ResizeGadget(#g_main_toggle_child,2,h+4,w-4,24)
    ;
  Else                                           ; create the window
    ;
    w = 400
    h = 400
    w_main_h = OpenWindow(#w_main_nr,10,10,400,400,#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"Primary")
    ;
    CreateMenu(#m_main_nr,w_main_h)
    MenuTitle("&File")
    MenuItem(#f_show_child,"&Show child")
    MenuItem(#f_close_child,"&Close child")
    MenuItem(#f_toggle_child,"&Toggle child")
    MenuBar()
    MenuItem(#f_exit,"E&xit")
    ;
    h = h-MenuHeight()-32
    CreateGadgetList(w_main_h)
    ListViewGadget(#g_main_sample_listview,2,2,w-4,h-4)
    ButtonGadget(#g_main_toggle_child,2,h+4,w-4,24,"Toggle child")
    ;
  EndIf
  ;
  ; *** child window ***
  ;
  ; showing all other windows would depend on the value of the associated flags / variables
  ;
  If show_child = #True                          ; we want a window
    If IsWindow(#w_child_nr)                     ; window already exists, redraw or resize
      ;
    Else                                         ; create the window
      ;
      w_child_h = OpenWindow(#w_child_nr,10,10,110,110,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Childwindow",w_main_h)
      CreateGadgetList(w_child_h)
      ButtonGadget(#g_child_close,2,2,108,108,"Close")
      ;
    EndIf
  Else                                           ; we donn't want a window
    If IsWindow(#w_child_nr)                     ; exists so close the window
      CloseWindow(#w_child_nr)
    Else                                         ; doesn't exist so don't bother
    EndIf
  EndIf
  ;
  ; repeat the above for any other window / gadget
  ;
EndProcedure

Procedure main_loop()
  Global event.l, event_gadget.l, event_window.l, event_menu.l, show_child.l
  ;
  draw()
  ;
  Repeat
    action = -1
    ;
    event = WaitWindowEvent()
    event_type = EventType()
    event_menu = EventMenuID()
    event_window = EventWindowID()
    event_gadget = EventGadgetID()
    ;
    ; i've set this up as following:
    ;
    ; 1. grab all events
    ; 2. process them per window
    ;    - first menu events
    ;    - then window events
    ;    - then gadgets
    ; 3. events either cause immediate actions, or they set the variable 'action'
    ;    (this allows me to have different events / gadgets / menu's to do the same thing)
    ; 4. if the action variable is non-zero it may cause certain actions as well
    ;
    Select event_window
    Case #w_main_nr
      ;
      ; process all events caused by the main window
      ;
      Select event
      Case #PB_Event_Menu
        action = event_menu
      Case #PB_Event_CloseWindow
        action = #f_exit
      Case #PB_Event_SizeWindow
        draw()
      Case #PB_Event_Gadget
        ;
        ; process all events caused by gadgets in the main window
        ;
        Select event_gadget
        Case #g_main_toggle_child
          action = #f_toggle_child
        Case #g_main_exit
          action = #f_exit
        Default
        EndSelect
        ;
      Default
      EndSelect
      ;
    Case #w_child_nr
      ;
      ; process all events caused by the child window
      ;
      Select event
      Case #PB_Event_Menu
        action = event_menu
      Case #PB_Event_CloseWindow
        action = #f_close_child
      Case #PB_Event_Gadget
        ;
        ; process all events caused by gadgets in the child window
        ;
        Select event_gadget
        Case #g_child_close
          action = #f_close_child
        Default
        EndSelect
        ;
      Default
      EndSelect
      ;
    EndSelect
    ;
    ;
    ; *** action section ***
    ;
    ; events either immediately take action (in the block above) or they
    ; set the action variable causing an action below
    ;
    Select action
    Case #f_show_child
      show_child = #True
      draw()
      reflect_settings()
    Case #f_close_child
      show_child = #False
      draw()
      reflect_settings()
    Case #f_toggle_child
      If show_child = #True
        show_child = #False
      Else
        show_child = #True
      EndIf
      draw()
      reflect_settings()
    EndSelect
    ;
  Until action = #f_exit
  ;
EndProcedure

Procedure main()
  Protected command.s
  ;
  ; in complex programs that support gui as well as command line functions i tend to
  ; seperate these two in two different sections
  ;
  command = ProgramParameter()
  Select command
  Case ""
    main_loop()
    ;
  Case "debug"
    MessageRequester("Command","Debug...",#PB_MessageRequester_Ok)
    ;
  Default
    MessageRequester("Command","Unknown!",#PB_MessageRequester_Ok)
    ;
  EndSelect
EndProcedure


; IDE Options = PureBasic v3.94 (Windows - x86)
; Folding = g-
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

Hi,
I should check it out.
I do an fast test in the IDE, but it refuse to run ...
Syntax error Line 20!
Thx,
//SEO
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

line 20 is a rem line? something starting with a semicolon like...

; *** whatever ***

that should work without a hitch, are you sure?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

Yes it is an REM line, and that generate the error!
And this time it is NOT me that is confused .....

But i know there is problems when Copy and Paste text ... Perhaps inserting some rubbish... There are also an Encoding problem with the Editor / debugger..

//SEO
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

SEO wrote:But i know there is problems when Copy and Paste text ...
That's it. :roll:

I found out, if I copy and paste code from forum to PB, the code crashes. If I open the code with MS-Word and look to the control characters (you can make it visible), then I see, that the "tab" is a circumflex !? If I change these characters with replace-function and save the file as ONLY TXT, with extension .pb, then the crashes on REMs have finished.

Try and see, i think it's a coding problem within tis mask as you say.

That's not only a problem within this forum, the same happens on german forum.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

weird, i did not use any tabs, i suspect your browser inserts them... oh well, if the code itself works then it's okay, isn't it? :-)

(try not to select the whole message, just the code section, does it still go wrong then?)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SEO
Enthusiast
Enthusiast
Posts: 178
Joined: Fri Dec 09, 2005 11:42 pm
Location: Sweden
Contact:

Post by SEO »

Now the code is cleaned up and compiled...

The result: Fails....

When the child window is opened the menu not working longer...
//SEO
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi blueznl & SEO
I have just tested your "blueznl's" code on windows, it works and i have send the working pb code to your mail SEO, so it should work now.

Happy NewYear All. :D
Best
Henrik

Doh.. why am i so slooow :evil:
Last edited by Henrik on Sat Dec 31, 2005 6:08 pm, edited 1 time in total.
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

@blueznl

Your code failed. If I open child-window, I can close it only via the button in it. The menu does'nt works.

I think, the "tab-problem" is made here, because the same happens in german forum. If I use copy & paste to get a code, then there are the " circumflexes", that lets run the code into an syntax error. Dont know, from where it comes.

michel51
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi may join for a sec.
There is beyond any doubt something wrong in the Mac version of pb. :cry:
I have been doing a lot off test with SEO lately.
It's not a question if SEO and michel51 is doing something wrong, but that they are trying to make a worke around the bug. :?

Now for your code @blueznl, -thanks for your effort blueznl btw- :D
The problem is: Mac Can only have (1)-ONE MENU (Insane but true) :shock:

So what's happening here blueznl is:
1. You creat the "Primary Window" with a Menu attached to it. (good so far)

2. Now when you then creat your -"Childwindow"- The Menu from the "Primary Window" gets destroyed.

So now you have a "Primary Window" with no Menu at all. :?

The Worke around i tried with SEO was:

Creating 3 windows and what ever window was Activ had a Dynamic menu created for it. But then the God Damn "EventWindowID()" reported wrong with a -1 randomly (am i right here SEO?) :?:
This did not happen on windows - mind you-
And when EventWindowID return -1 no Menu could be created. :evil:

Another thing SEO is trying really hard to convert his work from another language to PB, but it seems bit hard,
-"Fred Will Fix that of course"- :twisted:
They really want a worke around this problem and if anybody has an idear they are most welcome.
:D

Happy New Year to all of you :D
Best regrads
Henrik
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

1. You creat the "Primary Window" with a Menu attached to it. (good so far)
2. Now when you then creat your -"Childwindow"- The Menu from the "Primary Window" gets destroyed.
that is simply a bug, i'd say, something alpha will most likely fix in the next version, the moment he's going to have time to do so
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply