Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor! #3

Open
mtwilliams opened this issue Mar 18, 2015 · 1 comment
Open

Refactor! #3

mtwilliams opened this issue Mar 18, 2015 · 1 comment
Assignees
Milestone

Comments

@mtwilliams
Copy link
Member

/*===-- wtk/app.h -------------------------------------------*- mode: C -*-===*\
|*                                                                            *|
|*                                    _   _                                   *|
|*                              _ _ _| |_| |_                                 *|
|*                             | | | |  _| '_|                                *|
|*                             |_____|_| |_,_|                                *|
|*                                                                            *|
|*       This file is distributed under the terms described in LICENSE.       *|
|*                                                                            *|
|*===----------------------------------------------------------------------===*|
|*                                                                            *|
|*                                                                            *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

#ifndef _WTK_APP_H_
#define _WTK_APP_H_

/* #include "" */

WTK_BEGIN_EXTERN_C /* { */

/*! \copydoc wtk_app */
typedef struct wtk_app wtk_app_t;

/*! */
typedef (*wtk_app_on_quit_fn)(struct wtk_app *app);

/*! */
struct wtk_app {
  /*! \copydoc wtk_app_on_quit_fn */
  wtk_app_on_quit_fn on_quit;
};

/*! */
extern WTK_PUBLIC void wtk_app_init(struct wtk_app *app);

/*! */
extern WTK_PUBLIC void wtk_app_run(struct wtk_app *app); 

/*! */
extern WTK_PUBLIC void wtk_app_quit(struct wtk_app *app); 

WTK_END_EXTERN_C /* } */

#endif /* _WTK_APP_H_ */

/*===-- wtk/app.c -------------------------------------------*- mode: C -*-===*\
|*                                                                            *|
|*                                    _   _                                   *|
|*                              _ _ _| |_| |_                                 *|
|*                             | | | |  _| '_|                                *|
|*                             |_____|_| |_,_|                                *|
|*                                                                            *|
|*       This file is distributed under the terms described in LICENSE.       *|
|*                                                                            *|
|*===----------------------------------------------------------------------===*|
|*                                                                            *|
|*                                                                            *|
|*                                                                            *|
\*===----------------------------------------------------------------------===*/

#include "wtk/app.h"

#if WTK_PLATFORM == WTK_PLATFORM_WINDOWS
#  pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

WTK_BEGIN_EXTERN_C /* { */

static void _def_on_quit_handler(struct wtk_app *app) {
  wtk_assert_debug(app != (struct wtk_app *)NULL);
  exit(EXIT_SUCCESS);
}

void wtk_app_init(struct wtk_app *app) {
  wtk_assert_debug(app != (struct wtk_app *)NULL);
  app->on_quit = &_def_on_quit_handler;
#if WTK_PLATFORM == WTK_PLATFORM_WINDOWS
  /* Enable visual styles on Windows XP and later. */ {
    const DWORD dwVersion = GetVersion();
    const DWORD dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
    const DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
    if ((dwMajorVersion > 5) || ((dwMajorVersion == 5) && (dwMinorVersion >= 1))) {
      static const INITCOMMONCONTROLSEX iccx = {
        sizeof(INITCOMMONCONTROLSEX),
        ICC_BAR_CLASSES |
        ICC_HOTKEY_CLASS |
        ICC_INTERNET_CLASSES |
        ICC_LINK_CLASS |
        ICC_LISTVIEW_CLASSES |
        ICC_PROGRESS_CLASS |
        ICC_STANDARD_CLASSES |
        ICC_TAB_CLASSES |
        ICC_TREEVIEW_CLASSES
      };
      InitCommonControlsEx(&iccx);
    }
  }
#elif WTK_PLATFORM == WTK_PLATFORM_MAC_OS_X
#elif WTK_PLATFORM == WTK_PLATFORM_LINUX
#endif
}

void wtk_app_run(struct wtk_app *app) {
  wtk_assert_debug(app != (struct wtk_app *)NULL);
#if WTK_PLATFORM == WTK_PLATFORM_WINDOWS
  MSG msg;
  for (;;) {
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
      if (msg.message == WM_QUIT)
        app->on_quit(app);
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }
#elif WTK_PLATFORM == WTK_PLATFORM_MAC_OS_X
#elif WTK_PLATFORM == WTK_PLATFORM_LINUX
#endif
}

void wtk_app_quit(struct wtk_app *app) {
  wtk_assert_debug(app != (struct wtk_app *)NULL);
  wtk_assert_debug(app->on_quit != (wtk_app_on_quit_fn)NULL);
#if WTK_PLATFORM == WTK_PLATFORM_WINDOWS
  PostQuitMessage(0);
#elif WTK_PLATFORM == WTK_PLATFORM_MAC_OS_X
#elif WTK_PLATFORM == WTK_PLATFORM_LINUX
#endif
}

WTK_END_EXTERN_C /* } */
@mtwilliams mtwilliams self-assigned this Dec 4, 2015
@mtwilliams mtwilliams added this to the 1.0 milestone Dec 4, 2015
@mtwilliams
Copy link
Member Author

We'll want to move off of the "duck typing" used for arguments. Rather, a fixed API should be provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant