; Module/File: LIG_CellSelect&Edit_3.pb ; Function: Cell edit with doubleclick, half nativ - Linux gtk2/gtk3 invisible ; Author: Oma ; Date: Oct 03, 2014 ; Version: 0.3 ; Target Compiler: PureBasic 5.22/5.31/5.40 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- ;better use LIG_CellEditNative_1.pb ; ;todo / Problem ; Editfeld läßt sich nicht als Child des LIG definieren (Fehlermeldung bei gtk_widget_set_parent ()) ; Scrollen des LIG noch möglich, bricht jedoch jetzt mit Übernahme ab. ; Sperren des Scrollens noch nicht gefunden ; Funktionen sollten noch in eine Hauptproutine - keine mehrfache Abfragen in Event-Schleife - keine Globalen Variablen mehr nötig ; LIG_Edit_Close(Window, Gadget, Edit, Type) - Case: Events noch ausmisten ; EnableExplicit ImportC "" ;gtk_tree_view_convert_tree_to_widget_coords(*tree_view.GtkTreeView, bx.I, by.I, *wx, *wy) ;gtk_tree_view_convert_tree_to_bin_window_coords(*tree_view.GtkTreeView, bx.I, by.I, *wx, *wy) ;gtk_tree_view_convert_widget_to_bin_window_coords(*tree_view.GtkTreeView, bx.I, by.I, *wx, *wy) ;gtk_tree_view_convert_bin_window_to_tree_coords(*tree_view.GtkTreeView, bx.I, by.I, *wx, *wy) gtk_tree_view_convert_bin_window_to_widget_coords(*tree_view.GtkTreeView, bx.I, by.I, *wx, *wy) EndImport Structure LIGCELLDATA Path.l; Zeile Column.l; Spalte xFrame.l; Header-X-Offset yFrame.l; Header-Y-Offset (Höhe) EndStructure Global LigCellData.LIGCELLDATA #Win = 0 #List = 0 #Text = 1 Global.i gEvent, gGadget, gEventType, gMenu Global.i gTvEdit= -1 Global *gAdjustment.GtkAdjustment Declare.b LIG_Edit_Close(Window, Gadget, Edit, Type) ;- Functions ... ProcedureC TV_ScrollEvent(*adjustment.GtkAdjustment, user_data); callback for scrolling on #List If user_data= #List LIG_Edit_Close(#Win, #List, gTvEdit, #PB_EventType_LeftClick) EndIf EndProcedure Procedure.b TV_CellEditable(Window, Gadget, Column); unblock columns for editing Protected.b Unblock= #False If Window= #Win If Gadget= #List If Column> 1; editable an column-index > 1 Unblock= #True EndIf EndIf EndIf ProcedureReturn Unblock EndProcedure Procedure LIG_Edit_Start(Window, Gadget, Text.s, *Rect.GdkRectangle) UseGadgetList(Window) AddKeyboardShortcut(Window, #PB_Shortcut_Return, #PB_Key_Return) AddKeyboardShortcut(Window, #PB_Shortcut_Escape, #PB_Key_Escape) AddKeyboardShortcut(Window, #PB_Shortcut_Up, #PB_Key_Up) AddKeyboardShortcut(Window, #PB_Shortcut_Down, #PB_Key_Down) AddKeyboardShortcut(Window, #PB_Shortcut_F2, #PB_Key_F2) gTvEdit= StringGadget(#PB_Any, *Rect\x, *Rect\y, *Rect\width, *Rect\height, "") SetGadgetText(gTvEdit, Text) SetActiveGadget(gTvEdit) EndProcedure Procedure.b LIG_Edit_Close(Window, Gadget, Edit, Type) Protected.b Close= #False, Valid= #True, NextRow= -1 ;Debug "Type : " + Str(Type) If Edit= -1 : ProcedureReturn : EndIf Select Type Case #PB_EventType_LostFocus Close= #True Case #PB_EventType_LeftClick; clicked Close= #True Case #PB_Key_Escape, #PB_Shortcut_Escape Close= #True Valid= #False Case #PB_Key_Return, #PB_EventType_ReturnKey Close= #True Case #PB_Key_Scroll, #PB_EventType_KeyUp, #PB_EventType_KeyDown, #PB_EventType_Up, #PB_EventType_Down, #PB_Key_Up, #PB_Key_Down Close= #True Case #PB_Shortcut_Return, #PB_Shortcut_Up, #PB_Shortcut_Down Close= #True EndSelect If Close If IsGadget(Edit) RemoveKeyboardShortcut(Window, #PB_Shortcut_Return) RemoveKeyboardShortcut(Window, #PB_Shortcut_Escape) RemoveKeyboardShortcut(Window, #PB_Shortcut_Up) RemoveKeyboardShortcut(Window, #PB_Shortcut_Down) If Valid SetGadgetItemText(gadget, LigCellData\Path, GetGadgetText(Edit), LigCellData\Column) EndIf FreeGadget(Edit) gTvEdit= -1 EndIf If Type= #PB_Shortcut_Down Or Type= #PB_Key_Down If LigCellData\Path< CountGadgetItems(Gadget) SetGadgetState(Gadget, LigCellData\Path+ 1) EndIf EndIf EndIf EndProcedure Procedure LIG_CellEdit(Window, Gadget) Protected.i xOffs, yOffs Protected.i ItemIndex= -1, ColumnIndex= -1 Static *TreePath, *TreeColumn Protected *ColumnList.GList, Rect.GdkRectangle If GadgetType(Gadget)= #PB_GadgetType_Tree Or GadgetType(Gadget)= #PB_GadgetType_ListIcon gtk_tree_view_get_cursor_(GadgetID(Gadget), @*TreePath, @*TreeColumn); Adresse der Pfade von item & column an Cursor (Maus) - Position holen ItemIndex= PeekL(gtk_tree_path_get_indices_(*TreePath)); Index von Pfad (item) *ColumnList = gtk_tree_view_get_columns_(GadgetID(Gadget)); Adresse der column-Liste ColumnIndex = g_list_index_(*ColumnList, *TreeColumn); Index von column (Spalte) If TV_CellEditable(Window, Gadget, ColumnIndex) If ItemIndex> -1 And ColumnIndex> -1 gtk_tree_view_get_cell_area_ (GadgetID(Gadget), *TreePath, *TreeColumn, @Rect) gtk_tree_view_convert_bin_window_to_widget_coords(GadgetID(Gadget), 0, 0, @xOffs, @yOffs); rel. Cell-Y-Position Rect\x + xOffs + GadgetX(Gadget) Rect\y + yOffs + GadgetY(Gadget) LIG_Edit_Start(Window, Gadget, GetGadgetItemText(Gadget, ItemIndex, ColumnIndex), Rect) With LigCellData \Path = ItemIndex \Column= ColumnIndex \xFrame= xOffs \yFrame= yOffs EndWith EndIf gtk_tree_path_free_(*TreePath) g_list_free_(*ColumnList) EndIf EndIf EndProcedure Procedure CreateWin_Main() Protected.i I, J Protected.s pText If OpenWindow(#Win, 0, 0, 400, 300, "Cell Select & Edit", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) TextGadget(#Text, 10, 260, 280, 30, "", #PB_Text_Border) ListIconGadget(#List, 10, 10, 380, 240, "Col 0", 60) For I = 1 To 6 AddGadgetColumn(#List, I, "Col " + Str(I), 60) Next I For I = 0 To 25 pText = "" For J = 0 To 6 pText + Str(I) + "x" + Str(J) + Chr(10) Next J AddGadgetItem(#List, -1, pText) Next I ; / events an hor. scroll arrows, slider or mousewheel ... / *gAdjustment= gtk_tree_view_get_hadjustment_(GadgetID(#List)) g_signal_connect_data_(*gAdjustment, "value-changed", @TV_ScrollEvent(), #List, #Null, #Null) ; / events an vert. scroll arrows, slider or mousewheel ... / *gAdjustment= gtk_tree_view_get_vadjustment_(GadgetID(#List)) g_signal_connect_data_(*gAdjustment, "value-changed", @TV_ScrollEvent(), #List, #Null, #Null) EndIf EndProcedure ; ============================================================ ;- Example ; ============================================================ CreateWin_Main() Repeat gEvent = WaitWindowEvent() If EventWindow()= #Win If gEvent= #PB_Event_Gadget gGadget= EventGadget() If gGadget= #List gEventType= EventType() Select gEventType Case #PB_EventType_LeftDoubleClick LIG_CellEdit(#Win, #List) Case #PB_EventType_LeftClick LIG_Edit_Close(#Win, #List, gTvEdit, gEventType) EndSelect EndIf If gGadget= gTvEdit; kommt kaum vor? gEventType= EventType() Select gEventType Case #PB_EventType_LostFocus LIG_Edit_Close(#Win, #List, gTvEdit, gEventType) EndSelect EndIf EndIf If gEvent= #PB_Event_Menu gMenu= EventMenu() Select gMenu Case #PB_Key_Return, #PB_Key_Escape, #PB_Key_Up, #PB_Key_Down LIG_Edit_Close(#Win, #List, gTvEdit, gMenu) ; Case #PB_Key_F2; not implemented ; LIG_CellEdit(#Win, #List, #Edit) EndSelect EndIf EndIf Until gEvent= #PB_Event_CloseWindow ; IDE Options = PureBasic 5.62 (Linux - x86) ; Folding = -- ; EnableXP ; EnableUnicode