gcsx_frame.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /* GCSx
  2. ** FRAME.H
  3. **
  4. ** Frame windows
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #ifndef __GCSx_FRAME_H_
  24. #define __GCSx_FRAME_H_
  25. class FrameWindow : public Window {
  26. public:
  27. enum FrameType {
  28. // Frame types
  29. FRAMETYPE_BEVEL_TEXT, // Bevel with textbox color bk
  30. FRAMETYPE_BEVEL_BK, // Bevel with background color
  31. FRAMETYPE_DIALOG,
  32. FRAMETYPE_NOCHANGE,
  33. };
  34. enum TitlebarType {
  35. // Titlebar types
  36. TITLEBAR_OFF,
  37. TITLEBAR_NORMAL,
  38. TITLEBAR_TOOL,
  39. TITLEBAR_NOCHANGE,
  40. };
  41. enum ResizableType {
  42. // Resizing behaviors
  43. RESIZING_OFF = 0,
  44. RESIZING_NORMAL,
  45. RESIZING_SNAP, // Mostly for panels/toolbars- can't resize to a size the child window won't accept
  46. RESIZING_NOCHANGE,
  47. };
  48. enum {
  49. CLIENT_PRIMARY = 0,
  50. // These are all purposefully chosen sequences/values
  51. CLIENT_RIGHT = 0, // (default position)
  52. CLIENT_LEFT = 1,
  53. CLIENT_TOPBOTTOM = 2, // &this means top or bottom
  54. CLIENT_TOP = 2,
  55. CLIENT_BOTTOM = 3,
  56. CLIENT_GETSIDE = 3, // &this to get which side we're on
  57. // Free-floating
  58. CLIENT_FLOAT = 4,
  59. // OR with previous- Docked onto the desktop instead of window
  60. CLIENT_DOCKED = 8,
  61. // OR with previous- HIDDEN due to resizing of window
  62. CLIENT_HIDDEN = 16,
  63. // OR with previous- CLOSED means manually closed (toggle)
  64. CLIENT_CLOSED = 32,
  65. // &this means it's not visible or not docked onto our window
  66. CLIENT_NOTMANAGED = 60,
  67. };
  68. protected:
  69. enum DragType {
  70. // Drag types
  71. FRAME_DRAG_NONE,
  72. FRAME_DRAG_TITLE,
  73. FRAME_DRAG_BUTTONS,
  74. FRAME_DRAG_BORDER,
  75. // Includes tool panels, etc.- index in subtype
  76. FRAME_DRAG_CLIENT,
  77. FRAME_DRAG_SCROLLBAR_HORIZ,
  78. FRAME_DRAG_SCROLLBAR_VERT,
  79. };
  80. enum DragSubType {
  81. // Drag subtypes, can be OR'd (integers 1+ also used for titlebar buttons)
  82. FRAME_RESIZE_NONE = 0,
  83. FRAME_RESIZE_BOTTOM = 1,
  84. FRAME_RESIZE_TOP = 2,
  85. FRAME_RESIZE_LEFT = 4,
  86. FRAME_RESIZE_RIGHT = 8,
  87. // Drag subtypes for scrollbar
  88. FRAME_SCROLL_NONE = 0,
  89. FRAME_SCROLL_LESS, // Left/Up
  90. FRAME_SCROLL_PAGELESS, // Page Left/Up
  91. FRAME_SCROLL_MORE, // Right/Down
  92. FRAME_SCROLL_PAGEMORE, // Page Right/Down
  93. FRAME_SCROLL_TAB,
  94. };
  95. enum StateType {
  96. // State types
  97. FRAME_STATE_NORMAL = 0,
  98. FRAME_STATE_MINIMIZED = 1,
  99. FRAME_STATE_MAXIMIZED = 2,
  100. };
  101. enum {
  102. // Dirty reasons, can be OR'd
  103. FRAME_DIRTY_NONE = 0,
  104. FRAME_DIRTY_TITLE = 1, // Includes buttons
  105. FRAME_DIRTY_SCROLLVERT = 2,
  106. FRAME_DIRTY_SCROLLHORIZ = 4,
  107. FRAME_DIRTY_ALL = 255, // If resized or tool size or area/scroll existence changes
  108. };
  109. ResizableType resizable;
  110. int deleteMe;
  111. FrameType frameType;
  112. int outerBorder;
  113. class FrameWindow* framePanel; // Are we a panel on another frame window? (in parentnotify) resizing/moving handled differently
  114. TitlebarType titlebarType;
  115. std::string titlebar;
  116. StateType state;
  117. int whyDirty;
  118. // Used for cascading windows
  119. static int cascadeStep;
  120. int titlebarX;
  121. int titlebarY;
  122. int titlebarWidth;
  123. int titlebarHeight;
  124. int titlebarButtonX;
  125. int titlebarButtonY;
  126. int titlebarButtonSize;
  127. int titlebarButtonXPad;
  128. int titlebarButtonTotalWidth;
  129. char titlebarButtons[5];
  130. int scrollbarButtonSize;
  131. int scrollbarButtonXPad;
  132. // (width and position of our client areas- not necessarily width/position
  133. // of client window internally, which can be larger/smaller and scroll)
  134. // X/Y of -1 means not calculated yet; Width/Height of -1 means not
  135. // calculated and first time will use requested size by client area; after
  136. // that, the previous width/height will be used for all recalculations
  137. // Shown is the actual width/height of the area; other value is what we'd
  138. // like/request if possible; for main client area, "shown" is same as reg.
  139. // 0 = client 1+ = tool panels/toolbars (optional)
  140. struct ClientArea {
  141. Window* window;
  142. int x;
  143. int y;
  144. int width;
  145. int height;
  146. int widthShown;
  147. int heightShown;
  148. int position;
  149. };
  150. std::vector<ClientArea> clientArea;
  151. // Inner sizing of main client area (not including scrollbars, basically)
  152. int clientWidthInner;
  153. int clientHeightInner;
  154. // Amount of space reserved on each side for non-primary client areas
  155. int reserve[4];
  156. // Smallest size for a non-primary client area (height for left/right, width for top/bottom)
  157. static int minimumPanelSize;
  158. // Width and height of main client area
  159. // Reupdated whenever we resize()
  160. int clientActualWidth;
  161. int clientActualHeight;
  162. // Destination position for a floating panel being dragged (show highlighted)
  163. int floatTarget;
  164. int floatTargetX;
  165. int floatTargetY;
  166. int floatTargetWidth;
  167. int floatTargetHeight;
  168. // Scroll offset (usually zero or negative; positive offsets used to center in view area)
  169. int scrollX;
  170. int scrollY;
  171. int autoCenterScroll;
  172. // Scroll sizes- how much to scroll
  173. int vScrollLine;
  174. int vScrollPage;
  175. int hScrollLine;
  176. int hScrollPage;
  177. // Position to draw scrollbars; set to 0 if no scrollbars
  178. // Size of actual drawn scrollbars
  179. int vScrollbarX;
  180. int vScrollbarY;
  181. int vScrollbarWidth;
  182. int vScrollbarHeight;
  183. int vScrollbarTab; // Offset within scroll area
  184. int vScrollbarTabSize; // 0 = tab not shown
  185. int hScrollbarX;
  186. int hScrollbarY;
  187. int hScrollbarWidth;
  188. int hScrollbarHeight;
  189. int hScrollbarTab; // Offset within scroll area
  190. int hScrollbarTabSize; // 0 = tab not shown
  191. // Used for autorepeating scrollbar actions
  192. Uint32 scrollRepeatTicks;
  193. Uint32 scrollRepeatDelay;
  194. int restoreX;
  195. int restoreY;
  196. int restoreWidth;
  197. int restoreHeight;
  198. int haveFocus;
  199. int subFocus; // 0 client 1+ tool areas
  200. // Internal- for dragging titlebar, borders, etc.
  201. // hoverMode used just for hovering
  202. DragType dragMode;
  203. DragType hoverMode;
  204. DragSubType dragItem;
  205. DragSubType hoverItem;
  206. int dragX;
  207. int dragY;
  208. int dragItemOverflowX;
  209. int dragItemOverflowY;
  210. // Change states
  211. void maximize();
  212. void minimize();
  213. int isMinimized();
  214. void restore();
  215. void nextWindow();
  216. void prevWindow();
  217. // Takes an x/y/width/height and confines them to desktop/screen
  218. void confineSize(int& sX, int& sY, int& sWidth, int& sHeight) const;
  219. // Scrolls to a given -X, -Y
  220. // Automatically clips scroll to best possible
  221. // Can specify x and/or y for scrollbar tabs to force if needed
  222. void scrollTo(int sX, int sY, int tabX = -1, int tabY = -1);
  223. // Which area is a given coords in? titlebar, buttons, border, etc.
  224. // Returns a drag constant, and if applicable, a drag item (resize constant or button number)
  225. void whereCoords(int x, int y, DragType* dragType, DragSubType* dragItem) const;
  226. // Handles movement of mouse hover- called on mouse motion and after mouse btn release
  227. void doMouseHover(int x, int y, int hasFocus, SDL_Event& clientEvent);
  228. // Recalculates reserve*, clientX, clientY, clientWidth, clientHeight
  229. // Does not recalculate client*Innder or redraw *anything*
  230. void reorganizeReserves();
  231. enum {
  232. // Sizing constants
  233. FRAME_OUTERBORDER = 3,
  234. FRAME_INNERBORDER = 2,
  235. FRAME_BEVELTHICKNESS = 2,
  236. FRAME_TITLELEFTPAD = 5,
  237. FRAME_TITLETOPPAD = 3,
  238. FRAME_TITLEBOTTOMPAD = 2,
  239. FRAME_TOOLTITLELEFTPAD = 3,
  240. FRAME_TOOLTITLETOPPAD = 2,
  241. FRAME_TOOLTITLEBOTTOMPAD = 1,
  242. // Gutter between various client/tool areas
  243. FRAME_CLIENTPAD = 1,
  244. // Minimum size for scrollbar tab
  245. FRAME_SCROLLTABMIN = 10,
  246. // Distance from edge to allow corner-based resizing
  247. RESIZE_CORNER_SENSITIVITY = 13,
  248. // MS to wait before repeating scrollbar action initially
  249. DELAY_SCROLLBAR_REPEATSTART = 500,
  250. // MS to wait between additional repeats of scrollbar action
  251. DELAY_SCROLLBAR_REPEATAGAIN = 75,
  252. // Minimum "default" size for a frame window
  253. DEFAULT_MIN_WIDTH = 150,
  254. DEFAULT_MIN_HEIGHT = 100,
  255. };
  256. static const char* wtButtonAll;
  257. static const char* wtButtonNoResize;
  258. static const std::string wtButtonClose;
  259. static const std::string wtButtonUp;
  260. static const std::string wtButtonDown;
  261. static const std::string wtButtonLeft;
  262. static const std::string wtButtonRight;
  263. public:
  264. // Width and height default to fitting to the client area
  265. // These can easily be changed when you run show() to display the window
  266. // Scrollbars are supplied as needed and client gets resizes to update view size
  267. // Client area pointer will be deleted by us if it wantsToBeDeleted().
  268. // We don't take ownership of pointer if constructor fails.
  269. FrameWindow(const std::string& title, ResizableType isResizable, FrameType type, Window* client, TitlebarType hasTitlebarType = TITLEBAR_NORMAL, int hasOuterBorder = 1, class FrameWindow* isFramePanel = NULL);
  270. ~FrameWindow();
  271. Window* getClient() { return clientArea[0].window; }
  272. // Removes all clients from us so we can be deleted without deleting
  273. // client windows; typically called from a failed constructor; doesn't modify
  274. // appearance, etc.
  275. void dropClients();
  276. // Adds a tool panel
  277. // Tool panels don't get attemptClose or undoNotify calls
  278. void addToolPanel(FrameWindow* toolPanel, int position, std::vector<ClientArea>::iterator* insertBefore = NULL);
  279. void removeToolPanel(Window* toolPanel);
  280. // Returns 0 if not an existing tool panel, otherwise returns an index
  281. int findToolPanel(Window* toolPanel);
  282. // index of 0 to focus on client area; only works if panel is docked
  283. void focusToolPanel(int index);
  284. // Toggles visible and not visible, for now; only works if panel is docked
  285. void toggleToolPanel(int index, int giveFocusIfOpen = 1);
  286. // Handles dragging of a docked panel
  287. void dragToolPanel(int index, int xMotion, int yMotion, int& dragItemOverflowX, int& dragItemOverflowY);//@TODO:throw
  288. // Handles dragging of a floating panel; 0 = dragging, 1 = dropped
  289. void dragFloatPanel(int index, int drop);//@TODO:throw
  290. #ifndef NDEBUG
  291. const char* debugDump() const;
  292. #endif
  293. // Call when desktop area resizes to ensure we're sized/moved properly
  294. void redoSize();
  295. // Client should call this whenever it resizes
  296. // This will update scrollbars
  297. // Default Window::resize() will call this if appropriate
  298. void updateClientSize();
  299. // Client can request a minimum given view size
  300. // This won't ever reduce window size
  301. void requestViewSize(int requestWidth, int requestHeight);
  302. // Client may call this to set scrolling amounts; if not called,
  303. // a default size is used (page amounts are automatically
  304. // determined as the full width/height minus one "line")
  305. void setScroll(int vLine, int hLine);
  306. // Automatically center inner frame, if smaller than available size
  307. void setAutoCenter(int newAutoCenter);
  308. // Scrolls to show as much of the given rectangle as possible
  309. // Automatically clips scroll to best possible
  310. void scrollToView(int sX, int sY, int sWidth, int sHeight);
  311. // Scrolls to offset from current scroll
  312. void scrollBy(int sX, int sY);
  313. void setTitle(const std::string& newTitle);
  314. // use _NOCHANGE constants or -1 to initiate no change for an item
  315. // cannot undo framepanel
  316. void setFeatures(ResizableType isResizable, FrameType type = FRAMETYPE_NOCHANGE, TitlebarType hasTitlebarType = TITLEBAR_NOCHANGE, int hasOuterBorder = -1, class FrameWindow* isFramePanel = NULL, int skipResizing = 0);
  317. void resize(int newWidth, int newHeight, int newViewWidth = -1, int newViewHeight = -1, int fromParent = 0);
  318. void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
  319. void resolutionChange(int fromW, int fromH, int fromBpp, int toW, int toH, int toBpp);
  320. void childMoved(int fromX, int fromY, int toX, int toY, Window* child);
  321. void childResized(int fromW, int fromH, int toW, int toH, Window* child);
  322. void childDeleted(Window* child);
  323. const char* tooltip(int xPos, int yPos) const;
  324. void undoNotify(int undoType, int undoItemId, int undoItemSubId, int uX, int uY, int uW, int uH);
  325. int event(int hasFocus, const SDL_Event* event);
  326. /* Not currently used or supported
  327. int usesAlpha();
  328. */
  329. WindowType windowType() const;
  330. WindowSort windowSort() const;
  331. CommandSupport supportsCommand(int code) const;
  332. // Propogates to all other children via siblingModified
  333. void childModified(Window* child);
  334. void siblingModified(Window* sibling);
  335. // This is whether the frame window wants to be deleted when it recieves SDL_CLOSE,
  336. // and defaults to YES
  337. int wantsToBeDeleted() const;
  338. // Lets us set whether we want the frame window to delete itself
  339. void setWantsToBeDeleted(int fDeleteMe);
  340. int attemptClose();
  341. // Adds window to gui onscreen with focus/removes
  342. // Once shown, it can receive a close message and delete itself, unless show() fails
  343. // xPos/yPos can come from these constants, or be >= 0
  344. enum {
  345. SHOW_CASCADE = -1, // Default cascading size / pos
  346. SHOW_CURRENT = -2, // Current size / pos (which, if just created, fits the client/toolpanels)
  347. SHOW_CURRMIN = -3, // Current size / pos, but with a minimum default size
  348. };
  349. // Show/hide on desktop
  350. // Size is for entire frame window, not client area
  351. void show(int xPos = SHOW_CASCADE, int yPos = SHOW_CASCADE, int width = SHOW_CASCADE, int height = SHOW_CASCADE);
  352. void hide(); // Manually hiding won't delete the frame window, ever
  353. class FrameWindow* getFramePanel();
  354. };
  355. #endif