Code : Tout sélectionner
; Grid with input text
; December 26 -2003- PB 3.81
; by Einander
; Convert in V5.11 by Dobro
Enumeration
#win
#im
#font
;
#Ret
#Txt
#Input
EndEnumeration
#LightGray = $BDBDBD : #SAND = $BBFFFF
global Dim Selected.l(1): global Dim textcell$(0) : global Dim xcell.W(0) :global Dim ycell.W(0)
Global Mx, My, Mk,S$
Global Grid, Colum, Rows, _X, _Y, WCell, HCell, XGrid, YGrid, NColumns, NRows, NCells, WGrid, HGrid, SmallFont
S$=" "
Procedure inmous(x, y, x1, y1)
ProcedureReturn bool(mx >= x And my >= y And mx <= x1 And my <= y1)
EndProcedure
Procedure CleanCell(COLU, ROW)
x = XGrid + 1 + (COLU - 1) * WCell+1
y = YGrid + 1 + (ROW - 1) * HCell+1
Box(X, Y-1, WCell-2, HCell-1, #SAND)
SEL = (ROW - 1 ) * NColumns + COLU
DrawingFont(SmallFont)
FrontColor(rgb(0, 0, 0))
DrawText(x,y,textcell$(SEL - 1))
Selected(0) = 0
EndProcedure
Procedure DrawCell(Ev)
If inmous(xGrid + 1, yGrid + 1, xGrid + wGrid - 2, yGrid + hGrid - 2)
COLU = (MX - XGrid) / WCell + 1 : ROW = (MY - YGrid) / HCell + 1
SEL = (ROW - 1 ) * NColumns + COLU
If Ev = #WM_LBUTTONDOWN : ProcedureReturn SEL : EndIf
If Selected(0) <> COLU Or Selected(1) <> ROW
If Selected(0) : CleanCell(SELECTED(0), Selected(1)) : EndIf
x = XGrid + (COLU - 1) * WCell + 1 : y = YGrid + ((ROW - 1) * HCell) + 1
Box(x+1, y, WCell-2 , HCell-1 , #GREEN)
DrawingMode(1)
FrontColor(rgb(0, 0, 0))
DrawingFont(SmallFont)
DrawText(x,y,textcell$(SEL - 1))
DrawingMode(1)
Selected(0) = COLU : Selected(1) = ROW
EndIf
ElseIf selected(0)
CleanCell(Selected(0), Selected(1))
ProcedureReturn 0
EndIf
EndProcedure
Procedure DrawGrid()
Grid = CreateImage(#im, wGrid, hGrid )
StartDrawing(ImageOutput(#im))
DrawingMode(1)
Box(0, 0, wGrid, hGrid, #SAND)
Pos = HCell * NRows
x1 = 0 : y1 = 0
For i = 0 To NColumns
LineXY(x1, 0, x1, Pos, #LightGray)
x1 + WCell
Next i
Pos = WCell * NColumns
For i = 0 To NRows
LineXY(0, y1, Pos, y1)
y1 + HCell
Next i
FrontColor(rgb(0, 0, 0))
DrawingFont(SmallFont)
For i = 0 To Ncells
DrawText(xcell(i) + 2, ycell(i)+2,textcell$(i))
Next
StopDrawing()
EndProcedure
_X = GetSystemMetrics_(#SM_CXSCREEN) - 8 : _Y = GetSystemMetrics_(#SM_CYSCREEN) - 68
hWnd = OpenWindow(#win, 0, 0, _X, _Y,"Grid", #WS_OVERLAPPEDWINDOW)
AddKeyboardShortcut(#win, #PB_Shortcut_Return, #Ret)
XGrid = 100 : YGrid = 120 ; grid position
NColumns = 8 : NRows = 12 ; number of rows & columns
WCell = 72 : HCell = 22 ; cell sizes
SmallFont = LoadFont(#font, "Tahoma ", hcell/2)
NCells = NColumns * NRows
WGrid = WCell * NColumns + 1 : HGrid = HCell * NRows + 1
global Dim TextCell$(Ncells)
global Dim XCell.w(Ncells)
global Dim YCell.w(Ncells)
For i = 0 To ncells
If i > 0 And i % ncolumns = 0 : x = 0 : y + hcell : EndIf
TextCell$(i) = Str(i + 1)
Xcell(i) = x : ycell(i) = y
x + wcell
Next
; CreateGadgetList(hWnd)
TextGadget(#Txt, _x / 2, yGrid + hGrid + 10, 100, 40, "", #PB_Text_Center | #PB_Text_Border )
StringGadget(#Input, 0, 0, 0, 0, "")
DrawGrid()
StartDrawing(WindowOutput(#win))
Repeat
MX = WindowMouseX(#win) - GetSystemMetrics_(#SM_CYSIZEFRAME)
MY = WindowMouseY(#win) - GetSystemMetrics_(#SM_CYCAPTION) - GetSystemMetrics_(#SM_CYSIZEFRAME)
If #WM_LBUTTONDOWN : mk = 1 : Else : mk = 0 : EndIf
Ev = WindowEvent()
SEL = DrawCell(Ev)
If SEL
If mk
HideGadget(#input, 0)
ResizeGadget(#Input, mx, my, 200, 20)
Repeat
;ActivateGadget(#Input)
ev = WaitWindowEvent()
t$ = GetGadgetText(#Input)
If StringByteLength(t$+"W")>wcell:Break:EndIf ;TextLength(t$+"W")>wcell:Break:EndIf ; limit for text too long
Until ev = #PB_Event_Menu And EventMenu() = #Ret
If Len(t$): textcell$(sel - 1) = t$ : EndIf
StopDrawing()
drawgrid()
StartDrawing(WindowOutput(#win))
SetGadgetText(#input, "")
ResizeGadget(#input, 0, 0, 0, 0)
EndIf
SetGadgetText(#Txt, "Selected " + Str(SEL)+s$+textcell$(sel-1))
selected(0) = 0
EndIf
If Ev = #Wm_Paint : DrawImage(Grid, xgrid, ygrid) : EndIf
Until Ev = #PB_Event_CloseWindow
StopDrawing()
End
; EPB