"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/WinGroup.h" (8 May 2021, 4157 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "WinGroup.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2 AutoHotkey
    3 
    4 Copyright 2003-2009 Chris Mallett (support@autohotkey.com)
    5 
    6 This program is free software; you can redistribute it and/or
    7 modify it under the terms of the GNU General Public License
    8 as published by the Free Software Foundation; either version 2
    9 of the License, or (at your option) any later version.
   10 
   11 This program is distributed in the hope that it will be useful,
   12 but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 GNU General Public License for more details.
   15 */
   16 
   17 #ifndef wingroup_h
   18 #define wingroup_h
   19 
   20 #include "defines.h"
   21 #include "SimpleHeap.h" // for WinGroup's overloaded new/delete operators.
   22 
   23 
   24 // NOTE: This module is separate from the others because:
   25 // 1) If it were in script.h/cpp it would add clutter to that already large file.
   26 // 2) If it were in window.h/cpp it causes mutual-dependency problems between header
   27 //    (probably correctible, but it's fine this way).
   28 
   29 
   30 class Label;
   31 class WindowSpec
   32 {
   33 public:
   34     LPTSTR mTitle, mText, mExcludeTitle, mExcludeText;
   35     WindowSpec *mNextWindow;  // Next item in linked list.
   36     WindowSpec(LPTSTR aTitle = _T(""), LPTSTR aText = _T("")
   37         , LPTSTR aExcludeTitle = _T(""), LPTSTR aExcludeText = _T(""))
   38         // Caller should have allocated some dynamic memory for the given args if they're not
   39         // the empty string.  We just set our member variables to be equal to the given pointers.
   40         : mTitle(aTitle), mText(aText), mExcludeTitle(aExcludeTitle), mExcludeText(aExcludeText)
   41         , mNextWindow(NULL) // mNextWindow(NULL) is also required for thread-safety.
   42     {}
   43     void *operator new(size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
   44     void *operator new[](size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
   45     void operator delete(void *aPtr) {}
   46     void operator delete[](void *aPtr) {}
   47 };
   48 
   49 
   50 
   51 class WinGroup
   52 {
   53 private:
   54     // The maximum number of windows to keep track of:
   55     #define MAX_ALREADY_VISITED 500
   56     static WinGroup *sGroupLastUsed;
   57     static HWND *sAlreadyVisited;  // Array.  It will be dynamically allocated on first use.
   58     static int sAlreadyVisitedCount;
   59     bool mIsModeActivate;
   60 
   61     static void MarkAsVisited(HWND aWnd)
   62     {
   63         // For peace of mind, do dupe-check to rule out, once and for all,
   64         // the possibility of any unusual conditions where the list might get
   65         // quickly filled up with dupes:
   66         for (int i = 0; i < sAlreadyVisitedCount; ++i)
   67             if (sAlreadyVisited[i] == aWnd) // It's already in the list.
   68                 return;
   69         if (sAlreadyVisitedCount >= MAX_ALREADY_VISITED)
   70             // Can't store any more. Don't bother displaying an error (too unlikely).
   71             return;
   72         sAlreadyVisited[sAlreadyVisitedCount++] = aWnd;
   73     }
   74 
   75     ResultType Update(bool aIsModeActivate);
   76 
   77 public:
   78     LPTSTR mName;    // The name of the group.
   79     WindowSpec *mFirstWindow, *mLastWindow;
   80     Label *mJumpToLabel;
   81     WinGroup *mNextGroup;  // Next item in linked list.
   82     UINT mWindowCount;
   83 
   84     ResultType AddWindow(LPTSTR aTitle, LPTSTR aText, LPTSTR aExcludeTitle, LPTSTR aExcludeText);
   85     ResultType ActUponAll(ActionTypeType aActionType, int aTimeToWaitForClose);
   86     ResultType CloseAndGoToNext(bool aStartWithMostRecent);
   87     ResultType Activate(bool aStartWithMostRecent, WindowSpec *aWinSpec = NULL, Label **aJumpToLabel = NULL);
   88     ResultType Deactivate(bool aStartWithMostRecent);
   89     bool IsEmpty() {return mFirstWindow == NULL;}
   90     WindowSpec *IsMember(HWND aWnd, global_struct &aSettings);
   91     WinGroup(LPTSTR aGroupName)
   92         // The caller must ensure that aGroupName is non-null and non-empty-string.
   93         : mName(aGroupName) // Caller gave us a pointer to dynamic memory for this.
   94         , mFirstWindow(NULL), mLastWindow(NULL)
   95         , mWindowCount(0)
   96         , mNextGroup(NULL) // v1.0.41: Required for thread-safety, but also for maintainability.
   97         , mIsModeActivate(true) // arbitrary default.
   98         , mJumpToLabel(NULL)
   99     {}
  100     void *operator new(size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
  101     void *operator new[](size_t aBytes) {return SimpleHeap::Malloc(aBytes);}
  102     void operator delete(void *aPtr) {}
  103     void operator delete[](void *aPtr) {}
  104 };
  105 
  106 
  107 BOOL CALLBACK EnumParentFindAnyExcept(HWND aWnd, LPARAM lParam);
  108 BOOL CALLBACK EnumParentActUponAll(HWND aWnd, LPARAM lParam);
  109 
  110 #endif