- ; +======================================================+
- ; | |
- ; +------------------------------------------------------+
- ; | COPYRIGHT(C)2017-2019, ALL RIGHT RESERVED KOAKDESIGN |
- ; +--------------+---------------------------------------+
- ; | Program type | PUREBASIC 5.70 LTS (MODULE) |
- ; +--------------+---------------------------------------+
- ; | VER & REV | 0.0.1 |
- ; +--------------+---------------------------------------+
- ; | Program name | |
- ; +======================================================+
- ; +======================================================+
- ; | Original Version: 0.0.1 |
- ; +--------------+---------------------------------------+
- ; | Created by | GallyHomeCorp |
- ; | Graphix by | GallyHomeCorp |
- ; +--------------+---------------------------------------+
- ; | Comments: | |
- ; +--------------+ |
- ; | |
- ; | |
- ; | |
- ; +======================================================+
- ; +======================================================+
- ; | Système d'Exploitation |
- ; +--------------+---------------------------------------+
- ; | Window | Oui |
- ; | Linux | Oui |
- ; | MacOS | Oui |
- ; +======================================================+
- ; ****************************************************************************
- ; ****************************************************************************
- ; ****************************************************************************
- ;- INITIALISATION DES DIRECTIVES DU COMPILEUR.
- DisableASM
- CompilerIf #PB_Compiler_EnableExplicit
- EnableExplicit
- CompilerEndIf
- UsePNGImageDecoder()
- ; ****************************************************************************
- ; ****************************************************************************
- ; ****************************************************************************
- #PB_Event_CustomGadget_Splitter = #PB_Event_FirstCustomValue + 112
- #Splitter_Tab_Normal = 0
- #Splitter_Tab_First_Hide = 1
- #Splitter_Tab_Second_Hide = 2
- ; ****************************************************************************
- ; ****************************************************************************
- ; ****************************************************************************
- DeclareModule Splitter
- ;
- DisableASM
- CompilerIf #PB_Compiler_EnableExplicit
- EnableExplicit
- CompilerEndIf
- ;
- ;- DECLARATION PUBLIQUES DU MODULE.
- ;
- CompilerIf Defined(PB_Event_CustomGadget_PanTilt, #PB_Constant) = #False
- #PB_Event_CustomGadget_Splitter = #PB_Event_FirstCustomValue + 112
- CompilerEndIf
- ;
- CompilerIf Defined(Splitter_Tab_Normal, #PB_Constant) = #False
- #Splitter_Tab_Normal = 0
- CompilerEndIf
- CompilerIf Defined(Splitter_Tab_First_Hide, #PB_Constant) = #False
- #Splitter_Tab_First_Hide = 1
- CompilerEndIf
- CompilerIf Defined(Splitter_Tab_Second_Hide, #PB_Constant) = #False
- #Splitter_Tab_Second_Hide = 2
- CompilerEndIf
- ;
- ;
- ;
- Declare.i _CreateGadget (gadget.i, x.l, y.l, w.l, h.l, gadget1.i, gadget2.i)
- Declare _SetGadgetState (gadget.i, value.l)
- Declare _SetGadgetAttribute (gadget.i, attribut.l)
- Declare _ResizeGadget (gadget.i, x.l, y.l, w.l, h.l)
-
- EndDeclareModule
- ;
- ;
- ;
- Module Splitter
- ;
- DisableASM
- CompilerIf #PB_Compiler_EnableExplicit
- EnableExplicit
- CompilerEndIf
- ;
- ;- DECLARATION PRIVES DU MODULE.
- ;
- UsePNGImageDecoder ()
- ;
- Structure _STRUTURE_SPLITTER
- window.i
- gadget.i
- gadgetid.i
- x.l
- y.l
- w.l
- h.l
- px.l
- background.i
- attribut.l
- disable.b
- ;
- gadget1.i
- gadget2.i
- EndStructure
- Global NewMap _CREATE_SPLITTER._STRUTURE_SPLITTER()
- ;
- ;
- ;
- CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
- Structure point
- x.l
- y.l
- EndStructure
- CompilerEndIf
- CompilerIf Defined(_WINDOW_BACKGROUND, #PB_Procedure) = #False
- Procedure _WINDOW_BACKGROUND(hwnd.i = 0)
- ;
- ; http://www.purebasic.fr/english/viewtopic.php?p=472982#p472982
- ;
- CompilerSelect #PB_Compiler_OS
- CompilerCase #PB_OS_Windows
- ;
- Protected color = GetSysColor_(#COLOR_WINDOW)
- If color = $FFFFFF OR color=0
- color = GetSysColor_(#COLOR_BTNFACE)
- EndIf
- ProcedureReturn color
- ;
- CompilerCase #PB_OS_Linux
- ;
- Protected *style.GtkStyle, *color.GdkColor
- *style = gtk_widget_get_style_(hwnd)
- *color = *style\bg[0]
- ProcedureReturn RGB(*color\red >> 8, *color\green >> 8, *color\blue >> 8)
- ;
- CompilerCase #PB_OS_MacOS
- ;
- Protected.i color, Rect.NSRect, Image
- Protected.i NSColor = CocoaMessage(#Null, #Null, "NSColor windowBackgroundColor")
- If NSColor
- Rect\size\width = 1
- Rect\size\height = 1
- Image = CreateImage(#PB_Any, 1, 1)
- StartDrawing(ImageOutput(Image))
- CocoaMessage(#Null, NSColor, "drawSwatchInRect:@", @Rect)
- color = Point(0, 0)
- StopDrawing()
- FreeImage(Image)
- ProcedureReturn color
- Else
- ProcedureReturn -1
- EndIf
- ;
- CompilerEndSelect
- EndProcedure
- CompilerEndIf
- ;
- Procedure GadgetRefresh(gadget)
- ;
- CompilerSelect #PB_Compiler_OS
- CompilerCase #PB_OS_Windows
- InvalidateRect_(GadgetID(gadget), 0, 1)
- CompilerCase #PB_OS_Linux
- CompilerIf Subsystem("qt")
- QtScript("gadget(" + STR(gadget) + ").repaint()")
- CompilerElse
- gtk_widget_queue_draw_(GadgetID(gadget))
- CompilerEndIf
- CompilerCase #PB_OS_MacOS
- CocoaMessage(0, GadgetID(gadget), "setNeedsDisplay:", 1)
- CompilerEndSelect
-
- EndProcedure
- ;
- ;-
- ;
- Procedure _OnEvent_RESIZEGADGET(gadget.i)
- ;
- ;
- ;
- If FindMapElement(_CREATE_SPLITTER(), STR(gadget)) <> #Null
- ResizeGadget(_CREATE_SPLITTER()\gadget1, _CREATE_SPLITTER()\x, _CREATE_SPLITTER()\y , (_CREATE_SPLITTER()\px - _CREATE_SPLITTER()\x), _CREATE_SPLITTER()\h)
- ResizeGadget(_CREATE_SPLITTER()\gadget2, _CREATE_SPLITTER()\px + 8, _CREATE_SPLITTER()\y , _CREATE_SPLITTER()\w - (_CREATE_SPLITTER()\px - 2), _CREATE_SPLITTER()\h)
- EndIf
-
- EndProcedure
- ;
- Procedure _OnEvent_RESIZEALLGADGET(gadget.i)
- ;
- ;
- ;
- If FindMapElement(_CREATE_SPLITTER(), STR(gadget)) <> #Null
- Select _CREATE_SPLITTER()\attribut
- Case #Splitter_Tab_Normal
- ResizeGadget(_CREATE_SPLITTER()\gadget, _CREATE_SPLITTER()\px, #PB_Ignore, #PB_Ignore, #PB_Ignore)
- ResizeGadget(_CREATE_SPLITTER()\gadget1, _CREATE_SPLITTER()\x, _CREATE_SPLITTER()\y , (_CREATE_SPLITTER()\px - _CREATE_SPLITTER()\x), _CREATE_SPLITTER()\h)
- ResizeGadget(_CREATE_SPLITTER()\gadget2, _CREATE_SPLITTER()\px + 8, _CREATE_SPLITTER()\y , _CREATE_SPLITTER()\w - (_CREATE_SPLITTER()\px - 2), _CREATE_SPLITTER()\h)
- HideGadget(_CREATE_SPLITTER()\gadget,#False)
- HideGadget(_CREATE_SPLITTER()\gadget1,#False)
- HideGadget(_CREATE_SPLITTER()\gadget2,#False)
- Case #Splitter_Tab_First_Hide
- HideGadget(_CREATE_SPLITTER()\gadget,#True)
- HideGadget(_CREATE_SPLITTER()\gadget1,#True)
- ResizeGadget(_CREATE_SPLITTER()\gadget2, _CREATE_SPLITTER()\x, _CREATE_SPLITTER()\y , _CREATE_SPLITTER()\w + 5, _CREATE_SPLITTER()\h)
- Case #Splitter_Tab_Second_Hide
- HideGadget(_CREATE_SPLITTER()\gadget,#True)
- HideGadget(_CREATE_SPLITTER()\gadget2,#True)
- ResizeGadget(_CREATE_SPLITTER()\gadget2, _CREATE_SPLITTER()\x, _CREATE_SPLITTER()\y , _CREATE_SPLITTER()\w + 5, _CREATE_SPLITTER()\h)
- EndSelect
- ;
- If StartDrawing(CanvasOutput(gadget))
- Box(0, 0, 8, _CREATE_SPLITTER()\h, _CREATE_SPLITTER()\background)
- StopDrawing()
- EndIf
- ;
- GadgetRefresh(_CREATE_SPLITTER()\gadget)
- GadgetRefresh(_CREATE_SPLITTER()\gadget1)
- GadgetRefresh(_CREATE_SPLITTER()\gadget2)
- ;
- PostEvent(#PB_Event_CustomGadget_Splitter, _CREATE_SPLITTER()\window, gadget, #PB_EventType_Change)
- EndIf
-
- EndProcedure
- ;
- Procedure _OnEvent_SCANBORDERS(lvalue.l, lmin.l, lmax.l)
- ;
- ;
- ;
- If lvalue < lmin
- lvalue = lmin
- ElseIf lvalue > lmax
- lvalue = lmax
- EndIf
- ;
- ProcedureReturn lvalue
-
- EndProcedure
- ;
- Procedure _OnEvent_CUSTUMSPLITTER()
- ;
- ;
- ;
- Protected.i event = EventType ()
- Protected.i gadget = EventGadget()
- Protected.i windows = EventWindow()
- Protected.l positionX
- Static.b _SAV_CAPTURE
- Static.l _SAV_CANVASX
- ;
- If FindMapElement(_CREATE_SPLITTER(), STR(gadget)) <> #Null
- If _CREATE_SPLITTER()\disable = #False
- If event = #PB_EventType_LeftButtonDown OR event = #PB_EventType_LeftDoubleClick OR (event = #PB_EventType_MouseMove AND GetGadgetAttribute(gadget, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton) AND _SAV_CAPTURE = #True
- If _SAV_CAPTURE = #False
- _SAV_CANVASX = GetGadgetAttribute(gadget, #PB_Canvas_MouseX)
- EndIf
- _SAV_CAPTURE = #True
- positionX = WindowMouseX(windows) - _SAV_CANVASX
- positionX = _OnEvent_SCANBORDERS(positionX, _CREATE_SPLITTER()\x, (_CREATE_SPLITTER()\x + _CREATE_SPLITTER()\w) - 8)
- If _CREATE_SPLITTER()\px <> positionX
- _CREATE_SPLITTER()\px = positionX
- _OnEvent_RESIZEGADGET(gadget)
- ResizeGadget(gadget, positionX, #PB_Ignore, #PB_Ignore, #PB_Ignore)
- ;
- PostEvent(#PB_Event_CustomGadget_Splitter, _CREATE_SPLITTER()\window, gadget, #PB_EventType_Change)
- EndIf
- EndIf
- If event = #PB_EventType_LeftButtonUp AND _SAV_CAPTURE = #True
- _SAV_CAPTURE = #False
- ;
- GadgetRefresh(_CREATE_SPLITTER()\gadget1)
- GadgetRefresh(_CREATE_SPLITTER()\gadget2)
- EndIf
- If event = #PB_EventType_MouseLeave
- _SAV_CAPTURE = #False
- _SAV_CANVASX = 0
- EndIf
- EndIf
- EndIf
-
- EndProcedure
- ;
- ;-
- ;
- Procedure.i _CreateGadget(gadget.i, x.l, y.l, w.l, h.l, gadget1.i, gadget2.i)
- ;
- ;
- ;
- Protected.i ivalue
- ;
- ;
- ;
- If IsGadget(gadget1) = 0 OR IsGadget(gadget2) = 0
- ProcedureReturn 0
- EndIf
- ;
- If gadget = #PB_Any
- gadget = CanvasGadget(#PB_Any, (w - x) * 0.5, y, 8, h)
- ivalue = gadget
- Else
- ivalue = CanvasGadget(gadget, (w - x) * 0.5, y, 8, h, #PB_Container_BorderLess | #PB_Canvas_Keyboard)
- EndIf
- AddMapElement(_CREATE_SPLITTER(), STR(gadget), #PB_Map_ElementCheck)
- ;
- SetGadgetAttribute(gadget, #PB_Canvas_Cursor, #PB_Cursor_LeftRight)
- ;
- ;
- ;
- _CREATE_SPLITTER()\gadget = gadget
- _CREATE_SPLITTER()\gadgetid = ivalue
- _CREATE_SPLITTER()\x = x
- _CREATE_SPLITTER()\y = y
- _CREATE_SPLITTER()\w = w
- _CREATE_SPLITTER()\h = h
- _CREATE_SPLITTER()\px = (w - x) * 0.5
- _CREATE_SPLITTER()\disable = #False
- ;
- CompilerIf #PB_Compiler_OS = #PB_OS_Windows
- _CREATE_SPLITTER()\background = _WINDOW_BACKGROUND(#Null)
- CompilerElse
- _CREATE_SPLITTER()\background = _WINDOW_BACKGROUND(WindowID(_CREATE_SLIDER()\window))
- CompilerEndIf
- ;
- _CREATE_SPLITTER()\gadget1 = gadget1
- _CREATE_SPLITTER()\gadget2 = gadget2
- ;
- If StartDrawing(CanvasOutput(gadget))
- Box(0, 0, 8, h, _CREATE_SPLITTER()\background)
- StopDrawing()
- EndIf
- ;
- _OnEvent_RESIZEGADGET(_CREATE_SPLITTER()\gadget)
- ;
- BindGadgetEvent (_CREATE_SPLITTER()\gadget, @_OnEvent_CUSTUMSPLITTER(), #PB_All)
- ;
- ProcedureReturn ivalue
-
- EndProcedure
- ;
- Procedure _SetGadgetState(gadget.i, value.l)
- ;
- ;
- ;
- If FindMapElement(_CREATE_SPLITTER(), STR(gadget)) <> #Null
- value = _OnEvent_SCANBORDERS(value, _CREATE_SPLITTER()\x, (_CREATE_SPLITTER()\x + _CREATE_SPLITTER()\w) - 8)
- If _CREATE_SPLITTER()\px <> value
- _CREATE_SPLITTER()\px = value
- _OnEvent_RESIZEGADGET(gadget)
- ResizeGadget(gadget, value, #PB_Ignore, #PB_Ignore, #PB_Ignore)
- ;
- PostEvent(#PB_Event_CustomGadget_Splitter, _CREATE_SPLITTER()\window, gadget, #PB_EventType_Change)
- EndIf
-
- EndIf
-
- EndProcedure
- ;
- Procedure _SetGadgetAttribute(gadget.i, attribut.l)
- ;
- ;
- ;
- If FindMapElement(_CREATE_SPLITTER(), STR(gadget)) <> #Null
- Protected.l _SAV_ATTRIBUT = _CREATE_SPLITTER()\attribut
- Select attribut
- Case #Splitter_Tab_Normal
- _CREATE_SPLITTER()\attribut = attribut
- Case #Splitter_Tab_First_Hide
- _CREATE_SPLITTER()\attribut = attribut
- Case #Splitter_Tab_Second_Hide
- _CREATE_SPLITTER()\attribut = attribut
- EndSelect
- If _SAV_ATTRIBUT <> _CREATE_SPLITTER()\attribut
- _OnEvent_RESIZEALLGADGET(gadget)
- EndIf
- EndIf
- EndProcedure
- ;
- Procedure _ResizeGadget(gadget.i, x.l, y.l, w.l, h.l)
- ;
- ;
- ;
- If FindMapElement(_CREATE_SPLITTER(), STR(gadget)) <> #Null
- If x <> #PB_Ignore OR y <> #PB_Ignore OR w <> #PB_Ignore OR h <> #PB_Ignore
- ;
- If x <> #PB_Ignore
- _CREATE_SPLITTER()\x = x
- EndIf
- If y <> #PB_Ignore
- _CREATE_SPLITTER()\y = y
- EndIf
- If w <> #PB_Ignore
- _CREATE_SPLITTER()\w = w
- EndIf
- If h <> #PB_Ignore
- _CREATE_SPLITTER()\h = h
- EndIf
- ;_CREATE_SPLITTER()\px = (_CREATE_SPLITTER()\w - _CREATE_SPLITTER()\x) * 0.5
- ;
- ResizeGadget(gadget, x, y, #PB_Ignore, h)
- _OnEvent_RESIZEALLGADGET(gadget)
- EndIf
- EndIf
- EndProcedure
-
- EndModule
- ; ****************************************************************************
- ; ****************************************************************************
- ; ****************************************************************************
- ;-
- ;- ROUTINE DE TEST DES FONCTIONS (MODULE).
- CompilerIf #PB_Compiler_IsMainFile
-
- #FenetrePrincipale = 0
- #FenetreFille = 1
- If OpenWindow(#FenetrePrincipale, 0, 0, 1020, 640, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
- If CreateMenu(#FenetrePrincipale, WindowID(#FenetrePrincipale))
- MenuTitle("Index de menu 0")
- MenuTitle("Menu des fenêtres filles")
- MenuItem(0, "Elément auto-créé")
- MenuItem(1, "Elément auto-créé")
-
- MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_BorderLess)
- AddGadgetItem(0, #FenetreFille, "Fenêtre fille")
- UseGadgetList(WindowID(#FenetrePrincipale))
- TextGadget(1, 0, 0, 10, 20, "")
- SetGadgetColor(1, #PB_Gadget_BackColor, $cccccc)
-
- Define splitter = Splitter::_CreateGadget(#PB_Any, 10, 10, 1000, 600, 1, 0)
- Splitter::_SetGadgetState(splitter, 10)
- EndIf
- Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
- EndIf
- CompilerEndIf