home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / fsrc1241.zip / toolbarconfig.c < prev    next >
C/C++ Source or Header  |  1999-02-14  |  46KB  |  1,331 lines

  1. /*---------------------------------------------------------------------------+
  2.  | Titel: TOOLBARCONFIG.C                                                    |
  3.  +-----------------------------------------+---------------------------------+
  4.  | Erstellt von: Michael Hohner            | Am: 27.09.1995                  |
  5.  +-----------------------------------------+---------------------------------+
  6.  | System: OS/2 2.x                                                          |
  7.  +---------------------------------------------------------------------------+
  8.  | Beschreibung:                                                             |
  9.  |                                                                           |
  10.  |     Konfiguration der FleetStreet-Toolbar                                 |
  11.  |                                                                           |
  12.  |                                                                           |
  13.  +---------------------------------------------------------------------------+
  14.  | Bemerkungen:                                                              |
  15.  +---------------------------------------------------------------------------*/
  16.  
  17. #pragma strings(readonly)
  18.  
  19. /*----------------------------- Header-Dateien ------------------------------*/
  20.  
  21. #define INCL_WIN
  22. #include <os2.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include "main.h"
  26. #include "structs.h"
  27. #include "msgheader.h"
  28. #include "areaman\areaman.h"
  29. #include "utility.h"
  30. #include "resids.h"
  31. #include "dialogids.h"
  32. #include "controls\toolbar.h"
  33.  
  34. #include "toolbarconfig.h"
  35.  
  36. /*--------------------------------- Defines ---------------------------------*/
  37.  
  38. #define BUTTONTYPE "FleetStreet Button"
  39. #define BUTTONMECH "DRM_FLEET"
  40. #define BUTTONFORMAT "DRF_BUTTON"
  41. #define BUTTONRMF  "<" BUTTONMECH "," BUTTONFORMAT ">"
  42.  
  43. #define TBCM_REFRESHLISTS  (WM_USER+1)
  44.  
  45. /*---------------------------------- Typen ----------------------------------*/
  46.  
  47. /* Gesamt-Daten */
  48.  
  49. typedef struct
  50. {
  51.    ULONG ulButtonID;        /* IDB_* */
  52.    ULONG ulBitmapID;        /* IDBMP_* (große Darstellung) */
  53.    ULONG ulSmallBitmapID;   /* IDBMP_* (kleine Darstellung) */
  54.    ULONG ulStringID;        /* IDST_* (Erklärung */
  55.    HBITMAP hbmButton;
  56. } BUTTONLIST, *PBUTTONLIST;
  57.  
  58. /* Selektionsfenster */
  59.  
  60. #define LEN_BUTTONTEXT   50
  61.  
  62. typedef struct buttonselect
  63. {
  64.    struct buttonselect *next;
  65.    struct buttonselect *prev;
  66.    ULONG   ulButtonID;                       /* 0 = Spacer */
  67.    CHAR    pchButtonText[LEN_BUTTONTEXT+1];
  68.    HBITMAP hBitmap;
  69. } BUTTONSELECT, *PBUTTONSELECT;
  70.  
  71. typedef struct
  72. {
  73.    MINIRECORDCORE RecordCore;
  74.    HBITMAP hbmButton;
  75.    PCHAR   pchButtonText;
  76.    PBUTTONSELECT pButton;
  77. } BUTTONRECORD, *PBUTTONRECORD;
  78.  
  79. typedef struct
  80. {
  81.    char pchTitleDisp[50];
  82.    char pchTitleAvail[50];
  83.    LONG lMinX;
  84.    LONG lMinY;
  85.    BOOL bNotify;
  86.    PTOOLBARCONFIG pConfig;
  87.    PBUTTONSELECT pDisp;
  88.    PBUTTONSELECT pAvail;
  89. } TBCDATA, *PTBCDATA;
  90.  
  91. /*---------------------------- Globale Variablen ----------------------------*/
  92.  
  93. extern HAB anchor;
  94. extern HWND hwndhelp;
  95.  
  96. static HBITMAP hbmSeparator;
  97.  
  98. /* alle definierten Buttons */
  99. static BUTTONLIST ButtonList[]=
  100. {
  101.  /* ButtonID,      BitmapID,          BitmapID (klein),       StringID */
  102.  {IDB_OK,          IDBMP_OK,          IDBMP_OK_S,             IDST_HLP_OK, NULLHANDLE},
  103.  {IDB_CANCEL,      IDBMP_CANCEL,      IDBMP_CANCEL_S,         IDST_HLP_CANCEL, NULLHANDLE},
  104.  {IDB_PREVMSG,     IDBMP_PREVMSG,     IDBMP_PREVMSG_S,        IDST_HLP_PREVMSG, NULLHANDLE},
  105.  {IDB_NEXTMSG,     IDBMP_NEXTMSG,     IDBMP_NEXTMSG_S,        IDST_HLP_NEXTMSG, NULLHANDLE},
  106.  {IDB_PREVREPLY,   IDBMP_PREVREPLY,   IDBMP_PREVREPLY_S,      IDST_HLP_PREVREPLY, NULLHANDLE},
  107.  {IDB_NEXTREPLY,   IDBMP_NEXTREPLY,   IDBMP_NEXTREPLY_S,      IDST_HLP_NEXTREPLY, NULLHANDLE},
  108.  {IDB_FIRSTMSG,    IDBMP_FIRSTMSG,    IDBMP_FIRSTMSG_S,       IDST_HLP_FIRSTMSG, NULLHANDLE},
  109.  {IDB_LASTMSG,     IDBMP_LASTMSG,     IDBMP_LASTMSG_S,        IDST_HLP_LASTMSG, NULLHANDLE},
  110.  {IDB_FIND,        IDBMP_FIND,        IDBMP_FIND_S,           IDST_HLP_FIND, NULLHANDLE},
  111.  {IDB_MSGTREE,     IDBMP_MSGTREE,     IDBMP_MSGTREE_S,        IDST_HLP_MSGTREE, NULLHANDLE},
  112.  {IDB_NEWMSG,      IDBMP_NEWMSG,      IDBMP_NEWMSG_S,         IDST_HLP_NEWMSG, NULLHANDLE},
  113.  {IDB_REPLY,       IDBMP_REPLY,       IDBMP_REPLY_S,          IDST_HLP_REPLY, NULLHANDLE},
  114.  {IDB_IMPORT,      IDBMP_IMPORT,      IDBMP_IMPORT_S,         IDST_HLP_IMPORT, NULLHANDLE},
  115.  {IDB_EXPORT,      IDBMP_EXPORT,      IDBMP_EXPORT_S,         IDST_HLP_EXPORT, NULLHANDLE},
  116.  {IDB_DELMSG,      IDBMP_DELMSG,      IDBMP_DELMSG_S,         IDST_HLP_DELMSG, NULLHANDLE},
  117.  {IDB_EDITMSG,     IDBMP_EDITMSG,     IDBMP_EDITMSG_S,        IDST_HLP_EDITMSG, NULLHANDLE},
  118.  {IDB_AREA,        IDBMP_AREA,        IDBMP_AREA_S,           IDST_HLP_AREA, NULLHANDLE},
  119.  {IDB_MSGLIST,     IDBMP_MSGLIST,     IDBMP_MSGLIST_S,        IDST_HLP_MSGLIST, NULLHANDLE},
  120.  {IDB_PRINTMSG,    IDBMP_PRINTMSG,    IDBMP_PRINTMSG_S,       IDST_HLP_PRINTMSG, NULLHANDLE},
  121.  {IDB_SHOWKLUDGES, IDBMP_SHOWKLUDGES, IDBMP_SHOWKLUDGES_S,    IDST_HLP_SHOWKLUDGES, NULLHANDLE},
  122.  {IDB_HOMEMSG,     IDBMP_HOMEMSG,     IDBMP_HOMEMSG_S,        IDST_HLP_HOMEMSG, NULLHANDLE},
  123.  {IDB_NEXTAREA,    IDBMP_NEXTAREA,    IDBMP_NEXTAREA_S,       IDST_HLP_NEXTAREA, NULLHANDLE},
  124.  {IDB_BOOKMARKS,   IDBMP_BOOKMARKS,   IDBMP_BOOKMARKS_S,      IDST_HLP_WI_RESULTS, NULLHANDLE},
  125.  {IDB_HELP,        IDBMP_HELP,        IDBMP_HELP_S,           IDST_HLP_HE_GENERAL, NULLHANDLE},
  126.  {IDB_CUT,         IDBMP_CUT,         IDBMP_CUT_S,            IDST_HLP_ED_CUT, NULLHANDLE},
  127.  {IDB_COPY,        IDBMP_COPY,        IDBMP_COPY_S,           IDST_HLP_ED_COPY, NULLHANDLE},
  128.  {IDB_PASTE,       IDBMP_PASTE,       IDBMP_PASTE_S,          IDST_HLP_ED_PASTE, NULLHANDLE},
  129.  {IDB_COPYMSG,     IDBMP_COPYMSG,     IDBMP_COPYMSG_S,        IDST_HLP_MS_COPY, NULLHANDLE},
  130.  {IDB_SHELL,       IDBMP_SHELL,       IDBMP_SHELL_S,          IDST_HLP_FI_SHELL, NULLHANDLE},
  131.  {IDB_SCRIPTS,     IDBMP_SCRIPTS,     IDBMP_SCRIPTS_S,        IDST_HLP_RXSCRIPTS, NULLHANDLE},
  132.  {IDB_MOVEMSG,     IDBMP_MOVEMSG,     IDBMP_MOVEMSG_S,        IDST_HLP_MS_MOVE, NULLHANDLE},
  133.  {IDB_BROWSER,     IDBMP_BROWSER,     IDBMP_BROWSER_S,        IDST_HLP_SPCBROWSER, NULLHANDLE},
  134.  {IDB_FORWARD,     IDBMP_FORWARD,     IDBMP_FORWARD_S,        IDST_HLP_MS_FORWARD, NULLHANDLE},
  135.  {IDB_CATCHUP,     IDBMP_CATCHUP,     IDBMP_CATCHUP_S,        IDST_HLP_MS_MARK, NULLHANDLE},
  136.  {IDB_REQUEST,     IDBMP_REQUEST,     IDBMP_REQUEST_S,        IDST_HLP_MS_REQ, NULLHANDLE}
  137. };
  138.  
  139. #define SIZEOFBUTTONLIST (sizeof(ButtonList)/sizeof(ButtonList[1]))
  140.  
  141. /* Default-Konfiguration */
  142. static BUTTONCONFIG DefaultConfig[]=
  143. {
  144.  {IDB_HOMEMSG,     0},
  145.  {IDB_NEXTAREA,    0},
  146.  {IDB_PREVMSG,     TBITEM_SPACER},
  147.  {IDB_NEXTMSG,     0},
  148.  {IDB_PREVREPLY,   TBITEM_SPACER},
  149.  {IDB_NEXTREPLY,   0},
  150.  {IDB_FIRSTMSG,    TBITEM_SPACER},
  151.  {IDB_LASTMSG,     0},
  152.  {IDB_OK,          TBITEM_SPACER},
  153.  {IDB_CANCEL,      0},
  154.  {IDB_NEWMSG,      TBITEM_SPACER},
  155.  {IDB_EDITMSG,     0},
  156.  {IDB_REPLY,       0},
  157.  {IDB_DELMSG,      TBITEM_SPACER},
  158.  {IDB_COPYMSG,     0},
  159.  {IDB_MOVEMSG,     0},
  160.  {IDB_FORWARD,     0},
  161.  {IDB_PRINTMSG,    TBITEM_SPACER},
  162.  {IDB_IMPORT,      0},
  163.  {IDB_EXPORT,      0},
  164.  {IDB_FIND,        TBITEM_SPACER},
  165.  {IDB_MSGLIST,     0},
  166.  {IDB_MSGTREE,     0},
  167.  {IDB_AREA,        0},
  168.  {IDB_SHOWKLUDGES, 0},
  169.  {IDB_BOOKMARKS,   0},
  170.  {IDB_SCRIPTS,     0},
  171.  {IDB_BROWSER,     0},
  172.  {IDB_REQUEST,     0},
  173.  {IDB_CATCHUP,     0},
  174.  {IDB_SHELL,       TBITEM_SPACER},
  175.  {IDB_CUT,         TBITEM_SPACER},
  176.  {IDB_COPY,        0},
  177.  {IDB_PASTE,       0},
  178.  {IDB_HELP,        TBITEM_SPACER}
  179. };
  180.  
  181. /*--------------------------- Funktionsprototypen ---------------------------*/
  182.  
  183. /*----------------------- interne Funktionsprototypen -----------------------*/
  184.  
  185. static void CreateBitmaps(HWND hwndDlg);
  186. static void DestroyBitmaps(void);
  187. static PBUTTONSELECT ConfigToButtonSelect(PTOOLBARCONFIG pToolbarConfig);
  188. static PBUTTONSELECT AddButtonToSelect(PBUTTONSELECT *ppFirst, PBUTTONSELECT pCurrent, ULONG ulButtonID);
  189. static BOOL ButtonInSelection(PBUTTONSELECT pButtons, ULONG ulButtonID);
  190. static void InitButtonCnr(HWND hwndCnr, PCHAR pchTitleText);
  191. static void FillButtonCnr(HWND hwndCnr, PBUTTONSELECT pButtonSelect);
  192. static PBUTTONSELECT BuildAvailList(PBUTTONSELECT pSelected);
  193. static void FreeButtonList(PBUTTONSELECT pList);
  194. static void AddToDisp(HWND hwndDlg, PTBCDATA pTBCData);
  195. static void RemoveFromDisp(HWND hwndDlg, PTBCDATA pTBCData);
  196. static void ButtonSelectToConfig(PBUTTONSELECT pButtons, PTOOLBARCONFIG pToolbarConfig);
  197. static void InitButtonDrag(HWND hwndDlg, PCNRDRAGINIT pDragInit);
  198. static MRESULT DragAfter(HWND hwndDlg, PCNRDRAGINFO pCnrDrag);
  199. static void DropButton(HWND hwndDlg, PCNRDRAGINFO pCnrDrag, PTBCDATA pTBCData);
  200. static PBUTTONLIST FindButton(ULONG ulButtonID);
  201.  
  202.  
  203. /*-----------------------------------------------------------------------------
  204.  | Funktionsname:
  205.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  206.  | Beschreibung:
  207.  |
  208.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  209.  | Parameter:
  210.  |
  211.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  212.  | Rückgabewerte:
  213.  |
  214.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  215.  | Sonstiges:
  216.  |
  217.  +---------------------------------------------------------------------------*/
  218.  
  219. static void CreateBitmaps(HWND hwndDlg)
  220. {
  221.    int i;
  222.    HPS hps;
  223.  
  224.    hps = WinGetPS(hwndDlg);
  225.    if (hps)
  226.    {
  227.       for (i=0; i<SIZEOFBUTTONLIST; i++)
  228.          ButtonList[i].hbmButton = GpiLoadBitmap(hps, NULLHANDLE, ButtonList[i].ulSmallBitmapID, 0, 0);
  229.  
  230.       hbmSeparator = GpiLoadBitmap(hps, NULLHANDLE, IDBMP_SEPARATOR, 0, 0);
  231.  
  232.       WinReleasePS(hps);
  233.    }
  234.    return;
  235. }
  236.  
  237. /*-----------------------------------------------------------------------------
  238.  | Funktionsname:
  239.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  240.  | Beschreibung:
  241.  |
  242.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  243.  | Parameter:
  244.  |
  245.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  246.  | Rückgabewerte:
  247.  |
  248.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  249.  | Sonstiges:
  250.  |
  251.  +---------------------------------------------------------------------------*/
  252.  
  253. static void DestroyBitmaps(void)
  254. {
  255.    int i;
  256.  
  257.    for (i=0; i<SIZEOFBUTTONLIST; i++)
  258.       GpiDeleteBitmap(ButtonList[i].hbmButton);
  259.  
  260.    GpiDeleteBitmap(hbmSeparator);
  261.  
  262.    return;
  263. }
  264.  
  265. /*-----------------------------------------------------------------------------
  266.  | Funktionsname:
  267.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  268.  | Beschreibung:
  269.  |
  270.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  271.  | Parameter:
  272.  |
  273.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  274.  | Rückgabewerte:
  275.  |
  276.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  277.  | Sonstiges:
  278.  |
  279.  +---------------------------------------------------------------------------*/
  280.  
  281. static PBUTTONLIST FindButton(ULONG ulButtonID)
  282. {
  283.    int i=0;
  284.  
  285.    while (i < SIZEOFBUTTONLIST &&
  286.           ButtonList[i].ulButtonID != ulButtonID)
  287.       i++;
  288.  
  289.    if (i < SIZEOFBUTTONLIST)
  290.       return &(ButtonList[i]);
  291.    else
  292.       return NULL;
  293. }
  294.  
  295.  
  296. /*-----------------------------------------------------------------------------
  297.  | Funktionsname:
  298.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  299.  | Beschreibung:
  300.  |
  301.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  302.  | Parameter:
  303.  |
  304.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  305.  | Rückgabewerte:
  306.  |
  307.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  308.  | Sonstiges:
  309.  |
  310.  +---------------------------------------------------------------------------*/
  311.  
  312. static PBUTTONSELECT ConfigToButtonSelect(PTOOLBARCONFIG pToolbarConfig)
  313. {
  314.    PBUTTONSELECT pFirst=NULL, pCurrent=NULL;
  315.    int i=0;
  316.  
  317.    for (i=0; i<pToolbarConfig->ulNumButtons; i++)
  318.    {
  319.       if (pToolbarConfig->pButtons[i].ulFlags & TBITEM_SPACER)
  320.       {
  321.          pCurrent = AddButtonToSelect(&pFirst, pCurrent, 0);
  322.       }
  323.       pCurrent = AddButtonToSelect(&pFirst, pCurrent, pToolbarConfig->pButtons[i].ulButtonID);
  324.    }
  325.  
  326.    return pFirst;
  327. }
  328.  
  329. /*-----------------------------------------------------------------------------
  330.  | Funktionsname:
  331.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  332.  | Beschreibung:
  333.  |
  334.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  335.  | Parameter:
  336.  |
  337.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  338.  | Rückgabewerte:
  339.  |
  340.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  341.  | Sonstiges:
  342.  |
  343.  +---------------------------------------------------------------------------*/
  344.  
  345. static void ButtonSelectToConfig(PBUTTONSELECT pButtons, PTOOLBARCONFIG pToolbarConfig)
  346. {
  347.    ULONG ulNum=0;
  348.    PBUTTONSELECT pTemp=pButtons;
  349.    ULONG ulFlags=0;
  350.  
  351.    /* Alte Buttons freigeben */
  352.  
  353.    if (pToolbarConfig->pButtons)
  354.    {
  355.       free(pToolbarConfig->pButtons);
  356.       pToolbarConfig->pButtons=NULL;
  357.       pToolbarConfig->ulNumButtons = 0;
  358.    }
  359.  
  360.    pToolbarConfig->bDirty = TRUE;
  361.  
  362.    /* Buttons zaehlen */
  363.    while (pTemp)
  364.    {
  365.       if (pTemp->ulButtonID)
  366.          ulNum++;
  367.       pTemp = pTemp->next;
  368.    }
  369.  
  370.    if (ulNum)
  371.    {
  372.       pToolbarConfig->pButtons = calloc(ulNum, sizeof(BUTTONCONFIG));
  373.       pToolbarConfig->ulNumButtons = ulNum;
  374.  
  375.       pTemp = pButtons;
  376.       ulNum=0;
  377.  
  378.       while (pTemp)
  379.       {
  380.          if (pTemp->ulButtonID)
  381.          {
  382.             pToolbarConfig->pButtons[ulNum].ulButtonID = pTemp->ulButtonID;
  383.             pToolbarConfig->pButtons[ulNum].ulFlags = ulFlags;
  384.  
  385.             ulFlags=0;
  386.  
  387.             ulNum++;
  388.          }
  389.          else
  390.             ulFlags = TBITEM_SPACER;
  391.  
  392.          pTemp = pTemp->next;
  393.       }
  394.    }
  395.  
  396.    return;
  397. }
  398.  
  399. /*-----------------------------------------------------------------------------
  400.  | Funktionsname:
  401.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  402.  | Beschreibung:
  403.  |
  404.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  405.  | Parameter:
  406.  |
  407.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  408.  | Rückgabewerte:
  409.  |
  410.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  411.  | Sonstiges:
  412.  |
  413.  +---------------------------------------------------------------------------*/
  414.  
  415. static PBUTTONSELECT AddButtonToSelect(PBUTTONSELECT *ppFirst, PBUTTONSELECT pCurrent, ULONG ulButtonID)
  416. {
  417.    /* Speicher besorgen */
  418.    if (*ppFirst)
  419.    {
  420.       pCurrent->next = calloc(1, sizeof(BUTTONSELECT));
  421.       pCurrent->next->prev = pCurrent;
  422.       pCurrent = pCurrent->next;
  423.    }
  424.    else
  425.       pCurrent = *ppFirst = calloc(1, sizeof(BUTTONSELECT));
  426.  
  427.    /* Daten laden */
  428.    pCurrent->ulButtonID = ulButtonID;
  429.  
  430.    if (ulButtonID)
  431.    {
  432.       /* passenden Text u. Bitmap laden */
  433.       PBUTTONLIST pButtonDef = FindButton(ulButtonID);
  434.  
  435.       if (pButtonDef)
  436.       {
  437.          LoadString(pButtonDef->ulStringID, sizeof(pCurrent->pchButtonText),
  438.                     pCurrent->pchButtonText);
  439.  
  440.          /* Bitmap */
  441.          pCurrent->hBitmap = pButtonDef->hbmButton;
  442.       }
  443.    }
  444.    else
  445.    {
  446.       /* Text u. Bitmap f. Spacer laden */
  447.       LoadString(IDST_TBC_SEPARATOR, sizeof(pCurrent->pchButtonText),
  448.                  pCurrent->pchButtonText);
  449.  
  450.       /* Bitmap */
  451.       pCurrent->hBitmap = hbmSeparator;
  452.    }
  453.  
  454.    return pCurrent;
  455. }
  456.  
  457.  
  458. /*-----------------------------------------------------------------------------
  459.  | Funktionsname:
  460.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  461.  | Beschreibung:
  462.  |
  463.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  464.  | Parameter:
  465.  |
  466.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  467.  | Rückgabewerte:
  468.  |
  469.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  470.  | Sonstiges:
  471.  |
  472.  +---------------------------------------------------------------------------*/
  473.  
  474. static BOOL ButtonInSelection(PBUTTONSELECT pButtons, ULONG ulButtonID)
  475. {
  476.    while (pButtons && pButtons->ulButtonID != ulButtonID)
  477.       pButtons = pButtons->next;
  478.  
  479.    if (pButtons)
  480.       return TRUE;
  481.    else
  482.       return FALSE;
  483. }
  484.  
  485. /*-----------------------------------------------------------------------------
  486.  | Funktionsname:
  487.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  488.  | Beschreibung:
  489.  |
  490.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  491.  | Parameter:
  492.  |
  493.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  494.  | Rückgabewerte:
  495.  |
  496.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  497.  | Sonstiges:
  498.  |
  499.  +---------------------------------------------------------------------------*/
  500.  
  501. MRESULT EXPENTRY ToolbarConfigProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  502. {
  503.    PTBCDATA pTBCData = WinQueryWindowPtr(hwnd, QWL_USER);
  504.    SWP swp;
  505.    MRESULT mrbuffer;
  506.  
  507.    switch(msg)
  508.    {
  509.       case WM_INITDLG:
  510.          pTBCData = calloc(1, sizeof(TBCDATA));
  511.          WinSetWindowPtr(hwnd, QWL_USER, pTBCData);
  512.  
  513.          pTBCData->pConfig = (PTOOLBARCONFIG) mp2;
  514.  
  515.          CreateBitmaps(hwnd);
  516.  
  517.          LoadString(IDST_TBC_DISP, sizeof(pTBCData->pchTitleDisp), pTBCData->pchTitleDisp);
  518.          LoadString(IDST_TBC_AVAIL, sizeof(pTBCData->pchTitleAvail), pTBCData->pchTitleAvail);
  519.  
  520.          InitButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+1), pTBCData->pchTitleDisp);
  521.          InitButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+2), pTBCData->pchTitleAvail);
  522.  
  523.          /* Mindestgroesse ermitteln */
  524.          WinQueryWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+6), &swp);
  525.          pTBCData->lMinX = swp.x + swp.cx +10;
  526.          WinQueryWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+3), &swp);
  527.          pTBCData->lMinY = swp.y + swp.cy +50;
  528.  
  529.          /* Disp einfuegen */
  530.          pTBCData->pDisp = ConfigToButtonSelect(pTBCData->pConfig);
  531.  
  532.          /* Avail einfuegen */
  533.          pTBCData->pAvail = BuildAvailList(pTBCData->pDisp);
  534.          FillButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+1), pTBCData->pDisp);
  535.          FillButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+2), pTBCData->pAvail);
  536.  
  537.          RestoreWinPos(hwnd, &pTBCData->pConfig->SelectPos, TRUE, TRUE);
  538.          pTBCData->bNotify = TRUE;
  539.          break;
  540.  
  541.       case WM_DESTROY:
  542.          FreeButtonList(pTBCData->pDisp);
  543.          FreeButtonList(pTBCData->pAvail);
  544.          free(pTBCData);
  545.          DestroyBitmaps();
  546.          break;
  547.  
  548.       case WM_QUERYTRACKINFO:
  549.          mrbuffer = WinDefDlgProc(hwnd, msg, mp1, mp2);
  550.          ((PTRACKINFO)mp2)->ptlMinTrackSize.x = pTBCData->lMinX;
  551.          ((PTRACKINFO)mp2)->ptlMinTrackSize.y = pTBCData->lMinY;
  552.          return mrbuffer;
  553.  
  554.       case WM_ADJUSTFRAMEPOS:
  555.          if (((PSWP)mp1)->fl & (SWP_SIZE|SWP_MINIMIZE|SWP_MAXIMIZE|SWP_RESTORE))
  556.          {
  557.             RECTL rclClient;
  558.  
  559.             rclClient.xLeft=0;
  560.             rclClient.xRight=((PSWP)mp1)->cx;
  561.             rclClient.yBottom=0;
  562.             rclClient.yTop=((PSWP)mp1)->cy;
  563.  
  564.             CalcClientRect(anchor, hwnd, &rclClient);
  565.  
  566.             WinQueryWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+3), &swp);
  567.             rclClient.yBottom += swp.y + swp.cy;
  568.  
  569.             WinSetWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+1),
  570.                             NULLHANDLE,
  571.                             0, 0,
  572.                             (rclClient.xRight - rclClient.xLeft) /2,
  573.                             (rclClient.yTop - rclClient.yBottom),
  574.                             SWP_SIZE);
  575.  
  576.             WinSetWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+2),
  577.                             NULLHANDLE,
  578.                             rclClient.xLeft + (rclClient.xRight - rclClient.xLeft)/2 + 1,
  579.                             rclClient.yBottom,
  580.                             (rclClient.xRight - rclClient.xLeft) /2,
  581.                             (rclClient.yTop - rclClient.yBottom),
  582.                             SWP_SIZE | SWP_MOVE);
  583.  
  584.             WinQueryWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+3), &swp);
  585.             WinSetWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+3),
  586.                             NULLHANDLE,
  587.                             rclClient.xLeft + (rclClient.xRight - rclClient.xLeft)/2 - swp.cx/2,
  588.                             swp.y,
  589.                             0, 0,
  590.                             SWP_MOVE);
  591.             WinQueryWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+4), &swp);
  592.             WinSetWindowPos(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+4),
  593.                             NULLHANDLE,
  594.                             rclClient.xLeft + (rclClient.xRight - rclClient.xLeft)/2 - swp.cx/2,
  595.                             swp.y,
  596.                             0, 0,
  597.                             SWP_MOVE);
  598.  
  599.          }
  600.          break;
  601.  
  602.       case WM_WINDOWPOSCHANGED:
  603.          if (pTBCData && pTBCData->bNotify)
  604.             SaveWinPos(hwnd, (PSWP) mp1, &pTBCData->pConfig->SelectPos, &pTBCData->pConfig->bDirty);
  605.          break;
  606.  
  607.       case WM_COMMAND:
  608.          switch(SHORT1FROMMP(mp1))
  609.          {
  610.             case DID_OK:
  611.                ButtonSelectToConfig(pTBCData->pDisp, pTBCData->pConfig);
  612.                break;
  613.  
  614.             case DID_CANCEL:
  615.                break;
  616.  
  617.             case IDD_TOOLBARCONFIG+3: /* Hinzufuegen */
  618.                AddToDisp(hwnd, pTBCData);
  619.                return 0;
  620.  
  621.             case IDD_TOOLBARCONFIG+4: /* Entfernen */
  622.                RemoveFromDisp(hwnd, pTBCData);
  623.                return 0;
  624.  
  625.             case IDD_TOOLBARCONFIG+5: /* Default */
  626.                /* @@ Sicherheitsabfrage */
  627.  
  628.                /* alte Konfiguration freigeben */
  629.                if (pTBCData->pConfig->pButtons)
  630.                {
  631.                   free(pTBCData->pConfig->pButtons);
  632.                   pTBCData->pConfig->pButtons = NULL;
  633.                   pTBCData->pConfig->ulNumButtons = 0;
  634.                }
  635.  
  636.                /* Default-Konfiguration */
  637.                pTBCData->pConfig->pButtons = malloc(sizeof(DefaultConfig));
  638.                memcpy(pTBCData->pConfig->pButtons, DefaultConfig, sizeof(DefaultConfig));
  639.                pTBCData->pConfig->ulNumButtons = sizeof(DefaultConfig)/sizeof(DefaultConfig[0]);
  640.  
  641.                pTBCData->pConfig->bDirty = TRUE;
  642.  
  643.                /* Alte Selektionen freigeben */
  644.                FreeButtonList(pTBCData->pDisp);
  645.                FreeButtonList(pTBCData->pAvail);
  646.  
  647.                /* neue Selektion */
  648.                pTBCData->pDisp = ConfigToButtonSelect(pTBCData->pConfig);
  649.  
  650.                /* Avail einfuegen */
  651.                pTBCData->pAvail = BuildAvailList(pTBCData->pDisp);
  652.                FillButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+1), pTBCData->pDisp);
  653.                FillButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+2), pTBCData->pAvail);
  654.                return 0;
  655.  
  656.             default:
  657.                return 0;
  658.          }
  659.          break;
  660.  
  661.       case WM_CONTROL:
  662.          if (SHORT1FROMMP(mp1) == IDD_TOOLBARCONFIG+1)
  663.          {
  664.             switch(SHORT2FROMMP(mp1))
  665.             {
  666.                case CN_INITDRAG:
  667.                   InitButtonDrag(hwnd, (PCNRDRAGINIT) mp2);
  668.                   break;
  669.  
  670.                case CN_DROP:
  671.                   DropButton(hwnd, (PCNRDRAGINFO) mp2, pTBCData);
  672.                   break;
  673.  
  674.                case CN_DRAGAFTER:
  675.                   return DragAfter(hwnd, (PCNRDRAGINFO) mp2);
  676.  
  677.                default:
  678.                   break;
  679.             }
  680.          }
  681.          if (SHORT1FROMMP(mp1) == IDD_TOOLBARCONFIG+2)
  682.          {
  683.             switch(SHORT2FROMMP(mp1))
  684.             {
  685.                case CN_INITDRAG:
  686.                   InitButtonDrag(hwnd, (PCNRDRAGINIT) mp2);
  687.                   break;
  688.  
  689.                default:
  690.                   break;
  691.             }
  692.          }
  693.          break;
  694.  
  695.       case WM_ACTIVATE:
  696.          if (mp1)
  697.             WinAssociateHelpInstance(hwndhelp, hwnd);
  698.          else
  699.             WinAssociateHelpInstance(hwndhelp, NULLHANDLE);
  700.          break;
  701.  
  702.       case TBCM_REFRESHLISTS:
  703.          FillButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+1), pTBCData->pDisp);
  704.          FillButtonCnr(WinWindowFromID(hwnd, IDD_TOOLBARCONFIG+2), pTBCData->pAvail);
  705.          break;
  706.  
  707.       default:
  708.          break;
  709.    }
  710.    return WinDefDlgProc(hwnd, msg, mp1, mp2);
  711. }
  712.  
  713. /*-----------------------------------------------------------------------------
  714.  | Funktionsname:
  715.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  716.  | Beschreibung:
  717.  |
  718.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  719.  | Parameter:
  720.  |
  721.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  722.  | Rückgabewerte:
  723.  |
  724.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  725.  | Sonstiges:
  726.  |
  727.  +---------------------------------------------------------------------------*/
  728.  
  729. void LoadDefaultToolbar(PTOOLBARCONFIG pConfig)
  730. {
  731.    /* alte Konfiguration freigeben */
  732.    if (pConfig->pButtons)
  733.    {
  734.       free(pConfig->pButtons);
  735.       pConfig->pButtons = NULL;
  736.       pConfig->ulNumButtons = 0;
  737.    }
  738.  
  739.    /* Default-Konfiguration */
  740.    pConfig->pButtons = malloc(sizeof(DefaultConfig));
  741.    memcpy(pConfig->pButtons, DefaultConfig, sizeof(DefaultConfig));
  742.    pConfig->ulNumButtons = sizeof(DefaultConfig)/sizeof(DefaultConfig[0]);
  743.  
  744.    return;
  745. }
  746.  
  747. /*-----------------------------------------------------------------------------
  748.  | Funktionsname:
  749.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  750.  | Beschreibung:
  751.  |
  752.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  753.  | Parameter:
  754.  |
  755.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  756.  | Rückgabewerte:
  757.  |
  758.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  759.  | Sonstiges:
  760.  |
  761.  +---------------------------------------------------------------------------*/
  762.  
  763. static void InitButtonCnr(HWND hwndCnr, PCHAR pchTitleText)
  764. {
  765.    CNRINFO cnrinfo;
  766.    PFIELDINFO pField=NULL, pFirstField=NULL;
  767.    FIELDINFOINSERT InfoInsert;
  768.  
  769.    pFirstField = SendMsg(hwndCnr, CM_ALLOCDETAILFIELDINFO, MPFROMSHORT(2), NULL);
  770.    pField = pFirstField;
  771.  
  772.    if (pField)
  773.    {
  774.       pField->cb = sizeof(FIELDINFO);
  775.       pField->flData = CFA_BITMAPORICON | CFA_HORZSEPARATOR | CFA_SEPARATOR;
  776.       pField->flTitle = 0;
  777.       pField->offStruct = FIELDOFFSET(BUTTONRECORD, hbmButton);
  778.  
  779.       pField = pField->pNextFieldInfo;
  780.  
  781.       pField->cb = sizeof(FIELDINFO);
  782.       pField->flData = CFA_STRING | CFA_HORZSEPARATOR;
  783.       pField->flTitle = 0;
  784.       pField->offStruct = FIELDOFFSET(BUTTONRECORD, pchButtonText);
  785.  
  786.       InfoInsert.cb = sizeof(InfoInsert);
  787.       InfoInsert.cFieldInfoInsert = 2;
  788.       InfoInsert.pFieldInfoOrder = (PFIELDINFO) CMA_FIRST;
  789.       InfoInsert.fInvalidateFieldInfo = TRUE;
  790.  
  791.       SendMsg(hwndCnr, CM_INSERTDETAILFIELDINFO, pFirstField, &InfoInsert);
  792.    }
  793.  
  794.    cnrinfo.cb = sizeof(cnrinfo);
  795.    cnrinfo.flWindowAttr = CV_DETAIL | CA_DRAWBITMAP | CA_ORDEREDTARGETEMPH |
  796.                           CA_CONTAINERTITLE | CA_TITLEREADONLY | CA_TITLESEPARATOR;
  797.    cnrinfo.pszCnrTitle = pchTitleText;
  798.    cnrinfo.slBitmapOrIcon.cx = 15;
  799.    cnrinfo.slBitmapOrIcon.cy = 15;
  800.  
  801.    SendMsg(hwndCnr, CM_SETCNRINFO, &cnrinfo,
  802.            MPFROMLONG(CMA_FLWINDOWATTR | CMA_CNRTITLE | CMA_SLBITMAPORICON));
  803.  
  804.    return;
  805. }
  806.  
  807. /*-----------------------------------------------------------------------------
  808.  | Funktionsname:
  809.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  810.  | Beschreibung:
  811.  |
  812.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  813.  | Parameter:
  814.  |
  815.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  816.  | Rückgabewerte:
  817.  |
  818.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  819.  | Sonstiges:
  820.  |
  821.  +---------------------------------------------------------------------------*/
  822.  
  823. static void FillButtonCnr(HWND hwndCnr, PBUTTONSELECT pButtonSelect)
  824. {
  825.    ULONG ulNum=0;
  826.    PBUTTONSELECT pTemp=pButtonSelect;
  827.    PBUTTONRECORD pFirstRecord=NULL, pRecord=NULL;
  828.    RECORDINSERT RecordInsert;
  829.  
  830.    SendMsg(hwndCnr, CM_REMOVERECORD, NULL, MPFROM2SHORT(0, CMA_FREE));
  831.  
  832.    /* zaehlen */
  833.    while (pTemp)
  834.    {
  835.       ulNum++;
  836.       pTemp = pTemp->next;
  837.    }
  838.  
  839.    /* Records anfordern */
  840.    pFirstRecord = SendMsg(hwndCnr, CM_ALLOCRECORD,
  841.                           MPFROMLONG(sizeof(BUTTONRECORD)-sizeof(MINIRECORDCORE)),
  842.                           MPFROMSHORT(ulNum));
  843.    pRecord = pFirstRecord;
  844.  
  845.    pTemp = pButtonSelect;
  846.    while (pTemp && pRecord)
  847.    {
  848.       pRecord->pButton = pTemp;
  849.       pRecord->pchButtonText = pTemp->pchButtonText;
  850.       pRecord->hbmButton = pTemp->hBitmap;
  851.  
  852.       pTemp = pTemp->next;
  853.       pRecord = (PBUTTONRECORD) pRecord->RecordCore.preccNextRecord;
  854.    }
  855.  
  856.    if (ulNum)
  857.    {
  858.       RecordInsert.cb = sizeof(RecordInsert);
  859.       RecordInsert.pRecordOrder = (PRECORDCORE) CMA_FIRST;
  860.       RecordInsert.pRecordParent = NULL;
  861.       RecordInsert.fInvalidateRecord = TRUE;
  862.       RecordInsert.zOrder = CMA_TOP;
  863.       RecordInsert.cRecordsInsert = ulNum;
  864.  
  865.       SendMsg(hwndCnr, CM_INSERTRECORD, pFirstRecord, &RecordInsert);
  866.    }
  867.    else
  868.       SendMsg(hwndCnr, CM_INVALIDATERECORD, NULL, NULL);
  869.  
  870.    return;
  871. }
  872.  
  873. /*-----------------------------------------------------------------------------
  874.  | Funktionsname:
  875.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  876.  | Beschreibung:
  877.  |
  878.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  879.  | Parameter:
  880.  |
  881.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  882.  | Rückgabewerte:
  883.  |
  884.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  885.  | Sonstiges:
  886.  |
  887.  +---------------------------------------------------------------------------*/
  888.  
  889. static PBUTTONSELECT BuildAvailList(PBUTTONSELECT pSelected)
  890. {
  891.    int i;
  892.    PBUTTONSELECT pFirst=NULL, pCurrent=NULL;
  893.  
  894.    for (i=0; i<SIZEOFBUTTONLIST; i++)
  895.    {
  896.       if (!ButtonInSelection(pSelected, ButtonList[i].ulButtonID))
  897.          pCurrent = AddButtonToSelect(&pFirst, pCurrent, ButtonList[i].ulButtonID);
  898.    }
  899.  
  900.    /* Separator hinzufuegen */
  901.    pCurrent = AddButtonToSelect(&pFirst, pCurrent, 0);
  902.  
  903.    return pFirst;
  904. }
  905.  
  906. /*-----------------------------------------------------------------------------
  907.  | Funktionsname:
  908.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  909.  | Beschreibung:
  910.  |
  911.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  912.  | Parameter:
  913.  |
  914.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  915.  | Rückgabewerte:
  916.  |
  917.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  918.  | Sonstiges:
  919.  |
  920.  +---------------------------------------------------------------------------*/
  921.  
  922. static void FreeButtonList(PBUTTONSELECT pList)
  923. {
  924.    PBUTTONSELECT pTemp;
  925.  
  926.    while (pList)
  927.    {
  928.       pTemp = pList->next;
  929.  
  930.       free(pList);
  931.       pList = pTemp;
  932.    }
  933. }
  934.  
  935. /*-----------------------------------------------------------------------------
  936.  | Funktionsname:
  937.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  938.  | Beschreibung:
  939.  |
  940.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  941.  | Parameter:
  942.  |
  943.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  944.  | Rückgabewerte:
  945.  |
  946.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  947.  | Sonstiges:
  948.  |
  949.  +---------------------------------------------------------------------------*/
  950.  
  951. static void AddToDisp(HWND hwndDlg, PTBCDATA pTBCData)
  952. {
  953.    PBUTTONRECORD pButtonRecord;
  954.    PBUTTONSELECT pNewButton;
  955.  
  956.    pButtonRecord = WinSendDlgItemMsg(hwndDlg, IDD_TOOLBARCONFIG+2, CM_QUERYRECORDEMPHASIS,
  957.                                      MPFROMLONG(CMA_FIRST),
  958.                                      MPFROMSHORT(CRA_CURSORED));
  959.    if (pButtonRecord && pButtonRecord->pButton)
  960.    {
  961.       if (pTBCData->pDisp)
  962.       {
  963.          /* Am Ende anfuegen */
  964.          pNewButton = pTBCData->pDisp;
  965.          while (pNewButton->next)
  966.             pNewButton = pNewButton->next;
  967.          pNewButton->next = calloc(1, sizeof(BUTTONSELECT));
  968.          pNewButton->next->prev = pNewButton;
  969.          pNewButton = pNewButton->next;
  970.       }
  971.       else
  972.          pTBCData->pDisp = pNewButton = calloc(1, sizeof(BUTTONSELECT));
  973.  
  974.       /* Daten kopieren */
  975.       pNewButton->ulButtonID = pButtonRecord->pButton->ulButtonID;
  976.       memcpy(pNewButton->pchButtonText, pButtonRecord->pButton->pchButtonText, LEN_BUTTONTEXT);
  977.       pNewButton->hBitmap = pButtonRecord->pButton->hBitmap;
  978.  
  979.       if (pButtonRecord->pButton->ulButtonID)
  980.       {
  981.          /* in Quell-Liste loeschen */
  982.          if (pButtonRecord->pButton->next)
  983.             pButtonRecord->pButton->next->prev = pButtonRecord->pButton->prev;
  984.          if (pButtonRecord->pButton->prev)
  985.             pButtonRecord->pButton->prev->next = pButtonRecord->pButton->next;
  986.          if (pButtonRecord->pButton == pTBCData->pAvail)
  987.             pTBCData->pAvail = pButtonRecord->pButton->next;
  988.          free(pButtonRecord->pButton);
  989.       }
  990.  
  991.       /* neu anzeigen */
  992.       FillButtonCnr(WinWindowFromID(hwndDlg, IDD_TOOLBARCONFIG+1), pTBCData->pDisp);
  993.       FillButtonCnr(WinWindowFromID(hwndDlg, IDD_TOOLBARCONFIG+2), pTBCData->pAvail);
  994.    }
  995.  
  996.    return;
  997. }
  998.  
  999. /*-----------------------------------------------------------------------------
  1000.  | Funktionsname:
  1001.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1002.  | Beschreibung:
  1003.  |
  1004.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1005.  | Parameter:
  1006.  |
  1007.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1008.  | Rückgabewerte:
  1009.  |
  1010.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1011.  | Sonstiges:
  1012.  |
  1013.  +---------------------------------------------------------------------------*/
  1014.  
  1015. static void RemoveFromDisp(HWND hwndDlg, PTBCDATA pTBCData)
  1016. {
  1017.    PBUTTONRECORD pButtonRecord;
  1018.    PBUTTONSELECT pNewButton;
  1019.  
  1020.    pButtonRecord = WinSendDlgItemMsg(hwndDlg, IDD_TOOLBARCONFIG+1, CM_QUERYRECORDEMPHASIS,
  1021.                                      MPFROMLONG(CMA_FIRST),
  1022.                                      MPFROMSHORT(CRA_CURSORED));
  1023.    if (pButtonRecord && pButtonRecord->pButton)
  1024.    {
  1025.       if (pButtonRecord->pButton->ulButtonID)
  1026.       {
  1027.          if (pTBCData->pAvail)
  1028.          {
  1029.             /* Am Ende anfuegen */
  1030.             pNewButton = pTBCData->pAvail;
  1031.             while (pNewButton->next)
  1032.                pNewButton = pNewButton->next;
  1033.             pNewButton->next = calloc(1, sizeof(BUTTONSELECT));
  1034.             pNewButton->next->prev = pNewButton;
  1035.             pNewButton = pNewButton->next;
  1036.          }
  1037.          else
  1038.             pTBCData->pAvail = pNewButton = calloc(1, sizeof(BUTTONSELECT));
  1039.  
  1040.          /* Daten kopieren */
  1041.          pNewButton->ulButtonID = pButtonRecord->pButton->ulButtonID;
  1042.          memcpy(pNewButton->pchButtonText, pButtonRecord->pButton->pchButtonText, LEN_BUTTONTEXT);
  1043.          pNewButton->hBitmap = pButtonRecord->pButton->hBitmap;
  1044.       }
  1045.  
  1046.       /* in Quell-Liste loeschen */
  1047.       if (pButtonRecord->pButton->next)
  1048.          pButtonRecord->pButton->next->prev = pButtonRecord->pButton->prev;
  1049.       if (pButtonRecord->pButton->prev)
  1050.          pButtonRecord->pButton->prev->next = pButtonRecord->pButton->next;
  1051.       if (pButtonRecord->pButton == pTBCData->pDisp)
  1052.          pTBCData->pDisp = pButtonRecord->pButton->next;
  1053.       free(pButtonRecord->pButton);
  1054.  
  1055.       /* neu anzeigen */
  1056.       FillButtonCnr(WinWindowFromID(hwndDlg, IDD_TOOLBARCONFIG+1), pTBCData->pDisp);
  1057.       FillButtonCnr(WinWindowFromID(hwndDlg, IDD_TOOLBARCONFIG+2), pTBCData->pAvail);
  1058.    }
  1059.  
  1060.    return;
  1061. }
  1062.  
  1063. /*-----------------------------------------------------------------------------
  1064.  | Funktionsname:
  1065.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1066.  | Beschreibung:
  1067.  |
  1068.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1069.  | Parameter:
  1070.  |
  1071.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1072.  | Rückgabewerte:
  1073.  |
  1074.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1075.  | Sonstiges:
  1076.  |
  1077.  +---------------------------------------------------------------------------*/
  1078.  
  1079. static void InitButtonDrag(HWND hwndDlg, PCNRDRAGINIT pDragInit)
  1080. {
  1081.    PBUTTONRECORD pDragButton;
  1082.    PDRAGINFO pDraginfo;
  1083.    DRAGITEM DragItem;
  1084.    DRAGIMAGE DragImage;
  1085.  
  1086.    if (!pDragInit || !pDragInit->pRecord)
  1087.       return; /* nur echte Records */
  1088.  
  1089.    pDragButton = (PBUTTONRECORD) pDragInit->pRecord;
  1090.  
  1091.    pDraginfo = DrgAllocDraginfo(1); /* ein Item */
  1092.  
  1093.    /* Item vorbereiten */
  1094.    memset(&DragItem, 0, sizeof(DragItem));
  1095.    DragItem.hwndItem = pDragInit->hwndCnr;
  1096.    DragItem.ulItemID = (ULONG) pDragButton->pButton;
  1097.    DragItem.hstrType = DrgAddStrHandle(BUTTONTYPE);
  1098.    DragItem.hstrRMF  = DrgAddStrHandle(BUTTONRMF);
  1099.    DragItem.fsSupportedOps = DO_MOVEABLE;
  1100.  
  1101.    DrgSetDragitem(pDraginfo, &DragItem, sizeof(DragItem), 0);
  1102.  
  1103.    /* Image vorbereiten */
  1104.    memset(&DragImage, 0, sizeof(DragImage));
  1105.  
  1106.    DragImage.cb = sizeof(DragImage);
  1107.    DragImage.hImage = pDragButton->hbmButton;
  1108.    DragImage.fl = DRG_BITMAP;
  1109.  
  1110.    /* Drag */
  1111.    SendMsg(pDragInit->hwndCnr, CM_SETRECORDEMPHASIS, pDragButton, MPFROM2SHORT(TRUE, CRA_SOURCE));
  1112.    if (!DrgDrag(hwndDlg, pDraginfo, &DragImage, 1, VK_ENDDRAG, NULL))
  1113.       WinPostMsg(hwndDlg, TBCM_REFRESHLISTS, NULL, NULL);
  1114.  
  1115.    DrgFreeDraginfo(pDraginfo);
  1116.  
  1117.    return;
  1118. }
  1119.  
  1120. /*-----------------------------------------------------------------------------
  1121.  | Funktionsname:
  1122.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1123.  | Beschreibung:
  1124.  |
  1125.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1126.  | Parameter:
  1127.  |
  1128.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1129.  | Rückgabewerte:
  1130.  |
  1131.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1132.  | Sonstiges:
  1133.  |
  1134.  +---------------------------------------------------------------------------*/
  1135.  
  1136. static MRESULT DragAfter(HWND hwndDlg, PCNRDRAGINFO pCnrDrag)
  1137. {
  1138.    USHORT usDefOp = DO_MOVE;
  1139.    USHORT usDrop = DOR_NODROP;
  1140.    PBUTTONRECORD pAfterRecord;
  1141.    PDRAGITEM pDragItem;
  1142.  
  1143.    pAfterRecord = (PBUTTONRECORD) pCnrDrag->pRecord;
  1144.  
  1145.    DrgAccessDraginfo(pCnrDrag->pDragInfo);
  1146.  
  1147.    pDragItem = DrgQueryDragitemPtr(pCnrDrag->pDragInfo, 0);
  1148.  
  1149.    if (DrgVerifyType(pDragItem, BUTTONTYPE))
  1150.       if (DrgVerifyRMF(pDragItem, BUTTONMECH, BUTTONFORMAT))
  1151.          if (hwndDlg == pCnrDrag->pDragInfo->hwndSource)
  1152.             if (pDragItem->hwndItem != WinWindowFromID(hwndDlg, IDD_TOOLBARCONFIG+1) ||
  1153.                 pAfterRecord)
  1154.                if (pCnrDrag->pDragInfo->usOperation == DO_MOVE ||
  1155.                    pCnrDrag->pDragInfo->usOperation == DO_DEFAULT)
  1156.                   usDrop = DOR_DROP;
  1157.                else
  1158.                   usDrop = DOR_NODROPOP;
  1159.  
  1160.    DrgFreeDraginfo(pCnrDrag->pDragInfo);
  1161.  
  1162.    return MRFROM2SHORT(usDrop, usDefOp);
  1163. }
  1164.  
  1165. /*-----------------------------------------------------------------------------
  1166.  | Funktionsname:
  1167.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1168.  | Beschreibung:
  1169.  |
  1170.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1171.  | Parameter:
  1172.  |
  1173.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1174.  | Rückgabewerte:
  1175.  |
  1176.  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1177.  | Sonstiges:
  1178.  |
  1179.  +---------------------------------------------------------------------------*/
  1180.  
  1181. static void DropButton(HWND hwndDlg, PCNRDRAGINFO pCnrDrag, PTBCDATA pTBCData)
  1182. {
  1183.    PBUTTONRECORD pDropRecord;
  1184.    PDRAGITEM pDragItem;
  1185.    PBUTTONSELECT pSrcButton, pTargetButton=NULL, pNewButton;
  1186.  
  1187.    pDropRecord = (PBUTTONRECORD) pCnrDrag->pRecord;
  1188.  
  1189.    DrgAccessDraginfo(pCnrDrag->pDragInfo);
  1190.  
  1191.    pDragItem = DrgQueryDragitemPtr(pCnrDrag->pDragInfo, 0);
  1192.    pSrcButton = (PBUTTONSELECT) pDragItem->ulItemID;
  1193.    if (pDropRecord && pDropRecord != (PBUTTONRECORD) CMA_FIRST)
  1194.       pTargetButton = pDropRecord->pButton;
  1195.  
  1196.    if (pDragItem->hwndItem == WinWindowFromID(hwndDlg, IDD_TOOLBARCONFIG+1))
  1197.    {
  1198.       /* Drag innerhalb d. linken Containers */
  1199.       if (pSrcButton != pTargetButton &&
  1200.           pSrcButton->prev != pTargetButton)
  1201.       {
  1202.          /* Position hat sich geaendert */
  1203.          /* Src aushaengen */
  1204.          if (pSrcButton->next)
  1205.             pSrcButton->next->prev = pSrcButton->prev;
  1206.          if (pSrcButton->prev)
  1207.             pSrcButton->prev->next = pSrcButton->next;
  1208.          if (pTBCData->pDisp == pSrcButton)
  1209.             pTBCData->pDisp = pSrcButton->next;
  1210.  
  1211.          /* hinter Target einhaengen */
  1212.          pSrcButton->next = pTargetButton->next;
  1213.          pSrcButton->prev = pTargetButton;
  1214.          if (pTargetButton->next)
  1215.             pTargetButton->next->prev = pSrcButton;
  1216.          pTargetButton->next = pSrcButton;
  1217.  
  1218.          WinPostMsg(hwndDlg, TBCM_REFRESHLISTS, NULL, NULL);
  1219.       }
  1220.    }
  1221.    else
  1222.    {
  1223.       /* Drag v. rechts nach links */
  1224.       if (!pTargetButton)
  1225.       {
  1226.          if (pDropRecord == (PBUTTONRECORD) CMA_FIRST)
  1227.          {
  1228.             /* am Anfang einhaengen */
  1229.             pNewButton = calloc(1, sizeof(BUTTONSELECT));
  1230.             pNewButton->next = pTBCData->pDisp;
  1231.             if (pNewButton->next)
  1232.                pNewButton->next->prev = pNewButton;
  1233.             pTBCData->pDisp = pNewButton;
  1234.          }
  1235.          else
  1236.             /* Am Ende einhaengen */
  1237.             if (pTBCData->pDisp)
  1238.             {
  1239.                pNewButton = pTBCData->pDisp;
  1240.                while (pNewButton->next)
  1241.                   pNewButton = pNewButton->next;
  1242.                pNewButton->next = calloc(1, sizeof(BUTTONSELECT));
  1243.                pNewButton->next->prev = pNewButton;
  1244.                pNewButton = pNewButton->next;
  1245.             }
  1246.             else
  1247.                pNewButton = pTBCData->pDisp = calloc(1, sizeof(BUTTONSELECT));
  1248.       }
  1249.       else
  1250.       {
  1251.          /* Bei best. Stelle einfuegen */
  1252.          pNewButton = calloc(1, sizeof(BUTTONSELECT));
  1253.          pNewButton->prev = pTargetButton;
  1254.          pNewButton->next = pTargetButton->next;
  1255.          if (pTargetButton->next)
  1256.             pTargetButton->next->prev = pNewButton;
  1257.          pTargetButton->next = pNewButton;
  1258.       }
  1259.  
  1260.       /* Daten kopieren */
  1261.       pNewButton->ulButtonID = pSrcButton->ulButtonID;
  1262.       pNewButton->hBitmap = pSrcButton->hBitmap;
  1263.       memcpy(pNewButton->pchButtonText, pSrcButton->pchButtonText, LEN_BUTTONTEXT);
  1264.  
  1265.       if (pSrcButton->ulButtonID)
  1266.       {
  1267.          /* Non-Spacer in Src. loeschen */
  1268.          if (pSrcButton->next)
  1269.             pSrcButton->next->prev = pSrcButton->prev;
  1270.          if (pSrcButton->prev)
  1271.             pSrcButton->prev->next = pSrcButton->next;
  1272.          if (pTBCData->pAvail == pSrcButton)
  1273.             pTBCData->pAvail = pSrcButton->next;
  1274.          free(pSrcButton);
  1275.       }
  1276.       WinPostMsg(hwndDlg, TBCM_REFRESHLISTS, NULL, NULL);
  1277.    }
  1278.  
  1279.    DrgDeleteDraginfoStrHandles(pCnrDrag->pDragInfo);
  1280.    DrgFreeDraginfo(pCnrDrag->pDragInfo);
  1281.  
  1282.    return;
  1283. }
  1284.  
  1285. void RefreshToolbar(HWND hwndToolbar, PTOOLBARCONFIG pConfig, BOOL bSmallIcons)
  1286. {
  1287.    int i;
  1288.    TOOLBARITEM Item;
  1289.    PBUTTONLIST pButtonDef;
  1290.  
  1291.    SendMsg(hwndToolbar, TBM_DELETEALLITEMS, NULL, NULL);
  1292.    for (i=0; i<pConfig->ulNumButtons; i++)
  1293.    {
  1294.       if (pButtonDef = FindButton(pConfig->pButtons[i].ulButtonID))
  1295.       {
  1296.          Item.ulCommandID = pConfig->pButtons[i].ulButtonID;
  1297.          Item.ulParamSize=0;
  1298.          Item.pItemParams = NULL;
  1299.          Item.ulFlags = pConfig->pButtons[i].ulFlags;
  1300.          if (bSmallIcons)
  1301.             Item.ulBitmapID = pButtonDef->ulSmallBitmapID;
  1302.          else
  1303.             Item.ulBitmapID = pButtonDef->ulBitmapID;
  1304.  
  1305.          SendMsg(hwndToolbar, TBM_ADDITEM, &Item, MPFROMLONG(ADDITEM_LAST));
  1306.       }
  1307.    }
  1308.  
  1309.    return;
  1310. }
  1311.  
  1312. ULONG QueryBitmap(ULONG ulButtonID, BOOL bSmall)
  1313. {
  1314.    PBUTTONLIST pButtonDef;
  1315.  
  1316.    pButtonDef = FindButton(ulButtonID);
  1317.  
  1318.    if (pButtonDef)
  1319.    {
  1320.       if (bSmall)
  1321.          return pButtonDef->ulSmallBitmapID;
  1322.       else
  1323.          return pButtonDef->ulBitmapID;
  1324.    }
  1325.    else
  1326.       return 0;
  1327.  
  1328. }
  1329. /*-------------------------------- Modulende --------------------------------*/
  1330.  
  1331.