/apps/common/ftk_app.h

http://ftk.googlecode.com/ · C Header · 117 lines · 60 code · 27 blank · 30 comment · 22 complexity · 65d277bbc33f0e04c9db23ad7929d01a MD5 · raw file

  1. /*
  2. * File: ftk_app.h
  3. * Author: Li XianJing <xianjimli@hotmail.com>
  4. * Brief: application interface
  5. *
  6. * Copyright (c) 2009 - 2010 Li XianJing <xianjimli@hotmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2010-08-15 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #ifndef FTK_APP_H
  31. #define FTK_APP_H
  32. #include "ftk.h"
  33. FTK_BEGIN_DECLS
  34. struct _FtkApp;
  35. typedef struct _FtkApp FtkApp;
  36. typedef FtkBitmap* (*FtkAppGetIcon)(FtkApp* thiz);
  37. typedef const char* (*FtkAppGetName)(FtkApp* thiz);
  38. typedef Ret (*FtkAppRun)(FtkApp* thiz, int argc, char* argv[]);
  39. typedef void (*FtkAppDestroy)(FtkApp* thiz);
  40. typedef FtkApp* (*FtkLoadApp)(void);
  41. struct _FtkApp
  42. {
  43. FtkAppGetIcon get_icon;
  44. FtkAppGetName get_name;
  45. FtkAppRun run;
  46. FtkAppDestroy destroy;
  47. char priv[ZERO_LEN_ARRAY];
  48. };
  49. static inline FtkBitmap* ftk_app_get_icon(FtkApp* thiz)
  50. {
  51. return_val_if_fail(thiz != NULL && thiz->get_icon != NULL, NULL);
  52. return thiz->get_icon(thiz);
  53. }
  54. static inline const char* ftk_app_get_name(FtkApp* thiz)
  55. {
  56. return_val_if_fail(thiz != NULL && thiz->get_name != NULL, NULL);
  57. return thiz->get_name(thiz);
  58. }
  59. static inline Ret ftk_app_run(FtkApp* thiz, int argc, char* argv[])
  60. {
  61. return_val_if_fail(thiz != NULL && thiz->run != NULL, RET_FAIL);
  62. return thiz->run(thiz, argc, argv);
  63. }
  64. static inline void ftk_app_destroy(FtkApp* thiz)
  65. {
  66. if(thiz != NULL && thiz->destroy != NULL)
  67. {
  68. // thiz->destroy(thiz);
  69. }
  70. return;
  71. }
  72. #include "ftk_config.h"
  73. #include "ftk_globals.h"
  74. static FtkBitmap* ftk_app_load_bitmap(FtkApp* thiz, const char* app_name, const char* icon_name)
  75. {
  76. FtkBitmap* icon = NULL;
  77. char file_name[FTK_MAX_PATH + 1] = {0};
  78. return_val_if_fail(thiz != NULL && app_name != NULL && icon_name != NULL, NULL);
  79. ftk_snprintf(file_name, FTK_MAX_PATH, "%s/%s/icons/%s"FTK_STOCK_IMG_SUFFIX,
  80. FTK_ROOT_DIR, app_name, icon_name);
  81. icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name);
  82. if(icon != NULL) return icon;
  83. ftk_snprintf(file_name, FTK_MAX_PATH, "./icons/%s"FTK_STOCK_IMG_SUFFIX, icon_name);
  84. icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name);
  85. if(icon != NULL) return icon;
  86. icon = ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
  87. return icon;
  88. }
  89. FTK_END_DECLS
  90. #endif/*FTK_APP_H*/