Canvas based Grid gadget

Share your advanced PureBasic knowledge/code with the community.
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: Canvas based Grid gadget

Post by leonhardt »

well done!
PS:the demo window flickers when resize it , :(,SmartWindowRefresh doesn't work, Win7 32bit PB5.11
poor English...

PureBasic & Delphi & VBA
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: Canvas based Grid gadget

Post by RichardL »

An excellent job, well done Said!

I offer the following comments with the caveats (a) after a short test it is so easy to overlook the obvious and (b) the “it is different so it's wrong” syndrome applies to most people, but me in particular :oops:

- ComboBox() Cell - Yes please.
- Option for a single click to activate cell/s would be good. (I use this option with Srod's grid and prefer it.)
- I prefer not to press Return to leave text in a cell. (Option switch?)
- How do you recover a row that was accidentally shrunk to zero height?
- Numbers only/Letters only option for individual cells / rows / columns. 'Numbers only' to optionally allow a decimal point? Format mask ####.## would be superb!
- Could MyGrid_SetText() use the Pure Basic standard parameter order (Gadget#, X,Y,Text)
- The popup menu is not associated with the grid / cursor. I'm using multiple monitors and the grid can be on one and the popup can appear on the other.

Regards,
RichardL
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

leonhardt wrote:well done!
PS:the demo window flickers when resize it , :(,SmartWindowRefresh doesn't work, Win7 32bit PB5.11
Thanks, as for flicking honestly i have no clue how to fix this! It is not happening here Win7 x64?!
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

RichardL wrote:An excellent job, well done Said!

I offer the following comments with the caveats (a) after a short test it is so easy to overlook the obvious and (b) the “it is different so it's wrong” syndrome applies to most people, but me in particular :oops:

- ComboBox() Cell - Yes please.
- Option for a single click to activate cell/s would be good. (I use this option with Srod's grid and prefer it.)
- I prefer not to press Return to leave text in a cell. (Option switch?)
- How do you recover a row that was accidentally shrunk to zero height?
- Numbers only/Letters only option for individual cells / rows / columns. 'Numbers only' to optionally allow a decimal point? Format mask ####.## would be superb!
- Could MyGrid_SetText() use the Pure Basic standard parameter order (Gadget#, X,Y,Text)
- The popup menu is not associated with the grid / cursor. I'm using multiple monitors and the grid can be on one and the popup can appear on the other.

Regards,
RichardL
Thanks! appreciate your offered comments and i guess am affected by that syndrome as well :mrgreen:

Overall, for updates/revisions and new stuffs, i will try my best to implement as soon as i can (i have my daily work to finish as well :( ) ... Building a descent pro grid 'a la Excel' is a huge work. My code is open source and you (and others) are most welcome to have your say and customize it to suit your needs ...

- When you say 'activate cell' do you mean open it for editing? right now it is in 'overwrite' mode, if you press enter or double-click you go in insert mode
- Cell data type (number/decimals/dates/... with masks) will come later inshAllah
- That multiple monitors issue is new to me! I will try to figure out what is going on :shock:

- if a column/row is hidden (accidentally or on purpose) cannot be shown again via resizing, this is done on purpose! Right now un-hiding should be managed by the caller application that can offer to un-hide thru popup menus or other means. I admit this is not the common and expected behavior but these were the guidelines! I shall implement the normal way!

Regards,
Said
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

mevedia.de wrote:Nice :wink: , there's just a small Bug if you collapse a Column (can't size it anymore). I could recommend you the Scroll Control. :D Directly connect your Canvas and a Pointer to x/y Coordinates.
Thanks, personally am not comfortable with using userlibs ( i have the feelings they are a great source of un-managed errors :!: )

As for the described bug, actually this is done on purpose - this is not a common behavior but yes it was done on purpose! By the way, your work looks very appealing but being as userlib format is keeping me (and other i guess) from using it
User avatar
skywalk
Addict
Addict
Posts: 3519
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Canvas based Grid gadget

Post by skywalk »

said wrote:
RichardL wrote: - The popup menu is not associated with the grid / cursor. I'm using multiple monitors and the grid can be on one and the popup can appear on the other.

Regards,
RichardL
- That multiple monitors issue is new to me! I will try to figure out what is going on :shock:
Regards,
Said
I use multiple monitors also and this quick fix worked fine. :wink:

Code: Select all

      If _MyGrid_OverCellArea(*mg, x, y)
        ;DisplayPopupMenu(*mg\AttachedPopupMenu, WindowID(*mg\Window), x, y)
        DisplayPopupMenu(*mg\AttachedPopupMenu, WindowID(*mg\Window));, x, y)
      EndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

skywalk wrote: I use multiple monitors also and this quick fix worked fine. :wink:

Code: Select all

      If _MyGrid_OverCellArea(*mg, x, y)
        ;DisplayPopupMenu(*mg\AttachedPopupMenu, WindowID(*mg\Window), x, y)
        DisplayPopupMenu(*mg\AttachedPopupMenu, WindowID(*mg\Window));, x, y)
      EndIf
Interesting :!: thanks for the tip, i hope it solves the issue for RichardL (i dont have access to multi-monitors right now, i use only laptops)

@mevedia.de: i know maybe a new variant of XIncludeFile that works with encrypted source code would be an option :?: We need the help of the master here ... FRED
User avatar
Kwai chang caine
Addict
Addict
Posts: 4916
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Canvas based Grid gadget

Post by Kwai chang caine »

Great !!!
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

Just revised the code to allow un-hiding a row/col that was re-sized to 0 via mouse ... Now it works as one expects :D

See first 2 posts

Said
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Canvas based Grid gadget

Post by davido »

Has that professional look!

Very nice, thanks for sharing. :D
DE AA EB
User avatar
mk-soft
Addict
Addict
Posts: 3086
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Canvas based Grid gadget

Post by mk-soft »

Cool, I'm VERY excited. Thank´s to shared.

[Edit]
I´m added 'F2' for starting edit
Changed in MyGrid_ManageEvent

Code: Select all

...
Case #PB_Shortcut_Return, #PB_Shortcut_F2
...
: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
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

mk-soft wrote:Cool, I'm VERY excited. Thank´s to shared.

[Edit]
I´m added 'F2' for starting edit
Changed in MyGrid_ManageEvent

Code: Select all

...
Case #PB_Shortcut_Return, #PB_Shortcut_F2
...
:D
Nice tip :!: like in Excel
User avatar
mk-soft
Addict
Addict
Posts: 3086
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Canvas based Grid gadget

Post by mk-soft »

My Idee for Copy and Paste

Code: Select all

...

Enumeration 1024 ; <- Check valid MenuItemID
  #MyGrid_MenuEvent_Ctrl_C
  #MyGrid_MenuEvent_Ctrl_V
  #MyGrid_MenuEvent_Ctrl_X
EndEnumeration

Procedure.i MyGrid_ManageMenuEvent(Gdt.i, eType)
   Protected *mg._MyGrid_Type = GetGadgetData(Gdt)
   
    If GetActiveGadget() <> gdt
      ProcedureReturn
    EndIf
    
    Select eType
        
      Case #MyGrid_MenuEvent_Ctrl_C
        
        If MyGrid_ShowCell(gdt, *mg\Row, *mg\Col)
          SetClipboardText(MyGrid_GetText(gdt, *mg\Row, *mg\Col))
        EndIf
          
        Case #MyGrid_MenuEvent_Ctrl_V
          If MyGrid_ShowCell(gdt, *mg\Row, *mg\Col)
            MyGrid_SetText(gdt, *mg\Row, *mg\Col, GetClipboardText())
            MyGrid_Redraw(gdt)
          EndIf
          
        Case #MyGrid_MenuEvent_Ctrl_X
          If MyGrid_ShowCell(gdt, *mg\Row, *mg\Col)
            SetClipboardText(MyGrid_GetText(gdt, *mg\Row, *mg\Col))
            MyGrid_SetText(gdt, *mg\Row, *mg\Col, "")
            MyGrid_Redraw(gdt)
          EndIf
          
    EndSelect
        
EndProcedure    
        
;-{ Test
CompilerIf #PB_Compiler_IsMainFile
   
Enumeration
   #Win_Nbr
   #Grid_Nbr
   #Grid_ColScroll
   #Grid_RowScroll
   #Grid_PopupMenu
   #MenuItem_1
   #MenuItem_2
   #MenuItem_3
   #MenuItem_4
   #MenuItem_5
EndEnumeration

Global ii, iii, EvGd, Evnt, EvTp, EvMn

If OpenWindow(#Win_Nbr, 0, 0, 1000, 670, "MyGrid Said", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
   SetWindowColor(#Win_Nbr,#White)
   
   If CreatePopupMenu(#Grid_PopupMenu)      ; creation of the pop-up menu begins...
      MenuItem(#MenuItem_1, "Show")
      MenuItem(#MenuItem_2, "Hide")
      MenuItem(#MenuItem_3, "Freeze here")
      MenuBar()
      OpenSubMenu("Sub-menu")
         MenuItem(#MenuItem_4, "sub 1")
         MenuItem(#MenuItem_5, "sub 2")
      CloseSubMenu()
   EndIf
   
    MyGrid_New(#Win_Nbr, 0, #Grid_Nbr, #Grid_ColScroll, #Grid_RowScroll,10, 10, 920, 650,20000,100, #True)
    
    
    ; customize the grid ...
    MyGrid_AttachPopup(#Grid_Nbr, #Grid_PopupMenu)
    MyGrid_NoRedraw(#Grid_Nbr)
       
        MyGrid_Col_Freeze(#Grid_Nbr, 3)
        MyGrid_Row_Freeze(#Grid_Nbr, 5)
       
        ; example of extra style ( checkboxes at col# 9)
        ii = _MyGrid_AddExtraStyle(GetGadgetData(#Grid_Nbr), #MyGrid_Align_Center, $E6D8AD,#Blue,Font_A8,#MyGrid_CellType_Checkbox,#True)
        _MyGrid_SetExtraStyle(GetGadgetData(#Grid_Nbr), #MyGrid_RC_Data, 9, ii)
             
        ;MyGrid_Col_Hide(#Grid_Nbr, 0, 1)
        ;MyGrid_Row_Hide(#Grid_Nbr, 0, 1)
        MyGrid_Col_Hide(#Grid_Nbr, 7, 1)
        ; Add ShortCut
        AddKeyboardShortcut(#Win_Nbr, #PB_Shortcut_Control | #PB_Shortcut_C, #MyGrid_MenuEvent_Ctrl_C)
        AddKeyboardShortcut(#Win_Nbr, #PB_Shortcut_Control | #PB_Shortcut_V, #MyGrid_MenuEvent_Ctrl_V)
        AddKeyboardShortcut(#Win_Nbr, #PB_Shortcut_Control | #PB_Shortcut_X, #MyGrid_MenuEvent_Ctrl_X)
        

    MyGrid_Redraw(#Grid_Nbr)
    
    Repeat
        EvGd = -1
        EvTp = -1
        EvMn = -1
        Evnt = WaitWindowEvent()
        Select Evnt
            Case #PB_Event_SizeWindow
                MyGrid_Resize(#Grid_Nbr, #PB_Ignore, #PB_Ignore, WindowWidth(#Win_Nbr) - 80, WindowHeight(#Win_Nbr) - 20)
               
            Case #PB_Event_Gadget
                EvGd = EventGadget()
                EvTp = EventType()
                Select EvGd
                    Case #Grid_Nbr
                        MyGrid_ManageEvent(EvGd, EvTp, 0)
                    Case #Grid_ColScroll
                        MyGrid_ManageEvent(#Grid_Nbr, EvTp, #Grid_ColScroll)
                    Case #Grid_RowScroll
                        MyGrid_ManageEvent(#Grid_Nbr, EvTp, #Grid_RowScroll)
                EndSelect
           
         Case #PB_Event_Menu
            EvMn = EventMenu()
            MyGrid_ManageMenuEvent(#Grid_Nbr, EvMn)
            Select EvMn
               Case #MenuItem_1 : Debug " popup menu 1 "
               Case #MenuItem_2 : Debug " popup menu 2 "
               Case #MenuItem_3 : Debug " popup menu 3 "
               Case #MenuItem_4 : Debug " popup menu 4 "
               Case #MenuItem_5 : Debug " popup menu 5 "
            EndSelect
           
      EndSelect
       
       
    Until  Evnt = #PB_Event_CloseWindow
EndIf
CompilerEndIf
;}
:wink:
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
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Canvas based Grid gadget

Post by said »

mk-soft, you are faster than me in adding new stuff/improving :!: I shall resume work on it this weekend, and planning to add:
1. Cell span (merging cells in cols/rows)
2. Block management
3. Combo-box cell type

As for your additions i have the following remarks ...

1. I like your idea for Copy/Paste and MyGrid_ManageMenuEvent() fits well in the code and very much in line with what i have in mind (i might use it as is if you dont mind)
2. Pasting/Cutting( Ctrl V/X) should be done in editable cells only - we need to add a little test here
3. This works only so far with a single cell - the common way is to use it for a block of cells (i shall add that block asap now :? )
4. Since we are crossplatform, we need to make sure that the AddKeyboardShortcut are properly added for each OS (personally i have no idea what shall we use for OSX/Linux, is it the same, am stuck with windows only)
AddKeyboardShortcut(#Win_Nbr, #PB_Shortcut_Control | #PB_Shortcut_C, #MyGrid_MenuEvent_Ctrl_C)
AddKeyboardShortcut(#Win_Nbr, #PB_Shortcut_Control | #PB_Shortcut_V, #MyGrid_MenuEvent_Ctrl_V)
AddKeyboardShortcut(#Win_Nbr, #PB_Shortcut_Control | #PB_Shortcut_X, #MyGrid_MenuEvent_Ctrl_X)

And last thanks for improving :D
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: Canvas based Grid gadget

Post by RichardL »

Good morning,

Some random thoughts...

- I use SRod's grid a lot and one of the useful features is an option for a cell to become editable after a single click (not a double click, or F2 as in a spreadsheet.) Mostly this is an option chosen on a column basis.

- When designing a grid to be used as a data entry mechanism it is a good idea to imagine yourself as a super fast typist** who would much rather enter a new line of data without taking a hand away from the keyboard to use the mouse.

- Using F2 to start an edit allows the cursor left/right keys to be used to navigate the edit box around the grid and then to move the caret left/right in a cell to choose an edit point in pre-existing text.

I wish you a happy and productive weekend.... :D

RichardL

** Off topic: I have an aunt who trained as a touch typist in pre-computer days. She could put a paper bag over her head so she could not see the keyboard, then sing a song while typing it!
Post Reply