forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Drag Item In List Example

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 4 Source Code
View previous topic :: View next topic  
Author Message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Sep 11, 2002 6:32 am    Post subject: Drag Item In List Example Reply with quote

Code:
REM    _____________________________________________________
REM   |\___________________________________________________/|
REM   | |                                                 | |
REM   | | SOURCE TITLE:    Drag Item In List Example      | |
REM   | | ------------                                    | |
REM   | | SOURCE AUTHOR:   Garrett R. Hylltun             | |
REM   | | -------------                                   | |
REM   | | DATE:            11 September, 2002             | |
REM   | | ----                                            | |
REM   | | REQUIREMENTS:    VDS 4.x                        | |
REM   | | ------------                                    | |
REM   | | SOURCE STATUS:   Public Domain                  | |
REM   | | -------------                                   | |
REM   | | SOURCE DESCRIPTION:                             | |
REM   | | ------------------                              | |
REM   | |   This shows you how to drag an item within a   | |
REM   | | list.  Drag up or down the list, let go and the | |
REM   | | item is then placed in new location.            | |
REM   | |_________________________________________________| |
REM   |/___________________________________________________\|

  DIALOG CREATE,Drag Item In List Example,-1,0,240,339
  DIALOG ADD,LIST,LIST1,0,0,240,316,,CLICK
  DIALOG ADD,STATUS,STATUS1
  REM   --- |-------------------------------------------------| ---
  REM   --- |   We need a couple of items in the list to      | ---
  REM   --- | play with for this example, so lets gosub to    | ---
  REM   --- | create some items.                              | ---
  REM   --- |-------------------------------------------------| ---
  Gosub LoadLists
  DIALOG SHOW
  Option Sleeptime,100
  Option Decimalsep,.
  REM   --- |-------------------------------------------------| ---
  REM   --- |   I like setting my variables at the start      | ---
  REM   --- | and null them.                                  | ---
  REM   --- |-------------------------------------------------| ---
  %%ListAction =
  %%ListSelect =
  %%ListIndex =
  %%ListItem =
  %%Status =

:EventLoop
  Wait Event,0
  %E = @event()
  If %E
    Goto %E
  End
  Goto EventLoop

:Timer
  REM   --- |-------------------------------------------------| ---
  REM   --- |   Check to see if the mouse left button is down,| ---
  REM   --- | and if it is, we gather some info and check if  | ---
  REM   --- | it was clicked on our list.                     | ---
  REM   --- |-------------------------------------------------| ---
  If @mousedown(l)
    %%ListSelect = @focus()
    If @equal(%%ListSelect,LIST1)
      %%ListItem = @item(LIST1)
      %%ListIndex = @index(LIST1)
    End
    If @not(@null(%%ListItem))
      REM   --- |-------------------------------------------------| ---
      REM   --- |   If the list was selected, %%ListItem will     | ---
      REM   --- | have something in it, otherwise, we don't even  | ---
      REM   --- | bother doing anything.                          | ---
      REM   --- |-------------------------------------------------| ---
      parse "%V;%W",@mousepos()
      Repeat
        Wait "0.1"
        parse "%X;%Y",@mousepos()
        REM   --- |-------------------------------------------------| ---
        REM   --- |   We took mouse position above, now we keep     | ---
        REM   --- | checking to see if the mouse was moved.. If it  | ---
        REM   --- | was, then we delete the item we are moving.  We | ---
        REM   --- | also set a variable switch letting the rest of  | ---
        REM   --- | the code know we are now in drag mode.  We also | ---
        REM   --- | change the cursor to a DRAG cursor to let the   | ---
        REM   --- | user know they are now in drag mode.            | ---
        REM   --- |-------------------------------------------------| ---
        If @not(@equal(%X%Y,%V%W))
          If @null(%%Status)
            List Seek,LIST1,%%ListIndex
            List Delete,LIST1
            Dialog Cursor,DRAG
            Dialog Set,Status1,Drag in progress....
            %%Status = DragNow
          End
        End
        REM   --- |-------------------------------------------------| ---
        REM   --- |   If in drag mode, we need to see where the     | ---
        REM   --- | mouse goes and what it is over.  If it's not    | ---
        REM   --- | over the list we want to drop on, then we need  | ---
        REM   --- | to change the cursor to a NODROP.  If it's over | ---
        REM   --- | the destination list, we change the cursor to   | ---
        REM   --- | a DRAG.                                         | ---
        REM   --- |-------------------------------------------------| ---
        If @equal(%%Status,DragNow)
          REM   --- |-------------------------------------------------| ---
          REM   --- |   Get the name of the element that the mouse    | ---
          REM   --- | is over with the @wintext(@winatpoint(%X,%Y))   | ---
          REM   --- |-------------------------------------------------| ---
          %%Element = @wintext(@winatpoint(%X,%Y))
          If @equal(%%Element,LIST1)
            Dialog Cursor,DRAG
          Else
            Dialog Cursor,NODROP
          End
        End
      Until @not(@mousedown(l))
      If @equal(%%Status,DragNow)
        REM   --- |-------------------------------------------------| ---
        REM   --- |   Now the mouse button has been released, we    | ---
        REM   --- | need to see where it was released.  If it was   | ---
        REM   --- | over the list, then we just insert the item     | ---
        REM   --- | where the list was currently highlighted.  If   | ---
        REM   --- | it was not on the list, then we seek back to    | ---
        REM   --- | where it was and re-insert it.                  | ---
        REM   --- |-------------------------------------------------| ---
        If @equal(%%Element,LIST1)
          %%ListAction = Yes
          List Insert,LIST1,%%ListItem
        Else
          If @equal(%%ListIndex,@count(LIST1))
            REM   --- |-------------------------------------------------| ---
            REM   --- |   If it was the last item in the list then we   | ---
            REM   --- | need to add it back instead of insert.          | ---
            REM   --- |-------------------------------------------------| ---
            List Add,LIST1,%%ListItem
          Else
            List Seek,LIST1,%%ListIndex
            List Insert,LIST1,%%ListItem
          End
        End
      End
      Dialog Cursor
      %%ListSelect =
      %%ListIndex =
      %%ListItem =
      %%Status =
    End
  End
  Goto EventLoop

:Close
  Exit

:List1click
  If @equal(%%ListAction,Yes)
    Dialog Set,Status1,List1 was clicked and a drag action did occur
  Else
    Dialog Set,Status1,List1 was clicked but no drag occured
  End
  %%ListAction =
  Goto EventLoop

:LoadLists
  REM   --- |-------------------------------------------------| ---
  REM   --- |   Here's our sub to fill the lists.. Nothing    | ---
  REM   --- | of major importance or interest here.           | ---
  REM   --- |-------------------------------------------------| ---
  List Add,List1,"BEEP"
  List Add,List1,"BINFILE"
  List Add,List1,"CLIPBOARD"
  List Add,List1,"DDE"
  List Add,List1,"DIALOG"
  List Add,List1,"DIRECTORY"
  List Add,List1,"ELSE"
  List Add,List1,"ELSIF"
  List Add,List1,"END"
  List Add,List1,"EXIT"
  List Add,List1,"EXITWIN"
  List Add,List1,"EXTERNAL"
  Exit


Last edited by Garrett on Thu Sep 12, 2002 12:04 am; edited 1 time in total
Back to top
View user's profile Send private message
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Wed Sep 11, 2002 11:40 am    Post subject: Reply with quote

Excellent!

I will certainly use this.

Thanks!
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Wed Sep 11, 2002 9:07 pm    Post subject: Reply with quote

Another excellent example. Smile
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 4 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group